@dsmm/dsmm 0.2.2 → 0.3.1

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 (182) hide show
  1. package/README.md +26 -42
  2. package/cordis.patch.yml +1 -0
  3. package/docs/agent-presets.md +26 -14
  4. package/docs/compatibility.md +20 -79
  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 +34 -240
  13. package/docs/roadmap.md +23 -254
  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 +16 -2
  20. package/lib/child-capture.js +29 -10
  21. package/lib/client/ChildrenPanel.d.ts +1 -4
  22. package/lib/client/ChildrenPanel.js +4 -16
  23. package/lib/client/DeploymentFields.d.ts +28 -0
  24. package/lib/client/DeploymentFields.js +68 -0
  25. package/lib/client/DeploymentPage.d.ts +17 -5
  26. package/lib/client/DeploymentPage.js +79 -112
  27. package/lib/client/NativeCommandEntries.d.ts +17 -0
  28. package/lib/client/NativeCommandEntries.js +68 -0
  29. package/lib/client/PermissionsPanel.d.ts +1 -1
  30. package/lib/client/PermissionsPanel.js +8 -8
  31. package/lib/client/ProfilesSection.js +7 -5
  32. package/lib/client/RoleToolView-data.d.ts +35 -0
  33. package/lib/client/RoleToolView-data.js +52 -0
  34. package/lib/client/RoleToolView-locales.d.ts +36 -0
  35. package/lib/client/RoleToolView-locales.js +20 -0
  36. package/lib/client/RoleToolView.d.ts +10 -0
  37. package/lib/client/RoleToolView.js +47 -0
  38. package/lib/client/SessionProfiles.js +39 -15
  39. package/lib/client/children-controller.d.ts +2 -8
  40. package/lib/client/children-controller.js +1 -26
  41. package/lib/client/children-locales.d.ts +26 -51
  42. package/lib/client/children-locales.js +8 -12
  43. package/lib/client/configuration-display.d.ts +5 -0
  44. package/lib/client/configuration-display.js +11 -0
  45. package/lib/client/controller.d.ts +1 -0
  46. package/lib/client/controller.js +20 -13
  47. package/lib/client/deployment-controller.d.ts +13 -1
  48. package/lib/client/deployment-controller.js +85 -25
  49. package/lib/client/deployment-data.d.ts +1 -0
  50. package/lib/client/deployment-data.js +4 -1
  51. package/lib/client/deployment-locales.d.ts +43 -0
  52. package/lib/client/deployment-locales.js +35 -9
  53. package/lib/client/deployment-modules.d.ts +9 -0
  54. package/lib/client/deployment-modules.js +24 -0
  55. package/lib/client/deployment-workspace.d.ts +48 -0
  56. package/lib/client/deployment-workspace.js +123 -0
  57. package/lib/client/index.js +11 -74
  58. package/lib/client/locales.d.ts +7 -0
  59. package/lib/client/locales.js +12 -6
  60. package/lib/client/permission-controller.d.ts +1 -0
  61. package/lib/client/permission-controller.js +3 -2
  62. package/lib/client/permission-locales.d.ts +25 -0
  63. package/lib/client/permission-locales.js +24 -4
  64. package/lib/client/session-labels.js +4 -3
  65. package/lib/client/styles.d.ts +1 -1
  66. package/lib/client/styles.js +9 -8
  67. package/lib/client.js +2716 -2364
  68. package/lib/commands.js +2 -0
  69. package/lib/config-file-store.d.ts +3 -0
  70. package/lib/config-file-store.js +4 -2
  71. package/lib/config-revision.d.ts +5 -0
  72. package/lib/config-revision.js +11 -0
  73. package/lib/core-permission-authority.js +11 -41
  74. package/lib/deployment-config.d.ts +9 -2
  75. package/lib/deployment-config.js +35 -8
  76. package/lib/deployment-permission-rules.js +19 -7
  77. package/lib/dsh-types.d.ts +1 -1
  78. package/lib/host-llm-startup.js +3 -3
  79. package/lib/host-llm.d.ts +9 -3
  80. package/lib/host-llm.js +48 -8
  81. package/lib/index.d.ts +17 -21
  82. package/lib/index.js +131 -430
  83. package/lib/lifetime.d.ts +4 -0
  84. package/lib/lifetime.js +22 -0
  85. package/lib/live-pi-ai-owner.d.ts +1 -0
  86. package/lib/live-pi-ai-owner.js +8 -4
  87. package/lib/mode.d.ts +3 -2
  88. package/lib/mode.js +28 -41
  89. package/lib/model-routing.d.ts +2 -8
  90. package/lib/model-routing.js +59 -175
  91. package/lib/native-admission.d.ts +56 -0
  92. package/lib/native-admission.js +313 -0
  93. package/lib/native-pi-ai-wire.d.ts +3 -1
  94. package/lib/native-pi-ai-wire.js +47 -13
  95. package/lib/permission-control.d.ts +0 -3
  96. package/lib/permission-rpc.js +3 -3
  97. package/lib/preset-registry.js +3 -2
  98. package/lib/preset-skills.d.ts +3 -12
  99. package/lib/preset-skills.js +28 -58
  100. package/lib/profile-diagnostics.d.ts +1 -1
  101. package/lib/profile-diagnostics.js +2 -2
  102. package/lib/profile-remote.js +61 -22
  103. package/lib/profile-rpc.d.ts +4 -3
  104. package/lib/profile-rpc.js +39 -41
  105. package/lib/profile-runtime.d.ts +31 -74
  106. package/lib/profile-runtime.js +224 -639
  107. package/lib/profile-store.d.ts +18 -6
  108. package/lib/profile-store.js +106 -64
  109. package/lib/profile-types.d.ts +18 -4
  110. package/lib/profiles.d.ts +3 -1
  111. package/lib/profiles.js +9 -7
  112. package/lib/prompt-content.d.ts +1 -0
  113. package/lib/prompt-content.js +4 -1
  114. package/lib/prompts.d.ts +2 -12
  115. package/lib/prompts.js +11 -66
  116. package/lib/role-control-remote.d.ts +1 -4
  117. package/lib/role-control-remote.js +8 -36
  118. package/lib/role-control-rpc.d.ts +10 -36
  119. package/lib/role-control-rpc.js +112 -265
  120. package/lib/role-control-types.d.ts +3 -26
  121. package/lib/role-control-types.js +3 -4
  122. package/lib/role-identity.d.ts +5 -0
  123. package/lib/role-identity.js +10 -0
  124. package/lib/role-invocation.d.ts +2 -2
  125. package/lib/role-llm-runtime.js +5 -11
  126. package/lib/role-policy.d.ts +19 -53
  127. package/lib/role-policy.js +136 -525
  128. package/lib/role-providers.d.ts +5 -8
  129. package/lib/role-providers.js +20 -126
  130. package/lib/role-routing.d.ts +1 -3
  131. package/lib/role-routing.js +24 -34
  132. package/lib/role-subagents.d.ts +5 -14
  133. package/lib/role-subagents.js +149 -97
  134. package/lib/runtime-integration.d.ts +5 -109
  135. package/lib/runtime-integration.js +11 -779
  136. package/lib/session-metadata.d.ts +13 -12
  137. package/lib/session-metadata.js +6 -31
  138. package/lib/session-scope.js +6 -2
  139. package/lib/settings.d.ts +5 -18
  140. package/lib/settings.js +19 -43
  141. package/lib/state.d.ts +3 -2
  142. package/lib/state.js +26 -10
  143. package/lib/status.d.ts +1 -9
  144. package/lib/status.js +3 -55
  145. package/lib/web-fetch-address-policy.d.ts +24 -0
  146. package/lib/web-fetch-address-policy.js +189 -0
  147. package/lib/web-fetch-fakeip.d.ts +25 -0
  148. package/lib/web-fetch-fakeip.js +107 -0
  149. package/package.json +133 -113
  150. package/docs/research/deepseek-v4-pro.md +0 -74
  151. package/docs/research/oh-dsh.md +0 -96
  152. package/lib/child-admission.d.ts +0 -42
  153. package/lib/child-admission.js +0 -162
  154. package/lib/delivery-authority.d.ts +0 -68
  155. package/lib/delivery-authority.js +0 -260
  156. package/lib/legacy-child-policy.d.ts +0 -51
  157. package/lib/legacy-child-policy.js +0 -123
  158. package/lib/legacy-read-composition.d.ts +0 -20
  159. package/lib/legacy-read-composition.js +0 -144
  160. package/lib/legacy-read-contracts.d.ts +0 -157
  161. package/lib/legacy-read-contracts.js +0 -39
  162. package/lib/legacy-read-host.d.ts +0 -19
  163. package/lib/legacy-read-host.js +0 -67
  164. package/lib/legacy-read-integration.d.ts +0 -121
  165. package/lib/legacy-read-integration.js +0 -522
  166. package/lib/legacy-read-proxy.d.ts +0 -26
  167. package/lib/legacy-read-proxy.js +0 -237
  168. package/lib/native-child-evidence.d.ts +0 -42
  169. package/lib/native-child-evidence.js +0 -133
  170. package/lib/role-runs.d.ts +0 -135
  171. package/lib/role-runs.js +0 -304
  172. package/lib/session-persistence.d.ts +0 -35
  173. package/lib/session-persistence.js +0 -304
  174. package/lib/subagent-runtime.d.ts +0 -45
  175. package/lib/subagent-runtime.js +0 -131
  176. package/prompts/deepseek-flash.md +0 -11
  177. package/prompts/deepseek-v4-pro.md +0 -14
  178. package/scripts/cold-profile-composition.mjs +0 -329
  179. package/scripts/cold-profile-sources.mjs +0 -238
  180. package/scripts/migrate-cold-profile.mjs +0 -315
  181. package/scripts/repair-session-log.mjs +0 -476
  182. package/scripts/session-repair-native-verifier.mjs +0 -367
@@ -36,36 +36,35 @@ import { symbols } from "@deepseek-ai/cordis";
36
36
  import { SessionId } from "@deepseek-ai/dsh-session";
37
37
  import { SubagentError } from "@deepseek-ai/dsh-subagent";
38
38
  import { Remote, RemoteError, TypertRemoteService, remoteErrorOf } from "@deepseek-ai/dsh-typert-protocol";
39
- import { scopeLifetime } from "./delivery-authority.js";
40
- import { ROLE_CONTROL_HOST, parseChildSessionSnapshot, parseRoleControlBackgroundRequest, parseRoleControlCapabilities, parseRoleControlDescendants, parseRoleControlErrorInfo, parseRoleControlInterruptRequest, parseRoleControlPromptRequest, parseRoleControlSessionId } from "./role-control-remote.js";
41
- import { parseDsmmInvocationView, parseDsmmRoleRouteComparison } from "./profile-remote.js";
39
+ import { scopeLifetime } from "./lifetime.js";
40
+ import { runtimeAdmissionView } from "./runtime-integration.js";
41
+ import { invocationView } from "./role-invocation.js";
42
+ import { roleRouteComparison } from "./role-subagents.js";
43
+ import { ROLE_CONTROL_HOST, parseChildSessionSnapshot, parseRoleControlDescendants, parseRoleControlPromptRequest, parseRoleControlInterruptRequest, parseRoleControlSessionId } from "./role-control-remote.js";
44
+ const unavailable = { enabled: false, reason: "unavailable" };
42
45
  class ControlRefusal extends Error {
43
- info;
46
+ code;
47
+ field;
48
+ reason;
44
49
  constructor(code, field, reason) {
45
- super("The Host refused the child control operation.");
46
- this.info = { code, ...(field === undefined ? {} : { field }), ...(reason === undefined ? {} : { reason }) };
50
+ super("Native child control refused");
51
+ this.code = code;
52
+ this.field = field;
53
+ this.reason = reason;
47
54
  }
48
55
  }
49
- const disabled = (reason) => ({ enabled: false, reason });
50
- function requireEnabled(value) { if (!value.enabled)
51
- throw new ControlRefusal("disabled", undefined, value.reason); }
52
- function original(value) { return Reflect.get(value, symbols.original) ?? value; }
53
- function terminalTransition(state, runId) {
54
- return state === "settled" ? { status: "already-settled", runId } : state === "cancelled" ? { status: "cancelled", runId } : undefined;
56
+ const disabled = (reason) => ({ enabled: false, reason: reason ?? "unavailable" });
57
+ function boundedLabel(label) {
58
+ const last = label.charCodeAt(119), next = label.charCodeAt(120);
59
+ const bounded = label.slice(0, last >= 0xd800 && last <= 0xdbff && next >= 0xdc00 && next <= 0xdfff ? 119 : 120).replace(/[\u0000-\u001f\u007f]/gu, " ");
60
+ return new TextDecoder().decode(new TextEncoder().encode(bounded));
55
61
  }
56
- function boundedChildLabel(label) {
57
- const high = label.charCodeAt(119), low = label.charCodeAt(120);
58
- // Preserve the UTF-16 wire bound without splitting a valid native code point.
59
- const end = high >= 0xd800 && high <= 0xdbff && low >= 0xdc00 && low <= 0xdfff ? 119 : 120;
60
- return label.slice(0, end).replace(/[\u0000-\u001f\u007f]/gu, " ");
61
- }
62
- /** Separate namespace: native inbox/jobs remain the sole execution owners. */
62
+ /** Authenticated projection of the native catalog. Listing never wakes a session. */
63
63
  let DsmmChildrenHost = (() => {
64
64
  let _classSuper = TypertRemoteService;
65
65
  let _instanceExtraInitializers = [];
66
66
  let _describe_decorators;
67
67
  let _descendants_decorators;
68
- let _background_decorators;
69
68
  let _prompt_decorators;
70
69
  let _interrupt_decorators;
71
70
  return class DsmmChildrenHost extends _classSuper {
@@ -73,39 +72,65 @@ let DsmmChildrenHost = (() => {
73
72
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
74
73
  _describe_decorators = [Remote];
75
74
  _descendants_decorators = [Remote];
76
- _background_decorators = [Remote];
77
75
  _prompt_decorators = [Remote];
78
76
  _interrupt_decorators = [Remote];
79
77
  __esDecorate(this, null, _describe_decorators, { kind: "method", name: "describe", static: false, private: false, access: { has: obj => "describe" in obj, get: obj => obj.describe }, metadata: _metadata }, null, _instanceExtraInitializers);
80
78
  __esDecorate(this, null, _descendants_decorators, { kind: "method", name: "descendants", static: false, private: false, access: { has: obj => "descendants" in obj, get: obj => obj.descendants }, metadata: _metadata }, null, _instanceExtraInitializers);
81
- __esDecorate(this, null, _background_decorators, { kind: "method", name: "background", static: false, private: false, access: { has: obj => "background" in obj, get: obj => obj.background }, metadata: _metadata }, null, _instanceExtraInitializers);
82
79
  __esDecorate(this, null, _prompt_decorators, { kind: "method", name: "prompt", static: false, private: false, access: { has: obj => "prompt" in obj, get: obj => obj.prompt }, metadata: _metadata }, null, _instanceExtraInitializers);
83
80
  __esDecorate(this, null, _interrupt_decorators, { kind: "method", name: "interrupt", static: false, private: false, access: { has: obj => "interrupt" in obj, get: obj => obj.interrupt }, metadata: _metadata }, null, _instanceExtraInitializers);
84
81
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
85
82
  }
86
- lifetime = (__runInitializers(this, _instanceExtraInitializers), new AbortController());
87
- backgroundJobs = new WeakMap();
88
- collaborators;
89
- constructor(ctx, collaborators) {
83
+ admission = __runInitializers(this, _instanceExtraInitializers);
84
+ lifetime = new AbortController();
85
+ constructor(ctx, admission) {
90
86
  super(ctx, "dsmmChildren");
91
- this.collaborators = collaborators;
92
- scopeLifetime(ctx, "dsmm.children: close scoped controls", () => this.lifetime.abort());
87
+ this.admission = admission;
88
+ scopeLifetime(ctx, "dsmm: retire child controls", () => this.lifetime.abort());
93
89
  }
94
- async invoke(operation) {
90
+ async scoped(id, operation) {
91
+ let operationSignal;
95
92
  try {
96
- return await operation();
93
+ const sessionId = parseRoleControlSessionId(id), invocation = this.ctx.invocation;
94
+ const connection = this.ctx.get("connection");
95
+ if (!invocation?.peer || connection?.browserPeer !== invocation.peer)
96
+ throw new ControlRefusal("not-owned");
97
+ const owner = Reflect.get(connection, symbols.original) ?? connection;
98
+ const agents = this.ctx.get("agents");
99
+ if (!agents)
100
+ throw new ControlRefusal("unavailable");
101
+ const parent = agents.get(SessionId(sessionId));
102
+ if (!parent)
103
+ throw new ControlRefusal("not-found", "sessionId");
104
+ if (!agents.roots().includes(parent) || parent.session.header.origin === "subagent" || parent.session.id !== parent.id)
105
+ throw new ControlRefusal("not-owned", "sessionId");
106
+ const captured = this.admission.assert(parent);
107
+ const signal = AbortSignal.any([invocation.signal, invocation.peer.signal, this.lifetime.signal, this.admission.lifetime.signal]);
108
+ operationSignal = signal;
109
+ const check = () => {
110
+ signal.throwIfAborted();
111
+ const current = this.ctx.get("connection");
112
+ if (!current || (Reflect.get(current, symbols.original) ?? current) !== owner || current.browserPeer !== invocation.peer
113
+ || this.admission.assert(parent) !== captured || agents.get(parent.id) !== parent)
114
+ throw new ControlRefusal("not-owned", "sessionId");
115
+ };
116
+ check();
117
+ return await operation({ parent, epoch: captured.epoch, signal, check });
97
118
  }
98
119
  catch (error) {
99
120
  let info;
100
- if (error instanceof ControlRefusal)
101
- info = error.info;
121
+ if (operationSignal?.aborted)
122
+ info = { code: "cancelled" };
123
+ else if (error instanceof ControlRefusal)
124
+ info = { code: error.code, ...(error.field === undefined ? {} : { field: error.field }), ...(error.reason === undefined ? {} : { reason: error.reason }) };
125
+ else if (error instanceof TypeError)
126
+ info = { code: "validation", field: "request" };
102
127
  else {
103
- const code = String(remoteErrorOf(error)?.code ?? (error instanceof SubagentError ? error.code : ""));
104
- if (["gateway/cancelled", "ABORTED"].includes(code) || error instanceof Error && error.name === "AbortError")
128
+ const code = remoteErrorOf(error)?.code ?? (error instanceof SubagentError ? error.code : undefined);
129
+ if (code === "ABORTED" || code === "gateway/cancelled" || error instanceof Error && error.name === "AbortError")
105
130
  info = { code: "cancelled" };
106
- else if (["subagent/unauthorized", "UNAUTHORIZED"].includes(code))
131
+ else if (code === "UNAUTHORIZED" || code === "subagent/unauthorized")
107
132
  info = { code: "not-owned" };
108
- else if (["subagent/not-resumable", "NOT_RESUMABLE"].includes(code))
133
+ else if (code === "NOT_RESUMABLE" || code === "subagent/not-resumable")
109
134
  info = { code: "not-resumable", field: "childSessionId" };
110
135
  else if (code === "subagent/attachment-invalid" || code === "gateway/bad-request")
111
136
  info = { code: "invalid-content", field: "content" };
@@ -114,263 +139,85 @@ let DsmmChildrenHost = (() => {
114
139
  else
115
140
  info = { code: "unavailable" };
116
141
  }
117
- // Do not forward SDK messages, details, causes, paths, content or secrets.
118
- throw new RemoteError("dsmm-children/refused", "The Host refused the child control operation.", parseRoleControlErrorInfo(info));
119
- }
120
- }
121
- decode(parse, value) {
122
- try {
123
- return parse(value);
124
- }
125
- catch {
126
- throw new ControlRefusal("validation", "request");
142
+ throw new RemoteError("dsmm-children/refused", "The Host refused the native child control operation.", info);
127
143
  }
128
144
  }
129
- async scoped(sessionId, readOnly, operation) {
130
- const invocation = this.ctx.invocation;
131
- const connection = this.ctx.get("connection");
132
- if (invocation?.peer === undefined || connection === undefined || connection.operator !== invocation.peer)
133
- throw new ControlRefusal("not-owned");
134
- const connectionOwner = original(connection);
135
- const runtime = this.collaborators.runtime;
136
- if (!runtime.authority.view().deliveryFenceReady)
137
- throw new ControlRefusal("unavailable", undefined, "delivery-fence-unavailable");
138
- const browserSignal = runtime.authority.acquireBrowserSignal(this.ctx);
139
- const initialSignal = AbortSignal.any([invocation.signal, browserSignal, this.lifetime.signal]);
140
- const checkConnection = () => {
141
- if (initialSignal.aborted)
142
- throw new ControlRefusal("cancelled");
143
- const current = this.ctx.get("connection");
144
- if (current === undefined || original(current) !== connectionOwner || current.operator !== invocation.peer)
145
- throw new ControlRefusal("not-owned");
146
- const bound = this.ctx.get("subagents");
147
- if (bound === undefined || original(bound) !== original(runtime))
148
- throw new ControlRefusal("unavailable", undefined, "delivery-fence-unavailable");
149
- };
150
- checkConnection();
151
- const agents = this.ctx.get("agents");
152
- if (agents === undefined)
153
- throw new ControlRefusal("unavailable");
154
- let parent = agents.get(SessionId(sessionId));
155
- if (parent === undefined) {
156
- // Actions never wake an ordinary parent. Only an authenticated, decoded
157
- // read may use the public controller; Gateway parameter lookup cannot.
158
- if (!readOnly)
159
- throw new ControlRefusal("unavailable", "sessionId");
160
- const controller = this.ctx.get("sessionController");
161
- if (controller === undefined)
162
- throw new ControlRefusal("unavailable", "sessionId");
163
- const found = await controller.resolveAgent(SessionId(sessionId));
164
- checkConnection();
165
- if ("error" in found)
166
- throw new ControlRefusal("unavailable", "sessionId");
167
- parent = found.agent;
168
- }
169
- const exactParent = parent;
170
- const checkRoot = () => {
171
- checkConnection();
172
- const current = this.ctx.get("agents");
173
- if (current === undefined || current.get(SessionId(sessionId)) !== exactParent || exactParent.id !== sessionId || exactParent.session.id !== sessionId
174
- || exactParent.session.header.origin === "subagent" || !current.roots().includes(exactParent)
175
- || current.list().some(owner => owner !== exactParent && current.isOwnedBy(SessionId(sessionId), owner)))
176
- throw new ControlRefusal("not-owned", "sessionId");
177
- };
178
- checkRoot();
179
- const ticket = runtime.authority.acquireParentTicket(exactParent);
180
- const signal = AbortSignal.any([initialSignal, ticket.signal]);
181
- const scope = { parent: exactParent, ticket, signal, check() {
182
- if (signal.aborted)
183
- throw new ControlRefusal("cancelled");
184
- checkRoot();
185
- runtime.authority.assertTicket(ticket);
186
- } };
187
- scope.check();
188
- let result;
189
- try {
190
- result = await operation(scope);
191
- }
192
- catch (error) {
193
- if (signal.aborted)
194
- throw new ControlRefusal("cancelled");
195
- throw error;
196
- }
197
- // Native acceptance/handoff owns the write cutoff. Never turn a committed
198
- // receipt into a failure, rollback accepted work or automatically retry.
199
- if (readOnly)
200
- scope.check();
201
- return result;
202
- }
203
145
  capabilities(scope) {
204
146
  scope.check();
205
- const view = parseRoleControlCapabilities(this.collaborators.capabilities(scope.ticket));
206
- const runtime = this.collaborators.runtime.authority.view();
207
- scope.check();
208
- return { ...view, runtime };
147
+ const runtime = runtimeAdmissionView(this.ctx), settings = this.admission.assert(scope.parent).settings;
148
+ const control = !runtime.deliveryFenceReady || this.ctx.get("subagents") === undefined ? unavailable
149
+ : !settings.modules.deepwork.enabled ? disabled("module-off") : { enabled: true };
150
+ return { prompt: control, interrupt: control, images: control.enabled && this.ctx.get("attachments") !== undefined ? control : unavailable, runtime };
209
151
  }
210
- async childView(scope, entry, parentSessionId = scope.parent.id) {
211
- scope.check();
212
- const direct = parentSessionId === scope.parent.id;
213
- const inactive = this.ctx.get("agents")?.get(entry.id)?.status !== "running";
214
- const observation = direct ? await this.collaborators.observeChild(scope.ticket, entry, scope.signal) : undefined;
215
- scope.check();
216
- const reason = !direct ? "not-direct-child" : entry.mode === "one-shot" ? "one-shot" : "unknown-mode";
217
- const global = this.capabilities(scope);
218
- const controls = entry.mode === "continuable" && observation !== undefined
219
- ? { prompt: global.prompt.enabled ? observation.prompt : global.prompt, interrupt: global.interrupt.enabled ? observation.interrupt : global.interrupt }
220
- : { prompt: disabled(reason), interrupt: disabled(reason) };
221
- const projected = observation?.invocation === undefined ? undefined : parseDsmmInvocationView(observation.invocation);
222
- const routeComparison = observation?.routeComparison === undefined ? undefined : parseDsmmRoleRouteComparison(observation.routeComparison);
223
- if (projected?.childId !== undefined && projected.childId !== entry.id)
224
- throw new ControlRefusal("unavailable", "childSessionId");
225
- if (routeComparison !== undefined && routeComparison.childId !== entry.id)
226
- throw new ControlRefusal("unavailable", "childSessionId");
227
- return { id: entry.id, parentSessionId, mode: entry.mode, activity: inactive ? "inactive" : "running", readonly: !controls.prompt.enabled && !controls.interrupt.enabled,
228
- ...(entry.label === undefined ? {} : { label: boundedChildLabel(entry.label) }), controls,
229
- ...(projected === undefined ? {} : { invocation: { ...projected, childId: entry.id } }),
230
- ...(routeComparison === undefined ? {} : { routeComparison }),
231
- ...(observation?.evidence === undefined ? {} : { evidence: observation.evidence }) };
232
- }
233
- async runView(scope, holder) {
234
- scope.check();
235
- const identity = holder.invocation;
236
- const background = identity === undefined ? disabled(holder.state === "cancelled" ? "cancelled" : "starting")
237
- : await this.collaborators.backgroundAvailability(scope.ticket, identity, scope.signal);
152
+ child(scope, entry, parentId = scope.parent.id) {
238
153
  scope.check();
239
- const current = holder.invocation;
240
- let invocation;
241
- if (current !== undefined) {
242
- const { runId: _run, childId: _child, jobId: _job, ...projected } = parseDsmmInvocationView(this.collaborators.projectRun(current));
243
- const jobId = this.backgroundJobs.get(holder);
244
- invocation = parseDsmmInvocationView({ ...projected, mode: "one-shot", runId: current.runId,
245
- ...(current.childId === undefined ? {} : { childId: current.childId }), ...(jobId === undefined ? {} : { jobId }) });
246
- }
247
- const globalBackground = this.capabilities(scope).background;
248
- return { sessionId: holder.sessionId, toolCallId: holder.toolCallId, state: holder.state, ...(invocation === undefined ? {} : { invocation }),
249
- background: holder.state === "starting" ? disabled("starting") : holder.state === "settled" ? disabled("already-settled") : holder.state === "cancelled" ? disabled("cancelled")
250
- : holder.state === "background" ? disabled("already-background") : globalBackground.enabled ? background : globalBackground };
154
+ const child = this.ctx.get("agents")?.get(entry.id), direct = parentId === scope.parent.id;
155
+ const live = child && this.admission.get(child), invocation = child && this.admission.invocation(child);
156
+ const available = this.capabilities(scope);
157
+ const reason = !direct ? "not-direct-child" : entry.mode !== "continuable" ? entry.mode === "one-shot" ? "one-shot" : "unknown-mode" : !live || !child ? "evidence-unavailable" : undefined;
158
+ const control = reason !== undefined ? disabled(reason) : !this.ctx.get("agents")?.isOwnedBy(child.id, scope.parent) ? disabled("not-direct-child") : available.prompt;
159
+ return { id: entry.id, parentSessionId: parentId, mode: entry.mode === "external" ? "unknown" : entry.mode, activity: child?.status === "running" ? "running" : "inactive",
160
+ readonly: !control.enabled, controls: { prompt: control, interrupt: control }, ...(entry.label === undefined ? {} : { label: boundedLabel(entry.label) }),
161
+ ...(invocation === undefined ? {} : { invocation: invocationView(invocation, boundedLabel(entry.label ?? invocation.target), "continuable", { childId: entry.id }) }),
162
+ ...(child === undefined ? {} : { routeComparison: roleRouteComparison(child) }) };
251
163
  }
252
164
  describe(sessionId) {
253
- return this.invoke(() => this.scoped(this.decode(parseRoleControlSessionId, sessionId), true, async (scope) => {
254
- const catalog = await this.collaborators.runtime.listChildren(scope.parent.id, scope.signal);
255
- scope.check();
256
- const children = [], runs = [];
257
- for (const child of catalog)
258
- children.push(await this.childView(scope, child));
165
+ return this.scoped(sessionId, async (scope) => {
166
+ const rows = await this.ctx.get("subagents").listChildren(scope.parent.id, scope.signal);
259
167
  scope.check();
260
- for (const holder of this.collaborators.runs.list(scope.parent, scope.ticket.owner))
261
- runs.push(await this.runView(scope, holder));
262
- scope.check();
263
- return parseChildSessionSnapshot({ sessionId: scope.parent.id, admissionEpoch: scope.ticket.parentEpoch, children, runs, capabilities: this.capabilities(scope) });
264
- }));
168
+ return parseChildSessionSnapshot({ sessionId, admissionEpoch: scope.epoch, children: rows.map(row => this.child(scope, row)), capabilities: this.capabilities(scope) });
169
+ });
265
170
  }
266
171
  descendants(sessionId) {
267
- return this.invoke(() => this.scoped(this.decode(parseRoleControlSessionId, sessionId), true, async (scope) => {
268
- const catalog = await this.collaborators.runtime.listDescendants(scope.parent.id, scope.signal);
172
+ return this.scoped(sessionId, async (scope) => {
173
+ const rows = await this.ctx.get("subagents").listDescendants(scope.parent.id, scope.signal);
269
174
  scope.check();
270
- const descendants = [];
271
- for (const entry of catalog) {
272
- scope.check();
273
- if (entry.kind === "diagnostic")
274
- descendants.push({ kind: "diagnostic", id: entry.id, parentSessionId: entry.parentId, depth: entry.depth, reason: entry.reason });
275
- else {
276
- const child = await this.childView(scope, { id: entry.id, mode: entry.mode, createdAt: 0, ...("label" in entry ? { label: entry.label } : {}) }, entry.parentId);
277
- descendants.push({ kind: "child", depth: entry.depth, hasChildren: entry.hasChildren, child: { ...child, activity: entry.activity } });
278
- }
279
- }
280
- return parseRoleControlDescendants({ sessionId: scope.parent.id, admissionEpoch: scope.ticket.parentEpoch, descendants });
281
- }));
282
- }
283
- background(sessionId, input) {
284
- return this.invoke(async () => {
285
- const request = this.decode(parseRoleControlBackgroundRequest, input);
286
- if (request.sessionId !== this.decode(parseRoleControlSessionId, sessionId))
287
- throw new ControlRefusal("validation", "sessionId");
288
- return this.scoped(sessionId, false, async (scope) => {
289
- if (request.expectedAdmissionEpoch !== scope.ticket.parentEpoch)
290
- throw new ControlRefusal("conflict", "expectedAdmissionEpoch");
291
- const holder = this.collaborators.runs.get(scope.parent, scope.ticket.owner, { sessionId: scope.parent.id,
292
- toolCallId: request.toolCallId, runId: request.runId });
293
- if (holder?.invocation === undefined)
294
- throw new ControlRefusal("not-found", "runId");
295
- const terminal = terminalTransition(holder.state, holder.invocation.runId);
296
- if (terminal !== undefined) {
297
- scope.check();
298
- return terminal;
299
- }
300
- requireEnabled(this.capabilities(scope).background);
301
- const permitted = await this.collaborators.backgroundAvailability(scope.ticket, holder.invocation, scope.signal);
302
- scope.check();
303
- // Result/cancellation may win while asynchronous capability preparation
304
- // is pending. Observing that terminal state never creates a new job.
305
- const observed = terminalTransition(holder.state, holder.invocation.runId);
306
- if (observed !== undefined)
307
- return observed;
308
- requireEnabled(permitted);
309
- // All async preparation is fenced before the holder's native synchronous
310
- // jobs.start critical section, which rechecks its own exact authority.
311
- const result = holder.background({ parent: scope.parent, owner: scope.ticket.owner, sessionId: scope.parent.id,
312
- toolCallId: holder.toolCallId, runId: holder.invocation.runId, expectedAdmissionEpoch: request.expectedAdmissionEpoch });
313
- if ("receipt" in result) {
314
- this.backgroundJobs.set(holder, result.receipt.jobId);
315
- return { status: result.status, runId: result.receipt.invocation.runId, jobId: result.receipt.jobId };
316
- }
317
- if (result.status === "starting")
318
- throw new ControlRefusal("disabled", undefined, "starting");
319
- return { status: result.status, runId: request.runId };
320
- });
175
+ return parseRoleControlDescendants({ sessionId, admissionEpoch: scope.epoch, descendants: rows.map(row => row.kind === "diagnostic"
176
+ ? { kind: "diagnostic", id: row.id, parentSessionId: row.parentId, depth: row.depth, reason: row.reason }
177
+ : { kind: "child", depth: row.depth, hasChildren: row.hasChildren, child: { ...this.child(scope, row, row.parentId), readonly: true, controls: { prompt: disabled("not-direct-child"), interrupt: disabled("not-direct-child") } } }) });
321
178
  });
322
179
  }
323
- async directChild(scope, childId) {
324
- scope.check();
325
- const catalog = await this.collaborators.runtime.listChildren(scope.parent.id, scope.signal);
180
+ direct(scope, childId) {
326
181
  scope.check();
327
- const child = catalog.find(child => child.id === childId);
328
- if (child === undefined)
182
+ const child = this.ctx.get("agents")?.get(SessionId(childId));
183
+ if (!child)
184
+ throw new ControlRefusal("not-resumable", "childSessionId", "evidence-unavailable");
185
+ if (!this.ctx.get("agents")?.isOwnedBy(child.id, scope.parent))
329
186
  throw new ControlRefusal("not-owned", "childSessionId");
330
- if (child.mode !== "continuable")
331
- throw new ControlRefusal("not-resumable", "childSessionId");
332
- return this.childView(scope, child);
187
+ this.admission.assert(child);
188
+ return child;
333
189
  }
334
190
  prompt(sessionId, input) {
335
- return this.invoke(async () => {
336
- const request = this.decode(parseRoleControlPromptRequest, input);
337
- if (request.parentSessionId !== this.decode(parseRoleControlSessionId, sessionId))
191
+ return this.scoped(sessionId, async (scope) => {
192
+ const request = parseRoleControlPromptRequest(input);
193
+ if (request.parentSessionId !== sessionId)
338
194
  throw new ControlRefusal("validation", "parentSessionId");
339
- return this.scoped(sessionId, false, async (scope) => {
340
- requireEnabled(this.capabilities(scope).prompt);
341
- const child = await this.directChild(scope, request.childSessionId);
342
- scope.check();
343
- requireEnabled(child.controls.prompt);
344
- if (request.content.some(part => part.type === "image"))
345
- requireEnabled(this.capabilities(scope).images);
346
- scope.check();
347
- // Original browser request identity, content, images, zone and delivery
348
- // enter the unique C1 public override, then native pre-inbox cutoff.
349
- return this.ctx.subagents.prompt(request, scope.signal);
350
- });
195
+ const capabilities = this.capabilities(scope);
196
+ if (!capabilities.prompt.enabled)
197
+ throw new ControlRefusal("disabled", undefined, capabilities.prompt.reason);
198
+ if (request.content.some(part => part.type === "image") && !capabilities.images.enabled)
199
+ throw new ControlRefusal("disabled", "content", capabilities.images.reason);
200
+ this.direct(scope, request.childSessionId);
201
+ return this.ctx.get("subagents").prompt(request, scope.signal);
351
202
  });
352
203
  }
353
204
  interrupt(sessionId, input) {
354
- return this.invoke(async () => {
355
- const request = this.decode(parseRoleControlInterruptRequest, input);
356
- if (request.parentSessionId !== this.decode(parseRoleControlSessionId, sessionId))
205
+ return this.scoped(sessionId, async (scope) => {
206
+ const request = parseRoleControlInterruptRequest(input);
207
+ if (request.parentSessionId !== sessionId)
357
208
  throw new ControlRefusal("validation", "parentSessionId");
358
- return this.scoped(sessionId, false, async (scope) => {
359
- requireEnabled(this.capabilities(scope).interrupt);
360
- const child = await this.directChild(scope, request.childSessionId);
361
- scope.check();
362
- requireEnabled(child.controls.interrupt);
363
- scope.check();
364
- return this.ctx.subagents.interruptByParent(SessionId(request.childSessionId), scope.parent.id, "continuable");
365
- });
209
+ const capabilities = this.capabilities(scope);
210
+ if (!capabilities.interrupt.enabled)
211
+ throw new ControlRefusal("disabled", undefined, capabilities.interrupt.reason);
212
+ this.direct(scope, request.childSessionId);
213
+ return this.ctx.get("subagents").interruptByParent(SessionId(request.childSessionId), scope.parent.id, "continuable");
366
214
  });
367
215
  }
368
216
  };
369
217
  })();
370
218
  export { DsmmChildrenHost };
371
- /** Caller supplies an owned Host injection fiber; no replacement or auto-mount. */
372
- export function registerRoleControlRpc(ctx, collaborators) {
373
- const host = new DsmmChildrenHost(ctx, collaborators);
219
+ export function registerRoleControlRpc(ctx, admission) {
220
+ const host = new DsmmChildrenHost(ctx, admission);
374
221
  ctx.typert.register(ROLE_CONTROL_HOST);
375
222
  return host;
376
223
  }
@@ -1,9 +1,8 @@
1
1
  /** Browser-safe child control vocabulary; no Host or filesystem authority. */
2
2
  import type { DsmmInvocationView, DsmmRoleRouteComparison, SubagentRuntimeAdmissionView } from "./profile-types.js";
3
- import type { ChildAdmissionEvidenceView } from "./child-evidence.js";
4
3
  import type { SubagentPromptReceipt, SubagentPromptRequest, SubagentInterruptReceipt } from "@deepseek-ai/dsh-subagent";
5
- export type { DsmmInvocationView, DsmmRoleRouteComparison, ChildAdmissionEvidenceView, SubagentPromptRequest, SubagentPromptReceipt, SubagentInterruptReceipt };
6
- export declare const ROLE_CONTROL_DISABLED_REASONS: readonly ["module-off", "role-disabled", "read-only", "background-disabled", "jobs-unavailable", "starting", "already-background", "already-settled", "cancelled", "one-shot", "unknown-mode", "not-direct-child", "delivery-fence-unavailable", "evidence-unavailable", "legacy-capability-denied", "unavailable"];
4
+ export type { DsmmInvocationView, DsmmRoleRouteComparison, SubagentPromptRequest, SubagentPromptReceipt, SubagentInterruptReceipt };
5
+ export declare const ROLE_CONTROL_DISABLED_REASONS: readonly ["module-off", "role-disabled", "read-only", "one-shot", "unknown-mode", "not-direct-child", "evidence-unavailable", "unavailable"];
7
6
  export type RoleControlDisabledReason = typeof ROLE_CONTROL_DISABLED_REASONS[number];
8
7
  export type RoleControlAvailability = {
9
8
  enabled: true;
@@ -12,21 +11,12 @@ export type RoleControlAvailability = {
12
11
  reason: RoleControlDisabledReason;
13
12
  };
14
13
  export interface RoleControlCapabilities {
15
- background: RoleControlAvailability;
16
14
  prompt: RoleControlAvailability;
17
15
  interrupt: RoleControlAvailability;
18
16
  /** The native attachment/model admission still validates each image. */
19
17
  images: RoleControlAvailability;
20
18
  runtime: SubagentRuntimeAdmissionView;
21
19
  }
22
- export interface RoleControlRunView {
23
- sessionId: string;
24
- toolCallId: string;
25
- state: "starting" | "running" | "background" | "settled" | "cancelled";
26
- /** Absent before the real native run is published. */
27
- invocation?: DsmmInvocationView;
28
- background: RoleControlAvailability;
29
- }
30
20
  export interface RoleControlChildView {
31
21
  id: string;
32
22
  parentSessionId: string;
@@ -36,7 +26,6 @@ export interface RoleControlChildView {
36
26
  readonly: boolean;
37
27
  invocation?: DsmmInvocationView;
38
28
  routeComparison?: DsmmRoleRouteComparison;
39
- evidence?: ChildAdmissionEvidenceView;
40
29
  controls: {
41
30
  prompt: RoleControlAvailability;
42
31
  interrupt: RoleControlAvailability;
@@ -45,7 +34,6 @@ export interface RoleControlChildView {
45
34
  export interface ChildSessionSnapshot {
46
35
  sessionId: string;
47
36
  admissionEpoch: string;
48
- runs: RoleControlRunView[];
49
37
  children: RoleControlChildView[];
50
38
  capabilities: RoleControlCapabilities;
51
39
  }
@@ -66,24 +54,13 @@ export interface RoleControlDescendantsSnapshot {
66
54
  admissionEpoch: string;
67
55
  descendants: RoleControlDescendantView[];
68
56
  }
69
- export interface RoleControlBackgroundRequest {
70
- sessionId: string;
71
- toolCallId: string;
72
- runId: string;
73
- expectedAdmissionEpoch: string;
74
- }
75
- export interface BackgroundTransitionResult {
76
- status: "background" | "already-background" | "already-settled" | "cancelled";
77
- runId: string;
78
- jobId?: string;
79
- }
80
57
  export interface RoleControlInterruptRequest {
81
58
  parentSessionId: string;
82
59
  childSessionId: string;
83
60
  mode: "continuable";
84
61
  }
85
62
  export declare const ROLE_CONTROL_ERROR_CODES: readonly ["validation", "not-owned", "unavailable", "cancelled", "conflict", "not-found", "not-resumable", "invalid-content", "invalid-time-zone", "disabled"];
86
- export declare const ROLE_CONTROL_ERROR_FIELDS: readonly ["sessionId", "parentSessionId", "childSessionId", "toolCallId", "runId", "expectedAdmissionEpoch", "request", "content", "clientTimeZone"];
63
+ export declare const ROLE_CONTROL_ERROR_FIELDS: readonly ["sessionId", "parentSessionId", "childSessionId", "request", "content", "clientTimeZone"];
87
64
  export interface RoleControlErrorInfo {
88
65
  code: typeof ROLE_CONTROL_ERROR_CODES[number];
89
66
  field?: typeof ROLE_CONTROL_ERROR_FIELDS[number];
@@ -1,8 +1,7 @@
1
1
  export const ROLE_CONTROL_DISABLED_REASONS = [
2
- "module-off", "role-disabled", "read-only", "background-disabled", "jobs-unavailable",
3
- "starting", "already-background", "already-settled", "cancelled", "one-shot", "unknown-mode", "not-direct-child",
4
- "delivery-fence-unavailable", "evidence-unavailable", "legacy-capability-denied", "unavailable",
2
+ "module-off", "role-disabled", "read-only", "one-shot", "unknown-mode", "not-direct-child",
3
+ "evidence-unavailable", "unavailable",
5
4
  ];
6
5
  export const ROLE_CONTROL_ERROR_CODES = ["validation", "not-owned", "unavailable", "cancelled", "conflict", "not-found", "not-resumable", "invalid-content", "invalid-time-zone", "disabled"];
7
- export const ROLE_CONTROL_ERROR_FIELDS = ["sessionId", "parentSessionId", "childSessionId", "toolCallId", "runId", "expectedAdmissionEpoch", "request", "content", "clientTimeZone"];
6
+ export const ROLE_CONTROL_ERROR_FIELDS = ["sessionId", "parentSessionId", "childSessionId", "request", "content", "clientTimeZone"];
8
7
  //# sourceMappingURL=role-control-types.js.map
@@ -0,0 +1,5 @@
1
+ import type { DshAgent } from "./dsh-types.js";
2
+ import type { DsmmRoleId } from "./roles.js";
3
+ /** The caller supplies the policy-admitted identity; only its Agent layer is changed. */
4
+ export declare function registerRoleHarnessIdentity(agent: DshAgent, role: DsmmRoleId): () => void;
5
+ //# sourceMappingURL=role-identity.d.ts.map
@@ -0,0 +1,10 @@
1
+ import { nativeAgentContext } from "./native-scope.js";
2
+ import { buildRoleIdentity } from "./prompt-content.js";
3
+ import { DSMM_ROLES } from "./roles.js";
4
+ /** The caller supplies the policy-admitted identity; only its Agent layer is changed. */
5
+ export function registerRoleHarnessIdentity(agent, role) {
6
+ const prompt = nativeAgentContext(agent).get("systemPrompt");
7
+ return prompt.section({ name: "harness:identity", order: prompt.getSectionOrder("HARNESS_IDENTITY"),
8
+ text: buildRoleIdentity(DSMM_ROLES.find(row => row.id === role)) });
9
+ }
10
+ //# sourceMappingURL=role-identity.js.map
@@ -22,16 +22,16 @@ export interface ResolvedRoleInvocation {
22
22
  }
23
23
  export declare function duringRoleInvocation<T>(parent: DshAgent, invocation: ResolvedRoleInvocation, operation: () => T): T;
24
24
  export declare function currentRoleInvocation(parent: DshAgent, target: DsmmRoleId): ResolvedRoleInvocation | undefined;
25
- export declare function bindRoleInvocation(agent: DshAgent, invocation: ResolvedRoleInvocation, original: ChildAdmissionCapture | undefined): void;
25
+ export declare function bindRoleInvocation(agent: DshAgent, invocation: ResolvedRoleInvocation, original?: ChildAdmissionCapture): void;
26
26
  export declare function capturedRoleInvocation(agent: DshAgent): ResolvedRoleInvocation | undefined;
27
27
  export declare function capturedOriginalRoleInvocation(agent: DshAgent): ChildAdmissionCapture["invocation"] | undefined;
28
28
  /** Complete selections replace model and effort together; effort-only selections narrow candidates. */
29
29
  export declare function resolveRoleInvocation(parent: Agent, target: DsmmRoleId, settings: DsmmSettings, signal: AbortSignal, options?: DsmmInvocationOptions, nativeOptions?: AgentOptions): Promise<ResolvedRoleInvocation>;
30
30
  export declare function invocationAgentOptions(invocation: ResolvedRoleInvocation, options?: AgentOptions): AgentOptions;
31
31
  export declare function invocationView(invocation: ResolvedRoleInvocation, label: string, mode: DsmmInvocationView["mode"], ids?: Pick<DsmmInvocationView, "runId" | "childId" | "jobId">): {
32
- jobId?: string | undefined;
33
32
  runId?: string | undefined;
34
33
  childId?: string | undefined;
34
+ jobId?: string | undefined;
35
35
  role: "dsmm-orchestrator" | "dsmm-planner" | "dsmm-plan-critic" | "dsmm-builder" | "dsmm-reviewer" | "dsmm-oracle" | "dsmm-oracle-2nd" | "dsmm-creative" | "dsmm-code-search" | "dsmm-doc-search" | "dsmm-clarifier" | "dsmm-media-reader" | "dsmm-frontend" | "dsmm-hard-reasoning" | "dsmm-research" | "dsmm-quick" | "dsmm-coding" | "dsmm-normal-task" | "dsmm-complex" | "dsmm-deep" | "dsmm-documenting" | "dsmm-cross-cutting";
36
36
  label: string;
37
37
  level: DsmmInvocationLevel;