dsh-context-compression-improved 0.8.0 → 0.9.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 (171) hide show
  1. package/.gitattributes +2 -2
  2. package/.githooks/pre-push +37 -37
  3. package/.github/workflows/ci.yml +39 -39
  4. package/CHANGELOG.de.md +41 -0
  5. package/CHANGELOG.es.md +41 -0
  6. package/CHANGELOG.fr.md +42 -0
  7. package/CHANGELOG.it.md +41 -0
  8. package/CHANGELOG.ja.md +35 -0
  9. package/CHANGELOG.ko.md +34 -0
  10. package/CHANGELOG.md +40 -0
  11. package/CHANGELOG.ru.md +37 -0
  12. package/CHANGELOG.zh.md +32 -0
  13. package/CONTRIBUTING.md +22 -22
  14. package/LICENSE +21 -21
  15. package/README.de.md +7 -9
  16. package/README.es.md +7 -9
  17. package/README.fr.md +7 -9
  18. package/README.it.md +7 -9
  19. package/README.ja.md +6 -2
  20. package/README.ko.md +6 -2
  21. package/README.md +96 -98
  22. package/README.ru.md +7 -9
  23. package/README.zh.md +89 -85
  24. package/SECURITY.md +18 -18
  25. package/THIRD_PARTY_NOTICES.md +14 -14
  26. package/docs/compat-0.1.5-report.md +77 -77
  27. package/docs/installation.de.md +5 -5
  28. package/docs/installation.es.md +5 -5
  29. package/docs/installation.fr.md +5 -5
  30. package/docs/installation.it.md +5 -5
  31. package/docs/installation.ja.md +5 -5
  32. package/docs/installation.ko.md +5 -5
  33. package/docs/installation.md +5 -5
  34. package/docs/installation.ru.md +5 -5
  35. package/docs/installation.zh.md +5 -5
  36. package/docs/repair-log.md +657 -657
  37. package/package.json +23 -22
  38. package/packages/selector/LICENSE +21 -21
  39. package/packages/selector/README.md +26 -26
  40. package/packages/selector/README.zh.md +24 -24
  41. package/packages/selector/THIRD_PARTY_NOTICES.md +32 -32
  42. package/packages/selector/cordis.patch.yml +27 -27
  43. package/packages/selector/docs/history-tool-call-working-set-spec.md +112 -112
  44. package/packages/selector/docs/native-tool-result-selector-spec.md +34 -34
  45. package/packages/selector/docs/subagent-cache-reuse-spec.md +46 -46
  46. package/packages/selector/dsh.plugin.json +16 -16
  47. package/packages/selector/lib/client.js +178 -21
  48. package/packages/selector/lib/host-generation.js +62 -0
  49. package/packages/selector/lib/index.js +208 -1
  50. package/packages/selector/lib/invariant.js +1 -1
  51. package/packages/selector/lib/pruner.js +41 -43
  52. package/packages/selector/lib/style.css +53 -53
  53. package/packages/selector/lib/tail-trim.js +73 -4
  54. package/packages/selector/package.json +80 -21
  55. package/packages/selector/screenshots.json +3 -3
  56. package/packages/selector/src/client/CustomPolicyEditor.tsx +216 -216
  57. package/packages/selector/src/client/EstimatorControls.tsx +277 -277
  58. package/packages/selector/src/client/bridge-scope.ts +125 -0
  59. package/packages/selector/src/client/index.ts +109 -31
  60. package/packages/selector/src/client/monitor-fab.ts +0 -2
  61. package/packages/selector/src/client/preset-options.ts +88 -88
  62. package/packages/selector/src/client/scope-face.ts +24 -24
  63. package/packages/selector/src/compat/host-generation.ts +96 -0
  64. package/packages/selector/src/compat/settings-lease.ts +108 -0
  65. package/packages/selector/src/compat/tool-result.ts +91 -0
  66. package/packages/selector/src/css-modules.d.ts +6 -6
  67. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  68. package/packages/selector/src/estimator-catalog.ts +104 -104
  69. package/packages/selector/src/index.ts +8 -0
  70. package/packages/selector/src/invariant.ts +113 -113
  71. package/packages/selector/src/preset-overlay.ts +626 -626
  72. package/packages/selector/src/pruner/content.ts +198 -198
  73. package/packages/selector/src/pruner/session.ts +97 -96
  74. package/packages/selector/src/pruner/tuning.ts +23 -23
  75. package/packages/selector/src/pruner/types.ts +78 -78
  76. package/packages/selector/src/pruner.ts +45 -40
  77. package/packages/selector/src/runtime/adaptive-cost.ts +205 -205
  78. package/packages/selector/src/runtime/custom-policy.ts +278 -278
  79. package/packages/selector/src/runtime/deepseek-official-pricing.ts +298 -298
  80. package/packages/selector/src/runtime/deepseek-v4-vision-tokens.ts +254 -254
  81. package/packages/selector/src/runtime/measurement.ts +431 -431
  82. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  83. package/packages/selector/src/runtime/retrieve.ts +7 -3
  84. package/packages/selector/src/runtime/session-events.ts +30 -30
  85. package/packages/selector/src/runtime/tail-trim.ts +175 -165
  86. package/packages/selector/src/runtime/token-count.ts +72 -72
  87. package/packages/selector/src/runtime/tokenpilot/advisor.ts +419 -419
  88. package/packages/selector/src/runtime/tokenpilot/benefit.ts +200 -200
  89. package/packages/selector/src/runtime/tokenpilot/dedup.ts +81 -81
  90. package/packages/selector/src/runtime/tokenpilot/estimator.ts +151 -151
  91. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  92. package/packages/selector/src/runtime/tokenpilot/read-state.ts +98 -98
  93. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +303 -303
  94. package/packages/selector/src/runtime/toolclass.ts +103 -103
  95. package/packages/selector/src/runtime/value.ts +48 -48
  96. package/packages/selector/src/settings-bridge.ts +175 -0
  97. package/packages/selector/tests/advisor-report.host.spec.ts +223 -223
  98. package/packages/selector/tests/built/client-artifact.spec.ts +6 -9
  99. package/packages/selector/tests/cache-prefix-audit.spec.ts +123 -123
  100. package/packages/selector/tests/code-skeleton.client.spec.ts +98 -94
  101. package/packages/selector/tests/compat/compat-narrow-waist.spec.ts +150 -0
  102. package/packages/selector/tests/custom-contract.client.spec.ts +226 -223
  103. package/packages/selector/tests/estimator-catalog.spec.ts +70 -70
  104. package/packages/selector/tests/estimator-route-registration.host.spec.ts +199 -194
  105. package/packages/selector/tests/helpers/legacy-namespace.ts +35 -35
  106. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
  107. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
  108. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
  109. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
  110. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
  111. package/packages/selector/tests/host-preset-overlay.host.spec.ts +204 -204
  112. package/packages/selector/tests/preset-options-write.client.spec.ts +192 -188
  113. package/packages/selector/tests/preset-overlay-loader.e2e.host.spec.ts +200 -200
  114. package/packages/selector/tests/preset-overlay.host.spec.ts +246 -246
  115. package/packages/selector/tests/public/package-contract.client.spec.ts +11 -3
  116. package/packages/selector/tests/runtime/adaptive-cost.spec.ts +167 -167
  117. package/packages/selector/tests/runtime/advice-never-withholds.host.spec.ts +230 -230
  118. package/packages/selector/tests/runtime/advisor-invariant.spec.ts +272 -272
  119. package/packages/selector/tests/runtime/advisor.spec.ts +226 -226
  120. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  121. package/packages/selector/tests/runtime/char-basis.spec.ts +30 -30
  122. package/packages/selector/tests/runtime/code-skeleton.spec.ts +152 -152
  123. package/packages/selector/tests/runtime/deepseek-official-pricing.spec.ts +186 -186
  124. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  125. package/packages/selector/tests/runtime/deepseek-v4-vision-tokens.spec.ts +122 -122
  126. package/packages/selector/tests/runtime/deprecated-preset-options.spec.ts +96 -96
  127. package/packages/selector/tests/runtime/fixtures/profile-baseline.json +273 -273
  128. package/packages/selector/tests/runtime/fixtures/tokenizer-golden.json +106 -106
  129. package/packages/selector/tests/runtime/fixtures/vision-golden.json +459 -459
  130. package/packages/selector/tests/runtime/frequency-longstrings.spec.ts +74 -74
  131. package/packages/selector/tests/runtime/html-reducer.spec.ts +212 -212
  132. package/packages/selector/tests/runtime/line-mapping.spec.ts +153 -153
  133. package/packages/selector/tests/runtime/prose-reducers.spec.ts +133 -133
  134. package/packages/selector/tests/runtime/public/public-runtime.spec.ts +3 -3
  135. package/packages/selector/tests/runtime/read-input-cap.spec.ts +33 -33
  136. package/packages/selector/tests/runtime/search-reducer.spec.ts +110 -110
  137. package/packages/selector/tests/runtime/session-events.spec.ts +27 -27
  138. package/packages/selector/tests/runtime/sidechannel.spec.ts +241 -241
  139. package/packages/selector/tests/runtime/toc-and-bundled.spec.ts +159 -159
  140. package/packages/selector/tests/runtime/tokenizer-golden.spec.ts +53 -53
  141. package/packages/selector/tests/runtime/tokenpilot/benefit.spec.ts +217 -217
  142. package/packages/selector/tests/runtime/tokenpilot/dedup.spec.ts +52 -52
  143. package/packages/selector/tests/runtime/tokenpilot/estimator.spec.ts +79 -79
  144. package/packages/selector/tests/runtime/tokenpilot/locator.spec.ts +76 -76
  145. package/packages/selector/tests/runtime/tokenpilot/profile-baseline.spec.ts +116 -116
  146. package/packages/selector/tests/runtime/tokenpilot/read-state.spec.ts +82 -82
  147. package/packages/selector/tests/runtime/toolclass.spec.ts +156 -156
  148. package/packages/selector/tests/runtime/value.spec.ts +23 -23
  149. package/packages/selector/tests/settings-seat.client.spec.ts +45 -7
  150. package/packages/selector/tests/standing-generation.host.spec.ts +724 -724
  151. package/packages/selector/tests/subagent-cache-reuse.host.spec.ts +269 -269
  152. package/packages/selector/tests/support/cache-prefix-audit.ts +105 -105
  153. package/packages/selector/tests/support/mock-adapter.ts +37 -37
  154. package/packages/selector/tests/support/ui-primitives.tsx +34 -34
  155. package/packages/selector/tsconfig.json +11 -11
  156. package/packages/selector/tsdown.client.config.ts +102 -102
  157. package/packages/selector/tsdown.config.ts +20 -20
  158. package/scripts/capture-profile-baseline.mjs +42 -42
  159. package/scripts/generate-tokenizer-fixtures.py +81 -81
  160. package/scripts/generate-vision-fixtures.py +208 -208
  161. package/scripts/hosts.mjs +74 -0
  162. package/scripts/packed-components-smoke.mjs +763 -732
  163. package/scripts/packed-install-e2e.mjs +1330 -1273
  164. package/scripts/sync-hosts.mjs +174 -0
  165. package/scripts/toolclass-corpus-replay.mjs +281 -281
  166. package/scripts/verify-release.mjs +335 -318
  167. package/tsconfig.base.json +18 -18
  168. package/tsconfig.json +7 -7
  169. package/tsconfig.tests.json +15 -15
  170. package/vitest.built.config.ts +9 -9
  171. package/vitest.config.ts +46 -43
@@ -1,194 +1,199 @@
1
- /**
2
- * Host-side guard for the estimator catalog route.
3
- *
4
- * The defect this pins is a registration that never happens: the injection gate
5
- * asked for more services than the handler needs, and an unsatisfied
6
- * `ctx.inject` callback fails silently, so the plugin simply had no HTTP API
7
- * and every request fell through to the host 404. These cases assert the two
8
- * properties that failure violated — the route appears whenever `webServer` is
9
- * usable, in either arrival order, and its absence is never silent.
10
- */
11
-
12
- import { Context } from '@deepseek-ai/cordis'
13
- import { afterEach, describe, expect, it, vi } from 'vitest'
14
- import { apply } from '../src/index.ts'
15
-
16
- const CATALOG_ROUTE = '/api/dsh-context-compression-improved/estimator-catalog'
17
- const LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/estimator-catalog'
18
- const SAVINGS_ROUTE = '/api/dsh-context-compression-improved/savings'
19
- const SAVINGS_LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/savings'
20
- const MONITOR_ROUTE = '/api/dsh-context-compression-improved/monitor'
21
- const MONITOR_LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/monitor'
22
-
23
- interface RegisteredRoute {
24
- kind: string
25
- path: string
26
- handler: (req: unknown, res: unknown) => void
27
- }
28
-
29
- interface FakeResponse {
30
- status?: number
31
- body?: string
32
- }
33
-
34
- /** The state `register` reads off its own `this`, mirroring the host service. */
35
- interface WebServerStub {
36
- tables: { exact: Map<string, RegisteredRoute> }
37
- }
38
-
39
- let ctx: Context | undefined
40
-
41
- afterEach(async () => {
42
- await ctx?.fiber.dispose()
43
- ctx = undefined
44
- })
45
-
46
- /** Settle one macrotask so a deferred activation callback can run. */
47
- const settle = (): Promise<void> => new Promise(resolve => setTimeout(resolve, 20))
48
-
49
- /**
50
- * Mount a host web server stand-in that records routes and reproduces the real
51
- * host's duplicate-`(kind, path)` contract, so a double registration is a
52
- * failure rather than a silent overwrite.
53
- */
54
- async function mountWebServer(runtime: Context, routes: RegisteredRoute[]): Promise<void> {
55
- await runtime.plugin({
56
- name: 'fake-webserver',
57
- apply(webCtx) {
58
- webCtx.provide('webServer', {
59
- // Mirrors dsh-host-webserver: `register` reads its route table off
60
- // `this`. A caller that detaches the method and invokes it standalone
61
- // makes `this` the wrapper and fails here, exactly as the host does --
62
- // which is the defect this spec exists to catch.
63
- tables: { exact: new Map<string, RegisteredRoute>() },
64
- register(this: WebServerStub, route: RegisteredRoute) {
65
- const table = this.tables.exact
66
- if (table.has(route.path)) {
67
- throw new Error(`webserver: duplicate ${route.kind} route "${route.path}"`)
68
- }
69
- table.set(route.path, route)
70
- routes.push(route)
71
- return () => {}
72
- },
73
- })
74
- },
75
- })
76
- }
77
-
78
- /** Mount the estimator-side services the handler only enriches its payload with. */
79
- async function mountEstimatorServices(runtime: Context): Promise<void> {
80
- await runtime.plugin({
81
- name: 'fake-estimator-services',
82
- apply(estimatorCtx) {
83
- estimatorCtx.provide('llm', { listProviders: () => [] })
84
- estimatorCtx.provide('agentDefaultModel', { currentSelection: () => undefined })
85
- },
86
- })
87
- }
88
-
89
- /** Drive one registered route through a stand-in response. */
90
- async function invoke(route: RegisteredRoute): Promise<FakeResponse> {
91
- const captured: FakeResponse = {}
92
- const res = {
93
- writeHead(code: number) { captured.status = code },
94
- end(body?: string) { if (body !== undefined) captured.body = body },
95
- }
96
- route.handler({ method: 'GET' }, res)
97
- await settle()
98
- return captured
99
- }
100
-
101
- describe('estimator catalog route registration', () => {
102
- it('registers both route prefixes with only webServer present', async () => {
103
- const routes: RegisteredRoute[] = []
104
- const runtime = new Context()
105
- ctx = runtime
106
- await mountWebServer(runtime, routes)
107
-
108
- apply(runtime, { estimatorCatalogRoute: true })
109
- await settle()
110
-
111
- expect(routes.map(route => route.path)).toEqual([LEGACY_ROUTE, CATALOG_ROUTE, SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE])
112
- expect(routes.every(route => route.kind === 'exact')).toBe(true)
113
- })
114
-
115
- it('registers the route when webServer activates after the plugin applied', async () => {
116
- const routes: RegisteredRoute[] = []
117
- const runtime = new Context()
118
- ctx = runtime
119
-
120
- apply(runtime, { estimatorCatalogRoute: true })
121
- await settle()
122
- expect(routes).toHaveLength(0)
123
-
124
- await mountWebServer(runtime, routes)
125
- await settle()
126
-
127
- expect(routes.map(route => route.path)).toEqual([LEGACY_ROUTE, CATALOG_ROUTE, SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE])
128
- })
129
-
130
- it('registers nothing twice when the estimator services arrive later', async () => {
131
- const routes: RegisteredRoute[] = []
132
- const runtime = new Context()
133
- ctx = runtime
134
- await mountWebServer(runtime, routes)
135
-
136
- apply(runtime, { estimatorCatalogRoute: true })
137
- await settle()
138
- const afterRegistration = routes.length
139
-
140
- await mountEstimatorServices(runtime)
141
- await settle()
142
-
143
- expect(routes).toHaveLength(afterRegistration)
144
- })
145
-
146
- it('keeps the rest of the plugin alive and warns when webServer never arrives', async () => {
147
- const runtime = new Context()
148
- ctx = runtime
149
- // The diagnostic goes to `console`: the host's cordis logger surfaces no
150
- // plugin output at all, so a lifecycle line published there is invisible.
151
- const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
152
-
153
- try {
154
- expect(() => apply(runtime, { estimatorCatalogRoute: true })).not.toThrow()
155
- await settle()
156
-
157
- const messages = warn.mock.calls.map(([message]) => String(message))
158
- expect(messages.some(message => message.includes('estimator catalog route pending'))).toBe(true)
159
- } finally {
160
- warn.mockRestore()
161
- }
162
- })
163
-
164
- it('answers 200 without the estimator services, which only enrich the payload', async () => {
165
- const routes: RegisteredRoute[] = []
166
- const runtime = new Context()
167
- ctx = runtime
168
- await mountWebServer(runtime, routes)
169
-
170
- apply(runtime, { estimatorCatalogRoute: true })
171
- await settle()
172
-
173
- const route = routes.find(candidate => candidate.path === CATALOG_ROUTE)
174
- expect(route).toBeDefined()
175
- const response = await invoke(route as RegisteredRoute)
176
-
177
- expect(response.status).toBe(200)
178
- expect(JSON.parse(String(response.body))).toMatchObject({ ok: true, providers: [] })
179
- })
180
-
181
- it('without the estimator opt-in only the always-on read routes register (savings + monitor)', async () => {
182
- // savings 与 monitor 路由是有意常开的只读面(纯 token 聚合与折叠状态,无会话内容);estimator
183
- // catalog 才是 opt-in 行。默认面 = 恰好两条 savings 前缀 + 两条 monitor 前缀。
184
- const routes: RegisteredRoute[] = []
185
- const runtime = new Context()
186
- ctx = runtime
187
- await mountWebServer(runtime, routes)
188
-
189
- apply(runtime, { presetOverlay: false })
190
- await settle()
191
-
192
- expect(routes.map(route => route.path)).toEqual([SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE])
193
- })
194
- })
1
+ /**
2
+ * Host-side guard for the estimator catalog route.
3
+ *
4
+ * The defect this pins is a registration that never happens: the injection gate
5
+ * asked for more services than the handler needs, and an unsatisfied
6
+ * `ctx.inject` callback fails silently, so the plugin simply had no HTTP API
7
+ * and every request fell through to the host 404. These cases assert the two
8
+ * properties that failure violated — the route appears whenever `webServer` is
9
+ * usable, in either arrival order, and its absence is never silent.
10
+ */
11
+
12
+ import { Context } from '@deepseek-ai/cordis'
13
+ import { afterEach, describe, expect, it, vi } from 'vitest'
14
+ import { apply } from '../src/index.ts'
15
+
16
+ const CATALOG_ROUTE = '/api/dsh-context-compression-improved/estimator-catalog'
17
+ const LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/estimator-catalog'
18
+ const SAVINGS_ROUTE = '/api/dsh-context-compression-improved/savings'
19
+ const SAVINGS_LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/savings'
20
+ const MONITOR_ROUTE = '/api/dsh-context-compression-improved/monitor'
21
+
22
+ // compat-legacy: the settings bridge rides the same always-on plane — its
23
+ // two routes (both prefixes) register wherever savings/monitor do.
24
+ const SETTINGS_LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/settings'
25
+ const SETTINGS_ROUTE = '/api/dsh-context-compression-improved/settings'
26
+ const MONITOR_LEGACY_ROUTE = '/endpoint/dsh-context-compression-improved/monitor'
27
+
28
+ interface RegisteredRoute {
29
+ kind: string
30
+ path: string
31
+ handler: (req: unknown, res: unknown) => void
32
+ }
33
+
34
+ interface FakeResponse {
35
+ status?: number
36
+ body?: string
37
+ }
38
+
39
+ /** The state `register` reads off its own `this`, mirroring the host service. */
40
+ interface WebServerStub {
41
+ tables: { exact: Map<string, RegisteredRoute> }
42
+ }
43
+
44
+ let ctx: Context | undefined
45
+
46
+ afterEach(async () => {
47
+ await ctx?.fiber.dispose()
48
+ ctx = undefined
49
+ })
50
+
51
+ /** Settle one macrotask so a deferred activation callback can run. */
52
+ const settle = (): Promise<void> => new Promise(resolve => setTimeout(resolve, 20))
53
+
54
+ /**
55
+ * Mount a host web server stand-in that records routes and reproduces the real
56
+ * host's duplicate-`(kind, path)` contract, so a double registration is a
57
+ * failure rather than a silent overwrite.
58
+ */
59
+ async function mountWebServer(runtime: Context, routes: RegisteredRoute[]): Promise<void> {
60
+ await runtime.plugin({
61
+ name: 'fake-webserver',
62
+ apply(webCtx) {
63
+ webCtx.provide('webServer', {
64
+ // Mirrors dsh-host-webserver: `register` reads its route table off
65
+ // `this`. A caller that detaches the method and invokes it standalone
66
+ // makes `this` the wrapper and fails here, exactly as the host does --
67
+ // which is the defect this spec exists to catch.
68
+ tables: { exact: new Map<string, RegisteredRoute>() },
69
+ register(this: WebServerStub, route: RegisteredRoute) {
70
+ const table = this.tables.exact
71
+ if (table.has(route.path)) {
72
+ throw new Error(`webserver: duplicate ${route.kind} route "${route.path}"`)
73
+ }
74
+ table.set(route.path, route)
75
+ routes.push(route)
76
+ return () => {}
77
+ },
78
+ })
79
+ },
80
+ })
81
+ }
82
+
83
+ /** Mount the estimator-side services the handler only enriches its payload with. */
84
+ async function mountEstimatorServices(runtime: Context): Promise<void> {
85
+ await runtime.plugin({
86
+ name: 'fake-estimator-services',
87
+ apply(estimatorCtx) {
88
+ estimatorCtx.provide('llm', { listProviders: () => [] })
89
+ estimatorCtx.provide('agentDefaultModel', { currentSelection: () => undefined })
90
+ },
91
+ })
92
+ }
93
+
94
+ /** Drive one registered route through a stand-in response. */
95
+ async function invoke(route: RegisteredRoute): Promise<FakeResponse> {
96
+ const captured: FakeResponse = {}
97
+ const res = {
98
+ writeHead(code: number) { captured.status = code },
99
+ end(body?: string) { if (body !== undefined) captured.body = body },
100
+ }
101
+ route.handler({ method: 'GET' }, res)
102
+ await settle()
103
+ return captured
104
+ }
105
+
106
+ describe('estimator catalog route registration', () => {
107
+ it('registers both route prefixes with only webServer present', async () => {
108
+ const routes: RegisteredRoute[] = []
109
+ const runtime = new Context()
110
+ ctx = runtime
111
+ await mountWebServer(runtime, routes)
112
+
113
+ apply(runtime, { estimatorCatalogRoute: true })
114
+ await settle()
115
+
116
+ expect(routes.map(route => route.path)).toEqual([LEGACY_ROUTE, CATALOG_ROUTE, SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE, SETTINGS_LEGACY_ROUTE, SETTINGS_ROUTE])
117
+ expect(routes.every(route => route.kind === 'exact')).toBe(true)
118
+ })
119
+
120
+ it('registers the route when webServer activates after the plugin applied', async () => {
121
+ const routes: RegisteredRoute[] = []
122
+ const runtime = new Context()
123
+ ctx = runtime
124
+
125
+ apply(runtime, { estimatorCatalogRoute: true })
126
+ await settle()
127
+ expect(routes).toHaveLength(0)
128
+
129
+ await mountWebServer(runtime, routes)
130
+ await settle()
131
+
132
+ expect(routes.map(route => route.path)).toEqual([LEGACY_ROUTE, CATALOG_ROUTE, SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE, SETTINGS_LEGACY_ROUTE, SETTINGS_ROUTE])
133
+ })
134
+
135
+ it('registers nothing twice when the estimator services arrive later', async () => {
136
+ const routes: RegisteredRoute[] = []
137
+ const runtime = new Context()
138
+ ctx = runtime
139
+ await mountWebServer(runtime, routes)
140
+
141
+ apply(runtime, { estimatorCatalogRoute: true })
142
+ await settle()
143
+ const afterRegistration = routes.length
144
+
145
+ await mountEstimatorServices(runtime)
146
+ await settle()
147
+
148
+ expect(routes).toHaveLength(afterRegistration)
149
+ })
150
+
151
+ it('keeps the rest of the plugin alive and warns when webServer never arrives', async () => {
152
+ const runtime = new Context()
153
+ ctx = runtime
154
+ // The diagnostic goes to `console`: the host's cordis logger surfaces no
155
+ // plugin output at all, so a lifecycle line published there is invisible.
156
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
157
+
158
+ try {
159
+ expect(() => apply(runtime, { estimatorCatalogRoute: true })).not.toThrow()
160
+ await settle()
161
+
162
+ const messages = warn.mock.calls.map(([message]) => String(message))
163
+ expect(messages.some(message => message.includes('estimator catalog route pending'))).toBe(true)
164
+ } finally {
165
+ warn.mockRestore()
166
+ }
167
+ })
168
+
169
+ it('answers 200 without the estimator services, which only enrich the payload', async () => {
170
+ const routes: RegisteredRoute[] = []
171
+ const runtime = new Context()
172
+ ctx = runtime
173
+ await mountWebServer(runtime, routes)
174
+
175
+ apply(runtime, { estimatorCatalogRoute: true })
176
+ await settle()
177
+
178
+ const route = routes.find(candidate => candidate.path === CATALOG_ROUTE)
179
+ expect(route).toBeDefined()
180
+ const response = await invoke(route as RegisteredRoute)
181
+
182
+ expect(response.status).toBe(200)
183
+ expect(JSON.parse(String(response.body))).toMatchObject({ ok: true, providers: [] })
184
+ })
185
+
186
+ it('without the estimator opt-in only the always-on read routes register (savings + monitor)', async () => {
187
+ // savings 与 monitor 路由是有意常开的只读面(纯 token 聚合与折叠状态,无会话内容);estimator
188
+ // catalog 才是 opt-in 行。默认面 = 恰好两条 savings 前缀 + 两条 monitor 前缀。
189
+ const routes: RegisteredRoute[] = []
190
+ const runtime = new Context()
191
+ ctx = runtime
192
+ await mountWebServer(runtime, routes)
193
+
194
+ apply(runtime, { presetOverlay: false })
195
+ await settle()
196
+
197
+ expect(routes.map(route => route.path)).toEqual([SAVINGS_LEGACY_ROUTE, SAVINGS_ROUTE, MONITOR_LEGACY_ROUTE, MONITOR_ROUTE, SETTINGS_LEGACY_ROUTE, SETTINGS_ROUTE])
198
+ })
199
+ })
@@ -1,35 +1,35 @@
1
- /**
2
- * Test-host helper: registers the legacy `context-compression` settings
3
- * namespace on a 0.1.5-shaped test settings service, so specs can drive the
4
- * plugin through `settings.update(...)` exactly as they did before the 0.1.7
5
- * declarative migration. Production code reads the volatile entry field first
6
- * and falls back to this namespace; on a real 0.1.7 host neither the
7
- * registration nor this helper exists.
8
- */
9
- import type { Context } from '@deepseek-ai/cordis'
10
- import {
11
- CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
12
- ContextCompressionSettingsSchema,
13
- } from '../../src/runtime/config.ts'
14
-
15
- export const LegacyNamespaceRegistrar = {
16
- name: 'context-compression:test/legacy-namespace-registrar',
17
- async apply(ctx: Context): Promise<void> {
18
- await new Promise<void>((resolve) => {
19
- ctx.inject(['settings'], (s) => {
20
- try {
21
- // The test host mounts a vendored 0.1.5-shaped provider whose
22
- // static type is the 0.1.7 Context augmentation (`SettingsForms`);
23
- // narrow to the legacy registry surface at the seam.
24
- ;(s.settings as unknown as {
25
- register(ns: never, schema: unknown): unknown
26
- }).register(
27
- CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never,
28
- ContextCompressionSettingsSchema,
29
- )
30
- } catch { /* already registered by an earlier row */ }
31
- resolve()
32
- })
33
- })
34
- },
35
- }
1
+ /**
2
+ * Test-host helper: registers the legacy `context-compression` settings
3
+ * namespace on a 0.1.5-shaped test settings service, so specs can drive the
4
+ * plugin through `settings.update(...)` exactly as they did before the 0.1.7
5
+ * declarative migration. Production code reads the volatile entry field first
6
+ * and falls back to this namespace; on a real 0.1.7 host neither the
7
+ * registration nor this helper exists.
8
+ */
9
+ import type { Context } from '@deepseek-ai/cordis'
10
+ import {
11
+ CONTEXT_COMPRESSION_SETTINGS_NAMESPACE,
12
+ ContextCompressionSettingsSchema,
13
+ } from '../../src/runtime/config.ts'
14
+
15
+ export const LegacyNamespaceRegistrar = {
16
+ name: 'context-compression:test/legacy-namespace-registrar',
17
+ async apply(ctx: Context): Promise<void> {
18
+ await new Promise<void>((resolve) => {
19
+ ctx.inject(['settings'], (s) => {
20
+ try {
21
+ // The test host mounts a vendored 0.1.5-shaped provider whose
22
+ // static type is the 0.1.7 Context augmentation (`SettingsForms`);
23
+ // narrow to the legacy registry surface at the seam.
24
+ ;(s.settings as unknown as {
25
+ register(ns: never, schema: unknown): unknown
26
+ }).register(
27
+ CONTEXT_COMPRESSION_SETTINGS_NAMESPACE as never,
28
+ ContextCompressionSettingsSchema,
29
+ )
30
+ } catch { /* already registered by an earlier row */ }
31
+ resolve()
32
+ })
33
+ })
34
+ },
35
+ }
@@ -1,15 +1,15 @@
1
- /**
2
- * Legacy test-host settings seam.
3
- *
4
- * Vendored verbatim from `@deepseek-ai/dsh-settings@0.1.5-rc.2`
5
- * (`lib/types/index.js` + `lib/types/redact.js`, with the
6
- * `@deepseek-ai/dsh-util-values@0.1.5-rc.2` helpers inlined as
7
- * `./legacy/util-values.js`): the 0.1.7 host replaced the
8
- * namespace-registry provider with declarative `SettingsForms`, while the
9
- * plugin keeps the legacy `ctx.settings.get(ns)` read as a host-shape
10
- * fallback (see src/index.ts). The host specs mount a provider subclassing
11
- * this base to exercise exactly that fallback against the real 0.1.7
12
- * baseline. Type declarations: `./legacy/provider.d.ts`.
13
- */
14
- export { SettingsProvider as LegacySettingsProvider } from './legacy/provider.js'
15
-
1
+ /**
2
+ * Legacy test-host settings seam.
3
+ *
4
+ * Vendored verbatim from `@deepseek-ai/dsh-settings@0.1.5-rc.2`
5
+ * (`lib/types/index.js` + `lib/types/redact.js`, with the
6
+ * `@deepseek-ai/dsh-util-values@0.1.5-rc.2` helpers inlined as
7
+ * `./legacy/util-values.js`): the 0.1.7 host replaced the
8
+ * namespace-registry provider with declarative `SettingsForms`, while the
9
+ * plugin keeps the legacy `ctx.settings.get(ns)` read as a host-shape
10
+ * fallback (see src/index.ts). The host specs mount a provider subclassing
11
+ * this base to exercise exactly that fallback against the real 0.1.7
12
+ * baseline. Type declarations: `./legacy/provider.d.ts`.
13
+ */
14
+ export { SettingsProvider as LegacySettingsProvider } from './legacy/provider.js'
15
+
@@ -1,41 +1,41 @@
1
- /**
2
- * Narrow type surface for the vendored 0.1.5 `SettingsProvider` (legacy test-host seam).
3
- *
4
- * The 0.1.7 `@deepseek-ai/dsh-settings` host replaced the namespace-registry
5
- * provider with the declarative `SettingsForms` projector, but the plugin
6
- * deliberately keeps the legacy `ctx.settings.get(ns)` read as a fallback
7
- * "so a host that still serves the old service shape keeps working (test
8
- * hosts do exactly that)" (src/index.ts). The host specs drive that fallback
9
- * through this vendored base class — the verbatim 0.1.5-rc.2 implementation,
10
- * not a behavioral re-implementation.
11
- *
12
- * Only the members the specs and the production fallback actually touch are
13
- * declared; the full 0.1.5 surface exists at runtime in provider.js.
14
- */
15
- import { Service } from '@deepseek-ai/cordis'
16
-
17
- export declare abstract class SettingsProvider extends Service {
18
- /** Register as the `settings` service of `ctx` (implementation: `super(ctx, 'settings')`). */
19
- constructor(ctx: Context)
20
- /** Whether {@linkcode LegacySettingsProvider.update} may persist through this provider. */
21
- abstract readonly writable: boolean
22
- /** Load the provider's raw document (namespace → raw section) once at init. */
23
- protected abstract load(): Promise<Record<string, unknown>>
24
- /** Durably store one namespace's merged user section. */
25
- protected abstract persist(ns: string, section: Record<string, unknown>): Promise<void>
26
- /** Register a namespace schema; duplicate registration fails loud. */
27
- register(ns: string, schema: unknown, options?: unknown): unknown
28
- /** Read one registered namespace's resolved value (undefined while unregistered). */
29
- get(ns: string): unknown
30
- /** Merge a patch into one registered namespace's user layer, validate, persist. */
31
- update(ns: string, patch: object, expectedRevision?: number): Promise<void>
32
- /** Replace one registered namespace's user section wholesale, validate, persist. */
33
- replace(ns: string, section: object, expectedRevision?: number): Promise<void>
34
- /** Apply path-addressed edits to one registered namespace's user section. */
35
- mutate(ns: string, ops: readonly unknown[], expectedRevision?: number): Promise<void>
36
- /** Describe every registered namespace for configuration surfaces. */
37
- describe(options?: { redactSecrets?: boolean }): unknown[]
38
- /** Non-file providers expose no open-document affordance. */
39
- get documentPath(): string | undefined
40
- prepareDocument(): Promise<string | undefined>
41
- }
1
+ /**
2
+ * Narrow type surface for the vendored 0.1.5 `SettingsProvider` (legacy test-host seam).
3
+ *
4
+ * The 0.1.7 `@deepseek-ai/dsh-settings` host replaced the namespace-registry
5
+ * provider with the declarative `SettingsForms` projector, but the plugin
6
+ * deliberately keeps the legacy `ctx.settings.get(ns)` read as a fallback
7
+ * "so a host that still serves the old service shape keeps working (test
8
+ * hosts do exactly that)" (src/index.ts). The host specs drive that fallback
9
+ * through this vendored base class — the verbatim 0.1.5-rc.2 implementation,
10
+ * not a behavioral re-implementation.
11
+ *
12
+ * Only the members the specs and the production fallback actually touch are
13
+ * declared; the full 0.1.5 surface exists at runtime in provider.js.
14
+ */
15
+ import { Service } from '@deepseek-ai/cordis'
16
+
17
+ export declare abstract class SettingsProvider extends Service {
18
+ /** Register as the `settings` service of `ctx` (implementation: `super(ctx, 'settings')`). */
19
+ constructor(ctx: Context)
20
+ /** Whether {@linkcode LegacySettingsProvider.update} may persist through this provider. */
21
+ abstract readonly writable: boolean
22
+ /** Load the provider's raw document (namespace → raw section) once at init. */
23
+ protected abstract load(): Promise<Record<string, unknown>>
24
+ /** Durably store one namespace's merged user section. */
25
+ protected abstract persist(ns: string, section: Record<string, unknown>): Promise<void>
26
+ /** Register a namespace schema; duplicate registration fails loud. */
27
+ register(ns: string, schema: unknown, options?: unknown): unknown
28
+ /** Read one registered namespace's resolved value (undefined while unregistered). */
29
+ get(ns: string): unknown
30
+ /** Merge a patch into one registered namespace's user layer, validate, persist. */
31
+ update(ns: string, patch: object, expectedRevision?: number): Promise<void>
32
+ /** Replace one registered namespace's user section wholesale, validate, persist. */
33
+ replace(ns: string, section: object, expectedRevision?: number): Promise<void>
34
+ /** Apply path-addressed edits to one registered namespace's user section. */
35
+ mutate(ns: string, ops: readonly unknown[], expectedRevision?: number): Promise<void>
36
+ /** Describe every registered namespace for configuration surfaces. */
37
+ describe(options?: { redactSecrets?: boolean }): unknown[]
38
+ /** Non-file providers expose no open-document affordance. */
39
+ get documentPath(): string | undefined
40
+ prepareDocument(): Promise<string | undefined>
41
+ }