@dsmm/dsmm 0.3.25 → 0.3.27

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 (54) hide show
  1. package/README.md +21 -8
  2. package/docs/agent-presets.md +7 -7
  3. package/docs/agent-teams.md +27 -0
  4. package/docs/compatibility.md +7 -5
  5. package/docs/lsp.md +10 -12
  6. package/docs/maintenance.md +29 -0
  7. package/docs/roadmap.md +25 -9
  8. package/docs/runtime-recovery.md +3 -3
  9. package/docs/testing.md +2 -1
  10. package/docs/web-fetch-fakeip.md +1 -1
  11. package/dsh-plugin.json +1 -1
  12. package/lib/client/NativeToolView-data.d.ts +8 -0
  13. package/lib/client/NativeToolView-data.js +19 -0
  14. package/lib/client/NativeToolView.d.ts +19 -0
  15. package/lib/client/NativeToolView.js +46 -0
  16. package/lib/client/RoleToolView-data.js +1 -1
  17. package/lib/client/RoleToolView-locales.d.ts +7 -0
  18. package/lib/client/RoleToolView-locales.js +6 -0
  19. package/lib/client/RoleToolView.js +2 -0
  20. package/lib/client/children-locales.d.ts +5 -5
  21. package/lib/client/controller.js +20 -0
  22. package/lib/client.js +347 -186
  23. package/lib/core-permission-authority.js +19 -8
  24. package/lib/deployment-permission-rules.js +2 -1
  25. package/lib/dsh-types.d.ts +2 -2
  26. package/lib/mode.js +2 -2
  27. package/lib/native-admission.d.ts +8 -0
  28. package/lib/native-admission.js +285 -48
  29. package/lib/native-ownership.d.ts +20 -0
  30. package/lib/native-ownership.js +92 -0
  31. package/lib/native-subagents.d.ts +21 -0
  32. package/lib/native-subagents.js +31 -0
  33. package/lib/permission-rpc.js +3 -2
  34. package/lib/preset-registry.js +2 -1
  35. package/lib/profile-rpc.js +4 -3
  36. package/lib/profile-runtime.d.ts +1 -1
  37. package/lib/profile-runtime.js +2 -1
  38. package/lib/prompts.d.ts +2 -0
  39. package/lib/prompts.js +14 -8
  40. package/lib/role-control-remote.js +19 -8
  41. package/lib/role-control-rpc.js +11 -9
  42. package/lib/role-control-types.d.ts +18 -5
  43. package/lib/role-identity.js +3 -19
  44. package/lib/role-invocation.d.ts +1 -1
  45. package/lib/role-policy.d.ts +11 -3
  46. package/lib/role-policy.js +64 -23
  47. package/lib/role-subagents.js +26 -6
  48. package/lib/session-metadata.d.ts +27 -1
  49. package/lib/session-metadata.js +46 -0
  50. package/lib/session-scope.d.ts +1 -1
  51. package/lib/session-scope.js +2 -2
  52. package/package.json +116 -114
  53. package/prompts/source/deepwork/general.md +19 -0
  54. package/prompts/source/shared/native-teams.md +11 -0
@@ -1,3 +1,4 @@
1
+ import { nativeIsOwnedBy, nativeSameTree, nativeTreeRoot } from "./native-ownership.js";
1
2
  import { AsyncLocalStorage } from "node:async_hooks";
2
3
  import { SubagentError, delegationDepthOf } from "@deepseek-ai/dsh-subagent";
3
4
  import { Context, symbols } from "@deepseek-ai/cordis";
@@ -12,7 +13,7 @@ const liveIdentities = new WeakMap();
12
13
  const toolIdentities = new WeakMap();
13
14
  const controlledDefinitions = new WeakSet();
14
15
  export const READONLY_ROLE_DENIED_TOOLS = ["write", "edit", "bash", "pwsh"];
15
- const readTools = new Set(["read", "glob", "grep", "read_image", "web_search", "web_fetch", "skill", "load_skill", "structured_output", "send_message", "interrupt_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"]);
16
+ const readTools = new Set(["read", "glob", "grep", "read_image", "web_search", "web_fetch", "skill", "load_skill", "structured_output", "send_message", "interrupt_agent", "list_agents", "wait_agent", "team_task_list", "team_task_get", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"]);
16
17
  const readLsp = new Set(["status", "diagnostics", "goto_definition", "find_references", "find_symbol_related", "symbols", "prepare_rename"]);
17
18
  export function roleToolName(role) { return role.replace(/-/gu, "_"); }
18
19
  export function roleFromToolName(name) { return name === "explore" ? "dsmm-code-search" : DSMM_ROLES.find(row => roleToolName(row.id) === name)?.id; }
@@ -31,7 +32,7 @@ export function resolveAdmittedDsmmRole(agent, settings, active) {
31
32
  if (!settings.modules.deepwork.enabled || !agent.ctx.get("dsmmNativeAdmission")?.owns(agent) || agent.session.header?.origin === "subagent")
32
33
  return undefined;
33
34
  const preset = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx);
34
- const role = isDsmmRoleId(preset) ? preset : active ? "dsmm-orchestrator" : undefined;
35
+ const role = isDsmmRoleId(preset) ? preset : undefined;
35
36
  return role !== undefined && settings.roles[role] ? role : undefined;
36
37
  }
37
38
  return resolveEffectiveDsmmRole(agent, settings, active);
@@ -40,13 +41,11 @@ export function resolveAdmittedDsmmRole(agent, settings, active) {
40
41
  export class DsmmRolePolicy {
41
42
  ctx;
42
43
  getSettings;
43
- mode;
44
44
  executions = new AsyncLocalStorage();
45
45
  toolCalls = new WeakMap();
46
- constructor(ctx, getSettings, mode) {
46
+ constructor(ctx, getSettings, _mode) {
47
47
  this.ctx = ctx;
48
48
  this.getSettings = getSettings;
49
- this.mode = mode;
50
49
  }
51
50
  agents() { const agents = this.ctx.get?.("agents"); if (!agents)
52
51
  throw new SubagentError("Native registry unavailable", "UNAUTHORIZED"); return agents; }
@@ -65,26 +64,63 @@ export class DsmmRolePolicy {
65
64
  this.assertLive(agent);
66
65
  this.assertLive(parent);
67
66
  this.assertDelegation(parent, invocation.target);
68
- if (!this.agents().isOwnedBy(agent.id, parent) || agent.session.header?.parentSession !== parent.id || !independentComposition && this.selected(agent) !== this.selected(parent))
67
+ if (!nativeIsOwnedBy(this.agents(), agent.id, parent) || agent.session.header?.parentSession !== parent.id || !independentComposition && this.selected(agent) !== this.selected(parent))
69
68
  throw new SubagentError("Child lineage or composition mismatch", "UNAUTHORIZED");
70
69
  if (maximum !== undefined && delegationDepthOf(agent) > maximum)
71
70
  throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
72
71
  const upstream = this.identity(parent);
73
- liveIdentities.set(agent, Object.freeze({ role: invocation.target, child: true, parent, preset: this.selected(agent), epoch: admission.epoch, independentComposition,
72
+ liveIdentities.set(agent, Object.freeze({ role: invocation.target, child: true, parent,
73
+ owner: nativeTreeRoot(this.agents(), agent) ?? parent, creatorId: parent.id, maxDepth: this.maximumDepth(parent, maximum),
74
+ preset: this.selected(agent), epoch: admission.epoch, independentComposition, targetCeiling: upstream.targetCeiling,
74
75
  readOnly: this.readOnly(upstream) || DSMM_ROLES.find(row => row.id === invocation.target).access === "read-only",
75
76
  toolFilter: inheritToolFilter(inheritToolFilter(upstream.toolFilter, toolFilter), this.visibleToolCeiling(parent)) }));
76
77
  bindRoleInvocation(agent, invocation);
77
78
  captureRoleRuntimePolicy(admission.settings, invocation.target, invocation.policy);
78
79
  }
80
+ /** Cold identity is proven by native catalog/descriptor evidence before this binding. */
81
+ bindContinuedChild(agent, owner, admission, invocation, ceiling, maximum, independentComposition) {
82
+ this.assertLive(agent);
83
+ this.assertModuleAdmission(owner);
84
+ if (!nativeSameTree(this.agents(), agent, owner) || nativeTreeRoot(this.agents(), agent) !== owner
85
+ || agent.id !== ceiling.childId || agent.session.header?.parentSession !== ceiling.creatorId
86
+ || owner.id !== ceiling.rootId || (invocation?.target ?? null) !== ceiling.role)
87
+ throw new SubagentError("Cold child identity mismatch", "UNAUTHORIZED");
88
+ const maxDepth = this.maximumDepth(owner, maximum, ceiling.maxDepth ?? undefined);
89
+ if (maxDepth !== undefined && delegationDepthOf(agent) > maxDepth)
90
+ throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
91
+ const upstream = this.identity(owner);
92
+ liveIdentities.set(agent, Object.freeze({ role: ceiling.role ?? undefined, child: true, owner, creatorId: ceiling.creatorId,
93
+ preset: this.selected(agent), epoch: admission.epoch, independentComposition, maxDepth,
94
+ readOnly: ceiling.readOnly || this.readOnly(upstream) || DSMM_ROLES.find(row => row.id === ceiling.role)?.access === "read-only",
95
+ targetCeiling: Object.freeze(ceiling.targets.filter(target => upstream.targetCeiling === undefined || upstream.targetCeiling.includes(target))),
96
+ toolFilter: inheritToolFilter(inheritToolFilter(upstream.toolFilter, this.visibleToolCeiling(owner)), { ...(ceiling.allow === null ? {} : { allow: ceiling.allow }), deny: ceiling.deny }) }));
97
+ if (invocation !== undefined) {
98
+ bindRoleInvocation(agent, invocation);
99
+ captureRoleRuntimePolicy(admission.settings, invocation.target, invocation.policy);
100
+ }
101
+ }
102
+ maximumDepth(agent, ...limits) {
103
+ const values = [this.identity(agent).maxDepth, ...limits].filter((value) => value !== undefined);
104
+ return values.length === 0 ? undefined : Math.min(...values);
105
+ }
106
+ delegationCeiling(agent) {
107
+ const identity = this.identity(agent);
108
+ return { readOnly: this.readOnly(identity), allow: identity.toolFilter?.allow ?? null, deny: identity.toolFilter?.deny ?? [],
109
+ targets: this.targets(agent), maxDepth: identity.maxDepth ?? null };
110
+ }
79
111
  /** Ordinary native inheritance captures ceilings without inventing a role invocation. */
80
- bindInheritedChild(agent, parent, admission, continuation = false) {
112
+ bindInheritedChild(agent, parent, admission, continuation = false, maximum) {
81
113
  this.assertLive(agent);
82
114
  this.assertModuleAdmission(parent);
83
115
  const upstream = this.identity(parent), preset = this.selected(agent);
84
- if (!continuation && (upstream.role !== undefined || preset?.startsWith("dsmm-")) || !this.agents().isOwnedBy(agent.id, parent)
116
+ if (!continuation && (upstream.role !== undefined || preset?.startsWith("dsmm-")) || !nativeIsOwnedBy(this.agents(), agent.id, parent)
85
117
  || agent.session.header?.origin !== "subagent" || agent.session.header.parentSession !== parent.id)
86
118
  throw new SubagentError("Ordinary inheritance requires its exact non-controlled parent", "UNAUTHORIZED");
87
- liveIdentities.set(agent, Object.freeze({ child: true, parent, preset, epoch: admission.epoch,
119
+ const maxDepth = this.maximumDepth(parent, maximum);
120
+ if (maxDepth !== undefined && delegationDepthOf(agent) > maxDepth)
121
+ throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
122
+ liveIdentities.set(agent, Object.freeze({ child: true, parent, owner: nativeTreeRoot(this.agents(), agent) ?? parent,
123
+ creatorId: parent.id, maxDepth, preset, epoch: admission.epoch, targetCeiling: upstream.targetCeiling,
88
124
  readOnly: this.readOnly(upstream), toolFilter: inheritToolFilter(upstream.toolFilter, this.visibleToolCeiling(parent)) }));
89
125
  }
90
126
  release(agent) { liveIdentities.delete(agent); toolIdentities.delete(agent); }
@@ -92,10 +128,13 @@ export class DsmmRolePolicy {
92
128
  this.assertLive(agent);
93
129
  const settings = this.getSettings(agent), identity = liveIdentities.get(agent), selected = this.selected(agent);
94
130
  if (identity?.child) {
95
- this.assertLive(identity.parent);
96
- if (!this.agents().isOwnedBy(agent.id, identity.parent) || selected !== identity.preset
97
- || identity.role !== undefined && !identity.independentComposition && selected !== this.selected(identity.parent))
131
+ const owner = identity.owner ?? identity.parent;
132
+ this.assertLive(owner);
133
+ const tree = nativeTreeRoot(this.agents(), agent);
134
+ if ((tree === undefined ? !nativeIsOwnedBy(this.agents(), agent.id, owner) : tree !== owner)
135
+ || agent.session.header?.parentSession !== identity.creatorId || selected !== identity.preset) {
98
136
  throw new SubagentError("Child admission no longer matches composition", "UNAUTHORIZED");
137
+ }
99
138
  }
100
139
  else if (agent.session.header?.origin !== "subagent")
101
140
  this.validateRootRole(agent, this.getSettings.admission(agent));
@@ -109,10 +148,10 @@ export class DsmmRolePolicy {
109
148
  if (existing)
110
149
  return existing;
111
150
  const settings = this.getSettings(agent), selected = this.selected(agent);
112
- const parent = this.agents().list().find(row => row !== agent && this.agents().isOwnedBy(agent.id, row));
151
+ const parent = this.agents().list().find(row => row !== agent && nativeIsOwnedBy(this.agents(), agent.id, row));
113
152
  if (!parent)
114
153
  this.validateRootRole(agent, this.getSettings.admission(agent));
115
- const role = parent ? undefined : isDsmmRoleId(selected) ? selected : settings.modules.deepwork.enabled && this.mode.active(agent, settings.defaultActive) ? "dsmm-orchestrator" : undefined;
154
+ const role = parent ? undefined : isDsmmRoleId(selected) && settings.modules.deepwork.enabled && settings.roles[selected] ? selected : undefined;
116
155
  return Object.freeze({ role, child: parent !== undefined, parent, epoch: this.getSettings.admission(agent).epoch });
117
156
  }
118
157
  admit(agent) { return this.identity(agent); }
@@ -121,7 +160,8 @@ export class DsmmRolePolicy {
121
160
  const identity = this.identity(agent), settings = this.getSettings(agent);
122
161
  if (!settings.modules.deepwork.enabled || !identity.role || !settings.roles[identity.role])
123
162
  return [];
124
- return allowedRoleChildren(identity.role, identity.child).filter(role => settings.roles[role] && (!this.readOnly(identity) || DSMM_ROLES.find(row => row.id === role).access === "read-only")
163
+ return allowedRoleChildren(identity.role, identity.child).filter(role => settings.roles[role]
164
+ && (identity.targetCeiling === undefined || identity.targetCeiling.includes(role)) && (!this.readOnly(identity) || DSMM_ROLES.find(row => row.id === role).access === "read-only")
125
165
  && (identity.toolFilter?.allow === undefined || [roleToolName(role), DSMM_ROLES.find(row => row.id === role)?.kind === "category" ? "dsmm_category" : "dsmm_role"].some(name => identity.toolFilter.allow.includes(name)))
126
166
  && !identity.toolFilter?.deny?.includes(roleToolName(role)));
127
167
  }
@@ -154,7 +194,7 @@ export class DsmmRolePolicy {
154
194
  const agents = agent.ctx.get("agents"), tools = agent.ctx.get("agentPresets")?.serviceFor(agent, "tools") ?? agent.ctx.get("tools"), definition = tools?.get(execution.name, agent);
155
195
  this.toolCalls.set(execution, { agent, context: agent.ctx, registry: Reflect.get(agents, symbols.original) ?? agents,
156
196
  realm: tools === undefined ? undefined : Reflect.get(tools, symbols.original) ?? tools, scopeParent: scopeParentOf(agent),
157
- parents: agents.list().filter(parent => parent !== agent && agents.isOwnedBy(agent.id, parent)), parentSession: agent.session.header.parentSession,
197
+ owner: this.identity(agent).owner, parentSession: agent.session.header.parentSession,
158
198
  name: execution.name, args: execution.arguments, callId: execution.callId, signal: execution.signal,
159
199
  toolFilter: this.visibleToolCeiling(agent),
160
200
  ...(definition === undefined || !controlledDefinitions.has(definition) ? {} : { definition, body: definition.execute, argumentsJson: JSON.stringify(execution.arguments) }) });
@@ -184,10 +224,10 @@ export class DsmmRolePolicy {
184
224
  return;
185
225
  call.signal.throwIfAborted();
186
226
  const agents = agent.ctx.get("agents"), tools = agent.ctx.get("agentPresets")?.serviceFor(agent, "tools") ?? agent.ctx.get("tools");
187
- const parents = agents.list().filter(parent => parent !== agent && agents.isOwnedBy(agent.id, parent));
227
+ const owner = this.identity(agent).owner;
188
228
  if (agent !== call.agent || agent.ctx !== call.context || (Reflect.get(agents, symbols.original) ?? agents) !== call.registry
189
229
  || (tools === undefined ? undefined : Reflect.get(tools, symbols.original) ?? tools) !== call.realm || scopeParentOf(agent) !== call.scopeParent
190
- || agent.session.header.parentSession !== call.parentSession || parents.length !== call.parents.length || parents.some(parent => !call.parents.includes(parent)))
230
+ || agent.session.header.parentSession !== call.parentSession || owner !== call.owner)
191
231
  throw new SubagentError("Tool caller ownership changed", "UNAUTHORIZED");
192
232
  if (call.definition && (execution.name !== call.name || execution.arguments !== call.args || execution.callId !== call.callId || JSON.stringify(execution.arguments) !== call.argumentsJson
193
233
  || call.definition.execute !== call.body || tools?.get(call.name, agent) !== call.definition))
@@ -209,11 +249,12 @@ export class DsmmRolePolicy {
209
249
  const nativeOutput = name === "structured_output" && definition !== undefined && toolIdentities.get(agent)?.definitions.get(name) === definition;
210
250
  if (identity.toolFilter?.allow !== undefined && !identity.toolFilter.allow.includes(name) && !nativeOutput || identity.toolFilter?.deny?.includes(name))
211
251
  return "Tool exceeds inherited filter";
212
- if (identity.toolFilter && identity.parent && name !== "structured_output") {
213
- const parent = identity.parent, parentTools = parent.ctx.get("agentPresets")?.serviceFor(parent, "tools") ?? parent.ctx.get("tools");
252
+ const lifetimeOwner = identity.owner ?? identity.parent;
253
+ if (identity.toolFilter && lifetimeOwner && name !== "structured_output") {
254
+ const parent = lifetimeOwner, parentTools = parent.ctx.get("agentPresets")?.serviceFor(parent, "tools") ?? parent.ctx.get("tools");
214
255
  if (!parentTools?.get(name, parent))
215
- return "Parent no longer exposes this capability";
216
- const denied = this.preToolDenial(identity.parent, name, undefined, execution);
256
+ return "Admission owner no longer exposes this capability";
257
+ const denied = this.preToolDenial(lifetimeOwner, name, undefined, execution);
217
258
  if (denied)
218
259
  return denied;
219
260
  }
@@ -12,8 +12,10 @@ import { childOwnedSessionEvents } from "./session-scope.js";
12
12
  import { agentForScope, nativeAgentContext, scopeParentOf } from "./native-scope.js";
13
13
  import { roleRouteRuntimeState } from "./role-routing.js";
14
14
  import { modelRouteFromCall } from "./role-llm.js";
15
- import { buildDsmmDelegationGuidance } from "./prompts.js";
16
- const hostControls = ["send_message", "interrupt_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"];
15
+ import { buildDsmmDelegationGuidance, buildDsmmTeamGuidance } from "./prompts.js";
16
+ import { startNativeActivation } from "./native-subagents.js";
17
+ // Conditional Team tools stay in their native layer: copying a definition would discard its `when` registration.
18
+ const hostControls = ["send_message", "interrupt_agent", "list_agents", "wait_agent", "exit_plan_mode", "ask_user_question", "todo_write", "job_output", "job_list", "job_kill"];
17
19
  // Agent-owned policy realms survive a bundle reinstall; do not register another
18
20
  // delegation/tools layer on the same retained live Agent.
19
21
  const admittedRealms = new WeakMap();
@@ -191,7 +193,7 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ad
191
193
  const capturedProvider = provider;
192
194
  const parentComposition = parent.ctx.get?.("agentPresets")?.composedPreset(parent.ctx);
193
195
  const request = { parent, ...(parentComposition === undefined ? {} : { agentPreset: parentComposition }), prompt: [{ type: "text", text: args.prompt }],
194
- agentOptions: invocationAgentOptions(invocation), maxDepth: subagents.resolveMaxDepth(current.subagents.maxDepth) };
196
+ agentOptions: invocationAgentOptions(invocation), maxDepth: policy.maximumDepth(parent, subagents.resolveMaxDepth(current.subagents.maxDepth)) };
195
197
  const assertCurrent = () => {
196
198
  if (policy.assertDelegation(parent, role.id).epoch !== admitted.epoch)
197
199
  throw new SubagentError("DSMM parent admission changed before delegation", "UNAUTHORIZED");
@@ -209,7 +211,7 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ad
209
211
  void cancellation.catch(() => { });
210
212
  } };
211
213
  try {
212
- activation = await subagents.startActivation({ childId: pending.childId, provider: provider.name, label, request, signal: pending.signal, delivery: requestedBackground ? "parent" : "caller" });
214
+ activation = await startNativeActivation(subagents, { childId: pending.childId, provider: provider.name, label, request, signal: pending.signal, delivery: requestedBackground ? "parent" : "caller" });
213
215
  admission.track(activation);
214
216
  pending.signal.addEventListener("abort", cancel, { once: true });
215
217
  if (pending.signal.aborted) {
@@ -217,6 +219,18 @@ function registerRoleTool(agent, agentCtx, tools, entry, getSettings, policy, ad
217
219
  await cancellation;
218
220
  pending.signal.throwIfAborted();
219
221
  }
222
+ try {
223
+ const child = agentCtx.agents.get(activation.childId);
224
+ if (child === undefined)
225
+ throw new SubagentError("Native role activation has no live child", "UNAUTHORIZED");
226
+ await admission.ensure(child);
227
+ }
228
+ catch (error) {
229
+ cancel();
230
+ await cancellation;
231
+ throw error;
232
+ }
233
+ pending.signal.throwIfAborted();
220
234
  if (requestedBackground)
221
235
  return { kind: "continuable", subagentId: activation.childId, messageId: activation.messageId ?? null, invocation: { ...pending.view() } };
222
236
  const result = await activation.result;
@@ -268,14 +282,20 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
268
282
  if (context.scope !== agent && agentForScope(ctx, context.scope) !== agent)
269
283
  return "";
270
284
  const identity = policy.identity(agent), tools = states.get(agent)?.tools, settings = getSettings(agent);
285
+ const teams = agentCtx.get?.("agentTeams");
286
+ const toolSet = context.toolSet;
287
+ const teamGuidance = teams?.isEnabled(agent) && toolSet !== undefined
288
+ ? buildDsmmTeamGuidance([...toolSet.view(agent).keys()]) : "";
271
289
  if (identity.role === undefined)
272
- return "";
290
+ return teamGuidance;
273
291
  const captured = capturedRoleInvocation(agent);
274
- return buildDsmmDelegationGuidance(settings, { scope: identity.child ? "child" : "root", tools: tools?.schemas(agent) ?? [],
292
+ const delegationGuidance = buildDsmmDelegationGuidance(settings, { scope: identity.child ? "child" : "root", tools: tools?.schemas(agent) ?? [],
275
293
  delegation: tools === undefined ? [] : admittedCallableRoleInventory(agent, settings, policy, tools),
276
294
  ...(captured === undefined ? {} : { invocation: roleInvocationObservation(captured, DSMM_ROLES.find(role => role.id === captured.target).name, "continuable", getSettings, agent, { childId: agent.id }) }),
277
295
  runtimeAdmission: getSettings.subagentRuntime?.(), capabilities: { continuable: true, nativeChildDelivery: true,
296
+ nativeTree: typeof agentCtx.get("subagents")?.rootOf === "function",
278
297
  ...(agentCtx.get("dsmmChildren") === undefined ? {} : { nativeBrowserPrompt: { surface: "conversation.dsmm-children" } }) } });
298
+ return [delegationGuidance, teamGuidance].filter(Boolean).join("\n\n");
279
299
  } });
280
300
  state.promptRealm = promptRealm;
281
301
  }
@@ -1,6 +1,27 @@
1
1
  import type { DshSession, DshSessionEvent } from "./dsh-types.js";
2
2
  import type { DsmmRolePolicyEventData } from "./dsh-events.js";
3
- import type { DsmmModelRoute } from "./settings.js";
3
+ import type { DsmmInvocationLevel, DsmmModelRoute } from "./settings.js";
4
+ import type { DsmmRoleId } from "./roles.js";
5
+ interface DelegationCeilingRestrictions {
6
+ readonly version: 1;
7
+ readonly childId: string;
8
+ readonly creatorId: string;
9
+ readonly rootId: string;
10
+ readonly provider: string;
11
+ readonly profileId: string | null;
12
+ readonly readOnly: boolean;
13
+ readonly allow: readonly string[] | null;
14
+ readonly deny: readonly string[];
15
+ readonly targets: readonly DsmmRoleId[];
16
+ readonly maxDepth: number | null;
17
+ }
18
+ export type DsmmDelegationCeiling = DelegationCeilingRestrictions & ({
19
+ readonly role: DsmmRoleId;
20
+ readonly level: DsmmInvocationLevel;
21
+ } | {
22
+ readonly role: null;
23
+ readonly level: null;
24
+ });
4
25
  export interface DsmmModelSelectionRecordData {
5
26
  readonly version: 1;
6
27
  readonly source: "dsmm-selection" | "activation-setup";
@@ -14,6 +35,7 @@ declare module "@deepseek-ai/dsh-session/types" {
14
35
  };
15
36
  "plugin:dsmm/role-policy": DsmmRolePolicyEventData;
16
37
  "plugin:dsmm/model-selection": DsmmModelSelectionRecordData;
38
+ "plugin:dsmm/delegation-ceiling": DsmmDelegationCeiling;
17
39
  }
18
40
  }
19
41
  /** Model-hidden observations use the official ignorable record boundary, never authorization. */
@@ -23,4 +45,8 @@ export declare function appendModelSelectionRecord(session: DshSession, data: Ds
23
45
  export declare function readModelSelectionRecord(event: DshSessionEvent): (DsmmModelSelectionRecordData & {
24
46
  recordSeq: number;
25
47
  }) | undefined;
48
+ export declare function appendDelegationCeiling(session: DshSession, data: DsmmDelegationCeiling): void;
49
+ /** Only the child's own suffix can restrict a cold admission; fork seeds carry no identity. */
50
+ export declare function readDelegationCeiling(session: DshSession): DsmmDelegationCeiling | undefined;
51
+ export {};
26
52
  //# sourceMappingURL=session-metadata.d.ts.map
@@ -1,4 +1,9 @@
1
1
  import { appendPluginRecord, pluginRecordOf } from "@deepseek-ai/dsh-session";
2
+ import { SubagentError } from "@deepseek-ai/dsh-subagent";
3
+ import { isDeepStrictEqual } from "node:util";
4
+ import { isDsmmRoleId } from "./roles.js";
5
+ import { childOwnedSessionEvents } from "./session-scope.js";
6
+ import { validateProfileId } from "./profiles.js";
2
7
  /** Model-hidden observations use the official ignorable record boundary, never authorization. */
3
8
  export function appendModeRecord(session, active) {
4
9
  appendPluginRecord(session, "plugin:dsmm/mode", { active });
@@ -23,6 +28,47 @@ export function readModelSelectionRecord(event) {
23
28
  return { version, source, selectionSeq, route: { provider: route.provider, model: route.model,
24
29
  ...(route.reasoningEffort === undefined ? {} : { reasoningEffort: route.reasoningEffort }) }, recordSeq: Number(record.seq) };
25
30
  }
31
+ export function appendDelegationCeiling(session, data) {
32
+ appendPluginRecord(session, "plugin:dsmm/delegation-ceiling", data);
33
+ }
34
+ /** Only the child's own suffix can restrict a cold admission; fork seeds carry no identity. */
35
+ export function readDelegationCeiling(session) {
36
+ let ceiling;
37
+ for (const event of childOwnedSessionEvents(session)) {
38
+ const record = pluginRecordOf(event);
39
+ if (record?.type !== "plugin:dsmm/delegation-ceiling")
40
+ continue;
41
+ const data = record.data;
42
+ const invalid = () => { throw new SubagentError("Invalid or conflicting delegation ceiling", "UNAUTHORIZED"); };
43
+ if (!isRecord(data))
44
+ invalid();
45
+ const row = data;
46
+ const fields = ["version", "childId", "creatorId", "rootId", "provider", "role", "level", "profileId", "readOnly", "allow", "deny", "targets", "maxDepth"];
47
+ const text = (value) => typeof value === "string" && value.length > 0;
48
+ const names = (value) => Array.isArray(value) && value.every(text) && new Set(value).size === value.length;
49
+ if (Object.keys(row).length !== fields.length || fields.some(key => !Object.hasOwn(row, key))
50
+ || row.version !== 1 || !text(row.childId) || !text(row.creatorId) || !text(row.rootId) || !text(row.provider)
51
+ || row.childId === row.creatorId || row.childId === row.rootId
52
+ || (row.role === null ? row.level !== null : !isDsmmRoleId(row.role) || !["normal", "low", "high", "max"].includes(String(row.level)))
53
+ || typeof row.readOnly !== "boolean"
54
+ || row.allow !== null && !names(row.allow) || !names(row.deny) || !names(row.targets) || !row.targets.every(isDsmmRoleId)
55
+ || row.maxDepth !== null && (typeof row.maxDepth !== "number" || !Number.isSafeInteger(row.maxDepth) || row.maxDepth < 0))
56
+ invalid();
57
+ if (row.profileId !== null) {
58
+ try {
59
+ validateProfileId(row.profileId);
60
+ }
61
+ catch {
62
+ invalid();
63
+ }
64
+ }
65
+ const current = row;
66
+ if (ceiling !== undefined && !isDeepStrictEqual(ceiling, current))
67
+ invalid();
68
+ ceiling = current;
69
+ }
70
+ return ceiling;
71
+ }
26
72
  function isRecord(value) {
27
73
  return typeof value === "object" && value !== null && !Array.isArray(value);
28
74
  }
@@ -5,5 +5,5 @@ export declare function sessionEvents(session: DshSession | undefined): readonly
5
5
  export declare function resolveSelectedAgentPreset(session: DshSession | undefined): string | undefined;
6
6
  export declare function childOwnedSessionEvents(session: DshSession): readonly DshSessionEvent[];
7
7
  /** Parent preset/persona inheritance is deliberately not delegated role authority. */
8
- export declare function resolveEffectiveDsmmRole(agent: DshAgent, settings: DsmmSettings, modeActive: boolean): DsmmRoleId | undefined;
8
+ export declare function resolveEffectiveDsmmRole(agent: DshAgent, settings: DsmmSettings, _modeActive: boolean): DsmmRoleId | undefined;
9
9
  //# sourceMappingURL=session-scope.d.ts.map
@@ -26,7 +26,7 @@ export function childOwnedSessionEvents(session) {
26
26
  return sessionEvents(session).slice(inherited);
27
27
  }
28
28
  /** Parent preset/persona inheritance is deliberately not delegated role authority. */
29
- export function resolveEffectiveDsmmRole(agent, settings, modeActive) {
29
+ export function resolveEffectiveDsmmRole(agent, settings, _modeActive) {
30
30
  if (!settings.modules.deepwork.enabled)
31
31
  return undefined;
32
32
  let role;
@@ -39,7 +39,7 @@ export function resolveEffectiveDsmmRole(agent, settings, modeActive) {
39
39
  }
40
40
  else {
41
41
  const preset = resolveSelectedAgentPreset(agent.session);
42
- role = isDsmmRoleId(preset) ? preset : modeActive ? "dsmm-orchestrator" : undefined;
42
+ role = isDsmmRoleId(preset) ? preset : undefined;
43
43
  }
44
44
  return role !== undefined && settings.roles[role] ? role : undefined;
45
45
  }