ceulen 0.19.0 → 0.23.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 +131 -0
- package/extensions/lib/env.test.ts +45 -0
- package/extensions/lib/env.ts +56 -3
- package/extensions/lib/skill-path.test.ts +1 -1
- package/extensions/modules/a2a/lib/gateway.ts +3 -0
- package/extensions/modules/a2a/lib/persistence.ts +3 -2
- package/extensions/modules/a2a/test/persistence.test.ts +12 -0
- package/extensions/modules/classifier/index.ts +12 -1
- package/extensions/modules/classifier/lib/settings.ts +21 -0
- package/extensions/modules/classifier/lib/think-gate.ts +211 -0
- package/extensions/modules/classifier/test/classifier.test.ts +285 -1
- package/extensions/modules/config/piSettings.ts +6 -0
- package/extensions/modules/config/test/piSettings.test.ts +9 -0
- package/extensions/modules/cron/index.ts +1 -0
- package/extensions/modules/cron/lib/jobs.ts +2 -1
- package/extensions/modules/cron/test/cwd-repro.test.ts +10 -1
- package/extensions/modules/jfind/index.ts +13 -4
- package/extensions/modules/jfind/lib/cascade.ts +5 -2
- package/extensions/modules/jfind/lib/tree.ts +8 -3
- package/extensions/modules/jfind/test/cascade.test.ts +28 -1
- package/extensions/modules/munin/configPanel.ts +13 -3
- package/extensions/modules/munin/index.ts +7 -4
- package/extensions/modules/munin/test/configPanel.test.ts +9 -3
- package/extensions/modules/munin/test/extension.test.ts +31 -0
- package/extensions/modules/permission/index.ts +20 -9
- package/extensions/modules/permission/test/permission.test.ts +33 -1
- package/extensions/modules/plan/index.ts +36 -7
- package/extensions/modules/plan/lib/shell-gate.ts +93 -26
- package/extensions/modules/plan/test/module.test.ts +114 -1
- package/extensions/modules/plan/test/shell-gate.test.ts +64 -0
- package/extensions/modules/repair/lib/guards.ts +4 -1
- package/extensions/modules/repair/test/guards.test.ts +9 -0
- package/extensions/modules/router/lib/client.ts +24 -0
- package/extensions/modules/router/test/unit.test.ts +33 -3
- package/extensions/modules/sg/index.ts +3 -3
- package/extensions/modules/sg/lib/ops.ts +15 -1
- package/extensions/modules/sg/test/sg.test.ts +16 -2
- package/extensions/modules/subagent/index.ts +12 -1
- package/extensions/modules/subagent/lib/herdr.ts +37 -3
- package/extensions/modules/subagent/lib/history.ts +6 -2
- package/extensions/modules/subagent/lib/settings.ts +2 -1
- package/extensions/modules/subagent/test/extension.test.ts +31 -0
- package/extensions/modules/subagent/test/file-modes.test.ts +40 -0
- package/extensions/modules/subagent/test/herdr-stalled.test.ts +39 -0
- package/extensions/modules/web/lib/chatgpt.ts +2 -1
- package/extensions/scripts/probe-thinking.mjs +108 -0
- package/package.json +3 -3
- package/skills/review/SKILL.md +45 -0
|
@@ -26,7 +26,10 @@ export function checkDangerousCommand(command: unknown): string | undefined {
|
|
|
26
26
|
for (const [, args] of trimmed.matchAll(/\brm\s+([^;&|\n]+)/g)) {
|
|
27
27
|
const recursive = /(?:^|\s)(?:-[a-z]*r[a-z]*|--recursive)(?:\s|$)/.test(args);
|
|
28
28
|
const forced = /(?:^|\s)(?:-[a-z]*f[a-z]*|--force)(?:\s|$)/.test(args);
|
|
29
|
-
|
|
29
|
+
// Tilde and $HOME expand to an absolute path (the home directory) at
|
|
30
|
+
// execution — treat them as absolute too. 2026-10-17 incident: `rm -rf ~`
|
|
31
|
+
// passed the slash-only check and deleted the home directory.
|
|
32
|
+
const absolute = /(?:^|\s)(?:--\s+)?(?:["'](?:\/[^"']*|~[^"']*)["']|\/\S*|~(?:\/\S*)?|\$\{home\}|\$home\b)/.test(args);
|
|
30
33
|
if (recursive && forced && absolute) return "Forced recursive delete of an absolute path";
|
|
31
34
|
}
|
|
32
35
|
if (/\bdd\b[^\n;&|]*\bof=["']?\/dev\/(?:sd[a-z]\d*|vd[a-z]\d*|xvd[a-z]\d*|nvme\d+n\d+(?:p\d+)?|mmcblk\d+(?:p\d+)?|disk\d+|rdisk\d+|loop\d+|md\d+|mapper\/[a-z0-9._+-]+)\b/.test(trimmed)) return "Destructive dd write to a block device";
|
|
@@ -13,6 +13,15 @@ describe("checkDangerousCommand", () => {
|
|
|
13
13
|
assert.ok(checkDangerousCommand("rm -rf --no-preserve-root /"));
|
|
14
14
|
assert.ok(checkDangerousCommand("rm -rf '/home/user'"));
|
|
15
15
|
assert.equal(checkDangerousCommand("rm -rf -- /var/tmp/x"), "Forced recursive delete of an absolute path");
|
|
16
|
+
// Tilde / $HOME expand to the absolute home path at execution — same
|
|
17
|
+
// refusal (2026-10-17 home-wipe incident). Built from char codes so the
|
|
18
|
+
// test file itself carries no dangerous literal.
|
|
19
|
+
const tilde = String.fromCharCode(0x7e);
|
|
20
|
+
assert.ok(checkDangerousCommand(`rm -rf ${tilde}`));
|
|
21
|
+
assert.ok(checkDangerousCommand(`rm -rf ${tilde}/x`));
|
|
22
|
+
assert.ok(checkDangerousCommand(`rm -rf ${tilde}.pi`));
|
|
23
|
+
assert.ok(checkDangerousCommand("rm -rf $HOME"));
|
|
24
|
+
assert.ok(checkDangerousCommand("rm -rf ${HOME}/lib"));
|
|
16
25
|
});
|
|
17
26
|
|
|
18
27
|
it("does not flag safe rm", () => {
|
|
@@ -149,6 +149,20 @@ function detectThinkingFormat(modelId: string): string {
|
|
|
149
149
|
}
|
|
150
150
|
if (id.includes("kimi")) return "kimi";
|
|
151
151
|
if (id.includes("qwen") || id.includes("qwq")) return "qwen";
|
|
152
|
+
// GLM-5.3 / 5.3-Flash / 5.3-FlashX: Z.ai's own forced-thinking family —
|
|
153
|
+
// reasoning_effort low | high | max are real, distinct tiers (live probe
|
|
154
|
+
// 2026-10-19: low 6.5s/~90ch vs high 13s/~2Kch thinking on a reasoning
|
|
155
|
+
// puzzle, both zai/ and combo/ routes). GLM-5.3 CANNOT disable thinking;
|
|
156
|
+
// "none"/"off" are ACCEPTED but silently behave like max (probe: effort
|
|
157
|
+
// "none" produced ~2.9Kch thinking vs low's ~90ch) — so off→null (omit the
|
|
158
|
+
// parameter entirely, upstream default applies) is load-bearing, not
|
|
159
|
+
// cosmetic. low/medium→low is the honest mapping (Z.ai's Coding Plan maps
|
|
160
|
+
// low/medium→high for 5.2 — but on 5.3 "low" IS a native tier and pi's
|
|
161
|
+
// clampThinkingLevel rounds xhigh UP to max, so pi never needs a 5.3
|
|
162
|
+
// medium); mirrors the zai-anthropic provider map. probe: extensions/
|
|
163
|
+
// scripts/probe-thinking.mjs. Checked BEFORE the plain-glm zai map so
|
|
164
|
+
// 5.3+ ids don't fall into the GLM-5.2-shaped map below.
|
|
165
|
+
if (/glm-5\.3/i.test(id)) return "zai53";
|
|
152
166
|
if (id.includes("glm")) return "zai";
|
|
153
167
|
if (id.includes("minimax")) return "minimax";
|
|
154
168
|
if (id.includes("hunyuan")) return "hunyuan";
|
|
@@ -275,6 +289,16 @@ const FORMAT_TO_LEVEL_MAP: Record<string, Record<string, string | null>> = {
|
|
|
275
289
|
// zai: mirrors native zai-coding-cn/glm-5.2 — low/medium/high all map to "high"
|
|
276
290
|
// (GLM's single thinking-on tier), max→"max"; xhigh/minimal unsupported (hidden).
|
|
277
291
|
"zai": { off:"none", minimal:null, low:"high", medium:"high", high:"high", xhigh:null, max:"max" },
|
|
292
|
+
// zai53: GLM-5.3 family (forced thinking, no disable). low is a REAL native
|
|
293
|
+
// tier here (unlike glm-5.2) — probe 2026-10-19 (extensions/scripts/
|
|
294
|
+
// probe-thinking.mjs): zai/ and combo/ routes accept every effort value
|
|
295
|
+
// (no 4xx), but "none"/"off" silently think at max depth, so off maps to
|
|
296
|
+
// null (omit the param = upstream default) rather than a wire value.
|
|
297
|
+
// low/medium→low, high→high, xhigh→max (pi clamps xhigh UP), max→max.
|
|
298
|
+
// Same shape as the zai-anthropic provider's GLM-5.3 map (modules/zai/lib/
|
|
299
|
+
// anthropic.ts). GLM-4.7 is also forced-thinking per Z.ai docs but has no
|
|
300
|
+
// verified route here — not covered until probed.
|
|
301
|
+
"zai53": { off:null, minimal:"low", low:"low", medium:"low", high:"high", xhigh:"max", max:"max" },
|
|
278
302
|
"minimax": { off:"none", minimal:null, low:"low", medium:"medium", high:"high", xhigh:"xhigh", max:"xhigh" },
|
|
279
303
|
// Yardmaster CC-enum backends (combo/, live-probed): "none"/"minimal" 400,
|
|
280
304
|
// and the literal "off" 422s too (reasoning_effort: unknown variant 'off',
|
|
@@ -514,6 +514,33 @@ describe("client", () => {
|
|
|
514
514
|
assert.equal(tlm("deepseek-v4.1-flash").off, "none");
|
|
515
515
|
});
|
|
516
516
|
|
|
517
|
+
it("glm-5.3 family uses the zai53 map (native low; off omits the param)", async () => {
|
|
518
|
+
const { mapModel } = await import("../lib/client.js");
|
|
519
|
+
const tlm = (id: string) => mapModel({ id }, true).thinkingLevelMap ?? {};
|
|
520
|
+
// low is a REAL native tier on GLM-5.3 (probe 2026-10-19), unlike glm-5.2.
|
|
521
|
+
const m = tlm("zai/glm-5.3");
|
|
522
|
+
assert.equal(m.off, null); // omit — literal "none"/"off" would think at max depth
|
|
523
|
+
assert.equal(m.minimal, "low");
|
|
524
|
+
assert.equal(m.low, "low");
|
|
525
|
+
assert.equal(m.medium, "low");
|
|
526
|
+
assert.equal(m.high, "high");
|
|
527
|
+
assert.equal(m.xhigh, "max"); // pi clamps xhigh UP to max
|
|
528
|
+
assert.equal(m.max, "max");
|
|
529
|
+
// Flash/FlashX route ids resolve to the same map.
|
|
530
|
+
const flash = tlm("combo/glm-5.3-flash");
|
|
531
|
+
assert.equal(flash.off, null);
|
|
532
|
+
assert.equal(flash.low, "low");
|
|
533
|
+
assert.equal(flash.high, "high");
|
|
534
|
+
// combo/ prefix override (NO_DISABLE off→null) must not break zai53 levels.
|
|
535
|
+
const cmd = tlm("cmd/zai/glm-5.3-max");
|
|
536
|
+
assert.equal(cmd.off, null);
|
|
537
|
+
assert.equal(cmd.low, "low");
|
|
538
|
+
// Family detection intact for GLM-5.2: zai map unchanged (off→"none" valid there).
|
|
539
|
+
const g52 = tlm("zai/glm-5.2");
|
|
540
|
+
assert.equal(g52.off, "none");
|
|
541
|
+
assert.equal(g52.low, "high");
|
|
542
|
+
});
|
|
543
|
+
|
|
517
544
|
it("claude 3-5/3-7 use budget thinking; 4-6/4.6/5/sonnet-5 use adaptive", async () => {
|
|
518
545
|
const { mapModel } = await import("../lib/client.js");
|
|
519
546
|
const xhigh = (id: string) => (mapModel({ id }, true).thinkingLevelMap ?? {}).xhigh;
|
|
@@ -721,11 +748,14 @@ describe("client thinkingLevelMap no-disable prefix override", () => {
|
|
|
721
748
|
assert.equal(m.thinkingLevelMap?.xhigh, "xhigh");
|
|
722
749
|
});
|
|
723
750
|
|
|
724
|
-
it("glm-cn/
|
|
751
|
+
it("glm-cn/glm-5.3 uses the zai53 map: off omits the param (probe 2026-10-19)", async () => {
|
|
725
752
|
const { mapModel } = await import("../lib/client.js");
|
|
726
753
|
const m = mapModel({ id: "glm-cn/glm-5.3" }, true);
|
|
727
|
-
//
|
|
728
|
-
|
|
754
|
+
// GLM-5.3 cannot disable thinking, and a literal "none" silently thinks
|
|
755
|
+
// at max depth (live probe 2026-10-19: effort "none" → ~2.9Kch reasoning
|
|
756
|
+
// vs "low" → ~90ch). off must OMIT the parameter, never send "none".
|
|
757
|
+
assert.equal(m.thinkingLevelMap?.off, null);
|
|
758
|
+
assert.equal(m.thinkingLevelMap?.low, "low");
|
|
729
759
|
});
|
|
730
760
|
|
|
731
761
|
it("cmd/ alias prefix also nulls off/minimal", async () => {
|
|
@@ -13,7 +13,7 @@ const LANGUAGE_PARAM = Type.Optional(
|
|
|
13
13
|
);
|
|
14
14
|
|
|
15
15
|
async function runSearch(rg: SgRunner, cwd: string, opts: { pattern: string; language?: string; globs?: string[]; paths?: string[] }, signal?: AbortSignal) {
|
|
16
|
-
return parseSearch(await rg.run(cwd, buildRunArgs({ ...opts, json: true }), signal), opts.pattern);
|
|
16
|
+
return parseSearch(await rg.run(cwd, buildRunArgs({ ...opts, json: true, cwd }), signal), opts.pattern);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export default function sgModule(pi: ExtensionAPI): void {
|
|
@@ -96,13 +96,13 @@ export default function sgModule(pi: ExtensionAPI): void {
|
|
|
96
96
|
return { content: [{ type: "text", text: `no matches for ${p.pattern} — nothing to rewrite` }], details: { matches: 0 } };
|
|
97
97
|
}
|
|
98
98
|
if (p.write !== true) {
|
|
99
|
-
const preview = await realSg.run(cwd, buildRunArgs({ pattern: p.pattern, rewrite: p.rewrite, language: p.language, globs: p.globs, paths: p.paths }), signal);
|
|
99
|
+
const preview = await realSg.run(cwd, buildRunArgs({ pattern: p.pattern, rewrite: p.rewrite, language: p.language, globs: p.globs, paths: p.paths, cwd }), signal);
|
|
100
100
|
const files = [...new Set(before.matches.map((m) => m.file))];
|
|
101
101
|
let text = `DRY-RUN — ${before.matches.length} match(es) across ${files.length} file(s) would change:\n${files.map((f) => ` ${f}`).join("\n")}\n\n${preview.stdout.trim()}`;
|
|
102
102
|
if (text.length > 16_000) text = `${text.slice(0, 16_000)}\n[… preview truncated — narrow paths/globs …]`;
|
|
103
103
|
return { content: [{ type: "text", text }], details: { matches: before.matches.length, files } };
|
|
104
104
|
}
|
|
105
|
-
const apply = await realSg.run(cwd, buildRunArgs({ pattern: p.pattern, rewrite: p.rewrite, language: p.language, globs: p.globs, paths: p.paths, update: true }), signal);
|
|
105
|
+
const apply = await realSg.run(cwd, buildRunArgs({ pattern: p.pattern, rewrite: p.rewrite, language: p.language, globs: p.globs, paths: p.paths, update: true, cwd }), signal);
|
|
106
106
|
if (apply.exitCode !== 0) {
|
|
107
107
|
throw new Error(`sg -U rewrite failed (exit ${apply.exitCode}): ${apply.stderr.slice(0, 300) || apply.stdout.slice(0, 300)}`);
|
|
108
108
|
}
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
// run -p PAT -r REW … (no -U) → per-file diff preview (dry-run).
|
|
8
8
|
// run -p PAT -r REW … -U → writes files, prints NOTHING on success.
|
|
9
9
|
|
|
10
|
+
import { isAbsolute as pathIsAbsolute, relative as relPath, resolve } from "node:path";
|
|
11
|
+
|
|
10
12
|
export interface SgMatch {
|
|
11
13
|
file: string;
|
|
12
14
|
/** 1-based (converted from sg's 0-based range). */
|
|
@@ -38,6 +40,7 @@ export function buildRunArgs(opts: {
|
|
|
38
40
|
paths?: string[];
|
|
39
41
|
update?: boolean;
|
|
40
42
|
json?: boolean;
|
|
43
|
+
cwd?: string;
|
|
41
44
|
}): string[] {
|
|
42
45
|
const args = ["run", "-p", opts.pattern];
|
|
43
46
|
if (opts.rewrite !== undefined) args.push("-r", opts.rewrite);
|
|
@@ -45,7 +48,18 @@ export function buildRunArgs(opts: {
|
|
|
45
48
|
for (const g of opts.globs ?? []) args.push("--globs", g);
|
|
46
49
|
if (opts.update) args.push("-U");
|
|
47
50
|
if (opts.json) args.push("--json=compact");
|
|
48
|
-
|
|
51
|
+
// F9 (security review 2026-10-17): path text must never parse as a flag —
|
|
52
|
+
// `paths: ["-U"]` would turn a dry-run into a silent disk write. Reject
|
|
53
|
+
// flag-shaped paths and anything escaping cwd, then push a `--` separator.
|
|
54
|
+
const paths = opts.paths && opts.paths.length > 0 ? opts.paths : ["."];
|
|
55
|
+
for (const p of paths) {
|
|
56
|
+
if (/^-/.test(p)) throw new Error(`path looks like a flag: ${p}`);
|
|
57
|
+
if (opts.cwd) {
|
|
58
|
+
const rel = relPath(opts.cwd, resolve(opts.cwd, p));
|
|
59
|
+
if (rel.startsWith("..") || pathIsAbsolute(rel)) throw new Error(`path must be inside the workspace: ${p}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
args.push("--", ...paths);
|
|
49
63
|
return args;
|
|
50
64
|
}
|
|
51
65
|
|
|
@@ -23,11 +23,11 @@ const SEARCH_JSON = JSON.stringify([
|
|
|
23
23
|
|
|
24
24
|
describe("buildRunArgs", () => {
|
|
25
25
|
it("search: pattern + json + default path", () => {
|
|
26
|
-
assert.deepEqual(buildRunArgs({ pattern: "return 1", json: true }), ["run", "-p", "return 1", "--json=compact", "."]);
|
|
26
|
+
assert.deepEqual(buildRunArgs({ pattern: "return 1", json: true }), ["run", "-p", "return 1", "--json=compact", "--", "."]);
|
|
27
27
|
});
|
|
28
28
|
it("language, globs, paths", () => {
|
|
29
29
|
const args = buildRunArgs({ pattern: "P", language: "ts", globs: ["*.ts"], paths: ["src", "lib"], json: true });
|
|
30
|
-
assert.deepEqual(args, ["run", "-p", "P", "-l", "ts", "--globs", "*.ts", "--json=compact", "src", "lib"]);
|
|
30
|
+
assert.deepEqual(args, ["run", "-p", "P", "-l", "ts", "--globs", "*.ts", "--json=compact", "--", "src", "lib"]);
|
|
31
31
|
});
|
|
32
32
|
it("rewrite dry-run has NO -U; apply adds it", () => {
|
|
33
33
|
const dry = buildRunArgs({ pattern: "P", rewrite: "R", json: true });
|
|
@@ -36,6 +36,20 @@ describe("buildRunArgs", () => {
|
|
|
36
36
|
const apply = buildRunArgs({ pattern: "P", rewrite: "R", update: true });
|
|
37
37
|
assert.equal(apply.includes("-U"), true);
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
// F9 (security review 2026-10-17): path text must never parse as a flag,
|
|
41
|
+
// and path scope cannot escape the workspace.
|
|
42
|
+
it("rejects flag-shaped paths and cwd escapes; cwd containment when cwd given", () => {
|
|
43
|
+
assert.throws(() => buildRunArgs({ pattern: "P", paths: ["-U"] }), /looks like a flag/, "paths:['-U'] must not turn a dry-run into a write");
|
|
44
|
+
assert.throws(() => buildRunArgs({ pattern: "P", paths: ["--globs=x"] }), /looks like a flag/);
|
|
45
|
+
assert.throws(() => buildRunArgs({ pattern: "P", paths: ["/etc"], cwd: "/proj" }), /inside the workspace/);
|
|
46
|
+
assert.throws(() => buildRunArgs({ pattern: "P", paths: ["../outside"], cwd: "/proj" }), /inside the workspace/);
|
|
47
|
+
// In-workspace absolute and relative paths still pass.
|
|
48
|
+
const ok = buildRunArgs({ pattern: "P", paths: ["/proj/src/a.ts", "lib"], cwd: "/proj" });
|
|
49
|
+
assert.ok(ok.includes("--") && ok.slice(ok.indexOf("--") + 1).join(",") === "/proj/src/a.ts,lib");
|
|
50
|
+
// No cwd → flag/escape rejection still applies, containment can't.
|
|
51
|
+
assert.throws(() => buildRunArgs({ pattern: "P", paths: ["-x"] }), /looks like a flag/);
|
|
52
|
+
});
|
|
39
53
|
});
|
|
40
54
|
|
|
41
55
|
describe("parseSearch", () => {
|
|
@@ -87,6 +87,7 @@ import { startBackgroundTask,
|
|
|
87
87
|
clearBackgroundTasks,
|
|
88
88
|
} from "./lib/background.ts";
|
|
89
89
|
import { parseStructuredResult } from "./lib/result.ts";
|
|
90
|
+
import { skillsRoot } from "../../lib/skill-path.js";
|
|
90
91
|
import { appendHistory, readHistory, markInterruptedOnRestart, trimHistory, getHistoryPath } from "./lib/history.ts";
|
|
91
92
|
import { herdrCli } from './lib/herdr.ts';
|
|
92
93
|
/** Keep-alive cadence for herdr delegations (test seam: shorten to assert). */
|
|
@@ -290,6 +291,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
290
291
|
// (upstream: extensions/index.ts → ../agents; ceulen module: ./agents)
|
|
291
292
|
const bundledAgentsDir = path.resolve(__dirname, "agents");
|
|
292
293
|
|
|
294
|
+
// The review skill ships via its OWN resources_discover dir (munin/cron
|
|
295
|
+
// pattern) so the kill-switch gates it: disabled subagent module ⇒ factory
|
|
296
|
+
// never runs ⇒ no review skill registered. The skill dispatches THIS
|
|
297
|
+
// module's reviewer agent, so it lives and dies with the module.
|
|
298
|
+
pi.on("resources_discover", () => ({
|
|
299
|
+
skillPaths: [path.join(skillsRoot(), "review")],
|
|
300
|
+
}));
|
|
301
|
+
|
|
293
302
|
// Invalidate agent cache + clear thread store on session replacement.
|
|
294
303
|
pi.on("session_start", (event, ctx) => {
|
|
295
304
|
currentCtx = ctx;
|
|
@@ -2154,7 +2163,9 @@ ${lines.join("\n")}`;
|
|
|
2154
2163
|
// (report file — or inline reply for read-only children).
|
|
2155
2164
|
const text = entry ? wrapTaskPrompt(params.text, entry.resultFile, entry.readOnly) : params.text;
|
|
2156
2165
|
if (params.wait) {
|
|
2157
|
-
|
|
2166
|
+
// F16: the schema documents the 60-min ceiling — clamp, don't
|
|
2167
|
+
// trust, the model-supplied timeout.
|
|
2168
|
+
const timeoutMs = Math.min(params.timeout ?? 120_000, MAX_TIMEOUT_MS);
|
|
2158
2169
|
const fileStampBefore = entry
|
|
2159
2170
|
? await fs.stat(entry.resultFile).then((s) => `${s.size}:${s.mtimeMs}`).catch(() => "")
|
|
2160
2171
|
: "";
|
|
@@ -90,6 +90,9 @@ async function waitForOutputEvidence(opts: {
|
|
|
90
90
|
resultFile: string;
|
|
91
91
|
readOnly?: boolean;
|
|
92
92
|
stamp: OutputEvidenceStamp;
|
|
93
|
+
/** The exact submitted prompt — an echo-only tail (pane just repeating the
|
|
94
|
+
* wrapped task back) is NOT evidence the child produced output (F10). */
|
|
95
|
+
promptText?: string;
|
|
93
96
|
deadlineMs: number;
|
|
94
97
|
pollMs?: number;
|
|
95
98
|
signal?: AbortSignal;
|
|
@@ -106,6 +109,8 @@ async function waitForOutputEvidence(opts: {
|
|
|
106
109
|
};
|
|
107
110
|
let stableCount = 0;
|
|
108
111
|
let lastTail = "";
|
|
112
|
+
let curPoll = pollMs;
|
|
113
|
+
let polls = 0;
|
|
109
114
|
for (;;) {
|
|
110
115
|
if (opts.signal?.aborted) return false;
|
|
111
116
|
if (!opts.readOnly) {
|
|
@@ -120,13 +125,29 @@ async function waitForOutputEvidence(opts: {
|
|
|
120
125
|
// so a mid-stream snapshot is not collected as the final reply.
|
|
121
126
|
if (tail === lastTail) stableCount++;
|
|
122
127
|
else { stableCount = 1; lastTail = tail; }
|
|
123
|
-
if (stableCount >= 3)
|
|
128
|
+
if (stableCount >= 3) {
|
|
129
|
+
// F10: settle only on output BEYOND the prompt echo — a TUI echo
|
|
130
|
+
// (plus editor chrome) settling looks identical to a reply. Strip
|
|
131
|
+
// the submitted prompt (whitespace-normalized containment; TUI
|
|
132
|
+
// wrapping can break the exact substring) and require a remainder.
|
|
133
|
+
if (opts.promptText) {
|
|
134
|
+
const norm = (s: string) => s.replace(/\s+/g, " ");
|
|
135
|
+
const stripped = norm(tail).split(norm(opts.promptText)).join("");
|
|
136
|
+
if (stripped.trim().length === 0) { stableCount = 0; lastTail = ""; continue; }
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
124
140
|
} else {
|
|
125
141
|
stableCount = 0;
|
|
126
142
|
}
|
|
127
143
|
}
|
|
128
144
|
if (Date.now() >= deadline) return false;
|
|
129
|
-
|
|
145
|
+
// F16: back off 1s → 2s → 5s after ~10 polls — a long-lived wait must not
|
|
146
|
+
// hold a ~1/s spawn cadence for up to an hour.
|
|
147
|
+
polls++;
|
|
148
|
+
if (polls === 10) curPoll = 2_000;
|
|
149
|
+
if (polls === 20) curPoll = 5_000;
|
|
150
|
+
await sleep(curPoll);
|
|
130
151
|
}
|
|
131
152
|
}
|
|
132
153
|
/** Reject herdr tasks above this size — the prompt travels as a CLI argv element. */
|
|
@@ -480,6 +501,9 @@ export async function ensureTab(opts: {
|
|
|
480
501
|
"--label", opts.agentType,
|
|
481
502
|
// Children must not recurse into herdr dispatch.
|
|
482
503
|
"--env", `${HERDR_OFF_ENV}=off`,
|
|
504
|
+
// ...and must not run the main-session think gate (dispatch-routed
|
|
505
|
+
// thinking already covers panes; a per-turn gate would fight it).
|
|
506
|
+
"--env", "CEULEN_THINK_GATE_OFF=1",
|
|
483
507
|
...(opts.env ?? []).flatMap((e) => ["--env", e]),
|
|
484
508
|
"--no-focus",
|
|
485
509
|
]);
|
|
@@ -535,6 +559,7 @@ export async function ensurePane(opts: {
|
|
|
535
559
|
"--direction", direction,
|
|
536
560
|
"--cwd", opts.cwd,
|
|
537
561
|
"--env", `${HERDR_OFF_ENV}=off`,
|
|
562
|
+
"--env", "CEULEN_THINK_GATE_OFF=1",
|
|
538
563
|
...(opts.env ?? []).flatMap((e) => ["--env", e]),
|
|
539
564
|
"--no-focus",
|
|
540
565
|
]);
|
|
@@ -661,6 +686,7 @@ export async function promptAndWait(opts: {
|
|
|
661
686
|
resultFile: string;
|
|
662
687
|
readOnly?: boolean;
|
|
663
688
|
stamp: OutputEvidenceStamp;
|
|
689
|
+
promptText?: string;
|
|
664
690
|
graceMs?: number;
|
|
665
691
|
signal?: AbortSignal;
|
|
666
692
|
};
|
|
@@ -693,6 +719,7 @@ export async function promptAndWait(opts: {
|
|
|
693
719
|
resultFile: opts.evidence.resultFile,
|
|
694
720
|
readOnly: opts.evidence.readOnly,
|
|
695
721
|
stamp: opts.evidence.stamp,
|
|
722
|
+
promptText: opts.evidence.promptText,
|
|
696
723
|
// The CLI consumed ~5s observing its stall window; the evidence
|
|
697
724
|
// wait gets the full dispatch budget (floored at the grace minimum
|
|
698
725
|
// so very short timeouts still get a fair window).
|
|
@@ -728,7 +755,13 @@ export async function collectResult(opts: {
|
|
|
728
755
|
exec: HerdrExec;
|
|
729
756
|
}): Promise<{ output: string; source: "file" | "pane" | "none" }> {
|
|
730
757
|
try {
|
|
731
|
-
|
|
758
|
+
// F16: open + stat FIRST, read at most MAX_REPORT_BYTES (+1 sentinel) —
|
|
759
|
+
// a runaway report (GBs) must not buffer whole into memory before the cap.
|
|
760
|
+
const fh = await fs.open(opts.handle.resultFile, "r");
|
|
761
|
+
const want = Math.min((await fh.stat()).size, MAX_REPORT_BYTES + 1);
|
|
762
|
+
const raw = Buffer.alloc(want);
|
|
763
|
+
await fh.read(raw, 0, want, 0);
|
|
764
|
+
await fh.close();
|
|
732
765
|
const text = raw.length > MAX_REPORT_BYTES
|
|
733
766
|
? raw.subarray(0, MAX_REPORT_BYTES).toString("utf8") + "\n\n…(truncated)"
|
|
734
767
|
: raw.toString("utf8");
|
|
@@ -1111,6 +1144,7 @@ export async function executeHerdrTask(
|
|
|
1111
1144
|
resultFile: handle.resultFile,
|
|
1112
1145
|
readOnly: handle.readOnly,
|
|
1113
1146
|
stamp,
|
|
1147
|
+
promptText: wrapTaskPrompt(handle.task, handle.resultFile, handle.readOnly),
|
|
1114
1148
|
signal: opts.signal,
|
|
1115
1149
|
},
|
|
1116
1150
|
});
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* are marked `interrupted` — honest about the architectural ceiling.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { dirname, join } from "node:path";
|
|
15
15
|
|
|
16
16
|
// ---------------------------------------------------------------------------
|
|
@@ -84,7 +84,11 @@ export function appendHistory(piDir: string, entry: HistoryEntry): void {
|
|
|
84
84
|
export function writeHistory(piDir: string, entries: HistoryEntry[]): void {
|
|
85
85
|
const file = getHistoryPath(piDir);
|
|
86
86
|
mkdirSync(dirname(file), { recursive: true });
|
|
87
|
-
|
|
87
|
+
// tmp+rename at 0600 (F12): task text is sensitive AND a crash mid-write
|
|
88
|
+
// must not truncate the history file.
|
|
89
|
+
const tmp = `${file}.tmp-${process.pid}`;
|
|
90
|
+
writeFileSync(tmp, `${JSON.stringify(entries, null, 2)}\n`, { encoding: "utf-8", mode: 0o600 });
|
|
91
|
+
renameSync(tmp, file);
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
export function findHistory(piDir: string, id: string): HistoryEntry | undefined {
|
|
@@ -152,8 +152,9 @@ export function writeSubagentSection(patch: {
|
|
|
152
152
|
}
|
|
153
153
|
settings.subagent = sub;
|
|
154
154
|
mkdirSync(path.dirname(file), { recursive: true });
|
|
155
|
+
// 0600: settings.json may hold a2a tokens — never downgrade on rewrite (F6).
|
|
155
156
|
const tmp = file + ".tmp";
|
|
156
|
-
writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n");
|
|
157
|
+
writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
|
|
157
158
|
renameSync(tmp, file);
|
|
158
159
|
return file;
|
|
159
160
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Regression guard for the review-skill registration (reviewer finding,
|
|
2
|
+
// munin extension.test.ts harness pattern): a typo'd path.join segment or a
|
|
3
|
+
// dropped handler must fail here instead of shipping silently — pi only
|
|
4
|
+
// surfaces a bad skill path as a runtime warning.
|
|
5
|
+
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { describe, it } from "node:test";
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import subagentExtension from "../index.ts";
|
|
12
|
+
|
|
13
|
+
describe("review skill registration", () => {
|
|
14
|
+
it("registers the review skill via resources_discover", () => {
|
|
15
|
+
const discover: Function[] = [];
|
|
16
|
+
const pi: any = {
|
|
17
|
+
registerTool() {},
|
|
18
|
+
registerCommand() {},
|
|
19
|
+
on(name: string, handler: Function) { if (name === "resources_discover") discover.push(handler); },
|
|
20
|
+
};
|
|
21
|
+
// ESM: __dirname exists only inside pi's extension loading context; the
|
|
22
|
+
// factory body reads it (bundledAgentsDir), so supply the real dir.
|
|
23
|
+
(globalThis as any).__dirname = fileURLToPath(new URL("../", import.meta.url));
|
|
24
|
+
subagentExtension(pi);
|
|
25
|
+
assert.equal(discover.length, 1);
|
|
26
|
+
const result = discover[0]!() as { skillPaths: string[] };
|
|
27
|
+
assert.equal(result.skillPaths.length, 1);
|
|
28
|
+
assert.match(result.skillPaths[0]!, /review$/);
|
|
29
|
+
assert.ok(existsSync(join(result.skillPaths[0]!, "SKILL.md")), "SKILL.md exists in the contributed dir");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Security-review 2026-10-17 (F6/F12): settings.json may hold a2a tokens and
|
|
2
|
+
// history carries task text — both writes must land at 0600, and the history
|
|
3
|
+
// rewrite must be atomic (tmp+rename, crash cannot truncate).
|
|
4
|
+
import assert from "node:assert/strict";
|
|
5
|
+
import { mkdtempSync, statSync, rmSync, mkdirSync, existsSync, readdirSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { afterEach, describe, it } from "node:test";
|
|
9
|
+
import { writeSubagentSection } from "../lib/settings.js";
|
|
10
|
+
import { writeHistory, readHistory, getHistoryPath, type HistoryEntry } from "../lib/history.js";
|
|
11
|
+
|
|
12
|
+
const savedAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
13
|
+
const dir = mkdtempSync(join(tmpdir(), "subagent-modes-"));
|
|
14
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
if (savedAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
18
|
+
else process.env.PI_CODING_AGENT_DIR = savedAgentDir;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("subagent write modes (F6/F12)", () => {
|
|
22
|
+
it("writeSubagentSection keeps settings.json at 0600", () => {
|
|
23
|
+
const file = join(dir, "settings.json");
|
|
24
|
+
writeSubagentSection({ idleTimeoutMins: 5 });
|
|
25
|
+
assert.equal(existsSync(file), true);
|
|
26
|
+
assert.equal(statSync(file).mode & 0o777, 0o600, "settings.json must be 0600");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("writeHistory is 0600 and atomic (no tmp litter, content intact)", () => {
|
|
30
|
+
const piDir = join(dir, "hist");
|
|
31
|
+
mkdirSync(piDir, { recursive: true });
|
|
32
|
+
const entries = [{ id: "t1", agent: "scout", task: "probe", status: "done" } as unknown as HistoryEntry];
|
|
33
|
+
writeHistory(piDir, entries);
|
|
34
|
+
const file = getHistoryPath(piDir);
|
|
35
|
+
assert.equal(statSync(file).mode & 0o777, 0o600, "history must be 0600");
|
|
36
|
+
assert.deepEqual(readHistory(piDir).map((e) => e.id), ["t1"], "content survives the rename");
|
|
37
|
+
const litter = readdirSync(piDir).filter((f) => f.includes(".tmp-"));
|
|
38
|
+
assert.deepEqual(litter, [], "rename left no tmp litter");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -115,3 +115,42 @@ test("no regression: plain timeout still short-circuits before the stalled branc
|
|
|
115
115
|
assert.match(outcome.error ?? "", /timeout/);
|
|
116
116
|
assert.equal(calls.filter((c) => c.args[1] === "read").length, 0);
|
|
117
117
|
});
|
|
118
|
+
|
|
119
|
+
// F10 (security review 2026-10-17): a pane merely echoing the submitted
|
|
120
|
+
// prompt back must NOT settle as evidence — the child produced no output.
|
|
121
|
+
test("echo-only tail times out instead of settling (F10)", async () => {
|
|
122
|
+
const P = "Summarize the ledger for October and reply with your full final report.";
|
|
123
|
+
const echo = `> ${P}\n`;
|
|
124
|
+
const calls: Call[] = [];
|
|
125
|
+
const script = new Map<string, FakeRes[]>([
|
|
126
|
+
["agent prompt", [STALLED]],
|
|
127
|
+
// Every poll returns exactly the wrapped prompt - changed from baseline,
|
|
128
|
+
// then perfectly quiet: the pre-fix quiescence rule would settle here.
|
|
129
|
+
["agent read", [{ code: 0, stdout: echo }]],
|
|
130
|
+
]);
|
|
131
|
+
const outcome = await promptAndWait({
|
|
132
|
+
name: "a1", text: P, timeoutMs: 5000, exec: fakeExec(script, calls),
|
|
133
|
+
evidence: { resultFile: tmpResultFile(), readOnly: true, stamp: { fileStamp: "", paneTail: "PRE-PROMPT" }, promptText: P, graceMs: 300 },
|
|
134
|
+
});
|
|
135
|
+
assert.equal(outcome.delivered, true);
|
|
136
|
+
assert.match(outcome.error ?? "", /timeout/, "echo-only tails never settle - timeout semantics");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("echo followed by real reply content still settles (F10 does not over-block)", async () => {
|
|
140
|
+
const P = "Report the build status.";
|
|
141
|
+
const tail = `> ${P}\nThe build is green; 41 checks passed.\n`;
|
|
142
|
+
const calls: Call[] = [];
|
|
143
|
+
const script = new Map<string, FakeRes[]>([
|
|
144
|
+
["agent prompt", [STALLED]],
|
|
145
|
+
// Repeat the tail: quiescence needs 3 identical polls, and an exhausted
|
|
146
|
+
// script would answer "" and reset the stability counter instead.
|
|
147
|
+
["agent read", [{ code: 0, stdout: tail }, { code: 0, stdout: tail }, { code: 0, stdout: tail }, { code: 0, stdout: tail }, { code: 0, stdout: tail }, { code: 0, stdout: tail }]],
|
|
148
|
+
["agent get", [{ code: 0, stdout: idleInfo }]],
|
|
149
|
+
]);
|
|
150
|
+
const outcome = await promptAndWait({
|
|
151
|
+
name: "a1", text: P, timeoutMs: 5000, exec: fakeExec(script, calls),
|
|
152
|
+
evidence: { resultFile: tmpResultFile(), readOnly: true, stamp: { fileStamp: "", paneTail: "PRE" }, promptText: P, graceMs: 5000 },
|
|
153
|
+
});
|
|
154
|
+
assert.equal(outcome.delivered, true);
|
|
155
|
+
assert.equal(outcome.error, undefined, "output beyond the echo settles normally");
|
|
156
|
+
});
|
|
@@ -326,7 +326,8 @@ export function __resetChatGptAuthState(): void {
|
|
|
326
326
|
const expired = (auth: ChatGptAuth) => auth.expiresAt !== undefined && auth.expiresAt <= Date.now() + 30_000;
|
|
327
327
|
|
|
328
328
|
async function defaultRefreshFetch(url: string, init: { method: string; headers: Record<string, string>; body: string }): Promise<{ status: number; text: string }> {
|
|
329
|
-
|
|
329
|
+
// F17: a hung auth endpoint must not park the caller forever.
|
|
330
|
+
const res = await fetch(url, { method: init.method, headers: init.headers, body: init.body, signal: AbortSignal.timeout(15_000) });
|
|
330
331
|
return { status: res.status, text: await res.text() };
|
|
331
332
|
}
|
|
332
333
|
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// probe-thinking.mjs — live status matrix of `reasoning_effort` acceptance per
|
|
3
|
+
// router route. What values does the router forward, and what does the UPSTREAM
|
|
4
|
+
// accept for each glm-5.3* route? Read-only side effects: probe requests cost a
|
|
5
|
+
// handful of tokens.
|
|
6
|
+
//
|
|
7
|
+
// Config resolution mirrors the router module: ROUTER_API_KEY env → auth.json
|
|
8
|
+
// `router.key`; baseUrl from GLOBAL settings.json `router.baseUrl` (or
|
|
9
|
+
// ROUTER_BASE_URL env). Prints a value × route matrix of HTTP status.
|
|
10
|
+
//
|
|
11
|
+
// Usage: node extensions/scripts/probe-thinking.mjs [pattern]
|
|
12
|
+
// pattern — optional id substring filter (default "glm-5.3")
|
|
13
|
+
|
|
14
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
const EFFORTS = ["none", "off", "minimal", "low", "medium", "high", "xhigh", "max", "(omitted)"];
|
|
19
|
+
|
|
20
|
+
function agentDir() {
|
|
21
|
+
return process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function resolveConfig() {
|
|
25
|
+
let baseUrl = process.env.ROUTER_BASE_URL || "";
|
|
26
|
+
let key = process.env.ROUTER_API_KEY || "";
|
|
27
|
+
if (!baseUrl || !key) {
|
|
28
|
+
try {
|
|
29
|
+
if (existsSync(join(agentDir(), "settings.json"))) {
|
|
30
|
+
const settings = JSON.parse(readFileSync(join(agentDir(), "settings.json"), "utf8"));
|
|
31
|
+
if (!baseUrl) baseUrl = settings?.router?.baseUrl || "";
|
|
32
|
+
}
|
|
33
|
+
} catch { /* settings unreadable → env fallback only */ }
|
|
34
|
+
if (!key && existsSync(join(agentDir(), "auth.json"))) {
|
|
35
|
+
try {
|
|
36
|
+
const auth = JSON.parse(readFileSync(join(agentDir(), "auth.json"), "utf8"));
|
|
37
|
+
if (!key) key = auth?.router?.key || "";
|
|
38
|
+
} catch { /* ignore */ }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { baseUrl: baseUrl.replace(/\/+$/, ""), key };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function chat(baseUrl, key, model, effort) {
|
|
45
|
+
const url = /\/v1\/?$/.test(baseUrl) ? `${baseUrl}/chat/completions` : `${baseUrl}/v1/chat/completions`;
|
|
46
|
+
const body = { model, messages: [{ role: "user", content: "Reply with exactly: ok" }], max_tokens: 512 };
|
|
47
|
+
if (effort !== "(omitted)") body.reasoning_effort = effort;
|
|
48
|
+
const started = Date.now();
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetch(url, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: { "Content-Type": "application/json", ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
53
|
+
body: JSON.stringify(body),
|
|
54
|
+
signal: AbortSignal.timeout(120_000),
|
|
55
|
+
});
|
|
56
|
+
const ms = Date.now() - started;
|
|
57
|
+
if (res.ok) {
|
|
58
|
+
const json = await res.json().catch(() => null);
|
|
59
|
+
const reasoning = json?.choices?.[0]?.message?.reasoning_content;
|
|
60
|
+
const thinkLen = typeof reasoning === "string" ? reasoning.length : 0;
|
|
61
|
+
return `200 (${ms}ms, thinking ${thinkLen ? `~${thinkLen}ch` : "absent"})`;
|
|
62
|
+
}
|
|
63
|
+
const text = (await res.text().catch(() => "")).slice(0, 90).replace(/\s+/g, " ");
|
|
64
|
+
return `${res.status} ${text}`;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
return `ERR ${e instanceof Error ? e.message.slice(0, 60) : String(e)}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const { baseUrl, key } = resolveConfig();
|
|
71
|
+
if (!baseUrl || !key) {
|
|
72
|
+
console.error("No router baseUrl/key resolved (ROUTER_BASE_URL/ROUTER_API_KEY env, or settings.json/auth.json).");
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const pattern = process.argv[2] || "glm-5.3";
|
|
76
|
+
|
|
77
|
+
// 1. Discover glm-5.3* models from /v1/models.
|
|
78
|
+
let ids = [];
|
|
79
|
+
try {
|
|
80
|
+
const res = await fetch(`${baseUrl}/models`, { headers: { Authorization: `Bearer ${key}` }, signal: AbortSignal.timeout(30_000) });
|
|
81
|
+
const json = await res.json();
|
|
82
|
+
ids = (json?.data ?? []).map((m) => m.id).filter((id) => id.toLowerCase().includes(pattern.toLowerCase()));
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.error(`Model list failed: ${e instanceof Error ? e.message : e}`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
if (ids.length === 0) {
|
|
88
|
+
console.error(`No catalog ids matching /${pattern}/.`);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
// Cap: 9 efforts × N routes; keep the matrix sane.
|
|
92
|
+
ids = ids.slice(0, 4);
|
|
93
|
+
console.log(`Router: ${baseUrl}\nRoutes (${ids.length}): ${ids.join(", ")}\n`);
|
|
94
|
+
|
|
95
|
+
// 2. Probe each effort value against each route.
|
|
96
|
+
const header = "effort".padEnd(12) + ids.map((id) => id.slice(0, 38).padEnd(40)).join("");
|
|
97
|
+
console.log(header);
|
|
98
|
+
console.log("-".repeat(header.length));
|
|
99
|
+
for (const effort of EFFORTS) {
|
|
100
|
+
const cells = [];
|
|
101
|
+
for (const id of ids) {
|
|
102
|
+
process.stderr.write(` probing ${effort} × ${id}...\r`);
|
|
103
|
+
cells.push((await chat(baseUrl, key, id, effort)).slice(0, 38).padEnd(40));
|
|
104
|
+
}
|
|
105
|
+
process.stderr.write(" ".repeat(60) + "\r");
|
|
106
|
+
console.log(effort.padEnd(12) + cells.join(""));
|
|
107
|
+
}
|
|
108
|
+
console.log("\nRead: 200 = accepted; 4xx = rejected (value unsupported on that upstream); ERR = transport.");
|