Skip to content

Fallback to script parsing if prompt wasn't available through hooks#705

Merged
Soph merged 2 commits intomainfrom
soph/factory-ai-fixes
Mar 17, 2026
Merged

Fallback to script parsing if prompt wasn't available through hooks#705
Soph merged 2 commits intomainfrom
soph/factory-ai-fixes

Conversation

@Soph
Copy link
Copy Markdown
Collaborator

@Soph Soph commented Mar 16, 2026

The E2E tests are currently failing for Factory AI Droid because the tests assumes an extracted prompt but using droid exec will not trigger UserPromptSubmit which means we got no prompt. This meant so far an empty prompt was stored.

If we now have no prompt.txt at the end of the turn we fallback to session transcript parsing to extract the prompt.

Copilot AI review requested due to automatic review settings March 16, 2026 17:55
@cursor
Copy link
Copy Markdown

cursor bot commented Mar 16, 2026

PR Summary

Medium Risk
Changes turn-end lifecycle behavior to write prompt.txt and potentially update SessionState.LastPrompt based on transcript parsing, which can affect downstream commit message generation and metadata. Risk is moderate due to new control flow and file/state writes, but scoped to the missing-prompt fallback path.

Overview
Adds a new optional PromptExtractor agent interface plus AsPromptExtractor capability gating, enabling agents to provide prompt extraction from transcripts.

On TurnEnd, when prompt.txt is missing/empty, the CLI now attempts to backfill prompts from the transcript (joined with the existing --- separator) and, if successful, updates SessionState.LastPrompt after SaveStep to avoid being overwritten.

Factory AI Droid implements ExtractPrompts by scanning user transcript entries (stripping IDE context tags), and new unit tests cover the backfill behavior, preservation of existing prompt.txt, and session state update.

Written by Cursor Bugbot for commit 8fa1853. Configure here.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses missing prompt capture for agents (notably Factory AI Droid in exec mode) by backfilling prompt.txt from the session transcript when hooks didn’t provide a prompt, ensuring stored session metadata contains the user prompt.

Changes:

  • Add a new agent.PromptExtractor interface plus AsPromptExtractor capability gating helper.
  • Backfill prompt.txt during TurnEnd by extracting prompts from the transcript when prompt.txt is absent/empty, and update session state accordingly.
  • Add lifecycle and capability tests covering prompt writing/backfill behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
cmd/entire/cli/lifecycle.go Implements prompt.txt backfill from transcript on TurnEnd and updates session state after SaveStep.
cmd/entire/cli/lifecycle_test.go Adds tests for prompt file writing, transcript backfill, and session-state update behavior.
cmd/entire/cli/agent/agent.go Introduces the PromptExtractor interface for transcript-based prompt extraction.
cmd/entire/cli/agent/capabilities.go Adds AsPromptExtractor helper that gates usage for capability-declaring agents.
cmd/entire/cli/agent/capabilities_test.go Adds unit tests verifying AsPromptExtractor behavior for different agent types/cap declarations.
cmd/entire/cli/agent/factoryaidroid/lifecycle.go Declares Factory AI Droid agent implements PromptExtractor.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Entire-Checkpoint: af0f2abf5c4e
@Soph Soph marked this pull request as ready for review March 16, 2026 18:52
@Soph Soph requested a review from a team as a code owner March 16, 2026 18:52
@Soph Soph merged commit 79f576b into main Mar 17, 2026
3 checks passed
@Soph Soph deleted the soph/factory-ai-fixes branch March 17, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants