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
@@ -26,8 +26,11 @@ import { agentDirs } from "../../lib/registry.js";
26
26
  export const STOCK_DEFAULT_TOOLS = ["read", "bash", "edit", "write"] as const;
27
27
 
28
28
  /** Every built-in tool the panel offers, in render order. Blurbs from pi's
29
- * CLI docs. codemode/tool_search are built-in EXTENSION tools, off by
30
- * default; MCP activates codemode automatically when a server needs it. */
29
+ * CLI docs. codemode is a built-in EXTENSION tool, off by default; MCP
30
+ * activates it automatically when a server needs it. tool_search is NOT
31
+ * offered: ceulen's deferred tool tier depends on it, and the bundle entry
32
+ * re-activates it every session_start — a toggle here would be silently
33
+ * overridden (ceulen owns the switch, MCP-activates-codemode precedent). */
31
34
  const BUILTIN_TOOLS: readonly { name: string; blurb: string }[] = [
32
35
  { name: "read", blurb: "Read text files and supported images." },
33
36
  { name: "bash", blurb: "Run shell commands." },
@@ -38,7 +41,6 @@ const BUILTIN_TOOLS: readonly { name: string; blurb: string }[] = [
38
41
  { name: "find", blurb: "Find paths using glob patterns." },
39
42
  { name: "ls", blurb: "List directory contents." },
40
43
  { name: "codemode", blurb: "Run JavaScript that calls the other tools. MCP turns it on when needed." },
41
- { name: "tool_search", blurb: "Search tools not declared to the model and declare the matches." },
42
44
  ];
43
45
 
44
46
  export const DEFAULT_TOOLS_PREFIX = "pi.defaultTools.";
@@ -6,13 +6,14 @@
6
6
  * and the pi-package (plugins) groups — all categorized under OMP's settings
7
7
  * taxonomy (Appearance, Model, Interaction, Context, Tasks, Providers, …).
8
8
  *
9
- * The bundle-level kill-switch is no longer a standalone "Modules" tab: each
10
- * module's Enable row is prepended to its own functional section (Router →
11
- * Providers, Ponytail → Tasks, …) so a feature is turned on/off where it is
12
- * configured. Save routes edited row keys to their owner: `ceulen.disabled.*`
13
- * → the kill-switch file, `pi.*` → SettingsManager.flush(), `ceulen.plugins.*`
14
- * → the packages file, `<module>.<key>` → the module's `save()` — each in its
15
- * own try/catch, so one failure never blocks the others.
9
+ * Modules are always loaded; the `ceulen.disabled` settings key is a
10
+ * settings.json-only escape hatch read by the bundle entry, never edited here.
11
+ * Cold tools register `exposure: "deferred"` (registry `deferredTools`), so
12
+ * there is no per-module Enable row and no per-tool toggle — /config carries
13
+ * only functional settings. Save routes edited row keys to their owner:
14
+ * `pi.*` → SettingsManager.flush(), `ceulen.plugins.*` → the packages file,
15
+ * `<module>.<key>` → the module's `save()` — each in its own try/catch, so
16
+ * one failure never blocks the others.
16
17
  *
17
18
  * Naming note: `/settings` is a Pi builtin — an extension command with that
18
19
  * name is skipped in autocomplete and renamed (`/settings:1`), never an
@@ -22,105 +23,10 @@
22
23
  import { SettingsManager, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
23
24
  import { builtinToolRows, DEFAULT_TOOLS_PREFIX, nextDefaultTools, startupToolSet, writeDefaultTools } from "./defaultTools.js";
24
25
  import { openConfigPanel, row, type PanelGroup } from "../../lib/panel.js";
25
- import { agentDirs, isCore, MODULES, disabledSource, readDisabled, writeDisabled, type ModuleConfig, type ModuleLoadDeps } from "../../lib/registry.js";
26
- import { readDisabledTools, writeDisabledTools } from "../../lib/tools.js";
26
+ import { agentDirs, MODULES, type ModuleConfig, type ModuleLoadDeps } from "../../lib/registry.js";
27
27
  import { buildPiSettingsGroups, isPiKey, PI_TAB_ORDER, type PiMenuLookup } from "./piSettings.js";
28
28
  import { buildPluginsGroups, isPluginsKey, openPluginsWorking, savePlugins } from "./plugins.js";
29
29
 
30
- export const KILL_SWITCH_PREFIX = "ceulen.disabled.";
31
- export const TOOL_SWITCH_PREFIX = "ceulen.disabledTools.";
32
-
33
- /** Display overrides for tool rows whose bare name would not explain itself
34
- * (the row IS the tool's kill-switch, so it must say what on/off means).
35
- * Tools without an entry keep the bare tool name — the identity the model
36
- * sees — with the generic registration description. */
37
- const TOOL_PRETTY: Record<string, { label: string; description: string }> = {
38
- advisor: {
39
- label: "Consult tool",
40
- description: "Registers the advisor tool so the agent can ask for a second opinion on demand. Off = not registered; the background review is unaffected.",
41
- },
42
- };
43
-
44
- /** Read the current kill-switch state as a Set of ENABLED module names. */
45
- function enabledModules(): Set<string> {
46
- const disabled = new Set(readDisabled());
47
- // Core modules are always enabled, whatever a stale settings file says.
48
- return new Set(MODULES.map((m) => m.name).filter((n) => !disabled.has(n)));
49
- }
50
-
51
- /** The module's Enable kill-switch row over a live working Set (toggles
52
- * mutate it; save diffs it against the persisted state). Lives at the top of
53
- * the module's own section — the feature is turned on where it is
54
- * configured. When the effective settings file is the project's, the
55
- * description discloses where writes land. */
56
- export function moduleEnableRow(name: string, describe: string, working: Set<string>): ReturnType<typeof row> {
57
- const where = disabledSource().isProject ? "this project's .pi/settings.json" : "the global settings.json";
58
- return row(`${KILL_SWITCH_PREFIX}${name}`, "Enabled", "toggle", working.has(name), (v) => {
59
- if (v) working.add(name);
60
- else working.delete(name);
61
- }, {
62
- description: `${describe} Writes ${where}.`,
63
- // Sole warning rows: the kill-switch does NOT apply on save — the ⚠
64
- // marks "needs /reload" against the instant-apply rest.
65
- warning: "Takes effect after /reload (or restart).",
66
- defaultValue: true,
67
- });
68
- }
69
-
70
- /** Prepend a module's Enable row to the FIRST group of its contribution. */
71
- export function withEnableRow(groups: PanelGroup[], name: string, describe: string, working: Set<string>): PanelGroup[] {
72
- // Core modules are always on — no kill-switch row (nothing to toggle).
73
- if (isCore(name)) return groups;
74
- const [first, ...rest] = groups;
75
- if (!first) return groups;
76
- return [{ ...first, rows: [moduleEnableRow(name, describe, working), ...first.rows] }, ...rest];
77
- }
78
-
79
- /** The kill-switch list that results from toggling `working` (enabled set).
80
- * Pure — exported for tests. Core modules are excluded (never disableable). */
81
- export function nextDisabled(working: Set<string>): string[] {
82
- return MODULES.filter((m) => !m.core).map((m) => m.name).filter((n) => !working.has(n));
83
- }
84
-
85
- /** One per-tool toggle row (key `ceulen.disabledTools.<tool>` over the given
86
- * working set of ENABLED tool names). Applied live on save — no /reload. */
87
- export function moduleToolRow(tool: string, working: Set<string>): ReturnType<typeof row> {
88
- const pretty = TOOL_PRETTY[tool];
89
- return row(`${TOOL_SWITCH_PREFIX}${tool}`, pretty?.label ?? tool, "toggle", working.has(tool), (v) => {
90
- if (v) working.add(tool);
91
- else working.delete(tool);
92
- }, {
93
- description: pretty?.description ?? "Registers the tool inactive when off — applied to this session immediately on save.",
94
- defaultValue: true,
95
- });
96
- }
97
-
98
- /** Toggle rows for every tool a module declares. Exported for tests. */
99
- export function moduleToolRows(tools: string[] | undefined, working: Set<string>): ReturnType<typeof row>[] {
100
- return (tools ?? []).map((t) => moduleToolRow(t, working));
101
- }
102
-
103
- /** Append the module's tool rows after its (first-section) rows. A no-op for
104
- * modules without a `tools` list. Exported for tests. */
105
- export function withToolRows(groups: PanelGroup[], tools: string[] | undefined, working: Set<string>): PanelGroup[] {
106
- const rows = moduleToolRows(tools, working);
107
- if (rows.length === 0) return groups;
108
- const [first, ...rest] = groups;
109
- if (!first) return groups;
110
- return [{ ...first, rows: [...first.rows, ...rows] }, ...rest];
111
- }
112
-
113
- /** The disabled-tools list that results from toggling `working` (enabled set)
114
- * across every ceulen-declared tool. Pure — exported for tests. */
115
- export function nextDisabledTools(working: Set<string>): string[] {
116
- return MODULES.flatMap((m) => m.tools ?? []).filter((n) => !working.has(n));
117
- }
118
-
119
- /** Every tool name ceulen modules declare. */
120
- export function allDeclaredTools(): string[] {
121
- return MODULES.flatMap((m) => m.tools ?? []);
122
- }
123
-
124
30
  /** Apply the disabled-tools list to the LIVE session: drop newly disabled
125
31
  * tools, re-activate newly enabled ones (registered tools only — unknown
126
32
  * names are ignored by setActiveTools). Exported for tests. */
@@ -190,12 +96,7 @@ export async function saveContributions(
190
96
  }
191
97
 
192
98
  function summaryLines(groups: PanelGroup[]): string[] {
193
- const enabled = enabledModules();
194
- const lines = [
195
- "── Ceulen config ──",
196
- `Modules: ${MODULES.map((m) => `${m.name}${enabled.has(m.name) ? "" : " (off)"}`).join(", ")}`,
197
- "",
198
- ];
99
+ const lines = ["── Ceulen config ──"];
199
100
  // Generic row dump per tab/section (label: value) — stays in lockstep with
200
101
  // the panel's assembly, pi settings and plugins included.
201
102
  let lastTab = "";
@@ -224,7 +125,7 @@ function summaryLines(groups: PanelGroup[]): string[] {
224
125
  " /ceulen Module status",
225
126
  " /ponytail status Ponytail mode + default",
226
127
  "",
227
- "Kill-switch: `ceulen.disabled` in settings.json; /reload (or restart) applies.",
128
+ "Escape hatch: `ceulen.disabled` in settings.json (no UI); /reload applies.",
228
129
  );
229
130
  return lines;
230
131
  }
@@ -235,47 +136,11 @@ export default function configModule(pi: ExtensionAPI, deps?: ModuleLoadDeps): v
235
136
  // so a save that re-registers a provider stays the owner's claim.
236
137
  const factories = deps?.configContribs ?? new Map<string, () => ModuleConfig>();
237
138
 
238
- // Where each module's section lives in OMP's taxonomy — pretty section
239
- // names + icons only; the TAB comes from the registry's `category` (one
240
- // source: adding a module = one registry entry, no second map to touch).
241
- // A module WITHOUT a contribution factory (usage, config) renders an
242
- // Enable-only section here; unknown modules fall back to their own tab so
243
- // a new module still renders.
244
- const PRETTY_OF: Record<string, { section: string; icon?: string }> = {
245
- router: { section: "Router", icon: "🌐" },
246
- classifier: { section: "Classifier (Jev)", icon: "⚖" },
247
- advisor: { section: "Advisor", icon: "🧭" },
248
- steering: { section: "Steering", icon: "🎯" },
249
- zai: { section: "Z.AI (Anthropic)", icon: "⚡" },
250
- usage: { section: "Usage footer", icon: "📊" },
251
- munin: { section: "Munin", icon: "🪶" },
252
- composer: { section: "Composer", icon: "🎨" },
253
- ux: { section: "UX discipline", icon: "📐" },
254
- ponytail: { section: "Ponytail", icon: "🦥" },
255
- plan: { section: "Plan mode", icon: "🗺️" },
256
- todo: { section: "Todo", icon: "☑" },
257
- cron: { section: "Cron", icon: "⏰" },
258
- attachments: { section: "Attachments", icon: "📎" },
259
- permission: { section: "Permissions", icon: "🛡" },
260
- serena: { section: "Serena" },
261
- repair: { section: "Repair", icon: "🔧" },
262
- fff: { section: "FFF search" },
263
- web: { section: "Web", icon: "🌍" },
264
- gh: { section: "GitHub", icon: "🐙" },
265
- a2a: { section: "A2A", icon: "📡" },
266
- rtk: { section: "RTK" },
267
- config: { section: "Ceulen config", icon: "🧩" },
268
- };
269
- const SECTION_OF: Record<string, { tab: string; section: string; icon: string | undefined }> = Object.fromEntries(
270
- MODULES.map((m) => [m.name, { tab: m.category, section: PRETTY_OF[m.name]?.section ?? m.name, icon: PRETTY_OF[m.name]?.icon }]),
271
- );
272
139
 
273
140
  pi.registerCommand("config", {
274
141
  description: "Central settings panel for all ceulen modules.",
275
142
  handler: async (args, ctx) => {
276
143
  const sub = String(args ?? "").trim().toLowerCase();
277
- const workingEnabled = new Set(enabledModules());
278
- const workingTools = new Set(allDeclaredTools().filter((t) => !readDisabledTools().has(t)));
279
144
  const pluginsWorking = openPluginsWorking();
280
145
  // Pi core settings: an OWN SettingsManager instance over the same files
281
146
  // (typed setters persist to global settings.json with pi's own locking;
@@ -289,39 +154,16 @@ export default function configModule(pi: ExtensionAPI, deps?: ModuleLoadDeps): v
289
154
  const initialStartup = startupToolSet(piSettings);
290
155
  const workingStartup = new Set(initialStartup);
291
156
 
292
- // A DISABLED module has no registered factory (the loader skips it), so
293
- // its section collapses to the Enable row below — settings are moot
294
- // while off, and the row must stay reachable to turn it back on.
157
+ // The loader skips a module named in the `ceulen.disabled` settings
158
+ // escape hatch, so its factory (and section) never renders here — the
159
+ // settings.json key is the only way back, by design (no UI toggles).
295
160
  const contributions = [...factories.entries()].map(([name, factory]) => ({ name, cfg: factory() }));
296
161
 
297
162
  // Assemble in OMP taxonomy order: pi settings first (they own the
298
163
  // Appearance/Model/Interaction/Context/Shell spine), then ceulen module
299
- // sections with their Enable row, then plugins.
164
+ // sections (functional rows only — no Enable/tool toggles), then plugins.
300
165
  const assemble = (): PanelGroup[] => {
301
- const seen = new Set(contributions.map((c) => c.name));
302
- const modGroups = contributions.flatMap((c) => {
303
- const section = SECTION_OF[c.name];
304
- const groups = c.cfg.groups();
305
- if (!section) return groups;
306
- const module = MODULES.find((m) => m.name === c.name);
307
- return withToolRows(withEnableRow(groups, c.name, module?.describe ?? "", workingEnabled), module?.tools, workingTools);
308
- });
309
- // Modules with no contribution factory still need their Enable row
310
- // reachable (usage, config itself) — and a disabled module needs the
311
- // same synthesized section to be switchable back on. Core modules are
312
- // always on: no synthesized Enable-only section (their contribution,
313
- // if any, renders without one).
314
- for (const m of MODULES) {
315
- const section = SECTION_OF[m.name];
316
- if (!section || seen.has(m.name) || m.core) continue;
317
- modGroups.push({
318
- key: `ceulen-${m.name}`,
319
- label: section.section,
320
- tab: section.tab,
321
- icon: section.icon,
322
- rows: [moduleEnableRow(m.name, m.describe ?? "", workingEnabled), ...moduleToolRows(m.tools, workingTools)],
323
- });
324
- }
166
+ const modGroups = contributions.flatMap((c) => c.cfg.groups());
325
167
  // Plugins' package sections precede the config module's own switch.
326
168
  const piGroups = buildPiSettingsGroups(piSettings, piMenuLookup(ctx));
327
169
  // Built-in tools lead the Tools tab (before the extension-dirs rows).
@@ -356,34 +198,6 @@ export default function configModule(pi: ExtensionAPI, deps?: ModuleLoadDeps): v
356
198
  onSave: async (_saved, edited) => {
357
199
  const keys = edited ?? new Set<string>();
358
200
 
359
- // Kill-switch first: compare the working Set against what's persisted.
360
- if ([...keys].some((k) => k.startsWith(KILL_SWITCH_PREFIX))) {
361
- try {
362
- const file = writeDisabled(nextDisabled(workingEnabled));
363
- ctx.ui.notify(`Module kill-switch saved to ${file} — /reload (or restart) to apply.`, "info");
364
- } catch (e) {
365
- ctx.ui.notify(`Kill-switch save failed: ${e instanceof Error ? e.message : e}`, "error");
366
- }
367
- }
368
-
369
- if ([...keys].some((k) => k.startsWith(TOOL_SWITCH_PREFIX))) {
370
- try {
371
- const before = new Set(allDeclaredTools().filter((t) => !readDisabledTools().has(t)));
372
- const after = workingTools;
373
- const file = writeDisabledTools(nextDisabledTools(after));
374
- applyToolSwitches(pi, before, after);
375
- const changed = allDeclaredTools().filter((t) => before.has(t) !== after.has(t));
376
- ctx.ui.notify(
377
- changed.length > 0
378
- ? `Tools ${changed.map((t) => (after.has(t) ? `+${t}` : `-${t}`)).join(" ")} — saved to ${file}, applied live.`
379
- : `Tool toggles saved to ${file}.`,
380
- "info",
381
- );
382
- } catch (e) {
383
- ctx.ui.notify(`Tool toggle save failed: ${e instanceof Error ? e.message : e}`, "error");
384
- }
385
- }
386
-
387
201
  // Pi packages (plugins): writes land in the file each entry came from.
388
202
  if ([...keys].some(isPluginsKey)) {
389
203
  try {
@@ -396,8 +210,8 @@ export default function configModule(pi: ExtensionAPI, deps?: ModuleLoadDeps): v
396
210
  }
397
211
  }
398
212
 
399
- // Module contributions: each isolated — one module's failure must not
400
- // block the others (nor the kill-switch above).
213
+ // Module contributions: each isolated — one module's failure must
214
+ // never block the others.
401
215
  await saveContributions(contributions, keys, ctx);
402
216
 
403
217
  // Pi's built-in tools: persist the selection (stock-equal deletes
@@ -46,7 +46,7 @@ describe("startupToolSet", () => {
46
46
  describe("builtinToolRows", () => {
47
47
  it("renders one toggle per built-in tool, stock four default-on", () => {
48
48
  const rows = builtinToolRows(new Set(startupToolSet(SettingsManager.inMemory())));
49
- assert.equal(rows.length, 10);
49
+ assert.equal(rows.length, 9, "tool_search has no row — ceulen owns its activation");
50
50
  const byKey = new Map(rows.map((r) => [r.key, r]));
51
51
  for (const name of STOCK) {
52
52
  const r = byKey.get(`${DEFAULT_TOOLS_PREFIX}${name}`)!;
@@ -77,9 +77,8 @@ describe("nextDefaultTools", () => {
77
77
  });
78
78
 
79
79
  it("round-trips through the panel state", () => {
80
- const working = startupToolSet(SettingsManager.inMemory({ defaultTools: ["+codemode"] }));
81
- working.add("tool_search");
82
- assert.deepEqual(nextDefaultTools(working), [...STOCK, "codemode", "tool_search"]);
80
+ const working = startupToolSet(SettingsManager.inMemory({ defaultTools: ["+codemode", "+grep"] }));
81
+ assert.deepEqual(nextDefaultTools(working), [...STOCK, "grep", "codemode"]);
83
82
  });
84
83
  });
85
84
 
@@ -19,7 +19,7 @@ after(() => {
19
19
 
20
20
  const settingsPath = () => join(TMP_HOME, "settings.json");
21
21
 
22
- // ── registry: kill-switch read/write + layer precedence ─────────────────────
22
+ // ── registry: kill-switch read + layer precedence (write side deleted with the /config rows) ──
23
23
 
24
24
  describe("registry kill-switch", () => {
25
25
  it("readDisabled returns [] when no settings file exists", async () => {
@@ -28,34 +28,10 @@ describe("registry kill-switch", () => {
28
28
  assert.deepEqual(readDisabled(), []);
29
29
  });
30
30
 
31
- it("writeDisabled round-trips through the same file readDisabled resolves", async () => {
32
- try { unlinkSync(settingsPath()); } catch { /* ignore */ }
33
- const { readDisabled, writeDisabled, disabledSource } = await import("../../../lib/registry.js");
34
- const written = writeDisabled(["ponytail"]);
35
- assert.equal(written, settingsPath());
31
+ it("readDisabled honors a hand-written settings escape hatch and maps the deprecated sub alias", async () => {
32
+ writeFileSync(settingsPath(), JSON.stringify({ ceulen: { disabled: ["sub", "ponytail"] } }));
33
+ const { readDisabled } = await import("../../../lib/registry.js");
36
34
  assert.deepEqual(readDisabled(), ["ponytail"]);
37
- assert.equal(disabledSource().isProject, false);
38
- });
39
-
40
- it("writeDisabled merges — unrelated keys survive, tmp residue cleaned", async () => {
41
- writeFileSync(settingsPath(), JSON.stringify({ theme: "dark", ceulen: { disabled: ["usage"] } }));
42
- const inoBefore = statSync(settingsPath()).ino;
43
- const { writeDisabled } = await import("../../../lib/registry.js");
44
- writeDisabled(["ponytail"]);
45
- const json = JSON.parse(readFileSync(settingsPath(), "utf8"));
46
- assert.equal(json.theme, "dark");
47
- assert.deepEqual(json.ceulen.disabled, ["ponytail"]);
48
- assert.notEqual(inoBefore, statSync(settingsPath()).ino); // tmp+rename atomic
49
- assert.ok(!existsSync(settingsPath() + ".tmp"));
50
- });
51
-
52
- it("writeDisabled refuses to clobber a corrupt settings.json", async () => {
53
- writeFileSync(settingsPath(), '{ "ceulen": { "disabled": ["usage"] }\nOOPS');
54
- const before = readFileSync(settingsPath(), "utf8");
55
- const { writeDisabled } = await import("../../../lib/registry.js");
56
- assert.throws(() => writeDisabled(["ponytail"]), /not valid JSON/);
57
- assert.equal(readFileSync(settingsPath(), "utf8"), before);
58
- assert.ok(!existsSync(settingsPath() + ".tmp"));
59
35
  });
60
36
 
61
37
  it("deprecated \"sub\" alias still maps (to the now-core usage module, so it disables nothing)", async () => {
@@ -78,29 +54,22 @@ describe("registry kill-switch", () => {
78
54
  writeFileSync(join(TMP_HOME, "trust.json"), JSON.stringify({ [projectCwd]: true }));
79
55
  });
80
56
 
81
- it("project ceulen section wins the read AND captures the write", async () => {
57
+ it("project ceulen section wins the read", async () => {
82
58
  writeFileSync(settingsPath(), JSON.stringify({ ceulen: { disabled: ["usage"] } }));
83
59
  writeFileSync(projectSettings, JSON.stringify({ ceulen: { disabled: ["ponytail"] } }));
84
- const { readDisabled, writeDisabled, disabledSource } = await import("../../../lib/registry.js");
60
+ const { readDisabled, disabledSource } = await import("../../../lib/registry.js");
85
61
 
86
62
  assert.deepEqual(readDisabled(projectCwd), ["ponytail"]); // project wins
87
63
  const source = disabledSource(projectCwd);
88
64
  assert.equal(source.path, projectSettings);
89
65
  assert.equal(source.isProject, true);
90
-
91
- const written = writeDisabled(["munin"], projectCwd);
92
- assert.equal(written, projectSettings, "write lands where the read resolves — never shadowed");
93
- assert.deepEqual(readDisabled(projectCwd), ["munin"]);
94
- // Global file untouched by the project-scoped write.
95
- assert.deepEqual(JSON.parse(readFileSync(settingsPath(), "utf8")).ceulen.disabled, ["usage"]);
96
66
  });
97
67
 
98
- it("project file WITHOUT a ceulen section does not capture the write", async () => {
68
+ it("project file WITHOUT a ceulen section does not claim the key", async () => {
99
69
  writeFileSync(projectSettings, JSON.stringify({ router: { baseUrl: "http://x" } }));
100
70
  try { unlinkSync(settingsPath()); } catch { /* ignore */ }
101
- const { writeDisabled, disabledSource } = await import("../../../lib/registry.js");
71
+ const { disabledSource } = await import("../../../lib/registry.js");
102
72
  assert.equal(disabledSource(projectCwd).isProject, false);
103
- assert.equal(writeDisabled(["usage"], projectCwd), settingsPath());
104
73
  });
105
74
  });
106
75
  });
@@ -128,37 +97,6 @@ describe("config module", () => {
128
97
  };
129
98
  };
130
99
 
131
- it("moduleEnableRow toggles mutate the working set; nextDisabled inverts it", async () => {
132
- const { moduleEnableRow, nextDisabled } = await import("../index.js");
133
- const { MODULES } = await import("../../../lib/registry.js");
134
- const working = new Set(MODULES.map((m) => m.name));
135
- const enable = moduleEnableRow("ponytail", "Lazy mode.", working);
136
- assert.equal(enable.key, "ceulen.disabled.ponytail");
137
- assert.equal(enable.defaultValue, true);
138
-
139
- // Toggle "ponytail" off via its row setter.
140
- assert.equal(enable.value, true);
141
- enable.set(false);
142
- assert.equal(working.has("ponytail"), false);
143
- assert.deepEqual(nextDisabled(working), ["ponytail"]);
144
-
145
- enable.set(true);
146
- assert.deepEqual(nextDisabled(working), []);
147
- });
148
-
149
- it("withEnableRow prepends the Enable row to the module's FIRST section only", async () => {
150
- const { withEnableRow } = await import("../index.js");
151
- const { MODULES } = await import("../../../lib/registry.js");
152
- const working = new Set(MODULES.map((m) => m.name));
153
- const groups = [
154
- { key: "a", label: "Ponytail", tab: "Tasks", rows: [{ key: "ponytail.defaultMode" }] },
155
- { key: "b", label: "Models", tab: "Tasks", rows: [{ key: "ponytail.quietStartup" }] },
156
- ] as never;
157
- const out = withEnableRow(groups, "ponytail", "Lazy mode.", working);
158
- assert.deepEqual(out[0]!.rows.map((r) => r.key), ["ceulen.disabled.ponytail", "ponytail.defaultMode"]);
159
- assert.deepEqual(out[1]!.rows.map((r) => r.key), ["ponytail.quietStartup"], "second section untouched");
160
- });
161
-
162
100
  it("saveContributions: only edited-key owners are invoked, and a thrower doesn't block siblings", async () => {
163
101
  const { saveContributions } = await import("../index.js");
164
102
  const calls: string[] = [];
@@ -249,9 +187,8 @@ describe("config module", () => {
249
187
  registerCommand: (_name: string, opts: { handler: typeof handler }) => { handler = opts.handler; },
250
188
  } as never;
251
189
  const factories = new Map<string, () => never>([
252
- // Router is core, so its Providers section comes from its OWN
253
- // contribution (there is no synthesized Enable-only section).
254
190
  [
191
+
255
192
  "router",
256
193
  () => ({
257
194
  groups: () => [
@@ -32,7 +32,6 @@ import { closeSync, fstatSync, openSync, readSync, statSync } from "node:fs";
32
32
  import path from "node:path";
33
33
  import { StringDecoder } from "node:string_decoder";
34
34
  import { buildQuery, normalizeExcludes, normalizePathConstraint } from "./lib/query";
35
- import { readDisabledTools } from "../../lib/tools";
36
35
 
37
36
  // ---------------------------------------------------------------------------
38
37
  // Constants
@@ -426,7 +425,10 @@ export default function fffExtension(pi: ExtensionAPI) {
426
425
  let enableFsRootScanning = false;
427
426
  let toolsRegistered = false;
428
427
  let autocompleteRegistered = false;
429
- let disabledTools: Set<string> = new Set();
428
+ // Names registerBoundedTool could not claim this session (another
429
+ // extension's guarded() owns them). One dim note after the loop instead of
430
+ // a first-throw unwind — a single collision must not cost the whole toolset.
431
+ let skippedTools: string[] = [];
430
432
 
431
433
  function resolveRuntimeConfig() {
432
434
  // Pi populates extension flag values only after loading extension factories.
@@ -977,6 +979,9 @@ export default function fffExtension(pi: ExtensionAPI) {
977
979
  activeCwd = ctx.cwd;
978
980
  resolveRuntimeConfig();
979
981
  registerTools();
982
+ if (skippedTools.length > 0) {
983
+ ctx.ui.notify(`FFF: skipped ${skippedTools.join(", ")} — name already claimed by another extension.`, "info");
984
+ }
980
985
  if (currentMode === "override") {
981
986
  const available = new Set(pi.getAllTools().map((tool) => tool.name));
982
987
  const active = pi.getActiveTools();
@@ -1002,7 +1007,7 @@ export default function fffExtension(pi: ExtensionAPI) {
1002
1007
  function registerTools() {
1003
1008
  if (toolsRegistered) return;
1004
1009
  toolsRegistered = true;
1005
- disabledTools = readDisabledTools();
1010
+ skippedTools = [];
1006
1011
 
1007
1012
  // --- Shared render helpers ---
1008
1013
 
@@ -1034,14 +1039,20 @@ export default function fffExtension(pi: ExtensionAPI) {
1034
1039
  };
1035
1040
 
1036
1041
  const registerBoundedTool = (tool: any) => {
1042
+ const name = tool.name as string;
1043
+ try {
1044
+ registerOneBoundedTool(tool);
1045
+ } catch {
1046
+ // Collision (usually repair's guarded() owning the builtin name in
1047
+ // override mode): skip THIS tool, keep registering the rest.
1048
+ skippedTools.push(name);
1049
+ }
1050
+ };
1051
+
1052
+ const registerOneBoundedTool = (tool: any) => {
1037
1053
  const execute = tool.execute;
1038
- // Per-tool kill-switch (ceulen.disabledTools): rows use canonical names
1039
- // (ffgrep/fffind); override mode registers grep/find, so map before the
1040
- // defaultActive check. /config re-activates disabled tools live.
1041
- const canonical = tool.name === "grep" ? "ffgrep" : tool.name === "find" ? "fffind" : tool.name;
1042
1054
  pi.registerTool({
1043
1055
  ...tool,
1044
- defaultActive: !disabledTools.has(canonical),
1045
1056
  async execute(...args: any[]) {
1046
1057
  const result = await execute(...args);
1047
1058
  let truncation: TruncationResult | undefined;
@@ -67,7 +67,7 @@ function harness(
67
67
  finder: any,
68
68
  mode?: string,
69
69
  extraFlags: Record<string, unknown> = {},
70
- options: { cwd?: string; create?: (params: any) => any; excludedTools?: string[] } = {},
70
+ options: { cwd?: string; create?: (params: any) => any; excludedTools?: string[]; throwOnTool?: string } = {},
71
71
  ) {
72
72
  (FileFinder as any).create = (params: any) => ({
73
73
  ok: true,
@@ -77,13 +77,17 @@ function harness(
77
77
  const commands = new Map<string, any>();
78
78
  const events = new Map<string, Function[]>();
79
79
  const flags = new Map<string, unknown>(Object.entries(extraFlags));
80
+ const notifies: string[] = [];
80
81
  let activeTools = ["read", "bash", "edit", "write"];
81
82
  if (mode) flags.set("fff-mode", mode);
82
83
  let flagsReady = false;
83
84
  const pi = {
84
85
  getFlag: (name: string) => flagsReady ? flags.get(name) : undefined,
85
86
  registerFlag: () => {},
86
- registerTool: (tool: any) => tools.set(tool.name, tool),
87
+ registerTool: (tool: any) => {
88
+ if (tool.name === options.throwOnTool) throw new Error(`ceulen: tool "${tool.name}" already owned by another module`);
89
+ tools.set(tool.name, tool);
90
+ },
87
91
  registerCommand: (name: string, command: any) => commands.set(name, command),
88
92
  on: (name: string, handler: Function) => events.set(name, [...(events.get(name) ?? []), handler]),
89
93
  getAllTools: () => [...tools.values()]
@@ -94,9 +98,9 @@ function harness(
94
98
  };
95
99
  fffExtension(pi as any);
96
100
  flagsReady = true;
97
- const ctx = { cwd: options.cwd ?? process.cwd(), ui: { notify: () => {}, addAutocompleteProvider: () => {} } };
101
+ const ctx = { cwd: options.cwd ?? process.cwd(), ui: { notify: (m: string) => notifies.push(m), addAutocompleteProvider: () => {} } };
98
102
  const started = events.get("session_start")?.[0]({}, ctx);
99
- return { tools, commands, events, flags, started, setActiveTools: (names: string[]) => { activeTools = [...names]; }, get activeTools() { return activeTools; } };
103
+ return { tools, commands, events, flags, started, notifies, setActiveTools: (names: string[]) => { activeTools = [...names]; }, get activeTools() { return activeTools; } };
100
104
  }
101
105
 
102
106
  async function run(tool: any, params: any) {
@@ -572,6 +576,29 @@ describe("pi-fff tools", () => {
572
576
  assert.ok((text(result)).includes("[Output truncated:"));
573
577
  assert.ok(result.details.truncation.outputLines <= 2000);
574
578
  });
579
+
580
+ it("override mode degrades per tool when a name is already claimed (guarded collision)", async () => {
581
+ // registerTool throwing on "grep" simulates the bundle guarded() map:
582
+ // repair wrapped the builtin first. The throw must cost ONLY grep —
583
+ // resolve_file / fff_multi_grep / related_files still register and the
584
+ // session_start handler settles without an init failure.
585
+ const { tools, started, notifies } = harness(fakeFinder(), "override", {}, { throwOnTool: "grep" });
586
+ await started;
587
+ assert.ok(!tools.has("grep"));
588
+ for (const name of ["find", "resolve_file", "fff_multi_grep", "related_files"]) {
589
+ assert.ok(tools.has(name), `expected ${name} to register despite the grep collision`);
590
+ }
591
+ assert.ok(notifies.some((m) => m.includes("skipped") && m.includes("grep")));
592
+ assert.ok(!notifies.some((m) => m.includes("init failed")));
593
+ });
594
+
595
+ it("normal mode registers everything and never emits a skipped note", async () => {
596
+ const { tools, notifies } = harness(fakeFinder());
597
+ for (const name of ["ffgrep", "fffind", "resolve_file", "fff_multi_grep", "related_files"]) {
598
+ assert.ok(tools.has(name), `expected ${name} to register`);
599
+ }
600
+ assert.ok(!notifies.some((m) => m.includes("skipped")));
601
+ });
575
602
  });
576
603
 
577
604
  describe("before_agent_start search guidance", () => {
@@ -49,7 +49,7 @@ function writeRunWatchTimeoutSecs(secs: number): string {
49
49
  return file;
50
50
  }
51
51
 
52
- export function buildGhGroups(runWatchTimeoutSecs: number): PanelGroup[] {
52
+ export function buildGhGroups(working: { value: number }): PanelGroup[] {
53
53
  return [
54
54
  {
55
55
  key: "gh",
@@ -57,8 +57,11 @@ export function buildGhGroups(runWatchTimeoutSecs: number): PanelGroup[] {
57
57
  tab: "Tools",
58
58
  icon: "🐙",
59
59
  rows: [
60
- row("gh.runWatchTimeoutSecs", "run_watch budget", "number", runWatchTimeoutSecs, (v) => {
61
- runWatchTimeoutSecs = Math.max(10, Math.floor(Number(v)));
60
+ row("gh.runWatchTimeoutSecs", "run_watch budget", "number", working.value, (v) => {
61
+ // NaN guard is load-bearing: a garbage inline edit must not write
62
+ // NaN (JSON null) — leave the working value untouched instead.
63
+ const n = Math.floor(Number(v));
64
+ if (Number.isFinite(n)) working.value = Math.max(10, n);
62
65
  }, {
63
66
  defaultValue: DEFAULT_RUN_WATCH_TIMEOUT_SECS,
64
67
  description: "Seconds run_watch keeps polling a workflow run before reporting in-progress (capped at gh's 5-min command deadline).",
@@ -70,13 +73,13 @@ export function buildGhGroups(runWatchTimeoutSecs: number): PanelGroup[] {
70
73
 
71
74
  /** gh's ModuleConfig for the central /config panel. */
72
75
  export function ghConfig(_pi: ExtensionAPI): ModuleConfig {
73
- let working = readRunWatchTimeoutSecs();
76
+ const working = { value: readRunWatchTimeoutSecs() };
74
77
  return {
75
78
  groups: () => buildGhGroups(working),
76
79
  save: async (edited, ctx: ExtensionContext) => {
77
80
  if (![...edited].some((k) => k.startsWith("gh."))) return;
78
- const file = writeRunWatchTimeoutSecs(working);
79
- ctx.ui.notify(`Saved gh.runWatchTimeoutSecs=${working} to ${file} (applies to the next run_watch call).`, "info");
81
+ const file = writeRunWatchTimeoutSecs(working.value);
82
+ ctx.ui.notify(`Saved gh.runWatchTimeoutSecs=${working.value} to ${file} (applies to the next run_watch call).`, "info");
80
83
  },
81
84
  };
82
85
  }