xonecas.io
64875
Mc

mini-coder / commit 5192821

feat: system prompt updates.

Also removed the ridiculous tests around the prompt.

xonecas2026-03-31 5192821c9cc76f8e2db5dc5800cb645caae84dda parent 4b60f71

2 files changed

src/agent/system-prompt.test.ts+0−197
@@ -1,197 +0,0 @@
1-import { afterEach, beforeEach, describe, expect, it } from "bun:test";
2-import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3-import { tmpdir } from "node:os";
4-import { join } from "node:path";
5-import { loadLocalContextFile } from "./context-files.ts";
6-import { buildSystemPrompt } from "./system-prompt.ts";
7-
8-let tmpDir: string;
9-let fakeHome: string;
10-
11-beforeEach(() => {
12- tmpDir = mkdtempSync(join(tmpdir(), "mc-test-"));
13- fakeHome = mkdtempSync(join(tmpdir(), "mc-home-"));
14-});
15-
16-afterEach(() => {
17- rmSync(tmpDir, { recursive: true, force: true });
18- rmSync(fakeHome, { recursive: true, force: true });
19-});
20-
21-describe("loadLocalContextFile", () => {
22- it("returns null when no context files exist", () => {
23- expect(loadLocalContextFile(tmpDir)).toBeNull();
24- });
25-
26- it("reads all context files when multiple exist", () => {
27- mkdirSync(join(tmpDir, ".agents"), { recursive: true });
28- writeFileSync(join(tmpDir, ".agents", "AGENTS.md"), "agents content");
29- writeFileSync(join(tmpDir, "AGENTS.md"), "root content");
30- writeFileSync(join(tmpDir, "CLAUDE.md"), "claude content");
31- const result = loadLocalContextFile(tmpDir) as string;
32- expect(result).toContain("agents content");
33- expect(result).toContain("claude content");
34- expect(result).toContain("root content");
35- });
36-
37- it("reads both CLAUDE.md and AGENTS.md when .agents dir absent", () => {
38- writeFileSync(join(tmpDir, "CLAUDE.md"), "claude content");
39- writeFileSync(join(tmpDir, "AGENTS.md"), "root content");
40- const result = loadLocalContextFile(tmpDir) as string;
41- expect(result).toContain("claude content");
42- expect(result).toContain("root content");
43- });
44-
45- it("reads AGENTS.md at root when others absent", () => {
46- writeFileSync(join(tmpDir, "AGENTS.md"), "root content");
47- expect(loadLocalContextFile(tmpDir)).toBe("root content");
48- });
49-
50- it("reads .claude/CLAUDE.md when .agents files absent", () => {
51- mkdirSync(join(tmpDir, ".claude"), { recursive: true });
52- writeFileSync(join(tmpDir, ".claude", "CLAUDE.md"), "claude dir content");
53- expect(loadLocalContextFile(tmpDir)).toBe("claude dir content");
54- });
55-
56- it("reads .agents/CLAUDE.md when .agents/AGENTS.md absent", () => {
57- mkdirSync(join(tmpDir, ".agents"), { recursive: true });
58- writeFileSync(
59- join(tmpDir, ".agents", "CLAUDE.md"),
60- "agents claude content",
61- );
62- expect(loadLocalContextFile(tmpDir)).toBe("agents claude content");
63- });
64-
65- it("walks ancestor directories up to git root", () => {
66- mkdirSync(join(tmpDir, ".git"), { recursive: true });
67- writeFileSync(join(tmpDir, "AGENTS.md"), "root context");
68- const nested = join(tmpDir, "packages", "lib", "src");
69- mkdirSync(nested, { recursive: true });
70- expect(loadLocalContextFile(nested)).toBe("root context");
71- });
72-
73- it("stops walking at git root and does not go beyond", () => {
74- const gitRoot = join(tmpDir, "repo");
75- mkdirSync(join(gitRoot, ".git"), { recursive: true });
76- writeFileSync(join(tmpDir, "AGENTS.md"), "outside git");
77- const nested = join(gitRoot, "src");
78- mkdirSync(nested, { recursive: true });
79- expect(loadLocalContextFile(nested)).toBeNull();
80- });
81-
82- it("nearest context file wins over ancestor", () => {
83- mkdirSync(join(tmpDir, ".git"), { recursive: true });
84- writeFileSync(join(tmpDir, "AGENTS.md"), "root context");
85- const nested = join(tmpDir, "packages", "lib");
86- mkdirSync(nested, { recursive: true });
87- writeFileSync(join(nested, "AGENTS.md"), "nested context");
88- expect(loadLocalContextFile(nested)).toBe("nested context");
89- });
90-});
91-
92-describe("buildSystemPrompt", () => {
93- it("includes base guidelines without context files", () => {
94- const prompt = buildSystemPrompt("mock-time-anchor", tmpDir, fakeHome);
95- expect(prompt).toContain("You are mini-coder");
96- expect(prompt).toContain("Guidelines:");
97- expect(prompt).not.toContain("# Project context");
98- expect(prompt).toContain("# Safety");
99- expect(prompt).toContain("# Communication");
100- expect(prompt).toContain("# Error handling");
101- expect(prompt).toContain(
102- "Inspect code and files primarily through shell commands",
103- );
104- expect(prompt).toContain("invoke `mc-edit` via shell");
105- expect(prompt).toContain("never guess unknown state");
106- });
107-
108- it("includes local context under # Project context", () => {
109- writeFileSync(join(tmpDir, "AGENTS.md"), "local project info");
110- const prompt = buildSystemPrompt("mock-time-anchor", tmpDir, fakeHome);
111- expect(prompt).toContain("# Project context");
112- expect(prompt).toContain("local project info");
113- });
114-
115- it("has exactly one # Project context section when local context present", () => {
116- writeFileSync(join(tmpDir, "AGENTS.md"), "local info");
117- const prompt = buildSystemPrompt("mock-time-anchor", tmpDir, fakeHome);
118- const occurrences = prompt.split("# Project context").length - 1;
119- expect(occurrences).toBe(1);
120- });
121-
122- it("includes cwd and current time in prompt", () => {
123- const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
124- expect(prompt).toContain("Current working directory:");
125- expect(prompt).toContain("Current date/time:");
126- });
127-
128- it("includes global context when ~/.agents/AGENTS.md present", () => {
129- mkdirSync(join(fakeHome, ".agents"), { recursive: true });
130- writeFileSync(join(fakeHome, ".agents", "AGENTS.md"), "global info");
131- const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
132- expect(prompt).toContain("# Project context");
133- expect(prompt).toContain("global info");
134- });
135-
136- it("includes global context from ~/.claude/CLAUDE.md", () => {
137- mkdirSync(join(fakeHome, ".claude"), { recursive: true });
138- writeFileSync(join(fakeHome, ".claude", "CLAUDE.md"), "claude global info");
139- const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
140- expect(prompt).toContain("# Project context");
141- expect(prompt).toContain("claude global info");
142- });
143-
144- it("includes both global and local context in order (global before local)", () => {
145- mkdirSync(join(fakeHome, ".agents"), { recursive: true });
146- writeFileSync(join(fakeHome, ".agents", "AGENTS.md"), "global info");
147- writeFileSync(join(tmpDir, "AGENTS.md"), "local info");
148- const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
149- expect(prompt).toContain("global info");
150- expect(prompt).toContain("local info");
151- expect(prompt.indexOf("global info")).toBeLessThan(
152- prompt.indexOf("local info"),
153- );
154- });
155-
156- it("does not include # Project context when neither global nor local context present", () => {
157- const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
158- expect(prompt).not.toContain("# Project context");
159- });
160-
161- it("includes skill metadata guidance when skills are discoverable", () => {
162- const skillDir = join(tmpDir, ".agents", "skills", "deploy");
163- mkdirSync(skillDir, { recursive: true });
164- writeFileSync(
165- join(skillDir, "SKILL.md"),
166- "---\nname: deploy\ndescription: Deploy safely\n---\n\n# Deploy\nDetailed body",
167- );
168-
169- const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
170- expect(prompt).toContain("# Skills");
171- expect(prompt).toContain(
172- "call `readSkill` with that skill name before doing anything else",
173- );
174- expect(prompt).toContain("Check ALL skills against the current task");
175- expect(prompt).toContain("<available_skills>");
176- expect(prompt).toContain("<name>deploy</name>");
177- expect(prompt).toContain("<description>Deploy safely</description>");
178- expect(prompt).toContain(".agents/skills/deploy/SKILL.md</location>");
179- expect(prompt).toContain("<source>local</source>");
180- expect(prompt).not.toContain("Detailed body");
181- });
182-
183- it("includes globally discovered skill metadata when homeDir is provided", () => {
184- const skillDir = join(fakeHome, ".agents", "skills", "release");
185- mkdirSync(skillDir, { recursive: true });
186- writeFileSync(
187- join(skillDir, "SKILL.md"),
188- "---\nname: release\ndescription: Ship releases\n---\n\nRelease body",
189- );
190-
191- const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
192- expect(prompt).toContain("<name>release</name>");
193- expect(prompt).toContain("<description>Ship releases</description>");
194- expect(prompt).toContain("<source>global</source>");
195- expect(prompt).not.toContain("Release body");
196- });
197-});
src/agent/system-prompt.ts+39−55
@@ -6,36 +6,6 @@ import {
66 loadLocalContextFile,
77 } from "./context-files.ts";
88
9-const AUTONOMY = `
10-
11-# Autonomy
12-- Begin work immediately using tools. Gather context, implement, and verify — do not ask for permission to start.
13-- Carry changes through to completion. If blocked, summarise what is preventing progress instead of looping.
14-- Verify facts by inspecting files or running commands — never guess unknown state.`;
15-
16-const SAFETY = `
17-
18-# Safety
19-- Never expose, print, or commit secrets, tokens, or keys.
20-- Never invent URLs — only use URLs the user provided or that exist in project files.
21-- Never revert user-authored changes unless explicitly asked. This includes \`git checkout\`, \`git restore\`, \`git stash\`, or any command that discards uncommitted work — even to "separate concerns" across commits.
22-- Before any destructive or irreversible action (deleting data, force-pushing, resetting history), ask one targeted confirmation question — mistakes here are unrecoverable.
23-- If files you are editing change unexpectedly, pause and ask how to proceed.`;
24-
25-const COMMUNICATION = `
26-
27-# Communication
28-- Be concise: short bullets or a brief paragraph. No ceremonial preambles.
29-- For long tasks, send a one-sentence progress update every 3-5 tool calls.
30-- For code changes, state what changed, where, and why. Reference files with line numbers.
31-- Do not paste large file contents unless asked.`;
32-
33-const ERROR_HANDLING = `
34-
35-# Error handling
36-- On tool failure: read the error, adjust your approach, and retry once. If it fails again, explain the blocker to the user.
37-- If you find yourself re-reading or re-editing the same files without progress, stop and summarise what is blocking you.`;
38-
399 export function buildSystemPrompt(
4010 sessionTimeAnchor: string,
4111 cwd: string,
@@ -45,48 +15,53 @@ export function buildSystemPrompt(
4515 const globalContext = loadGlobalContextFile(homeDir ?? homedir());
4616 const localContext = loadLocalContextFile(cwd);
4717 const cwdDisplay = tildePath(cwd);
48- let prompt = `You are mini-coder, a small and fast CLI coding agent.
49-You have access to shell, listSkills, readSkill, connected MCP tools, and optional web tools.
18+ let prompt = `You are using mini-coder, a small and fast CLI coding agent harness.
5019
5120 Current working directory: ${cwdDisplay}
5221 Current date/time: ${sessionTimeAnchor}
5322
54-Guidelines:
55-- You are a capable senior engineer. Proactively gather context and implement — work the problem, not just the symptom. Prefer root-cause fixes over patches.
56-- Inspect code and files primarily through shell commands. Use temp files for large content to avoid filling your context window.
57-- For file edits, invoke \`mc-edit\` via shell. Prefer small, targeted edits over full rewrites so diffs stay reviewable.
58-- Make parallel tool calls when the lookups are independent — this speeds up multi-file investigation.
59-- Before starting work, scan the skills list below. If there is even a small chance a skill applies to your task, load it with \`readSkill\` and follow its instructions before writing code or responding. Skills are mandatory when they match — not optional references.
60-- Keep it simple: DRY, KISS, YAGNI. Avoid unnecessary complexity.
61-- Apply Rob Pike's 5 Rules of Programming:
23+# Guidelines:
24+- Act like am experienced senior engineer. Proactively gather context and implement — work the problem, not just the symptom. Prefer root-cause fixes over patches and avoid hacks and over-engineering.
25+- Inspect code and files primarily through shell commands. Always prefer \`mc-edit\` command via shell tool for file edits.
26+- Always apply DRY, KISS, and YAGNI.
27+- Always apply Rob Pike's 5 Rules of Programming:
6228 1. You can't tell where a program is going to spend its time. Bottlenecks occur in surprising places, so don't try to second guess and put in a speed hack until you've proven that's where the bottleneck is.
6329 2. Measure. Don't tune for speed until you've measured, and even then don't unless one part of the code overwhelms the rest.
6430 3. Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. Until you know that n is frequently going to be big, don't get fancy. (Even if n does get big, use Rule 2 first.)
6531 4. Fancy algorithms are buggier than simple ones, and they're much harder to implement. Use simple algorithms as well as simple data structures.
6632 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.
6733
34+## Autonomy
35+- Begin work immediately using tools. Gather context, implement, and verify — do not ask for permission to start.
36+- Carry changes through to completion. If blocked, summarise what is preventing progress instead of looping
37+
38+## Safety
39+- Never expose, print, or commit secrets, tokens, or keys.
40+- Never invent URLs — only use URLs the user provided or that exist in project files.
41+- Verify facts by inspecting files, running commands, and checking online — never guess unknown state, never make assumptions
42+- Never revert user-authored changes unless explicitly asked. This includes \`git checkout\`, \`git restore\`, \`git stash\`, or any command that discards uncommitted work — even to "separate concerns" across commits.
43+- Before any destructive or irreversible action (deleting data, force-pushing, resetting history), ask one targeted confirmation question — mistakes here are unrecoverable.
44+- If files you are editing change unexpectedly, pause and ask how to proceed.
45+
46+## Communication
47+- Be concise: short bullets or a brief paragraph. No ceremonial preambles.
48+- For code changes, state what changed, where, and why.
49+- Do not paste large file contents unless asked.
50+
51+## Error handling
52+- On tool failure: read the error, adjust your approach, and retry once. If it fails again, explain the blocker to the user.
53+- If you find yourself re-reading or re-editing the same files without progress, stop and summarise what is blocking you.
54+
6855 # File editing with mc-edit
6956 \`mc-edit\` applies one exact-text replacement per invocation. It fails deterministically if the old text is missing or matches more than once.
7057
7158 Usage: mc-edit <path> (--old <text> | --old-file <path>) [--new <text> | --new-file <path>] [--cwd <path>]
7259 - Omit --new / --new-file to delete the matched text.
7360 - To create new files, use shell commands (e.g. \`cat > file.txt << 'EOF'\\n...\\nEOF\`).
74-`;
75-
76- prompt += AUTONOMY;
77- prompt += SAFETY;
78- prompt += COMMUNICATION;
79- prompt += ERROR_HANDLING;
8061
81- if (globalContext || localContext) {
82- prompt += "\n\n# Project context";
83- if (globalContext) {
84- prompt += `\n\n${globalContext}`;
85- }
86- if (localContext) {
87- prompt += `\n\n${localContext}`;
88- }
89- }
62+# Subagents via mc
63+Use the \`mc\` command via the shell tool to instantiate a sub agent with a prompt for their task.
64+`;
9065
9166 const skills = Array.from(loadSkillsIndex(cwd, homeDir).values());
9267 if (skills.length > 0) {
@@ -108,5 +83,14 @@ Usage: mc-edit <path> (--old <text> | --old-file <path>) [--new <text> | --new-f
10883 prompt += "\n</available_skills>";
10984 }
11085
86+ if (globalContext || localContext) {
87+ if (globalContext) {
88+ prompt += `\n\n${globalContext}`;
89+ }
90+ if (localContext) {
91+ prompt += `\n\n${localContext}`;
92+ }
93+ }
94+
11195 return prompt;
11296 }