dsh-context-compression-improved 0.11.1 → 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.
Files changed (311) hide show
  1. package/README.md +15 -110
  2. package/README.zh.md +14 -104
  3. package/THIRD_PARTY_NOTICES.md +25 -7
  4. package/{packages/selector/dsh.plugin.json → dsh.plugin.json} +1 -1
  5. package/{packages/selector/lib → lib}/index.js +101 -0
  6. package/package.json +125 -112
  7. package/screenshots.json +3 -6
  8. package/.agents/plans/improve/checklist.md +0 -32
  9. package/.agents/plans/improve/findings.md +0 -102
  10. package/.agents/plans/improve/spec.md +0 -53
  11. package/.agents/plans/improve/tasks.md +0 -70
  12. package/.gitattributes +0 -2
  13. package/.githooks/pre-push +0 -37
  14. package/.github/workflows/ci.yml +0 -47
  15. package/CHANGELOG.de.md +0 -580
  16. package/CHANGELOG.es.md +0 -588
  17. package/CHANGELOG.fr.md +0 -576
  18. package/CHANGELOG.it.md +0 -577
  19. package/CHANGELOG.ja.md +0 -261
  20. package/CHANGELOG.ko.md +0 -254
  21. package/CHANGELOG.md +0 -557
  22. package/CHANGELOG.ru.md +0 -554
  23. package/CHANGELOG.zh.md +0 -247
  24. package/CONTRIBUTING.md +0 -22
  25. package/README.de.md +0 -96
  26. package/README.es.md +0 -96
  27. package/README.fr.md +0 -96
  28. package/README.it.md +0 -96
  29. package/README.ja.md +0 -102
  30. package/README.ko.md +0 -102
  31. package/README.ru.md +0 -96
  32. package/SECURITY.md +0 -18
  33. package/assets/board.png +0 -0
  34. package/assets/context.png +0 -0
  35. package/assets/dshfind-card.svg +0 -33
  36. package/docs/assets/context-compression-selector-profiles.jpg +0 -0
  37. package/docs/assets/context-compression-selector-settings.png +0 -0
  38. package/docs/compat-0.1.5-report.md +0 -77
  39. package/docs/installation.de.md +0 -104
  40. package/docs/installation.es.md +0 -104
  41. package/docs/installation.fr.md +0 -104
  42. package/docs/installation.it.md +0 -104
  43. package/docs/installation.ja.md +0 -78
  44. package/docs/installation.ko.md +0 -78
  45. package/docs/installation.md +0 -103
  46. package/docs/installation.ru.md +0 -104
  47. package/docs/installation.zh.md +0 -100
  48. package/docs/repair-log.md +0 -657
  49. package/docs/shallow-teaching-preset-template.md +0 -46
  50. package/eslint.config.js +0 -30
  51. package/packages/selector/LICENSE +0 -21
  52. package/packages/selector/README.md +0 -26
  53. package/packages/selector/README.zh.md +0 -24
  54. package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
  55. package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
  56. package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
  57. package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
  58. package/packages/selector/lib/style.css +0 -350
  59. package/packages/selector/package.json +0 -178
  60. package/packages/selector/screenshots.json +0 -3
  61. package/packages/selector/src/client/CompressionProfileControls.tsx +0 -352
  62. package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
  63. package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -89
  64. package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
  65. package/packages/selector/src/client/EstimatorControls.tsx +0 -277
  66. package/packages/selector/src/client/bridge-scope.ts +0 -125
  67. package/packages/selector/src/client/decode.ts +0 -68
  68. package/packages/selector/src/client/fab-pos.ts +0 -71
  69. package/packages/selector/src/client/index.ts +0 -438
  70. package/packages/selector/src/client/locales/de.ts +0 -167
  71. package/packages/selector/src/client/locales/es.ts +0 -167
  72. package/packages/selector/src/client/locales/fr.ts +0 -167
  73. package/packages/selector/src/client/locales/it.ts +0 -167
  74. package/packages/selector/src/client/locales/ja.ts +0 -167
  75. package/packages/selector/src/client/locales/ko.ts +0 -167
  76. package/packages/selector/src/client/locales/ru.ts +0 -167
  77. package/packages/selector/src/client/locales.ts +0 -334
  78. package/packages/selector/src/client/monitor-fab.ts +0 -445
  79. package/packages/selector/src/client/preset-options.ts +0 -88
  80. package/packages/selector/src/client/savings-card.tsx +0 -269
  81. package/packages/selector/src/client/scope-face.ts +0 -24
  82. package/packages/selector/src/client/settings-section.tsx +0 -156
  83. package/packages/selector/src/compat/host-generation.ts +0 -96
  84. package/packages/selector/src/compat/llm-messages.ts +0 -50
  85. package/packages/selector/src/compat/settings-lease.ts +0 -108
  86. package/packages/selector/src/compat/tool-result.ts +0 -91
  87. package/packages/selector/src/css-modules.d.ts +0 -6
  88. package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
  89. package/packages/selector/src/estimator-catalog.ts +0 -104
  90. package/packages/selector/src/index.ts +0 -890
  91. package/packages/selector/src/invariant.ts +0 -113
  92. package/packages/selector/src/preset-overlay.ts +0 -749
  93. package/packages/selector/src/profiles.ts +0 -554
  94. package/packages/selector/src/pruner/content.ts +0 -199
  95. package/packages/selector/src/pruner/session.ts +0 -97
  96. package/packages/selector/src/pruner/state.ts +0 -61
  97. package/packages/selector/src/pruner/tuning.ts +0 -23
  98. package/packages/selector/src/pruner/types.ts +0 -78
  99. package/packages/selector/src/pruner.ts +0 -3222
  100. package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
  101. package/packages/selector/src/runtime/audit.ts +0 -321
  102. package/packages/selector/src/runtime/config.ts +0 -887
  103. package/packages/selector/src/runtime/custom-policy.ts +0 -300
  104. package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
  105. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
  106. package/packages/selector/src/runtime/display-prefs.ts +0 -98
  107. package/packages/selector/src/runtime/fold-router.ts +0 -143
  108. package/packages/selector/src/runtime/measurement.ts +0 -444
  109. package/packages/selector/src/runtime/monitor.ts +0 -341
  110. package/packages/selector/src/runtime/panel-command.ts +0 -213
  111. package/packages/selector/src/runtime/reducers.ts +0 -1755
  112. package/packages/selector/src/runtime/retrieve.ts +0 -505
  113. package/packages/selector/src/runtime/savings-integral.ts +0 -117
  114. package/packages/selector/src/runtime/savings-projection.ts +0 -229
  115. package/packages/selector/src/runtime/savings-verify.ts +0 -446
  116. package/packages/selector/src/runtime/savings.ts +0 -526
  117. package/packages/selector/src/runtime/sediment-card.ts +0 -126
  118. package/packages/selector/src/runtime/sediment-clock.ts +0 -87
  119. package/packages/selector/src/runtime/sediment-guard.ts +0 -136
  120. package/packages/selector/src/runtime/sediment-publish.ts +0 -144
  121. package/packages/selector/src/runtime/sediment-span.ts +0 -170
  122. package/packages/selector/src/runtime/sediment.ts +0 -209
  123. package/packages/selector/src/runtime/session-events.ts +0 -30
  124. package/packages/selector/src/runtime/session-file-decode.ts +0 -523
  125. package/packages/selector/src/runtime/shallow-tools.ts +0 -342
  126. package/packages/selector/src/runtime/stats-backfill.ts +0 -541
  127. package/packages/selector/src/runtime/stats-db.ts +0 -492
  128. package/packages/selector/src/runtime/stats-schema.ts +0 -123
  129. package/packages/selector/src/runtime/stats-sync.ts +0 -307
  130. package/packages/selector/src/runtime/summary-command.ts +0 -127
  131. package/packages/selector/src/runtime/tail-trim.ts +0 -177
  132. package/packages/selector/src/runtime/token-count.ts +0 -72
  133. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
  134. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
  135. package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
  136. package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
  137. package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -82
  138. package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
  139. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  140. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  141. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  142. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  143. package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -129
  144. package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
  145. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
  146. package/packages/selector/src/runtime/tool-names.ts +0 -42
  147. package/packages/selector/src/runtime/toolclass.ts +0 -103
  148. package/packages/selector/src/runtime/triage/masks.ts +0 -128
  149. package/packages/selector/src/runtime/triage/shallow.ts +0 -132
  150. package/packages/selector/src/runtime/triage/signals.ts +0 -167
  151. package/packages/selector/src/runtime/triage/types.ts +0 -125
  152. package/packages/selector/src/runtime/types.ts +0 -396
  153. package/packages/selector/src/runtime/value.ts +0 -48
  154. package/packages/selector/src/settings-bridge.ts +0 -175
  155. package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
  156. package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
  157. package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
  158. package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
  159. package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
  160. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
  161. package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
  162. package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
  163. package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
  164. package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
  165. package/packages/selector/tests/fab-pos.client.spec.ts +0 -47
  166. package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +0 -231
  167. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +0 -236
  168. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +0 -220
  169. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +0 -140
  170. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +0 -117
  171. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +0 -67
  172. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +0 -119
  173. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +0 -119
  174. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +0 -131
  175. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +0 -196
  176. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +0 -71
  177. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +0 -126
  178. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +0 -86
  179. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +0 -50
  180. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +0 -102
  181. package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
  182. package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
  183. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
  184. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
  185. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
  186. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
  187. package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
  188. package/packages/selector/tests/monitor-fab.client.spec.ts +0 -240
  189. package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
  190. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
  191. package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
  192. package/packages/selector/tests/profiles.client.spec.tsx +0 -436
  193. package/packages/selector/tests/ptc-custom-write.client.spec.ts +0 -86
  194. package/packages/selector/tests/public/package-contract.client.spec.ts +0 -89
  195. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
  196. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
  197. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
  198. package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
  199. package/packages/selector/tests/runtime/audit.spec.ts +0 -275
  200. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
  201. package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
  202. package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
  203. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
  204. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
  205. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
  206. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
  207. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
  208. package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
  209. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
  210. package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
  211. package/packages/selector/tests/runtime/fold-router.spec.ts +0 -140
  212. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
  213. package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
  214. package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
  215. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  216. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  217. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
  218. package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
  219. package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
  220. package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
  221. package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
  222. package/packages/selector/tests/runtime/ptc-profile.spec.ts +0 -133
  223. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2795
  224. package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
  225. package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
  226. package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
  227. package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
  228. package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
  229. package/packages/selector/tests/runtime/savings.spec.ts +0 -139
  230. package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
  231. package/packages/selector/tests/runtime/sediment-card.spec.ts +0 -111
  232. package/packages/selector/tests/runtime/sediment-config.spec.ts +0 -56
  233. package/packages/selector/tests/runtime/sediment-guard.spec.ts +0 -71
  234. package/packages/selector/tests/runtime/sediment-masks.spec.ts +0 -95
  235. package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +0 -166
  236. package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +0 -65
  237. package/packages/selector/tests/runtime/sediment-publish.spec.ts +0 -142
  238. package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +0 -158
  239. package/packages/selector/tests/runtime/sediment-settings.spec.ts +0 -73
  240. package/packages/selector/tests/runtime/sediment-signals.spec.ts +0 -124
  241. package/packages/selector/tests/runtime/sediment-span.spec.ts +0 -92
  242. package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
  243. package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
  244. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
  245. package/packages/selector/tests/runtime/shallow-primitives.spec.ts +0 -135
  246. package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
  247. package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
  248. package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -350
  249. package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
  250. package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
  251. package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
  252. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
  253. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
  254. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
  255. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
  256. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
  257. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
  258. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
  259. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -121
  260. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
  261. package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
  262. package/packages/selector/tests/runtime/value.spec.ts +0 -23
  263. package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
  264. package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
  265. package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
  266. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
  267. package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
  268. package/packages/selector/tests/support/mock-adapter.ts +0 -37
  269. package/packages/selector/tests/support/ui-primitives.tsx +0 -34
  270. package/packages/selector/tsconfig.json +0 -11
  271. package/packages/selector/tsdown.client.config.ts +0 -102
  272. package/packages/selector/tsdown.config.ts +0 -20
  273. package/pnpm-workspace.yaml +0 -76
  274. package/scripts/capture-profile-baseline.mjs +0 -42
  275. package/scripts/cell-browser-e2e.mjs +0 -354
  276. package/scripts/generate-tokenizer-fixtures.py +0 -81
  277. package/scripts/generate-vision-fixtures.py +0 -208
  278. package/scripts/hosts.d.mts +0 -3
  279. package/scripts/hosts.mjs +0 -81
  280. package/scripts/packed-components-smoke.mjs +0 -763
  281. package/scripts/packed-install-e2e.mjs +0 -1346
  282. package/scripts/sediment-latency-report.mjs +0 -63
  283. package/scripts/sync-hosts.mjs +0 -174
  284. package/scripts/toolclass-corpus-replay.mjs +0 -281
  285. package/scripts/verify-release.mjs +0 -343
  286. package/tests/TEST_INVENTORY.md +0 -41
  287. package/tsconfig.base.json +0 -18
  288. package/tsconfig.json +0 -7
  289. package/tsconfig.tests.json +0 -15
  290. package/vitest.built.config.ts +0 -9
  291. package/vitest.config.ts +0 -54
  292. /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  293. /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
  294. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
  295. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
  296. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  297. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  298. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  299. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  300. /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
  301. /package/{packages/selector/lib → lib}/client.d.ts +0 -0
  302. /package/{packages/selector/lib → lib}/client.js +0 -0
  303. /package/{packages/selector/lib → lib}/index.d.ts +0 -0
  304. /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
  305. /package/{packages/selector/lib → lib}/invariant.js +0 -0
  306. /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
  307. /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
  308. /package/{packages/selector/lib → lib}/pruner.js +0 -0
  309. /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
  310. /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
  311. /package/{packages/selector/lib → lib}/tool-result.js +0 -0
@@ -1,132 +0,0 @@
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
- }
@@ -1,167 +0,0 @@
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
- }
@@ -1,125 +0,0 @@
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
- }