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.
Files changed (65) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +5 -3
  3. package/extensions/index.ts +33 -1
  4. package/extensions/lib/registry.ts +31 -52
  5. package/extensions/modules/a2a/index.ts +0 -9
  6. package/extensions/modules/a2a/lib/config.ts +15 -1
  7. package/extensions/modules/a2a/test/config.test.ts +27 -0
  8. package/extensions/modules/a2a/test/extension.test.ts +1 -19
  9. package/extensions/modules/advisor/commands/advisor.ts +3 -9
  10. package/extensions/modules/advisor/test/configPanel.test.ts +1 -1
  11. package/extensions/modules/advisor/test/module.test.ts +0 -11
  12. package/extensions/modules/classifier/index.ts +0 -3
  13. package/extensions/modules/composer/test/module.test.ts +0 -22
  14. package/extensions/modules/config/defaultTools.ts +5 -3
  15. package/extensions/modules/config/index.ts +18 -204
  16. package/extensions/modules/config/test/defaultTools.test.ts +3 -4
  17. package/extensions/modules/config/test/panel.test.ts +9 -72
  18. package/extensions/modules/fff/index.ts +19 -8
  19. package/extensions/modules/fff/test/index.test.ts +31 -4
  20. package/extensions/modules/gh/configPanel.ts +9 -6
  21. package/extensions/modules/gh/index.ts +0 -3
  22. package/extensions/modules/gh/test/gh.test.ts +61 -0
  23. package/extensions/modules/jfind/index.ts +10 -4
  24. package/extensions/modules/jfind/lib/cascade.ts +15 -1
  25. package/extensions/modules/jfind/lib/lexical.ts +18 -6
  26. package/extensions/modules/jfind/lib/tree.ts +34 -4
  27. package/extensions/modules/jfind/test/cascade.test.ts +56 -1
  28. package/extensions/modules/munin/index.ts +5 -7
  29. package/extensions/modules/notify/index.ts +0 -3
  30. package/extensions/modules/plan/index.ts +1 -7
  31. package/extensions/modules/repair/configPanel.ts +11 -8
  32. package/extensions/modules/repair/index.ts +58 -33
  33. package/extensions/modules/repair/lib/auto-bg.ts +45 -2
  34. package/extensions/modules/repair/lib/auto-generated.ts +14 -4
  35. package/extensions/modules/repair/lib/read-archive.ts +14 -0
  36. package/extensions/modules/repair/lib/read-sqlite.ts +10 -4
  37. package/extensions/modules/repair/lib/settings.ts +19 -8
  38. package/extensions/modules/repair/test/auto-bg.test.ts +66 -0
  39. package/extensions/modules/repair/test/hardening.test.ts +214 -0
  40. package/extensions/modules/repair/test/settings.test.ts +52 -13
  41. package/extensions/modules/rules/index.ts +0 -4
  42. package/extensions/modules/rules/lib/rules.ts +1 -1
  43. package/extensions/modules/rules/test/module.test.ts +2 -29
  44. package/extensions/modules/serena/index.ts +1 -6
  45. package/extensions/modules/serena/lib/guidance.ts +9 -5
  46. package/extensions/modules/sg/index.ts +0 -5
  47. package/extensions/modules/shells/index.ts +31 -16
  48. package/extensions/modules/shells/lib/sessions.ts +76 -8
  49. package/extensions/modules/shells/test/output.test.ts +130 -0
  50. package/extensions/modules/shells/test/sessions.test.ts +127 -5
  51. package/extensions/modules/steering/lib/think.ts +0 -2
  52. package/extensions/modules/steering/test/think.test.ts +1 -5
  53. package/extensions/modules/todo/index.ts +0 -2
  54. package/extensions/modules/usage/index.ts +19 -9
  55. package/extensions/modules/usage/test/context.test.ts +18 -7
  56. package/extensions/modules/ux/index.ts +1 -5
  57. package/extensions/modules/ux/test/extension.test.ts +0 -5
  58. package/extensions/modules/web/index.ts +0 -9
  59. package/extensions/modules/web/lib/pdf.ts +4 -2
  60. package/extensions/modules/web/test/extension.test.ts +8 -18
  61. package/extensions/modules/web/test/pdf.test.ts +84 -0
  62. package/package.json +1 -1
  63. package/extensions/lib/tools.ts +0 -47
  64. package/extensions/modules/config/test/renderTools.test.ts +0 -71
  65. package/extensions/modules/config/test/tools.test.ts +0 -146
@@ -28,7 +28,6 @@ import {
28
28
  } from "./lib/config.js";
29
29
  import { getUxInstructions } from "./lib/instructions.js";
30
30
  import { row, type PanelGroup } from "../../lib/panel.js";
31
- import { readDisabledTools } from "../../lib/tools.js";
32
31
  import { skillsRoot } from "../../lib/skill-path.js";
33
32
  import type { ModuleConfig } from "../../lib/registry.js";
34
33
 
@@ -293,9 +292,6 @@ export default function uxExtension(pi: ExtensionAPI) {
293
292
  currentMode = normalized;
294
293
  };
295
294
 
296
- // Per-tool kill-switch (ceulen.disabledTools): ux_audit registers inactive
297
- // when listed — /config re-activates it live via setActiveTools.
298
- const disabled = readDisabledTools();
299
295
  const auditTool: AuditToolDefinition = {
300
296
  name: "ux_audit",
301
297
  label: "UX Slop Audit",
@@ -331,7 +327,7 @@ export default function uxExtension(pi: ExtensionAPI) {
331
327
  };
332
328
  },
333
329
  };
334
- pi.registerTool({ ...auditTool, defaultActive: !disabled.has("ux_audit") });
330
+ pi.registerTool(auditTool);
335
331
 
336
332
  pi.registerCommand("ux", {
337
333
  description: `Set mode: ${RUNTIME_MODES.join("|")}, or status`,
@@ -84,11 +84,6 @@ test("extension registers the /ux command and ux_audit tool, and NO status bar",
84
84
  assert.equal(events.has("agent_end"), false, "no agent_end handler (status-bar only)");
85
85
  });
86
86
 
87
- test("ux_audit is registered default-active unless ceulen.disabledTools lists it", () => {
88
- const active = createPiHarness();
89
- assert.equal(active.tools.get("ux_audit").defaultActive, true);
90
- });
91
-
92
87
  test("ux_audit parameter schema has the expected shape", () => {
93
88
  const { tools } = createPiHarness();
94
89
  const params = tools.get("ux_audit").parameters;
@@ -17,7 +17,6 @@ import { resolve as resolvePath } from "node:path";
17
17
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
18
18
  import { Type } from "typebox";
19
19
 
20
- import { readDisabledTools } from "../../lib/tools.js";
21
20
  import { skillsRoot } from "../../lib/skill-path.js";
22
21
 
23
22
  import { formatA11ySummary, runA11yAudit } from "./lib/a11y";
@@ -174,14 +173,6 @@ export default function piWebExtension(pi: ExtensionAPI) {
174
173
  skillPaths: [path.join(skillsRoot(), "web")],
175
174
  }));
176
175
 
177
- // Per-tool kill-switch (ceulen.disabledTools): listed tools register
178
- // inactive — /config re-activates them live via setActiveTools. Wrapping
179
- // registerTool keeps the 11 definitions below untouched (munin pattern).
180
- const disabledTools = readDisabledTools();
181
- const registerTool = pi.registerTool.bind(pi);
182
- pi.registerTool = ((tool: Parameters<typeof pi.registerTool>[0]) =>
183
- registerTool({ ...tool, defaultActive: !disabledTools.has((tool as { name: string }).name) })) as typeof pi.registerTool;
184
-
185
176
  // ── web_search ────────────────────────────────────────────────────────
186
177
  pi.registerTool({
187
178
  name: "web_search",
@@ -9,7 +9,7 @@
9
9
 
10
10
  import { readFileSync } from "node:fs";
11
11
  import path from "node:path";
12
- import { fileURLToPath } from "node:url";
12
+ import { fileURLToPath, pathToFileURL } from "node:url";
13
13
 
14
14
  // ── Shapes ──────────────────────────────────────────────────────────────────
15
15
 
@@ -61,7 +61,9 @@ export async function loadPdfEngine(): Promise<PdfEngine> {
61
61
  const file = path.join(path.dirname(fileURLToPath(import.meta.url)), "../vendor/pdfjs/pdf.min.mjs");
62
62
  // Lazily dynamic-import the vendored module by FILE URL so the bundler /
63
63
  // typechecker never sees a static dependency.
64
- const mod = (await import(`file://${file}`)) as PdfEngine & Record<string, unknown>;
64
+ // pathToFileURL (not string concat): spaces/`#` in the install path must
65
+ // be %-encoded or the lazy pdf.js import resolves a broken URL.
66
+ const mod = (await import(pathToFileURL(file).href)) as PdfEngine & Record<string, unknown>;
65
67
  cachedEngine = mod;
66
68
  return mod;
67
69
  }
@@ -1,6 +1,7 @@
1
- // ceulen integration contract: per-tool kill-switch (ceulen.disabledTools →
2
- // defaultActive:false), skill contributed via resources_discover, and the
3
- // before_agent_start guidance hook gated on active web_* tools.
1
+ // ceulen integration contract: 13 registered tools (9 deferred by the bundle
2
+ // entry's registry tier list — the module itself registers plain), skill
3
+ // contributed via resources_discover, and the before_agent_start guidance
4
+ // hook gated on active web_* tools.
4
5
 
5
6
  import { describe, it, beforeEach, afterEach } from "node:test";
6
7
  import assert from "node:assert/strict";
@@ -16,8 +17,8 @@ const ALL_TOOLS = [
16
17
  "read_pdf",
17
18
  ];
18
19
 
19
- function harness(opts: { disabledTools?: string[]; activeTools?: string[] } = {}) {
20
- const tools: Record<string, { name: string; defaultActive?: boolean }> = {};
20
+ function harness(opts: { activeTools?: string[] } = {}) {
21
+ const tools: Record<string, { name: string }> = {};
21
22
  const handlers: Record<string, Function[]> = {};
22
23
  const discoverResults: { skillPaths: string[] }[] = [];
23
24
  const pi: any = {
@@ -44,9 +45,6 @@ function harness(opts: { disabledTools?: string[]; activeTools?: string[] } = {}
44
45
  // + a settings file carrying the disabled list.
45
46
  const dir = fs.mkdtempSync(path.join(os.tmpdir(), "web-ext-"));
46
47
  process.env.PI_CODING_AGENT_DIR = dir;
47
- if (opts.disabledTools?.length) {
48
- fs.writeFileSync(path.join(dir, "settings.json"), JSON.stringify({ ceulen: { disabledTools: opts.disabledTools } }));
49
- }
50
48
  try {
51
49
  webExtension(pi);
52
50
  } finally {
@@ -77,17 +75,9 @@ describe("web module ceulen contract", () => {
77
75
  assert.deepEqual(Object.keys(tools).sort(), [...ALL_TOOLS].sort());
78
76
  });
79
77
 
80
- it("ceulen.disabledTools → defaultActive:false (inactive at registration)", () => {
81
- const { tools } = harness({ disabledTools: ["web_search", "web_image"] });
82
- assert.equal(tools.web_search!.defaultActive, false);
83
- assert.equal(tools.web_image!.defaultActive, false);
84
- assert.equal(tools.web_extract!.defaultActive, true);
85
- assert.equal(tools.web_status!.defaultActive, true);
86
- });
87
-
88
- it("all tools default-active when the kill-switch list is empty", () => {
78
+ it("registers every tool plain (the bundle entry injects the deferred exposure)", () => {
89
79
  const { tools } = harness();
90
- for (const name of ALL_TOOLS) assert.equal(tools[name]!.defaultActive, true, name);
80
+ for (const name of ALL_TOOLS) assert.ok(tools[name], name);
91
81
  });
92
82
 
93
83
  it("contributes exactly one skill: skills/web (kill-switch gated by factory load)", () => {
@@ -0,0 +1,84 @@
1
+ // read_pdf unit tests — C12 regression: the lazy pdf.js engine import must go
2
+ // through pathToFileURL (an unencoded `file://` string breaks on spaces in
3
+ // the install path). Verified by loading the vendored engine from a vendor
4
+ // directory whose name carries a space — no valid PDF is needed: the import
5
+ // resolving at all is the regression, so getDocument is never asserted.
6
+
7
+ import assert from "node:assert/strict";
8
+ import { cpSync, mkdtempSync, rmSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import path from "node:path";
11
+ import { after, before, describe, it } from "node:test";
12
+ import { itemsToLines, parsePagesParam, resetPdfEngineCache, formatPdfText } from "../lib/pdf.js";
13
+ import type { PdfEngine } from "../lib/pdf.js";
14
+
15
+ const dir = mkdtempSync(path.join(tmpdir(), "ceulen-web-pdf-"));
16
+ after(() => rmSync(dir, { recursive: true, force: true }));
17
+
18
+ // The vendored pdfjs (source of truth for the copy).
19
+ const vendorPdfjs = path.join(
20
+ path.dirname(new URL(import.meta.url).pathname.replace(/^\/([^/]:)/, "$1")),
21
+ "../vendor/pdfjs",
22
+ );
23
+
24
+ describe("pdf engine load (C12)", () => {
25
+ // A spaced vendor dir: `file://` + raw path would split at the space and
26
+ // fail the dynamic import; pathToFileURL percent-encodes it.
27
+ const spacedVendor = path.join(dir, "vendor space", "vendor", "pdfjs");
28
+
29
+ before(() => {
30
+ cpSync(vendorPdfjs, spacedVendor, { recursive: true });
31
+ });
32
+
33
+ it("loadPdfEngine resolves from an install path containing a space", async () => {
34
+ // Point the module at the spaced copy: loadPdfEngine derives the vendor
35
+ // path from import.meta.url, so the test re-imports the lib FROM the
36
+ // spaced directory (mirroring the module layout: lib/ beside vendor/).
37
+ const libCopy = path.join(dir, "vendor space", "lib");
38
+ cpSync(path.join(vendorPdfjs, "..", "..", "lib", "pdf.ts"), path.join(libCopy, "pdf.ts"));
39
+ const mod = await import(`file://${encodeURI(libCopy)}/pdf.ts`).catch(() => null);
40
+ assert.ok(mod, "spaced-path lib import resolves");
41
+ const engine: PdfEngine = await mod!.loadPdfEngine();
42
+ assert.ok(engine, "engine resolved through the encoded file URL");
43
+ assert.equal(typeof engine.getDocument, "function");
44
+ // getDocument is deliberately NOT called here — a real PDF is out of
45
+ // scope for this regression; the import resolving IS the fix proof.
46
+ resetPdfEngineCache();
47
+ });
48
+ });
49
+
50
+ describe("pdf formatting helpers", () => {
51
+ it("itemsToLines groups by baseline y, sorts by x, joins runs", () => {
52
+ const lines = itemsToLines([
53
+ { str: "world", transform: [1, 0, 0, 1, 120, 100] },
54
+ { str: "hello", transform: [1, 0, 0, 1, 10, 100] },
55
+ { str: "next", transform: [1, 0, 0, 1, 10, 90] },
56
+ { str: "", transform: [1, 0, 0, 1, 0, 80] },
57
+ ]);
58
+ assert.deepEqual(lines, ["hello world", "next"]);
59
+ });
60
+
61
+ it("parsePagesParam: default first 5, ranges, cap 10, out-of-range dropped", () => {
62
+ assert.deepEqual(parsePagesParam(undefined, 12), [1, 2, 3, 4, 5]);
63
+ assert.deepEqual(parsePagesParam("3", 12), [3]);
64
+ assert.deepEqual(parsePagesParam("2,4,6-8", 12), [2, 4, 6, 7, 8]);
65
+ assert.deepEqual(parsePagesParam("1-3", 2), [1, 2], "clamped to the document");
66
+ assert.throws(() => parsePagesParam("abc", 5), /invalid pages spec/);
67
+ assert.throws(() => parsePagesParam("40-50", 5), /no valid pages/);
68
+ });
69
+
70
+ it("formatPdfText notes empty pages", () => {
71
+ const out = formatPdfText({
72
+ path: "x.pdf",
73
+ totalPages: 2,
74
+ pages: [
75
+ { page: 1, lines: ["text"], chars: 4 },
76
+ { page: 2, lines: [], chars: 0 },
77
+ ],
78
+ emptyPages: [2],
79
+ });
80
+ assert.match(out, /2 page\(s\), showing 2/);
81
+ assert.match(out, /no extractable text/);
82
+ assert.match(out, /\[empty pages: 2\]/);
83
+ });
84
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ceulen",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Ceulen — the Pi coding agent, fully dressed: one bundle extension carrying the full toolkit with a single /ceulen config command.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,47 +0,0 @@
1
- /**
2
- * Shared per-tool kill-switch: `ceulen.disabledTools: string[]` in the SAME
3
- * settings file `ceulen.disabled` resolves to (see registry.ts). Listed tool
4
- * names register inactive (`defaultActive: false`); the /config panel's
5
- * tool rows write this key and re-activate/deactivate live via
6
- * `pi.setActiveTools`, so a toggle needs no /reload.
7
- */
8
-
9
- import { disabledSource } from "./registry.js";
10
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
11
- import path from "node:path";
12
-
13
- /** Read the `ceulen.disabledTools` list (non-string entries dropped). */
14
- export function readDisabledTools(cwd = process.cwd()): Set<string> {
15
- const { path: file } = disabledSource(cwd);
16
- if (!existsSync(file)) return new Set();
17
- try {
18
- const raw = JSON.parse(readFileSync(file, "utf8"))?.ceulen ?? {};
19
- if (!Array.isArray(raw.disabledTools)) return new Set();
20
- return new Set(raw.disabledTools.filter((n: unknown): n is string => typeof n === "string"));
21
- } catch {
22
- return new Set(); // malformed → defaults (all tools on)
23
- }
24
- }
25
-
26
- /** Write `ceulen.disabledTools` into the SAME file readDisabledTools resolves
27
- * to (never a shadowed layer). Atomic (tmp + rename); a corrupt file refuses
28
- * to clobber. Returns the written path for the caller's disclosure. */
29
- export function writeDisabledTools(list: string[], cwd = process.cwd()): string {
30
- const { path: file } = disabledSource(cwd);
31
- let settings: Record<string, unknown> = {};
32
- if (existsSync(file)) {
33
- try {
34
- settings = JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown>;
35
- } catch {
36
- throw new Error(`${file} is not valid JSON — fix or remove it before saving.`);
37
- }
38
- }
39
- const ceulen = (settings.ceulen ?? {}) as Record<string, unknown>;
40
- ceulen.disabledTools = list.filter((n) => typeof n === "string");
41
- settings.ceulen = ceulen;
42
- mkdirSync(path.dirname(file), { recursive: true });
43
- const tmp = file + ".tmp";
44
- writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
45
- renameSync(tmp, file);
46
- return file;
47
- }
@@ -1,71 +0,0 @@
1
- /**
2
- * Render smoke for the ported modules' /config sections (Serena, FFF search,
3
- * RTK): boxed frame intact, tool rows visible, no width overflow, no icons.
4
- */
5
- import assert from "node:assert/strict";
6
- import { describe, it } from "node:test";
7
- import { ConfigPanelModel, row, type PanelGroup } from "../../../lib/panel.js";
8
- import { MODULES } from "../../../lib/registry.js";
9
- import { moduleEnableRow, moduleToolRows } from "../index.js";
10
-
11
- const theme = {
12
- fg: (text: string) => text,
13
- bold: (text: string) => text,
14
- underline: (text: string) => text,
15
- } as never;
16
-
17
- const plain = (l: string) => l.replace(/\u001b\[[0-9;]*m/g, "");
18
-
19
- function toolGroups(): PanelGroup[] {
20
- const workingTools = new Set(MODULES.flatMap((m) => m.tools ?? [])); // all on
21
- const out: PanelGroup[] = [];
22
- for (const m of MODULES) {
23
- if (!m.tools) continue;
24
- out.push({
25
- key: `ceulen-${m.name}`,
26
- label: m.name === "fff" ? "FFF search" : m.name === "serena" ? "Serena" : m.name,
27
- tab: m.category,
28
- rows: [moduleEnableRow(m.name, m.describe ?? "", new Set([m.name])), ...moduleToolRows(m.tools, workingTools)],
29
- });
30
- }
31
- return out;
32
- }
33
-
34
- describe("render smoke — ported modules' /config sections", () => {
35
- it("renders Enable + per-tool rows inside the boxed frame with zero overflow", () => {
36
- const groups = toolGroups();
37
- assert.equal(groups.length, 20, "serena + fff + jfind + ux + munin + classifier + advisor + subagent + repair + plan + todo + web + rules + a2a + gh + sg + notify + cron + shells + steering·think (rtk has no tools)");
38
- const m = new ConfigPanelModel(groups, theme, "Settings");
39
- m.getHeight = () => 40;
40
- for (const w of [110, 100, 80, 60]) {
41
- for (const line of m.render(w)) {
42
- assert.ok(
43
- (line as unknown as string).length >= 0 && plain(line as unknown as string).length <= w,
44
- `line wider than ${w}`,
45
- );
46
- }
47
- }
48
- });
49
-
50
- it("shows the tool names as row labels and no icon glyphs in the groups", () => {
51
- const groups = toolGroups();
52
- const serena = groups.find((g) => g.label === "Serena")!;
53
- const keys = serena.rows.map((r) => r.key);
54
- assert.ok(keys.includes("ceulen.disabledTools.serena_find_symbol"));
55
- assert.ok(keys.includes("ceulen.disabledTools.serena_onboarding"));
56
- assert.equal(keys.length, 21, "Enable + 20 serena tools");
57
- const fff = groups.find((g) => g.label === "FFF search")!;
58
- assert.ok(fff.rows.some((r) => r.key === "ceulen.disabledTools.ffgrep"));
59
- const ux = groups.find((g) => g.label === "ux")!;
60
- assert.ok(ux.rows.some((r) => r.key === "ceulen.disabledTools.ux_audit"));
61
- const advisor = groups.find((g) => g.label === "advisor")!;
62
- assert.ok(advisor.rows.some((r) => r.key === "ceulen.disabledTools.advisor"));
63
- const subagent = groups.find((g) => g.label === "subagent")!;
64
- assert.ok(subagent.rows.some((r) => r.key === "ceulen.disabledTools.subagent"));
65
- assert.ok(subagent.rows.some((r) => r.key === "ceulen.disabledTools.herdr"));
66
- for (const g of groups) assert.equal(g.icon, undefined, "no icons for the ported modules");
67
- });
68
- });
69
-
70
- // keep `row` import used (types only otherwise)
71
- void row;
@@ -1,146 +0,0 @@
1
- /**
2
- * Per-tool kill-switch (ceulen.disabledTools): registry helpers roundtrip,
3
- * /config row synthesis, live-apply set arithmetic, and the module-side
4
- * defaultActive gating (serena's reg(), fff's registerBoundedTool mapping).
5
- */
6
-
7
- import assert from "node:assert/strict";
8
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
9
- import { tmpdir } from "node:os";
10
- import { join } from "node:path";
11
- import { after, before, describe, it } from "node:test";
12
-
13
- import { MODULES } from "../../../lib/registry.js";
14
- import { readDisabledTools, writeDisabledTools } from "../../../lib/tools.js";
15
- import {
16
- allDeclaredTools,
17
- applyToolSwitches,
18
- moduleToolRow,
19
- moduleToolRows,
20
- nextDisabledTools,
21
- TOOL_SWITCH_PREFIX,
22
- withToolRows,
23
- } from "../index.js";
24
-
25
- let tmpHome = "";
26
-
27
- before(() => {
28
- tmpHome = mkdtempSync(join(tmpdir(), "ceulen-tools-test-"));
29
- process.env.PI_CODING_AGENT_DIR = tmpHome;
30
- });
31
-
32
- after(() => {
33
- delete process.env.PI_CODING_AGENT_DIR;
34
- rmSync(tmpHome, { recursive: true, force: true });
35
- });
36
-
37
- const settingsFile = () => join(tmpHome, "settings.json");
38
- const readSettings = (): Record<string, unknown> =>
39
- JSON.parse(readFileSync(settingsFile(), "utf8")) as Record<string, unknown>;
40
-
41
- describe("disabledTools settings roundtrip", () => {
42
- it("reads empty when no file or no key exists", () => {
43
- writeFileSync(settingsFile(), "{}", "utf8");
44
- assert.deepEqual([...readDisabledTools()], []);
45
- });
46
-
47
- it("roundtrips the list through the ceulen section and drops non-strings", () => {
48
- writeDisabledTools(["serena_onboarding", 42 as unknown as string, "ffgrep"]);
49
- assert.deepEqual([...readDisabledTools()].sort(), ["ffgrep", "serena_onboarding"]);
50
- const ceulen = readSettings().ceulen as Record<string, unknown>;
51
- assert.ok(Array.isArray(ceulen.disabledTools), "lives in the ceulen section");
52
- });
53
-
54
- it("preserves sibling keys and refuses a corrupt file", () => {
55
- writeDisabledTools(["ffgrep"]);
56
- writeFileSync(settingsFile(), "not json", "utf8");
57
- assert.deepEqual([...readDisabledTools()], [], "malformed file → defaults (all on)");
58
- assert.throws(() => writeDisabledTools([]), /not valid JSON/);
59
- writeFileSync(settingsFile(), "{}", "utf8");
60
- });
61
- });
62
-
63
- describe("declared tool inventory", () => {
64
- it("matches the modules' actual tool names", () => {
65
- assert.ok(MODULES.find((m) => m.name === "serena")!.tools!.includes("serena_find_symbol"));
66
- assert.ok(MODULES.find((m) => m.name === "fff")!.tools!.includes("ffgrep"));
67
- assert.equal(MODULES.find((m) => m.name === "rtk")!.tools, undefined, "rtk has no tools");
68
- assert.equal(new Set(allDeclaredTools()).size, allDeclaredTools().length, "no duplicate declarations");
69
- });
70
- });
71
-
72
- describe("tool toggle rows", () => {
73
- it("keys rows under ceulen.disabledTools.<tool> over the working set", () => {
74
- const working = new Set(["ffgrep", "ffind"]);
75
- const r = moduleToolRow("ffgrep", working);
76
- assert.equal(r.key, `${TOOL_SWITCH_PREFIX}ffgrep`);
77
- assert.equal(r.value, true);
78
- r.set(false);
79
- assert.ok(!working.has("ffgrep"));
80
- r.set(true);
81
- assert.ok(working.has("ffgrep"));
82
- });
83
-
84
- it("labels tools by name, with a pretty label/description for the ones that need explaining", () => {
85
- assert.equal(moduleToolRow("ffgrep", new Set()).label, "ffgrep", "bare names stay the identity the model sees");
86
- assert.match(String(moduleToolRow("ffgrep", new Set()).description), /Registers the tool inactive when off/);
87
- const advisor = moduleToolRow("advisor", new Set());
88
- assert.equal(advisor.label, "Consult tool", "advisor's row says what it is, not the feature's name twice");
89
- assert.match(String(advisor.description), /second opinion on demand/);
90
- assert.match(String(advisor.description), /background review is unaffected/);
91
- });
92
-
93
- it("synthesizes rows only for declared tools; withToolRows appends to the first group", () => {
94
- assert.deepEqual(moduleToolRows(undefined, new Set()), []);
95
- const groups = [{ key: "s", label: "Serena", tab: "Tools", rows: [{ key: "ceulen.disabled.serena" }] }] as never;
96
- const out = withToolRows(groups, ["ffgrep", "ffind"], new Set());
97
- assert.deepEqual(
98
- (out[0] as { rows: { key: string }[] }).rows.map((r) => r.key),
99
- ["ceulen.disabled.serena", `${TOOL_SWITCH_PREFIX}ffgrep`, `${TOOL_SWITCH_PREFIX}ffind`],
100
- );
101
- assert.equal(withToolRows(groups, [], new Set()), groups, "no tools → unchanged");
102
- });
103
-
104
- it("nextDisabledTools inverts the working set over every declared tool", () => {
105
- const all = allDeclaredTools();
106
- const working = new Set(all);
107
- working.delete("serena_onboarding");
108
- assert.deepEqual(nextDisabledTools(working), ["serena_onboarding"]);
109
- assert.deepEqual(nextDisabledTools(new Set(all)), []);
110
- });
111
- });
112
-
113
- describe("applyToolSwitches (live set arithmetic)", () => {
114
- function stubPi(active: string[], registered: string[]) {
115
- const calls: string[][] = [];
116
- return {
117
- calls,
118
- pi: {
119
- getActiveTools: () => [...active],
120
- getAllTools: () => registered.map((name) => ({ name })),
121
- setActiveTools: (names: string[]) => calls.push(names),
122
- },
123
- };
124
- }
125
-
126
- it("drops newly disabled, re-adds newly enabled (registered only)", () => {
127
- const { pi, calls } = stubPi(["read", "bash", "ffgrep", "serena_find_symbol"], ["read", "bash", "ffgrep", "serena_find_symbol", "ffind"]);
128
- // before=enabled set {ffgrep, serena_find_symbol, ffind}; after={ffind}:
129
- // ffgrep + serena_find_symbol drop out of the active set; ffind was
130
- // already enabled (in before) so it is NOT re-added — it was never active.
131
- applyToolSwitches(pi, new Set(["ffgrep", "serena_find_symbol", "ffind"]), new Set(["ffind"]));
132
- assert.deepEqual(calls[0]!.sort(), ["bash", "read"]);
133
- });
134
-
135
- it("no-op diff still issues one setActiveTools with the unchanged set", () => {
136
- const { pi, calls } = stubPi(["read", "ffgrep"], ["read", "ffgrep"]);
137
- applyToolSwitches(pi, new Set(["ffgrep"]), new Set(["ffgrep"]));
138
- assert.deepEqual(calls[0]!.sort(), ["ffgrep", "read"]);
139
- });
140
-
141
- it("enabling an unregistered tool is skipped silently", () => {
142
- const { pi, calls } = stubPi(["read"], ["read"]);
143
- applyToolSwitches(pi, new Set(), new Set(["ghost_tool"]));
144
- assert.deepEqual(calls[0]!, ["read"]);
145
- });
146
- });