ceulen 0.20.0 → 0.25.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 +176 -0
- package/extensions/lib/env.test.ts +45 -0
- package/extensions/lib/env.ts +56 -3
- package/extensions/lib/registry.ts +8 -0
- 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/composer/lib/shapes.ts +2 -1
- 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/goal/configPanel.ts +63 -0
- package/extensions/modules/goal/index.ts +545 -0
- package/extensions/modules/goal/lib/settings.ts +73 -0
- package/extensions/modules/goal/lib/state.ts +223 -0
- package/extensions/modules/goal/test/goal.test.ts +522 -0
- 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 +4 -4
- package/skills/review/SKILL.md +45 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,181 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.25.0 — 2026-11-01
|
|
4
|
+
|
|
5
|
+
Goal module (`extensions/modules/goal/`): OMP/Codex-style **autonomous
|
|
6
|
+
self-continuation goal mode** — reverses the 2026-10-02 decision that
|
|
7
|
+
dropped pi-plan's `/goal` (all three peer harnesses ship the feature:
|
|
8
|
+
Codex v0.128+, Claude Code `/goal`, OMP core).
|
|
9
|
+
|
|
10
|
+
- **`/goal <objective> [--budget N]`** (+ `status|pause|resume|clear|
|
|
11
|
+
budget <N|off>`): sets a session goal and fires the objective as the
|
|
12
|
+
first work turn. After every settled turn (`agent_settled` — pi's
|
|
13
|
+
"no retry/compaction/queued continuation will run" contract) a hidden
|
|
14
|
+
continuation re-prompts (`triggerTurn:true, deliverAs:"followUp"` —
|
|
15
|
+
cron's fire mechanism) with OMP's 6-point completion-audit prompt.
|
|
16
|
+
- **`goal` tool (DIRECT, never deferred)**: `get` reports state;
|
|
17
|
+
`complete` ends the loop — accepted only from the agent, and only when
|
|
18
|
+
repo state proves every deliverable (budget exhaustion ≠ completion).
|
|
19
|
+
Plan mode blocks it via plan-tools.ts BLOCKED_TOOLS; goal mode never
|
|
20
|
+
bypasses plan gates or bash approvals.
|
|
21
|
+
- **Token budget** = OMP `goalTokenDelta` (input+cacheWrite+output;
|
|
22
|
+
cacheRead excluded) over rolling `message_end` snapshots: a goal set
|
|
23
|
+
mid-run bills only post-goal deltas; a fresh-session goal bills from
|
|
24
|
+
zero (live-test fix — the first turn of a fresh-session goal is goal
|
|
25
|
+
work). Flip to `budget-limited` sends ONE wrap-up turn
|
|
26
|
+
(`followUp+triggerTurn`, deliberately not OMP's mid-turn steer: at a
|
|
27
|
+
pi turn boundary nothing can consume a steer). One wrap-up per budget
|
|
28
|
+
episode; `/goal budget` set-below-usage re-limits immediately, raise
|
|
29
|
+
above usage revives.
|
|
30
|
+
- **Boundaries**: turn cap `goal.maxTurns` (default 50) stops the loop;
|
|
31
|
+
abort/plan-mode pauses; restart restores PAUSED — terminal tombstone
|
|
32
|
+
entries (`complete`/`stopped`) prevent cleared-goal resurrection.
|
|
33
|
+
- **Settings**: GLOBAL `goal` section (`maxTurns`, `defaultBudget`,
|
|
34
|
+
0 = unbounded); /config → Tasks → Goal mode 🎯; status segment
|
|
35
|
+
`ceulen-goal`; registry position before rules/steering (append-only
|
|
36
|
+
`before_agent_start` composer). Live-verified in a herdr pane
|
|
37
|
+
(set/complete/continuation/budget/pause/resume + 16-entry jsonl trail).
|
|
38
|
+
|
|
39
|
+
## 0.24.0 — 2026-10-23
|
|
40
|
+
|
|
41
|
+
pi 1.4.0 compatibility pass (verified by diffing the 1.3.0 and 1.4.0
|
|
42
|
+
managed releases surface by surface): **no breaking changes**. The 1.4.0
|
|
43
|
+
delta is additive for the extension API — types.d.ts zero-diff,
|
|
44
|
+
SettingsManager/settings-selector/theme-schema byte-identical, pi-tui
|
|
45
|
+
editor internals unchanged.
|
|
46
|
+
|
|
47
|
+
- **Peer deps widened** `>=0.99.1 <1.4.0` → `>=0.99.1 <1.5.0` for both
|
|
48
|
+
`@earendil-works/pi-coding-agent` and `@earendil-works/pi-tui` (the old
|
|
49
|
+
range semver-excluded pi 1.4.0). AGENTS.md inline range updated; lockfile
|
|
50
|
+
refreshed to pi 1.4.0 + pi-tui 1.4.0.
|
|
51
|
+
- **Deferred tier verified against the #11062 resume rework**: pi 1.4.0
|
|
52
|
+
activates never-mentioned extension tools on session resume, but only
|
|
53
|
+
ones declarable on registration (`direct`/`model-only`) — deferred tools
|
|
54
|
+
stay inactive, the session_start `tool_search` re-arm still composes.
|
|
55
|
+
- **Composer comment** updated to pi 1.4.0 compaction semantics
|
|
56
|
+
(`reserveTokens` only controls when compaction STARTS; summaries use the
|
|
57
|
+
model's full output limit).
|
|
58
|
+
- **Free wins from pi 1.4.0**: codemode worker queueing (parallel subagent
|
|
59
|
+
dispatches queue up to 60s instead of failing), truncated-tool-call
|
|
60
|
+
recovery (#11227), OpenAI Responses prompt-cache retention on deferred
|
|
61
|
+
tool loads (#10940), dialog stacking (#11166 — /config + a2a prompts no
|
|
62
|
+
longer orphan promises).
|
|
63
|
+
|
|
64
|
+
Verification: tsc clean against 1.4.0; 2931 tests / 0 fail (3 env skips);
|
|
65
|
+
rpc-mode live smoke on managed pi 1.4.0 — 29 modules, 59 commands (parity
|
|
66
|
+
with 1.3.0), 51 deferred tools, zero stderr.
|
|
67
|
+
|
|
68
|
+
## 0.23.0 — 2026-10-19
|
|
69
|
+
|
|
70
|
+
Thinking-mode gaps closed — GLM-5.3 gets its real effort ladder on the router,
|
|
71
|
+
and the main session's thinking level is classifier-routed per turn.
|
|
72
|
+
|
|
73
|
+
Research basis: GLM-5.3/5.3-Flash accept only `reasoning_effort: low|high|max`
|
|
74
|
+
(forced thinking — `none`/`off` are accepted but silently think at max depth;
|
|
75
|
+
live probe 2026-10-19), `high` ≈ 93% of `max` quality at ~⅔ the tokens
|
|
76
|
+
(Z.ai Code Bench), and overthinking hurts on easy tasks (arXiv 2601.21418,
|
|
77
|
+
2604.10739).
|
|
78
|
+
|
|
79
|
+
- **Router `zai53` map** (`router/lib/client.ts`): GLM-5.3 family split out of
|
|
80
|
+
the GLM-5.2-shaped `zai` map — `off` now OMITS the parameter (never sends
|
|
81
|
+
`"none"`, which would think at max depth), and the native `low` tier is
|
|
82
|
+
reachable (`low/medium→low`, `xhigh→max` via pi's clamp). `combo/` routes keep
|
|
83
|
+
the CC enum; glm-5.2 keeps the old map. Probe script shipped:
|
|
84
|
+
`extensions/scripts/probe-thinking.mjs` (value × route status matrix).
|
|
85
|
+
- **`classifier.thinkGate`** (new, `classifier/lib/think-gate.ts`): one Jev
|
|
86
|
+
score question per user turn sets the session thinking level; baseline
|
|
87
|
+
restored at settle. planGate pattern — default fully OFF, observe-first, 2.5s
|
|
88
|
+
budget, fail-open everywhere, every verdict audited to `classifier.log`
|
|
89
|
+
(`ceulen-think-gate` tag; missing-model fail-opens audit once per session).
|
|
90
|
+
Stands down for the session when the user touches the thinking dial; skips
|
|
91
|
+
plan mode, custom messages, and herdr children (`CEULEN_THINK_GATE_OFF=1`
|
|
92
|
+
injected by the subagent module — covers `thinking_level_select` too, so
|
|
93
|
+
child panes are fully inert). Live-verified in herdr: parent pane full
|
|
94
|
+
cycle (trivial → `off`(→minimal), architecture → `xhigh`), child panes zero
|
|
95
|
+
gate events.
|
|
96
|
+
- Pitfalls encoded as tests: pi emits `thinking_level_select` synchronously
|
|
97
|
+
off the set call site with CLAMPED values (ownership = pre-call timestamp
|
|
98
|
+
arm + effective-level re-read); level-capped models clamp DOWN (xhigh→high
|
|
99
|
+
regression case covered).
|
|
100
|
+
|
|
101
|
+
## 0.22.0 — 2026-10-17
|
|
102
|
+
|
|
103
|
+
Post-completion review gate — the research-backed practice (Codex Auto-review,
|
|
104
|
+
Anthropic verification guidance) shipped as a convention skill, not a hook:
|
|
105
|
+
after a plan finishes executing or a substantial task ends, capture the diff
|
|
106
|
+
scope + acceptance criteria and dispatch the bundled `reviewer` subagent
|
|
107
|
+
(fresh context, evidence-required findings) before claiming done.
|
|
108
|
+
|
|
109
|
+
- **`review` skill** (new, `skills/review/SKILL.md`): one reviewer pass per
|
|
110
|
+
gate (never parallel fans), review AGAINST plan acceptance criteria not
|
|
111
|
+
open-ended style, fix critical/high/blocking only, ONE revision loop, human
|
|
112
|
+
reviews last. Advisor owns per-turn review; this owns task-end — never
|
|
113
|
+
stacked on the same turn.
|
|
114
|
+
- **Registration**: subagent module contributes the skill via
|
|
115
|
+
`resources_discover` (munin/cron pattern) — the module kill-switch gates it,
|
|
116
|
+
since the skill dispatches that module's reviewer agent.
|
|
117
|
+
- **Tests**: skill-path existence list covers `cron` + `review`; new
|
|
118
|
+
subagent `extension.test.ts` asserts the registration (typo/dropped-handler
|
|
119
|
+
mutation-verified). AGENTS.md layout + subagent sections updated.
|
|
120
|
+
|
|
121
|
+
## 0.21.0 — 2026-10-17
|
|
122
|
+
|
|
123
|
+
Security-review pass — 18 findings (1 critical, 5 high, 7 medium, 5 low),
|
|
124
|
+
all verified against code and now fixed. Every finding carries a regression
|
|
125
|
+
test; the plan-mode shell gate also gained live-tested hardening after the
|
|
126
|
+
F1 exploit class was executed against a real session during the review
|
|
127
|
+
(the home-wipe incident — see the shell-gate entry).
|
|
128
|
+
|
|
129
|
+
- **plan/shell-gate (F1, critical)**: backslash handling in the quote
|
|
130
|
+
scanners created a *phantom-quote* bypass — `ls \" ; rm …` classified
|
|
131
|
+
`read` and **auto-ran in plan mode**. One shared bash-faithful helper
|
|
132
|
+
(`quoteCloses`: single quotes close on any `'`; double quotes on an EVEN
|
|
133
|
+
backslash run) now drives all four scanners; escaped quotes outside
|
|
134
|
+
quotes never open spans; `$()`/backticks inside double quotes still scan
|
|
135
|
+
as live; dangling quotes classify confirm, never read.
|
|
136
|
+
- **plan gating (F2/F3/F11/F13/F15)**: a session allow ("npm test") can no
|
|
137
|
+
longer auto-run a RISKY command on the same first token ("npm publish");
|
|
138
|
+
subagent auto-allow resolves at the scope the tool actually runs (a
|
|
139
|
+
read-only project agent can no longer shadow a full-write bundled
|
|
140
|
+
namesake); the planGate static pre-check also tests a de-quoted copy
|
|
141
|
+
(`curl … | 'b''a''s''h'` never reaches Jev; `cargo publish`, `twine
|
|
142
|
+
upload`, `gem push` join the classifier RISKY list); the textconv
|
|
143
|
+
diff-driver probe is awaited before bash classification (kills the `git
|
|
144
|
+
log -p` read race); `session_tree` resets the ask-loop dampener.
|
|
145
|
+
- **shell tool parity (F4)**: a `shell action:"start"` is a shell command —
|
|
146
|
+
permission `bash` rules now apply to it (deny blocks, ask shows the
|
|
147
|
+
command, session promotions key under bash) and the classifier risky hook
|
|
148
|
+
annotates it like bash.
|
|
149
|
+
- **file modes (F5/F6/F12)**: permission allowlist persist, subagent
|
|
150
|
+
settings, cron jobs.json + run logs, and a2a transcripts (dir 0700) write
|
|
151
|
+
0600; subagent history switched to atomic tmp+rename 0600.
|
|
152
|
+
- **munin apiKey (F7)**: the API key never lands in the git-trackable
|
|
153
|
+
project `.pi/settings.json` — the /config save diverts to
|
|
154
|
+
`<agentDir>/.env.local` (0600, mirrored live into the session env), and
|
|
155
|
+
the startup secret migration scrubs a plaintext key from a trusted
|
|
156
|
+
project file.
|
|
157
|
+
- **jfind containment (F8)**: symlink entries are never followed
|
|
158
|
+
(lstat + skip in both walk branches, single-file symlink scopes yield
|
|
159
|
+
nothing) and the `path` scope must stay inside the workspace — file
|
|
160
|
+
contents ship to the classifier, so the scope is a content boundary.
|
|
161
|
+
- **sg path validation (F9)**: flag-shaped paths (`paths:["-U"]` turned a
|
|
162
|
+
dry-run into a silent write) and cwd escapes are rejected; a `--`
|
|
163
|
+
separator guards every path list.
|
|
164
|
+
- **herdr evidence + resources (F10/F16)**: a pane echoing the submitted
|
|
165
|
+
prompt back no longer counts as completion evidence (echo-stripped tails
|
|
166
|
+
must carry a remainder); report reads cap before buffering (256 KB);
|
|
167
|
+
evidence polls back off 1s→2s→5s; the herdr tool's prompt-wait timeout is
|
|
168
|
+
clamped to the documented 60-min ceiling.
|
|
169
|
+
- **smaller fixes (F14/F17/F18)**: munin validation runs before the loop
|
|
170
|
+
dampener (invalid calls return validation errors, not loop guidance);
|
|
171
|
+
the ChatGPT OAuth refresh fetch gets a 15s timeout; the a2a gateway
|
|
172
|
+
reverse-channel dispatch gets a 120s timeout.
|
|
173
|
+
- **test hygiene (home-wipe incident)**: shell-gate exploit fixtures now
|
|
174
|
+
target sacrificial `/tmp` paths (never `~`/`$HOME`), a meta-test keeps the
|
|
175
|
+
fixture file free of home-pointing `rm` lines, and the repair bash guard
|
|
176
|
+
treats `~`, `$HOME`, `${HOME}` as absolute paths in its recursive-force
|
|
177
|
+
delete refusal (live-verified: the pre-fix guard waved `rm -rf ~` through).
|
|
178
|
+
|
|
3
179
|
## 0.20.0 — 2026-10-16
|
|
4
180
|
|
|
5
181
|
pi 1.3.0 compatibility pass (verified by diffing the 1.2.0 and 1.3.0
|
|
@@ -114,6 +114,51 @@ test("migrate: missing/corrupt settings.json is a silent no-op", () => {
|
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
+
test("migrate: trusted project munin.apiKey moves to .env.local and is scrubbed (F7)", () => {
|
|
118
|
+
const dir = tmpDir();
|
|
119
|
+
const prevCwd = process.cwd();
|
|
120
|
+
const project = fs.mkdtempSync(path.join(os.tmpdir(), "ceulen-env-proj-"));
|
|
121
|
+
try {
|
|
122
|
+
// Isolation: a pi session that imported env.ts with a REAL ~/.pi/agent/.env.local
|
|
123
|
+
// has MUNIN_API_KEY already in process.env — onlyAbsent would keep it and the
|
|
124
|
+
// asserts below would see the ambient value, not the migrated one.
|
|
125
|
+
delete process.env.MUNIN_API_KEY;
|
|
126
|
+
// Trust the project cwd (keyed on the REAL path process.cwd() returns
|
|
127
|
+
// after chdir — path.resolve does not resolve symlinks), then give it a
|
|
128
|
+
// plaintext munin key.
|
|
129
|
+
process.chdir(project);
|
|
130
|
+
fs.writeFileSync(path.join(dir, "trust.json"), JSON.stringify({ [process.cwd()]: true }));
|
|
131
|
+
fs.mkdirSync(path.join(project, ".pi"), { recursive: true });
|
|
132
|
+
fs.writeFileSync(path.join(project, ".pi", "settings.json"), JSON.stringify({
|
|
133
|
+
munin: { apiKey: "proj-secret", project: "my-bank" },
|
|
134
|
+
other: { keep: true },
|
|
135
|
+
}));
|
|
136
|
+
migrateSecretsFromSettings();
|
|
137
|
+
|
|
138
|
+
const envText = fs.readFileSync(path.join(dir, ".env.local"), "utf8");
|
|
139
|
+
assert.match(envText, /MUNIN_API_KEY=proj-secret/, "project key migrated");
|
|
140
|
+
assert.equal(process.env.MUNIN_API_KEY, "proj-secret");
|
|
141
|
+
|
|
142
|
+
const raw = JSON.parse(fs.readFileSync(path.join(project, ".pi", "settings.json"), "utf8"));
|
|
143
|
+
assert.equal(raw.munin.apiKey, undefined, "the key is scrubbed");
|
|
144
|
+
assert.equal(raw.munin.project, "my-bank", "non-secret munin config stays");
|
|
145
|
+
assert.deepEqual(raw.other, { keep: true }, "sibling keys stay");
|
|
146
|
+
|
|
147
|
+
// Untrusted cwd: the key stays (an untrusted checkout's settings.json is
|
|
148
|
+
// never read at all — scrubbing it would change nothing effective).
|
|
149
|
+
fs.writeFileSync(path.join(dir, "trust.json"), JSON.stringify({ [process.cwd()]: false }));
|
|
150
|
+
fs.writeFileSync(path.join(project, ".pi", "settings.json"), JSON.stringify({ munin: { apiKey: "untrusted-secret" } }));
|
|
151
|
+
migrateSecretsFromSettings();
|
|
152
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(project, ".pi", "settings.json"), "utf8")).munin.apiKey, "untrusted-secret", "untrusted file untouched");
|
|
153
|
+
} finally {
|
|
154
|
+
process.chdir(prevCwd);
|
|
155
|
+
delete process.env.MUNIN_API_KEY;
|
|
156
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
157
|
+
fs.rmSync(project, { recursive: true, force: true });
|
|
158
|
+
delete process.env.PI_CODING_AGENT_DIR;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
117
162
|
test("writeSecretEnvs: upsert + create + onlyAbsent semantics, 0600", () => {
|
|
118
163
|
const dir = tmpDir();
|
|
119
164
|
try {
|
package/extensions/lib/env.ts
CHANGED
|
@@ -95,6 +95,52 @@ function agentDirsForSecrets(): string[] {
|
|
|
95
95
|
: [path.join(os.homedir(), ".pi", "agent"), path.join(os.homedir(), ".pi", "agents")];
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
/** Trust walk for the cwd's .pi/settings.json (registry.isProjectTrusted
|
|
99
|
+
* inlined — env.ts stays a leaf). */
|
|
100
|
+
function isTrustedCwd(cwd: string): boolean {
|
|
101
|
+
const resolved = path.resolve(cwd);
|
|
102
|
+
for (const dir of agentDirsForSecrets()) {
|
|
103
|
+
const file = path.join(dir, "trust.json");
|
|
104
|
+
if (!fs.existsSync(file)) continue;
|
|
105
|
+
try {
|
|
106
|
+
const data = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
107
|
+
let current = resolved;
|
|
108
|
+
for (;;) {
|
|
109
|
+
const v = data[current];
|
|
110
|
+
if (typeof v === "boolean") return v;
|
|
111
|
+
const parent = path.dirname(current);
|
|
112
|
+
if (parent === current) break;
|
|
113
|
+
current = parent;
|
|
114
|
+
}
|
|
115
|
+
} catch { /* unreadable trust.json → not trusted */ }
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** F7 (security review 2026-10-17): munin.apiKey must not sit in the
|
|
121
|
+
* git-trackable project .pi/settings.json. When the cwd is trusted, move its
|
|
122
|
+
* munin.apiKey into `migrate` FIRST (project beats global at read time, so
|
|
123
|
+
* its value must win the onlyAbsent write) and scrub the file atomically. */
|
|
124
|
+
function migrateProjectMuninKey(migrate: Record<string, string>): boolean {
|
|
125
|
+
try {
|
|
126
|
+
const cwd = process.cwd();
|
|
127
|
+
if (!isTrustedCwd(cwd)) return false;
|
|
128
|
+
const projectFile = path.join(cwd, ".pi", "settings.json");
|
|
129
|
+
const settings = JSON.parse(fs.readFileSync(projectFile, "utf8"));
|
|
130
|
+
const munin = settings?.munin;
|
|
131
|
+
if (!munin || typeof munin !== "object" || typeof munin.apiKey !== "string" || munin.apiKey === "") return false;
|
|
132
|
+
migrate.MUNIN_API_KEY = munin.apiKey;
|
|
133
|
+
delete munin.apiKey;
|
|
134
|
+
if (Object.keys(munin).length === 0) delete settings.munin;
|
|
135
|
+
const tmp = projectFile + ".tmp";
|
|
136
|
+
fs.writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
|
|
137
|
+
fs.renameSync(tmp, projectFile);
|
|
138
|
+
return true;
|
|
139
|
+
} catch {
|
|
140
|
+
return false; // absent/corrupt/unwritable project file — nothing to do
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
98
144
|
/** Read the current secrets file as parsed entries ({} when absent). */
|
|
99
145
|
export function readSecretEnvs(agentDir?: string): Record<string, string> {
|
|
100
146
|
return readEnvFile(secretsEnvFile(agentDir));
|
|
@@ -156,16 +202,23 @@ const WEB_SECRET_ENV_BY_KEY: Record<string, string> = {
|
|
|
156
202
|
* Never throws — a failed migration leaves the (working) status quo. */
|
|
157
203
|
export function migrateSecretsFromSettings(): void {
|
|
158
204
|
try {
|
|
205
|
+
const migrate: Record<string, string> = {};
|
|
206
|
+
const scrubWeb: string[] = [];
|
|
207
|
+
// Project munin key FIRST (F7): it must also run when the GLOBAL
|
|
208
|
+
// settings.json is absent/corrupt — its early return below still has to
|
|
209
|
+
// flush this env write.
|
|
210
|
+
migrateProjectMuninKey(migrate);
|
|
159
211
|
const dir = agentDirsForSecrets()[0]!;
|
|
160
212
|
const settingsFile = path.join(dir, "settings.json");
|
|
161
213
|
let settings: Record<string, any>;
|
|
162
214
|
try {
|
|
163
215
|
settings = JSON.parse(fs.readFileSync(settingsFile, "utf8"));
|
|
164
216
|
} catch {
|
|
165
|
-
|
|
217
|
+
// Absent/corrupt — nothing else to migrate, but a project-file find
|
|
218
|
+
// above still lands in .env.local.
|
|
219
|
+
if (Object.keys(migrate).length > 0) writeSecretEnvs(migrate, { agentDir: dir, onlyAbsent: true });
|
|
220
|
+
return;
|
|
166
221
|
}
|
|
167
|
-
const migrate: Record<string, string> = {};
|
|
168
|
-
const scrubWeb: string[] = [];
|
|
169
222
|
// web section: flat or nested secret keys.
|
|
170
223
|
const web = settings.web && typeof settings.web === "object" ? settings.web : {};
|
|
171
224
|
for (const [key, envName] of Object.entries(WEB_SECRET_ENV_BY_KEY)) {
|
|
@@ -50,6 +50,8 @@ import attachmentsModule from "../modules/attachments/index.ts";
|
|
|
50
50
|
import { attachmentsConfig } from "../modules/attachments/configPanel.ts";
|
|
51
51
|
import cronModule from "../modules/cron/index.ts";
|
|
52
52
|
import { cronConfig } from "../modules/cron/configPanel.ts";
|
|
53
|
+
import goalModule from "../modules/goal/index.ts";
|
|
54
|
+
import { goalConfig } from "../modules/goal/configPanel.ts";
|
|
53
55
|
import permissionModule from "../modules/permission/index.ts";
|
|
54
56
|
import shellsModule from "../modules/shells/index.ts";
|
|
55
57
|
import sgModule from "../modules/sg/index.ts";
|
|
@@ -163,6 +165,12 @@ export const MODULES: ModuleEntry[] = [
|
|
|
163
165
|
// Cron after todo: scheduled prompts into the live session (the clock-driven
|
|
164
166
|
// sibling of the task board). No before_agent_start → no ordering constraint.
|
|
165
167
|
{ 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, deferredTools: ["cron"] },
|
|
168
|
+
// Goal after cron: the autonomy sibling (cron is clock-driven, goal is
|
|
169
|
+
// condition-driven). It IS a before_agent_start composer (append-only
|
|
170
|
+
// goal_context) — must precede rules/steering like every prompt composer.
|
|
171
|
+
// `goal` tool stays DIRECT (munin-loop lesson: a protocol's terminal action
|
|
172
|
+
// never rides the deferred tier); plan mode blocks it via plan-tools.ts.
|
|
173
|
+
{ name: "goal", category: "Tasks", describe: "Autonomous goal mode: /goal sets an objective; the loop re-injects continuation after every settled turn until the agent verifies completion via the goal tool, hits the token budget or turn cap, or you pause.", load: goalModule, config: goalConfig },
|
|
166
174
|
// ── Tools ─────────────────────────────────────────────────────────────
|
|
167
175
|
// Repair first in the section: it wraps the built-in tools; serena/fff ride
|
|
168
176
|
// on top (no load-order dependency — hooks resolve at call time).
|
|
@@ -24,7 +24,7 @@ describe("skillsRoot", () => {
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
it("joins to this package's own skill dirs", () => {
|
|
27
|
-
for (const name of ["web", "munin", "a2a", "ponytail", "ux-design"]) {
|
|
27
|
+
for (const name of ["web", "munin", "a2a", "ponytail", "ux-design", "cron", "review"]) {
|
|
28
28
|
assert.ok(existsSync(join(skillsRoot(), name)), `skill dir exists: ${name}`);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
@@ -835,6 +835,9 @@ export class ChannelClient {
|
|
|
835
835
|
method: env.method,
|
|
836
836
|
headers,
|
|
837
837
|
body: ["GET", "HEAD"].includes(env.method) ? undefined : binary,
|
|
838
|
+
// F18: the reverse-channel dispatch must not leak an inflight promise
|
|
839
|
+
// when the local server never answers.
|
|
840
|
+
signal: AbortSignal.timeout(120_000),
|
|
838
841
|
});
|
|
839
842
|
const buf = new Uint8Array(await res.arrayBuffer());
|
|
840
843
|
if (buf.length > MAX_CHANNEL_BODY) {
|
|
@@ -44,8 +44,9 @@ export function persistMessage(opts: {
|
|
|
44
44
|
peer: opts.peer,
|
|
45
45
|
};
|
|
46
46
|
const p = fileFor(opts.piDir, opts.contextId);
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
// 0700/0600: transcripts are private peer conversations (F12).
|
|
48
|
+
mkdirSync(dir(opts.piDir), { recursive: true, mode: 0o700 });
|
|
49
|
+
appendFileSync(p, JSON.stringify(rec) + "\n", { encoding: "utf-8", mode: 0o600 });
|
|
49
50
|
} catch {
|
|
50
51
|
/* best-effort persistence */
|
|
51
52
|
}
|
|
@@ -10,6 +10,18 @@ function tmpDir(): string {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
describe("persistence", () => {
|
|
13
|
+
it("writes transcripts 0600 into a 0700 dir (F12)", () => {
|
|
14
|
+
const dir = tmpDir();
|
|
15
|
+
persistMessage({ piDir: dir, contextId: "ctx-sec", role: "user", text: "secret" });
|
|
16
|
+
const p = childTranscriptDir(dir) === dir ? dir : path.join(dir, "a2a_sessions");
|
|
17
|
+
// Find the transcript file wherever fileFor put it.
|
|
18
|
+
const walk = (d: string): string[] =>
|
|
19
|
+
fs.existsSync(d) ? fs.readdirSync(d, { withFileTypes: true }).flatMap((e) => e.isDirectory() ? walk(path.join(d, e.name)) : [path.join(d, e.name)]) : [];
|
|
20
|
+
const files = walk(dir).filter((f) => f.endsWith(".jsonl"));
|
|
21
|
+
assert.lengthOf(files, 1);
|
|
22
|
+
assert.equal(fs.statSync(files[0]!).mode & 0o777, 0o600, "transcript file is 0600");
|
|
23
|
+
});
|
|
24
|
+
|
|
13
25
|
it("round-trips messages to JSONL", () => {
|
|
14
26
|
const dir = tmpDir();
|
|
15
27
|
persistMessage({ piDir: dir, contextId: "ctx-1", role: "user", text: "hello" });
|
|
@@ -32,6 +32,7 @@ import { join } from "node:path";
|
|
|
32
32
|
import { Type } from "typebox";
|
|
33
33
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
34
34
|
import { getClassifierSettings } from "./lib/settings.js";
|
|
35
|
+
import { registerThinkGate } from "./lib/think-gate.js";
|
|
35
36
|
import { setClassifierRegistry } from "./configPanel.js";
|
|
36
37
|
|
|
37
38
|
// ── Risk gate (static, before Jev ever sees a command) ──────────────────────
|
|
@@ -42,6 +43,7 @@ const RISKY = [
|
|
|
42
43
|
/\bgit\s+push\b[^|;&]*--force/, /\bgit\s+push\s+-f\b/, /\bgit\s+reset\s+--hard\b/,
|
|
43
44
|
/curl[^|;&]*\|\s*(ba)?sh/, /wget[^|;&]*\|\s*(ba)?sh/, // pipe-to-shell
|
|
44
45
|
/\b(npm|pnpm|yarn|bun)\s+publish\b/, /\bgh\s+release\s+(create|upload)\b/,
|
|
46
|
+
/\bcargo\s+publish\b/, /\btwine\s+upload\b/, /\bgem\s+push\b/,
|
|
45
47
|
/\bterraform\s+(apply|destroy)\b/, /\bkubectl\s+(delete|apply)\b/,
|
|
46
48
|
/(^|\s)~?\/?\.?(ssh|aws|gnupg|kube)(\/|$)/, /id_rsa|\.pem\b|credentials\b/i,
|
|
47
49
|
];
|
|
@@ -166,6 +168,12 @@ export function getLastTask(): string {
|
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
export default function (pi: ExtensionAPI) {
|
|
171
|
+
// Main-session per-turn thinking gate (classifier.thinkGate, default off —
|
|
172
|
+
// planGate pattern). Register the handlers even while off: settings are read
|
|
173
|
+
// per turn, so a settings.json flip needs no /reload. Returns undefined —
|
|
174
|
+
// never touches systemPrompt (steering load-order contract).
|
|
175
|
+
registerThinkGate(pi);
|
|
176
|
+
|
|
169
177
|
// The /config contribution reads discovered decision models at open time;
|
|
170
178
|
// config factories get no ctx, so the module stashes the live registry
|
|
171
179
|
// here (the panel always opens after a session exists). Cleared on shutdown
|
|
@@ -263,7 +271,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
263
271
|
const CLASSIFIER_HOOK_BUDGET_MS = 2_500;
|
|
264
272
|
|
|
265
273
|
pi.on("tool_call", async (event, ctx) => {
|
|
266
|
-
|
|
274
|
+
// F4: a shell tool START runs a shell command with shell:true — the same
|
|
275
|
+
// exposure as bash, so it gets the same risky-hook annotation.
|
|
276
|
+
const isShellStart = event.toolName === "shell" && event.input?.action === "start";
|
|
277
|
+
if (event.toolName !== "bash" && !isShellStart) return undefined;
|
|
267
278
|
const command = String(event.input?.command || "");
|
|
268
279
|
if (!command) return undefined;
|
|
269
280
|
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
// "observe": false, // log-only audit pass — verdicts land in classifier.log, nothing changes
|
|
19
19
|
// "threshold": 0.9 // p(reversible) must clear it for an auto-run
|
|
20
20
|
// }
|
|
21
|
+
//
|
|
22
|
+
// `thinkGate` (ceulen; main-session per-turn thinking level):
|
|
23
|
+
//
|
|
24
|
+
// "thinkGate": {
|
|
25
|
+
// "enabled": false, // let the gate SET the session thinking level per user turn
|
|
26
|
+
// "observe": false, // log-only audit pass — verdicts land in classifier.log
|
|
27
|
+
// "threshold": 0.6 // the score answer's confidence must clear it
|
|
28
|
+
// }
|
|
21
29
|
|
|
22
30
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
23
31
|
import { homedir } from "node:os";
|
|
@@ -36,6 +44,11 @@ export interface ClassifierSettings {
|
|
|
36
44
|
observe: boolean;
|
|
37
45
|
threshold: number;
|
|
38
46
|
};
|
|
47
|
+
thinkGate: {
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
observe: boolean;
|
|
50
|
+
threshold: number;
|
|
51
|
+
};
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
function agentDir(): string {
|
|
@@ -62,6 +75,7 @@ export function getClassifierSettings(): ClassifierSettings {
|
|
|
62
75
|
const c = raw.classifier && typeof raw.classifier === "object" ? (raw.classifier as Record<string, unknown>) : {};
|
|
63
76
|
const perm = c.permission && typeof c.permission === "object" ? (c.permission as Record<string, unknown>) : {};
|
|
64
77
|
const gate = c.planGate && typeof c.planGate === "object" ? (c.planGate as Record<string, unknown>) : {};
|
|
78
|
+
const think = c.thinkGate && typeof c.thinkGate === "object" ? (c.thinkGate as Record<string, unknown>) : {};
|
|
65
79
|
return {
|
|
66
80
|
model: typeof c.model === "string" ? c.model.trim() : "",
|
|
67
81
|
permission: {
|
|
@@ -77,6 +91,13 @@ export function getClassifierSettings(): ClassifierSettings {
|
|
|
77
91
|
observe: gate.observe === true,
|
|
78
92
|
threshold: typeof gate.threshold === "number" && gate.threshold > 0 && gate.threshold < 1 ? gate.threshold : 0.9,
|
|
79
93
|
},
|
|
94
|
+
// Default 0.6 = subagent-routing effort precedent (the dial is reversible
|
|
95
|
+
// mid-turn via /think; planGate's 0.9 is for destructive auto-run).
|
|
96
|
+
thinkGate: {
|
|
97
|
+
enabled: think.enabled === true,
|
|
98
|
+
observe: think.observe === true,
|
|
99
|
+
threshold: typeof think.threshold === "number" && think.threshold > 0 && think.threshold < 1 ? think.threshold : 0.6,
|
|
100
|
+
},
|
|
80
101
|
};
|
|
81
102
|
}
|
|
82
103
|
|