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.
This commit is contained in:
@@ -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 `<role>
|
||||
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.
|
||||
</role>
|
||||
|
||||
Description: ${description}
|
||||
<task>
|
||||
${description}
|
||||
</task>
|
||||
|
||||
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:
|
||||
<session_startup>
|
||||
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.
|
||||
</session_startup>
|
||||
|
||||
{ "status": "done", "result": { "message": "<one-sentence summary of what you changed>" } }
|
||||
<execution_rules>
|
||||
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 <file>\`, commit with a clear message describing what you did.
|
||||
5. Do not leave uncommitted work.
|
||||
</execution_rules>
|
||||
|
||||
If you cannot complete the change:
|
||||
<anti_patterns>
|
||||
- **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.
|
||||
</anti_patterns>
|
||||
${DEVIATION_RULES}
|
||||
${GIT_WORKFLOW}
|
||||
|
||||
{ "status": "error", "error": "<explanation>" }
|
||||
<signal_format>
|
||||
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": "<one-sentence summary of what you changed>" } }\`
|
||||
- Unrecoverable error: \`{ "status": "error", "error": "<explanation>" }\` — include the actual error output, stack trace, or repro steps, not just a summary
|
||||
|
||||
Do not create any other output files.
|
||||
</signal_format>`;
|
||||
}
|
||||
|
||||
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 `<role>
|
||||
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.
|
||||
</role>
|
||||
|
||||
Original description: ${description}
|
||||
|
||||
The user reviewed your changes and requested revisions:
|
||||
<task>
|
||||
**Original description:**
|
||||
${description}
|
||||
|
||||
**Revision feedback:**
|
||||
${feedback}
|
||||
</task>
|
||||
|
||||
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:
|
||||
<session_startup>
|
||||
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.
|
||||
</session_startup>
|
||||
|
||||
{ "status": "done", "result": { "message": "<one-sentence summary of what you changed>" } }
|
||||
<execution_rules>
|
||||
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 <file>\`, commit with a clear message describing what you revised.
|
||||
6. Do not leave uncommitted work.
|
||||
</execution_rules>
|
||||
|
||||
If you cannot complete the change:
|
||||
<anti_patterns>
|
||||
- **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.
|
||||
</anti_patterns>
|
||||
${DEVIATION_RULES}
|
||||
${GIT_WORKFLOW}
|
||||
|
||||
{ "status": "error", "error": "<explanation>" }
|
||||
<signal_format>
|
||||
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": "<one-sentence summary of what you changed>" } }\`
|
||||
- Unrecoverable error: \`{ "status": "error", "error": "<explanation>" }\` — include the actual error output, stack trace, or repro steps, not just a summary
|
||||
|
||||
Do not create any other output files.
|
||||
</signal_format>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user