@@ -22,34 +22,75 @@ describe("loadLocalContextFile", () => {
2222 expect(loadLocalContextFile(tmpDir)).toBeNull();
2323 });
2424
25- it("reads .agents/AGENTS.md (highest priority)", () => {
25+ it("reads all context files when multiple exist", () => {
2626 mkdirSync(join(tmpDir, ".agents"), { recursive: true });
2727 writeFileSync(join(tmpDir, ".agents", "AGENTS.md"), "agents content");
2828 writeFileSync(join(tmpDir, "AGENTS.md"), "root content");
2929 writeFileSync(join(tmpDir, "CLAUDE.md"), "claude content");
30- expect(loadLocalContextFile(tmpDir)).toBe("agents content");
30+ const result = loadLocalContextFile(tmpDir) as string;
31+ expect(result).toContain("agents content");
32+ expect(result).toContain("claude content");
33+ expect(result).toContain("root content");
3134 });
3235
33- it("reads CLAUDE.md when .agents/AGENTS.md absent", () => {
36+ it("reads both CLAUDE.md and AGENTS.md when .agents dir absent", () => {
3437 writeFileSync(join(tmpDir, "CLAUDE.md"), "claude content");
3538 writeFileSync(join(tmpDir, "AGENTS.md"), "root content");
36- expect(loadLocalContextFile(tmpDir)).toBe("claude content");
39+ const result = loadLocalContextFile(tmpDir) as string;
40+ expect(result).toContain("claude content");
41+ expect(result).toContain("root content");
3742 });
3843
3944 it("reads AGENTS.md at root when others absent", () => {
4045 writeFileSync(join(tmpDir, "AGENTS.md"), "root content");
4146 expect(loadLocalContextFile(tmpDir)).toBe("root content");
4247 });
48+
49+ it("reads .claude/CLAUDE.md when .agents files absent", () => {
50+ mkdirSync(join(tmpDir, ".claude"), { recursive: true });
51+ writeFileSync(join(tmpDir, ".claude", "CLAUDE.md"), "claude dir content");
52+ expect(loadLocalContextFile(tmpDir)).toBe("claude dir content");
53+ });
54+
55+ it("reads .agents/CLAUDE.md when .agents/AGENTS.md absent", () => {
56+ mkdirSync(join(tmpDir, ".agents"), { recursive: true });
57+ writeFileSync(
58+ join(tmpDir, ".agents", "CLAUDE.md"),
59+ "agents claude content",
60+ );
61+ expect(loadLocalContextFile(tmpDir)).toBe("agents claude content");
62+ });
63+
64+ it("walks ancestor directories up to git root", () => {
65+ mkdirSync(join(tmpDir, ".git"), { recursive: true });
66+ writeFileSync(join(tmpDir, "AGENTS.md"), "root context");
67+ const nested = join(tmpDir, "packages", "lib", "src");
68+ mkdirSync(nested, { recursive: true });
69+ expect(loadLocalContextFile(nested)).toBe("root context");
70+ });
71+
72+ it("stops walking at git root and does not go beyond", () => {
73+ const gitRoot = join(tmpDir, "repo");
74+ mkdirSync(join(gitRoot, ".git"), { recursive: true });
75+ writeFileSync(join(tmpDir, "AGENTS.md"), "outside git");
76+ const nested = join(gitRoot, "src");
77+ mkdirSync(nested, { recursive: true });
78+ expect(loadLocalContextFile(nested)).toBeNull();
79+ });
80+
81+ it("nearest context file wins over ancestor", () => {
82+ mkdirSync(join(tmpDir, ".git"), { recursive: true });
83+ writeFileSync(join(tmpDir, "AGENTS.md"), "root context");
84+ const nested = join(tmpDir, "packages", "lib");
85+ mkdirSync(nested, { recursive: true });
86+ writeFileSync(join(nested, "AGENTS.md"), "nested context");
87+ expect(loadLocalContextFile(nested)).toBe("nested context");
88+ });
4389 });
4490
4591 describe("buildSystemPrompt", () => {
4692 it("includes base guidelines without context files", () => {
47- const prompt = buildSystemPrompt(
48- "mock-time-anchor",
49- tmpDir,
50- undefined,
51- fakeHome,
52- );
93+ const prompt = buildSystemPrompt("mock-time-anchor", tmpDir, fakeHome);
5394 expect(prompt).toContain("You are mini-coder");
5495 expect(prompt).toContain("Guidelines:");
5596 expect(prompt).not.toContain("# Project context");
@@ -58,7 +99,7 @@ describe("buildSystemPrompt", () => {
5899 expect(prompt).toContain("# Progress communication");
59100 expect(prompt).toContain("# Final response style");
60101 expect(prompt).toContain(
61- "Prefer shell for reading, searching, verification",
102+ "Inspect code and files primarily through shell commands",
62103 );
63104 expect(prompt).toContain("use shell commands that invoke `mc-edit`");
64105 expect(prompt).toContain(
@@ -72,38 +113,20 @@ describe("buildSystemPrompt", () => {
72113
73114 it("includes local context under # Project context", () => {
74115 writeFileSync(join(tmpDir, "AGENTS.md"), "local project info");
75- const prompt = buildSystemPrompt(
76- "mock-time-anchor",
77- tmpDir,
78- undefined,
79- fakeHome,
80- );
116+ const prompt = buildSystemPrompt("mock-time-anchor", tmpDir, fakeHome);
81117 expect(prompt).toContain("# Project context");
82118 expect(prompt).toContain("local project info");
83119 });
84120
85121 it("has exactly one # Project context section when local context present", () => {
86122 writeFileSync(join(tmpDir, "AGENTS.md"), "local info");
87- const prompt = buildSystemPrompt(
88- "mock-time-anchor",
89- tmpDir,
90- undefined,
91- fakeHome,
92- );
123+ const prompt = buildSystemPrompt("mock-time-anchor", tmpDir, fakeHome);
93124 const occurrences = prompt.split("# Project context").length - 1;
94125 expect(occurrences).toBe(1);
95126 });
96127
97- it("appends extraSystemPrompt after context", () => {
98- writeFileSync(join(tmpDir, "AGENTS.md"), "ctx");
99- const prompt = buildSystemPrompt("mock", tmpDir, "custom extra", fakeHome);
100- const extraIdx = prompt.indexOf("custom extra");
101- const contextIdx = prompt.indexOf("ctx");
102- expect(contextIdx).toBeLessThan(extraIdx);
103- });
104-
105128 it("includes cwd and current time in prompt", () => {
106- const prompt = buildSystemPrompt("mock", tmpDir, undefined, fakeHome);
129+ const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
107130 expect(prompt).toContain("Current working directory:");
108131 expect(prompt).toContain("Current date/time:");
109132 });
@@ -111,16 +134,24 @@ describe("buildSystemPrompt", () => {
111134 it("includes global context when ~/.agents/AGENTS.md present", () => {
112135 mkdirSync(join(fakeHome, ".agents"), { recursive: true });
113136 writeFileSync(join(fakeHome, ".agents", "AGENTS.md"), "global info");
114- const prompt = buildSystemPrompt("mock", tmpDir, undefined, fakeHome);
137+ const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
115138 expect(prompt).toContain("# Project context");
116139 expect(prompt).toContain("global info");
117140 });
118141
142+ it("includes global context from ~/.claude/CLAUDE.md", () => {
143+ mkdirSync(join(fakeHome, ".claude"), { recursive: true });
144+ writeFileSync(join(fakeHome, ".claude", "CLAUDE.md"), "claude global info");
145+ const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
146+ expect(prompt).toContain("# Project context");
147+ expect(prompt).toContain("claude global info");
148+ });
149+
119150 it("includes both global and local context in order (global before local)", () => {
120151 mkdirSync(join(fakeHome, ".agents"), { recursive: true });
121152 writeFileSync(join(fakeHome, ".agents", "AGENTS.md"), "global info");
122153 writeFileSync(join(tmpDir, "AGENTS.md"), "local info");
123- const prompt = buildSystemPrompt("mock", tmpDir, undefined, fakeHome);
154+ const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
124155 expect(prompt).toContain("global info");
125156 expect(prompt).toContain("local info");
126157 expect(prompt.indexOf("global info")).toBeLessThan(
@@ -129,7 +160,7 @@ describe("buildSystemPrompt", () => {
129160 });
130161
131162 it("does not include # Project context when neither global nor local context present", () => {
132- const prompt = buildSystemPrompt("mock", tmpDir, undefined, fakeHome);
163+ const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
133164 expect(prompt).not.toContain("# Project context");
134165 });
135166
@@ -141,12 +172,13 @@ describe("buildSystemPrompt", () => {
141172 "---\nname: deploy\ndescription: Deploy safely\n---\n\n# Deploy\nDetailed body",
142173 );
143174
144- const prompt = buildSystemPrompt("mock", tmpDir, undefined, fakeHome);
175+ const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
145176 expect(prompt).toContain("# Available skills (metadata only)");
146177 expect(prompt).toContain(
147178 "Use `listSkills` to browse and `readSkill` to load one SKILL.md on demand.",
148179 );
149- expect(prompt).toContain("- deploy: Deploy safely (local)");
180+ expect(prompt).toContain("- deploy: Deploy safely (local,");
181+ expect(prompt).toContain(".agents/skills/deploy/SKILL.md)");
150182 expect(prompt).not.toContain("Detailed body");
151183 });
152184
@@ -158,8 +190,8 @@ describe("buildSystemPrompt", () => {
158190 "---\nname: release\ndescription: Ship releases\n---\n\nRelease body",
159191 );
160192
161- const prompt = buildSystemPrompt("mock", tmpDir, undefined, fakeHome);
162- expect(prompt).toContain("- release: Ship releases (global)");
193+ const prompt = buildSystemPrompt("mock", tmpDir, fakeHome);
194+ expect(prompt).toContain("- release: Ship releases (global,");
163195 expect(prompt).not.toContain("Release body");
164196 });
165197 });