feat(core): add error recovery guidance to non-interactive system prompt

The autonomous system prompt did not guide the agent on error recovery,
causing fallback loops. Adds a non-interactive error recovery section
to renderOperationalGuidelines() gated behind !options.interactive.

Covers: analyze before retrying, two-strike rule for trying alternatives,
avoid alternating-approach loops, verify fixes incrementally.
This commit is contained in:
Bryan Morgan
2026-03-12 15:16:50 -04:00
parent 333475c41f
commit b949049dcb
2 changed files with 24 additions and 2 deletions
@@ -918,7 +918,13 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi
## Interaction Details
- **Help Command:** The user can use '/help' to display help information.
- **Feedback:** To report a bug or provide feedback, please use the /bug command."
- **Feedback:** To report a bug or provide feedback, please use the /bug command.
## Error Recovery (Non-Interactive)
- **Analyze before retrying:** When a command or tool call fails, read the error message carefully. Identify the root cause before attempting a fix. Do not blindly retry the same command.
- **Two-strike rule:** If the same approach fails twice, try a fundamentally different approach. Do not repeat a failing strategy more than twice.
- **Avoid loops:** If you find yourself alternating between two approaches that both fail, stop and reassess. Consider whether the task requirements need to be adjusted or a completely different tool/method is needed.
- **Incremental progress:** After recovering from an error, verify the fix worked before moving on. Do not assume success."
`;
exports[`Core System Prompt (prompts.ts) > should handle CodebaseInvestigator with tools=grep_search,glob 1`] = `
@@ -1040,7 +1046,13 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi
## Interaction Details
- **Help Command:** The user can use '/help' to display help information.
- **Feedback:** To report a bug or provide feedback, please use the /bug command."
- **Feedback:** To report a bug or provide feedback, please use the /bug command.
## Error Recovery (Non-Interactive)
- **Analyze before retrying:** When a command or tool call fails, read the error message carefully. Identify the root cause before attempting a fix. Do not blindly retry the same command.
- **Two-strike rule:** If the same approach fails twice, try a fundamentally different approach. Do not repeat a failing strategy more than twice.
- **Avoid loops:** If you find yourself alternating between two approaches that both fail, stop and reassess. Consider whether the task requirements need to be adjusted or a completely different tool/method is needed.
- **Incremental progress:** After recovering from an error, verify the fix worked before moving on. Do not assume success."
`;
exports[`Core System Prompt (prompts.ts) > should handle git instructions when isGitRepository=false 1`] = `
+10
View File
@@ -365,9 +365,19 @@ export function renderOperationalGuidelines(
## Interaction Details
- **Help Command:** The user can use '/help' to display help information.
- **Feedback:** To report a bug or provide feedback, please use the /bug command.
${!options.interactive ? nonInteractiveErrorRecovery() : ''}
`.trim();
}
function nonInteractiveErrorRecovery(): string {
return `
## Error Recovery (Non-Interactive)
- **Analyze before retrying:** When a command or tool call fails, read the error message carefully. Identify the root cause before attempting a fix. Do not blindly retry the same command.
- **Two-strike rule:** If the same approach fails twice, try a fundamentally different approach. Do not repeat a failing strategy more than twice.
- **Avoid loops:** If you find yourself alternating between two approaches that both fail, stop and reassess. Consider whether the task requirements need to be adjusted or a completely different tool/method is needed.
- **Incremental progress:** After recovering from an error, verify the fix worked before moving on. Do not assume success.`;
}
export function renderSandbox(mode?: SandboxMode): string {
if (!mode) return '';
if (mode === 'macos-seatbelt') {