@dsmm/dsmm 0.3.3 → 0.3.5

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 (99) hide show
  1. package/agent-presets/dsmm-builder/agent.cordis.yml +1 -1
  2. package/agent-presets/dsmm-clarifier/agent.cordis.yml +1 -1
  3. package/agent-presets/dsmm-code-search/agent.cordis.yml +1 -1
  4. package/agent-presets/dsmm-coding/agent.cordis.yml +3 -2
  5. package/agent-presets/dsmm-complex/agent.cordis.yml +2 -1
  6. package/agent-presets/dsmm-creative/agent.cordis.yml +1 -1
  7. package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +1 -1
  8. package/agent-presets/dsmm-deep/agent.cordis.yml +2 -1
  9. package/agent-presets/dsmm-doc-search/agent.cordis.yml +1 -1
  10. package/agent-presets/dsmm-documenting/agent.cordis.yml +1 -1
  11. package/agent-presets/dsmm-frontend/agent.cordis.yml +4 -2
  12. package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +1 -1
  13. package/agent-presets/dsmm-media-reader/agent.cordis.yml +1 -1
  14. package/agent-presets/dsmm-normal-task/agent.cordis.yml +3 -2
  15. package/agent-presets/dsmm-oracle/agent.cordis.yml +1 -1
  16. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +1 -1
  17. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +11 -1
  18. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +1 -1
  19. package/agent-presets/dsmm-planner/agent.cordis.yml +1 -1
  20. package/agent-presets/dsmm-quick/agent.cordis.yml +2 -1
  21. package/agent-presets/dsmm-research/agent.cordis.yml +1 -1
  22. package/agent-presets/dsmm-reviewer/agent.cordis.yml +1 -1
  23. package/docs/native-permissions.md +11 -3
  24. package/docs/roadmap.md +30 -3
  25. package/docs/runtime-recovery.md +30 -2
  26. package/docs/settings-status.md +6 -4
  27. package/docs/skill-sync.md +13 -14
  28. package/lib/client/DeploymentFields.js +30 -2
  29. package/lib/client/DeploymentPage.js +29 -17
  30. package/lib/client/NativeCommandEntries.js +47 -37
  31. package/lib/client/PermissionRuleEntries.d.ts +17 -0
  32. package/lib/client/PermissionRuleEntries.js +70 -0
  33. package/lib/client/PermissionsPanel.js +8 -5
  34. package/lib/client/deployment-locales.d.ts +2 -2
  35. package/lib/client/deployment-locales.js +8 -8
  36. package/lib/client/deployment-modules.d.ts +5 -3
  37. package/lib/client/deployment-modules.js +4 -4
  38. package/lib/client/deployment-workspace.d.ts +4 -0
  39. package/lib/client/deployment-workspace.js +37 -11
  40. package/lib/client/index.js +2 -18
  41. package/lib/client/permission-controller.d.ts +23 -0
  42. package/lib/client/permission-controller.js +59 -27
  43. package/lib/client/permission-locales.d.ts +30 -4
  44. package/lib/client/permission-locales.js +42 -18
  45. package/lib/client/permission-session.d.ts +37 -0
  46. package/lib/client/permission-session.js +34 -0
  47. package/lib/client/styles.d.ts +1 -1
  48. package/lib/client/styles.js +12 -8
  49. package/lib/client.js +1491 -1153
  50. package/lib/core-permission-authority.js +28 -16
  51. package/lib/index.js +2 -9
  52. package/lib/native-admission.d.ts +3 -0
  53. package/lib/native-admission.js +60 -26
  54. package/lib/permission-controller.js +1 -1
  55. package/lib/permission-native-command.js +6 -4
  56. package/lib/permission-settings.d.ts +21 -7
  57. package/lib/permission-settings.js +21 -9
  58. package/lib/role-identity.d.ts +1 -1
  59. package/lib/role-identity.js +16 -4
  60. package/lib/role-policy.d.ts +3 -0
  61. package/lib/role-policy.js +29 -5
  62. package/lib/role-subagents.js +4 -3
  63. package/lib/runtime-integration.js +4 -4
  64. package/lib/settings.js +4 -1
  65. package/lib/state.d.ts +4 -1
  66. package/lib/state.js +37 -6
  67. package/package.json +1 -1
  68. package/prompts/deepwork.md +13 -1
  69. package/prompts/source/agents/orchestrator.md +10 -0
  70. package/prompts/source/category/coding.md +2 -1
  71. package/prompts/source/category/complex.md +1 -0
  72. package/prompts/source/category/deep.md +1 -0
  73. package/prompts/source/category/frontend.md +3 -1
  74. package/prompts/source/category/normal-task.md +2 -1
  75. package/prompts/source/category/quick.md +1 -0
  76. package/prompts/source/deepwork/claude-opus-5.md +2 -0
  77. package/prompts/source/deepwork/default.md +12 -0
  78. package/prompts/source/deepwork/gemini.md +6 -1
  79. package/prompts/source/deepwork/glm.md +5 -1
  80. package/prompts/source/deepwork/gpt.md +22 -2
  81. package/prompts/source/deepwork/kimi-k27.md +2 -0
  82. package/prompts/source/deepwork/planner.md +3 -1
  83. package/prompts/source/deepwork/swe-2.md +2 -0
  84. package/prompts/source/manifest.json +3 -68
  85. package/prompts/source/shared/dsh-host-contract.md +1 -1
  86. package/skills/ast-grep/SKILL.md +1 -1
  87. package/skills/brainstorming/SKILL.md +1 -1
  88. package/skills/coding-agent-sessions/SKILL.md +1 -1
  89. package/skills/debugging/SKILL.md +1 -1
  90. package/skills/dispatching-parallel-agents/SKILL.md +1 -1
  91. package/skills/frontend/SKILL.md +1 -1
  92. package/skills/git-master/SKILL.md +1 -1
  93. package/skills/init-deep/SKILL.md +1 -1
  94. package/skills/receiving-code-review/SKILL.md +1 -1
  95. package/skills/remove-ai-slops/SKILL.md +1 -1
  96. package/skills/requesting-code-review/SKILL.md +1 -1
  97. package/skills/subagent-driven-development/SKILL.md +1 -1
  98. package/skills/using-git-worktrees/SKILL.md +1 -1
  99. package/skills/writing-plans/SKILL.md +1 -1
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import { scopeLifetime } from "./lifetime.js";
3
3
  import { PermissionRefusal, permissionOriginal } from "./permission-control.js";
4
4
  import { DSMM_ROLES } from "./roles.js";
5
- import { classifyDsmmAgent } from "./runtime-integration.js";
5
+ import { capturedRoleInvocation } from "./role-invocation.js";
6
6
  function sameFacts(a, b) {
7
7
  return a.length === b.length && a.every((value, index) => value === b[index]);
8
8
  }
@@ -48,13 +48,16 @@ export function createCorePermissionAuthority(ctx, options) {
48
48
  current = owners[0];
49
49
  }
50
50
  };
51
- const coreAdmission = (agent) => {
51
+ const coreDomain = (agent) => {
52
52
  const core = ctx.get("dsmmCoreLlmOwner"), profiles = ctx.get("dsmmProfileRuntime");
53
53
  const ownerCore = coreOwner.get("dsmmCoreLlmOwner"), realmCore = agent.ctx.get("dsmmCoreLlmOwner");
54
54
  if (core === undefined || ownerCore === undefined || realmCore === undefined || profiles === undefined
55
55
  || permissionOriginal(core) !== permissionOriginal(ownerCore) || permissionOriginal(core) !== permissionOriginal(realmCore))
56
56
  throw new PermissionRefusal("unavailable");
57
- const structural = agent, admission = getSettings.admission?.(structural);
57
+ return profiles;
58
+ };
59
+ const coreAdmission = (agent) => {
60
+ const profiles = coreDomain(agent), structural = agent, admission = getSettings.admission?.(structural);
58
61
  if (admission === undefined || profiles.admission(structural) !== admission || getSettings(structural) !== admission.settings)
59
62
  throw new PermissionRefusal("stale");
60
63
  return admission;
@@ -63,21 +66,29 @@ export function createCorePermissionAuthority(ctx, options) {
63
66
  const previous = generations.get(agent);
64
67
  try {
65
68
  const structural = agent;
66
- const nativeChild = parent !== undefined && !parent.controlled && classifyDsmmAgent(agent) === "native";
67
- if (!nativeChild)
69
+ const profiles = coreDomain(agent);
70
+ const captured = host?.owns(agent) === true || capturedRoleInvocation(structural) !== undefined;
71
+ const native = !captured && !profiles.hasAdmission(structural);
72
+ if (native && parent?.controlled)
73
+ throw new PermissionRefusal("not-owned");
74
+ if (captured) {
75
+ if (host === undefined)
76
+ throw new PermissionRefusal("unavailable");
77
+ host.assert(agent);
78
+ }
79
+ if (!native)
68
80
  rolePolicy.assertModuleAdmission(structural);
69
- // Ordinary native children borrow the actual parent's Core policy domain,
70
- // while retaining their own native realm, restrictions and lifetime.
71
- const admission = nativeChild ? parent.admission : coreAdmission(agent);
72
- const identity = nativeChild ? undefined : rolePolicy.identity(structural);
81
+ // Unadmitted native calls retain physical authority, never DSMM role rights.
82
+ const admission = native ? parent?.admission : coreAdmission(agent);
83
+ const identity = native ? undefined : rolePolicy.identity(structural);
73
84
  const tools = agent.ctx.get("tools"), approval = agent.ctx.get("approval");
74
- if (tools === undefined || !nativeChild && (identity?.epoch !== admission.epoch
85
+ if (tools === undefined || !native && (identity?.epoch !== admission.epoch
75
86
  || (parent === undefined ? agent !== root || identity.child : identity.parent !== parent.authority.agent || !identity.child)))
76
87
  throw new PermissionRefusal("not-owned");
77
88
  const nativePolicy = approval === undefined ? undefined : approval.overrideOf(agent.session) ?? approval.config.policy;
78
89
  if (approval !== undefined && nativePolicy !== "ask" && nativePolicy !== "never")
79
90
  throw new PermissionRefusal("unavailable");
80
- const managed = parent !== undefined && !nativeChild;
91
+ const managed = parent !== undefined && identity?.role !== undefined;
81
92
  if (managed && host === undefined)
82
93
  throw new PermissionRefusal("unavailable");
83
94
  const entry = managed ? permissionOriginal(host) : undefined;
@@ -85,7 +96,7 @@ export function createCorePermissionAuthority(ctx, options) {
85
96
  const facts = [root, agent.ctx, parent?.authority.signal, permissionOriginal(ctx.get("dsmmCoreLlmOwner")),
86
97
  permissionOriginal(ctx.get("dsmmProfileRuntime")), permissionOriginal(tools),
87
98
  approval === undefined ? undefined : permissionOriginal(approval),
88
- admission.settings, nativeChild, identity?.role, identity?.child, identity?.parent, identity?.epoch, identity?.readOnly,
99
+ admission?.settings, native, captured, identity?.role, identity?.child, identity?.parent, identity?.epoch, identity?.readOnly,
89
100
  JSON.stringify(identity?.toolFilter)];
90
101
  if (previous !== undefined && !previous.authority.signal.aborted && previous.integration === entry
91
102
  && previous.authority.owner === owner && previous.admission === admission && sameFacts(previous.facts, facts)) {
@@ -96,13 +107,14 @@ export function createCorePermissionAuthority(ctx, options) {
96
107
  previous?.revoke();
97
108
  if (managed && host.assert(agent) !== admission)
98
109
  throw new PermissionRefusal("not-owned");
110
+ const revision = admission?.epoch ?? randomUUID();
99
111
  const controller = new AbortController();
100
112
  const signal = AbortSignal.any([controller.signal, lifetimeSignal, ...parent === undefined ? [] : [parent.authority.signal]]);
101
113
  const detach = [];
102
114
  let revoked = false;
103
- const generation = { nativeChild, controlled: managed || identity?.role !== undefined, integration: entry, admission, facts,
104
- authority: Object.freeze({ agent, root, realm: agent.ctx, owner, ownerGeneration: admission.epoch,
105
- admissionRevision: admission.epoch, permissionRevision: randomUUID(), signal }),
115
+ const generation = { native, controlled: managed || identity?.role !== undefined, integration: entry, admission, facts,
116
+ authority: Object.freeze({ agent, root, realm: agent.ctx, owner, ownerGeneration: revision,
117
+ admissionRevision: revision, permissionRevision: randomUUID(), signal }),
106
118
  revoke() {
107
119
  if (revoked)
108
120
  return;
@@ -186,7 +198,7 @@ export function createCorePermissionAuthority(ctx, options) {
186
198
  throw new PermissionRefusal("stale");
187
199
  const tools = live.agent.ctx.get("tools");
188
200
  if (tools?.get(exec.name, live.agent) === undefined
189
- || !generations.get(live.agent)?.nativeChild && rolePolicy.toolDenial(live.agent, exec.name, tools, exec) !== undefined)
201
+ || !generations.get(live.agent)?.native && rolePolicy.toolDenial(live.agent, exec.name, tools, exec) !== undefined)
190
202
  throw new PermissionRefusal("denied");
191
203
  },
192
204
  };
package/lib/index.js CHANGED
@@ -57,18 +57,9 @@ export async function apply(input, config = {}, startupOptions = {}) {
57
57
  const deployment = new DsmmDeploymentConfig(ctx, config);
58
58
  const lifetime = new AbortController();
59
59
  scopeLifetime(ctx, "dsmm: retire Core", () => lifetime.abort());
60
- // Install a startup execution fence before asynchronous configuration reads.
61
60
  let admission;
62
61
  const assert = (agent) => { lifetime.signal.throwIfAborted(); if (!admission)
63
62
  throw new Error("DSMM initialization is incomplete"); return admission.assert(agent); };
64
- ctx.on("agent/created", () => { lifetime.signal.throwIfAborted(); if (!admission?.isReady)
65
- throw new Error("DSMM initialization is incomplete"); }, { global: true, prepend: true });
66
- ctx.on("agent/pre-step", async (frame, next) => { await admission?.ensure(frame.agent); assert(frame.agent); return next(); }, { global: true, prepend: true });
67
- ctx.on("agent/request", async (frame, next) => { await admission?.ensure(frame.agent); assert(frame.agent); return next(); }, { global: true, prepend: true });
68
- ctx.on("tools/pre-execute", async (exec, next) => { if (exec.agent) {
69
- await admission?.ensure(exec.agent);
70
- assert(exec.agent);
71
- } return next(); }, { global: true, prepend: true });
72
63
  const startup = await deployment.readDesired();
73
64
  lifetime.signal.throwIfAborted();
74
65
  const getSettings = agent => agent === undefined ? startup.settings : admission.configuration(agent).settings;
@@ -91,6 +82,8 @@ export async function apply(input, config = {}, startupOptions = {}) {
91
82
  ctx.provide("dsmmProfileRuntime", profiles);
92
83
  ctx.provide("dsmmDeploymentConfig", deployment);
93
84
  ctx.provide("dsmmCoreLlmOwner", { async admit(frame) {
85
+ if (!admission.owns(frame.agent))
86
+ return undefined;
94
87
  const captured = assert(frame.agent), full = nativeStandingFullAccess(ctx, frame.agent);
95
88
  const permissions = ctx.get("dsmmPermissionController");
96
89
  if (!full && captured.settings.permissionControl.enabled && permissions === undefined)
@@ -41,6 +41,9 @@ export declare class NativeAdmission {
41
41
  constructor(ctx: Context, profiles: DsmmProfileRuntime, policy: DsmmRolePolicy);
42
42
  activate(install: NonNullable<NativeAdmission["install"]>): void;
43
43
  get isReady(): boolean;
44
+ /** Exact process-local capture, retained after retirement so stale objects never become native. */
45
+ owns(agent: Agent): boolean;
46
+ guardExecution(agent: Agent): Promise<"native" | "dsmm">;
44
47
  isSelecting(agent: Agent): boolean;
45
48
  get(agent: Agent): DsmmProfileAdmission | undefined;
46
49
  configuration(agent: Agent): DsmmProfileAdmission;
@@ -65,17 +65,21 @@ export class NativeAdmission {
65
65
  profiles.release(agent);
66
66
  policy.release(agent);
67
67
  }, { global: true });
68
- // Unbound retained Agents are not enrolled by listing. These guards also cover startup failures.
69
- ctx.on("agent/pre-step", async (frame, next) => { await this.ensure(frame.agent); return next(); }, { global: true, prepend: true });
70
- ctx.on("agent/request", async (frame, next) => { await this.ensure(frame.agent); return next(); }, { global: true, prepend: true });
71
- ctx.on("tools/execute", async (exec, next) => { if (exec.agent)
72
- await this.ensure(exec.agent); return policy.duringToolExecution(exec, next); }, { global: true, prepend: true });
68
+ // Only exact DSMM captures are guarded; native reconstruction is not an admission request.
69
+ ctx.on("agent/pre-step", async (frame, next) => { await this.guardExecution(frame.agent); return next(); }, { global: true, prepend: true });
70
+ ctx.on("agent/request", async (frame, next) => { await this.guardExecution(frame.agent); return next(); }, { global: true, prepend: true });
71
+ ctx.on("tools/execute", async (exec, next) => {
72
+ if (exec.agent && await this.guardExecution(exec.agent) === "native")
73
+ return next();
74
+ return policy.duringToolExecution(exec, next);
75
+ }, { global: true, prepend: true });
73
76
  ctx.on("tools/pre-execute", async (exec, next) => {
74
77
  if (exec.agent) {
78
+ if (await this.guardExecution(exec.agent) === "native")
79
+ return next();
75
80
  const active = this.executions.get(exec.agent) ?? new Set();
76
81
  active.add(exec.token);
77
82
  this.executions.set(exec.agent, active);
78
- await this.ensure(exec.agent);
79
83
  }
80
84
  return next();
81
85
  }, { global: true, prepend: true });
@@ -90,8 +94,23 @@ export class NativeAdmission {
90
94
  void binding.catch(() => { });
91
95
  }, { global: true });
92
96
  }
93
- activate(install) { this.lifetime.signal.throwIfAborted(); this.install = install; this.ready = true; }
94
- get isReady() { return this.ready && !this.lifetime.signal.aborted; }
97
+ activate(install) {
98
+ this.lifetime.signal.throwIfAborted();
99
+ this.install = install;
100
+ this.ready = true;
101
+ }
102
+ get isReady() {
103
+ const current = this.ctx.get("dsmmNativeAdmission");
104
+ return this.ready && !this.lifetime.signal.aborted && current !== undefined && original(current) === original(this);
105
+ }
106
+ /** Exact process-local capture, retained after retirement so stale objects never become native. */
107
+ owns(agent) { return this.agentLifetimes.has(agent); }
108
+ async guardExecution(agent) {
109
+ if (!this.owns(agent))
110
+ return "native";
111
+ await this.ensure(agent);
112
+ return "dsmm";
113
+ }
95
114
  isSelecting(agent) { return this.selecting.has(agent); }
96
115
  get(agent) { return this.live.get(agent)?.admission; }
97
116
  configuration(agent) {
@@ -127,14 +146,14 @@ export class NativeAdmission {
127
146
  throw new SubagentError("Session configuration restoration failed; create a new session", "UNAUTHORIZED");
128
147
  if (this.selecting.has(agent))
129
148
  throw new SubagentError("Session configuration maintenance is in progress", "UNAUTHORIZED");
130
- if (!this.ready || !live || this.ctx.agents.get(agent.id) !== agent)
149
+ if (!this.isReady || !live || this.ctx.agents.get(agent.id) !== agent)
131
150
  throw new SubagentError("No trusted live admission; create a new session", "UNAUTHORIZED");
132
151
  if (live.preset !== agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) || live.scopeParent !== scopeParentOf(agent))
133
152
  throw new SubagentError("Preset composition changed; create a new session", "UNAUTHORIZED");
134
153
  if (live.parent && (this.ctx.agents.get(live.parent.id) !== live.parent || !this.ctx.agents.isOwnedBy(agent.id, live.parent)))
135
154
  throw new SubagentError("Parent residency changed", "UNAUTHORIZED");
136
155
  if (live.parent)
137
- this.agentLifetimes.get(live.parent)?.signal.throwIfAborted();
156
+ this.assert(live.parent);
138
157
  this.policy.assertModuleAdmission(agent);
139
158
  return live.admission;
140
159
  }
@@ -201,10 +220,6 @@ export class NativeAdmission {
201
220
  return [name, provider];
202
221
  }));
203
222
  for (const role of targets) {
204
- const preset = await agent.ctx.get("agentPresets").resolve(role);
205
- assertCurrent();
206
- if (preset.broken !== undefined)
207
- throw new DsmmProfileError("activation", "An enabled role preset is unavailable.", role);
208
223
  const routing = admission.settings.roleRouting[role];
209
224
  if (routing?.primary !== undefined || routing?.fallbackRoutes !== undefined) {
210
225
  await resolveRoleInvocation(agent, role, admission.settings, preparationSignal, {}, undefined, resolvedModelParameterPolicy(admission));
@@ -358,6 +373,8 @@ export class NativeAdmission {
358
373
  async rebindBlank(agent) {
359
374
  await this.blankUpdates.get(agent);
360
375
  this.lifetime.signal.throwIfAborted();
376
+ if (!this.isReady)
377
+ throw new SubagentError("DSMM owner is no longer current", "UNAUTHORIZED");
361
378
  const previous = this.live.get(agent);
362
379
  if (previous === undefined)
363
380
  throw new SubagentError("The blank Agent owner was retired", "UNAUTHORIZED");
@@ -374,23 +391,31 @@ export class NativeAdmission {
374
391
  await this.install(agent, this.getter(agent));
375
392
  this.lifetime.signal.throwIfAborted();
376
393
  this.agentLifetimes.get(agent).signal.throwIfAborted();
377
- if (this.ctx.agents.get(agent.id) !== agent || this.live.get(agent) !== previous || scopeParentOf(agent) !== scopeParent)
394
+ if (!this.isReady || this.ctx.agents.get(agent.id) !== agent || this.live.get(agent) !== previous || scopeParentOf(agent) !== scopeParent)
378
395
  throw new SubagentError("Composition changed during blank admission", "UNAUTHORIZED");
379
396
  this.live.set(agent, Object.freeze({ ...previous, preset, scopeParent }));
380
397
  }
381
398
  async created(agent, source, creationSignal) {
382
- if (this.live.has(agent)) {
399
+ if (this.owns(agent)) {
383
400
  this.assert(agent);
384
401
  return;
385
402
  }
386
- if (!this.ready || !this.install)
403
+ const pending = this.pending.get(agent.id);
404
+ // Native resume, promotion and durable provider recovery do not restore a DSMM role grant.
405
+ if (source === "resume" && pending === undefined)
406
+ return;
407
+ if (pending && source !== "startup")
408
+ throw new SubagentError("Role creation requires its first pending call", "UNAUTHORIZED");
409
+ if (!this.isReady || !this.install)
387
410
  throw new SubagentError("DSMM admission is initializing", "UNAUTHORIZED");
388
411
  const signal = AbortSignal.any([...creationSignal ? [creationSignal] : [], this.lifetime.signal]);
389
412
  signal.throwIfAborted();
390
413
  const parents = this.ctx.agents.list().filter(parent => parent !== agent && this.ctx.agents.isOwnedBy(agent.id, parent));
391
- const parent = parents[0], preset = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx), presetScope = scopeParentOf(agent), pending = this.pending.get(agent.id);
414
+ const parent = parents[0], preset = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx), presetScope = scopeParentOf(agent);
392
415
  if (parents.length > 1 || this.ctx.agents.get(agent.id) !== agent)
393
416
  throw new SubagentError("Invalid native ownership", "UNAUTHORIZED");
417
+ if (!pending && (parent && !this.owns(parent) || !parent && agent.session.header.origin === "subagent"))
418
+ return;
394
419
  let admission;
395
420
  if (parent) {
396
421
  const parentAdmission = this.assert(parent), controlled = this.policy.identity(parent).role !== undefined;
@@ -407,23 +432,30 @@ export class NativeAdmission {
407
432
  }
408
433
  else {
409
434
  if (controlled || preset?.startsWith("dsmm-"))
410
- throw new SubagentError("Use an admitted DSMM role tool; cold recovery is unavailable", "UNAUTHORIZED");
435
+ throw new SubagentError("Use an admitted DSMM role tool", "UNAUTHORIZED");
411
436
  admission = parentAdmission;
412
437
  }
413
438
  }
414
439
  else {
415
- if (agent.session.header.origin === "subagent" || pending)
440
+ if (pending)
416
441
  throw new SubagentError("Missing exact parent", "UNAUTHORIZED");
417
- // A resumed session receives a fresh admission from the current deployment:
418
- // its persisted history stays readable user intent, while no old
419
- // authorization survives — delegation authority and child residency can
420
- // never be reconstructed from a log.
421
442
  admission = await this.profiles.prepareRoot(agent, signal);
422
443
  this.policy.validateRootRole(agent, admission);
423
444
  }
424
445
  this.agentLifetimes.set(agent, new AbortController());
425
446
  scopeLifetime(agent.ctx, "dsmm: retire exact Agent work", () => { void this.retireAgent(agent).catch(() => { }); });
426
- agent.ctx.effect(() => () => this.retireAgent(agent));
447
+ agent.ctx.effect(() => async () => {
448
+ try {
449
+ await this.retireAgent(agent);
450
+ }
451
+ finally {
452
+ this.live.delete(agent);
453
+ this.candidates.delete(agent);
454
+ this.agents.delete(agent);
455
+ this.profiles.release(agent);
456
+ this.policy.release(agent);
457
+ }
458
+ });
427
459
  this.candidates.set(agent, admission);
428
460
  this.agents.add(agent);
429
461
  // These registrations belong to the Agent, not the plugin owner. Revocation remains effective after unload.
@@ -441,6 +473,8 @@ export class NativeAdmission {
441
473
  try {
442
474
  if (pending)
443
475
  this.policy.bindChild(agent, parent, admission, pending.invocation, pending.maxDepth, pending.toolFilter);
476
+ else if (parent)
477
+ this.policy.bindInheritedChild(agent, parent, admission);
444
478
  await this.install(agent, this.getter(agent));
445
479
  signal.throwIfAborted();
446
480
  this.agentLifetimes.get(agent).signal.throwIfAborted();
@@ -448,7 +482,7 @@ export class NativeAdmission {
448
482
  this.check(pending);
449
483
  if (parent)
450
484
  this.assert(parent);
451
- if (this.ctx.agents.get(agent.id) !== agent || preset !== agent.ctx.get("agentPresets")?.composedPreset(agent.ctx)
485
+ if (!this.isReady || this.ctx.agents.get(agent.id) !== agent || preset !== agent.ctx.get("agentPresets")?.composedPreset(agent.ctx)
452
486
  || presetScope !== scopeParentOf(agent) || parent && !this.ctx.agents.isOwnedBy(agent.id, parent))
453
487
  throw new SubagentError("Agent changed during initialization", "UNAUTHORIZED");
454
488
  this.profiles.publish(agent, admission);
@@ -56,7 +56,7 @@ export class DsmmPermissionController extends Service {
56
56
  captureIntegrity: options.authority.captureIntegrity === undefined ? undefined : exec => options.authority.captureIntegrity(exec),
57
57
  current: exec => options.authority.current(exec),
58
58
  assertCurrent: (current, exec) => {
59
- options.authority.assertCurrent(options.authority.current(exec), exec);
59
+ options.authority.assertCurrent(current, exec);
60
60
  if (current.agent !== exec.agent || this.lifetime.signal.aborted)
61
61
  throw new PermissionRefusal("stale");
62
62
  },
@@ -1,5 +1,5 @@
1
1
  import { isAbsolute, normalize, parse, resolve } from "node:path";
2
- import { parseNativeCommands } from "./permission-settings.js";
2
+ import { parseNativeCommandPattern, parseNativeCommands } from "./permission-settings.js";
3
3
  import { PermissionRefusal } from "./permission-errors.js";
4
4
  /** Host-only validation: Windows drive-relative roots never authorize an enhancement. */
5
5
  export function parseHostNativeCommands(input = {}) {
@@ -82,9 +82,11 @@ export function nativeCommandMatch(settings, tool, identity, args, workspace) {
82
82
  if (words === undefined)
83
83
  return undefined;
84
84
  const matches = parseHostNativeCommands(settings).entries.filter(entry => {
85
- const match = entry.match, argv = match.subcommand === undefined ? words.slice(1) : words.slice(2);
86
- return match.tool === tool && match.executable === words[0] && normalize(match.workingDirectory) === cwd
87
- && (match.subcommand === undefined || match.subcommand === words[1]) && argv.length === match.args.length && argv.every((value, index) => value === match.args[index]);
85
+ const match = entry.match;
86
+ if (match.tool !== tool || normalize(match.workingDirectory) !== cwd)
87
+ return false;
88
+ const pattern = parseNativeCommandPattern(match.commandPattern);
89
+ return pattern.executable === words[0] && pattern.subcommands.includes(words[1]);
88
90
  });
89
91
  if (new Set(matches.map(entry => entry.sandboxMode)).size > 1)
90
92
  return "ambiguous";
@@ -5,16 +5,15 @@ export interface PermissionWebPolicy {
5
5
  readonly enabled: boolean;
6
6
  readonly rule: PermissionRuleAction;
7
7
  }
8
+ export interface NativeCommandMatch {
9
+ readonly tool: "bash" | "pwsh";
10
+ readonly workingDirectory: string;
11
+ readonly commandPattern: string;
12
+ }
8
13
  export interface NativeCommandEntry {
9
14
  readonly id: string;
10
15
  readonly mode: "ask" | "allow";
11
- readonly match: {
12
- readonly tool: "bash" | "pwsh";
13
- readonly executable: string;
14
- readonly subcommand?: string;
15
- readonly args: readonly string[];
16
- readonly workingDirectory: string;
17
- };
16
+ readonly match: NativeCommandMatch;
18
17
  readonly sandboxMode: "workspace-write" | "danger-full-access";
19
18
  }
20
19
  export interface NativeCommandsSettings {
@@ -38,7 +37,22 @@ export interface PermissionControlSchemaInput {
38
37
  readonly rules?: readonly PermissionRule[];
39
38
  readonly nativeCommands?: Partial<NativeCommandsSettings>;
40
39
  }
40
+ export interface NativeCommandPattern {
41
+ readonly executable: string;
42
+ readonly subcommands: readonly string[];
43
+ }
44
+ /** Bounded static prefix grammar; the optional final star always denotes the whole argv tail. */
45
+ export declare function parseNativeCommandPattern(input: unknown): NativeCommandPattern;
41
46
  export declare function parseNativeCommands(input?: unknown): NativeCommandsSettings;
47
+ export declare const nativeCommandMatchSchema: z<Schemastery.ObjectS<NoInfer<{
48
+ tool: z<"bash" | "pwsh", "bash" | "pwsh", "defined">;
49
+ workingDirectory: z<string, string, "defined">;
50
+ commandPattern: z<string, string, "defined">;
51
+ }>>, Schemastery.ObjectT<NoInfer<{
52
+ tool: z<"bash" | "pwsh", "bash" | "pwsh", "defined">;
53
+ workingDirectory: z<string, string, "defined">;
54
+ commandPattern: z<string, string, "defined">;
55
+ }>>, "defined">;
42
56
  export declare const DEFAULT_PERMISSION_CONTROL: PermissionControlSettings;
43
57
  export declare const permissionControlSchema: z<PermissionControlSettings>;
44
58
  export declare function resolvePermissionControl(input?: PermissionControlSchemaInput): PermissionControlSettings;
@@ -1,6 +1,19 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
2
  import { parsePermissionRules, permissionRuleRow } from "./permission-rules.js";
3
3
  import { PermissionRefusal } from "./permission-errors.js";
4
+ /** Bounded static prefix grammar; the optional final star always denotes the whole argv tail. */
5
+ export function parseNativeCommandPattern(input) {
6
+ if (typeof input !== "string" || input.length > 32768)
7
+ throw new PermissionRefusal("validation");
8
+ const tokens = input.replace(/^[ \t]+|[ \t]+$/gu, "").split(/[ \t]+/u);
9
+ if (tokens.length !== 2 && (tokens.length !== 3 || tokens[2] !== "*")
10
+ || tokens[0].length === 0 || /[^\p{L}\p{M}\p{N}_./:=+%\\\-]/u.test(tokens[0]))
11
+ throw new PermissionRefusal("validation");
12
+ const subcommands = tokens[1].split("|");
13
+ if (subcommands.some(value => value.length === 0 || /[^\p{L}\p{M}\p{N}_./:=+%\-]/u.test(value)))
14
+ throw new PermissionRefusal("validation");
15
+ return Object.freeze({ executable: tokens[0], subcommands: Object.freeze(subcommands) });
16
+ }
4
17
  export function parseNativeCommands(input = {}) {
5
18
  const row = permissionRuleRow(input, [], ["enabled", "entries"]);
6
19
  if (row.enabled !== undefined && typeof row.enabled !== "boolean" || row.entries !== undefined && (!Array.isArray(row.entries) || row.entries.length > 1024))
@@ -9,25 +22,24 @@ export function parseNativeCommands(input = {}) {
9
22
  throw new PermissionRefusal("validation"); return value; };
10
23
  const ids = new Set();
11
24
  const entries = (row.entries ?? []).map(value => {
12
- const entry = permissionRuleRow(value, ["id", "mode", "match", "sandboxMode"]), match = permissionRuleRow(entry.match, ["tool", "executable", "args", "workingDirectory"], ["subcommand"]);
25
+ const entry = permissionRuleRow(value, ["id", "mode", "match", "sandboxMode"]);
26
+ const match = permissionRuleRow(entry.match, ["tool", "workingDirectory", "commandPattern"]);
13
27
  const id = text(entry.id), cwd = text(match.workingDirectory);
14
28
  if (ids.has(id) || !["ask", "allow"].includes(entry.mode) || !["bash", "pwsh"].includes(match.tool)
15
29
  || !["workspace-write", "danger-full-access"].includes(entry.sandboxMode)
16
30
  // Wire paths belong to the Host, not the browser's platform. The Host validates and canonicalizes them before use.
17
- || !/^(?:\/|[a-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+(?:[\\/]|$))/iu.test(cwd) || !Array.isArray(match.args))
31
+ || !/^(?:\/|[a-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+(?:[\\/]|$))/iu.test(cwd))
18
32
  throw new PermissionRefusal("validation");
19
33
  ids.add(id);
20
- return Object.freeze({ id, mode: entry.mode, sandboxMode: entry.sandboxMode, match: Object.freeze({
21
- tool: match.tool, executable: text(match.executable), ...match.subcommand === undefined ? {} : { subcommand: text(match.subcommand) },
22
- args: Object.freeze(match.args.map(text)), workingDirectory: cwd,
23
- }) });
34
+ parseNativeCommandPattern(match.commandPattern);
35
+ const parsed = { tool: match.tool, workingDirectory: cwd, commandPattern: match.commandPattern };
36
+ return Object.freeze({ id, mode: entry.mode, sandboxMode: entry.sandboxMode, match: Object.freeze(parsed) });
24
37
  });
25
38
  return Object.freeze({ enabled: row.enabled ?? false, entries: Object.freeze(entries) });
26
39
  }
40
+ export const nativeCommandMatchSchema = z.object({ tool: z.union(["bash", "pwsh"]).required(), workingDirectory: z.string().required(), commandPattern: z.string().required() }).required();
27
41
  const nativeCommands = z.object({ enabled: z.boolean().default(false), entries: z.array(z.object({
28
- id: z.string().required(), mode: z.union(["ask", "allow"]).required(), match: z.object({
29
- tool: z.union(["bash", "pwsh"]).required(), executable: z.string().required(), subcommand: z.string(), args: z.array(z.string()).required(), workingDirectory: z.string().required(),
30
- }).required(), sandboxMode: z.union(["workspace-write", "danger-full-access"]).required(),
42
+ id: z.string().required(), mode: z.union(["ask", "allow"]).required(), match: nativeCommandMatchSchema, sandboxMode: z.union(["workspace-write", "danger-full-access"]).required(),
31
43
  })).default([]) });
32
44
  const webDefault = Object.freeze({ enabled: true, rule: "inherit" });
33
45
  export const DEFAULT_PERMISSION_CONTROL = Object.freeze({ enabled: true, outsideReads: "inherit", webSearch: webDefault, webFetch: webDefault, rules: Object.freeze([]), nativeCommands: parseNativeCommands() });
@@ -1,5 +1,5 @@
1
1
  import type { DshAgent } from "./dsh-types.js";
2
2
  import type { DsmmRoleId } from "./roles.js";
3
3
  /** The caller supplies the policy-admitted identity; only its Agent layer is changed. */
4
- export declare function registerRoleHarnessIdentity(agent: DshAgent, role: DsmmRoleId): () => void;
4
+ export declare function registerRoleHarnessIdentity(agent: DshAgent, role: DsmmRoleId, child?: boolean): () => void;
5
5
  //# sourceMappingURL=role-identity.d.ts.map
@@ -1,10 +1,22 @@
1
+ import { getTraceable } from "@deepseek-ai/cordis";
1
2
  import { nativeAgentContext } from "./native-scope.js";
2
3
  import { buildRoleIdentity } from "./prompt-content.js";
3
4
  import { DSMM_ROLES } from "./roles.js";
4
5
  /** 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)) });
6
+ export function registerRoleHarnessIdentity(agent, role, child = false) {
7
+ const ctx = nativeAgentContext(agent);
8
+ const prompt = getTraceable(ctx, ctx.get("agentPresets")?.serviceFor({ ctx }, "systemPrompt") ?? ctx.get("systemPrompt"));
9
+ const definition = DSMM_ROLES.find(row => row.id === role);
10
+ const identity = prompt.section({ name: "harness:identity", order: prompt.getSectionOrder("HARNESS_IDENTITY"),
11
+ text: buildRoleIdentity(definition) });
12
+ try {
13
+ const persona = child ? prompt.section({ name: "deployment:persona-prefix", order: prompt.getSectionOrder("DEPLOYMENT_PERSONA_PREFIX"),
14
+ text: definition.persona }) : undefined;
15
+ return () => { persona?.(); identity(); };
16
+ }
17
+ catch (error) {
18
+ identity();
19
+ throw error;
20
+ }
9
21
  }
10
22
  //# sourceMappingURL=role-identity.js.map
@@ -12,6 +12,7 @@ export interface DsmmRoleIdentity {
12
12
  readonly parent?: DshAgent;
13
13
  readonly readOnly?: boolean;
14
14
  readonly toolFilter?: ToolRestriction;
15
+ readonly preset?: string;
15
16
  }
16
17
  export declare const READONLY_ROLE_DENIED_TOOLS: readonly ["write", "edit", "bash", "pwsh"];
17
18
  export declare function roleToolName(role: DsmmRoleId): string;
@@ -32,6 +33,8 @@ export declare class DsmmRolePolicy {
32
33
  private selected;
33
34
  validateRootRole(agent: DshAgent, admission: DsmmProfileAdmission): void;
34
35
  bindChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission, invocation: ResolvedRoleInvocation, maximum: number | undefined, toolFilter: ToolRestriction): void;
36
+ /** Ordinary native inheritance captures ceilings without inventing a role invocation. */
37
+ bindInheritedChild(agent: DshAgent, parent: DshAgent, admission: DsmmProfileAdmission): void;
35
38
  release(agent: DshAgent): void;
36
39
  assertModuleAdmission(agent: DshAgent): void;
37
40
  identity(agent: DshAgent): DsmmRoleIdentity;
@@ -1,6 +1,6 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import { SubagentError, delegationDepthOf } from "@deepseek-ai/dsh-subagent";
3
- import { symbols } from "@deepseek-ai/cordis";
3
+ import { Context, symbols } from "@deepseek-ai/cordis";
4
4
  import { DSMM_ROLES, allowedRoleChildren, isDsmmRoleId } from "./roles.js";
5
5
  export { allowedRoleChildren } from "./roles.js";
6
6
  import { isRootRoleEnabled } from "./settings.js";
@@ -24,7 +24,17 @@ export function inheritToolFilter(parent, requested) {
24
24
  return Object.freeze({ ...(allow === undefined ? {} : { allow: Object.freeze([...allow]) }), deny: Object.freeze([...new Set([...parent?.deny ?? [], ...requested?.deny ?? []])]) });
25
25
  }
26
26
  export function resolveAdmittedDsmmRole(agent, settings, active) {
27
- return liveIdentities.get(agent)?.role ?? resolveEffectiveDsmmRole(agent, settings, active);
27
+ const identity = liveIdentities.get(agent);
28
+ if (identity !== undefined)
29
+ return identity.role;
30
+ if (Context.is(agent.ctx)) {
31
+ if (!settings.modules.deepwork.enabled || !agent.ctx.get("dsmmNativeAdmission")?.owns(agent) || agent.session.header?.origin === "subagent")
32
+ return undefined;
33
+ const preset = agent.ctx.get("agentPresets")?.composedPreset(agent.ctx);
34
+ const role = isDsmmRoleId(preset) ? preset : active ? "dsmm-orchestrator" : undefined;
35
+ return role !== undefined && settings.roles[role] ? role : undefined;
36
+ }
37
+ return resolveEffectiveDsmmRole(agent, settings, active);
28
38
  }
29
39
  /** Role and exact-call restrictions; no child creation or execution owner. */
30
40
  export class DsmmRolePolicy {
@@ -42,7 +52,9 @@ export class DsmmRolePolicy {
42
52
  throw new SubagentError("Native registry unavailable", "UNAUTHORIZED"); return agents; }
43
53
  assertLive(agent) { if (!agent.id || this.agents().get(agent.id) !== agent)
44
54
  throw new SubagentError("Exact live Agent required", "UNAUTHORIZED"); }
45
- selected(agent) { return agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) ?? resolveSelectedAgentPreset(agent.session); }
55
+ selected(agent) {
56
+ return Context.is(agent.ctx) ? agent.ctx.get("agentPresets")?.composedPreset(agent.ctx) : resolveSelectedAgentPreset(agent.session);
57
+ }
46
58
  validateRootRole(agent, admission) {
47
59
  this.assertLive(agent);
48
60
  const selected = this.selected(agent);
@@ -58,19 +70,31 @@ export class DsmmRolePolicy {
58
70
  if (maximum !== undefined && delegationDepthOf(agent) > maximum)
59
71
  throw new SubagentError("Delegation depth exceeded", "UNAUTHORIZED");
60
72
  const upstream = this.identity(parent);
61
- liveIdentities.set(agent, Object.freeze({ role: invocation.target, child: true, parent, epoch: admission.epoch,
73
+ liveIdentities.set(agent, Object.freeze({ role: invocation.target, child: true, parent, preset: this.selected(agent), epoch: admission.epoch,
62
74
  readOnly: this.readOnly(upstream) || DSMM_ROLES.find(row => row.id === invocation.target).access === "read-only",
63
75
  toolFilter: inheritToolFilter(inheritToolFilter(upstream.toolFilter, toolFilter), this.visibleToolCeiling(parent)) }));
64
76
  bindRoleInvocation(agent, invocation);
65
77
  captureRoleRuntimePolicy(admission.settings, invocation.target, invocation.policy);
66
78
  }
79
+ /** Ordinary native inheritance captures ceilings without inventing a role invocation. */
80
+ bindInheritedChild(agent, parent, admission) {
81
+ this.assertLive(agent);
82
+ this.assertModuleAdmission(parent);
83
+ const upstream = this.identity(parent), preset = this.selected(agent);
84
+ if (upstream.role !== undefined || preset?.startsWith("dsmm-") || !this.agents().isOwnedBy(agent.id, parent)
85
+ || agent.session.header?.origin !== "subagent" || agent.session.header.parentSession !== parent.id)
86
+ 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,
88
+ readOnly: this.readOnly(upstream), toolFilter: inheritToolFilter(upstream.toolFilter, this.visibleToolCeiling(parent)) }));
89
+ }
67
90
  release(agent) { liveIdentities.delete(agent); toolIdentities.delete(agent); }
68
91
  assertModuleAdmission(agent) {
69
92
  this.assertLive(agent);
70
93
  const settings = this.getSettings(agent), identity = liveIdentities.get(agent), selected = this.selected(agent);
71
94
  if (identity?.child) {
72
95
  this.assertLive(identity.parent);
73
- if (!this.agents().isOwnedBy(agent.id, identity.parent) || selected !== this.selected(identity.parent))
96
+ if (!this.agents().isOwnedBy(agent.id, identity.parent) || selected !== identity.preset
97
+ || identity.role !== undefined && selected !== this.selected(identity.parent))
74
98
  throw new SubagentError("Child admission no longer matches composition", "UNAUTHORIZED");
75
99
  }
76
100
  else if (agent.session.header?.origin !== "subagent")
@@ -250,12 +250,13 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
250
250
  return;
251
251
  }
252
252
  const states = new WeakMap();
253
- const reconcileIdentity = (agent, role = policy.identity(agent).role) => {
253
+ const reconcileIdentity = (agent, identity = policy.identity(agent)) => {
254
+ const role = identity.role;
254
255
  const state = states.get(agent);
255
256
  if (state === undefined || state.identityRole === role)
256
257
  return;
257
258
  state.identityPrompt?.();
258
- state.identityPrompt = role === undefined ? undefined : registerRoleHarnessIdentity(agent, role);
259
+ state.identityPrompt = role === undefined ? undefined : registerRoleHarnessIdentity(agent, role, identity.child);
259
260
  state.identityRole = role;
260
261
  };
261
262
  const reconcile = (agent) => {
@@ -289,7 +290,7 @@ export async function registerHeadlessRoleTools(ctx, controller, getSettings, po
289
290
  } });
290
291
  state.promptRealm = promptRealm;
291
292
  }
292
- reconcileIdentity(agent, identity.role);
293
+ reconcileIdentity(agent, identity);
293
294
  const subagents = agentCtx.get("subagents");
294
295
  const host = ctx.get?.("tools");
295
296
  const names = [...hostControls, ...host?.schemas().map((row) => row.name).filter((name) => name.startsWith(`mcp__${settings.lsp.serverName}__`)) ?? []];