ceulen 0.14.0 → 0.15.1
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 +39 -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/test/extension.test.ts +1 -19
- package/extensions/modules/advisor/commands/advisor.ts +3 -9
- package/extensions/modules/advisor/index.ts +6 -1
- package/extensions/modules/advisor/test/configPanel.test.ts +1 -1
- package/extensions/modules/advisor/test/module.test.ts +18 -13
- 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 +0 -8
- package/extensions/modules/gh/index.ts +0 -3
- package/extensions/modules/jfind/index.ts +0 -3
- package/extensions/modules/munin/index.ts +5 -7
- package/extensions/modules/notify/index.ts +0 -3
- package/extensions/modules/plan/index.ts +6 -8
- package/extensions/modules/plan/test/module.test.ts +14 -0
- package/extensions/modules/repair/index.ts +0 -8
- 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 +0 -2
- 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/test/extension.test.ts +8 -18
- package/package.json +3 -3
- 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
|
@@ -200,6 +200,20 @@ describe("plan mode — prompt + approval flow", () => {
|
|
|
200
200
|
assert.match(h.userMessages[0].content, /Execute the approved plan/);
|
|
201
201
|
});
|
|
202
202
|
|
|
203
|
+
it("auto-approve never fires off an aborted settle; the plan still approves on a clean one", async () => {
|
|
204
|
+
setPlanSettings(agent.dir, { autoApprove: true });
|
|
205
|
+
const h = await start();
|
|
206
|
+
await h.commands.plan.handler("", h.ctx({ cwd: REPO }));
|
|
207
|
+
await h.tools.write_plan.execute("tc1", { title: "T", content: "body" }, undefined, undefined, h.ctx({ cwd: REPO }));
|
|
208
|
+
// User hit Escape after write_plan → no autonomous execution.
|
|
209
|
+
await h.fire("agent_settled", { aborted: true }, h.ctx({ cwd: REPO }));
|
|
210
|
+
assert.equal(h.userMessages.length, 0, "aborted settle does not execute");
|
|
211
|
+
// The plan stays pending: the next clean settle approves it.
|
|
212
|
+
await h.fire("agent_settled", {}, h.ctx({ cwd: REPO }));
|
|
213
|
+
assert.equal(h.userMessages.length, 1);
|
|
214
|
+
assert.match(h.userMessages[0].content, /Execute the approved plan/);
|
|
215
|
+
});
|
|
216
|
+
|
|
203
217
|
it("/plan-approve without a plan warns", async () => {
|
|
204
218
|
const h = await start();
|
|
205
219
|
await h.commands["plan-approve"].handler("current", h.ctx({ cwd: REPO }));
|
|
@@ -41,7 +41,6 @@ import {
|
|
|
41
41
|
defineTool,
|
|
42
42
|
} from "@earendil-works/pi-coding-agent";
|
|
43
43
|
import { Type } from "typebox";
|
|
44
|
-
import { readDisabledTools } from "../../lib/tools.js";
|
|
45
44
|
import { abortAllBgJobs, bashAutoBgClause, setBgDeliveryEnabled, wrapWithAutoBg } from "./lib/auto-bg.js";
|
|
46
45
|
import {
|
|
47
46
|
computeRetryEdit,
|
|
@@ -654,10 +653,6 @@ export default function repairModule(pi: ExtensionAPI) {
|
|
|
654
653
|
const autoBgOn = settings.autoBg;
|
|
655
654
|
const autoBgSecs = settings.autoBgSecs;
|
|
656
655
|
|
|
657
|
-
// Per-tool kill-switch: a tool named in ceulen.disabledTools registers
|
|
658
|
-
// inactive, so /config's live tool toggles keep working over the wrapped
|
|
659
|
-
// built-ins too. The persisted list re-applies on every load.
|
|
660
|
-
const disabled = readDisabledTools();
|
|
661
656
|
const repairCounts = new Map<string, number>();
|
|
662
657
|
// Per-file edit-mismatch counters — escalate to apply_patch after repeated
|
|
663
658
|
// unresolvable misses on the same file (26% retry-fail tail).
|
|
@@ -699,7 +694,6 @@ export default function repairModule(pi: ExtensionAPI) {
|
|
|
699
694
|
() => pi.getActiveTools(),
|
|
700
695
|
(cwd: string) => readRepairSettings(cwd).editRetry,
|
|
701
696
|
),
|
|
702
|
-
defaultActive: !disabled.has(template.name),
|
|
703
697
|
});
|
|
704
698
|
}
|
|
705
699
|
|
|
@@ -754,7 +748,6 @@ export default function repairModule(pi: ExtensionAPI) {
|
|
|
754
748
|
}
|
|
755
749
|
},
|
|
756
750
|
}),
|
|
757
|
-
defaultActive: !disabled.has("apply_patch"),
|
|
758
751
|
});
|
|
759
752
|
|
|
760
753
|
// ── str_replace_editor: DSH Minimal-pair editor (byte-faithful schema) ──
|
|
@@ -772,7 +765,6 @@ export default function repairModule(pi: ExtensionAPI) {
|
|
|
772
765
|
}
|
|
773
766
|
return result;
|
|
774
767
|
},
|
|
775
|
-
defaultActive: !disabled.has("str_replace_editor"),
|
|
776
768
|
});
|
|
777
769
|
|
|
778
770
|
// ── Session lifecycle ──
|
|
@@ -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,
|
|
@@ -114,7 +113,6 @@ export default function shellsModule(pi: ExtensionAPI): void {
|
|
|
114
113
|
pi.registerTool({
|
|
115
114
|
name: "shell",
|
|
116
115
|
label: "Shell",
|
|
117
|
-
defaultActive: !readDisabledTools().has("shell"),
|
|
118
116
|
description: [
|
|
119
117
|
"Run a shell command as a PERSISTENT background session and interact with it across tool calls (dev servers, watchers, long builds). Actions:",
|
|
120
118
|
'- start: {command, name?, cwd?} — spawn in its own process group; returns an id ("s1"…).',
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
import { Text } from "@earendil-works/pi-tui";
|
|
20
20
|
import { Type } from "typebox";
|
|
21
21
|
|
|
22
|
-
import { readDisabledTools } from "../../../lib/tools.js";
|
|
23
22
|
|
|
24
23
|
/** The dim marker shown in place of the thoughts. */
|
|
25
24
|
export const THINK_MARKER = "·";
|
|
@@ -46,7 +45,6 @@ export function thinkTool() {
|
|
|
46
45
|
promptGuidelines: ["Use the think tool to plan before complex multi-step work."],
|
|
47
46
|
// kill-switch: ceulen.disabledTools names it → registers inactive (the
|
|
48
47
|
// config module's tool rows flip it live via setActiveTools).
|
|
49
|
-
defaultActive: !readDisabledTools().has("think"),
|
|
50
48
|
parameters: Type.Object(
|
|
51
49
|
{ thoughts: Type.String({ description: "private scratchpad; not shown to user" }) },
|
|
52
50
|
{ additionalProperties: false },
|
|
@@ -54,9 +54,6 @@ describe("think tool", () => {
|
|
|
54
54
|
assert.match((plain as unknown as { render(w: number): string[] }).render(80).join(""), /· think \(1 chars\)/);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
it("defaultActive is true unless the kill-switch names think", () => {
|
|
58
|
-
assert.equal(thinkTool().defaultActive, true, "isolated dir has no ceulen.disabledTools");
|
|
59
|
-
});
|
|
60
57
|
});
|
|
61
58
|
|
|
62
59
|
describe("module gating", () => {
|
|
@@ -66,12 +63,11 @@ describe("think tool", () => {
|
|
|
66
63
|
assert.equal(pi.tools.length, 0, "no tool when the gate is off");
|
|
67
64
|
});
|
|
68
65
|
|
|
69
|
-
it("thinkTool: true registers the think tool
|
|
66
|
+
it("thinkTool: true registers the think tool", () => {
|
|
70
67
|
setSteeringSettings(iso.dir, { thinkTool: true });
|
|
71
68
|
const pi = createFakePi();
|
|
72
69
|
assert.equal(pi.tools.length, 1);
|
|
73
70
|
assert.equal(pi.tools[0]!.name, "think");
|
|
74
|
-
assert.equal(pi.tools[0]!.defaultActive, true);
|
|
75
71
|
});
|
|
76
72
|
});
|
|
77
73
|
});
|
|
@@ -47,7 +47,6 @@ import {
|
|
|
47
47
|
type WidgetTheme,
|
|
48
48
|
} from "./lib/render.ts";
|
|
49
49
|
import { readLingerSecs } from "./lib/settings.ts";
|
|
50
|
-
import { readDisabledTools } from "../../lib/tools.js";
|
|
51
50
|
|
|
52
51
|
export const TODO_TOOL = "todo";
|
|
53
52
|
export const TODO_ENTRY_TYPE = "ceulen-todo";
|
|
@@ -394,7 +393,6 @@ export default function todoModule(pi: ExtensionAPI): void {
|
|
|
394
393
|
"External waits (user, another agent, a service): block with the blocker ids, which suppresses the stop reminder; unblock when actionable, and append a clearing phase when the blocker is agent-actionable.",
|
|
395
394
|
"Phase ids are stable for the list's lifetime; when the board loses text, view it — never guess.",
|
|
396
395
|
],
|
|
397
|
-
defaultActive: !readDisabledTools().has(TODO_TOOL),
|
|
398
396
|
parameters: todoSchema,
|
|
399
397
|
// TUI-only: the colored board (status colors, strikethrough on done).
|
|
400
398
|
// The LLM-facing text content stays the plain board — this only swaps
|
|
@@ -1688,7 +1688,7 @@ export interface ContextBreakdown {
|
|
|
1688
1688
|
/** Human-readable model name, e.g. "GLM-5.3". */
|
|
1689
1689
|
modelName?: string;
|
|
1690
1690
|
systemPrompt: { total: number; sections: Record<string, number> };
|
|
1691
|
-
tools: { total: number; activeCount: number; registeredCount: number; bySource: Record<string, { tokens: number; count: number }> };
|
|
1691
|
+
tools: { total: number; activeCount: number; registeredCount: number; deferred: { count: number; tokens: number }; bySource: Record<string, { tokens: number; count: number }> };
|
|
1692
1692
|
/** Per-tool costs, descending — powers the "top tools" list. */
|
|
1693
1693
|
toolCosts: { name: string; tokens: number; source: string }[];
|
|
1694
1694
|
skills: { total: number; count: number };
|
|
@@ -1751,14 +1751,24 @@ export function computeContextBreakdown(input: ContextBreakdownInput): ContextBr
|
|
|
1751
1751
|
const bySource: Record<string, { tokens: number; count: number }> = {};
|
|
1752
1752
|
const toolCosts: { name: string; tokens: number; source: string }[] = [];
|
|
1753
1753
|
let toolsTotal = 0;
|
|
1754
|
+
// Deferred/inactive tools are NOT in the prompt (pi only declares active
|
|
1755
|
+
// `direct` tools); count their schemas separately so the report reflects
|
|
1756
|
+
// what the model actually receives.
|
|
1757
|
+
let deferredCount = 0;
|
|
1758
|
+
let deferredTokens = 0;
|
|
1754
1759
|
for (const t of tools) {
|
|
1755
1760
|
const cost = toolTokens(t);
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1761
|
+
if (activeSet.has(t.name)) {
|
|
1762
|
+
toolsTotal += cost;
|
|
1763
|
+
const src = t.sourceInfo?.source ?? "unknown";
|
|
1764
|
+
const bucket = (bySource[src] ??= { tokens: 0, count: 0 });
|
|
1765
|
+
bucket.tokens += cost;
|
|
1766
|
+
bucket.count += 1;
|
|
1767
|
+
toolCosts.push({ name: t.name, tokens: cost, source: src });
|
|
1768
|
+
} else {
|
|
1769
|
+
deferredCount += 1;
|
|
1770
|
+
deferredTokens += cost;
|
|
1771
|
+
}
|
|
1762
1772
|
}
|
|
1763
1773
|
toolCosts.sort((a, b) => b.tokens - a.tokens);
|
|
1764
1774
|
|
|
@@ -1826,7 +1836,7 @@ export function computeContextBreakdown(input: ContextBreakdownInput): ContextBr
|
|
|
1826
1836
|
modelLabel: model && "provider" in model && model.provider ? `${model.provider}/${model.id ?? "?"}` : undefined,
|
|
1827
1837
|
modelName: model && "name" in model ? model.name : undefined,
|
|
1828
1838
|
systemPrompt: { total: systemTotal, sections },
|
|
1829
|
-
tools: { total: toolsTotal, activeCount: activeSet.size, registeredCount: tools.length, bySource },
|
|
1839
|
+
tools: { total: toolsTotal, activeCount: activeSet.size, registeredCount: tools.length, deferred: { count: deferredCount, tokens: deferredTokens }, bySource },
|
|
1830
1840
|
toolCosts,
|
|
1831
1841
|
skills: { total: sections.skills ?? 0, count: countSkills(skillsRaw) },
|
|
1832
1842
|
memoryFiles: {
|
|
@@ -1898,7 +1908,7 @@ export function renderContextPanel(b: ContextBreakdown): string[] {
|
|
|
1898
1908
|
for (const name of sectionNames) lines.push(` ${name}: ${k(b.systemPrompt.sections[name])}`);
|
|
1899
1909
|
}
|
|
1900
1910
|
if (b.toolCosts.length > 0) {
|
|
1901
|
-
lines.push("", `Tools (${b.tools.
|
|
1911
|
+
lines.push("", `Tools (${b.tools.activeCount} active · ${k(b.tools.total)} tokens in prompt${b.tools.deferred.count > 0 ? ` · ${b.tools.deferred.count} deferred not in prompt (${k(b.tools.deferred.tokens)})` : ""}):`);
|
|
1902
1912
|
for (const t of b.toolCosts.slice(0, 5)) lines.push(` ${t.name}: ${k(t.tokens)}`);
|
|
1903
1913
|
const top = Object.entries(b.tools.bySource).sort((x, y) => y[1].tokens - x[1].tokens).slice(0, 3);
|
|
1904
1914
|
for (const [src, s] of top) lines.push(` ${shortSource(src)}: ${k(s.tokens)} · ${s.count} tool${s.count === 1 ? "" : "s"}`);
|
|
@@ -161,12 +161,16 @@ test("computeContextBreakdown splits sections, groups tools by source, reserves
|
|
|
161
161
|
assert.equal(b.systemPrompt.sections.preamble, 100);
|
|
162
162
|
assert.equal(b.systemPrompt.sections.project_context, 2000);
|
|
163
163
|
assert.equal(b.systemPrompt.sections.rules, undefined);
|
|
164
|
-
// Tools: (400
|
|
164
|
+
// Tools: (400+~20)/4=105, (800+~40)/4=210, 800/4=201. Only the two
|
|
165
|
+
// ACTIVE tools count toward the prompt; web_extract (inactive) is deferred.
|
|
165
166
|
assert.equal(b.tools.registeredCount, 3);
|
|
166
167
|
assert.equal(b.tools.activeCount, 2);
|
|
167
|
-
assert.equal(b.tools.
|
|
168
|
+
assert.equal(b.tools.deferred.count, 1);
|
|
169
|
+
assert.equal(b.tools.deferred.tokens, 201);
|
|
170
|
+
assert.equal(b.tools.bySource["@bacnh85/pi-web"].count, 1);
|
|
168
171
|
assert.equal(b.tools.bySource.pi.count, 1);
|
|
169
172
|
assert.equal(b.tools.total, b.tools.bySource.pi.tokens + b.tools.bySource["@bacnh85/pi-web"].tokens);
|
|
173
|
+
assert.equal(b.tools.total, 105 + 210);
|
|
170
174
|
// Skills parsed from the skills section.
|
|
171
175
|
assert.equal(b.skills.count, 2);
|
|
172
176
|
assert.ok(b.skills.total > 0 && b.skills.total < 300);
|
|
@@ -177,7 +181,7 @@ test("computeContextBreakdown splits sections, groups tools by source, reserves
|
|
|
177
181
|
assert.equal(b.messages.count, 2);
|
|
178
182
|
assert.equal(b.messages.total, 50 + 100);
|
|
179
183
|
// Per-tool costs, descending (powers the top-tools list).
|
|
180
|
-
assert.deepEqual(b.toolCosts.map((t) => t.name), ["web_search", "
|
|
184
|
+
assert.deepEqual(b.toolCosts.map((t) => t.name), ["web_search", "read"]);
|
|
181
185
|
// Reserved is the compaction slice only; free space excludes it (pi's trigger:
|
|
182
186
|
// tokens > window - reserveTokens). Model output is NOT reserved.
|
|
183
187
|
assert.deepEqual(b.reserved, { compaction: 16384 });
|
|
@@ -258,18 +262,25 @@ test("renderContextPanel lays the legend beside a 20x10 grid (OMP geometry)", ()
|
|
|
258
262
|
});
|
|
259
263
|
|
|
260
264
|
test("renderContextPanel fires recommendations above thresholds", () => {
|
|
261
|
-
// Tiny-ish window so the
|
|
262
|
-
const b = computeContextBreakdown(fixtureInput({ ctx: fixtureCtx(), model: { maxTokens: 8192, contextWindow:
|
|
265
|
+
// Tiny-ish window so the 315-token active-tool fixture crosses the 40% recommendation threshold.
|
|
266
|
+
const b = computeContextBreakdown(fixtureInput({ ctx: fixtureCtx(), model: { maxTokens: 8192, contextWindow: 700 } }));
|
|
263
267
|
const lines = renderContextPanel(b);
|
|
264
|
-
assert.ok(lines.some((l) => l.includes("5.0K/
|
|
268
|
+
assert.ok(lines.some((l) => l.includes("5.0K/700 tokens (714.3%)")), lines.join("\n"));
|
|
265
269
|
assert.ok(lines.some((l) => l.includes("pi-web:")), lines.join("\n"));
|
|
266
270
|
assert.ok(!lines.some((l) => l.includes("@bacnh85/")), "package labels are shortened");
|
|
267
271
|
assert.ok(lines.some((l) => l.includes("project_context: 2.0K")));
|
|
268
|
-
// tools (
|
|
272
|
+
// active tools (317) > 40% of the 700-token window → recommendation fires.
|
|
269
273
|
assert.ok(lines.some((l) => l.startsWith("- ") && l.includes("setActiveTools")), lines.join("\n"));
|
|
270
274
|
assert.ok(!lines.some((l) => l.includes("trimming AGENTS.md")));
|
|
271
275
|
});
|
|
272
276
|
|
|
277
|
+
test("renderContextPanel discloses the deferred tier separately", () => {
|
|
278
|
+
const b = computeContextBreakdown(fixtureInput());
|
|
279
|
+
const lines = renderContextPanel(b);
|
|
280
|
+
assert.ok(lines.some((l) => l.includes("2 active ·") && l.includes("tokens in prompt")), lines.join("\n"));
|
|
281
|
+
assert.ok(lines.some((l) => l.includes("1 deferred not in prompt (201)")), lines.join("\n"));
|
|
282
|
+
});
|
|
283
|
+
|
|
273
284
|
test("renderContextPanel fires memory + skills recommendations above thresholds", () => {
|
|
274
285
|
const ctx = fixtureCtx();
|
|
275
286
|
const big = "m".repeat(4 * 4000); // 4000 tokens
|
|
@@ -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(
|
|
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",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// ceulen integration contract:
|
|
2
|
-
//
|
|
3
|
-
//
|
|
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: {
|
|
20
|
-
const tools: Record<string, { name: string
|
|
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("
|
|
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.
|
|
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)", () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ceulen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
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",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@earendil-works/pi-coding-agent": ">=0.99.1 <1.
|
|
56
|
-
"@earendil-works/pi-tui": ">=0.99.1 <1.
|
|
55
|
+
"@earendil-works/pi-coding-agent": ">=0.99.1 <1.2.0",
|
|
56
|
+
"@earendil-works/pi-tui": ">=0.99.1 <1.2.0",
|
|
57
57
|
"typebox": "*"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
package/extensions/lib/tools.ts
DELETED
|
@@ -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
|
-
}
|