@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
@@ -0,0 +1,383 @@
1
+ diff --git a/lib/index.js b/lib/index.js
2
+ index 332c382bc90be78ab38b595c99f046f9d15d3f27..8be67f2cd777e17419a31d57ba731f1e004f39a9 100644
3
+ --- a/lib/index.js
4
+ +++ b/lib/index.js
5
+ @@ -1,3 +1,86 @@
6
+ +/** Host-only activation authority. No serializable value grants admission. */
7
+ +class SessionActivationError extends Error {
8
+ + constructor(category, message) {
9
+ + super(message);
10
+ + this.name = "SessionActivationError";
11
+ + this.category = category;
12
+ + }
13
+ +}
14
+ +
15
+ +function synchronousAdmission(result) {
16
+ + if (result === undefined) return;
17
+ + Promise.resolve(result).catch(() => {});
18
+ + throw new SessionActivationError('authorization-required', 'Activation validation and disposal must complete synchronously');
19
+ +}
20
+ +
21
+ +class ActivationAdmissions {
22
+ + required = false;
23
+ + guards = new Set();
24
+ + states = new Map();
25
+ + register(guard) {
26
+ + const entry = { guard, active: true };
27
+ + this.guards.add(entry);
28
+ + return () => { entry.active = false; this.guards.delete(entry); };
29
+ + }
30
+ + async begin(owner, persistence, options, signal) {
31
+ + const id = options.resumeSessionId;
32
+ + if (this.states.has(id)) throw new SessionActivationError("initializing", "Session activation is already in progress");
33
+ + const request = Object.freeze({ identity: Object.freeze({}), owner, persistence, sessionId: id, parentAgent: options.parentAgent, options, setup: options.setup, signal, processPending: options.processPending === true });
34
+ + const state = { phase: "initializing", request };
35
+ + this.states.set(id, state);
36
+ + const guards = [...this.guards];
37
+ + const admissions = [];
38
+ + const fail = (category, message) => { throw new SessionActivationError(category, message); };
39
+ + const current = () => {
40
+ + if (signal.aborted) fail("cancelled", "Session activation was cancelled");
41
+ + owner.fiber.assertActive();
42
+ + if (this.states.get(id) !== state) fail("stale", "Activation owner changed");
43
+ + if (this.required && guards.length === 0) fail("authorization-required", "A current activation admission provider is required");
44
+ + if (guards.some(entry => !entry.active) || [...this.guards].some(entry => !guards.includes(entry))) fail("stale", "Activation admission providers changed");
45
+ + for (const { admission } of admissions) synchronousAdmission(admission.assertCurrent());
46
+ + };
47
+ + let closed = false;
48
+ + const close = () => {
49
+ + if (closed) return;
50
+ + closed = true;
51
+ + if (this.states.get(id) === state) this.states.delete(id);
52
+ + const failures = [];
53
+ + for (const { admission } of admissions.reverse()) {
54
+ + try { synchronousAdmission(admission.dispose()); } catch (error) { failures.push(error); }
55
+ + }
56
+ + if (failures.length) throw new AggregateError(failures, 'Activation admission cleanup failed');
57
+ + };
58
+ + try {
59
+ + current();
60
+ + for (const entry of guards) {
61
+ + const admission = await entry.guard(request);
62
+ + if (!admission) fail("authorization-required", "Every activation guard must admit the operation");
63
+ + admissions.push({ admission });
64
+ + current();
65
+ + }
66
+ + if ((this.required || guards.length > 0) && persistence.writeAdmission?.lockedInspection !== 1) fail("unsupported-backend", "Persistence does not validate admission under its writer lease");
67
+ + current();
68
+ + return {
69
+ + request,
70
+ + current,
71
+ + loaded: inspection => {
72
+ + current();
73
+ + for (const { admission } of admissions) synchronousAdmission(admission.validateLoaded(inspection));
74
+ + current();
75
+ + },
76
+ + publish: agent => {
77
+ + current();
78
+ + state.agent = agent;
79
+ + for (const { admission } of admissions) synchronousAdmission(admission.validatePublish(agent));
80
+ + current();
81
+ + },
82
+ + commit: agent => { current(); state.phase = "committed"; state.agent = agent; },
83
+ + close,
84
+ + };
85
+ + } catch (error) { close(); throw error; }
86
+ + }
87
+ +}
88
+ +
89
+ import { Service } from "@deepseek-ai/cordis";
90
+ import { randomUUID } from "node:crypto";
91
+ import z from "@deepseek-ai/schemastery";
92
+ @@ -745,6 +828,7 @@ function abortedCancelCause(signal) {
93
+ }
94
+ /** Drives one session through turn and step boundaries. */
95
+ var ReactLoopAgent = class {
96
+ + preserveUncommittedInbox = false;
97
+ loopCtx;
98
+ id;
99
+ options;
100
+ @@ -813,7 +897,7 @@ var ReactLoopAgent = class {
101
+ this.send(input, "next-step", false);
102
+ }
103
+ cancel(cause, options = {}) {
104
+ - if (!options.keepInbox) {
105
+ + if (!options.keepInbox && !this.preserveUncommittedInbox) {
106
+ this.inbox.clear();
107
+ if (this.phase.kind !== "idle") this.phase.wakeRequested = false;
108
+ }
109
+ @@ -1551,6 +1635,7 @@ var AgentLoop = class extends Service {
110
+ ];
111
+ /** Runtime schema for declarative agents. */
112
+ static Config = z.object({
113
+ + activationAdmissionRequired: z.boolean().default(false),
114
+ maxParallelToolCalls: z.number().step(1).min(1).default(10).volatile(),
115
+ agents: z.array(z.object({
116
+ id: z.string().required(),
117
+ @@ -1565,16 +1650,22 @@ var AgentLoop = class extends Service {
118
+ });
119
+ /** Validated configuration owned by the agent-loop service. */
120
+ config;
121
+ + activationAdmissions = new ActivationAdmissions();
122
+ + requireActivationAdmission() { this.activationAdmissions.required = true; }
123
+ + registerActivationGuard(guard) { return this.activationAdmissions.register(guard); }
124
+ + activationState(id) { return this.activationAdmissions.states.get(id); }
125
+ ownership;
126
+ /** Plain holder prevents Cordis from re-tracing the factory's dependency context through a caller shadow. */
127
+ runtime;
128
+ constructor(ctx, config) {
129
+ super(ctx, "agentLoop");
130
+ this.config = {
131
+ + activationAdmissionRequired: config.activationAdmissionRequired ?? false,
132
+ agents: applyLauncherIdentities(config.agents, ctx.get(CONFIGURED_AGENT_IDENTITIES_KEY)),
133
+ maxParallelToolCalls: config.maxParallelToolCalls
134
+ };
135
+ validateConfiguredAgents(this.config.agents);
136
+ + this.activationAdmissions.required = this.config.activationAdmissionRequired;
137
+ const ownership = this.ownership = new FactoryOwnership(ctx.fiber);
138
+ this.runtime = { ctx };
139
+ ctx.effect(function* () {
140
+ @@ -1678,7 +1769,7 @@ var AgentLoop = class extends Service {
141
+ * BEFORE publication, so a mid-setup unload rolls everything back; `signal`
142
+ * fuses caller cancellation with lifecycle teardown for setup awaits.
143
+ */
144
+ - prepare(ownerCtx, id, options, session, callerSignal, handle, parentAgent) {
145
+ + prepare(ownerCtx, id, options, session, callerSignal, handle, parentAgent, activation) {
146
+ assertAgentOptions(options);
147
+ ownerCtx.fiber.assertActive();
148
+ /* v8 ignore next -- unreachable backstop, see above */
149
+ @@ -1748,6 +1839,7 @@ var AgentLoop = class extends Service {
150
+ try {
151
+ unfollowOwner = ownerCtx.effect(function* () {
152
+ const created = machine = new ReactLoopAgent(loopCtx, id, options, session);
153
+ + created.preserveUncommittedInbox = activation !== void 0;
154
+ machineReady.resolve();
155
+ if (!INACTIVE_STATES.has(loopCtx.fiber.state)) unfollowScope = loopCtx.effect(function* () {
156
+ yield created.scope.rawDispose;
157
+ @@ -1793,6 +1885,10 @@ var AgentLoop = class extends Service {
158
+ assertLive();
159
+ await loopCtx.agents.announce(agent, source, abort.signal);
160
+ assertLive();
161
+ + activation?.publish(agent);
162
+ + activation?.commit(agent);
163
+ + agent.preserveUncommittedInbox = false;
164
+ + if (activation?.request.processPending && agent.inbox.hasPending) agent.wakeDriver();
165
+ return {
166
+ agent,
167
+ dispose
168
+ @@ -1912,7 +2008,7 @@ var AgentLoop = class extends Service {
169
+ return published;
170
+ }
171
+ /** Prepare one Agent around an acquired Session, run setup, and publish it. */
172
+ - async setupAndPublish(ownerCtx, id, preparation, agentOptions, setup, signal, source, stored, parentAgent) {
173
+ + async setupAndPublish(ownerCtx, id, preparation, agentOptions, setup, signal, source, stored, parentAgent, activation) {
174
+ const env_2 = {
175
+ stack: [],
176
+ error: void 0,
177
+ @@ -1922,14 +2018,19 @@ var AgentLoop = class extends Service {
178
+ const session = __addDisposableResource(env_2, preparation, false).session;
179
+ let prepared;
180
+ try {
181
+ - prepared = this.prepare(ownerCtx, id, agentOptions, session, signal, stored?.handle, parentAgent);
182
+ + activation?.current();
183
+ + prepared = this.prepare(ownerCtx, id, agentOptions, session, signal, stored?.handle, parentAgent, activation);
184
+ } catch (error) {
185
+ await stored?.handle.close().catch(() => {});
186
+ throw error;
187
+ }
188
+ return await this.initializeAgent(prepared, async () => {
189
+ - (await raceAbort(setup?.(prepared.agent.ctx, prepared.agent), prepared.signal, id))?.commit();
190
+ + const setupCommit = await raceAbort(setup?.(prepared.agent.ctx, prepared.agent), prepared.signal, id);
191
+ + activation?.current();
192
+ + setupCommit?.commit();
193
+ + activation?.publish(prepared.agent);
194
+ await this.appendUnstoredSuffix(stored, session);
195
+ + activation?.current();
196
+ return await prepared.publish(source);
197
+ });
198
+ } catch (e_2) {
199
+ @@ -1967,11 +2068,14 @@ var AgentLoop = class extends Service {
200
+ }
201
+ /** Resume through an explicit persistence handle used by the deferred config path. */
202
+ resumeWith(ownerCtx, persistence, options) {
203
+ + assertAgentOptions(options.agentOptions ?? {});
204
+ + ownerCtx.fiber.assertActive();
205
+ const id = options.resumeSessionId;
206
+ const published = (async () => {
207
+ const ownerAbort = new AbortController();
208
+ + let observingOwner = true;
209
+ const unfollowOwner = ownerCtx.effect(() => () => {
210
+ - ownerAbort.abort(/* @__PURE__ */ new Error(`agent "${id}" setup aborted: owner disposed during setup`));
211
+ + if (observingOwner) ownerAbort.abort(/* @__PURE__ */ new Error(`agent "${id}" setup aborted: owner disposed during setup`));
212
+ }, `agentLoop.resume-load(${id})`);
213
+ const fused = AbortSignal.any([
214
+ ...options.signal === void 0 ? [] : [options.signal],
215
+ @@ -1981,38 +2085,45 @@ var AgentLoop = class extends Service {
216
+ let handle;
217
+ let stored;
218
+ let preparation;
219
+ + let activation;
220
+ try {
221
+ - try {
222
+ - handle = await raceAbortCall(() => persistence.open(id, "write", { signal: fused }), fused, id, (abandoned) => {
223
+ - abandoned.close();
224
+ - });
225
+ - const coldRead = await handle.read(0, void 0, { signal: fused });
226
+ - fused.throwIfAborted();
227
+ - const persisted = coldRead.events;
228
+ - const closers = interruptedTurnClosers(persisted);
229
+ - if (closers.length > 0) await handle.append(closers);
230
+ - preparation = SessionPreparation.create(this.runtime.ctx.sessions.prepare(id, {
231
+ - seed: [...persisted, ...closers],
232
+ - meta: structuredClone(handle.header),
233
+ - inheritedEventCount: handle.inheritedEventCount,
234
+ - eventState: coldRead.eventState
235
+ - }));
236
+ - stored = {
237
+ - handle,
238
+ - storedCount: persisted.length + closers.length
239
+ - };
240
+ - await this.appendUnstoredSuffix(stored, preparation.session);
241
+ - } finally {
242
+ - await unfollowOwner();
243
+ - }
244
+ + activation = await this.activationAdmissions.begin(ownerCtx, persistence, options, fused);
245
+ + activation.current();
246
+ + handle = await raceAbortCall(() => persistence.open(id, "write", { signal: fused, validateWriteAdmission: activation.loaded }), fused, id, (abandoned) => {
247
+ + abandoned.close();
248
+ + });
249
+ + const coldRead = await handle.read(0, void 0, { signal: fused });
250
+ + fused.throwIfAborted();
251
+ + activation.current();
252
+ + const persisted = coldRead.events;
253
+ + const closers = interruptedTurnClosers(persisted);
254
+ + if (closers.length > 0) await handle.append(closers);
255
+ + activation.current();
256
+ + preparation = SessionPreparation.create(this.runtime.ctx.sessions.prepare(id, {
257
+ + seed: [...persisted, ...closers],
258
+ + meta: structuredClone(handle.header),
259
+ + inheritedEventCount: handle.inheritedEventCount,
260
+ + eventState: coldRead.eventState
261
+ + }));
262
+ + stored = {
263
+ + handle,
264
+ + storedCount: persisted.length + closers.length
265
+ + };
266
+ + activation.current();
267
+ + await this.appendUnstoredSuffix(stored, preparation.session);
268
+ ownerCtx.fiber.assertActive();
269
+ if (!this.ownership.isActive()) throw new Error("agent loop is not active");
270
+ const owned = stored;
271
+ handle = void 0;
272
+ - return await this.setupAndPublish(ownerCtx, id, preparation, options.agentOptions ?? {}, options.setup, options.signal, "resume", owned, options.parentAgent);
273
+ + return await this.setupAndPublish(ownerCtx, id, preparation, options.agentOptions ?? {}, options.setup, fused, "resume", owned, options.parentAgent, activation);
274
+ } finally {
275
+ preparation?.[Symbol.dispose]();
276
+ await handle?.close().catch(() => {});
277
+ + try { activation?.close(); }
278
+ + finally {
279
+ + observingOwner = false;
280
+ + await unfollowOwner();
281
+ + }
282
+ }
283
+ })();
284
+ this.ownership.trackWrapper(published);
285
+ @@ -2021,3 +2132,4 @@ var AgentLoop = class extends Service {
286
+ };
287
+ //#endregion
288
+ export { AgentLoop, AgentLoop as default, CONFIGURED_AGENT_IDENTITIES_KEY, DEFAULT_MAX_PARALLEL_TOOL_CALLS, turnBoundaryProjectionDefinition };
289
+ +export { SessionActivationError };
290
+ diff --git a/lib/types/activation.d.ts b/lib/types/activation.d.ts
291
+ new file mode 100644
292
+ index 0000000000000000000000000000000000000000..1d09b1e506ce164cd28a9f0a920bf91bcc6f555b
293
+ --- /dev/null
294
+ +++ b/lib/types/activation.d.ts
295
+ @@ -0,0 +1,37 @@
296
+ +import type { Context } from '@deepseek-ai/cordis';
297
+ +import type { Agent, ResumeAgentOptions } from '@deepseek-ai/dsh-agent';
298
+ +import type { SessionId } from '@deepseek-ai/dsh-session';
299
+ +import type { SessionPersistence, SessionWriteInspection } from '@deepseek-ai/dsh-session-persistence';
300
+ +export type SessionActivationFailure = 'authorization-required' | 'stale' | 'cancelled' | 'unsupported-backend' | 'initializing';
301
+ +export declare class SessionActivationError extends Error {
302
+ + readonly category: SessionActivationFailure;
303
+ + constructor(category: SessionActivationFailure, message: string);
304
+ +}
305
+ +export interface SessionActivationRequest {
306
+ + readonly processPending: boolean;
307
+ + readonly identity: object;
308
+ + readonly owner: Context;
309
+ + readonly persistence: SessionPersistence;
310
+ + readonly sessionId: SessionId;
311
+ + readonly parentAgent: Agent | undefined;
312
+ + readonly options: ResumeActivationOptions;
313
+ + readonly setup: ResumeAgentOptions['setup'];
314
+ + readonly signal: AbortSignal;
315
+ +}
316
+ +export interface ResumeActivationOptions extends ResumeAgentOptions {
317
+ + /** Wake the existing inbox after final admission and all created notifications; no replay or reinsertion. */
318
+ + readonly processPending?: boolean;
319
+ +}
320
+ +/** All checks are synchronous and throw to veto. Disposal revokes only this operation. */
321
+ +export interface SessionActivationAdmission {
322
+ + assertCurrent(): undefined;
323
+ + validateLoaded(inspection: SessionWriteInspection): undefined;
324
+ + validatePublish(agent: Agent): undefined;
325
+ + dispose(): undefined;
326
+ +}
327
+ +export type SessionActivationGuard = (request: SessionActivationRequest) => SessionActivationAdmission | Promise<SessionActivationAdmission>;
328
+ +export interface SessionActivationState {
329
+ + readonly phase: 'initializing' | 'committed';
330
+ + readonly request: SessionActivationRequest;
331
+ + readonly agent?: Agent;
332
+ +}
333
+ diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts
334
+ index be9292f235ee91af25cb92ea853a16865b87875a..582913a0680708817672ef4464a4537581c6bccb 100644
335
+ --- a/lib/types/index.d.ts
336
+ +++ b/lib/types/index.d.ts
337
+ @@ -11,6 +11,9 @@ import { z as zod } from 'zod';
338
+ import type { Agent, AgentFactory, AgentHandle, AgentOptions, CreateAgentOptions, ResumeAgentOptions, TurnBoundaryProjection } from '@deepseek-ai/dsh-agent';
339
+ import type { SessionHeader, SessionId } from '@deepseek-ai/dsh-session';
340
+ import { DEFAULT_MAX_PARALLEL_TOOL_CALLS } from './constants.ts';
341
+ +import type { SessionActivationGuard, SessionActivationState, ResumeActivationOptions } from './activation.js';
342
+ +export { SessionActivationError } from './activation.js';
343
+ +export type { SessionActivationGuard, SessionActivationState, SessionActivationRequest, SessionActivationAdmission, SessionActivationFailure, ResumeActivationOptions } from './activation.js';
344
+ /** Host projection of agent turn and step boundaries. */
345
+ export declare const turnBoundaryProjectionDefinition: {
346
+ key: "turnBoundary";
347
+ @@ -78,6 +81,8 @@ export interface ConfiguredAgentIdentities extends Readonly<Record<string, Launc
348
+ export declare const CONFIGURED_AGENT_IDENTITIES_KEY = "configuredAgentIdentities";
349
+ /** Agent-loop plugin configuration. */
350
+ export interface Config {
351
+ + /** Reject resume before write when no current Host guard admits it. Defaults to false. */
352
+ + activationAdmissionRequired?: boolean;
353
+ /**
354
+ * Maximum parallel-safe calls in flight per agent step. `1` is serial;
355
+ * omission defaults to {@link DEFAULT_MAX_PARALLEL_TOOL_CALLS}.
356
+ @@ -100,6 +105,7 @@ export declare class AgentLoop extends Service implements AgentFactory {
357
+ static inject: string[];
358
+ /** Runtime schema for declarative agents. */
359
+ static Config: z<{
360
+ + activationAdmissionRequired?: boolean;
361
+ agents?: Config['agents'];
362
+ maxParallelToolCalls?: number;
363
+ }, Config>;
364
+ @@ -109,6 +115,10 @@ export declare class AgentLoop extends Service implements AgentFactory {
365
+ /** Plain holder prevents Cordis from re-tracing the factory's dependency context through a caller shadow. */
366
+ private readonly runtime;
367
+ constructor(ctx: Context, config: Config);
368
+ + /** Sticky requirement; removing the last provider never restores implicit admission. */
369
+ + requireActivationAdmission(): void;
370
+ + registerActivationGuard(guard: SessionActivationGuard): () => void;
371
+ + activationState(id: SessionId): SessionActivationState | undefined;
372
+ /** Report a contained declarative-start failure to identity-bound consumers. */
373
+ private reportConfiguredStartupFailure;
374
+ /** Restore a materialized exact config identity on remount, or create it on first use. */
375
+ @@ -171,7 +181,7 @@ export declare class AgentLoop extends Service implements AgentFactory {
376
+ * @param options - persisted identity, optional live parent, loop options, setup, and cancellation.
377
+ * @returns the published handle.
378
+ */
379
+ - resume(ownerCtx: Context, options: ResumeAgentOptions): Promise<AgentHandle>;
380
+ + resume(ownerCtx: Context, options: ResumeActivationOptions): Promise<AgentHandle>;
381
+ /** Resume through an explicit persistence handle used by the deferred config path. */
382
+ private resumeWith;
383
+ }
@@ -0,0 +1,55 @@
1
+ diff --git a/lib/index.js b/lib/index.js
2
+ --- a/lib/index.js
3
+ +++ b/lib/index.js
4
+ @@ -777,6 +777,9 @@ let AgentPresetRegistry = (() => {
5
+ let disposed = false;
6
+ return {
7
+ key: generation.key,
8
+ + assertCurrent: () => {
9
+ + if (disposed || generation.retired || this.definitions.get(generation.mount.presetId)?.generation !== generation) throw new Error("Preset revision is no longer current");
10
+ + },
11
+ [Symbol.asyncDispose]: async () => {
12
+ if (disposed) return;
13
+ disposed = true;
14
+ diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts
15
+ --- a/lib/types/index.d.ts
16
+ +++ b/lib/types/index.d.ts
17
+ @@ -13,6 +13,12 @@ export { entryListProblem, type PresetDefinition } from './definition.ts';
18
+ export { auditRows, leakedServices, type PresetMount, type RowAudit } from './mount.ts';
19
+ export type { AgentPresetInspection } from './composition-inventory.ts';
20
+ export type { AgentPreset, Config } from './preset.ts';
21
+ +/** Retains a revision; current-authority consumers must also call assertCurrent. */
22
+ +export interface AgentPresetScopeLease extends AsyncDisposable {
23
+ + readonly key: ScopeKey;
24
+ + /** Synchronously throws when disposed, retired, or replaced in the registry. */
25
+ + assertCurrent(): void;
26
+ +}
27
+ declare module '@deepseek-ai/cordis' {
28
+ interface Context {
29
+ agentPresets: AgentPresetRegistry;
30
+ @@ -126,9 +132,7 @@ export declare class AgentPresetRegistry extends TypertRemoteService {
31
+ * @param id Preset identity or the default.
32
+ * @returns A revision lease; dispose it after the scoped read completes.
33
+ */
34
+ - acquireScope(id?: string): Promise<{
35
+ - key: ScopeKey;
36
+ - } & AsyncDisposable>;
37
+ + acquireScope(id?: string): Promise<AgentPresetScopeLease>;
38
+ /** Read plugin rows without creating an Agent.
39
+ * @returns Current declaration metadata and activation states.
40
+ */
41
+ diff --git a/lib/types/index.js b/lib/types/index.js
42
+ --- a/lib/types/index.js
43
+ +++ b/lib/types/index.js
44
+ @@ -386,7 +386,10 @@ let AgentPresetRegistry = (() => {
45
+ async acquireScope(id) {
46
+ const generation = await this.retain(id);
47
+ let disposed = false;
48
+ - return { key: generation.key, [Symbol.asyncDispose]: async () => {
49
+ + return { key: generation.key, assertCurrent: () => {
50
+ + if (disposed || generation.retired || this.definitions.get(generation.mount.presetId)?.generation !== generation)
51
+ + throw new Error("Preset revision is no longer current");
52
+ + }, [Symbol.asyncDispose]: async () => {
53
+ if (disposed)
54
+ return;
55
+ disposed = true;