@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
@@ -1,21 +1,25 @@
1
1
  import { join } from "node:path";
2
2
  import { createHash, randomUUID } from "node:crypto";
3
3
  import { ProfileStore, validateSessionProfileId } from "./profile-store.js";
4
- import { DsmmProfileError, resolveProfileSettings } from "./profiles.js";
5
- import { DSMM_ROLES, isRootRole } from "./roles.js";
6
- import { roleRouteRuntimeState, selectInitialModelRoute } from "./role-routing.js";
4
+ import { DsmmProfileError, profileDocumentWarnings, requiredReason, resolveProfileSettings } from "./profiles.js";
5
+ import { DSMM_ROLES, isDsmmRoleId } from "./roles.js";
6
+ import { roleRouteRuntimeState } from "./role-routing.js";
7
7
  import { sessionEvents } from "./session-scope.js";
8
8
  import { resolveAdmittedDsmmRole as resolveEffectiveDsmmRole } from "./role-policy.js";
9
9
  import { DeepworkModeController, hasOpenTurn } from "./state.js";
10
- import { resolveRoleRuntimePolicy } from "./settings.js";
11
- import { freezeSettings } from "./settings.js";
10
+ import { freezeSettings, isRootRoleEnabled } from "./settings.js";
12
11
  import { resolveDshHome } from "./dsh-home.js";
13
12
  import { lstatSync } from "node:fs";
14
- import { projectDeepworkModule } from "./modules.js";
13
+ import { projectDsmmModules } from "./modules.js";
15
14
  import { Context } from "@deepseek-ai/cordis";
16
15
  import { readOnlySettings, readOnlySettingSources } from "./status.js";
16
+ import { resolveSelectedAgentPreset } from "./session-scope.js";
17
+ import { admissionFromChildCapture, parseChildAdmissionCapture, parseLegacyChildEvidence } from "./child-capture.js";
18
+ import { normalizeModelRouteJson } from "./route-json.js";
19
+ import { resolvedModelParameterPolicy } from "./model-parameter-policy.js";
20
+ import { scopeLifetime } from "./delivery-authority.js";
17
21
  function deploymentAdmissionView(admission) {
18
- return { settings: { ...readOnlySettings(admission.settings) }, sources: readOnlySettingSources(admission.sources ?? {}),
22
+ return { modelParameterPolicy: resolvedModelParameterPolicy(admission), settings: { ...readOnlySettings(admission.settings) }, sources: readOnlySettingSources(admission.sources ?? {}),
19
23
  captures: readOnlySettingSources(admission.sourceCaptures?.fields ?? {}), restartRequired: [...admission.restartRequired ?? []], named: admission.profile === null ? null : { ...admission.profile } };
20
24
  }
21
25
  // Exact live native children retain their capture across DSMM runtime replacement.
@@ -28,6 +32,7 @@ export class DsmmProfileRuntime {
28
32
  ctx;
29
33
  store;
30
34
  options;
35
+ childCaptureStore;
31
36
  getSettings = (agent) => agent === undefined ? this.current.settings : this.bind(agent).settings;
32
37
  current;
33
38
  currentDocument = null;
@@ -36,6 +41,7 @@ export class DsmmProfileRuntime {
36
41
  admitting = new WeakSet();
37
42
  disposedAgents = new WeakSet();
38
43
  switching = new WeakSet();
44
+ admissionObservers = new Set();
39
45
  disposed = false;
40
46
  selectionQueue = Promise.resolve();
41
47
  mode;
@@ -43,29 +49,71 @@ export class DsmmProfileRuntime {
43
49
  this.ctx = ctx;
44
50
  this.store = store;
45
51
  this.options = options;
52
+ this.childCaptureStore = options.childCaptureStore ?? store;
46
53
  this.baseline = immutableSettings(baseline);
47
54
  this.mode = options.modeController ?? new DeepworkModeController({ get: (name) => ctx.get?.(name) }, (agent) => this.getSettings(agent).modules.deepwork.enabled);
48
55
  this.current = this.prepare(null, { selectedId: null, appliedRevision: null, selectionRevision: "absent" });
49
56
  this.getSettings.admission = (agent) => this.admission(agent);
50
- this.getSettings.moduleStates = (agent) => { const admission = this.admission(agent); return [projectDeepworkModule(this.baseline, admission.deployment, admission)]; };
57
+ this.getSettings.moduleStates = (agent) => { const admission = this.admission(agent); return projectDsmmModules(this.baseline, admission.deployment, admission, false, this.options.getMountedPermission); };
58
+ this.getSettings.subagentRuntime = () => this.subagentRuntimeView();
51
59
  }
52
60
  async initialize() {
61
+ const retire = () => { this.disposed = true; this.admissionObservers.clear(); for (const agent of this.agents()?.list() ?? [])
62
+ if (this.bound.has(agent))
63
+ this.options.childAuthority?.revokeParent(agent, "runtime-disposed"); };
64
+ if (this.ctx instanceof Context)
65
+ scopeLifetime(this.ctx, "dsmm.profiles: retire admission lifecycle", retire);
66
+ else
67
+ this.ctx.effect?.(() => retire);
53
68
  const selection = await this.store.loadSelection();
69
+ if (this.disposed)
70
+ throw new DsmmProfileError("disposed", "Profile initialization was disposed.");
54
71
  this.currentDocument = selection.document === null ? null : freezeSettings(selection.document);
55
72
  this.current = this.prepare(selection.document, selection);
56
73
  this.ctx.on?.("agent/created", async ({ agent, signal }) => {
57
74
  // Factory initialization already owns native maintenance: never whenIdle
58
75
  // or reserve maintenance from inside this serial creation listener.
59
- await this.admit(agent, signal);
76
+ await this.completeAdmission(agent, signal);
60
77
  }, { global: true, prepend: true });
61
- this.ctx.on?.("agent/disposed", ({ agent }) => { this.disposedAgents.add(agent); childAdmissions.delete(agent); }, { global: true });
62
- this.ctx.effect?.(() => () => { this.disposed = true; });
78
+ this.ctx.on?.("agent/disposed", ({ agent }) => { this.options.childAuthority?.revokeParent(agent, "agent-disposed"); this.disposedAgents.add(agent); childAdmissions.delete(agent); }, { global: true });
79
+ if (this.options.onAdmissionGuardsInstalled !== undefined)
80
+ await this.options.onAdmissionGuardsInstalled(this);
63
81
  // Installation into an already-running host treats those Agents as admitted
64
82
  // now, while all later profile switches continue to preserve their snapshot.
83
+ const visited = new Set(), visiting = new Set();
84
+ const admitExisting = async (agent) => {
85
+ if (visited.has(agent))
86
+ return;
87
+ if (visiting.has(agent))
88
+ throw new DsmmProfileError("not-owned", "Existing Agent ownership has a cycle; no child authority was inferred.");
89
+ visiting.add(agent);
90
+ const parent = this.owner(agent);
91
+ if (parent !== undefined && this.options.deferRetainedChildren) {
92
+ visiting.delete(agent);
93
+ return;
94
+ }
95
+ if (parent !== undefined)
96
+ await admitExisting(parent);
97
+ await this.completeAdmission(agent, undefined, this.options.startup);
98
+ visiting.delete(agent);
99
+ visited.add(agent);
100
+ };
65
101
  for (const agent of this.agents()?.list() ?? [])
66
- await this.admit(agent, undefined, this.options.startup);
102
+ await admitExisting(agent);
67
103
  }
68
104
  admission(agent) { return agent === undefined ? this.current : this.bind(agent); }
105
+ /** Host enrollment observes completed exact admissions, never an entered but unpublished policy. */
106
+ hasAdmission(agent) { return !this.disposed && !this.disposedAgents.has(agent) && this.bound.has(agent) && this.agents()?.get?.(agent.id) === agent; }
107
+ observeAdmissions(observer) {
108
+ if (this.disposed)
109
+ throw new DsmmProfileError("disposed", "Profile admission observation was disposed.");
110
+ this.admissionObservers.add(observer);
111
+ return () => { this.admissionObservers.delete(observer); };
112
+ }
113
+ async announceAdmission(agent) {
114
+ for (const observer of this.admissionObservers)
115
+ await observer(agent);
116
+ }
69
117
  async getSession(agent) {
70
118
  this.assertRoot(agent);
71
119
  const admitted = this.bind(agent);
@@ -81,8 +129,9 @@ export class DsmmProfileRuntime {
81
129
  const profileModel = this.declaredProfileModel(admitted.settings, role);
82
130
  return { sessionId: agent.id, globalDefault: selectionState(this.current), selection: selectionState(disk), admittedSelection: selectionState(admitted), scope: admitted.scope,
83
131
  rolePolicy: roleRouteRuntimeState(agent, admitted.settings, role, admitted.epoch), deepwork: this.mode.describe(agent, admitted.settings.defaultActive),
84
- modules: [projectDeepworkModule(this.baseline, admitted.deployment, admitted)],
132
+ modules: projectDsmmModules(this.baseline, admitted.deployment, admitted, false, this.options.getMountedPermission),
85
133
  configuration: deploymentAdmissionView(admitted),
134
+ warnings: structuredClone(admitted.warnings ?? []), roles: structuredClone(admitted.roleAvailability ?? []), subagentRuntime: this.subagentRuntimeView(),
86
135
  ...(profileModel === undefined ? {} : { profileModel }),
87
136
  admissionEpoch: admitted.epoch, switchAllowed: reason === undefined, ...(reason === undefined ? {} : { switchUnavailableReason: reason }) };
88
137
  }
@@ -147,12 +196,27 @@ export class DsmmProfileRuntime {
147
196
  if (request.sessionId !== agent.id)
148
197
  throw new DsmmProfileError("not-owned", "The native session does not match the captured Agent.");
149
198
  const admitted = this.bind(agent);
199
+ const modeRevision = this.mode.describe(agent, admitted.settings.defaultActive).revision;
200
+ const coreOnly = () => resolveEffectiveDsmmRole(agent, admitted.settings, this.mode.active(agent, admitted.settings.defaultActive)) === undefined;
201
+ let requiresDelivery = this.options.childAuthority !== undefined && !coreOnly();
150
202
  const assertCurrent = (maintenanceSignal) => {
151
203
  this.assertRoot(agent);
152
204
  if (signal?.aborted || maintenanceSignal?.aborted)
153
205
  throw new DsmmProfileError("cancelled", "Session profile selection was cancelled; the previous admission was retained.");
154
- if (this.bind(agent) !== admitted || admitted.epoch !== request.expectedAdmissionEpoch)
206
+ if (this.bind(agent) !== admitted || admitted.epoch !== request.expectedAdmissionEpoch || this.mode.describe(agent, admitted.settings.defaultActive).revision !== modeRevision)
155
207
  throw new DsmmProfileError("conflict", "The session admission changed. Refresh before selecting again.");
208
+ if (this.options.childAuthority !== undefined) {
209
+ if (requiresDelivery)
210
+ this.assertDeliveryFence();
211
+ if (!requiresDelivery && this.options.childAuthority.assertCoreParentAdmission !== undefined) {
212
+ this.options.childAuthority.assertCoreParentAdmission(agent, this.options.childAuthorityOwner ?? this, admitted);
213
+ }
214
+ else {
215
+ const ticket = this.options.childAuthority.acquireParentTicket(agent);
216
+ if (ticket.admission !== admitted || ticket.owner !== (this.options.childAuthorityOwner ?? this))
217
+ throw new DsmmProfileError("not-owned", "The stable Host authority does not own this exact admission.");
218
+ }
219
+ }
156
220
  assertAuthority?.();
157
221
  };
158
222
  assertCurrent();
@@ -169,27 +233,56 @@ export class DsmmProfileRuntime {
169
233
  const epoch = newEpoch();
170
234
  let profileModel;
171
235
  let committed;
236
+ let next;
172
237
  const result = await this.store.selectSession(request, epoch, async (document) => {
173
238
  const prepared = immutableSettings(resolveProfileSettings(admitted.baseline, document?.settings ?? {}));
174
- await this.validate(prepared, agent, maintenanceSignal);
239
+ const candidate = { settings: prepared, epoch, scope: request.id === null ? "deployment-baseline" : "session-override",
240
+ profile: document === null ? null : { id: document.id, revision: request.expectedRevision } };
241
+ this.assertRootRole(agent, prepared);
242
+ this.validateRootRole(agent, candidate);
243
+ const controlled = !coreOnly() || resolveEffectiveDsmmRole(agent, prepared, this.mode.active(agent, prepared.defaultActive)) !== undefined;
244
+ requiresDelivery ||= controlled && (this.options.childAuthority !== undefined
245
+ || ["roles", "guards", "subagents"].some(key => JSON.stringify(Reflect.get(prepared, key)) !== JSON.stringify(Reflect.get(admitted.settings, key))));
246
+ if (requiresDelivery)
247
+ this.assertDeliveryFence();
248
+ await this.validate(prepared, requiresDelivery);
249
+ assertCurrent(maintenanceSignal);
250
+ this.assertRootRole(agent, prepared);
251
+ this.validateRootRole(agent, candidate);
175
252
  const role = resolveEffectiveDsmmRole(agent, prepared, this.mode.active(agent, prepared.defaultActive));
176
253
  profileModel = this.declaredProfileModel(prepared, role);
177
- assertCurrent(maintenanceSignal);
178
254
  return prepared;
179
255
  }, {
180
256
  assertCurrent: () => assertCurrent(maintenanceSignal),
257
+ prepare: (selection, settings) => {
258
+ next = this.profileAdmission(selection, settings, epoch, request.id === null ? "deployment-baseline" : "session-override", admitted.baseline, admitted.deployment, admitted.restartRequired, selection.document, selection.warnings);
259
+ this.validateRootRole(agent, next);
260
+ if (!requiresDelivery && this.options.childAuthority?.prepareCoreParentAdmission !== undefined) {
261
+ this.options.childAuthority.prepareCoreParentAdmission(agent, this.options.childAuthorityOwner ?? this, admitted, next);
262
+ }
263
+ else
264
+ this.options.childAuthority?.prepareParentAdmission(agent, admitted.epoch, next);
265
+ },
181
266
  committed: (selection, settings) => {
182
- committed = this.profileAdmission(selection, settings, epoch, request.id === null ? "deployment-baseline" : "session-override", admitted.baseline, admitted.deployment, admitted.restartRequired, selection.document);
183
- this.bound.set(agent, committed);
184
- this.mode.changed(agent);
267
+ const install = () => { this.bound.set(agent, next); };
268
+ if (this.options.childAuthority !== undefined)
269
+ this.options.childAuthority.publishParentAdmission(agent, admitted.epoch, next, install);
270
+ else
271
+ install();
272
+ committed = next;
185
273
  }
186
274
  });
275
+ try {
276
+ this.mode.changed(agent);
277
+ }
278
+ catch { /* Observers cannot undo a successful durable admission publication. */ }
187
279
  // A committed selection remains a successful transaction even if a
188
280
  // queued wake or disposal wins immediately when maintenance releases.
189
281
  return { sessionId: request.sessionId, globalDefault: selectionState(this.current), selection: selectionState(result.selection), admittedSelection: selectionState(result.selection),
190
282
  deepwork: this.mode.describe(agent, result.prepared.defaultActive),
191
- modules: [projectDeepworkModule(this.baseline, committed.deployment, committed)],
283
+ modules: projectDsmmModules(this.baseline, committed.deployment, committed, false, this.options.getMountedPermission),
192
284
  configuration: deploymentAdmissionView(committed),
285
+ warnings: structuredClone(committed.warnings ?? []), roles: structuredClone(committed.roleAvailability ?? []), subagentRuntime: this.subagentRuntimeView(),
193
286
  ...(profileModel === undefined ? {} : { profileModel }),
194
287
  scope: request.id === null ? "deployment-baseline" : "session-override", admissionEpoch: epoch, switchAllowed: true };
195
288
  }
@@ -213,11 +306,12 @@ export class DsmmProfileRuntime {
213
306
  || persisted.selectionRevision !== current.selectionRevision;
214
307
  return {
215
308
  ...persisted,
309
+ selectedWarnings: structuredClone(current.warnings ?? []),
216
310
  roles: DSMM_ROLES.map((role) => {
217
311
  const configured = this.baseline.roleRouting[role.id];
218
312
  const runtimePolicy = { ...(configured?.strategy === undefined ? {} : { strategy: configured.strategy }),
219
313
  ...(configured?.rateLimit === undefined ? {} : { rateLimit: structuredClone(configured.rateLimit) }) };
220
- return { id: role.id, label: role.name, enabled: this.baseline.roles[role.id],
314
+ return { id: role.id, label: role.name, enabled: this.current.settings.roles[role.id], availability: this.current.roleAvailability?.find(state => state.id === role.id),
221
315
  ...(Object.keys(runtimePolicy).length === 0 ? {} : { runtimePolicy }) };
222
316
  }),
223
317
  editorDefaults: structuredClone(this.baseline.runtimePolicy),
@@ -256,7 +350,7 @@ export class DsmmProfileRuntime {
256
350
  });
257
351
  // There is no await between successful durable commit and publication of
258
352
  // the complete settings value. Draft saves never reach this assignment.
259
- this.current = this.profileAdmission(result.selection, result.prepared, newEpoch(), "global-default", baseline, this.options.startup, this.current.restartRequired, selectedDocument);
353
+ this.current = this.profileAdmission(result.selection, result.prepared, newEpoch(), "global-default", baseline, this.options.startup, this.current.restartRequired, selectedDocument, result.selection.warnings);
260
354
  this.currentDocument = selectedDocument;
261
355
  return this.describe();
262
356
  });
@@ -268,6 +362,13 @@ export class DsmmProfileRuntime {
268
362
  const effective = structuredClone(desired);
269
363
  const restartRequired = [];
270
364
  effective.modules.deepwork.enabled = desired.modules.deepwork.enabled && this.baseline.modules.deepwork.enabled;
365
+ effective.subagents.allowRouteOverride = desired.subagents.allowRouteOverride && this.baseline.subagents.allowRouteOverride;
366
+ if (desired.subagents.allowRouteOverride && !this.baseline.subagents.allowRouteOverride)
367
+ restartRequired.push("subagents.allowRouteOverride");
368
+ if (this.baseline.subagents.maxDepth !== undefined && (desired.subagents.maxDepth === undefined || desired.subagents.maxDepth > this.baseline.subagents.maxDepth)) {
369
+ effective.subagents.maxDepth = this.baseline.subagents.maxDepth;
370
+ restartRequired.push("subagents.maxDepth");
371
+ }
271
372
  if (desired.modules.deepwork.enabled && !this.baseline.modules.deepwork.enabled)
272
373
  restartRequired.push("modules.deepwork.enabled");
273
374
  for (const role of DSMM_ROLES) {
@@ -280,6 +381,9 @@ export class DsmmProfileRuntime {
280
381
  effective.subagents.enableRunInBackground = false;
281
382
  restartRequired.push("subagents");
282
383
  }
384
+ if (desired.permissionControl.enabled !== this.baseline.permissionControl.enabled)
385
+ restartRequired.push("permissionControl.enabled");
386
+ effective.permissionControl = { ...desired.permissionControl, enabled: this.baseline.permissionControl.enabled };
283
387
  for (const key of ["modeName", "promptOrder", "presets", "lsp"]) {
284
388
  if (JSON.stringify(desired[key]) !== JSON.stringify(this.baseline[key]))
285
389
  restartRequired.push(key);
@@ -289,9 +393,9 @@ export class DsmmProfileRuntime {
289
393
  && (deployment.profile.section ?? deployment.global.section) !== (this.options.startup.profile.section ?? this.options.startup.global.section))
290
394
  restartRequired.push("section");
291
395
  const baseline = immutableSettings(effective);
292
- return this.profileAdmission(selection, immutableSettings(resolveProfileSettings(baseline, document?.settings ?? {})), epoch, scope, baseline, deployment, restartRequired, document);
396
+ return this.profileAdmission(selection, immutableSettings(resolveProfileSettings(baseline, document?.settings ?? {})), epoch, scope, baseline, deployment, restartRequired, document, selection.warnings);
293
397
  }
294
- profileAdmission(selection, settings, epoch, scope, baseline = this.baseline, deployment = this.options.startup, restartRequired = [], document = null) {
398
+ profileAdmission(selection, settings, epoch, scope, baseline = this.baseline, deployment = this.options.startup, restartRequired = [], document = null, warnings = profileDocumentWarnings(document)) {
295
399
  const sources = { ...deployment?.sources };
296
400
  const fields = Object.fromEntries(Object.keys(sources).map((path) => [path, "deployment"]));
297
401
  const pinStartup = (prefix) => {
@@ -305,10 +409,14 @@ export class DsmmProfileRuntime {
305
409
  fields[path] = "startup";
306
410
  }
307
411
  };
308
- for (const key of ["modeName", "promptOrder", "presets", "lsp"])
412
+ for (const key of ["modeName", "promptOrder", "presets", "lsp", "permissionControl.enabled"])
309
413
  pinStartup(key);
310
414
  if (deployment?.settings.modules.deepwork.enabled && !baseline.modules.deepwork.enabled)
311
415
  pinStartup("modules.deepwork.enabled");
416
+ if (deployment?.settings.subagents.allowRouteOverride && !baseline.subagents.allowRouteOverride)
417
+ pinStartup("subagents.allowRouteOverride");
418
+ if (deployment !== undefined && deployment.settings.subagents.maxDepth !== baseline.subagents.maxDepth)
419
+ pinStartup("subagents.maxDepth");
312
420
  for (const role of DSMM_ROLES) {
313
421
  if (deployment?.settings.roles[role.id] && !baseline.roles[role.id])
314
422
  pinStartup(`roles.${role.id}`);
@@ -324,16 +432,16 @@ export class DsmmProfileRuntime {
324
432
  }
325
433
  };
326
434
  for (const [role, policy] of Object.entries(document?.settings.roleRouting ?? {})) {
327
- if (policy?.primary === undefined)
328
- continue;
329
- const prefix = `roleRouting.${role}.primary.`;
330
- for (const path of Object.keys(sources).filter((path) => path.startsWith(prefix))) {
331
- delete sources[path];
332
- delete fields[path];
333
- }
435
+ const prefixes = [...policy?.primary === undefined ? [] : [`roleRouting.${role}.primary.`], ...Object.keys(policy?.levels ?? {}).map(level => `roleRouting.${role}.levels.${level}.`)];
436
+ for (const prefix of prefixes)
437
+ for (const path of Object.keys(sources).filter((path) => path.startsWith(prefix))) {
438
+ delete sources[path];
439
+ delete fields[path];
440
+ }
334
441
  }
335
442
  mark(document?.settings ?? {}, []);
336
443
  return Object.freeze({ ...selectionState(selection), settings, baseline, epoch, scope, ...(deployment === undefined ? {} : { deployment }),
444
+ warnings: freezeSettings(warnings), roleAvailability: freezeSettings(this.roleAvailability(settings, baseline, deployment, document)), subagentRuntime: freezeSettings(this.subagentRuntimeView()),
337
445
  ...(this.store.origin === undefined ? {} : { store: Object.freeze({ origin: this.store.origin, readOnly: this.store.readOnly === true,
338
446
  ...(this.store.writeRestriction === undefined ? {} : { writeRestriction: this.store.writeRestriction }) }) }),
339
447
  sources: Object.freeze(sources), sourceCaptures: Object.freeze({ fields: Object.freeze(fields), ...(this.options.startup === undefined ? {} : { startup: Object.freeze({
@@ -342,8 +450,7 @@ export class DsmmProfileRuntime {
342
450
  }
343
451
  declaredProfileModel(settings, role) {
344
452
  const primary = role === undefined ? undefined : settings.roleRouting[role]?.primary;
345
- return primary === undefined ? undefined : { provider: primary.provider, model: primary.model,
346
- ...(primary.reasoningEffort === undefined ? {} : { reasoningEffort: primary.reasoningEffort }) };
453
+ return primary === undefined ? undefined : normalizeModelRouteJson(primary);
347
454
  }
348
455
  agents() { return this.ctx.get?.("agents"); }
349
456
  bind(agent) {
@@ -361,24 +468,22 @@ export class DsmmProfileRuntime {
361
468
  // The native factory enters the exact child/owner pair before announcing
362
469
  // creation. Durable lineage and inherited persona never establish ownership.
363
470
  const parent = this.owner(agent);
364
- const admitted = this.bindChild(agent, parent) ?? this.current;
471
+ if (parent === undefined && agent.session.header?.origin === "subagent")
472
+ throw new DsmmProfileError("not-owned", "A child requires exact direct-parent admission, not current root defaults.");
473
+ if (parent !== undefined)
474
+ throw new DsmmProfileError("activation", "A retained child must complete role validation and authority registration before its settings are published.");
475
+ const admitted = this.current;
476
+ this.assertRootRole(agent, admitted.settings);
477
+ this.validateRootRole(agent, admitted);
365
478
  this.bound.set(agent, admitted);
366
- return admitted;
367
- }
368
- bindChild(agent, parent) {
369
- const retained = childAdmissions.get(agent);
370
- if (retained !== undefined) {
371
- const registry = this.agents();
372
- if (parent !== retained.parent || registry?.get !== undefined && (agent.id === undefined || registry.get(agent.id) !== agent)) {
373
- throw new DsmmProfileError("not-owned", "The retained child's exact live owner changed; its captured admission was not rebound.");
374
- }
479
+ try {
480
+ this.options.childAuthority?.registerParent(agent, admitted, this.options.childAuthorityOwner ?? this);
375
481
  }
376
- if (parent === undefined)
377
- return undefined;
378
- const admission = retained?.admission ?? this.bind(parent);
379
- this.bound.set(agent, admission);
380
- childAdmissions.set(agent, { parent, admission });
381
- return admission;
482
+ catch (error) {
483
+ this.bound.delete(agent);
484
+ throw error;
485
+ }
486
+ return admitted;
382
487
  }
383
488
  owner(agent) {
384
489
  const agents = this.agents();
@@ -395,12 +500,29 @@ export class DsmmProfileRuntime {
395
500
  throw new DsmmProfileError("not-owned", "Session profile selection requires the exact live ordinary root Agent.");
396
501
  }
397
502
  }
503
+ /** Host-only awaited completion for fresh, retained and cold exact Agents; no execution occurs here. */
504
+ async completeAdmission(agent, signal, startup) {
505
+ await this.admit(agent, signal, startup);
506
+ return this.bound.get(agent);
507
+ }
398
508
  async admit(agent, signal, startup) {
399
509
  if (this.bound.has(agent))
400
510
  return;
401
511
  const parent = this.owner(agent);
402
- if (this.bindChild(agent, parent) !== undefined)
512
+ if (parent !== undefined) {
513
+ this.assertDeliveryFence();
514
+ if (this.options.childAdmission === undefined)
515
+ throw new DsmmProfileError("unavailable", "Child admission completion is not installed; no child policy was inferred from its current parent.");
516
+ const ticket = this.options.childAuthority.acquireParentTicket(parent);
517
+ this.assertOwnedParentTicket(ticket);
518
+ const merged = AbortSignal.any([ticket.signal, ...signal === undefined ? [] : [signal]]);
519
+ const prepared = await this.options.childAdmission.prepare(agent, parent, ticket, merged);
520
+ merged.throwIfAborted();
521
+ await this.completeChildAdmission(agent, parent, prepared, merged);
403
522
  return;
523
+ }
524
+ if (agent.session.header?.origin === "subagent")
525
+ throw new DsmmProfileError("not-owned", "A child cannot be admitted as a new root without its exact live direct parent.");
404
526
  if (agent.id === undefined) {
405
527
  this.bind(agent);
406
528
  return;
@@ -420,29 +542,219 @@ export class DsmmProfileRuntime {
420
542
  const candidate = selection.admissionEpoch === null
421
543
  ? this.options.readDesired === undefined ? this.current : this.prepare(this.currentDocument, this.current, newEpoch(), "global-default", deployment)
422
544
  : this.prepare(selection.document, selection, selection.admissionEpoch, selection.selectedId === null ? "deployment-baseline" : "session-override", deployment);
545
+ this.assertRootRole(agent, candidate.settings);
546
+ this.validateRootRole(agent, candidate);
423
547
  if (this.options.readDesired !== undefined)
424
- await this.validate(candidate.settings, agent, signal, startup !== undefined);
548
+ await this.validate(candidate.settings);
425
549
  signal?.throwIfAborted();
426
550
  if (this.disposed || this.disposedAgents.has(agent))
427
551
  throw new DsmmProfileError("disposed", "The session was disposed during deployment admission.");
428
552
  if (registry?.get !== undefined && registry.get(agent.id) !== agent)
429
553
  throw new DsmmProfileError("not-owned", "The live session changed during deployment admission.");
554
+ this.assertRootRole(agent, candidate.settings);
555
+ this.validateRootRole(agent, candidate);
430
556
  this.bound.set(agent, candidate);
557
+ try {
558
+ this.options.childAuthority?.registerParent(agent, candidate, this.options.childAuthorityOwner ?? this);
559
+ }
560
+ catch (error) {
561
+ this.bound.delete(agent);
562
+ throw error;
563
+ }
564
+ await this.announceAdmission(agent);
565
+ signal?.throwIfAborted();
566
+ if (this.disposed || this.disposedAgents.has(agent))
567
+ throw new DsmmProfileError("disposed", "Root enrollment lost its live admission.");
568
+ if (registry?.get !== undefined && registry.get(agent.id) !== agent)
569
+ throw new DsmmProfileError("not-owned", "Root enrollment lost its exact residency.");
431
570
  }
432
571
  finally {
433
572
  this.admitting.delete(agent);
434
573
  }
435
574
  }
436
- async validate(settings, agent, signal, auditCatalog = true) {
575
+ /** Awaited native creation completion: evidence + persistence + role identity + exact-parent authority. */
576
+ async completeChildAdmission(agent, parent, prepared, signal) {
577
+ this.assertDeliveryFence();
578
+ if (this.options.childAdmission === undefined)
579
+ throw new DsmmProfileError("unavailable", "Child role validation is unavailable.");
580
+ const ticket = this.options.childAuthority.acquireParentTicket(parent);
581
+ this.assertOwnedParentTicket(ticket);
582
+ const merged = AbortSignal.any([ticket.signal, ...signal === undefined ? [] : [signal]]);
583
+ const evidence = "mode" in prepared.evidence ? parseLegacyChildEvidence(prepared.evidence) : parseChildAdmissionCapture(prepared.evidence);
584
+ const check = () => {
585
+ merged.throwIfAborted();
586
+ if (this.disposed || this.disposedAgents.has(agent) || this.owner(agent) !== parent || this.agents()?.get?.(agent.id) !== agent || this.agents()?.get?.(parent.id) !== parent || evidence.childSessionId !== agent.id || evidence.parentSessionId !== parent.id)
587
+ throw new DsmmProfileError("not-owned", "The exact child or its direct parent changed during admission.");
588
+ const current = this.options.childAuthority.acquireParentTicket(parent);
589
+ this.assertOwnedParentTicket(current);
590
+ if (current.admission !== ticket.admission || current.owner !== ticket.owner)
591
+ throw new DsmmProfileError("conflict", "The child creation parent ticket changed.");
592
+ };
593
+ check();
594
+ if (prepared.creation && "mode" in evidence)
595
+ throw new DsmmProfileError("validation", "New children require a full original capture, not legacy evidence.");
596
+ const original = "mode" in evidence ? prepared.admission : admissionFromChildCapture(evidence, this.baseline);
597
+ const retained = childAdmissions.get(agent);
598
+ if (retained !== undefined && retained.parent !== parent)
599
+ throw new DsmmProfileError("not-owned", "The retained child's exact direct parent changed.");
600
+ if (retained !== undefined && prepared.creation)
601
+ throw new DsmmProfileError("validation", "A retained child cannot be admitted as a new creation.");
602
+ if (retained !== undefined && JSON.stringify(retained.evidence) !== JSON.stringify(evidence))
603
+ throw new DsmmProfileError("corrupt-selection", "Retained child evidence cannot be replaced by a new parent policy.");
604
+ const admission = retained?.admission ?? freezeSettings({ ...original, baseline: original.settings,
605
+ selectedId: original.profile?.id ?? null, appliedRevision: original.profile?.revision ?? null, selectionRevision: "absent" });
606
+ if (!("mode" in evidence)) {
607
+ if (prepared.creation && evidence.originalAdmissionEpoch !== ticket.parentEpoch)
608
+ throw new DsmmProfileError("conflict", "The child creation invocation epoch changed.");
609
+ if (prepared.admission.epoch !== evidence.originalAdmissionEpoch || JSON.stringify(prepared.admission.profile) !== JSON.stringify(evidence.profilePin))
610
+ throw new DsmmProfileError("validation", "Child admission identity does not match its original capture.");
611
+ if (this.options.childCapturePersistence === "resident") {
612
+ if (!prepared.creation && retained === undefined)
613
+ throw new DsmmProfileError("unavailable", "Resident-only child capture has no cold restart guarantee.");
614
+ }
615
+ else {
616
+ if (this.childCaptureStore.readChildAdmission === undefined || this.childCaptureStore.createChildAdmission === undefined)
617
+ throw new DsmmProfileError("unavailable", "Durable child capture storage is unavailable.");
618
+ if (prepared.creation)
619
+ await this.childCaptureStore.createChildAdmission(evidence, check);
620
+ else {
621
+ const stored = await this.childCaptureStore.readChildAdmission(evidence.childSessionId, evidence.parentSessionId);
622
+ if (JSON.stringify(stored) !== JSON.stringify(evidence))
623
+ throw new DsmmProfileError("corrupt-selection", "The child evidence does not match its immutable stored capture.");
624
+ }
625
+ }
626
+ }
627
+ else {
628
+ if (prepared.admission.profile !== null)
629
+ throw new DsmmProfileError("validation", "Legacy admission cannot synthesize an original profile pin.");
630
+ if (this.childCaptureStore.readChildAdmission === undefined)
631
+ throw new DsmmProfileError("unavailable", "Legacy admission requires a safe capture-absence check.");
632
+ if (await this.childCaptureStore.readChildAdmission(evidence.childSessionId, evidence.parentSessionId) !== null)
633
+ throw new DsmmProfileError("corrupt-selection", "A captured child cannot be downgraded to legacy recovery.");
634
+ }
635
+ check();
636
+ this.options.childAdmission.validateRole(agent, parent, { ...prepared, evidence, admission, retained: retained !== undefined });
637
+ check();
638
+ this.bound.set(agent, admission);
639
+ try {
640
+ this.options.childAuthority.registerParent(agent, admission, this.options.childAuthorityOwner ?? this);
641
+ }
642
+ catch (error) {
643
+ this.bound.delete(agent);
644
+ throw error;
645
+ }
646
+ childAdmissions.set(agent, { parent, admission, evidence });
647
+ await this.announceAdmission(agent);
648
+ check();
649
+ }
650
+ /** C's scoped resolver callback: original resident/durable evidence, then explicit trusted legacy folds. */
651
+ async resolveOriginalChildEvidence(ticket, childId, signal, readLegacy) {
652
+ validateSessionProfileId(childId);
653
+ const merged = AbortSignal.any([ticket.signal, signal]);
654
+ const check = () => {
655
+ merged.throwIfAborted();
656
+ this.assertDeliveryFence();
657
+ if (this.disposed || this.disposedAgents.has(ticket.parent) || this.agents()?.get?.(ticket.parent.id) !== ticket.parent)
658
+ throw new DsmmProfileError("not-owned", "Original child evidence requires its exact live direct parent.");
659
+ const current = this.options.childAuthority.acquireParentTicket(ticket.parent);
660
+ this.assertOwnedParentTicket(current);
661
+ if (current.owner !== ticket.owner || current.admission !== ticket.admission || current.parentEpoch !== ticket.parentEpoch)
662
+ throw new DsmmProfileError("conflict", "The original child evidence ticket changed.");
663
+ };
664
+ check();
665
+ const child = this.agents().get(childId);
666
+ if (child !== undefined && this.owner(child) !== ticket.parent)
667
+ throw new DsmmProfileError("not-owned", "Original evidence is scoped to the actual direct child, not an ancestor.");
668
+ const retained = child === undefined ? undefined : childAdmissions.get(child);
669
+ if (retained !== undefined && retained.parent !== ticket.parent)
670
+ throw new DsmmProfileError("not-owned", "The retained evidence has a different exact parent.");
671
+ const checkChild = () => {
672
+ const current = this.agents().get(childId);
673
+ if (current !== undefined && this.owner(current) !== ticket.parent)
674
+ throw new DsmmProfileError("not-owned", "The addressed child's direct owner changed during evidence reading.");
675
+ if (retained !== undefined && (current !== child || childAdmissions.get(child) !== retained))
676
+ throw new DsmmProfileError("conflict", "The retained child residency changed during evidence reading.");
677
+ };
678
+ const stored = await this.childCaptureStore.readChildAdmission?.(childId, ticket.parent.id);
679
+ check();
680
+ checkChild();
681
+ if (stored !== undefined && stored !== null) {
682
+ const capture = parseChildAdmissionCapture(stored);
683
+ if (capture.childSessionId !== childId || capture.parentSessionId !== ticket.parent.id || retained !== undefined && JSON.stringify(retained.evidence) !== JSON.stringify(capture))
684
+ throw new DsmmProfileError("corrupt-selection", "Original child capture identity does not match its scoped residency.");
685
+ return capture;
686
+ }
687
+ if (retained !== undefined) {
688
+ if (!("mode" in retained.evidence)) {
689
+ if (this.options.childCapturePersistence !== "resident")
690
+ throw new DsmmProfileError("corrupt-selection", "The durable original child capture is missing; legacy recovery is not allowed.");
691
+ return retained.evidence;
692
+ }
693
+ if (stored === undefined)
694
+ throw new DsmmProfileError("unavailable", "Legacy evidence requires a safe capture-absence check.");
695
+ return retained.evidence;
696
+ }
697
+ if (stored === undefined || readLegacy === undefined)
698
+ throw new DsmmProfileError("unavailable", "Original capture is unavailable; only an explicit trusted legacy evidence reader can recover a captureless child.");
699
+ const evidence = parseLegacyChildEvidence(await readLegacy(ticket, childId, merged));
700
+ check();
701
+ checkChild();
702
+ if (evidence.childSessionId !== childId || evidence.parentSessionId !== ticket.parent.id)
703
+ throw new DsmmProfileError("not-owned", "Legacy evidence does not identify the addressed direct child.");
704
+ return evidence;
705
+ }
706
+ assertOwnedParentTicket(ticket) {
707
+ if (ticket.owner !== (this.options.childAuthorityOwner ?? this) || this.bound.get(ticket.parent) !== ticket.admission || ticket.parentEpoch !== ticket.admission.epoch)
708
+ throw new DsmmProfileError("not-owned", "Child admission requires this entry's exact completed parent admission and owner.");
709
+ }
710
+ subagentRuntimeView() {
711
+ const view = this.options.childAuthority?.view() ?? { binding: "unavailable", deliveryFenceReady: false, restartRequired: true, reason: "explicit-composition-required" };
712
+ if (view.binding === "dsmm" && view.deliveryFenceReady && (this.options.childAdmission === undefined || this.options.validateRootRole === undefined))
713
+ return { ...view, deliveryFenceReady: false, restartRequired: true, reason: "authority-not-ready" };
714
+ return view;
715
+ }
716
+ assertDeliveryFence() {
717
+ const view = this.subagentRuntimeView();
718
+ if (view.binding !== "dsmm" || !view.deliveryFenceReady || this.options.childAuthority === undefined)
719
+ throw new DsmmProfileError("unavailable", "This operation requires the explicit DSMM SubagentRuntime composition and ready Host admission authority; configure and restart before retrying.");
720
+ }
721
+ assertRootRole(agent, settings) {
722
+ const role = resolveSelectedAgentPreset(agent.session);
723
+ if (isDsmmRoleId(role) && (!settings.modules.deepwork.enabled || !settings.roles[role]))
724
+ throw new DsmmProfileError("activation", "The selected root role is disabled by the candidate admission.", `settings.roles.${role}`, "deployment-ceiling");
725
+ if (role === "dsmm-planner" && !settings.presets.plannerRootEnabled)
726
+ throw new DsmmProfileError("activation", "The Planner root preset is disabled in the startup admission.", "settings.presets.plannerRootEnabled", "deployment-ceiling");
727
+ }
728
+ validateRootRole(agent, admission) {
729
+ if (this.options.childAuthority !== undefined && this.options.validateRootRole === undefined)
730
+ throw new DsmmProfileError("unavailable", "Root role admission completion is unavailable; no direct-parent authority was registered.");
731
+ this.options.validateRootRole?.(agent, admission);
732
+ }
733
+ roleAvailability(settings, baseline, deployment, document) {
734
+ return DSMM_ROLES.map(role => {
735
+ const required = requiredReason(settings, role.id), named = document?.settings.roles?.[role.id];
736
+ const startup = this.baseline.roles[role.id], desired = deployment?.settings.roles[role.id] ?? baseline.roles[role.id];
737
+ const admitted = settings.modules.deepwork.enabled && settings.roles[role.id];
738
+ const reason = !settings.modules.deepwork.enabled ? "module-off" : !desired ? "deployment-disabled" : !startup ? "startup-unavailable" : named === false ? "profile-disabled" : undefined;
739
+ const startupCeiling = !startup && desired;
740
+ const source = named !== undefined ? "named-session" : startupCeiling ? this.options.startup?.sources[`roles.${role.id}`] ?? "defaults" : deployment?.sources[`roles.${role.id}`] ?? "defaults";
741
+ const capture = named !== undefined ? "named-session" : startupCeiling ? "startup" : "deployment";
742
+ return { id: role.id, required: required !== undefined, ...(required === undefined ? {} : { requiredReason: required }), startupAvailable: startup, deploymentEnabled: desired,
743
+ ...(named === undefined ? {} : { namedEnabled: named }), admitted, ...(reason === undefined ? {} : { reason }), source, capture };
744
+ });
745
+ }
746
+ async validate(settings, auditPresets = true) {
437
747
  if (!settings.modules.deepwork.enabled)
438
748
  return;
439
749
  if (this.options.validateCandidate !== undefined) {
440
750
  await this.options.validateCandidate(settings);
441
751
  return;
442
752
  }
753
+ if (!auditPresets)
754
+ return;
443
755
  const registry = this.ctx.get?.("agentPresets");
444
756
  if (registry !== undefined) {
445
- for (const role of DSMM_ROLES.filter((role) => isRootRole(role) && settings.roles[role.id])) {
757
+ for (const role of DSMM_ROLES.filter((role) => isRootRoleEnabled(settings, role.id))) {
446
758
  try {
447
759
  const preset = await registry.resolve(role.id);
448
760
  if (preset.broken !== undefined)
@@ -453,44 +765,6 @@ export class DsmmProfileRuntime {
453
765
  }
454
766
  }
455
767
  }
456
- // New-root capture validates deployment/schema and standing capability, not
457
- // dormant role routes. Actual root requests and role/alias preflight own
458
- // model selection. Named Apply and retained-root startup keep full audits.
459
- if (!auditCatalog)
460
- return;
461
- const nativeAgent = agent ?? (this.agents()?.list() ?? []).find((candidate) => candidate.ctx?.get?.("llm")?.resolveCallConfig !== undefined);
462
- const inherited = nativeAgent?.options;
463
- const inheritedRoute = inherited?.provider === undefined || inherited.model === undefined ? undefined
464
- : { provider: inherited.provider, model: inherited.model, ...(inherited.reasoningEffort === undefined ? {} : { reasoningEffort: inherited.reasoningEffort }) };
465
- const chains = [];
466
- for (const role of DSMM_ROLES) {
467
- if (!settings.roles[role.id])
468
- continue;
469
- const policy = resolveRoleRuntimePolicy(settings, role.id);
470
- // No explicit primary inherits native routing. Dormant fallbacks alone
471
- // cannot make a usable inherited route fail profile Apply. If that exact
472
- // route is unavailable here, native request preflight remains authority.
473
- if (policy.primary === undefined && inheritedRoute === undefined)
474
- continue;
475
- const routes = [policy.primary ?? inheritedRoute, ...policy.fallbackRoutes];
476
- if (routes.length > 0)
477
- chains.push({ routes, field: `settings.roleRouting.${role.id}.${policy.primary === undefined ? "fallbackRoutes" : "primary"}` });
478
- }
479
- if (chains.length === 0)
480
- return;
481
- const llm = nativeAgent?.ctx?.get?.("llm")
482
- ?? this.ctx.get?.("llm") ?? (this.ctx.get === undefined ? this.ctx.llm : undefined);
483
- if (llm?.resolveCallConfig === undefined) {
484
- throw new DsmmProfileError("activation", "Open a chat so its native model service can validate configured routes before applying this profile.");
485
- }
486
- for (const { routes, field } of chains) {
487
- try {
488
- await selectInitialModelRoute(llm, routes, signal);
489
- }
490
- catch {
491
- throw new DsmmProfileError("activation", "The configured provider, model or exact reasoning effort is unavailable in the native model catalog.", field);
492
- }
493
- }
494
768
  }
495
769
  }
496
770
  function newEpoch() { return createHash("sha256").update(randomUUID()).digest("hex"); }
@@ -516,7 +790,8 @@ export async function createProfileRuntime(ctx, baseline, options = {}) {
516
790
  // constructor path has one compatibility namespace, not a guessed entry.
517
791
  const entry = options.startup?.entryId ?? (ctx instanceof Context ? ctx.fiber.entry?.id : undefined) ?? "trusted-direct";
518
792
  const store = exists ? ProfileStore.fromLegacy(legacy) : ProfileStore.fromCentral(resolveDshHome(profile.home), profile.dir, entry);
519
- const runtime = new DsmmProfileRuntime(ctx, baseline, store, options);
793
+ const childCaptureStore = options.childCaptureStore ?? (exists ? ProfileStore.fromCentral(resolveDshHome(profile.home), profile.dir, entry) : store);
794
+ const runtime = new DsmmProfileRuntime(ctx, baseline, store, { ...options, childCaptureStore });
520
795
  await runtime.initialize();
521
796
  return runtime;
522
797
  }