@linxin666/dsh-liangshen 0.4.5 → 0.4.7

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.
@@ -6,11 +6,9 @@
6
6
  * PRESENTATION: the `presentation` config picks how this session's tools sit
7
7
  * on the wire, matching the SDK's ToolPresentationMode:
8
8
  * - `native`: the assembled native roster, no code transport;
9
- * - `ptc`: the wire collapses to the single `run_code` transport and every
10
- * other tool is reached from inside the program through the generated SDK;
11
- * - `both` (default): the full native roster plus the `run_code` transport
12
- * co-resident on the wire — native calls carry ordinary work, `run_code`
13
- * covers programmatic batch computation and overlapped fan-out.
9
+ * - `ptc` (default): the wire collapses to the single `run_code` transport
10
+ * and every other tool is reached from inside the program through the
11
+ * generated SDK.
14
12
  *
15
13
  * The declaration happens once per agent scope (agent.ctx.tools.presentAs) as
16
14
  * early as the scope exists — there is no turn-boundary staging: the retired
@@ -43,6 +41,11 @@
43
41
  * (`withheldToolNames`) and is lifted before a new one is applied, so repeated
44
42
  * collections do not accumulate filters.
45
43
  *
44
+ * WHICH PRESENTATION PAGES WHAT: the registry restriction is installed for
45
+ * `ptc` alone, because a collapsed wire is the one presentation where the
46
+ * scope's registry IS the whole reachable surface. `native` carries no
47
+ * program at all, so the wire partition is the whole of paging there.
48
+ *
46
49
  * TIMING: that restriction is installed from OUTSIDE the assembly waterfall.
47
50
  * `SystemPrompt.assemble()` collects the tool providers and calls every
48
51
  * section's `text(context)` BEFORE it runs the `system-prompt/assemble`
@@ -56,16 +59,22 @@
56
59
  * CATALOG: the durable user message appended after the user's own message
57
60
  * names exactly the tools the current request's wire carries (each tool's
58
61
  * argument signature plus a one-line summary), then summarizes the paged-out
59
- * namespaces with their activation pointer. Under 'both' the catalog lists
60
- * `run_code` like any other tool and notes the programmatic-escape hatch; the
61
- * 'ptc' program contract only ships when the wire actually collapsed to it.
62
+ * namespaces with their activation pointer. The 'ptc' program contract ships
63
+ * when the wire actually collapsed to the transport. A tool the catalog
64
+ * curates renders the hand-written line from
65
+ * {@link CURATED_TOOL_SUMMARIES}; only an uncurated tool falls back to the
66
+ * mechanical `descriptionMaxLength` truncation of its own schema description,
67
+ * because a character-count cut can slice off exactly the sentence that says
68
+ * what the tool is for.
62
69
  * The catalog republishes only when its content changes or the published copy
63
70
  * left the visible surface (compaction, resume).
64
71
  *
65
- * RESIDENT BUDGET: `maxResidentTokens` (default 1500) estimates the
66
- * always-on-wire surface and warns once when it is crossed. The guard is a
67
- * diagnostic, never a truncation: silently dropping a tool the session needs
68
- * would trade a measurable context cost for an unmeasurable capability loss.
72
+ * RESIDENT BUDGET: `maxResidentTokens` estimates the always-on-wire surface
73
+ * and warns once when it is crossed; the shipped ceiling is the
74
+ * `DEFAULT_MAX_RESIDENT_TOKENS` constant below, and a deployment may raise or
75
+ * lower it through the config. The guard is a diagnostic, never a truncation:
76
+ * silently dropping a tool the session needs would trade a measurable context
77
+ * cost for an unmeasurable capability loss.
69
78
  */
70
79
 
71
80
  import {
@@ -91,7 +100,7 @@ export const inject = ['systemPrompt']
91
100
  const DEFAULT_DESCRIPTION_MAX_LENGTH = 200
92
101
 
93
102
  /** The presentation modes the SDK's ToolPresentationMode supports. */
94
- export const PRESENTATION_MODES = ['native', 'ptc', 'both']
103
+ export const PRESENTATION_MODES = ['native', 'ptc']
95
104
 
96
105
  /**
97
106
  * The default presentation: the wire collapses to the single \`run_code\` transport
@@ -100,7 +109,7 @@ export const PRESENTATION_MODES = ['native', 'ptc', 'both']
100
109
  *
101
110
  * This is a deliberate trade, not a measured win. Collapsing the wire removes the
102
111
  * native roster's schema payload from every request, which is the cheapest static
103
- * context of the three modes; the official published scaffold comparison, however,
112
+ * context of the two modes; the official published scaffold comparison, however,
104
113
  * places this presentation BELOW the natively presented surface on both code-agent
105
114
  * benchmarks (DeepSWE v1.1: 67.6 against 72.6; Terminal-Bench 2.1: 85.8 against
106
115
  * 90.6). The default is chosen for its static-context cost on long sessions and is
@@ -173,13 +182,23 @@ function optionalBoolean(value, field, fallback) {
173
182
  }
174
183
 
175
184
  /**
176
- * Resolve the presentation config: the explicit `presentation` enum wins; the
177
- * legacy boolean `ptcPresentation` maps onto it (true -> 'ptc', false ->
178
- * 'native') with a one-time deprecation warning; neither means the default.
185
+ * Resolve the presentation config: the explicit `presentation` enum wins (with
186
+ * the pre-0.2.1 `'both'` default mapped to `'ptc'` with a one-time deprecation
187
+ * warning so older profiles keep booting); the legacy boolean `ptcPresentation`
188
+ * maps onto it (true -> 'ptc', false -> 'native') with a one-time deprecation
189
+ * warning; neither means the default.
179
190
  */
180
191
  function resolvePresentation(config, warn) {
181
192
  const explicit = config?.presentation
182
193
  if (explicit !== undefined) {
194
+ if (explicit === 'both') {
195
+ if (config?.ptcPresentation !== undefined) {
196
+ optionalBoolean(config.ptcPresentation, 'ptcPresentation', true)
197
+ warn('the ptcPresentation key is deprecated — presentation takes precedence over it')
198
+ }
199
+ warn("the 'both' presentation was removed in 0.2.1; mapping 'both' -> 'ptc'")
200
+ return 'ptc'
201
+ }
183
202
  if (!PRESENTATION_MODES.includes(explicit)) {
184
203
  throw new TypeError(`${name}: presentation must be one of ${JSON.stringify(PRESENTATION_MODES)}`)
185
204
  }
@@ -210,6 +229,94 @@ function validateRetiredAnchorTools(value) {
210
229
  }
211
230
  }
212
231
 
232
+ /**
233
+ * Curated one-line summaries, one per host builtin tool this preset can put on
234
+ * a wire. Each line says what the tool is FOR and names the arguments that
235
+ * decide how it is called, kept well inside {@link DEFAULT_DESCRIPTION_MAX_LENGTH}.
236
+ *
237
+ * PRECEDENCE: a tool named here renders THIS line; every other tool keeps the
238
+ * mechanical cap — its own schema description, whitespace collapsed and cut to
239
+ * `descriptionMaxLength`. Curation therefore wins over truncation and never
240
+ * replaces it: a tool the table does not name (a paged MCP namespace's tool, a
241
+ * plugin-registered tool, a tool the harness adds later) still reaches the
242
+ * model, just at whatever the cap leaves of its own description. A character
243
+ * count is a poor editor — it slices off the sentence that says what the tool
244
+ * is for — so the tools this session mounts on every request get a hand-written
245
+ * line instead.
246
+ *
247
+ * SCOPE: exactly the host builtins the preset's own `agent.cordis.yml` rows
248
+ * mount for a session, which is the surface the paging wildcard leaves resident
249
+ * (`pagedToolPatterns` defaults to `mcp__*`, so no host builtin is ever paged
250
+ * out):
251
+ * - the shell (one of bash / pwsh per platform), the filesystem and discovery
252
+ * tools, the background-job controls, and the editor;
253
+ * - the prompt/skill surface, the todo list, the user question tool, and
254
+ * `web_search` (the preset's own `tool-web` row configures `fetch: false`,
255
+ * so the session opens the search tool alone);
256
+ * - the preset's own `tool_activate` and `fact_register`;
257
+ * - the READ-ONLY MCP resource tools, which the base composition mounts and
258
+ * which are reachable whenever the deployment registers an MCP server — even
259
+ * though a configured `mcp__*` server's tools are the ones paging withholds.
260
+ *
261
+ * Three names a reader might expect are deliberately ABSENT, because this
262
+ * composition mounts no row that registers them and curating them would write a
263
+ * catalog line for a tool surface the request never opens — exactly the claim
264
+ * the declare-exactly-what-the-request-opens contract forbids:
265
+ * - `present`: only the builtin Standard / PTC / Cordis compositions mount the
266
+ * `@deepseek-ai/dsh-tool-present` row, and the web app disables the host one;
267
+ * - `web_fetch`: the per-session `tool-web` row below sets `fetch: false`,
268
+ * so this session opens `web_search` alone;
269
+ * - `workflow`: the delegation group ships that row `disabled: true` so no
270
+ * second model-authored orchestration surface sits beside `run_code`.
271
+ * The goal tools and `exit_plan_mode` ARE here, because the `tool-goal` and
272
+ * `plan-mode` rows below mount them.
273
+ *
274
+ * `run_code` is also absent: it is the transport the harness adds for a code
275
+ * presentation, not a row-mounted builtin, and the catalog never lists it as
276
+ * an entry — under `ptc` the program contract describes it, under `native` the
277
+ * request does not carry it.
278
+ *
279
+ * Adding a tool the preset mounts is the one edit an entry needs, and no test
280
+ * pins the exact text of any line: an operator reword is not a behavior change.
281
+ * That is why the table is exported — a test can prove every key is a tool name
282
+ * and every value is a single bounded line, without freezing the prose.
283
+ */
284
+
285
+ export const CURATED_TOOL_SUMMARIES = new Map([
286
+ ['bash', 'Run a command in a fresh bash shell (`command`, optional `timeoutMs`, `workdir`, `run_in_background`).'],
287
+ ['pwsh', 'Run a command in a fresh PowerShell process (`command`, optional `timeoutMs`, `workdir`, `run_in_background`); native Windows paths and `$env:NAME` variables.'],
288
+ ['read', 'Read one UTF-8 text file as line-numbered content (`file_path`, optional `offset` and `limit`).'],
289
+ ['read_image', 'Read a PNG/JPEG/WebP/GIF image file and return the image itself (`file_path`); large images are downscaled automatically.'],
290
+ ['write', 'Create or fully replace one UTF-8 text file (`file_path`, `content`).'],
291
+ ['edit', 'Replace literal text in one existing file (`file_path`, `old_string`, `new_string`, optional `replace_all`).'],
292
+ ['str_replace_editor', 'View, create, and edit files through one command tool (`command`, `path`, plus `file_text`, `old_str` / `new_str`, `insert_line`, `view_range`).'],
293
+ ['glob', 'Find files whose paths match a glob pattern (`pattern`, optional `path`); up to 100 paths in modification-time order.'],
294
+ ['grep', 'Search file contents with a ripgrep expression (`pattern`, optional `path`, optional `include`); matching lines with line numbers.'],
295
+ ['job_output', 'Read a background job: output since the previous read, or the finished result (`job_id`, optional `wait`, `timeout_ms`).'],
296
+ ['job_list', 'List the background jobs started by this session with their ids, kinds, and statuses.'],
297
+ ['job_kill', 'Request cancellation of a running background job (`job_id`, optional `reason`).'],
298
+ ['todo_write', 'Record and update the plan as one todo per concrete step (`todos`: content and status); skip it for trivial single-step work.'],
299
+ ['create_goal', 'Create a persisted goal that keeps this session working across automatic continuation rounds (`objective`, optional `max_goal_rounds`).'],
300
+ ['get_goal', 'Read the current session goal, including the id and revision that update_goal requires.'],
301
+ ['update_goal', 'Change one goal: edit, pause, resume, complete or blocked (`goal_id`, `revision`, `action`, plus `objective`, `max_goal_rounds`, `blocked_reason`).'],
302
+ ['exit_plan_mode', 'Present the completed plan for user review (`plan`, markdown starting with a title); approval is the only way out of plan mode.'],
303
+ ['subagent', 'Delegate a self-contained task to a subagent that works in its own context and returns its result, not its steps (`description`, `prompt`, optional `provider` / `model` / `reasoning_effort`).'],
304
+ ['subagent_fork', 'Delegate a task to a subagent seeded with this conversation (`description`, `prompt`); it inherits the parent route, so route fields are not accepted.'],
305
+ ['list_subagent_models', 'Discover the subagent routes this session authorizes (`provider`, optional `model`); the returned ids feed the delegation tools.'],
306
+ ['send_message', 'Send a message to a subagent started from this session (`agent_id`, `message`); the call confirms delivery, not the answer.'],
307
+ ['list_agents', 'List the subagents started from this session with their ids, labels, and status (`scope`).'],
308
+ ['interrupt_agent', 'Ask a subagent to stop its current work (`agent_id`); the call returns without waiting for it to settle.'],
309
+ ['ask_user_question', 'Ask the user a concise question and wait for the answer (`questions`: id, question, optional header, options, and custom input).'],
310
+ ['web_search', 'Search the web for current information (one to four `queries`); returns a merged summary and its source URLs.'],
311
+ ['skill', 'Load the full instructions of one session skill (`name`); call it before acting on a task that names or matches a skill.'],
312
+ ['tool_activate', 'Load one paged tool namespace back onto the wire and into the generated SDK (`namespace`, exactly as the catalog names it).'],
313
+ ['fact_register', 'Pin one key fact into the working context (`fact`, optional `tag`), or unpin with `revoke`; at most twelve short facts stay pinned.'],
314
+ ['ralph', 'Run a foreground fresh-agent Ralph loop toward one immutable objective (`objective`, optional `maxRounds`); only when the human explicitly asks for it.'],
315
+ ['list_mcp_resources', 'List the resources an MCP server exposes (`server`, optional `cursor`).'],
316
+ ['list_mcp_resource_templates', 'List the parameterized resource URI templates of one MCP server (`server`, optional `cursor`).'],
317
+ ['read_mcp_resource', 'Read one MCP resource by URI from the named server (`server`, `uri`).'],
318
+ ])
319
+
213
320
  /**
214
321
  * One-line model-facing summary of a tool description: whitespace collapsed,
215
322
  * truncated with an ellipsis when maxLength is specified.
@@ -220,6 +327,23 @@ export function catalogDescription(value, maxLength) {
220
327
  return `${normalized.slice(0, maxLength - 3)}...`
221
328
  }
222
329
 
330
+ /**
331
+ * The one-line summary one entry renders for a tool: the curated line when the
332
+ * table names it, otherwise the mechanically capped schema description. The
333
+ * order is the whole point — curation first, truncation only as the fallback
334
+ * for a tool nobody has written a line for yet.
335
+ * @param {{ name?: unknown, description?: unknown }} schema - one tool definition.
336
+ * @param {number} maxLength - the schema-description cap, in characters.
337
+ * @returns the summary text for the catalog entry.
338
+ */
339
+ export function toolSummary(schema, maxLength) {
340
+ const name = schema?.name
341
+ if (typeof name === 'string' && CURATED_TOOL_SUMMARIES.has(name)) {
342
+ return CURATED_TOOL_SUMMARIES.get(name)
343
+ }
344
+ return catalogDescription(schema?.description, maxLength)
345
+ }
346
+
223
347
  /** One scalar literal as TypeScript-ish text; non-JSON scalars degrade to the broad type. */
224
348
  function renderLiteral(value) {
225
349
  const json = JSON.stringify(value)
@@ -277,17 +401,19 @@ export function renderSignature(parameters) {
277
401
  /**
278
402
  * Catalog entries for one tool surface, sorted by name so an unchanged surface
279
403
  * renders byte-identical text across assemblies. Nameless definitions are
280
- * skipped; the `run_code` transport is listed only when the presentation puts
281
- * it on the wire beside the native tools ('both').
404
+ * skipped; the `run_code` transport never renders as an entry — under `ptc`
405
+ * the program contract describes it, under `native` the request does not
406
+ * carry it. Each entry's summary is resolved by {@link toolSummary}: the
407
+ * curated line where the table has one, the capped schema description
408
+ * otherwise.
282
409
  */
283
410
  export function catalogEntries(schemas, maxLength, options) {
284
- const includeRunCode = options?.includeRunCode === true
285
411
  const patterns = Array.isArray(options?.patterns) ? options.patterns : []
286
412
  const entries = []
287
413
  for (const schema of Array.isArray(schemas) ? schemas : []) {
288
414
  const toolName = schema?.name
289
415
  if (typeof toolName !== 'string' || toolName === '') continue
290
- if (toolName === 'run_code' && !includeRunCode) continue
416
+ if (toolName === 'run_code') continue
291
417
  // A tool from a paged family carries its namespace so the catalog can group
292
418
  // it the way the model calls it, instead of scattering one server's tools
293
419
  // through an alphabetical list.
@@ -295,7 +421,7 @@ export function catalogEntries(schemas, maxLength, options) {
295
421
  entries.push({
296
422
  name: toolName,
297
423
  signature: renderSignature(schema.parameters),
298
- description: catalogDescription(schema.description, maxLength),
424
+ description: toolSummary(schema, maxLength),
299
425
  ...(namespace === undefined ? {} : { namespace }),
300
426
  })
301
427
  }
@@ -319,24 +445,13 @@ const PTC_PROGRAM_LINES = [
319
445
  'A namespace this session has not activated with `tool_activate({ namespace: "..." })` is not listed above and cannot be reached from inside a program either: the page is a page on the whole surface, not only on the wire, and the paged-out list below names exactly what is withheld. Activating one puts its tools back into this list and back into a program from the next request on.',
320
446
  ]
321
447
 
322
- /**
323
- * The short note the catalog carries when `run_code` sits on the wire beside
324
- * the native roster ('both'): native calls are the primary surface, and the
325
- * transport covers programmatic batch work. Paged-out namespaces stay reachable
326
- * through the SDK inside a program even before activation.
327
- */
328
- const BOTH_PROGRAM_LINES = [
329
- 'Prefer calling the tools above directly by name: ordinary single-step work (read, edit, bash, one search) goes through the native call, never through `run_code`. Reserve `run_code` for what a direct call cannot do — an async TypeScript body (`code`, with a short `description`) that reaches tools as `await tools.<name>({ ... })`, overlaps independent read-only calls under `Promise.all`, and catches `ToolCallError` to continue: programmatic batch computation, wide fan-out, or multi-step data shaping. Routing everyday calls through a program adds a wrapping layer with no payoff.',
330
- 'Paged-out namespaces below stay off the NATIVE wire but stay reachable through the SDK inside a program even before activation; activating one also puts its tools back on the direct surface.',
331
- ]
332
-
333
448
  /**
334
449
  * Model-facing catalog text.
335
- * - Native presentation: the on-wire tool list plus the paged-out namespace summary.
336
- * - 'both': the on-wire list INCLUDING `run_code`, the namespace summary, and
337
- * the short programmatic-escape note.
450
+ * - Native presentation: the on-wire tool list plus the paged-out namespace
451
+ * summary with its wire-only reachability.
338
452
  * - 'ptc' (wire collapsed to `run_code`): the SDK-reachable list plus the full
339
- * program contract naming `run_code` the one direct transport.
453
+ * program contract naming `run_code` the one direct transport, and a
454
+ * namespace summary whose page covers the whole surface.
340
455
  */
341
456
  export function renderCatalogText(entries, presentation = 'native', inactive = []) {
342
457
  // Activated paged families are listed under their namespace heading; every
@@ -364,18 +479,24 @@ export function renderCatalogText(entries, presentation = 'native', inactive = [
364
479
  const footer = inactive.length === 0
365
480
  ? 'This is the complete current list and replaces any earlier available-tools list in this session.'
366
481
  : 'This is the current on-wire list and replaces any earlier available-tools list in this session.'
482
+ // The paged-out summary states its own reachability per presentation, because
483
+ // the presentations differ on exactly the fact a reader would otherwise have
484
+ // to infer from the program contract further down: 'ptc' pages the whole
485
+ // surface, and 'native' carries no program at all.
486
+ const inactiveReachability = presentation === 'ptc'
487
+ ? 'The page covers the whole surface here, not the wire alone: these namespaces are unreachable from inside a program too until they are activated.'
488
+ : 'This presentation carries no program transport, so the wire is the only surface these namespaces can be reached through.'
367
489
  const inactiveBlock = inactive.length === 0 ? [] : [
368
490
  '',
369
491
  'These tool namespaces are registered but currently paged out of the wire:',
492
+ inactiveReachability,
370
493
  '<inactive_namespaces>',
371
- ...inactive.map(ns => `- \`${ns.namespace}\` (${ns.count} tool${ns.count === 1 ? '' : 's'}${ns.sample === '' ? '' : `, e.g. \`${ns.sample}\``}): ${ns.description} Call \`tool_activate({ namespace: "${ns.namespace}" })\` to load them onto the wire.`),
494
+ ...inactive.map(ns => `- \`${ns.namespace}\` (${ns.count} tool${ns.count === 1 ? '' : 's'}${ns.sample === '' ? '' : `, e.g. \`${ns.sample}\``}): ${ns.description} Call \`tool_activate({ namespace: "${ns.namespace}" })\` to activate it.`),
372
495
  '</inactive_namespaces>',
373
496
  ]
374
497
  const presentationLines = presentation === 'ptc'
375
498
  ? ['', ...PTC_PROGRAM_LINES]
376
- : presentation === 'both'
377
- ? ['', ...BOTH_PROGRAM_LINES]
378
- : []
499
+ : []
379
500
  return [
380
501
  '<system-reminder>',
381
502
  'The following tools are available in this session:',
@@ -534,7 +655,7 @@ export function apply(ctx, config) {
534
655
  if (config?.anchorTools !== undefined) {
535
656
  warnOnce('anchor', 'anchor-turn staging is retired — the anchorTools key is accepted but no longer narrows the wire')
536
657
  }
537
- const presentation = resolvePresentation(config, detail => warnOnce('ptcPresentation', detail))
658
+ const presentation = resolvePresentation(config, detail => warnOnce(`presentation:${detail}`, detail))
538
659
 
539
660
  // Per-agent fresh state evaluated on every assembly (never stale across steps/turns)
540
661
  const agentCatalogState = new WeakMap()
@@ -635,10 +756,8 @@ export function apply(ctx, config) {
635
756
  * GATED ON THE WIRE ACTUALLY COLLAPSING, not on the configuration asking for
636
757
  * it. Both halves of that gate matter, and each covers a deployment where
637
758
  * paging at the registry would be wrong:
638
- * - `presentation === 'ptc'` is what the operator configured, and it excludes
639
- * `both`, whose documented contract is that a paged-out namespace stays
640
- * reachable through the SDK inside a program before activation. Installing
641
- * the restriction there would break that contract for the first request;
759
+ * - `presentation === 'ptc'` is what the operator configured, and it is the
760
+ * only presentation whose registry is the whole reachable surface;
642
761
  * - `agentDeclared.has(agent)` is the scope's own declaration actually
643
762
  * landing, which is NOT the same as `transportReady()`. A deployment with
644
763
  * no mounted code runtime (and one whose host declines the declaration)
@@ -841,8 +960,7 @@ export function apply(ctx, config) {
841
960
  // transport and lists the tools from their SDK projection. Where no
842
961
  // projection can be read at all, declaring would collapse the executor and
843
962
  // then have to undo it, losing the native wire on the way out. Stay native
844
- // instead. Under 'both' the native roster stays on the wire either way, so
845
- // the declaration needs no projection guard.
963
+ // instead.
846
964
  const projectable = publicSchemas(agent)
847
965
  if (presentation === 'ptc' && (projectable === undefined || projectable.length === 0)) {
848
966
  warnOnce('runtime', 'no tool schema projection available — keeping the native tool surface')
@@ -898,17 +1016,14 @@ export function apply(ctx, config) {
898
1016
 
899
1017
  // Under a collapsed `ptc` wire the registry is the ONLY surface a tool can
900
1018
  // be reached through, so the page is expressed as a registry restriction.
901
- // Every other wire still carries paging by itself on the assembled array,
902
- // and `both` deliberately stays unrestricted: that is what keeps its
903
- // documented "paged namespaces stay reachable through the SDK inside a
904
- // program" behavior intact. A wire that carries the native roster again (a
905
- // reverted declaration) must also drop a page left over from a collapsed
906
- // assembly, or the filter would keep hiding tools that wire just handed
907
- // back.
1019
+ // The native wire carries paging by itself on the assembled array. A wire
1020
+ // that carries the native roster again (a reverted declaration) must also
1021
+ // drop a page left over from a collapsed assembly, or the filter would keep
1022
+ // hiding tools that wire just handed back.
908
1023
  let surface = agent !== undefined ? publicSchemas(agent) : undefined
909
1024
  // The wire partition replays the durable log itself: `pagingState` exists
910
- // only where a restriction was installed (the collapsed ptc wire), and
911
- // native/both still page the assembled array from the same event stream.
1025
+ // only where a restriction was installed (the collapsed ptc wire), and the
1026
+ // native wire still pages the assembled array from the same event stream.
912
1027
  const activeNamespaces = new Set(
913
1028
  replayActivations(sessionEvents(agent?.session), maxActiveNamespaces, pagedToolPatterns).active,
914
1029
  )
@@ -928,13 +1043,12 @@ export function apply(ctx, config) {
928
1043
  }
929
1044
 
930
1045
  const effectiveWire = correctedWire ?? assembledTools
931
- const effectiveHasRunCode = (effectiveWire ?? []).some(t => t?.name === 'run_code')
932
1046
  const effectiveOnlyRunCode = effectiveWire !== undefined && effectiveWire.length > 0 && effectiveWire.every(t => t?.name === 'run_code')
933
1047
 
934
1048
  // The catalog describes the transport this request actually carries, never
935
- // the configuration's intent: a collapsed wire is 'ptc', run_code beside the
936
- // native roster is 'both', and anything else is native.
937
- const effectivePresentation = effectiveOnlyRunCode ? 'ptc' : (effectiveHasRunCode ? 'both' : 'native')
1049
+ // the configuration's intent: a collapsed wire is 'ptc', and anything else
1050
+ // is native.
1051
+ const effectivePresentation = effectiveOnlyRunCode ? 'ptc' : 'native'
938
1052
 
939
1053
  // Gentle paging: the active namespaces were replayed from the durable event
940
1054
  // stream above; here the paged-but-inactive tools come off the wire itself.
@@ -959,8 +1073,7 @@ export function apply(ctx, config) {
959
1073
  // The catalog describes this request's ACTUAL surface: with a live page it
960
1074
  // summarizes exactly the namespaces that page withholds (the same fact the
961
1075
  // restriction was built from), and otherwise the namespaces the WIRE
962
- // partition found — which under `both` stay reachable through the SDK
963
- // inside a program, as the programmatic-escape note below states.
1076
+ // partition found.
964
1077
  const catalogInactive = summarizeInactive(
965
1078
  pagingState?.inactive ?? inactive,
966
1079
  describe => catalogDescription(describe, descriptionMaxLength),
@@ -973,10 +1086,7 @@ export function apply(ctx, config) {
973
1086
  entries = catalogEntries(surface ?? [], descriptionMaxLength, { patterns: pagedToolPatterns })
974
1087
  } else {
975
1088
  const merged = mergeProjectedSchemas(resident, surface)
976
- entries = catalogEntries(merged, descriptionMaxLength, {
977
- includeRunCode: effectivePresentation === 'both',
978
- patterns: pagedToolPatterns,
979
- })
1089
+ entries = catalogEntries(merged, descriptionMaxLength, { patterns: pagedToolPatterns })
980
1090
  }
981
1091
  const inactiveSummary = catalogInactive
982
1092
 
@@ -195,18 +195,12 @@ describe('dsh-liangshen preset declaration', () => {
195
195
  })
196
196
 
197
197
  it('operator gets the committed settings applied to the rows they shape', async () => {
198
- // Given committed presentation and guard settings, When the operator
199
- // activates the plugin, Then the declared rows carry those values.
200
- const { host } = await mount({ presentation: 'ptc', guardEnabled: false, guardEchoFailures: 5 })
198
+ // Given a committed presentation, When the operator activates the plugin,
199
+ // Then the declared tool-catalog row carries it.
200
+ const { host } = await mount({ presentation: 'native' })
201
201
  const rows = host.declarations[0]!.definition.plugins as readonly { id?: string, config?: Record<string, unknown> }[]
202
- expect(rows.find(row => row.id === 'tool-catalog')?.config?.['presentation']).toBe('ptc')
203
- expect(rows.find(row => row.id === 'guard')?.config).toEqual({
204
- enabled: false,
205
- sensitivity: 'balanced',
206
- stallReasoningChars: 8000,
207
- globalStallCap: 4,
208
- echoFailures: 5,
209
- })
202
+ expect(rows.find(row => row.id === 'tool-catalog')?.config?.['presentation']).toBe('native')
203
+ expect(rows.find(row => row.id === 'guard')).toBeUndefined()
210
204
  })
211
205
 
212
206
  it('operator keeps the roster and the prompt untouched while the master switch is off', async () => {
@@ -223,7 +217,7 @@ describe('dsh-liangshen preset declaration', () => {
223
217
  // Then the preset is declared again and the previous declaration released.
224
218
  vi.resetModules()
225
219
  const mod = await import('../src/index.ts')
226
- let presentation = 'both'
220
+ let presentation = 'ptc'
227
221
  let announceToAgent = false
228
222
  const host = makeHost()
229
223
  mounted.push(host)
@@ -251,7 +245,7 @@ describe('dsh-liangshen preset declaration', () => {
251
245
  // last value and every predecessor is released.
252
246
  vi.resetModules()
253
247
  const mod = await import('../src/index.ts')
254
- let presentation = 'both'
248
+ let presentation = 'ptc'
255
249
  const host = makeHost()
256
250
  mounted.push(host)
257
251
  mod.apply(host.ctx, { presentation: { get: () => presentation } as never })
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Card mark for the LiangShen settings entry: the mode's machine is a
3
+ * slot-machine lever, so the mark is that lever reduced to one knob, one arm
4
+ * and one pivot foot. Three rounded shapes with no interior detail stay
5
+ * legible at 18px, and every shape is painted with `currentColor` so the mark
6
+ * follows the surrounding theme like the lever itself does.
7
+ */
8
+
9
+ import type { ReactElement } from 'react'
10
+
11
+ /**
12
+ * Render the LiangShen card mark.
13
+ * @returns the 18x18 lever mark, in the current text color.
14
+ */
15
+ export function LiangShenMark(): ReactElement {
16
+ return (
17
+ <svg width="18" height="18" viewBox="0 0 18 18" fill="none" aria-hidden="true">
18
+ <rect x="3.6" y="13.2" width="8.8" height="2.8" rx="1.4" fill="currentColor" />
19
+ <g transform="rotate(20 8 14.4)">
20
+ <rect x="6.5" y="4.6" width="3" height="9.8" rx="1.5" fill="currentColor" />
21
+ <circle cx="8" cy="4.4" r="2.9" fill="currentColor" />
22
+ </g>
23
+ </svg>
24
+ )
25
+ }
@@ -1,25 +1,24 @@
1
1
  /**
2
- * LiangShen settings card: availability and the wire presentation. Registers
3
- * into the `web-ui.plugin.item` child slot the Web UI plugin group renders,
4
- * bound to the `liangshen` settings namespace (the Host profile entry id).
2
+ * LiangShen settings card: availability, the wire presentation, and the
3
+ * dispatcher identity. Registers into the `web-ui.plugin.item` child slot the
4
+ * Web UI plugin group renders, bound to the `liangshen` settings namespace
5
+ * (the Host profile entry id).
5
6
  *
6
- * The presentation field does not act on this client half: the Host applies it
7
- * to the preset it declares to the agent-preset registry, so a session reads it
8
- * from its preset. This card is the operator's only handle on it, which is why
9
- * every field the Host schema carries appears here.
7
+ * No field acts on this client half: the Host applies the presentation and the
8
+ * dispatcher switch to the preset it declares to the agent-preset registry, so
9
+ * a session reads both from its preset. The card is the operator's only handle
10
+ * on them, which is why every field the Host schema carries appears here.
10
11
  */
11
12
 
12
13
  import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
13
14
  import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
14
15
  import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
15
- import { BooleanField, ChoiceField, PluginSettingsCard, ValueField } from './PluginSettingsCard.tsx'
16
- import { CardForm, booleanField, choiceField, numberField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
16
+ import { LiangShenMark } from './LiangShenMark.tsx'
17
+ import { BooleanField, ChoiceField, PluginSettingsCard } from './PluginSettingsCard.tsx'
18
+ import { CardForm, booleanField, choiceField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
17
19
 
18
20
  /** Wire presentations the tool catalog accepts (mirrors the Host schema). */
19
- export const PRESENTATION_CHOICES = ['ptc', 'native', 'both'] as const
20
-
21
- /** Sensitivity presets for the circuit breaker (mirrors the Host schema). */
22
- export const SENSITIVITY_CHOICES = ['conservative', 'balanced', 'aggressive'] as const
21
+ export const PRESENTATION_CHOICES = ['ptc', 'native'] as const
23
22
 
24
23
  /** The LiangShen fields this card edits (the namespace's full schema). */
25
24
  export interface LiangShenSettings {
@@ -29,16 +28,8 @@ export interface LiangShenSettings {
29
28
  announceToAgent?: boolean
30
29
  /** Wire presentation the Host applies to the preset's tool-catalog row. */
31
30
  presentation?: string
32
- /** Master switch for the runtime degeneration circuit breaker. */
33
- guardEnabled?: boolean
34
- /** Sensitivity preset scaling the breaker's adaptive thresholds. */
35
- guardSensitivity?: string
36
- /** Per-step reasoning-character floor for the breaker's runaway ladder. */
37
- guardStallReasoningChars?: number
38
- /** Consecutive output-free reasoning steps for the breaker's slow-burn ladder. */
39
- guardGlobalStallCap?: number
40
- /** Identical-argument tool failures for the breaker's echo ladder. */
41
- guardEchoFailures?: number
31
+ /** Whether the preset appends the dispatcher rules section after the persona. */
32
+ dispatcher?: boolean
42
33
  }
43
34
 
44
35
  /** What the LiangShen card renders. */
@@ -46,11 +37,7 @@ export interface LiangShenSettingsCardState extends CardShell {
46
37
  enabled: CardFieldState
47
38
  announceToAgent: CardFieldState
48
39
  presentation: CardFieldState
49
- guardEnabled: CardFieldState
50
- guardSensitivity: CardFieldState
51
- guardStallReasoningChars: CardFieldState
52
- guardGlobalStallCap: CardFieldState
53
- guardEchoFailures: CardFieldState
40
+ dispatcher: CardFieldState
54
41
  }
55
42
 
56
43
  /** The registration-side face the card's slot entry injects. */
@@ -72,11 +59,7 @@ export class LiangShenSettingsCardController {
72
59
  booleanField('enabled'),
73
60
  booleanField('announceToAgent'),
74
61
  choiceField('presentation', PRESENTATION_CHOICES),
75
- booleanField('guardEnabled'),
76
- choiceField('guardSensitivity', SENSITIVITY_CHOICES),
77
- numberField('guardStallReasoningChars', { integer: true, min: 200 }),
78
- numberField('guardGlobalStallCap', { integer: true, min: 2 }),
79
- numberField('guardEchoFailures', { integer: true, min: 2 }),
62
+ booleanField('dispatcher'),
80
63
  ])
81
64
  this.store = this.form.bind(() => this.projection())
82
65
  }
@@ -87,11 +70,7 @@ export class LiangShenSettingsCardController {
87
70
  enabled: this.form.field('enabled'),
88
71
  announceToAgent: this.form.field('announceToAgent'),
89
72
  presentation: this.form.field('presentation'),
90
- guardEnabled: this.form.field('guardEnabled'),
91
- guardSensitivity: this.form.field('guardSensitivity'),
92
- guardStallReasoningChars: this.form.field('guardStallReasoningChars'),
93
- guardGlobalStallCap: this.form.field('guardGlobalStallCap'),
94
- guardEchoFailures: this.form.field('guardEchoFailures'),
73
+ dispatcher: this.form.field('dispatcher'),
95
74
  }
96
75
  }
97
76
 
@@ -135,6 +114,7 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
135
114
  t={t}
136
115
  titleKey="settings.title"
137
116
  descriptionKey="settings.description"
117
+ icon={<LiangShenMark />}
138
118
  defaultOpen={false}
139
119
  state={state}
140
120
  renderChildrenWhenNotExposed
@@ -175,58 +155,15 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
175
155
  onReset={() => { props.resetField('presentation') }}
176
156
  />
177
157
  <BooleanField
178
- id="settings-liangshen-guard-enabled"
179
- label={t('settings.guardEnabled')}
180
- hint={t('settings.guardEnabledHint')}
158
+ id="settings-liangshen-dispatcher"
159
+ label={t('settings.dispatcher')}
160
+ hint={t('settings.dispatcherHint')}
181
161
  onLabel={t('settings.on')}
182
162
  offLabel={t('settings.off')}
183
163
  {...fieldProps}
184
- {...state.guardEnabled}
185
- onEdit={(text) => { props.edit('guardEnabled', text) }}
186
- onReset={() => { props.resetField('guardEnabled') }}
187
- />
188
- <ChoiceField
189
- id="settings-liangshen-guard-sensitivity"
190
- label={t('settings.guardSensitivity')}
191
- hint={t('settings.guardSensitivityHint')}
192
- choices={SENSITIVITY_CHOICES.map(choice => ({ value: choice, label: t(`sensitivity.${choice}`) }))}
193
- {...fieldProps}
194
- {...state.guardSensitivity}
195
- onEdit={(text) => { props.edit('guardSensitivity', text) }}
196
- onReset={() => { props.resetField('guardSensitivity') }}
197
- />
198
- <ValueField
199
- id="settings-liangshen-guard-stall-chars"
200
- numeric
201
- label={t('settings.guardStallChars')}
202
- hint={t('settings.guardStallCharsHint')}
203
- placeholder="8000"
204
- {...fieldProps}
205
- {...state.guardStallReasoningChars}
206
- onEdit={(text) => { props.edit('guardStallReasoningChars', text) }}
207
- onReset={() => { props.resetField('guardStallReasoningChars') }}
208
- />
209
- <ValueField
210
- id="settings-liangshen-guard-global-cap"
211
- numeric
212
- label={t('settings.guardGlobalCap')}
213
- hint={t('settings.guardGlobalCapHint')}
214
- placeholder="4"
215
- {...fieldProps}
216
- {...state.guardGlobalStallCap}
217
- onEdit={(text) => { props.edit('guardGlobalStallCap', text) }}
218
- onReset={() => { props.resetField('guardGlobalStallCap') }}
219
- />
220
- <ValueField
221
- id="settings-liangshen-guard-echo"
222
- numeric
223
- label={t('settings.guardEchoFailures')}
224
- hint={t('settings.guardEchoFailuresHint')}
225
- placeholder="3"
226
- {...fieldProps}
227
- {...state.guardEchoFailures}
228
- onEdit={(text) => { props.edit('guardEchoFailures', text) }}
229
- onReset={() => { props.resetField('guardEchoFailures') }}
164
+ {...state.dispatcher}
165
+ onEdit={(text) => { props.edit('dispatcher', text) }}
166
+ onReset={() => { props.resetField('dispatcher') }}
230
167
  />
231
168
  </PluginSettingsCard>
232
169
  )