feat(chat-workflow): thread real cwd + currentBranch into system prompt (cutover Bundle A.7)
Summary
Third open-agents → api cutover bundle. The handler was hardcoding workingDirectory: DEFAULT_WORKING_DIRECTORY and never setting currentBranch, so the agent had no environment info in its system prompt and had to run pwd / git branch on every turn.
Production reproducer (today, before this fix)
Same prompt sent to https://recoup-api.vercel.app/api/chat/workflow:
Prompt: "DO NOT run any tools. Just answer from your system prompt only: what is your current working directory and current git branch? If your system prompt doesn't contain that info, say exactly 'My system prompt does not contain working directory or branch information.'"
Agent response: "My system prompt does not contain working directory or branch information."
Compare against sandbox.recoupable.com (open-agents prod) which answers:
"My system prompt states the working directory is . (workspace root), but it does not contain any git branch information." (branch missing because that session had no repo attached; open-agents threads it when present)
After this fix
The agent receives an # Environment section + Current branch: <branch> line + cloud-sandbox checkpointing block — same shape as open-agents emits.
Changes (SRP)
lib/chat/buildAgentSystemPrompt.ts— assembles environment section → Current branch → cloud-sandbox checkpointing → custom instructions, all conditional on inputs. Mirrorsopen-agents/packages/agent/system-prompt.ts:420-447.lib/chat/cloudSandboxInstructions.ts— portsCLOUD_SANDBOX_INSTRUCTIONSblock with{branch}placeholder substitution.handleChatWorkflowStream— reuses the already-connected sandbox (currently only used for skill discovery) to read realworkingDirectory+currentBranch, threads both intoAgentContext.sandbox. Falls back toDEFAULT_WORKING_DIRECTORYon connect failure (preserves today's behavior).runAgentStep— callsbuildAgentSystemPrompt({cwd, currentBranch, customInstructions})instead of using staticagentCustomInstructionsdirectly.
Scope reduced from "A.7+9"
Dropped contextLimit plumbing. Grepped open-agents' server code — it never reads context.contextLimit either. It's a client-side display concern (token-usage progress bar), and api already accepts the field via Zod strip. Verified behaviorally: production selectedModelId is identical with/without contextLimit in both api and open-agents. Bundle A is now just A.7.
Cutover roadmap
| # | Bundle | This PR | Notes |
|---|---|---|---|
| 1 | C per-message cost/usage | ✅ merged | #592 / #593 |
| 2 | B subagent live progress + transcript | ✅ merged | #594 / #595 |
| 3 | A.7 real cwd + currentBranch in system prompt | ✅ this PR | A.9 dropped — not a server concern |
| 4 | A.6 Anthropic prompt cache control | ||
| 5 | A.4 forward Privy JWT as recoupAccessToken |
Test plan
- 7 new unit tests (6 buildAgentSystemPrompt + 1 runAgentStep wiring assertion)
- Full suite 3121/3121 pass; lint clean
- E2E on preview: re-run the "what's your cwd/branch?" prompt — expect the agent to answer with the env section info instead of "doesn't contain"
🤖 Generated with Claude Code
Summary by cubic
Threads the sandbox working directory into the agent’s system prompt so the agent knows it’s in a workspace and can use relative paths without running pwd each turn. Drops branch templating for now since it’s always main.
-
New Features
- Added
buildAgentSystemPromptto prepend an Environment section and then append custom instructions. - Updated
handleChatWorkflowStreamto connect to the sandbox, read realworkingDirectory, and pass it intoAgentContext.sandbox(falls back toDEFAULT_WORKING_DIRECTORYon failure). - Updated
runAgentStepto usebuildAgentSystemPrompt({ cwd, customInstructions })instead of a staticagentCustomInstructions.
- Added
-
Bug Fixes
- Removed a stale
currentBranchargument inrunAgentStepafter dropping branch templating, fixing the build.
- Removed a stale
Summary by CodeRabbit
-
New Features
- Agent system prompts now dynamically include sandbox working directory and branch information.
-
Improvements
- Sandbox connection established earlier in the workflow process for better context discovery.
- System prompt generation enhanced with conditional environment information.