ceulen 0.28.2 → 0.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/extensions/lib/registry.ts +2 -2
- package/extensions/modules/a2a/index.ts +1 -1
- package/extensions/modules/repair/configPanel.ts +8 -1
- package/extensions/modules/repair/index.ts +29 -6
- package/extensions/modules/repair/lib/persistent-bash.ts +440 -0
- package/extensions/modules/repair/lib/settings.ts +5 -1
- package/extensions/modules/repair/test/persistent-bash.test.ts +402 -0
- package/extensions/modules/repair/test/settings.test.ts +6 -3
- package/extensions/modules/steering/configPanel.ts +0 -15
- package/extensions/modules/steering/index.ts +26 -201
- package/extensions/modules/steering/lib/settings.ts +6 -7
- package/extensions/modules/steering/test/harness.ts +3 -3
- package/extensions/modules/steering/test/settings.test.ts +14 -19
- package/extensions/modules/steering/test/status.test.ts +6 -9
- package/package.json +1 -1
- package/extensions/modules/steering/lib/anchor.ts +0 -189
- package/extensions/modules/steering/test/anchor-plan.test.ts +0 -74
- package/extensions/modules/steering/test/anchor-regressions.test.ts +0 -123
- package/extensions/modules/steering/test/anchor-wiring.test.ts +0 -82
- package/extensions/modules/steering/test/anchor.test.ts +0 -162
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* fast-mode body) — the "zai" module.
|
|
11
11
|
*
|
|
12
12
|
* What stays here is everything that depends on knowing WHICH model family is
|
|
13
|
-
* serving the request
|
|
13
|
+
* serving the request:
|
|
14
14
|
*
|
|
15
15
|
* 1. family detection (deepseek-v4 | glm), latched from the requested model
|
|
16
16
|
* and the session-captured one (proxies rewrite ctx.model between hooks).
|
|
@@ -23,14 +23,20 @@
|
|
|
23
23
|
* 4. tool-error categorization → the next turn's recovery hint, plus the
|
|
24
24
|
* reasoning-accumulation 400 detector.
|
|
25
25
|
* 5. DeepSeek-only semantic-miss / dedicated-tool steering on tool_call.
|
|
26
|
-
*
|
|
26
|
+
*
|
|
27
|
+
* The ds-anchor (DSH minimal-mode bootstrap) was DELETED 2026-11: the A/B
|
|
28
|
+
* evidence showed it HURT DeepSeek Flash cold tool use (3/5 vs 5/5 with it
|
|
29
|
+
* off — the pair-only request #1 hid codemode/tool_search and explicit
|
|
30
|
+
* requests for them ended without a tool call), and DeepSeek Harness itself
|
|
31
|
+
* dropped that composition (str_replace_editor removed from minimal
|
|
32
|
+
* 2026-09-03: one file-mutation interface = the shell). Do not reintroduce a
|
|
33
|
+
* first-request bootstrap here; the persistent-shell work lives in repair.
|
|
27
34
|
*
|
|
28
35
|
* ORDERING CONTRACT (why this module is its own unit): in ceulen's registry
|
|
29
36
|
* `steering` loads AFTER ponytail and subagent, so this `before_agent_start`
|
|
30
37
|
* handler runs LAST in the chain (each handler's returned systemPrompt becomes
|
|
31
|
-
* the next handler's event.systemPrompt). Always compose the full prompt here
|
|
32
|
-
*
|
|
33
|
-
* so a fail-open or the next tool round gets the original composed prompt.
|
|
38
|
+
* the next handler's event.systemPrompt). Always compose the full prompt here —
|
|
39
|
+
* never replace it.
|
|
34
40
|
*
|
|
35
41
|
* Config: the `steering` section of the agent-dir settings.json, overlaid by a
|
|
36
42
|
* trusted project `.pi/settings.json` (lib/settings.ts), read per turn — so
|
|
@@ -43,8 +49,7 @@
|
|
|
43
49
|
// reminders threshold is now a fixed policy inside strictSerena, and the
|
|
44
50
|
// reasoning-truncation budget is a function argument.
|
|
45
51
|
|
|
46
|
-
import type { ExtensionAPI
|
|
47
|
-
import { isPlanActive } from "../../lib/plan-bridge.ts";
|
|
52
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
48
53
|
import { detectFamily, type ModelFamily } from "./lib/family.js";
|
|
49
54
|
import {
|
|
50
55
|
applyPatchPreferenceGuidance,
|
|
@@ -61,15 +66,6 @@ import {
|
|
|
61
66
|
stripReasoningContent,
|
|
62
67
|
tailIsPlainUserPrompt,
|
|
63
68
|
} from "./lib/history.js";
|
|
64
|
-
import {
|
|
65
|
-
BOOTSTRAP_TOOLS,
|
|
66
|
-
MINIMAL_SYSTEM_PROMPT,
|
|
67
|
-
WE_NEED_DIRECTIVE,
|
|
68
|
-
dshBootstrapTools,
|
|
69
|
-
hasPromotionSignal,
|
|
70
|
-
isAnchorTarget,
|
|
71
|
-
withMinimalPrompt,
|
|
72
|
-
} from "./lib/anchor.js";
|
|
73
69
|
import {
|
|
74
70
|
categorizeToolError,
|
|
75
71
|
detectReasoningRejection,
|
|
@@ -95,8 +91,6 @@ export { steeringConfig } from "./configPanel.js";
|
|
|
95
91
|
const BLOCK_AFTER_REMINDERS = 3;
|
|
96
92
|
/** Cap on the per-tool error-history map (upstream's default). */
|
|
97
93
|
const MAX_ERROR_HISTORY = 100;
|
|
98
|
-
/** DSH's captured minimal-mode output budget — pinned on the bootstrap request. */
|
|
99
|
-
const BOOTSTRAP_MAX_TOKENS = 256000;
|
|
100
94
|
/** customType for steering notes. LLM-visible (unlike …status output). */
|
|
101
95
|
const STEERING_MESSAGE_TYPE = "ceulen-steering";
|
|
102
96
|
|
|
@@ -128,28 +122,12 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
128
122
|
// reinforcement) stashed here and appended to the CURRENT user message by
|
|
129
123
|
// before_provider_request — never the system prompt (the cache head).
|
|
130
124
|
let pendingGuidance: string | undefined;
|
|
131
|
-
let bootstrapGuidance: string | undefined;
|
|
132
125
|
// Effective settings — refreshed per turn (before_agent_start) and at
|
|
133
|
-
// session_start
|
|
126
|
+
// session_start.
|
|
134
127
|
let settings: SteeringSettings = readSteeringSettings();
|
|
135
128
|
|
|
136
|
-
//
|
|
137
|
-
// Invariant: anchorBootstrapping = dsAnchor && target && !anchorPromoted.
|
|
138
|
-
let anchorReady = false;
|
|
139
|
-
let anchorPromoted = false;
|
|
140
|
-
let anchorRunActive = false;
|
|
141
|
-
let anchorInspectedCount = 0;
|
|
142
|
-
let anchorWarned = false;
|
|
143
|
-
// Last-known thinking level (thinking_level_select) — surfaced in status
|
|
144
|
-
// because the DSH minimal-mode recipe requires max thinking.
|
|
129
|
+
// Last-known thinking level (thinking_level_select) — surfaced in status.
|
|
145
130
|
let currentThinking: string | undefined;
|
|
146
|
-
// Ring buffer of anchor decisions — surfaced by /steering so the bootstrap can
|
|
147
|
-
// be verified without any debug env.
|
|
148
|
-
const anchorTrace: string[] = [];
|
|
149
|
-
function anchorTracePush(line: string) {
|
|
150
|
-
anchorTrace.push(`${new Date().toISOString().slice(11, 19)} ${line}`);
|
|
151
|
-
if (anchorTrace.length > 8) anchorTrace.shift();
|
|
152
|
-
}
|
|
153
131
|
|
|
154
132
|
const reminderCounts = new Map<string, number>();
|
|
155
133
|
const errorHistory = new Map<string, { count: number; lastCategory: ErrorCategory }>();
|
|
@@ -164,60 +142,10 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
164
142
|
return detectFamily(model) ?? detectFamily(sessionModel);
|
|
165
143
|
}
|
|
166
144
|
|
|
167
|
-
// Anchor target: check BOTH ctx.model and session-captured model — proxies
|
|
168
|
-
// rewrite ctx.model between hooks (see family() above for the same defense).
|
|
169
|
-
function anchorTarget(model?: { id?: string }): boolean {
|
|
170
|
-
return settings.dsAnchor && (isAnchorTarget(model?.id) || isAnchorTarget(sessionModel?.id));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function warnAnchorOnce(ctx: ExtensionContext, message: string) {
|
|
174
|
-
if (anchorWarned) return;
|
|
175
|
-
anchorWarned = true;
|
|
176
|
-
try { ctx.ui?.notify?.(message, "warning"); } catch { /* no UI */ }
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Scan durable entries for a promotion signal; fail-open on error.
|
|
180
|
-
function scanAnchorEntries(ctx: ExtensionContext) {
|
|
181
|
-
if (anchorPromoted) return;
|
|
182
|
-
try {
|
|
183
|
-
const entries = ctx.sessionManager.getEntries() as unknown[];
|
|
184
|
-
const from = entries.length >= anchorInspectedCount ? anchorInspectedCount : 0;
|
|
185
|
-
if (hasPromotionSignal(entries.slice(from) as never)) anchorPromoted = true;
|
|
186
|
-
anchorInspectedCount = entries.length;
|
|
187
|
-
if (!anchorReady) anchorReady = true;
|
|
188
|
-
} catch {
|
|
189
|
-
anchorPromoted = true;
|
|
190
|
-
warnAnchorOnce(ctx, "steering: ds-anchor session inspection failed; full catalog exposed");
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function anchorBootstrapping(model?: { id?: string }): boolean {
|
|
195
|
-
// Target check per hook — proxies rewrite ctx.model between hooks WITHOUT
|
|
196
|
-
// firing model_select (e.g. a session requested as flash that is served
|
|
197
|
-
// deepseek-v4-pro). Requiring a session_start-latched ready flag silently
|
|
198
|
-
// skipped the bootstrap for such sessions — the exact failure observed in
|
|
199
|
-
// a live a2a gateway session. anchorReady is display-only here.
|
|
200
|
-
const target = anchorTarget(model);
|
|
201
|
-
if (target && !anchorReady) anchorReady = true;
|
|
202
|
-
// Plan mode hard-blocks the mutator tools (str_replace_editor is in
|
|
203
|
-
// plan's BLOCKED_TOOLS), so the DSH pair can never reach the payload.
|
|
204
|
-
// Defer — not fail-open — so the session stays anchorable and the
|
|
205
|
-
// fail-open warning never fires: plan-mode replies promote naturally via
|
|
206
|
-
// the entries scan, and with no replies the bootstrap engages on the
|
|
207
|
-
// first post-exit turn (permission-module precedent: plan-bridge).
|
|
208
|
-
if (isPlanActive()) return false;
|
|
209
|
-
return target && !anchorPromoted;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
145
|
// ── /steering ──
|
|
213
146
|
pi.registerCommand("steering", {
|
|
214
|
-
description: "Show per-model-family steering state: active family, flags,
|
|
147
|
+
description: "Show per-model-family steering state: active family, flags, prompt-cache stats.",
|
|
215
148
|
handler: async (_args, cmdCtx) => {
|
|
216
|
-
const anchorActive = anchorTarget(cmdCtx.model); // includes sessionModel fallback
|
|
217
|
-
const anchorState = !anchorActive || !anchorReady
|
|
218
|
-
? "off"
|
|
219
|
-
: isPlanActive() && !anchorPromoted ? "deferred (plan mode)"
|
|
220
|
-
: anchorPromoted ? "promoted" : "bootstrapping";
|
|
221
149
|
const totalErrors = [...errorHistory.values()].reduce((sum, e) => sum + e.count, 0);
|
|
222
150
|
const status = [
|
|
223
151
|
"## steering status",
|
|
@@ -233,9 +161,7 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
233
161
|
` Strict Serena (DeepSeek V4): ${settings.strictSerena ? `on (block after ${BLOCK_AFTER_REMINDERS} reminders)` : "off"}`,
|
|
234
162
|
` Reasoning strip: ${settings.stripReasoning ? "on" : "off"}`,
|
|
235
163
|
` Leaked content cleaning: always on for detected families`,
|
|
236
|
-
`
|
|
237
|
-
` We-need directive (bootstrap): ${settings.weNeed ? "on" : "off"}`,
|
|
238
|
-
` Thinking level: ${currentThinking ?? "unknown"}${currentThinking !== "max" && anchorActive ? " (recipe wants max)" : ""}`,
|
|
164
|
+
` Thinking level: ${currentThinking ?? "unknown"}`,
|
|
239
165
|
` Super Power turns: ${turnCounter}`,
|
|
240
166
|
"",
|
|
241
167
|
...(cacheStats.input > 0
|
|
@@ -258,7 +184,6 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
258
184
|
})()
|
|
259
185
|
: []),
|
|
260
186
|
`**Errors:** ${totalErrors} total${lastErrorInfo ? `, last: ${lastErrorInfo.category} on ${lastErrorInfo.toolName}` : ""}`,
|
|
261
|
-
...(anchorTrace.length > 0 ? ["", "**ds-anchor trace:**", ...anchorTrace.map((l) => ` ${l}`)] : []),
|
|
262
187
|
];
|
|
263
188
|
cmdCtx.ui.notify(status.join("\n"), "info");
|
|
264
189
|
},
|
|
@@ -270,18 +195,8 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
270
195
|
settings = readSteeringSettings(ctx);
|
|
271
196
|
// Capture the session's initial thinking level: thinking_level_select only
|
|
272
197
|
// fires on CHANGES, so a session born at max would otherwise show "unknown"
|
|
273
|
-
// —
|
|
198
|
+
// — the value the status line should report.
|
|
274
199
|
currentThinking = ctx.thinkingLevel;
|
|
275
|
-
// ds-anchor: reset and init from durable state (resume of a session that
|
|
276
|
-
// already has an assistant reply = instantly promoted, no bootstrap).
|
|
277
|
-
anchorReady = anchorTarget(ctx.model);
|
|
278
|
-
anchorPromoted = false;
|
|
279
|
-
anchorRunActive = false;
|
|
280
|
-
anchorInspectedCount = 0;
|
|
281
|
-
anchorWarned = false;
|
|
282
|
-
anchorTrace.length = 0; // per-session trace — never leak prior-session lines
|
|
283
|
-
anchorTracePush(`session_start: requested=${ctx.model?.id ?? "?"}${anchorTarget(ctx.model) ? " → target" : " → not target"}`);
|
|
284
|
-
scanAnchorEntries(ctx);
|
|
285
200
|
activeFamily = null;
|
|
286
201
|
hasErrorThisTurn = false;
|
|
287
202
|
lastErrorInfo = null;
|
|
@@ -296,35 +211,19 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
296
211
|
cacheStats.hitTurns = 0;
|
|
297
212
|
cacheStats.missTurns = 0;
|
|
298
213
|
pendingGuidance = undefined;
|
|
299
|
-
bootstrapGuidance = undefined;
|
|
300
214
|
});
|
|
301
215
|
|
|
302
|
-
// ── thinking_level_select: track the level
|
|
216
|
+
// ── thinking_level_select: track the level ──
|
|
303
217
|
pi.on("thinking_level_select", (event) => { currentThinking = event.level; });
|
|
304
218
|
|
|
305
|
-
// ── model_select: keep the latched model in sync
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
//
|
|
309
|
-
// target after a /model switch away (bootstrap firing on e.g. flash,
|
|
310
|
-
// pinning max_tokens and hiding tools for a non-target model).
|
|
219
|
+
// ── model_select: keep the latched model in sync ──
|
|
220
|
+
pi.on("model_select", (event) => {
|
|
221
|
+
// The stale-sessionModel fallback in family() would otherwise keep
|
|
222
|
+
// matching the OLD family after a /model switch away.
|
|
311
223
|
sessionModel = event.model ? { id: event.model.id, provider: event.model.provider } : undefined;
|
|
312
|
-
if (isAnchorTarget(event.model?.id)) {
|
|
313
|
-
if (!anchorReady) {
|
|
314
|
-
anchorReady = true;
|
|
315
|
-
anchorPromoted = false;
|
|
316
|
-
anchorInspectedCount = 0;
|
|
317
|
-
scanAnchorEntries(ctx);
|
|
318
|
-
}
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
// Switched away (or to a non-target): anchor goes inert.
|
|
322
|
-
anchorReady = false;
|
|
323
|
-
anchorPromoted = false;
|
|
324
|
-
anchorRunActive = false;
|
|
325
224
|
});
|
|
326
225
|
|
|
327
|
-
// ── before_agent_start:
|
|
226
|
+
// ── before_agent_start: static prompt blocks + dynamic guidance ──
|
|
328
227
|
//
|
|
329
228
|
// Cache-stability split: the system prompt is the byte-stable HEAD of the
|
|
330
229
|
// prefix cache — DeepSeek (exact prefix) and GLM (Z.ai automatic
|
|
@@ -354,21 +253,8 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
354
253
|
const hidden = event.systemPromptOptions?.hiddenTools;
|
|
355
254
|
const directTools = hidden?.length ? activeForHint.filter((name) => !hidden.includes(name)) : activeForHint;
|
|
356
255
|
|
|
357
|
-
// Read-only child loadouts, codemode-only, plan mode and custom runs keep
|
|
358
|
-
// their prompt and tools. Wire-level validation below is still authoritative.
|
|
359
|
-
anchorRunActive = false;
|
|
360
|
-
if (!isCustomRun && anchorBootstrapping(ctx.model)) {
|
|
361
|
-
scanAnchorEntries(ctx);
|
|
362
|
-
if (!anchorPromoted && BOOTSTRAP_TOOLS.every((name) => directTools.includes(name))) {
|
|
363
|
-
anchorRunActive = true;
|
|
364
|
-
} else if (!anchorPromoted) {
|
|
365
|
-
anchorTracePush("bootstrap skipped: bash/str_replace_editor not declared");
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
256
|
remindedThisTurn = false;
|
|
370
257
|
pendingGuidance = undefined;
|
|
371
|
-
bootstrapGuidance = undefined;
|
|
372
258
|
if (!activeFamily) return;
|
|
373
259
|
|
|
374
260
|
const dynamicParts: string[] = [];
|
|
@@ -390,9 +276,6 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
390
276
|
// Hints heuristically read the USER's task text: a custom-triggered run has
|
|
391
277
|
// no prompt, and hinting off a machine message would be noise.
|
|
392
278
|
const runPrompt = !isCustomRun && "prompt" in event ? event.prompt : "";
|
|
393
|
-
if (settings.firstToolHints && anchorRunActive && readUncertainPathHint(runPrompt)) {
|
|
394
|
-
bootstrapGuidance = "Resolve the bare filename inside the current workspace with bash (`find . -name ...`), not by searching from `/`.";
|
|
395
|
-
}
|
|
396
279
|
if (settings.firstToolHints && !isCustomRun && directTools.includes("bash")) {
|
|
397
280
|
const runHint = runTaskFirstToolHint(runPrompt);
|
|
398
281
|
if (runHint) dynamicParts.push(runHint);
|
|
@@ -447,40 +330,13 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
447
330
|
return systemPrompt === event.systemPrompt ? undefined : { systemPrompt };
|
|
448
331
|
});
|
|
449
332
|
|
|
450
|
-
// ── before_provider_request:
|
|
333
|
+
// ── before_provider_request: dynamic guidance + history cleaning ──
|
|
451
334
|
//
|
|
452
335
|
// before_provider_headers / after_provider_response are NOT registered here —
|
|
453
336
|
// the zai module owns those (fast-mode + client signing).
|
|
454
337
|
pi.on("before_provider_request", (event, ctx) => {
|
|
455
338
|
if (!family(ctx.model)) return;
|
|
456
339
|
let payload: unknown = event.payload;
|
|
457
|
-
// ds-anchor bootstrap: replace the provider payload's tools with the
|
|
458
|
-
// byte-exact DSH Minimal pair. Request-level only — Pi's global active-tool
|
|
459
|
-
// state is untouched; execution routes to the registered tools by name.
|
|
460
|
-
if (anchorBootstrapping(ctx.model) && anchorRunActive) {
|
|
461
|
-
const p = payload as Record<string, unknown> | undefined;
|
|
462
|
-
const filtered = dshBootstrapTools(p?.tools);
|
|
463
|
-
const minimal = filtered.ok && withMinimalPrompt(p, settings.weNeed ? WE_NEED_DIRECTIVE + MINIMAL_SYSTEM_PROMPT : MINIMAL_SYSTEM_PROMPT);
|
|
464
|
-
if (!minimal) {
|
|
465
|
-
const reason = filtered.reason ?? "system prompt unavailable in payload";
|
|
466
|
-
anchorPromoted = true; // fail-open
|
|
467
|
-
anchorRunActive = false;
|
|
468
|
-
anchorTracePush(`FAIL-OPEN: ${reason}`);
|
|
469
|
-
warnAnchorOnce(ctx, `steering: ds-anchor ${reason}; bootstrap disabled, full prompt and catalog preserved`);
|
|
470
|
-
} else {
|
|
471
|
-
// max_tokens: the DSH captured minimal-mode payload sent 256000, and
|
|
472
|
-
// dsh-anchored-standard issue #11 isolated the output budget as a
|
|
473
|
-
// trajectory lever. Match it on the bootstrap request only. Exactly one
|
|
474
|
-
// budget field is emitted — the other is dropped from the spread so a
|
|
475
|
-
// payload carrying both can't send conflicting fields.
|
|
476
|
-
const other = minimal.max_completion_tokens !== undefined ? "max_completion_tokens" : "max_tokens";
|
|
477
|
-
const dropped = other === "max_tokens" ? "max_completion_tokens" : "max_tokens";
|
|
478
|
-
const { [dropped]: _omit, ...rest } = minimal;
|
|
479
|
-
const maxTokens = Math.min(BOOTSTRAP_MAX_TOKENS, ctx.model?.maxTokens ?? BOOTSTRAP_MAX_TOKENS);
|
|
480
|
-
payload = { ...rest, tools: filtered.tools, [other]: maxTokens };
|
|
481
|
-
anchorTracePush(`bootstrap: minimal prompt engaged; tools=[bash,str_replace_editor] + ${other}=${maxTokens} sent to ${ctx.model?.id ?? "?"}`);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
340
|
// Append per-turn dynamic guidance to the current user message (request
|
|
485
341
|
// tail) so the system-prompt cache head stays byte-identical across turns
|
|
486
342
|
// (both DeepSeek exact-prefix and GLM Z.ai content-similarity caches).
|
|
@@ -488,7 +344,7 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
488
344
|
// prompt): mid-turn rounds end with tool results, where re-appending the
|
|
489
345
|
// hint reads as a fresh repeated demand and loops strict models into
|
|
490
346
|
// re-running bash ("I've been complying") instead of settling.
|
|
491
|
-
const guidance =
|
|
347
|
+
const guidance = pendingGuidance;
|
|
492
348
|
if (guidance && tailIsPlainUserPrompt(payload)) {
|
|
493
349
|
const withGuidance = appendGuidanceToLastUserMessage(payload, guidance);
|
|
494
350
|
if (withGuidance !== payload) payload = withGuidance;
|
|
@@ -533,30 +389,9 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
533
389
|
// ── agent_end: the per-turn steering latch closes with the run ──
|
|
534
390
|
pi.on("agent_end", () => { remindedThisTurn = false; });
|
|
535
391
|
|
|
536
|
-
// ──
|
|
537
|
-
pi.on("agent_settled", () => { anchorRunActive = false; });
|
|
538
|
-
|
|
539
|
-
// ── turn_end: anchor promotion + prompt-cache usage bookkeeping ──
|
|
392
|
+
// ── turn_end: prompt-cache usage bookkeeping ──
|
|
540
393
|
pi.on("turn_end", (event) => {
|
|
541
|
-
// ds-anchor: promote only on a DURABLE assistant reply — an error/aborted
|
|
542
|
-
// bootstrap request (429, network blip, 400 from the injected payload) must
|
|
543
|
-
// NOT silently promote the session (matches hasPromotionSignal's
|
|
544
|
-
// non-empty-content semantics; keeps the retry anchored).
|
|
545
394
|
const msg = event.message as unknown as AssistantLike;
|
|
546
|
-
if (anchorRunActive && msg.role === "assistant") {
|
|
547
|
-
const durable =
|
|
548
|
-
msg.stopReason !== "error" &&
|
|
549
|
-
msg.stopReason !== "aborted" &&
|
|
550
|
-
Array.isArray(msg.content) &&
|
|
551
|
-
msg.content.length > 0;
|
|
552
|
-
if (durable) {
|
|
553
|
-
anchorPromoted = true;
|
|
554
|
-
anchorRunActive = false;
|
|
555
|
-
anchorTracePush("promoted: first durable assistant reply received");
|
|
556
|
-
} else {
|
|
557
|
-
anchorTracePush(`bootstrap: reply not durable (stopReason=${msg.stopReason ?? "?"}) — retry stays anchored`);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
395
|
// turn_end fires once per assistant LLM call (agent-loop emits per round),
|
|
561
396
|
// so each message.usage is a single API call — no double-counting.
|
|
562
397
|
if (msg.role !== "assistant") return;
|
|
@@ -585,16 +420,6 @@ export default function steeringModule(pi: ExtensionAPI): void {
|
|
|
585
420
|
const f = family(ctx.model);
|
|
586
421
|
if (!f) return;
|
|
587
422
|
|
|
588
|
-
// ds-anchor bootstrap: the payload declared only bash + str_replace_editor
|
|
589
|
-
// (before_provider_request), so block a hallucinated name instead of
|
|
590
|
-
// burning a turn — the model must use the declared pair.
|
|
591
|
-
if (anchorBootstrapping(ctx.model) && anchorRunActive) {
|
|
592
|
-
if (!BOOTSTRAP_TOOLS.includes(event.toolName)) {
|
|
593
|
-
return { block: true, reason: `steering: ${event.toolName} is unavailable during the bootstrap request; use bash or str_replace_editor (command: "view" to read files).` };
|
|
594
|
-
}
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
423
|
// A Serena call is the behavior we steer TOWARD — re-arm the per-turn latch.
|
|
599
424
|
if (event.toolName.startsWith("serena_")) { remindedThisTurn = false; return; }
|
|
600
425
|
|
|
@@ -13,10 +13,13 @@
|
|
|
13
13
|
// "superpowerPrompt": "", // custom text; empty = built-in
|
|
14
14
|
// "strictSerena": false, // escalate dedicated-tool misses to a block
|
|
15
15
|
// "stripReasoning": true, // drop accumulated reasoning_content
|
|
16
|
-
// "dsAnchor": true, // V4 Pro / V4.1 Flash minimal-mode bootstrap
|
|
17
|
-
// "weNeed": false, // A/B: "We need…" bootstrap directive
|
|
18
16
|
// "thinkTool": false // register the OMP-parity think scratchpad
|
|
19
17
|
// }
|
|
18
|
+
//
|
|
19
|
+
// The `dsAnchor` / `weNeed` keys (DSH minimal-mode bootstrap) were DELETED
|
|
20
|
+
// 2026-11 with the anchor itself — the A/B evidence showed it hurt DeepSeek
|
|
21
|
+
// Flash cold tool use and DSH dropped that composition. Unknown keys are
|
|
22
|
+
// ignored by the reader, so existing settings files need no migration.
|
|
20
23
|
|
|
21
24
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
22
25
|
import os from "node:os";
|
|
@@ -31,8 +34,6 @@ export interface SteeringSettings {
|
|
|
31
34
|
superpowerPrompt: string;
|
|
32
35
|
strictSerena: boolean;
|
|
33
36
|
stripReasoning: boolean;
|
|
34
|
-
dsAnchor: boolean;
|
|
35
|
-
weNeed: boolean;
|
|
36
37
|
/** Register the OMP-parity `think` scratchpad tool. Presence binds at load. */
|
|
37
38
|
thinkTool: boolean;
|
|
38
39
|
}
|
|
@@ -44,8 +45,6 @@ export const DEFAULT_STEERING_SETTINGS: SteeringSettings = {
|
|
|
44
45
|
superpowerPrompt: "",
|
|
45
46
|
strictSerena: false,
|
|
46
47
|
stripReasoning: true,
|
|
47
|
-
dsAnchor: true,
|
|
48
|
-
weNeed: false,
|
|
49
48
|
thinkTool: false,
|
|
50
49
|
};
|
|
51
50
|
|
|
@@ -79,7 +78,7 @@ function section(json: Record<string, unknown> | null): Record<string, unknown>
|
|
|
79
78
|
/** Merge one settings layer's `steering` keys into out. */
|
|
80
79
|
function mergeLayer(out: SteeringSettings, json: Record<string, unknown> | null): void {
|
|
81
80
|
const s = section(json);
|
|
82
|
-
for (const key of ["firstToolHints", "selectionGuidance", "superpower", "strictSerena", "stripReasoning", "
|
|
81
|
+
for (const key of ["firstToolHints", "selectionGuidance", "superpower", "strictSerena", "stripReasoning", "thinkTool"] as const) {
|
|
83
82
|
if (typeof s[key] === "boolean") out[key] = s[key] as boolean;
|
|
84
83
|
}
|
|
85
84
|
if (typeof s.superpowerPrompt === "string") out.superpowerPrompt = s.superpowerPrompt.trim();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Fake-pi harness for the steering lifecycle tests (adapted from
|
|
2
|
-
// pi-model-tools'
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// pi-model-tools' cache-stats / guidance harnesses): the module's handlers are
|
|
3
|
+
// collected off a stub ExtensionAPI and fired directly with synthetic events,
|
|
4
|
+
// so the returned results can be asserted on.
|
|
5
5
|
|
|
6
6
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { tmpdir } from "node:os";
|
|
@@ -52,33 +52,31 @@ describe("readSteeringSettings layering", () => {
|
|
|
52
52
|
superpowerPrompt: "",
|
|
53
53
|
strictSerena: false,
|
|
54
54
|
stripReasoning: true,
|
|
55
|
-
dsAnchor: true,
|
|
56
|
-
weNeed: false,
|
|
57
55
|
thinkTool: false,
|
|
58
56
|
});
|
|
59
57
|
});
|
|
60
58
|
|
|
61
59
|
it("reads the global section, ignoring unknown keys and bad types", () => {
|
|
62
|
-
writeGlobal({ steering: { superpower: true, superpowerPrompt: " custom ",
|
|
60
|
+
writeGlobal({ steering: { superpower: true, superpowerPrompt: " custom ", stripReasoning: "yes", strictSerena: 1, firstToolHints: false } });
|
|
63
61
|
const s = readSteeringSettings();
|
|
64
62
|
assert.equal(s.superpower, true);
|
|
65
63
|
assert.equal(s.superpowerPrompt, "custom", "trimmed");
|
|
66
|
-
assert.equal(s.
|
|
64
|
+
assert.equal(s.stripReasoning, true, "non-boolean ignored → default");
|
|
67
65
|
assert.equal(s.strictSerena, false, "non-boolean ignored → default");
|
|
68
66
|
assert.equal(s.firstToolHints, false);
|
|
69
67
|
});
|
|
70
68
|
|
|
71
69
|
it("a TRUSTED project file overrides the global section per field", () => {
|
|
72
|
-
writeGlobal({ steering: { superpower: true,
|
|
70
|
+
writeGlobal({ steering: { superpower: true, strictSerena: true, stripReasoning: false } });
|
|
73
71
|
writeProject({ steering: { superpower: false, stripReasoning: true } });
|
|
74
72
|
const s = readSteeringSettings({ cwd: REPO, isProjectTrusted: () => true });
|
|
75
73
|
assert.equal(s.superpower, false, "project wins");
|
|
76
74
|
assert.equal(s.stripReasoning, true, "project wins");
|
|
77
|
-
assert.equal(s.
|
|
75
|
+
assert.equal(s.strictSerena, true, "untouched field falls through to global");
|
|
78
76
|
});
|
|
79
77
|
|
|
80
78
|
it("an UNTRUSTED project file is ignored entirely", () => {
|
|
81
|
-
writeProject({ steering: {
|
|
79
|
+
writeProject({ steering: { superpower: true, firstToolHints: false } });
|
|
82
80
|
const s = readSteeringSettings({ cwd: REPO, isProjectTrusted: () => false });
|
|
83
81
|
assert.deepEqual(s, DEFAULT_STEERING_SETTINGS);
|
|
84
82
|
assert.equal(projectOverridesSteering(REPO, false), false, "untrusted project never disclosed as shadowing");
|
|
@@ -92,19 +90,19 @@ describe("readSteeringSettings layering", () => {
|
|
|
92
90
|
|
|
93
91
|
describe("writeSteeringSection", () => {
|
|
94
92
|
it("merges into the file without clobbering siblings", () => {
|
|
95
|
-
writeGlobal({ theme: "dark", router: { baseUrl: "http://x/v1" }, steering: {
|
|
93
|
+
writeGlobal({ theme: "dark", router: { baseUrl: "http://x/v1" }, steering: { strictSerena: true } });
|
|
96
94
|
writeSteeringSection({ superpower: true, superpowerPrompt: "go loud" });
|
|
97
95
|
const s = readBack();
|
|
98
96
|
assert.equal(s.theme, "dark");
|
|
99
97
|
assert.equal(s.router.baseUrl, "http://x/v1");
|
|
100
|
-
assert.equal(s.steering.
|
|
98
|
+
assert.equal(s.steering.strictSerena, true, "existing steering keys survive");
|
|
101
99
|
assert.equal(s.steering.superpower, true);
|
|
102
100
|
assert.equal(s.steering.superpowerPrompt, "go loud");
|
|
103
101
|
});
|
|
104
102
|
|
|
105
103
|
it("writes only the patched keys and refuses to clobber a corrupt file", () => {
|
|
106
|
-
writeSteeringSection({
|
|
107
|
-
assert.deepEqual(readBack().steering, {
|
|
104
|
+
writeSteeringSection({ stripReasoning: false });
|
|
105
|
+
assert.deepEqual(readBack().steering, { stripReasoning: false }, "one key patched, nothing else written");
|
|
108
106
|
writeFileSync(globalFile(), "{ not json");
|
|
109
107
|
assert.throws(() => writeSteeringSection({ superpower: true }), /not valid JSON/);
|
|
110
108
|
});
|
|
@@ -112,7 +110,7 @@ describe("writeSteeringSection", () => {
|
|
|
112
110
|
|
|
113
111
|
describe("projectOverridesSteering", () => {
|
|
114
112
|
it("is true only for a trusted project that actually sets steering.*", () => {
|
|
115
|
-
writeProject({ steering: {
|
|
113
|
+
writeProject({ steering: { stripReasoning: false } });
|
|
116
114
|
assert.equal(projectOverridesSteering(REPO, true), true);
|
|
117
115
|
writeProject({ munin: { project: "x" } });
|
|
118
116
|
assert.equal(projectOverridesSteering(REPO, true), false, "another module's section is not a steering override");
|
|
@@ -133,14 +131,11 @@ describe("/config contribution", () => {
|
|
|
133
131
|
"steering.superpowerPrompt",
|
|
134
132
|
"steering.strictSerena",
|
|
135
133
|
"steering.stripReasoning",
|
|
136
|
-
"steering.dsAnchor",
|
|
137
|
-
"steering.weNeed",
|
|
138
134
|
"steering.thinkTool",
|
|
139
135
|
]);
|
|
140
|
-
const
|
|
141
|
-
assert.equal(
|
|
142
|
-
assert.equal(
|
|
143
|
-
assert.match(anchor.warning!, /V4 Pro and V4\.1 Flash:.*bash and str_replace_editor when both are declared/);
|
|
136
|
+
const think = groups[0].rows.find((r) => r.key === "steering.thinkTool")!;
|
|
137
|
+
assert.equal(think.kind, "toggle");
|
|
138
|
+
assert.equal(think.defaultValue, false);
|
|
144
139
|
// No Enable row here — the config module prepends it.
|
|
145
140
|
assert.equal(keys.some((k) => k.startsWith("ceulen.disabled")), false);
|
|
146
141
|
});
|
|
@@ -155,7 +150,7 @@ describe("/config contribution", () => {
|
|
|
155
150
|
});
|
|
156
151
|
|
|
157
152
|
it("save writes the changed keys to the global file and discloses a project override", async () => {
|
|
158
|
-
writeProject({ steering: {
|
|
153
|
+
writeProject({ steering: { strictSerena: true } });
|
|
159
154
|
const contrib = steeringConfig();
|
|
160
155
|
const rows = contrib.groups()[0].rows;
|
|
161
156
|
rows.find((r) => r.key === "steering.stripReasoning")!.set(false);
|
|
@@ -28,9 +28,8 @@ describe("/steering status", () => {
|
|
|
28
28
|
assert.match(text, /Super Power Mode \(DeepSeek V4\): off/);
|
|
29
29
|
assert.match(text, /Strict Serena \(DeepSeek V4\): off/);
|
|
30
30
|
assert.match(text, /Reasoning strip: on/);
|
|
31
|
-
assert.match(text, /ds-anchor \(V4 Pro \/ V4\.1 Flash\): off/);
|
|
32
|
-
assert.match(text, /We-need directive \(bootstrap\): off/);
|
|
33
31
|
assert.match(text, /Super Power turns: 0/);
|
|
32
|
+
assert.doesNotMatch(text, /ds-anchor/, "the anchor was deleted — no status surface may reference it");
|
|
34
33
|
});
|
|
35
34
|
|
|
36
35
|
it("reflects settings rows and the custom Super Power prompt", () => {
|
|
@@ -43,20 +42,19 @@ describe("/steering status", () => {
|
|
|
43
42
|
assert.match(text, /Reasoning strip: off/);
|
|
44
43
|
});
|
|
45
44
|
|
|
46
|
-
it("
|
|
45
|
+
it("reports the thinking level and follows a level change", () => {
|
|
47
46
|
const h = createFakePi();
|
|
48
47
|
const ctx = h.ctx("combo/deepseek-v4.1-flash", { thinkingLevel: "high" });
|
|
49
48
|
h.fire("session_start", {}, ctx);
|
|
50
49
|
h.fire("before_agent_start", { prompt: "x", systemPrompt: "FULL", systemPromptOptions: {} }, ctx);
|
|
51
50
|
const below = h.status(ctx);
|
|
52
|
-
assert.match(below, /Thinking level: high
|
|
53
|
-
assert.
|
|
54
|
-
// A level change past max clears the marker.
|
|
51
|
+
assert.match(below, /Thinking level: high/);
|
|
52
|
+
assert.doesNotMatch(below, /recipe wants max/);
|
|
55
53
|
h.fire("thinking_level_select", { level: "max", previousLevel: "high" }, ctx);
|
|
56
54
|
assert.match(h.status(ctx), /Thinking level: max$/m);
|
|
57
55
|
});
|
|
58
56
|
|
|
59
|
-
it("shows the error tally
|
|
57
|
+
it("shows the error tally", () => {
|
|
60
58
|
const h = createFakePi();
|
|
61
59
|
const ctx = h.ctx("deepseek-v4-pro");
|
|
62
60
|
h.setEntries([]);
|
|
@@ -66,7 +64,6 @@ describe("/steering status", () => {
|
|
|
66
64
|
h.fire("tool_execution_end", { toolName: "read", isError: true, result: "ENOENT: no such file or directory" }, ctx);
|
|
67
65
|
const text = h.status(ctx);
|
|
68
66
|
assert.match(text, /\*\*Errors:\*\* 1 total, last: path_not_found on read/);
|
|
69
|
-
assert.
|
|
70
|
-
assert.match(text, /bootstrap: minimal prompt engaged/);
|
|
67
|
+
assert.doesNotMatch(text, /\*\*ds-anchor trace:\*\*/);
|
|
71
68
|
});
|
|
72
69
|
});
|
package/package.json
CHANGED