@dsmm/dsmm 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/README.md +38 -66
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +10 -2015
  3. package/agent-presets/dsmm-clarifier/agent.cordis.yml +24 -343
  4. package/agent-presets/dsmm-code-search/agent.cordis.yml +19 -6
  5. package/agent-presets/dsmm-coding/agent.cordis.yml +19 -438
  6. package/agent-presets/dsmm-complex/agent.cordis.yml +23 -1009
  7. package/agent-presets/dsmm-creative/agent.cordis.yml +25 -442
  8. package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +29 -1013
  9. package/agent-presets/dsmm-deep/agent.cordis.yml +24 -1008
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +19 -6
  11. package/agent-presets/dsmm-documenting/agent.cordis.yml +26 -439
  12. package/agent-presets/dsmm-frontend/agent.cordis.yml +21 -440
  13. package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +22 -441
  14. package/agent-presets/dsmm-media-reader/agent.cordis.yml +19 -6
  15. package/agent-presets/dsmm-normal-task/agent.cordis.yml +19 -438
  16. package/agent-presets/dsmm-oracle/agent.cordis.yml +25 -340
  17. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +25 -340
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +29 -2025
  19. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +24 -341
  20. package/agent-presets/dsmm-planner/agent.cordis.yml +14 -344
  21. package/agent-presets/dsmm-quick/agent.cordis.yml +19 -6
  22. package/agent-presets/dsmm-research/agent.cordis.yml +23 -8
  23. package/agent-presets/dsmm-reviewer/agent.cordis.yml +25 -340
  24. package/docs/agent-presets.md +36 -52
  25. package/docs/compatibility.md +50 -108
  26. package/docs/deferred-native-approval-risk.md +19 -0
  27. package/docs/design.md +2 -2
  28. package/docs/lsp.md +11 -21
  29. package/docs/migration-from-ocmm.md +2 -2
  30. package/docs/model-routing.md +84 -59
  31. package/docs/native-permissions.md +35 -0
  32. package/docs/profiles.md +40 -87
  33. package/docs/releasing.md +83 -2
  34. package/docs/roadmap.md +71 -17
  35. package/docs/settings-status.md +34 -169
  36. package/docs/skill-sync.md +52 -15
  37. package/lib/child-admission-contract.d.ts +37 -0
  38. package/lib/child-admission-contract.js +2 -0
  39. package/lib/child-admission.d.ts +42 -0
  40. package/lib/child-admission.js +162 -0
  41. package/lib/child-capture.d.ts +81 -0
  42. package/lib/child-capture.js +203 -0
  43. package/lib/child-evidence.d.ts +17 -0
  44. package/lib/child-evidence.js +43 -0
  45. package/lib/client/ChildrenPanel.d.ts +43 -0
  46. package/lib/client/ChildrenPanel.js +82 -0
  47. package/lib/client/DeploymentPage.js +15 -8
  48. package/lib/client/EditableChoice.d.ts +17 -0
  49. package/lib/client/EditableChoice.js +49 -0
  50. package/lib/client/PermissionsPanel.d.ts +14 -0
  51. package/lib/client/PermissionsPanel.js +46 -0
  52. package/lib/client/ProfilesSection.js +30 -15
  53. package/lib/client/RoleAvailability.d.ts +7 -0
  54. package/lib/client/RoleAvailability.js +19 -0
  55. package/lib/client/SessionProfiles.js +27 -9
  56. package/lib/client/StructuredEditor.js +15 -7
  57. package/lib/client/children-controller.d.ts +98 -0
  58. package/lib/client/children-controller.js +296 -0
  59. package/lib/client/children-locales.d.ts +367 -0
  60. package/lib/client/children-locales.js +69 -0
  61. package/lib/client/controller.d.ts +6 -1
  62. package/lib/client/controller.js +14 -8
  63. package/lib/client/deployment-data.d.ts +2 -1
  64. package/lib/client/deployment-data.js +34 -5
  65. package/lib/client/deployment-locales.d.ts +4 -0
  66. package/lib/client/deployment-locales.js +11 -2
  67. package/lib/client/diagnostics.d.ts +14 -0
  68. package/lib/client/diagnostics.js +53 -0
  69. package/lib/client/index.d.ts +4 -0
  70. package/lib/client/index.js +96 -2
  71. package/lib/client/locales.d.ts +54 -0
  72. package/lib/client/locales.js +34 -16
  73. package/lib/client/permission-client.d.ts +16 -0
  74. package/lib/client/permission-client.js +38 -0
  75. package/lib/client/permission-controller.d.ts +62 -0
  76. package/lib/client/permission-controller.js +149 -0
  77. package/lib/client/permission-locales.d.ts +114 -0
  78. package/lib/client/permission-locales.js +75 -0
  79. package/lib/client/session-labels.js +4 -4
  80. package/lib/client/structured.js +19 -5
  81. package/lib/client/styles.d.ts +1 -1
  82. package/lib/client/styles.js +20 -0
  83. package/lib/client.js +5780 -1679
  84. package/lib/core-permission-authority.d.ts +18 -0
  85. package/lib/core-permission-authority.js +255 -0
  86. package/lib/core-permissions.d.ts +8 -0
  87. package/lib/core-permissions.js +33 -0
  88. package/lib/delivery-authority.d.ts +68 -0
  89. package/lib/delivery-authority.js +260 -0
  90. package/lib/deployment-config.d.ts +23 -0
  91. package/lib/deployment-config.js +61 -40
  92. package/lib/deployment-permission-rules.d.ts +55 -0
  93. package/lib/deployment-permission-rules.js +306 -0
  94. package/lib/dsh-types.d.ts +10 -4
  95. package/lib/guards.d.ts +1 -1
  96. package/lib/guards.js +29 -8
  97. package/lib/host-llm-startup.d.ts +41 -0
  98. package/lib/host-llm-startup.js +65 -0
  99. package/lib/host-llm.d.ts +92 -0
  100. package/lib/host-llm.js +325 -0
  101. package/lib/index.d.ts +15 -4
  102. package/lib/index.js +300 -47
  103. package/lib/legacy-child-policy.d.ts +51 -0
  104. package/lib/legacy-child-policy.js +123 -0
  105. package/lib/legacy-read-composition.d.ts +20 -0
  106. package/lib/legacy-read-composition.js +144 -0
  107. package/lib/legacy-read-contracts.d.ts +157 -0
  108. package/lib/legacy-read-contracts.js +39 -0
  109. package/lib/legacy-read-host.d.ts +19 -0
  110. package/lib/legacy-read-host.js +67 -0
  111. package/lib/legacy-read-integration.d.ts +121 -0
  112. package/lib/legacy-read-integration.js +522 -0
  113. package/lib/legacy-read-proxy.d.ts +26 -0
  114. package/lib/legacy-read-proxy.js +237 -0
  115. package/lib/live-pi-ai-owner.d.ts +18 -0
  116. package/lib/live-pi-ai-owner.js +144 -0
  117. package/lib/llm-runtime.d.ts +11 -0
  118. package/lib/llm-runtime.js +21 -0
  119. package/lib/managed-settings.d.ts +5 -0
  120. package/lib/managed-settings.js +14 -0
  121. package/lib/model-parameter-policy.d.ts +11 -0
  122. package/lib/model-parameter-policy.js +27 -0
  123. package/lib/model-routing.js +28 -17
  124. package/lib/modules.d.ts +13 -5
  125. package/lib/modules.js +17 -1
  126. package/lib/native-child-evidence.d.ts +42 -0
  127. package/lib/native-child-evidence.js +133 -0
  128. package/lib/native-pi-ai-wire.d.ts +37 -0
  129. package/lib/native-pi-ai-wire.js +261 -0
  130. package/lib/native-scope.js +1 -1
  131. package/lib/permission-bash.d.ts +6 -0
  132. package/lib/permission-bash.js +7 -0
  133. package/lib/permission-control.d.ts +73 -0
  134. package/lib/permission-control.js +205 -0
  135. package/lib/permission-controller.d.ts +68 -0
  136. package/lib/permission-controller.js +317 -0
  137. package/lib/permission-errors.d.ts +7 -0
  138. package/lib/permission-errors.js +21 -0
  139. package/lib/permission-fs-search.d.ts +5 -0
  140. package/lib/permission-fs-search.js +7 -0
  141. package/lib/permission-fs.d.ts +5 -0
  142. package/lib/permission-fs.js +7 -0
  143. package/lib/permission-native-access.d.ts +11 -0
  144. package/lib/permission-native-access.js +6 -0
  145. package/lib/permission-native-command.d.ts +10 -0
  146. package/lib/permission-native-command.js +93 -0
  147. package/lib/permission-native-rules.d.ts +75 -0
  148. package/lib/permission-native-rules.js +278 -0
  149. package/lib/permission-pwsh.d.ts +6 -0
  150. package/lib/permission-pwsh.js +7 -0
  151. package/lib/permission-remote.d.ts +26 -0
  152. package/lib/permission-remote.js +53 -0
  153. package/lib/permission-rpc.d.ts +29 -0
  154. package/lib/permission-rpc.js +152 -0
  155. package/lib/permission-rules.d.ts +115 -0
  156. package/lib/permission-rules.js +256 -0
  157. package/lib/permission-settings.d.ts +45 -0
  158. package/lib/permission-settings.js +48 -0
  159. package/lib/permission-shell.d.ts +38 -0
  160. package/lib/permission-shell.js +150 -0
  161. package/lib/permission-web.d.ts +5 -0
  162. package/lib/permission-web.js +7 -0
  163. package/lib/preset-registry.js +36 -25
  164. package/lib/profile-diagnostics.d.ts +45 -0
  165. package/lib/profile-diagnostics.js +148 -0
  166. package/lib/profile-locale.d.ts +3 -0
  167. package/lib/profile-locale.js +2 -0
  168. package/lib/profile-remote.d.ts +8 -0
  169. package/lib/profile-remote.js +163 -39
  170. package/lib/profile-rpc.d.ts +4 -3
  171. package/lib/profile-rpc.js +14 -12
  172. package/lib/profile-runtime.d.ts +40 -1
  173. package/lib/profile-runtime.js +368 -93
  174. package/lib/profile-store.d.ts +11 -0
  175. package/lib/profile-store.js +143 -11
  176. package/lib/profile-types.d.ts +70 -1
  177. package/lib/profile-types.js +1 -0
  178. package/lib/profiles.d.ts +16 -2
  179. package/lib/profiles.js +156 -79
  180. package/lib/prompt-content.js +1 -1
  181. package/lib/prompts.d.ts +37 -2
  182. package/lib/prompts.js +111 -9
  183. package/lib/recovery-policy.js +20 -7
  184. package/lib/role-control-remote.d.ts +38 -0
  185. package/lib/role-control-remote.js +211 -0
  186. package/lib/role-control-rpc.d.ts +51 -0
  187. package/lib/role-control-rpc.js +377 -0
  188. package/lib/role-control-types.d.ts +92 -0
  189. package/lib/role-control-types.js +8 -0
  190. package/lib/role-invocation.d.ts +47 -0
  191. package/lib/role-invocation.js +135 -0
  192. package/lib/role-llm-runtime.d.ts +17 -0
  193. package/lib/role-llm-runtime.js +62 -0
  194. package/lib/role-llm.d.ts +31 -0
  195. package/lib/role-llm.js +66 -0
  196. package/lib/role-policy.d.ts +49 -8
  197. package/lib/role-policy.js +437 -60
  198. package/lib/role-providers.d.ts +1 -1
  199. package/lib/role-providers.js +30 -35
  200. package/lib/role-routing.d.ts +11 -2
  201. package/lib/role-routing.js +42 -25
  202. package/lib/role-runs.d.ts +135 -0
  203. package/lib/role-runs.js +304 -0
  204. package/lib/role-subagents.d.ts +58 -3
  205. package/lib/role-subagents.js +169 -56
  206. package/lib/roles.d.ts +5 -6
  207. package/lib/roles.js +10 -39
  208. package/lib/route-json.d.ts +19 -0
  209. package/lib/route-json.js +129 -0
  210. package/lib/routing-policy.d.ts +2 -0
  211. package/lib/routing-policy.js +12 -2
  212. package/lib/runtime-integration.d.ts +112 -0
  213. package/lib/runtime-integration.js +784 -0
  214. package/lib/runtime-recovery.js +18 -8
  215. package/lib/settings.d.ts +47 -13
  216. package/lib/settings.js +217 -82
  217. package/lib/skills.js +2 -2
  218. package/lib/status.d.ts +10 -1
  219. package/lib/status.js +11 -8
  220. package/lib/subagent-runtime.d.ts +45 -0
  221. package/lib/subagent-runtime.js +131 -0
  222. package/package.json +106 -56
  223. package/patches/subagent-runtime.yml +15 -0
  224. package/prompts/deepseek-flash.md +1 -1
  225. package/prompts/deepseek-v4-pro.md +2 -2
  226. package/prompts/deepwork.md +27 -18
  227. package/prompts/source/agents/clarifier.md +5 -3
  228. package/prompts/source/agents/orchestrator.md +18 -9
  229. package/prompts/source/agents/plan-critic.md +5 -1
  230. package/prompts/source/agents/planner.md +4 -2
  231. package/prompts/source/agents/reviewer.md +6 -0
  232. package/prompts/source/category/complex.md +4 -4
  233. package/prompts/source/category/creative.md +6 -4
  234. package/prompts/source/category/cross-cutting.md +10 -8
  235. package/prompts/source/category/deep.md +5 -3
  236. package/prompts/source/category/documenting.md +7 -1
  237. package/prompts/source/category/frontend.md +2 -2
  238. package/prompts/source/category/hard-reasoning.md +3 -3
  239. package/prompts/source/category/research.md +4 -2
  240. package/prompts/source/deepwork/claude-opus-5.md +2 -2
  241. package/prompts/source/deepwork/codex.md +1 -1
  242. package/prompts/source/deepwork/default.md +22 -15
  243. package/prompts/source/deepwork/gemini.md +23 -16
  244. package/prompts/source/deepwork/glm.md +21 -14
  245. package/prompts/source/deepwork/gpt.md +12 -6
  246. package/prompts/source/deepwork/planner.md +8 -5
  247. package/prompts/source/manifest.json +178 -63
  248. package/prompts/source/shared/dsh-host-contract.md +5 -3
  249. package/prompts/source/shared/locale.md +2 -2
  250. package/prompts/source/terminal/orchestrator.md +1 -1
  251. package/scripts/cold-profile-composition.mjs +329 -0
  252. package/scripts/cold-profile-sources.mjs +238 -0
  253. package/scripts/migrate-cold-profile.mjs +315 -0
  254. package/skills/ast-grep/SKILL.md +7 -4
  255. package/skills/brainstorming/SKILL.md +43 -22
  256. package/skills/coding-agent-sessions/SKILL.md +7 -4
  257. package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -46
  258. package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -130
  259. package/skills/debugging/SKILL.md +14 -9
  260. package/skills/debugging/references/methodology/00-setup.md +14 -62
  261. package/skills/debugging/references/methodology/02-investigate.md +4 -4
  262. package/skills/debugging/references/methodology/03-flaky-triage.md +3 -3
  263. package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +2 -14
  264. package/skills/debugging/references/methodology/06-fix.md +6 -6
  265. package/skills/debugging/references/methodology/08-qa.md +5 -5
  266. package/skills/debugging/references/methodology/09-cleanup.md +15 -153
  267. package/skills/debugging/references/methodology/partial-runtime-evidence.md +3 -16
  268. package/skills/debugging/references/runtimes/bundled-js-binary.md +1 -16
  269. package/skills/debugging/references/runtimes/native-binary.md +9 -54
  270. package/skills/debugging/references/runtimes/node.md +4 -15
  271. package/skills/debugging/references/runtimes/python.md +3 -15
  272. package/skills/debugging/references/runtimes/rust.md +2 -18
  273. package/skills/debugging/references/tools/dap.md +1 -1
  274. package/skills/debugging/references/tools/ghidra.md +4 -15
  275. package/skills/debugging/references/tools/playwright-cli.md +3 -15
  276. package/skills/debugging/references/tools/pwntools.md +4 -16
  277. package/skills/dispatching-parallel-agents/SKILL.md +18 -16
  278. package/skills/frontend/SKILL.md +7 -4
  279. package/skills/frontend/references/design/react-dev-tooling-skill.md +1 -1
  280. package/skills/git-master/SKILL.md +7 -4
  281. package/skills/init-deep/SKILL.md +7 -4
  282. package/skills/receiving-code-review/SKILL.md +17 -12
  283. package/skills/remove-ai-slops/SKILL.md +39 -38
  284. package/skills/requesting-code-review/SKILL.md +19 -17
  285. package/skills/requesting-code-review/code-reviewer.md +13 -1
  286. package/skills/subagent-driven-development/SKILL.md +29 -26
  287. package/skills/subagent-driven-development/implementer-prompt.md +29 -11
  288. package/skills/subagent-driven-development/spec-reviewer-prompt.md +6 -1
  289. package/skills/using-git-worktrees/SKILL.md +7 -4
  290. package/skills/writing-plans/SKILL.md +29 -24
  291. package/skills/writing-plans/plan-document-reviewer-prompt.md +10 -1
@@ -2,15 +2,21 @@ import { getTraceable, symbols } from "@deepseek-ai/cordis";
2
2
  import { createRequire } from "node:module";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import { defineTool } from "@deepseek-ai/dsh-tools";
5
- import { settleRun, SubagentError } from "@deepseek-ai/dsh-subagent";
5
+ import { SubagentError } from "@deepseek-ai/dsh-subagent";
6
6
  import { DSMM_ROLES } from "./roles.js";
7
+ import { isDsmmRoleId } from "./roles.js";
7
8
  import { DsmmRolePolicy, roleToolName } from "./role-policy.js";
8
- import { roleProviderName, roleAgentOptions } from "./role-providers.js";
9
+ import { roleProviderName } from "./role-providers.js";
10
+ import { capturedOriginalRoleInvocation, duringRoleInvocation, invocationAgentOptions, invocationView, resolveRoleInvocation } from "./role-invocation.js";
11
+ import { childOwnedSessionEvents } from "./session-scope.js";
9
12
  import { agentForScope, nativeAgentContext, scopeParentOf } from "./native-scope.js";
13
+ import { roleRouteRuntimeState } from "./role-routing.js";
14
+ import { modelRouteFromCall } from "./role-llm.js";
10
15
  const hostControls = ["send_message", "interrupt_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"];
11
16
  // Agent-owned policy realms survive a bundle reinstall; do not register another
12
17
  // identity prompt/tools layer on the same retained live Agent.
13
18
  const admittedRealms = new WeakSet();
19
+ const callableDefinitions = new WeakMap();
14
20
  /** Keep native controls on the frozen startup substrate, not desired-save reconciliation. */
15
21
  export async function registerNativeSubagentControls(ctx) {
16
22
  const tools = ctx.get("tools");
@@ -29,86 +35,192 @@ export async function registerNativeSubagentControls(ctx) {
29
35
  ctx.logger.warn("DSMM native subagent controls unavailable; continuable control requires the installed host substrate");
30
36
  }
31
37
  }
32
- async function foreground(run) {
33
- const [execution] = await Promise.allSettled([run.result.then((result) => {
34
- if (result.stopReason !== "completed") {
35
- const partial = result.output.filter((block) => block.type === "text").map((block) => block.text).join("");
36
- throw new SubagentError(`subagent ${result.stopReason}${result.diagnostic === undefined ? "" : `: ${result.diagnostic}`}${partial === "" ? "" : `\nPartial output: ${partial}`}`, result.stopReason.toUpperCase());
37
- }
38
- // Native results are borrowed readonly JSON; the tool runtime owns lossless
39
- // materialization, so do not duplicate blocks to erase readonly typing.
40
- return { kind: "foreground", runId: run.id, output: result.output };
41
- })]);
42
- const [disposal] = await Promise.allSettled([run.dispose()]);
43
- if (execution.status === "rejected") {
44
- if (disposal.status === "rejected")
45
- throw new AggregateError([execution.reason, disposal.reason], "DSMM subagent result and disposal failed");
46
- throw execution.reason;
38
+ /** C's same-run holder/live projection can read the actual lock without reapplying defaults. */
39
+ export function roleInvocationView(invocation, label, mode, getSettings, child, ids = {}) {
40
+ return roleInvocationObservation(invocation, label, mode, getSettings, child, ids).view;
41
+ }
42
+ /** Initial preflight/lock is not an observed SDK request; keep E's distinction truthful. */
43
+ export function roleInvocationObservation(invocation, label, mode, getSettings, child, ids = {}) {
44
+ const view = invocationView(invocation, label, mode, ids);
45
+ if (child === undefined)
46
+ return { view, routeKind: "initial" };
47
+ const actual = latestOwnRoleRoute(child);
48
+ if (actual.status === "known")
49
+ return { view: { ...view, route: actual.route }, routeKind: "actual" };
50
+ const route = roleRouteRuntimeState(child, getSettings(child), invocation.target, getSettings.admission?.(child).epoch).route;
51
+ return { view: route === undefined ? view : { ...view, route: { ...route } }, routeKind: "initial" };
52
+ }
53
+ function latestOwnRoleRoute(child) {
54
+ const own = childOwnedSessionEvents(child.session);
55
+ for (let index = own.length - 1; index >= 0; index--) {
56
+ const event = own[index];
57
+ if (event.type !== "request/header")
58
+ continue;
59
+ const config = event.data?.header?.config;
60
+ if (typeof config?.provider !== "string" || typeof config.model !== "string"
61
+ || config.reasoningEffort !== undefined && typeof config.reasoningEffort !== "string") {
62
+ return { status: "unknown", reason: "invalid-own-request-header" };
63
+ }
64
+ try {
65
+ return { status: "known", source: "own-native-request-header", route: Object.freeze(modelRouteFromCall({ ...config, provider: config.provider, model: config.model })) };
66
+ }
67
+ catch {
68
+ return { status: "unknown", reason: "invalid-own-request-header" };
69
+ }
47
70
  }
48
- if (disposal.status === "rejected")
49
- throw disposal.reason;
50
- return execution.value;
71
+ return { status: "unknown", reason: "no-own-request-header" };
72
+ }
73
+ /** Both observations belong to this exact native Agent; no parent/settings/route-lock fallback. */
74
+ export function roleRouteComparison(child) {
75
+ const agent = child;
76
+ const invocation = capturedOriginalRoleInvocation(agent);
77
+ return { childId: child.id, initialRoute: invocation === undefined ? { status: "unknown", reason: "missing-invocation-capture" }
78
+ : { status: "known", source: "invocation-capture", route: Object.freeze({ ...invocation.initialRoute }) }, liveRoute: latestOwnRoleRoute(agent) };
51
79
  }
52
- function registerRoleTool(agent, agentCtx, tools, role, getSettings, policy) {
80
+ /** Shared by runtime registration and the prompt assembler; empty groups have no callable entry. */
81
+ export function callableRoleInventory(settings, targets) {
82
+ const admitted = targets.filter(id => id !== "dsmm-orchestrator" && settings.roles[id]);
83
+ const roleTargets = admitted.filter(id => DSMM_ROLES.find(row => row.id === id)?.kind === "role");
84
+ const categories = admitted.filter(id => DSMM_ROLES.find(row => row.id === id)?.kind === "category");
85
+ return [
86
+ ...settings.subagents.toolTopology === "per-role" ? roleTargets.map(id => ({ name: roleToolName(id), kind: "role", targets: [id] }))
87
+ : roleTargets.length === 0 ? [] : [{ name: "dsmm_role", kind: "role", targets: roleTargets, targetParameter: "role" }],
88
+ ...categories.length === 0 ? [] : [{ name: "dsmm_category", kind: "category", targets: categories, targetParameter: "category" }]
89
+ ];
90
+ }
91
+ /** Exact currently exposed definitions, suitable for E's runtime guidance and safe capability views. */
92
+ export function admittedCallableRoleInventory(agent, settings, policy, tools) {
93
+ const allowed = new Set(policy.targets(agent)), providers = nativeAgentContext(agent).get("subagents");
94
+ return tools.schemas(agent).flatMap(schema => {
95
+ const definition = tools.get(schema.name, agent), registered = definition === undefined ? undefined : callableDefinitions.get(definition);
96
+ if (registered === undefined || policy.toolDenial(agent, schema.name, tools) !== undefined)
97
+ return [];
98
+ const targets = registered.entry.targets.filter(target => allowed.has(target) && settings.roles[target]
99
+ && providers?.getProvider(roleProviderName(target)) === registered.providers.get(target)
100
+ && providers?.getProvider(roleProviderName(target))?.capabilities.depthLimit === true);
101
+ return targets.length === 0 ? [] : [{ ...registered.entry, targets }];
102
+ });
103
+ }
104
+ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, roleRuns) {
53
105
  const settings = getSettings(agent);
54
106
  const subagents = agentCtx.get("subagents");
55
107
  if (subagents === undefined)
56
108
  throw new Error("DSMM role tools require native subagents");
57
109
  const background = settings.subagents.enableRunInBackground;
58
110
  const continuable = settings.subagents.backgroundMode === "continuable";
59
- return tools.register(defineTool({
60
- name: roleToolName(role.id), description: `Delegate a bounded ${role.name} task through the native runtime. ${background ? continuable ? "Background continuable is opt-in here; returns a durable child id for native send_message/interrupt_agent. Set run_in_background false to wait." : "Waits by default; explicit background work is owned by native jobs." : "Waits for the child's useful result. Background execution is disabled."}`,
111
+ const admittedProviders = new Map(entry.targets.map(target => [target, subagents.getProvider(roleProviderName(target))]));
112
+ const definition = defineTool({
113
+ name: entry.name, description: `Delegate a bounded ${entry.kind} task through the native runtime. ${background ? continuable ? "Background continuable is opt-in here; returns a durable child id for native send_message/interrupt_agent. Set run_in_background false to wait." : "Waits by default; explicit background work is owned by native jobs." : "Waits for the child's useful result. Background execution is disabled."}`,
61
114
  parameters: { description: { type: "string", required: true }, prompt: { type: "string", required: true },
115
+ ...(entry.targetParameter === undefined ? {} : { [entry.targetParameter]: { type: "string", enum: entry.targets, required: true } }),
116
+ level: { type: "string", enum: ["normal", "low", "high", "max"] },
117
+ ...(settings.subagents.allowRouteOverride ? { route: { oneOf: [
118
+ { type: "object", additionalProperties: false, properties: { reasoningEffort: { type: "string", required: true } } },
119
+ { type: "object", additionalProperties: true, properties: { provider: { type: "string", required: true }, model: { type: "string", required: true }, reasoningEffort: { type: "string" } } }
120
+ ] } } : {}),
62
121
  ...(background ? { run_in_background: { type: "boolean" } } : {}) },
63
122
  output: { schema: { type: "json" }, render(_args, value) {
64
123
  const result = value;
65
- return [{ type: "text", text: result.kind === "continuable" ? `started subagent ${result.subagentId}` : result.kind === "background" ? `started background subagent job ${result.jobId}` : result.output?.filter((block) => block.type === "text").map((block) => block.text).join("") ?? "" }];
66
- } },
124
+ const invocation = result.invocation;
125
+ const route = invocation?.route;
126
+ const metadata = invocation === undefined ? "" : `${invocation.role} level=${invocation.level}${route === undefined ? "" : ` route=${route.provider}/${route.model}${route.reasoningEffort === undefined ? "" : ` effort=${route.reasoningEffort}`}`}`;
127
+ return result.kind === "foreground" ? [{ type: "text", text: metadata }, ...result.output ?? []]
128
+ : [{ type: "text", text: `${metadata}\n${result.kind === "continuable" ? `started subagent ${result.subagentId}` : `started background subagent job ${result.jobId}`}` }];
129
+ }, presentationMeta(_args, value) { return typeof value === "object" && value !== null && !Array.isArray(value) ? value.invocation ?? null : null; } },
67
130
  async execute(args, exec) {
68
- const fields = background ? ["description", "prompt", "run_in_background"] : ["description", "prompt"];
131
+ const fields = ["description", "prompt", "level", ...entry.targetParameter === undefined ? [] : [entry.targetParameter],
132
+ ...settings.subagents.allowRouteOverride ? ["route"] : [], ...background ? ["run_in_background"] : []];
69
133
  if (Object.keys(exec.arguments).some((key) => !fields.includes(key)))
70
134
  throw new SubagentError("DSMM delegation parameter is unsupported by this admitted tool", "UNSUPPORTED_CAPABILITY");
71
135
  const parent = exec.agent;
72
136
  if (parent === undefined)
73
137
  throw new SubagentError("DSMM delegation requires a calling Agent", "UNAUTHORIZED");
138
+ if (parent !== agent || tools.get(entry.name, parent) === undefined || policy.toolDenial(agent, entry.name, tools) !== undefined)
139
+ throw new SubagentError("DSMM tool is not the exact admitted caller definition", "UNAUTHORIZED");
140
+ const target = entry.targetParameter === undefined ? entry.targets[0] : exec.arguments[entry.targetParameter];
141
+ if (!isDsmmRoleId(target) || !entry.targets.includes(target) || DSMM_ROLES.find(row => row.id === target).kind !== entry.kind)
142
+ throw new SubagentError("DSMM target is unknown, cross-kind or not admitted", "UNAUTHORIZED");
143
+ const role = DSMM_ROLES.find(row => row.id === target);
74
144
  const admitted = policy.assertDelegation(parent, role.id);
75
145
  const current = getSettings(parent);
76
146
  const provider = subagents.getProvider(roleProviderName(role.id));
77
- if (provider === undefined)
78
- throw new SubagentError("DSMM role provider is unavailable", "NO_PROVIDER");
147
+ if (provider === undefined || provider !== admittedProviders.get(role.id))
148
+ throw new SubagentError("DSMM exact admitted role provider is unavailable", "NO_PROVIDER");
149
+ const invocation = await resolveRoleInvocation(parent, role.id, current, exec.signal, { ...(args.level === undefined ? {} : { level: args.level }), ...(args.route === undefined ? {} : { route: args.route }) });
150
+ const capturedProvider = provider;
79
151
  const request = { parent, label: args.description, prompt: [{ type: "text", text: args.prompt }],
80
- persona: role.persona, maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
152
+ persona: role.persona, agentOptions: invocationAgentOptions(invocation), maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
81
153
  const assertCurrent = () => {
82
154
  if (policy.assertDelegation(parent, role.id).epoch !== admitted.epoch)
83
155
  throw new SubagentError("DSMM parent admission changed before delegation", "UNAUTHORIZED");
156
+ if (subagents.getProvider(roleProviderName(role.id)) !== capturedProvider)
157
+ throw new SubagentError("DSMM exact provider changed before delegation", "NO_PROVIDER");
84
158
  };
85
159
  exec.signal.throwIfAborted();
86
- if (background && (args.run_in_background ?? continuable)) {
87
- if (continuable) {
88
- if (provider.prepareContinuable === undefined)
89
- throw new SubagentError("DSMM provider has no prepareContinuable capability", "UNSUPPORTED_CAPABILITY");
90
- const agentOptions = await roleAgentOptions(parent, role.id, current, exec.signal);
160
+ const requestedBackground = background && (args.run_in_background ?? continuable);
161
+ if (requestedBackground && continuable) {
162
+ if (provider.prepareContinuable === undefined)
163
+ throw new SubagentError("DSMM provider has no prepareContinuable capability", "UNSUPPORTED_CAPABILITY");
164
+ assertCurrent();
165
+ const child = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(parent, role.id, () => subagents.startContinuable({ provider: provider.name, label: args.description,
166
+ request, signal: exec.signal }), request.toolFilter, request.maxDepth));
167
+ return { kind: "continuable", subagentId: child.childId, invocation: { ...invocationView(invocation, args.description, "continuable", { childId: child.childId }) } };
168
+ }
169
+ assertCurrent();
170
+ if (roleRuns === undefined)
171
+ throw new SubagentError("DSMM one-shot delegation requires the stable Host role-run registry", "UNSUPPORTED_CAPABILITY");
172
+ const admission = getSettings.admission?.(agent);
173
+ if (admission === undefined || admission.epoch !== admitted.epoch)
174
+ throw new SubagentError("DSMM one-shot capture requires the exact original parent admission", "UNAUTHORIZED");
175
+ const jobs = agentCtx.get("jobs");
176
+ if (requestedBackground && jobs === undefined)
177
+ throw new SubagentError("DSMM background jobs require the native jobs registry/controller", "UNSUPPORTED_CAPABILITY");
178
+ let child;
179
+ const projection = { ...invocationView(invocation, args.description, "one-shot"), get route() {
180
+ return roleInvocationView(invocation, args.description, "one-shot", getSettings, child).route;
181
+ } };
182
+ const holder = roleRuns.registry.start({ parent, owner: roleRuns.owner, sessionId: parent.id, toolCallId: exec.callId,
183
+ admissionEpoch: admitted.epoch, capture: Object.freeze({ invocation, admission }), projection, label: args.description, callerAbort: exec.signal, jobs,
184
+ async start(signal) {
91
185
  assertCurrent();
92
- const child = await policy.duringDelegation(parent, role.id, () => subagents.startContinuable({ provider: provider.name, label: args.description,
93
- request: { ...request, ...(agentOptions === undefined ? {} : { agentOptions }) }, signal: exec.signal }), request.toolFilter);
94
- return { kind: "continuable", subagentId: child.childId };
186
+ const run = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(agent, role.id, () => subagents.start(provider.name, { ...request, signal }), request.toolFilter, request.maxDepth, agent => { child = agent; }));
187
+ projection.runId = run.id;
188
+ child ??= run.localAgent;
189
+ if (child?.id !== undefined)
190
+ projection.childId = child.id;
191
+ return run;
192
+ } });
193
+ if (requestedBackground) {
194
+ try {
195
+ const identity = await holder.ready;
196
+ const transition = holder.background({ parent, owner: roleRuns.owner, sessionId: parent.id, toolCallId: exec.callId,
197
+ runId: identity.runId, expectedAdmissionEpoch: admitted.epoch });
198
+ if (transition.status === "starting")
199
+ throw new SubagentError("DSMM ready run is not transferable", "UNAUTHORIZED");
200
+ }
201
+ catch (error) {
202
+ holder.cancel(error);
203
+ const [drain] = await Promise.allSettled([holder.drained]);
204
+ if (drain.status === "rejected" && drain.reason !== error)
205
+ throw new AggregateError([error, drain.reason], "DSMM background handoff was refused and its owned run drain rejected");
206
+ throw error;
95
207
  }
96
- const jobs = agentCtx.get("jobs");
97
- if (jobs === undefined)
98
- throw new SubagentError("DSMM background jobs require the native jobs registry/controller", "UNSUPPORTED_CAPABILITY");
99
- return { kind: "background", jobId: jobs.start({ kind: "subagent", owner: parent.id, label: args.description, run() {
100
- const cancel = new AbortController();
101
- const started = Promise.resolve().then(() => { assertCurrent(); return subagents.start(provider.name, { ...request, signal: cancel.signal }); });
102
- return { cancel(reason) { cancel.abort(reason); }, done: started.then(settleRun, (error) => ({ status: cancel.signal.aborted ? "killed" : "failed", detail: String(error) })) };
103
- } }) };
104
208
  }
105
- assertCurrent();
106
- return foreground(await subagents.start(provider.name, { ...request, signal: exec.signal }));
209
+ const held = await holder.foreground;
210
+ if (held.kind === "background")
211
+ projection.jobId = held.jobId;
212
+ const { route, ...metadata } = projection;
213
+ const view = { ...metadata, ...(route === undefined ? {} : { route: { ...route } }) };
214
+ return held.kind === "foreground" ? { kind: held.kind, runId: held.runId, output: held.output, invocation: view }
215
+ : { kind: held.kind, runId: held.invocation.runId, jobId: held.jobId, invocation: view };
107
216
  }
108
- }));
217
+ });
218
+ callableDefinitions.set(definition, { entry: Object.freeze({ ...entry, targets: Object.freeze([...entry.targets]) }), providers: admittedProviders });
219
+ const dispose = tools.register(definition);
220
+ return () => { callableDefinitions.delete(definition); dispose(); };
109
221
  }
110
222
  /** Published name retained; all native/headless Agents consume one admitted policy. */
111
- export async function registerHeadlessRoleTools(ctx, controller, getSettings, policy = new DsmmRolePolicy(ctx, getSettings, controller)) {
223
+ export async function registerHeadlessRoleTools(ctx, controller, getSettings, policy = new DsmmRolePolicy(ctx, getSettings, controller), roleRuns) {
112
224
  const states = new WeakMap();
113
225
  const reconcile = async (agent) => {
114
226
  const state = states.get(agent);
@@ -137,7 +249,7 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
137
249
  state.tools = tools;
138
250
  // rc.2 has no public filter for own-layer registrations. A native monotonic
139
251
  // guard fences their invocation and exact definition identity instead.
140
- state.guard = tools.guard((execution) => execution.agent === agent ? policy.toolDenial(agent, execution.name, tools) : undefined);
252
+ state.guard = tools.guard((execution) => execution.agent === agent ? policy.toolDenial(agent, execution.name, tools, execution) : undefined);
141
253
  const forbidden = tools.schemas(agent).map((tool) => tool.name).filter((name) => name !== "run_code" && policy.toolDenial(agent, name) !== undefined
142
254
  && tools.get(name, parentScope) === tools.get(name, agent));
143
255
  if (forbidden.length > 0)
@@ -148,11 +260,10 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
148
260
  if (definition !== undefined && tools.get(definition.name, agent) === undefined && policy.toolDenial(agent, definition.name) === undefined)
149
261
  state.owned.push(tools.register(definition));
150
262
  }
151
- for (const role of DSMM_ROLES.filter((row) => targets.includes(row.id))) {
152
- if (subagents?.getProvider(roleProviderName(role.id))?.capabilities.depthLimit === true)
153
- state.owned.push(registerRoleTool(agent, agentCtx, tools, role, getSettings, policy));
154
- }
155
- policy.captureTools(agent, tools, [...targets.map(roleToolName), ...names], !sameRealm || !sameParent);
263
+ const inventory = callableRoleInventory(settings, targets.filter(role => subagents?.getProvider(roleProviderName(role))?.capabilities.depthLimit === true));
264
+ for (const entry of inventory)
265
+ state.owned.push(registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, roleRuns));
266
+ policy.captureTools(agent, tools, [...inventory.map(entry => entry.name), ...names], !sameRealm || !sameParent);
156
267
  state.signature = signature;
157
268
  state.hostDefinitions = definitions;
158
269
  state.parentScope = parentScope;
@@ -168,7 +279,9 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
168
279
  policy.installDrain(agent);
169
280
  agentCtx.get("systemPrompt").section({ name: "dsmm:delegation-identity", order: 49, text() {
170
281
  const identity = policy.identity(agent);
171
- return identity.role === undefined ? "" : `Native admitted role: ${identity.role}; ${identity.child ? "bounded child, not stage-owner" : "root"}. Permitted child roles: ${policy.targets(agent).join(", ") || "none"}. Native same-layer registrations may remain displayed but forbidden calls are denied. Role/host permissions remain in force when common is off. Read-only plans are complete Markdown for native review and authorized coordinator persistence, never planner writes.`;
282
+ const tools = states.get(agent)?.tools;
283
+ const inventory = tools === undefined ? [] : admittedCallableRoleInventory(agent, getSettings(agent), policy, tools);
284
+ return identity.role === undefined ? "" : `Native admitted role: ${identity.role}; ${identity.child ? "bounded child, not stage-owner" : "root"}. Admitted callable delegation: ${inventory.map(entry => `${entry.name}${entry.targetParameter === undefined ? "" : ` (${entry.targetParameter}: ${entry.targets.join(", ")})`}`).join("; ") || "none"}. level defaults to normal; low/high/max require this target's configured level. route is only available with admitted deployment opt-in. Role/host permissions remain in force when common is off. Read-only plans are complete Markdown for native review and authorized coordinator persistence, never planner writes.`;
172
285
  } });
173
286
  agentCtx.effect(() => () => {
174
287
  const state = states.get(agent);
package/lib/roles.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DsmmSkillName } from "./skills.js";
2
- import type { DsmmModelRoute, DsmmRoleRouting } from "./settings.js";
2
+ import type { DsmmRoleRouting } from "./settings.js";
3
3
  export declare const DSMM_ROLE_IDS: readonly ["dsmm-orchestrator", "dsmm-planner", "dsmm-plan-critic", "dsmm-builder", "dsmm-reviewer", "dsmm-oracle", "dsmm-oracle-2nd", "dsmm-creative", "dsmm-code-search", "dsmm-doc-search", "dsmm-clarifier", "dsmm-media-reader", "dsmm-frontend", "dsmm-hard-reasoning", "dsmm-research", "dsmm-quick", "dsmm-coding", "dsmm-normal-task", "dsmm-complex", "dsmm-deep", "dsmm-documenting", "dsmm-cross-cutting"];
4
4
  export type DsmmRoleId = (typeof DSMM_ROLE_IDS)[number];
5
5
  export type DsmmRoleMode = "primary" | "all" | "subagent";
@@ -21,6 +21,8 @@ export interface DsmmRoleDefinition {
21
21
  }
22
22
  export declare const DSMM_ROLES: readonly (DsmmRoleDefinition & Required<Pick<DsmmRoleDefinition, "sourceId" | "kind" | "delegation" | "allowedChildren">>)[];
23
23
  export declare function isDsmmRoleId(value: unknown): value is DsmmRoleId;
24
+ export declare function roleProviderName(role: DsmmRoleId): string;
25
+ export declare function allowedRoleChildren(role: DsmmRoleId, child?: boolean): readonly DsmmRoleId[];
24
26
  /** Root exposure is separate from whether a role is enabled for delegation. */
25
27
  export declare function isRootRole(role: Pick<DsmmRoleDefinition, "mode">): boolean;
26
28
  /**
@@ -36,10 +38,7 @@ export interface RolePluginRow {
36
38
  isolate?: Record<string, boolean>;
37
39
  disabled?: boolean;
38
40
  }
39
- /** Native definitions and YAML share this inventory; skills is an ignored positional compatibility argument. */
40
- export declare function rolePluginRows(role: DsmmRoleDefinition, skills?: readonly DsmmSkillName[], enabledRoles?: readonly DsmmRoleId[], roleRouting?: DsmmRoleRouting): RolePluginRow[];
41
- /** DSH's spawn provider joins the parent's preset; persona/filter give each child its own role. */
42
- export declare function roleSubagentPluginRows(enabledRoles?: readonly DsmmRoleId[], roleRouting?: DsmmRoleRouting): RolePluginRow[];
43
- export declare function roleSubagentConfig(role: DsmmRoleDefinition, availableTools?: readonly string[], primary?: DsmmModelRoute): Record<string, unknown>;
41
+ /** Standing native capabilities; session routes, skills and callable delegation are admission-owned. */
42
+ export declare function rolePluginRows(role: DsmmRoleDefinition, _skills?: readonly DsmmSkillName[], _enabledRoles?: readonly DsmmRoleId[], _roleRouting?: DsmmRoleRouting): RolePluginRow[];
44
43
  export declare function renderPresetMetadata(role: DsmmRoleDefinition): string;
45
44
  //# sourceMappingURL=roles.d.ts.map
package/lib/roles.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { DSMM_SKILL_NAMES } from "./skills.js";
2
2
  import { buildRolePersona, SOURCE_ROLE_CATALOG } from "./prompt-content.js";
3
- import { roleProviderName } from "./role-providers.js";
4
- import { allowedRoleChildren } from "./role-policy.js";
5
3
  export const DSMM_ROLE_IDS = [
6
4
  "dsmm-orchestrator", "dsmm-planner", "dsmm-plan-critic", "dsmm-builder",
7
5
  "dsmm-reviewer", "dsmm-oracle", "dsmm-oracle-2nd", "dsmm-creative",
@@ -23,6 +21,11 @@ const defaultEnabledRoleIds = DSMM_ROLES.filter((role) => role.enabledByDefault)
23
21
  export function isDsmmRoleId(value) {
24
22
  return typeof value === "string" && DSMM_ROLE_IDS.includes(value);
25
23
  }
24
+ export function roleProviderName(role) { return `dsmm-role-${role.slice("dsmm-".length)}`; }
25
+ export function allowedRoleChildren(role, child = false) {
26
+ const definition = DSMM_ROLES.find(row => row.id === role);
27
+ return child && role === "dsmm-builder" ? definition.childBuilderAllowedChildren ?? [] : definition.allowedChildren;
28
+ }
26
29
  /** Root exposure is separate from whether a role is enabled for delegation. */
27
30
  export function isRootRole(role) {
28
31
  return role.mode === "primary" || role.mode === "all";
@@ -48,14 +51,14 @@ Resolve discoverable facts by inspection. Use ask_user_question only for user-ow
48
51
  Make the plan decision-complete: state the goal and success criteria; group implementation changes by subsystem; identify public API, schema, and data-flow changes; cover edge cases, failure modes, tests, acceptance criteria, and explicit assumptions. Keep it concise enough to review but detailed enough that another engineer can implement it without making design decisions.
49
52
 
50
53
  When ready, call exit_plan_mode with the complete plan markdown, starting with a # title. Make exit_plan_mode the only and final tool call in that assistant response: it presents the plan for approval, and implementation begins only in a later step after approval. Do not paste the final plan as a plain reply or ask "should I proceed?" through prose or ask_user_question. If review rejects it, incorporate the feedback and present again. If the review channel is unavailable or aborted, stay in plan mode and ask the user to switch modes manually; do not proceed with implementation.`;
51
- /** Native definitions and YAML share this inventory; skills is an ignored positional compatibility argument. */
52
- export function rolePluginRows(role, skills = DSMM_SKILL_NAMES, enabledRoles = defaultEnabledRoleIds, roleRouting = {}) {
54
+ /** Standing native capabilities; session routes, skills and callable delegation are admission-owned. */
55
+ export function rolePluginRows(role, _skills = DSMM_SKILL_NAMES, _enabledRoles = defaultEnabledRoleIds, _roleRouting = {}) {
53
56
  const rows = [
54
57
  { id: "persona", name: "@deepseek-ai/dsh-persona", config: { prefix: role.persona } },
55
58
  { id: "agent-instructions", name: "@deepseek-ai/dsh-agent-instructions", config: { maxBytes: 65536 } },
56
- { id: "tool-fs", name: "@deepseek-ai/dsh-tool-fs" },
57
- { id: "tool-fs-search", name: "@deepseek-ai/dsh-tool-fs-search", config: { sampleOverCapGlobResults: false } },
58
- { id: "tool-web", name: "@deepseek-ai/dsh-tool-web", config: { fetch: true } },
59
+ { id: "tool-fs", name: "@dsmm/dsmm/permission-fs" },
60
+ { id: "tool-fs-search", name: "@dsmm/dsmm/permission-fs-search", config: { sampleOverCapGlobResults: false } },
61
+ { id: "tool-web", name: "@dsmm/dsmm/permission-web", config: { fetch: true } },
59
62
  { id: "skill-filesystem", name: "@deepseek-ai/dsh-skill-filesystem" },
60
63
  { id: "tool-skill", name: "@deepseek-ai/dsh-tool-skill" }
61
64
  ];
@@ -81,40 +84,8 @@ export function rolePluginRows(role, skills = DSMM_SKILL_NAMES, enabledRoles = d
81
84
  if (role.id !== "dsmm-planner")
82
85
  rows.push({ id: "tool-todo", name: "@deepseek-ai/dsh-tool-todo", config: { allowParallelInProgress: true } });
83
86
  }
84
- rows.push(...roleSubagentPluginRows(enabledRoles.filter((id) => allowedRoleChildren(role.id).includes(id)), roleRouting));
85
87
  return rows;
86
88
  }
87
- /** DSH's spawn provider joins the parent's preset; persona/filter give each child its own role. */
88
- export function roleSubagentPluginRows(enabledRoles = defaultEnabledRoleIds, roleRouting = {}) {
89
- return DSMM_ROLES.filter((role) => role.id !== "dsmm-orchestrator" && enabledRoles.includes(role.id)).map((role) => ({
90
- id: `subagent-${role.id}`,
91
- name: "@deepseek-ai/dsh-tool-subagent",
92
- config: roleSubagentConfig(role, enabledRoles.map((id) => id.replace(/-/gu, "_")), roleRouting[role.id]?.primary)
93
- }));
94
- }
95
- export function roleSubagentConfig(role, availableTools = [], primary) {
96
- const readOnlyTools = ["read", "glob", "grep"];
97
- if (role.id === "dsmm-doc-search" || role.id === "dsmm-media-reader") {
98
- readOnlyTools.push("web_search", "web_fetch");
99
- }
100
- // read_image is conditional on the DSH attachment store; an unknown name
101
- // would make DSH's native toolFilter reject the child at startup.
102
- if (role.id === "dsmm-media-reader" && availableTools.includes("read_image"))
103
- readOnlyTools.push("read_image");
104
- readOnlyTools.push(...allowedRoleChildren(role.id).map((id) => id.replace(/-/gu, "_")).filter((name) => availableTools.includes(name)));
105
- return {
106
- provider: roleProviderName(role.id),
107
- ...(primary === undefined ? {} : { agentOptions: { ...primary } }),
108
- toolName: role.id.replace(/-/gu, "_"),
109
- // Selection remains host-owned; identity and monotonic execution fences are
110
- // admitted separately from this standing composition.
111
- modelSelectionSettings: false,
112
- backgroundMode: "one-shot",
113
- enableRunInBackground: false,
114
- persona: role.persona,
115
- ...(role.access === "read-only" ? { toolFilter: { allow: readOnlyTools } } : {})
116
- };
117
- }
118
89
  export function renderPresetMetadata(role) {
119
90
  return `id: ${role.id}
120
91
  name: ${quoteYamlString(role.name)}
@@ -0,0 +1,19 @@
1
+ export type RouteJson = null | boolean | number | string | RouteJson[] | {
2
+ [key: string]: RouteJson;
3
+ };
4
+ export type ModelRouteJson = {
5
+ provider: string;
6
+ model: string;
7
+ reasoningEffort?: string;
8
+ } & {
9
+ [key: string]: RouteJson;
10
+ };
11
+ export declare function validateModelRouteFieldName(key: string): void;
12
+ /** Copies only lossless JSON, without evaluating getters or accepting prototype keys. */
13
+ export declare function copyRouteJson<T>(input: T): T;
14
+ /** Sparse deployment routes validate present fields; identity is required on complete values. */
15
+ export declare function normalizeModelRouteJson(input: unknown, sparse?: boolean, allowIdentityWhitespace?: boolean): ModelRouteJson;
16
+ /** Stable complete-value identity; not a replacement for legacy capture or role-pin hashes. */
17
+ export declare function canonicalModelRouteJson(input: unknown): string;
18
+ export declare function sameModelRouteJson(left: unknown, right: unknown): boolean;
19
+ //# sourceMappingURL=route-json.d.ts.map
@@ -0,0 +1,129 @@
1
+ const MAX_ROUTE_BYTES = 128 * 1024;
2
+ const hostFields = new Set([
3
+ "provider", "model", "messages", "tools", "toolHistory", "system", "input",
4
+ "agent", "agentId", "role", "roleId", "session", "sessionId", "signal",
5
+ "permission", "permissions", "auth", "authorization", "apiKey", "apiKeyEnv", "credentials",
6
+ "headers", "endpoint", "apiEndpoint", "baseURL", "url", "fetch", "onPayload", "callbacks",
7
+ "stream", "stream_options", "tool_choice", "parallel_tool_calls", "functions", "function_call",
8
+ "timeout", "timeoutMs", "transport", "transformHeaders", "onResponse",
9
+ "context", "systemPromptUpdate", "toolUpdate", "adapterDefaults",
10
+ "readOnly", "toolFilter", "authorityCeiling", "guards", "roleRouting", "runtimePolicy", "runtimePolicyCapture",
11
+ "subagents", "allowRouteOverride", "maxDepth", "toolTopology", "profilePin", "originalAdmissionEpoch", "admissionEpoch",
12
+ "childSessionId", "parentSessionId",
13
+ ].map(parameterKey));
14
+ const aliases = [
15
+ ["reasoningEffort", "reasoning_effort"],
16
+ ["maxTokens", "max_tokens", "max_completion_tokens", "max_output_tokens"],
17
+ ];
18
+ function parameterKey(key) { return key.toLowerCase().replace(/[-_]/gu, ""); }
19
+ function fail() { throw new TypeError("Model routes must contain bounded plain JSON and valid route fields"); }
20
+ const routeFields = new Set(["provider", "model", "temperature", "stop", ...aliases.flat()]);
21
+ export function validateModelRouteFieldName(key) {
22
+ if (["__proto__", "prototype", "constructor"].includes(key))
23
+ fail();
24
+ if (routeFields.has(key))
25
+ return;
26
+ if (hostFields.has(parameterKey(key))
27
+ || [...routeFields].some(field => parameterKey(field) === parameterKey(key)))
28
+ fail();
29
+ }
30
+ /** Copies only lossless JSON, without evaluating getters or accepting prototype keys. */
31
+ export function copyRouteJson(input) {
32
+ const active = new Set();
33
+ const copy = (value, depth) => {
34
+ if (depth > 32)
35
+ fail();
36
+ if (value === null || typeof value === "boolean")
37
+ return value;
38
+ if (typeof value === "string") {
39
+ if (new TextDecoder("utf-8", { ignoreBOM: true }).decode(new TextEncoder().encode(value)) !== value)
40
+ fail();
41
+ return value;
42
+ }
43
+ if (typeof value === "number" && Number.isFinite(value) && !Object.is(value, -0))
44
+ return value;
45
+ if (typeof value !== "object" || value === null || active.has(value))
46
+ fail();
47
+ const prototype = Object.getPrototypeOf(value);
48
+ if (Array.isArray(value) ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null)
49
+ fail();
50
+ if (Object.getOwnPropertySymbols(value).length)
51
+ fail();
52
+ active.add(value);
53
+ const result = Array.isArray(value) ? [] : {};
54
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
55
+ if (Array.isArray(value) && key === "length")
56
+ continue;
57
+ if (new TextDecoder("utf-8", { ignoreBOM: true }).decode(new TextEncoder().encode(key)) !== key || ["__proto__", "prototype", "constructor"].includes(key)
58
+ || !Object.hasOwn(descriptor, "value") || !descriptor.enumerable)
59
+ fail();
60
+ if (Array.isArray(value) && !/^(0|[1-9][0-9]*)$/u.test(key))
61
+ fail();
62
+ Reflect.set(result, key, copy(descriptor.value, depth + 1));
63
+ }
64
+ if (Array.isArray(value) && Object.keys(result).length !== value.length)
65
+ fail();
66
+ active.delete(value);
67
+ return result;
68
+ };
69
+ const result = copy(input, 0);
70
+ if (new TextEncoder().encode(JSON.stringify(result)).byteLength > MAX_ROUTE_BYTES)
71
+ fail();
72
+ return result;
73
+ }
74
+ function boundedText(value, max) {
75
+ if (typeof value !== "string" || !value.trim() || value.length > max || /[\u0000-\u001f\u007f]/u.test(value))
76
+ fail();
77
+ }
78
+ /** Sparse deployment routes validate present fields; identity is required on complete values. */
79
+ export function normalizeModelRouteJson(input, sparse = false, allowIdentityWhitespace = false) {
80
+ const route = copyRouteJson(input);
81
+ if (route === null || typeof route !== "object" || Array.isArray(route))
82
+ fail();
83
+ const row = route;
84
+ if (!sparse && (!Object.hasOwn(row, "provider") || !Object.hasOwn(row, "model")))
85
+ fail();
86
+ for (const key of Object.keys(row)) {
87
+ validateModelRouteFieldName(key);
88
+ const value = row[key];
89
+ if (key === "provider") {
90
+ boundedText(value, 128);
91
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/u.test(allowIdentityWhitespace ? value.trim() : value))
92
+ fail();
93
+ }
94
+ else if (key === "model") {
95
+ boundedText(value, 512);
96
+ if (value.includes("://"))
97
+ fail();
98
+ }
99
+ else if (key === "reasoningEffort" || key === "reasoning_effort") {
100
+ boundedText(value, 64);
101
+ }
102
+ else if (key === "temperature") {
103
+ if (typeof value !== "number")
104
+ fail();
105
+ }
106
+ else if (aliases[1].includes(key)) {
107
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0)
108
+ fail();
109
+ }
110
+ else if (key === "stop") {
111
+ if (!Array.isArray(value) || !value.every(item => typeof item === "string"))
112
+ fail();
113
+ }
114
+ }
115
+ for (const group of aliases)
116
+ if (group.filter(key => Object.hasOwn(row, key)).length > 1)
117
+ fail();
118
+ return row;
119
+ }
120
+ /** Stable complete-value identity; not a replacement for legacy capture or role-pin hashes. */
121
+ export function canonicalModelRouteJson(input) {
122
+ const order = (value) => Array.isArray(value) ? value.map(order)
123
+ : value !== null && typeof value === "object" ? Object.fromEntries(Object.keys(value).sort().map(key => [key, order(value[key])])) : value;
124
+ return JSON.stringify(order(normalizeModelRouteJson(input)));
125
+ }
126
+ export function sameModelRouteJson(left, right) {
127
+ return canonicalModelRouteJson(left) === canonicalModelRouteJson(right);
128
+ }
129
+ //# sourceMappingURL=route-json.js.map
@@ -27,6 +27,8 @@ export declare function normalizeRoutingStrategy(value: unknown): DsmmRoutingStr
27
27
  export declare function normalizeRateLimitOverrides(value: unknown): Partial<DsmmRateLimitPolicy>;
28
28
  export declare function normalizeRateLimitPolicy(value?: unknown, defaults?: Readonly<DsmmRateLimitPolicy>): DsmmRateLimitPolicy;
29
29
  export declare function normalizeRuntimePolicy(value?: unknown): DsmmRuntimePolicySettings;
30
+ /** Install a preflighted invocation only on this child's immutable settings identity. */
31
+ export declare function captureRoleRuntimePolicy(settings: DsmmSettings, role: DsmmRoleId, policy: DsmmResolvedRoleRuntimePolicy): void;
30
32
  /** Resolve once per immutable settings admission; omission and explicit [] remain distinct. */
31
33
  export declare function resolveRoleRuntimePolicy(settings: DsmmSettings, role?: DsmmRoleId): DsmmResolvedRoleRuntimePolicy;
32
34
  //# sourceMappingURL=routing-policy.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { canonicalModelRouteJson } from "./route-json.js";
1
2
  export const DEFAULT_DSMM_RATE_LIMIT_POLICY = Object.freeze({
2
3
  maxRetries: 3,
3
4
  initialDelayMs: 500,
@@ -57,6 +58,15 @@ function isRecord(value) {
57
58
  return typeof value === "object" && value !== null && !Array.isArray(value);
58
59
  }
59
60
  const resolvedRoleRuntimePolicies = new WeakMap();
61
+ /** Install a preflighted invocation only on this child's immutable settings identity. */
62
+ export function captureRoleRuntimePolicy(settings, role, policy) {
63
+ let policies = resolvedRoleRuntimePolicies.get(settings);
64
+ if (policies === undefined) {
65
+ policies = new Map();
66
+ resolvedRoleRuntimePolicies.set(settings, policies);
67
+ }
68
+ policies.set(role, policy);
69
+ }
60
70
  /** Resolve once per immutable settings admission; omission and explicit [] remain distinct. */
61
71
  export function resolveRoleRuntimePolicy(settings, role) {
62
72
  let policies = resolvedRoleRuntimePolicies.get(settings);
@@ -70,10 +80,10 @@ export function resolveRoleRuntimePolicy(settings, role) {
70
80
  const configured = role === undefined ? undefined : settings.roleRouting[role];
71
81
  const defaults = settings.runtimePolicy;
72
82
  const primary = configured?.primary === undefined ? undefined : Object.freeze({ ...configured.primary });
73
- const seen = new Set(primary === undefined ? [] : [JSON.stringify([primary.provider, primary.model])]);
83
+ const seen = new Set(primary === undefined ? [] : [canonicalModelRouteJson(primary)]);
74
84
  const fallbacks = [];
75
85
  for (const route of configured?.fallbackRoutes ?? settings.runtimeRecovery.fallbackRoutes) {
76
- const identity = JSON.stringify([route.provider, route.model]);
86
+ const identity = canonicalModelRouteJson(route);
77
87
  if (seen.has(identity))
78
88
  continue;
79
89
  seen.add(identity);