ceulen 0.16.1 → 0.18.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 +81 -1
- package/extensions/lib/registry.test.ts +5 -2
- package/extensions/lib/registry.ts +7 -2
- package/extensions/modules/a2a/lib/client.ts +2 -1
- package/extensions/modules/advisor/commands/advisor.ts +22 -12
- package/extensions/modules/advisor/test/module.test.ts +26 -0
- package/extensions/modules/munin/index.ts +93 -6
- package/extensions/modules/munin/test/extension.test.ts +124 -0
- package/extensions/modules/plan/index.ts +64 -0
- package/extensions/modules/plan/test/module.test.ts +112 -0
- package/extensions/modules/steering/index.ts +25 -6
- package/extensions/modules/steering/test/anchor-regressions.test.ts +38 -0
- package/package.json +3 -3
- package/scripts/validate-themes.mjs +31 -3
- package/skills/munin/SKILL.md +1 -1
- package/themes/alabaster.json +2 -17
- package/themes/amethyst.json +2 -19
- package/themes/anthracite.json +2 -22
- package/themes/basalt.json +3 -31
- package/themes/birch.json +2 -19
- package/themes/catppuccin-mocha.json +1 -7
- package/themes/dark-abyss.json +2 -17
- package/themes/dark-arctic.json +2 -23
- package/themes/dark-aurora.json +2 -18
- package/themes/dark-catppuccin.json +2 -25
- package/themes/dark-cavern.json +2 -18
- package/themes/dark-celestial.json +2 -18
- package/themes/dark-copper.json +2 -18
- package/themes/dark-cosmos.json +2 -17
- package/themes/dark-cyberpunk.json +2 -21
- package/themes/dark-dracula.json +2 -20
- package/themes/dark-eclipse.json +2 -18
- package/themes/dark-ember.json +2 -18
- package/themes/dark-equinox.json +2 -17
- package/themes/dark-forest.json +2 -21
- package/themes/dark-github.json +2 -24
- package/themes/dark-gruvbox.json +2 -30
- package/themes/dark-lavender.json +2 -18
- package/themes/dark-lunar.json +2 -17
- package/themes/dark-midnight.json +2 -18
- package/themes/dark-monochrome.json +2 -19
- package/themes/dark-monokai.json +2 -21
- package/themes/dark-nebula.json +2 -18
- package/themes/dark-neon-noir.json +2 -21
- package/themes/dark-nord.json +2 -21
- package/themes/dark-ocean.json +2 -22
- package/themes/dark-one.json +2 -21
- package/themes/dark-poimandres.json +4 -41
- package/themes/dark-rainforest.json +2 -17
- package/themes/dark-reef.json +2 -18
- package/themes/dark-retro.json +2 -18
- package/themes/dark-rose-pine.json +3 -21
- package/themes/dark-sakura.json +2 -18
- package/themes/dark-slate.json +2 -18
- package/themes/dark-solarized.json +2 -23
- package/themes/dark-solstice.json +2 -17
- package/themes/dark-starfall.json +2 -17
- package/themes/dark-sunset.json +2 -23
- package/themes/dark-swamp.json +2 -18
- package/themes/dark-synthwave.json +2 -25
- package/themes/dark-taiga.json +2 -17
- package/themes/dark-terminal.json +2 -18
- package/themes/dark-tokyo-night.json +2 -23
- package/themes/dark-tundra.json +2 -18
- package/themes/dark-twilight.json +2 -17
- package/themes/dark-volcanic.json +2 -17
- package/themes/dark.json +2 -6
- package/themes/graphite.json +2 -21
- package/themes/light-arctic.json +2 -27
- package/themes/light-aurora-day.json +2 -18
- package/themes/light-canyon.json +2 -17
- package/themes/light-catppuccin.json +3 -24
- package/themes/light-cirrus.json +2 -18
- package/themes/light-coral.json +2 -18
- package/themes/light-cyberpunk.json +2 -19
- package/themes/light-dawn.json +2 -17
- package/themes/light-dunes.json +2 -17
- package/themes/light-eucalyptus.json +2 -18
- package/themes/light-forest.json +3 -24
- package/themes/light-frost.json +2 -18
- package/themes/light-github.json +3 -39
- package/themes/light-glacier.json +2 -17
- package/themes/light-gruvbox.json +3 -30
- package/themes/light-haze.json +2 -18
- package/themes/light-honeycomb.json +2 -18
- package/themes/light-lagoon.json +2 -17
- package/themes/light-lavender.json +2 -18
- package/themes/light-meadow.json +2 -17
- package/themes/light-mint.json +2 -18
- package/themes/light-monochrome.json +2 -21
- package/themes/light-ocean.json +2 -20
- package/themes/light-one.json +2 -20
- package/themes/light-opal.json +2 -18
- package/themes/light-orchard.json +2 -18
- package/themes/light-paper.json +2 -18
- package/themes/light-poimandres.json +4 -41
- package/themes/light-prism.json +2 -19
- package/themes/light-retro.json +3 -21
- package/themes/light-sand.json +2 -18
- package/themes/light-savanna.json +2 -17
- package/themes/light-solarized.json +2 -22
- package/themes/light-soleil.json +2 -18
- package/themes/light-sunset.json +2 -22
- package/themes/light-synthwave.json +2 -22
- package/themes/light-tokyo-night.json +3 -28
- package/themes/light-wetland.json +2 -17
- package/themes/light-zenith.json +2 -18
- package/themes/light.json +2 -6
- package/themes/limestone.json +2 -19
- package/themes/mahogany.json +2 -19
- package/themes/marble.json +2 -19
- package/themes/mirage.json +2 -6
- package/themes/obsidian.json +2 -19
- package/themes/onyx.json +2 -17
- package/themes/pearl.json +2 -21
- package/themes/porcelain.json +2 -17
- package/themes/quartz.json +2 -19
- package/themes/sandstone.json +2 -20
- package/themes/titanium.json +2 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,79 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.18.0 — 2026-10-14
|
|
4
|
+
|
|
5
|
+
pi 1.2.0 compatibility + the ask_user_question confirmation loop (incident
|
|
6
|
+
report 2026-10-14, session 01a12a6c: six consecutive permission dialogs, each
|
|
7
|
+
answered, with the dispatch they were asking about never sent):
|
|
8
|
+
|
|
9
|
+
- **Themes broke on pi 1.2.0 — all 104 shipped themes failed to load**
|
|
10
|
+
(`Error: Failed to load theme "titanium": Theme not found: titanium` →
|
|
11
|
+
system fallback). pi 1.2.0 validates themes at startup against a schema with
|
|
12
|
+
`additionalProperties: false` at both the root object and `colors`; 100 of
|
|
13
|
+
the 104 themes carried non-schema keys inherited from the pi-themes port
|
|
14
|
+
(`statusLine*` ×14, `pythonMode`, `link`, `toolText`) that pi and ceulen both
|
|
15
|
+
ignore. Validation threw, the resource loader swallowed it as a diagnostic,
|
|
16
|
+
and the theme silently vanished. All 104 themes are now schema-clean (their
|
|
17
|
+
255 orphaned `vars` pruned, `$schema` repointed to
|
|
18
|
+
`https://pi.dev/schemas/theme.schema.json`), and `scripts/validate-themes.mjs`
|
|
19
|
+
— which runs in `npm test` — gained ALLOWED/ROOT/EXPORT gates mirroring pi's
|
|
20
|
+
closed schema, so a stray key fails the suite instead of vanishing at boot.
|
|
21
|
+
Verified against pi 1.2.0's own validator: 4/104 → 104/104, all 104 also
|
|
22
|
+
build a Theme instance.
|
|
23
|
+
- **Peer deps widened** to `>=0.99.1 <1.3.0` for both `@earendil-works/pi-coding-agent`
|
|
24
|
+
and `@earendil-works/pi-tui` — the old range excluded 1.2.0 semver-wise. Dev
|
|
25
|
+
lockfile refreshed; typecheck + full suite now run against 1.2.0 types.
|
|
26
|
+
- **steering**: pi 1.2.0 made `BeforeAgentStartEvent` a union on `messageType`
|
|
27
|
+
(`prompt`/`images` only on the `"user"` variant) and now fires
|
|
28
|
+
`before_agent_start` for `sendMessage({triggerTurn:true})` runs too (cron
|
|
29
|
+
fires, repair auto-bg follow-ups, subagent receipts). The first-tool hints
|
|
30
|
+
read `event.prompt` (3 type errors) and the ds-anchor bootstrap could be
|
|
31
|
+
consumed by a machine-initiated run — running a cron task under the DSH
|
|
32
|
+
minimal prompt with bash/str_replace_editor only. Custom runs now skip the
|
|
33
|
+
bootstrap and the prompt-derived hints; the bootstrap stays pending for the
|
|
34
|
+
next user turn. Tested as "not custom" (not `=== "user"`), since pi ≤1.1.0
|
|
35
|
+
sends no `messageType`. 2 new tests.
|
|
36
|
+
- **plan**: `ask_user_question` gains a two-arm loop dampener. Either arm alone
|
|
37
|
+
has a hole: an identical-args guard misses the incident's reworded repeats
|
|
38
|
+
("Ready to execute…dispatch…peer now?" → "Execute: dispatch to peer now?" →
|
|
39
|
+
"Dispatch now?" → "Dispatch?"). Arm A refuses a near-duplicate of an
|
|
40
|
+
already-answered question (stopword-filtered content-word containment, cut at
|
|
41
|
+
0.8 — the incident's rewording scores 1.00 every time, the closest distinct
|
|
42
|
+
pair 0.67; replaying the incident it fires at ask #2). Arm B is the
|
|
43
|
+
wording-blind backstop: a 4th ask with no other tool call in between. The
|
|
44
|
+
guard returns the earlier question + answer and an instruction to act instead
|
|
45
|
+
of opening another dialog; any other tool call or a new session clears it.
|
|
46
|
+
8 new tests.
|
|
47
|
+
- **advisor**: a whole-chain consult failure now wraps the raw provider error
|
|
48
|
+
(`400 insufficient credits` is what spun the model into asking) with what it
|
|
49
|
+
means and what to do — continue without guidance, do not stall the user.
|
|
50
|
+
1 new test.
|
|
51
|
+
- **a2a**: the reply-timeout error now points at `a2a_status` and
|
|
52
|
+
`async_dispatch: true` before re-sending, and notes a duplicate synchronous
|
|
53
|
+
send can double-deliver.
|
|
54
|
+
|
|
55
|
+
## 0.17.0 — 2026-10-13
|
|
56
|
+
|
|
57
|
+
- **Munin loop fixed** (incident report 2026-10-12; two sessions on
|
|
58
|
+
glm-5.3-flash looped 30/33 consecutive munin_search/munin_get calls while
|
|
59
|
+
intending munin_store, losing both sessions' memories):
|
|
60
|
+
- `munin_store` promoted DIRECT — a deferred store silently vanished from
|
|
61
|
+
the live tool schema across plan-mode transitions / branch restores, and
|
|
62
|
+
a model cannot emit a tool absent from its request's tool array, so it
|
|
63
|
+
looped on the always-declared read neighbors instead. The protocol's
|
|
64
|
+
terminal action is now declared in every configured session (plan mode
|
|
65
|
+
still blocks it via BLOCKED_TOOLS). Guarded by the registry tier test.
|
|
66
|
+
- Consecutive-call loop dampener on the munin read tools: the 3rd identical
|
|
67
|
+
-args call or 6th same-tool call (any args — incident A's queries
|
|
68
|
+
degenerated/varied) returns guidance ("call munin_store directly")
|
|
69
|
+
instead of executing. Resets on a different munin tool, ANY non-munin
|
|
70
|
+
tool_call (protocol-compliant search→work→search sessions never
|
|
71
|
+
accumulate), session_start, and after guidance fires. 7 new tests.
|
|
72
|
+
- Protocol header + skill text aligned: "munin_search/munin_get/
|
|
73
|
+
munin_store are always declared".
|
|
74
|
+
- Live-verified post-reload (4 probes: schema declaration, both dampener
|
|
75
|
+
rules, non-munin reset).
|
|
76
|
+
|
|
3
77
|
## 0.16.1 — 2026-10-10
|
|
4
78
|
|
|
5
79
|
- **herdr stall recovery rewritten on output evidence** — live probing
|
|
@@ -17,7 +91,13 @@
|
|
|
17
91
|
across all five agent types under 4-way concurrency, including a mid-turn
|
|
18
92
|
Z.ai 429 recovery; 6 new regression tests (`test/herdr-stalled.test.ts`).
|
|
19
93
|
|
|
20
|
-
## 0.16.0 — 2026-10-09
|
|
94
|
+
## 0.16.0 — 2026-10-09 (never released separately)
|
|
95
|
+
|
|
96
|
+
The v0.16.0 tag/release was not created (bump+changelog landed in commit
|
|
97
|
+
`901cc0e`, but the tag step was skipped), so publish.yml never ran for it and
|
|
98
|
+
npm jumped 0.15.2 → 0.16.1. Its full content ships inside **0.16.1** together
|
|
99
|
+
with the a474b… review wave (27 defect fixes) — do not create a v0.16.0
|
|
100
|
+
release retroactively: it would publish a pre-security-fix artifact.
|
|
21
101
|
|
|
22
102
|
- **RTK selective rewrite** — the prompt note states the policy honestly
|
|
23
103
|
(RTK rewrites only what it models; chains, redirects, and inline scripts
|
|
@@ -50,11 +50,14 @@ describe("isProjectTrusted", () => {
|
|
|
50
50
|
|
|
51
51
|
describe("deferredTools tiers", () => {
|
|
52
52
|
// 2026-10-08 usage re-eval: these four were promoted from deferred to
|
|
53
|
-
// direct.
|
|
53
|
+
// direct. 2026-10-12 munin-loop incident: munin_store joined them — a
|
|
54
|
+
// deferred store vanished from the live schema across plan-mode/branch
|
|
55
|
+
// restores and the model looped on the read neighbors. A registry edit that
|
|
56
|
+
// silently reverts any of these must fail here.
|
|
54
57
|
it("keeps the promoted hot tools out of every deferred list", async () => {
|
|
55
58
|
const { MODULES } = await import("./registry.js");
|
|
56
59
|
const allDeferred = new Set(MODULES.flatMap((m) => m.deferredTools ?? []));
|
|
57
|
-
for (const hot of ["munin_search", "munin_get", "github", "ux_audit"]) {
|
|
60
|
+
for (const hot of ["munin_search", "munin_get", "munin_store", "github", "ux_audit"]) {
|
|
58
61
|
assert.equal(allDeferred.has(hot), false, `${hot} must stay direct`);
|
|
59
62
|
}
|
|
60
63
|
});
|
|
@@ -134,11 +134,16 @@ export const MODULES: ModuleEntry[] = [
|
|
|
134
134
|
// munin_search + munin_get are DIRECT (2026-10-08 usage re-eval): the Memory
|
|
135
135
|
// Protocol is injected into every configured session and its before-acting
|
|
136
136
|
// rule is a search — forcing a tool_search round-trip first was pure
|
|
137
|
-
// latency.
|
|
137
|
+
// latency. munin_store joined them DIRECT (2026-10-12 munin-loop incident):
|
|
138
|
+
// it is the protocol's terminal action (every configured session's last
|
|
139
|
+
// munin call), and a deferred store silently vanished from the live schema
|
|
140
|
+
// across plan-mode transitions / branch restores — the model then cannot
|
|
141
|
+
// emit it at all and loops on the always-declared read neighbors (two full
|
|
142
|
+
// sessions lost). The remaining five stay deferred: list/recent/delete/
|
|
138
143
|
// capabilities/share are needed only after search/get evidence is in hand
|
|
139
144
|
// (and store/delete/share stay behind plan mode's BLOCKED_TOOLS).
|
|
140
145
|
{ name: "munin", category: "Memory", describe: "Munin long-term memory tools (search/get/store/list/recent/delete/capabilities/share) + memory protocol. Config at project level.", load: muninModule, config: muninConfig, deferredTools: [
|
|
141
|
-
"
|
|
146
|
+
"munin_list", "munin_recent", "munin_delete", "munin_capabilities", "munin_share",
|
|
142
147
|
] },
|
|
143
148
|
// ── Tasks ──────────────────────────────────────────────────────────────
|
|
144
149
|
{ name: "ponytail", category: "Tasks", describe: "Lazy-senior-dev mode: prompts, skills, subagent instructions.", load: ponytailModule, config: ponytailConfig },
|
|
@@ -224,7 +224,8 @@ async function postJsonRpc(
|
|
|
224
224
|
} catch (e: any) {
|
|
225
225
|
if (ctrl.signal.aborted) {
|
|
226
226
|
throw new Error(
|
|
227
|
-
`reply timed out after ${timeoutMs}ms; delivery status unknown (requestId=${String(body.id)})
|
|
227
|
+
`reply timed out after ${timeoutMs}ms; delivery status unknown (requestId=${String(body.id)}). ` +
|
|
228
|
+
`The peer may still be working: check a2a_status before re-sending, and use async_dispatch: true for a peer that is routinely slow — a second synchronous send can double-deliver the work.`,
|
|
228
229
|
);
|
|
229
230
|
}
|
|
230
231
|
throw new Error(`connection failed — ${e?.message || String(e)}`);
|
|
@@ -119,18 +119,28 @@ export function registerAdvisor(pi: ExtensionAPI, state: AdvisorState): AdvisorH
|
|
|
119
119
|
// must not leave its partial output above the next candidate's response.
|
|
120
120
|
let output = "";
|
|
121
121
|
let attempt = 0;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
122
|
+
let result;
|
|
123
|
+
try {
|
|
124
|
+
result = await runIsolatedChain(ctx, models, {
|
|
125
|
+
systemPrompt: `${SYSTEM}\n\nPRIMARY AGENT SYSTEM PROMPT:\n${ctx.getSystemPrompt()}`,
|
|
126
|
+
messages: [{
|
|
127
|
+
role: "user",
|
|
128
|
+
content: [{ type: "text", text: `<transcript>${transcriptEvidence}</transcript>\n\nProvide strategic guidance for the executor.` }],
|
|
129
|
+
timestamp: Date.now(),
|
|
130
|
+
}],
|
|
131
|
+
}, (delta, forAttempt) => {
|
|
132
|
+
if (forAttempt !== attempt) { attempt = forAttempt; output = ""; }
|
|
133
|
+
output += delta;
|
|
134
|
+
onUpdate?.({ content: [{ type: "text", text: output }], details: { models } });
|
|
135
|
+
}, signal);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
// The whole chain failed (provider/key/quota — e.g. a 400 "insufficient
|
|
138
|
+
// credits"). A bare provider string reads to weak models as "the session
|
|
139
|
+
// is broken, so stall and ask the user" — the 2026-10-14 ask-loop
|
|
140
|
+
// incident started exactly here. Say what it means and what to do.
|
|
141
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
142
|
+
throw new Error(`Advisor unavailable (chain ${chain}): ${reason}\nContinue the task without advisor guidance. Do not tell the user the advisor failed and do not ask them to retry it — it is an optional second opinion, not a gate.`);
|
|
143
|
+
}
|
|
134
144
|
return {
|
|
135
145
|
content: [{ type: "text", text: `Advice from ${result.model}:\n${result.text}\n\nAdvisor usage: ${usageLine(result.usage.input, result.usage.output, result.usage.cost)}` }],
|
|
136
146
|
details: { models, served: result.model },
|
|
@@ -683,3 +683,29 @@ describe("writeAdvisorSettings integration", () => {
|
|
|
683
683
|
function cmdStatus(state: any, ctx: any): void {
|
|
684
684
|
state.commands.get("advisor").handler("status", ctx);
|
|
685
685
|
}
|
|
686
|
+
|
|
687
|
+
describe("consult tool — chain exhaustion message", () => {
|
|
688
|
+
it("wraps a raw provider failure with what it means and what to do", async () => {
|
|
689
|
+
writeSettings({ advisor: { enabled: true, models: [MODEL] } });
|
|
690
|
+
const { pi, state } = createFakePi();
|
|
691
|
+
advisorModule(pi);
|
|
692
|
+
const ctx = available(fakeCtx([]));
|
|
693
|
+
await fire(pi, state, "session_start", ctx);
|
|
694
|
+
const tool = state.tools.get("advisor");
|
|
695
|
+
assert.ok(tool, "consult tool registered");
|
|
696
|
+
// The provider rejects the call (the 400 "insufficient credits" shape).
|
|
697
|
+
ctx.modelRegistry.streamSimple = () => {
|
|
698
|
+
throw new Error('400: {"message":"You have insufficient credits to make this request."}');
|
|
699
|
+
};
|
|
700
|
+
await assert.rejects(
|
|
701
|
+
() => tool.execute("tc1", {}, undefined, undefined, ctx),
|
|
702
|
+
(err: Error) => {
|
|
703
|
+
assert.match(err.message, /Advisor unavailable \(chain /, "names the failed chain");
|
|
704
|
+
assert.match(err.message, /insufficient credits/, "keeps the provider reason");
|
|
705
|
+
assert.match(err.message, /Continue the task without advisor guidance/, "tells the model to proceed");
|
|
706
|
+
assert.match(err.message, /Do not tell the user the advisor failed/, "forbids the stall-and-ask loop");
|
|
707
|
+
return true;
|
|
708
|
+
},
|
|
709
|
+
);
|
|
710
|
+
});
|
|
711
|
+
});
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Ported from @bacnh85/pi-munin 0.5.12 extensions/index.ts (SDK vendored to
|
|
4
4
|
// lib/sdk.ts; dotenv dropped — ceulen's bundle env.ts ingests trusted .env).
|
|
5
|
-
// Registers the 8 munin_* tools (search/get direct; the other
|
|
6
|
-
// tool_search loads them),
|
|
5
|
+
// Registers the 8 munin_* tools (search/get/store direct; the other five
|
|
6
|
+
// deferred — tool_search loads them), the consecutive-call loop dampener,
|
|
7
7
|
// /munin-status, the Munin Memory Protocol injection (only when configured),
|
|
8
8
|
// the tool_result error sanitizer, and the munin skill (resources_discover).
|
|
9
9
|
// Config lives at PROJECT level (.pi/settings.json `munin` section) — see
|
|
@@ -69,8 +69,8 @@ const MUNIN_PROTOCOL_HEADER = `## Munin Memory Protocol
|
|
|
69
69
|
|
|
70
70
|
Use Munin to recover and preserve verified project knowledge, not as a task log.
|
|
71
71
|
If Munin is unavailable, state that briefly when it matters and continue from
|
|
72
|
-
repository evidence. munin_search/munin_get are always declared;
|
|
73
|
-
munin_* tools load on demand with one tool_search call for "munin".
|
|
72
|
+
repository evidence. munin_search/munin_get/munin_store are always declared;
|
|
73
|
+
the other munin_* tools load on demand with one tool_search call for "munin".
|
|
74
74
|
|
|
75
75
|
### Before acting
|
|
76
76
|
|
|
@@ -265,7 +265,65 @@ function invokeMuninAction(
|
|
|
265
265
|
// generic (same pattern as ux_audit).
|
|
266
266
|
type AnyTool = ToolDefinition<any, unknown>;
|
|
267
267
|
|
|
268
|
-
|
|
268
|
+
/** Read-only munin tools the dampener may suppress (mutators are confirm-gated
|
|
269
|
+
* already; suppress-on-repeat has no legitimacy case there). */
|
|
270
|
+
const DAMPENED_TOOLS = new Set(["munin_search", "munin_get", "munin_list", "munin_recent"]);
|
|
271
|
+
|
|
272
|
+
/** Loop-dampener state (2026-10-12 munin-loop incident: a model intending
|
|
273
|
+
* munin_store emitted the always-declared read neighbors 30/33× and could not
|
|
274
|
+
* stop). Tracks the CONSECUTIVE munin_* run: same-tool run length and the
|
|
275
|
+
* identical-args run length. Reset by a different munin tool, ANY non-munin
|
|
276
|
+
* tool call (a protocol-compliant session interleaves non-munin work between
|
|
277
|
+
* searches — it must never accumulate), session_start, and after guidance
|
|
278
|
+
* fires (a renewed loop re-trips the same threshold). */
|
|
279
|
+
interface DampenerState {
|
|
280
|
+
lastTool: string | undefined;
|
|
281
|
+
runCount: number;
|
|
282
|
+
lastArgsSig: string | undefined;
|
|
283
|
+
identicalRunCount: number;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function createDampener() {
|
|
287
|
+
const state: DampenerState = { lastTool: undefined, runCount: 0, lastArgsSig: undefined, identicalRunCount: 0 };
|
|
288
|
+
|
|
289
|
+
function reset(): void {
|
|
290
|
+
state.lastTool = undefined;
|
|
291
|
+
state.runCount = 0;
|
|
292
|
+
state.lastArgsSig = undefined;
|
|
293
|
+
state.identicalRunCount = 0;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Record one munin tool call; returns guidance (do-not-execute) only for
|
|
297
|
+
* read tools: 3rd consecutive identical-args call, or 6th consecutive
|
|
298
|
+
* same-tool call with any args (incident A's queries degenerated/varied —
|
|
299
|
+
* an identical-args-only rule would have missed it). */
|
|
300
|
+
function dampenCheck(name: string, params: Record<string, unknown>): { text: string; runCount: number; identicalRunCount: number } | undefined {
|
|
301
|
+
if (name !== state.lastTool) {
|
|
302
|
+
state.lastTool = name;
|
|
303
|
+
state.runCount = 1;
|
|
304
|
+
state.identicalRunCount = 0;
|
|
305
|
+
state.lastArgsSig = undefined;
|
|
306
|
+
} else {
|
|
307
|
+
state.runCount += 1;
|
|
308
|
+
}
|
|
309
|
+
const sig = JSON.stringify(Object.entries(params ?? {}).sort());
|
|
310
|
+
state.identicalRunCount = sig === state.lastArgsSig ? state.identicalRunCount + 1 : 1;
|
|
311
|
+
state.lastArgsSig = sig;
|
|
312
|
+
|
|
313
|
+
if (!DAMPENED_TOOLS.has(name)) return undefined;
|
|
314
|
+
const fire = state.identicalRunCount >= 3 || state.runCount >= 6;
|
|
315
|
+
if (!fire) return undefined;
|
|
316
|
+
const text =
|
|
317
|
+
`${name} has been called ${Math.max(state.runCount, state.identicalRunCount)} times in a row — repeating it returns nothing new. ` +
|
|
318
|
+
`If you intend to STORE memory, call munin_store directly (always available). Otherwise state your finding and move on.`;
|
|
319
|
+
reset();
|
|
320
|
+
return { text, runCount: state.runCount, identicalRunCount: state.identicalRunCount };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return { state, reset, dampenCheck };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function makeTools(dampenCheck: (name: string, params: Record<string, unknown>) => { text: string } | undefined): AnyTool[] {
|
|
269
327
|
return [
|
|
270
328
|
{
|
|
271
329
|
name: "munin_search",
|
|
@@ -298,6 +356,8 @@ function makeTools(): AnyTool[] {
|
|
|
298
356
|
),
|
|
299
357
|
}),
|
|
300
358
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
359
|
+
const dampened = dampenCheck("munin_search", params as Record<string, unknown>);
|
|
360
|
+
if (dampened) return { content: [{ type: "text" as const, text: dampened.text }], details: { dampened: true, ...dampened } };
|
|
301
361
|
const { query, topK = 10, tags, tag_mode, since, before, include_total } = params as Record<string, any>;
|
|
302
362
|
validateSearchQuery(query);
|
|
303
363
|
const tagMode = validateTagMode(tag_mode);
|
|
@@ -330,6 +390,8 @@ function makeTools(): AnyTool[] {
|
|
|
330
390
|
key: Type.String({ description: "Key to retrieve." }),
|
|
331
391
|
}),
|
|
332
392
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
393
|
+
const dampened = dampenCheck("munin_get", params as Record<string, unknown>);
|
|
394
|
+
if (dampened) return { content: [{ type: "text" as const, text: dampened.text }], details: { dampened: true, ...dampened } };
|
|
333
395
|
const { key: rawKey } = params as Record<string, any>;
|
|
334
396
|
const key = validateMemoryKey(rawKey);
|
|
335
397
|
const result = await withMuninClient(params as Record<string, unknown>, async (client, projectId) => {
|
|
@@ -374,6 +436,8 @@ function makeTools(): AnyTool[] {
|
|
|
374
436
|
),
|
|
375
437
|
}),
|
|
376
438
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
439
|
+
const dampened = dampenCheck("munin_store", params as Record<string, unknown>);
|
|
440
|
+
if (dampened) return { content: [{ type: "text" as const, text: dampened.text }], details: { dampened: true, ...dampened } };
|
|
377
441
|
const { key: rawKey, title, content, tags, valid_from, valid_to, pinned } = params as Record<string, any>;
|
|
378
442
|
const key = validateMemoryKey(rawKey);
|
|
379
443
|
const tagValidation = validateMemoryTags(tags);
|
|
@@ -415,6 +479,8 @@ function makeTools(): AnyTool[] {
|
|
|
415
479
|
),
|
|
416
480
|
}),
|
|
417
481
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
482
|
+
const dampened = dampenCheck("munin_list", params as Record<string, unknown>);
|
|
483
|
+
if (dampened) return { content: [{ type: "text" as const, text: dampened.text }], details: { dampened: true, ...dampened } };
|
|
418
484
|
const { limit = 20, offset = 0 } = params as Record<string, any>;
|
|
419
485
|
const result = await withMuninClient(params as Record<string, unknown>, async (client, projectId) => {
|
|
420
486
|
return callMunin(client, projectId, "list", { limit, offset });
|
|
@@ -440,6 +506,8 @@ function makeTools(): AnyTool[] {
|
|
|
440
506
|
),
|
|
441
507
|
}),
|
|
442
508
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
509
|
+
const dampened = dampenCheck("munin_recent", params as Record<string, unknown>);
|
|
510
|
+
if (dampened) return { content: [{ type: "text" as const, text: dampened.text }], details: { dampened: true, ...dampened } };
|
|
443
511
|
const { limit = 10 } = params as Record<string, any>;
|
|
444
512
|
const result = await withMuninClient(params as Record<string, unknown>, async (client, projectId) => {
|
|
445
513
|
return callMunin(client, projectId, "recent", { limit });
|
|
@@ -464,6 +532,8 @@ function makeTools(): AnyTool[] {
|
|
|
464
532
|
key: Type.String({ description: "Key to delete." }),
|
|
465
533
|
}),
|
|
466
534
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
535
|
+
const dampened = dampenCheck("munin_delete", params as Record<string, unknown>);
|
|
536
|
+
if (dampened) return { content: [{ type: "text" as const, text: dampened.text }], details: { dampened: true, ...dampened } };
|
|
467
537
|
const { key: rawKey } = params as Record<string, any>;
|
|
468
538
|
const key = validateMemoryKey(rawKey);
|
|
469
539
|
const confirmed = await ctx.ui.confirm(
|
|
@@ -499,6 +569,8 @@ function makeTools(): AnyTool[] {
|
|
|
499
569
|
...controlSchema,
|
|
500
570
|
}),
|
|
501
571
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
572
|
+
const dampened = dampenCheck("munin_capabilities", params as Record<string, unknown>);
|
|
573
|
+
if (dampened) return { content: [{ type: "text" as const, text: dampened.text }], details: { dampened: true, ...dampened } };
|
|
502
574
|
const result = await withMuninClient(params as Record<string, unknown>, async (client, projectId) => {
|
|
503
575
|
return callMunin(client, projectId, "capabilities", {});
|
|
504
576
|
}, ctx);
|
|
@@ -523,6 +595,8 @@ function makeTools(): AnyTool[] {
|
|
|
523
595
|
target_project_ids: Type.Array(Type.String(), { description: "Target project IDs." }),
|
|
524
596
|
}),
|
|
525
597
|
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
598
|
+
const dampened = dampenCheck("munin_share", params as Record<string, unknown>);
|
|
599
|
+
if (dampened) return { content: [{ type: "text" as const, text: dampened.text }], details: { dampened: true, ...dampened } };
|
|
526
600
|
const { memory_ids, target_project_ids } = params as Record<string, any>;
|
|
527
601
|
const confirmed = await ctx.ui.confirm(
|
|
528
602
|
"Share Munin memories?",
|
|
@@ -577,7 +651,20 @@ export default function muninExtension(pi: ExtensionAPI) {
|
|
|
577
651
|
skillPaths: [path.join(skillsRoot(), "munin")],
|
|
578
652
|
}));
|
|
579
653
|
|
|
580
|
-
|
|
654
|
+
const dampener = createDampener();
|
|
655
|
+
|
|
656
|
+
// Any NON-munin tool call breaks the consecutive munin run: a
|
|
657
|
+
// protocol-compliant session interleaves non-munin work between searches and
|
|
658
|
+
// must never accumulate toward the dampener (both 2026-10-12 incidents were
|
|
659
|
+
// munin-only back-to-back sequences — true loops stay caught).
|
|
660
|
+
pi.on("tool_call", async (event) => {
|
|
661
|
+
if (!String(event.toolName || "").startsWith("munin_")) dampener.reset();
|
|
662
|
+
return undefined;
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
pi.on("session_start", () => dampener.reset());
|
|
666
|
+
|
|
667
|
+
for (const tool of makeTools(dampener.dampenCheck)) {
|
|
581
668
|
pi.registerTool(tool as AnyTool);
|
|
582
669
|
}
|
|
583
670
|
|
|
@@ -222,3 +222,127 @@ describe("munin extension", () => {
|
|
|
222
222
|
assert.equal(await hook({ toolName: "munin_search", isError: false, content: [{ type: "text", text: "ok" }] }), undefined);
|
|
223
223
|
});
|
|
224
224
|
});
|
|
225
|
+
|
|
226
|
+
describe("loop dampener", () => {
|
|
227
|
+
beforeEach(() => {
|
|
228
|
+
process.env.MUNIN_API_KEY = "key";
|
|
229
|
+
process.env.MUNIN_PROJECT = "project";
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
afterEach(() => {
|
|
233
|
+
delete process.env.MUNIN_API_KEY;
|
|
234
|
+
delete process.env.MUNIN_PROJECT;
|
|
235
|
+
delete (MuninClient.prototype as { invoke?: unknown }).invoke;
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
function stubInvoke(calls: string[]): void {
|
|
239
|
+
MuninClient.prototype.invoke = async function (this: unknown, _projectId: string, action: string) {
|
|
240
|
+
calls.push(action);
|
|
241
|
+
return { ok: true } as any;
|
|
242
|
+
} as typeof MuninClient.prototype.invoke;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
it("3rd identical munin_get returns guidance without executing", async () => {
|
|
246
|
+
const { tools, ctx } = harness();
|
|
247
|
+
const calls: string[] = [];
|
|
248
|
+
stubInvoke(calls);
|
|
249
|
+
for (let i = 0; i < 2; i++) {
|
|
250
|
+
const r = await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
251
|
+
assert.equal((r.details as { dampened?: boolean }).dampened ?? false, false);
|
|
252
|
+
}
|
|
253
|
+
assert.equal(calls.length, 2);
|
|
254
|
+
const third = await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
255
|
+
assert.equal(calls.length, 2, "3rd identical call must not reach the SDK");
|
|
256
|
+
assert.match((third.content[0] as { text: string }).text, /call munin_store directly/);
|
|
257
|
+
assert.equal((third.details as { dampened: boolean }).dampened, true);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("6th consecutive munin_search with varying queries returns guidance", async () => {
|
|
261
|
+
const { tools, ctx } = harness();
|
|
262
|
+
const calls: string[] = [];
|
|
263
|
+
stubInvoke(calls);
|
|
264
|
+
for (let i = 0; i < 5; i++) {
|
|
265
|
+
const r = await tools.munin_search.execute("id", { query: `query-${i}` }, undefined, undefined, ctx);
|
|
266
|
+
assert.equal((r.details as { dampened?: boolean }).dampened ?? false, false);
|
|
267
|
+
}
|
|
268
|
+
assert.equal(calls.length, 5);
|
|
269
|
+
const sixth = await tools.munin_search.execute("id", { query: "query-5" }, undefined, undefined, ctx);
|
|
270
|
+
assert.equal(calls.length, 5, "6th consecutive same-tool call must not reach the SDK");
|
|
271
|
+
assert.equal((sixth.details as { dampened: boolean }).dampened, true);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("any non-munin tool call resets the run counter (protocol-compliant sessions never dampen)", async () => {
|
|
275
|
+
const { tools, ctx, handlers } = harness();
|
|
276
|
+
const calls: string[] = [];
|
|
277
|
+
stubInvoke(calls);
|
|
278
|
+
const nonMunin = handlers.tool_call[0];
|
|
279
|
+
for (let i = 0; i < 5; i++) {
|
|
280
|
+
await tools.munin_search.execute("id", { query: `q-${i}` }, undefined, undefined, ctx);
|
|
281
|
+
await nonMunin({ toolName: "read", input: {} });
|
|
282
|
+
}
|
|
283
|
+
assert.equal(calls.length, 5);
|
|
284
|
+
// All 10 searches executed — the interleaved non-munin work resets the run.
|
|
285
|
+
for (let i = 0; i < 5; i++) {
|
|
286
|
+
const r = await tools.munin_search.execute("id", { query: `p-${i}` }, undefined, undefined, ctx);
|
|
287
|
+
assert.equal((r.details as { dampened?: boolean }).dampened ?? false, false, `search ${i + 6} must execute`);
|
|
288
|
+
await nonMunin({ toolName: "read", input: {} });
|
|
289
|
+
}
|
|
290
|
+
assert.equal(calls.length, 10);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("a different munin tool resets the run counter", async () => {
|
|
294
|
+
const { tools, ctx } = harness();
|
|
295
|
+
const calls: string[] = [];
|
|
296
|
+
stubInvoke(calls);
|
|
297
|
+
for (let i = 0; i < 5; i++) {
|
|
298
|
+
await tools.munin_search.execute("id", { query: `q-${i}` }, undefined, undefined, ctx);
|
|
299
|
+
}
|
|
300
|
+
await tools.munin_list.execute("id", {}, undefined, undefined, ctx);
|
|
301
|
+
assert.equal(calls.length, 6);
|
|
302
|
+
const r = await tools.munin_search.execute("id", { query: "fresh" }, undefined, undefined, ctx);
|
|
303
|
+
assert.equal((r.details as { dampened?: boolean }).dampened ?? false, false);
|
|
304
|
+
assert.equal(calls.length, 7);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("guidance resets state — the next identical call executes again", async () => {
|
|
308
|
+
const { tools, ctx } = harness();
|
|
309
|
+
const calls: string[] = [];
|
|
310
|
+
stubInvoke(calls);
|
|
311
|
+
await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
312
|
+
await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
313
|
+
const third = await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
314
|
+
assert.equal((third.details as { dampened: boolean }).dampened, true);
|
|
315
|
+
assert.equal(calls.length, 2);
|
|
316
|
+
const fourth = await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
317
|
+
assert.equal((fourth.details as { dampened?: boolean }).dampened ?? false, false);
|
|
318
|
+
assert.equal(calls.length, 3);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("munin_store never returns dampener guidance", async () => {
|
|
322
|
+
const { tools, ctx } = harness();
|
|
323
|
+
const calls: string[] = [];
|
|
324
|
+
stubInvoke(calls);
|
|
325
|
+
for (let i = 0; i < 3; i++) {
|
|
326
|
+
const r = await tools.munin_store.execute("id", {
|
|
327
|
+
key: "fact/repeat-key",
|
|
328
|
+
title: "Title",
|
|
329
|
+
content: "Content",
|
|
330
|
+
tags: "type:fact,domain:memory",
|
|
331
|
+
}, undefined, undefined, ctx);
|
|
332
|
+
assert.equal((r.details as { dampened?: boolean }).dampened ?? false, false);
|
|
333
|
+
}
|
|
334
|
+
assert.equal(calls.length, 3);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("session_start resets the dampener", async () => {
|
|
338
|
+
const { tools, ctx, handlers } = harness();
|
|
339
|
+
const calls: string[] = [];
|
|
340
|
+
stubInvoke(calls);
|
|
341
|
+
await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
342
|
+
await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
343
|
+
await handlers.session_start[0]({ reason: "startup" }, ctx);
|
|
344
|
+
const r = await tools.munin_get.execute("id", { key: "bug-fix/some-key" }, undefined, undefined, ctx);
|
|
345
|
+
assert.equal((r.details as { dampened?: boolean }).dampened ?? false, false);
|
|
346
|
+
assert.equal(calls.length, 3);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
@@ -519,10 +519,64 @@ export default function planModule(pi: ExtensionAPI): void {
|
|
|
519
519
|
// ponytail: ctx.ui.select is not reentrant — serialize concurrent dialogs.
|
|
520
520
|
let askQuestionQueue: Promise<unknown> = Promise.resolve();
|
|
521
521
|
|
|
522
|
+
// Ask-loop dampener (2026-10-14 incident, session 01a12a6c): a glm-5.3-flash
|
|
523
|
+
// run asked permission 6 times in a row — each answered "Send it" — without
|
|
524
|
+
// ever emitting the a2a_call it was asking about. The wording drifted each
|
|
525
|
+
// time ("Ready to execute…dispatch now?" → "Execute: dispatch to peer now?" →
|
|
526
|
+
// "Dispatch now?" → "Dispatch?"), so an identical-args guard catches nothing.
|
|
527
|
+
// TWO independent arms, because either alone leaves a hole:
|
|
528
|
+
// A. near-duplicate — catches the incident's reworded repeats immediately.
|
|
529
|
+
// B. consecutive count — wording-independent backstop for a loop that drifts
|
|
530
|
+
// past the similarity cut (a 4th ask with NO tool call in between is a
|
|
531
|
+
// loop whatever it says; three distinct questions is a legitimate flow).
|
|
532
|
+
// ANY other tool call (see the tool_call hook) or a new session clears both.
|
|
533
|
+
let asksSinceToolCall = 0;
|
|
534
|
+
const ASK_RUN_LIMIT = 4;
|
|
535
|
+
let answeredAsks: { question: string; tokens: Set<string>; answer: string }[] = [];
|
|
536
|
+
// Filler words carry no intent and are removed first: without this "Should I
|
|
537
|
+
// dispatch the diagnosis to the peer now?" and "Should I revert the config
|
|
538
|
+
// now?" overlap on should/i/the/now and read as the same question.
|
|
539
|
+
const ASK_STOPWORDS = new Set([
|
|
540
|
+
"a", "an", "and", "are", "be", "before", "can", "do", "does", "for", "from", "go", "i", "if",
|
|
541
|
+
"in", "is", "it", "its", "me", "my", "now", "of", "on", "or", "please", "ready", "should",
|
|
542
|
+
"so", "that", "the", "then", "this", "to", "up", "use", "we", "what", "when", "which", "with",
|
|
543
|
+
"you", "your",
|
|
544
|
+
]);
|
|
545
|
+
const askTokens = (q: string): Set<string> =>
|
|
546
|
+
new Set((q.toLowerCase().match(/[a-z0-9]+/g) ?? []).filter((t) => !ASK_STOPWORDS.has(t) && t.length > 1));
|
|
547
|
+
// 0.8 keeps the recall we need without tripping on same-verb/different-object
|
|
548
|
+
// questions. Measured on the incident's real wording drift (identical intent):
|
|
549
|
+
// "Ready to execute…dispatch…peer now?" vs "Execute: dispatch to peer now?" /
|
|
550
|
+
// "Dispatch now?" / "Dispatch?" all score 1.00, while the closest DISTINCT pair
|
|
551
|
+
// ("Should I restart the radius unit?" vs "…nginx unit?") scores 0.67.
|
|
552
|
+
/** Content words the shorter question shares with the longer, ≥0.8 → "same intent". */
|
|
553
|
+
const isNearDuplicate = (a: Set<string>, b: Set<string>): boolean => {
|
|
554
|
+
if (a.size === 0 || b.size === 0) return false;
|
|
555
|
+
const [small, big] = a.size <= b.size ? [a, b] : [b, a];
|
|
556
|
+
let shared = 0;
|
|
557
|
+
for (const token of small) if (big.has(token)) shared += 1;
|
|
558
|
+
return shared / small.size >= 0.8;
|
|
559
|
+
};
|
|
560
|
+
|
|
522
561
|
async function executeAskQuestion(_toolCallId: string, params: unknown, _signal: unknown, _onUpdate: unknown, ctx: ExtensionToolContext) {
|
|
523
562
|
const typedParams = params as PlanQuestionParams;
|
|
524
563
|
const { options, recommendedIndex } = validateQuestionParams(typedParams);
|
|
525
564
|
const textBlock = (text: string) => ({ type: "text" as const, text });
|
|
565
|
+
const tokens = askTokens(typedParams.question);
|
|
566
|
+
const repeat = answeredAsks.find((entry) => isNearDuplicate(tokens, entry.tokens));
|
|
567
|
+
asksSinceToolCall += 1;
|
|
568
|
+
const prior = repeat ?? answeredAsks[answeredAsks.length - 1];
|
|
569
|
+
if (repeat || (asksSinceToolCall >= ASK_RUN_LIMIT && prior)) {
|
|
570
|
+
return {
|
|
571
|
+
content: [textBlock(
|
|
572
|
+
`Loop guard: ${repeat
|
|
573
|
+
? `you already asked this and the user answered — "${repeat.question}" → "${repeat.answer}".`
|
|
574
|
+
: `this is ask_user_question call #${asksSinceToolCall} in a row with no other tool call in between; the last answer was "${prior.question}" → "${prior.answer}".`} ` +
|
|
575
|
+
`Act on that answer now instead of asking again. If something genuinely blocks you, do the work that resolves it or say what the blocker is in plain text (a further question is allowed after any other tool call).`,
|
|
576
|
+
)],
|
|
577
|
+
details: { question: typedParams.question, options, answer: prior.answer, cancelled: false, loopGuard: true },
|
|
578
|
+
};
|
|
579
|
+
}
|
|
526
580
|
const cancelled = {
|
|
527
581
|
content: [textBlock("User cancelled the question.")],
|
|
528
582
|
details: { question: typedParams.question, options, answer: null, cancelled: true, wasCustom: false },
|
|
@@ -546,6 +600,8 @@ export default function planModule(pi: ExtensionAPI): void {
|
|
|
546
600
|
if (choice === otherLabel) {
|
|
547
601
|
const answer = (await ctx.ui.editor("Your answer", ""))?.trim();
|
|
548
602
|
if (!answer) return cancelled;
|
|
603
|
+
answeredAsks.push({ question: typedParams.question, tokens, answer });
|
|
604
|
+
if (answeredAsks.length > 8) answeredAsks.shift();
|
|
549
605
|
return {
|
|
550
606
|
content: [textBlock(`User wrote: ${answer}`)],
|
|
551
607
|
details: { question: typedParams.question, options, answer, wasCustom: true, cancelled: false },
|
|
@@ -553,6 +609,8 @@ export default function planModule(pi: ExtensionAPI): void {
|
|
|
553
609
|
}
|
|
554
610
|
const selectedIndex = displayLabels.indexOf(choice);
|
|
555
611
|
const answer = options[selectedIndex]?.label ?? choice;
|
|
612
|
+
answeredAsks.push({ question: typedParams.question, tokens, answer });
|
|
613
|
+
if (answeredAsks.length > 8) answeredAsks.shift();
|
|
556
614
|
return {
|
|
557
615
|
content: [textBlock(`User selected: ${answer}`)],
|
|
558
616
|
details: { question: typedParams.question, options, answer, selectedIndex, wasCustom: false, cancelled: false },
|
|
@@ -871,6 +929,8 @@ export default function planModule(pi: ExtensionAPI): void {
|
|
|
871
929
|
|
|
872
930
|
pi.on("session_start", async (event, ctx) => {
|
|
873
931
|
sessionAllows.clear();
|
|
932
|
+
answeredAsks = [];
|
|
933
|
+
asksSinceToolCall = 0;
|
|
874
934
|
refreshSettings(ctx);
|
|
875
935
|
setPlanRegistry(ctx.modelRegistry);
|
|
876
936
|
void probeDiffDrivers(ctx.cwd); // best-effort: textconv-aware bash gating
|
|
@@ -923,6 +983,10 @@ export default function planModule(pi: ExtensionAPI): void {
|
|
|
923
983
|
* blocked mutators → hard error; bash writers → hard-block; bash reads →
|
|
924
984
|
* auto-allow; unknown executables + non-read tools → confirm tier. */
|
|
925
985
|
pi.on("tool_call", async (event, ctx) => {
|
|
986
|
+
// Ask-loop dampener: any tool call other than the question itself breaks the
|
|
987
|
+
// run (munin dampener contract). Deliberately above the
|
|
988
|
+
// plan-mode early return — the loop it guards is not plan-specific.
|
|
989
|
+
if (event.toolName !== ASK_USER_QUESTION_TOOL) { answeredAsks = []; asksSinceToolCall = 0; }
|
|
926
990
|
if (!planModeEnabled) return;
|
|
927
991
|
if (BLOCKED_TOOLS.has(event.toolName)) {
|
|
928
992
|
return { block: true, reason: `plan mode: ${event.toolName} is not available while planning. Use ${PLAN_TOOL} to write the plan file.` };
|