@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.
@@ -67,14 +67,51 @@ export function apply(ctx, config) {
67
67
  DEFAULT_IDLE_RECLAIM_STEPS,
68
68
  )
69
69
 
70
+ const scopedToolsOf = (agent) => {
71
+ const agentCtx = agent?.ctx
72
+ if (agentCtx === undefined || agentCtx === null) return undefined
73
+ if (typeof agentCtx.get === 'function') {
74
+ const bound = agentCtx.get('tools')
75
+ if (bound !== undefined) return bound
76
+ }
77
+ try {
78
+ return agentCtx.tools
79
+ } catch {
80
+ return undefined
81
+ }
82
+ }
83
+
70
84
  /**
71
- * Read the session's visible tool schemas from the public API, tolerating
72
- * test stubs that only provide sdkSchemas.
85
+ * Read the session's visible tool schemas from the public API.
86
+ * Supports 0.2.3-alpha.3 `tools.getAll(agent)` (falling back to unscoped
87
+ * `tools.getAll()` when a PTC root collapses scoped reads to `run_code`),
88
+ * and tolerates legacy `schemas` / `sdkSchemas` test stubs.
73
89
  */
74
90
  const schemasFor = (agent) => {
75
- const candidates = [agent?.ctx?.tools, ctx.tools, ctx.get('tools')]
91
+ const candidates = [scopedToolsOf(agent), ctx.tools, ctx.get('tools')]
76
92
  for (const tools of candidates) {
77
93
  if (tools === undefined) continue
94
+ if (typeof tools?.getAll === 'function') {
95
+ try {
96
+ const scoped = tools.getAll(agent)
97
+ if (Array.isArray(scoped)) {
98
+ const nonTransport = scoped.filter(entry => entry?.name && entry.name !== 'run_code')
99
+ if (nonTransport.length > 0) return nonTransport
100
+ // Under a 0.2.3-alpha.3 PTC root registry, scoped getAll(agent)
101
+ // returns only [run_code]; the unscoped root stays native and holds
102
+ // the global/plugin/MCP registrations that paging covers.
103
+ if (scoped.some(entry => entry?.name === 'run_code')) {
104
+ const globalEntries = tools.getAll()
105
+ if (Array.isArray(globalEntries)) {
106
+ return globalEntries.filter(entry => entry?.name && entry.name !== 'run_code')
107
+ }
108
+ }
109
+ return []
110
+ }
111
+ } catch {
112
+ // A hostile or unavailable projection falls through to the next source.
113
+ }
114
+ }
78
115
  for (const method of ['schemas', 'sdkSchemas']) {
79
116
  if (typeof tools?.[method] !== 'function') continue
80
117
  try {
@@ -129,6 +166,9 @@ export function apply(ctx, config) {
129
166
 
130
167
  ctx.tools.register({
131
168
  name: 'tool_activate',
169
+ // Session-log-only meta-tool: never touches the execution machine, so it
170
+ // stays callable inside remote SSH execution environments (DSH 0.2.3-alpha.4+).
171
+ environment: 'independent',
132
172
  description: [
133
173
  `Load one paged tool namespace back into this session's reach — onto the wire, and the generated SDK along with it. The session catalog summarizes the paged namespaces; activating one makes its tools callable from the next request on.`,
134
174
  `At most ${maxActiveNamespaces} namespaces stay active at once: activating beyond the cap evicts the least recently used namespace back to the catalog summary.`,
@@ -11,8 +11,8 @@
11
11
  * generated SDK.
12
12
  *
13
13
  * The preset composition is what actually selects it: `src/composition.ts`
14
- * enables or disables the `tool-executor-ptc` row from the same setting, and
15
- * that row is what installs the executor whose `describe()` decides the wire
14
+ * enables or disables the `tool-registry-ptc` row from the same setting, and
15
+ * that row is what installs the root registry whose entries decide the wire
16
16
  * (0.2.2 retired `ctx.tools.presentAs`, the old per-scope declaration, so this
17
17
  * plugin no longer declares anything). A deployment with no code runtime keeps
18
18
  * the native surface, and the catalog says so. There is no turn-boundary
@@ -393,7 +393,8 @@ export const CURATED_TOOL_SUMMARIES = new Map([
393
393
  ['read_image', 'Read a PNG/JPEG/WebP/GIF image file and return the image itself (`file_path`); large images are downscaled automatically.'],
394
394
  ['write', 'Create or fully replace one UTF-8 text file (`file_path`, `content`).'],
395
395
  ['edit', 'Replace literal text in one existing file (`file_path`, `old_string`, `new_string`, optional `replace_all`).'],
396
- ['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`).'],
396
+ ['apply_patch', 'Apply a structured multi-file patch in one call (`input`, using `*** Begin Patch` / `*** Add File:` / `*** Update File:` / `*** Delete File:` / `*** End Patch`).'],
397
+ ['str_replace_editor', 'View, create, and edit files (`command`, `path`, `file_text`, `old_str` / `new_str`, `insert_line`, `view_range`); local-only, in remote environments use read/write/edit/apply_patch.'],
397
398
  ['glob', 'Find files whose paths match a glob pattern (`pattern`, optional `path`); up to 100 paths in modification-time order.'],
398
399
  ['grep', 'Search file contents with a ripgrep expression (`pattern`, optional `path`, optional `include`); matching lines with line numbers.'],
399
400
  ['job_output', 'Read a background job: output since the previous read, or the finished result (`job_id`, optional `wait`, `timeout_ms`).'],
@@ -649,6 +650,120 @@ function stateCatalogText(state) {
649
650
  return state.text
650
651
  }
651
652
 
653
+ /**
654
+ * Parse tool bindings rendered by `@deepseek-ai/dsh-tool-registry-ptc` into
655
+ * the `tools:sdk` system-prompt section (`interface ToolArgsMap { ... }`).
656
+ *
657
+ * Under DSH 0.2.3-alpha.3+ (`tool-registry-roots`), `ctx.tools.getAll(agent)`
658
+ * returns only `[run_code]` when a PTC root registry is active, while
659
+ * `PtcToolRegistry.renderSdk(toolStep)` deterministically emits every bound
660
+ * tool's JSDoc summary and argument signature in `interface ToolArgsMap`.
661
+ * Parsing that block reconstructs `{ name, description, parameters }` without
662
+ * reaching into private registry internals.
663
+ * @param sdkText - Rendered `tools:sdk` section text.
664
+ * @returns parsed tool entries (excluding `run_code`), or undefined when no
665
+ * `ToolArgsMap` block is present.
666
+ */
667
+ export function parseToolsSdkSurface(sdkText) {
668
+ if (typeof sdkText !== 'string') return undefined
669
+ const startMatch = /^interface ToolArgsMap \{/m.exec(sdkText)
670
+ if (startMatch === null) return undefined
671
+ const bodyStart = startMatch.index + startMatch[0].length
672
+ const rest = sdkText.slice(bodyStart)
673
+ const lines = rest.split(/\r?\n/)
674
+ const entries = []
675
+ let pendingDoc = ''
676
+ let current = undefined
677
+
678
+ const unquoteKey = (bare, quoted) => {
679
+ if (bare !== undefined) return bare
680
+ try {
681
+ return JSON.parse(`"${quoted}"`)
682
+ } catch {
683
+ return quoted
684
+ }
685
+ }
686
+
687
+ /** Map a single-line TS type emitted by `jsonSchemaToTs` back to a compact JSON-Schema node. */
688
+ const parseTsType = (raw) => {
689
+ const trimmed = raw.replace(/;\s*$/, '').trim()
690
+ if (trimmed === 'string' || trimmed === 'number' || trimmed === 'boolean' || trimmed === 'null') {
691
+ return { type: trimmed }
692
+ }
693
+ if (trimmed === '{' || trimmed.startsWith('Record<')) {
694
+ return { type: 'object' }
695
+ }
696
+ if (trimmed.endsWith('[]')) {
697
+ const inner = trimmed.slice(0, -2).trim()
698
+ const unwrapped = inner.startsWith('(') && inner.endsWith(')') ? inner.slice(1, -1) : inner
699
+ return { type: 'array', items: parseTsType(unwrapped) }
700
+ }
701
+ if (trimmed.includes(' | ')) {
702
+ const parts = trimmed.split(' | ').map(part => part.trim())
703
+ const literals = []
704
+ let allLiterals = true
705
+ for (const part of parts) {
706
+ try {
707
+ literals.push(JSON.parse(part))
708
+ } catch {
709
+ allLiterals = false
710
+ break
711
+ }
712
+ }
713
+ if (allLiterals && literals.length > 0) return { enum: literals }
714
+ return { oneOf: parts.map(parseTsType) }
715
+ }
716
+ try {
717
+ return { const: JSON.parse(trimmed) }
718
+ } catch {
719
+ return {}
720
+ }
721
+ }
722
+
723
+ for (const line of lines) {
724
+ if (line === '}') break
725
+ if (current === undefined) {
726
+ const doc = /^ {2}\/\*\* (.*) \*\/$/.exec(line)
727
+ if (doc !== null) {
728
+ pendingDoc = doc[1].replaceAll('*\\/', '*/')
729
+ continue
730
+ }
731
+ const member = /^ {2}(?:([A-Za-z_$][A-Za-z0-9_$]*)|"((?:\\.|[^"\\])*)"):\s*(.*)$/.exec(line)
732
+ if (member === null) continue
733
+ const toolName = unquoteKey(member[1], member[2])
734
+ const rhs = member[3].trim()
735
+ const entry = {
736
+ name: toolName,
737
+ description: pendingDoc,
738
+ parameters: { type: 'object', properties: {}, required: [] },
739
+ }
740
+ pendingDoc = ''
741
+ if (rhs === '{') {
742
+ current = entry
743
+ } else if (toolName !== '' && toolName !== 'run_code') {
744
+ entries.push(entry)
745
+ }
746
+ continue
747
+ }
748
+ if (/^ {2}\}(?:\s*&.*)?;?$/.test(line)) {
749
+ if (current.name !== '' && current.name !== 'run_code') {
750
+ entries.push(current)
751
+ }
752
+ current = undefined
753
+ continue
754
+ }
755
+ const prop = /^ {4}(?:([A-Za-z_$][A-Za-z0-9_$]*)|"((?:\\.|[^"\\])*)")(\?)?:\s*(.*)$/.exec(line)
756
+ if (prop !== null) {
757
+ const propName = unquoteKey(prop[1], prop[2])
758
+ if (propName !== '') {
759
+ current.parameters.properties[propName] = parseTsType(prop[4] ?? '')
760
+ if (prop[3] !== '?') current.parameters.required.push(propName)
761
+ }
762
+ }
763
+ }
764
+ return entries
765
+ }
766
+
652
767
  /** Register the registry paging and the per-step catalog injection. */
653
768
  export function apply(ctx, config) {
654
769
  const descriptionMaxLength = integerAtLeast(
@@ -713,6 +828,13 @@ export function apply(ctx, config) {
713
828
  // released with the agent so a departed scope leaves no filter behind.
714
829
  const agentPaging = new WeakMap()
715
830
 
831
+ // Under DSH 0.2.3-alpha.3+ (`tool-registry-roots`), a PTC root registry only
832
+ // exposes `[run_code]` through `ctx.tools.getAll(agent)`, while publishing
833
+ // its step-bound tool declarations in the `tools:sdk` prompt section. Cache
834
+ // the last parsed SDK surface per agent so subsequent paging syncs also see
835
+ // preset-scoped bindings alongside unscoped global registrations.
836
+ const agentSdkSurface = new WeakMap()
837
+
716
838
  /** Lift one agent scope's live restriction, if it has one. */
717
839
  const clearScopePaging = (agent) => {
718
840
  const state = agentPaging.get(agent)
@@ -744,6 +866,24 @@ export function apply(ctx, config) {
744
866
  * request it runs in. Returns the stored state, or undefined when the scope
745
867
  * needs none — nothing paged, an unusable scoped view, or a refused filter.
746
868
  */
869
+ /**
870
+ * Read the agent-scoped ToolsService without triggering Cordis's undeclared-inject
871
+ * getter trap when a context does not statically inject `tools`.
872
+ */
873
+ const scopedToolsOf = (agent) => {
874
+ const agentCtx = agent?.ctx
875
+ if (agentCtx === undefined || agentCtx === null) return undefined
876
+ if (typeof agentCtx.get === 'function') {
877
+ const bound = agentCtx.get('tools')
878
+ if (bound !== undefined) return bound
879
+ }
880
+ try {
881
+ return agentCtx.tools
882
+ } catch {
883
+ return undefined
884
+ }
885
+ }
886
+
747
887
  const syncScopePaging = (agent) => {
748
888
  clearScopePaging(agent)
749
889
  // Retract the earlier publication first: every early return below means this
@@ -751,7 +891,7 @@ export function apply(ctx, config) {
751
891
  // activation tool can no longer reach.
752
892
  publishPagedSurface(agent, undefined)
753
893
 
754
- const tools = agent?.ctx?.tools
894
+ const tools = scopedToolsOf(agent)
755
895
  if (tools === undefined || typeof tools.restrict !== 'function') {
756
896
  warnOnce('paging-runtime', 'no scoped tools view to page through — the paged namespaces stay reachable through a program in this session')
757
897
  return undefined
@@ -762,7 +902,7 @@ export function apply(ctx, config) {
762
902
  // nothing left to withhold. Silent on an unreadable surface: a sync may
763
903
  // run before the registry is populated, and "no tools yet" is not the
764
904
  // assembly-path emergency that warning describes.
765
- const fullSurface = readSurface(agent, undefined, { quiet: true }) ?? []
905
+ const fullSurface = readSurface(agent, undefined, { quiet: true, forPaging: true }) ?? []
766
906
  if (fullSurface.length === 0) return undefined
767
907
  // ONE partition of the full surface, with the empty active set: it is both
768
908
  // the publication the activation tool reads back (every paged namespace,
@@ -844,59 +984,108 @@ export function apply(ctx, config) {
844
984
  // `@deepseek-ai/dsh-ptc-runtime`); the old key is gone, so reading it would
845
985
  // silently disable program presentation for every session.
846
986
  //
847
- // This is the ONE fact that decides what the request carries, because no
848
- // reader can observe the collapse itself: the petc executor keeps `run_code`
849
- // outside the registry (`describe()` returns it, `tools.schemas()` never
850
- // does), so a `schemas()` read returns the same roster under both
851
- // presentations. The composition enables the `tool-executor-ptc` row from
987
+ // The composition enables the `tool-registry-ptc` row from
852
988
  // exactly this setting (see `src/composition.ts`), so the configured
853
989
  // presentation plus a mounted runtime IS the wire.
854
990
  const collapsedTransport = () => presentation !== 'native' && ctx.get('ptcRuntime') !== undefined
855
991
 
856
992
  /**
857
- * Read visible tool schemas from the public tools.schemas(agent) API.
858
- * Excludes run_code. Tolerates test stubs providing sdkSchemas.
993
+ * Read visible tool schemas from the public tool registry API.
994
+ * Supports 0.2.3-alpha.3+ `tools.getAll(agent)` (and `ToolStep.declarations`)
995
+ * as well as legacy `schemas` / `sdkSchemas` test stubs.
859
996
  */
860
997
  const resolveToolsService = (agent) => {
861
- const scoped = agent?.ctx?.tools
862
- if (typeof scoped?.schemas === 'function' || typeof scoped?.sdkSchemas === 'function') {
863
- return scoped
864
- }
998
+ const supportsRead = (candidate) => (
999
+ typeof candidate?.getAll === 'function'
1000
+ || typeof candidate?.schemas === 'function'
1001
+ || typeof candidate?.sdkSchemas === 'function'
1002
+ )
1003
+ const scoped = scopedToolsOf(agent)
1004
+ if (supportsRead(scoped)) return scoped
865
1005
  const reg = registry()
866
- if (typeof reg?.schemas === 'function' || typeof reg?.sdkSchemas === 'function') {
867
- return reg
868
- }
1006
+ if (supportsRead(reg)) return reg
869
1007
  return scoped ?? reg
870
1008
  }
871
1009
 
1010
+ /** Merge two schema arrays by tool name, preserving first occurrence order. */
1011
+ const mergeSchemasByName = (primary, secondary) => {
1012
+ const merged = []
1013
+ const seen = new Set()
1014
+ for (const list of [primary, secondary]) {
1015
+ for (const entry of Array.isArray(list) ? list : []) {
1016
+ const toolName = entry?.name
1017
+ if (typeof toolName !== 'string' || toolName === '' || toolName === 'run_code' || seen.has(toolName)) continue
1018
+ seen.add(toolName)
1019
+ merged.push(entry)
1020
+ }
1021
+ }
1022
+ return merged
1023
+ }
1024
+
872
1025
  /**
873
1026
  * Read the model-facing surface one scope offers this step, without the
874
1027
  * reserved transport (the catalog never lists run_code as an entry).
875
1028
  *
876
- * `toolSet` is the assemble context's step admission: passing it narrows the
877
- * read to exactly the tools this request may carry, conditionally registered
878
- * ones excluded. Omitted, the read covers every registered definition, which
879
- * is what the paging sync needs to compute its page.
1029
+ * Supports both DSH 0.2.3-alpha.3+ (`ToolStep` + `tools.getAll(agent)`) and
1030
+ * legacy `schemas(agent, toolSet)` / `sdkSchemas` stubs:
1031
+ * - Under a Native root registry, `ToolStep.declarations` or `tools.getAll(agent)`
1032
+ * returns the complete scoped tool definitions directly.
1033
+ * - Under a 0.2.3-alpha.3+ PTC root registry, `ToolStep.declarations` and
1034
+ * `tools.getAll(agent)` return only `[run_code]`:
1035
+ * - when `options.forPaging` is true, read the unscoped global view
1036
+ * (`tools.getAll()`, which uses the host Native root and holds every
1037
+ * global plugin / MCP / AgentToolRegistry tool) merged with any previously
1038
+ * parsed `tools:sdk` bindings for this agent;
1039
+ * - otherwise return `undefined` so the `system-prompt/assemble` listener
1040
+ * extracts the exact step bindings from the rendered `tools:sdk` section.
880
1041
  *
881
1042
  * An EMPTY list and an UNREADABLE registry are different facts, and the
882
1043
  * return type keeps them apart: `[]` means this scope really offers no tool,
883
- * `undefined` means nothing could be read (a deployment without the registry,
884
- * a projection that threw). A caller that treats the second as the first
885
- * announces "no tools" to a session that has them — the defect issue #2016
886
- * reports.
1044
+ * `undefined` means nothing could be read (issue #2016).
887
1045
  *
888
1046
  * @param agent - agent scope the surface is read for.
889
- * @param toolSet - the step's admitted selection, or undefined for every definition.
890
- * @param options - `quiet` suppresses the diagnostic of an unreadable registry.
891
- * @returns the visible schemas minus run_code, or undefined when unreadable.
1047
+ * @param stepAdmission - the step's `ToolStep` (0.2.3-alpha.3+) or legacy `toolSet`, or undefined.
1048
+ * @param options - `quiet` suppresses diagnostics; `forPaging` uses unscoped fallback under PTC.
1049
+ * @returns the visible schemas minus run_code, or undefined when unreadable / PTC-collapsed.
892
1050
  */
893
- const readSurface = (agent, toolSet, options) => {
1051
+ const readSurface = (agent, stepAdmission, options) => {
1052
+ // 0.2.3-alpha.3+ ToolStep carries the exact declarations captured for this step.
1053
+ if (Array.isArray(stepAdmission?.declarations)) {
1054
+ const declarations = stepAdmission.declarations
1055
+ const nonTransport = declarations.filter(entry => entry?.name && entry.name !== 'run_code')
1056
+ if (nonTransport.length > 0) return nonTransport
1057
+ if (declarations.some(entry => entry?.name === 'run_code')) {
1058
+ return options?.forPaging === true ? readUnscopedPagingSurface(agent) : undefined
1059
+ }
1060
+ return []
1061
+ }
1062
+
894
1063
  const tools = resolveToolsService(agent)
895
1064
  if (tools === undefined) return undefined
1065
+
1066
+ if (typeof tools.getAll === 'function') {
1067
+ try {
1068
+ const entries = tools.getAll(agent)
1069
+ if (Array.isArray(entries)) {
1070
+ const nonTransport = entries.filter(entry => entry?.name && entry.name !== 'run_code')
1071
+ if (nonTransport.length > 0) return nonTransport
1072
+ if (entries.some(entry => entry?.name === 'run_code')) {
1073
+ return options?.forPaging === true ? readUnscopedPagingSurface(agent, tools) : undefined
1074
+ }
1075
+ return []
1076
+ }
1077
+ } catch (err) {
1078
+ if (options?.quiet !== true) {
1079
+ warnOnce('surface', `no tool schemas available (${err instanceof Error ? err.message : String(err)}) — the catalog keeps its last published state`)
1080
+ }
1081
+ return undefined
1082
+ }
1083
+ }
1084
+
896
1085
  for (const method of ['schemas', 'sdkSchemas']) {
897
1086
  if (typeof tools[method] !== 'function') continue
898
1087
  try {
899
- const schemas = tools[method](agent, toolSet)
1088
+ const schemas = tools[method](agent, stepAdmission)
900
1089
  if (Array.isArray(schemas)) return schemas.filter(entry => entry?.name && entry.name !== 'run_code')
901
1090
  } catch (err) {
902
1091
  if (options?.quiet !== true) {
@@ -910,6 +1099,27 @@ export function apply(ctx, config) {
910
1099
  return undefined
911
1100
  }
912
1101
 
1102
+ /**
1103
+ * Read the unscoped global tool list (served by the host Native root) plus
1104
+ * any cached PTC SDK bindings for `agent`, used to compute paging restrictions
1105
+ * before `system-prompt/assemble` renders `tools:sdk`.
1106
+ */
1107
+ const readUnscopedPagingSurface = (agent, explicitTools) => {
1108
+ const tools = explicitTools ?? resolveToolsService(agent)
1109
+ let globalEntries = []
1110
+ if (typeof tools?.getAll === 'function') {
1111
+ try {
1112
+ const raw = tools.getAll()
1113
+ if (Array.isArray(raw)) globalEntries = raw
1114
+ } catch {
1115
+ globalEntries = []
1116
+ }
1117
+ }
1118
+ const cached = agent === undefined ? undefined : agentSdkSurface.get(agent)
1119
+ const merged = mergeSchemasByName(globalEntries, cached)
1120
+ return merged.length > 0 ? merged : undefined
1121
+ }
1122
+
913
1123
  // Early lifecycle hook: page the scope as soon as it exists.
914
1124
  //
915
1125
  // The 0.1.6 cohort folded the former `agent/session-start` into the async
@@ -933,6 +1143,7 @@ export function apply(ctx, config) {
933
1143
  // keyed by the agent, and a recycled key would inherit a stale filter.
934
1144
  ctx.on('agent/disposed', ({ agent }) => {
935
1145
  agentCatalogState.delete(agent)
1146
+ agentSdkSurface.delete(agent)
936
1147
  clearScopePaging(agent)
937
1148
  })
938
1149
 
@@ -972,11 +1183,10 @@ export function apply(ctx, config) {
972
1183
 
973
1184
  ctx.on('system-prompt/assemble', async (assembly, context, next) => {
974
1185
  const agent = context?.agent
975
- // The step's admitted selection, and the one fact about this request's tool
976
- // set a listener can still read: since 0.2.2 the assembly value carries no
977
- // tool array, and the providers it is built from are collected before this
978
- // waterfall runs.
979
- const toolSet = context?.toolSet
1186
+ // The step's admitted selection (`toolStep` in DSH 0.2.3-alpha.3+, legacy
1187
+ // `toolSet` in earlier cohorts), and the one fact about this request's tool
1188
+ // set a listener can still read directly.
1189
+ const stepAdmission = context?.toolStep ?? context?.toolSet
980
1190
 
981
1191
  if (agent !== undefined && agent.session !== undefined) {
982
1192
  agentBySession.set(agent.session, agent)
@@ -996,13 +1206,25 @@ export function apply(ctx, config) {
996
1206
  // are provider-owned, so there is no array here to filter or restore.
997
1207
  const assembled = await next()
998
1208
 
999
- // The catalog describes THIS request's surface, read from the registry
1000
- // through the step's admission. `schemas()` reads through the scope's
1001
- // restriction, so the result is exactly the list this request carries: the
1002
- // native roster, or - under a collapsed `ptc` wire - the projection every
1003
- // tool is reached through from inside a program (run_code is the transport,
1004
- // never a catalog entry).
1005
- const surface = agent === undefined ? undefined : readSurface(agent, toolSet)
1209
+ // The catalog describes THIS request's surface: under Native root registries
1210
+ // `readSurface()` reads `ToolStep.declarations` / `tools.getAll(agent)` directly;
1211
+ // under DSH 0.2.3-alpha.3+ PTC root registries, `tools.getAll(agent)` returns
1212
+ // only `[run_code]`, so extract the exact step-bound declarations rendered
1213
+ // into the official `tools:sdk` section by `PtcToolRegistry.renderSdk()`.
1214
+ let surface = agent === undefined ? undefined : readSurface(agent, stepAdmission)
1215
+ if (agent !== undefined && surface === undefined) {
1216
+ const sdkSection = Array.isArray(assembled?.sections)
1217
+ ? assembled.sections.find(section => section?.name === 'tools:sdk')
1218
+ : undefined
1219
+ const sdkText = typeof sdkSection?.text === 'string'
1220
+ ? sdkSection.text
1221
+ : (typeof assembled?.prompt === 'string' && assembled.prompt.includes('interface ToolArgsMap') ? assembled.prompt : undefined)
1222
+ const parsed = sdkText === undefined ? undefined : parseToolsSdkSurface(sdkText)
1223
+ if (parsed !== undefined) {
1224
+ agentSdkSurface.set(agent, parsed)
1225
+ surface = parsed
1226
+ }
1227
+ }
1006
1228
 
1007
1229
  // The presentation this request carries is the one the composition mounted.
1008
1230
  // Nothing in the assembly names it and `schemas()` reads the same roster
@@ -373,8 +373,8 @@ describe('dsh-liangshen preset parse reuse', () => {
373
373
  // And the declaration the write replaced still reports what it declared,
374
374
  // so the overlay derived a new row list instead of mutating the cached one
375
375
  expect(catalogOf(0)).toBe('ptc')
376
- expect(rowsOf(host, 0).find(row => row.id === 'tool-executor-ptc')?.disabled).toBe(false)
377
- expect(rowsOf(host, 1).find(row => row.id === 'tool-executor-ptc')?.disabled).toBe(true)
376
+ expect(rowsOf(host, 0).find(row => row.id === 'tool-registry-ptc')?.disabled).toBe(false)
377
+ expect(rowsOf(host, 1).find(row => row.id === 'tool-registry-ptc')?.disabled).toBe(true)
378
378
 
379
379
  // When the operator commits the shipped value back
380
380
  presentation = 'ptc'
@@ -10,7 +10,7 @@
10
10
  * on them, which is why every field the Host schema carries appears here.
11
11
  */
12
12
 
13
- import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
13
+ import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots/client'
14
14
  import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
15
15
  import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
16
16
  import { LiangShenMark } from './LiangShenMark.tsx'
@@ -23,7 +23,7 @@ import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
23
23
  import type {} from '@deepseek-ai/dsh-client-locale/client'
24
24
  // Type-only: pulls the ui-conversation SlotMap merge (the composer tool row).
25
25
  import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
26
- import type {} from '@deepseek-ai/dsh-client-ui-slots'
26
+ import type {} from '@deepseek-ai/dsh-client-ui-slots/client'
27
27
  import type { ConfigForm, ConfigForms } from '@deepseek-ai/dsh-client-ui-settings/client'
28
28
  // Type-only: pulls the settings-surface Context merge (ctx.configForms).
29
29
  import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
@@ -114,7 +114,7 @@ export interface SettingsPluginItemOwnerProps {
114
114
  children?: never
115
115
  }
116
116
 
117
- declare module '@deepseek-ai/dsh-client-ui-slots' {
117
+ declare module '@deepseek-ai/dsh-client-ui-slots/client' {
118
118
  interface SlotMap {
119
119
  /**
120
120
  * The child slot the Web UI plugin group declares; this card registers into
@@ -158,7 +158,7 @@ export interface LiangShenFormSpec<T> {
158
158
  */
159
159
  export const inject = ['slots', 'locale', 'sessions', 'configForms', 'remote', 'remote.agentPresets']
160
160
 
161
- declare module '@deepseek-ai/dsh-client-ui-slots' {
161
+ declare module '@deepseek-ai/dsh-client-ui-slots/client' {
162
162
  interface LocaleNamespaceMap {
163
163
  /** The LiangShen lever copy. */
164
164
  'liangshen': LiangShenKey
@@ -321,10 +321,10 @@ describe('applyPresetOverrides', () => {
321
321
  // a presentation, Then the catalog and the executor select the same mode.
322
322
  const ptc = applyPresetOverrides(rows(), { presentation: 'ptc' })
323
323
  expect(configOf(rowOf(ptc, 'tool-catalog'))['presentation']).toBe('ptc')
324
- expect(rowOf(ptc, 'tool-executor-ptc').disabled).toBe(false)
324
+ expect(rowOf(ptc, 'tool-registry-ptc').disabled).toBe(false)
325
325
  const native = applyPresetOverrides(rows(), { presentation: 'native' })
326
326
  expect(configOf(rowOf(native, 'tool-catalog'))['presentation']).toBe('native')
327
- expect(rowOf(native, 'tool-executor-ptc').disabled).toBe(true)
327
+ expect(rowOf(native, 'tool-registry-ptc').disabled).toBe(true)
328
328
  expect(rowOf(native, 'tool-catalog').disabled).toBeUndefined()
329
329
  })
330
330
 
@@ -587,7 +587,7 @@ export function applyPresetOverrides(
587
587
  const table = overrideTargets(overrides)
588
588
  return rows.map((row) => {
589
589
  const id = (row as CompositionRow).id
590
- if (id === 'tool-executor-ptc' && overrides.presentation !== undefined) {
590
+ if ((id === 'tool-registry-ptc' || id === 'tool-executor-ptc') && overrides.presentation !== undefined) {
591
591
  return { ...row, disabled: overrides.presentation !== 'ptc' }
592
592
  }
593
593
  const target = table.find(([targetId]) => targetId === id)
package/src/dsh-home.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  // Generated by scripts/sync-shared.mjs from shared/host/dsh-home.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
2
  /**
3
- * DSH_HOME resolution shared by the plugin family's Host halves: the
4
- * environment override wins, the platform home fallback follows. Mirrors
5
- * what dsh-pet and dsh-liangshen each used to implement locally.
3
+ * DSH_HOME and DSH_AGENTS_HOME resolution shared by the plugin family's Host
4
+ * halves: environment overrides win (blank values treated as unset), then the
5
+ * platform home fallbacks follow — mirroring `@deepseek-ai/dsh-home-paths`.
6
6
  */
7
7
 
8
8
  import { homedir } from 'node:os'
@@ -18,6 +18,21 @@ export function expandHome(path: string, home: string = homedir()): string {
18
18
  return path
19
19
  }
20
20
 
21
+ function resolveUserRoot(
22
+ envValue: string | undefined,
23
+ defaultDirName: string,
24
+ home: string,
25
+ ): string {
26
+ const isPosix = home.startsWith('/')
27
+ const j = isPosix ? posixJoin : join
28
+ const isAbs = isPosix ? posixIsAbsolute : isAbsolute
29
+ if (envValue !== undefined && envValue.trim() !== '') {
30
+ const expanded = expandHome(envValue.trim(), home)
31
+ return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
32
+ }
33
+ return j(home, defaultDirName)
34
+ }
35
+
21
36
  /**
22
37
  * Resolve the DSH home directory.
23
38
  * @param env - process environment to read DSH_HOME from.
@@ -25,18 +40,26 @@ export function expandHome(path: string, home: string = homedir()): string {
25
40
  * @returns the absolute DSH home path.
26
41
  */
27
42
  export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
28
- const isPosix = home.startsWith('/')
29
- const j = isPosix ? posixJoin : join
30
- const isAbs = isPosix ? posixIsAbsolute : isAbsolute
31
- const raw = env.DSH_HOME
32
- if (raw !== undefined && raw.trim() !== '') {
33
- const expanded = expandHome(raw.trim(), home)
34
- return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
35
- }
36
- return j(home, '.dsh')
43
+ return resolveUserRoot(env.DSH_HOME, '.dsh', home)
37
44
  }
38
45
 
39
46
  /** Resolve the DSH home directory from the live environment. */
40
47
  export function dshHome(): string {
41
48
  return resolveDshHome()
42
49
  }
50
+
51
+ /**
52
+ * Resolve the shared agent configuration root (`$DSH_AGENTS_HOME`, defaulting
53
+ * to `<home>/.agents`), matching `@deepseek-ai/dsh-home-paths`'s `resolveAgentsHome`.
54
+ * @param env - process environment to read DSH_AGENTS_HOME from.
55
+ * @param home - platform home directory fallback (test seam).
56
+ * @returns the absolute shared agents home path.
57
+ */
58
+ export function resolveAgentsHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
59
+ return resolveUserRoot(env.DSH_AGENTS_HOME, '.agents', home)
60
+ }
61
+
62
+ /** Resolve the shared agent configuration root from the live environment. */
63
+ export function agentsHome(): string {
64
+ return resolveAgentsHome()
65
+ }