dsh-context-compression-improved 0.10.4 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plans/improve/checklist.md +32 -0
- package/.agents/plans/improve/findings.md +102 -0
- package/.agents/plans/improve/spec.md +53 -0
- package/.agents/plans/improve/tasks.md +70 -0
- package/.gitattributes +2 -0
- package/.githooks/pre-push +37 -0
- package/.github/workflows/ci.yml +47 -0
- package/CHANGELOG.de.md +580 -0
- package/CHANGELOG.es.md +588 -0
- package/CHANGELOG.fr.md +576 -0
- package/CHANGELOG.it.md +577 -0
- package/CHANGELOG.ja.md +261 -0
- package/CHANGELOG.ko.md +254 -0
- package/CHANGELOG.md +557 -0
- package/CHANGELOG.ru.md +554 -0
- package/CHANGELOG.zh.md +247 -0
- package/CONTRIBUTING.md +22 -0
- package/README.de.md +96 -0
- package/README.es.md +96 -0
- package/README.fr.md +96 -0
- package/README.it.md +96 -0
- package/README.ja.md +102 -0
- package/README.ko.md +102 -0
- package/README.md +110 -15
- package/README.ru.md +96 -0
- package/README.zh.md +104 -14
- package/SECURITY.md +18 -0
- package/THIRD_PARTY_NOTICES.md +7 -25
- 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 +77 -0
- package/docs/installation.de.md +104 -0
- package/docs/installation.es.md +104 -0
- package/docs/installation.fr.md +104 -0
- package/docs/installation.it.md +104 -0
- package/docs/installation.ja.md +78 -0
- package/docs/installation.ko.md +78 -0
- package/docs/installation.md +103 -0
- package/docs/installation.ru.md +104 -0
- package/docs/installation.zh.md +100 -0
- package/docs/repair-log.md +657 -0
- package/docs/shallow-teaching-preset-template.md +46 -0
- package/eslint.config.js +30 -0
- package/package.json +116 -129
- package/packages/selector/LICENSE +21 -0
- package/packages/selector/README.md +26 -0
- package/packages/selector/README.zh.md +24 -0
- package/packages/selector/THIRD_PARTY_NOTICES.md +32 -0
- package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -0
- package/packages/selector/docs/native-tool-result-selector-spec.md +34 -0
- package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -0
- package/{dsh.plugin.json → packages/selector/dsh.plugin.json} +1 -1
- package/{lib → packages/selector/lib}/client.d.ts +8 -0
- package/{lib → packages/selector/lib}/client.js +212 -3
- package/{lib → packages/selector/lib}/index.js +1 -1
- package/{lib → packages/selector/lib}/profiles.d.ts +34 -0
- package/{lib → packages/selector/lib}/pruner.d.ts +55 -0
- package/{lib → packages/selector/lib}/pruner.js +1925 -303
- package/{lib → packages/selector/lib}/savings-integral.js +126 -3
- package/packages/selector/lib/style.css +350 -0
- package/{lib → packages/selector/lib}/tool-result.js +9 -1
- package/packages/selector/package.json +178 -0
- package/packages/selector/screenshots.json +3 -0
- package/packages/selector/src/client/CompressionProfileControls.tsx +352 -0
- package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -0
- package/packages/selector/src/client/CompressionProfileSelector.tsx +89 -0
- package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -0
- package/packages/selector/src/client/EstimatorControls.tsx +277 -0
- package/packages/selector/src/client/bridge-scope.ts +125 -0
- package/packages/selector/src/client/decode.ts +68 -0
- package/packages/selector/src/client/fab-pos.ts +71 -0
- package/packages/selector/src/client/index.ts +438 -0
- package/packages/selector/src/client/locales/de.ts +167 -0
- package/packages/selector/src/client/locales/es.ts +167 -0
- package/packages/selector/src/client/locales/fr.ts +167 -0
- package/packages/selector/src/client/locales/it.ts +167 -0
- package/packages/selector/src/client/locales/ja.ts +167 -0
- package/packages/selector/src/client/locales/ko.ts +167 -0
- package/packages/selector/src/client/locales/ru.ts +167 -0
- package/packages/selector/src/client/locales.ts +334 -0
- package/packages/selector/src/client/monitor-fab.ts +445 -0
- package/packages/selector/src/client/preset-options.ts +88 -0
- package/packages/selector/src/client/savings-card.tsx +269 -0
- package/packages/selector/src/client/scope-face.ts +24 -0
- package/packages/selector/src/client/settings-section.tsx +156 -0
- package/packages/selector/src/compat/host-generation.ts +96 -0
- package/packages/selector/src/compat/llm-messages.ts +50 -0
- package/packages/selector/src/compat/settings-lease.ts +108 -0
- package/packages/selector/src/compat/tool-result.ts +91 -0
- package/packages/selector/src/css-modules.d.ts +6 -0
- package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -0
- package/packages/selector/src/estimator-catalog.ts +104 -0
- package/packages/selector/src/index.ts +890 -0
- package/packages/selector/src/invariant.ts +113 -0
- package/packages/selector/src/preset-overlay.ts +749 -0
- package/packages/selector/src/profiles.ts +554 -0
- package/packages/selector/src/pruner/content.ts +199 -0
- package/packages/selector/src/pruner/session.ts +97 -0
- package/packages/selector/src/pruner/state.ts +61 -0
- package/packages/selector/src/pruner/tuning.ts +23 -0
- package/packages/selector/src/pruner/types.ts +78 -0
- package/packages/selector/src/pruner.ts +3222 -0
- package/packages/selector/src/runtime/adaptive-cost.ts +205 -0
- package/packages/selector/src/runtime/audit.ts +321 -0
- package/packages/selector/src/runtime/config.ts +887 -0
- package/packages/selector/src/runtime/custom-policy.ts +300 -0
- package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -0
- package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -0
- package/packages/selector/src/runtime/display-prefs.ts +98 -0
- package/packages/selector/src/runtime/fold-router.ts +143 -0
- package/packages/selector/src/runtime/measurement.ts +444 -0
- package/packages/selector/src/runtime/monitor.ts +341 -0
- package/packages/selector/src/runtime/panel-command.ts +213 -0
- package/packages/selector/src/runtime/reducers.ts +1755 -0
- package/packages/selector/src/runtime/retrieve.ts +505 -0
- package/packages/selector/src/runtime/savings-integral.ts +117 -0
- package/packages/selector/src/runtime/savings-projection.ts +229 -0
- package/packages/selector/src/runtime/savings-verify.ts +446 -0
- package/packages/selector/src/runtime/savings.ts +526 -0
- package/packages/selector/src/runtime/sediment-card.ts +126 -0
- package/packages/selector/src/runtime/sediment-clock.ts +87 -0
- package/packages/selector/src/runtime/sediment-guard.ts +136 -0
- package/packages/selector/src/runtime/sediment-publish.ts +144 -0
- package/packages/selector/src/runtime/sediment-span.ts +170 -0
- package/packages/selector/src/runtime/sediment.ts +209 -0
- package/packages/selector/src/runtime/session-events.ts +30 -0
- package/packages/selector/src/runtime/session-file-decode.ts +523 -0
- package/packages/selector/src/runtime/shallow-tools.ts +342 -0
- package/packages/selector/src/runtime/stats-backfill.ts +541 -0
- package/packages/selector/src/runtime/stats-db.ts +492 -0
- package/packages/selector/src/runtime/stats-schema.ts +123 -0
- package/packages/selector/src/runtime/stats-sync.ts +307 -0
- package/packages/selector/src/runtime/summary-command.ts +127 -0
- package/packages/selector/src/runtime/tail-trim.ts +177 -0
- package/packages/selector/src/runtime/token-count.ts +72 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
- package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
- package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
- package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
- package/packages/selector/src/runtime/tokenpilot/dedup.ts +82 -0
- package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -0
- package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
- package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
- package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
- package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
- package/packages/selector/src/runtime/tokenpilot/locator.ts +129 -0
- package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -0
- package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
- package/packages/selector/src/runtime/tool-names.ts +42 -0
- package/packages/selector/src/runtime/toolclass.ts +103 -0
- package/packages/selector/src/runtime/triage/masks.ts +128 -0
- package/packages/selector/src/runtime/triage/shallow.ts +132 -0
- package/packages/selector/src/runtime/triage/signals.ts +167 -0
- package/packages/selector/src/runtime/triage/types.ts +125 -0
- package/packages/selector/src/runtime/types.ts +396 -0
- package/packages/selector/src/runtime/value.ts +48 -0
- package/packages/selector/src/settings-bridge.ts +175 -0
- package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
- package/packages/selector/tests/auto-compact.client.spec.tsx +214 -0
- package/packages/selector/tests/built/client-artifact.spec.ts +56 -0
- package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -0
- package/packages/selector/tests/code-skeleton.client.spec.ts +98 -0
- package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
- package/packages/selector/tests/custom-contract.client.spec.ts +226 -0
- package/packages/selector/tests/estimator-catalog.spec.ts +70 -0
- package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -0
- package/packages/selector/tests/estimator-route-registration.host.spec.ts +202 -0
- package/packages/selector/tests/fab-pos.client.spec.ts +47 -0
- package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +231 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +236 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +220 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +140 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +117 -0
- package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +67 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +119 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +119 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +131 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +196 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +71 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +126 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +86 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +50 -0
- package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +102 -0
- package/packages/selector/tests/helpers/legacy-namespace.ts +35 -0
- package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -0
- package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -0
- package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -0
- package/packages/selector/tests/monitor-fab.client.spec.ts +240 -0
- package/packages/selector/tests/preset-options-write.client.spec.ts +192 -0
- package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -0
- package/packages/selector/tests/preset-overlay.host.spec.ts +246 -0
- package/packages/selector/tests/profiles.client.spec.tsx +436 -0
- package/packages/selector/tests/ptc-custom-write.client.spec.ts +86 -0
- package/packages/selector/tests/public/package-contract.client.spec.ts +89 -0
- package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -0
- package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -0
- package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
- package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
- package/packages/selector/tests/runtime/audit.spec.ts +275 -0
- package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -0
- package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
- package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -0
- package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -0
- package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -0
- package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -0
- package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
- package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -0
- package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +46 -0
- package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -0
- package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -0
- package/packages/selector/tests/runtime/fold-router.spec.ts +140 -0
- package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
- package/packages/selector/tests/runtime/fresh-gate.spec.ts +43 -0
- package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
- package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
- package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
- package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +79 -0
- package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -0
- package/packages/selector/tests/runtime/monitor.spec.ts +354 -0
- package/packages/selector/tests/runtime/panel-command.spec.ts +101 -0
- package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
- package/packages/selector/tests/runtime/ptc-profile.spec.ts +133 -0
- package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2795 -0
- package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
- package/packages/selector/tests/runtime/savings-accounting.spec.ts +291 -0
- package/packages/selector/tests/runtime/savings-integral.spec.ts +169 -0
- package/packages/selector/tests/runtime/savings-projection.spec.ts +89 -0
- package/packages/selector/tests/runtime/savings-verify.spec.ts +226 -0
- package/packages/selector/tests/runtime/savings.spec.ts +139 -0
- package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
- package/packages/selector/tests/runtime/sediment-card.spec.ts +111 -0
- package/packages/selector/tests/runtime/sediment-config.spec.ts +56 -0
- package/packages/selector/tests/runtime/sediment-guard.spec.ts +71 -0
- package/packages/selector/tests/runtime/sediment-masks.spec.ts +95 -0
- package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +166 -0
- package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +65 -0
- package/packages/selector/tests/runtime/sediment-publish.spec.ts +142 -0
- package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +158 -0
- package/packages/selector/tests/runtime/sediment-settings.spec.ts +73 -0
- package/packages/selector/tests/runtime/sediment-signals.spec.ts +124 -0
- package/packages/selector/tests/runtime/sediment-span.spec.ts +92 -0
- package/packages/selector/tests/runtime/session-events.spec.ts +27 -0
- package/packages/selector/tests/runtime/session-file-decode.spec.ts +281 -0
- package/packages/selector/tests/runtime/settings-unwrap.spec.ts +58 -0
- package/packages/selector/tests/runtime/shallow-primitives.spec.ts +135 -0
- package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
- package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +167 -0
- package/packages/selector/tests/runtime/stats-backfill.spec.ts +350 -0
- package/packages/selector/tests/runtime/stats-db.spec.ts +361 -0
- package/packages/selector/tests/runtime/stats-privacy.spec.ts +55 -0
- package/packages/selector/tests/runtime/stats-sync.spec.ts +278 -0
- package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
- package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
- package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -0
- package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
- package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -0
- package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -0
- package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -0
- package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +121 -0
- package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -0
- package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
- package/packages/selector/tests/runtime/value.spec.ts +23 -0
- package/packages/selector/tests/savings-sessions.client.spec.tsx +140 -0
- package/packages/selector/tests/settings-seat.client.spec.ts +215 -0
- package/packages/selector/tests/standing-generation.host.spec.ts +724 -0
- package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -0
- package/packages/selector/tests/support/cache-prefix-audit.ts +105 -0
- package/packages/selector/tests/support/mock-adapter.ts +37 -0
- package/packages/selector/tests/support/ui-primitives.tsx +34 -0
- package/packages/selector/tsconfig.json +11 -0
- package/packages/selector/tsdown.client.config.ts +102 -0
- package/packages/selector/tsdown.config.ts +20 -0
- package/pnpm-workspace.yaml +76 -0
- package/screenshots.json +6 -3
- package/scripts/capture-profile-baseline.mjs +42 -0
- package/scripts/cell-browser-e2e.mjs +354 -0
- package/scripts/generate-tokenizer-fixtures.py +81 -0
- package/scripts/generate-vision-fixtures.py +208 -0
- package/scripts/hosts.d.mts +3 -0
- package/scripts/hosts.mjs +79 -0
- package/scripts/packed-components-smoke.mjs +763 -0
- package/scripts/packed-install-e2e.mjs +1346 -0
- package/scripts/sediment-latency-report.mjs +63 -0
- package/scripts/sync-hosts.mjs +174 -0
- package/scripts/toolclass-corpus-replay.mjs +281 -0
- package/scripts/verify-release.mjs +343 -0
- package/tests/TEST_INVENTORY.md +41 -0
- package/tsconfig.base.json +18 -0
- package/tsconfig.json +7 -0
- package/tsconfig.tests.json +15 -0
- package/vitest.built.config.ts +9 -0
- package/vitest.config.ts +54 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/manifest.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer_config.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/manifest.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
- /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
- /package/{cordis.patch.yml → packages/selector/cordis.patch.yml} +0 -0
- /package/{lib → packages/selector/lib}/index.d.ts +0 -0
- /package/{lib → packages/selector/lib}/invariant.d.ts +0 -0
- /package/{lib → packages/selector/lib}/invariant.js +0 -0
- /package/{lib → packages/selector/lib}/tail-trim.js +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shallow-read primitives (plan cci-sedimentation-triage, Phase 4.5).
|
|
3
|
+
*
|
|
4
|
+
* Pure decision layer for the upgrade-discard pair:
|
|
5
|
+
* - `normalizeToolPath` — the pairing key (drive letter lowered, separators
|
|
6
|
+
* unified, `./` resolved); false pairing must fail CLOSED (no footer, guard
|
|
7
|
+
* refuses), never silently drop content;
|
|
8
|
+
* - `classifyShallowSample` — the `probe` decision: O(1) header sample picks
|
|
9
|
+
* which shallow view fits (T4.12);
|
|
10
|
+
* - `evaluateDiscardGuard` — the asymmetric protection (M20): discarding the
|
|
11
|
+
* MAP when the covering full read is only a slice is refused; discarding
|
|
12
|
+
* the full read while the checkpoint survives is always allowed;
|
|
13
|
+
* - `buildShallowFooter` / `renderCheckpointLine` — the data-shaped teaching
|
|
14
|
+
* that rides the pruner seam (findings F5: reminders as data, not rules).
|
|
15
|
+
*/
|
|
16
|
+
import type { ShallowCheckpoint } from './types.ts'
|
|
17
|
+
|
|
18
|
+
/** Windows-first corpus; forward slashes accepted everywhere. */
|
|
19
|
+
export function normalizeToolPath(raw: string): string {
|
|
20
|
+
const unified = raw.replace(/\\/g, '/').replace(/^\.\//, '')
|
|
21
|
+
const lowered = /^[A-Za-z]:\//.test(unified)
|
|
22
|
+
? `${unified[0]!.toLowerCase()}${unified.slice(1)}`
|
|
23
|
+
: unified
|
|
24
|
+
// collapse duplicate separators and trailing slash, keep leading root
|
|
25
|
+
const collapsed = lowered.replace(/\/{2,}/g, '/').replace(/\/$/, '')
|
|
26
|
+
// resolve `..` segments lexically (no fs access here)
|
|
27
|
+
const segments = collapsed.split('/')
|
|
28
|
+
const out: string[] = []
|
|
29
|
+
for (const segment of segments) {
|
|
30
|
+
if (segment === '..') out.pop()
|
|
31
|
+
else if (segment !== '.' && segment !== '') out.push(segment)
|
|
32
|
+
}
|
|
33
|
+
const joined = out.join('/')
|
|
34
|
+
return collapsed.startsWith('/') ? `/${joined}` : joined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Shallow view methods the probe can recommend. */
|
|
38
|
+
export type ShallowMethod = 'json-skeleton' | 'code-skeleton' | 'csv-header' | 'toc-lines' | 'head-tail'
|
|
39
|
+
|
|
40
|
+
export interface ProbeVerdict {
|
|
41
|
+
readonly method: ShallowMethod
|
|
42
|
+
readonly reason: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const JSON_START = /^[{[]/
|
|
46
|
+
const CSV_HINT = /^[^\n,]*,.*\n(?:[^\n,]*,.*){2,}/
|
|
47
|
+
const FRONTMATTER_HINT = /^---\n/
|
|
48
|
+
|
|
49
|
+
/** Classify from a bounded header sample only — the body is never opened here. */
|
|
50
|
+
export function classifyShallowSample(head: string, ext: string, totalBytes: number): ProbeVerdict {
|
|
51
|
+
const extension = ext.toLowerCase().replace(/^\./, '')
|
|
52
|
+
const trimmed = head.replace(/^\uFEFF/, '').trimStart()
|
|
53
|
+
if (extension === 'json' || extension === 'jsonc' || (JSON_START.test(trimmed) && (extension === '' || extension === 'jsonl'))) {
|
|
54
|
+
return { method: 'json-skeleton', reason: 'structured JSON: key skeleton beats raw text' }
|
|
55
|
+
}
|
|
56
|
+
if (extension === 'jsonl' || extension === 'ndjson') {
|
|
57
|
+
return { method: 'code-skeleton', reason: 'record stream: head/tail records with counts' }
|
|
58
|
+
}
|
|
59
|
+
if (extension === 'csv' || extension === 'tsv' || (totalBytes > 2000 && CSV_HINT.test(trimmed))) {
|
|
60
|
+
return { method: 'csv-header', reason: 'tabular: header row + row count, rows elided' }
|
|
61
|
+
}
|
|
62
|
+
if (['md', 'markdown', 'rst', 'txt', 'adoc'].includes(extension)) {
|
|
63
|
+
return { method: 'toc-lines', reason: 'prose: heading outline, bodies elided' }
|
|
64
|
+
}
|
|
65
|
+
if (['ts', 'tsx', 'js', 'jsx', 'mjs', 'py', 'go', 'rs', 'java', 'c', 'h', 'cc', 'cpp', 'cs', 'kt', 'swift', 'php', 'rb'].includes(extension)
|
|
66
|
+
|| FRONTMATTER_HINT.test(trimmed) === false && /^\s*(?:import|from|package|use|def|fn|class|const|function)/.test(trimmed)) {
|
|
67
|
+
return { method: 'code-skeleton', reason: 'source code: declarations kept, bodies elided' }
|
|
68
|
+
}
|
|
69
|
+
if (totalBytes < 4000) {
|
|
70
|
+
return { method: 'head-tail', reason: 'small enough that a plain slice is the honest view' }
|
|
71
|
+
}
|
|
72
|
+
return { method: 'toc-lines', reason: 'unknown shape: line-structure outline as safe default' }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** One side of a discard pair. */
|
|
76
|
+
export interface ReadPairSide {
|
|
77
|
+
readonly seq: number
|
|
78
|
+
readonly path: string
|
|
79
|
+
/** 'full' covers whole file; 'slice' carries the covered line window. */
|
|
80
|
+
readonly coverage: { readonly kind: 'full' } | { readonly kind: 'slice'; readonly from: number; readonly to: number }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface DiscardGuardInput {
|
|
84
|
+
/** The MAP side being considered for discard (the skeleton result). */
|
|
85
|
+
readonly map: ReadPairSide
|
|
86
|
+
/** The covering side claimed to supersede the map. */
|
|
87
|
+
readonly covering: ReadPairSide
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The asymmetric guard (findings F6): losing the map costs far more than the
|
|
92
|
+
* saved bytes. Discarding the map requires the covering read to span it
|
|
93
|
+
* fully; equal paths after normalization are a precondition, never assumed.
|
|
94
|
+
*/
|
|
95
|
+
export function evaluateDiscardGuard(input: DiscardGuardInput): { readonly allowed: boolean; readonly reason: string } {
|
|
96
|
+
const mapPath = normalizeToolPath(input.map.path)
|
|
97
|
+
const coveringPath = normalizeToolPath(input.covering.path)
|
|
98
|
+
if (mapPath === '' || coveringPath === '' || mapPath !== coveringPath) {
|
|
99
|
+
return { allowed: false, reason: `path-mismatch:${input.map.path}|${input.covering.path}` }
|
|
100
|
+
}
|
|
101
|
+
if (input.map.coverage.kind === 'full') {
|
|
102
|
+
// map covers everything; only a full covering read supersedes it
|
|
103
|
+
if (input.covering.coverage.kind === 'full') return { allowed: true, reason: 'covered-full' }
|
|
104
|
+
return { allowed: false, reason: 'map-is-full-need-full-coverage' }
|
|
105
|
+
}
|
|
106
|
+
if (input.covering.coverage.kind === 'full') return { allowed: true, reason: 'covered-by-full' }
|
|
107
|
+
const fromOk = input.covering.coverage.from <= input.map.coverage.from
|
|
108
|
+
const toOk = input.covering.coverage.to >= input.map.coverage.to
|
|
109
|
+
return fromOk && toOk
|
|
110
|
+
? { allowed: true, reason: 'covered-by-window' }
|
|
111
|
+
: { allowed: false, reason: `window-gap:${input.map.coverage.from}-${input.map.coverage.to} vs ${input.covering.coverage.from}-${input.covering.coverage.to}` }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Footer riding a full read that pairs with a live shallow map (T4.8). */
|
|
115
|
+
export function buildShallowFooter(checkpoint: ShallowCheckpoint, savedTokens: number): string {
|
|
116
|
+
return `[cci-shallow-pair] 同文件的浅读视图 ${checkpoint.ref}(≈${savedTokens} tok)仍在上下文;确认不再需要时可调 context_compression_discard 释放(检查点行会保留)。被省略的输出不要凭本行推测补写。`
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The one permanent line a discarded map leaves behind (R11). */
|
|
120
|
+
export function renderCheckpointLine(checkpoint: ShallowCheckpoint): string {
|
|
121
|
+
return `[cci-checkpoint] ${checkpoint.path} | ${checkpoint.coverage} | ref ${checkpoint.ref} | fp ${checkpoint.fingerprint}`
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Cheap order-sensitive header hash + size; staleness hint only, never authority. */
|
|
125
|
+
export function shallowFingerprint(text: string): string {
|
|
126
|
+
const head = text.slice(0, 512)
|
|
127
|
+
let hash = 5381
|
|
128
|
+
for (let index = 0; index < head.length; index += 1) {
|
|
129
|
+
hash = ((hash << 5) + hash + head.charCodeAt(index)) >>> 0
|
|
130
|
+
}
|
|
131
|
+
return `${text.length.toString(16)}-${hash.toString(16)}`
|
|
132
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line-A signal rules (plan cci-sedimentation-triage, Phase 1).
|
|
3
|
+
*
|
|
4
|
+
* Two decoupled layers, mirroring the trial-3 findings:
|
|
5
|
+
* 1. `blockFailureVerdict` — the five BASE structural signals that mark a
|
|
6
|
+
* whole tool result as a hard failure (audit + card section grouping).
|
|
7
|
+
* 2. `linePool` — verbatim per-line capture, INDEPENDENT of the block verdict
|
|
8
|
+
* so soft-failure blocks (exit 0 with error lines in the body) still yield
|
|
9
|
+
* protected lines. Round-1 replay measured 62.4% recall when capture was
|
|
10
|
+
* gated on the block verdict; decoupling is the regression anchor.
|
|
11
|
+
*
|
|
12
|
+
* The base set is never removable; `mergeExtraPatterns` appends the validated
|
|
13
|
+
* default extras (trial-3: extras carried 48.2% of pool lines) plus user
|
|
14
|
+
* entries from `sediment.extraSignalPatterns`. Invalid regex entries are
|
|
15
|
+
* skipped here (profiles decode already rejects them upstream — belt and
|
|
16
|
+
* suspenders, never a throw at capture time).
|
|
17
|
+
*
|
|
18
|
+
* @module runtime/triage/signals
|
|
19
|
+
*/
|
|
20
|
+
import type { TriageRole, VerbatimLine } from './types.ts'
|
|
21
|
+
|
|
22
|
+
/** Per-line verbatim cap (plan: 240 codepoints, ` …` marker excluded). */
|
|
23
|
+
const LINE_CAP = 240
|
|
24
|
+
|
|
25
|
+
/** Base structural block signals: id + predicate over the raw result text. */
|
|
26
|
+
const BASE_BLOCK_SIGNALS: ReadonlyArray<{
|
|
27
|
+
readonly id: string
|
|
28
|
+
readonly test: (text: string, isError: boolean) => boolean
|
|
29
|
+
}> = Object.freeze([
|
|
30
|
+
{ id: 'sig:isError-flag', test: (_text, isError) => isError },
|
|
31
|
+
{ id: 'sig:stderr-prefix', test: text => text.trimStart().startsWith('[stderr]') },
|
|
32
|
+
{
|
|
33
|
+
id: 'sig:exit-code-bracket',
|
|
34
|
+
test: text => {
|
|
35
|
+
const trimmed = text.trim()
|
|
36
|
+
return /\[exit code:\s*(?!0\b)-?\d+\s*\]\s*$/.test(trimmed)
|
|
37
|
+
|| /\[Command finished with exit code\s+(?!0\b)-?\d+\]\s*$/.test(trimmed)
|
|
38
|
+
|| /^exit_code=\s*(?!0\b)-?\d+\s*$/.test(trimmed)
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'sig:json-exitcode',
|
|
43
|
+
test: text => {
|
|
44
|
+
const trimmed = text.trim()
|
|
45
|
+
if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) return false
|
|
46
|
+
try {
|
|
47
|
+
const parsed: unknown = JSON.parse(trimmed)
|
|
48
|
+
return typeof (parsed as Record<string, unknown>)?.exitCode === 'number'
|
|
49
|
+
&& (parsed as { exitCode: number }).exitCode !== 0
|
|
50
|
+
} catch {
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
])
|
|
56
|
+
|
|
57
|
+
/** Line-level base family: the classic failure markers (spine-validated). */
|
|
58
|
+
const FAILURE_BASE_PATTERN = /(?:^|\s)(?:FAIL(?:ED)?\b|Error:|Exception:|Traceback\b|panic:|AssertionError)/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Built-in default extras — trial-3 validated families the base misses
|
|
62
|
+
* (48.2% of pool lines in the replay corpus). Distributed like user extras:
|
|
63
|
+
* append-only, never replaces the base, individually skippable when invalid.
|
|
64
|
+
*/
|
|
65
|
+
const DEFAULT_EXTRA_PATTERNS: ReadonlyArray<{ readonly id: string; readonly source: string }> = Object.freeze([
|
|
66
|
+
{ id: 'ext:tool-timeout', source: String.raw`TOOL_TIMEOUT|timed out after \d+ms` },
|
|
67
|
+
{ id: 'ext:npm-err', source: String.raw`npm ERR!|\bERR!` },
|
|
68
|
+
{ id: 'ext:proc-kill', source: String.raw`\bkilled\b|OOM|out of memory` },
|
|
69
|
+
{ id: 'ext:assert-ctx', source: String.raw`expected .* to (?:be|equal|throw)|Received:|toStrictEqual` },
|
|
70
|
+
])
|
|
71
|
+
|
|
72
|
+
/** One compiled line rule with its audit id. */
|
|
73
|
+
export interface LineRule {
|
|
74
|
+
readonly id: string
|
|
75
|
+
readonly pattern: RegExp
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Compile the append-only line-rule set: base classic family first (its id
|
|
80
|
+
* wins on multi-rule matches, keeping audit stable), then built-in default
|
|
81
|
+
* extras, then user extras. Invalid user regexes are skipped silently — the
|
|
82
|
+
* settings boundary already rejected them upstream; capture must never throw.
|
|
83
|
+
*/
|
|
84
|
+
export function mergeExtraPatterns(userExtra: readonly string[]): readonly LineRule[] {
|
|
85
|
+
const rules: LineRule[] = [{ id: 'line:failure-classic', pattern: FAILURE_BASE_PATTERN }]
|
|
86
|
+
for (const entry of DEFAULT_EXTRA_PATTERNS) {
|
|
87
|
+
try {
|
|
88
|
+
rules.push({ id: entry.id, pattern: new RegExp(entry.source, 'i') })
|
|
89
|
+
} catch {
|
|
90
|
+
// Unreachable by construction; keep the loop total regardless.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const source of userExtra) {
|
|
94
|
+
try {
|
|
95
|
+
rules.push({ id: `ext:user:${source.slice(0, 60)}`, pattern: new RegExp(source) })
|
|
96
|
+
} catch {
|
|
97
|
+
// Invalid or oversized entry: skip this rule only; base and defaults stay armed.
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return rules
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const DEFAULT_LINE_RULES = mergeExtraPatterns([])
|
|
104
|
+
|
|
105
|
+
/** Verdict of the base structural block-signal set. */
|
|
106
|
+
export interface BlockFailureVerdict {
|
|
107
|
+
readonly hard: boolean
|
|
108
|
+
readonly ruleIds: readonly string[]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Decide whether the whole block carries a hard failure signal (audit/grouping only — never gates the line pool). */
|
|
112
|
+
export function blockFailureVerdict(text: string, isError: boolean): BlockFailureVerdict {
|
|
113
|
+
const ruleIds: string[] = []
|
|
114
|
+
for (const rule of BASE_BLOCK_SIGNALS) {
|
|
115
|
+
if (rule.test(text, isError)) ruleIds.push(rule.id)
|
|
116
|
+
}
|
|
117
|
+
return { hard: ruleIds.length > 0, ruleIds }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Capture context for one block's lines. */
|
|
121
|
+
export interface LinePoolContext {
|
|
122
|
+
readonly seq: number
|
|
123
|
+
readonly role: TriageRole
|
|
124
|
+
readonly hardFailure: boolean
|
|
125
|
+
/** Compiled rule set from `mergeExtraPatterns`; absent uses the default set. */
|
|
126
|
+
readonly extraPatterns?: readonly LineRule[]
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function usefulLines(text: string): string[] {
|
|
130
|
+
return text.replace(/\n+$/, '').split('\n')
|
|
131
|
+
.filter(line => {
|
|
132
|
+
const trimmed = line.trim()
|
|
133
|
+
return trimmed.length > 0 && trimmed !== '[stderr]' && !/^\[exit code:/.test(trimmed)
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Verbatim per-line capture over the compiled rule set. Dedup by exact line
|
|
139
|
+
* text within the block, 240-codepoint cap with ` …` marker, first-matching
|
|
140
|
+
* rule wins the audit id (base order guarantees `line:failure-classic` wins
|
|
141
|
+
* ties). Decoupled from block classification: soft-failure blocks pass through
|
|
142
|
+
* with `hardFailure: false` and still yield lines.
|
|
143
|
+
*/
|
|
144
|
+
export function linePool(text: string, context: LinePoolContext): VerbatimLine[] {
|
|
145
|
+
const rules = context.extraPatterns ?? DEFAULT_LINE_RULES
|
|
146
|
+
const pool: VerbatimLine[] = []
|
|
147
|
+
const seen = new Set<string>()
|
|
148
|
+
for (const raw of usefulLines(text)) {
|
|
149
|
+
const line = raw.trim()
|
|
150
|
+
if (seen.has(line)) continue
|
|
151
|
+
const matched = rules.find(rule => rule.pattern.test(line))
|
|
152
|
+
if (matched === undefined) continue
|
|
153
|
+
seen.add(line)
|
|
154
|
+
const chars = Array.from(line)
|
|
155
|
+
const truncated = chars.length > LINE_CAP
|
|
156
|
+
const captured = truncated ? `${chars.slice(0, LINE_CAP).join('')} …` : line
|
|
157
|
+
pool.push({
|
|
158
|
+
seq: context.seq,
|
|
159
|
+
role: context.role,
|
|
160
|
+
text: captured,
|
|
161
|
+
ruleId: matched.id,
|
|
162
|
+
truncated,
|
|
163
|
+
hardFailure: context.hardFailure,
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
return pool
|
|
167
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frozen triage contract (plan cci-sedimentation-triage, T0.4).
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for the three-line sorting vocabulary shared by the
|
|
5
|
+
* signal pool (line A), the narrative stream (line B), and the deterministic
|
|
6
|
+
* masks (line C), plus the whole-turn card assembly. Downstream phases treat
|
|
7
|
+
* this file as read-only: contract changes require a plan amendment, not an
|
|
8
|
+
* in-flight edit.
|
|
9
|
+
*
|
|
10
|
+
* @module runtime/triage/types
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Roles whose lines may enter the verbatim protection pool. */
|
|
14
|
+
export type TriageRole = 'user' | 'assistant' | 'tool'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Permanent shallow-read checkpoint (plan R11): survives `discard` — the
|
|
18
|
+
* map is never lost, only the map's bulk. Four fields, rendered as one line.
|
|
19
|
+
*/
|
|
20
|
+
export interface ShallowCheckpoint {
|
|
21
|
+
/** Normalized target path (drive letter lowered, separators unified). */
|
|
22
|
+
readonly path: string
|
|
23
|
+
/** Coverage statement of the body the checkpoint stands for. */
|
|
24
|
+
readonly coverage: string
|
|
25
|
+
/** session:// reference into the original event (retrieve target). */
|
|
26
|
+
readonly ref: string
|
|
27
|
+
/** Cheap structural fingerprint (size + head hash) for staleness hints. */
|
|
28
|
+
readonly fingerprint: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** One verbatim line captured by a signal rule, capped at capture time. */
|
|
32
|
+
export interface VerbatimLine {
|
|
33
|
+
/** Event seq of the owning tool/result or message on the session surface. */
|
|
34
|
+
readonly seq: number
|
|
35
|
+
readonly role: TriageRole
|
|
36
|
+
/** Line text as captured (240-codepoint cap applied, `truncated` marks it). */
|
|
37
|
+
readonly text: string
|
|
38
|
+
/** Rule id that captured this line (base set or extra slot), for audit. */
|
|
39
|
+
readonly ruleId: string
|
|
40
|
+
/** True when the stored text hit the per-line cap. */
|
|
41
|
+
readonly truncated: boolean
|
|
42
|
+
/** True when the owning block carried a hard failure signal (exit/stderr/isError). */
|
|
43
|
+
readonly hardFailure: boolean
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Deterministic mask verdict for one tool result (line C). */
|
|
47
|
+
export type MaskVerdict =
|
|
48
|
+
| {
|
|
49
|
+
readonly kind: 'manifest'
|
|
50
|
+
/** Target paths resolved from call args first, result text only as fallback. */
|
|
51
|
+
readonly paths: readonly string[]
|
|
52
|
+
readonly seq: number
|
|
53
|
+
}
|
|
54
|
+
| {
|
|
55
|
+
readonly kind: 'skeleton'
|
|
56
|
+
/** Captured declaration lines (base order preserved, capped). */
|
|
57
|
+
readonly lines: readonly string[]
|
|
58
|
+
/** Total body lines the skeleton stands for. */
|
|
59
|
+
readonly totalLines: number
|
|
60
|
+
/** Byte length of the elided body, for omission stats. */
|
|
61
|
+
readonly elidedChars: number
|
|
62
|
+
readonly seq: number
|
|
63
|
+
/** Permanent checkpoint layer (R11); `discard` may remove body, never this. */
|
|
64
|
+
readonly checkpoint?: ShallowCheckpoint
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
readonly kind: 'pointer'
|
|
68
|
+
/** Oversized single result replaced by its event-seq pointer. */
|
|
69
|
+
readonly seq: number
|
|
70
|
+
readonly tokens: number
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One narrative span left for the compression stream (line B). */
|
|
74
|
+
export interface NarrativeSpan {
|
|
75
|
+
readonly seq: number
|
|
76
|
+
readonly role: TriageRole
|
|
77
|
+
/** Token estimate carried by the span (estimator contract: same meter as stats). */
|
|
78
|
+
readonly tokens: number
|
|
79
|
+
readonly text: string
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Complete per-block triage output. `poolLines` and `mask` are verbatim-safe
|
|
84
|
+
* (copy, never paraphrase); `residualNarrative` is the only fold-eligible
|
|
85
|
+
* material and MUST NOT contain pooled or masked content.
|
|
86
|
+
*/
|
|
87
|
+
export interface TriageResult {
|
|
88
|
+
readonly poolLines: readonly VerbatimLine[]
|
|
89
|
+
readonly mask?: MaskVerdict
|
|
90
|
+
readonly residualNarrative: readonly NarrativeSpan[]
|
|
91
|
+
/** Gross tokens of the source block, for the rewrite guard accounting. */
|
|
92
|
+
readonly sourceTokens: number
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Card assembly order (R1/R7): mechanical cache first, narrative appended last. */
|
|
96
|
+
export interface TurnCardDraft {
|
|
97
|
+
/** Pointer head: one line, event-seq reference, no backup paths. */
|
|
98
|
+
readonly head: string
|
|
99
|
+
/** Verbatim protection pool section (line A). */
|
|
100
|
+
readonly pool: readonly VerbatimLine[]
|
|
101
|
+
/** Mask sections (line C), in span order. */
|
|
102
|
+
readonly masks: readonly MaskVerdict[]
|
|
103
|
+
/** Omission stats line (counts only). */
|
|
104
|
+
readonly omissionStats: string
|
|
105
|
+
/** Narrative segment: closing text (tier 1) or fold output (tier 2); absent = tier 3. */
|
|
106
|
+
readonly narrative?: string
|
|
107
|
+
/** Narrative tier actually used, for audit and stats separation (M22). */
|
|
108
|
+
readonly narrativeTier: 'closing' | 'fold' | 'mechanical-only'
|
|
109
|
+
/** Sum of retained verbatim+narrative tokens; replacement requires < sourceTokens (M7). */
|
|
110
|
+
readonly retainedTokens: number
|
|
111
|
+
/** Source span tokens this card replaces. */
|
|
112
|
+
readonly sourceTokens: number
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Gate verdicts for one whole-turn replacement candidate (R13). */
|
|
116
|
+
export interface TurnGateVerdict {
|
|
117
|
+
/** reason gate: only `turn/end(completed)` may proceed. */
|
|
118
|
+
readonly completed: boolean
|
|
119
|
+
/** closing qualification gate result (tier decision already made upstream). */
|
|
120
|
+
readonly narrativeTier: TurnCardDraft['narrativeTier']
|
|
121
|
+
/** rewrite guard: retained saving must clear tail-rewrite × ratio (findings F2). */
|
|
122
|
+
readonly rewriteGuardPassed: boolean
|
|
123
|
+
/** estimated cached-tail tokens invalidated by the replacement point. */
|
|
124
|
+
readonly rewriteTailTokens: number
|
|
125
|
+
}
|