dsh-context-compression-improved 0.6.5 → 0.7.0-beta.2
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/.github/workflows/ci.yml +39 -39
- package/CHANGELOG.ja.md +217 -211
- package/CHANGELOG.ko.md +211 -205
- package/CHANGELOG.md +392 -350
- package/CHANGELOG.zh.md +196 -190
- package/README.md +97 -96
- package/README.zh.md +86 -85
- package/eslint.config.js +76 -30
- package/package.json +3 -1
- package/packages/selector/dsh.plugin.json +1 -1
- package/packages/selector/lib/client.js +747 -3
- package/packages/selector/lib/index.js +92 -1
- package/packages/selector/lib/{advisor-state.js → intent-gate.js} +91 -3
- package/packages/selector/lib/profiles.d.ts +9 -0
- package/packages/selector/lib/pruner.d.ts +59 -0
- package/packages/selector/lib/pruner.js +410 -8
- package/packages/selector/src/client/decode.ts +53 -49
- package/packages/selector/src/client/index.ts +30 -0
- package/packages/selector/src/client/locales/de.ts +98 -0
- package/packages/selector/src/client/locales/es.ts +98 -0
- package/packages/selector/src/client/locales/fr.ts +98 -0
- package/packages/selector/src/client/locales/it.ts +98 -0
- package/packages/selector/src/client/locales/ja.ts +98 -0
- package/packages/selector/src/client/locales/ko.ts +98 -0
- package/packages/selector/src/client/locales/ru.ts +98 -0
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
- package/packages/selector/src/index.ts +418 -411
- package/packages/selector/src/preset-overlay.ts +629 -626
- package/packages/selector/src/profiles.ts +414 -394
- package/packages/selector/src/pruner/content.ts +198 -198
- package/packages/selector/src/pruner/state.ts +57 -50
- package/packages/selector/src/pruner.ts +2665 -2421
- package/packages/selector/src/runtime/audit.ts +303 -286
- package/packages/selector/src/runtime/config.ts +731 -706
- package/packages/selector/src/runtime/reducers.ts +1674 -1674
- package/packages/selector/src/runtime/summary-command.ts +133 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -188
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -149
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -303
- package/packages/selector/src/runtime/types.ts +358 -346
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -213
- package/packages/selector/tests/built/client-artifact.spec.ts +61 -59
- package/packages/selector/tests/code-skeleton.client.spec.ts +94 -93
- package/packages/selector/tests/custom-contract.client.spec.ts +223 -222
- package/packages/selector/tests/estimator-channel.client.spec.tsx +252 -252
- package/packages/selector/tests/preset-options-write.client.spec.ts +188 -187
- package/packages/selector/tests/profiles.client.spec.tsx +436 -434
- package/packages/selector/tests/runtime/audit.spec.ts +275 -274
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +5 -0
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +15 -35
- package/scripts/packed-components-smoke.mjs +734 -732
- package/scripts/packed-install-e2e.mjs +1275 -1273
- package/scripts/verify-release.mjs +318 -317
- package/tests/TEST_INVENTORY.md +41 -41
- package/tsconfig.tests.json +17 -15
- package/vitest.config.ts +57 -43
- package/.agents-stash-064.patch +0 -39
- package/_dsh_devdeps.json +0 -50
- package/_verify064/package/package.json +0 -162
- package/_verify064/package/packages/selector/src/client/index.ts +0 -232
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as getLastIntentFold, i as getAdvisorState, n as INTENT_GATE_GROWTH_TOKENS, o as getObservedIntentEnabled, p as setSummaryOverride, s as getSummaryOverride, t as INTENT_GATE_FLOOR_FRACTION, v as DEFAULT_CONTEXT_COMPRESSION_SETTINGS } from "./intent-gate.js";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
@@ -75,6 +75,96 @@ async function buildEstimatorCatalog(deps) {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
//#endregion
|
|
78
|
+
//#region src/runtime/summary-command.ts
|
|
79
|
+
const SUMMARY_COMMAND_NAME = "ctx-summary";
|
|
80
|
+
const USAGE = "Usage: /ctx-summary off|on|status";
|
|
81
|
+
/** Parse the raw argument string; `undefined` = unrecognized (usage error). */
|
|
82
|
+
function parseSummaryCommandArgs(rawInput) {
|
|
83
|
+
const token = rawInput.trim().toLowerCase();
|
|
84
|
+
if (token === "off" || token === "on" || token === "status") return token;
|
|
85
|
+
}
|
|
86
|
+
function describeFold(sessionId) {
|
|
87
|
+
const fold = getLastIntentFold(sessionId);
|
|
88
|
+
if (fold === void 0) return "none";
|
|
89
|
+
return `turn ${fold.turn}, seq ${fold.startSeq}..${fold.endSeq}`;
|
|
90
|
+
}
|
|
91
|
+
/** Human-facing status line; observability only, never a decision input. */
|
|
92
|
+
function formatSummaryStatus(sessionId) {
|
|
93
|
+
const override = getSummaryOverride(sessionId);
|
|
94
|
+
const enabled = getObservedIntentEnabled(sessionId);
|
|
95
|
+
const enabledText = enabled === void 0 ? "unknown (gate not evaluated yet)" : enabled ? "yes" : "no";
|
|
96
|
+
return [
|
|
97
|
+
`ctx-summary status:`,
|
|
98
|
+
` override: ${override ?? "default (settings-driven)"}`,
|
|
99
|
+
` intentSummary enabled (settings): ${enabledText}`,
|
|
100
|
+
` gate: floor >${Math.round(INTENT_GATE_FLOOR_FRACTION * 100)}% of window AND growth >${INTENT_GATE_GROWTH_TOKENS} tokens since last fold`,
|
|
101
|
+
` last fold: ${describeFold(sessionId)}`
|
|
102
|
+
].join("\n");
|
|
103
|
+
}
|
|
104
|
+
/** Resolve the invoking agent's session id (`''` when the host exposes none). */
|
|
105
|
+
function sessionIdOf(agent) {
|
|
106
|
+
const session = agent?.session;
|
|
107
|
+
if (session === void 0 || session.id === void 0 || session.id === null) return "";
|
|
108
|
+
return String(session.id);
|
|
109
|
+
}
|
|
110
|
+
/** Best-effort `CommandDefinitionId` brand; `undefined` on stripped hosts (registered without it). */
|
|
111
|
+
async function loadCommandDefinitionId() {
|
|
112
|
+
try {
|
|
113
|
+
return (await import("@deepseek-ai/dsh-commands")).CommandDefinitionId;
|
|
114
|
+
} catch {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Mount `/ctx-summary` for every composed human-command adapter. Never
|
|
120
|
+
* throws: the command is a convenience surface, and a host without the
|
|
121
|
+
* commands service (or with an incompatible registry shape) simply runs
|
|
122
|
+
* without it.
|
|
123
|
+
*/
|
|
124
|
+
function registerSummaryCommand(ctx) {
|
|
125
|
+
ctx.inject(["commands"], (injected) => {
|
|
126
|
+
const commands = injected.commands;
|
|
127
|
+
if (commands === void 0 || typeof commands.register !== "function") return;
|
|
128
|
+
(async () => {
|
|
129
|
+
try {
|
|
130
|
+
const definitionId = await loadCommandDefinitionId();
|
|
131
|
+
await commands.register({
|
|
132
|
+
name: SUMMARY_COMMAND_NAME,
|
|
133
|
+
description: "Turn-tail intent summary: temporarily disable/resume or inspect status",
|
|
134
|
+
...definitionId === void 0 ? {} : { definitionId: definitionId("dsh-context-compression-improved/ctx-summary") },
|
|
135
|
+
handler: async (invocation) => {
|
|
136
|
+
const args = parseSummaryCommandArgs(typeof invocation.rawInput === "string" ? invocation.rawInput : "");
|
|
137
|
+
if (args === void 0) return {
|
|
138
|
+
kind: "error",
|
|
139
|
+
text: USAGE
|
|
140
|
+
};
|
|
141
|
+
const sessionId = sessionIdOf(invocation.agent);
|
|
142
|
+
if (args === "status") {
|
|
143
|
+
if (sessionId === "") return {
|
|
144
|
+
kind: "error",
|
|
145
|
+
text: "ctx-summary: no session is attached to this invocation"
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
kind: "success",
|
|
149
|
+
text: formatSummaryStatus(sessionId)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (sessionId === "") return {
|
|
153
|
+
kind: "error",
|
|
154
|
+
text: "ctx-summary: no session is attached to this invocation"
|
|
155
|
+
};
|
|
156
|
+
setSummaryOverride(sessionId, args);
|
|
157
|
+
return {
|
|
158
|
+
kind: "success",
|
|
159
|
+
text: args === "off" ? "ctx-summary: turn-tail intent summary paused for this session (until process restart or `/ctx-summary on`)" : "ctx-summary: turn-tail intent summary resumed for this session (numeric gates still apply)"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
} catch {}
|
|
164
|
+
})();
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
78
168
|
//#region src/preset-overlay.ts
|
|
79
169
|
/** Plugin-owned, reversible compression overlays for native agent presets. */
|
|
80
170
|
/**
|
|
@@ -742,6 +832,7 @@ function apply(ctx, config = {}) {
|
|
|
742
832
|
try {
|
|
743
833
|
if (config.estimatorCatalogRoute === true) registerEstimatorCatalogRoute(ctx);
|
|
744
834
|
if (config.advisorReportRoute === true) registerAdvisorReportRoute(ctx);
|
|
835
|
+
registerSummaryCommand(ctx);
|
|
745
836
|
if (config.presetOverlay !== true) return;
|
|
746
837
|
ctx.inject(["agentPresets"], (presetsCtx) => {
|
|
747
838
|
const installation = decorateAgentPresets(presetsCtx.agentPresets, {
|
|
@@ -373,6 +373,20 @@ function parseCodeSkeletonSettings(value) {
|
|
|
373
373
|
return { enabled };
|
|
374
374
|
}
|
|
375
375
|
/**
|
|
376
|
+
* Strictly parse the persisted intentSummary section. Mirrors the codeSkeleton
|
|
377
|
+
* section semantics: absent inherits the lossless `false` default, while a
|
|
378
|
+
* present-but-invalid section is an explicitly invalid document.
|
|
379
|
+
*/
|
|
380
|
+
function parseIntentSummarySettings(value) {
|
|
381
|
+
if (value === void 0) return { enabled: false };
|
|
382
|
+
if (!isPlainRecord(value)) throw new TypeError("Context-compression intentSummary must be a plain object");
|
|
383
|
+
const keys = Object.keys(value);
|
|
384
|
+
if (keys.length !== 1 || keys[0] !== "enabled") throw new TypeError(`Context-compression intentSummary: expected exactly "enabled", got "${keys.join("\", \"")}"`);
|
|
385
|
+
const enabled = value.enabled;
|
|
386
|
+
if (typeof enabled !== "boolean") throw new TypeError("Context-compression intentSummary.enabled must be a boolean");
|
|
387
|
+
return { enabled };
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
376
390
|
* Parse the optional tokenpilot-inspired preset sub-capability section. Absent
|
|
377
391
|
* inherits the preset defaults; present-but-invalid is rejected, mirroring the
|
|
378
392
|
* codeSkeleton section semantics.
|
|
@@ -479,7 +493,8 @@ const DEFAULT_CONTEXT_COMPRESSION_SETTINGS = {
|
|
|
479
493
|
profile: "balanced",
|
|
480
494
|
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
481
495
|
autoCompact: { thresholdPercent: AUTO_COMPACT_THRESHOLD_LIMITS.default },
|
|
482
|
-
codeSkeleton: { enabled: false }
|
|
496
|
+
codeSkeleton: { enabled: false },
|
|
497
|
+
intentSummary: { enabled: false }
|
|
483
498
|
};
|
|
484
499
|
/**
|
|
485
500
|
* Parse one settings document with the persisted-section semantics: `undefined`
|
|
@@ -497,17 +512,19 @@ const ContextCompressionSettingsSchema = z.transform(z.any().required(), (value)
|
|
|
497
512
|
if (!isPlainRecord(value)) throw new TypeError("Context-compression settings must be a plain object");
|
|
498
513
|
assertPlainDataTree(value);
|
|
499
514
|
const candidate = structuredClone(value);
|
|
500
|
-
const unknown = Object.keys(candidate).find((key) => key !== "profile" && key !== "custom" && key !== "autoCompact" && key !== "codeSkeleton" && key !== "presetOptions");
|
|
515
|
+
const unknown = Object.keys(candidate).find((key) => key !== "profile" && key !== "custom" && key !== "autoCompact" && key !== "codeSkeleton" && key !== "intentSummary" && key !== "presetOptions");
|
|
501
516
|
if (unknown !== void 0) throw new TypeError(`Context-compression settings: unknown key "${unknown}"`);
|
|
502
517
|
assertPresentSection(candidate, "profile", isSupportedProfile);
|
|
503
518
|
assertPresentSection(candidate, "custom", isUsableCustomDocument);
|
|
504
519
|
const autoCompact = parseAutoCompactSettings(candidate.autoCompact);
|
|
505
520
|
const codeSkeleton = parseCodeSkeletonSettings(candidate.codeSkeleton);
|
|
521
|
+
const intentSummary = parseIntentSummarySettings(candidate.intentSummary);
|
|
506
522
|
const presetOptions = parsePresetOptionsSettings(candidate.presetOptions);
|
|
507
523
|
return {
|
|
508
524
|
...contextCompressionSettingsInputSchema(candidate),
|
|
509
525
|
autoCompact,
|
|
510
526
|
codeSkeleton,
|
|
527
|
+
intentSummary,
|
|
511
528
|
...presetOptions === void 0 ? {} : { presetOptions }
|
|
512
529
|
};
|
|
513
530
|
}).default(DEFAULT_CONTEXT_COMPRESSION_SETTINGS);
|
|
@@ -958,5 +975,76 @@ function invalidateOnTaskChange(state, todoVersion) {
|
|
|
958
975
|
state.lastSummaryTurn = -1;
|
|
959
976
|
return true;
|
|
960
977
|
}
|
|
978
|
+
/**
|
|
979
|
+
* `/ctx-summary off|on` overrides, keyed by session id (string). The command
|
|
980
|
+
* handler only sees `invocation.agent.session.id`, not the pruner's Session
|
|
981
|
+
* object, so these are id-keyed rather than WeakMap'd. Entries are two-char
|
|
982
|
+
* strings per session and cleared whenever the override is lifted.
|
|
983
|
+
*/
|
|
984
|
+
const summaryOverrides = /* @__PURE__ */ new Map();
|
|
985
|
+
/** Read the session's `/ctx-summary` override; `undefined` = default (settings-driven). */
|
|
986
|
+
function getSummaryOverride(sessionId) {
|
|
987
|
+
return summaryOverrides.get(sessionId);
|
|
988
|
+
}
|
|
989
|
+
/** Set or clear (`undefined`) the session's `/ctx-summary` override. */
|
|
990
|
+
function setSummaryOverride(sessionId, value) {
|
|
991
|
+
if (value === void 0) summaryOverrides.delete(sessionId);
|
|
992
|
+
else summaryOverrides.set(sessionId, value);
|
|
993
|
+
}
|
|
994
|
+
/** Last observed `intentSummary.enabled` for a session, for `/ctx-summary status`. */
|
|
995
|
+
const lastObservedIntentEnabled = /* @__PURE__ */ new Map();
|
|
996
|
+
/** Record the gate input the pass last evaluated for this session. */
|
|
997
|
+
function observeIntentEnabled(sessionId, enabled) {
|
|
998
|
+
lastObservedIntentEnabled.set(sessionId, enabled);
|
|
999
|
+
}
|
|
1000
|
+
/** The settings-side enabled flag last observed for the session, if any. */
|
|
1001
|
+
function getObservedIntentEnabled(sessionId) {
|
|
1002
|
+
return lastObservedIntentEnabled.get(sessionId);
|
|
1003
|
+
}
|
|
1004
|
+
const lastIntentFolds = /* @__PURE__ */ new Map();
|
|
1005
|
+
/** Record a landed intent fold for the session (newest wins). */
|
|
1006
|
+
function recordIntentFold(sessionId, record) {
|
|
1007
|
+
lastIntentFolds.set(sessionId, record);
|
|
1008
|
+
}
|
|
1009
|
+
/** The most recent landed intent fold for the session, if any. */
|
|
1010
|
+
function getLastIntentFold(sessionId) {
|
|
1011
|
+
return lastIntentFolds.get(sessionId);
|
|
1012
|
+
}
|
|
1013
|
+
//#endregion
|
|
1014
|
+
//#region src/runtime/tokenpilot/intent-gate.ts
|
|
1015
|
+
/**
|
|
1016
|
+
* Turn-tail intent-summary growth gate (TokenPilot-inspired E2).
|
|
1017
|
+
*
|
|
1018
|
+
* Pure decision helper evaluated at the turn-boundary postflight: it decides
|
|
1019
|
+
* whether this turn may spend a summary-writer LLM call and stage a fold for
|
|
1020
|
+
* the next pressure round. The gate is deliberately conservative — every
|
|
1021
|
+
* unresolved input (unknown context window, non-finite counters) fails closed
|
|
1022
|
+
* toward "do not run", because a skipped fold is free while a wasted summary
|
|
1023
|
+
* call is not. Content safety is unaffected either way: fail-open semantics
|
|
1024
|
+
* live in the fold landing path, not here.
|
|
1025
|
+
*/
|
|
1026
|
+
/** Floor: the live surface must exceed this fraction of the context window. */
|
|
1027
|
+
const INTENT_GATE_FLOOR_FRACTION = .45;
|
|
1028
|
+
/** Growth: the live surface must have grown by more than this since the last landed fold. */
|
|
1029
|
+
const INTENT_GATE_GROWTH_TOKENS = 5e4;
|
|
1030
|
+
function isUsableNumber(value) {
|
|
1031
|
+
return Number.isFinite(value) && value >= 0;
|
|
1032
|
+
}
|
|
1033
|
+
/** Same evaluation with the reason attached, for audits and `/ctx-summary status`. */
|
|
1034
|
+
function evaluateIntentGate(input) {
|
|
1035
|
+
const snapshot = (decision, reason) => ({
|
|
1036
|
+
...input,
|
|
1037
|
+
decision,
|
|
1038
|
+
reason
|
|
1039
|
+
});
|
|
1040
|
+
if (!input.enabled) return snapshot(false, "disabled");
|
|
1041
|
+
if (input.override === "off") return snapshot(false, "override-off");
|
|
1042
|
+
if (!isUsableNumber(input.liveTokens)) return snapshot(false, "below-floor");
|
|
1043
|
+
if (input.contextWindow === void 0 || !isUsableNumber(input.contextWindow)) return snapshot(false, "no-window");
|
|
1044
|
+
if (!(input.liveTokens > input.contextWindow * .45)) return snapshot(false, "below-floor");
|
|
1045
|
+
if (!isUsableNumber(input.baselineTokens)) return snapshot(false, "below-growth");
|
|
1046
|
+
if (!(input.liveTokens - input.baselineTokens > 5e4)) return snapshot(false, "below-growth");
|
|
1047
|
+
return snapshot(true, "passed");
|
|
1048
|
+
}
|
|
961
1049
|
//#endregion
|
|
962
|
-
export {
|
|
1050
|
+
export { resolveCustomPolicy as A, isCompressionProfile as C, resolvePolicy as D, resolveConfig as E, deepFreeze as M, COMPRESSION_PROFILES as N, CustomCompressionPolicySchema as O, codePointLength as S, parseContextCompressionSettings as T, DEFAULTS as _, getLastIntentFold as a, charsForTokens as b, invalidateOnTaskChange as c, recordRecertified as d, recordScore as f, ContextCompressionSettingsSchema as g, CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as h, getAdvisorState as i, assertNever as j, DEFAULT_CUSTOM_COMPRESSION_POLICY as k, observeIntentEnabled as l, AUTO_COMPACT_THRESHOLD_LIMITS as m, INTENT_GATE_GROWTH_TOKENS as n, getObservedIntentEnabled as o, setSummaryOverride as p, evaluateIntentGate as r, getSummaryOverride as s, INTENT_GATE_FLOOR_FRACTION as t, recordIntentFold as u, DEFAULT_CONTEXT_COMPRESSION_SETTINGS as v, isValidAutoCompactThresholdPercent as w, charsToTokens as x, PRUNE_MARKER as y };
|
|
@@ -68,6 +68,13 @@ interface AutoCompactSettings {
|
|
|
68
68
|
interface CodeSkeletonSettings {
|
|
69
69
|
enabled: boolean;
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Orthogonal turn-tail intent-summary gate, mirrored browser-safe from the
|
|
73
|
+
* runtime: independent of every profile, default off.
|
|
74
|
+
*/
|
|
75
|
+
interface IntentSummarySettings {
|
|
76
|
+
enabled: boolean;
|
|
77
|
+
}
|
|
71
78
|
/** Browser-safe mirror of the runtime presetOptions section. */
|
|
72
79
|
interface PresetOptionsSettings {
|
|
73
80
|
readonly dedupeToolResults?: boolean;
|
|
@@ -98,6 +105,8 @@ interface ContextCompressionSettings {
|
|
|
98
105
|
autoCompact: AutoCompactSettings;
|
|
99
106
|
/** Code-skeleton reducer gate captured independently of `profile`. */
|
|
100
107
|
codeSkeleton: CodeSkeletonSettings;
|
|
108
|
+
/** Turn-tail intent-summary gate captured independently of `profile`. */
|
|
109
|
+
intentSummary: IntentSummarySettings;
|
|
101
110
|
/** Optional tokenpilot-inspired sub-capability overrides (presence-validated only). */
|
|
102
111
|
presetOptions?: PresetOptionsSettings;
|
|
103
112
|
}
|
|
@@ -134,6 +134,15 @@ interface AutoCompactSettings {
|
|
|
134
134
|
interface CodeSkeletonSettings {
|
|
135
135
|
enabled: boolean;
|
|
136
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Orthogonal turn-tail intent-summary gate. Independent of every profile:
|
|
139
|
+
* when enabled, the turn-boundary growth gate may fold consumed-increment
|
|
140
|
+
* tool results into an LLM-written intent block (skeleton + verbatim error
|
|
141
|
+
* lines are kept; the model only ever writes the summary segment).
|
|
142
|
+
*/
|
|
143
|
+
interface IntentSummarySettings {
|
|
144
|
+
enabled: boolean;
|
|
145
|
+
}
|
|
137
146
|
/**
|
|
138
147
|
* Persisted sub-capability overrides for the `tokenpilot-inspired` preset.
|
|
139
148
|
* Absent fields inherit the preset defaults; the section is only meaningful
|
|
@@ -173,6 +182,8 @@ interface ContextCompressionSettings {
|
|
|
173
182
|
autoCompact: AutoCompactSettings;
|
|
174
183
|
/** Code-skeleton reducer gate snapped independently of `profile`. */
|
|
175
184
|
codeSkeleton: CodeSkeletonSettings;
|
|
185
|
+
/** Turn-tail intent-summary gate snapped independently of `profile`. */
|
|
186
|
+
intentSummary: IntentSummarySettings;
|
|
176
187
|
/** Optional tokenpilot-inspired sub-capability overrides; absent inherits preset defaults. */
|
|
177
188
|
presetOptions?: PresetOptionsSettings;
|
|
178
189
|
}
|
|
@@ -397,6 +408,32 @@ interface EstimatorFailures {
|
|
|
397
408
|
cooldownUntil: number;
|
|
398
409
|
}
|
|
399
410
|
//#endregion
|
|
411
|
+
//#region src/runtime/tokenpilot/intent-input-mask.d.ts
|
|
412
|
+
type IntentRole = 'read-mask' | 'write-keep' | 'conservative';
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/runtime/tokenpilot/intent-fold.d.ts
|
|
415
|
+
/** One staged fold awaiting the next pressure round. */
|
|
416
|
+
interface PendingIntentFold {
|
|
417
|
+
readonly createdAt: number;
|
|
418
|
+
readonly turn: number;
|
|
419
|
+
/** Inclusive seq span of the folded candidates. */
|
|
420
|
+
readonly startSeq: number;
|
|
421
|
+
readonly endSeq: number;
|
|
422
|
+
/** LLM-written summary segment (fail-open parsed, char-capped). */
|
|
423
|
+
readonly summary: string;
|
|
424
|
+
/** Verbatim error lines collected across the batch (never LLM-revoiced). */
|
|
425
|
+
readonly errorLines: readonly string[];
|
|
426
|
+
/** Per-candidate faces: read-mask single lines ride the block, keep-class lines prompt-only. */
|
|
427
|
+
readonly records: ReadonlyArray<{
|
|
428
|
+
readonly seq: number;
|
|
429
|
+
readonly role: IntentRole;
|
|
430
|
+
readonly toolName: string;
|
|
431
|
+
readonly line: string;
|
|
432
|
+
}>;
|
|
433
|
+
/** Characters consumed by the summary-writer call (credit accounting). */
|
|
434
|
+
readonly summaryCallChars: number;
|
|
435
|
+
}
|
|
436
|
+
//#endregion
|
|
400
437
|
//#region src/pruner/state.d.ts
|
|
401
438
|
/** Mutable per-session state bag used inside {@link ToolResultPruner}. */
|
|
402
439
|
interface PrunerState {
|
|
@@ -430,6 +467,12 @@ interface PrunerState {
|
|
|
430
467
|
readonly estimatorRemainingTurns: WeakMap<Session, number>;
|
|
431
468
|
/** Per-session advisor side channel, constructed once with the advisor overrides. */
|
|
432
469
|
readonly advisorChannels: WeakMap<Session, SideChannel>;
|
|
470
|
+
/** Staged intent fold awaiting the next pressure round (at most one per session). */
|
|
471
|
+
readonly pendingIntentFolds: WeakMap<Session, PendingIntentFold>;
|
|
472
|
+
/** Landed intent-fold seqs: fold-once, never reconsidered by any later stage. */
|
|
473
|
+
readonly intentFoldedSeqs: WeakMap<Session, Set<number>>;
|
|
474
|
+
/** Live-surface tokens when the last intent fold landed (growth-gate baseline). */
|
|
475
|
+
readonly intentBaselines: WeakMap<Session, number>;
|
|
433
476
|
}
|
|
434
477
|
//#endregion
|
|
435
478
|
//#region src/runtime/custom-policy.d.ts
|
|
@@ -759,6 +802,22 @@ declare class ToolResultPruner extends Service {
|
|
|
759
802
|
* reads, so the default configuration adds exactly zero behavior.
|
|
760
803
|
*/
|
|
761
804
|
private postflightAdvisorPass;
|
|
805
|
+
/**
|
|
806
|
+
* Fire-and-forget postflight: evaluate the growth gate, and only when it
|
|
807
|
+
* passes, select the consumed increment OUTSIDE the protected working set,
|
|
808
|
+
* mask it to semantic-role records, and spend ONE summary-writer call. The
|
|
809
|
+
* verdict stages as a pending fold that the NEXT pressure round lands via
|
|
810
|
+
* the ordinary plan/apply machinery — the synchronous decision path never
|
|
811
|
+
* waits on an LLM.
|
|
812
|
+
*/
|
|
813
|
+
private postflightIntentFoldPass;
|
|
814
|
+
/**
|
|
815
|
+
* Convert a staged pending fold into per-candidate planned replacements
|
|
816
|
+
* (reducer `intent-summary`). Fail-open: a candidate that would grow, is
|
|
817
|
+
* rich-content, or no longer exists keeps its original text. Returns
|
|
818
|
+
* `undefined` when there is nothing (or no longer anything) to fold.
|
|
819
|
+
*/
|
|
820
|
+
private applyPendingIntentFold;
|
|
762
821
|
/**
|
|
763
822
|
* Monotonic per-session turn clock for advisory records. Bumped by the agent
|
|
764
823
|
* loop payloads (`pre-step`); passes without a turn coordinate reuse the last
|