ceulen 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/README.md +5 -3
- package/extensions/index.ts +33 -1
- package/extensions/lib/registry.ts +31 -52
- package/extensions/modules/a2a/index.ts +0 -9
- package/extensions/modules/a2a/lib/config.ts +15 -1
- package/extensions/modules/a2a/test/config.test.ts +27 -0
- package/extensions/modules/a2a/test/extension.test.ts +1 -19
- package/extensions/modules/advisor/commands/advisor.ts +3 -9
- package/extensions/modules/advisor/test/configPanel.test.ts +1 -1
- package/extensions/modules/advisor/test/module.test.ts +0 -11
- package/extensions/modules/classifier/index.ts +0 -3
- package/extensions/modules/composer/test/module.test.ts +0 -22
- package/extensions/modules/config/defaultTools.ts +5 -3
- package/extensions/modules/config/index.ts +18 -204
- package/extensions/modules/config/test/defaultTools.test.ts +3 -4
- package/extensions/modules/config/test/panel.test.ts +9 -72
- package/extensions/modules/fff/index.ts +19 -8
- package/extensions/modules/fff/test/index.test.ts +31 -4
- package/extensions/modules/gh/configPanel.ts +9 -6
- package/extensions/modules/gh/index.ts +0 -3
- package/extensions/modules/gh/test/gh.test.ts +61 -0
- package/extensions/modules/jfind/index.ts +10 -4
- package/extensions/modules/jfind/lib/cascade.ts +15 -1
- package/extensions/modules/jfind/lib/lexical.ts +18 -6
- package/extensions/modules/jfind/lib/tree.ts +34 -4
- package/extensions/modules/jfind/test/cascade.test.ts +56 -1
- package/extensions/modules/munin/index.ts +5 -7
- package/extensions/modules/notify/index.ts +0 -3
- package/extensions/modules/plan/index.ts +1 -7
- package/extensions/modules/repair/configPanel.ts +11 -8
- package/extensions/modules/repair/index.ts +58 -33
- package/extensions/modules/repair/lib/auto-bg.ts +45 -2
- package/extensions/modules/repair/lib/auto-generated.ts +14 -4
- package/extensions/modules/repair/lib/read-archive.ts +14 -0
- package/extensions/modules/repair/lib/read-sqlite.ts +10 -4
- package/extensions/modules/repair/lib/settings.ts +19 -8
- package/extensions/modules/repair/test/auto-bg.test.ts +66 -0
- package/extensions/modules/repair/test/hardening.test.ts +214 -0
- package/extensions/modules/repair/test/settings.test.ts +52 -13
- package/extensions/modules/rules/index.ts +0 -4
- package/extensions/modules/rules/lib/rules.ts +1 -1
- package/extensions/modules/rules/test/module.test.ts +2 -29
- package/extensions/modules/serena/index.ts +1 -6
- package/extensions/modules/serena/lib/guidance.ts +9 -5
- package/extensions/modules/sg/index.ts +0 -5
- package/extensions/modules/shells/index.ts +31 -16
- package/extensions/modules/shells/lib/sessions.ts +76 -8
- package/extensions/modules/shells/test/output.test.ts +130 -0
- package/extensions/modules/shells/test/sessions.test.ts +127 -5
- package/extensions/modules/steering/lib/think.ts +0 -2
- package/extensions/modules/steering/test/think.test.ts +1 -5
- package/extensions/modules/todo/index.ts +0 -2
- package/extensions/modules/usage/index.ts +19 -9
- package/extensions/modules/usage/test/context.test.ts +18 -7
- package/extensions/modules/ux/index.ts +1 -5
- package/extensions/modules/ux/test/extension.test.ts +0 -5
- package/extensions/modules/web/index.ts +0 -9
- package/extensions/modules/web/lib/pdf.ts +4 -2
- package/extensions/modules/web/test/extension.test.ts +8 -18
- package/extensions/modules/web/test/pdf.test.ts +84 -0
- package/package.json +1 -1
- package/extensions/lib/tools.ts +0 -47
- package/extensions/modules/config/test/renderTools.test.ts +0 -71
- package/extensions/modules/config/test/tools.test.ts +0 -146
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Regression suite for the 2026-10-07 hardening round (reviewer findings):
|
|
2
|
+
// A1 archive member+range reads, A2 guard × archive-member reads, A4 tar
|
|
3
|
+
// option-injection gate, A6 auto-gen guard rel-path correctness, A9 ascii
|
|
4
|
+
// rename-arrow target paths. index.ts helpers are driven through the real
|
|
5
|
+
// module wiring where practical (guard-selector.test.ts precedent).
|
|
6
|
+
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
9
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
10
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { after, before, describe, it } from "node:test";
|
|
14
|
+
import { matchMember, readArchiveMember, archiveKind } from "../lib/read-archive.js";
|
|
15
|
+
import { checkAutoGenerated } from "../lib/auto-generated.js";
|
|
16
|
+
import { applySpecialView } from "../index.js";
|
|
17
|
+
import { parsePatch } from "../lib/patch.js";
|
|
18
|
+
|
|
19
|
+
const dir = mkdtempSync(path.join(tmpdir(), "ceulen-repair-hardening-"));
|
|
20
|
+
after(() => rmSync(dir, { recursive: true, force: true }));
|
|
21
|
+
|
|
22
|
+
// ── A1: member + line ranges ────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
describe("archive member+range (A1)", () => {
|
|
25
|
+
const proj = path.join(dir, "a1");
|
|
26
|
+
const archive = path.join(proj, "pkg.tgz");
|
|
27
|
+
before(() => {
|
|
28
|
+
mkdirSync(proj, { recursive: true });
|
|
29
|
+
writeFileSync(path.join(proj, "src.ts"), "ignored on disk\n");
|
|
30
|
+
execFileSync("tar", ["-czf", archive, "-C", proj, "src.ts"]);
|
|
31
|
+
// Overwrite the MEMBER content so the disk copy can't mask a failure.
|
|
32
|
+
writeFileSync(path.join(dir, "member-body.txt"), "one\ntwo\nthree\nfour\nfive\n");
|
|
33
|
+
execFileSync("tar", ["-czf", archive, "-C", dir, "member-body.txt"]);
|
|
34
|
+
rmSync(path.join(dir, "member-body.txt"));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("pkg.tgz:member:50-80 reads the real member, sliced — not an error", () => {
|
|
38
|
+
const out = applySpecialView("pkg.tgz:member-body.txt:2-3", proj);
|
|
39
|
+
assert.ok(out, "special view triggered");
|
|
40
|
+
assert.match(out!.text, /member-body\.txt/);
|
|
41
|
+
assert.match(out!.text, /two/);
|
|
42
|
+
assert.match(out!.text, /three/);
|
|
43
|
+
assert.doesNotMatch(out!.text, /four|five/);
|
|
44
|
+
assert.doesNotMatch(out!.text, /no member matching/);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("member without a range is unchanged", () => {
|
|
48
|
+
const out = applySpecialView("pkg.tgz:member-body.txt", proj);
|
|
49
|
+
assert.ok(out);
|
|
50
|
+
assert.match(out!.text, /one/);
|
|
51
|
+
assert.match(out!.text, /five/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("a bare-number member does NOT peel as a selector", () => {
|
|
55
|
+
// A member literally named "123" parses as a line selector — it must stay
|
|
56
|
+
// whole for the member lookup (no phantom "" member + sliced error text).
|
|
57
|
+
writeFileSync(path.join(dir, "123"), "numeric member\n");
|
|
58
|
+
execFileSync("tar", ["-czf", path.join(proj, "nums.tgz"), "-C", dir, "123"]);
|
|
59
|
+
const out = applySpecialView(`nums.tgz:123`, proj);
|
|
60
|
+
assert.ok(out);
|
|
61
|
+
assert.match(out!.text, /123/);
|
|
62
|
+
assert.match(out!.text, /numeric member/);
|
|
63
|
+
rmSync(path.join(dir, "123"));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("tail selector :-2 works over the member body", () => {
|
|
67
|
+
const out = applySpecialView("pkg.tgz:member-body.txt:-2", proj);
|
|
68
|
+
assert.ok(out);
|
|
69
|
+
assert.match(out!.text, /four/);
|
|
70
|
+
assert.match(out!.text, /five/);
|
|
71
|
+
assert.doesNotMatch(out!.text, /one\n|two\n|three\n/);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ── A2: guard × archive-member reads ────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
describe("read guard × archive-member reads (A2)", () => {
|
|
78
|
+
it("pkg.tgz:src/x.ts and pkg.tgz:src/x.ts:50-80 pass the guard when the archive exists", async () => {
|
|
79
|
+
const { default: repairModule } = await import("../index.js");
|
|
80
|
+
const proj = await mkdtemp(path.join(tmpdir(), "repair-guard-arch-"));
|
|
81
|
+
const archive = path.join(proj, "pkg.tgz");
|
|
82
|
+
writeFileSync(path.join(proj, "x.ts"), "member\n");
|
|
83
|
+
execFileSync("tar", ["-czf", archive, "-C", proj, "x.ts"]);
|
|
84
|
+
const handlers: Record<string, (event: unknown, ctx: unknown) => unknown> = {};
|
|
85
|
+
const orig = process.env.PI_CODING_AGENT_DIR;
|
|
86
|
+
process.env.PI_CODING_AGENT_DIR = proj;
|
|
87
|
+
try {
|
|
88
|
+
repairModule({
|
|
89
|
+
on: (event: string, handler: (event: unknown, ctx: unknown) => unknown) => { handlers[event] = handler; },
|
|
90
|
+
registerTool: () => {},
|
|
91
|
+
registerCommand: () => {},
|
|
92
|
+
} as never);
|
|
93
|
+
const call = (p: string) =>
|
|
94
|
+
handlers.tool_call!({ toolName: "read", input: { path: p } }, { cwd: proj }) as { block: boolean } | undefined;
|
|
95
|
+
assert.equal(await call("pkg.tgz:x.ts"), undefined, "member read not blocked");
|
|
96
|
+
assert.equal(await call("pkg.tgz:x.ts:1-2"), undefined, "member+range read not blocked");
|
|
97
|
+
assert.equal(await call("pkg.tgz:missing.ts"), undefined, "missing member in an EXISTING archive still passes (the archive view handles it)");
|
|
98
|
+
const blocked = await call("missing.tgz:x.ts") as { block: boolean } | undefined;
|
|
99
|
+
assert.ok(blocked?.block, "a missing .ts-shaped path still blocks");
|
|
100
|
+
} finally {
|
|
101
|
+
if (orig === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
102
|
+
else process.env.PI_CODING_AGENT_DIR = orig;
|
|
103
|
+
await rm(proj, { recursive: true, force: true });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// ── A4: tar option-injection gate ───────────────────────────────────────────
|
|
109
|
+
|
|
110
|
+
describe("archive option-injection gate (A4)", () => {
|
|
111
|
+
it("matchMember still matches normal members", () => {
|
|
112
|
+
assert.deepEqual(matchMember(["a.ts", "b.ts"], "a.ts"), { member: "a.ts", via: "exact" });
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("readArchiveMember refuses a dash-leading member before any spawn", () => {
|
|
116
|
+
// Build an archive with a member named "--checkpoint-action=exec=evil".
|
|
117
|
+
// bsdtar/GNU tar only treats it as an option during EXTRACTION with
|
|
118
|
+
// positional args — exactly what extractMember does — so listing it works.
|
|
119
|
+
const evilDir = path.join(dir, "a4");
|
|
120
|
+
mkdirSync(evilDir, { recursive: true });
|
|
121
|
+
const archive = path.join(evilDir, "evil.tgz");
|
|
122
|
+
const staging = path.join(evilDir, "stage");
|
|
123
|
+
mkdirSync(staging, { recursive: true });
|
|
124
|
+
writeFileSync(path.join(staging, "safe.txt"), "safe\n");
|
|
125
|
+
execFileSync("tar", ["-czf", path.join(evilDir, "plain.tgz"), "-C", staging, "safe.txt"]);
|
|
126
|
+
// Craft the dash member via a tar file listing manipulation: rename inside
|
|
127
|
+
// a ustar header is fiddly — instead create the file and rely on tar -C.
|
|
128
|
+
const evilFile = path.join(staging, "--checkpoint-action=exec=echo pwned");
|
|
129
|
+
writeFileSync(evilFile, "evil\n");
|
|
130
|
+
execFileSync("tar", ["-czf", archive, "-C", staging, "--", "--checkpoint-action=exec=echo pwned", "safe.txt"]);
|
|
131
|
+
const members = ["--checkpoint-action=exec=echo pwned", "safe.txt"];
|
|
132
|
+
assert.equal(archiveKind(archive), "tgz");
|
|
133
|
+
const out = readArchiveMember(archive, "tgz", "--checkpoint-action=exec=echo pwned", "evil.tgz");
|
|
134
|
+
assert.match(out.text, /refusing member/);
|
|
135
|
+
assert.match(out.text, /parsed as tar\/unzip options/);
|
|
136
|
+
void members;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("a dash-leading request through the matcher surfaces the gate", () => {
|
|
140
|
+
const out = readArchiveMember(path.join(dir, "a4", "plain.tgz"), "tgz", "--checkpoint-action=exec=echo pwned", "p.tgz");
|
|
141
|
+
assert.match(out.text, /refusing member|no member matching/);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// ── A6: auto-gen guard rel path ─────────────────────────────────────────────
|
|
146
|
+
|
|
147
|
+
describe("auto-generated rel-path correctness (A6)", () => {
|
|
148
|
+
const cwd = path.join(dir, "a6", "proj");
|
|
149
|
+
before(() => mkdirSync(path.join(cwd, "dist"), { recursive: true }));
|
|
150
|
+
|
|
151
|
+
it("in-cwd absolute paths still match", () => {
|
|
152
|
+
assert.ok(checkAutoGenerated(path.join(cwd, "package-lock.json"), cwd));
|
|
153
|
+
assert.ok(checkAutoGenerated(path.join(cwd, "dist", "x.js"), cwd));
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("an absolute path OUTSIDE cwd matches nothing (no garbage rel)", () => {
|
|
157
|
+
const outside = path.resolve(cwd, "../elsewhere/dist/x.js");
|
|
158
|
+
assert.ok(!outside.startsWith(cwd));
|
|
159
|
+
assert.equal(checkAutoGenerated(outside, cwd), null);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("cwd itself resolves to '.' and matches nothing", () => {
|
|
163
|
+
assert.equal(checkAutoGenerated(cwd, cwd), null);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("relative inputs are matched as given", () => {
|
|
167
|
+
assert.ok(checkAutoGenerated("package-lock.json", cwd));
|
|
168
|
+
assert.equal(checkAutoGenerated("src/app.ts", cwd), null);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
// ── A9: ascii rename arrow in patch target paths ────────────────────────────
|
|
173
|
+
|
|
174
|
+
describe("patch rename arrows (A9)", () => {
|
|
175
|
+
it("parsePatch accepts both arrows (lib contract)", () => {
|
|
176
|
+
assert.equal(parsePatch("*** Update File: a.ts → b.ts\n*** End Patch").ops[0]!.movePath, "b.ts");
|
|
177
|
+
assert.equal(parsePatch("*** Update File: a.ts -> b.ts\n*** End Patch").ops[0]!.movePath, "b.ts");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("the guard/mtime target parser yields the SOURCE path for both arrows", async () => {
|
|
181
|
+
// parsePatchTargetPaths is module-private; drive it through the wrapper:
|
|
182
|
+
// an auto-gen-guarded RENAME with the ascii arrow must be refused because
|
|
183
|
+
// the SOURCE (a lockfile) is the file being touched.
|
|
184
|
+
const { default: repairModule } = await import("../index.js");
|
|
185
|
+
const proj = await mkdtemp(path.join(tmpdir(), "repair-arrow-"));
|
|
186
|
+
const orig = process.env.PI_CODING_AGENT_DIR;
|
|
187
|
+
process.env.PI_CODING_AGENT_DIR = proj;
|
|
188
|
+
const tools: any[] = [];
|
|
189
|
+
try {
|
|
190
|
+
repairModule({
|
|
191
|
+
on: () => {},
|
|
192
|
+
registerTool: (def: any) => tools.push(def),
|
|
193
|
+
registerCommand: () => {},
|
|
194
|
+
} as never);
|
|
195
|
+
const applyPatch = tools.find((t) => t.name === "apply_patch");
|
|
196
|
+
assert.ok(applyPatch, "apply_patch registered");
|
|
197
|
+
for (const arrow of ["→", "->"]) {
|
|
198
|
+
const res = await applyPatch.execute(
|
|
199
|
+
"t1",
|
|
200
|
+
{ patch: `*** Begin Patch\n*** Update File: package-lock.json ${arrow} package-lock2.json\n@@ x\n-y\n+z\n*** End Patch` },
|
|
201
|
+
undefined,
|
|
202
|
+
undefined,
|
|
203
|
+
{ cwd: proj },
|
|
204
|
+
);
|
|
205
|
+
assert.equal(res.isError, true, `ascii arrow: rename of a lockfile refused (${arrow})`);
|
|
206
|
+
assert.match(res.content[0].text, /auto-generated/);
|
|
207
|
+
}
|
|
208
|
+
} finally {
|
|
209
|
+
if (orig === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
210
|
+
else process.env.PI_CODING_AGENT_DIR = orig;
|
|
211
|
+
await rm(proj, { recursive: true, force: true });
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
@@ -7,7 +7,6 @@ import { after, beforeEach, describe, it } from "node:test";
|
|
|
7
7
|
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
9
|
import { join } from "node:path";
|
|
10
|
-
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
11
10
|
import {
|
|
12
11
|
DEFAULT_REPAIR_SETTINGS,
|
|
13
12
|
projectShadow,
|
|
@@ -29,14 +28,17 @@ async function tempDir(): Promise<string> {
|
|
|
29
28
|
return dir;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
/** The settings reader resolves trust via lib/registry isProjectTrusted —
|
|
32
|
+
* <agentDir>/trust.json. Write the trust entry instead of a ctx stub. */
|
|
33
|
+
async function setProjectTrust(trusted: boolean): Promise<void> {
|
|
34
|
+
await writeFile(join(agentDir, "trust.json"), JSON.stringify({ [cwd]: trusted }));
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
beforeEach(async () => {
|
|
37
38
|
agentDir = await tempDir();
|
|
38
39
|
cwd = await tempDir();
|
|
39
40
|
process.env.PI_CODING_AGENT_DIR = agentDir;
|
|
41
|
+
await setProjectTrust(true);
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
after(async () => {
|
|
@@ -56,12 +58,12 @@ async function writeProject(cwdPath: string, repair: unknown): Promise<void> {
|
|
|
56
58
|
|
|
57
59
|
describe("readRepairSettings", () => {
|
|
58
60
|
it("defaults: repair on, guards on, autoBg off @120s", () => {
|
|
59
|
-
assert.deepEqual(readRepairSettings(
|
|
61
|
+
assert.deepEqual(readRepairSettings(cwd), DEFAULT_REPAIR_SETTINGS);
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
it("reads the global agent-dir `repair` section", async () => {
|
|
63
65
|
await writeGlobal({ arguments: false, autoBg: true, autoBgSecs: 30 });
|
|
64
|
-
const s = readRepairSettings(
|
|
66
|
+
const s = readRepairSettings(cwd);
|
|
65
67
|
assert.equal(s.arguments, false);
|
|
66
68
|
assert.equal(s.autoBg, true);
|
|
67
69
|
assert.equal(s.autoBgSecs, 30);
|
|
@@ -71,7 +73,7 @@ describe("readRepairSettings", () => {
|
|
|
71
73
|
it("trusted project file overrides the global layer field-wise", async () => {
|
|
72
74
|
await writeGlobal({ guards: false, autoBgSecs: 30 });
|
|
73
75
|
await writeProject(cwd, { guards: true, autoBgSecs: 45, autoBg: true });
|
|
74
|
-
const s = readRepairSettings(
|
|
76
|
+
const s = readRepairSettings(cwd);
|
|
75
77
|
assert.equal(s.guards, true, "project wins");
|
|
76
78
|
assert.equal(s.autoBgSecs, 45, "project wins");
|
|
77
79
|
assert.equal(s.autoBg, true, "project-only key");
|
|
@@ -80,29 +82,36 @@ describe("readRepairSettings", () => {
|
|
|
80
82
|
it("an UNTRUSTED project file is ignored entirely", async () => {
|
|
81
83
|
await writeGlobal({ guards: false });
|
|
82
84
|
await writeProject(cwd, { guards: true, autoBg: true });
|
|
83
|
-
|
|
85
|
+
await setProjectTrust(false);
|
|
86
|
+
const s = readRepairSettings(cwd);
|
|
84
87
|
assert.equal(s.guards, false, "global value survives an untrusted project");
|
|
85
88
|
assert.equal(s.autoBg, false);
|
|
89
|
+
await setProjectTrust(true); // restore for the later suites
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("no cwd argument → global layer only (ctx-less callers)", async () => {
|
|
93
|
+
await writeProject(cwd, { autoBgSecs: 45 });
|
|
94
|
+
assert.equal(readRepairSettings().autoBgSecs, 120, "project layer skipped without cwd");
|
|
86
95
|
});
|
|
87
96
|
|
|
88
97
|
it("clamps autoBgSecs: fractional floors to ≥1, garbage falls back", async () => {
|
|
89
98
|
await writeGlobal({ autoBgSecs: 0.5 });
|
|
90
|
-
assert.equal(readRepairSettings(
|
|
99
|
+
assert.equal(readRepairSettings(cwd).autoBgSecs, 1, "0.5 → floor 0 → clamped to 1");
|
|
91
100
|
await writeGlobal({ autoBgSecs: -10 });
|
|
92
|
-
assert.equal(readRepairSettings(
|
|
101
|
+
assert.equal(readRepairSettings(cwd).autoBgSecs, 1);
|
|
93
102
|
await writeGlobal({ autoBgSecs: "abc" });
|
|
94
|
-
assert.equal(readRepairSettings(
|
|
103
|
+
assert.equal(readRepairSettings(cwd).autoBgSecs, 120, "non-number → default");
|
|
95
104
|
await writeGlobal({ autoBgSecs: 30.9 });
|
|
96
|
-
assert.equal(readRepairSettings(
|
|
105
|
+
assert.equal(readRepairSettings(cwd).autoBgSecs, 30);
|
|
97
106
|
});
|
|
98
107
|
|
|
99
108
|
it("ignores wrong-typed booleans and a corrupt file", async () => {
|
|
100
109
|
await writeGlobal({ arguments: "yes", guards: 0 });
|
|
101
|
-
let s = readRepairSettings(
|
|
110
|
+
let s = readRepairSettings(cwd);
|
|
102
111
|
assert.equal(s.arguments, true);
|
|
103
112
|
assert.equal(s.guards, true);
|
|
104
113
|
await writeFile(settingsPath(), "{ not json");
|
|
105
|
-
s = readRepairSettings(
|
|
114
|
+
s = readRepairSettings(cwd);
|
|
106
115
|
assert.deepEqual(s, DEFAULT_REPAIR_SETTINGS);
|
|
107
116
|
});
|
|
108
117
|
});
|
|
@@ -133,6 +142,36 @@ describe("projectShadow", () => {
|
|
|
133
142
|
});
|
|
134
143
|
});
|
|
135
144
|
|
|
145
|
+
describe("tool_call honors the trusted-project layer (A5 e2e)", () => {
|
|
146
|
+
it("project autoGenGuard:false blocks a guarded write through the REAL wrapped tool", async () => {
|
|
147
|
+
await writeGlobal({}); // global layer silent
|
|
148
|
+
await writeProject(cwd, { autoGenGuard: false });
|
|
149
|
+
const { wrapToolDefinition } = await import("../index.js");
|
|
150
|
+
const { createWriteToolDefinition } = await import("@earendil-works/pi-coding-agent");
|
|
151
|
+
const wrapped = wrapToolDefinition(createWriteToolDefinition(cwd), createWriteToolDefinition, () => false, () => {});
|
|
152
|
+
const res: any = await wrapped.execute("t1", { path: join(cwd, "package-lock.json"), content: "{}" }, undefined, undefined, { cwd });
|
|
153
|
+
assert.equal(res.isError, undefined, "project layer OFF → guard must NOT fire, write lands");
|
|
154
|
+
assert.match(await readFile(join(cwd, "package-lock.json"), "utf8"), /\{\}/);
|
|
155
|
+
// And with the project layer silent again, the same write is refused.
|
|
156
|
+
await rm(join(cwd, ".pi"), { recursive: true, force: true });
|
|
157
|
+
const res2: any = await wrapped.execute("t2", { path: join(cwd, "package-lock.json"), content: "{}" }, undefined, undefined, { cwd });
|
|
158
|
+
assert.equal(res2.isError, true);
|
|
159
|
+
assert.match(res2.content[0].text, /auto-generated/);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("an UNTRUSTED project file never reaches the guard", async () => {
|
|
163
|
+
await setProjectTrust(false);
|
|
164
|
+
await writeGlobal({});
|
|
165
|
+
await writeProject(cwd, { autoGenGuard: false });
|
|
166
|
+
const { wrapToolDefinition } = await import("../index.js");
|
|
167
|
+
const { createWriteToolDefinition } = await import("@earendil-works/pi-coding-agent");
|
|
168
|
+
const wrapped = wrapToolDefinition(createWriteToolDefinition(cwd), createWriteToolDefinition, () => false, () => {});
|
|
169
|
+
const res: any = await wrapped.execute("t3", { path: join(cwd, "yarn.lock"), content: "{}" }, undefined, undefined, { cwd });
|
|
170
|
+
assert.equal(res.isError, true);
|
|
171
|
+
assert.match(res.content[0].text, /auto-generated/, "untrusted project layer ignored — global/default governs");
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
136
175
|
describe("buildRepairGroups (panel contract)", () => {
|
|
137
176
|
it("renders the six repair.* rows on the Tools tab with the documented defaults", () => {
|
|
138
177
|
const groups = buildRepairGroups({ ...DEFAULT_REPAIR_SETTINGS });
|
|
@@ -22,7 +22,6 @@ import type {
|
|
|
22
22
|
ExtensionContext,
|
|
23
23
|
} from "@earendil-works/pi-coding-agent";
|
|
24
24
|
import { Type } from "typebox";
|
|
25
|
-
import { readDisabledTools } from "../../lib/tools";
|
|
26
25
|
import { clearRuleCache, loadRules, type RuleModel } from "./lib/rules";
|
|
27
26
|
|
|
28
27
|
/** Cap on a single rule body returned by rule_get (chars). */
|
|
@@ -59,8 +58,6 @@ function statusLines(model: RuleModel, cwd: string): string {
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
export default function rulesExtension(pi: ExtensionAPI): void {
|
|
62
|
-
const disabledTools = readDisabledTools();
|
|
63
|
-
|
|
64
61
|
pi.on("before_agent_start", async (event, ctx): Promise<BeforeAgentStartEventResult | undefined> => {
|
|
65
62
|
let model: RuleModel;
|
|
66
63
|
try {
|
|
@@ -81,7 +78,6 @@ export default function rulesExtension(pi: ExtensionAPI): void {
|
|
|
81
78
|
parameters: Type.Object({
|
|
82
79
|
name: Type.String({ description: "Rule name (the `## <name>` heading) from the rulebook listing." }),
|
|
83
80
|
}),
|
|
84
|
-
defaultActive: !disabledTools.has("rule_get"),
|
|
85
81
|
async execute(_id: string, params: { name: string }, _signal, _onUpdate, ctx) {
|
|
86
82
|
const model = loadRules(ctx?.cwd ?? process.cwd(), undefined, projectTrusted(ctx));
|
|
87
83
|
const wanted = (params.name ?? "").trim();
|
|
@@ -354,7 +354,7 @@ export function composeRulesBlock(model: RuleModel, cwd: string): string | undef
|
|
|
354
354
|
}
|
|
355
355
|
if (model.rulebook.length > 0) {
|
|
356
356
|
const lines = model.rulebook.map((rule) => `- ${rule.name}: ${rule.description}`).join("\n");
|
|
357
|
-
sections.push(`Rulebook — read the full body with rule_get("<name>") before applying one:\n${lines}`);
|
|
357
|
+
sections.push(`Rulebook — read the full body with rule_get("<name>") before applying one (rule_get is deferred: if not yet declared, load it with one tool_search call for "rule_get"):\n${lines}`);
|
|
358
358
|
}
|
|
359
359
|
return `<user-rules>\n${sections.join("\n\n")}\n</user-rules>`;
|
|
360
360
|
}
|
|
@@ -15,7 +15,6 @@ import os from "node:os";
|
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
|
|
17
17
|
import rulesExtension from "../index.ts";
|
|
18
|
-
import { readDisabledTools } from "../../../lib/tools";
|
|
19
18
|
|
|
20
19
|
const temps: string[] = [];
|
|
21
20
|
const envBackup = process.env.PI_CODING_AGENT_DIR;
|
|
@@ -27,7 +26,6 @@ after(() => {
|
|
|
27
26
|
for (const dir of temps) rmSync(dir, { recursive: true, force: true });
|
|
28
27
|
if (envBackup !== undefined) process.env.PI_CODING_AGENT_DIR = envBackup;
|
|
29
28
|
else delete process.env.PI_CODING_AGENT_DIR;
|
|
30
|
-
clearDisabled();
|
|
31
29
|
});
|
|
32
30
|
|
|
33
31
|
function tmp(prefix: string): string {
|
|
@@ -77,16 +75,6 @@ function context(cwd: string, notes: Harness["notes"] = []): any {
|
|
|
77
75
|
return { cwd, ui: { notify: (message: string, level?: string) => notes.push({ message, level }) }, isProjectTrusted: () => true };
|
|
78
76
|
}
|
|
79
77
|
|
|
80
|
-
/** Point the kill-switch at the temp agent dir (readDisabledTools has no cwd arg). */
|
|
81
|
-
function disableTools(names: string[]): void {
|
|
82
|
-
process.env.PI_CODING_AGENT_DIR = agentDir;
|
|
83
|
-
writeFileSync(path.join(agentDir, "settings.json"), JSON.stringify({ ceulen: { disabledTools: names } }), "utf8");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function clearDisabled(): void {
|
|
87
|
-
rmSync(path.join(agentDir, "settings.json"), { force: true });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
78
|
async function startBlock(cwd: string, base = "BASE"): Promise<string | undefined> {
|
|
91
79
|
const { events } = harness();
|
|
92
80
|
const result = await events.get("before_agent_start")!({ systemPrompt: base, prompt: "p" }, context(cwd));
|
|
@@ -112,21 +100,14 @@ describe("rules module — before_agent_start", () => {
|
|
|
112
100
|
|
|
113
101
|
it("does not gate on the tool set (the fff pattern minus the active-tool check)", async () => {
|
|
114
102
|
const cwd = workspace({ ".pi/RULES.md": "## sticky\nS body\n" });
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
assert.equal(readDisabledTools().has("rule_get"), true);
|
|
118
|
-
assert.ok((await startBlock(cwd))!.includes("S body"));
|
|
119
|
-
} finally {
|
|
120
|
-
clearDisabled();
|
|
121
|
-
}
|
|
103
|
+
assert.ok((await startBlock(cwd))!.includes("S body"));
|
|
122
104
|
});
|
|
123
105
|
});
|
|
124
106
|
|
|
125
107
|
describe("rules module — rule_get", () => {
|
|
126
|
-
it("registers the canonical tool name
|
|
108
|
+
it("registers the canonical tool name", () => {
|
|
127
109
|
const { tools } = harness();
|
|
128
110
|
assert.deepEqual([...tools.keys()], ["rule_get"]);
|
|
129
|
-
assert.equal(tools.get("rule_get").defaultActive, true);
|
|
130
111
|
});
|
|
131
112
|
|
|
132
113
|
it("returns the body (imports expanded) for a found rule and lists names when not found", async () => {
|
|
@@ -160,14 +141,6 @@ describe("rules module — rule_get", () => {
|
|
|
160
141
|
assert.ok(result.content[0].text.includes("no RULES.md exists in this workspace"));
|
|
161
142
|
});
|
|
162
143
|
|
|
163
|
-
it("registers inactive when listed in ceulen.disabledTools", () => {
|
|
164
|
-
disableTools(["rule_get"]);
|
|
165
|
-
try {
|
|
166
|
-
assert.equal(harness().tools.get("rule_get").defaultActive, false);
|
|
167
|
-
} finally {
|
|
168
|
-
clearDisabled();
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
144
|
});
|
|
172
145
|
|
|
173
146
|
describe("rules module — /rules command", () => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { readDisabledTools } from "../../lib/tools";
|
|
3
2
|
import { Type, type TSchema } from "typebox";
|
|
4
3
|
import { withFileMutationQueue } from "@earendil-works/pi-coding-agent";
|
|
5
4
|
import path from "node:path";
|
|
@@ -200,12 +199,8 @@ export function shouldRetryAfterTimeout(
|
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
export default function serenaToolsExtension(pi: ExtensionAPI) {
|
|
203
|
-
// Per-tool kill-switch: tools listed in ceulen.disabledTools register
|
|
204
|
-
// inactive (defaultActive: false) — /config re-activates them live via
|
|
205
|
-
// setActiveTools; the persisted list re-applies on every load.
|
|
206
|
-
const disabled = readDisabledTools();
|
|
207
202
|
const reg = <P extends TSchema, D = unknown>(tool: ToolDefinition<P, D>) =>
|
|
208
|
-
pi.registerTool(
|
|
203
|
+
pi.registerTool(tool);
|
|
209
204
|
|
|
210
205
|
const getWorker = () => {
|
|
211
206
|
if (!worker) {
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { commandLooksLikeSemanticCodeSearch, pathLooksLikeCode, pathLooksNonSemantic } from "./detect";
|
|
2
2
|
|
|
3
|
-
export const SERENA_FIRST_GUIDANCE = "Serena-first code navigation: before reading whole code files for code navigation, call Serena first. For named source files, start with serena_get_symbols_overview(relative_path=...). For named functions/classes/methods/variables, use serena_find_symbol. Use serena_find_referencing_symbols before behavior changes or renames, and serena_find_declaration / serena_find_implementations for definitions, interfaces, and implementations. Use read/grep/find for docs, configs, non-code files, exact text checks, or narrow code ranges after Serena identifies the target.";
|
|
3
|
+
export const SERENA_FIRST_GUIDANCE = "Serena-first code navigation: before reading whole code files for code navigation, call Serena first (serena tools are deferred — if not yet declared, load them with one tool_search call for \"serena\"). For named source files, start with serena_get_symbols_overview(relative_path=...). For named functions/classes/methods/variables, use serena_find_symbol. Use serena_find_referencing_symbols before behavior changes or renames, and serena_find_declaration / serena_find_implementations for definitions, interfaces, and implementations. Use read/grep/find for docs, configs, non-code files, exact text checks, or narrow code ranges after Serena identifies the target.";
|
|
4
4
|
|
|
5
5
|
export const SERENA_MISS_GUIDANCE = "Use serena_get_symbols_overview for source-file outlines or serena_find_symbol for named symbols before reading/searching code. Use read after Serena identifies the relevant region, or for docs/config/non-code files.";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Is Serena's tool surface actually
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Is Serena's tool surface actually usable in this session? Serena tools
|
|
9
|
+
* register DEFERRED (registry deferredTools) — they load on the first
|
|
10
|
+
* tool_search call and stay declared for the rest of the session. Active
|
|
11
|
+
* `serena_find_symbol` means loaded; active `tool_search` means one search
|
|
12
|
+
* away. Exported pure predicate so the hook and its tests share one
|
|
13
|
+
* definition.
|
|
11
14
|
*/
|
|
12
15
|
export function isSerenaActive(activeTools: readonly string[] | undefined): boolean {
|
|
13
|
-
|
|
16
|
+
if (!Array.isArray(activeTools)) return false;
|
|
17
|
+
return activeTools.includes("serena_find_symbol") || activeTools.includes("tool_search");
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
const BLOCKED_TOOLS = new Set(["read", "bash"]);
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import { Type } from "typebox";
|
|
8
|
-
import { readDisabledTools } from "../../lib/tools.js";
|
|
9
8
|
import { realSg, sgAvailable, type SgRunner } from "./lib/sg-cli.js";
|
|
10
9
|
import { buildRunArgs, formatMatches, mergeMatches, parseSearch } from "./lib/ops.js";
|
|
11
10
|
|
|
@@ -22,12 +21,9 @@ export default function sgModule(pi: ExtensionAPI): void {
|
|
|
22
21
|
// (install + /reload activates).
|
|
23
22
|
if (!sgAvailable()) return;
|
|
24
23
|
|
|
25
|
-
const disabled = readDisabledTools();
|
|
26
|
-
|
|
27
24
|
pi.registerTool({
|
|
28
25
|
name: "ast_grep",
|
|
29
26
|
label: "AST Grep",
|
|
30
|
-
defaultActive: !disabled.has("ast_grep"),
|
|
31
27
|
description:
|
|
32
28
|
"Structural code search via the ast-grep CLI: match AST patterns with meta-variables ($VAR = one node, $$$ALL = many) instead of regex — `$FUNC($$$ARGS)` finds every call. " +
|
|
33
29
|
"Patterns are snippets of real code in the target language. Use for syntax-aware searches regex mangles (calls, imports, JSX). Returns path:line:col + matched text.",
|
|
@@ -70,7 +66,6 @@ export default function sgModule(pi: ExtensionAPI): void {
|
|
|
70
66
|
pi.registerTool({
|
|
71
67
|
name: "ast_edit",
|
|
72
68
|
label: "AST Edit",
|
|
73
|
-
defaultActive: !disabled.has("ast_edit"),
|
|
74
69
|
description:
|
|
75
70
|
"Structural code rewrite via the ast-grep CLI: one pattern → rewrite pair applied across files (the rewrite reuses $VAR / $$$ALL meta-variables). " +
|
|
76
71
|
"DRY-RUN BY DEFAULT: returns the per-file diff without touching disk. Pass write:true to apply (files are rewritten in place; NOT atomic across files). " +
|
|
@@ -8,7 +8,6 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
|
|
|
8
8
|
import { spawn } from "node:child_process";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { Type } from "typebox";
|
|
11
|
-
import { readDisabledTools } from "../../lib/tools.js";
|
|
12
11
|
import {
|
|
13
12
|
createSession,
|
|
14
13
|
killSession,
|
|
@@ -66,20 +65,30 @@ function renderOutput(session: ShellSession, params: Record<string, unknown>): s
|
|
|
66
65
|
const since = params.since === "last" ? "last" : "start";
|
|
67
66
|
const out: string[] = [];
|
|
68
67
|
let truncated = false;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
// Each stream slices by ITS OWN cursor — one shared offset went stale on
|
|
69
|
+
// the shorter stream (stderr duplicated when stdout was longer, invisible
|
|
70
|
+
// when shorter). Cursors are lifetime line counts, not array indices:
|
|
71
|
+
// a ring-cap trip SHRINKS the visible array, which strands an index
|
|
72
|
+
// cursor above it forever (permanent "no new output yet" blackout).
|
|
73
|
+
const cursorOf = { stdout: "lastStdoutOffset", stderr: "lastStderrOffset" } as const;
|
|
74
|
+
for (const stream of ["stdout", "stderr"] as const) {
|
|
75
|
+
const buf = session[stream];
|
|
76
|
+
if (since === "last") {
|
|
77
|
+
const fresh = buf.linesSince(session[cursorOf[stream]]);
|
|
78
|
+
if (fresh.length === 0) continue;
|
|
79
|
+
const shown = fresh.slice(-max);
|
|
80
|
+
if (fresh.length > shown.length) truncated = true;
|
|
81
|
+
out.push(`── ${stream} (new) ──`, ...shown);
|
|
82
|
+
// Advance ONLY on since:"last" reads, and only forward.
|
|
83
|
+
session[cursorOf[stream]] = Math.max(session[cursorOf[stream]], buf.lifetimeLines());
|
|
84
|
+
} else {
|
|
85
|
+
const all = buf.lines();
|
|
86
|
+
if (all.length === 0) continue;
|
|
87
|
+
const shown = all.slice(-max);
|
|
88
|
+
if (all.length > shown.length) truncated = true;
|
|
89
|
+
out.push(`── ${stream} ──`, ...shown);
|
|
90
|
+
}
|
|
80
91
|
}
|
|
81
|
-
// Advance the cursor ONLY on since:"last" reads.
|
|
82
|
-
if (since === "last") session.lastOutputOffset = Math.max(session.stdout.lines().length, session.lastOutputOffset);
|
|
83
92
|
if (out.length === 0) return `${session.id}: no ${since === "last" ? "new " : ""}output yet`;
|
|
84
93
|
const totalLines = session.stdout.lines().length + session.stderr.lines().length;
|
|
85
94
|
out.push(`── total ${totalLines} line(s)${truncated || session.stdout.isTruncated() || session.stderr.isTruncated() ? ", buffer truncated" : ""} ──`);
|
|
@@ -88,10 +97,11 @@ function renderOutput(session: ShellSession, params: Record<string, unknown>): s
|
|
|
88
97
|
|
|
89
98
|
export default function shellsModule(pi: ExtensionAPI): void {
|
|
90
99
|
const store = new SessionStore();
|
|
100
|
+
(shellsModule as unknown as { __storeForTests?: SessionStore }).__storeForTests = store;
|
|
91
101
|
|
|
92
102
|
pi.on("session_start", () => {
|
|
93
103
|
// A fresh session can't reach children from a replaced one.
|
|
94
|
-
store.
|
|
104
|
+
store.clear(); // killAll already ran on shutdown; plain clear
|
|
95
105
|
});
|
|
96
106
|
|
|
97
107
|
pi.on("session_shutdown", () => {
|
|
@@ -103,7 +113,6 @@ export default function shellsModule(pi: ExtensionAPI): void {
|
|
|
103
113
|
pi.registerTool({
|
|
104
114
|
name: "shell",
|
|
105
115
|
label: "Shell",
|
|
106
|
-
defaultActive: !readDisabledTools().has("shell"),
|
|
107
116
|
description: [
|
|
108
117
|
"Run a shell command as a PERSISTENT background session and interact with it across tool calls (dev servers, watchers, long builds). Actions:",
|
|
109
118
|
'- start: {command, name?, cwd?} — spawn in its own process group; returns an id ("s1"…).',
|
|
@@ -208,3 +217,9 @@ export default function shellsModule(pi: ExtensionAPI): void {
|
|
|
208
217
|
},
|
|
209
218
|
});
|
|
210
219
|
}
|
|
220
|
+
|
|
221
|
+
// ponytail: test seam — a constructor-injected store would be the upgrade
|
|
222
|
+
// path if non-test code ever needs it; one module-scope slot, last load wins.
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
224
|
+
const shellsModuleAny = shellsModule as unknown as { __storeForTests?: SessionStore };
|
|
225
|
+
export const getStoreForTests = (): SessionStore | undefined => shellsModuleAny.__storeForTests;
|