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.
Files changed (310) hide show
  1. package/.agents/plans/improve/checklist.md +32 -0
  2. package/.agents/plans/improve/findings.md +102 -0
  3. package/.agents/plans/improve/spec.md +53 -0
  4. package/.agents/plans/improve/tasks.md +70 -0
  5. package/.gitattributes +2 -0
  6. package/.githooks/pre-push +37 -0
  7. package/.github/workflows/ci.yml +47 -0
  8. package/CHANGELOG.de.md +580 -0
  9. package/CHANGELOG.es.md +588 -0
  10. package/CHANGELOG.fr.md +576 -0
  11. package/CHANGELOG.it.md +577 -0
  12. package/CHANGELOG.ja.md +261 -0
  13. package/CHANGELOG.ko.md +254 -0
  14. package/CHANGELOG.md +557 -0
  15. package/CHANGELOG.ru.md +554 -0
  16. package/CHANGELOG.zh.md +247 -0
  17. package/CONTRIBUTING.md +22 -0
  18. package/README.de.md +96 -0
  19. package/README.es.md +96 -0
  20. package/README.fr.md +96 -0
  21. package/README.it.md +96 -0
  22. package/README.ja.md +102 -0
  23. package/README.ko.md +102 -0
  24. package/README.md +110 -15
  25. package/README.ru.md +96 -0
  26. package/README.zh.md +104 -14
  27. package/SECURITY.md +18 -0
  28. package/THIRD_PARTY_NOTICES.md +7 -25
  29. package/assets/board.png +0 -0
  30. package/assets/context.png +0 -0
  31. package/docs/assets/context-compression-selector-profiles.jpg +0 -0
  32. package/docs/assets/context-compression-selector-settings.png +0 -0
  33. package/docs/compat-0.1.5-report.md +77 -0
  34. package/docs/installation.de.md +104 -0
  35. package/docs/installation.es.md +104 -0
  36. package/docs/installation.fr.md +104 -0
  37. package/docs/installation.it.md +104 -0
  38. package/docs/installation.ja.md +78 -0
  39. package/docs/installation.ko.md +78 -0
  40. package/docs/installation.md +103 -0
  41. package/docs/installation.ru.md +104 -0
  42. package/docs/installation.zh.md +100 -0
  43. package/docs/repair-log.md +657 -0
  44. package/docs/shallow-teaching-preset-template.md +46 -0
  45. package/eslint.config.js +30 -0
  46. package/package.json +116 -129
  47. package/packages/selector/LICENSE +21 -0
  48. package/packages/selector/README.md +26 -0
  49. package/packages/selector/README.zh.md +24 -0
  50. package/packages/selector/THIRD_PARTY_NOTICES.md +32 -0
  51. package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -0
  52. package/packages/selector/docs/native-tool-result-selector-spec.md +34 -0
  53. package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -0
  54. package/{dsh.plugin.json → packages/selector/dsh.plugin.json} +1 -1
  55. package/{lib → packages/selector/lib}/client.d.ts +8 -0
  56. package/{lib → packages/selector/lib}/client.js +212 -3
  57. package/{lib → packages/selector/lib}/index.js +1 -1
  58. package/{lib → packages/selector/lib}/profiles.d.ts +34 -0
  59. package/{lib → packages/selector/lib}/pruner.d.ts +55 -0
  60. package/{lib → packages/selector/lib}/pruner.js +1925 -303
  61. package/{lib → packages/selector/lib}/savings-integral.js +126 -3
  62. package/packages/selector/lib/style.css +350 -0
  63. package/{lib → packages/selector/lib}/tool-result.js +9 -1
  64. package/packages/selector/package.json +178 -0
  65. package/packages/selector/screenshots.json +3 -0
  66. package/packages/selector/src/client/CompressionProfileControls.tsx +352 -0
  67. package/packages/selector/src/client/CompressionProfileSelector.module.css +199 -0
  68. package/packages/selector/src/client/CompressionProfileSelector.tsx +89 -0
  69. package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -0
  70. package/packages/selector/src/client/EstimatorControls.tsx +277 -0
  71. package/packages/selector/src/client/bridge-scope.ts +125 -0
  72. package/packages/selector/src/client/decode.ts +68 -0
  73. package/packages/selector/src/client/fab-pos.ts +71 -0
  74. package/packages/selector/src/client/index.ts +438 -0
  75. package/packages/selector/src/client/locales/de.ts +167 -0
  76. package/packages/selector/src/client/locales/es.ts +167 -0
  77. package/packages/selector/src/client/locales/fr.ts +167 -0
  78. package/packages/selector/src/client/locales/it.ts +167 -0
  79. package/packages/selector/src/client/locales/ja.ts +167 -0
  80. package/packages/selector/src/client/locales/ko.ts +167 -0
  81. package/packages/selector/src/client/locales/ru.ts +167 -0
  82. package/packages/selector/src/client/locales.ts +334 -0
  83. package/packages/selector/src/client/monitor-fab.ts +445 -0
  84. package/packages/selector/src/client/preset-options.ts +88 -0
  85. package/packages/selector/src/client/savings-card.tsx +269 -0
  86. package/packages/selector/src/client/scope-face.ts +24 -0
  87. package/packages/selector/src/client/settings-section.tsx +156 -0
  88. package/packages/selector/src/compat/host-generation.ts +96 -0
  89. package/packages/selector/src/compat/llm-messages.ts +50 -0
  90. package/packages/selector/src/compat/settings-lease.ts +108 -0
  91. package/packages/selector/src/compat/tool-result.ts +91 -0
  92. package/packages/selector/src/css-modules.d.ts +6 -0
  93. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -0
  94. package/packages/selector/src/estimator-catalog.ts +104 -0
  95. package/packages/selector/src/index.ts +890 -0
  96. package/packages/selector/src/invariant.ts +113 -0
  97. package/packages/selector/src/preset-overlay.ts +749 -0
  98. package/packages/selector/src/profiles.ts +554 -0
  99. package/packages/selector/src/pruner/content.ts +199 -0
  100. package/packages/selector/src/pruner/session.ts +97 -0
  101. package/packages/selector/src/pruner/state.ts +61 -0
  102. package/packages/selector/src/pruner/tuning.ts +23 -0
  103. package/packages/selector/src/pruner/types.ts +78 -0
  104. package/packages/selector/src/pruner.ts +3222 -0
  105. package/packages/selector/src/runtime/adaptive-cost.ts +205 -0
  106. package/packages/selector/src/runtime/audit.ts +321 -0
  107. package/packages/selector/src/runtime/config.ts +887 -0
  108. package/packages/selector/src/runtime/custom-policy.ts +300 -0
  109. package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -0
  110. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -0
  111. package/packages/selector/src/runtime/display-prefs.ts +98 -0
  112. package/packages/selector/src/runtime/fold-router.ts +143 -0
  113. package/packages/selector/src/runtime/measurement.ts +444 -0
  114. package/packages/selector/src/runtime/monitor.ts +341 -0
  115. package/packages/selector/src/runtime/panel-command.ts +213 -0
  116. package/packages/selector/src/runtime/reducers.ts +1755 -0
  117. package/packages/selector/src/runtime/retrieve.ts +505 -0
  118. package/packages/selector/src/runtime/savings-integral.ts +117 -0
  119. package/packages/selector/src/runtime/savings-projection.ts +229 -0
  120. package/packages/selector/src/runtime/savings-verify.ts +446 -0
  121. package/packages/selector/src/runtime/savings.ts +526 -0
  122. package/packages/selector/src/runtime/sediment-card.ts +126 -0
  123. package/packages/selector/src/runtime/sediment-clock.ts +87 -0
  124. package/packages/selector/src/runtime/sediment-guard.ts +136 -0
  125. package/packages/selector/src/runtime/sediment-publish.ts +144 -0
  126. package/packages/selector/src/runtime/sediment-span.ts +170 -0
  127. package/packages/selector/src/runtime/sediment.ts +209 -0
  128. package/packages/selector/src/runtime/session-events.ts +30 -0
  129. package/packages/selector/src/runtime/session-file-decode.ts +523 -0
  130. package/packages/selector/src/runtime/shallow-tools.ts +342 -0
  131. package/packages/selector/src/runtime/stats-backfill.ts +541 -0
  132. package/packages/selector/src/runtime/stats-db.ts +492 -0
  133. package/packages/selector/src/runtime/stats-schema.ts +123 -0
  134. package/packages/selector/src/runtime/stats-sync.ts +307 -0
  135. package/packages/selector/src/runtime/summary-command.ts +127 -0
  136. package/packages/selector/src/runtime/tail-trim.ts +177 -0
  137. package/packages/selector/src/runtime/token-count.ts +72 -0
  138. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -0
  139. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -0
  140. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -0
  141. package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -0
  142. package/packages/selector/src/runtime/tokenpilot/dedup.ts +82 -0
  143. package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -0
  144. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -0
  145. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -0
  146. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -0
  147. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -0
  148. package/packages/selector/src/runtime/tokenpilot/locator.ts +129 -0
  149. package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -0
  150. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -0
  151. package/packages/selector/src/runtime/tool-names.ts +42 -0
  152. package/packages/selector/src/runtime/toolclass.ts +103 -0
  153. package/packages/selector/src/runtime/triage/masks.ts +128 -0
  154. package/packages/selector/src/runtime/triage/shallow.ts +132 -0
  155. package/packages/selector/src/runtime/triage/signals.ts +167 -0
  156. package/packages/selector/src/runtime/triage/types.ts +125 -0
  157. package/packages/selector/src/runtime/types.ts +396 -0
  158. package/packages/selector/src/runtime/value.ts +48 -0
  159. package/packages/selector/src/settings-bridge.ts +175 -0
  160. package/packages/selector/tests/advisor-report.host.spec.ts +223 -0
  161. package/packages/selector/tests/auto-compact.client.spec.tsx +214 -0
  162. package/packages/selector/tests/built/client-artifact.spec.ts +56 -0
  163. package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -0
  164. package/packages/selector/tests/code-skeleton.client.spec.ts +98 -0
  165. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
  166. package/packages/selector/tests/custom-contract.client.spec.ts +226 -0
  167. package/packages/selector/tests/estimator-catalog.spec.ts +70 -0
  168. package/packages/selector/tests/estimator-channel.client.spec.tsx +253 -0
  169. package/packages/selector/tests/estimator-route-registration.host.spec.ts +202 -0
  170. package/packages/selector/tests/fab-pos.client.spec.ts +47 -0
  171. package/packages/selector/tests/fixtures/sediment-pool/52adc205-cloud-5.orig.txt +231 -0
  172. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-25.orig.txt +236 -0
  173. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-38.orig.txt +220 -0
  174. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-42.orig.txt +140 -0
  175. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-cloud-53.orig.txt +117 -0
  176. package/packages/selector/tests/fixtures/sediment-pool/95fcba5d-local-10.orig.txt +67 -0
  177. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-45.orig.txt +119 -0
  178. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-49.orig.txt +119 -0
  179. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-63.orig.txt +131 -0
  180. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-75.orig.txt +196 -0
  181. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-76.orig.txt +71 -0
  182. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-85.orig.txt +126 -0
  183. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-86.orig.txt +86 -0
  184. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-87.orig.txt +50 -0
  185. package/packages/selector/tests/fixtures/sediment-pool/a7a767c0-cloud-96.orig.txt +102 -0
  186. package/packages/selector/tests/helpers/legacy-namespace.ts +35 -0
  187. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -0
  188. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -0
  189. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -0
  190. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -0
  191. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -0
  192. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -0
  193. package/packages/selector/tests/monitor-fab.client.spec.ts +240 -0
  194. package/packages/selector/tests/preset-options-write.client.spec.ts +192 -0
  195. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -0
  196. package/packages/selector/tests/preset-overlay.host.spec.ts +246 -0
  197. package/packages/selector/tests/profiles.client.spec.tsx +436 -0
  198. package/packages/selector/tests/ptc-custom-write.client.spec.ts +86 -0
  199. package/packages/selector/tests/public/package-contract.client.spec.ts +89 -0
  200. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -0
  201. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -0
  202. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -0
  203. package/packages/selector/tests/runtime/advisor.spec.ts +226 -0
  204. package/packages/selector/tests/runtime/audit.spec.ts +275 -0
  205. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -0
  206. package/packages/selector/tests/runtime/char-basis.spec.ts +30 -0
  207. package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -0
  208. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -0
  209. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -0
  210. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -0
  211. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -0
  212. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -0
  213. package/packages/selector/tests/runtime/fixtures/session-v4-dump.jsonl +46 -0
  214. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -0
  215. package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -0
  216. package/packages/selector/tests/runtime/fold-router.spec.ts +140 -0
  217. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -0
  218. package/packages/selector/tests/runtime/fresh-gate.spec.ts +43 -0
  219. package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -0
  220. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -0
  221. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -0
  222. package/packages/selector/tests/runtime/jsonl-reducer.spec.ts +79 -0
  223. package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -0
  224. package/packages/selector/tests/runtime/monitor.spec.ts +354 -0
  225. package/packages/selector/tests/runtime/panel-command.spec.ts +101 -0
  226. package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -0
  227. package/packages/selector/tests/runtime/ptc-profile.spec.ts +133 -0
  228. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +2795 -0
  229. package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -0
  230. package/packages/selector/tests/runtime/savings-accounting.spec.ts +291 -0
  231. package/packages/selector/tests/runtime/savings-integral.spec.ts +169 -0
  232. package/packages/selector/tests/runtime/savings-projection.spec.ts +89 -0
  233. package/packages/selector/tests/runtime/savings-verify.spec.ts +226 -0
  234. package/packages/selector/tests/runtime/savings.spec.ts +139 -0
  235. package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -0
  236. package/packages/selector/tests/runtime/sediment-card.spec.ts +111 -0
  237. package/packages/selector/tests/runtime/sediment-config.spec.ts +56 -0
  238. package/packages/selector/tests/runtime/sediment-guard.spec.ts +71 -0
  239. package/packages/selector/tests/runtime/sediment-masks.spec.ts +95 -0
  240. package/packages/selector/tests/runtime/sediment-orchestrator.spec.ts +166 -0
  241. package/packages/selector/tests/runtime/sediment-pool-share.spec.ts +65 -0
  242. package/packages/selector/tests/runtime/sediment-publish.spec.ts +142 -0
  243. package/packages/selector/tests/runtime/sediment-real-shapes.spec.ts +158 -0
  244. package/packages/selector/tests/runtime/sediment-settings.spec.ts +73 -0
  245. package/packages/selector/tests/runtime/sediment-signals.spec.ts +124 -0
  246. package/packages/selector/tests/runtime/sediment-span.spec.ts +92 -0
  247. package/packages/selector/tests/runtime/session-events.spec.ts +27 -0
  248. package/packages/selector/tests/runtime/session-file-decode.spec.ts +281 -0
  249. package/packages/selector/tests/runtime/settings-unwrap.spec.ts +58 -0
  250. package/packages/selector/tests/runtime/shallow-primitives.spec.ts +135 -0
  251. package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -0
  252. package/packages/selector/tests/runtime/stats-backfill-scheduler.spec.ts +167 -0
  253. package/packages/selector/tests/runtime/stats-backfill.spec.ts +350 -0
  254. package/packages/selector/tests/runtime/stats-db.spec.ts +361 -0
  255. package/packages/selector/tests/runtime/stats-privacy.spec.ts +55 -0
  256. package/packages/selector/tests/runtime/stats-sync.spec.ts +278 -0
  257. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -0
  258. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -0
  259. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -0
  260. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -0
  261. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -0
  262. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -0
  263. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -0
  264. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +121 -0
  265. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -0
  266. package/packages/selector/tests/runtime/toolclass.spec.ts +156 -0
  267. package/packages/selector/tests/runtime/value.spec.ts +23 -0
  268. package/packages/selector/tests/savings-sessions.client.spec.tsx +140 -0
  269. package/packages/selector/tests/settings-seat.client.spec.ts +215 -0
  270. package/packages/selector/tests/standing-generation.host.spec.ts +724 -0
  271. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -0
  272. package/packages/selector/tests/support/cache-prefix-audit.ts +105 -0
  273. package/packages/selector/tests/support/mock-adapter.ts +37 -0
  274. package/packages/selector/tests/support/ui-primitives.tsx +34 -0
  275. package/packages/selector/tsconfig.json +11 -0
  276. package/packages/selector/tsdown.client.config.ts +102 -0
  277. package/packages/selector/tsdown.config.ts +20 -0
  278. package/pnpm-workspace.yaml +76 -0
  279. package/screenshots.json +6 -3
  280. package/scripts/capture-profile-baseline.mjs +42 -0
  281. package/scripts/cell-browser-e2e.mjs +354 -0
  282. package/scripts/generate-tokenizer-fixtures.py +81 -0
  283. package/scripts/generate-vision-fixtures.py +208 -0
  284. package/scripts/hosts.d.mts +3 -0
  285. package/scripts/hosts.mjs +79 -0
  286. package/scripts/packed-components-smoke.mjs +763 -0
  287. package/scripts/packed-install-e2e.mjs +1346 -0
  288. package/scripts/sediment-latency-report.mjs +63 -0
  289. package/scripts/sync-hosts.mjs +174 -0
  290. package/scripts/toolclass-corpus-replay.mjs +281 -0
  291. package/scripts/verify-release.mjs +343 -0
  292. package/tests/TEST_INVENTORY.md +41 -0
  293. package/tsconfig.base.json +18 -0
  294. package/tsconfig.json +7 -0
  295. package/tsconfig.tests.json +15 -0
  296. package/vitest.built.config.ts +9 -0
  297. package/vitest.config.ts +54 -0
  298. /package/{assets → packages/selector/assets}/deepseek-v4/LICENSE.DeepSeek-V4-Pro.txt +0 -0
  299. /package/{assets → packages/selector/assets}/deepseek-v4/manifest.json +0 -0
  300. /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer.json +0 -0
  301. /package/{assets → packages/selector/assets}/deepseek-v4/tokenizer_config.json +0 -0
  302. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/LICENSE.DeepSeek-V4-Flash-Vision-Exp.txt +0 -0
  303. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/manifest.json +0 -0
  304. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer.json +0 -0
  305. /package/{assets → packages/selector/assets}/deepseek-v4-vision-exp/tokenizer_config.json +0 -0
  306. /package/{cordis.patch.yml → packages/selector/cordis.patch.yml} +0 -0
  307. /package/{lib → packages/selector/lib}/index.d.ts +0 -0
  308. /package/{lib → packages/selector/lib}/invariant.d.ts +0 -0
  309. /package/{lib → packages/selector/lib}/invariant.js +0 -0
  310. /package/{lib → packages/selector/lib}/tail-trim.js +0 -0
@@ -0,0 +1,78 @@
1
+ /* Vendored verbatim from @deepseek-ai/<pkg> — third-party code, exempt from this repo's lint rules. */
2
+ /**
3
+ * Structural secret redaction for settings values. `role('secret')` fields are
4
+ * removed from a value before it crosses a wire boundary; a sidecar records
5
+ * each schema-declared secret position and whether it currently holds a value,
6
+ * so a configuration surface can render a write-only input without ever
7
+ * receiving the secret itself.
8
+ * @module @deepseek-ai/dsh-settings/redact
9
+ */
10
+ /** Whether a value is a plain data object the walker may recurse into. */
11
+ function isRecord(value) {
12
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
13
+ }
14
+ function walk(node, value, path, secrets) {
15
+ if (node === undefined)
16
+ return value;
17
+ if (node.meta?.role === 'secret') {
18
+ secrets.push({ path, set: value !== undefined });
19
+ return undefined;
20
+ }
21
+ switch (node.type) {
22
+ case 'object': {
23
+ const properties = node.dict ?? {};
24
+ const source = isRecord(value) ? value : undefined;
25
+ const rebuilt = {};
26
+ if (source !== undefined) {
27
+ for (const [key, entry] of Object.entries(source)) {
28
+ if (key in properties)
29
+ continue;
30
+ rebuilt[key] = entry;
31
+ }
32
+ }
33
+ for (const [key, child] of Object.entries(properties)) {
34
+ const stripped = walk(child, source?.[key], [...path, key], secrets);
35
+ if (stripped !== undefined)
36
+ rebuilt[key] = stripped;
37
+ }
38
+ return source === undefined && Object.keys(rebuilt).length === 0 ? value : rebuilt;
39
+ }
40
+ case 'dict': {
41
+ if (!isRecord(value))
42
+ return value;
43
+ const rebuilt = {};
44
+ for (const [key, entry] of Object.entries(value)) {
45
+ const stripped = walk(node.inner, entry, [...path, key], secrets);
46
+ if (stripped !== undefined)
47
+ rebuilt[key] = stripped;
48
+ }
49
+ return rebuilt;
50
+ }
51
+ case 'array': {
52
+ if (!Array.isArray(value))
53
+ return value;
54
+ return value.map((entry, index) => walk(node.inner, entry, [...path, String(index)], secrets));
55
+ }
56
+ default:
57
+ // TODO(settings-wire-redaction): Fail closed instead — a secret reachable
58
+ // only through a union, intersection, or transform is returned verbatim
59
+ // here, with nothing recording that it was missed.
60
+ return value;
61
+ }
62
+ }
63
+ /**
64
+ * Remove every `role('secret')` field a schema declares from a value. The
65
+ * walker follows `object`, `dict`, and `array` containers; a secret must be
66
+ * declared directly on a field reachable through those containers (a secret
67
+ * buried inside a union branch or transform is not reachable and must not be
68
+ * modeled that way). The input is never mutated.
69
+ * @param schema - live schemastery schema describing the value.
70
+ * @param value - the value to strip; `undefined` yields an empty record with
71
+ * object-property secret slots still enumerated.
72
+ * @returns the stripped detached value and the ordered secret positions.
73
+ */
74
+ export function redactSecrets(schema, value) {
75
+ const secrets = [];
76
+ const stripped = walk(schema, value, [], secrets);
77
+ return { value: stripped, secrets };
78
+ }
@@ -0,0 +1,234 @@
1
+ /* Vendored verbatim from @deepseek-ai/<pkg> — third-party code, exempt from this repo's lint rules. */
2
+ /* eslint-disable */
3
+ //#region lib/types/index.js
4
+ /** Duplicate-install-safe JSON and immutable-value helpers. @module @deepseek-ai/dsh-util-values */
5
+ /**
6
+ * Mark an unreachable closed-union branch.
7
+ * @param value - impossible value; an unhandled typed variant fails at the call site.
8
+ * @param context - optional switch-site label included in the failure message.
9
+ * @returns never; a runtime value that escaped its type always throws.
10
+ */
11
+ function assertNever(value, context) {
12
+ const rendered = JSON.stringify(value) ?? String(value);
13
+ throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
14
+ }
15
+ /** Whether a realm-owned intrinsic prototype is backed by its native constructor. */
16
+ function hasIntrinsicConstructor(prototype, name) {
17
+ const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
18
+ if (typeof constructor !== "function") return false;
19
+ try {
20
+ return constructor.name === name && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+ /** Whether a candidate is one realm's intrinsic `Object.prototype`. */
26
+ function isIntrinsicObjectPrototype(value) {
27
+ return Object.getPrototypeOf(value) === null && hasIntrinsicConstructor(value, "Object");
28
+ }
29
+ /** Whether an array uses one realm's intrinsic `Array.prototype`, not a subclass or forged prototype. */
30
+ function hasPlainArrayPrototype(value) {
31
+ const prototype = Object.getPrototypeOf(value);
32
+ if (!Array.isArray(prototype) || !hasIntrinsicConstructor(prototype, "Array")) return false;
33
+ const objectPrototype = Object.getPrototypeOf(prototype);
34
+ return typeof objectPrototype === "object" && objectPrototype !== null && isIntrinsicObjectPrototype(objectPrototype);
35
+ }
36
+ /** Whether an object is a plain or null-prototype record from any JavaScript realm. */
37
+ function hasPlainObjectPrototype(value) {
38
+ const prototype = Object.getPrototypeOf(value);
39
+ return prototype === null || typeof prototype === "object" && isIntrinsicObjectPrototype(prototype);
40
+ }
41
+ /** Return every JSON-visible object key, or reject own data JSON would discard. */
42
+ function enumerableStringKeys(value) {
43
+ const keys = Reflect.ownKeys(value);
44
+ if (keys.some((key) => typeof key !== "string" || !Object.prototype.propertyIsEnumerable.call(value, key))) return void 0;
45
+ return keys;
46
+ }
47
+ /** Validate lossless JSON iteratively, optionally materializing a detached snapshot. */
48
+ function walkJsonValue(value, detach) {
49
+ const ancestors = /* @__PURE__ */ new Set();
50
+ let root;
51
+ const assign = (destination, item) => {
52
+ if (destination === void 0) return;
53
+ if (destination.kind === "root") root = item;
54
+ else if (destination.kind === "array") destination.target[destination.index] = item;
55
+ else Object.defineProperty(destination.target, destination.key, {
56
+ value: item,
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true
60
+ });
61
+ };
62
+ const tasks = [{
63
+ kind: "visit",
64
+ value,
65
+ ...detach ? { destination: { kind: "root" } } : {}
66
+ }];
67
+ for (let task = tasks.pop(); task !== void 0; task = tasks.pop()) {
68
+ if (task.kind === "leave") {
69
+ ancestors.delete(task.source);
70
+ continue;
71
+ }
72
+ if (task.kind === "array-item") {
73
+ if (!Object.prototype.hasOwnProperty.call(task.source, task.index)) return void 0;
74
+ tasks.push({
75
+ kind: "visit",
76
+ value: task.source[task.index],
77
+ ...task.target === void 0 ? {} : { destination: {
78
+ kind: "array",
79
+ target: task.target,
80
+ index: task.index
81
+ } }
82
+ });
83
+ continue;
84
+ }
85
+ if (task.kind === "object-property") {
86
+ tasks.push({
87
+ kind: "visit",
88
+ value: task.source[task.key],
89
+ ...task.target === void 0 ? {} : { destination: {
90
+ kind: "object",
91
+ target: task.target,
92
+ key: task.key
93
+ } }
94
+ });
95
+ continue;
96
+ }
97
+ const current = task.value;
98
+ if (current === null) {
99
+ assign(task.destination, null);
100
+ continue;
101
+ }
102
+ if (typeof current === "boolean" || typeof current === "string") {
103
+ assign(task.destination, current);
104
+ continue;
105
+ }
106
+ if (typeof current === "number") {
107
+ if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
108
+ assign(task.destination, current);
109
+ continue;
110
+ }
111
+ if (typeof current !== "object") return void 0;
112
+ if (ancestors.has(current)) return void 0;
113
+ if (Array.isArray(current)) {
114
+ if (!hasPlainArrayPrototype(current)) return void 0;
115
+ const length = current.length;
116
+ if (Reflect.ownKeys(current).length !== length + 1) return void 0;
117
+ const target = detach ? [] : void 0;
118
+ if (target !== void 0) assign(task.destination, target);
119
+ ancestors.add(current);
120
+ tasks.push({
121
+ kind: "leave",
122
+ source: current
123
+ });
124
+ for (let index = length - 1; index >= 0; index--) tasks.push({
125
+ kind: "array-item",
126
+ source: current,
127
+ index,
128
+ ...target === void 0 ? {} : { target }
129
+ });
130
+ continue;
131
+ }
132
+ if (!hasPlainObjectPrototype(current)) return void 0;
133
+ const keys = enumerableStringKeys(current);
134
+ if (keys === void 0) return void 0;
135
+ const target = detach ? {} : void 0;
136
+ if (target !== void 0) assign(task.destination, target);
137
+ ancestors.add(current);
138
+ tasks.push({
139
+ kind: "leave",
140
+ source: current
141
+ });
142
+ for (let index = keys.length - 1; index >= 0; index--) {
143
+ const key = keys[index];
144
+ /* v8 ignore next -- the loop is bounded by the captured key count. */
145
+ if (key === void 0) return void 0;
146
+ tasks.push({
147
+ kind: "object-property",
148
+ source: current,
149
+ key,
150
+ ...target === void 0 ? {} : { target }
151
+ });
152
+ }
153
+ }
154
+ return detach ? root : true;
155
+ }
156
+ /**
157
+ * Validate and detach lossless JSON in one read per property.
158
+ * @param value - candidate value to validate and detach.
159
+ * @returns the detached snapshot, or `undefined` when the value is not losslessly JSON-serializable.
160
+ */
161
+ function snapshotJsonValue(value) {
162
+ return walkJsonValue(value, true);
163
+ }
164
+ /**
165
+ * Test the same lossless JSON rules as {@link snapshotJsonValue} without detaching the value.
166
+ * @param value - candidate value to test.
167
+ * @returns whether the value survives a JSON round trip without loss.
168
+ */
169
+ function isJsonValue(value) {
170
+ return walkJsonValue(value, false) === true;
171
+ }
172
+ /**
173
+ * Compare JSON-compatible values structurally.
174
+ * @param a - one JSON-compatible value.
175
+ * @param b - the other JSON-compatible value.
176
+ * @returns whether both values contain the same JSON data.
177
+ */
178
+ function deepEqualJson(a, b) {
179
+ if (a === b) return true;
180
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
181
+ if (Array.isArray(a) || Array.isArray(b)) {
182
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
183
+ return a.every((entry, index) => deepEqualJson(entry, b[index]));
184
+ }
185
+ const left = a;
186
+ const right = b;
187
+ const keys = Object.keys(left);
188
+ if (keys.length !== Object.keys(right).length) return false;
189
+ return keys.every((key) => key in right && deepEqualJson(left[key], right[key]));
190
+ }
191
+ /**
192
+ * Deep-freeze an object graph in place while leaving live AbortSignal objects mutable.
193
+ * @param value - value to freeze.
194
+ * @returns the same value after every reachable enumerable child is frozen.
195
+ */
196
+ function deepFreeze(value) {
197
+ const seen = /* @__PURE__ */ new WeakSet();
198
+ const pending = [{
199
+ kind: "visit",
200
+ node: value
201
+ }];
202
+ while (pending.length > 0) {
203
+ const task = pending.pop();
204
+ /* v8 ignore next -- the loop condition guarantees one pending task. */
205
+ if (task === void 0) continue;
206
+ if (task.kind === "property") {
207
+ pending.push({
208
+ kind: "visit",
209
+ node: task.source[task.key]
210
+ });
211
+ continue;
212
+ }
213
+ const node = task.node;
214
+ if (node === null || typeof node !== "object") continue;
215
+ if (node instanceof AbortSignal) continue;
216
+ if (seen.has(node)) continue;
217
+ seen.add(node);
218
+ Object.freeze(node);
219
+ const keys = Object.keys(node);
220
+ for (let index = keys.length - 1; index >= 0; index--) {
221
+ const key = keys[index];
222
+ /* v8 ignore next -- the loop is bounded by the captured key count. */
223
+ if (key === void 0) continue;
224
+ pending.push({
225
+ kind: "property",
226
+ source: node,
227
+ key
228
+ });
229
+ }
230
+ }
231
+ return value;
232
+ }
233
+ //#endregion
234
+ export { assertNever, deepEqualJson, deepFreeze, isJsonValue, snapshotJsonValue };
@@ -0,0 +1,204 @@
1
+ import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
2
+ import { tmpdir } from 'node:os'
3
+ import { dirname, join } from 'node:path'
4
+ import { Context, Service } from '@deepseek-ai/cordis'
5
+ import type { AgentPreset } from '@deepseek-ai/dsh-agent-presets'
6
+ import { type SettingsNamespace } from '@deepseek-ai/dsh-settings'
7
+ import { LegacySettingsProvider } from './helpers/legacy-settings/index.ts'
8
+ import { afterEach, describe, expect, it } from 'vitest'
9
+ import { apply } from '../src/index.ts'
10
+ import type { OverlayableAgentPresets } from '../src/preset-overlay.ts'
11
+ import { LegacyNamespaceRegistrar } from './helpers/legacy-namespace.ts'
12
+
13
+ // 0.1.5 removed the settingsNamespace() wrapper; namespaces are validated at runtime.
14
+ const nsBrand = (value: string): SettingsNamespace => value as unknown as SettingsNamespace
15
+
16
+ let root: string | undefined
17
+ let ctx: Context | undefined
18
+
19
+ afterEach(async () => {
20
+ await ctx?.fiber.dispose()
21
+ ctx = undefined
22
+ if (root !== undefined) await rm(root, { recursive: true, force: true })
23
+ root = undefined
24
+ })
25
+
26
+ class MemorySettings extends LegacySettingsProvider {
27
+ readonly writable = true
28
+ private readonly stored: Record<string, unknown> = {}
29
+
30
+ protected load(): Promise<Record<string, unknown>> {
31
+ return Promise.resolve(structuredClone(this.stored))
32
+ }
33
+
34
+ protected persist(ns: SettingsNamespace, section: Record<string, unknown>): Promise<void> {
35
+ this.stored[ns] = structuredClone(section)
36
+ return Promise.resolve()
37
+ }
38
+ }
39
+
40
+ class FakeAgentPresets extends Service implements OverlayableAgentPresets {
41
+ constructor(ctx: Context, readonly preset: AgentPreset) {
42
+ super(ctx, 'agentPresets')
43
+ }
44
+
45
+ async resolve(): Promise<AgentPreset> {
46
+ return this.preset
47
+ }
48
+
49
+ async mount(_agentCtx: unknown): Promise<AgentPreset> {
50
+ return await this.resolve()
51
+ }
52
+
53
+ async recompose(_agentCtx: unknown, _id: string): Promise<AgentPreset> {
54
+ return await this.resolve()
55
+ }
56
+
57
+ async standingKeyFor(): Promise<string> {
58
+ return (await this.resolve()).path
59
+ }
60
+ }
61
+
62
+ async function sourcePreset(): Promise<AgentPreset> {
63
+ root = await mkdtemp(join(tmpdir(), 'dsh-selector-host-overlay-'))
64
+ const path = join(root, 'standard', 'agent.cordis.yml')
65
+ await mkdir(dirname(path), { recursive: true })
66
+ await writeFile(path, "- id: persona\n name: '/opt/preset/persona.js'\n")
67
+ return { id: 'standard', trust: 'system', path }
68
+ }
69
+
70
+ describe('context compression selector Host preset integration', () => {
71
+ it('decorates native composition only for the lifetime of the selector fiber', async () => {
72
+ const preset = await sourcePreset()
73
+ ctx = new Context()
74
+ await ctx.plugin(MemorySettings).await()
75
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
76
+ await ctx.plugin(FakeAgentPresets, preset).await()
77
+
78
+ const selector = ctx.plugin({ apply: (child) => {
79
+ apply(child, { presetOverlay: true })
80
+ } })
81
+ await selector.await()
82
+
83
+ const service = ctx.agentPresets as unknown as OverlayableAgentPresets
84
+ const mounted = await service.mount({})
85
+ expect(mounted.path).not.toBe(preset.path)
86
+ expect(await readFile(mounted.path, 'utf8')).toContain('id: tool-result-pruner')
87
+ expect((await service.resolve()).path).toBe(preset.path)
88
+
89
+ await selector.dispose()
90
+ expect((await service.mount({})).path).toBe(preset.path)
91
+ })
92
+
93
+ it('0.1.7: duplicate Host rows own independent entry configs — one row\u2019s disposal never disturbs the other', async () => {
94
+ const preset = await sourcePreset()
95
+ ctx = new Context()
96
+ await ctx.plugin(MemorySettings).await()
97
+ await ctx.plugin(FakeAgentPresets, preset).await()
98
+
99
+ const builtIn = ctx.plugin({ apply })
100
+ await builtIn.await()
101
+
102
+ const service = ctx.agentPresets as unknown as OverlayableAgentPresets
103
+ expect((await service.mount({})).path).toBe(preset.path)
104
+
105
+ // 0.1.7: there is no shared settings registration to lease — each row
106
+ // carries its own compression doc on its entry config, so duplicate rows
107
+ // cannot disturb each other and disposal is purely per row.
108
+ const bundle = ctx.plugin({ apply: (child) => {
109
+ apply(child, { presetOverlay: true, settings: { profile: 'cache-strict' } } as never)
110
+ } })
111
+ await bundle.await()
112
+
113
+ const mounted = await service.mount({})
114
+ expect(mounted.path).not.toBe(preset.path)
115
+ expect((await service.recompose({}, 'standard')).path).toBe(mounted.path)
116
+
117
+ // Disposing the non-overlay row never touches the overlay row's decoration
118
+ // or its entry config.
119
+ await builtIn.dispose()
120
+ expect((await service.mount({})).path).toBe(mounted.path)
121
+
122
+ await bundle.dispose()
123
+ expect((await service.mount({})).path).toBe(preset.path)
124
+ })
125
+
126
+ it('writes the saved Auto Compact threshold into the generated compaction-basic composition', async () => {
127
+ const preset = await sourcePreset()
128
+ ctx = new Context()
129
+ await ctx.plugin(MemorySettings).await()
130
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
131
+ await ctx.plugin(FakeAgentPresets, preset).await()
132
+ // A settings-owning row must register the namespace before the update.
133
+ await ctx.plugin({ apply }).await()
134
+ const namespace = nsBrand('context-compression')
135
+ await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 73 } })
136
+
137
+ const bundle = ctx.plugin({ apply: (child) => {
138
+ apply(child, { presetOverlay: true })
139
+ } })
140
+ await bundle.await()
141
+
142
+ const service = ctx.agentPresets as unknown as OverlayableAgentPresets
143
+ const mounted = await service.mount({})
144
+ const rendered = await readFile(mounted.path, 'utf8')
145
+ expect(rendered).toContain('id: compaction-basic')
146
+ expect(rendered).toContain('thresholdRatio: 0.73')
147
+ // First-release retention stays pinned at 0.16 next to the threshold.
148
+ expect(rendered).toContain('retainRatio: 0.16')
149
+ // The SAME read feeds the runtime deployment config, so one generation
150
+ // cannot split Auto Compact and micro compact across two thresholds.
151
+ expect(rendered).toContain('id: tool-result-pruner')
152
+ expect(rendered).toContain('autoCompactThresholdPercent: 73')
153
+ await bundle.dispose()
154
+ })
155
+
156
+ it('defaults the generated threshold to 0.8 and keeps it absent from settings until saved', async () => {
157
+ const preset = await sourcePreset()
158
+ ctx = new Context()
159
+ await ctx.plugin(MemorySettings).await()
160
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
161
+ await ctx.plugin(FakeAgentPresets, preset).await()
162
+
163
+ const bundle = ctx.plugin({ apply: (child) => {
164
+ apply(child, { presetOverlay: true })
165
+ } })
166
+ await bundle.await()
167
+
168
+ const service = ctx.agentPresets as unknown as OverlayableAgentPresets
169
+ const rendered = await readFile((await service.mount({})).path, 'utf8')
170
+ expect(rendered).toContain('thresholdRatio: 0.8')
171
+ await bundle.dispose()
172
+ })
173
+
174
+ it('moves the standing composition generation when an equal-length threshold changes', async () => {
175
+ const preset = await sourcePreset()
176
+ ctx = new Context()
177
+ await ctx.plugin(MemorySettings).await()
178
+ await ctx.plugin(LegacyNamespaceRegistrar).await()
179
+ await ctx.plugin(FakeAgentPresets, preset).await()
180
+ // A settings-owning row must register the namespace before the update.
181
+ await ctx.plugin({ apply }).await()
182
+ const namespace = nsBrand('context-compression')
183
+ await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 70 } })
184
+
185
+ const bundle = ctx.plugin({ apply: (child) => {
186
+ apply(child, { presetOverlay: true })
187
+ } })
188
+ await bundle.await()
189
+
190
+ const service = ctx.agentPresets as unknown as OverlayableAgentPresets
191
+ const first = await service.mount({})
192
+ expect(await readFile(first.path, 'utf8')).toContain('thresholdRatio: 0.7')
193
+ expect(await service.standingKeyFor()).toBe(first.path)
194
+
195
+ // Same character length, different content: the generated identity and
196
+ // standing composition generation must both move to the new threshold.
197
+ await ctx.settings.update(namespace, { autoCompact: { thresholdPercent: 80 } })
198
+ const second = await service.mount({})
199
+ expect(second.path).not.toBe(first.path)
200
+ expect(await readFile(second.path, 'utf8')).toContain('thresholdRatio: 0.8')
201
+ expect(await service.standingKeyFor()).toBe(second.path)
202
+ await bundle.dispose()
203
+ })
204
+ })