diff --git a/packages/core/src/core/__snapshots__/prompts.test.ts.snap b/packages/core/src/core/__snapshots__/prompts.test.ts.snap index 5e58768c62..985a97a38c 100644 --- a/packages/core/src/core/__snapshots__/prompts.test.ts.snap +++ b/packages/core/src/core/__snapshots__/prompts.test.ts.snap @@ -791,12 +791,49 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Help Command:** The user can use '/help' to display help information. - **Feedback:** To report a bug or provide feedback, please use the /bug command. +## File Creation (Non-Interactive) +- **Prefer write_file over shell heredocs** for creating or overwriting files. The write_file tool is more reliable and avoids shell escaping issues. +- Only use shell heredocs when you need to append to a file or when the content depends on shell variable expansion. +- If you must use a heredoc, always use the full syntax: \`cat << 'EOF' > filename\` — never omit \`cat\`. + +## Background Services (Non-Interactive) +- To start a service that must persist across turns, use: \`nohup > /tmp/.log 2>&1 &\` +- After starting, verify the process is running: + 1. \`echo $!\` to capture the PID immediately after starting + 2. \`sleep 1 && kill -0 \` to confirm it's still alive + 3. Check the log file for startup errors: \`cat /tmp/.log\` +- If a service fails to start, check the log file before retrying. +- For services that need time to initialize (databases, web servers), add a brief \`sleep 2\` and verify the port is open before proceeding. + ## Error Recovery (Non-Interactive) - **Don't blindly retry:** When a tool call fails, analyze the error before retrying. Do not immediately retry with the same arguments. - **Web fetch failures:** If web_fetch fails, try simplifying the prompt or use google_web_search as an alternative to find the information. - **Shell failures:** Check error codes and run diagnostic commands before retrying. For compilation errors, fix one issue at a time rather than attempting multiple fixes simultaneously. - **Maximum retries:** Attempt the same approach at most 2 times. If it fails twice, try an alternative strategy or tool. -- **Avoid loops:** If you find yourself repeating the same sequence of actions, stop and reassess your approach." +- **Avoid loops:** If you find yourself repeating the same sequence of actions, stop and reassess your approach. + +## Missing Commands / "command not found" +- When a command is not found, install the package that provides it before retrying. +- Use \`apt-get install -y \` (Debian/Ubuntu) or \`yum install -y \` (RHEL/CentOS). +- Common mappings: + - pgrep, ps, pidof → procps + - ss → iproute2 + - netstat, ifconfig → net-tools + - curl → curl + - jq → jq + - dig, nslookup → dnsutils (or bind-utils on RHEL) + - ip → iproute2 + - lsof → lsof + - wget → wget + - tree → tree + - zip/unzip → zip / unzip +- If you don't know the package name, try \`apt-cache search \` or \`yum provides \`. + +## Process Verification Without pgrep +- If pgrep/ps are unavailable and you can't install them, verify processes using: + - \`ls /proc/[PID]\` to check if a PID is still running + - \`kill -0 \` to test if a process exists (returns 0 if it does) + - \`cat /proc//cmdline\` to inspect what a process is running" `; exports[`Core System Prompt (prompts.ts) > should handle CodebaseInvestigator with tools=grep_search,glob 1`] = ` @@ -920,12 +957,49 @@ Operate using a **Research -> Strategy -> Execution** lifecycle. For the Executi - **Help Command:** The user can use '/help' to display help information. - **Feedback:** To report a bug or provide feedback, please use the /bug command. +## File Creation (Non-Interactive) +- **Prefer write_file over shell heredocs** for creating or overwriting files. The write_file tool is more reliable and avoids shell escaping issues. +- Only use shell heredocs when you need to append to a file or when the content depends on shell variable expansion. +- If you must use a heredoc, always use the full syntax: \`cat << 'EOF' > filename\` — never omit \`cat\`. + +## Background Services (Non-Interactive) +- To start a service that must persist across turns, use: \`nohup > /tmp/.log 2>&1 &\` +- After starting, verify the process is running: + 1. \`echo $!\` to capture the PID immediately after starting + 2. \`sleep 1 && kill -0 \` to confirm it's still alive + 3. Check the log file for startup errors: \`cat /tmp/.log\` +- If a service fails to start, check the log file before retrying. +- For services that need time to initialize (databases, web servers), add a brief \`sleep 2\` and verify the port is open before proceeding. + ## Error Recovery (Non-Interactive) - **Don't blindly retry:** When a tool call fails, analyze the error before retrying. Do not immediately retry with the same arguments. - **Web fetch failures:** If web_fetch fails, try simplifying the prompt or use google_web_search as an alternative to find the information. - **Shell failures:** Check error codes and run diagnostic commands before retrying. For compilation errors, fix one issue at a time rather than attempting multiple fixes simultaneously. - **Maximum retries:** Attempt the same approach at most 2 times. If it fails twice, try an alternative strategy or tool. -- **Avoid loops:** If you find yourself repeating the same sequence of actions, stop and reassess your approach." +- **Avoid loops:** If you find yourself repeating the same sequence of actions, stop and reassess your approach. + +## Missing Commands / "command not found" +- When a command is not found, install the package that provides it before retrying. +- Use \`apt-get install -y \` (Debian/Ubuntu) or \`yum install -y \` (RHEL/CentOS). +- Common mappings: + - pgrep, ps, pidof → procps + - ss → iproute2 + - netstat, ifconfig → net-tools + - curl → curl + - jq → jq + - dig, nslookup → dnsutils (or bind-utils on RHEL) + - ip → iproute2 + - lsof → lsof + - wget → wget + - tree → tree + - zip/unzip → zip / unzip +- If you don't know the package name, try \`apt-cache search \` or \`yum provides \`. + +## Process Verification Without pgrep +- If pgrep/ps are unavailable and you can't install them, verify processes using: + - \`ls /proc/[PID]\` to check if a PID is still running + - \`kill -0 \` to test if a process exists (returns 0 if it does) + - \`cat /proc//cmdline\` to inspect what a process is running" `; exports[`Core System Prompt (prompts.ts) > should handle git instructions when isGitRepository=false 1`] = ` diff --git a/packages/core/src/prompts/snippets.ts b/packages/core/src/prompts/snippets.ts index b30bf07c0e..8cc8dfa1fb 100644 --- a/packages/core/src/prompts/snippets.ts +++ b/packages/core/src/prompts/snippets.ts @@ -333,6 +333,8 @@ 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 ? nonInteractiveFileWritingGuidance() : ''} +${!options.interactive ? nonInteractiveProcessGuidance() : ''} ${!options.interactive ? nonInteractiveErrorRecovery() : ''} `.trim(); } @@ -675,6 +677,26 @@ function gitRepoKeepUserInformed(interactive: boolean): string { : ''; } +function nonInteractiveFileWritingGuidance(): string { + return ` +## File Creation (Non-Interactive) +- **Prefer ${WRITE_FILE_TOOL_NAME} over shell heredocs** for creating or overwriting files. The ${WRITE_FILE_TOOL_NAME} tool is more reliable and avoids shell escaping issues. +- Only use shell heredocs when you need to append to a file or when the content depends on shell variable expansion. +- If you must use a heredoc, always use the full syntax: \`cat << 'EOF' > filename\` — never omit \`cat\`.`; +} + +function nonInteractiveProcessGuidance(): string { + return ` +## Background Services (Non-Interactive) +- To start a service that must persist across turns, use: \`nohup > /tmp/.log 2>&1 &\` +- After starting, verify the process is running: + 1. \`echo $!\` to capture the PID immediately after starting + 2. \`sleep 1 && kill -0 \` to confirm it's still alive + 3. Check the log file for startup errors: \`cat /tmp/.log\` +- If a service fails to start, check the log file before retrying. +- For services that need time to initialize (databases, web servers), add a brief \`sleep 2\` and verify the port is open before proceeding.`; +} + function nonInteractiveErrorRecovery(): string { return ` ## Error Recovery (Non-Interactive) @@ -682,7 +704,30 @@ function nonInteractiveErrorRecovery(): string { - **Web fetch failures:** If web_fetch fails, try simplifying the prompt or use google_web_search as an alternative to find the information. - **Shell failures:** Check error codes and run diagnostic commands before retrying. For compilation errors, fix one issue at a time rather than attempting multiple fixes simultaneously. - **Maximum retries:** Attempt the same approach at most 2 times. If it fails twice, try an alternative strategy or tool. -- **Avoid loops:** If you find yourself repeating the same sequence of actions, stop and reassess your approach.`; +- **Avoid loops:** If you find yourself repeating the same sequence of actions, stop and reassess your approach. + +## Missing Commands / "command not found" +- When a command is not found, install the package that provides it before retrying. +- Use \`apt-get install -y \` (Debian/Ubuntu) or \`yum install -y \` (RHEL/CentOS). +- Common mappings: + - pgrep, ps, pidof → procps + - ss → iproute2 + - netstat, ifconfig → net-tools + - curl → curl + - jq → jq + - dig, nslookup → dnsutils (or bind-utils on RHEL) + - ip → iproute2 + - lsof → lsof + - wget → wget + - tree → tree + - zip/unzip → zip / unzip +- If you don't know the package name, try \`apt-cache search \` or \`yum provides \`. + +## Process Verification Without pgrep +- If pgrep/ps are unavailable and you can't install them, verify processes using: + - \`ls /proc/[PID]\` to check if a PID is still running + - \`kill -0 \` to test if a process exists (returns 0 if it does) + - \`cat /proc//cmdline\` to inspect what a process is running`; } function formatToolName(name: string): string {