dsh-context-compression-improved 0.11.0 → 0.11.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/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}/index.js +101 -0
- 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 -47
- 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 -557
- package/CHANGELOG.ru.md +0 -554
- package/CHANGELOG.zh.md +0 -247
- 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/docs/shallow-teaching-preset-template.md +0 -46
- 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 -352
- package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
- package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -89
- 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 -68
- package/packages/selector/src/client/fab-pos.ts +0 -71
- package/packages/selector/src/client/index.ts +0 -438
- package/packages/selector/src/client/locales/de.ts +0 -167
- package/packages/selector/src/client/locales/es.ts +0 -167
- package/packages/selector/src/client/locales/fr.ts +0 -167
- package/packages/selector/src/client/locales/it.ts +0 -167
- package/packages/selector/src/client/locales/ja.ts +0 -167
- package/packages/selector/src/client/locales/ko.ts +0 -167
- package/packages/selector/src/client/locales/ru.ts +0 -167
- package/packages/selector/src/client/locales.ts +0 -334
- package/packages/selector/src/client/monitor-fab.ts +0 -445
- 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 -156
- 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 -554
- package/packages/selector/src/pruner/content.ts +0 -199
- 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 -3222
- package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
- package/packages/selector/src/runtime/audit.ts +0 -321
- package/packages/selector/src/runtime/config.ts +0 -887
- package/packages/selector/src/runtime/custom-policy.ts +0 -300
- 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/fold-router.ts +0 -143
- package/packages/selector/src/runtime/measurement.ts +0 -444
- package/packages/selector/src/runtime/monitor.ts +0 -341
- package/packages/selector/src/runtime/panel-command.ts +0 -213
- package/packages/selector/src/runtime/reducers.ts +0 -1755
- package/packages/selector/src/runtime/retrieve.ts +0 -505
- 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/sediment-card.ts +0 -126
- package/packages/selector/src/runtime/sediment-clock.ts +0 -87
- package/packages/selector/src/runtime/sediment-guard.ts +0 -136
- package/packages/selector/src/runtime/sediment-publish.ts +0 -144
- package/packages/selector/src/runtime/sediment-span.ts +0 -170
- package/packages/selector/src/runtime/sediment.ts +0 -209
- 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/shallow-tools.ts +0 -342
- 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 -177
- 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 -82
- 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 -129
- 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/tool-names.ts +0 -42
- package/packages/selector/src/runtime/toolclass.ts +0 -103
- package/packages/selector/src/runtime/triage/masks.ts +0 -128
- package/packages/selector/src/runtime/triage/shallow.ts +0 -132
- package/packages/selector/src/runtime/triage/signals.ts +0 -167
- package/packages/selector/src/runtime/triage/types.ts +0 -125
- package/packages/selector/src/runtime/types.ts +0 -396
- 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/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +0 -231
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +0 -236
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +0 -220
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +0 -140
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +0 -117
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +0 -67
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +0 -119
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +0 -119
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +0 -131
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +0 -196
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +0 -71
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +0 -126
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +0 -86
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +0 -50
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +0 -102
- 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/ptc-custom-write.client.spec.ts +0 -86
- package/packages/selector/tests/public/package-contract.client.spec.ts +0 -89
- 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/fold-router.spec.ts +0 -140
- 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/ptc-profile.spec.ts +0 -133
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2795
- 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/sediment-card.spec.ts +0 -111
- package/packages/selector/tests/runtime/sediment-config.spec.ts +0 -56
- package/packages/selector/tests/runtime/sediment-guard.spec.ts +0 -71
- package/packages/selector/tests/runtime/sediment-masks.spec.ts +0 -95
- package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +0 -166
- package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +0 -65
- package/packages/selector/tests/runtime/sediment-publish.spec.ts +0 -142
- package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +0 -158
- package/packages/selector/tests/runtime/sediment-settings.spec.ts +0 -73
- package/packages/selector/tests/runtime/sediment-signals.spec.ts +0 -124
- package/packages/selector/tests/runtime/sediment-span.spec.ts +0 -92
- 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/shallow-primitives.spec.ts +0 -135
- 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 -350
- 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 -121
- 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.d.mts +0 -3
- package/scripts/hosts.mjs +0 -79
- package/scripts/packed-components-smoke.mjs +0 -763
- package/scripts/packed-install-e2e.mjs +0 -1346
- package/scripts/sediment-latency-report.mjs +0 -63
- package/scripts/sync-hosts.mjs +0 -174
- package/scripts/toolclass-corpus-replay.mjs +0 -281
- package/scripts/verify-release.mjs +0 -343
- 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}/client.d.ts +0 -0
- /package/{packages/selector/lib → lib}/client.js +0 -0
- /package/{packages/selector/lib → lib}/index.d.ts +0 -0
- /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
- /package/{packages/selector/lib → lib}/invariant.js +0 -0
- /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
- /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
- /package/{packages/selector/lib → lib}/pruner.js +0 -0
- /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
- /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
- /package/{packages/selector/lib → lib}/tool-result.js +0 -0
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prompt construction and answer parsing for the advisory relevance advisor.
|
|
3
|
-
*
|
|
4
|
-
* Same conventions as the estimator prompts: temperature-0 small-model calls,
|
|
5
|
-
* JSON-only output instructions, and fail-open parsers that return
|
|
6
|
-
* `undefined` (never throw) on any malformed answer so the advisor stays
|
|
7
|
-
* observational even against a hostile or broken channel.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/** One summary answer: overall task, active subtasks, prescreen keywords. */
|
|
11
|
-
export interface AdvisorSummaryAnswer {
|
|
12
|
-
readonly overallTask: string
|
|
13
|
-
readonly activeSubtasks: readonly string[]
|
|
14
|
-
readonly keywords: readonly string[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** One scoring answer row. */
|
|
18
|
-
export interface AdvisorScoreAnswer {
|
|
19
|
-
readonly seq: number
|
|
20
|
-
/** Relevance in [0, 1]; out-of-range rows are dropped. */
|
|
21
|
-
readonly score: number
|
|
22
|
-
/** Short reason; kept out of audits, used only for diagnosis in tests. */
|
|
23
|
-
readonly reason?: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function buildAdvisorSummarySystemPrompt(): string {
|
|
27
|
-
return [
|
|
28
|
-
'You summarize what an agent session is working on, for relevance statistics only.',
|
|
29
|
-
'Input: the session todolist snapshot and a recent tail of assistant narration.',
|
|
30
|
-
'Answer with ONLY one JSON object:',
|
|
31
|
-
'{"overallTask":"<one sentence>","activeSubtasks":["<subtask>"],"keywords":["<task keyword>"]}.',
|
|
32
|
-
'keywords must be 3-10 short distinctive words describing the CURRENT task.',
|
|
33
|
-
'Never add commentary; never invent tasks that the input does not support.',
|
|
34
|
-
].join(' ')
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function buildAdvisorSummaryUserPrompt(taskText: string, tailText: string): string {
|
|
38
|
-
const lines = [
|
|
39
|
-
`todolist:\n${taskText}`,
|
|
40
|
-
tailText.trim().length > 0 ? `recent tail:\n${tailText.trim()}` : 'recent tail: (none)',
|
|
41
|
-
]
|
|
42
|
-
return lines.join('\n\n')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function buildAdvisorScoringSystemPrompt(): string {
|
|
46
|
-
return [
|
|
47
|
-
'You score how relevant each historical session artifact is to the current task,',
|
|
48
|
-
'for statistics only. Relevance covers both the artifact content and its comments',
|
|
49
|
-
'(comment semantics count too). 0 means unrelated, 1 means the live agent will',
|
|
50
|
-
'very likely need this exact content again.',
|
|
51
|
-
'Answer with ONLY one JSON object per input line:',
|
|
52
|
-
'{"seq":<number>,"score":<number between 0 and 1>,"reason":"<short>"}',
|
|
53
|
-
'one per line, same order as the input. Never invent seq values; never add commentary.',
|
|
54
|
-
].join(' ')
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function buildAdvisorScoringUserPrompt(
|
|
58
|
-
taskText: string,
|
|
59
|
-
activeSubtasks: readonly string[],
|
|
60
|
-
candidates: readonly { readonly seq: number, readonly preview: string }[],
|
|
61
|
-
): string {
|
|
62
|
-
const lines = [
|
|
63
|
-
`task: ${taskText.replace(/\s+/gu, ' ').slice(0, 600)}`,
|
|
64
|
-
activeSubtasks.length > 0 ? `active subtasks: ${activeSubtasks.join('; ').slice(0, 300)}` : 'active subtasks: (none)',
|
|
65
|
-
'',
|
|
66
|
-
...candidates.map(candidate => `seq=${String(candidate.seq)} | ${candidate.preview.replace(/\s+/gu, ' ')}`),
|
|
67
|
-
]
|
|
68
|
-
return lines.join('\n')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Pull the first balanced JSON object out of a possibly chatty answer. */
|
|
72
|
-
export function firstJsonObject(text: string): Record<string, unknown> | undefined {
|
|
73
|
-
const start = text.indexOf('{')
|
|
74
|
-
if (start < 0) return undefined
|
|
75
|
-
let depth = 0
|
|
76
|
-
let inString = false
|
|
77
|
-
let escaped = false
|
|
78
|
-
for (let index = start; index < text.length; index += 1) {
|
|
79
|
-
const char = text[index]
|
|
80
|
-
if (inString) {
|
|
81
|
-
if (escaped) escaped = false
|
|
82
|
-
else if (char === '\\') escaped = true
|
|
83
|
-
else if (char === '"') inString = false
|
|
84
|
-
continue
|
|
85
|
-
}
|
|
86
|
-
if (char === '"') inString = true
|
|
87
|
-
else if (char === '{') depth += 1
|
|
88
|
-
else if (char === '}') {
|
|
89
|
-
depth -= 1
|
|
90
|
-
if (depth === 0) {
|
|
91
|
-
try {
|
|
92
|
-
const parsed: unknown = JSON.parse(text.slice(start, index + 1))
|
|
93
|
-
return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
94
|
-
? parsed as Record<string, unknown>
|
|
95
|
-
: undefined
|
|
96
|
-
} catch {
|
|
97
|
-
return undefined
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return undefined
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function stringList(value: unknown, limit: number): string[] {
|
|
106
|
-
if (!Array.isArray(value)) return []
|
|
107
|
-
return value
|
|
108
|
-
.filter((entry): entry is string => typeof entry === 'string' && entry.trim().length > 0)
|
|
109
|
-
.slice(0, limit)
|
|
110
|
-
.map(entry => entry.trim())
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Parse one summary answer. Fail-open: `undefined` on any malformed or
|
|
115
|
-
* missing field, so a broken channel can never poison the cached summary.
|
|
116
|
-
*/
|
|
117
|
-
export function parseAdvisorSummary(text: string | undefined): AdvisorSummaryAnswer | undefined {
|
|
118
|
-
if (text === undefined || text.trim().length === 0) return undefined
|
|
119
|
-
const object = firstJsonObject(text)
|
|
120
|
-
if (object === undefined) return undefined
|
|
121
|
-
const overallTask = object.overallTask
|
|
122
|
-
if (typeof overallTask !== 'string' || overallTask.trim().length === 0) return undefined
|
|
123
|
-
const activeSubtasks = stringList(object.activeSubtasks, 12)
|
|
124
|
-
const keywords = stringList(object.keywords, 12)
|
|
125
|
-
if (keywords.length === 0 && activeSubtasks.length === 0) return undefined
|
|
126
|
-
return { overallTask: overallTask.trim(), activeSubtasks, keywords }
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** Extract every balanced JSON object from a JSON-lines or chatty answer. */
|
|
130
|
-
function jsonObjects(text: string): Record<string, unknown>[] {
|
|
131
|
-
const objects: Record<string, unknown>[] = []
|
|
132
|
-
let depth = 0
|
|
133
|
-
let start = -1
|
|
134
|
-
let inString = false
|
|
135
|
-
let escaped = false
|
|
136
|
-
for (let index = 0; index < text.length; index += 1) {
|
|
137
|
-
const char = text[index]
|
|
138
|
-
if (inString) {
|
|
139
|
-
if (escaped) escaped = false
|
|
140
|
-
else if (char === '\\') escaped = true
|
|
141
|
-
else if (char === '"') inString = false
|
|
142
|
-
continue
|
|
143
|
-
}
|
|
144
|
-
if (char === '"') inString = true
|
|
145
|
-
else if (char === '{') {
|
|
146
|
-
if (depth === 0) start = index
|
|
147
|
-
depth += 1
|
|
148
|
-
} else if (char === '}') {
|
|
149
|
-
depth -= 1
|
|
150
|
-
if (depth === 0 && start >= 0) {
|
|
151
|
-
try {
|
|
152
|
-
const parsed: unknown = JSON.parse(text.slice(start, index + 1))
|
|
153
|
-
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
154
|
-
objects.push(parsed as Record<string, unknown>)
|
|
155
|
-
}
|
|
156
|
-
} catch {
|
|
157
|
-
// Skip one malformed object; the rest of the answer can still parse.
|
|
158
|
-
}
|
|
159
|
-
start = -1
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return objects
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Parse one scoring answer. Fail-open: returns the valid rows it could read
|
|
168
|
-
* (`undefined` when nothing valid remains) — a partially garbage answer still
|
|
169
|
-
* contributes its good rows, mirroring the estimator's per-item tolerance.
|
|
170
|
-
*/
|
|
171
|
-
export function parseAdvisorScores(
|
|
172
|
-
text: string | undefined,
|
|
173
|
-
validSeqs: ReadonlySet<number>,
|
|
174
|
-
): Map<number, AdvisorScoreAnswer> | undefined {
|
|
175
|
-
if (text === undefined || text.trim().length === 0) return undefined
|
|
176
|
-
const scores = new Map<number, AdvisorScoreAnswer>()
|
|
177
|
-
for (const object of jsonObjects(text)) {
|
|
178
|
-
const seq = object.seq
|
|
179
|
-
const score = object.score
|
|
180
|
-
if (typeof seq !== 'number' || !Number.isSafeInteger(seq) || !validSeqs.has(seq)) continue
|
|
181
|
-
if (typeof score !== 'number' || !Number.isFinite(score) || score < 0 || score > 1) continue
|
|
182
|
-
const reason = typeof object.reason === 'string' && object.reason.trim().length > 0
|
|
183
|
-
? object.reason.trim()
|
|
184
|
-
: undefined
|
|
185
|
-
scores.set(seq, { seq, score, ...(reason !== undefined ? { reason } : {}) })
|
|
186
|
-
}
|
|
187
|
-
return scores.size > 0 ? scores : undefined
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Hard character cap for one intent-summary answer (summary segment only). */
|
|
191
|
-
export const INTENT_SUMMARY_CHAR_CAP = 1_600
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Intent-summary writer prompts (task_2.3). Input records are already
|
|
195
|
-
* semantic-role-masked by intent-input-mask.ts: read-class candidates are
|
|
196
|
-
* one-line "read X" records, keep-class candidates carry skeleton heads and
|
|
197
|
-
* VERBATIM error lines. The model writes ONLY the summary segment — it never
|
|
198
|
-
* revoices error lines, and its answer must stay inside the char cap.
|
|
199
|
-
*/
|
|
200
|
-
export function buildIntentSummarySystemPrompt(): string {
|
|
201
|
-
return [
|
|
202
|
-
'You write one concise intent summary of folded tool results for a coding agent session.',
|
|
203
|
-
'Input: the session task (todolist) and per-tool slimmed records (read lines, or skeleton heads with verbatim error lines).',
|
|
204
|
-
`Write ONLY what the agent DID and LEARNED in this span, as flowing prose under ${INTENT_SUMMARY_CHAR_CAP} characters.`,
|
|
205
|
-
'Mention which files/areas were consulted and what changed, so a later turn can continue without the originals.',
|
|
206
|
-
'Never invent files, commands, or outcomes absent from the records. Never revoice error lines; they are preserved verbatim elsewhere.',
|
|
207
|
-
'Answer with ONLY one JSON object: {"summary":"<prose>"}. Never add commentary.',
|
|
208
|
-
].join(' ')
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function buildIntentSummaryUserPrompt(
|
|
212
|
-
taskText: string,
|
|
213
|
-
records: readonly string[],
|
|
214
|
-
tailText: string,
|
|
215
|
-
): string {
|
|
216
|
-
const nl = String.fromCharCode(10)
|
|
217
|
-
const lines = [
|
|
218
|
-
`task: ${taskText.replace(/\s+/gu, ' ').slice(0, 600)}`,
|
|
219
|
-
records.length > 0 ? `records:${nl}${records.join(nl)}` : 'records: (none)',
|
|
220
|
-
tailText.trim().length > 0 ? `recent tail:${nl}${tailText.trim().slice(0, 1_200)}` : 'recent tail: (none)',
|
|
221
|
-
]
|
|
222
|
-
return lines.join(nl + nl)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/** Fail-open parse of one intent-summary answer; `undefined` on any malformed shape. */
|
|
226
|
-
export function parseIntentSummaryAnswer(text: string): { readonly summary: string } | undefined {
|
|
227
|
-
const parsed = firstJsonObject(text)
|
|
228
|
-
if (parsed === undefined) return undefined
|
|
229
|
-
const summary = parsed.summary
|
|
230
|
-
if (typeof summary !== 'string' || summary.trim().length === 0) return undefined
|
|
231
|
-
if (summary.length > INTENT_SUMMARY_CHAR_CAP * 2) return undefined
|
|
232
|
-
return { summary: summary.trim().slice(0, INTENT_SUMMARY_CHAR_CAP) }
|
|
233
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Per-session state for the advisory relevance advisor.
|
|
3
|
-
*
|
|
4
|
-
* The advisor is statistics and suggestions only — its outputs (summaries,
|
|
5
|
-
* scores, decay, recertification marks) are observational and must never
|
|
6
|
-
* suppress, delay, or rewrite any reduction that would land. All state lives
|
|
7
|
-
* in WeakMaps keyed by the Session object so it is collected with the session
|
|
8
|
-
* and never leaks across sessions; every collection inside the state is
|
|
9
|
-
* bounded.
|
|
10
|
-
*
|
|
11
|
-
* Module-level `getAdvisorState` mirrors the PrunerState consolidation pattern
|
|
12
|
-
* (GC semantics identical) so `pruner.ts` reaches advisor state through a
|
|
13
|
-
* plain import rather than constructor injection.
|
|
14
|
-
*/
|
|
15
|
-
import type { Session } from '@deepseek-ai/dsh-session'
|
|
16
|
-
import type { AdviceBand } from './benefit.ts'
|
|
17
|
-
|
|
18
|
-
/** The most recent benefit-model label of a landed batch. Observational only:
|
|
19
|
-
* no decision path reads it — the report route serves it verbatim. */
|
|
20
|
-
export interface AdvisorAdviceSnapshot {
|
|
21
|
-
readonly band: AdviceBand
|
|
22
|
-
/** Turn index the advised batch landed at. */
|
|
23
|
-
readonly turn: number
|
|
24
|
-
readonly itemSeqs: readonly number[]
|
|
25
|
-
readonly recoveredTokens: number
|
|
26
|
-
readonly penaltyTokens: number
|
|
27
|
-
readonly paybackTurns?: number
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** One relevance score for one surface seq, with the turn it was scored at. */
|
|
31
|
-
export interface AdvisorScoreEntry {
|
|
32
|
-
readonly score: number
|
|
33
|
-
/** Turn index the score was produced at. */
|
|
34
|
-
readonly turn: number
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** LLM-summarized tail-task semantics bound to the session todolist. */
|
|
38
|
-
export interface AdvisorSummary {
|
|
39
|
-
/** The session's overall task, one sentence. */
|
|
40
|
-
readonly overallTask: string
|
|
41
|
-
/** Subtasks currently being pushed forward. */
|
|
42
|
-
readonly activeSubtasks: readonly string[]
|
|
43
|
-
/** Short task keywords used by the local relevance prescreen. */
|
|
44
|
-
readonly keywords: readonly string[]
|
|
45
|
-
/** Task-semantics version the summary was derived from. */
|
|
46
|
-
readonly todoVersion: string
|
|
47
|
-
/** Turn index the summary was produced at. */
|
|
48
|
-
readonly turn: number
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Per-session estimator-style failure bookkeeping for exponential backoff. */
|
|
52
|
-
export interface AdvisorFailures {
|
|
53
|
-
failures: number
|
|
54
|
-
cooldownUntil: number
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Bounded per-session advisor state bag. */
|
|
58
|
-
export interface AdvisorState {
|
|
59
|
-
/** Version of the task semantics the cached summary and scores were built against. */
|
|
60
|
-
todoVersion: string | undefined
|
|
61
|
-
summary: AdvisorSummary | undefined
|
|
62
|
-
/** Turn index the last summary pass ran at. */
|
|
63
|
-
lastSummaryTurn: number
|
|
64
|
-
/** Highest candidate seq the scoring pass has examined (incremental watermark). */
|
|
65
|
-
watermarkSeq: number
|
|
66
|
-
/** LRU-bounded seq → score map (most recent touch wins, oldest evicted). */
|
|
67
|
-
readonly scores: Map<number, AdvisorScoreEntry>
|
|
68
|
-
/** Bounded seq → turn marks for old low-relevance segments (suggestions only). */
|
|
69
|
-
readonly recertified: Map<number, number>
|
|
70
|
-
failures: AdvisorFailures | undefined
|
|
71
|
-
/** Re-entry guard: summary + scoring are two LLM calls, so the overlap window is wide. */
|
|
72
|
-
inFlight: boolean
|
|
73
|
-
/** Most recent decay computation, shared verbatim by audits and the report route. */
|
|
74
|
-
lastDecay: { readonly decay: number, readonly weightedChars: number, readonly turn: number } | undefined
|
|
75
|
-
/** Most recent benefit-model advice; replaced by every advised batch. */
|
|
76
|
-
lastAdvice: AdvisorAdviceSnapshot | undefined
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Upper bound of the per-session scores LRU. */
|
|
80
|
-
export const ADVISOR_SCORES_LIMIT = 64
|
|
81
|
-
/** Upper bound of the per-session recertification marks. */
|
|
82
|
-
export const ADVISOR_RECERTIFIED_LIMIT = 64
|
|
83
|
-
|
|
84
|
-
const advisorStates = new WeakMap<Session, AdvisorState>()
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* The per-session advisor state, created on first touch.
|
|
88
|
-
* @param session - the session to key the state on (by object identity).
|
|
89
|
-
*/
|
|
90
|
-
export function getAdvisorState(session: Session): AdvisorState {
|
|
91
|
-
let state = advisorStates.get(session)
|
|
92
|
-
if (state === undefined) {
|
|
93
|
-
state = {
|
|
94
|
-
todoVersion: undefined,
|
|
95
|
-
summary: undefined,
|
|
96
|
-
lastSummaryTurn: -1,
|
|
97
|
-
watermarkSeq: 0,
|
|
98
|
-
scores: new Map(),
|
|
99
|
-
recertified: new Map(),
|
|
100
|
-
failures: undefined,
|
|
101
|
-
inFlight: false,
|
|
102
|
-
lastDecay: undefined,
|
|
103
|
-
lastAdvice: undefined,
|
|
104
|
-
}
|
|
105
|
-
advisorStates.set(session, state)
|
|
106
|
-
}
|
|
107
|
-
return state
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Insert or refresh one score with LRU semantics: a re-touched seq moves to
|
|
112
|
-
* the newest position, and the oldest entry is evicted once the map exceeds
|
|
113
|
-
* {@link ADVISOR_SCORES_LIMIT}.
|
|
114
|
-
*/
|
|
115
|
-
export function recordScore(state: AdvisorState, seq: number, entry: AdvisorScoreEntry): void {
|
|
116
|
-
state.scores.delete(seq)
|
|
117
|
-
state.scores.set(seq, entry)
|
|
118
|
-
if (state.scores.size > ADVISOR_SCORES_LIMIT) {
|
|
119
|
-
const oldest = state.scores.keys().next()
|
|
120
|
-
if (oldest.done !== true) state.scores.delete(oldest.value)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Mark one seq as LLM-recertified low relevance (a suggestion for later
|
|
126
|
-
* history-aggressiveness decisions, consumed by nothing in this round).
|
|
127
|
-
* Bounded at {@link ADVISOR_RECERTIFIED_LIMIT} with the same LRU eviction.
|
|
128
|
-
*/
|
|
129
|
-
export function recordRecertified(state: AdvisorState, seq: number, turn: number): void {
|
|
130
|
-
state.recertified.delete(seq)
|
|
131
|
-
state.recertified.set(seq, turn)
|
|
132
|
-
if (state.recertified.size > ADVISOR_RECERTIFIED_LIMIT) {
|
|
133
|
-
const oldest = state.recertified.keys().next()
|
|
134
|
-
if (oldest.done !== true) state.recertified.delete(oldest.value)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Drop every cached artifact that depends on the task semantics: a changed
|
|
140
|
-
* todo version invalidates the summary and makes all eligible candidates
|
|
141
|
-
* rescore-worthy (the watermark alone would otherwise hide them).
|
|
142
|
-
*/
|
|
143
|
-
export function invalidateOnTaskChange(state: AdvisorState, todoVersion: string): boolean {
|
|
144
|
-
if (state.todoVersion === todoVersion) return false
|
|
145
|
-
state.todoVersion = todoVersion
|
|
146
|
-
state.summary = undefined
|
|
147
|
-
state.lastSummaryTurn = -1
|
|
148
|
-
return true
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// ─────────── Turn-tail intent summary: session-scoped overrides and records ───────────
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* `/ctx-summary off|on` overrides, keyed by session id (string). The command
|
|
155
|
-
* handler only sees `invocation.agent.session.id`, not the pruner's Session
|
|
156
|
-
* object, so these are id-keyed rather than WeakMap'd. Entries are two-char
|
|
157
|
-
* strings per session and cleared whenever the override is lifted.
|
|
158
|
-
*/
|
|
159
|
-
const summaryOverrides = new Map<string, 'on' | 'off'>()
|
|
160
|
-
|
|
161
|
-
/** Read the session's `/ctx-summary` override; `undefined` = default (settings-driven). */
|
|
162
|
-
export function getSummaryOverride(sessionId: string): 'on' | 'off' | undefined {
|
|
163
|
-
return summaryOverrides.get(sessionId)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/** Set or clear (`undefined`) the session's `/ctx-summary` override. */
|
|
167
|
-
export function setSummaryOverride(sessionId: string, value: 'on' | 'off' | undefined): void {
|
|
168
|
-
if (value === undefined) summaryOverrides.delete(sessionId)
|
|
169
|
-
else summaryOverrides.set(sessionId, value)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** Last observed `intentSummary.enabled` for a session, for `/ctx-summary status`. */
|
|
173
|
-
const lastObservedIntentEnabled = new Map<string, boolean>()
|
|
174
|
-
|
|
175
|
-
/** Record the gate input the pass last evaluated for this session. */
|
|
176
|
-
export function observeIntentEnabled(sessionId: string, enabled: boolean): void {
|
|
177
|
-
lastObservedIntentEnabled.set(sessionId, enabled)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/** The settings-side enabled flag last observed for the session, if any. */
|
|
181
|
-
export function getObservedIntentEnabled(sessionId: string): boolean | undefined {
|
|
182
|
-
return lastObservedIntentEnabled.get(sessionId)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/** One landed intent fold, kept for `/ctx-summary status` (one per session). */
|
|
186
|
-
export interface IntentFoldRecord {
|
|
187
|
-
readonly turn: number
|
|
188
|
-
readonly startSeq: number
|
|
189
|
-
readonly endSeq: number
|
|
190
|
-
readonly liveTokensBefore: number
|
|
191
|
-
readonly at: number
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const lastIntentFolds = new Map<string, IntentFoldRecord>()
|
|
195
|
-
|
|
196
|
-
/** Record a landed intent fold for the session (newest wins). */
|
|
197
|
-
export function recordIntentFold(sessionId: string, record: IntentFoldRecord): void {
|
|
198
|
-
lastIntentFolds.set(sessionId, record)
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/** The most recent landed intent fold for the session, if any. */
|
|
202
|
-
export function getLastIntentFold(sessionId: string): IntentFoldRecord | undefined {
|
|
203
|
-
return lastIntentFolds.get(sessionId)
|
|
204
|
-
}
|