@linxin666/dsh-liangshen 0.4.22 → 0.4.23

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.
package/lib/index.js CHANGED
@@ -458,7 +458,7 @@ function applyPresetOverrides(rows, overrides) {
458
458
  const table = overrideTargets(overrides);
459
459
  return rows.map((row) => {
460
460
  const id = row.id;
461
- if (id === "tool-executor-ptc" && overrides.presentation !== void 0) return {
461
+ if ((id === "tool-registry-ptc" || id === "tool-executor-ptc") && overrides.presentation !== void 0) return {
462
462
  ...row,
463
463
  disabled: overrides.presentation !== "ptc"
464
464
  };
@@ -9,7 +9,7 @@
9
9
  * a session reads both from its preset. The card is the operator's only handle
10
10
  * on them, which is why every field the Host schema carries appears here.
11
11
  */
12
- import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
12
+ import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots/client';
13
13
  import type { SnapshotStore } from '@deepseek-ai/dsh-client-store';
14
14
  import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
15
15
  import { type CardActions, type CardShell, type FieldSpec, type FieldState as CardFieldState } from './settings-form.ts';
@@ -67,7 +67,7 @@ export interface SettingsPluginItemOwnerProps {
67
67
  /** Marker field: card owner props are intentionally empty. */
68
68
  children?: never;
69
69
  }
70
- declare module '@deepseek-ai/dsh-client-ui-slots' {
70
+ declare module '@deepseek-ai/dsh-client-ui-slots/client' {
71
71
  interface SlotMap {
72
72
  /**
73
73
  * The child slot the Web UI plugin group declares; this card registers into
@@ -113,7 +113,7 @@ export interface LiangShenFormSpec<T> {
113
113
  * `ctx.remote.agentPresets` needs `remote` as well.
114
114
  */
115
115
  export declare const inject: string[];
116
- declare module '@deepseek-ai/dsh-client-ui-slots' {
116
+ declare module '@deepseek-ai/dsh-client-ui-slots/client' {
117
117
  interface LocaleNamespaceMap {
118
118
  /** The LiangShen lever copy. */
119
119
  'liangshen': LiangShenKey;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * DSH_HOME resolution shared by the plugin family's Host halves: the
3
- * environment override wins, the platform home fallback follows. Mirrors
4
- * what dsh-pet and dsh-liangshen each used to implement locally.
2
+ * DSH_HOME and DSH_AGENTS_HOME resolution shared by the plugin family's Host
3
+ * halves: environment overrides win (blank values treated as unset), then the
4
+ * platform home fallbacks follow — mirroring `@deepseek-ai/dsh-home-paths`.
5
5
  */
6
6
  /** Expand a leading ~ (or ~user) in a path, platform-style. */
7
7
  export declare function expandHome(path: string, home?: string): string;
@@ -14,3 +14,13 @@ export declare function expandHome(path: string, home?: string): string;
14
14
  export declare function resolveDshHome(env?: NodeJS.ProcessEnv, home?: string): string;
15
15
  /** Resolve the DSH home directory from the live environment. */
16
16
  export declare function dshHome(): string;
17
+ /**
18
+ * Resolve the shared agent configuration root (`$DSH_AGENTS_HOME`, defaulting
19
+ * to `<home>/.agents`), matching `@deepseek-ai/dsh-home-paths`'s `resolveAgentsHome`.
20
+ * @param env - process environment to read DSH_AGENTS_HOME from.
21
+ * @param home - platform home directory fallback (test seam).
22
+ * @returns the absolute shared agents home path.
23
+ */
24
+ export declare function resolveAgentsHome(env?: NodeJS.ProcessEnv, home?: string): string;
25
+ /** Resolve the shared agent configuration root from the live environment. */
26
+ export declare function agentsHome(): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-liangshen",
3
3
  "description": "LiangShen (梁神) agent preset plus its composer lever for the dsh web GUI. The host half declares the bundled preset to the harness's agent-preset registry at activation (declare = enabled), so the preset is selectable for new sessions without writing anything into the harness home; the preset keeps a minimal persona with standing working discipline while the harness's own user-role agent-instructions injection delivers the workspace instructions (the optional `instructionSource: system-prompt` mode lifts them into the prompt instead), and declares one tool presentation for the session's whole lifetime: `ptc` by default (the wire collapses to `run_code` and every other tool is reached through the generated SDK), with `native` as the explicit assembled-roster option. High-fan-out tool families (default `['mcp__*', 'browser_*', 'task_board_*', 'team_*', 'squad*', 'ui_*', 'ssh_*']`, while every host builtin stays resident; customizable via `pagedToolPatterns`) stay paged out of the wire and generated SDK until the preset's own `tool_activate` tool loads their namespace (LRU cap three, state replayed from the durable session event stream), and the tool catalog — exactly the reachable tools plus paged-out namespace summaries — and a one-line working-context projection travel as durable user messages republished only on change. The browser half adds a slot-machine lever left of the model selector on the new-session screen to toggle the mode. Hot-pluggable via cordis.patch.yml + profile symlink, no dsh source changes.",
4
- "version": "0.4.22",
4
+ "version": "0.4.23",
5
5
  "icon": "icon.svg",
6
6
  "type": "module",
7
7
  "engines": {
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dsh": {
27
27
  "engines": {
28
- "dsh": ">=0.2.3-alpha.2"
28
+ "dsh": ">=0.2.3-alpha.4"
29
29
  },
30
30
  "bundle": {
31
31
  "patch": "./cordis.patch.yml"
@@ -42,33 +42,38 @@
42
42
  }
43
43
  },
44
44
  "peerDependencies": {
45
- "@deepseek-ai/dsh": ">=0.2.3-alpha.2"
45
+ "@deepseek-ai/dsh": ">=0.2.3-alpha.4"
46
46
  },
47
47
  "dependencies": {
48
- "@deepseek-ai/schemastery": "~3.20.0-alpha.1"
48
+ "@deepseek-ai/schemastery": "~3.20.0-alpha.3"
49
49
  },
50
50
  "devDependencies": {
51
- "@deepseek-ai/cordis": "~4.2.0-alpha.1",
52
- "@deepseek-ai/dsh-agent-preset-registry": "^0.2.3-alpha.2",
53
- "@deepseek-ai/dsh-api-remotes": "^0.2.3-alpha.2",
54
- "@deepseek-ai/dsh-api-session-controller": "^0.2.3-alpha.2",
55
- "@deepseek-ai/dsh-client-connection": "^0.2.3-alpha.2",
56
- "@deepseek-ai/dsh-client-locale": "^0.2.3-alpha.2",
57
- "@deepseek-ai/dsh-client-store": "^0.2.3-alpha.2",
58
- "@deepseek-ai/dsh-client-ui-conversation": "^0.2.3-alpha.2",
59
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.3-alpha.2",
60
- "@deepseek-ai/dsh-client-ui-settings": "^0.2.3-alpha.2",
61
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.3-alpha.2",
62
- "@deepseek-ai/dsh-settings": "^0.2.3-alpha.2",
63
- "@deepseek-ai/dsh-system-prompt": "^0.2.3-alpha.2",
64
- "@testing-library/react": "^16.1.0",
51
+ "@deepseek-ai/cordis": "~4.2.0-alpha.3",
52
+ "@deepseek-ai/dsh-agent-preset-registry": "^0.2.3-alpha.4",
53
+ "@deepseek-ai/dsh-api-remotes": "^0.2.3-alpha.4",
54
+ "@deepseek-ai/dsh-api-session-controller": "^0.2.3-alpha.4",
55
+ "@deepseek-ai/dsh-client-connection": "^0.2.3-alpha.4",
56
+ "@deepseek-ai/dsh-client-locale": "^0.2.3-alpha.4",
57
+ "@deepseek-ai/dsh-client-store": "^0.2.3-alpha.4",
58
+ "@deepseek-ai/dsh-client-ui-conversation": "^0.2.3-alpha.4",
59
+ "@deepseek-ai/dsh-client-ui-renderer": "^0.2.3-alpha.4",
60
+ "@deepseek-ai/dsh-client-ui-settings": "^0.2.3-alpha.4",
61
+ "@deepseek-ai/dsh-client-ui-slots": "^0.2.3-alpha.4",
62
+ "@deepseek-ai/dsh-ptc-runtime": "^0.2.3-alpha.4",
63
+ "@deepseek-ai/dsh-scope": "^0.2.3-alpha.4",
64
+ "@deepseek-ai/dsh-settings": "^0.2.3-alpha.4",
65
+ "@deepseek-ai/dsh-system-prompt": "^0.2.3-alpha.4",
66
+ "@deepseek-ai/dsh-tool-registry-native": "^0.2.3-alpha.4",
67
+ "@deepseek-ai/dsh-tool-registry-ptc": "^0.2.3-alpha.4",
68
+ "@deepseek-ai/dsh-tools": "^0.2.3-alpha.4",
69
+ "@testing-library/react": "^16.3.3",
65
70
  "@types/node": "^22.20.0",
66
- "@types/react": "~18.3.1",
67
- "@types/react-dom": "~18.3.1",
71
+ "@types/react": "~19.3.2",
72
+ "@types/react-dom": "~19.3.0",
68
73
  "@vitest/coverage-v8": "^4.1.11",
69
74
  "jsdom": "^25.0.0",
70
- "react": "^18.3.1",
71
- "react-dom": "^18.3.1",
75
+ "react": "^19.3.1",
76
+ "react-dom": "^19.3.1",
72
77
  "tsdown": "0.22.2",
73
78
  "typescript": "~5.7.2",
74
79
  "vitest": "^4.1.11"
@@ -10,7 +10,7 @@
10
10
  # the roster on the wire, and `'ptc'` collapses the wire to the single
11
11
  # `run_code` transport with every other tool reached from inside the program
12
12
  # through the generated SDK. The settings overlay turns that key into the
13
- # `tool-executor-ptc` row below, which is what actually decides the wire:
13
+ # `tool-registry-ptc` row below, which is what actually decides the wire:
14
14
  # 0.2.2 retired `agent.ctx.tools.presentAs`, so no plugin declares it per
15
15
  # scope any more, and a deployment with no code runtime keeps the native
16
16
  # surface. The retired anchor-turn staging is gone: the legacy `anchorTools`
@@ -218,8 +218,8 @@
218
218
  # ── the wire ────────────────────────────────────────────────────────────────
219
219
  #
220
220
  # `presentation` on the `tool-catalog` row above IS the wire, because the
221
- # settings overlay turns it into the `tool-executor-ptc` row below: a mounted
222
- # ptc executor collapses the wire to the single `run_code` transport, and the
221
+ # settings overlay turns it into the `tool-registry-ptc` row below: a mounted
222
+ # ptc root registry collapses the wire to the single `run_code` transport, and the
223
223
  # `native` value disables that row so the roster is what the request carries.
224
224
  # The catalog reads the same fact back (a `ptc` setting plus a mounted
225
225
  # runtime) because no reader can observe the collapse itself: the ptc
@@ -577,8 +577,8 @@
577
577
  fetch: false
578
578
  searchTimeoutMs: 60000
579
579
 
580
- # PTC execution is an agent-scoped plugin in this cohort, and this row IS the
580
+ # PTC execution is an agent-scoped root registry in 0.2.3-alpha.3+, and this row IS the
581
581
  # presentation: the settings overlay disables it for the native presentation.
582
- # Without that executor the wire has no `run_code` to carry a program.
583
- - id: tool-executor-ptc
584
- name: '@deepseek-ai/dsh-tool-executor-ptc'
582
+ # Without that root registry the wire has no `run_code` to carry a program.
583
+ - id: tool-registry-ptc
584
+ name: '@deepseek-ai/dsh-tool-registry-ptc'
@@ -448,9 +448,13 @@ Plan mode is the user's switch, not a stop this mode manufactures. The official
448
448
  * pinned fact is read as current state when it is really a reading taken when
449
449
  * it was registered: the register is an anchor, and a stale anchor is worse
450
450
  * than no anchor because nothing downstream questions it.
451
+ *
452
+ * G17 amends R6/R-W for DSH 0.2.3-alpha.4 subagent settlement notifications
453
+ * carrying error code, HTTP status, or user-stop details. G18 documents that
454
+ * workspace directory Markdown links open the directory in the web sidebar.
451
455
  */
452
456
  export const DISPATCHER_RULES_APPENDIX = `
453
- G7 to G14 below are the local additions to G1 to G6 above: where they conflict with G1 to G6, those entries win. G15 below is a separate addition to R5, and G16 a separate rule for the fact register this preset injects; neither has a counterpart upstream.
457
+ G7 to G14 below are the local additions to G1 to G6 above: where they conflict with G1 to G6, those entries win. G15 below is a separate addition to R5, G16 governs the fact register this preset injects, G17 amends R6/R-W settlement diagnostics, and G18 covers directory links in replies; none has a counterpart upstream.
454
458
 
455
459
  - G7 Asking budget: at most 4 questions a round, at most 3 rounds, ordered by blast radius—the branch-overturning one first. An unknown whose answers would change neither the path, the acceptance criteria nor the cost is not asked: put it on the assumption list.
456
460
  - G8 Assumption exit: if the user declines the interview, or a question is still unanswerable after two rounds, list "I will proceed on these assumptions" (one per line) plus what would bring you back, then continue.
@@ -462,11 +466,14 @@ G7 to G14 below are the local additions to G1 to G6 above: where they conflict w
462
466
  - G14 Fact-check dispatches: the read-only check G4 sends is not bound by R5's interview precondition, which covers implementation only; its finding lands in your reply before the next question.
463
467
  - G15 Task board is not a dispatch: neither a project card nor a built-in team task (team_task_create and its siblings) substitutes for an R5 dispatch, so an L2 task briefs and dispatches its subagents per R5 whether the card exists or not.
464
468
  - G16 Facts are anchors, not sources of truth: a pinned fact records the state when it was registered, so once its subject changes re-read it with a tool before planning on it, and revoke the entry through fact_register once settled. A stale anchor is worse than none: it reads as current, costs a turn to disprove, and is never questioned because you supplied it.
469
+ - G17 Subagent settlement diagnostics: local subagent failure or stop notifications include error codes, HTTP statuses, or user-stop details; use them to separate retryable faults from user-initiated stops, and never auto-re-dispatch a child the user stopped.
470
+ - G18 Directory links in replies: a Markdown link pointing to a workspace directory opens that folder directly in the sidebar, so prefer linking it over pasting a raw directory listing.
465
471
 
466
472
  Violations added here (continuing the anti-pattern list above):
467
473
  A. Asking instead of judging: handing over an unknown whose answers change nothing, or inflating a bounded assumption into a blocker.
468
474
  B. Asking one decision twice, or reading "either is fine" as no answer.
469
475
  C. Planning on a pinned fact whose subject changed, without re-reading it.
476
+ D. Auto-re-dispatching a subagent whose settlement notification reports a user-initiated stop.
470
477
  `
471
478
 
472
479
  /** What the prompt appends: the reference block, then the local additions. */
@@ -151,6 +151,9 @@ export function renderLedgerField(facts) {
151
151
  export function apply(ctx) {
152
152
  ctx.tools.register({
153
153
  name: FACT_LEDGER_TOOL,
154
+ // Session-log-only register: never touches the execution machine, so it
155
+ // stays callable inside remote SSH execution environments (DSH 0.2.3-alpha.4+).
156
+ environment: 'independent',
154
157
  description: [
155
158
  'Pin one key fact into this session working context — the line the runtime projects next to the newest message every step. Use it for the facts a long session must not lose: a hard user constraint, a confirmed architecture decision, a path that already failed.',
156
159
  `A fact is one short line (<= ${MAX_FACT_CHARS} chars); at most ${MAX_FACTS} stay pinned, the oldest dropping off. Pass the same text again to no-op; pass the revoke field with a fact tag (or its exact text) to unpin everything under it.`,
@@ -125,6 +125,19 @@ export const PLAN_POLICY_SECTION_NAME = 'plan:policy'
125
125
  */
126
126
  export const PTC_SECTION_NAMES = ['tools:ptc-only', 'tools:sdk']
127
127
 
128
+ /**
129
+ * Official `@deepseek-ai/dsh-mcp-client` on-demand tool catalog sections
130
+ * (`mcp:<serverName>:tools`). Retained automatically so servers configured with
131
+ * `toolLoading: 'on-demand'` remain discoverable alongside LiangShen's compact
132
+ * system prompt.
133
+ */
134
+ export const MCP_ON_DEMAND_TOOLS_SECTION_RE = /^mcp:.+:tools$/
135
+
136
+ /** Whether a prompt section name is an official on-demand MCP tool catalog section. */
137
+ export function isMcpOnDemandToolsSection(sectionName) {
138
+ return typeof sectionName === 'string' && MCP_ON_DEMAND_TOOLS_SECTION_RE.test(sectionName)
139
+ }
140
+
128
141
  /**
129
142
  * The section this plugin appends to the prompt with the workspace
130
143
  * instructions, and the assembly variable whose value carries the rendered
@@ -144,7 +157,7 @@ export const WORKSPACE_INSTRUCTIONS_VARIABLE = 'workspace_instructions'
144
157
  export const INSTRUCTION_SOURCES = ['host', 'system-prompt', 'hint']
145
158
 
146
159
  /** Tools whose executions touch workspace files and may trigger dynamic instruction discovery. */
147
- export const FILE_TOUCH_TOOL_NAMES = new Set(['read', 'write', 'edit', 'str_replace_editor'])
160
+ export const FILE_TOUCH_TOOL_NAMES = new Set(['read', 'write', 'edit', 'apply_patch', 'str_replace_editor'])
148
161
 
149
162
  /**
150
163
  * Instruction file candidates per directory, in the harness's order: the
@@ -503,31 +516,99 @@ export function instructionHintMessages(messages, state) {
503
516
  return kept
504
517
  }
505
518
 
519
+ const APPLY_PATCH_FILE_PREFIXES = [
520
+ '*** Add File: ',
521
+ '*** Update File: ',
522
+ '*** Delete File: ',
523
+ '*** Move to: ',
524
+ ]
525
+
526
+ function extractApplyPatchPaths(input) {
527
+ if (typeof input !== 'string' || input.length === 0) return []
528
+ const paths = []
529
+ const seen = new Set()
530
+ const record = (raw) => {
531
+ const trimmed = raw.trim()
532
+ if (trimmed.length === 0 || seen.has(trimmed)) return
533
+ seen.add(trimmed)
534
+ paths.push(trimmed)
535
+ }
536
+
537
+ let mode = 'header'
538
+ for (const line of input.split(/\r?\n/)) {
539
+ if (mode === 'add') {
540
+ if (line.startsWith('+')) continue
541
+ mode = 'header'
542
+ } else if (mode === 'hunk') {
543
+ if (line.startsWith('+') || line.startsWith('-') || line.startsWith(' ')) continue
544
+ if (line === '@@' || line.startsWith('@@ ') || line.trim() === '*** End of File') continue
545
+ mode = 'header'
546
+ } else if (mode === 'update') {
547
+ if (line === '@@' || line.startsWith('@@ ')) {
548
+ mode = 'hunk'
549
+ continue
550
+ }
551
+ if (line.startsWith('+') || line.startsWith('-') || line.startsWith(' ')) {
552
+ mode = 'hunk'
553
+ continue
554
+ }
555
+ }
556
+
557
+ const trimmed = line.trim()
558
+ if (trimmed === '*** End Patch') break
559
+ let matched = false
560
+ for (const prefix of APPLY_PATCH_FILE_PREFIXES) {
561
+ if (!trimmed.startsWith(prefix)) continue
562
+ record(trimmed.slice(prefix.length))
563
+ if (prefix === '*** Add File: ') mode = 'add'
564
+ else if (prefix === '*** Update File: ' || prefix === '*** Move to: ') mode = 'update'
565
+ else mode = 'header'
566
+ matched = true
567
+ break
568
+ }
569
+ if (!matched && mode === 'update') mode = 'header'
570
+ }
571
+ return paths
572
+ }
573
+
506
574
  /**
507
- * Extract touched file path from a ToolExecution object.
508
- * Synchronously extracts path from:
575
+ * Extract all touched file paths from a ToolExecution object.
576
+ * Synchronously extracts paths from:
509
577
  * - `read`, `write`, `edit` via `exec.arguments.file_path`
578
+ * - `apply_patch` via patch headers in `exec.arguments.input`
510
579
  * - `str_replace_editor` via `exec.arguments.path`
511
580
  * Supports both top-level and PTC nested executions without guessing code strings.
512
581
  */
513
- export function filePathFromExecution(exec) {
514
- if (!exec || typeof exec !== 'object') return undefined
515
- if (typeof exec.name !== 'string') return undefined
516
- if (typeof exec.arguments !== 'object' || exec.arguments === null) return undefined
582
+ export function filePathsFromExecution(exec) {
583
+ if (!exec || typeof exec !== 'object') return []
584
+ if (typeof exec.name !== 'string') return []
585
+ if (typeof exec.arguments !== 'object' || exec.arguments === null) return []
586
+
587
+ if (exec.name === 'apply_patch') {
588
+ return extractApplyPatchPaths(exec.arguments.input)
589
+ }
517
590
 
518
591
  if (exec.name === 'str_replace_editor') {
519
592
  if ('path' in exec.arguments && typeof exec.arguments.path === 'string') {
520
593
  const p = exec.arguments.path.trim()
521
- return p.length > 0 ? p : undefined
594
+ return p.length > 0 ? [p] : []
522
595
  }
523
596
  }
524
597
 
525
598
  if ('file_path' in exec.arguments && typeof exec.arguments.file_path === 'string') {
526
599
  const p = exec.arguments.file_path.trim()
527
- return p.length > 0 ? p : undefined
600
+ return p.length > 0 ? [p] : []
528
601
  }
529
602
 
530
- return undefined
603
+ return []
604
+ }
605
+
606
+ /**
607
+ * Extract the first touched file path from a ToolExecution object.
608
+ * Kept for compatibility alongside {@link filePathsFromExecution}.
609
+ */
610
+ export function filePathFromExecution(exec) {
611
+ return filePathsFromExecution(exec)[0]
531
612
  }
532
613
 
533
614
  /**
@@ -791,12 +872,14 @@ export function apply(ctx, config) {
791
872
  // an error touched nothing.
792
873
  if (ev?.type !== 'tool/call' && ev?.type !== 'tool/ptc-dispatch') continue
793
874
  if (!ev.data || ev.data.isError === true) continue
875
+ if (ev.data.environment !== undefined) continue
794
876
  let args = ev.data.arguments
795
877
  if (typeof args === 'string') {
796
878
  try { args = JSON.parse(args) } catch {}
797
879
  }
798
- const p = filePathFromExecution({ name: ev.data.name, arguments: args })
799
- if (p) state.touchedDirs.add(dirname(resolve(cwd, p)))
880
+ for (const p of filePathsFromExecution({ name: ev.data.name, arguments: args })) {
881
+ state.touchedDirs.add(dirname(resolve(cwd, p)))
882
+ }
800
883
  }
801
884
  } catch {
802
885
  // Replay reconstruction fallback
@@ -848,7 +931,7 @@ export function apply(ctx, config) {
848
931
  // Logger unavailable
849
932
  }
850
933
  }
851
- const sections = assembled.sections.filter(section => keep.has(section?.name))
934
+ const sections = assembled.sections.filter(section => keep.has(section?.name) || isMcpOnDemandToolsSection(section?.name))
852
935
  if (sections.length === 0) {
853
936
  warnOnce(`${name}: no section matched ${JSON.stringify([...keep])} — `
854
937
  + 'keeping the assembled prompt instead of sending an empty one')
@@ -896,15 +979,19 @@ export function apply(ctx, config) {
896
979
  ctx.on('tools/result', (exec, result) => {
897
980
  if (instructionSource !== 'system-prompt') return
898
981
  if (result?.isError || !exec?.agent || exec?.signal?.aborted) return
899
- const path = filePathFromExecution(exec)
900
- if (!path) return
982
+ // Remote execution environment paths belong to the remote host, not this machine's cwd.
983
+ if (exec.environment !== undefined) return
984
+ const paths = filePathsFromExecution(exec)
985
+ if (paths.length === 0) return
901
986
 
902
987
  const session = exec.agent.session
903
988
  if (!session) return
904
989
 
905
990
  const cwd = session.header?.cwd ?? process.cwd()
906
991
  const state = getSessionState(session)
907
- state.touchedDirs.add(dirname(resolve(cwd, path)))
992
+ for (const path of paths) {
993
+ state.touchedDirs.add(dirname(resolve(cwd, path)))
994
+ }
908
995
  })
909
996
 
910
997
  // 3. Agent pre-step message filter & dynamic discovery
@@ -55,6 +55,27 @@ export const DEFAULT_IDLE_RECLAIM_STEPS = 0
55
55
  /** The activation tool this preset registers. */
56
56
  export const TOOL_ACTIVATE_NAME = 'tool_activate'
57
57
 
58
+ /**
59
+ * Official `@deepseek-ai/dsh-mcp-client` on-demand loader tool name
60
+ * (`mcp__<serverName>__load_tools`). A server configured with
61
+ * `toolLoading: 'on-demand'` already manages its own progressive loading, so
62
+ * its loader — and any tools the agent explicitly loads from that server —
63
+ * must stay resident rather than being paged out a second time by `mcp__*`.
64
+ */
65
+ export const MCP_ON_DEMAND_LOADER_RE = /^mcp__(.+)__load_tools$/
66
+
67
+ /** Extract the MCP server name from an official on-demand loader tool name, or undefined. */
68
+ export function mcpOnDemandServerOf(name) {
69
+ if (typeof name !== 'string') return undefined
70
+ const match = MCP_ON_DEMAND_LOADER_RE.exec(name)
71
+ return match !== null && match[1].length > 0 ? match[1] : undefined
72
+ }
73
+
74
+ /** Whether a tool name is an official MCP `on-demand` loader (`mcp__<server>__load_tools`). */
75
+ export function isMcpOnDemandLoader(name) {
76
+ return mcpOnDemandServerOf(name) !== undefined
77
+ }
78
+
58
79
  /** Validate a positive-integer config value, or fall back when absent. */
59
80
  export function integerAtLeast(plugin, value, field, minimum, fallback) {
60
81
  if (value === undefined) return fallback
@@ -102,6 +123,7 @@ export function validatePagedToolPatterns(plugin, value, fallback = DEFAULT_PAGE
102
123
  */
103
124
  export function patternNamespace(name, pattern) {
104
125
  if (typeof name !== 'string' || typeof pattern !== 'string' || !pattern.endsWith('*')) return undefined
126
+ if (isMcpOnDemandLoader(name)) return undefined
105
127
  const prefix = pattern.slice(0, -1)
106
128
  if (!name.startsWith(prefix)) return undefined
107
129
  const rest = name.slice(prefix.length)
@@ -123,16 +145,33 @@ export function namespaceOf(name, patterns) {
123
145
 
124
146
  /**
125
147
  * Partition one wire tool list into resident tools and paged-but-inactive
126
- * namespaces. A paged tool whose namespace is active stays resident. The
127
- * inactive map is keyed by namespace in sorted order so one surface renders
148
+ * namespaces. A paged tool whose namespace is active stays resident. Official
149
+ * on-demand MCP servers (identified by the presence of
150
+ * `mcp__<server>__load_tools`) keep both their loader and any already-loaded
151
+ * tools resident so two progressive-loading layers do not fight each other.
152
+ * The inactive map is keyed by namespace in sorted order so one surface renders
128
153
  * byte-identical text across assemblies.
129
154
  */
130
155
  export function partitionWireTools(tools, patterns, activeNamespaces) {
131
156
  const resident = []
132
157
  const inactive = new Map()
133
158
  const active = activeNamespaces instanceof Set ? activeNamespaces : new Set(activeNamespaces ?? [])
134
- for (const tool of Array.isArray(tools) ? tools : []) {
135
- const namespace = namespaceOf(tool?.name, patterns)
159
+ const list = Array.isArray(tools) ? tools : []
160
+ const onDemandMcpServers = new Set()
161
+ for (const tool of list) {
162
+ const server = mcpOnDemandServerOf(tool?.name)
163
+ if (server !== undefined) onDemandMcpServers.add(server)
164
+ }
165
+ for (const tool of list) {
166
+ const toolName = tool?.name
167
+ if (typeof toolName === 'string' && toolName.startsWith('mcp__')) {
168
+ const server = toolName.slice('mcp__'.length).split('__')[0]
169
+ if (server !== '' && onDemandMcpServers.has(server)) {
170
+ resident.push(tool)
171
+ continue
172
+ }
173
+ }
174
+ const namespace = namespaceOf(toolName, patterns)
136
175
  if (namespace === undefined || active.has(namespace)) {
137
176
  resident.push(tool)
138
177
  continue
@@ -182,6 +182,26 @@ export function liveServiceRoutes(service) {
182
182
  return { handled: true, routes: normalizeRoutes(raw) }
183
183
  }
184
184
 
185
+ /**
186
+ * Resolve the optional live default child route (`subagentModelSelection.defaultRoute()`,
187
+ * added in DSH 0.2.3-alpha.3 #9373). Returns `{ provider, model }` when a valid
188
+ * default route is configured, or undefined when absent / unsupported / throwing.
189
+ * @param service - Optional `ctx.get('subagentModelSelection')` service instance.
190
+ */
191
+ export function liveServiceDefaultRoute(service) {
192
+ if (typeof service?.defaultRoute !== 'function') return undefined
193
+ let raw
194
+ try {
195
+ raw = service.defaultRoute()
196
+ } catch {
197
+ return undefined
198
+ }
199
+ const route = asRecord(raw)
200
+ const provider = asString(route?.['provider'])
201
+ const model = asString(route?.['model'])
202
+ return provider !== undefined && model !== undefined ? { provider, model } : undefined
203
+ }
204
+
185
205
  /**
186
206
  * Resolve the allowlist a delegation from this agent must respect: the agent's
187
207
  * own recorded policy, else the nearest ancestor Session that recorded one.
@@ -260,18 +280,48 @@ export function delegationModeOf(toolName, explicitToolNames, inheritToolNames)
260
280
  return undefined
261
281
  }
262
282
 
283
+ /** Read whether one tool definition declares `provider` or `model` parameter fields. */
284
+ function definitionDeclaresRouteFields(definition) {
285
+ const parameters = asRecord(definition?.parameters)
286
+ if (parameters === undefined) return undefined
287
+ const properties = asRecord(parameters['properties'])
288
+ if (properties !== undefined) {
289
+ return properties['provider'] !== undefined || properties['model'] !== undefined
290
+ }
291
+ return parameters['provider'] !== undefined || parameters['model'] !== undefined
292
+ }
293
+
263
294
  /**
264
- * Ask the tool registry whether one delegation tool currently declares the
265
- * route fields. The answer is read per call: an HMR replacement or a preset
295
+ * Ask the tool execution or registry whether one delegation tool currently declares
296
+ * the route fields. The answer is read per call: an HMR replacement or a preset
266
297
  * change can remount the tool, and a stale answer would put the guard back on
267
298
  * the branch no call can satisfy.
299
+ *
300
+ * In DSH 0.2.3-alpha.3+ (`tool-registry-roots`), `tools.definitions()` was removed
301
+ * and every `ToolExecution` carries its resolved `definition` directly (including
302
+ * nested PTC calls); fall back to `tools.get(toolName, agent)` and finally legacy
303
+ * `tools.definitions(agent)` for older Hosts and test stubs.
268
304
  * @param tools - Tool registry from the Host context.
269
305
  * @param agent - Calling agent, whose scope selects the visible definitions.
270
306
  * @param toolName - Tool being dispatched.
307
+ * @param executionDefinition - Resolved `ToolExecution.definition` when available.
271
308
  * @returns whether the tool declares a route field, or undefined when the
272
309
  * registry cannot answer (which keeps the configured mode in charge).
273
310
  */
274
- export function routeParameterProbe(tools, agent, toolName) {
311
+ export function routeParameterProbe(tools, agent, toolName, executionDefinition) {
312
+ if (executionDefinition !== undefined) {
313
+ const fromExec = definitionDeclaresRouteFields(executionDefinition)
314
+ if (fromExec !== undefined) return fromExec
315
+ }
316
+ if (typeof tools?.get === 'function') {
317
+ try {
318
+ const definition = tools.get(toolName, agent)
319
+ const fromGet = definitionDeclaresRouteFields(definition)
320
+ if (fromGet !== undefined) return fromGet
321
+ } catch {
322
+ // Fall through to legacy probe when root lookup throws.
323
+ }
324
+ }
275
325
  if (typeof tools?.definitions !== 'function') return undefined
276
326
  let definitions
277
327
  try {
@@ -280,9 +330,7 @@ export function routeParameterProbe(tools, agent, toolName) {
280
330
  return undefined
281
331
  }
282
332
  const definition = (Array.isArray(definitions) ? definitions : []).find(entry => entry?.name === toolName)
283
- const parameters = asRecord(definition?.parameters)
284
- if (parameters === undefined) return undefined
285
- return parameters['provider'] !== undefined || parameters['model'] !== undefined
333
+ return definitionDeclaresRouteFields(definition)
286
334
  }
287
335
 
288
336
  /** Denial reason for a delegation that named a route on an inherit-only tool. */
@@ -384,7 +432,20 @@ export function delegationDenialReason(input) {
384
432
  // child would inherit. Only the COMPLETE pair falls through.
385
433
  if (!complete) return inheritedRouteDenial(agent, toolName, allowed)
386
434
  }
387
- if (!complete) return missingPairReason(toolName, named, inheritedRouteOf(agent), allowed)
435
+ if (!complete) {
436
+ // DSH 0.2.3-alpha.3 (#9373): when the operator configured a default child
437
+ // model on the Plugins page (`subagentModelSelection.defaultRoute()`), a
438
+ // call that omits both `provider` and `model` runs on that default route
439
+ // instead of inheriting the parent route. Allow it whenever that configured
440
+ // default route is itself authorized by the active allowlist.
441
+ if (named.provider === undefined && named.model === undefined) {
442
+ const defaultRoute = liveServiceDefaultRoute(liveService)
443
+ if (defaultRoute !== undefined && routesInclude(allowed, defaultRoute.provider, defaultRoute.model)) {
444
+ return undefined
445
+ }
446
+ }
447
+ return missingPairReason(toolName, named, inheritedRouteOf(agent), allowed)
448
+ }
388
449
  if (!routesInclude(allowed, named.provider, named.model)) {
389
450
  return unauthorizedReason(toolName, named.provider, named.model, allowed)
390
451
  }
@@ -413,7 +474,7 @@ export function installSubagentRoutes(ctx, config = {}) {
413
474
  getModelSelection,
414
475
  explicitToolNames,
415
476
  inheritToolNames,
416
- probe: (agent, toolName) => routeParameterProbe(tools, agent, toolName),
477
+ probe: (agent, toolName) => routeParameterProbe(tools, agent, toolName, execution?.definition),
417
478
  }))
418
479
  }
419
480