dsh-context-compression-improved 0.10.3 → 0.10.4
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 +15 -110
- package/README.zh.md +14 -104
- package/THIRD_PARTY_NOTICES.md +25 -7
- package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +2 -2
- package/{packages/selector/lib → lib}/client.d.ts +4 -0
- package/{packages/selector/lib → lib}/client.js +70 -5
- package/{packages/selector/lib → lib}/invariant.js +1 -1
- package/{packages/selector/lib → lib}/profiles.d.ts +3 -1
- package/{packages/selector/lib → lib}/pruner.d.ts +4 -2
- package/{packages/selector/lib → lib}/pruner.js +40 -37
- package/{packages/selector/lib → lib}/savings-integral.js +83 -24
- package/{packages/selector/lib → lib}/tail-trim.js +2 -2
- package/{packages/selector/lib → lib}/tool-result.js +22 -1
- package/package.json +129 -116
- package/screenshots.json +3 -6
- package/.agents/plans/improve/checklist.md +0 -32
- package/.agents/plans/improve/findings.md +0 -102
- package/.agents/plans/improve/spec.md +0 -53
- package/.agents/plans/improve/tasks.md +0 -70
- package/.gitattributes +0 -2
- package/.githooks/pre-push +0 -37
- package/.github/workflows/ci.yml +0 -39
- package/CHANGELOG.de.md +0 -580
- package/CHANGELOG.es.md +0 -588
- package/CHANGELOG.fr.md +0 -576
- package/CHANGELOG.it.md +0 -577
- package/CHANGELOG.ja.md +0 -261
- package/CHANGELOG.ko.md +0 -254
- package/CHANGELOG.md +0 -549
- package/CHANGELOG.ru.md +0 -554
- package/CHANGELOG.zh.md +0 -238
- package/CONTRIBUTING.md +0 -22
- package/README.de.md +0 -96
- package/README.es.md +0 -96
- package/README.fr.md +0 -96
- package/README.it.md +0 -96
- package/README.ja.md +0 -102
- package/README.ko.md +0 -102
- package/README.ru.md +0 -96
- package/SECURITY.md +0 -18
- package/assets/board.png +0 -0
- package/assets/context.png +0 -0
- package/docs/assets/context-compression-selector-profiles.jpg +0 -0
- package/docs/assets/context-compression-selector-settings.png +0 -0
- package/docs/compat-0.1.5-report.md +0 -77
- package/docs/installation.de.md +0 -104
- package/docs/installation.es.md +0 -104
- package/docs/installation.fr.md +0 -104
- package/docs/installation.it.md +0 -104
- package/docs/installation.ja.md +0 -78
- package/docs/installation.ko.md +0 -78
- package/docs/installation.md +0 -103
- package/docs/installation.ru.md +0 -104
- package/docs/installation.zh.md +0 -100
- package/docs/repair-log.md +0 -657
- package/eslint.config.js +0 -30
- package/packages/selector/LICENSE +0 -21
- package/packages/selector/README.md +0 -26
- package/packages/selector/README.zh.md +0 -24
- package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
- package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
- package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
- package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
- package/packages/selector/lib/style.css +0 -350
- package/packages/selector/package.json +0 -178
- package/packages/selector/screenshots.json +0 -3
- package/packages/selector/src/client/CompressionProfileControls.tsx +0 -293
- package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
- package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -85
- package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
- package/packages/selector/src/client/EstimatorControls.tsx +0 -277
- package/packages/selector/src/client/bridge-scope.ts +0 -125
- package/packages/selector/src/client/decode.ts +0 -57
- package/packages/selector/src/client/fab-pos.ts +0 -71
- package/packages/selector/src/client/index.ts +0 -424
- package/packages/selector/src/client/locales/de.ts +0 -158
- package/packages/selector/src/client/locales/es.ts +0 -158
- package/packages/selector/src/client/locales/fr.ts +0 -158
- package/packages/selector/src/client/locales/it.ts +0 -158
- package/packages/selector/src/client/locales/ja.ts +0 -158
- package/packages/selector/src/client/locales/ko.ts +0 -158
- package/packages/selector/src/client/locales/ru.ts +0 -158
- package/packages/selector/src/client/locales.ts +0 -316
- package/packages/selector/src/client/monitor-fab.ts +0 -431
- package/packages/selector/src/client/preset-options.ts +0 -88
- package/packages/selector/src/client/savings-card.tsx +0 -269
- package/packages/selector/src/client/scope-face.ts +0 -24
- package/packages/selector/src/client/settings-section.tsx +0 -140
- package/packages/selector/src/compat/host-generation.ts +0 -96
- package/packages/selector/src/compat/llm-messages.ts +0 -50
- package/packages/selector/src/compat/settings-lease.ts +0 -108
- package/packages/selector/src/compat/tool-result.ts +0 -91
- package/packages/selector/src/css-modules.d.ts +0 -6
- package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
- package/packages/selector/src/estimator-catalog.ts +0 -104
- package/packages/selector/src/index.ts +0 -890
- package/packages/selector/src/invariant.ts +0 -113
- package/packages/selector/src/preset-overlay.ts +0 -749
- package/packages/selector/src/profiles.ts +0 -431
- package/packages/selector/src/pruner/content.ts +0 -198
- package/packages/selector/src/pruner/session.ts +0 -97
- package/packages/selector/src/pruner/state.ts +0 -61
- package/packages/selector/src/pruner/tuning.ts +0 -23
- package/packages/selector/src/pruner/types.ts +0 -78
- package/packages/selector/src/pruner.ts +0 -2914
- package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
- package/packages/selector/src/runtime/audit.ts +0 -320
- package/packages/selector/src/runtime/config.ts +0 -756
- package/packages/selector/src/runtime/custom-policy.ts +0 -278
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
- package/packages/selector/src/runtime/display-prefs.ts +0 -98
- package/packages/selector/src/runtime/measurement.ts +0 -444
- package/packages/selector/src/runtime/monitor.ts +0 -310
- package/packages/selector/src/runtime/panel-command.ts +0 -213
- package/packages/selector/src/runtime/reducers.ts +0 -1754
- package/packages/selector/src/runtime/retrieve.ts +0 -503
- package/packages/selector/src/runtime/savings-integral.ts +0 -117
- package/packages/selector/src/runtime/savings-projection.ts +0 -229
- package/packages/selector/src/runtime/savings-verify.ts +0 -446
- package/packages/selector/src/runtime/savings.ts +0 -526
- package/packages/selector/src/runtime/session-events.ts +0 -30
- package/packages/selector/src/runtime/session-file-decode.ts +0 -523
- package/packages/selector/src/runtime/stats-backfill.ts +0 -541
- package/packages/selector/src/runtime/stats-db.ts +0 -492
- package/packages/selector/src/runtime/stats-schema.ts +0 -123
- package/packages/selector/src/runtime/stats-sync.ts +0 -307
- package/packages/selector/src/runtime/summary-command.ts +0 -127
- package/packages/selector/src/runtime/tail-trim.ts +0 -176
- package/packages/selector/src/runtime/token-count.ts +0 -72
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -81
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
- package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -128
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
- package/packages/selector/src/runtime/toolclass.ts +0 -103
- package/packages/selector/src/runtime/types.ts +0 -365
- package/packages/selector/src/runtime/value.ts +0 -48
- package/packages/selector/src/settings-bridge.ts +0 -175
- package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
- package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
- package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
- package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
- package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
- package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
- package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
- package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
- package/packages/selector/tests/fab-pos.client.spec.ts +0 -47
- package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
- package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
- package/packages/selector/tests/monitor-fab.client.spec.ts +0 -240
- package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
- package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
- package/packages/selector/tests/profiles.client.spec.tsx +0 -436
- package/packages/selector/tests/public/package-contract.client.spec.ts +0 -86
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
- package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
- package/packages/selector/tests/runtime/audit.spec.ts +0 -275
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
- package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
- package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
- package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
- package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
- package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
- package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
- package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
- package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
- package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
- package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2781
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
- package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
- package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
- package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
- package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
- package/packages/selector/tests/runtime/savings.spec.ts +0 -139
- package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
- package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
- package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
- package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
- package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
- package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
- package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -348
- package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
- package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
- package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
- package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -119
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
- package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
- package/packages/selector/tests/runtime/value.spec.ts +0 -23
- package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
- package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
- package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
- package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
- package/packages/selector/tests/support/mock-adapter.ts +0 -37
- package/packages/selector/tests/support/ui-primitives.tsx +0 -34
- package/packages/selector/tsconfig.json +0 -11
- package/packages/selector/tsdown.client.config.ts +0 -102
- package/packages/selector/tsdown.config.ts +0 -20
- package/pnpm-workspace.yaml +0 -76
- package/scripts/capture-profile-baseline.mjs +0 -42
- package/scripts/cell-browser-e2e.mjs +0 -354
- package/scripts/generate-tokenizer-fixtures.py +0 -81
- package/scripts/generate-vision-fixtures.py +0 -208
- package/scripts/hosts.mjs +0 -78
- package/scripts/packed-components-smoke.mjs +0 -763
- package/scripts/packed-install-e2e.mjs +0 -1346
- package/scripts/sync-hosts.mjs +0 -174
- package/scripts/toolclass-corpus-replay.mjs +0 -281
- package/scripts/verify-release.mjs +0 -338
- package/tests/TEST_INVENTORY.md +0 -41
- package/tsconfig.base.json +0 -18
- package/tsconfig.json +0 -7
- package/tsconfig.tests.json +0 -15
- package/vitest.built.config.ts +0 -9
- package/vitest.config.ts +0 -54
- /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
- /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
- /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
- /package/{packages/selector/lib → lib}/index.d.ts +0 -0
- /package/{packages/selector/lib → lib}/index.js +0 -0
- /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ as isValidAutoCompactThresholdPercent, A as officialRequestUsage, At as recordRecertified, B as unavailableCount, Ct as getAdvisorState, D as dedupePlaceholder, Dt as invalidateOnTaskChange, E as dedupeHash, Et as getSummaryOverride, F as onlyTextBlocks, Ft as priceOfficialDeepSeekUsage, G as ContextCompressionSettingsSchema, H as countOmittedLines, I as pressureCost, It as resolveOfficialDeepSeekPrice, J as PRUNE_MARKER, K as DEFAULTS, L as recoveryMarker, Lt as getSavingsLedger, M as emptyResult, N as nativePruneContent, Nt as DEEPSEEK_OFFICIAL_PRICE_CATALOG_VERSION, O as flattenPlainText, Ot as observeIntentEnabled, P as onlyTextBlock, Pt as decimalRateNanoUnits, Q as isCompressionProfile, R as sameProviderMeasurementKey, St as evaluateIntentGate, T as DedupeTable, U as AUTO_COMPACT_THRESHOLD_LIMITS, V as CAPACITY_PRESSURE_RATIO, W as CONTEXT_COMPRESSION_SETTINGS_NAMESPACE, X as charsToTokens, Y as charsForTokens, Z as codePointLength, _ as scheduleUsageFlush, at as resolveCustomPolicy, ct as COMPRESSION_PROFILES, d as claimFromLand, et as parseContextCompressionSettings, f as claimOffset, ft as deepSeekV4TokenizerForModel, g as reclaimFromTailTrim, it as DEFAULT_CUSTOM_COMPRESSION_POLICY, j as countToolContent, jt as recordScore, k as measureForCompaction, kt as recordIntentFold, lt as countExactCanonicalTextFields, m as flushUsageOnDispose, n as sampleIntegralBoundary, nt as resolvePolicy, o as kickStatsBackfillOnDispose, ot as assertNever, rt as CustomCompressionPolicySchema, st as deepFreeze, tt as resolveConfig, v as setStatsLivePathBusy, w as projectSessionSavings, yt as observeContextUsage, z as summarize } from "./savings-integral.js";
|
|
2
|
-
import { n as viewToolResult, o as
|
|
2
|
+
import { c as eventBySeq, l as sessionEvents, n as viewToolResult, o as PTC_BINDING_NOTE, s as RUNTIME_TOOL_NAMES, t as compressionMessageSource } from "./tool-result.js";
|
|
3
3
|
import { a as validatePublishedTailTrim, i as tailTrimStub, n as tailTrimMessage, o as createUserMessage, r as tailTrimRef, s as freezeMessage, t as parseTailTrimRef } from "./tail-trim.js";
|
|
4
4
|
import z from "@deepseek-ai/schemastery";
|
|
5
5
|
import * as dshSessionNamespace from "@deepseek-ai/dsh-session";
|
|
@@ -15,8 +15,8 @@ const MAX_LINES = 1e3;
|
|
|
15
15
|
const DEFAULT_MAX_CHARS = 12e3;
|
|
16
16
|
const DEFAULT_MAX_SCAN_CHARS = 25e4;
|
|
17
17
|
const DEFAULT_MAX_QUERY_CHARS = 256;
|
|
18
|
-
const TRUNCATION_MARKER =
|
|
19
|
-
const PROMPT =
|
|
18
|
+
const TRUNCATION_MARKER = `\n[${RUNTIME_TOOL_NAMES.RETRIEVE} output truncated; reported lines describe the selected source range]\n`;
|
|
19
|
+
const PROMPT = `When a compacted tool result contains a session://<session-id>/event/<seq> reference, or TailTrim contains a session://<session-id>/tailtrim/<seq> reference, use ${RUNTIME_TOOL_NAMES.RETRIEVE} with that exact ref and a narrow line range or query if the omitted evidence is necessary. Prefer a query or a tight start_line/max_lines over re-reading the whole result: every recovery re-enters the context and is charged against the savings, so a targeted slice keeps the rest of the reduction. The returned event content comes from the append-only session log, which is the source of truth. ` + PTC_BINDING_NOTE;
|
|
20
20
|
const OUTPUT = {
|
|
21
21
|
schema: { type: "string" },
|
|
22
22
|
render: (_args, value) => [{
|
|
@@ -40,8 +40,8 @@ function installContextCompressionRetrieve(ctx, config = {}) {
|
|
|
40
40
|
text: PROMPT
|
|
41
41
|
});
|
|
42
42
|
ctx.tools.register(defineTool({
|
|
43
|
-
name:
|
|
44
|
-
description:
|
|
43
|
+
name: RUNTIME_TOOL_NAMES.RETRIEVE,
|
|
44
|
+
description: `Recover exact content from one compacted tool result or TailTrim group using its current-session session:// reference. ${PTC_BINDING_NOTE}`,
|
|
45
45
|
parameters: {
|
|
46
46
|
ref: {
|
|
47
47
|
type: "string",
|
|
@@ -64,11 +64,11 @@ function installContextCompressionRetrieve(ctx, config = {}) {
|
|
|
64
64
|
output: OUTPUT,
|
|
65
65
|
isConcurrencySafe: () => true,
|
|
66
66
|
execute(args, exec) {
|
|
67
|
-
if (exec.agent === void 0) throw new Error(
|
|
67
|
+
if (exec.agent === void 0) throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE} requires an agent session`);
|
|
68
68
|
const match = REF_PATTERN.exec(args.ref);
|
|
69
69
|
const tailTrimRef = parseTailTrimRef(args.ref);
|
|
70
|
-
if (match === null && tailTrimRef === null) throw new Error(
|
|
71
|
-
if ((match?.[1] ?? tailTrimRef?.sessionId) !== String(exec.agent.session.id)) throw new Error(
|
|
70
|
+
if (match === null && tailTrimRef === null) throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: ref must be session://<session-id>/(event|tailtrim)/<seq>`);
|
|
71
|
+
if ((match?.[1] ?? tailTrimRef?.sessionId) !== String(exec.agent.session.id)) throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: a compression reference may only read the caller's current session`);
|
|
72
72
|
if (tailTrimRef !== null) {
|
|
73
73
|
const sessionId = String(exec.agent.session.id);
|
|
74
74
|
return Promise.resolve(recoverTailTrim(exec.agent.session, args.ref, tailTrimRef.manifestSeq, args.query, args.start_line, args.max_lines, {
|
|
@@ -93,14 +93,14 @@ function installContextCompressionRetrieve(ctx, config = {}) {
|
|
|
93
93
|
}
|
|
94
94
|
const seq = Number(match?.[2]);
|
|
95
95
|
const event = sessionEvents(exec.agent.session)[seq];
|
|
96
|
-
if (event?.type !== "tool/result") throw new Error(
|
|
96
|
+
if (event?.type !== "tool/result") throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: event ${String(seq)} is not a tool/result in the current session`);
|
|
97
97
|
const maxLines = resolveMaxLines(args.max_lines);
|
|
98
98
|
const resultView = viewToolResult(event.data.message);
|
|
99
99
|
const scan = scanBlocks(resultView.blocks, maxScanChars);
|
|
100
100
|
const scannedLines = splitScannedLines(scan);
|
|
101
101
|
const lines = scannedLines.lines;
|
|
102
102
|
const query = args.query;
|
|
103
|
-
if (query !== void 0 && exceedsCodePointLimit(query, maxQueryChars)) throw new Error(
|
|
103
|
+
if (query !== void 0 && exceedsCodePointLimit(query, maxQueryChars)) throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: query must be at most ${String(maxQueryChars)} Unicode code points`);
|
|
104
104
|
const selected = query === void 0 || query === "" ? directSlice(lines, args.start_line ?? 1, maxLines, scan.complete, scannedLines.partialTail) : querySlice(lines, query, maxLines, scan.complete, scannedLines.partialTail);
|
|
105
105
|
const total = scan.complete ? String(lines.length) : `at least ${String(lines.length)}`;
|
|
106
106
|
const bounded = boundCodePoints(`${[
|
|
@@ -131,8 +131,8 @@ function installContextCompressionRetrieve(ctx, config = {}) {
|
|
|
131
131
|
}
|
|
132
132
|
function recoverTailTrim(session, ref, manifestSeq, query, startLine, requestedMaxLines, bounds) {
|
|
133
133
|
const published = validatePublishedTailTrim(session, manifestSeq);
|
|
134
|
-
if (published === null || published.ref !== ref) throw new Error(
|
|
135
|
-
if (query !== void 0 && exceedsCodePointLimit(query, bounds.maxQueryChars)) throw new Error(
|
|
134
|
+
if (published === null || published.ref !== ref) throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: ref is not a valid published TailTrim group`);
|
|
135
|
+
if (query !== void 0 && exceedsCodePointLimit(query, bounds.maxQueryChars)) throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: query must be at most ${String(bounds.maxQueryChars)} Unicode code points`);
|
|
136
136
|
const fixedHeader = [
|
|
137
137
|
`source: ${ref}`,
|
|
138
138
|
"kind: tailtrim-group",
|
|
@@ -158,7 +158,7 @@ function resolvePositiveInteger(name, value, fallback) {
|
|
|
158
158
|
}
|
|
159
159
|
function resolveMaxLines(value) {
|
|
160
160
|
const resolved = value ?? 200;
|
|
161
|
-
if (!Number.isSafeInteger(resolved) || resolved < 1 || resolved > MAX_LINES) throw new Error(
|
|
161
|
+
if (!Number.isSafeInteger(resolved) || resolved < 1 || resolved > MAX_LINES) throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: max_lines must be an integer from 1 to ${String(MAX_LINES)}`);
|
|
162
162
|
return resolved;
|
|
163
163
|
}
|
|
164
164
|
function scanBlocks(blocks, maxChars) {
|
|
@@ -229,7 +229,7 @@ function* jsonTokens(value) {
|
|
|
229
229
|
yield "}";
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
|
-
default: throw new TypeError(
|
|
232
|
+
default: throw new TypeError(`${RUNTIME_TOOL_NAMES.RETRIEVE}: source content is not JSON-serializable`);
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
function jsonScalar(value) {
|
|
@@ -262,8 +262,11 @@ function splitScannedLines(scan) {
|
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
264
|
function directSlice(lines, startLine, maxLines, scanComplete, partialTail) {
|
|
265
|
-
if (!Number.isSafeInteger(startLine) || startLine < 1) throw new Error(
|
|
266
|
-
if (startLine > lines.length)
|
|
265
|
+
if (!Number.isSafeInteger(startLine) || startLine < 1) throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: start_line must be a positive safe integer`);
|
|
266
|
+
if (startLine > lines.length) {
|
|
267
|
+
const reason = scanComplete ? "outside the source line range" : "beyond the source scan limit";
|
|
268
|
+
throw new Error(`${RUNTIME_TOOL_NAMES.RETRIEVE}: start_line ${String(startLine)} is ${reason}`);
|
|
269
|
+
}
|
|
267
270
|
const startIndex = startLine - 1;
|
|
268
271
|
const selected = lines.slice(startIndex, startIndex + maxLines);
|
|
269
272
|
return {
|
|
@@ -499,7 +502,7 @@ function buildLocatorBlock(events, shadowedRange) {
|
|
|
499
502
|
`- seq range: ${String(shadowedRange.start)}-${String(shadowedRange.end)}`,
|
|
500
503
|
...[...spillFiles].map((path) => `- spill file: ${path}`),
|
|
501
504
|
...[...touchedFiles].map((path) => `- file touched: ${path}`),
|
|
502
|
-
|
|
505
|
+
`(Use \`read <spill file>\` or \`${RUNTIME_TOOL_NAMES.RETRIEVE}\` with a \`session://\` source — pass start_line/max_lines to window the text — to restore exact text.)`
|
|
503
506
|
].join("\n"),
|
|
504
507
|
spillFiles: spillFiles.size,
|
|
505
508
|
touchedFiles: touchedFiles.size
|
|
@@ -751,7 +754,7 @@ function historicalPlaceholder(input) {
|
|
|
751
754
|
const lastFolded = normalized.folded.at(-1);
|
|
752
755
|
const elidedLines = lastFolded === void 0 ? void 0 : lastFolded.originalLineEnd ?? lastFolded.originalLine;
|
|
753
756
|
const anchorLine = input.compact ? void 0 : (normalized.folded.find((line) => IMPORTANT_PATTERN.test(line.text)) ?? void 0)?.originalLine;
|
|
754
|
-
const retrieveHint = anchorLine === void 0 ? `retrieve:
|
|
757
|
+
const retrieveHint = anchorLine === void 0 ? `retrieve: ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}"})` : `retrieve: ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}","start_line":${String(anchorLine)},"max_lines":${String(RETRIEVE_HINT_MAX_LINES)}})`;
|
|
755
758
|
const lines = [
|
|
756
759
|
"[Old tool result content cleared from active context]",
|
|
757
760
|
`tool: ${input.toolName || "unknown"}`,
|
|
@@ -991,7 +994,7 @@ function reduceBundledJs(input) {
|
|
|
991
994
|
if (declarations.size === 0) return null;
|
|
992
995
|
const hasSourceMap = input.contentText.includes(SOURCEMAP_DIRECTIVE);
|
|
993
996
|
const entries = [...declarations.entries()].sort((a, b) => a[1] - b[1]);
|
|
994
|
-
const kept = [`[bundled/minified JS detected; ${String(entries.length)} declarations; minified symbols may be renamed — exports.*/module.exports traces are the reliable ones;${hasSourceMap ? " source map present, prefer reading the original source;" : ""} source: ${input.sourceRef}; retrieve with
|
|
997
|
+
const kept = [`[bundled/minified JS detected; ${String(entries.length)} declarations; minified symbols may be renamed — exports.*/module.exports traces are the reliable ones;${hasSourceMap ? " source map present, prefer reading the original source;" : ""} source: ${input.sourceRef}; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}"}) (line-addressed: single-line bundles come back whole)]`, ...entries.slice(0, 400).map(([symbol, line]) => `${symbol} (line ${String(line)})`)];
|
|
995
998
|
const start = input.lines[0]?.originalLine ?? 1;
|
|
996
999
|
const end = originalEnd(input.lines, input.lines.length - 1);
|
|
997
1000
|
if (end > start) kept.push(elidedRangeMarker(start, end));
|
|
@@ -1219,7 +1222,7 @@ function reduceSearch(input, fileRanking) {
|
|
|
1219
1222
|
rows
|
|
1220
1223
|
})), fileRanking)) perFile.set(entry.id, [...entry.rows].sort((a, b) => a.important === b.important ? a.fileLine - b.fileLine : a.important ? -1 : 1));
|
|
1221
1224
|
const allLocators = [...perFile.keys()].map((path) => locatorFor(path, groups.get(path)));
|
|
1222
|
-
const headerFor = (l2Rows, omitted) => `[search results compressed; ${String(groups.size)} files, ${String(totalMatches)} matches; ${String(l2Rows)} content rows shown, ${String(omitted)} matches omitted; source: ${input.sourceRef}; retrieve with
|
|
1225
|
+
const headerFor = (l2Rows, omitted) => `[search results compressed; ${String(groups.size)} files, ${String(totalMatches)} matches; ${String(l2Rows)} content rows shown, ${String(omitted)} matches omitted; source: ${input.sourceRef}; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}"})]`;
|
|
1223
1226
|
const fillL2 = (output, quotaChars) => {
|
|
1224
1227
|
let used = 0;
|
|
1225
1228
|
let shown = 0;
|
|
@@ -1306,7 +1309,7 @@ function reduceGit(input, command) {
|
|
|
1306
1309
|
}
|
|
1307
1310
|
if (keep.length === 0) return reduceSalient(input, reducer);
|
|
1308
1311
|
const text = fitLines([
|
|
1309
|
-
`[git output compressed; ${scannedTotals(input, keep.length)}; source: ${input.sourceRef}; scatter-masked: retrieve with
|
|
1312
|
+
`[git output compressed; ${scannedTotals(input, keep.length)}; source: ${input.sourceRef}; scatter-masked: retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}","query":"<keyword>"}) for missed rows]`,
|
|
1310
1313
|
...keep,
|
|
1311
1314
|
...lines.slice(-8).map((line) => line.text)
|
|
1312
1315
|
], input.budgetChars, input.sourceRef);
|
|
@@ -1320,7 +1323,7 @@ function reducePatternLog(input, reducer, pattern) {
|
|
|
1320
1323
|
const lines = input.lines;
|
|
1321
1324
|
const kept = lines.filter((line) => pattern.test(line.text) || IMPORTANT_PATTERN.test(line.text) || STATUS_PATTERN.test(line.text));
|
|
1322
1325
|
const text = fitLines([
|
|
1323
|
-
`[command output compressed by ${reducer}; ${scannedTotals(input, kept.length)}; source: ${input.sourceRef}; scatter-masked: retrieve with
|
|
1326
|
+
`[command output compressed by ${reducer}; ${scannedTotals(input, kept.length)}; source: ${input.sourceRef}; scatter-masked: retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}","query":"<keyword>"}) for missed rows]`,
|
|
1324
1327
|
...kept.map((line) => line.text),
|
|
1325
1328
|
...lines.slice(-20).map((line) => line.text)
|
|
1326
1329
|
], input.budgetChars, input.sourceRef);
|
|
@@ -1335,7 +1338,7 @@ function reduceShell(input) {
|
|
|
1335
1338
|
const important = lines.filter((line) => IMPORTANT_PATTERN.test(line.text));
|
|
1336
1339
|
if (important.length === 0) return reduceTail(input, "pi-tail");
|
|
1337
1340
|
const text = fitLines([
|
|
1338
|
-
`[shell/log output compressed; ${scannedTotals(input, important.length)}; source: ${input.sourceRef}; scatter-masked: retrieve with
|
|
1341
|
+
`[shell/log output compressed; ${scannedTotals(input, important.length)}; source: ${input.sourceRef}; scatter-masked: retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}","query":"<keyword>"}) for missed rows]`,
|
|
1339
1342
|
...important.map((line) => line.text),
|
|
1340
1343
|
"--- final output ---",
|
|
1341
1344
|
...lines.slice(-40).map((line) => line.text)
|
|
@@ -1524,7 +1527,7 @@ function reduceHtml(input) {
|
|
|
1524
1527
|
if (slim.length === 0) return null;
|
|
1525
1528
|
const buildHeader = (reducer, firstElided) => {
|
|
1526
1529
|
const startLine = firstElided === void 0 ? "" : `,"start_line":${String(firstElided.start)},"max_lines":${String(RETRIEVE_HINT_MAX_LINES)}`;
|
|
1527
|
-
return `[html compressed by ${reducer}; source: ${input.sourceRef}; retrieve with
|
|
1530
|
+
return `[html compressed by ${reducer}; source: ${input.sourceRef}; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}"${startLine}})]`;
|
|
1528
1531
|
};
|
|
1529
1532
|
const foldedSlim = foldRepeatedHtmlBlocks(slim, (index) => input.lines[index]?.originalLine ?? 1);
|
|
1530
1533
|
if (foldedSlim.reduce((sum, line) => sum + codePointLength(line.text) + 1, 0) + 160 <= input.budgetChars) {
|
|
@@ -1679,7 +1682,7 @@ function reduceDocSkeleton(input, sectionRanking) {
|
|
|
1679
1682
|
kept.push(elidedRangeMarker(start, end));
|
|
1680
1683
|
}
|
|
1681
1684
|
const hint = firstElided === void 0 ? "" : `,"start_line":${String(firstElided)},"max_lines":${String(RETRIEVE_HINT_MAX_LINES)}`;
|
|
1682
|
-
kept.unshift(`[document compressed by doc-skeleton; source: ${input.sourceRef}; retrieve with
|
|
1685
|
+
kept.unshift(`[document compressed by doc-skeleton; source: ${input.sourceRef}; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}"${hint}})]`);
|
|
1683
1686
|
return {
|
|
1684
1687
|
text: fitLines(kept, budget, input.sourceRef),
|
|
1685
1688
|
...firstElided === void 0 ? {} : { firstElided },
|
|
@@ -1750,7 +1753,7 @@ function reduceProseKeep(input) {
|
|
|
1750
1753
|
const last = lines[lines.length - 1];
|
|
1751
1754
|
const tailLine = last.originalLineEnd ?? last.originalLine;
|
|
1752
1755
|
const markerTemplate = elidedRangeMarker(first.originalLine, tailLine);
|
|
1753
|
-
const sourceNoteTemplate = `; source: ${input.sourceRef}; retrieve with
|
|
1756
|
+
const sourceNoteTemplate = `; source: ${input.sourceRef}; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}"})`;
|
|
1754
1757
|
const reserved = codePointLength(markerTemplate) + codePointLength(sourceNoteTemplate) + 2;
|
|
1755
1758
|
const bodyBudget = input.budgetChars - reserved;
|
|
1756
1759
|
if (bodyBudget <= 0) return null;
|
|
@@ -1777,7 +1780,7 @@ function reduceProseKeep(input) {
|
|
|
1777
1780
|
const elidedStart = lines[headCount].originalLine;
|
|
1778
1781
|
const elidedEnd = originalEnd(lines, lines.length - tailCount - 1);
|
|
1779
1782
|
if (elidedEnd < elidedStart) return null;
|
|
1780
|
-
const sourceNote = `; source: ${input.sourceRef}; retrieve with
|
|
1783
|
+
const sourceNote = `; source: ${input.sourceRef}; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}","start_line":${String(elidedStart)},"max_lines":${String(RETRIEVE_HINT_MAX_LINES)}})`;
|
|
1781
1784
|
return {
|
|
1782
1785
|
text: [
|
|
1783
1786
|
...lines.slice(0, headCount).map((line) => line.text),
|
|
@@ -1929,7 +1932,7 @@ function reduceCodeSkeleton(input) {
|
|
|
1929
1932
|
return finishSkeleton(kept, lines, input, firstElided, elidedTotal);
|
|
1930
1933
|
}
|
|
1931
1934
|
function finishSkeleton(kept, lines, input, firstElided, elidedLines) {
|
|
1932
|
-
const hint = firstElided === void 0 ? "" : `; retrieve with
|
|
1935
|
+
const hint = firstElided === void 0 ? "" : `; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}","start_line":${String(firstElided.start)},"max_lines":${String(RETRIEVE_HINT_MAX_LINES)}})`;
|
|
1933
1936
|
const text = fitLines([
|
|
1934
1937
|
`[code output compressed by hypa-code-skeleton; source: ${input.sourceRef}${hint}]`,
|
|
1935
1938
|
...kept,
|
|
@@ -1986,7 +1989,7 @@ function looksLikeSourceCode(text) {
|
|
|
1986
1989
|
return false;
|
|
1987
1990
|
}
|
|
1988
1991
|
function omissionMarker(input, reducer) {
|
|
1989
|
-
return `[... ${reducer} omitted content; original_chars=${String(codePointLength(input.text))}; source=${input.sourceRef}; retrieve with
|
|
1992
|
+
return `[... ${reducer} omitted content; original_chars=${String(codePointLength(input.text))}; source=${input.sourceRef}; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE} ...]`;
|
|
1990
1993
|
}
|
|
1991
1994
|
/**
|
|
1992
1995
|
* Continuous-mask marker (R9b): an original-event line range plus a pasteable
|
|
@@ -1994,7 +1997,7 @@ function omissionMarker(input, reducer) {
|
|
|
1994
1997
|
* at the RAW event because retrieve reads raw events (D8).
|
|
1995
1998
|
*/
|
|
1996
1999
|
function rangeOmissionMarker(input, reducer, elidedStart, elidedEnd) {
|
|
1997
|
-
return `[... lines ${String(elidedStart)}-${String(elidedEnd)} elided (${String(elidedEnd - elidedStart + 1)} lines); ${reducer}; original_chars=${String(codePointLength(input.text))}; source=${input.sourceRef}; retrieve with
|
|
2000
|
+
return `[... lines ${String(elidedStart)}-${String(elidedEnd)} elided (${String(elidedEnd - elidedStart + 1)} lines); ${reducer}; original_chars=${String(codePointLength(input.text))}; source=${input.sourceRef}; retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${input.sourceRef}","start_line":${String(elidedStart)},"max_lines":${String(RETRIEVE_HINT_MAX_LINES)}}) ...]`;
|
|
1998
2001
|
}
|
|
1999
2002
|
/** Scatter-mask note (R9b): totals instead of fragmented per-run ranges. */
|
|
2000
2003
|
function scannedTotals(input, kept) {
|
|
@@ -4040,7 +4043,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4040
4043
|
}, settings.profile, settings.custom, {
|
|
4041
4044
|
...contextWindowTokens === void 0 ? {} : { contextWindowTokens },
|
|
4042
4045
|
autoCompactThresholdPercent: settings.autoCompact.thresholdPercent
|
|
4043
|
-
});
|
|
4046
|
+
}, settings.ptcCustom);
|
|
4044
4047
|
const route = routeAuditFact(session);
|
|
4045
4048
|
const auditKey = JSON.stringify({
|
|
4046
4049
|
policy,
|
|
@@ -4287,7 +4290,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4287
4290
|
* recovery tool; the per-session set admits future recovery paths.
|
|
4288
4291
|
*/
|
|
4289
4292
|
isRecoveryExempt(session, candidate) {
|
|
4290
|
-
if (candidate.call.name ===
|
|
4293
|
+
if (candidate.call.name === RUNTIME_TOOL_NAMES.RETRIEVE) return true;
|
|
4291
4294
|
return this.state.recoveryExemptions.get(session)?.has(candidate.seq) ?? false;
|
|
4292
4295
|
}
|
|
4293
4296
|
/** Register a result seq as permanently exempt from further reduction. */
|
|
@@ -4335,7 +4338,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4335
4338
|
const dedupeEnabled = policy.presetOptions?.dedupeToolResults === true;
|
|
4336
4339
|
const maxCandidateTokens = candidates.length === 0 ? void 0 : Math.max(...candidates.map((candidate) => candidate.count.kind === "exact-tokenizer" ? candidate.count.tokens : charsToTokens(candidate.characterPressure)));
|
|
4337
4340
|
if (policy.freshEnabled) {
|
|
4338
|
-
if (candidates.some((candidate) => candidate.call.name !==
|
|
4341
|
+
if (candidates.some((candidate) => candidate.call.name !== RUNTIME_TOOL_NAMES.RETRIEVE && candidate.count.kind !== "exact-tokenizer")) this.warnExactUnavailable(session, view, "fresh");
|
|
4339
4342
|
for (const candidate of candidates) {
|
|
4340
4343
|
if (this.isRecoveryExempt(session, candidate)) continue;
|
|
4341
4344
|
if (dedupeEnabled) {
|
|
@@ -4525,7 +4528,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4525
4528
|
"[Tool result reduced to satisfy the completed-step aggregate budget]",
|
|
4526
4529
|
`tool: ${candidate.call.name}`,
|
|
4527
4530
|
`source: ${sourceRef$2}`,
|
|
4528
|
-
|
|
4531
|
+
`Retrieve a narrow slice via ${RUNTIME_TOOL_NAMES.RETRIEVE} if needed.`
|
|
4529
4532
|
].join("\n");
|
|
4530
4533
|
const plan = this.plan(candidate, [{
|
|
4531
4534
|
type: "text",
|
|
@@ -4747,7 +4750,7 @@ var ToolResultPruner = class extends Service {
|
|
|
4747
4750
|
const assistant = eventBySeq(events, assistantSeq);
|
|
4748
4751
|
if (assistant?.type !== "assistant/message" || assistant.data.interrupted === true || assistant.data.message.content.length === 0 || assistant.data.message.content.some((block) => block.type !== "tool-call") || assistant.data.turn === firstCompletedSurfaceTurn || !completedTurns.has(assistant.data.turn) || !completedSteps.has(`${String(assistant.data.turn)}:${String(assistant.data.step)}`)) continue;
|
|
4749
4752
|
const calls = assistant.data.message.content;
|
|
4750
|
-
if (calls.some((call) => call.name ===
|
|
4753
|
+
if (calls.some((call) => call.name === RUNTIME_TOOL_NAMES.RETRIEVE)) continue;
|
|
4751
4754
|
const callIds = calls.map((call) => String(call.id));
|
|
4752
4755
|
if (new Set(callIds).size !== callIds.length) continue;
|
|
4753
4756
|
const resultSeqs = nodes.slice(index + 1, index + 1 + calls.length);
|
|
@@ -5036,7 +5039,7 @@ var ToolResultPruner = class extends Service {
|
|
|
5036
5039
|
landAll(session, plans) {
|
|
5037
5040
|
if (plans.length === 0) return [];
|
|
5038
5041
|
if (!this.hasRecoveryTool(session)) {
|
|
5039
|
-
this.warnOnce(session, "missing-context-retrieve",
|
|
5042
|
+
this.warnOnce(session, "missing-context-retrieve", `context-compression kept original tool results because ${RUNTIME_TOOL_NAMES.RETRIEVE} is unavailable`);
|
|
5040
5043
|
return [];
|
|
5041
5044
|
}
|
|
5042
5045
|
if (!hasOpenTurn(session)) throw new Error("tool-result pruning cannot append a surface replacement outside any open turn");
|
|
@@ -5052,7 +5055,7 @@ var ToolResultPruner = class extends Service {
|
|
|
5052
5055
|
const tools = this.ctx.get("tools");
|
|
5053
5056
|
if (tools === void 0) return false;
|
|
5054
5057
|
const agent = this.ctx.get("agents")?.get(session.id);
|
|
5055
|
-
return tools.get(
|
|
5058
|
+
return tools.get(RUNTIME_TOOL_NAMES.RETRIEVE, agent) !== void 0;
|
|
5056
5059
|
}
|
|
5057
5060
|
auditHistoryEvaluation(session, policy, view, allowed, outcome) {
|
|
5058
5061
|
if (policy.historyMode === "disabled") {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as viewToolResult, s as
|
|
1
|
+
import { l as sessionEvents, n as viewToolResult, s as RUNTIME_TOOL_NAMES } from "./tool-result.js";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
@@ -1778,6 +1778,7 @@ const COMPRESSION_PROFILES = [
|
|
|
1778
1778
|
"savings",
|
|
1779
1779
|
"adaptive",
|
|
1780
1780
|
"tokenpilot-inspired",
|
|
1781
|
+
"ptc",
|
|
1781
1782
|
"custom"
|
|
1782
1783
|
];
|
|
1783
1784
|
//#endregion
|
|
@@ -1921,6 +1922,38 @@ const DEFAULT_CUSTOM_COMPRESSION_POLICY = deepFreeze({
|
|
|
1921
1922
|
}
|
|
1922
1923
|
});
|
|
1923
1924
|
/**
|
|
1925
|
+
* PTC/code-mode default policy: window-independent absolute watermarks tuned
|
|
1926
|
+
* for many-small-result sessions. `ptc` seeds its own editable `ptcCustom`
|
|
1927
|
+
* document from this value, so editing `ptcCustom` never touches `custom` /
|
|
1928
|
+
* `tokenpilot-inspired`.
|
|
1929
|
+
*/
|
|
1930
|
+
const DEFAULT_PTC_COMPRESSION_POLICY = deepFreeze({
|
|
1931
|
+
version: 3,
|
|
1932
|
+
unit: "tokens",
|
|
1933
|
+
fresh: {
|
|
1934
|
+
enabled: true,
|
|
1935
|
+
trigger: 4096,
|
|
1936
|
+
target: 1536
|
|
1937
|
+
},
|
|
1938
|
+
aggregate: {
|
|
1939
|
+
enabled: true,
|
|
1940
|
+
trigger: 16384,
|
|
1941
|
+
target: 4096
|
|
1942
|
+
},
|
|
1943
|
+
history: {
|
|
1944
|
+
enabled: true,
|
|
1945
|
+
trigger: 2e4,
|
|
1946
|
+
keepRecentToolCalls: 8,
|
|
1947
|
+
keepRecentTokens: 8e3,
|
|
1948
|
+
minReclaim: 6e3
|
|
1949
|
+
},
|
|
1950
|
+
prefixPolicy: "pressure-break",
|
|
1951
|
+
tailTrim: {
|
|
1952
|
+
enabled: false,
|
|
1953
|
+
trigger: 7e5
|
|
1954
|
+
}
|
|
1955
|
+
});
|
|
1956
|
+
/**
|
|
1924
1957
|
* Resolve one validated Custom document to the same token policy used by public presets.
|
|
1925
1958
|
* @param value - untrusted or typed Custom settings value.
|
|
1926
1959
|
* @param options - routed model capacity for context-percent documents.
|
|
@@ -2257,7 +2290,8 @@ function parsePresetOptionsSettings(value) {
|
|
|
2257
2290
|
/** Settings schema used by the user-facing profile selector. */
|
|
2258
2291
|
const contextCompressionSettingsInputSchema = z.object({
|
|
2259
2292
|
profile: z.union([...COMPRESSION_PROFILES]).default("balanced"),
|
|
2260
|
-
custom: CustomCompressionPolicySchema.default(DEFAULT_CUSTOM_COMPRESSION_POLICY)
|
|
2293
|
+
custom: CustomCompressionPolicySchema.default(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
2294
|
+
ptcCustom: CustomCompressionPolicySchema.default(DEFAULT_PTC_COMPRESSION_POLICY)
|
|
2261
2295
|
});
|
|
2262
2296
|
/**
|
|
2263
2297
|
* Reject a section that is PRESENT but not a usable value. Schemastery
|
|
@@ -2275,6 +2309,7 @@ const isUsableCustomDocument = (value) => isPlainRecord(value);
|
|
|
2275
2309
|
const DEFAULT_CONTEXT_COMPRESSION_SETTINGS = {
|
|
2276
2310
|
profile: "balanced",
|
|
2277
2311
|
custom: structuredClone(DEFAULT_CUSTOM_COMPRESSION_POLICY),
|
|
2312
|
+
ptcCustom: structuredClone(DEFAULT_PTC_COMPRESSION_POLICY),
|
|
2278
2313
|
autoCompact: { thresholdPercent: AUTO_COMPACT_THRESHOLD_LIMITS.default },
|
|
2279
2314
|
codeSkeleton: { enabled: false },
|
|
2280
2315
|
intentSummary: { enabled: false },
|
|
@@ -2296,10 +2331,11 @@ const ContextCompressionSettingsSchema = z.transform(z.any().required(), (value)
|
|
|
2296
2331
|
if (!isPlainRecord(value)) throw new TypeError("Context-compression settings must be a plain object");
|
|
2297
2332
|
assertPlainDataTree(value);
|
|
2298
2333
|
const candidate = structuredClone(value);
|
|
2299
|
-
const unknown = Object.keys(candidate).find((key) => key !== "profile" && key !== "custom" && key !== "autoCompact" && key !== "codeSkeleton" && key !== "intentSummary" && key !== "monitorPanel" && key !== "presetOptions");
|
|
2334
|
+
const unknown = Object.keys(candidate).find((key) => key !== "profile" && key !== "custom" && key !== "ptcCustom" && key !== "autoCompact" && key !== "codeSkeleton" && key !== "intentSummary" && key !== "monitorPanel" && key !== "presetOptions");
|
|
2300
2335
|
if (unknown !== void 0) throw new TypeError(`Context-compression settings: unknown key "${unknown}"`);
|
|
2301
2336
|
assertPresentSection(candidate, "profile", isSupportedProfile);
|
|
2302
2337
|
assertPresentSection(candidate, "custom", isUsableCustomDocument);
|
|
2338
|
+
assertPresentSection(candidate, "ptcCustom", isUsableCustomDocument);
|
|
2303
2339
|
const autoCompact = parseAutoCompactSettings(candidate.autoCompact);
|
|
2304
2340
|
const codeSkeleton = parseCodeSkeletonSettings(candidate.codeSkeleton);
|
|
2305
2341
|
const intentSummary = parseIntentSummarySettings(candidate.intentSummary);
|
|
@@ -2546,8 +2582,48 @@ function resolveAutoCompactLinkage(profile, options) {
|
|
|
2546
2582
|
* to resolve context-percent Custom values and standard-profile linkage.
|
|
2547
2583
|
* @returns the effective deterministic compression policy.
|
|
2548
2584
|
*/
|
|
2549
|
-
function resolvePolicy(config, profile, custom = DEFAULT_CUSTOM_COMPRESSION_POLICY, options = {}) {
|
|
2585
|
+
function resolvePolicy(config, profile, custom = DEFAULT_CUSTOM_COMPRESSION_POLICY, options = {}, ptcCustom = DEFAULT_PTC_COMPRESSION_POLICY) {
|
|
2550
2586
|
if (profile === "custom") return resolveCustomPolicy(custom, options);
|
|
2587
|
+
if (profile === "ptc") {
|
|
2588
|
+
const resolved = resolveCustomPolicy(ptcCustom, options);
|
|
2589
|
+
const policy = {
|
|
2590
|
+
...resolved,
|
|
2591
|
+
profile: "ptc",
|
|
2592
|
+
freshTriggerTokens: config.freshTriggerTokens ?? resolved.freshTriggerTokens,
|
|
2593
|
+
freshTargetTokens: config.freshTargetTokens ?? resolved.freshTargetTokens,
|
|
2594
|
+
aggregateTriggerTokens: config.aggregateTriggerTokens ?? resolved.aggregateTriggerTokens,
|
|
2595
|
+
aggregateTargetTokens: config.aggregateTargetTokens ?? resolved.aggregateTargetTokens,
|
|
2596
|
+
historyTriggerTokens: config.historyTriggerTokens ?? resolved.historyTriggerTokens,
|
|
2597
|
+
historyKeepRecentToolCalls: config.historyKeepRecentToolCalls ?? resolved.historyKeepRecentToolCalls,
|
|
2598
|
+
historyKeepRecentTokens: config.historyKeepRecentTokens ?? resolved.historyKeepRecentTokens,
|
|
2599
|
+
historyMinReclaimTokens: config.historyMinReclaimTokens ?? resolved.historyMinReclaimTokens,
|
|
2600
|
+
...config.readInputCapChars === void 0 ? {} : { readInputCapChars: config.readInputCapChars }
|
|
2601
|
+
};
|
|
2602
|
+
if (policy.freshTargetTokens >= policy.freshTriggerTokens && policy.freshEnabled) throw new Error("context compression policy: fresh target must be below trigger");
|
|
2603
|
+
if (policy.aggregateTargetTokens >= policy.aggregateTriggerTokens && policy.aggregateEnabled) throw new Error("context compression policy: aggregate target must be below trigger");
|
|
2604
|
+
if (policy.readInputCapChars !== void 0 && policy.readInputCapChars <= policy.freshTriggerTokens * 4) throw new Error("context compression policy: read input cap would silence the fresh path");
|
|
2605
|
+
return deepFreeze(policy);
|
|
2606
|
+
}
|
|
2607
|
+
if (profile === "tokenpilot-inspired") {
|
|
2608
|
+
const resolved = resolveCustomPolicy(custom, options);
|
|
2609
|
+
const policy = {
|
|
2610
|
+
...resolved,
|
|
2611
|
+
profile: "tokenpilot-inspired",
|
|
2612
|
+
freshTriggerTokens: config.freshTriggerTokens ?? resolved.freshTriggerTokens,
|
|
2613
|
+
freshTargetTokens: config.freshTargetTokens ?? resolved.freshTargetTokens,
|
|
2614
|
+
aggregateTriggerTokens: config.aggregateTriggerTokens ?? resolved.aggregateTriggerTokens,
|
|
2615
|
+
aggregateTargetTokens: config.aggregateTargetTokens ?? resolved.aggregateTargetTokens,
|
|
2616
|
+
historyTriggerTokens: config.historyTriggerTokens ?? resolved.historyTriggerTokens,
|
|
2617
|
+
historyKeepRecentToolCalls: config.historyKeepRecentToolCalls ?? resolved.historyKeepRecentToolCalls,
|
|
2618
|
+
historyKeepRecentTokens: config.historyKeepRecentTokens ?? resolved.historyKeepRecentTokens,
|
|
2619
|
+
historyMinReclaimTokens: config.historyMinReclaimTokens ?? resolved.historyMinReclaimTokens,
|
|
2620
|
+
...config.readInputCapChars === void 0 ? {} : { readInputCapChars: config.readInputCapChars },
|
|
2621
|
+
presetOptions: mergePresetOptions(config.presetOptions)
|
|
2622
|
+
};
|
|
2623
|
+
if (policy.freshTargetTokens >= policy.freshTriggerTokens && policy.freshEnabled) throw new Error("context compression policy: fresh target must be below trigger");
|
|
2624
|
+
if (policy.aggregateTargetTokens >= policy.aggregateTriggerTokens && policy.aggregateEnabled) throw new Error("context compression policy: aggregate target must be below trigger");
|
|
2625
|
+
return deepFreeze(policy);
|
|
2626
|
+
}
|
|
2551
2627
|
const preset = {
|
|
2552
2628
|
off: {
|
|
2553
2629
|
nativeToolResultEnabled: false,
|
|
@@ -2644,22 +2720,6 @@ function resolvePolicy(config, profile, custom = DEFAULT_CUSTOM_COMPRESSION_POLI
|
|
|
2644
2720
|
historyKeepRecentToolCalls: 10,
|
|
2645
2721
|
historyKeepRecentTokens: 64e3,
|
|
2646
2722
|
historyMinReclaimTokens: 96e3
|
|
2647
|
-
},
|
|
2648
|
-
"tokenpilot-inspired": {
|
|
2649
|
-
nativeToolResultEnabled: false,
|
|
2650
|
-
freshEnabled: true,
|
|
2651
|
-
aggregateEnabled: true,
|
|
2652
|
-
historyMode: "routine",
|
|
2653
|
-
nativeTriggerTokens: Number.MAX_SAFE_INTEGER,
|
|
2654
|
-
nativeTargetTokens: Number.MAX_SAFE_INTEGER,
|
|
2655
|
-
freshTriggerTokens: 4096,
|
|
2656
|
-
freshTargetTokens: 1536,
|
|
2657
|
-
aggregateTriggerTokens: 32768,
|
|
2658
|
-
aggregateTargetTokens: 12288,
|
|
2659
|
-
historyTriggerTokens: 5e5,
|
|
2660
|
-
historyKeepRecentToolCalls: 10,
|
|
2661
|
-
historyKeepRecentTokens: 64e3,
|
|
2662
|
-
historyMinReclaimTokens: 96e3
|
|
2663
2723
|
}
|
|
2664
2724
|
}[profile];
|
|
2665
2725
|
const linkage = resolveAutoCompactLinkage(profile, options);
|
|
@@ -2680,8 +2740,7 @@ function resolvePolicy(config, profile, custom = DEFAULT_CUSTOM_COMPRESSION_POLI
|
|
|
2680
2740
|
...linkage === void 0 ? {} : {
|
|
2681
2741
|
autoCompactTokens: linkage.autoCompactTokens,
|
|
2682
2742
|
microDeadlineTokens: linkage.microDeadlineTokens
|
|
2683
|
-
}
|
|
2684
|
-
...profile === "tokenpilot-inspired" ? { presetOptions: mergePresetOptions(config.presetOptions) } : {}
|
|
2743
|
+
}
|
|
2685
2744
|
};
|
|
2686
2745
|
if (policy.nativeTargetTokens >= policy.nativeTriggerTokens && profile === "native") throw new Error("context compression policy: native target must be below trigger");
|
|
2687
2746
|
if (policy.freshTargetTokens >= policy.freshTriggerTokens && policy.freshEnabled) throw new Error("context compression policy: fresh target must be below trigger");
|
|
@@ -2729,7 +2788,7 @@ function unavailableCount(reason) {
|
|
|
2729
2788
|
});
|
|
2730
2789
|
}
|
|
2731
2790
|
function recoveryMarker(sourceRef, label, startLine) {
|
|
2732
|
-
return `\n\n[... ${label}; source=${sourceRef}; ${startLine === void 0 ?
|
|
2791
|
+
return `\n\n[... ${label}; source=${sourceRef}; ${startLine === void 0 ? `use ${RUNTIME_TOOL_NAMES.RETRIEVE} with a query or narrow start_line/max_lines if needed (avoid re-reading the whole result)` : `retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${sourceRef}","start_line":${String(startLine)},"max_lines":80})`} ...]\n\n`;
|
|
2733
2792
|
}
|
|
2734
2793
|
/**
|
|
2735
2794
|
* Measure text content in Unicode code points; non-text blocks cost zero.
|
|
@@ -3131,7 +3190,7 @@ function dedupePlaceholder(entry, originalChars) {
|
|
|
3131
3190
|
return [
|
|
3132
3191
|
`[... identical to the earlier ${entry.toolName} result; first seen at ${entry.sourceRef};`,
|
|
3133
3192
|
`original_chars=${String(originalChars)};`,
|
|
3134
|
-
|
|
3193
|
+
`retrieve with ${RUNTIME_TOOL_NAMES.RETRIEVE}({"ref":"${entry.sourceRef}","start_line":1}) if the omitted evidence is necessary.]`
|
|
3135
3194
|
].join(" ");
|
|
3136
3195
|
}
|
|
3137
3196
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as viewToolResult, s as
|
|
1
|
+
import { l as sessionEvents, n as viewToolResult, s as RUNTIME_TOOL_NAMES, t as compressionMessageSource } from "./tool-result.js";
|
|
2
2
|
//#region src/compat/llm-messages.ts
|
|
3
3
|
/** Recursive `Object.freeze` over own enumerable properties (arrays included). */
|
|
4
4
|
function deepFreeze(value) {
|
|
@@ -50,7 +50,7 @@ function tailTrimStub(ref, toolNames, sourceEventSeqs) {
|
|
|
50
50
|
`ref: ${ref}`,
|
|
51
51
|
`tools: ${toolNames.join(", ")}`,
|
|
52
52
|
`source_event_seqs: ${sourceEventSeqs.join(", ")}`,
|
|
53
|
-
|
|
53
|
+
`use ${RUNTIME_TOOL_NAMES.RETRIEVE} with this TailTrim ref if needed`
|
|
54
54
|
].join("\n");
|
|
55
55
|
return Array.from(stub).length <= MAX_STUB_CODE_POINTS ? stub : null;
|
|
56
56
|
}
|
|
@@ -20,6 +20,27 @@ function eventBySeq(events, seq) {
|
|
|
20
20
|
return events[Number(seq)];
|
|
21
21
|
}
|
|
22
22
|
//#endregion
|
|
23
|
+
//#region src/runtime/tool-names.ts
|
|
24
|
+
/**
|
|
25
|
+
* Runtime tool names owned by this plugin, plus the code-mode calling-convention
|
|
26
|
+
* note. Every place that REGISTERS a tool and every place that JUDGES reachability
|
|
27
|
+
* or exemption must read the SAME constant. billion-context learned this the hard
|
|
28
|
+
* way (#3600 / #3884): a hard-coded omnibus / tool literal silently stopped
|
|
29
|
+
* matching after the host renamed its transport, which suppressed the whole
|
|
30
|
+
* compression surface without any error. Keeping one source prevents that class
|
|
31
|
+
* of silent split here.
|
|
32
|
+
*/
|
|
33
|
+
const RUNTIME_TOOL_NAMES = Object.freeze({ RETRIEVE: "context_compression_retrieve" });
|
|
34
|
+
/**
|
|
35
|
+
* Calling-convention note appended to the retrieval tool description. In a
|
|
36
|
+
* standard (direct tool-call) preset the model calls the tool directly; when the
|
|
37
|
+
* harness folds tool use into an omnibus program (run_code / code_run) the same
|
|
38
|
+
* tool is reached through the program's SDK. Naming both keeps one static
|
|
39
|
+
* description correct on every preset, since CCI registers a single tool and
|
|
40
|
+
* cannot branch its description per preset.
|
|
41
|
+
*/
|
|
42
|
+
const PTC_BINDING_NOTE = `Call it directly as a tool when the environment allows direct tool calls; if this environment routes all tool use through a program (${Object.freeze(["run_code", "code_run"]).join(" / ")}), call it from inside that program via the tool SDK instead of emitting a standalone call.`;
|
|
43
|
+
//#endregion
|
|
23
44
|
//#region src/compat/host-generation.ts
|
|
24
45
|
let cached;
|
|
25
46
|
/**
|
|
@@ -147,4 +168,4 @@ function compressionMessageSource(generation) {
|
|
|
147
168
|
return { kind: "dsh-context-compression" };
|
|
148
169
|
}
|
|
149
170
|
//#endregion
|
|
150
|
-
export { noteResolvedSettingsService as a, detectHostGeneration as i, viewToolResult as n,
|
|
171
|
+
export { noteResolvedSettingsService as a, eventBySeq as c, detectHostGeneration as i, sessionEvents as l, viewToolResult as n, PTC_BINDING_NOTE as o, compatLog as r, RUNTIME_TOOL_NAMES as s, compressionMessageSource as t };
|