@thready-web/dsh-bot-plugin 0.1.0-beta.1 → 0.1.0-beta.11

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 (160) hide show
  1. package/README.md +109 -1
  2. package/client.js +646 -621
  3. package/dist/approvals.js +160 -0
  4. package/dist/authorization.js +225 -0
  5. package/dist/canvas-http.js +248 -0
  6. package/dist/canvas-skills.js +56 -0
  7. package/dist/canvas-store.js +794 -0
  8. package/dist/canvas-tools.js +211 -0
  9. package/dist/cli.js +32 -12
  10. package/dist/context.js +60 -17
  11. package/dist/cron.js +1 -1
  12. package/dist/cua-access.js +79 -0
  13. package/dist/desk.js +314 -37
  14. package/dist/engine.js +178 -84
  15. package/dist/fs-safe.js +1 -1
  16. package/dist/host.js +1 -0
  17. package/dist/http-plugin.js +14 -4
  18. package/dist/http.js +402 -85
  19. package/dist/inbox.js +51 -40
  20. package/dist/index.js +201 -47
  21. package/dist/live-diff.js +3 -1
  22. package/dist/live-snapshot.js +2 -13
  23. package/dist/log/canonical.js +37 -0
  24. package/dist/log/plan.js +62 -0
  25. package/dist/log/routes.js +144 -0
  26. package/dist/log/snapshot-service.js +76 -0
  27. package/dist/log/source.js +173 -0
  28. package/dist/memory-catalog.js +798 -0
  29. package/dist/permissions.js +86 -0
  30. package/dist/provision.js +2 -0
  31. package/dist/questions.js +407 -0
  32. package/dist/runtime-registry.js +4 -4
  33. package/dist/session-files.js +2 -2
  34. package/dist/session-previews.js +5 -1
  35. package/dist/store.js +20 -5
  36. package/dist/tools.js +150 -32
  37. package/dist/triggers.js +83 -39
  38. package/dist/work-admit.js +222 -25
  39. package/dist/work-child.js +17 -9
  40. package/dist/work-http.js +52 -2
  41. package/dist/work-ledger.js +256 -16
  42. package/dist/work-mock-host.js +9 -6
  43. package/dist/work-mock.js +29 -19
  44. package/dist/work-tickets.js +423 -96
  45. package/dist/work-tools.js +43 -6
  46. package/dist/work-worker.js +1033 -207
  47. package/dist/workspace-files.js +319 -0
  48. package/dist/workspace-image.js +91 -0
  49. package/fixtures/mock-llm.mjs +17 -2
  50. package/package.json +16 -5
  51. package/public/assets/SourceEditor-CJwK846Z.css +1 -0
  52. package/public/assets/SourceEditor-uu0G7jsM.js +669 -0
  53. package/public/assets/abap-CRCWOmpq.js +1 -0
  54. package/public/assets/apex-DnsZk_dE.js +1 -0
  55. package/public/assets/azcli-1IWB1ccx.js +1 -0
  56. package/public/assets/bat-DPkNLes8.js +1 -0
  57. package/public/assets/bicep-Corcdgou.js +2 -0
  58. package/public/assets/cameligo-CGrWLZr3.js +1 -0
  59. package/public/assets/clojure-D9WOWImG.js +1 -0
  60. package/public/assets/codicon-DCmgc-ay.ttf +0 -0
  61. package/public/assets/coffee-B7EJu28W.js +1 -0
  62. package/public/assets/cpp-SEyurbux.js +1 -0
  63. package/public/assets/csharp-BoL64M5l.js +1 -0
  64. package/public/assets/csp-C46ZqvIl.js +1 -0
  65. package/public/assets/css-DQU6DXDx.js +3 -0
  66. package/public/assets/css.worker-DYpkewsP.js +79 -0
  67. package/public/assets/cssMode-C5DAFF5H.js +4 -0
  68. package/public/assets/cypher-D84EuPTj.js +1 -0
  69. package/public/assets/dart-D8lhlL1r.js +1 -0
  70. package/public/assets/dockerfile-DLk6rpji.js +1 -0
  71. package/public/assets/ecl-BO6FnfXk.js +1 -0
  72. package/public/assets/editor.worker-B4pQIWZD.js +12 -0
  73. package/public/assets/elixir-BRjLKONM.js +1 -0
  74. package/public/assets/flow9-Cac8vKd7.js +1 -0
  75. package/public/assets/freemarker2-DExNwSiZ.js +3 -0
  76. package/public/assets/fsharp-fd1GTHhf.js +1 -0
  77. package/public/assets/go-O9LJTZXk.js +1 -0
  78. package/public/assets/graphql-LQdxqEYJ.js +1 -0
  79. package/public/assets/handlebars-BK7YAvpQ.js +1 -0
  80. package/public/assets/hcl-DxDQ3s82.js +1 -0
  81. package/public/assets/html-CdDm_zae.js +1 -0
  82. package/public/assets/html.worker-tnXziJOq.js +456 -0
  83. package/public/assets/htmlMode-CLdn9oa1.js +4 -0
  84. package/public/assets/index-BB-QDSf2.css +1 -0
  85. package/public/assets/index-CsX-_qbo.js +62 -0
  86. package/public/assets/ini-BvajGCUy.js +1 -0
  87. package/public/assets/java-SYsfObOQ.js +1 -0
  88. package/public/assets/javascript-mLl83_3W.js +1 -0
  89. package/public/assets/json.worker-aFakAbRR.js +44 -0
  90. package/public/assets/jsonMode-B1-bihFd.js +10 -0
  91. package/public/assets/julia-DQXNmw_w.js +1 -0
  92. package/public/assets/kotlin-qQ0MG-9I.js +1 -0
  93. package/public/assets/less-GGFNNJHn.js +2 -0
  94. package/public/assets/lexon-Canl7DCW.js +1 -0
  95. package/public/assets/liquid-Cv8m0HUb.js +1 -0
  96. package/public/assets/lua-D28Ae8-K.js +1 -0
  97. package/public/assets/m3-DPitgjJI.js +1 -0
  98. package/public/assets/markdown-B811l8j2.js +1 -0
  99. package/public/assets/mdx-Q12b91rL.js +1 -0
  100. package/public/assets/mips-CdjsipkG.js +1 -0
  101. package/public/assets/msdax-CYqgjx_P.js +1 -0
  102. package/public/assets/mysql-BHd6q0vd.js +1 -0
  103. package/public/assets/objective-c-B1aVtJYH.js +1 -0
  104. package/public/assets/pascal-BhNW15KB.js +1 -0
  105. package/public/assets/pascaligo-5jv8CcQD.js +1 -0
  106. package/public/assets/perl-DlYyT36c.js +1 -0
  107. package/public/assets/pgsql-Dy0bjov7.js +1 -0
  108. package/public/assets/php-120yhfDK.js +1 -0
  109. package/public/assets/pla-CjnFlu4u.js +1 -0
  110. package/public/assets/postiats-CQpG440k.js +1 -0
  111. package/public/assets/powerquery-DdJtto1Z.js +1 -0
  112. package/public/assets/powershell-Bu_VLpJB.js +1 -0
  113. package/public/assets/protobuf-IBS6jZEB.js +2 -0
  114. package/public/assets/pug-kFxLfcjb.js +1 -0
  115. package/public/assets/python-Kda811W0.js +1 -0
  116. package/public/assets/qsharp-q7JyzKFN.js +1 -0
  117. package/public/assets/r-BIFz-_sK.js +1 -0
  118. package/public/assets/razor-CRuCpdOW.js +1 -0
  119. package/public/assets/redis-CHOsPHWR.js +1 -0
  120. package/public/assets/redshift-CBifECDb.js +1 -0
  121. package/public/assets/restructuredtext-CghPJEOS.js +1 -0
  122. package/public/assets/ruby-CYWGW-b1.js +1 -0
  123. package/public/assets/rust-DMDD0SHb.js +1 -0
  124. package/public/assets/sb-BYAiYHFx.js +1 -0
  125. package/public/assets/scala-Bqvq8jcR.js +1 -0
  126. package/public/assets/scheme-Dhb-2j9p.js +1 -0
  127. package/public/assets/scss-CTwUZ5N7.js +3 -0
  128. package/public/assets/shell-CsDZo4DB.js +1 -0
  129. package/public/assets/solidity-CME5AdoB.js +1 -0
  130. package/public/assets/sophia-RYC1BQQz.js +1 -0
  131. package/public/assets/sparql-KEyrF7De.js +1 -0
  132. package/public/assets/sql-BdTr02Mf.js +1 -0
  133. package/public/assets/st-C7iG7M4S.js +1 -0
  134. package/public/assets/swift-D7IUmUK8.js +1 -0
  135. package/public/assets/systemverilog-DgMryOEJ.js +1 -0
  136. package/public/assets/tcl-PloMZuKG.js +1 -0
  137. package/public/assets/ts.worker-Bij5J2kb.js +51316 -0
  138. package/public/assets/tsMode-BGHcz-M3.js +11 -0
  139. package/public/assets/twig-BfRIq3la.js +1 -0
  140. package/public/assets/typescript-Db1e0DCT.js +1 -0
  141. package/public/assets/typespec-CzxlYoT_.js +1 -0
  142. package/public/assets/vb-BwAE3J76.js +1 -0
  143. package/public/assets/wgsl-B_1kOXbF.js +298 -0
  144. package/public/assets/xml-H3zzFmnd.js +1 -0
  145. package/public/assets/yaml-BQrKvmTF.js +1 -0
  146. package/public/index.html +2 -2
  147. package/skills/ui/baseline-ui/SKILL.md +85 -0
  148. package/skills/ui/bencium-innovative-ux-designer/SKILL.md +227 -0
  149. package/skills/ui/better-ui/SKILL.md +133 -0
  150. package/skills/ui/design-lab/SKILL.md +920 -0
  151. package/skills/ui/frontend-design/SKILL.md +71 -0
  152. package/skills/ui/impeccable/SKILL.md +93 -0
  153. package/skills/ui/interface-design/SKILL.md +320 -0
  154. package/skills/ui/sources.json +66 -0
  155. package/skills/ui/ui-design/SKILL.md +35 -0
  156. package/skills/ui/ui-skills-root/SKILL.md +59 -0
  157. package/skills/ui/visual-design-foundations/SKILL.md +318 -0
  158. package/skills/ui/web-design-guidelines/SKILL.md +39 -0
  159. package/public/assets/index-Be82iGwe.css +0 -1
  160. package/public/assets/index-ByU9a3Lh.js +0 -61
@@ -1,19 +1,179 @@
1
1
  /** Admission and host budgets. Neither function calls a model or reorders an inbox. */
2
+ /**
3
+ * Main-session caps. The main bot may still call host tools; these caps are a
4
+ * runaway guard. Worker parallelism is a separate slot/queue policy: `perBot`
5
+ * and `global` limit running workers, and `perBotQueue` / `globalQueue` cap
6
+ * tickets waiting for a slot. `needs_user` does not occupy a running slot.
7
+ * `main*` is the cap after a dispatch or a host tool and is never looser than
8
+ * `chat*`.
9
+ */
10
+ /** Hard ceiling so a typo cannot raise a slot cap without bound. */
11
+ export const WORK_SLOT_MAX = 64;
12
+ /** Hard ceiling so a typo cannot raise a queue cap without bound. */
13
+ export const WORK_QUEUE_MAX = 256;
2
14
  export const DEFAULT_WORK_BUDGET = Object.freeze({
3
- mainMaxSteps: 2,
4
- mainWallMs: 20_000,
5
- chatMaxSteps: 4,
6
- chatWallMs: 120_000,
15
+ mainMaxSteps: 80,
16
+ mainWallMs: 30 * 60 * 1000,
17
+ chatMaxSteps: 80,
18
+ chatWallMs: 30 * 60 * 1000,
7
19
  holdMs: 15_000,
8
20
  workerMaxSteps: 8,
9
- workerWallMs: 10 * 60 * 1000,
10
- workerMaxTokens: 400_000,
11
- perBot: 1,
12
- global: 2,
21
+ /** One budget slice. A grant adds another slice; there is no cumulative ceiling. */
22
+ workerWallMs: 30 * 60 * 1000,
23
+ /** One budget slice. A grant adds another slice; there is no cumulative ceiling. */
24
+ workerMaxTokens: 1_000_000,
25
+ perBot: 2,
26
+ global: 4,
27
+ perBotQueue: 8,
28
+ globalQueue: 16,
13
29
  leaseMs: 60_000,
14
30
  starveMs: 30_000,
15
31
  mergeWindowMs: 1_000,
16
32
  });
33
+ const BUDGET_KEYS = Object.keys(DEFAULT_WORK_BUDGET);
34
+ const INT_MAX = {
35
+ perBot: WORK_SLOT_MAX,
36
+ global: WORK_SLOT_MAX,
37
+ perBotQueue: WORK_QUEUE_MAX,
38
+ globalQueue: WORK_QUEUE_MAX,
39
+ };
40
+ /**
41
+ * A single bot cannot run more workers than the global cap, even if `perBot`
42
+ * is larger. The same applies to the queue caps. Existing running workers are
43
+ * not cancelled when a later process start uses a lower cap.
44
+ * @param {WorkBudget} budget
45
+ */
46
+ export function effectiveWorkLimits(budget) {
47
+ return {
48
+ perBot: Math.min(budget.perBot, budget.global),
49
+ global: budget.global,
50
+ perBotQueue: Math.min(budget.perBotQueue, budget.globalQueue),
51
+ globalQueue: budget.globalQueue,
52
+ };
53
+ }
54
+ /** Environment variable the launcher uses to pass `--work-budget` to the plugin. */
55
+ export const WORK_BUDGET_ENV = 'DSH_BOT_WORK_BUDGET';
56
+ /**
57
+ * Milliseconds from a number or a `90s` / `30m` / `2h` / `1500ms` string.
58
+ * @param {unknown} value
59
+ */
60
+ function durationMs(value) {
61
+ if (typeof value === 'number')
62
+ return value;
63
+ if (typeof value !== 'string')
64
+ return Number.NaN;
65
+ const match = /^\s*(\d+(?:\.\d+)?)\s*(ms|s|m|h)?\s*$/i.exec(value);
66
+ if (!match)
67
+ return Number.NaN;
68
+ const unit = (match[2] ?? 'ms').toLowerCase();
69
+ const scale = unit === 'h' ? 3_600_000 : unit === 'm' ? 60_000 : unit === 's' ? 1000 : 1;
70
+ return Number(match[1]) * scale;
71
+ }
72
+ /**
73
+ * Keep only known, positive, finite budget fields. Unknown keys and bad values
74
+ * are dropped (and listed in `ignored`) so a typo never zeroes a cap or raises
75
+ * it to Infinity. Slot and queue integers above WORK_SLOT_MAX / WORK_QUEUE_MAX
76
+ * are clamped (and listed in `clamped`). Non-integer slot/queue/step values
77
+ * are ignored.
78
+ * Shorthands: `steps` sets mainMaxSteps and chatMaxSteps; `wall` sets mainWallMs and chatWallMs.
79
+ * Fields ending in `Ms` accept duration strings such as `30m`.
80
+ * @param {unknown} input
81
+ */
82
+ export function normalizeWorkBudget(input) {
83
+ const budget = {};
84
+ const ignored = [];
85
+ const clamped = [];
86
+ if (input == null || typeof input !== 'object' || Array.isArray(input))
87
+ return { budget, ignored, clamped };
88
+ const raw = { ...input };
89
+ const expanded = {};
90
+ if ('steps' in raw) {
91
+ expanded.mainMaxSteps = raw.steps;
92
+ expanded.chatMaxSteps = raw.steps;
93
+ delete raw.steps;
94
+ }
95
+ if ('wall' in raw) {
96
+ expanded.mainWallMs = raw.wall;
97
+ expanded.chatWallMs = raw.wall;
98
+ delete raw.wall;
99
+ }
100
+ Object.assign(expanded, raw);
101
+ for (const [key, value] of Object.entries(expanded)) {
102
+ if (!BUDGET_KEYS.includes(key)) {
103
+ ignored.push(key);
104
+ continue;
105
+ }
106
+ const duration = key.endsWith('Ms');
107
+ const number = duration ? durationMs(value) : Number(value);
108
+ if (!Number.isFinite(number) || number <= 0) {
109
+ ignored.push(key);
110
+ continue;
111
+ }
112
+ if (!duration && !Number.isInteger(number)) {
113
+ ignored.push(key);
114
+ continue;
115
+ }
116
+ const max = INT_MAX[key];
117
+ if (max != null && number > max) {
118
+ budget[key] = max;
119
+ clamped.push(key);
120
+ continue;
121
+ }
122
+ budget[key] = duration ? Math.floor(number) : number;
123
+ }
124
+ return { budget, ignored, clamped };
125
+ }
126
+ /**
127
+ * Parse `--work-budget` / DSH_BOT_WORK_BUDGET: JSON (`{"steps":80,"wall":"30m"}`)
128
+ * or comma-separated `key=value` (`steps=80,wall=30m,mainMaxSteps=10`).
129
+ * @param {string | undefined} text
130
+ */
131
+ export function parseWorkBudget(text) {
132
+ const source = typeof text === 'string' ? text.trim() : '';
133
+ if (source === '')
134
+ return { budget: {}, ignored: [], clamped: [] };
135
+ if (source.startsWith('{')) {
136
+ try {
137
+ return normalizeWorkBudget(JSON.parse(source));
138
+ }
139
+ catch {
140
+ return { budget: {}, ignored: [source], clamped: [] };
141
+ }
142
+ }
143
+ const object = {};
144
+ const ignored = [];
145
+ for (const part of source.split(',')) {
146
+ const piece = part.trim();
147
+ if (piece === '')
148
+ continue;
149
+ const eq = piece.indexOf('=');
150
+ if (eq <= 0) {
151
+ ignored.push(piece);
152
+ continue;
153
+ }
154
+ object[piece.slice(0, eq).trim()] = piece.slice(eq + 1).trim();
155
+ }
156
+ const normalized = normalizeWorkBudget(object);
157
+ return { budget: normalized.budget, ignored: [...ignored, ...normalized.ignored], clamped: normalized.clamped };
158
+ }
159
+ /**
160
+ * Defaults, then the environment (launcher `--work-budget` / `DSH_BOT_WORK_BUDGET`),
161
+ * then plugin config `work`. Limits are applied when the work runtime is created
162
+ * (process start or plugin load). They are not hot-reloaded into an already
163
+ * running runtime. Lowering a cap never cancels a worker that is already running;
164
+ * later dispatch and promotion use the new caps.
165
+ * @param {unknown} config
166
+ * @param {string | undefined} envText
167
+ */
168
+ export function resolveWorkBudget(config, envText) {
169
+ const fromEnv = parseWorkBudget(envText);
170
+ const fromConfig = normalizeWorkBudget(config);
171
+ return {
172
+ budget: { ...DEFAULT_WORK_BUDGET, ...fromEnv.budget, ...fromConfig.budget },
173
+ ignored: [...fromEnv.ignored, ...fromConfig.ignored],
174
+ clamped: [...fromEnv.clamped, ...fromConfig.clamped],
175
+ };
176
+ }
17
177
  /**
18
178
  * Pending next-turn ids whose source is not a ticket notice and not a delivery.
19
179
  * @param {string[]} pendingIds
@@ -62,45 +222,78 @@ export function decideAdmission(input) {
62
222
  * @returns {'steps' | 'wall' | 'tokens' | null}
63
223
  */
64
224
  export function budgetTrip(input) {
65
- if (Number.isFinite(input.maxSteps) && Number(input.steps) >= input.maxSteps)
225
+ const maxSteps = input.maxSteps;
226
+ const maxTokens = input.maxTokens;
227
+ if (maxSteps != null && Number.isFinite(maxSteps) && Number(input.steps) >= maxSteps)
66
228
  return 'steps';
67
- if (Number.isFinite(input.maxTokens) && Number(input.tokens) >= input.maxTokens)
229
+ if (maxTokens != null && Number.isFinite(maxTokens) && Number(input.tokens) >= maxTokens)
68
230
  return 'tokens';
69
231
  if (input.elapsedMs >= input.wallMs)
70
232
  return 'wall';
71
233
  return null;
72
234
  }
73
235
  /**
74
- * Positive integer inside an inclusive range.
236
+ * Positive integer at or above `min`. A non-finite value is omitted.
75
237
  * @param {unknown} value
76
238
  * @param {number} min
77
- * @param {number} max
78
239
  */
79
- function clampInt(value, min, max) {
240
+ function clampAtLeast(value, min) {
80
241
  const number = Number(value);
81
242
  if (!Number.isFinite(number))
82
243
  return null;
83
- return Math.max(min, Math.min(max, Math.floor(number)));
244
+ return Math.max(min, Math.floor(number));
84
245
  }
85
246
  /**
86
247
  * Ticket budget chosen when the main bot dispatches.
87
- * An explicit estimate is kept inside the host ceiling. An omitted field is
88
- * derived from the briefing length so every ticket gets its own numbers.
89
- * @param {string} briefing
248
+ * An omitted field is one standard slice. An explicit estimate is kept, with a
249
+ * floor of 1000. Later grants add on top and are not capped by this slice.
250
+ * @param {string} _briefing
90
251
  * @param {{ wallMs?: number, maxTokens?: number } | null | undefined} suggestion
91
252
  * @param {typeof DEFAULT_WORK_BUDGET} defaults
92
253
  */
93
- export function estimateWorkerBudget(briefing, suggestion, defaults = DEFAULT_WORK_BUDGET) {
94
- const chars = typeof briefing === 'string' ? briefing.length : 0;
95
- const guessedWall = Math.min(defaults.workerWallMs, 180_000 + chars * 100);
96
- const guessedTokens = Math.min(defaults.workerMaxTokens, 24_000 + chars * 8);
254
+ export function estimateWorkerBudget(_briefing, suggestion, defaults = DEFAULT_WORK_BUDGET) {
97
255
  return {
98
- wallMs: clampInt(suggestion?.wallMs, 1000, defaults.workerWallMs) ?? guessedWall,
99
- maxTokens: clampInt(suggestion?.maxTokens, 1000, defaults.workerMaxTokens) ?? guessedTokens,
256
+ wallMs: clampAtLeast(suggestion?.wallMs, 1000) ?? defaults.workerWallMs,
257
+ maxTokens: clampAtLeast(suggestion?.maxTokens, 1000) ?? defaults.workerMaxTokens,
100
258
  perBot: defaults.perBot,
101
259
  global: defaults.global,
260
+ perBotQueue: defaults.perBotQueue,
261
+ globalQueue: defaults.globalQueue,
102
262
  };
103
263
  }
264
+ /** Main-session reasoning effort. `off` skips thinking so the reply starts sooner. */
265
+ export const MAIN_REASONING_EFFORT = 'off';
266
+ /**
267
+ * Record `off` on a bot main session before the next step is prepared.
268
+ * A matching selection is left alone. Ordinary sessions are left alone.
269
+ * Call this outside an open session append: `model.select` appends `model/selection`.
270
+ * @param {{ id?: string, model?: { current?: () => ModelSelection, select?: (selection: { provider: string, model: string, reasoningEffort: string }) => void } } | null | undefined} agent
271
+ * @param {(sessionId: string) => boolean} isBot
272
+ */
273
+ export function pinMainReasoning(agent, isBot) {
274
+ if (!agent || typeof agent.id !== 'string' || agent.id === '' || !isBot(agent.id))
275
+ return false;
276
+ const current = agent.model?.current?.();
277
+ if (!current?.provider || !current.model || current.reasoningEffort === MAIN_REASONING_EFFORT)
278
+ return false;
279
+ agent.model?.select?.({
280
+ provider: current.provider,
281
+ model: current.model,
282
+ reasoningEffort: MAIN_REASONING_EFFORT,
283
+ });
284
+ return true;
285
+ }
286
+ /**
287
+ * Worker route copied from the main session. Thinking stays at the adapter
288
+ * default: the main session's `off` is for reply latency and is not copied.
289
+ * @param {ModelSelection} model
290
+ */
291
+ export function workerModelSelection(model) {
292
+ if (!model || model.reasoningEffort !== MAIN_REASONING_EFFORT)
293
+ return model;
294
+ const { reasoningEffort: _effort, ...rest } = model;
295
+ return rest;
296
+ }
104
297
  /**
105
298
  * Child creation options. parentAgent and meta.parentSession are omitted on purpose:
106
299
  * the parent link lives only on the ticket row.
@@ -116,12 +309,16 @@ export function childCreateOptions(sessionId, cwd, model, maxTokens) {
116
309
  const options = { sessionId };
117
310
  if (typeof cwd === 'string' && cwd !== '')
118
311
  options.meta = { cwd };
119
- if (model && typeof model.provider === 'string' && model.provider !== '' && typeof model.model === 'string' && model.model !== '') {
312
+ if (model &&
313
+ typeof model.provider === 'string' &&
314
+ model.provider !== '' &&
315
+ typeof model.model === 'string' &&
316
+ model.model !== '') {
120
317
  options.agentOptions = { provider: model.provider, model: model.model };
121
318
  if (typeof model.reasoningEffort === 'string' && model.reasoningEffort !== '') {
122
319
  options.agentOptions.reasoningEffort = model.reasoningEffort;
123
320
  }
124
- if (Number.isSafeInteger(maxTokens) && maxTokens > 0)
321
+ if (typeof maxTokens === 'number' && Number.isSafeInteger(maxTokens) && maxTokens > 0)
125
322
  options.agentOptions.maxTokens = maxTokens;
126
323
  }
127
324
  return options;
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * File tools for a worker. Plugin-created agents do not inherit the web preset,
3
3
  * so their request header otherwise lists only host tools.
4
- * This preset is tool-fs only: read, write, and edit. It does not add bash,
5
- * and it does not change the sandbox mode or add writable roots.
6
- * The session cwd copied at create remains the workspace-write boundary.
4
+ * This preset mounts official file tools and official command tools
5
+ * (`@deepseek-ai/dsh-tool-bash`, `@deepseek-ai/dsh-tool-jobs`). It does not
6
+ * change the host sandbox mode, add writable roots, or mount the web preset
7
+ * (no web_fetch, subagent, or other profile tools). The session cwd copied
8
+ * at create remains the workspace-write boundary; bash uses the already
9
+ * composed host bash-sandbox and approval policy.
7
10
  */
8
11
  export const WORKER_FILE_PRESET = 'foundations-files';
9
12
  /**
@@ -14,7 +17,9 @@ function presetsOf(ctx) {
14
17
  if (typeof ctx.get === 'function')
15
18
  return ctx.get('agentPresets') ?? null;
16
19
  }
17
- catch { /* preset service is optional until a worker is created */ }
20
+ catch {
21
+ /* preset service is optional until a worker is created */
22
+ }
18
23
  try {
19
24
  return ctx.agentPresets ?? null;
20
25
  }
@@ -31,7 +36,8 @@ export function ensureWorkerFilePreset(ctx) {
31
36
  const presets = presetsOf(ctx);
32
37
  if (!presets?.register || !presets?.mount)
33
38
  return Promise.resolve(null);
34
- return presets.register({
39
+ return presets
40
+ .register({
35
41
  id: WORKER_FILE_PRESET,
36
42
  plugins: [
37
43
  {
@@ -39,8 +45,12 @@ export function ensureWorkerFilePreset(ctx) {
39
45
  name: '@deepseek-ai/dsh-tool-fs',
40
46
  config: { applyPatch: false, readImage: false },
41
47
  },
48
+ { id: 'tool-bash', name: '@deepseek-ai/dsh-tool-bash' },
49
+ { id: 'tool-jobs', name: '@deepseek-ai/dsh-tool-jobs' },
42
50
  ],
43
- }).then(() => WORKER_FILE_PRESET).catch(error => {
51
+ })
52
+ .then(() => WORKER_FILE_PRESET)
53
+ .catch((error) => {
44
54
  const message = error instanceof Error ? error.message : String(error);
45
55
  if (message.includes('Duplicate'))
46
56
  return WORKER_FILE_PRESET;
@@ -59,9 +69,7 @@ export function workerFileSetup(ctx, presetId) {
59
69
  const presets = presetsOf(ctx);
60
70
  if (!presets?.mount)
61
71
  return;
62
- const recorded = agent?.session && typeof presets.presetForSession === 'function'
63
- ? presets.presetForSession(agent.session)
64
- : null;
72
+ const recorded = agent?.session && typeof presets.presetForSession === 'function' ? presets.presetForSession(agent.session) : null;
65
73
  const id = presetId || recorded || presets.defaultId;
66
74
  if (!id)
67
75
  return;
package/dist/work-http.js CHANGED
@@ -141,12 +141,53 @@ export function openPageLive(req, res, source) {
141
141
  const intervalMs = source.intervalMs ?? 1000;
142
142
  /** @type {ReturnType<typeof setInterval> | null} */
143
143
  let timer = null;
144
+ let interactionTimer = null;
145
+ let lastInteractions = '';
146
+ let interactionFailed = false;
147
+ let lastCanvas = '';
148
+ const pumpCanvas = () => {
149
+ if (stopped || !source.canvas)
150
+ return;
151
+ try {
152
+ const text = JSON.stringify(source.canvas());
153
+ if (text === lastCanvas)
154
+ return;
155
+ lastCanvas = text;
156
+ if (text === '{"ok":true,"events":[]}')
157
+ return;
158
+ res.write(`event: canvas\ndata: ${text}\n\n`);
159
+ }
160
+ catch {
161
+ // A canvas notice failure leaves the desk and ticket streams open.
162
+ }
163
+ };
164
+ const pumpInteractions = () => {
165
+ if (stopped || !source.interactions)
166
+ return;
167
+ try {
168
+ const text = JSON.stringify(source.interactions());
169
+ if (text === lastInteractions && !interactionFailed)
170
+ return;
171
+ interactionFailed = false;
172
+ lastInteractions = text;
173
+ res.write(`event: interactions\ndata: ${text}\n\n`);
174
+ }
175
+ catch {
176
+ // Downgrade the client to REST fallback without closing desk/work updates.
177
+ if (!interactionFailed) {
178
+ interactionFailed = true;
179
+ res.write('event: interaction-error\ndata: {}\n\n');
180
+ }
181
+ }
182
+ };
144
183
  const stop = () => {
145
184
  if (stopped)
146
185
  return;
147
186
  stopped = true;
148
187
  if (timer)
149
188
  clearInterval(timer);
189
+ if (interactionTimer)
190
+ clearInterval(interactionTimer);
150
191
  if (!res.writableEnded)
151
192
  res.end();
152
193
  };
@@ -201,8 +242,17 @@ export function openPageLive(req, res, source) {
201
242
  busy = false;
202
243
  }
203
244
  };
245
+ pumpCanvas();
246
+ pumpInteractions();
247
+ if (source.interactions) {
248
+ interactionTimer = setInterval(pumpInteractions, intervalMs);
249
+ interactionTimer.unref?.();
250
+ }
204
251
  void pump();
205
- timer = setInterval(() => { void pump(); }, intervalMs);
252
+ timer = setInterval(() => {
253
+ pumpCanvas();
254
+ void pump();
255
+ }, intervalMs);
206
256
  timer.unref?.();
207
257
  req.on('close', stop);
208
258
  res.on('error', stop);
@@ -216,7 +266,7 @@ export function openPageLive(req, res, source) {
216
266
  * @param {string} path
217
267
  * @param {URL} url
218
268
  * @param {Record<string, unknown>} body
219
- * @param {ReturnType<import('./work-worker.js').createWorkRuntime> | null} work
269
+ * @param {ReturnType<typeof import('./work-worker.js').createWorkRuntime> | null} work
220
270
  */
221
271
  export async function handleWorkApi(method, path, url, body, work) {
222
272
  if (!path.startsWith('/session-foundations/api/work'))