@dsmm/dsmm 0.2.2 → 0.3.0

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 (61) hide show
  1. package/README.md +8 -10
  2. package/cordis.patch.yml +14 -0
  3. package/docs/agent-presets.md +4 -4
  4. package/docs/compatibility.md +19 -24
  5. package/docs/deferred-native-approval-risk.md +2 -2
  6. package/docs/model-routing.md +3 -3
  7. package/docs/profiles.md +1 -1
  8. package/docs/releasing.md +46 -6
  9. package/docs/settings-status.md +2 -2
  10. package/lib/agent-registry.d.ts +36 -0
  11. package/lib/agent-registry.js +75 -0
  12. package/lib/child-admission.d.ts +0 -2
  13. package/lib/child-admission.js +13 -24
  14. package/lib/child-capture.d.ts +5 -1
  15. package/lib/child-capture.js +7 -5
  16. package/lib/client/children-locales.d.ts +13 -13
  17. package/lib/client/deployment-controller.js +1 -1
  18. package/lib/client.js +3 -3
  19. package/lib/delivery-authority.d.ts +18 -3
  20. package/lib/delivery-authority.js +149 -12
  21. package/lib/index.d.ts +2 -2
  22. package/lib/index.js +13 -26
  23. package/lib/native-child-evidence.d.ts +1 -3
  24. package/lib/native-child-evidence.js +0 -29
  25. package/lib/permission-rpc.js +3 -3
  26. package/lib/profile-rpc.js +6 -4
  27. package/lib/profile-store.js +2 -2
  28. package/lib/role-control-rpc.js +12 -8
  29. package/lib/role-invocation.d.ts +1 -1
  30. package/lib/role-policy.d.ts +1 -4
  31. package/lib/role-policy.js +24 -41
  32. package/lib/role-providers.d.ts +1 -1
  33. package/lib/role-providers.js +15 -55
  34. package/lib/role-runs.d.ts +17 -14
  35. package/lib/role-runs.js +45 -14
  36. package/lib/role-subagents.js +16 -6
  37. package/lib/runtime-integration.d.ts +4 -35
  38. package/lib/runtime-integration.js +38 -120
  39. package/lib/session-persistence.d.ts +2 -1
  40. package/lib/session-persistence.js +1 -1
  41. package/lib/session-scope.js +4 -1
  42. package/lib/subagent-runtime.d.ts +19 -7
  43. package/lib/subagent-runtime.js +141 -15
  44. package/package.json +110 -100
  45. package/lib/legacy-child-policy.d.ts +0 -51
  46. package/lib/legacy-child-policy.js +0 -123
  47. package/lib/legacy-read-composition.d.ts +0 -20
  48. package/lib/legacy-read-composition.js +0 -144
  49. package/lib/legacy-read-contracts.d.ts +0 -157
  50. package/lib/legacy-read-contracts.js +0 -39
  51. package/lib/legacy-read-host.d.ts +0 -19
  52. package/lib/legacy-read-host.js +0 -67
  53. package/lib/legacy-read-integration.d.ts +0 -121
  54. package/lib/legacy-read-integration.js +0 -522
  55. package/lib/legacy-read-proxy.d.ts +0 -26
  56. package/lib/legacy-read-proxy.js +0 -237
  57. package/scripts/cold-profile-composition.mjs +0 -329
  58. package/scripts/cold-profile-sources.mjs +0 -238
  59. package/scripts/migrate-cold-profile.mjs +0 -315
  60. package/scripts/repair-session-log.mjs +0 -476
  61. package/scripts/session-repair-native-verifier.mjs +0 -367
@@ -1,8 +1,7 @@
1
1
  import { SessionId } from "@deepseek-ai/dsh-session";
2
2
  import { SubagentError } from "@deepseek-ai/dsh-subagent";
3
3
  import { parseChildAdmissionCapture, parseChildAdmissionEvidenceView, parseLegacyChildEvidence } from "./child-capture.js";
4
- import { NativeChildEvidenceReader, assertNativeChildCapture, legacyEvidenceFromNativeFacts } from "./native-child-evidence.js";
5
- import { createConservativeLegacyAdmission, installLegacyChildToolPolicy } from "./legacy-child-policy.js";
4
+ import { NativeChildEvidenceReader, assertNativeChildCapture } from "./native-child-evidence.js";
6
5
  function unauthorized() { throw new SubagentError("Child admission requires an issued ticket and exact native Agent owner", "UNAUTHORIZED"); }
7
6
  /** Connects A's structural contract to C1's opaque ticket provenance without manufacturing Agents. */
8
7
  export function createChildAdmissionBinding(options) {
@@ -42,7 +41,7 @@ export function createChildAdmissionBinding(options) {
42
41
  return actual;
43
42
  };
44
43
  const reader = new NativeChildEvidenceReader(ctx, assertNative, options.nativeHistory);
45
- const readLegacy = (ticket, id, signal) => reader.legacy(nativeTicket(ticket), id, signal);
44
+ const readLegacy = () => { throw new SubagentError("Child admission without a current capture or trusted fresh invocation is unsupported; no evidence is synthesized", "UNSUPPORTED_CAPABILITY"); };
46
45
  const resolve = async (ticket, id, callerSignal) => {
47
46
  assertNative(ticket);
48
47
  const signal = AbortSignal.any([ticket.signal, callerSignal]);
@@ -50,17 +49,13 @@ export function createChildAdmissionBinding(options) {
50
49
  const evidence = await collaborators.resolveOriginalChildEvidence(profileTicket(ticket), id, signal, readLegacy);
51
50
  signal.throwIfAborted();
52
51
  assertNative(ticket);
53
- const parsed = "mode" in evidence ? parseLegacyChildEvidence(evidence) : parseChildAdmissionCapture(evidence);
52
+ if ("mode" in evidence || evidence.version !== 3)
53
+ throw new SubagentError("Only current child capture V3 is supported", "UNSUPPORTED_CAPABILITY");
54
+ const parsed = parseChildAdmissionCapture(evidence);
54
55
  const facts = await reader.read(ticket, id, signal);
55
56
  signal.throwIfAborted();
56
57
  assertNative(ticket);
57
- if ("mode" in parsed) {
58
- const physical = legacyEvidenceFromNativeFacts(facts);
59
- if (!sameLegacyEvidence(parsed, physical))
60
- unauthorized();
61
- }
62
- else
63
- assertNativeChildCapture(parsed, facts);
58
+ assertNativeChildCapture(parsed, facts);
64
59
  return evidence;
65
60
  };
66
61
  const authority = {
@@ -90,7 +85,7 @@ export function createChildAdmissionBinding(options) {
90
85
  revokeParent: (parent, reason) => {
91
86
  const actual = registeredParents.get(parent);
92
87
  if (actual !== undefined) {
93
- delivery.revokeParent(actual, reason);
88
+ delivery.withdrawParent(actual, reason);
94
89
  registeredParents.delete(parent);
95
90
  }
96
91
  },
@@ -110,14 +105,14 @@ export function createChildAdmissionBinding(options) {
110
105
  const prepared = await collaborators.childAdmission.prepare(agent, parent, ticket, merged);
111
106
  merged.throwIfAborted();
112
107
  assertNative(issued);
113
- return "mode" in prepared.evidence ? { ...prepared,
114
- admission: createConservativeLegacyAdmission(prepared.evidence, ticket.admission, options.nativeSubstrate) } : prepared;
108
+ if ("mode" in prepared.evidence || prepared.evidence.version !== 3)
109
+ throw new SubagentError("Only current child capture V3 is supported", "UNSUPPORTED_CAPABILITY");
110
+ return prepared;
115
111
  },
116
112
  validateRole(agent, parent, candidate) {
113
+ if ("mode" in candidate.evidence || candidate.evidence.version !== 3)
114
+ throw new SubagentError("Only current child capture V3 is supported", "UNSUPPORTED_CAPABILITY");
117
115
  collaborators.childAdmission.validateRole(agent, parent, candidate);
118
- if ("mode" in candidate.evidence && !candidate.retained) {
119
- installLegacyChildToolPolicy(candidate.evidence, exact(parent), exact(agent), options.legacyCapabilities);
120
- }
121
116
  },
122
117
  };
123
118
  return { authority, policy, childAdmission, readLegacy,
@@ -126,17 +121,11 @@ export function createChildAdmissionBinding(options) {
126
121
  onAdmissionGuardsInstalled() { delivery.enablePolicy(owner); },
127
122
  /** Holder owner calls this before native disposal/drain; no replacement residency is revoked. */
128
123
  async revokeBeforeDispose(parent, dispose) {
129
- authority.revokeParent(parent, "holder-disposed");
124
+ delivery.revokeParent(parent, "holder-disposed");
130
125
  await dispose();
131
126
  },
132
127
  };
133
128
  }
134
- function sameLegacyEvidence(left, right) {
135
- return left.childSessionId === right.childSessionId && left.parentSessionId === right.parentSessionId && left.role === right.role
136
- && left.depth === right.depth && JSON.stringify(left.route) === JSON.stringify(right.route)
137
- && JSON.stringify(left.toolFilter) === JSON.stringify(right.toolFilter)
138
- && left.provenFields.every(field => right.provenFields.includes(field));
139
- }
140
129
  /** DTO consumers supply the CURRENT direct-parent epoch; original epochs are not an authorization equality test. */
141
130
  export function projectChildAdmissionEvidence(evidence, parentAdmissionEpoch, parentDenied = []) {
142
131
  let view;
@@ -51,7 +51,11 @@ export interface ChildAdmissionCaptureV2 extends ChildAdmissionCaptureBase {
51
51
  effortSource: "native" | "dsmm-config";
52
52
  };
53
53
  }
54
- export type ChildAdmissionCapture = ChildAdmissionCaptureV1 | ChildAdmissionCaptureV2;
54
+ export interface ChildAdmissionCaptureV3 extends Omit<ChildAdmissionCaptureV2, "version"> {
55
+ version: 3;
56
+ delegationMode: "one-shot" | "continuable";
57
+ }
58
+ export type ChildAdmissionCapture = ChildAdmissionCaptureV1 | ChildAdmissionCaptureV2 | ChildAdmissionCaptureV3;
55
59
  /** Trusted native folds only; never synthesized from the current parent's settings. */
56
60
  export interface LegacyChildEvidence {
57
61
  version: 1;
@@ -88,11 +88,13 @@ export function parseLegacyChildEvidence(input) {
88
88
  export function parseChildAdmissionCapture(input) {
89
89
  const plain = copyJson(input);
90
90
  const version = plain?.version;
91
- if (version !== 1 && version !== 2)
91
+ if (version !== 1 && version !== 2 && version !== 3)
92
92
  fail();
93
- const row = object(plain, ["version", "childSessionId", "parentSessionId", "role", "profilePin", "originalAdmissionEpoch", "invocation", "runtimePolicyCapture", "authorityCeiling", "toolTopology", ...version === 2 ? ["modelParameterPolicy"] : []], ["locale"]);
94
- if (version === 2)
93
+ const row = object(plain, ["version", "childSessionId", "parentSessionId", "role", "profilePin", "originalAdmissionEpoch", "invocation", "runtimePolicyCapture", "authorityCeiling", "toolTopology", ...version !== 1 ? ["modelParameterPolicy"] : [], ...version === 3 ? ["delegationMode"] : []], ["locale"]);
94
+ if (version !== 1)
95
95
  parseModelParameterPolicy(row.modelParameterPolicy);
96
+ if (version === 3 && row.delegationMode !== "one-shot" && row.delegationMode !== "continuable")
97
+ fail();
96
98
  text(row.childSessionId, 256);
97
99
  text(row.parentSessionId, 256);
98
100
  role(row.role);
@@ -105,11 +107,11 @@ export function parseChildAdmissionCapture(input) {
105
107
  fail();
106
108
  epoch(pin.revision);
107
109
  }
108
- const invocation = object(row.invocation, ["level", "initialRoute", "routeSource", ...version === 2 ? ["requestedRoute", "effortSource"] : []]);
110
+ const invocation = object(row.invocation, ["level", "initialRoute", "routeSource", ...version !== 1 ? ["requestedRoute", "effortSource"] : []]);
109
111
  if (typeof invocation.level !== "string" || !["normal", "low", "high", "max"].includes(invocation.level) || !DSMM_ROUTE_SOURCES.includes(invocation.routeSource))
110
112
  fail();
111
113
  (version === 1 ? legacyRoute : route)(invocation.initialRoute);
112
- if (version === 2) {
114
+ if (version !== 1) {
113
115
  route(invocation.requestedRoute);
114
116
  if (invocation.effortSource !== "native" && invocation.effortSource !== "dsmm-config")
115
117
  fail();
@@ -112,21 +112,21 @@ export declare const childrenZh: Record<keyof typeof childrenEn, string>;
112
112
  export declare const childDisabledCopy: Record<RoleControlDisabledReason, readonly [string, string]>;
113
113
  export type ChildrenLocaleKey = keyof typeof childrenEn | `reason:${RoleControlDisabledReason}`;
114
114
  export declare const childrenLocaleEn: {
115
- "reason:unavailable": string;
116
115
  "reason:cancelled": string;
117
- "reason:starting": string;
116
+ "reason:unavailable": string;
118
117
  "reason:one-shot": string;
118
+ "reason:starting": string;
119
119
  "reason:already-background": string;
120
120
  "reason:already-settled": string;
121
121
  "reason:read-only": string;
122
122
  "reason:module-off": string;
123
- "reason:evidence-unavailable": string;
124
123
  "reason:role-disabled": string;
125
124
  "reason:background-disabled": string;
126
125
  "reason:jobs-unavailable": string;
127
126
  "reason:unknown-mode": string;
128
127
  "reason:not-direct-child": string;
129
128
  "reason:delivery-fence-unavailable": string;
129
+ "reason:evidence-unavailable": string;
130
130
  "reason:legacy-capability-denied": string;
131
131
  title: "Deepwork children";
132
132
  description: "Observed native runs and child conversations. Refresh for current state; receipts are not completion.";
@@ -236,30 +236,32 @@ export declare const childrenLocaleEn: {
236
236
  parentDenied: "Current parent denies this capability";
237
237
  };
238
238
  export declare const childrenLocaleZh: {
239
- "reason:unavailable": string;
240
239
  "reason:cancelled": string;
241
- "reason:starting": string;
240
+ "reason:unavailable": string;
242
241
  "reason:one-shot": string;
242
+ "reason:starting": string;
243
243
  "reason:already-background": string;
244
244
  "reason:already-settled": string;
245
245
  "reason:read-only": string;
246
246
  "reason:module-off": string;
247
- "reason:evidence-unavailable": string;
248
247
  "reason:role-disabled": string;
249
248
  "reason:background-disabled": string;
250
249
  "reason:jobs-unavailable": string;
251
250
  "reason:unknown-mode": string;
252
251
  "reason:not-direct-child": string;
253
252
  "reason:delivery-fence-unavailable": string;
253
+ "reason:evidence-unavailable": string;
254
254
  "reason:legacy-capability-denied": string;
255
+ pending: string;
256
+ unavailable: string;
255
257
  text: string;
256
- authority: string;
258
+ delivery: string;
259
+ role: string;
257
260
  error: string;
261
+ childId: string;
258
262
  disabled: string;
259
- unavailable: string;
260
263
  diagnostic: string;
261
264
  enabled: string;
262
- role: string;
263
265
  session: string;
264
266
  field: string;
265
267
  unknown: string;
@@ -269,7 +271,6 @@ export declare const childrenLocaleZh: {
269
271
  toolCallId: string;
270
272
  runId: string;
271
273
  mode: string;
272
- childId: string;
273
274
  stale: string;
274
275
  prompt: string;
275
276
  captured: string;
@@ -281,12 +282,11 @@ export declare const childrenLocaleZh: {
281
282
  initialRoute: string;
282
283
  routeSource: string;
283
284
  description: string;
284
- evidence: string;
285
285
  epoch: string;
286
+ evidence: string;
286
287
  yes: string;
287
288
  no: string;
288
289
  liveRoute: string;
289
- pending: string;
290
290
  descendants: string;
291
291
  interrupt: string;
292
292
  images: string;
@@ -295,9 +295,9 @@ export declare const childrenLocaleZh: {
295
295
  readonly: string;
296
296
  runs: string;
297
297
  children: string;
298
- delivery: string;
299
298
  queue: string;
300
299
  steer: string;
300
+ authority: string;
301
301
  foreign: string;
302
302
  reading: string;
303
303
  title: string;
@@ -77,7 +77,7 @@ export class DeploymentController {
77
77
  canWriteProfile(snapshot = this.state.snapshot) {
78
78
  const native = this.form?.state;
79
79
  return this.currentConnection() && snapshot !== null && this.rowNamespace !== null && this.rowNamespace === snapshot.namespace
80
- && native?.status === "ready" && native.mode === "host" && native.writable
80
+ && native?.status === "ready" && native.writable
81
81
  && native.revision === snapshot.nativeFormRevision && snapshot.nativeForm !== null
82
82
  && equal(native.base ?? null, snapshot.nativeForm.base) && equal(native.user ?? null, snapshot.nativeForm.user);
83
83
  }
package/lib/client.js CHANGED
@@ -1629,7 +1629,7 @@ function applyEdits(text5, edits) {
1629
1629
  return text5;
1630
1630
  }
1631
1631
 
1632
- // ../node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.5/node_modules/@deepseek-ai/cosmokit/lib/index.js
1632
+ // ../node_modules/.pnpm/@deepseek-ai+cosmokit@1.8.6/node_modules/@deepseek-ai/cosmokit/lib/index.js
1633
1633
  function isNullable(value) {
1634
1634
  return value === null || value === void 0;
1635
1635
  }
@@ -1854,7 +1854,7 @@ var Time;
1854
1854
  Time2.template = template;
1855
1855
  })(Time || (Time = {}));
1856
1856
 
1857
- // ../node_modules/.pnpm/@deepseek-ai+schemastery@3.18.4/node_modules/@deepseek-ai/schemastery/lib/index.mjs
1857
+ // ../node_modules/.pnpm/@deepseek-ai+schemastery@3.18.5/node_modules/@deepseek-ai/schemastery/lib/index.mjs
1858
1858
  var kSchema = Symbol.for("schemastery");
1859
1859
  var kValidationError = Symbol.for("ValidationError");
1860
1860
  globalThis.__schemastery_index__ ??= 0;
@@ -5472,7 +5472,7 @@ var DeploymentController = class _DeploymentController {
5472
5472
  }
5473
5473
  canWriteProfile(snapshot4 = this.state.snapshot) {
5474
5474
  const native = this.form?.state;
5475
- return this.currentConnection() && snapshot4 !== null && this.rowNamespace !== null && this.rowNamespace === snapshot4.namespace && native?.status === "ready" && native.mode === "host" && native.writable && native.revision === snapshot4.nativeFormRevision && snapshot4.nativeForm !== null && equal(native.base ?? null, snapshot4.nativeForm.base) && equal(native.user ?? null, snapshot4.nativeForm.user);
5475
+ return this.currentConnection() && snapshot4 !== null && this.rowNamespace !== null && this.rowNamespace === snapshot4.namespace && native?.status === "ready" && native.writable && native.revision === snapshot4.nativeFormRevision && snapshot4.nativeForm !== null && equal(native.base ?? null, snapshot4.nativeForm.base) && equal(native.user ?? null, snapshot4.nativeForm.user);
5476
5476
  }
5477
5477
  edit(path, value) {
5478
5478
  if (this.state.busy || this.disposed || this.state.snapshot === null || !this.currentConnection() || this.state.issue === "not-owned" || this.layer === "profile" && !this.canWriteProfile()) return;
@@ -1,6 +1,7 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
2
  import type { Agent } from "@deepseek-ai/dsh-agent";
3
3
  import type { SessionId } from "@deepseek-ai/dsh-session";
4
+ import type { ManagedCreation } from "./agent-registry.js";
4
5
  /** A borrowed immutable admission, never reconstructed from current settings. */
5
6
  export interface DeliveryAdmission {
6
7
  readonly epoch: string;
@@ -20,6 +21,8 @@ export interface DeliveryPolicyBinding<A extends DeliveryAdmission, E> {
20
21
  resolveChildEvidence(ticket: ParentAdmissionTicket<A>, childId: SessionId, signal: AbortSignal): Promise<E>;
21
22
  /** Check direct target identity, original ceiling AND current parent authorization. */
22
23
  assertDelivery(ticket: ParentAdmissionTicket<A>, childId: SessionId, evidence: E): void;
24
+ /** Exact Host-minted native proof; absent proof always requires managed admission. */
25
+ isNativeEvidence?(evidence: E): boolean;
23
26
  }
24
27
  export interface DeliveryFenceView {
25
28
  readonly binding: "dsmm";
@@ -36,6 +39,9 @@ export declare class DsmmDeliveryAuthority<A extends DeliveryAdmission = Deliver
36
39
  private readonly parents;
37
40
  private readonly tickets;
38
41
  private readonly managedIds;
42
+ private readonly managed;
43
+ private readonly liveManaged;
44
+ private readonly retiredAgents;
39
45
  private binding?;
40
46
  private connection?;
41
47
  private readonly providersReady;
@@ -47,12 +53,19 @@ export declare class DsmmDeliveryAuthority<A extends DeliveryAdmission = Deliver
47
53
  bindPolicy(scope: Context, owner: object, policy: DeliveryPolicyBinding<A, E>): () => void;
48
54
  /** Called after A/B admission/capture guards are installed, not at service mount. */
49
55
  enablePolicy(owner: object): void;
50
- isManaged(parent: Agent): boolean;
56
+ isManaged(parent: Agent, intent?: "delivery" | "creation"): boolean;
51
57
  registerParent(parent: Agent, admission: A, owner: object): void;
58
+ beginPending(operation: ManagedCreation, agent: Agent): void;
59
+ /** Receipt acceptance, not the caller's old operation signal, opens execution. */
60
+ promote(operation: ManagedCreation): void;
61
+ assertSender(parent: Agent): void;
62
+ waitForPromotion(parent: Agent, signal?: AbortSignal): Promise<void>;
63
+ retireOperation(operation: ManagedCreation, reason: string): void;
52
64
  acquireParentTicket(parent: Agent): ParentAdmissionTicket<A>;
53
65
  assertTicket(ticket: ParentAdmissionTicket<A>): void;
54
66
  resolveChildEvidence(ticket: ParentAdmissionTicket<A>, childId: SessionId, signal: AbortSignal): Promise<E>;
55
- assertDelivery(ticket: ParentAdmissionTicket<A>, childId: SessionId, evidence: E): void;
67
+ /** Validate the target and return whether its materialization requires DSMM capture. */
68
+ assertDelivery(ticket: ParentAdmissionTicket<A>, childId: SessionId, evidence: E): boolean;
56
69
  prepareParentAdmission(parent: Agent, expectedEpoch: string, nextAdmission: A): void;
57
70
  /** Core configuration uses the same exact parent state without acquiring delivery capability. */
58
71
  assertCoreParentAdmission(parent: Agent, owner: object, expected: A): void;
@@ -60,8 +73,10 @@ export declare class DsmmDeliveryAuthority<A extends DeliveryAdmission = Deliver
60
73
  /** Trusted successful-commit callback: install MUST be synchronous and nonthrowing. */
61
74
  publishParentAdmission(parent: Agent, expectedEpoch: string, nextAdmission: A, install: () => void): void;
62
75
  revokeParent(parent: Agent, _reason: string): void;
76
+ /** Admission withdrawal invalidates tickets without terminating a living Agent. */
77
+ withdrawParent(parent: Agent, reason: string): void;
63
78
  revokeOwner(owner: object, reason: string): void;
64
- /** Only the native exact operator/Connection can authorize browser delivery. */
79
+ /** Only the native exact browser peer/Connection can authorize browser delivery. */
65
80
  acquireBrowserSignal(callerCtx: Context): AbortSignal;
66
81
  private current;
67
82
  }
@@ -1,5 +1,6 @@
1
1
  import { symbols } from "@deepseek-ai/cordis";
2
2
  import { SubagentError } from "@deepseek-ai/dsh-subagent";
3
+ import { currentManagedCreation, exactRegistry } from "./agent-registry.js";
3
4
  function original(value) {
4
5
  return Reflect.get(value, symbols.original) ?? value;
5
6
  }
@@ -48,6 +49,9 @@ export class DsmmDeliveryAuthority {
48
49
  parents = new Map();
49
50
  tickets = new WeakMap();
50
51
  managedIds = new Set();
52
+ managed = new WeakMap();
53
+ liveManaged = new Set();
54
+ retiredAgents = new WeakSet();
51
55
  binding;
52
56
  connection;
53
57
  providersReady;
@@ -60,23 +64,40 @@ export class DsmmDeliveryAuthority {
60
64
  this.hostClassifier = hostClassifier;
61
65
  scopeLifetime(ctx, "dsmm.deliveryAuthority: revoke Host tickets", () => {
62
66
  this.lifetime.abort();
67
+ for (const parent of this.liveManaged)
68
+ this.revokeParent(parent, "host-disposed");
63
69
  for (const parent of this.parents.keys())
64
70
  this.revokeParent(parent, "host-disposed");
65
71
  this.changed();
66
72
  });
67
73
  ctx.on("agent/disposed", ({ agent }) => this.revokeParent(agent, "registry-residency-disposed"), { global: true });
74
+ ctx.on("agent/created", ({ agent, signal }) => {
75
+ const retire = () => this.revokeParent(agent, "agent-lifecycle-ended");
76
+ signal?.addEventListener("abort", retire, { once: true });
77
+ if (signal?.aborted)
78
+ retire();
79
+ const operation = currentManagedCreation();
80
+ if (operation === undefined || !operation.claimed || operation.childId !== agent.id
81
+ || operation.registry !== exactRegistry(ctx.agents) || !ctx.agents.isOwnedBy(agent.id, operation.parent))
82
+ return;
83
+ if (operation.child !== agent || operation.retired)
84
+ unauthorized();
85
+ if (signal?.aborted || operation.ownerSignal?.aborted)
86
+ retire();
87
+ }, { global: true, prepend: true });
68
88
  ctx.inject(["connection"], (connectionCtx) => {
69
89
  const connection = connectionCtx.get("connection");
70
- const state = { owner: original(connection), operator: connection.operator, controller: new AbortController() };
90
+ const state = { owner: original(connection), browserPeer: connection.browserPeer, controller: new AbortController() };
71
91
  const revoke = () => {
72
92
  state.controller.abort();
73
93
  if (this.connection === state)
74
94
  this.connection = undefined;
75
95
  };
76
- // Native operator scope ancestry includes the exact providing Connection fiber.
77
- const detachOperator = scopeLifetime(connection.operator.ctx, "dsmm.deliveryAuthority: revoke operator and Connection lifetime", revoke);
78
- scopeLifetime(connectionCtx, "dsmm.deliveryAuthority: release Connection observer", () => { revoke(); detachOperator(); }, () => {
79
- if (state.controller.signal.aborted)
96
+ connection.browserPeer.signal.addEventListener("abort", revoke, { once: true });
97
+ // Browser peer scope ancestry includes the exact providing Connection fiber.
98
+ const detachPeer = scopeLifetime(connection.browserPeer.ctx, "dsmm.deliveryAuthority: revoke browser and Connection lifetime", revoke);
99
+ scopeLifetime(connectionCtx, "dsmm.deliveryAuthority: release Connection observer", () => { revoke(); connection.browserPeer.signal.removeEventListener("abort", revoke); detachPeer(); }, () => {
100
+ if (state.controller.signal.aborted || connection.browserPeer.signal.aborted)
80
101
  unauthorized();
81
102
  this.connection = state;
82
103
  });
@@ -110,7 +131,14 @@ export class DsmmDeliveryAuthority {
110
131
  this.binding.enabled = true;
111
132
  this.changed();
112
133
  }
113
- isManaged(parent) {
134
+ isManaged(parent, intent = "delivery") {
135
+ if (this.managed.has(parent))
136
+ return true;
137
+ // An admitted native parent still needs current proof of its delivery target's identity.
138
+ if (intent === "delivery" && this.parents.has(parent))
139
+ return true;
140
+ if (intent === "creation" && parent.session.header.origin !== "subagent" && this.binding?.policy.classifyParent(parent) === "native")
141
+ return false;
114
142
  if (this.managedIds.has(parent.id))
115
143
  return true;
116
144
  // An absent binding is unknown authority, never proof of a native caller.
@@ -121,9 +149,21 @@ export class DsmmDeliveryAuthority {
121
149
  return kind !== "native";
122
150
  }
123
151
  registerParent(parent, admission, owner) {
124
- if (this.binding?.owner !== owner || this.lifetime.signal.aborted
152
+ if (this.retiredAgents.has(parent) || this.binding?.owner !== owner || this.lifetime.signal.aborted
125
153
  || this.ctx.get("agents")?.get(parent.id) !== parent || admission.epoch.length === 0)
126
154
  unauthorized();
155
+ const managed = this.managed.get(parent);
156
+ if (managed === undefined && parent.session.header.origin === "subagent")
157
+ unauthorized();
158
+ if (managed?.status === "retired")
159
+ unauthorized();
160
+ if (managed?.status === "pending") {
161
+ if (managed.admission !== undefined && (managed.admission !== admission || managed.owner !== owner))
162
+ unauthorized();
163
+ managed.admission = admission;
164
+ managed.owner = owner;
165
+ return;
166
+ }
127
167
  const existing = this.parents.get(parent);
128
168
  if (existing !== undefined) {
129
169
  if (existing.owner !== owner || existing.admission !== admission || existing.publishing)
@@ -142,9 +182,75 @@ export class DsmmDeliveryAuthority {
142
182
  this.revokeParent(parent, "residency-disposed");
143
183
  }, () => {
144
184
  this.parents.set(parent, state);
145
- this.managedIds.add(parent.id);
146
185
  });
147
186
  }
187
+ beginPending(operation, agent) {
188
+ if (operation.child !== undefined || operation.retired || this.managed.has(agent) || this.retiredAgents.has(agent))
189
+ unauthorized();
190
+ operation.child = agent;
191
+ let release;
192
+ const ready = new Promise(done => { release = done; });
193
+ this.managed.set(agent, { operation, status: "pending", ready, release });
194
+ this.liveManaged.add(agent);
195
+ this.managedIds.add(operation.parent.id);
196
+ this.managedIds.add(agent.id);
197
+ const retire = () => this.revokeParent(agent, "managed-owner-ended");
198
+ operation.ownerSignal?.addEventListener("abort", retire, { once: true });
199
+ scopeLifetime(agent.ctx, "dsmm.deliveryAuthority: pending residency", retire);
200
+ if (operation.ownerSignal?.aborted || this.lifetime.signal.aborted)
201
+ retire();
202
+ }
203
+ /** Receipt acceptance, not the caller's old operation signal, opens execution. */
204
+ promote(operation) {
205
+ const child = operation.child, managed = child === undefined ? undefined : this.managed.get(child);
206
+ if (child === undefined || managed?.operation !== operation)
207
+ throw new SubagentError("Managed receipt has no exact prepared child", "UNAUTHORIZED");
208
+ if (managed.status !== "pending" || operation.retired || operation.ownerSignal?.aborted)
209
+ throw new SubagentError("Managed receipt residency ended before promotion", "UNAUTHORIZED");
210
+ if (this.ctx.agents.get(child.id) !== child || !this.ctx.agents.isOwnedBy(child.id, operation.parent)
211
+ || exactRegistry(this.ctx.agents) !== operation.registry)
212
+ throw new SubagentError("Managed receipt registry or ownership changed", "UNAUTHORIZED");
213
+ if (managed.admission === undefined || managed.owner !== operation.owner)
214
+ throw new SubagentError("Managed receipt has no completed capture admission", "UNAUTHORIZED");
215
+ managed.status = "active";
216
+ try {
217
+ this.registerParent(child, managed.admission, managed.owner);
218
+ }
219
+ catch (error) {
220
+ this.revokeParent(child, "promotion-failed");
221
+ throw error;
222
+ }
223
+ managed.release();
224
+ }
225
+ assertSender(parent) {
226
+ if (this.retiredAgents.has(parent))
227
+ unauthorized();
228
+ const state = this.managed.get(parent);
229
+ if (state !== undefined && state.status !== "active")
230
+ unauthorized();
231
+ }
232
+ async waitForPromotion(parent, signal) {
233
+ if (this.retiredAgents.has(parent))
234
+ unauthorized();
235
+ const state = this.managed.get(parent);
236
+ if (state === undefined || state.status === "active")
237
+ return;
238
+ if (state.status === "retired" || signal === undefined)
239
+ unauthorized();
240
+ signal.throwIfAborted();
241
+ await new Promise((resolve, reject) => {
242
+ const abort = () => { signal.removeEventListener("abort", abort); reject(signal.reason); };
243
+ signal.addEventListener("abort", abort, { once: true });
244
+ void state.ready.then(() => { signal.removeEventListener("abort", abort); resolve(); });
245
+ });
246
+ signal.throwIfAborted();
247
+ this.assertSender(parent);
248
+ }
249
+ retireOperation(operation, reason) {
250
+ operation.retired = true;
251
+ if (operation.child !== undefined)
252
+ this.revokeParent(operation.child, reason);
253
+ }
148
254
  acquireParentTicket(parent) {
149
255
  if (!this.view().deliveryFenceReady)
150
256
  unauthorized();
@@ -172,10 +278,15 @@ export class DsmmDeliveryAuthority {
172
278
  this.assertTicket(ticket);
173
279
  return evidence;
174
280
  }
281
+ /** Validate the target and return whether its materialization requires DSMM capture. */
175
282
  assertDelivery(ticket, childId, evidence) {
176
283
  this.assertTicket(ticket);
177
284
  this.binding.policy.assertDelivery(ticket, childId, evidence);
285
+ const managed = this.binding.policy.isNativeEvidence?.(evidence) !== true;
286
+ if (!managed && this.managedIds.has(childId))
287
+ unauthorized();
178
288
  this.assertTicket(ticket);
289
+ return managed;
179
290
  }
180
291
  prepareParentAdmission(parent, expectedEpoch, nextAdmission) {
181
292
  if (!this.view().deliveryFenceReady)
@@ -216,7 +327,7 @@ export class DsmmDeliveryAuthority {
216
327
  previous.abort();
217
328
  }
218
329
  catch (error) {
219
- this.revokeParent(parent, "publication-failed");
330
+ this.withdrawParent(parent, "publication-failed");
220
331
  throw error;
221
332
  }
222
333
  finally {
@@ -224,6 +335,26 @@ export class DsmmDeliveryAuthority {
224
335
  }
225
336
  }
226
337
  revokeParent(parent, _reason) {
338
+ this.retiredAgents.add(parent);
339
+ const managed = this.managed.get(parent);
340
+ if (managed !== undefined) {
341
+ managed.status = "retired";
342
+ managed.operation.retired = true;
343
+ managed.release();
344
+ }
345
+ this.liveManaged.delete(parent);
346
+ for (const child of this.liveManaged)
347
+ if (this.managed.get(child).operation.parent === parent)
348
+ this.revokeParent(child, _reason);
349
+ this.withdrawParent(parent, _reason);
350
+ }
351
+ /** Admission withdrawal invalidates tickets without terminating a living Agent. */
352
+ withdrawParent(parent, reason) {
353
+ const managed = this.managed.get(parent);
354
+ if (managed?.status === "pending") {
355
+ this.revokeParent(parent, reason);
356
+ return;
357
+ }
227
358
  const state = this.parents.get(parent);
228
359
  if (state === undefined)
229
360
  return;
@@ -234,22 +365,28 @@ export class DsmmDeliveryAuthority {
234
365
  state.detachResidency?.();
235
366
  }
236
367
  revokeOwner(owner, reason) {
368
+ for (const parent of this.liveManaged) {
369
+ const state = this.managed.get(parent);
370
+ if (state.status === "pending" && state.operation.owner === owner)
371
+ this.revokeParent(parent, reason);
372
+ }
237
373
  for (const [parent, state] of this.parents)
238
374
  if (state.owner === owner)
239
- this.revokeParent(parent, reason);
375
+ this.withdrawParent(parent, reason);
240
376
  }
241
- /** Only the native exact operator/Connection can authorize browser delivery. */
377
+ /** Only the native exact browser peer/Connection can authorize browser delivery. */
242
378
  acquireBrowserSignal(callerCtx) {
243
379
  const invocation = callerCtx.invocation;
244
380
  const connection = callerCtx.get("connection");
245
381
  const state = this.connection;
246
382
  if (invocation?.peer === undefined || connection === undefined || state === undefined
247
- || original(connection) !== state.owner || connection.operator !== invocation.peer || state.operator !== invocation.peer)
383
+ || original(connection) !== state.owner || connection.browserPeer !== invocation.peer || state.browserPeer !== invocation.peer)
248
384
  unauthorized();
249
385
  state.controller.signal.throwIfAborted();
250
386
  return state.controller.signal;
251
387
  }
252
388
  current(parent) {
389
+ this.assertSender(parent);
253
390
  const state = this.parents.get(parent);
254
391
  if (state === undefined || state.publishing || state.lifetime.signal.aborted || this.lifetime.signal.aborted
255
392
  || this.binding?.owner !== state.owner || this.ctx.get("agents")?.get(parent.id) !== parent)
package/lib/index.d.ts CHANGED
@@ -41,11 +41,11 @@ export { DEEPWORK_MODE_EVENT, DeepworkModeController, hasOpenTurn, isDeepworkAct
41
41
  export type { DsmmHostStartupOptions } from "./runtime-integration.js";
42
42
  export { DsmmNativeLlmRuntime } from "./llm-runtime.js";
43
43
  export type { DsmmLlmAdmission, DsmmLlmCallConfig, DsmmLlmHostOwner, DsmmLlmGeneration, DsmmJson } from "./host-llm.js";
44
- /** Experimental Host collaborators are programmatic only; serialized settings cannot authenticate them. */
44
+ /** The current Host composition does not accept compatibility adapters. */
45
45
  export declare function createDsmmHostPlugin(startup: DsmmHostStartupOptions): {
46
46
  name: string;
47
47
  Config: import("@deepseek-ai/schemastery").default<DsmmPluginConfig>;
48
- inject: string[] | readonly ["profileContext", "agents"];
48
+ inject: readonly ["profileContext", "agents"];
49
49
  apply(ctx: DshContext, config?: Config): void | Promise<void>;
50
50
  };
51
51
  export declare function apply(ctx: DshContext, config?: Config, hostStartup?: DsmmHostStartupOptions): void | Promise<void>;