@dsmm/dsmm 0.3.0 → 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 (166) hide show
  1. package/README.md +26 -40
  2. package/cordis.patch.yml +0 -13
  3. package/docs/agent-presets.md +26 -14
  4. package/docs/compatibility.md +19 -73
  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 -280
  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 +12 -2
  20. package/lib/child-capture.js +22 -5
  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 +27 -52
  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 +84 -24
  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 +2713 -2361
  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 +16 -20
  82. package/lib/index.js +130 -416
  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/preset-registry.js +3 -2
  97. package/lib/preset-skills.d.ts +3 -12
  98. package/lib/preset-skills.js +28 -58
  99. package/lib/profile-diagnostics.d.ts +1 -1
  100. package/lib/profile-diagnostics.js +2 -2
  101. package/lib/profile-remote.js +61 -22
  102. package/lib/profile-rpc.d.ts +4 -3
  103. package/lib/profile-rpc.js +33 -37
  104. package/lib/profile-runtime.d.ts +31 -74
  105. package/lib/profile-runtime.js +224 -639
  106. package/lib/profile-store.d.ts +18 -6
  107. package/lib/profile-store.js +104 -62
  108. package/lib/profile-types.d.ts +18 -4
  109. package/lib/profiles.d.ts +3 -1
  110. package/lib/profiles.js +9 -7
  111. package/lib/prompt-content.d.ts +1 -0
  112. package/lib/prompt-content.js +4 -1
  113. package/lib/prompts.d.ts +2 -12
  114. package/lib/prompts.js +11 -66
  115. package/lib/role-control-remote.d.ts +1 -4
  116. package/lib/role-control-remote.js +8 -36
  117. package/lib/role-control-rpc.d.ts +10 -36
  118. package/lib/role-control-rpc.js +112 -269
  119. package/lib/role-control-types.d.ts +3 -26
  120. package/lib/role-control-types.js +3 -4
  121. package/lib/role-identity.d.ts +5 -0
  122. package/lib/role-identity.js +10 -0
  123. package/lib/role-invocation.d.ts +2 -2
  124. package/lib/role-llm-runtime.js +5 -11
  125. package/lib/role-policy.d.ts +19 -50
  126. package/lib/role-policy.js +136 -508
  127. package/lib/role-providers.d.ts +5 -8
  128. package/lib/role-providers.js +20 -86
  129. package/lib/role-routing.d.ts +1 -3
  130. package/lib/role-routing.js +24 -34
  131. package/lib/role-subagents.d.ts +5 -14
  132. package/lib/role-subagents.js +148 -106
  133. package/lib/runtime-integration.d.ts +5 -78
  134. package/lib/runtime-integration.js +11 -697
  135. package/lib/session-metadata.d.ts +13 -12
  136. package/lib/session-metadata.js +6 -31
  137. package/lib/session-scope.js +2 -1
  138. package/lib/settings.d.ts +5 -18
  139. package/lib/settings.js +19 -43
  140. package/lib/state.d.ts +3 -2
  141. package/lib/state.js +26 -10
  142. package/lib/status.d.ts +1 -9
  143. package/lib/status.js +3 -55
  144. package/lib/web-fetch-address-policy.d.ts +24 -0
  145. package/lib/web-fetch-address-policy.js +189 -0
  146. package/lib/web-fetch-fakeip.d.ts +25 -0
  147. package/lib/web-fetch-fakeip.js +107 -0
  148. package/package.json +113 -103
  149. package/docs/research/deepseek-v4-pro.md +0 -74
  150. package/docs/research/oh-dsh.md +0 -96
  151. package/lib/agent-registry.d.ts +0 -36
  152. package/lib/agent-registry.js +0 -75
  153. package/lib/child-admission.d.ts +0 -40
  154. package/lib/child-admission.js +0 -151
  155. package/lib/delivery-authority.d.ts +0 -83
  156. package/lib/delivery-authority.js +0 -397
  157. package/lib/native-child-evidence.d.ts +0 -40
  158. package/lib/native-child-evidence.js +0 -104
  159. package/lib/role-runs.d.ts +0 -138
  160. package/lib/role-runs.js +0 -335
  161. package/lib/session-persistence.d.ts +0 -36
  162. package/lib/session-persistence.js +0 -304
  163. package/lib/subagent-runtime.d.ts +0 -57
  164. package/lib/subagent-runtime.js +0 -257
  165. package/prompts/deepseek-flash.md +0 -11
  166. package/prompts/deepseek-v4-pro.md +0 -14
@@ -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,267 +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.browserPeer !== 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, invocation.peer.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.browserPeer !== 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 projected = observation?.invocation === undefined ? undefined : parseDsmmInvocationView(observation.invocation);
217
- const mode = entry.mode === "external" ? "unknown" : entry.mode === "continuable" && projected?.mode === "one-shot" ? "one-shot" : entry.mode;
218
- const reason = !direct ? "not-direct-child" : mode === "one-shot" ? "one-shot" : "unknown-mode";
219
- const global = this.capabilities(scope);
220
- const controls = mode === "continuable" && entry.mode === "continuable" && observation !== undefined
221
- ? { prompt: global.prompt.enabled ? observation.prompt : global.prompt, interrupt: global.interrupt.enabled ? observation.interrupt : global.interrupt }
222
- : { prompt: disabled(reason), interrupt: disabled(reason) };
223
- const routeComparison = observation?.routeComparison === undefined ? undefined : parseDsmmRoleRouteComparison(observation.routeComparison);
224
- if (projected?.childId !== undefined && projected.childId !== entry.id)
225
- throw new ControlRefusal("unavailable", "childSessionId");
226
- if (routeComparison !== undefined && routeComparison.childId !== entry.id)
227
- throw new ControlRefusal("unavailable", "childSessionId");
228
- return { id: entry.id, parentSessionId, mode, activity: inactive ? "inactive" : "running", readonly: !controls.prompt.enabled && !controls.interrupt.enabled,
229
- ...(entry.label === undefined ? {} : { label: boundedChildLabel(entry.label) }), controls,
230
- ...(projected === undefined ? {} : { invocation: { ...projected, childId: entry.id } }),
231
- ...(routeComparison === undefined ? {} : { routeComparison }),
232
- ...(observation?.evidence === undefined ? {} : { evidence: observation.evidence }) };
233
- }
234
- async runView(scope, holder) {
235
- scope.check();
236
- const identity = holder.invocation;
237
- const background = identity === undefined ? disabled(holder.state === "cancelled" ? "cancelled" : "starting")
238
- : await this.collaborators.backgroundAvailability(scope.ticket, identity, scope.signal);
152
+ child(scope, entry, parentId = scope.parent.id) {
239
153
  scope.check();
240
- const current = holder.invocation;
241
- let invocation;
242
- if (current !== undefined) {
243
- const { runId: _run, childId: _child, jobId: _job, ...projected } = parseDsmmInvocationView(this.collaborators.projectRun(current));
244
- const jobId = this.backgroundJobs.get(holder);
245
- invocation = parseDsmmInvocationView({ ...projected, mode: "one-shot", runId: current.runId,
246
- ...(current.childId === undefined ? {} : { childId: current.childId }), ...(jobId === undefined ? {} : { jobId }) });
247
- }
248
- const globalBackground = this.capabilities(scope).background;
249
- return { sessionId: holder.sessionId, toolCallId: holder.toolCallId, state: holder.state, ...(invocation === undefined ? {} : { invocation }),
250
- background: holder.state === "starting" ? disabled("starting") : holder.state === "settled" ? disabled("already-settled") : holder.state === "cancelled" ? disabled("cancelled")
251
- : 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) }) };
252
163
  }
253
164
  describe(sessionId) {
254
- return this.invoke(() => this.scoped(this.decode(parseRoleControlSessionId, sessionId), true, async (scope) => {
255
- const catalog = await this.collaborators.runtime.listChildren(scope.parent.id, scope.signal);
256
- scope.check();
257
- const children = [], runs = [];
258
- for (const child of catalog)
259
- 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);
260
167
  scope.check();
261
- for (const holder of this.collaborators.runs.list(scope.parent, scope.ticket.owner))
262
- runs.push(await this.runView(scope, holder));
263
- scope.check();
264
- return parseChildSessionSnapshot({ sessionId: scope.parent.id, admissionEpoch: scope.ticket.parentEpoch, children, runs, capabilities: this.capabilities(scope) });
265
- }));
168
+ return parseChildSessionSnapshot({ sessionId, admissionEpoch: scope.epoch, children: rows.map(row => this.child(scope, row)), capabilities: this.capabilities(scope) });
169
+ });
266
170
  }
267
171
  descendants(sessionId) {
268
- return this.invoke(() => this.scoped(this.decode(parseRoleControlSessionId, sessionId), true, async (scope) => {
269
- 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);
270
174
  scope.check();
271
- const descendants = [];
272
- for (const entry of catalog) {
273
- scope.check();
274
- if (entry.kind === "diagnostic")
275
- descendants.push({ kind: "diagnostic", id: entry.id, parentSessionId: entry.parentId, depth: entry.depth, reason: entry.reason });
276
- else {
277
- const child = await this.childView(scope, { id: entry.id, mode: entry.mode, createdAt: 0, ...("label" in entry ? { label: entry.label } : {}) }, entry.parentId);
278
- descendants.push({ kind: "child", depth: entry.depth, hasChildren: entry.hasChildren, child: { ...child, activity: entry.activity } });
279
- }
280
- }
281
- return parseRoleControlDescendants({ sessionId: scope.parent.id, admissionEpoch: scope.ticket.parentEpoch, descendants });
282
- }));
283
- }
284
- background(sessionId, input) {
285
- return this.invoke(async () => {
286
- const request = this.decode(parseRoleControlBackgroundRequest, input);
287
- if (request.sessionId !== this.decode(parseRoleControlSessionId, sessionId))
288
- throw new ControlRefusal("validation", "sessionId");
289
- return this.scoped(sessionId, false, async (scope) => {
290
- if (request.expectedAdmissionEpoch !== scope.ticket.parentEpoch)
291
- throw new ControlRefusal("conflict", "expectedAdmissionEpoch");
292
- const holder = this.collaborators.runs.get(scope.parent, scope.ticket.owner, { sessionId: scope.parent.id,
293
- toolCallId: request.toolCallId, runId: request.runId });
294
- if (holder?.invocation === undefined)
295
- throw new ControlRefusal("not-found", "runId");
296
- const terminal = terminalTransition(holder.state, holder.invocation.runId);
297
- if (terminal !== undefined) {
298
- scope.check();
299
- return terminal;
300
- }
301
- requireEnabled(this.capabilities(scope).background);
302
- const permitted = await this.collaborators.backgroundAvailability(scope.ticket, holder.invocation, scope.signal);
303
- scope.check();
304
- // Result/cancellation may win while asynchronous capability preparation
305
- // is pending. Observing that terminal state never creates a new job.
306
- const observed = terminalTransition(holder.state, holder.invocation.runId);
307
- if (observed !== undefined)
308
- return observed;
309
- requireEnabled(permitted);
310
- // All async preparation is fenced before the holder's native synchronous
311
- // jobs.start critical section, which rechecks its own exact authority.
312
- const result = holder.background({ parent: scope.parent, owner: scope.ticket.owner, sessionId: scope.parent.id,
313
- toolCallId: holder.toolCallId, runId: holder.invocation.runId, expectedAdmissionEpoch: request.expectedAdmissionEpoch });
314
- if ("receipt" in result) {
315
- this.backgroundJobs.set(holder, result.receipt.jobId);
316
- return { status: result.status, runId: result.receipt.invocation.runId, jobId: result.receipt.jobId };
317
- }
318
- if (result.status === "starting")
319
- throw new ControlRefusal("disabled", undefined, "starting");
320
- return { status: result.status, runId: request.runId };
321
- });
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") } } }) });
322
178
  });
323
179
  }
324
- async directChild(scope, childId) {
325
- scope.check();
326
- const catalog = await this.collaborators.runtime.listChildren(scope.parent.id, scope.signal);
180
+ direct(scope, childId) {
327
181
  scope.check();
328
- const child = catalog.find(child => child.id === childId);
329
- 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))
330
186
  throw new ControlRefusal("not-owned", "childSessionId");
331
- if (child.mode !== "continuable")
332
- throw new ControlRefusal("not-resumable", "childSessionId");
333
- const view = await this.childView(scope, child);
334
- if (view.mode !== "continuable")
335
- throw new ControlRefusal("not-resumable", "childSessionId");
336
- return view;
187
+ this.admission.assert(child);
188
+ return child;
337
189
  }
338
190
  prompt(sessionId, input) {
339
- return this.invoke(async () => {
340
- const request = this.decode(parseRoleControlPromptRequest, input);
341
- if (request.parentSessionId !== this.decode(parseRoleControlSessionId, sessionId))
191
+ return this.scoped(sessionId, async (scope) => {
192
+ const request = parseRoleControlPromptRequest(input);
193
+ if (request.parentSessionId !== sessionId)
342
194
  throw new ControlRefusal("validation", "parentSessionId");
343
- return this.scoped(sessionId, false, async (scope) => {
344
- requireEnabled(this.capabilities(scope).prompt);
345
- const child = await this.directChild(scope, request.childSessionId);
346
- scope.check();
347
- requireEnabled(child.controls.prompt);
348
- if (request.content.some(part => part.type === "image"))
349
- requireEnabled(this.capabilities(scope).images);
350
- scope.check();
351
- // Original browser request identity, content, images, zone and delivery
352
- // enter the unique C1 public override, then native pre-inbox cutoff.
353
- return this.ctx.subagents.prompt(request, scope.signal);
354
- });
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);
355
202
  });
356
203
  }
357
204
  interrupt(sessionId, input) {
358
- return this.invoke(async () => {
359
- const request = this.decode(parseRoleControlInterruptRequest, input);
360
- if (request.parentSessionId !== this.decode(parseRoleControlSessionId, sessionId))
205
+ return this.scoped(sessionId, async (scope) => {
206
+ const request = parseRoleControlInterruptRequest(input);
207
+ if (request.parentSessionId !== sessionId)
361
208
  throw new ControlRefusal("validation", "parentSessionId");
362
- return this.scoped(sessionId, false, async (scope) => {
363
- requireEnabled(this.capabilities(scope).interrupt);
364
- const child = await this.directChild(scope, request.childSessionId);
365
- scope.check();
366
- requireEnabled(child.controls.interrupt);
367
- scope.check();
368
- return this.ctx.subagents.interruptByParent(SessionId(request.childSessionId), scope.parent.id, "continuable");
369
- });
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");
370
214
  });
371
215
  }
372
216
  };
373
217
  })();
374
218
  export { DsmmChildrenHost };
375
- /** Caller supplies an owned Host injection fiber; no replacement or auto-mount. */
376
- export function registerRoleControlRpc(ctx, collaborators) {
377
- const host = new DsmmChildrenHost(ctx, collaborators);
219
+ export function registerRoleControlRpc(ctx, admission) {
220
+ const host = new DsmmChildrenHost(ctx, admission);
378
221
  ctx.typert.register(ROLE_CONTROL_HOST);
379
222
  return host;
380
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
+ runId?: string | undefined;
32
33
  childId?: string | undefined;
33
34
  jobId?: string | undefined;
34
- runId?: 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;