@@ -4,28 +4,28 @@ import { join } from "node:path";
44 import { tildePath } from "../cli/output.ts";
55
66 function tryReadFile(p: string): string | null {
7- if (!existsSync(p)) return null;
8- try {
9- return readFileSync(p, "utf-8");
10- } catch {
11- return null;
12- }
7+ if (!existsSync(p)) return null;
8+ try {
9+ return readFileSync(p, "utf-8");
10+ } catch {
11+ return null;
12+ }
1313 }
1414
1515 function loadGlobalContextFile(homeDir: string): string | null {
16- const globalDir = join(homeDir, ".agents");
17- return (
18- tryReadFile(join(globalDir, "AGENTS.md")) ??
19- tryReadFile(join(globalDir, "CLAUDE.md"))
20- );
16+ const globalDir = join(homeDir, ".agents");
17+ return (
18+ tryReadFile(join(globalDir, "AGENTS.md")) ??
19+ tryReadFile(join(globalDir, "CLAUDE.md"))
20+ );
2121 }
2222
2323 export function loadLocalContextFile(cwd: string): string | null {
24- return (
25- tryReadFile(join(cwd, ".agents", "AGENTS.md")) ??
26- tryReadFile(join(cwd, "CLAUDE.md")) ??
27- tryReadFile(join(cwd, "AGENTS.md"))
28- );
24+ return (
25+ tryReadFile(join(cwd, ".agents", "AGENTS.md")) ??
26+ tryReadFile(join(cwd, "CLAUDE.md")) ??
27+ tryReadFile(join(cwd, "AGENTS.md"))
28+ );
2929 }
3030
3131 const AUTONOMY = `
@@ -37,23 +37,54 @@ const AUTONOMY = `
3737 - Do NOT output an upfront plan or preamble before working. Start making tool calls immediately.
3838 - Do NOT ask "shall I proceed?", "shall I start?", or any equivalent. Just start.
3939 - If something is ambiguous, pick the most reasonable interpretation, implement it, and note the assumption at the end.
40+- Do not guess unknown facts. Inspect files/tools first and state assumptions explicitly when needed.
4041 - Avoid excessive looping: if you find yourself re-reading or re-editing the same files without clear progress, stop and summarise what's blocking you.`;
4142
43+const SAFETY = `
44+
45+# Safety and risk boundaries
46+- Never expose, print, or commit secrets/tokens/keys.
47+- Never invent URLs. Use URLs explicitly provided by the user or found in trusted project files/docs.
48+- For destructive or irreversible actions (for example deleting data or force-resetting git history), ask one targeted confirmation question before proceeding.`;
49+
50+const WORKSPACE_GUARDRAILS = `
51+
52+# Workspace guardrails
53+- Never revert user-authored changes unless explicitly asked.
54+- If unexpected modifications appear in files you are actively editing, pause and ask how to proceed.
55+- Avoid destructive git commands unless explicitly requested. Prefer non-interactive git commands.`;
56+
57+const STATUS_UPDATES = `
58+
59+# Progress communication
60+- Do not send ceremonial preambles.
61+- For long-running or multi-phase tasks, send brief progress updates every few tool batches (one sentence with the next concrete action).`;
62+
63+const FINAL_MESSAGE = `
64+
65+# Final response style
66+- Default to concise output (short bullets or a brief paragraph).
67+- For substantial code changes, state what changed, where, and why.
68+- Reference files with line numbers when helpful.
69+- Do not paste large file contents unless asked.
70+- If verification was run, report commands and outcomes briefly.
71+- If verification could not be run, say so clearly.`;
72+
4273 const SUBAGENT_DELEGATION = `You are running as a subagent. Complete the task you have been given directly using your tools. Do not spawn further subagents unless the subtask is unambiguously separable and self-contained.`;
4374
4475 export function buildSystemPrompt(
45- cwd: string,
46- extraSystemPrompt?: string,
47- isSubagent?: boolean,
48- /** Override home directory — used in tests to isolate global context loading. */
49- homeDir?: string,
76+ cwd: string,
77+ extraSystemPrompt?: string,
78+ isSubagent?: boolean,
79+ /** Override home directory — used in tests to isolate global context loading. */
80+ homeDir?: string,
5081 ): string {
51- const globalContext = loadGlobalContextFile(homeDir ?? homedir());
52- const localContext = loadLocalContextFile(cwd);
53- const cwdDisplay = tildePath(cwd);
54- const now = new Date().toLocaleString(undefined, { hour12: false });
82+ const globalContext = loadGlobalContextFile(homeDir ?? homedir());
83+ const localContext = loadLocalContextFile(cwd);
84+ const cwdDisplay = tildePath(cwd);
85+ const now = new Date().toLocaleString(undefined, { hour12: false });
5586
56- let prompt = `You are mini-coder, a small and fast CLI coding agent.
87+ let prompt = `You are mini-coder, a small and fast CLI coding agent.
5788 You have access to tools to read files, search code, make edits, run shell commands, and spawn subagents.
5889
5990 Current working directory: ${cwdDisplay}
@@ -69,25 +100,29 @@ Guidelines:
69100 # Tool output format
70101 \`read\` and \`grep\` prefix every line with \`line:hash|\` (e.g. \`11:a3| code here\`). This prefix is metadata — never include it in file content you write. Use the \`line:hash\` values as anchors for \`replace\` and \`insert\`.`;
71102
72- prompt += AUTONOMY;
73-
74- if (globalContext || localContext) {
75- prompt += "\n\n# Project context";
76- if (globalContext) {
77- prompt += `\n\n${globalContext}`;
78- }
79- if (localContext) {
80- prompt += `\n\n${localContext}`;
81- }
82- }
83-
84- if (isSubagent) {
85- prompt += `\n\n${SUBAGENT_DELEGATION}`;
86- }
87-
88- if (extraSystemPrompt) {
89- prompt += `\n\n${extraSystemPrompt}`;
90- }
91-
92- return prompt;
103+ prompt += AUTONOMY;
104+ prompt += SAFETY;
105+ prompt += WORKSPACE_GUARDRAILS;
106+ prompt += STATUS_UPDATES;
107+ prompt += FINAL_MESSAGE;
108+
109+ if (globalContext || localContext) {
110+ prompt += "\n\n# Project context";
111+ if (globalContext) {
112+ prompt += `\n\n${globalContext}`;
113+ }
114+ if (localContext) {
115+ prompt += `\n\n${localContext}`;
116+ }
117+ }
118+
119+ if (isSubagent) {
120+ prompt += `\n\n${SUBAGENT_DELEGATION}`;
121+ }
122+
123+ if (extraSystemPrompt) {
124+ prompt += `\n\n${extraSystemPrompt}`;
125+ }
126+
127+ return prompt;
93128 }