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.
Files changed (310) 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} +2 -2
  5. package/{packages/selector/lib → lib}/index.js +101 -0
  6. package/package.json +129 -116
  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/docs/assets/context-compression-selector-profiles.jpg +0 -0
  36. package/docs/assets/context-compression-selector-settings.png +0 -0
  37. package/docs/compat-0.1.5-report.md +0 -77
  38. package/docs/installation.de.md +0 -104
  39. package/docs/installation.es.md +0 -104
  40. package/docs/installation.fr.md +0 -104
  41. package/docs/installation.it.md +0 -104
  42. package/docs/installation.ja.md +0 -78
  43. package/docs/installation.ko.md +0 -78
  44. package/docs/installation.md +0 -103
  45. package/docs/installation.ru.md +0 -104
  46. package/docs/installation.zh.md +0 -100
  47. package/docs/repair-log.md +0 -657
  48. package/docs/shallow-teaching-preset-template.md +0 -46
  49. package/eslint.config.js +0 -30
  50. package/packages/selector/LICENSE +0 -21
  51. package/packages/selector/README.md +0 -26
  52. package/packages/selector/README.zh.md +0 -24
  53. package/packages/selector/THIRD_PARTY_NOTICES.md +0 -32
  54. package/packages/selector/docs/history-tool-call-working-set-spec.md +0 -112
  55. package/packages/selector/docs/native-tool-result-selector-spec.md +0 -34
  56. package/packages/selector/docs/subagent-cache-reuse-spec.md +0 -46
  57. package/packages/selector/lib/style.css +0 -350
  58. package/packages/selector/package.json +0 -178
  59. package/packages/selector/screenshots.json +0 -3
  60. package/packages/selector/src/client/CompressionProfileControls.tsx +0 -352
  61. package/packages/selector/src/client/CompressionProfileSelector.module.css +0 -199
  62. package/packages/selector/src/client/CompressionProfileSelector.tsx +0 -89
  63. package/packages/selector/src/client/CustomPolicyEditor.tsx +0 -216
  64. package/packages/selector/src/client/EstimatorControls.tsx +0 -277
  65. package/packages/selector/src/client/bridge-scope.ts +0 -125
  66. package/packages/selector/src/client/decode.ts +0 -68
  67. package/packages/selector/src/client/fab-pos.ts +0 -71
  68. package/packages/selector/src/client/index.ts +0 -438
  69. package/packages/selector/src/client/locales/de.ts +0 -167
  70. package/packages/selector/src/client/locales/es.ts +0 -167
  71. package/packages/selector/src/client/locales/fr.ts +0 -167
  72. package/packages/selector/src/client/locales/it.ts +0 -167
  73. package/packages/selector/src/client/locales/ja.ts +0 -167
  74. package/packages/selector/src/client/locales/ko.ts +0 -167
  75. package/packages/selector/src/client/locales/ru.ts +0 -167
  76. package/packages/selector/src/client/locales.ts +0 -334
  77. package/packages/selector/src/client/monitor-fab.ts +0 -445
  78. package/packages/selector/src/client/preset-options.ts +0 -88
  79. package/packages/selector/src/client/savings-card.tsx +0 -269
  80. package/packages/selector/src/client/scope-face.ts +0 -24
  81. package/packages/selector/src/client/settings-section.tsx +0 -156
  82. package/packages/selector/src/compat/host-generation.ts +0 -96
  83. package/packages/selector/src/compat/llm-messages.ts +0 -50
  84. package/packages/selector/src/compat/settings-lease.ts +0 -108
  85. package/packages/selector/src/compat/tool-result.ts +0 -91
  86. package/packages/selector/src/css-modules.d.ts +0 -6
  87. package/packages/selector/src/deepseek-v4-tokenizer.ts +0 -205
  88. package/packages/selector/src/estimator-catalog.ts +0 -104
  89. package/packages/selector/src/index.ts +0 -890
  90. package/packages/selector/src/invariant.ts +0 -113
  91. package/packages/selector/src/preset-overlay.ts +0 -749
  92. package/packages/selector/src/profiles.ts +0 -554
  93. package/packages/selector/src/pruner/content.ts +0 -199
  94. package/packages/selector/src/pruner/session.ts +0 -97
  95. package/packages/selector/src/pruner/state.ts +0 -61
  96. package/packages/selector/src/pruner/tuning.ts +0 -23
  97. package/packages/selector/src/pruner/types.ts +0 -78
  98. package/packages/selector/src/pruner.ts +0 -3222
  99. package/packages/selector/src/runtime/adaptive-cost.ts +0 -205
  100. package/packages/selector/src/runtime/audit.ts +0 -321
  101. package/packages/selector/src/runtime/config.ts +0 -887
  102. package/packages/selector/src/runtime/custom-policy.ts +0 -300
  103. package/packages/selector/src/runtime/deepseek-official-pricing.ts +0 -298
  104. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +0 -254
  105. package/packages/selector/src/runtime/display-prefs.ts +0 -98
  106. package/packages/selector/src/runtime/fold-router.ts +0 -143
  107. package/packages/selector/src/runtime/measurement.ts +0 -444
  108. package/packages/selector/src/runtime/monitor.ts +0 -341
  109. package/packages/selector/src/runtime/panel-command.ts +0 -213
  110. package/packages/selector/src/runtime/reducers.ts +0 -1755
  111. package/packages/selector/src/runtime/retrieve.ts +0 -505
  112. package/packages/selector/src/runtime/savings-integral.ts +0 -117
  113. package/packages/selector/src/runtime/savings-projection.ts +0 -229
  114. package/packages/selector/src/runtime/savings-verify.ts +0 -446
  115. package/packages/selector/src/runtime/savings.ts +0 -526
  116. package/packages/selector/src/runtime/sediment-card.ts +0 -126
  117. package/packages/selector/src/runtime/sediment-clock.ts +0 -87
  118. package/packages/selector/src/runtime/sediment-guard.ts +0 -136
  119. package/packages/selector/src/runtime/sediment-publish.ts +0 -144
  120. package/packages/selector/src/runtime/sediment-span.ts +0 -170
  121. package/packages/selector/src/runtime/sediment.ts +0 -209
  122. package/packages/selector/src/runtime/session-events.ts +0 -30
  123. package/packages/selector/src/runtime/session-file-decode.ts +0 -523
  124. package/packages/selector/src/runtime/shallow-tools.ts +0 -342
  125. package/packages/selector/src/runtime/stats-backfill.ts +0 -541
  126. package/packages/selector/src/runtime/stats-db.ts +0 -492
  127. package/packages/selector/src/runtime/stats-schema.ts +0 -123
  128. package/packages/selector/src/runtime/stats-sync.ts +0 -307
  129. package/packages/selector/src/runtime/summary-command.ts +0 -127
  130. package/packages/selector/src/runtime/tail-trim.ts +0 -177
  131. package/packages/selector/src/runtime/token-count.ts +0 -72
  132. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +0 -233
  133. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +0 -204
  134. package/packages/selector/src/runtime/tokenpilot/advisor.ts +0 -419
  135. package/packages/selector/src/runtime/tokenpilot/benefit.ts +0 -200
  136. package/packages/selector/src/runtime/tokenpilot/dedup.ts +0 -82
  137. package/packages/selector/src/runtime/tokenpilot/estimator.ts +0 -151
  138. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +0 -53
  139. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +0 -65
  140. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +0 -125
  141. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +0 -37
  142. package/packages/selector/src/runtime/tokenpilot/locator.ts +0 -129
  143. package/packages/selector/src/runtime/tokenpilot/read-state.ts +0 -98
  144. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +0 -303
  145. package/packages/selector/src/runtime/tool-names.ts +0 -42
  146. package/packages/selector/src/runtime/toolclass.ts +0 -103
  147. package/packages/selector/src/runtime/triage/masks.ts +0 -128
  148. package/packages/selector/src/runtime/triage/shallow.ts +0 -132
  149. package/packages/selector/src/runtime/triage/signals.ts +0 -167
  150. package/packages/selector/src/runtime/triage/types.ts +0 -125
  151. package/packages/selector/src/runtime/types.ts +0 -396
  152. package/packages/selector/src/runtime/value.ts +0 -48
  153. package/packages/selector/src/settings-bridge.ts +0 -175
  154. package/packages/selector/tests/advisor-report.host.spec.ts +0 -223
  155. package/packages/selector/tests/auto-compact.client.spec.tsx +0 -214
  156. package/packages/selector/tests/built/client-artifact.spec.ts +0 -56
  157. package/packages/selector/tests/cache-prefix-audit.spec.ts +0 -123
  158. package/packages/selector/tests/code-skeleton.client.spec.ts +0 -98
  159. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +0 -150
  160. package/packages/selector/tests/custom-contract.client.spec.ts +0 -226
  161. package/packages/selector/tests/estimator-catalog.spec.ts +0 -70
  162. package/packages/selector/tests/estimator-channel.client.spec.tsx +0 -253
  163. package/packages/selector/tests/estimator-route-registration.host.spec.ts +0 -202
  164. package/packages/selector/tests/fab-pos.client.spec.ts +0 -47
  165. package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +0 -231
  166. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +0 -236
  167. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +0 -220
  168. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +0 -140
  169. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +0 -117
  170. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +0 -67
  171. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +0 -119
  172. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +0 -119
  173. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +0 -131
  174. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +0 -196
  175. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +0 -71
  176. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +0 -126
  177. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +0 -86
  178. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +0 -50
  179. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +0 -102
  180. package/packages/selector/tests/helpers/legacy-namespace.ts +0 -35
  181. package/packages/selector/tests/helpers/legacy-settings/index.ts +0 -15
  182. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +0 -41
  183. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +0 -647
  184. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +0 -78
  185. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +0 -234
  186. package/packages/selector/tests/host-preset-overlay.host.spec.ts +0 -204
  187. package/packages/selector/tests/monitor-fab.client.spec.ts +0 -240
  188. package/packages/selector/tests/preset-options-write.client.spec.ts +0 -192
  189. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +0 -200
  190. package/packages/selector/tests/preset-overlay.host.spec.ts +0 -246
  191. package/packages/selector/tests/profiles.client.spec.tsx +0 -436
  192. package/packages/selector/tests/ptc-custom-write.client.spec.ts +0 -86
  193. package/packages/selector/tests/public/package-contract.client.spec.ts +0 -89
  194. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +0 -167
  195. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +0 -230
  196. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +0 -272
  197. package/packages/selector/tests/runtime/advisor.spec.ts +0 -226
  198. package/packages/selector/tests/runtime/audit.spec.ts +0 -275
  199. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +0 -523
  200. package/packages/selector/tests/runtime/char-basis.spec.ts +0 -30
  201. package/packages/selector/tests/runtime/code-skeleton.spec.ts +0 -152
  202. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +0 -186
  203. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +0 -122
  204. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +0 -122
  205. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +0 -96
  206. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +0 -273
  207. package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +0 -46
  208. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +0 -106
  209. package/packages/selector/tests/runtime/fixtures/vision-golden.json +0 -459
  210. package/packages/selector/tests/runtime/fold-router.spec.ts +0 -140
  211. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +0 -74
  212. package/packages/selector/tests/runtime/fresh-gate.spec.ts +0 -43
  213. package/packages/selector/tests/runtime/html-reducer.spec.ts +0 -212
  214. package/packages/selector/tests/runtime/intent-gate.spec.ts +0 -62
  215. package/packages/selector/tests/runtime/intent-summary.spec.ts +0 -156
  216. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +0 -79
  217. package/packages/selector/tests/runtime/line-mapping.spec.ts +0 -153
  218. package/packages/selector/tests/runtime/monitor.spec.ts +0 -354
  219. package/packages/selector/tests/runtime/panel-command.spec.ts +0 -101
  220. package/packages/selector/tests/runtime/prose-reducers.spec.ts +0 -133
  221. package/packages/selector/tests/runtime/ptc-profile.spec.ts +0 -133
  222. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +0 -2795
  223. package/packages/selector/tests/runtime/read-input-cap.spec.ts +0 -33
  224. package/packages/selector/tests/runtime/savings-accounting.spec.ts +0 -291
  225. package/packages/selector/tests/runtime/savings-integral.spec.ts +0 -169
  226. package/packages/selector/tests/runtime/savings-projection.spec.ts +0 -89
  227. package/packages/selector/tests/runtime/savings-verify.spec.ts +0 -226
  228. package/packages/selector/tests/runtime/savings.spec.ts +0 -139
  229. package/packages/selector/tests/runtime/search-reducer.spec.ts +0 -110
  230. package/packages/selector/tests/runtime/sediment-card.spec.ts +0 -111
  231. package/packages/selector/tests/runtime/sediment-config.spec.ts +0 -56
  232. package/packages/selector/tests/runtime/sediment-guard.spec.ts +0 -71
  233. package/packages/selector/tests/runtime/sediment-masks.spec.ts +0 -95
  234. package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +0 -166
  235. package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +0 -65
  236. package/packages/selector/tests/runtime/sediment-publish.spec.ts +0 -142
  237. package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +0 -158
  238. package/packages/selector/tests/runtime/sediment-settings.spec.ts +0 -73
  239. package/packages/selector/tests/runtime/sediment-signals.spec.ts +0 -124
  240. package/packages/selector/tests/runtime/sediment-span.spec.ts +0 -92
  241. package/packages/selector/tests/runtime/session-events.spec.ts +0 -27
  242. package/packages/selector/tests/runtime/session-file-decode.spec.ts +0 -281
  243. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +0 -58
  244. package/packages/selector/tests/runtime/shallow-primitives.spec.ts +0 -135
  245. package/packages/selector/tests/runtime/sidechannel.spec.ts +0 -241
  246. package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +0 -167
  247. package/packages/selector/tests/runtime/stats-backfill.spec.ts +0 -350
  248. package/packages/selector/tests/runtime/stats-db.spec.ts +0 -361
  249. package/packages/selector/tests/runtime/stats-privacy.spec.ts +0 -55
  250. package/packages/selector/tests/runtime/stats-sync.spec.ts +0 -278
  251. package/packages/selector/tests/runtime/summary-command.spec.ts +0 -154
  252. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +0 -159
  253. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +0 -53
  254. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +0 -217
  255. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +0 -52
  256. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +0 -79
  257. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +0 -76
  258. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +0 -121
  259. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +0 -82
  260. package/packages/selector/tests/runtime/toolclass.spec.ts +0 -156
  261. package/packages/selector/tests/runtime/value.spec.ts +0 -23
  262. package/packages/selector/tests/savings-sessions.client.spec.tsx +0 -140
  263. package/packages/selector/tests/settings-seat.client.spec.ts +0 -215
  264. package/packages/selector/tests/standing-generation.host.spec.ts +0 -724
  265. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +0 -269
  266. package/packages/selector/tests/support/cache-prefix-audit.ts +0 -105
  267. package/packages/selector/tests/support/mock-adapter.ts +0 -37
  268. package/packages/selector/tests/support/ui-primitives.tsx +0 -34
  269. package/packages/selector/tsconfig.json +0 -11
  270. package/packages/selector/tsdown.client.config.ts +0 -102
  271. package/packages/selector/tsdown.config.ts +0 -20
  272. package/pnpm-workspace.yaml +0 -76
  273. package/scripts/capture-profile-baseline.mjs +0 -42
  274. package/scripts/cell-browser-e2e.mjs +0 -354
  275. package/scripts/generate-tokenizer-fixtures.py +0 -81
  276. package/scripts/generate-vision-fixtures.py +0 -208
  277. package/scripts/hosts.d.mts +0 -3
  278. package/scripts/hosts.mjs +0 -79
  279. package/scripts/packed-components-smoke.mjs +0 -763
  280. package/scripts/packed-install-e2e.mjs +0 -1346
  281. package/scripts/sediment-latency-report.mjs +0 -63
  282. package/scripts/sync-hosts.mjs +0 -174
  283. package/scripts/toolclass-corpus-replay.mjs +0 -281
  284. package/scripts/verify-release.mjs +0 -343
  285. package/tests/TEST_INVENTORY.md +0 -41
  286. package/tsconfig.base.json +0 -18
  287. package/tsconfig.json +0 -7
  288. package/tsconfig.tests.json +0 -15
  289. package/vitest.built.config.ts +0 -9
  290. package/vitest.config.ts +0 -54
  291. /package/{packages/selector/assets → assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  292. /package/{packages/selector/assets → assets}/deepseek-v4/manifest.json +0 -0
  293. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer.json +0 -0
  294. /package/{packages/selector/assets → assets}/deepseek-v4/tokenizer_config.json +0 -0
  295. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  296. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  297. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  298. /package/{packages/selector/assets → assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  299. /package/{packages/selector/cordis.patch.yml → cordis.patch.yml} +0 -0
  300. /package/{packages/selector/lib → lib}/client.d.ts +0 -0
  301. /package/{packages/selector/lib → lib}/client.js +0 -0
  302. /package/{packages/selector/lib → lib}/index.d.ts +0 -0
  303. /package/{packages/selector/lib → lib}/invariant.d.ts +0 -0
  304. /package/{packages/selector/lib → lib}/invariant.js +0 -0
  305. /package/{packages/selector/lib → lib}/profiles.d.ts +0 -0
  306. /package/{packages/selector/lib → lib}/pruner.d.ts +0 -0
  307. /package/{packages/selector/lib → lib}/pruner.js +0 -0
  308. /package/{packages/selector/lib → lib}/savings-integral.js +0 -0
  309. /package/{packages/selector/lib → lib}/tail-trim.js +0 -0
  310. /package/{packages/selector/lib → lib}/tool-result.js +0 -0
@@ -1,87 +0,0 @@
1
- /**
2
- * Sediment commit clock (plan cci-sedimentation-triage, Phase 3, T3.4).
3
- *
4
- * Decides WHEN a prepared card may touch the surface. The predicate is the
5
- * event-sequence form from the plan (R7/T3.4): commit only in the quiet seam
6
- * after `step/end` or `turn/end`, never with an in-flight request, never
7
- * inside a compaction lifecycle, never on the first batch after resume, and
8
- * yielding exactly once to a freshly landed official checkpoint (spine's
9
- * seen-seq cooldown, adopted verbatim in behavior).
10
- *
11
- * Per-session state lives in `SedimentClock` instances — one agent's cooldown
12
- * must never leak into another's (same discipline as the engine's session
13
- * state map).
14
- */
15
-
16
- export interface CommitContext {
17
- /** Type of the most recent surface event, e.g. 'turn/end' | 'step/end' | 'request/header'. */
18
- readonly lastEventType: string | undefined
19
- /** A request was dispatched for the current step and has not settled. */
20
- readonly inFlightRequest: boolean
21
- /** Between `compaction/start` and `compaction/end`. */
22
- readonly compactionOpen: boolean
23
- /** Seq of the newest official `compact-checkpoint` on the surface, if any. */
24
- readonly officialCheckpointSeq: number | undefined
25
- /** Seq of the official checkpoint this session already yielded to once. */
26
- readonly seenOfficialCheckpointSeq: number | undefined
27
- /** First commit window after a cold resume — replay paths are still settling. */
28
- readonly resumeFirstBatch: boolean
29
- }
30
-
31
- export interface CommitDecision {
32
- readonly ok: boolean
33
- readonly reason: string
34
- }
35
-
36
- /** Pure commit predicate; every exclusion returns a machine-readable reason. */
37
- export function canCommitNow(context: CommitContext): CommitDecision {
38
- if (!context.inFlightRequest
39
- && context.lastEventType !== 'turn/end'
40
- && context.lastEventType !== 'step/end') {
41
- return { ok: false, reason: 'not-in-quiet-seam' }
42
- }
43
- if (context.inFlightRequest) return { ok: false, reason: 'request-in-flight' }
44
- if (context.compactionOpen) return { ok: false, reason: 'compaction-in-progress' }
45
- if (context.resumeFirstBatch) return { ok: false, reason: 'resume-first-batch' }
46
- const official = context.officialCheckpointSeq
47
- if (official !== undefined && official !== context.seenOfficialCheckpointSeq) {
48
- return { ok: false, reason: `yield-official-checkpoint-${official}` }
49
- }
50
- return { ok: true, reason: 'quiet-seam' }
51
- }
52
-
53
- /** Mutable per-session clock: cooldown consumption + re-entrance guard. */
54
- export class SedimentClock {
55
- private warming = false
56
- private seenOfficialSeq: number | undefined
57
-
58
- /** True while a commit job is running for this session (no stacked cuts). */
59
- get busy(): boolean {
60
- return this.warming
61
- }
62
-
63
- /** Claim the commit slot; false means another job owns this session's seam. */
64
- begin(): boolean {
65
- if (this.warming) return false
66
- this.warming = true
67
- return true
68
- }
69
-
70
- end(): void {
71
- this.warming = false
72
- }
73
-
74
- /** Consume the one-time yield for the given official checkpoint seq. */
75
- noteOfficialConsumed(seq: number): void {
76
- this.seenOfficialSeq = seq
77
- }
78
-
79
- get seenOfficial(): number | undefined {
80
- return this.seenOfficialSeq
81
- }
82
-
83
- /** Decide with this clock's cooldown state folded in. */
84
- decide(base: Omit<CommitContext, 'seenOfficialCheckpointSeq'>): CommitDecision {
85
- return canCommitNow({ ...base, seenOfficialCheckpointSeq: this.seenOfficialSeq })
86
- }
87
- }
@@ -1,136 +0,0 @@
1
- /**
2
- * PTC downgrade guard (plan cci-sedimentation-triage, Phase 3, T3.10/T3.11).
3
- *
4
- * Two decisions live here as pure functions, unit-tested before any wiring:
5
- * 1. PTC-mode detection — registration truth via the omnibus tool names
6
- * (`run_code` on 0.1.x, `code_run` on 0.2.x), never wire literal guessing;
7
- * 2. the negative-feedback loop — when net savings stay negative across K
8
- * request boundaries (the community 1:15 / HUD -24,035 shape), fall back
9
- * to conservative mode: aging decisions OFF, only fresh large-block cuts.
10
- *
11
- * The WRITE_TOOLS blindness probe encodes the root cause directly: in PTC,
12
- * write operations fold into run_code bodies, so the regex-based read-state
13
- * predicate sees zero hits and its "superseded" verdicts are untrustworthy.
14
- */
15
- import type { SedimentSettings } from './types.ts'
16
-
17
- /** Omnibus tool names that mark a PTC/code-mode session (both host lines). */
18
- export const OMNIBUS_TOOL_NAMES: readonly string[] = Object.freeze(['run_code', 'code_run'])
19
-
20
- /** Conservative fallback mode: aging-style decisions disabled. */
21
- export interface ConservativeMode {
22
- readonly conservative: boolean
23
- readonly reason: string
24
- }
25
-
26
- /** True when the registered tool surface contains an omnibus runner. */
27
- export function detectPtcMode(hasTool: (name: string) => boolean): boolean {
28
- return OMNIBUS_TOOL_NAMES.some(name => hasTool(name))
29
- }
30
-
31
- /**
32
- * read-state blindness probe: with PTC active and ZERO write-tool regex hits
33
- * across the observed calls, the superseded predicate cannot see real write
34
- * targets — aging decisions must be considered untrustworthy.
35
- */
36
- export function readStateBlind(ptcActive: boolean, writeRegexHits: number, observedCalls: number): boolean {
37
- if (!ptcActive) return false
38
- return observedCalls > 0 && writeRegexHits === 0
39
- }
40
-
41
- export interface NetSample {
42
- readonly grossSaved: number
43
- readonly recallOffset: number
44
- }
45
-
46
- /**
47
- * Feedback loop state: consumes request-boundary samples and decides whether
48
- * sediment/aging operation should run in conservative mode. K consecutive
49
- * negative-net samples arm it; a positive net sample disarms immediately.
50
- */
51
- export class FeedbackLoop {
52
- private negativeStreak = 0
53
- private armed = false
54
-
55
- constructor(private readonly k: number = 5) {}
56
-
57
- get conservative(): boolean {
58
- return this.armed
59
- }
60
-
61
- observe(sample: NetSample): ConservativeMode {
62
- const net = sample.grossSaved - sample.recallOffset
63
- if (net < 0) {
64
- this.negativeStreak += 1
65
- if (this.negativeStreak >= this.k) this.armed = true
66
- } else if (net > 0) {
67
- this.negativeStreak = 0
68
- this.armed = false
69
- }
70
- return {
71
- conservative: this.armed,
72
- reason: this.armed ? `net-negative-x${this.negativeStreak}` : 'ok',
73
- }
74
- }
75
- }
76
-
77
- /**
78
- * Watcher adapter (T3.11 consumption point): the savings ledger reports
79
- * CUMULATIVE gross/offsets; the feedback loop needs per-boundary NET deltas.
80
- * This wrapper remembers the last reading and feeds the loop the difference.
81
- */
82
- export class SedimentFeedbackWatcher {
83
- private last: { gross: number; offsets: number } = { gross: 0, offsets: 0 }
84
-
85
- constructor(private readonly loop: FeedbackLoop = new FeedbackLoop(5)) {}
86
-
87
- observe(totals: { gross: { exact: number, estimated: number }, offsets: { exact: number, estimated: number } }): ConservativeMode {
88
- const gross = totals.gross.exact + totals.gross.estimated
89
- const offsets = totals.offsets.exact + totals.offsets.estimated
90
- const sample = {
91
- grossSaved: gross - this.last.gross,
92
- recallOffset: offsets - this.last.offsets,
93
- }
94
- this.last = { gross, offsets }
95
- return this.loop.observe(sample)
96
- }
97
-
98
- get conservative(): boolean {
99
- return this.loop.conservative
100
- }
101
- }
102
-
103
- /**
104
- * Effective sediment behavior for one session after the PTC guard is folded
105
- * in: in PTC mode, aging-style decisions short-circuit and the rewrite guard
106
- * ratio tightens; the card pipeline itself (mask/pool/pointer) is unaffected.
107
- */
108
- export function effectiveSedimentMode(
109
- settings: SedimentSettings,
110
- ptcActive: boolean,
111
- blindReadState: boolean,
112
- feedback: ConservativeMode,
113
- ): {
114
- readonly enabled: boolean
115
- readonly agingAllowed: boolean
116
- readonly rewriteGuardRatio: number
117
- readonly reason: string
118
- } {
119
- if (!settings.enabled) {
120
- return { enabled: false, agingAllowed: false, rewriteGuardRatio: settings.rewriteGuardRatio, reason: 'disabled' }
121
- }
122
- const agingAllowed = !(ptcActive && blindReadState) && !feedback.conservative
123
- const rewriteGuardRatio = ptcActive || feedback.conservative
124
- ? Math.max(settings.rewriteGuardRatio, 5)
125
- : settings.rewriteGuardRatio
126
- return {
127
- enabled: true,
128
- agingAllowed,
129
- rewriteGuardRatio,
130
- reason: feedback.conservative
131
- ? `conservative:${feedback.reason}`
132
- : ptcActive && blindReadState
133
- ? 'ptc-blind-aging-off'
134
- : 'normal',
135
- }
136
- }
@@ -1,144 +0,0 @@
1
- /**
2
- * Sediment publication (plan cci-sedimentation-triage, Phase 3, T3.5/T3.6).
3
- *
4
- * The commit transaction mirrors the proven TailTrim publication shape
5
- * (pruner.ts L2386-2406): a `compaction/prune` manifest event, then ONE
6
- * `user/message` replacement carrying `surfaceOp: replace` and
7
- * `sourceEventSeqs`, through the generation-gated message builder so 0.1.x
8
- * and 0.2.x hosts accept the same code path. The shortening proof (M7) runs
9
- * BEFORE any append — a card that does not shrink the span is refused, and
10
- * nothing half-committed can exist.
11
- *
12
- * The session is injected as a minimal interface so the transaction is
13
- * unit-testable without a host; the wiring site passes the real session.
14
- */
15
- import { tailTrimMessage } from './tail-trim.ts'
16
- import { renderTurnCard } from './sediment-card.ts'
17
- import type { TurnCardDraft } from './triage/types.ts'
18
-
19
- export interface PublishTarget {
20
- append(type: 'compaction/prune', data: Record<string, unknown>): { seq: number }
21
- append(type: 'user/message', message: unknown, options?: Record<string, unknown>): { seq: number }
22
- }
23
-
24
- export interface PublishResult {
25
- readonly ok: boolean
26
- readonly reason: string
27
- readonly manifestSeq?: number
28
- readonly replacementSeq?: number
29
- }
30
-
31
- export interface PublishSpan {
32
- readonly startSeq: number
33
- readonly endSeq: number
34
- readonly shadowedSeqs: readonly number[]
35
- }
36
-
37
- /** Commit one card over the span. Never throws; every failure is a reason code. */
38
- export function publishSettledCard(
39
- session: PublishTarget,
40
- draft: TurnCardDraft,
41
- span: PublishSpan,
42
- ): PublishResult {
43
- if (draft.retainedTokens >= draft.sourceTokens) {
44
- return { ok: false, reason: `shortening-proof-failed:${draft.retainedTokens}>=${draft.sourceTokens}` }
45
- }
46
- if (span.shadowedSeqs.length === 0) {
47
- return { ok: false, reason: 'empty-span' }
48
- }
49
- const manifest = session.append('compaction/prune', {
50
- shadowedRange: { start: span.startSeq, end: span.endSeq },
51
- shadowedSeqs: [...span.shadowedSeqs],
52
- shadowedTokenCount: draft.sourceTokens,
53
- })
54
- let replacementSeq: number
55
- try {
56
- const message = tailTrimMessage(renderTurnCard(draft))
57
- replacementSeq = session.append('user/message', message, {
58
- surfaceOp: { op: 'replace', startSeq: span.startSeq, endSeq: span.endSeq },
59
- sourceEventSeqs: [manifest.seq, ...span.shadowedSeqs],
60
- }).seq
61
- } catch (error) {
62
- // The manifest stands alone (same tolerated state as TailTrim publication
63
- // failure: an append without replacement is inert on the surface).
64
- return { ok: false, reason: `publication-failed:${error instanceof Error ? error.message : String(error)}`, manifestSeq: manifest.seq }
65
- }
66
- return { ok: true, reason: 'landed', manifestSeq: manifest.seq, replacementSeq }
67
- }
68
-
69
- /**
70
- * Rewrite guard (T3.3 accounting, findings F2 community 1:15 evidence):
71
- * a cut may only land when its saving clears the estimated cached-tail
72
- * rewrite cost by the configured ratio. Pure function over token counts.
73
- */
74
- export function passesRewriteGuard(
75
- draft: TurnCardDraft,
76
- rewriteTailTokens: number,
77
- ratio: number,
78
- ): boolean {
79
- const saving = draft.sourceTokens - draft.retainedTokens
80
- return saving > 0 && saving >= rewriteTailTokens * ratio
81
- }
82
-
83
- /**
84
- * Project a host session event into the minimal `SurfaceEvent` the span
85
- * planner consumes. Kept separate from the planner so the planner stays
86
- * host-type-free; the wiring site supplies the call-id → name/args map.
87
- */
88
- export function projectSurfaceEvent(
89
- seq: number,
90
- event: {
91
- type: string
92
- data?: {
93
- message?: { content?: unknown; toolCallId?: string; isError?: boolean }
94
- content?: unknown
95
- reason?: { kind?: string }
96
- }
97
- },
98
- callInfo: { name: string; argsJson: string } | undefined,
99
- ): import('./sediment-span.ts').SurfaceEvent | null {
100
- const text = flattenText(event.data?.message?.content ?? event.data?.content)
101
- switch (event.type) {
102
- case 'user/message':
103
- return { seq, type: 'user/message', text }
104
- case 'assistant/message': {
105
- const toolCalls = countToolCallBlocks(event.data?.message?.content)
106
- return { seq, type: 'assistant/message', text: stripToolCallBlocks(text), toolCalls }
107
- }
108
- case 'tool/result':
109
- return {
110
- seq,
111
- type: 'tool/result',
112
- text,
113
- ...(callInfo === undefined ? {} : { toolName: callInfo.name, argsJson: callInfo.argsJson }),
114
- isError: event.data?.message?.isError === true,
115
- }
116
- case 'turn/end': {
117
- const reasonKind = event.data?.reason?.kind
118
- return { seq, type: 'turn/end', text: '', ...(reasonKind === undefined ? {} : { reasonKind }) }
119
- }
120
- default:
121
- return null
122
- }
123
- }
124
-
125
- function blockText(block: unknown): string {
126
- if (block === null || typeof block !== 'object') return ''
127
- const record = block as Record<string, unknown>
128
- return typeof record.text === 'string' ? record.text : ''
129
- }
130
-
131
- function flattenText(content: unknown): string {
132
- if (typeof content === 'string') return content
133
- if (Array.isArray(content)) return content.map(blockText).filter(entry => entry !== '').join('\n')
134
- return ''
135
- }
136
-
137
- function countToolCallBlocks(content: unknown): number {
138
- if (!Array.isArray(content)) return 0
139
- return content.filter(block => (block as Record<string, unknown> | null)?.type === 'tool-call').length
140
- }
141
-
142
- function stripToolCallBlocks(text: string): string {
143
- return text // blocks already filtered by blockText (tool-call blocks carry no .text)
144
- }
@@ -1,170 +0,0 @@
1
- /**
2
- * Whole-turn span planning (plan cci-sedimentation-triage, Phase 3, T3.3).
3
- *
4
- * Pure function over a minimal projected event list (the wiring site adapts
5
- * real session events to `SurfaceEvent`). Decisions made here:
6
- * - reason gate (R13①): only turns that ended `completed` are replaceable;
7
- * - tail-kept region (R13③): the last `tailRoundsKept` tool rounds stay
8
- * verbatim on the surface — the replacement span ends before them;
9
- * - closing extraction: the last tool-call-free assistant text is the
10
- * candidate closing body for the qualification gate;
11
- * - the span covers contiguous assistant/tool events after the turn's user
12
- * message; a span with no maskable/replaceable block returns null.
13
- *
14
- * Turn boundaries make cross-turn pairing checks unnecessary (rounds close
15
- * inside their turn), which is the whole-turn granularity's main simplification.
16
- */
17
- import type { TriageResult } from './triage/types.ts'
18
- import { blockFailureVerdict, linePool, type LineRule } from './triage/signals.ts'
19
- import { manifestFromCall, skeletonFromRead } from './triage/masks.ts'
20
- import { estimateTokens } from './sediment-card.ts'
21
-
22
- /** Minimal projected event the wiring site must provide per surface node. */
23
- export interface SurfaceEvent {
24
- readonly seq: number
25
- readonly type: 'user/message' | 'assistant/message' | 'tool/result' | 'turn/end'
26
- readonly text: string
27
- /** tool-call block count on an assistant message (0 otherwise). */
28
- readonly toolCalls?: number
29
- /** Resolved tool name for a tool/result (call-id lookup done by the wiring site). */
30
- readonly toolName?: string
31
- /** Raw arguments JSON for the call owning a tool/result. */
32
- readonly argsJson?: string
33
- readonly isError?: boolean
34
- /** `turn/end` reason kind, e.g. 'completed' | 'interrupted'. */
35
- readonly reasonKind?: string
36
- }
37
-
38
- export interface TurnSpanPlan {
39
- readonly completed: boolean
40
- /** Inclusive replacement span; null when nothing is replaceable. */
41
- readonly startSeq: number | null
42
- readonly endSeq: number | null
43
- /** Events inside the span (assistant/tool), in order. */
44
- readonly blocks: readonly SurfaceEvent[]
45
- /** The turn's closing body (last tool-call-free assistant text after the span). */
46
- readonly closingText: string
47
- /** Kept-verbatim seqs: user messages, tail rounds, closing — never in the span. */
48
- readonly keptSeqs: readonly number[]
49
- }
50
-
51
- export interface TurnSpanOptions {
52
- readonly tailRoundsKept?: number
53
- }
54
-
55
- interface Round { readonly start: number; readonly end: number }
56
-
57
- /** Close tool rounds over the projected events (open-stack, same shape as the replay harness). */
58
- function closeRounds(events: readonly SurfaceEvent[]): Round[] {
59
- const rounds: Round[] = []
60
- let open = 0
61
- let start = -1
62
- for (const event of events) {
63
- const calls = event.type === 'assistant/message' ? event.toolCalls ?? 0 : 0
64
- if (calls > 0) {
65
- if (open === 0) start = events.indexOf(event)
66
- open += calls
67
- continue
68
- }
69
- if (event.type !== 'tool/result') continue
70
- if (open <= 0) continue
71
- open -= 1
72
- if (open === 0 && start >= 0) {
73
- rounds.push({ start, end: events.indexOf(event) })
74
- start = -1
75
- }
76
- }
77
- return rounds
78
- }
79
-
80
- /** Plan the replacement span for one turn's projected events. */
81
- export function planTurnSpan(events: readonly SurfaceEvent[], options: TurnSpanOptions = {}): TurnSpanPlan {
82
- const tailRoundsKept = options.tailRoundsKept ?? 1
83
- const turnEnd = events.find(event => event.type === 'turn/end')
84
- const completed = turnEnd?.reasonKind === 'completed'
85
- const body = events.filter(event => event.type !== 'turn/end')
86
- const keptSeqs: number[] = body.filter(event => event.type === 'user/message').map(event => event.seq)
87
-
88
- const rounds = closeRounds(body)
89
- // Closing body: last assistant text without tool-calls, after the last closed round.
90
- const lastRoundEnd = rounds.length > 0 ? (rounds[rounds.length - 1] as Round).end : -1
91
- let closingText = ''
92
- let closingIndex = -1
93
- for (let index = body.length - 1; index > lastRoundEnd; index -= 1) {
94
- const event = body[index]
95
- if (event === undefined) continue
96
- if (event.type === 'assistant/message' && (event.toolCalls ?? 0) === 0 && event.text.trim() !== '') {
97
- closingText = event.text.trim()
98
- closingIndex = index
99
- keptSeqs.push(event.seq)
100
- break
101
- }
102
- }
103
-
104
- // Tail-kept rounds: last `tailRoundsKept` rounds stay verbatim.
105
- const keptRounds = tailRoundsKept > 0 ? rounds.slice(Math.max(0, rounds.length - tailRoundsKept)) : []
106
- for (const round of keptRounds) {
107
- for (let index = round.start; index <= round.end; index += 1) {
108
- const event = body[index]
109
- if (event !== undefined) keptSeqs.push(event.seq)
110
- }
111
- }
112
-
113
- // Replacement span: from the first replaceable event up to the kept boundary.
114
- // The closing body is never inside the span (it stays verbatim on the surface).
115
- const firstIndex = body.findIndex(event => event.type === 'assistant/message' || event.type === 'tool/result')
116
- const keptStartIndex = keptRounds.length > 0
117
- ? (keptRounds[0] as Round).start
118
- : closingIndex >= 0 ? closingIndex : body.length
119
- const spanEndIndex = Math.max(firstIndex, keptStartIndex) - 1
120
- const replaceable = firstIndex >= 0 && spanEndIndex >= firstIndex
121
- const blocks = replaceable ? body.slice(firstIndex, spanEndIndex + 1) : []
122
-
123
- return {
124
- completed,
125
- startSeq: replaceable ? (blocks[0] as SurfaceEvent).seq : null,
126
- endSeq: replaceable ? (blocks[blocks.length - 1] as SurfaceEvent).seq : null,
127
- blocks,
128
- closingText,
129
- keptSeqs,
130
- }
131
- }
132
-
133
- /** Triage every block of a planned span into the frozen TriageResult shape. */
134
- export function triageSpanBlocks(
135
- plan: TurnSpanPlan,
136
- rules: readonly LineRule[],
137
- ): TriageResult[] {
138
- return plan.blocks.map(event => {
139
- const sourceTokens = estimateTokens(event.text)
140
- if (event.type === 'tool/result') {
141
- const verdict = blockFailureVerdict(event.text, event.isError === true)
142
- const poolLines = linePool(event.text, {
143
- seq: event.seq,
144
- role: 'tool',
145
- hardFailure: verdict.hard,
146
- extraPatterns: rules,
147
- })
148
- const mask = manifestFromCall(event.toolName ?? '', event.argsJson ?? '', event.text, event.seq)
149
- ?? (event.toolName !== undefined && /^(read|read_file|view)$/i.test(event.toolName)
150
- ? skeletonFromRead(event.text, event.seq)
151
- : null)
152
- const residualNarrative = poolLines.length === 0 && mask === null && event.text.trim() !== ''
153
- ? [{ seq: event.seq, role: 'tool' as const, tokens: sourceTokens, text: event.text }]
154
- : []
155
- return { poolLines, ...(mask === null ? {} : { mask }), residualNarrative, sourceTokens }
156
- }
157
- // Assistant text inside the span: pool-check it (assertion lines occur here too).
158
- const verdict = blockFailureVerdict(event.text, false)
159
- const poolLines = linePool(event.text, {
160
- seq: event.seq,
161
- role: 'assistant',
162
- hardFailure: verdict.hard,
163
- extraPatterns: rules,
164
- })
165
- const residualNarrative = poolLines.length === 0
166
- ? [{ seq: event.seq, role: 'assistant' as const, tokens: sourceTokens, text: event.text }]
167
- : []
168
- return { poolLines, residualNarrative, sourceTokens }
169
- })
170
- }