@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
@@ -0,0 +1,335 @@
1
+ import { SubagentError } from "@deepseek-ai/dsh-subagent";
2
+ import { scopeLifetime } from "./delivery-authority.js";
3
+ import { isManagedCancellation } from "./agent-registry.js";
4
+ // Cancellation provenance belongs to each holder, not to a rejection's error code.
5
+ const cancelledDrains = new WeakSet();
6
+ function deferred() {
7
+ let resolve, reject;
8
+ const promise = new Promise((yes, no) => { resolve = yes; reject = no; });
9
+ // Holders remain observable even when a caller stops waiting after handoff.
10
+ void promise.catch(() => { });
11
+ return { promise, resolve, reject };
12
+ }
13
+ function terminalError(result) {
14
+ if (result.stopReason === "completed")
15
+ return undefined;
16
+ const partial = result.output.filter((block) => block.type === "text").map((block) => block.text).join("");
17
+ return new SubagentError(`subagent ${result.stopReason}${result.diagnostic === undefined ? "" : `: ${result.diagnostic}`}${partial === "" ? "" : `\nPartial output: ${partial}`}`, result.stopReason.toUpperCase());
18
+ }
19
+ function outcomeFailure(error) {
20
+ return error instanceof AggregateError ? [String(error), ...error.errors.map(outcomeFailure)].join("; ") : String(error);
21
+ }
22
+ /** One foreground call's real native run and its revocable caller-cancel relay. */
23
+ export class RoleRunHolder {
24
+ controller = new AbortController();
25
+ readyResult = deferred();
26
+ foregroundResult = deferred();
27
+ drainedResult = deferred();
28
+ currentState = "starting";
29
+ identity;
30
+ receipt;
31
+ outcome;
32
+ disposeActivation;
33
+ terminal = false;
34
+ finished = false;
35
+ registering = false;
36
+ committing = false;
37
+ detachParent = () => { };
38
+ callerRelay;
39
+ ready = this.readyResult.promise;
40
+ foreground = this.foregroundResult.promise;
41
+ /** Quiescence, preserving typed result and aggregate cleanup errors even in background. */
42
+ drained = this.drainedResult.promise;
43
+ request;
44
+ collaborators;
45
+ release;
46
+ constructor(request, collaborators, release) {
47
+ this.request = request;
48
+ this.collaborators = collaborators;
49
+ this.release = release;
50
+ this.callerRelay = () => {
51
+ // Native registration cannot fail after its synchronous starter returns.
52
+ // Contained registered-event reentrancy must not let the old caller kill
53
+ // work whose ownership has just committed to the native job.
54
+ if (!this.committing)
55
+ this.cancel(request.callerAbort.reason);
56
+ };
57
+ this.detachParent = scopeLifetime(request.parent.ctx, "dsmm.roleRun: exact parent lifetime", () => {
58
+ if (this.finished)
59
+ return;
60
+ collaborators.teardown.revokeParent(request.parent, "parent-disposed");
61
+ this.cancel(new SubagentError("DSMM run parent was disposed", "ABORTED"));
62
+ });
63
+ request.callerAbort.addEventListener("abort", this.callerRelay, { once: true });
64
+ if (request.callerAbort.aborted)
65
+ this.callerRelay();
66
+ void Promise.resolve().then(() => this.begin());
67
+ }
68
+ get state() { return this.currentState; }
69
+ get owner() { return this.request.owner; }
70
+ get sessionId() { return this.request.sessionId; }
71
+ get toolCallId() { return this.request.toolCallId; }
72
+ get invocation() { return this.identity; }
73
+ get holderSignal() { return this.controller.signal; }
74
+ cancel(reason) {
75
+ if (this.finished)
76
+ return;
77
+ if (!this.terminal)
78
+ this.currentState = "cancelled";
79
+ this.controller.abort(reason);
80
+ void this.disposeActivation?.().catch(() => { });
81
+ }
82
+ background(request) {
83
+ this.assertAddress(request);
84
+ this.assertAuthorization(request);
85
+ if (this.receipt !== undefined)
86
+ return { status: "already-background", receipt: this.receipt };
87
+ if (this.currentState === "cancelled")
88
+ return { status: "cancelled" };
89
+ if (this.terminal)
90
+ return { status: "already-settled" };
91
+ if (this.identity === undefined)
92
+ return { status: "starting" };
93
+ const jobs = this.request.jobs;
94
+ if (jobs === undefined)
95
+ throw new SubagentError("DSMM background requires native jobs and an owner controller", "UNSUPPORTED_CAPABILITY");
96
+ if (this.registering)
97
+ throw new SubagentError("DSMM background registration is already in progress", "UNAUTHORIZED");
98
+ this.registering = true;
99
+ try {
100
+ const jobId = jobs.start({ kind: "subagent", owner: this.request.parent.id, label: this.request.label, run: () => {
101
+ // This is the final, synchronous native-registration critical section.
102
+ this.assertAuthorization(request);
103
+ if (this.terminal || this.controller.signal.aborted)
104
+ throw new SubagentError("DSMM run is no longer transferable", "ABORTED");
105
+ this.committing = true;
106
+ return { cancel: (reason) => this.cancel(reason), done: this.outcome };
107
+ } });
108
+ this.receipt = Object.freeze({ kind: "background", jobId, invocation: this.identity });
109
+ this.request.callerAbort.removeEventListener("abort", this.callerRelay);
110
+ if (!this.controller.signal.aborted && !this.terminal)
111
+ this.currentState = "background";
112
+ this.foregroundResult.resolve(this.receipt);
113
+ return { status: "background", receipt: this.receipt };
114
+ }
115
+ finally {
116
+ this.committing = false;
117
+ this.registering = false;
118
+ // Preflight/authorization failure leaves cancellation and disposal owned
119
+ // by this foreground holder, including a caller abort during preflight.
120
+ if (this.receipt === undefined && this.request.callerAbort.aborted)
121
+ this.callerRelay();
122
+ }
123
+ }
124
+ assertAddress(address) {
125
+ if (address.parent !== this.request.parent || address.owner !== this.request.owner
126
+ || address.sessionId !== this.request.sessionId || address.toolCallId !== this.request.toolCallId
127
+ || (this.identity !== undefined && address.runId !== this.identity.runId)) {
128
+ throw new SubagentError("DSMM run requires exact parent, owner and invocation", "UNAUTHORIZED");
129
+ }
130
+ }
131
+ assertAuthorization(request) {
132
+ const epoch = this.collaborators.currentEpoch(request.parent, request.owner);
133
+ if (epoch !== request.expectedAdmissionEpoch)
134
+ throw new SubagentError("DSMM run admission epoch changed", "UNAUTHORIZED");
135
+ if (this.identity !== undefined && !this.collaborators.canBackground(request.parent, this.identity, epoch)) {
136
+ throw new SubagentError("DSMM background capability is disabled", "UNSUPPORTED_CAPABILITY");
137
+ }
138
+ if (this.collaborators.currentEpoch(request.parent, request.owner) !== epoch) {
139
+ throw new SubagentError("DSMM run admission changed during authorization", "UNAUTHORIZED");
140
+ }
141
+ }
142
+ async begin() {
143
+ try {
144
+ if (this.controller.signal.aborted) {
145
+ // No native starter has been invoked, so this is holder-owned cancellation.
146
+ cancelledDrains.add(this.drained);
147
+ this.controller.signal.throwIfAborted();
148
+ }
149
+ if (this.collaborators.currentEpoch(this.request.parent, this.request.owner) !== this.request.admissionEpoch) {
150
+ throw new SubagentError("DSMM run admission changed before start", "UNAUTHORIZED");
151
+ }
152
+ const run = await this.request.start(this.controller.signal);
153
+ this.identity = Object.freeze({ parent: this.request.parent, owner: this.request.owner,
154
+ sessionId: this.request.sessionId, toolCallId: this.request.toolCallId, runId: run.childId,
155
+ admissionEpoch: this.request.admissionEpoch, capture: this.request.capture, projection: this.request.projection,
156
+ mode: "one-shot", childId: run.childId });
157
+ if (!this.controller.signal.aborted)
158
+ this.currentState = "running";
159
+ let execution;
160
+ let disposal;
161
+ // Only this read/observer consumes the original native result. Settlement
162
+ // borrows its cached promise and a single disposer, not a replacement run.
163
+ const result = run.result.then((value) => {
164
+ execution = { status: "fulfilled", value };
165
+ this.observed(value.stopReason === "aborted");
166
+ return value;
167
+ }, (reason) => {
168
+ execution = { status: "rejected", reason };
169
+ this.observed(this.controller.signal.aborted);
170
+ throw reason;
171
+ });
172
+ let disposed;
173
+ const dispose = () => {
174
+ if (disposed !== undefined)
175
+ return disposed;
176
+ try {
177
+ disposed = this.collaborators.teardown.disposeRun(run);
178
+ }
179
+ catch (error) {
180
+ disposed = Promise.reject(error);
181
+ }
182
+ return disposed = disposed.then(() => { disposal = { status: "fulfilled", value: undefined }; }, (reason) => {
183
+ disposal = { status: "rejected", reason };
184
+ throw reason;
185
+ });
186
+ };
187
+ this.disposeActivation = dispose;
188
+ if (this.controller.signal.aborted)
189
+ void dispose().catch(() => { });
190
+ const settlement = (async () => {
191
+ await Promise.allSettled([result]);
192
+ await Promise.allSettled([dispose()]);
193
+ })();
194
+ this.outcome = settlement.then(() => {
195
+ const value = execution.status === "fulfilled" ? execution.value : undefined;
196
+ const failures = [execution, disposal].flatMap(result => result.status === "rejected" ? [outcomeFailure(result.reason)] : []);
197
+ return { status: disposal.status === "rejected" || execution.status === "rejected" ? "failed"
198
+ : value?.stopReason === "aborted" ? "killed" : value?.stopReason === "completed" ? "completed" : "failed",
199
+ ...(value === undefined ? {} : { result: value.output.filter(block => block.type === "text").map(block => block.text).join("") }),
200
+ detail: failures.length ? failures.join("; ") : value?.diagnostic ?? value?.stopReason };
201
+ });
202
+ if (this.controller.signal.aborted)
203
+ this.readyResult.reject(this.controller.signal.reason);
204
+ else
205
+ this.readyResult.resolve(this.identity);
206
+ await settlement;
207
+ const failure = execution.status === "rejected" ? execution.reason : terminalError(execution.value);
208
+ const failed = execution.status === "rejected" || failure !== undefined;
209
+ if (execution.status === "fulfilled" && execution.value.stopReason === "aborted" && disposal.status === "fulfilled") {
210
+ cancelledDrains.add(this.drained);
211
+ }
212
+ if (failed && disposal.status === "rejected")
213
+ throw new AggregateError([failure, disposal.reason], "DSMM subagent result and disposal failed");
214
+ if (execution.status === "rejected")
215
+ throw execution.reason;
216
+ if (failure !== undefined)
217
+ throw failure;
218
+ if (disposal.status === "rejected")
219
+ throw disposal.reason;
220
+ this.foregroundResult.resolve({ kind: "foreground", runId: run.childId, invocation: this.identity, output: execution.value.output });
221
+ this.drainedResult.resolve();
222
+ }
223
+ catch (error) {
224
+ if (isManagedCancellation(error))
225
+ cancelledDrains.add(this.drained);
226
+ this.observed(this.controller.signal.aborted);
227
+ this.readyResult.reject(error);
228
+ this.foregroundResult.reject(error);
229
+ this.drainedResult.reject(error);
230
+ }
231
+ finally {
232
+ this.finished = true;
233
+ this.request.callerAbort.removeEventListener("abort", this.callerRelay);
234
+ this.detachParent();
235
+ this.release();
236
+ }
237
+ }
238
+ observed(cancelled) {
239
+ if (this.terminal)
240
+ return;
241
+ this.terminal = true;
242
+ this.currentState = cancelled || this.controller.signal.aborted ? "cancelled" : "settled";
243
+ }
244
+ }
245
+ /** Current process-local calls only; native jobs remain the sole background registry. */
246
+ export class RoleRunRegistry {
247
+ calls = new Map();
248
+ closed = false;
249
+ collaborators;
250
+ /** ctx is the stable Host-owned scope, not a reinstalled profile entry. */
251
+ constructor(ctx, collaborators) {
252
+ this.collaborators = collaborators;
253
+ scopeLifetime(ctx, "dsmm.roleRuns: close Host admission", () => this.close("host-disposed"));
254
+ ctx.effect(() => () => this.drain(), "dsmm.roleRuns: drain native holders");
255
+ }
256
+ start(request) {
257
+ if (this.closed || request.sessionId !== request.parent.id)
258
+ throw new SubagentError("DSMM run requires a live exact session owner", "UNAUTHORIZED");
259
+ if (this.collaborators.currentEpoch(request.parent, request.owner) !== request.admissionEpoch) {
260
+ throw new SubagentError("DSMM run requires current admission", "UNAUTHORIZED");
261
+ }
262
+ let calls = this.calls.get(request.parent);
263
+ if (calls === undefined) {
264
+ calls = new Map();
265
+ this.calls.set(request.parent, calls);
266
+ }
267
+ if (calls.has(request.toolCallId))
268
+ throw new SubagentError("DSMM invocation is already held", "UNAUTHORIZED");
269
+ const entries = calls;
270
+ try {
271
+ const holder = new RoleRunHolder(request, this.collaborators, () => {
272
+ entries.delete(request.toolCallId);
273
+ if (entries.size === 0)
274
+ this.calls.delete(request.parent);
275
+ });
276
+ entries.set(request.toolCallId, holder);
277
+ return holder;
278
+ }
279
+ catch (error) {
280
+ if (entries.size === 0)
281
+ this.calls.delete(request.parent);
282
+ throw error;
283
+ }
284
+ }
285
+ /** Host-only lookup; C3 must authorize operator/session/epoch before exposing a view. */
286
+ get(parent, owner, address) {
287
+ this.collaborators.currentEpoch(parent, owner);
288
+ const holder = this.calls.get(parent)?.get(address.toolCallId);
289
+ const identity = holder?.invocation;
290
+ return identity?.owner === owner && identity.sessionId === address.sessionId && identity.runId === address.runId ? holder : undefined;
291
+ }
292
+ /** Host-only active-call inventory, including starting calls without invented run ids. */
293
+ list(parent, owner) {
294
+ this.collaborators.currentEpoch(parent, owner);
295
+ return [...this.calls.get(parent)?.values() ?? []].filter((holder) => holder.owner === owner);
296
+ }
297
+ /**
298
+ * Trusted parent teardown first revokes C1 authority, then awaits this before
299
+ * the original AgentHandle.dispose. Already-revoked tickets are not reacquired.
300
+ */
301
+ async drainParent(parent, owner, reason) {
302
+ const holders = [...this.calls.get(parent)?.values() ?? []];
303
+ // Trusted teardown may have already revoked the C1 ticket. Match the exact
304
+ // held parent/entry owner, rather than reacquiring revoked admission.
305
+ if (holders.some((holder) => holder.owner !== owner))
306
+ throw new SubagentError("DSMM run drain requires exact owner", "UNAUTHORIZED");
307
+ if (holders.length === 0)
308
+ return;
309
+ this.collaborators.teardown.revokeParent(parent, reason);
310
+ for (const holder of holders)
311
+ holder.cancel(new SubagentError("DSMM run owner was disposed", "ABORTED"));
312
+ await this.awaitHolders(holders);
313
+ }
314
+ close(reason) {
315
+ this.closed = true;
316
+ for (const [parent, calls] of this.calls) {
317
+ this.collaborators.teardown.revokeParent(parent, reason);
318
+ for (const holder of calls.values())
319
+ holder.cancel(new SubagentError("DSMM run Host was disposed", "ABORTED"));
320
+ }
321
+ }
322
+ async drain() {
323
+ await this.awaitHolders([...this.calls.values()].flatMap((calls) => [...calls.values()]));
324
+ }
325
+ async awaitHolders(holders) {
326
+ const results = await Promise.allSettled(holders.map((holder) => holder.drained));
327
+ // Native cancellation is successful teardown; infrastructure/cleanup faults
328
+ // remain errors and are never relabeled as ordinary cancellation.
329
+ const errors = results.flatMap((result, index) => result.status === "rejected"
330
+ && !cancelledDrains.has(holders[index].drained) ? [result.reason] : []);
331
+ if (errors.length > 0)
332
+ throw new AggregateError(errors, "DSMM native run drain failed");
333
+ }
334
+ }
335
+ //# sourceMappingURL=role-runs.js.map
@@ -1,10 +1,65 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
- import type { DshContext } from "./dsh-types.js";
2
+ import type { Agent } from "@deepseek-ai/dsh-agent";
3
+ import type { ToolRuntime } from "@deepseek-ai/dsh-tools";
4
+ import type { DshAgent, DshContext } from "./dsh-types.js";
5
+ import type { DsmmRoleId } from "./roles.js";
3
6
  import { DsmmRolePolicy } from "./role-policy.js";
4
- import type { DsmmSettingsGetter } from "./settings.js";
7
+ import type { DsmmSettings, DsmmSettingsGetter, DsmmProfileAdmission, DsmmModelRoute } from "./settings.js";
5
8
  import type { DeepworkModeController } from "./state.js";
9
+ import type { DsmmInvocationView } from "./profile-types.js";
10
+ import type { ResolvedRoleInvocation } from "./role-invocation.js";
11
+ import type { RoleRunRegistry } from "./role-runs.js";
6
12
  /** Keep native controls on the frozen startup substrate, not desired-save reconciliation. */
7
13
  export declare function registerNativeSubagentControls(ctx: Context): Promise<void>;
14
+ /** C's same-run holder/live projection can read the actual lock without reapplying defaults. */
15
+ export declare function roleInvocationView(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], getSettings: DsmmSettingsGetter, child?: DshAgent, ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): DsmmInvocationView;
16
+ /** Initial preflight/lock is not an observed SDK request; keep E's distinction truthful. */
17
+ export declare function roleInvocationObservation(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], getSettings: DsmmSettingsGetter, child?: DshAgent, ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): {
18
+ view: DsmmInvocationView;
19
+ routeKind: "initial" | "actual";
20
+ };
21
+ export type DsmmInitialRoleRoute = {
22
+ readonly status: "known";
23
+ readonly source: "invocation-capture";
24
+ readonly route: Readonly<DsmmModelRoute>;
25
+ } | {
26
+ readonly status: "unknown";
27
+ readonly reason: "missing-invocation-capture";
28
+ };
29
+ export type DsmmLiveRoleRoute = {
30
+ readonly status: "known";
31
+ readonly source: "own-native-request-header";
32
+ readonly route: Readonly<DsmmModelRoute>;
33
+ } | {
34
+ readonly status: "unknown";
35
+ readonly reason: "no-own-request-header" | "invalid-own-request-header";
36
+ };
37
+ export interface DsmmRoleRouteComparison {
38
+ readonly childId: string;
39
+ readonly initialRoute: DsmmInitialRoleRoute;
40
+ readonly liveRoute: DsmmLiveRoleRoute;
41
+ }
42
+ /** Both observations belong to this exact native Agent; no parent/settings/route-lock fallback. */
43
+ export declare function roleRouteComparison(child: Agent): DsmmRoleRouteComparison;
44
+ export interface DsmmRoleRunCapture {
45
+ readonly invocation: ResolvedRoleInvocation;
46
+ readonly admission: DsmmProfileAdmission;
47
+ }
48
+ /** Created on the parent's stable Host scope, never per profile entry or tool call. */
49
+ export interface DsmmRoleRunsBinding {
50
+ readonly registry: RoleRunRegistry<DsmmRoleRunCapture, DsmmInvocationView>;
51
+ readonly owner: object;
52
+ }
53
+ export interface DsmmCallableEntry {
54
+ name: string;
55
+ kind: "role" | "category";
56
+ targets: readonly DsmmRoleId[];
57
+ targetParameter?: "role" | "category";
58
+ }
59
+ /** Shared by runtime registration and the prompt assembler; empty groups have no callable entry. */
60
+ export declare function callableRoleInventory(settings: DsmmSettings, targets: readonly DsmmRoleId[]): readonly DsmmCallableEntry[];
61
+ /** Exact currently exposed definitions, suitable for E's runtime guidance and safe capability views. */
62
+ export declare function admittedCallableRoleInventory(agent: DshAgent, settings: DsmmSettings, policy: DsmmRolePolicy, tools: ToolRuntime): readonly DsmmCallableEntry[];
8
63
  /** Published name retained; all native/headless Agents consume one admitted policy. */
9
- export declare function registerHeadlessRoleTools(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, policy?: DsmmRolePolicy): Promise<void>;
64
+ export declare function registerHeadlessRoleTools(ctx: DshContext, controller: DeepworkModeController, getSettings: DsmmSettingsGetter, policy?: DsmmRolePolicy, roleRuns?: DsmmRoleRunsBinding): Promise<void>;
10
65
  //# sourceMappingURL=role-subagents.d.ts.map