@xmoon76/dsh-pi-tui 0.5.3 → 0.5.4

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 (35) hide show
  1. package/README.en.md +174 -150
  2. package/README.md +118 -103
  3. package/cordis.patch.yml +54 -2
  4. package/dist/builtins.mjs +2 -2
  5. package/dist/client-bootstrap-F5DHFI9t.mjs +5576 -0
  6. package/dist/context-summary-DAisTA_7.mjs +8557 -0
  7. package/dist/dispose-cause-CNFuUnjR.mjs +24 -0
  8. package/dist/entry-control-DvSrndWd.mjs +111 -0
  9. package/dist/extension/advanced.d.mts +1 -1
  10. package/dist/extension/unstable.d.mts +1 -1
  11. package/dist/{extensions-DzpBiiYb.d.mts → extensions-Bte3XOt5.d.mts} +1 -1
  12. package/dist/{extensions-a-rxanjw.mjs → extensions-CcuMY4n2.mjs} +722 -324
  13. package/dist/extensions.d.mts +2 -2
  14. package/dist/extensions.mjs +1 -1
  15. package/dist/host-bootstrap-DAgKknbY.mjs +119 -0
  16. package/dist/index.d.mts +1 -1
  17. package/dist/index.mjs +45243 -27018
  18. package/dist/local-client.mjs +323 -0
  19. package/dist/local-host.mjs +176 -0
  20. package/dist/{performance-host-BJT6scGF.mjs → performance-host-CcDJjjVA.mjs} +1 -1
  21. package/dist/performance-host.mjs +1 -1
  22. package/dist/{performance-view-jvvd8Jn7.mjs → performance-view-CfGvLZyD.mjs} +1 -1
  23. package/dist/{public-types-gZi3iFNh.d.mts → public-types-Dgf1bDke.d.mts} +3 -3
  24. package/dist/runtime-status-0lp9CM0V.mjs +1923 -0
  25. package/dist/{runtime-BtPH-UUb.mjs → runtime-vc4mdr-R.mjs} +1395 -1088
  26. package/dist/{session-BZLxhrPQ.mjs → session-tdJHLnJR.mjs} +3329 -281
  27. package/dist/{startup-D5Xu8diR.mjs → startup-JaVZoTIl.mjs} +54 -13
  28. package/dist/startup.d.mts +2 -1
  29. package/dist/startup.mjs +1 -1
  30. package/dist/{terminal-progress-source-BlmksrSD.mjs → terminal-progress-source-xor3vakJ.mjs} +102 -46
  31. package/dist/visual-tools.d.mts +62 -0
  32. package/dist/visual-tools.mjs +556 -0
  33. package/generated/dsh-presets/README.md +1 -1
  34. package/package.json +132 -113
  35. package/dist/context-summary-CxUpNkA9.mjs +0 -2951
@@ -0,0 +1,556 @@
1
+ import { C as chartArgsProblem, E as chartFactFromArgs, L as PRESENT_VISUAL_TOOL_NAME, S as svgFactFromArgs, g as visualReferenceLine, h as visualReference, i as decidePublication, n as asVisualSessionEvents, o as parsePresentVisualArguments, t as VISUAL_TOOLS_STATUS_SERVICE, v as svgArgsProblem, w as chartContentBlocks, y as svgContentBlocks, z as VISUAL_PUBLISHED_PREFIX } from "./runtime-status-0lp9CM0V.mjs";
2
+ import z from "@deepseek-ai/schemastery";
3
+ import { defineTool } from "@deepseek-ai/dsh-tools";
4
+ //#region src/app/host/visual-tools.ts
5
+ /** Stable Cordis plugin name (the Loader row id in `cordis.patch.yml`). */
6
+ const name = "pi-tui-visual-tools";
7
+ /**
8
+ * The Host services this row uses: the registry it owns, the live Agent (the
9
+ * executing Session identity) and the official Session read service that
10
+ * returns a committed observation.
11
+ */
12
+ const inject = [
13
+ "tools",
14
+ "agents",
15
+ "sessionQuery",
16
+ "sessionProjections"
17
+ ];
18
+ /**
19
+ * The two stable, namespaced generating tool names.
20
+ *
21
+ * These stay DEFINED here (not re-exported from `domain/visual/tools.ts`) for two
22
+ * reasons: `@xmoon76/dsh-pi-tui/visual-tools` has publicly exported them since the
23
+ * row shipped, so removing them would be a breaking change to a published entry,
24
+ * and a re-export would add the domain module's declaration region to the
25
+ * packaged `dist/visual-tools.d.mts`. They are compile-time literals, so the
26
+ * domain's copy is the same value and the two can never disagree at runtime.
27
+ */
28
+ const CHART_TOOL_NAME = "dsh_pi_tui_chart";
29
+ const SVG_TOOL_NAME = "dsh_pi_tui_svg";
30
+ /** The Config schema the Loader resolves (default ON, live form field). */
31
+ const Config = z.object({ enabled: z.boolean().default(true).volatile() });
32
+ const CHART_POINT_SCHEMA = {
33
+ type: "object",
34
+ additionalProperties: false,
35
+ properties: {
36
+ label: {
37
+ type: "string",
38
+ required: true
39
+ },
40
+ value: {
41
+ type: "number",
42
+ required: true
43
+ }
44
+ }
45
+ };
46
+ const CHART_OUTPUT_SCHEMA = {
47
+ type: "object",
48
+ additionalProperties: false,
49
+ properties: {
50
+ version: {
51
+ type: "integer",
52
+ const: 1,
53
+ required: true
54
+ },
55
+ type: {
56
+ type: "string",
57
+ const: "chart",
58
+ required: true
59
+ },
60
+ kind: {
61
+ type: "string",
62
+ enum: ["bars", "spark"],
63
+ required: true
64
+ },
65
+ title: {
66
+ type: "string",
67
+ required: true
68
+ },
69
+ unit: { type: "string" },
70
+ series: {
71
+ type: "array",
72
+ required: true,
73
+ items: CHART_POINT_SCHEMA
74
+ }
75
+ }
76
+ };
77
+ const SVG_OUTPUT_SCHEMA = {
78
+ type: "object",
79
+ additionalProperties: false,
80
+ properties: {
81
+ version: {
82
+ type: "integer",
83
+ const: 1,
84
+ required: true
85
+ },
86
+ type: {
87
+ type: "string",
88
+ const: "svg",
89
+ required: true
90
+ },
91
+ title: {
92
+ type: "string",
93
+ required: true
94
+ },
95
+ description: {
96
+ type: "string",
97
+ required: true
98
+ },
99
+ digest: {
100
+ type: "string",
101
+ required: true
102
+ },
103
+ bytes: {
104
+ type: "integer",
105
+ required: true
106
+ }
107
+ }
108
+ };
109
+ const PUBLISHED_OUTPUT_SCHEMA = {
110
+ type: "object",
111
+ additionalProperties: false,
112
+ properties: {
113
+ version: {
114
+ type: "integer",
115
+ const: 1,
116
+ required: true
117
+ },
118
+ published: {
119
+ type: "array",
120
+ required: true,
121
+ items: {
122
+ type: "object",
123
+ additionalProperties: false,
124
+ properties: { ref: {
125
+ type: "string",
126
+ required: true
127
+ } }
128
+ }
129
+ }
130
+ }
131
+ };
132
+ /**
133
+ * Insert the model-visible reference block before the final `visual-v1:` block
134
+ * of one generating result.
135
+ *
136
+ * The reference is injected ONLY when the call has a real Agent, is a root
137
+ * call, is inside an open turn whose latest boundary is an open `step/start`,
138
+ * succeeded, and already ends with a valid `visual-v1:` fact line. Otherwise
139
+ * the original projection is preserved verbatim — an agentless or failed call
140
+ * keeps its exact previous behaviour.
141
+ */
142
+ function projectVisualReference(projections, exec, result) {
143
+ if (exec.agent === void 0 || exec.parent !== void 0) return void 0;
144
+ if (result.isError) return void 0;
145
+ const boundary = projections.stateOf(exec.agent.session, "turnBoundary");
146
+ if (boundary === void 0) return void 0;
147
+ if (boundary.openTurnStartSeq === null || boundary.lastStepStartSeq === null) return void 0;
148
+ if (boundary.lastStepBoundary === null || boundary.lastStepBoundary.kind !== "start") return void 0;
149
+ const blocks = result.content;
150
+ let lastText = -1;
151
+ for (let index = blocks.length - 1; index >= 0; index -= 1) if (blocks[index].type === "text") {
152
+ lastText = index;
153
+ break;
154
+ }
155
+ if (lastText === -1) return void 0;
156
+ if (!blocks[lastText].text.startsWith("visual-v1:")) return void 0;
157
+ const reference = visualReference({
158
+ sessionId: exec.agent.session.id,
159
+ turn: boundary.lastTurn,
160
+ stepStartSeq: boundary.lastStepStartSeq,
161
+ callId: exec.callId
162
+ });
163
+ return [
164
+ ...blocks.slice(0, lastText),
165
+ {
166
+ type: "text",
167
+ text: visualReferenceLine(reference)
168
+ },
169
+ ...blocks.slice(lastText)
170
+ ];
171
+ }
172
+ /**
173
+ * Define the chart tool. The tool body is a pure canonical projection of the
174
+ * caller's supplied numbers: no filesystem, network, model or workspace access.
175
+ * @param projections - the turn-boundary reader the reference projection uses.
176
+ */
177
+ function chartTool(projections) {
178
+ return defineTool({
179
+ name: CHART_TOOL_NAME,
180
+ description: "Render a small static chart from numbers supplied by the user or by an explicitly labelled example. Use only when a visual comparison is clearer than prose; never invent data, query a monitor, or imply the values are live measurements. Supports bars or a sparkline with 2 to 12 labelled points and an optional unit. The result always includes every exact label and value as readable text, and carries a stable visual ref (`visual-ref-v1:sv1_…`) you may later pass to present_visual.",
181
+ parameters: {
182
+ kind: {
183
+ type: "string",
184
+ enum: ["bars", "spark"],
185
+ required: true,
186
+ description: "Chart shape: bars or spark."
187
+ },
188
+ title: {
189
+ type: "string",
190
+ required: true,
191
+ description: "Short chart title (at most 100 Unicode code points)."
192
+ },
193
+ unit: {
194
+ type: "string",
195
+ description: "Optional unit shown after each value (at most 32 Unicode code points)."
196
+ },
197
+ series: {
198
+ type: "array",
199
+ required: true,
200
+ description: "The supplied points in display order (2 to 12).",
201
+ items: CHART_POINT_SCHEMA
202
+ }
203
+ },
204
+ output: {
205
+ schema: CHART_OUTPUT_SCHEMA,
206
+ render: (_args, value) => chartContentBlocks(value)
207
+ },
208
+ projectContent: (exec, result) => projectVisualReference(projections, exec, result),
209
+ isConcurrencySafe: () => true,
210
+ async execute(args) {
211
+ const problem = chartArgsProblem(args);
212
+ if (problem !== void 0) throw new Error(problem);
213
+ const fact = chartFactFromArgs(args);
214
+ return {
215
+ version: fact.version,
216
+ type: fact.type,
217
+ kind: fact.kind,
218
+ title: fact.title,
219
+ ...fact.unit === void 0 ? {} : { unit: fact.unit },
220
+ series: fact.series.map((point) => ({
221
+ label: point.label,
222
+ value: point.value
223
+ }))
224
+ };
225
+ }
226
+ });
227
+ }
228
+ /**
229
+ * Define the SVG tool. The body admits a bounded static subset and returns the
230
+ * short credential; the source itself stays in the durable call arguments.
231
+ * @param projections - the turn-boundary reader the reference projection uses.
232
+ */
233
+ function svgTool(projections) {
234
+ return defineTool({
235
+ name: SVG_TOOL_NAME,
236
+ description: "Render one static, self-contained SVG figure. Use only when a diagram communicates better than text. The document must have an explicit viewBox or absolute width/height and use only static shapes, paths, text, gradients, masks and local references. Scripts, foreignObject, CSS/style elements, animation, DOCTYPE, external files or URLs are rejected. Use absolute units (px/pt/pc/mm/cm/in or unitless); relative units (percentages, em/ex/ch/rem/vw/vh) are rejected (a gradient stop offset may be a 0-100% fraction). Always provide a short readable description; the result keeps the description and a short source credential, while the SVG source itself stays in the tool call. The result carries a stable visual ref (`visual-ref-v1:sv1_…`) you may later pass to present_visual.",
237
+ parameters: {
238
+ title: {
239
+ type: "string",
240
+ required: true,
241
+ description: "Short figure title (at most 100 code points)."
242
+ },
243
+ description: {
244
+ type: "string",
245
+ required: true,
246
+ description: "Short readable description (at most 500 code points)."
247
+ },
248
+ svg: {
249
+ type: "string",
250
+ required: true,
251
+ description: "The complete standalone SVG document (at most 128 KiB UTF-8)."
252
+ }
253
+ },
254
+ output: {
255
+ schema: SVG_OUTPUT_SCHEMA,
256
+ render: (_args, value) => svgContentBlocks(value)
257
+ },
258
+ projectContent: (exec, result) => projectVisualReference(projections, exec, result),
259
+ isConcurrencySafe: () => true,
260
+ async execute(args) {
261
+ const problem = svgArgsProblem(args);
262
+ if (problem !== void 0) throw new Error(problem);
263
+ return svgFactFromArgs(args);
264
+ }
265
+ });
266
+ }
267
+ /**
268
+ * Define the publication tool.
269
+ *
270
+ * The body reads the committed Session through the official observation lease,
271
+ * fences the turn/step boundary before and after the read, and delegates the
272
+ * whole qualification decision to the domain authority — the same function cold
273
+ * replay uses. A refusal throws one readable error; there is no partial
274
+ * publication.
275
+ * @param ctx - the Host context (recorded so the tool body reads the live Host).
276
+ * @param projections - the turn-boundary reader used for the boundary fences.
277
+ */
278
+ function presentVisualTool(ctx, projections) {
279
+ return defineTool({
280
+ name: PRESENT_VISUAL_TOOL_NAME,
281
+ description: `Select previously generated chart/SVG visuals for presentation to the user. First call dsh_pi_tui_chart or dsh_pi_tui_svg and read the \`visual-ref-v1:sv1_…\` reference in its result. Wait until that generating call has finished, then in a LATER model step pass 1 to 8 refs (usually the 1-2 figures that genuinely help the explanation) and briefly explain their content in your final answer. Only visuals generated in the current turn of this session may be selected; the whole call fails if any ref is unknown, repeated, from an earlier turn, or not committed yet.`,
282
+ parameters: { visuals: {
283
+ type: "array",
284
+ required: true,
285
+ description: `The visuals to present, in display order (1 to 8).`,
286
+ items: {
287
+ type: "object",
288
+ additionalProperties: false,
289
+ properties: { ref: {
290
+ type: "string",
291
+ required: true,
292
+ description: "The `sv1_…` reference from a chart/SVG tool result."
293
+ } }
294
+ }
295
+ } },
296
+ output: {
297
+ schema: PUBLISHED_OUTPUT_SCHEMA,
298
+ render: (_args, value) => publicationBlocks(value)
299
+ },
300
+ isConcurrencySafe: () => true,
301
+ async execute(args, exec) {
302
+ if (exec.agent === void 0) throw new Error("present_visual requires an agent Session");
303
+ if (exec.parent !== void 0) throw new Error("present_visual is only available as a top-level model tool call");
304
+ const parsed = parsePresentVisualArguments(args);
305
+ if (!parsed.ok) throw new Error(parsed.reason);
306
+ const requested = parsed.refs;
307
+ const session = exec.agent.session;
308
+ const before = requireOpenStep(projections, session, "present_visual");
309
+ const observation = await ctx.reflect.get("sessionQuery").observeSession(session.id, {
310
+ signal: exec.signal,
311
+ projectionMode: "none"
312
+ });
313
+ let events;
314
+ try {
315
+ exec.signal.throwIfAborted();
316
+ if (observation.header.id !== session.id) throw new Error("present_visual could not confirm the executing Session identity");
317
+ if (observation.source !== "live") throw new Error("present_visual requires a live Session observation");
318
+ events = asVisualSessionEvents(observation.events);
319
+ } finally {
320
+ observation[Symbol.dispose]();
321
+ }
322
+ exec.signal.throwIfAborted();
323
+ if (!sameBoundary(before, requireOpenStep(projections, session, "present_visual"))) throw new Error("present_visual aborted: the turn/step boundary changed while reading the Session");
324
+ const decision = decidePublication({
325
+ sessionId: session.id,
326
+ events,
327
+ refs: [...requested],
328
+ turn: before.lastTurn,
329
+ stepStartSeq: before.lastStepStartSeq,
330
+ callId: exec.callId
331
+ });
332
+ if (!decision.ok) throw new Error(decision.reason);
333
+ return {
334
+ version: 1,
335
+ published: decision.receipt.published.map((entry) => ({ ref: entry.ref }))
336
+ };
337
+ }
338
+ });
339
+ }
340
+ /** Read the turn boundary and require an open turn with an open `step/start`. */
341
+ function requireOpenStep(projections, session, toolName) {
342
+ const boundary = projections.stateOf(session, "turnBoundary");
343
+ if (boundary === void 0) throw new Error(`${toolName} requires the turnBoundary session projection`);
344
+ if (boundary.openTurnStartSeq === null) throw new Error(`${toolName} requires an open turn`);
345
+ if (boundary.lastStepStartSeq === null) throw new Error(`${toolName} requires an open step`);
346
+ if (boundary.lastStepBoundary === null || boundary.lastStepBoundary.kind !== "start") throw new Error(`${toolName} requires an open step`);
347
+ return boundary;
348
+ }
349
+ /** Whether two boundary reads describe the exact same execution fence. */
350
+ function sameBoundary(a, b) {
351
+ const stepA = a.lastStepBoundary;
352
+ const stepB = b.lastStepBoundary;
353
+ return a.openTurnStartSeq === b.openTurnStartSeq && a.lastStepStartSeq === b.lastStepStartSeq && a.lastTurn === b.lastTurn && stepA?.kind === stepB?.kind && stepA?.seq === stepB?.seq;
354
+ }
355
+ /** The two content blocks of one successful publication receipt. */
356
+ function publicationBlocks(value) {
357
+ const count = value.published.length;
358
+ return [{
359
+ type: "text",
360
+ text: `Selected ${count} visual${count === 1 ? "" : "s"} for presentation.`
361
+ }, {
362
+ type: "text",
363
+ text: `${VISUAL_PUBLISHED_PREFIX}${JSON.stringify(value)}`
364
+ }];
365
+ }
366
+ /** Fail closed when a visible same-name definition already owns the name. */
367
+ function assertNameFree(tools, toolName) {
368
+ if (tools.get(toolName) !== void 0) throw new Error(`visual tool name conflict: "${toolName}" is already registered; this row will not shadow another tool`);
369
+ }
370
+ /**
371
+ * Release one registration and answer the handle the row should keep.
372
+ *
373
+ * A dsh-tools disposer removes the registry entry BEFORE it emits
374
+ * `tools/change`, and that synchronous emit propagates listener exceptions.
375
+ * The handle may therefore be dropped even when `dispose()` throws (the tool is
376
+ * already gone); it is kept only while the registry still returns THIS
377
+ * definition, so a later reconciliation can attempt the release again.
378
+ */
379
+ function releaseRegistered(tools, name, registered, errors) {
380
+ if (registered === void 0) return void 0;
381
+ try {
382
+ registered.dispose();
383
+ } catch (error) {
384
+ errors.push(error);
385
+ if (tools.get(name) === registered.definition) return registered;
386
+ }
387
+ }
388
+ /**
389
+ * Register this Host row: reconcile the three tool registrations with the
390
+ * `enabled` Config reference at mount and after every volatile commit.
391
+ *
392
+ * `ctx.reflect.get` is the documented permanent-Host-plane idiom
393
+ * (`docs/architecture/host-client.md`): this module IS the Host plane, so the
394
+ * registry read is not Client-side coupling and the client-boundary inventory
395
+ * stays inside the existing baseline. The explicit `inject` above guarantees
396
+ * every service.
397
+ *
398
+ * The Loader commits every volatile value BEFORE it dispatches
399
+ * `loader/volatile-update`, so the listener must read the reference (never the
400
+ * event payload) and ignore unrelated paths. A throwing listener is contained
401
+ * by the Loader: the write stays committed, and the next read of
402
+ * {@link VISUAL_TOOLS_STATUS_SERVICE} proves the registration did not follow.
403
+ *
404
+ * Reconciliation is SERIALIZED: a `tools/change` listener may synchronously
405
+ * write the Config back from inside a registration/disposal callback, so that
406
+ * request is queued and applied after the current transition reaches a
407
+ * consistent group instead of interleaving two transitions.
408
+ *
409
+ * @param ctx - the Host context that owns this row's fiber.
410
+ * @param config - the resolved Config (the live `enabled` reference).
411
+ */
412
+ function apply(ctx, config) {
413
+ const tools = ctx.reflect.get("tools");
414
+ const projections = ctx.reflect.get("sessionProjections");
415
+ let chart;
416
+ let svg;
417
+ let present;
418
+ /** One synchronous reconciliation seat (see `request`). */
419
+ let reconciling = false;
420
+ /** The LATEST requested target while the seat is held. */
421
+ let pending;
422
+ /** The live group, in registration order. */
423
+ const group = () => [
424
+ [CHART_TOOL_NAME, chart],
425
+ [SVG_TOOL_NAME, svg],
426
+ [PRESENT_VISUAL_TOOL_NAME, present]
427
+ ];
428
+ /** The LIVE GROUP fact, read from the official registry (never a second
429
+ * enable value): all three definitions this row registered are currently
430
+ * the ones the registry returns. A partially released group answers false. */
431
+ const applied = () => group().every(([name, registered]) => registered !== void 0 && tools.get(name) === registered.definition);
432
+ ctx.provide(VISUAL_TOOLS_STATUS_SERVICE, { applied });
433
+ /**
434
+ * Attempt ALL THREE releases even when one of them throws, then surface the
435
+ * collected failures: one broken `tools/change` listener must never strand
436
+ * the other registrations. Releases run in reverse registration order.
437
+ *
438
+ * The handles are DETACHED before any disposer runs. A disposer emits
439
+ * `tools/change` synchronously, and a Host listener may re-enter the switch;
440
+ * that request is queued by `request()`, but it must never observe or
441
+ * overwrite a handle this release already owns.
442
+ */
443
+ const release = () => {
444
+ const errors = [];
445
+ const releasing = [
446
+ [PRESENT_VISUAL_TOOL_NAME, present],
447
+ [SVG_TOOL_NAME, svg],
448
+ [CHART_TOOL_NAME, chart]
449
+ ];
450
+ chart = void 0;
451
+ svg = void 0;
452
+ present = void 0;
453
+ const restored = /* @__PURE__ */ new Map();
454
+ for (const [name, registered] of releasing) {
455
+ const kept = releaseRegistered(tools, name, registered, errors);
456
+ if (kept !== void 0) restored.set(name, kept);
457
+ }
458
+ chart = restored.get(CHART_TOOL_NAME);
459
+ svg = restored.get(SVG_TOOL_NAME);
460
+ present = restored.get(PRESENT_VISUAL_TOOL_NAME);
461
+ if (errors.length === 1) throw errors[0];
462
+ if (errors.length > 1) throw new AggregateError(errors, "visual tools: releasing the registrations failed");
463
+ };
464
+ /** Register all three definitions in the fixed order; a failure rolls back the
465
+ * ones this transition already registered, so the SETTLED group is all-or-none.
466
+ * Each `tools.register()` publishes its own `tools/change` synchronously (the
467
+ * registry has no batch seam), so a synchronous observer can see the
468
+ * intermediate additions of a transition that is still running. */
469
+ const register = () => {
470
+ for (const [name] of group()) assertNameFree(tools, name);
471
+ const created = [];
472
+ const rollback = (failure) => {
473
+ const errors = [failure];
474
+ for (const registered of [...created].reverse()) try {
475
+ registered.dispose();
476
+ } catch (rollbackError) {
477
+ errors.push(rollbackError);
478
+ }
479
+ if (errors.length === 1) throw failure;
480
+ throw new AggregateError(errors, "visual tools: a registration failed and the rollback did not complete");
481
+ };
482
+ try {
483
+ const chartDefinition = chartTool(projections);
484
+ chart = {
485
+ definition: chartDefinition,
486
+ dispose: tools.register(chartDefinition)
487
+ };
488
+ created.push(chart);
489
+ const svgDefinition = svgTool(projections);
490
+ svg = {
491
+ definition: svgDefinition,
492
+ dispose: tools.register(svgDefinition)
493
+ };
494
+ created.push(svg);
495
+ const presentDefinition = presentVisualTool(ctx, projections);
496
+ present = {
497
+ definition: presentDefinition,
498
+ dispose: tools.register(presentDefinition)
499
+ };
500
+ created.push(present);
501
+ } catch (error) {
502
+ chart = void 0;
503
+ svg = void 0;
504
+ present = void 0;
505
+ rollback(error);
506
+ }
507
+ };
508
+ /** Apply ONE settled target value; runs only while `request()` holds the
509
+ * reconciliation seat. */
510
+ const applyState = (enabled) => {
511
+ if (enabled) {
512
+ if (applied()) return;
513
+ release();
514
+ register();
515
+ return;
516
+ }
517
+ release();
518
+ };
519
+ /**
520
+ * Serialize every reconciliation request. The Loader commits the value
521
+ * before dispatch, and a `tools/change` listener may synchronously write the
522
+ * Config back (or emit `loader/volatile-update` directly) from inside a
523
+ * registration or disposal callback. Re-entering the state machine there
524
+ * would interleave two group transitions and could clobber a newly registered
525
+ * handle, so a nested request only records the LATEST target; the outer drain
526
+ * applies it after the current transition reaches a consistent group.
527
+ */
528
+ const request = (enabled) => {
529
+ pending = enabled;
530
+ if (reconciling) return;
531
+ reconciling = true;
532
+ const failures = [];
533
+ try {
534
+ while (pending !== void 0) {
535
+ const next = pending;
536
+ pending = void 0;
537
+ try {
538
+ applyState(next);
539
+ } catch (error) {
540
+ failures.push(error);
541
+ }
542
+ }
543
+ } finally {
544
+ reconciling = false;
545
+ }
546
+ if (failures.length === 1) throw failures[0];
547
+ if (failures.length > 1) throw new AggregateError(failures, "visual tools: reconciliation failed repeatedly");
548
+ };
549
+ ctx.on("loader/volatile-update", (paths) => {
550
+ if (!paths.some((path) => path.length === 1 && path[0] === "enabled")) return;
551
+ request(config.enabled.get());
552
+ });
553
+ request(config.enabled.get());
554
+ }
555
+ //#endregion
556
+ export { CHART_TOOL_NAME, Config, SVG_TOOL_NAME, apply, inject, name };
@@ -6,7 +6,7 @@ patch assets exported by `@deepseek-ai/dsh-web-app` (see
6
6
 
7
7
  **DO NOT EDIT.** dsh-pi-tui does not own the shipped preset definitions:
8
8
  `pnpm build` regenerates the mirror from the official package, and
9
- `test/dsh-preset-parity.test.mjs` fails the suite on any byte drift.
9
+ `test/tooling/dsh-preset-parity.test.mjs` fails the suite on any byte drift.
10
10
 
11
11
  This mirror exists only because DSH 0.1.7's (through 0.1.7-rc.2)
12
12
  `dsh.bundle.patch` resolves bundle-package-relative paths and cannot