From bf4a55f2f222a677cd19f57e14eb7d6129ff362e Mon Sep 17 00:00:00 2001 From: Lukas May Date: Sat, 7 Mar 2026 01:00:36 +0100 Subject: [PATCH] refactor: rewrite errand prompts with structured XML sections Bring buildErrandPrompt() and buildErrandRevisionPrompt() in line with the codebase pattern used by execute, plan, detail, etc. Import shared DEVIATION_RULES and GIT_WORKFLOW constants. Add session_startup (pwd, git status, CLAUDE.md, expected-pwd.txt), execution_rules, and anti_patterns sections. Keep signal format inline since errands use result.message instead of the standard questions format. --- apps/server/agent/prompts/errand.ts | 102 ++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 20 deletions(-) diff --git a/apps/server/agent/prompts/errand.ts b/apps/server/agent/prompts/errand.ts index ca1d665..91df4d4 100644 --- a/apps/server/agent/prompts/errand.ts +++ b/apps/server/agent/prompts/errand.ts @@ -1,39 +1,101 @@ +/** + * Errand mode prompt — small, focused changes in an isolated worktree. + */ + +import { DEVIATION_RULES, GIT_WORKFLOW } from './shared.js'; + export function buildErrandPrompt(description: string): string { - return `You are working on a small, focused change in an isolated worktree. + return ` +You are a Worker agent making a small, focused change in an isolated worktree. +Make only the changes needed to fulfill the description. Do not expand scope. + -Description: ${description} + +${description} + -Work interactively with the user. Make only the changes needed to fulfill the description. -Before signaling completion, commit all your changes with a clear commit message describing what you did. Do not leave uncommitted work. -When you are done, write .cw/output/signal.json: + +1. \`pwd\` — confirm working directory +2. \`git status\` — check for unexpected state +3. Read \`CLAUDE.md\` at the repo root (if it exists) — it contains project conventions and patterns you must follow. +4. Read \`.cw/expected-pwd.txt\` — it contains the absolute path you should be working from. If your \`pwd\` doesn't match, \`cd\` to that path before doing anything else. + -{ "status": "done", "result": { "message": "" } } + +1. Read any files relevant to the task before making changes. +2. Implement the change — minimum code to fulfill the description. +3. Run tests, linter, or type checker if the change touches testable code. +4. Stage specific files with \`git add \`, commit with a clear message describing what you did. +5. Do not leave uncommitted work. + -If you cannot complete the change: + +- **Scope creep**: Only do what the description asks. No drive-by refactors, no bonus features. +- **Blind edits**: Always read a file before modifying it. +- **Debug artifacts**: Remove all \`console.log\`, debug statements, and temporary instrumentation before committing. +- **Spinning on failures**: If a fix attempt fails 3 times, signal "error" with what you tried. Don't loop indefinitely. +- **Relative path assumptions**: Always use absolute paths or verify your working directory first. + +${DEVIATION_RULES} +${GIT_WORKFLOW} -{ "status": "error", "error": "" } + +CRITICAL: Write \`.cw/output/signal.json\` as your ABSOLUTE LAST action. The system monitors this file as a completion trigger — writing it before committing causes your work to be silently discarded. -Do not create any other output files.`; +- Done: \`{ "status": "done", "result": { "message": "" } }\` +- Unrecoverable error: \`{ "status": "error", "error": "" }\` — include the actual error output, stack trace, or repro steps, not just a summary + +Do not create any other output files. +`; } export function buildErrandRevisionPrompt(description: string, feedback: string): string { - return `You are revising a previous change in an isolated worktree. The worktree already contains your prior work. + return ` +You are a Worker agent revising a previous change in an isolated worktree. +The worktree already contains your prior work. Address the feedback without undoing prior work unless specifically asked. + -Original description: ${description} - -The user reviewed your changes and requested revisions: + +**Original description:** +${description} +**Revision feedback:** ${feedback} + -Make only the changes needed to address the feedback. Do not undo prior work unless the feedback specifically asks for it. -Before signaling completion, commit all your changes with a clear commit message describing what you did. Do not leave uncommitted work. -When you are done, write .cw/output/signal.json: + +1. \`pwd\` — confirm working directory +2. \`git status\` — check for unexpected state +3. Read \`CLAUDE.md\` at the repo root (if it exists) — it contains project conventions and patterns you must follow. +4. Read \`.cw/expected-pwd.txt\` — it contains the absolute path you should be working from. If your \`pwd\` doesn't match, \`cd\` to that path before doing anything else. + -{ "status": "done", "result": { "message": "" } } + +1. Read the files affected by your prior work and the feedback. +2. Implement only the changes needed to address the feedback. +3. Do not undo prior work unless the feedback specifically asks for it. +4. Run tests, linter, or type checker if the change touches testable code. +5. Stage specific files with \`git add \`, commit with a clear message describing what you revised. +6. Do not leave uncommitted work. + -If you cannot complete the change: + +- **Scope creep**: Only address the feedback. No drive-by refactors, no bonus features. +- **Blind edits**: Always read a file before modifying it. +- **Undoing prior work**: Your previous changes are intentional. Only revert what the feedback explicitly asks to change. +- **Debug artifacts**: Remove all \`console.log\`, debug statements, and temporary instrumentation before committing. +- **Spinning on failures**: If a fix attempt fails 3 times, signal "error" with what you tried. Don't loop indefinitely. +- **Relative path assumptions**: Always use absolute paths or verify your working directory first. + +${DEVIATION_RULES} +${GIT_WORKFLOW} -{ "status": "error", "error": "" } + +CRITICAL: Write \`.cw/output/signal.json\` as your ABSOLUTE LAST action. The system monitors this file as a completion trigger — writing it before committing causes your work to be silently discarded. -Do not create any other output files.`; +- Done: \`{ "status": "done", "result": { "message": "" } }\` +- Unrecoverable error: \`{ "status": "error", "error": "" }\` — include the actual error output, stack trace, or repro steps, not just a summary + +Do not create any other output files. +`; }