@dsmm/dsmm 0.2.0 → 0.3.0

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 (285) hide show
  1. package/README.md +37 -67
  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/cordis.patch.yml +14 -0
  25. package/docs/agent-presets.md +36 -52
  26. package/docs/compatibility.md +47 -110
  27. package/docs/deferred-native-approval-risk.md +19 -0
  28. package/docs/design.md +2 -2
  29. package/docs/lsp.md +11 -21
  30. package/docs/migration-from-ocmm.md +2 -2
  31. package/docs/model-routing.md +84 -59
  32. package/docs/native-permissions.md +35 -0
  33. package/docs/profiles.md +40 -87
  34. package/docs/releasing.md +123 -2
  35. package/docs/roadmap.md +71 -17
  36. package/docs/settings-status.md +34 -169
  37. package/docs/skill-sync.md +52 -15
  38. package/lib/agent-registry.d.ts +36 -0
  39. package/lib/agent-registry.js +75 -0
  40. package/lib/child-admission-contract.d.ts +37 -0
  41. package/lib/child-admission-contract.js +2 -0
  42. package/lib/child-admission.d.ts +40 -0
  43. package/lib/child-admission.js +151 -0
  44. package/lib/child-capture.d.ts +85 -0
  45. package/lib/child-capture.js +205 -0
  46. package/lib/child-evidence.d.ts +17 -0
  47. package/lib/child-evidence.js +43 -0
  48. package/lib/client/ChildrenPanel.d.ts +43 -0
  49. package/lib/client/ChildrenPanel.js +82 -0
  50. package/lib/client/DeploymentPage.js +15 -8
  51. package/lib/client/EditableChoice.d.ts +17 -0
  52. package/lib/client/EditableChoice.js +49 -0
  53. package/lib/client/PermissionsPanel.d.ts +14 -0
  54. package/lib/client/PermissionsPanel.js +46 -0
  55. package/lib/client/ProfilesSection.js +30 -15
  56. package/lib/client/RoleAvailability.d.ts +7 -0
  57. package/lib/client/RoleAvailability.js +19 -0
  58. package/lib/client/SessionProfiles.js +27 -9
  59. package/lib/client/StructuredEditor.js +15 -7
  60. package/lib/client/children-controller.d.ts +98 -0
  61. package/lib/client/children-controller.js +296 -0
  62. package/lib/client/children-locales.d.ts +367 -0
  63. package/lib/client/children-locales.js +69 -0
  64. package/lib/client/controller.d.ts +6 -1
  65. package/lib/client/controller.js +14 -8
  66. package/lib/client/deployment-controller.js +1 -1
  67. package/lib/client/deployment-data.d.ts +2 -1
  68. package/lib/client/deployment-data.js +34 -5
  69. package/lib/client/deployment-locales.d.ts +4 -0
  70. package/lib/client/deployment-locales.js +11 -2
  71. package/lib/client/diagnostics.d.ts +14 -0
  72. package/lib/client/diagnostics.js +53 -0
  73. package/lib/client/index.d.ts +4 -0
  74. package/lib/client/index.js +96 -2
  75. package/lib/client/locales.d.ts +54 -0
  76. package/lib/client/locales.js +34 -16
  77. package/lib/client/permission-client.d.ts +16 -0
  78. package/lib/client/permission-client.js +38 -0
  79. package/lib/client/permission-controller.d.ts +62 -0
  80. package/lib/client/permission-controller.js +149 -0
  81. package/lib/client/permission-locales.d.ts +114 -0
  82. package/lib/client/permission-locales.js +75 -0
  83. package/lib/client/session-labels.js +4 -4
  84. package/lib/client/structured.js +19 -5
  85. package/lib/client/styles.d.ts +1 -1
  86. package/lib/client/styles.js +20 -0
  87. package/lib/client.js +5780 -1679
  88. package/lib/core-permission-authority.d.ts +18 -0
  89. package/lib/core-permission-authority.js +255 -0
  90. package/lib/core-permissions.d.ts +8 -0
  91. package/lib/core-permissions.js +33 -0
  92. package/lib/delivery-authority.d.ts +83 -0
  93. package/lib/delivery-authority.js +397 -0
  94. package/lib/deployment-config.d.ts +23 -0
  95. package/lib/deployment-config.js +61 -40
  96. package/lib/deployment-permission-rules.d.ts +55 -0
  97. package/lib/deployment-permission-rules.js +306 -0
  98. package/lib/dsh-types.d.ts +10 -4
  99. package/lib/guards.d.ts +1 -1
  100. package/lib/guards.js +29 -8
  101. package/lib/host-llm-startup.d.ts +41 -0
  102. package/lib/host-llm-startup.js +65 -0
  103. package/lib/host-llm.d.ts +92 -0
  104. package/lib/host-llm.js +325 -0
  105. package/lib/index.d.ts +15 -4
  106. package/lib/index.js +288 -48
  107. package/lib/live-pi-ai-owner.d.ts +18 -0
  108. package/lib/live-pi-ai-owner.js +144 -0
  109. package/lib/llm-runtime.d.ts +11 -0
  110. package/lib/llm-runtime.js +21 -0
  111. package/lib/managed-settings.d.ts +5 -0
  112. package/lib/managed-settings.js +14 -0
  113. package/lib/model-parameter-policy.d.ts +11 -0
  114. package/lib/model-parameter-policy.js +27 -0
  115. package/lib/model-routing.js +28 -17
  116. package/lib/modules.d.ts +13 -5
  117. package/lib/modules.js +17 -1
  118. package/lib/native-child-evidence.d.ts +40 -0
  119. package/lib/native-child-evidence.js +104 -0
  120. package/lib/native-pi-ai-wire.d.ts +37 -0
  121. package/lib/native-pi-ai-wire.js +261 -0
  122. package/lib/native-scope.js +1 -1
  123. package/lib/permission-bash.d.ts +6 -0
  124. package/lib/permission-bash.js +7 -0
  125. package/lib/permission-control.d.ts +73 -0
  126. package/lib/permission-control.js +205 -0
  127. package/lib/permission-controller.d.ts +68 -0
  128. package/lib/permission-controller.js +317 -0
  129. package/lib/permission-errors.d.ts +7 -0
  130. package/lib/permission-errors.js +21 -0
  131. package/lib/permission-fs-search.d.ts +5 -0
  132. package/lib/permission-fs-search.js +7 -0
  133. package/lib/permission-fs.d.ts +5 -0
  134. package/lib/permission-fs.js +7 -0
  135. package/lib/permission-native-access.d.ts +11 -0
  136. package/lib/permission-native-access.js +6 -0
  137. package/lib/permission-native-command.d.ts +10 -0
  138. package/lib/permission-native-command.js +93 -0
  139. package/lib/permission-native-rules.d.ts +75 -0
  140. package/lib/permission-native-rules.js +278 -0
  141. package/lib/permission-pwsh.d.ts +6 -0
  142. package/lib/permission-pwsh.js +7 -0
  143. package/lib/permission-remote.d.ts +26 -0
  144. package/lib/permission-remote.js +53 -0
  145. package/lib/permission-rpc.d.ts +29 -0
  146. package/lib/permission-rpc.js +152 -0
  147. package/lib/permission-rules.d.ts +115 -0
  148. package/lib/permission-rules.js +256 -0
  149. package/lib/permission-settings.d.ts +45 -0
  150. package/lib/permission-settings.js +48 -0
  151. package/lib/permission-shell.d.ts +38 -0
  152. package/lib/permission-shell.js +150 -0
  153. package/lib/permission-web.d.ts +5 -0
  154. package/lib/permission-web.js +7 -0
  155. package/lib/preset-registry.js +36 -25
  156. package/lib/profile-diagnostics.d.ts +45 -0
  157. package/lib/profile-diagnostics.js +148 -0
  158. package/lib/profile-locale.d.ts +3 -0
  159. package/lib/profile-locale.js +2 -0
  160. package/lib/profile-remote.d.ts +8 -0
  161. package/lib/profile-remote.js +163 -39
  162. package/lib/profile-rpc.d.ts +4 -3
  163. package/lib/profile-rpc.js +20 -16
  164. package/lib/profile-runtime.d.ts +40 -1
  165. package/lib/profile-runtime.js +368 -93
  166. package/lib/profile-store.d.ts +11 -0
  167. package/lib/profile-store.js +143 -11
  168. package/lib/profile-types.d.ts +70 -1
  169. package/lib/profile-types.js +1 -0
  170. package/lib/profiles.d.ts +16 -2
  171. package/lib/profiles.js +156 -79
  172. package/lib/prompt-content.js +1 -1
  173. package/lib/prompts.d.ts +37 -2
  174. package/lib/prompts.js +111 -9
  175. package/lib/recovery-policy.js +20 -7
  176. package/lib/role-control-remote.d.ts +38 -0
  177. package/lib/role-control-remote.js +211 -0
  178. package/lib/role-control-rpc.d.ts +51 -0
  179. package/lib/role-control-rpc.js +381 -0
  180. package/lib/role-control-types.d.ts +92 -0
  181. package/lib/role-control-types.js +8 -0
  182. package/lib/role-invocation.d.ts +47 -0
  183. package/lib/role-invocation.js +135 -0
  184. package/lib/role-llm-runtime.d.ts +17 -0
  185. package/lib/role-llm-runtime.js +62 -0
  186. package/lib/role-llm.d.ts +31 -0
  187. package/lib/role-llm.js +66 -0
  188. package/lib/role-policy.d.ts +46 -8
  189. package/lib/role-policy.js +421 -61
  190. package/lib/role-providers.d.ts +2 -2
  191. package/lib/role-providers.js +27 -72
  192. package/lib/role-routing.d.ts +11 -2
  193. package/lib/role-routing.js +42 -25
  194. package/lib/role-runs.d.ts +138 -0
  195. package/lib/role-runs.js +335 -0
  196. package/lib/role-subagents.d.ts +58 -3
  197. package/lib/role-subagents.js +179 -56
  198. package/lib/roles.d.ts +5 -6
  199. package/lib/roles.js +10 -39
  200. package/lib/route-json.d.ts +19 -0
  201. package/lib/route-json.js +129 -0
  202. package/lib/routing-policy.d.ts +2 -0
  203. package/lib/routing-policy.js +12 -2
  204. package/lib/runtime-integration.d.ts +81 -0
  205. package/lib/runtime-integration.js +702 -0
  206. package/lib/runtime-recovery.js +18 -8
  207. package/lib/session-persistence.d.ts +2 -1
  208. package/lib/session-persistence.js +1 -1
  209. package/lib/session-scope.js +4 -1
  210. package/lib/settings.d.ts +47 -13
  211. package/lib/settings.js +217 -82
  212. package/lib/skills.js +2 -2
  213. package/lib/status.d.ts +10 -1
  214. package/lib/status.js +11 -8
  215. package/lib/subagent-runtime.d.ts +57 -0
  216. package/lib/subagent-runtime.js +257 -0
  217. package/package.json +149 -89
  218. package/patches/subagent-runtime.yml +15 -0
  219. package/prompts/deepseek-flash.md +1 -1
  220. package/prompts/deepseek-v4-pro.md +2 -2
  221. package/prompts/deepwork.md +27 -18
  222. package/prompts/source/agents/clarifier.md +5 -3
  223. package/prompts/source/agents/orchestrator.md +18 -9
  224. package/prompts/source/agents/plan-critic.md +5 -1
  225. package/prompts/source/agents/planner.md +4 -2
  226. package/prompts/source/agents/reviewer.md +6 -0
  227. package/prompts/source/category/complex.md +4 -4
  228. package/prompts/source/category/creative.md +6 -4
  229. package/prompts/source/category/cross-cutting.md +10 -8
  230. package/prompts/source/category/deep.md +5 -3
  231. package/prompts/source/category/documenting.md +7 -1
  232. package/prompts/source/category/frontend.md +2 -2
  233. package/prompts/source/category/hard-reasoning.md +3 -3
  234. package/prompts/source/category/research.md +4 -2
  235. package/prompts/source/deepwork/claude-opus-5.md +2 -2
  236. package/prompts/source/deepwork/codex.md +1 -1
  237. package/prompts/source/deepwork/default.md +22 -15
  238. package/prompts/source/deepwork/gemini.md +23 -16
  239. package/prompts/source/deepwork/glm.md +21 -14
  240. package/prompts/source/deepwork/gpt.md +12 -6
  241. package/prompts/source/deepwork/planner.md +8 -5
  242. package/prompts/source/manifest.json +178 -63
  243. package/prompts/source/shared/dsh-host-contract.md +5 -3
  244. package/prompts/source/shared/locale.md +2 -2
  245. package/prompts/source/terminal/orchestrator.md +1 -1
  246. package/skills/ast-grep/SKILL.md +7 -4
  247. package/skills/brainstorming/SKILL.md +43 -22
  248. package/skills/coding-agent-sessions/SKILL.md +7 -4
  249. package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -46
  250. package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -130
  251. package/skills/debugging/SKILL.md +14 -9
  252. package/skills/debugging/references/methodology/00-setup.md +14 -62
  253. package/skills/debugging/references/methodology/02-investigate.md +4 -4
  254. package/skills/debugging/references/methodology/03-flaky-triage.md +3 -3
  255. package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +2 -14
  256. package/skills/debugging/references/methodology/06-fix.md +6 -6
  257. package/skills/debugging/references/methodology/08-qa.md +5 -5
  258. package/skills/debugging/references/methodology/09-cleanup.md +15 -153
  259. package/skills/debugging/references/methodology/partial-runtime-evidence.md +3 -16
  260. package/skills/debugging/references/runtimes/bundled-js-binary.md +1 -16
  261. package/skills/debugging/references/runtimes/native-binary.md +9 -54
  262. package/skills/debugging/references/runtimes/node.md +4 -15
  263. package/skills/debugging/references/runtimes/python.md +3 -15
  264. package/skills/debugging/references/runtimes/rust.md +2 -18
  265. package/skills/debugging/references/tools/dap.md +1 -1
  266. package/skills/debugging/references/tools/ghidra.md +4 -15
  267. package/skills/debugging/references/tools/playwright-cli.md +3 -15
  268. package/skills/debugging/references/tools/pwntools.md +4 -16
  269. package/skills/dispatching-parallel-agents/SKILL.md +18 -16
  270. package/skills/frontend/SKILL.md +7 -4
  271. package/skills/frontend/references/design/react-dev-tooling-skill.md +1 -1
  272. package/skills/git-master/SKILL.md +7 -4
  273. package/skills/init-deep/SKILL.md +7 -4
  274. package/skills/receiving-code-review/SKILL.md +17 -12
  275. package/skills/remove-ai-slops/SKILL.md +39 -38
  276. package/skills/requesting-code-review/SKILL.md +19 -17
  277. package/skills/requesting-code-review/code-reviewer.md +13 -1
  278. package/skills/subagent-driven-development/SKILL.md +29 -26
  279. package/skills/subagent-driven-development/implementer-prompt.md +29 -11
  280. package/skills/subagent-driven-development/spec-reviewer-prompt.md +6 -1
  281. package/skills/using-git-worktrees/SKILL.md +7 -4
  282. package/skills/writing-plans/SKILL.md +29 -24
  283. package/skills/writing-plans/plan-document-reviewer-prompt.md +10 -1
  284. package/scripts/repair-session-log.mjs +0 -476
  285. package/scripts/session-repair-native-verifier.mjs +0 -367
@@ -2,15 +2,23 @@ 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
+ import { PERSONA_PREFIX_SECTION } from "@deepseek-ai/dsh-persona";
6
7
  import { DSMM_ROLES } from "./roles.js";
8
+ import { isDsmmRoleId } from "./roles.js";
7
9
  import { DsmmRolePolicy, roleToolName } from "./role-policy.js";
8
- import { roleProviderName, roleAgentOptions } from "./role-providers.js";
10
+ import { roleProviderName } from "./role-providers.js";
11
+ import { capturedOriginalRoleInvocation, duringRoleInvocation, invocationAgentOptions, invocationView, resolveRoleInvocation } from "./role-invocation.js";
12
+ import { childOwnedSessionEvents } from "./session-scope.js";
9
13
  import { agentForScope, nativeAgentContext, scopeParentOf } from "./native-scope.js";
14
+ import { roleRouteRuntimeState } from "./role-routing.js";
15
+ import { modelRouteFromCall } from "./role-llm.js";
16
+ import { duringActivationOwnership } from "./agent-registry.js";
10
17
  const hostControls = ["send_message", "interrupt_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"];
11
18
  // Agent-owned policy realms survive a bundle reinstall; do not register another
12
19
  // identity prompt/tools layer on the same retained live Agent.
13
20
  const admittedRealms = new WeakSet();
21
+ const callableDefinitions = new WeakMap();
14
22
  /** Keep native controls on the frozen startup substrate, not desired-save reconciliation. */
15
23
  export async function registerNativeSubagentControls(ctx) {
16
24
  const tools = ctx.get("tools");
@@ -29,86 +37,191 @@ export async function registerNativeSubagentControls(ctx) {
29
37
  ctx.logger.warn("DSMM native subagent controls unavailable; continuable control requires the installed host substrate");
30
38
  }
31
39
  }
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;
40
+ /** C's same-run holder/live projection can read the actual lock without reapplying defaults. */
41
+ export function roleInvocationView(invocation, label, mode, getSettings, child, ids = {}) {
42
+ return roleInvocationObservation(invocation, label, mode, getSettings, child, ids).view;
43
+ }
44
+ /** Initial preflight/lock is not an observed SDK request; keep E's distinction truthful. */
45
+ export function roleInvocationObservation(invocation, label, mode, getSettings, child, ids = {}) {
46
+ const view = invocationView(invocation, label, mode, ids);
47
+ if (child === undefined)
48
+ return { view, routeKind: "initial" };
49
+ const actual = latestOwnRoleRoute(child);
50
+ if (actual.status === "known")
51
+ return { view: { ...view, route: actual.route }, routeKind: "actual" };
52
+ const route = roleRouteRuntimeState(child, getSettings(child), invocation.target, getSettings.admission?.(child).epoch).route;
53
+ return { view: route === undefined ? view : { ...view, route: { ...route } }, routeKind: "initial" };
54
+ }
55
+ function latestOwnRoleRoute(child) {
56
+ const own = childOwnedSessionEvents(child.session);
57
+ for (let index = own.length - 1; index >= 0; index--) {
58
+ const event = own[index];
59
+ if (event.type !== "request/header")
60
+ continue;
61
+ const config = event.data?.header?.config;
62
+ if (typeof config?.provider !== "string" || typeof config.model !== "string"
63
+ || config.reasoningEffort !== undefined && typeof config.reasoningEffort !== "string") {
64
+ return { status: "unknown", reason: "invalid-own-request-header" };
65
+ }
66
+ try {
67
+ return { status: "known", source: "own-native-request-header", route: Object.freeze(modelRouteFromCall({ ...config, provider: config.provider, model: config.model })) };
68
+ }
69
+ catch {
70
+ return { status: "unknown", reason: "invalid-own-request-header" };
71
+ }
47
72
  }
48
- if (disposal.status === "rejected")
49
- throw disposal.reason;
50
- return execution.value;
73
+ return { status: "unknown", reason: "no-own-request-header" };
74
+ }
75
+ /** Both observations belong to this exact native Agent; no parent/settings/route-lock fallback. */
76
+ export function roleRouteComparison(child) {
77
+ const agent = child;
78
+ const invocation = capturedOriginalRoleInvocation(agent);
79
+ return { childId: child.id, initialRoute: invocation === undefined ? { status: "unknown", reason: "missing-invocation-capture" }
80
+ : { status: "known", source: "invocation-capture", route: Object.freeze({ ...invocation.initialRoute }) }, liveRoute: latestOwnRoleRoute(agent) };
81
+ }
82
+ /** Shared by runtime registration and the prompt assembler; empty groups have no callable entry. */
83
+ export function callableRoleInventory(settings, targets) {
84
+ const admitted = targets.filter(id => id !== "dsmm-orchestrator" && settings.roles[id]);
85
+ const roleTargets = admitted.filter(id => DSMM_ROLES.find(row => row.id === id)?.kind === "role");
86
+ const categories = admitted.filter(id => DSMM_ROLES.find(row => row.id === id)?.kind === "category");
87
+ return [
88
+ ...settings.subagents.toolTopology === "per-role" ? roleTargets.map(id => ({ name: roleToolName(id), kind: "role", targets: [id] }))
89
+ : roleTargets.length === 0 ? [] : [{ name: "dsmm_role", kind: "role", targets: roleTargets, targetParameter: "role" }],
90
+ ...categories.length === 0 ? [] : [{ name: "dsmm_category", kind: "category", targets: categories, targetParameter: "category" }]
91
+ ];
51
92
  }
52
- function registerRoleTool(agent, agentCtx, tools, role, getSettings, policy) {
93
+ /** Exact currently exposed definitions, suitable for E's runtime guidance and safe capability views. */
94
+ export function admittedCallableRoleInventory(agent, settings, policy, tools) {
95
+ const allowed = new Set(policy.targets(agent)), providers = nativeAgentContext(agent).get("subagents");
96
+ return tools.schemas(agent).flatMap(schema => {
97
+ const definition = tools.get(schema.name, agent), registered = definition === undefined ? undefined : callableDefinitions.get(definition);
98
+ if (registered === undefined || policy.toolDenial(agent, schema.name, tools) !== undefined)
99
+ return [];
100
+ const targets = registered.entry.targets.filter(target => allowed.has(target) && settings.roles[target]
101
+ && providers?.getProvider(roleProviderName(target)) === registered.providers.get(target)
102
+ && providers?.getProvider(roleProviderName(target))?.capabilities.depthLimit === true);
103
+ return targets.length === 0 ? [] : [{ ...registered.entry, targets }];
104
+ });
105
+ }
106
+ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, roleRuns) {
53
107
  const settings = getSettings(agent);
54
108
  const subagents = agentCtx.get("subagents");
55
109
  if (subagents === undefined)
56
110
  throw new Error("DSMM role tools require native subagents");
57
111
  const background = settings.subagents.enableRunInBackground;
58
112
  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."}`,
113
+ const admittedProviders = new Map(entry.targets.map(target => [target, subagents.getProvider(roleProviderName(target))]));
114
+ const definition = defineTool({
115
+ 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
116
  parameters: { description: { type: "string", required: true }, prompt: { type: "string", required: true },
117
+ ...(entry.targetParameter === undefined ? {} : { [entry.targetParameter]: { type: "string", enum: entry.targets, required: true } }),
118
+ level: { type: "string", enum: ["normal", "low", "high", "max"] },
119
+ ...(settings.subagents.allowRouteOverride ? { route: { oneOf: [
120
+ { type: "object", additionalProperties: false, properties: { reasoningEffort: { type: "string", required: true } } },
121
+ { type: "object", additionalProperties: true, properties: { provider: { type: "string", required: true }, model: { type: "string", required: true }, reasoningEffort: { type: "string" } } }
122
+ ] } } : {}),
62
123
  ...(background ? { run_in_background: { type: "boolean" } } : {}) },
63
124
  output: { schema: { type: "json" }, render(_args, value) {
64
125
  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
- } },
126
+ const invocation = result.invocation;
127
+ const route = invocation?.route;
128
+ const metadata = invocation === undefined ? "" : `${invocation.role} level=${invocation.level}${route === undefined ? "" : ` route=${route.provider}/${route.model}${route.reasoningEffort === undefined ? "" : ` effort=${route.reasoningEffort}`}`}`;
129
+ return result.kind === "foreground" ? [{ type: "text", text: metadata }, ...result.output ?? []]
130
+ : [{ type: "text", text: `${metadata}\n${result.kind === "continuable" ? `started subagent ${result.subagentId}` : `started background subagent job ${result.jobId}`}` }];
131
+ }, presentationMeta(_args, value) { return typeof value === "object" && value !== null && !Array.isArray(value) ? value.invocation ?? null : null; } },
67
132
  async execute(args, exec) {
68
- const fields = background ? ["description", "prompt", "run_in_background"] : ["description", "prompt"];
133
+ const fields = ["description", "prompt", "level", ...entry.targetParameter === undefined ? [] : [entry.targetParameter],
134
+ ...settings.subagents.allowRouteOverride ? ["route"] : [], ...background ? ["run_in_background"] : []];
69
135
  if (Object.keys(exec.arguments).some((key) => !fields.includes(key)))
70
136
  throw new SubagentError("DSMM delegation parameter is unsupported by this admitted tool", "UNSUPPORTED_CAPABILITY");
71
137
  const parent = exec.agent;
72
138
  if (parent === undefined)
73
139
  throw new SubagentError("DSMM delegation requires a calling Agent", "UNAUTHORIZED");
140
+ if (parent !== agent || tools.get(entry.name, parent) === undefined || policy.toolDenial(agent, entry.name, tools) !== undefined)
141
+ throw new SubagentError("DSMM tool is not the exact admitted caller definition", "UNAUTHORIZED");
142
+ const target = entry.targetParameter === undefined ? entry.targets[0] : exec.arguments[entry.targetParameter];
143
+ if (!isDsmmRoleId(target) || !entry.targets.includes(target) || DSMM_ROLES.find(row => row.id === target).kind !== entry.kind)
144
+ throw new SubagentError("DSMM target is unknown, cross-kind or not admitted", "UNAUTHORIZED");
145
+ const role = DSMM_ROLES.find(row => row.id === target);
74
146
  const admitted = policy.assertDelegation(parent, role.id);
75
147
  const current = getSettings(parent);
76
148
  const provider = subagents.getProvider(roleProviderName(role.id));
77
- if (provider === undefined)
78
- throw new SubagentError("DSMM role provider is unavailable", "NO_PROVIDER");
149
+ if (provider === undefined || provider !== admittedProviders.get(role.id))
150
+ throw new SubagentError("DSMM exact admitted role provider is unavailable", "NO_PROVIDER");
151
+ const invocation = await resolveRoleInvocation(parent, role.id, current, exec.signal, { ...(args.level === undefined ? {} : { level: args.level }), ...(args.route === undefined ? {} : { route: args.route }) });
152
+ const capturedProvider = provider;
79
153
  const request = { parent, label: args.description, prompt: [{ type: "text", text: args.prompt }],
80
- persona: role.persona, maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
154
+ agentOptions: invocationAgentOptions(invocation), maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
81
155
  const assertCurrent = () => {
82
156
  if (policy.assertDelegation(parent, role.id).epoch !== admitted.epoch)
83
157
  throw new SubagentError("DSMM parent admission changed before delegation", "UNAUTHORIZED");
158
+ if (subagents.getProvider(roleProviderName(role.id)) !== capturedProvider)
159
+ throw new SubagentError("DSMM exact provider changed before delegation", "NO_PROVIDER");
84
160
  };
85
161
  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);
162
+ const requestedBackground = background && (args.run_in_background ?? continuable);
163
+ if (requestedBackground && continuable) {
164
+ if (provider.prepareContinuable === undefined)
165
+ throw new SubagentError("DSMM provider has no prepareContinuable capability", "UNSUPPORTED_CAPABILITY");
166
+ assertCurrent();
167
+ const child = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(parent, role.id, () => subagents.startActivation({ provider: provider.name, label: args.description,
168
+ request, signal: exec.signal, delivery: "parent" }), undefined, request.maxDepth));
169
+ return { kind: "continuable", subagentId: child.childId, invocation: { ...invocationView(invocation, args.description, "continuable", { childId: child.childId }) } };
170
+ }
171
+ assertCurrent();
172
+ if (roleRuns === undefined)
173
+ throw new SubagentError("DSMM one-shot delegation requires the stable Host role-run registry", "UNSUPPORTED_CAPABILITY");
174
+ const admission = getSettings.admission?.(agent);
175
+ if (admission === undefined || admission.epoch !== admitted.epoch)
176
+ throw new SubagentError("DSMM one-shot capture requires the exact original parent admission", "UNAUTHORIZED");
177
+ const jobs = agentCtx.get("jobs");
178
+ if (requestedBackground && jobs === undefined)
179
+ throw new SubagentError("DSMM background jobs require the native jobs registry/controller", "UNSUPPORTED_CAPABILITY");
180
+ let child;
181
+ const projection = { ...invocationView(invocation, args.description, "one-shot"), get route() {
182
+ return roleInvocationView(invocation, args.description, "one-shot", getSettings, child).route;
183
+ } };
184
+ const holder = roleRuns.registry.start({ parent, owner: roleRuns.owner, sessionId: parent.id, toolCallId: exec.callId,
185
+ admissionEpoch: admitted.epoch, capture: Object.freeze({ invocation, admission }), projection, label: args.description, callerAbort: exec.signal, jobs,
186
+ async start(signal) {
91
187
  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 };
188
+ const run = await duringRoleInvocation(agent, invocation, () => policy.duringDelegation(agent, role.id, () => duringActivationOwnership(signal, () => subagents.startActivation({ provider: provider.name, label: args.description, request, signal, delivery: "caller" })), undefined, request.maxDepth, agent => { child = agent; }));
189
+ projection.runId = run.childId;
190
+ if (child?.id !== undefined)
191
+ projection.childId = child.id;
192
+ return run;
193
+ } });
194
+ if (requestedBackground) {
195
+ try {
196
+ const identity = await holder.ready;
197
+ const transition = holder.background({ parent, owner: roleRuns.owner, sessionId: parent.id, toolCallId: exec.callId,
198
+ runId: identity.runId, expectedAdmissionEpoch: admitted.epoch });
199
+ if (transition.status === "starting")
200
+ throw new SubagentError("DSMM ready run is not transferable", "UNAUTHORIZED");
201
+ }
202
+ catch (error) {
203
+ holder.cancel(error);
204
+ const [drain] = await Promise.allSettled([holder.drained]);
205
+ if (drain.status === "rejected" && drain.reason !== error)
206
+ throw new AggregateError([error, drain.reason], "DSMM background handoff was refused and its owned run drain rejected");
207
+ throw error;
95
208
  }
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
209
  }
105
- assertCurrent();
106
- return foreground(await subagents.start(provider.name, { ...request, signal: exec.signal }));
210
+ const held = await holder.foreground;
211
+ if (held.kind === "background")
212
+ projection.jobId = held.jobId;
213
+ const { route, ...metadata } = projection;
214
+ const view = { ...metadata, ...(route === undefined ? {} : { route: { ...route } }) };
215
+ return held.kind === "foreground" ? { kind: held.kind, runId: held.runId, output: held.output, invocation: view }
216
+ : { kind: held.kind, runId: held.invocation.runId, jobId: held.jobId, invocation: view };
107
217
  }
108
- }));
218
+ });
219
+ callableDefinitions.set(definition, { entry: Object.freeze({ ...entry, targets: Object.freeze([...entry.targets]) }), providers: admittedProviders });
220
+ const dispose = tools.register(definition);
221
+ return () => { callableDefinitions.delete(definition); dispose(); };
109
222
  }
110
223
  /** 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)) {
224
+ export async function registerHeadlessRoleTools(ctx, controller, getSettings, policy = new DsmmRolePolicy(ctx, getSettings, controller), roleRuns) {
112
225
  const states = new WeakMap();
113
226
  const reconcile = async (agent) => {
114
227
  const state = states.get(agent);
@@ -120,6 +233,14 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
120
233
  if (tools === undefined)
121
234
  throw new Error("DSMM role tools require native guard/restrict services");
122
235
  const settings = getSettings(agent), identity = policy.identity(agent), targets = policy.targets(agent);
236
+ const personaRole = identity.child ? identity.role : undefined;
237
+ if (state.personaRole !== personaRole) {
238
+ state.persona?.();
239
+ const prompt = agentCtx.get("systemPrompt");
240
+ state.persona = personaRole === undefined ? undefined : prompt.section({ name: PERSONA_PREFIX_SECTION,
241
+ order: prompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"), text: DSMM_ROLES.find(role => role.id === personaRole).persona });
242
+ state.personaRole = personaRole;
243
+ }
123
244
  const subagents = agentCtx.get("subagents");
124
245
  const host = ctx.get?.("tools");
125
246
  const names = [...hostControls, ...host?.schemas().map((row) => row.name).filter((name) => name.startsWith(`mcp__${settings.lsp.serverName}__`)) ?? []];
@@ -137,7 +258,7 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
137
258
  state.tools = tools;
138
259
  // rc.2 has no public filter for own-layer registrations. A native monotonic
139
260
  // 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);
261
+ state.guard = tools.guard((execution) => execution.agent === agent ? policy.toolDenial(agent, execution.name, tools, execution) : undefined);
141
262
  const forbidden = tools.schemas(agent).map((tool) => tool.name).filter((name) => name !== "run_code" && policy.toolDenial(agent, name) !== undefined
142
263
  && tools.get(name, parentScope) === tools.get(name, agent));
143
264
  if (forbidden.length > 0)
@@ -148,11 +269,10 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
148
269
  if (definition !== undefined && tools.get(definition.name, agent) === undefined && policy.toolDenial(agent, definition.name) === undefined)
149
270
  state.owned.push(tools.register(definition));
150
271
  }
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);
272
+ const inventory = callableRoleInventory(settings, targets.filter(role => subagents?.getProvider(roleProviderName(role))?.capabilities.depthLimit === true));
273
+ for (const entry of inventory)
274
+ state.owned.push(registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, roleRuns));
275
+ policy.captureTools(agent, tools, [...inventory.map(entry => entry.name), ...names], !sameRealm || !sameParent);
156
276
  state.signature = signature;
157
277
  state.hostDefinitions = definitions;
158
278
  state.parentScope = parentScope;
@@ -168,12 +288,15 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
168
288
  policy.installDrain(agent);
169
289
  agentCtx.get("systemPrompt").section({ name: "dsmm:delegation-identity", order: 49, text() {
170
290
  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.`;
291
+ const tools = states.get(agent)?.tools;
292
+ const inventory = tools === undefined ? [] : admittedCallableRoleInventory(agent, getSettings(agent), policy, tools);
293
+ 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
294
  } });
173
295
  agentCtx.effect(() => () => {
174
296
  const state = states.get(agent);
175
297
  state?.restriction?.();
176
298
  state?.guard?.();
299
+ state?.persona?.();
177
300
  for (const dispose of state?.owned ?? [])
178
301
  dispose();
179
302
  states.delete(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