@pentoshi/clai 4.1.0 → 4.2.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/README.md +14 -0
- package/dist/agent/compaction-executor.d.ts +68 -0
- package/dist/agent/compaction-executor.js +343 -0
- package/dist/agent/compaction-executor.js.map +1 -0
- package/dist/agent/context-breakdown.js +2 -0
- package/dist/agent/context-breakdown.js.map +1 -1
- package/dist/agent/context-manager.d.ts +23 -9
- package/dist/agent/context-manager.js +72 -43
- package/dist/agent/context-manager.js.map +1 -1
- package/dist/agent/events.d.ts +3 -0
- package/dist/agent/loop-guard.d.ts +2 -0
- package/dist/agent/loop-guard.js +48 -3
- package/dist/agent/loop-guard.js.map +1 -1
- package/dist/agent/prompt-composer.js +6 -6
- package/dist/agent/prompt-composer.js.map +1 -1
- package/dist/agent/reliability-policy.d.ts +1 -0
- package/dist/agent/reliability-policy.js +6 -3
- package/dist/agent/reliability-policy.js.map +1 -1
- package/dist/agent/request-accounting.d.ts +97 -0
- package/dist/agent/request-accounting.js +207 -0
- package/dist/agent/request-accounting.js.map +1 -0
- package/dist/agent/request-budget.d.ts +2 -2
- package/dist/agent/request-budget.js +2 -4
- package/dist/agent/request-budget.js.map +1 -1
- package/dist/agent/runner.d.ts +8 -2
- package/dist/agent/runner.js +409 -178
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/session-title.d.ts +0 -26
- package/dist/agent/session-title.js +0 -80
- package/dist/agent/session-title.js.map +1 -1
- package/dist/agent/tool-history.d.ts +2 -2
- package/dist/agent/tool-history.js +19 -6
- package/dist/agent/tool-history.js.map +1 -1
- package/dist/app/adapters/agent-event-adapter.js +19 -0
- package/dist/app/adapters/agent-event-adapter.js.map +1 -1
- package/dist/app/adapters/current-agent-adapter.js +4 -0
- package/dist/app/adapters/current-agent-adapter.js.map +1 -1
- package/dist/app/commands/catalog.js +24 -0
- package/dist/app/commands/catalog.js.map +1 -1
- package/dist/app/controllers/cancel-coordinator.d.ts +51 -0
- package/dist/app/controllers/cancel-coordinator.js +48 -0
- package/dist/app/controllers/cancel-coordinator.js.map +1 -0
- package/dist/app/controllers/session-compact-helper.d.ts +19 -2
- package/dist/app/controllers/session-compact-helper.js +100 -127
- package/dist/app/controllers/session-compact-helper.js.map +1 -1
- package/dist/app/controllers/session-context-usage.d.ts +32 -15
- package/dist/app/controllers/session-context-usage.js +186 -51
- package/dist/app/controllers/session-context-usage.js.map +1 -1
- package/dist/app/controllers/session-controller.d.ts +20 -11
- package/dist/app/controllers/session-controller.js +111 -90
- package/dist/app/controllers/session-controller.js.map +1 -1
- package/dist/app/controllers/session-naming.d.ts +31 -0
- package/dist/app/controllers/session-naming.js +173 -0
- package/dist/app/controllers/session-naming.js.map +1 -0
- package/dist/app/controllers/session-persistence.d.ts +2 -2
- package/dist/app/controllers/session-persistence.js +3 -6
- package/dist/app/controllers/session-persistence.js.map +1 -1
- package/dist/app/controllers/session-turn-request.d.ts +2 -1
- package/dist/app/controllers/session-turn-request.js +3 -0
- package/dist/app/controllers/session-turn-request.js.map +1 -1
- package/dist/app/controllers/turn-controller.d.ts +2 -1
- package/dist/app/controllers/turn-controller.js +1 -0
- package/dist/app/controllers/turn-controller.js.map +1 -1
- package/dist/app/events/app-event.d.ts +9 -0
- package/dist/app/events/app-event.js.map +1 -1
- package/dist/app/ports/agent-port.d.ts +8 -1
- package/dist/classic/app/ClassicApp.js +2 -1
- package/dist/classic/app/ClassicApp.js.map +1 -1
- package/dist/classic/app/app-wiring.js +1 -2
- package/dist/classic/app/app-wiring.js.map +1 -1
- package/dist/classic/app/wiring-interactions.js +2 -7
- package/dist/classic/app/wiring-interactions.js.map +1 -1
- package/dist/classic/blocks/tool-lines.js +2 -1
- package/dist/classic/blocks/tool-lines.js.map +1 -1
- package/dist/classic/input/cancel-ladder.d.ts +2 -19
- package/dist/classic/input/cancel-ladder.js +13 -20
- package/dist/classic/input/cancel-ladder.js.map +1 -1
- package/dist/commands/providers.js +2 -0
- package/dist/commands/providers.js.map +1 -1
- package/dist/llm/adapters/anthropic-tools.d.ts +31 -14
- package/dist/llm/adapters/anthropic-tools.js +124 -29
- package/dist/llm/adapters/anthropic-tools.js.map +1 -1
- package/dist/llm/adapters/gemini-tools.d.ts +16 -4
- package/dist/llm/adapters/gemini-tools.js +117 -16
- package/dist/llm/adapters/gemini-tools.js.map +1 -1
- package/dist/llm/adapters/openai-tools.d.ts +13 -2
- package/dist/llm/adapters/openai-tools.js +58 -11
- package/dist/llm/adapters/openai-tools.js.map +1 -1
- package/dist/llm/agentrouter.js +68 -45
- package/dist/llm/agentrouter.js.map +1 -1
- package/dist/llm/anthropic.js +69 -36
- package/dist/llm/anthropic.js.map +1 -1
- package/dist/llm/aws-mantle.js +70 -32
- package/dist/llm/aws-mantle.js.map +1 -1
- package/dist/llm/bynara.js +26 -69
- package/dist/llm/bynara.js.map +1 -1
- package/dist/llm/capabilities.d.ts +2 -1
- package/dist/llm/capabilities.js +47 -0
- package/dist/llm/capabilities.js.map +1 -1
- package/dist/llm/context-snapshot.d.ts +100 -0
- package/dist/llm/context-snapshot.js +277 -0
- package/dist/llm/context-snapshot.js.map +1 -0
- package/dist/llm/context-windows.d.ts +10 -0
- package/dist/llm/context-windows.js +129 -0
- package/dist/llm/context-windows.js.map +1 -0
- package/dist/llm/custom-provider-profile.d.ts +75 -0
- package/dist/llm/custom-provider-profile.js +558 -0
- package/dist/llm/custom-provider-profile.js.map +1 -0
- package/dist/llm/custom-providers.d.ts +13 -1
- package/dist/llm/custom-providers.js +77 -25
- package/dist/llm/custom-providers.js.map +1 -1
- package/dist/llm/effort-fallback.d.ts +44 -0
- package/dist/llm/effort-fallback.js +101 -0
- package/dist/llm/effort-fallback.js.map +1 -0
- package/dist/llm/fireworks.js +4 -0
- package/dist/llm/fireworks.js.map +1 -1
- package/dist/llm/free.js +4 -0
- package/dist/llm/free.js.map +1 -1
- package/dist/llm/gemini.d.ts +1 -1
- package/dist/llm/gemini.js +89 -51
- package/dist/llm/gemini.js.map +1 -1
- package/dist/llm/groq.js +4 -0
- package/dist/llm/groq.js.map +1 -1
- package/dist/llm/hetzner.js +4 -0
- package/dist/llm/hetzner.js.map +1 -1
- package/dist/llm/http.d.ts +49 -10
- package/dist/llm/http.js +417 -153
- package/dist/llm/http.js.map +1 -1
- package/dist/llm/kimchi.js +4 -0
- package/dist/llm/kimchi.js.map +1 -1
- package/dist/llm/lightning.js +4 -0
- package/dist/llm/lightning.js.map +1 -1
- package/dist/llm/meta.d.ts +2 -0
- package/dist/llm/meta.js +811 -655
- package/dist/llm/meta.js.map +1 -1
- package/dist/llm/modal.js +4 -0
- package/dist/llm/modal.js.map +1 -1
- package/dist/llm/model-families.d.ts +9 -0
- package/dist/llm/model-families.js +39 -0
- package/dist/llm/model-families.js.map +1 -0
- package/dist/llm/nvidia.js +4 -0
- package/dist/llm/nvidia.js.map +1 -1
- package/dist/llm/ollama.js +44 -40
- package/dist/llm/ollama.js.map +1 -1
- package/dist/llm/openai.js +4 -0
- package/dist/llm/openai.js.map +1 -1
- package/dist/llm/openrouter.js +4 -0
- package/dist/llm/openrouter.js.map +1 -1
- package/dist/llm/operation-ledger.d.ts +60 -0
- package/dist/llm/operation-ledger.js +136 -0
- package/dist/llm/operation-ledger.js.map +1 -0
- package/dist/llm/operation-usage.d.ts +32 -0
- package/dist/llm/operation-usage.js +172 -0
- package/dist/llm/operation-usage.js.map +1 -0
- package/dist/llm/orcarouter.d.ts +7 -0
- package/dist/llm/orcarouter.js +166 -0
- package/dist/llm/orcarouter.js.map +1 -0
- package/dist/llm/provider-profile-layers.d.ts +7 -0
- package/dist/llm/provider-profile-layers.js +961 -0
- package/dist/llm/provider-profile-layers.js.map +1 -0
- package/dist/llm/provider-profile.d.ts +181 -0
- package/dist/llm/provider-profile.js +329 -0
- package/dist/llm/provider-profile.js.map +1 -0
- package/dist/llm/provider-profiles.d.ts +13 -0
- package/dist/llm/provider-profiles.js +86 -0
- package/dist/llm/provider-profiles.js.map +1 -0
- package/dist/llm/provider.d.ts +2 -0
- package/dist/llm/provider.js +67 -0
- package/dist/llm/provider.js.map +1 -1
- package/dist/llm/qwen-cloud.js +4 -0
- package/dist/llm/qwen-cloud.js.map +1 -1
- package/dist/llm/reasoning-artifacts.d.ts +101 -0
- package/dist/llm/reasoning-artifacts.js +440 -0
- package/dist/llm/reasoning-artifacts.js.map +1 -0
- package/dist/llm/request-fingerprint.d.ts +10 -0
- package/dist/llm/request-fingerprint.js +313 -0
- package/dist/llm/request-fingerprint.js.map +1 -0
- package/dist/llm/request-plan.d.ts +119 -0
- package/dist/llm/request-plan.js +279 -0
- package/dist/llm/request-plan.js.map +1 -0
- package/dist/llm/router.d.ts +19 -1
- package/dist/llm/router.js +447 -75
- package/dist/llm/router.js.map +1 -1
- package/dist/llm/stream-events.d.ts +47 -0
- package/dist/llm/stream-events.js +55 -0
- package/dist/llm/stream-events.js.map +1 -0
- package/dist/llm/stream-terminal.d.ts +30 -0
- package/dist/llm/stream-terminal.js +51 -0
- package/dist/llm/stream-terminal.js.map +1 -0
- package/dist/llm/token-estimate-calibration.d.ts +23 -0
- package/dist/llm/token-estimate-calibration.js +140 -0
- package/dist/llm/token-estimate-calibration.js.map +1 -0
- package/dist/llm/token-usage.d.ts +35 -5
- package/dist/llm/token-usage.js +212 -162
- package/dist/llm/token-usage.js.map +1 -1
- package/dist/llm/tokenrouter.js +8 -2
- package/dist/llm/tokenrouter.js.map +1 -1
- package/dist/modes/ask.js +11 -5
- package/dist/modes/ask.js.map +1 -1
- package/dist/noninteractive/start-noninteractive.js +31 -2
- package/dist/noninteractive/start-noninteractive.js.map +1 -1
- package/dist/noninteractive/stream-blocks.js +15 -4
- package/dist/noninteractive/stream-blocks.js.map +1 -1
- package/dist/prompts/embedded.js +1 -1
- package/dist/prompts/embedded.js.map +1 -1
- package/dist/prompts/system.agent.md +6 -0
- package/dist/store/config.js +5 -1
- package/dist/store/config.js.map +1 -1
- package/dist/store/history.d.ts +2 -0
- package/dist/store/history.js +19 -10
- package/dist/store/history.js.map +1 -1
- package/dist/store/plan.js +20 -14
- package/dist/store/plan.js.map +1 -1
- package/dist/tools/elevated-shell.d.ts +1 -1
- package/dist/tools/elevated-shell.js +24 -72
- package/dist/tools/elevated-shell.js.map +1 -1
- package/dist/tools/nmap-runner.js +30 -36
- package/dist/tools/nmap-runner.js.map +1 -1
- package/dist/tools/sudo-session.d.ts +83 -0
- package/dist/tools/sudo-session.js +124 -0
- package/dist/tools/sudo-session.js.map +1 -0
- package/dist/tui-v2/app/App.js +9 -24
- package/dist/tui-v2/app/App.js.map +1 -1
- package/dist/tui-v2/components/status/context-limit-chip.js +2 -2
- package/dist/tui-v2/components/status/context-limit-chip.js.map +1 -1
- package/dist/tui-v2/components/transcript/intro-card.js +2 -1
- package/dist/tui-v2/components/transcript/intro-card.js.map +1 -1
- package/dist/tui-v2/composer/composer-editor.js +2 -1
- package/dist/tui-v2/composer/composer-editor.js.map +1 -1
- package/dist/types.d.ts +156 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/ui-core/bootstrap/composition-root.d.ts +2 -0
- package/dist/ui-core/bootstrap/composition-root.js +26 -3
- package/dist/ui-core/bootstrap/composition-root.js.map +1 -1
- package/dist/ui-core/commands/picker-commands.js +11 -5
- package/dist/ui-core/commands/picker-commands.js.map +1 -1
- package/dist/ui-core/commands/session-commands.js +41 -5
- package/dist/ui-core/commands/session-commands.js.map +1 -1
- package/dist/ui-core/plan/plan-lifecycle.js +3 -2
- package/dist/ui-core/plan/plan-lifecycle.js.map +1 -1
- package/dist/ui-core/rendering/context-limit.js +4 -1
- package/dist/ui-core/rendering/context-limit.js.map +1 -1
- package/dist/ui-core/rendering/duration.d.ts +2 -1
- package/dist/ui-core/rendering/duration.js +13 -5
- package/dist/ui-core/rendering/duration.js.map +1 -1
- package/dist/ui-core/rendering/intro-header.js +2 -2
- package/dist/ui-core/rendering/intro-header.js.map +1 -1
- package/dist/ui-core/rendering/theme.d.ts +1 -0
- package/dist/ui-core/rendering/theme.js +2 -0
- package/dist/ui-core/rendering/theme.js.map +1 -1
- package/dist/ui-core/state/transcript-hydrate.js +3 -3
- package/dist/ui-core/state/transcript-hydrate.js.map +1 -1
- package/dist/ui-core/state/transcript-reducer.d.ts +5 -0
- package/dist/ui-core/state/transcript-reducer.js +76 -3
- package/dist/ui-core/state/transcript-reducer.js.map +1 -1
- package/dist/ui-core/state/transcript-store.d.ts +10 -1
- package/dist/ui-core/state/transcript-store.js +22 -1
- package/dist/ui-core/state/transcript-store.js.map +1 -1
- package/dist/ui-core/state/transcript-types.d.ts +2 -0
- package/dist/ui-core/state/transcript-types.js.map +1 -1
- package/dist/version.generated.d.ts +2 -2
- package/dist/version.generated.js +2 -2
- package/package.json +6 -1
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Summarizer callback used by SessionController.compact (keeps the controller slim).
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { buildDirectCompactionPrompt, compactionSinglePassInputBudget, COMPACTION_MAX_COMPLETION_TOKENS, COMPACTION_MAP_MAX_COMPLETION_TOKENS, } from "../../agent/compaction-summary.js";
|
|
5
|
+
import { executeCompactionSummary, planCompactionReplay, } from "../../agent/compaction-executor.js";
|
|
5
6
|
import { compactMessagesWithSummary, estimateMessagesTokens, isCompactionMemoryMessage, } from "../../agent/context-manager.js";
|
|
6
|
-
import { completeWithProvider, streamWithProvider } from "../../llm/router.js";
|
|
7
|
-
import { streamAlreadyEmitted } from "../../llm/stream-progress.js";
|
|
8
7
|
import { modelContextWindow } from "../../llm/token-usage.js";
|
|
9
|
-
import {
|
|
10
|
-
function isCompactionServerError(error) {
|
|
11
|
-
if (streamAlreadyEmitted(error))
|
|
12
|
-
return false;
|
|
13
|
-
const status = error && typeof error === "object" && "status" in error
|
|
14
|
-
? Number(error.status)
|
|
15
|
-
: 0;
|
|
16
|
-
if (status >= 500 && status <= 504)
|
|
17
|
-
return true;
|
|
18
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
19
|
-
return /internal server error/i.test(message);
|
|
20
|
-
}
|
|
8
|
+
import { OperationLedger, } from "../../llm/operation-ledger.js";
|
|
21
9
|
export async function summarizeForSessionCompact(prompt, opts) {
|
|
22
10
|
const maxTokens = opts.stage === "map"
|
|
23
11
|
? COMPACTION_MAP_MAX_COMPLETION_TOKENS
|
|
@@ -25,113 +13,53 @@ export async function summarizeForSessionCompact(prompt, opts) {
|
|
|
25
13
|
const systemContent = opts.purpose === "plan-implement"
|
|
26
14
|
? "Write concise, non-redundant research memory for an agent executing an approved plan. Do not add framing: the PLAN MODE HANDOFF wrapper and active plan are injected separately. For coding target 600–1000 tokens; preserve only verified state, reusable research/artifacts, decisions, blockers, and risks. Security handoffs may be longer to preserve findings and coverage. Never invent or cut a fact mid-token. You are summarizing, not continuing: never emit tool calls or fabricate tool results, file receipts, or transcript lines."
|
|
27
15
|
: "You compress conversation history into accurate continuation memory. You are SUMMARIZING the past session, not continuing it: do not answer the user, do not perform the next task, and never emit tool calls or fabricate tool results, file-write receipts (bytes/lines/sha256), exit codes, or 'TOOL:'/'[tools: …]' transcript lines. Describe what already happened in your own words.";
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
signal: opts.signal,
|
|
48
|
-
};
|
|
49
|
-
const runProviderAttempt = async (attemptRequest, replace = false) => {
|
|
50
|
-
if (!onToken) {
|
|
51
|
-
return completeWithProvider(attemptRequest, { maxRetries: 0 });
|
|
52
|
-
}
|
|
53
|
-
if (replace)
|
|
54
|
-
onToken("", true);
|
|
55
|
-
const parser = createThinkingStreamParser((text) => onToken(text), undefined, { remember: false });
|
|
56
|
-
const result = await streamWithProvider(attemptRequest, (token) => parser.push(token), { onStatus: () => undefined, maxRetries: 0 });
|
|
57
|
-
parser.finish();
|
|
58
|
-
return result;
|
|
59
|
-
};
|
|
60
|
-
const runAttempt = async (attemptRequest, replace = false) => {
|
|
61
|
-
try {
|
|
62
|
-
return await runProviderAttempt(attemptRequest, replace);
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
if (!isCompactionServerError(error))
|
|
66
|
-
throw error;
|
|
67
|
-
return await runProviderAttempt(attemptRequest, replace);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const first = await runAttempt(request);
|
|
71
|
-
let visible = normalizeCompactionSummary(stripThinking(first.text).visible);
|
|
72
|
-
let retryReason;
|
|
73
|
-
if (isCompactionCompletionTruncated(first, maxTokens)) {
|
|
74
|
-
retryReason = "truncated";
|
|
75
|
-
}
|
|
76
|
-
else if (!visible) {
|
|
77
|
-
retryReason = "reasoning-only";
|
|
78
|
-
}
|
|
79
|
-
else if (looksLikeTranscriptReplay(visible)) {
|
|
80
|
-
retryReason = "replayed";
|
|
81
|
-
}
|
|
82
|
-
else if (looksLikeIncompleteCompactionSummary(visible)) {
|
|
83
|
-
retryReason = "incomplete";
|
|
84
|
-
}
|
|
85
|
-
if (retryReason) {
|
|
86
|
-
const retry = await runAttempt({
|
|
87
|
-
...request,
|
|
88
|
-
messages: opts.sourceMessages
|
|
89
|
-
? [
|
|
90
|
-
...opts.sourceMessages,
|
|
91
|
-
{
|
|
92
|
-
role: "user",
|
|
93
|
-
content: buildCompactionRetryPrompt(p, retryReason),
|
|
94
|
-
},
|
|
95
|
-
]
|
|
96
|
-
: [
|
|
97
|
-
{
|
|
98
|
-
role: "system",
|
|
99
|
-
content: `${systemContent}\nReturn only a complete continuation-memory summary. Do not include analysis, reasoning, or <think> tags.`,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
role: "user",
|
|
103
|
-
content: buildCompactionRetryPrompt(p, retryReason),
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
temperature: 0,
|
|
107
|
-
maxTokens,
|
|
108
|
-
thinking: { enabled: false, effort: "none" },
|
|
109
|
-
}, true);
|
|
110
|
-
if (isCompactionCompletionTruncated(retry, maxTokens)) {
|
|
111
|
-
throw new Error("compaction failed: model hit the summary output limit twice — original context retained");
|
|
112
|
-
}
|
|
113
|
-
visible = normalizeCompactionSummary(stripThinking(retry.text).visible);
|
|
114
|
-
if (!visible) {
|
|
115
|
-
throw new Error("compaction failed: model returned an empty summary");
|
|
116
|
-
}
|
|
117
|
-
if (looksLikeTranscriptReplay(visible)) {
|
|
118
|
-
throw new Error("compaction failed: model replayed the transcript twice — original context retained");
|
|
119
|
-
}
|
|
120
|
-
if (looksLikeIncompleteCompactionSummary(visible)) {
|
|
121
|
-
throw new Error("compaction failed: model returned an incomplete summary twice — original context retained");
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return visible;
|
|
125
|
-
};
|
|
126
|
-
// `compactMessagesWithSummary` owns chunking/map-reduce. A second splitting
|
|
127
|
-
// layer here multiplied one /compact into N map calls plus another reduce.
|
|
128
|
-
return completeSummary(prompt, opts.onToken);
|
|
16
|
+
return executeCompactionSummary({
|
|
17
|
+
provider: opts.provider,
|
|
18
|
+
model: opts.model,
|
|
19
|
+
systemContent,
|
|
20
|
+
prompt,
|
|
21
|
+
maxTokens,
|
|
22
|
+
signal: opts.signal,
|
|
23
|
+
...(opts.sourceMessages ? { sourceMessages: opts.sourceMessages } : {}),
|
|
24
|
+
...(opts.baseRequest ? { baseRequest: opts.baseRequest } : {}),
|
|
25
|
+
...(opts.history ? { history: opts.history } : {}),
|
|
26
|
+
...(opts.contextLimitTokens !== undefined
|
|
27
|
+
? { contextLimitTokens: opts.contextLimitTokens }
|
|
28
|
+
: {}),
|
|
29
|
+
...(opts.operation ? { operation: opts.operation } : {}),
|
|
30
|
+
stream: Boolean(opts.onToken),
|
|
31
|
+
retryOnServerError: true,
|
|
32
|
+
qualityRetry: false,
|
|
33
|
+
onToken: opts.onToken,
|
|
34
|
+
});
|
|
129
35
|
}
|
|
130
36
|
export async function runSessionCompaction(options) {
|
|
131
37
|
const emit = (type, payload) => {
|
|
132
38
|
options.emit(options.sequencer.build(type, payload, undefined));
|
|
133
39
|
};
|
|
134
|
-
const
|
|
40
|
+
const historyTokensBefore = estimateMessagesTokens(options.history);
|
|
41
|
+
// The request-scoped measurement is the same provider-reported number the
|
|
42
|
+
// composer chip shows. The raw history estimate can exceed it (deliberately
|
|
43
|
+
// conservative chars-per-token ratio); preferring the estimate here made the
|
|
44
|
+
// compaction card disagree with the chip, so the request-scoped figure wins
|
|
45
|
+
// whenever one exists.
|
|
46
|
+
const requestTokensBefore = typeof options.requestTokensBefore === "number" &&
|
|
47
|
+
Number.isFinite(options.requestTokensBefore) &&
|
|
48
|
+
options.requestTokensBefore > 0
|
|
49
|
+
? Math.floor(options.requestTokensBefore)
|
|
50
|
+
: undefined;
|
|
51
|
+
const scope = requestTokensBefore === undefined ? "message-history" : "assembled-request";
|
|
52
|
+
const beforeTokens = requestTokensBefore ?? historyTokensBefore;
|
|
53
|
+
// Compaction only rewrites messages: the system prefix and tool schemas are
|
|
54
|
+
// untouched, so the request shrinks by exactly what the history shrinks by.
|
|
55
|
+
const reportedFor = (result) => ({
|
|
56
|
+
beforeTokens,
|
|
57
|
+
afterTokens: requestTokensBefore === undefined
|
|
58
|
+
? result.afterTokens
|
|
59
|
+
: Math.max(0, requestTokensBefore -
|
|
60
|
+
Math.max(0, result.beforeTokens - result.afterTokens)),
|
|
61
|
+
scope,
|
|
62
|
+
});
|
|
135
63
|
if (options.persist) {
|
|
136
64
|
emit("compaction-started", {
|
|
137
65
|
compactionId: options.compactionId,
|
|
@@ -139,16 +67,58 @@ export async function runSessionCompaction(options) {
|
|
|
139
67
|
});
|
|
140
68
|
}
|
|
141
69
|
let settled = false;
|
|
70
|
+
const operation = new OperationLedger({
|
|
71
|
+
kind: "compaction",
|
|
72
|
+
admissionBudget: 64,
|
|
73
|
+
continuationBudget: 0,
|
|
74
|
+
});
|
|
142
75
|
try {
|
|
143
|
-
const
|
|
76
|
+
const successfulRequest = options.successfulRequest;
|
|
77
|
+
if (!successfulRequest) {
|
|
78
|
+
throw new Error("compaction failed: no successful live model request is available for cache-preserving compaction; complete a turn first");
|
|
79
|
+
}
|
|
80
|
+
const contextLimitTokens = options.contextLimitTokens ??
|
|
81
|
+
modelContextWindow(successfulRequest.model, successfulRequest.provider);
|
|
82
|
+
const instruction = buildDirectCompactionPrompt({
|
|
83
|
+
...(options.purpose ? { purpose: options.purpose } : {}),
|
|
84
|
+
});
|
|
85
|
+
// Cache-preserving replay: the summary request resends the last
|
|
86
|
+
// successful turn request verbatim with the instruction appended, so the
|
|
87
|
+
// whole prior prompt is served from cache. When that assembled request
|
|
88
|
+
// would not fit (e.g. compacting a nearly-full session), fall back to the
|
|
89
|
+
// legacy transcript-rendered requests rather than failing closed.
|
|
90
|
+
const replayPlan = planCompactionReplay({
|
|
91
|
+
baseRequest: successfulRequest,
|
|
92
|
+
history: options.history,
|
|
93
|
+
prompt: instruction,
|
|
94
|
+
maxTokens: COMPACTION_MAX_COMPLETION_TOKENS,
|
|
95
|
+
contextLimitTokens,
|
|
96
|
+
stream: true,
|
|
97
|
+
});
|
|
98
|
+
const replay = replayPlan && !replayPlan.accounting.overLimit
|
|
99
|
+
? successfulRequest
|
|
100
|
+
: undefined;
|
|
101
|
+
const result = await compactMessagesWithSummary(options.history, (prompt, stage) => summarizeForSessionCompact(replay ? instruction : prompt, {
|
|
144
102
|
provider: options.provider,
|
|
145
103
|
model: options.model,
|
|
146
104
|
signal: options.signal,
|
|
147
105
|
purpose: options.purpose,
|
|
148
106
|
stage: stage?.phase,
|
|
149
|
-
...(
|
|
150
|
-
? {
|
|
151
|
-
|
|
107
|
+
...(replay
|
|
108
|
+
? {
|
|
109
|
+
baseRequest: replay,
|
|
110
|
+
history: options.history,
|
|
111
|
+
contextLimitTokens,
|
|
112
|
+
}
|
|
113
|
+
: {
|
|
114
|
+
// Legacy path: the direct strategy carries the full source
|
|
115
|
+
// messages; the transcript strategies embed the material in
|
|
116
|
+
// the prompt itself and need no sourceMessages.
|
|
117
|
+
...(stage?.sourceMessages
|
|
118
|
+
? { sourceMessages: stage.sourceMessages }
|
|
119
|
+
: {}),
|
|
120
|
+
}),
|
|
121
|
+
operation,
|
|
152
122
|
...(options.persist && stage?.phase !== "map"
|
|
153
123
|
? {
|
|
154
124
|
onToken: (text, replace) => {
|
|
@@ -166,12 +136,14 @@ export async function runSessionCompaction(options) {
|
|
|
166
136
|
budgetTokens: 0,
|
|
167
137
|
keepRecent: options.keepRecent,
|
|
168
138
|
purpose: options.purpose,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
139
|
+
singleAdmission: true,
|
|
140
|
+
...(replay ? { forceDirectSinglePass: true } : {}),
|
|
141
|
+
singlePassInputBudgetTokens: compactionSinglePassInputBudget(contextLimitTokens),
|
|
142
|
+
});
|
|
172
143
|
if (!options.isCurrent())
|
|
173
144
|
return result;
|
|
174
|
-
|
|
145
|
+
const reported = reportedFor(result);
|
|
146
|
+
options.commit(result, reported);
|
|
175
147
|
if (options.persist && result.summarized) {
|
|
176
148
|
const summary = [...result.messages]
|
|
177
149
|
.reverse()
|
|
@@ -180,8 +152,9 @@ export async function runSessionCompaction(options) {
|
|
|
180
152
|
emit("compaction-completed", {
|
|
181
153
|
compactionId: options.compactionId,
|
|
182
154
|
summary,
|
|
183
|
-
beforeTokens:
|
|
184
|
-
afterTokens:
|
|
155
|
+
beforeTokens: reported.beforeTokens,
|
|
156
|
+
afterTokens: reported.afterTokens,
|
|
157
|
+
contextScope: reported.scope,
|
|
185
158
|
});
|
|
186
159
|
}
|
|
187
160
|
else if (options.persist) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-compact-helper.js","sourceRoot":"","sources":["../../../src/app/controllers/session-compact-helper.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"session-compact-helper.js","sourceRoot":"","sources":["../../../src/app/controllers/session-compact-helper.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,gCAAgC,EAChC,oCAAoC,GACrC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,yBAAyB,GAE1B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EACL,eAAe,GAEhB,MAAM,+BAA+B,CAAC;AAOvC,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,MAAc,EACd,IAaC;IAED,MAAM,SAAS,GACb,IAAI,CAAC,KAAK,KAAK,KAAK;QAClB,CAAC,CAAC,oCAAoC;QACtC,CAAC,CAAC,gCAAgC,CAAC;IACvC,MAAM,aAAa,GACjB,IAAI,CAAC,OAAO,KAAK,gBAAgB;QAC/B,CAAC,CAAC,mhBAAmhB;QACrhB,CAAC,CAAC,4XAA4X,CAAC;IAEnY,OAAO,wBAAwB,CAAC;QAC9B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,aAAa;QACb,MAAM;QACN,SAAS;QACT,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAA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CAAC,YAAY;gBACnC,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,YAAY,EAAE,QAAQ,CAAC,KAAK;aAC7B,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YAC3B,IAAI,CAAC,mBAAmB,EAAE;gBACxB,YAAY,EAAE,OAAO,CAAC,YAAY;gBAClC,OAAO,EAAE,yCAAyC;gBAClD,cAAc,EAAE,YAAY;aAC7B,CAAC,CAAC;QACL,CAAC;QACD,IAAI,OAAO,CAAC,OAAO;YAAE,OAAO,GAAG,IAAI,CAAC;QACpC,IAAI,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;YAC3E,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;YACvD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,IAAI,CAAC,mBAAmB,EAAE;gBACxB,YAAY,EAAE,OAAO,CAAC,YAAY;gBAClC,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,OAAO;gBACzE,cAAc,EAAE,YAAY;aAC7B,CAAC,CAAC;QACL,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ContextAttemptReference, type ContextSnapshotScope, type ContextSnapshotV1 } from "../../llm/context-snapshot.js";
|
|
2
|
+
import type { ContextUsageSnapshot } from "../../llm/token-usage.js";
|
|
2
3
|
import type { ChatMessage, ProviderId, TokenUsage } from "../../types.js";
|
|
3
4
|
export interface ContextUsageTarget {
|
|
4
5
|
readonly provider?: ProviderId | undefined;
|
|
@@ -6,22 +7,38 @@ export interface ContextUsageTarget {
|
|
|
6
7
|
/** Explicit provider/model window for this session, if the user set one. */
|
|
7
8
|
readonly contextLimitTokens?: number | undefined;
|
|
8
9
|
}
|
|
10
|
+
export type ContextClock = () => number;
|
|
9
11
|
export declare function contextUsageLimit(target: ContextUsageTarget): number;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Keep the most recent request-scoped measurement. The message-history estimate
|
|
14
|
+
* omits the system prefix and tool schemas, so substituting it for a live
|
|
15
|
+
* measurement made the displayed number oscillate between two different scopes
|
|
16
|
+
* every step; it is now only a cold-start fallback.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveContextSnapshot(target: ContextUsageTarget, history: readonly ChatMessage[], current: ContextSnapshotV1 | undefined, now?: ContextClock): ContextSnapshotV1 | undefined;
|
|
19
|
+
/** Fold provider usage into one canonical provider-request observation. */
|
|
20
|
+
export declare function recordContextUsageSnapshot(target: ContextUsageTarget, current: ContextSnapshotV1 | undefined, usage: TokenUsage, attempt: ContextAttemptReference | undefined, now?: ContextClock): ContextSnapshotV1;
|
|
21
|
+
/** After compaction, exact provider fill is stale and the new scope is explicit. */
|
|
22
|
+
export declare function compactedContextSnapshot(target: ContextUsageTarget, current: ContextSnapshotV1 | undefined, history: readonly ChatMessage[], afterTokens: number | undefined, scope: Extract<ContextSnapshotScope, "message-history" | "assembled-request">, now?: ContextClock): ContextSnapshotV1;
|
|
23
|
+
export declare function estimatedContextSnapshot(target: ContextUsageTarget, current: ContextSnapshotV1 | undefined, estimatedTokens: number, now?: ContextClock): ContextSnapshotV1 | undefined;
|
|
14
24
|
export interface ContextProjection {
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
readonly contextSnapshot: ContextSnapshotV1 | undefined;
|
|
26
|
+
readonly contextUsage: ContextUsageSnapshot | undefined;
|
|
27
|
+
readonly contextChip: string | undefined;
|
|
17
28
|
}
|
|
18
|
-
export declare function createContextProjector(formatChip: (snapshot: ContextUsageSnapshot) => string): (target: ContextUsageTarget, history: readonly ChatMessage[], current:
|
|
29
|
+
export declare function createContextProjector(formatChip: (snapshot: ContextUsageSnapshot) => string): (target: ContextUsageTarget, history: readonly ChatMessage[], current: ContextSnapshotV1 | undefined, now?: ContextClock) => ContextProjection;
|
|
30
|
+
/** Legacy persisted shape, optionally carrying the additive V1 object. */
|
|
19
31
|
export interface PartialUsageSnapshot {
|
|
20
|
-
contextTokens: number;
|
|
21
|
-
contextLimit?: number | undefined;
|
|
22
|
-
lastCompletionTokens?: number | undefined;
|
|
23
|
-
sessionPromptTokens?: number | undefined;
|
|
24
|
-
sessionCompletionTokens?: number | undefined;
|
|
25
|
-
exact: boolean;
|
|
32
|
+
readonly contextTokens: number;
|
|
33
|
+
readonly contextLimit?: number | undefined;
|
|
34
|
+
readonly lastCompletionTokens?: number | undefined;
|
|
35
|
+
readonly sessionPromptTokens?: number | undefined;
|
|
36
|
+
readonly sessionCompletionTokens?: number | undefined;
|
|
37
|
+
readonly exact: boolean;
|
|
38
|
+
readonly contextSnapshot?: unknown;
|
|
26
39
|
}
|
|
27
|
-
|
|
40
|
+
/** Restore V1 when available, otherwise migrate the unversioned legacy shape. */
|
|
41
|
+
export declare function restoredContextSnapshot(target: ContextUsageTarget, usage: PartialUsageSnapshot | ContextUsageSnapshot | ContextSnapshotV1 | undefined, now?: ContextClock): ContextSnapshotV1 | undefined;
|
|
42
|
+
export declare function resolveContextUsageSnapshot(target: ContextUsageTarget, history: readonly ChatMessage[], current: ContextUsageSnapshot | undefined): ContextUsageSnapshot | undefined;
|
|
43
|
+
export declare function compactedUsageSnapshot(target: ContextUsageTarget, current: ContextUsageSnapshot | undefined, history: readonly ChatMessage[], afterTokens?: number): ContextUsageSnapshot;
|
|
44
|
+
export declare function estimatedUsageSnapshot(target: ContextUsageTarget, current: ContextUsageSnapshot | undefined, estimatedTokens: number): ContextUsageSnapshot | undefined;
|