ceulen 0.10.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +107 -1
- package/README.md +56 -1
- package/extensions/index.ts +5 -1
- package/extensions/lib/env.test.ts +147 -0
- package/extensions/lib/env.ts +180 -0
- package/extensions/lib/order.test.ts +74 -0
- package/extensions/lib/plan-bridge.ts +18 -0
- package/extensions/lib/registry.test.ts +8 -5
- package/extensions/lib/registry.ts +22 -3
- package/extensions/modules/a2a/configPanel.ts +42 -1
- package/extensions/modules/a2a/index.ts +4 -2
- package/extensions/modules/a2a/lib/config.ts +8 -3
- package/extensions/modules/a2a/test/configPanel.test.ts +7 -4
- package/extensions/modules/advisor/index.ts +6 -3
- package/extensions/modules/advisor/test/module.test.ts +31 -0
- package/extensions/modules/attachments/configPanel.ts +91 -0
- package/extensions/modules/attachments/index.ts +274 -0
- package/extensions/modules/attachments/lib/clipboard-files.ts +80 -0
- package/extensions/modules/attachments/lib/pastes.ts +45 -0
- package/extensions/modules/attachments/lib/paths.ts +74 -0
- package/extensions/modules/attachments/lib/registry.ts +70 -0
- package/extensions/modules/attachments/lib/settings.ts +99 -0
- package/extensions/modules/attachments/lib/tray.ts +74 -0
- package/extensions/modules/attachments/test/configPanel.test.ts +122 -0
- package/extensions/modules/attachments/test/index.test.ts +870 -0
- package/extensions/modules/attachments/test/module.test.ts +53 -0
- package/extensions/modules/classifier/index.ts +55 -1
- package/extensions/modules/classifier/test/classifier.test.ts +62 -0
- package/extensions/modules/composer/test/module.test.ts +2 -2
- package/extensions/modules/config/index.ts +3 -0
- package/extensions/modules/config/test/renderTools.test.ts +1 -1
- package/extensions/modules/cron/configPanel.ts +103 -0
- package/extensions/modules/cron/index.ts +638 -0
- package/extensions/modules/cron/lib/jobs.ts +201 -0
- package/extensions/modules/cron/lib/schedule.ts +161 -0
- package/extensions/modules/cron/test/cwd-repro.test.ts +98 -0
- package/extensions/modules/cron/test/index.test.ts +859 -0
- package/extensions/modules/cron/test/schedule.test.ts +93 -0
- package/extensions/modules/munin/index.ts +3 -1
- package/extensions/modules/permission/index.ts +567 -0
- package/extensions/modules/permission/test/permission.test.ts +789 -0
- package/extensions/modules/plan/index.ts +5 -0
- package/extensions/modules/repair/index.ts +160 -5
- package/extensions/modules/repair/test/freshness.test.ts +209 -0
- package/extensions/modules/repair/test/guard-selector.test.ts +67 -0
- package/extensions/modules/router/configPanel.ts +4 -4
- package/extensions/modules/router/index.ts +1 -1
- package/extensions/modules/router/lib/config.ts +9 -4
- package/extensions/modules/router/lib/systemone.ts +17 -4
- package/extensions/modules/router/test/unit.test.ts +46 -1
- package/extensions/modules/rules/index.ts +13 -3
- package/extensions/modules/rules/lib/rules.ts +24 -12
- package/extensions/modules/rules/test/lib.test.ts +20 -0
- package/extensions/modules/rules/test/module.test.ts +21 -0
- package/extensions/modules/subagent/index.ts +49 -10
- package/extensions/modules/subagent/lib/herdr.ts +5 -0
- package/extensions/modules/subagent/lib/routing.ts +31 -8
- package/extensions/modules/subagent/lib/runner.ts +356 -14
- package/extensions/modules/subagent/test/routing.test.ts +45 -0
- package/extensions/modules/subagent/test/worktree.test.ts +230 -0
- package/extensions/modules/usage/index.ts +193 -71
- package/extensions/modules/usage/test/context.test.ts +160 -120
- package/extensions/modules/web/configPanel.ts +67 -8
- package/extensions/modules/web/index.ts +3 -1
- package/extensions/modules/web/test/a11y.test.ts +1 -1
- package/extensions/modules/web/test/configPanel.test.ts +7 -3
- package/extensions/modules/web/test/settings.test.ts +6 -0
- package/package.json +2 -2
- package/skills/cron/SKILL.md +58 -0
|
@@ -53,15 +53,18 @@ describe("MODULES load order", () => {
|
|
|
53
53
|
// rewriter (its ds-anchor bootstrap REPLACES the final prompt; a rewriter
|
|
54
54
|
// loaded after it would append to the byte-identical minimal prompt, which
|
|
55
55
|
// is exactly what serena/web used to do) and ahead of the non-rewriters
|
|
56
|
-
// (
|
|
57
|
-
// steering: munin, advisor, ux, ponytail, subagent, plan, fff, serena, web
|
|
58
|
-
// — web is the last of them, hence the anchor below.
|
|
59
|
-
|
|
56
|
+
// (config). Modules registering before_agent_start and loading BEFORE
|
|
57
|
+
// steering: munin, advisor, ux, ponytail, subagent, plan, fff, serena, web,
|
|
58
|
+
// rules, rtk — web is the last of them, hence the anchor below. rtk IS a
|
|
59
|
+
// prompt rewriter (its before_agent_start appends the RTK note), so it must
|
|
60
|
+
// sit before steering or the ds-anchor bootstrap loses byte-identity.
|
|
61
|
+
it("steering is the last prompt rewriter, after rtk, before config", async () => {
|
|
60
62
|
const { MODULES } = await import("./registry.js");
|
|
61
63
|
const at = (name: string) => MODULES.findIndex((m) => m.name === name);
|
|
62
64
|
assert.ok(at("steering") > at("web"), "steering loads after the last rewriter (web)");
|
|
63
65
|
assert.ok(at("steering") > at("serena") && at("steering") > at("plan"));
|
|
64
|
-
assert.ok(at("steering")
|
|
66
|
+
assert.ok(at("steering") > at("rtk"), "rtk (a prompt rewriter) loads before steering");
|
|
67
|
+
assert.ok(at("steering") > at("rules"), "rules (prompt composer) loads before steering");
|
|
65
68
|
assert.equal(MODULES.at(-1)!.name, "config", "config stays last");
|
|
66
69
|
});
|
|
67
70
|
});
|
|
@@ -45,6 +45,11 @@ import { webConfig } from "../modules/web/configPanel.ts";
|
|
|
45
45
|
import ghModule from "../modules/gh/index.ts";
|
|
46
46
|
import { ghConfig } from "../modules/gh/configPanel.js";
|
|
47
47
|
import rulesModule from "../modules/rules/index.ts";
|
|
48
|
+
import attachmentsModule from "../modules/attachments/index.ts";
|
|
49
|
+
import { attachmentsConfig } from "../modules/attachments/configPanel.ts";
|
|
50
|
+
import cronModule from "../modules/cron/index.ts";
|
|
51
|
+
import { cronConfig } from "../modules/cron/configPanel.ts";
|
|
52
|
+
import permissionModule from "../modules/permission/index.ts";
|
|
48
53
|
import configModule from "../modules/config/index.ts";
|
|
49
54
|
|
|
50
55
|
/** A module's contribution to the central `/config` panel. */
|
|
@@ -132,6 +137,9 @@ export const MODULES: ModuleEntry[] = [
|
|
|
132
137
|
// child sessions reuse the host-only session guards in the module.
|
|
133
138
|
{ name: "a2a", category: "Tasks", describe: "A2A Protocol v1.0 peer: call remote agents (a2a_call…), be called by them (opt-in inbound server), local/mDNS/gateway discovery.", load: a2aModule, config: a2aConfig, tools: ["a2a_call", "a2a_status", "a2a_discover", "a2a_list", "a2a_history", "a2a_orchestrate", "a2a_peers"] },
|
|
134
139
|
{ name: "todo", category: "Tasks", describe: "Phased task board: the `todo` tool (init/start/done/block/unblock) with session persistence, blockers, an above-editor HUD, and a status-segment progress readout.", load: todoModule, config: todoConfig, tools: ["todo"] },
|
|
140
|
+
// Cron after todo: scheduled prompts into the live session (the clock-driven
|
|
141
|
+
// sibling of the task board). No before_agent_start → no ordering constraint.
|
|
142
|
+
{ name: "cron", category: "Tasks", describe: "Scheduled jobs firing prompts into the live session: add/remove/list/run/enable/disable/test/logs/export, headless pinned runs, crontab export.", load: cronModule, config: cronConfig, tools: ["cron"] },
|
|
135
143
|
// ── Tools ─────────────────────────────────────────────────────────────
|
|
136
144
|
// Repair first in the section: it wraps the built-in tools; serena/fff ride
|
|
137
145
|
// on top (no load-order dependency — hooks resolve at call time).
|
|
@@ -155,10 +163,17 @@ export const MODULES: ModuleEntry[] = [
|
|
|
155
163
|
"web_search", "web_extract", "web_map", "web_crawl", "web_screenshot", "web_pdf", "web_interact", "web_research", "web_image", "web_chat", "web_status", "web_a11y",
|
|
156
164
|
] },
|
|
157
165
|
{ name: "rules", category: "Context", describe: "Sticky RULES.md constraints carried in every request + a rulebook of on-demand rules served by rule_get. Nearest-first project walk over user-level.", load: rulesModule, tools: ["rule_get"] },
|
|
166
|
+
// Attachments: paste/drop files become real attachments. No tools/commands —
|
|
167
|
+
// input hook + widget + shortcut only; no load-order constraint.
|
|
168
|
+
{ name: "attachments", category: "Files", describe: "Real attachments from pasted/dropped files: [[attach:]] tokens + 📎 chips, image ImageContent parts, large-paste collapse, clipboard file paste.", load: attachmentsModule, config: attachmentsConfig },
|
|
158
169
|
// gh after web: same class of external-fetch tooling; fail-open on a missing
|
|
159
170
|
// gh binary (registers nothing until installed). Read-only ops only, so
|
|
160
171
|
// plan mode auto-allows it (plan-tools.ts READ_ONLY_TOOLS).
|
|
161
172
|
{ name: "gh", category: "Tools", describe: "GitHub tool over the gh CLI: repo/file/PR views, PR diff, five search flavors, Actions run_watch. Read-only; mutating flows stay on bash gh.", load: ghModule, config: ghConfig, tools: ["github"] },
|
|
173
|
+
// rtk is a PROMPT REWRITER (its before_agent_start appends the RTK note), so
|
|
174
|
+
// it must load BEFORE steering — during a ds-anchor bootstrap, steering's
|
|
175
|
+
// minimal prompt replaces everything, including this note (byte-identity);
|
|
176
|
+
// on the normal path steering composes onto it.
|
|
162
177
|
// Steering LAST of the prompt rewriters, i.e. after EVERY before_agent_start
|
|
163
178
|
// composer (ponytail/plan/subagent/munin/advisor/ux/fff/serena/web/rules) and
|
|
164
179
|
// before the config module (load order is load-bearing even though its
|
|
@@ -166,11 +181,15 @@ export const MODULES: ModuleEntry[] = [
|
|
|
166
181
|
// independently): pi chains before_agent_start results, so steering must run
|
|
167
182
|
// LAST for its deepseek-v4-pro anchor bootstrap to REPLACE the final prompt
|
|
168
183
|
// (byte-identical minimal prompt) instead of appending to a prompt that
|
|
169
|
-
// serena/web then append to.
|
|
170
|
-
//
|
|
184
|
+
// serena/web/rtk then append to. rtk (a prompt rewriter — it appends the
|
|
185
|
+
// RTK note) loads BEFORE this entry; nothing after steering touches the
|
|
186
|
+
// prompt — do not move rtk back after it or add a prompt rewriter here.
|
|
187
|
+
{ name: "rtk", category: "Shell", describe: "Route shell commands through RTK for token savings.", load: rtkModule },
|
|
171
188
|
{ name: "steering", category: "Model", describe: "Per-model-family steering (DeepSeek/GLM): first-tool hints, reasoning strip, leak cleaning, error recovery hints, DeepSeek guidance + v4-pro minimal-mode anchor.", load: steeringModule, config: steeringConfig, tools: ["think"] },
|
|
172
189
|
// ── Shell ──────────────────────────────────────────────────────────────
|
|
173
|
-
|
|
190
|
+
// Permission after rtk: persistent allow/ask/deny gating. Inert until rules
|
|
191
|
+
// exist; defers to plan mode via the shared plan-bridge flag (order-free).
|
|
192
|
+
{ name: "permission", category: "Shell", describe: "Persistent allow/ask/deny permission rules per tool (wildcards, external-directory boundary, doom-loop guard) — opt-in via the `permission` settings section; inert until configured.", load: permissionModule },
|
|
174
193
|
// ── Plugins ────────────────────────────────────────────────────────────
|
|
175
194
|
// Config last: it owns /config and reads the contrib map. CORE: the panel is
|
|
176
195
|
// the only in-app way back from a misconfiguration — it can never be the
|
|
@@ -29,6 +29,13 @@ import {
|
|
|
29
29
|
type Peer,
|
|
30
30
|
} from "./lib/config.js";
|
|
31
31
|
import { a2aServerRunning as a2aServerRunningIndex, restartA2AServer as restartA2AServerIndex } from "./index.js";
|
|
32
|
+
import { writeSecretEnvs } from "../../lib/env.js";
|
|
33
|
+
|
|
34
|
+
/** Env var name for one gateway secret (per-key diversion). */
|
|
35
|
+
function gatewayTokenEnv(key: string, field: "token" | "upstreamToken"): string {
|
|
36
|
+
const keyEnv = key.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
|
|
37
|
+
return field === "token" ? `A2A_GATEWAY_${keyEnv}_TOKEN` : `A2A_GATEWAY_${keyEnv}_UPSTREAM_TOKEN`;
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
/** Restart bridge — defaults to the index.ts exports; tests inject via
|
|
34
41
|
* __setRestartBridgeForTests (the panel must not spin real servers). */
|
|
@@ -380,10 +387,43 @@ export function a2aConfig(pi: ExtensionAPI): ModuleConfig {
|
|
|
380
387
|
gatewayChanged,
|
|
381
388
|
editedGatewayKeys,
|
|
382
389
|
});
|
|
390
|
+
// SECRETS DIVERSION: gateway tokens never persist in settings.json.
|
|
391
|
+
// Tokens the user actually edited → .env.local (0600, ingested at
|
|
392
|
+
// startup, env wins at read time); the loader's per-key env fallback
|
|
393
|
+
// (config.ts) resolves them at read time. The settings patch keeps
|
|
394
|
+
// every non-secret field (URL, name, heartbeat, enabled).
|
|
395
|
+
const secretEnvs: Record<string, string> = {};
|
|
396
|
+
const diverted = (patch: (a2a: any) => any): (a2a: any) => any => (a2a: any) => {
|
|
397
|
+
const out = patch(a2a);
|
|
398
|
+
if (out?.discovery && typeof out.discovery === "object") {
|
|
399
|
+
const scrub = (entry: Record<string, any>, key: string | null, editedToken: boolean, editedUpstream: boolean) => {
|
|
400
|
+
if (editedToken && entry.token) {
|
|
401
|
+
secretEnvs[key ? gatewayTokenEnv(key, "token") : "A2A_GATEWAY_TOKEN"] = String(entry.token);
|
|
402
|
+
entry.token = "";
|
|
403
|
+
}
|
|
404
|
+
if (editedUpstream && entry.upstreamToken) {
|
|
405
|
+
secretEnvs[key ? gatewayTokenEnv(key, "upstreamToken") : "A2A_GATEWAY_UPSTREAM_TOKEN"] = String(entry.upstreamToken);
|
|
406
|
+
entry.upstreamToken = undefined;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
if (out.discovery.gateway && typeof out.discovery.gateway === "object") {
|
|
410
|
+
scrub(out.discovery.gateway, null, editedGatewayKeys.has("gateway.token"), editedGatewayKeys.has("gateway.upstreamToken"));
|
|
411
|
+
}
|
|
412
|
+
if (out.discovery.gateways && typeof out.discovery.gateways === "object") {
|
|
413
|
+
for (const [k, entry] of Object.entries(out.discovery.gateways as Record<string, any>)) {
|
|
414
|
+
if (entry && typeof entry === "object") {
|
|
415
|
+
scrub(entry, k, editedGatewayKeys.has(`gw.${k}.token`), editedGatewayKeys.has(`gw.${k}.upstreamToken`));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return out;
|
|
421
|
+
};
|
|
383
422
|
const written = writeSettingsA2A({
|
|
384
423
|
cwd: ctx.cwd,
|
|
385
|
-
patch: builtPatch,
|
|
424
|
+
patch: diverted(builtPatch),
|
|
386
425
|
});
|
|
426
|
+
const savedSecrets = Object.keys(secretEnvs).length > 0 ? writeSecretEnvs(secretEnvs) : [];
|
|
387
427
|
|
|
388
428
|
// Live apply — config is read per call; no /reload needed.
|
|
389
429
|
setConfigOverrides({
|
|
@@ -395,6 +435,7 @@ export function a2aConfig(pi: ExtensionAPI): ModuleConfig {
|
|
|
395
435
|
});
|
|
396
436
|
|
|
397
437
|
const notes = [`A2A config saved to ${written} — applied live.`];
|
|
438
|
+
if (savedSecrets.length) notes.push(`Gateway token(s) saved to .env.local (${savedSecrets.length}) — never settings.json.`);
|
|
398
439
|
// Env overrides still shadowing edited fields.
|
|
399
440
|
const envOverrides = [...edited]
|
|
400
441
|
.map((k) => (k.startsWith("a2a.") ? ENV_SHADOW[k.slice("a2a.".length)] : undefined))
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { homedir } from "node:os";
|
|
16
|
-
import { chmodSync
|
|
16
|
+
import { chmodSync } from "node:fs";
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
19
19
|
import { Type } from "typebox";
|
|
@@ -547,7 +547,9 @@ export default function a2aExtension(pi: ExtensionAPI): void {
|
|
|
547
547
|
// resources_discover — NOT via the package.json pi.skills manifest — so the
|
|
548
548
|
// kill-switch gates it too (web module pattern).
|
|
549
549
|
pi.on("resources_discover", () => {
|
|
550
|
-
|
|
550
|
+
// skillsRoot() is already a native absolute path (fileURLToPath) — no
|
|
551
|
+
// realpath needed; a throw here would kill the whole module load.
|
|
552
|
+
return { skillPaths: [join(skillsRoot(), "a2a")] };
|
|
551
553
|
});
|
|
552
554
|
|
|
553
555
|
pi.registerTool({
|
|
@@ -503,7 +503,9 @@ export function loadConfig(opts: {
|
|
|
503
503
|
url: gwUrl,
|
|
504
504
|
token: gwToken,
|
|
505
505
|
name: dg.name ? String(dg.name) : undefined,
|
|
506
|
-
|
|
506
|
+
// Secrets live in .env.local (panel diversion) — env fallback keeps
|
|
507
|
+
// settings.json free of tokens while the value still resolves.
|
|
508
|
+
upstreamToken: dg.upstreamToken != null ? String(dg.upstreamToken) : (env.A2A_GATEWAY_UPSTREAM_TOKEN || undefined),
|
|
507
509
|
heartbeatSec: num(dg.heartbeatSec, 60),
|
|
508
510
|
channel: dg.channel === undefined ? undefined : bool(dg.channel, true),
|
|
509
511
|
};
|
|
@@ -518,15 +520,18 @@ export function loadConfig(opts: {
|
|
|
518
520
|
if (!GATEWAY_KEY_RE.test(key)) continue;
|
|
519
521
|
if (!raw || typeof raw !== "object") continue;
|
|
520
522
|
const g = raw as Record<string, any>;
|
|
523
|
+
// Per-gateway secret env names (panel diversion — tokens never persist
|
|
524
|
+
// in settings.json): A2A_GATEWAY_<KEY>_TOKEN / _UPSTREAM_TOKEN.
|
|
525
|
+
const keyEnv = key.toUpperCase().replace(/[^A-Z0-9_]/g, "_");
|
|
521
526
|
const u = String(g.url ?? "");
|
|
522
|
-
const t = String(g.token ?? "");
|
|
527
|
+
const t = String(g.token ?? env[`A2A_GATEWAY_${keyEnv}_TOKEN`] ?? "");
|
|
523
528
|
const enabled = g.enabled !== undefined ? bool(g.enabled, true) : Boolean(u && t);
|
|
524
529
|
gateways[key] = {
|
|
525
530
|
enabled,
|
|
526
531
|
url: u,
|
|
527
532
|
token: t,
|
|
528
533
|
name: g.name ? String(g.name) : undefined,
|
|
529
|
-
upstreamToken: g.upstreamToken ? String(g.upstreamToken) : undefined,
|
|
534
|
+
upstreamToken: g.upstreamToken != null ? String(g.upstreamToken) : (env[`A2A_GATEWAY_${keyEnv}_UPSTREAM_TOKEN`] || undefined),
|
|
530
535
|
heartbeatSec: num(g.heartbeatSec, 60),
|
|
531
536
|
channel: g.channel === undefined ? undefined : bool(g.channel, true),
|
|
532
537
|
};
|
|
@@ -277,7 +277,7 @@ describe("configPanel contribution", () => {
|
|
|
277
277
|
);
|
|
278
278
|
});
|
|
279
279
|
|
|
280
|
-
it("gateway token: an EDITED token
|
|
280
|
+
it("gateway token: an EDITED token diverts to .env.local — never settings.json; unrelated edits touch nothing", async () => {
|
|
281
281
|
await withoutA2AEnv(() =>
|
|
282
282
|
withIsolatedPiDir(async (dir) => {
|
|
283
283
|
// Operator has a gateway configured in the GLOBAL file (env-sourced token case:
|
|
@@ -302,16 +302,19 @@ describe("configPanel contribution", () => {
|
|
|
302
302
|
hb.set(90);
|
|
303
303
|
await (cfg.save as SaveFn)(new Set(["a2a.gw.work.heartbeatSec"]), ctx);
|
|
304
304
|
let written = JSON.parse(fs.readFileSync(globalSettings, "utf-8"));
|
|
305
|
-
assert.equal(written.a2a.discovery.gateways.work.token, "file-token", "unedited token survives an unrelated edit");
|
|
305
|
+
assert.equal(written.a2a.discovery.gateways.work.token, "file-token", "unedited token survives an unrelated edit (legacy value untouched)");
|
|
306
306
|
|
|
307
|
-
// Now edit the token itself →
|
|
307
|
+
// Now edit the token itself → diverts to .env.local, scrubbed from settings.json.
|
|
308
308
|
const cfg2 = a2aConfig({} as never);
|
|
309
309
|
cfg2.groups();
|
|
310
310
|
const tok = rowsOf(cfg2.groups()).find((r) => r.key === "a2a.gw.work.token")!;
|
|
311
311
|
tok.set("rotated-token");
|
|
312
312
|
await (cfg2.save as SaveFn)(new Set(["a2a.gw.work.token"]), ctx);
|
|
313
313
|
written = JSON.parse(fs.readFileSync(globalSettings, "utf-8"));
|
|
314
|
-
assert.
|
|
314
|
+
assert.ok(!written.a2a.discovery.gateways.work.token, "edited token must NOT persist in settings.json");
|
|
315
|
+
const envLocal = fs.readFileSync(path.join(process.env.PI_CODING_AGENT_DIR!, ".env.local"), "utf-8");
|
|
316
|
+
assert.match(envLocal, /A2A_GATEWAY_WORK_TOKEN=rotated-token/, "edited token diverted to .env.local");
|
|
317
|
+
assert.equal(process.env.A2A_GATEWAY_WORK_TOKEN, "rotated-token", "live session resolves the diverted token immediately");
|
|
315
318
|
}),
|
|
316
319
|
);
|
|
317
320
|
});
|
|
@@ -89,7 +89,6 @@ export default function advisorModule(pi: ExtensionAPI): void {
|
|
|
89
89
|
// watchEnabled is only updated at the end of this function.
|
|
90
90
|
const willWatch = masterChanged ? next.enabled : watchEnabled;
|
|
91
91
|
const rt = runtime;
|
|
92
|
-
const wasEmpty = !rt || rt.models.length === 0;
|
|
93
92
|
if (rt) {
|
|
94
93
|
rt.config = next;
|
|
95
94
|
rt.models = next.models;
|
|
@@ -98,8 +97,12 @@ export default function advisorModule(pi: ExtensionAPI): void {
|
|
|
98
97
|
rt.stats.paused = false;
|
|
99
98
|
rt.failures = 0;
|
|
100
99
|
}
|
|
101
|
-
// Enabling mid-session must not replay history
|
|
102
|
-
|
|
100
|
+
// Enabling mid-session must not replay history: reseed on FIRST
|
|
101
|
+
// activation (cursor still undefined), which covers BOTH the 0→N chain
|
|
102
|
+
// transition and the enable-only save on a session that started with
|
|
103
|
+
// enabled:false + a configured chain (a no-chain or disabled session
|
|
104
|
+
// never seeds the cursor, so `undefined` is exactly "not yet active").
|
|
105
|
+
if (willWatch && rt.models.length > 0 && rt.cursor === undefined) reseedCursor(rt, ctx);
|
|
103
106
|
}
|
|
104
107
|
// An explicit master change re-arms/disarms the session; otherwise a
|
|
105
108
|
// /advisor watch-off override stays in place.
|
|
@@ -261,6 +261,37 @@ describe("advisor module wiring", () => {
|
|
|
261
261
|
await fire(pi, state, "agent_settled", step(available(fakeCtx(entries)), "tui"));
|
|
262
262
|
assert.equal(calls, 0, "nothing new since the reseed → no review of the pre-existing turn");
|
|
263
263
|
});
|
|
264
|
+
|
|
265
|
+
it("session_start(review off, chain configured) + enable-only save reseeds the cursor (no history replay)", async () => {
|
|
266
|
+
// Live-found defect (reviewer 2026-10-06): the reseed keyed on the 0→N
|
|
267
|
+
// chain transition, so enabling `Review settled turns` on a session that
|
|
268
|
+
// STARTED with enabled:false + a configured chain left cursor undefined —
|
|
269
|
+
// the first settled turn counted the ENTIRE session's tool calls and
|
|
270
|
+
// reviewed the whole transcript. The reseed must key on first activation.
|
|
271
|
+
const { pi, state } = createFakePi();
|
|
272
|
+
advisorModule(pi);
|
|
273
|
+
writeSettings({ advisor: { enabled: false, models: [MODEL] } });
|
|
274
|
+
let ctx = available(fakeCtx(toolCalls(4)));
|
|
275
|
+
await fire(pi, state, "session_start", ctx);
|
|
276
|
+
const rt = __getRuntimeForTest();
|
|
277
|
+
assert.ok(rt, "runtime created");
|
|
278
|
+
assert.equal(rt!.models.length, 1, "chain was configured all along");
|
|
279
|
+
assert.equal(rt!.cursor, undefined, "review off at start → cursor never seeded");
|
|
280
|
+
|
|
281
|
+
// Enable ONLY the review — the chain is untouched.
|
|
282
|
+
const entries = toolCalls(4);
|
|
283
|
+
ctx = available(fakeCtx(entries));
|
|
284
|
+
const m = advisorConfig();
|
|
285
|
+
m.groups()[0]!.rows[0]!.set(true);
|
|
286
|
+
await m.save(new Set(["advisor.enabled"]), ctx);
|
|
287
|
+
|
|
288
|
+
assert.equal(rt!.cursor, entries.at(-1).id, "enable-only save reseeds to the tail — history is not replayed");
|
|
289
|
+
|
|
290
|
+
let calls = 0;
|
|
291
|
+
__setIsolatedForTest(async (_c, models) => { calls++; return { text: "", model: models[0], usage: NO_USAGE }; });
|
|
292
|
+
await fire(pi, state, "agent_settled", step(available(fakeCtx(entries)), "tui"));
|
|
293
|
+
assert.equal(calls, 0, "no new work since enable → no review");
|
|
294
|
+
});
|
|
264
295
|
});
|
|
265
296
|
|
|
266
297
|
describe("advisor review flow", () => {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* attachments' /config contribution — Files tab, Attachments section.
|
|
3
|
+
*
|
|
4
|
+
* Rows write the GLOBAL agent-dir settings.json `attachments` section
|
|
5
|
+
* (lib/settings.ts — the same file the module re-reads on session_start, so a
|
|
6
|
+
* save applies to the NEXT session without /reload; the paste-file shortcut
|
|
7
|
+
* additionally binds at module load and needs a full restart).
|
|
8
|
+
*/
|
|
9
|
+
import { row, type PanelGroup } from "../../lib/panel.js";
|
|
10
|
+
import type { ModuleConfig } from "../../lib/registry.js";
|
|
11
|
+
import { DEFAULTS, loadSettings, writeAttachmentsSection, type AttachmentsSettings } from "./lib/settings.js";
|
|
12
|
+
|
|
13
|
+
/** Build the attachments panel groups over a working copy (mutated by row
|
|
14
|
+
* setters). Exported for tests. */
|
|
15
|
+
export function buildAttachmentsGroups(cfg: AttachmentsSettings): PanelGroup[] {
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
key: "attachments",
|
|
19
|
+
label: "Attachments",
|
|
20
|
+
tab: "Files",
|
|
21
|
+
icon: "📎",
|
|
22
|
+
rows: [
|
|
23
|
+
row("attachments.inlineTextFiles", "Inline text files", "toggle", cfg.inlineTextFiles, (v) => {
|
|
24
|
+
cfg.inlineTextFiles = Boolean(v);
|
|
25
|
+
}, {
|
|
26
|
+
description: "Inline text-file paths as <file> content blocks instead of 📎 path chips — convenient, but re-read on every turn.",
|
|
27
|
+
defaultValue: DEFAULTS.inlineTextFiles,
|
|
28
|
+
}),
|
|
29
|
+
row("attachments.maxInlineBytes", "Max inline bytes", "number", cfg.maxInlineBytes, (v) => {
|
|
30
|
+
const n = Number(v);
|
|
31
|
+
if (Number.isFinite(n) && n > 0) cfg.maxInlineBytes = n;
|
|
32
|
+
}, {
|
|
33
|
+
description: "Size cap for text-file inlining (inline mode only). Larger files keep the 📎 path chip.",
|
|
34
|
+
defaultValue: DEFAULTS.maxInlineBytes,
|
|
35
|
+
}),
|
|
36
|
+
row("attachments.pasteFileShortcut", "Paste-file shortcut", "string", cfg.pasteFileShortcut, (v) => {
|
|
37
|
+
const s = String(v ?? "").trim();
|
|
38
|
+
if (s) cfg.pasteFileShortcut = s;
|
|
39
|
+
}, {
|
|
40
|
+
warning: "Takes effect after a full restart — the shortcut binds when the extension loads.",
|
|
41
|
+
description: "Keybinding for paste-file-from-clipboard (pi-tui KeyId grammar, e.g. alt+shift+v, ctrl+shift+v, f2).",
|
|
42
|
+
defaultValue: DEFAULTS.pasteFileShortcut,
|
|
43
|
+
}),
|
|
44
|
+
row("attachments.pasteCollapseLines", "Paste collapse lines", "number", cfg.pasteCollapseLines, (v) => {
|
|
45
|
+
const n = Number(v);
|
|
46
|
+
if (Number.isFinite(n) && n >= 0) cfg.pasteCollapseLines = n;
|
|
47
|
+
}, {
|
|
48
|
+
description: "Pastes with ≥ this many lines collapse to a paste file + one token. 0 disables.",
|
|
49
|
+
defaultValue: DEFAULTS.pasteCollapseLines,
|
|
50
|
+
}),
|
|
51
|
+
row("attachments.pasteCollapseChars", "Paste collapse chars", "number", cfg.pasteCollapseChars, (v) => {
|
|
52
|
+
const n = Number(v);
|
|
53
|
+
if (Number.isFinite(n) && n >= 0) cfg.pasteCollapseChars = n;
|
|
54
|
+
}, {
|
|
55
|
+
description: "Pastes with ≥ this many characters collapse even below the line threshold (minified JSON walls). 0 disables.",
|
|
56
|
+
defaultValue: DEFAULTS.pasteCollapseChars,
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const OWNED_PREFIX = "attachments.";
|
|
64
|
+
|
|
65
|
+
/** attachments' ModuleConfig for the central /config panel. */
|
|
66
|
+
export function attachmentsConfig(): ModuleConfig {
|
|
67
|
+
const before = loadSettings();
|
|
68
|
+
const working: AttachmentsSettings = { ...before };
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
groups: () => buildAttachmentsGroups(working),
|
|
72
|
+
save: async (edited, ctx) => {
|
|
73
|
+
const FIELDS: (keyof AttachmentsSettings)[] = [
|
|
74
|
+
"inlineTextFiles", "maxInlineBytes", "pasteFileShortcut", "pasteCollapseLines", "pasteCollapseChars",
|
|
75
|
+
];
|
|
76
|
+
const patch: Partial<AttachmentsSettings> = {};
|
|
77
|
+
for (const key of edited) {
|
|
78
|
+
if (!key.startsWith(OWNED_PREFIX)) continue;
|
|
79
|
+
const field = key.slice(OWNED_PREFIX.length) as keyof AttachmentsSettings;
|
|
80
|
+
if (FIELDS.includes(field)) (patch as Record<string, unknown>)[field] = working[field];
|
|
81
|
+
}
|
|
82
|
+
if (!Object.keys(patch).length) return;
|
|
83
|
+
try {
|
|
84
|
+
const file = writeAttachmentsSection(patch);
|
|
85
|
+
ctx.ui.notify(`Attachments settings saved to ${file} — applies next session (shortcut: full restart).`, "info");
|
|
86
|
+
} catch (e) {
|
|
87
|
+
ctx.ui.notify(`Attachments save failed: ${e instanceof Error ? e.message : e}`, "error");
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|