@dsmm/dsmm 0.3.0 → 0.3.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 (245) hide show
  1. package/README.md +26 -40
  2. package/cordis.patch.yml +9 -13
  3. package/docs/agent-presets.md +26 -14
  4. package/docs/compatibility.md +24 -68
  5. package/docs/deferred-native-approval-risk.md +8 -12
  6. package/docs/design.md +25 -254
  7. package/docs/lsp.md +2 -2
  8. package/docs/migration-from-ocmm.md +38 -51
  9. package/docs/model-routing.md +21 -21
  10. package/docs/native-permissions.md +17 -7
  11. package/docs/profiles.md +13 -9
  12. package/docs/releasing.md +25 -311
  13. package/docs/roadmap.md +52 -241
  14. package/docs/runtime-recovery.md +29 -91
  15. package/docs/safety-guards.md +19 -16
  16. package/docs/settings-status.md +23 -11
  17. package/docs/skill-sync.md +17 -17
  18. package/docs/web-fetch-fakeip.md +82 -0
  19. package/lib/child-capture.d.ts +12 -2
  20. package/lib/child-capture.js +22 -5
  21. package/lib/client/ChildPermissions.d.ts +43 -0
  22. package/lib/client/ChildPermissions.js +100 -0
  23. package/lib/client/ChildrenPanel.d.ts +5 -5
  24. package/lib/client/ChildrenPanel.js +6 -18
  25. package/lib/client/DeploymentFields.d.ts +32 -0
  26. package/lib/client/DeploymentFields.js +70 -0
  27. package/lib/client/DeploymentPage.d.ts +21 -6
  28. package/lib/client/DeploymentPage.js +80 -112
  29. package/lib/client/HistoryContinuation.d.ts +7 -0
  30. package/lib/client/HistoryContinuation.js +22 -0
  31. package/lib/client/NativeCommandEntries.d.ts +17 -0
  32. package/lib/client/NativeCommandEntries.js +68 -0
  33. package/lib/client/PermissionPanelEntry.d.ts +8 -0
  34. package/lib/client/PermissionPanelEntry.js +11 -0
  35. package/lib/client/PermissionsPanel.d.ts +3 -1
  36. package/lib/client/PermissionsPanel.js +10 -9
  37. package/lib/client/ProfilesSection.js +8 -6
  38. package/lib/client/RoleAvailability.js +1 -1
  39. package/lib/client/RoleToolView-data.d.ts +35 -0
  40. package/lib/client/RoleToolView-data.js +52 -0
  41. package/lib/client/RoleToolView-locales.d.ts +36 -0
  42. package/lib/client/RoleToolView-locales.js +20 -0
  43. package/lib/client/RoleToolView.d.ts +10 -0
  44. package/lib/client/RoleToolView.js +47 -0
  45. package/lib/client/SessionProfiles.js +51 -24
  46. package/lib/client/TemporaryPermissions.d.ts +21 -0
  47. package/lib/client/TemporaryPermissions.js +94 -0
  48. package/lib/client/children-controller.d.ts +2 -8
  49. package/lib/client/children-controller.js +1 -26
  50. package/lib/client/children-locales.d.ts +27 -52
  51. package/lib/client/children-locales.js +8 -12
  52. package/lib/client/configuration-display.d.ts +5 -0
  53. package/lib/client/configuration-display.js +11 -0
  54. package/lib/client/controller.d.ts +18 -0
  55. package/lib/client/controller.js +118 -28
  56. package/lib/client/deployment-controller.d.ts +13 -1
  57. package/lib/client/deployment-controller.js +84 -24
  58. package/lib/client/deployment-data.d.ts +1 -0
  59. package/lib/client/deployment-data.js +4 -1
  60. package/lib/client/deployment-locales.d.ts +43 -0
  61. package/lib/client/deployment-locales.js +45 -19
  62. package/lib/client/deployment-modules.d.ts +9 -0
  63. package/lib/client/deployment-modules.js +24 -0
  64. package/lib/client/deployment-workspace.d.ts +48 -0
  65. package/lib/client/deployment-workspace.js +123 -0
  66. package/lib/client/history-controller.d.ts +29 -0
  67. package/lib/client/history-controller.js +111 -0
  68. package/lib/client/history-entry.d.ts +11 -0
  69. package/lib/client/history-entry.js +106 -0
  70. package/lib/client/history-locales.d.ts +95 -0
  71. package/lib/client/history-locales.js +41 -0
  72. package/lib/client/index.js +26 -76
  73. package/lib/client/locales.d.ts +13 -0
  74. package/lib/client/locales.js +104 -86
  75. package/lib/client/permission-controller.d.ts +1 -0
  76. package/lib/client/permission-controller.js +3 -2
  77. package/lib/client/permission-locales.d.ts +51 -0
  78. package/lib/client/permission-locales.js +59 -19
  79. package/lib/client/session-labels.js +4 -3
  80. package/lib/client/styles.d.ts +1 -1
  81. package/lib/client/styles.js +9 -8
  82. package/lib/client/temporary-permission-client.d.ts +20 -0
  83. package/lib/client/temporary-permission-client.js +52 -0
  84. package/lib/client/temporary-permission-entry.d.ts +6 -0
  85. package/lib/client/temporary-permission-entry.js +56 -0
  86. package/lib/client.js +5691 -3439
  87. package/lib/commands.js +2 -0
  88. package/lib/config-file-store.d.ts +3 -0
  89. package/lib/config-file-store.js +4 -2
  90. package/lib/config-revision.d.ts +5 -0
  91. package/lib/config-revision.js +11 -0
  92. package/lib/core-permission-authority.js +11 -41
  93. package/lib/deployment-config.d.ts +9 -2
  94. package/lib/deployment-config.js +35 -8
  95. package/lib/deployment-permission-rules.js +19 -7
  96. package/lib/dsh-types.d.ts +1 -1
  97. package/lib/history-candidates.d.ts +30 -0
  98. package/lib/history-candidates.js +176 -0
  99. package/lib/history-codec.d.ts +11 -0
  100. package/lib/history-codec.js +102 -0
  101. package/lib/history-contract.d.ts +44 -0
  102. package/lib/history-contract.js +2 -0
  103. package/lib/history-controller.d.ts +42 -0
  104. package/lib/history-controller.js +329 -0
  105. package/lib/history-policy.d.ts +4 -0
  106. package/lib/history-policy.js +8 -0
  107. package/lib/history-remote.d.ts +28 -0
  108. package/lib/history-remote.js +17 -0
  109. package/lib/history-rpc.d.ts +24 -0
  110. package/lib/history-rpc.js +136 -0
  111. package/lib/history-support.d.ts +15 -0
  112. package/lib/history-support.js +21 -0
  113. package/lib/history-types.d.ts +67 -0
  114. package/lib/history-types.js +2 -0
  115. package/lib/host-llm-startup.js +3 -3
  116. package/lib/host-llm.d.ts +9 -3
  117. package/lib/host-llm.js +48 -8
  118. package/lib/index.d.ts +18 -20
  119. package/lib/index.js +147 -415
  120. package/lib/lifetime.d.ts +4 -0
  121. package/lib/lifetime.js +22 -0
  122. package/lib/live-pi-ai-owner.d.ts +1 -0
  123. package/lib/live-pi-ai-owner.js +8 -4
  124. package/lib/mode.d.ts +3 -2
  125. package/lib/mode.js +28 -41
  126. package/lib/model-routing.d.ts +2 -8
  127. package/lib/model-routing.js +59 -175
  128. package/lib/native-admission.d.ts +77 -0
  129. package/lib/native-admission.js +503 -0
  130. package/lib/native-pi-ai-wire.d.ts +3 -1
  131. package/lib/native-pi-ai-wire.js +47 -13
  132. package/lib/permission-child-control.d.ts +36 -0
  133. package/lib/permission-child-control.js +164 -0
  134. package/lib/permission-control.d.ts +2 -3
  135. package/lib/permission-control.js +7 -0
  136. package/lib/permission-controller.js +2 -2
  137. package/lib/permission-exec-argv.d.ts +32 -0
  138. package/lib/permission-exec-argv.js +171 -0
  139. package/lib/permission-fs-search.js +2 -1
  140. package/lib/permission-fs.js +2 -1
  141. package/lib/permission-native-rules.js +3 -3
  142. package/lib/permission-temporary-files.d.ts +19 -0
  143. package/lib/permission-temporary-files.js +248 -0
  144. package/lib/permission-temporary-grants.d.ts +106 -0
  145. package/lib/permission-temporary-grants.js +198 -0
  146. package/lib/permission-temporary-install.d.ts +25 -0
  147. package/lib/permission-temporary-install.js +86 -0
  148. package/lib/permission-temporary-remote.d.ts +19 -0
  149. package/lib/permission-temporary-remote.js +75 -0
  150. package/lib/permission-temporary-rpc.d.ts +37 -0
  151. package/lib/permission-temporary-rpc.js +154 -0
  152. package/lib/permission-temporary-types.d.ts +47 -0
  153. package/lib/permission-temporary-types.js +2 -0
  154. package/lib/permission-temporary-web.d.ts +11 -0
  155. package/lib/permission-temporary-web.js +154 -0
  156. package/lib/permission-web.js +2 -1
  157. package/lib/preset-registry.js +3 -2
  158. package/lib/preset-skills.d.ts +3 -12
  159. package/lib/preset-skills.js +28 -58
  160. package/lib/profile-diagnostics.d.ts +1 -1
  161. package/lib/profile-diagnostics.js +2 -2
  162. package/lib/profile-remote.js +61 -22
  163. package/lib/profile-rpc.d.ts +4 -3
  164. package/lib/profile-rpc.js +35 -37
  165. package/lib/profile-runtime.d.ts +42 -74
  166. package/lib/profile-runtime.js +314 -617
  167. package/lib/profile-store.d.ts +20 -8
  168. package/lib/profile-store.js +112 -63
  169. package/lib/profile-types.d.ts +19 -4
  170. package/lib/profiles.d.ts +3 -1
  171. package/lib/profiles.js +9 -7
  172. package/lib/prompt-content.d.ts +1 -0
  173. package/lib/prompt-content.js +4 -1
  174. package/lib/prompts.d.ts +2 -12
  175. package/lib/prompts.js +11 -66
  176. package/lib/role-control-remote.d.ts +1 -4
  177. package/lib/role-control-remote.js +8 -36
  178. package/lib/role-control-rpc.d.ts +10 -36
  179. package/lib/role-control-rpc.js +112 -269
  180. package/lib/role-control-types.d.ts +3 -26
  181. package/lib/role-control-types.js +3 -4
  182. package/lib/role-identity.d.ts +5 -0
  183. package/lib/role-identity.js +10 -0
  184. package/lib/role-invocation.d.ts +3 -3
  185. package/lib/role-invocation.js +2 -2
  186. package/lib/role-llm-runtime.js +5 -11
  187. package/lib/role-policy.d.ts +19 -50
  188. package/lib/role-policy.js +136 -508
  189. package/lib/role-providers.d.ts +5 -8
  190. package/lib/role-providers.js +20 -86
  191. package/lib/role-routing.d.ts +1 -3
  192. package/lib/role-routing.js +24 -34
  193. package/lib/role-subagents.d.ts +5 -14
  194. package/lib/role-subagents.js +163 -108
  195. package/lib/runtime-integration.d.ts +5 -78
  196. package/lib/runtime-integration.js +11 -697
  197. package/lib/session-metadata.d.ts +13 -12
  198. package/lib/session-metadata.js +6 -31
  199. package/lib/session-scope.js +2 -1
  200. package/lib/settings.d.ts +5 -18
  201. package/lib/settings.js +19 -43
  202. package/lib/skills.d.ts +1 -0
  203. package/lib/skills.js +5 -1
  204. package/lib/state.d.ts +3 -2
  205. package/lib/state.js +26 -10
  206. package/lib/status.d.ts +1 -9
  207. package/lib/status.js +3 -55
  208. package/lib/web-fetch-address-policy.d.ts +24 -0
  209. package/lib/web-fetch-address-policy.js +189 -0
  210. package/lib/web-fetch-fakeip.d.ts +25 -0
  211. package/lib/web-fetch-fakeip.js +107 -0
  212. package/package.json +124 -106
  213. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +13291 -0
  214. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +9133 -0
  215. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +156 -0
  216. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +3546 -0
  217. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +431 -0
  218. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +119 -0
  219. package/patches/dsh-approval-settlement/README.md +41 -0
  220. package/patches/dsh-approval-settlement/metadata.json +10 -0
  221. package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +383 -0
  222. package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +55 -0
  223. package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +16673 -0
  224. package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +29 -0
  225. package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +196 -0
  226. package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +35 -0
  227. package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +40 -0
  228. package/docs/research/deepseek-v4-pro.md +0 -74
  229. package/docs/research/oh-dsh.md +0 -96
  230. package/lib/agent-registry.d.ts +0 -36
  231. package/lib/agent-registry.js +0 -75
  232. package/lib/child-admission.d.ts +0 -40
  233. package/lib/child-admission.js +0 -151
  234. package/lib/delivery-authority.d.ts +0 -83
  235. package/lib/delivery-authority.js +0 -397
  236. package/lib/native-child-evidence.d.ts +0 -40
  237. package/lib/native-child-evidence.js +0 -104
  238. package/lib/role-runs.d.ts +0 -138
  239. package/lib/role-runs.js +0 -335
  240. package/lib/session-persistence.d.ts +0 -36
  241. package/lib/session-persistence.js +0 -304
  242. package/lib/subagent-runtime.d.ts +0 -57
  243. package/lib/subagent-runtime.js +0 -257
  244. package/prompts/deepseek-flash.md +0 -11
  245. package/prompts/deepseek-v4-pro.md +0 -14
@@ -1,104 +0,0 @@
1
- import { symbols } from "@deepseek-ai/cordis";
2
- import { SessionId } from "@deepseek-ai/dsh-session";
3
- import { foldSubagentDescriptor, SubagentError } from "@deepseek-ai/dsh-subagent";
4
- import { freezeSettings } from "./settings.js";
5
- import { isDsmmRoleId } from "./roles.js";
6
- function unauthorized() { throw new SubagentError("Child history does not prove its direct native identity", "UNAUTHORIZED"); }
7
- /** Exact public catalog and replay-validated physical cuts; never resumes an Agent. */
8
- export class NativeChildEvidenceReader {
9
- ctx;
10
- assertTicket;
11
- history;
12
- constructor(ctx, assertTicket, history) {
13
- this.ctx = ctx;
14
- this.assertTicket = assertTicket;
15
- this.history = history;
16
- }
17
- async read(ticket, childId, callerSignal) {
18
- const signal = AbortSignal.any([ticket.signal, callerSignal]);
19
- const check = () => {
20
- signal.throwIfAborted();
21
- this.assertTicket(ticket);
22
- const current = this.ctx.get("sessionQuery");
23
- if (current === undefined || (Reflect.get(current, symbols.original) ?? current) !== (Reflect.get(this.history, symbols.original) ?? this.history))
24
- unauthorized();
25
- };
26
- check();
27
- if (this.ctx.agents.get(ticket.parent.id) !== ticket.parent || childId === ticket.parent.id)
28
- unauthorized();
29
- const rows = await this.ctx.subagents.listChildren(ticket.parent.id, signal);
30
- check();
31
- const matches = rows.filter(row => row.id === childId);
32
- if (matches.length !== 1 || matches[0].mode !== "continuable")
33
- unauthorized();
34
- const observation = await this.history.observeSession(SessionId(childId), { signal, projectionMode: "none" });
35
- try {
36
- check();
37
- const facts = readFacts(ticket.parent, childId, observation);
38
- const catalog = matches[0];
39
- if (catalog.createdAt !== observation.header.createdAt || catalog.mode !== facts.descriptor.mode || catalog.label !== facts.descriptor.label)
40
- unauthorized();
41
- check();
42
- return facts;
43
- }
44
- finally {
45
- observation[Symbol.dispose]();
46
- }
47
- }
48
- }
49
- function readFacts(parent, childId, observation) {
50
- const header = observation.header;
51
- if (header.version !== 4 || header.id !== childId || header.parentSession !== parent.id || header.origin !== "subagent"
52
- || !Number.isSafeInteger(header.delegationDepth) || header.delegationDepth <= (parent.session.header.delegationDepth ?? 0)
53
- || typeof header.cwd !== "string")
54
- unauthorized();
55
- const inherited = observation.inheritedEventCount;
56
- if (!Number.isSafeInteger(inherited) || inherited < 0 || inherited > observation.events.length)
57
- unauthorized();
58
- const own = observation.events.slice(inherited);
59
- // The catalog projection is display data; a second descriptor cannot replace the establishing composition.
60
- if (own.filter(event => event.type === "subagent/descriptor").length !== 1)
61
- unauthorized();
62
- const descriptor = foldSubagentDescriptor(own);
63
- if (descriptor?.mode !== "continuable" || !descriptor.provider.startsWith("dsmm-role-"))
64
- unauthorized();
65
- const role = `dsmm-${descriptor.provider.slice("dsmm-role-".length)}`;
66
- if (!isDsmmRoleId(role) || role === "dsmm-orchestrator" || descriptor.agentProvider === undefined || descriptor.agentModel === undefined)
67
- unauthorized();
68
- let active;
69
- for (const event of own) {
70
- if (event.type === "dsmm/role-policy") {
71
- const data = event.data;
72
- if (data === null || typeof data !== "object" || Array.isArray(data) || Object.keys(data).length !== 3
73
- || data.version !== 1 || data.role !== role || data.policy !== null && (typeof data.policy !== "string" || !/^[a-f0-9]{64}$/u.test(data.policy)))
74
- unauthorized();
75
- }
76
- else if (event.type === "deepwork/mode") {
77
- const data = event.data;
78
- if (data === null || typeof data !== "object" || Array.isArray(data) || Object.keys(data).length !== 1 || typeof data.active !== "boolean")
79
- unauthorized();
80
- active = data.active;
81
- }
82
- }
83
- return freezeSettings({ childSessionId: childId, parentSessionId: parent.id, depth: header.delegationDepth, role, descriptor,
84
- ...(active === undefined ? {} : { active }), requestBudgetObserved: own.some(hasRequestBudget) });
85
- }
86
- function hasRequestBudget(event) {
87
- if (event.type !== "request/header")
88
- return false;
89
- return event.data.header.config.maxTokens !== undefined;
90
- }
91
- /** Capture evidence must agree with the child's establishing descriptor, not current parent routing. */
92
- export function assertNativeChildCapture(capture, facts) {
93
- const route = capture.invocation.initialRoute, descriptor = facts.descriptor;
94
- if (capture.childSessionId !== facts.childSessionId || capture.parentSessionId !== facts.parentSessionId || capture.role !== facts.role
95
- || facts.depth > capture.authorityCeiling.maxDepth || descriptor.agentProvider !== route.provider || descriptor.agentModel !== route.model
96
- || descriptor.agentReasoningEffort !== route.reasoningEffort)
97
- unauthorized();
98
- const ceiling = capture.authorityCeiling.toolFilter, native = descriptor.toolFilter;
99
- if (native?.allow !== undefined && (ceiling?.allow === undefined || ceiling.allow.some(name => !native.allow.includes(name))))
100
- unauthorized();
101
- if (native?.deny?.some(name => ceiling?.allow?.includes(name) || ceiling?.allow === undefined && !ceiling?.deny?.includes(name)))
102
- unauthorized();
103
- }
104
- //# sourceMappingURL=native-child-evidence.js.map
@@ -1,138 +0,0 @@
1
- import type { Context } from "@deepseek-ai/cordis";
2
- import type { Agent } from "@deepseek-ai/dsh-agent";
3
- import type { ContentBlock, ToolCallId } from "@deepseek-ai/dsh-llm";
4
- import type { SessionId } from "@deepseek-ai/dsh-session";
5
- import type { SubagentActivation } from "@deepseek-ai/dsh-subagent";
6
- import type { JobRegistry } from "@deepseek-ai/dsh-jobs";
7
- declare module "@deepseek-ai/dsh-jobs/view" {
8
- interface JobKindMap {
9
- subagent: "subagent";
10
- }
11
- }
12
- export type RoleRunState = "starting" | "running" | "background" | "settled" | "cancelled";
13
- export type RoleRunJobId = ReturnType<JobRegistry["start"]>;
14
- export interface RoleRunAddress {
15
- readonly sessionId: SessionId;
16
- readonly toolCallId: ToolCallId;
17
- /** Public role-run address is the activation childId, never lifecycle-event runId. */
18
- readonly runId: SubagentActivation["childId"];
19
- }
20
- /** Host-only identity. Capture/projection are the borrowed original admitted objects. */
21
- export interface RoleRunInvocation<C = unknown, P = unknown> extends RoleRunAddress {
22
- readonly parent: Agent;
23
- readonly owner: object;
24
- readonly admissionEpoch: string;
25
- readonly capture: C;
26
- readonly projection: P;
27
- readonly mode: "one-shot";
28
- readonly childId?: SessionId;
29
- }
30
- export interface RoleRunForeground<C = unknown, P = unknown> {
31
- readonly kind: "foreground";
32
- readonly runId: SubagentActivation["childId"];
33
- readonly invocation: RoleRunInvocation<C, P>;
34
- readonly output: readonly ContentBlock[];
35
- }
36
- export interface RoleRunBackground<C = unknown, P = unknown> {
37
- readonly kind: "background";
38
- readonly jobId: RoleRunJobId;
39
- readonly invocation: RoleRunInvocation<C, P>;
40
- }
41
- export type RoleRunTransition<C = unknown, P = unknown> = {
42
- readonly status: "background" | "already-background";
43
- readonly receipt: RoleRunBackground<C, P>;
44
- } | {
45
- readonly status: "already-settled" | "starting" | "cancelled";
46
- };
47
- export interface RoleRunBackgroundRequest extends RoleRunAddress {
48
- readonly parent: Agent;
49
- readonly owner: object;
50
- readonly expectedAdmissionEpoch: string;
51
- }
52
- export interface RoleRunTeardown {
53
- /** Supply the stable Host authority's revokeParent, never an epoch-only abort. */
54
- revokeParent(agent: Agent, reason: string): void;
55
- /** Invoke the exact activation disposer, whose runtime boundary revokes its tree. */
56
- disposeRun(run: SubagentActivation): Promise<void>;
57
- }
58
- export interface RoleRunCollaborators<C = unknown, P = unknown> {
59
- /** Synchronous exact-parent/entry-owner check plus the current stable epoch. */
60
- currentEpoch(parent: Agent, owner: object): string;
61
- /** Trusted admission/operator adapter; no UI/RPC protocol is synthesized here. */
62
- canBackground(parent: Agent, identity: RoleRunInvocation<C, P>, currentEpoch: string): boolean;
63
- readonly teardown: RoleRunTeardown;
64
- }
65
- export interface RoleRunStart<C = unknown, P = unknown> {
66
- readonly parent: Agent;
67
- readonly owner: object;
68
- readonly sessionId: SessionId;
69
- readonly toolCallId: ToolCallId;
70
- readonly admissionEpoch: string;
71
- readonly capture: C;
72
- readonly projection: P;
73
- readonly label: string;
74
- readonly callerAbort: AbortSignal;
75
- readonly jobs?: JobRegistry;
76
- /** Call native startActivation exactly once, forwarding this holder signal. */
77
- start(signal: AbortSignal): Promise<SubagentActivation>;
78
- }
79
- /** One foreground call's real native run and its revocable caller-cancel relay. */
80
- export declare class RoleRunHolder<C = unknown, P = unknown> {
81
- private readonly controller;
82
- private readonly readyResult;
83
- private readonly foregroundResult;
84
- private readonly drainedResult;
85
- private currentState;
86
- private identity?;
87
- private receipt?;
88
- private outcome?;
89
- private disposeActivation?;
90
- private terminal;
91
- private finished;
92
- private registering;
93
- private committing;
94
- private detachParent;
95
- private readonly callerRelay;
96
- readonly ready: Promise<RoleRunInvocation<C, P>>;
97
- readonly foreground: Promise<RoleRunBackground<C, P> | RoleRunForeground<C, P>>;
98
- /** Quiescence, preserving typed result and aggregate cleanup errors even in background. */
99
- readonly drained: Promise<void>;
100
- private readonly request;
101
- private readonly collaborators;
102
- private readonly release;
103
- constructor(request: RoleRunStart<C, P>, collaborators: RoleRunCollaborators<C, P>, release: () => void);
104
- get state(): RoleRunState;
105
- get owner(): object;
106
- get sessionId(): SessionId;
107
- get toolCallId(): ToolCallId;
108
- get invocation(): RoleRunInvocation<C, P> | undefined;
109
- get holderSignal(): AbortSignal;
110
- cancel(reason?: unknown): void;
111
- background(request: RoleRunBackgroundRequest): RoleRunTransition<C, P>;
112
- private assertAddress;
113
- private assertAuthorization;
114
- private begin;
115
- private observed;
116
- }
117
- /** Current process-local calls only; native jobs remain the sole background registry. */
118
- export declare class RoleRunRegistry<C = unknown, P = unknown> {
119
- private readonly calls;
120
- private closed;
121
- private readonly collaborators;
122
- /** ctx is the stable Host-owned scope, not a reinstalled profile entry. */
123
- constructor(ctx: Context, collaborators: RoleRunCollaborators<C, P>);
124
- start(request: RoleRunStart<C, P>): RoleRunHolder<C, P>;
125
- /** Host-only lookup; C3 must authorize operator/session/epoch before exposing a view. */
126
- get(parent: Agent, owner: object, address: RoleRunAddress): RoleRunHolder<C, P> | undefined;
127
- /** Host-only active-call inventory, including starting calls without invented run ids. */
128
- list(parent: Agent, owner: object): readonly RoleRunHolder<C, P>[];
129
- /**
130
- * Trusted parent teardown first revokes C1 authority, then awaits this before
131
- * the original AgentHandle.dispose. Already-revoked tickets are not reacquired.
132
- */
133
- drainParent(parent: Agent, owner: object, reason: string): Promise<void>;
134
- close(reason: string): void;
135
- drain(): Promise<void>;
136
- private awaitHolders;
137
- }
138
- //# sourceMappingURL=role-runs.d.ts.map
package/lib/role-runs.js DELETED
@@ -1,335 +0,0 @@
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,36 +0,0 @@
1
- import { Context, Service } from "@deepseek-ai/cordis";
2
- import type { SessionHeader, SessionId } from "@deepseek-ai/dsh-session";
3
- import { SessionPersistence } from "@deepseek-ai/dsh-session-persistence";
4
- import type { SessionAccess, SessionHandle, SessionPersistenceCreateOptions, SessionPersistenceListOptions, SessionPersistenceOpenOptions, SessionPersistenceStatOptions } from "@deepseek-ai/dsh-session-persistence";
5
- import * as JsonlSessionPersistence from "@deepseek-ai/dsh-session-persistence-jsonl";
6
- import type { Config } from "@deepseek-ai/dsh-session-persistence-jsonl";
7
- export { DSMM_PERSISTENCE_COMPATIBILITY } from "./session-metadata.js";
8
- export type { Config } from "@deepseek-ai/dsh-session-persistence-jsonl";
9
- /**
10
- * Drop-in native JSONL persistence companion for audited DSMM metadata.
11
- * A separate root Context is intentional: a child service-isolation scope still
12
- * shares the host event bus and would persist every live event twice.
13
- */
14
- export default class DsmmSessionPersistence extends SessionPersistence {
15
- readonly config: Config;
16
- static Config: import("@deepseek-ai/schemastery").default<JsonlSessionPersistence.Config>;
17
- readonly name = "dsmm-session-persistence";
18
- private readonly inner;
19
- private readonly ready;
20
- private readonly handles;
21
- private readonly writers;
22
- private readonly acquisitions;
23
- private readonly closeFailures;
24
- private disposed;
25
- constructor(ctx: Context, config: Config);
26
- [Service.init](): Promise<void>;
27
- create(header: SessionHeader, options?: SessionPersistenceCreateOptions): Promise<SessionHandle>;
28
- open(id: SessionId, access: SessionAccess, options?: SessionPersistenceOpenOptions): Promise<SessionHandle>;
29
- flush(): Promise<void>;
30
- stat(id: SessionId, options?: SessionPersistenceStatOptions): Promise<import("@deepseek-ai/dsh-session-persistence").SessionPersistenceSnapshot | undefined>;
31
- list(options?: SessionPersistenceListOptions): Promise<readonly import("@deepseek-ai/dsh-session-persistence").SessionPersistenceSnapshot[]>;
32
- private acquire;
33
- private warn;
34
- private assertActive;
35
- }
36
- //# sourceMappingURL=session-persistence.d.ts.map