@deepseek-ai/dsh-subagent 0.2.2-rc.1 → 0.2.2-rc.2

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 (108) hide show
  1. package/README.i18n.yaml +46 -28
  2. package/README.md +52 -23
  3. package/README.zh.md +52 -23
  4. package/lib/index.js +845 -902
  5. package/lib/typert.host.js +91 -125
  6. package/lib/typert.remote-client.d.ts +3 -3
  7. package/lib/typert.remote-client.d.ts.map +1 -0
  8. package/lib/typert.remote-client.js +17 -63
  9. package/lib/types/activation.d.ts +17 -25
  10. package/lib/types/activation.d.ts.map +1 -0
  11. package/lib/types/activation.js +1 -1
  12. package/lib/types/activation.js.map +1 -0
  13. package/lib/types/archive-admission.d.ts +11 -4
  14. package/lib/types/archive-admission.d.ts.map +1 -0
  15. package/lib/types/archive-admission.js +39 -115
  16. package/lib/types/archive-admission.js.map +1 -0
  17. package/lib/types/assistant-output.d.ts.map +1 -0
  18. package/lib/types/assistant-output.js.map +1 -0
  19. package/lib/types/catalog.d.ts +27 -7
  20. package/lib/types/catalog.d.ts.map +1 -0
  21. package/lib/types/catalog.js +31 -8
  22. package/lib/types/catalog.js.map +1 -0
  23. package/lib/types/child-agent.d.ts +7 -17
  24. package/lib/types/child-agent.d.ts.map +1 -0
  25. package/lib/types/child-agent.js +6 -4
  26. package/lib/types/child-agent.js.map +1 -0
  27. package/lib/types/client.d.ts.map +1 -0
  28. package/lib/types/client.js.map +1 -0
  29. package/lib/types/continuation-messages.d.ts +13 -10
  30. package/lib/types/continuation-messages.d.ts.map +1 -0
  31. package/lib/types/continuation-messages.js +22 -22
  32. package/lib/types/continuation-messages.js.map +1 -0
  33. package/lib/types/control-types.d.ts +7 -28
  34. package/lib/types/control-types.d.ts.map +1 -0
  35. package/lib/types/control-types.js.map +1 -0
  36. package/lib/types/control.d.ts +0 -4
  37. package/lib/types/control.d.ts.map +1 -0
  38. package/lib/types/control.js +1 -5
  39. package/lib/types/control.js.map +1 -0
  40. package/lib/types/depth.d.ts.map +1 -0
  41. package/lib/types/depth.js.map +1 -0
  42. package/lib/types/descriptor.d.ts +1 -1
  43. package/lib/types/descriptor.d.ts.map +1 -0
  44. package/lib/types/descriptor.js +1 -1
  45. package/lib/types/descriptor.js.map +1 -0
  46. package/lib/types/error.d.ts.map +1 -0
  47. package/lib/types/error.js.map +1 -0
  48. package/lib/types/index.d.ts +74 -97
  49. package/lib/types/index.d.ts.map +1 -0
  50. package/lib/types/index.js +125 -146
  51. package/lib/types/index.js.map +1 -0
  52. package/lib/types/lifecycle.d.ts +9 -38
  53. package/lib/types/lifecycle.d.ts.map +1 -0
  54. package/lib/types/lifecycle.js +5 -31
  55. package/lib/types/lifecycle.js.map +1 -0
  56. package/lib/types/list-children.d.ts +12 -0
  57. package/lib/types/list-children.d.ts.map +1 -0
  58. package/lib/types/list-children.js +35 -6
  59. package/lib/types/list-children.js.map +1 -0
  60. package/lib/types/manager.d.ts +96 -112
  61. package/lib/types/manager.d.ts.map +1 -0
  62. package/lib/types/manager.js +471 -568
  63. package/lib/types/manager.js.map +1 -0
  64. package/lib/types/names.d.ts +56 -0
  65. package/lib/types/names.d.ts.map +1 -0
  66. package/lib/types/names.js +96 -0
  67. package/lib/types/names.js.map +1 -0
  68. package/lib/types/out-of-process.d.ts.map +1 -0
  69. package/lib/types/out-of-process.js.map +1 -0
  70. package/lib/types/projection-types.d.ts +18 -6
  71. package/lib/types/projection-types.d.ts.map +1 -0
  72. package/lib/types/projection-types.js.map +1 -0
  73. package/lib/types/projection.d.ts +2 -2
  74. package/lib/types/projection.d.ts.map +1 -0
  75. package/lib/types/projection.js.map +1 -0
  76. package/lib/types/structured.d.ts +1 -1
  77. package/lib/types/structured.d.ts.map +1 -0
  78. package/lib/types/structured.js +2 -2
  79. package/lib/types/structured.js.map +1 -0
  80. package/lib/types/types.d.ts +34 -28
  81. package/lib/types/types.d.ts.map +1 -0
  82. package/lib/types/types.js +2 -4
  83. package/lib/types/types.js.map +1 -0
  84. package/package.json +54 -54
  85. package/src/activation.ts +184 -0
  86. package/src/archive-admission.ts +84 -0
  87. package/src/assistant-output.ts +75 -0
  88. package/src/catalog.ts +194 -0
  89. package/src/child-agent.ts +280 -0
  90. package/src/client.ts +8 -0
  91. package/src/continuation-messages.ts +176 -0
  92. package/src/control-types.ts +127 -0
  93. package/src/control.ts +103 -0
  94. package/src/depth.ts +51 -0
  95. package/src/descriptor.ts +269 -0
  96. package/src/error.ts +15 -0
  97. package/src/index.ts +604 -0
  98. package/src/lifecycle.ts +116 -0
  99. package/src/list-children.ts +168 -0
  100. package/src/manager.ts +1359 -0
  101. package/src/names.ts +113 -0
  102. package/src/out-of-process.ts +217 -0
  103. package/src/projection-types.ts +109 -0
  104. package/src/projection.ts +184 -0
  105. package/src/structured.ts +155 -0
  106. package/src/types.ts +364 -0
  107. package/lib/types/internal.d.ts +0 -58
  108. package/lib/types/internal.js +0 -58
@@ -56,6 +56,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
56
56
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
57
  });
58
58
  import { SubagentError } from "./error.js";
59
+ import { isAgentName, joinAgentPath } from "./names.js";
59
60
  /**
60
61
  * Read one parent's durable catalog through a live-preferred Session observation.
61
62
  * @param ctx - context carrying the Session query service.
@@ -115,15 +116,17 @@ export async function listDescendants(ctx, rootSessionId, signal) {
115
116
  return children;
116
117
  };
117
118
  const stack = (await readChildren(rootSessionId))
118
- .map(entry => ({ entry, parentId: rootSessionId, depth: 1 }))
119
+ .map(entry => ({ entry, parentId: rootSessionId, depth: 1, parentPath: '' }))
119
120
  .reverse();
120
121
  const visited = new Set([rootSessionId]);
121
122
  const result = [];
122
123
  for (let position = stack.pop(); position !== undefined; position = stack.pop()) {
123
- const { entry, parentId, depth } = position;
124
+ const { entry, parentId, depth, parentPath } = position;
124
125
  if (visited.has(entry.id))
125
126
  continue;
126
127
  visited.add(entry.id);
128
+ const path = joinAgentPath(parentPath, 'name' in entry ? entry.name : undefined);
129
+ const at = { parentId, depth, ...path === undefined ? {} : { path } };
127
130
  let children;
128
131
  try {
129
132
  children = entry.mode === 'external' ? [] : await readChildren(entry.id);
@@ -133,30 +136,56 @@ export async function listDescendants(ctx, rootSessionId, signal) {
133
136
  throw error;
134
137
  const code = error instanceof Error && 'code' in error ? error.code : undefined;
135
138
  result.push({
136
- kind: 'diagnostic', id: entry.id, parentId, depth,
139
+ kind: 'diagnostic', id: entry.id, ...at,
137
140
  reason: code === 'SESSION_QUERY_CORRUPT_SESSION' || code === 'SESSION_QUERY_SOURCE_CONFLICT'
138
141
  ? 'corrupt' : 'unavailable',
139
142
  });
140
143
  continue;
141
144
  }
142
145
  if (entry.mode === 'unknown') {
143
- result.push({ kind: 'diagnostic', id: entry.id, parentId, depth, reason: 'unsupported' });
146
+ result.push({ kind: 'diagnostic', id: entry.id, ...at, reason: 'unsupported' });
144
147
  }
145
148
  else {
146
149
  const { createdAt: _createdAt, ...identity } = entry;
147
150
  result.push({
148
- ...identity, kind: 'child', parentId, depth,
151
+ ...identity, kind: 'child', ...at,
149
152
  activity: sessions.get(entry.id) === undefined ? 'inactive' : 'running',
150
153
  hasChildren: children.length > 0,
151
154
  });
152
155
  }
153
156
  // Catalog event order defines siblings; the stack visits the first one next.
154
157
  for (const child of [...children].reverse()) {
155
- stack.push({ entry: child, parentId: entry.id, depth: depth + 1 });
158
+ stack.push({ entry: child, parentId: entry.id, depth: depth + 1, parentPath: path });
156
159
  }
157
160
  }
158
161
  return result;
159
162
  }
163
+ /**
164
+ * Resolve a slash-separated name by reading only the catalogs along its path.
165
+ * @param ctx - context carrying the Session query service.
166
+ * @param rootSessionId - tree root whose catalog holds the first name.
167
+ * @param name - candidate full name relative to the root.
168
+ * @param signal - cancellation forwarded to each catalog read.
169
+ * @returns the named member's Session id, or undefined when the text is not a name in this tree.
170
+ * @throws {@link SubagentError} when a catalog dependency is unavailable; Session read failures propagate.
171
+ */
172
+ export async function resolveAgentPath(ctx, rootSessionId, name, signal) {
173
+ const segments = name.split('/');
174
+ if (!segments.every(isAgentName))
175
+ return undefined;
176
+ let current = rootSessionId;
177
+ for (const [index, segment] of segments.entries()) {
178
+ const children = await listChildren(ctx, current, signal);
179
+ const child = children.find(entry => 'name' in entry && entry.name === segment);
180
+ if (child === undefined)
181
+ return undefined;
182
+ // External and unknown children own no local Session, so they are the last segment too.
183
+ if (index < segments.length - 1 && child.mode !== 'continuable' && child.mode !== 'one-shot')
184
+ return undefined;
185
+ current = child.id;
186
+ }
187
+ return current;
188
+ }
160
189
  /** Stop the complete traversal when its caller cancels. */
161
190
  function assertListingNotCancelled(signal) {
162
191
  if (signal?.aborted) {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-children.js","sourceRoot":"","sources":["../../src/list-children.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAevD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,GAAY,EACZ,eAA0B,EAC1B,MAAoB;;;QAEpB,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QACrC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,aAAa,CACrB,2FAA2F,EAC3F,oCAAoC,CACrC,CAAA;QACH,CAAC;QACD,MAAM,MAAM,kCAAG,MAAM,KAAK,CAAC,cAAc,CAAC,eAAe,EAAE;YACzD,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE;SAC1C,CAAC,QAAA,CAAA;QACF,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,eAAe,CA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CAAC;QAAE,OAAO,SAAS,CAAA;IAClD,IAAI,OAAO,GAAG,aAAa,CAAA;IAC3B,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QAClD,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QACzD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAA;QAC/E,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAA;QACzC,wFAAwF;QACxF,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;YAAE,OAAO,SAAS,CAAA;QAC9G,OAAO,GAAG,KAAK,CAAC,EAAE,CAAA;IACpB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,2DAA2D;AAC3D,SAAS,yBAAyB,CAAC,MAA+B;IAChE,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,aAAa,CAAC,gCAAgC,EAAE,WAAW,CAAC,CAAA;IACxE,CAAC;AACH,CAAC"}
@@ -1,23 +1,36 @@
1
1
  /**
2
2
  * Owns subagent startup, message admission, cold resume, and execution lifetimes.
3
3
  * One child lock orders input acceptance and closure; one activation map owns
4
- * capacity, parent relationships, and resource release across all providers.
4
+ * capacity, runtime ownership, and resource release across all providers.
5
5
  *
6
6
  * @module @deepseek-ai/dsh-subagent/manager
7
7
  */
8
- import type { Context } from '@deepseek-ai/cordis';
8
+ import { type Context } from '@deepseek-ai/cordis';
9
9
  import type { Agent } from '@deepseek-ai/dsh-agent';
10
10
  import type { ContentBlock, MessageId, MessageSource } from '@deepseek-ai/dsh-llm';
11
- import type { SessionId } from '@deepseek-ai/dsh-session';
12
- import type { ActivationObserver } from './lifecycle.ts';
13
- import type { ContinuableCreateRequest, ContinuableCreateSpec, SubagentInterruptAuthority, SubagentActivationSpec, SubagentActivation, SubagentRun, SubagentSendMessageOptions, ResolvedSubagentStartRequest } from './types.ts';
11
+ import type { Session, SessionId } from '@deepseek-ai/dsh-session';
12
+ import type { LifecycleEmitter } from './lifecycle.ts';
13
+ import type { SubagentCatalogEntry, SubagentIdentityProjection } from './projection-types.ts';
14
+ import type { ContinuableCreateRequest, ContinuableCreateSpec, SubagentInterruptAuthority, SubagentActivationSpec, SubagentActivation, SubagentMemberNames, SubagentRun, SubagentSendMessageOptions, ResolvedSubagentStartRequest } from './types.ts';
15
+ import type { SubagentDelivery } from './control-types.ts';
16
+ /** Inputs shared by model steering and human prompt delivery. */
17
+ type ChildDeliveryOptions = {
18
+ readonly delivery: SubagentDelivery;
19
+ readonly source: MessageSource;
20
+ readonly signal: AbortSignal;
21
+ /** Recheck the original model caller at final inbox admission. */
22
+ readonly authorize?: () => void;
23
+ /** Record successful inbox admission before another asynchronous operation can intervene. */
24
+ readonly onAccepted?: () => void;
25
+ };
14
26
  /** Package-private hooks supplied by the owning service. */
15
27
  interface SubagentHost {
16
- startExternal(name: string, request: ResolvedSubagentStartRequest): Promise<SubagentRun>;
17
- /** Resolve one provider's detached continuable-creation contribution. */
18
- prepareContinuable(name: string, request: ContinuableCreateRequest): Promise<ContinuableCreateSpec>;
19
- /** Build the lifecycle observer for one Activation residency epoch. */
20
- observeActivation(provider: string, childId: SessionId, parent: Agent): ActivationObserver;
28
+ /** Read the current descriptor identity through the service-owned projection. */
29
+ identityOf(session: Session): SubagentIdentityProjection | undefined;
30
+ /** Read a live Session's direct-child catalog through the service-owned projection. */
31
+ catalogOf(session: Session): readonly SubagentCatalogEntry[];
32
+ /** Publish lifecycle events through the owning service's scoped dispatcher. */
33
+ readonly emitLifecycle: LifecycleEmitter;
21
34
  }
22
35
  /** Own subagent requests and the resources of every live activation. */
23
36
  export declare class SubagentManager {
@@ -34,99 +47,104 @@ export declare class SubagentManager {
34
47
  private readonly locks;
35
48
  /** Structural Cordis owner of every Activation handle. */
36
49
  private readonly ownerCtx;
37
- /**
38
- * Exact roots whose host teardown has begun, with the live lineage members
39
- * observed under each root. Entries remain until that exact root leaves the
40
- * Agent registry, closing admission throughout its host's teardown without
41
- * poisoning a later same-id replacement.
42
- */
43
- private readonly closingScopes;
50
+ /** Exact subagent tree roots whose host teardown has closed admission. */
51
+ private readonly closingRoots;
52
+ /** Sibling names held by creations that have not committed their catalog entry. */
53
+ private readonly names;
44
54
  private draining;
45
55
  /**
46
56
  * Build one manager inside the service's Agent-injected context.
47
57
  * @param ctx - context providing Agents, Sessions, and teardown ownership.
48
- * @param host - provider dispatch and lifecycle observation owned by the service.
58
+ * @param host - descriptor reads and lifecycle publication owned by the service.
49
59
  * @param maxActiveSubagents - the current configured child capacity.
50
60
  */
51
61
  constructor(ctx: Context, host: SubagentHost, maxActiveSubagents: () => number);
52
62
  /**
53
63
  * Interrupt one live continuable child's current turn under the supplied authority.
54
64
  * @param targetSessionId - the durable child session id to interrupt.
55
- * @param authority - the human parent address or exact live ancestor Agent.
65
+ * @param authority - a trusted user operation or exact live ancestor Agent.
56
66
  */
57
67
  interrupt(targetSessionId: SessionId, authority: SubagentInterruptAuthority): void;
58
68
  /**
59
69
  * Close admission, await every already-admitted materialization through
60
- * publication or rollback, then dispose the stable live Activation graph
61
- * child-first.
70
+ * publication or rollback, then dispose every agent in the subagent tree.
62
71
  */
63
72
  drain(): Promise<void>;
64
73
  /**
65
- * Join progressing child work, leaving idle parked inboxes resident.
66
- * @param parent - exact live parent whose descendants are observed.
67
- * @returns whether work was joined and the host must recheck parent completion.
74
+ * Join progressing subagent tree work for its root, leaving idle parked inboxes resident.
75
+ * @param root - exact live subagent tree root; ordinary members return false.
76
+ * @returns whether work was joined and the host must recheck root completion.
68
77
  */
69
- waitForChildren(parent: Agent): Promise<boolean>;
78
+ waitForTreeWork(root: Agent): Promise<boolean>;
70
79
  /**
71
- * Stop the managed descendants of exact live host-owned parents.
72
- * @param parents - exact live roots whose managed descendants must stop.
80
+ * Stop every member of the selected subagent trees; ordinary members do not close a subagent tree.
81
+ * @param parents - exact live subagent tree roots whose instances must stop.
73
82
  */
74
83
  drainDescendants(parents: readonly Agent[]): Promise<void>;
75
- /**
76
- * Release selected resident direct children of one exact live parent.
77
- * @param parent - exact live direct parent authorizing the selected release.
78
- * @param childIds - durable direct-child ids to release when resident.
79
- */
80
- drainChildren(parent: Agent, childIds: readonly SessionId[]): Promise<void>;
81
84
  /**
82
85
  * Start one continuable background child and resolve at initial inbox acceptance.
83
86
  * Every earlier failure disposes any created handle and rolls back Activation
84
- * and parent ownership without returning either id.
87
+ * and its capacity slot without returning either id.
85
88
  * @param spec - provider, delegation request, and caller cancellation.
89
+ * @param prepare - creation contribution bound to the checked provider.
86
90
  * @returns the durable child id and accepted initial prompt message id.
87
91
  */
88
- startLocal(spec: SubagentActivationSpec): Promise<SubagentActivation & {
92
+ startLocal(spec: SubagentActivationSpec, prepare: (request: ContinuableCreateRequest) => Promise<ContinuableCreateSpec>): Promise<SubagentActivation & {
89
93
  messageId: MessageId;
90
94
  }>;
95
+ /** Create one local child under a name reserved before any await. */
96
+ private startLocalNamed;
91
97
  /**
92
98
  * Start an external backend under activation ownership.
93
99
  * @param spec - task, provider, cancellation, and delivery policy.
100
+ * @param start - execution bound to the checked provider.
94
101
  * @returns the accepted activation and its result/disposal capabilities.
95
102
  */
96
- startExternal(spec: SubagentActivationSpec): Promise<SubagentActivation>;
103
+ startExternal(spec: SubagentActivationSpec, start: (request: ResolvedSubagentStartRequest) => Promise<SubagentRun>): Promise<SubagentActivation>;
104
+ /** Start one external execution, cataloging parent-delivered runs under their reserved name. */
105
+ private startExternalNamed;
97
106
  /** Capture the explicit or inherited directory while the parent still owns startup. */
98
107
  private resolveDirectory;
99
108
  /**
100
- * Deliver one model-authored message to a direct continuable child or to the
101
- * sender's direct parent. A missing direct child cold-resumes through the
102
- * ordinary continuation lifecycle.
103
- * @param sender - exact live Agent authorizing and originating the message.
104
- * @param targetId - durable direct-parent or direct-child session id.
105
- * @param content - model-authored content to deliver.
106
- * @param options - caller cancellation before acceptance.
107
- * @returns the accepted message's inbox id.
109
+ * Resolve the live subagent tree root from runtime ownership, independent of creator residency.
110
+ * @param caller - exact live Agent selecting the subagent tree.
111
+ * @returns the live subagent tree root.
112
+ * @throws when the caller has no active runtime owner.
113
+ */
114
+ rootOf(caller: Agent): Agent;
115
+ /** Capture creation ancestry separately from the root that owns the new instance. */
116
+ private ancestryForChild;
117
+ /** Claim a sibling name against the creator's committed catalog and in-flight siblings. */
118
+ private reserveName;
119
+ /** Path of an exact live tree member: `''` for the root, undefined for unnamed history. */
120
+ private pathOf;
121
+ /**
122
+ * Report the model-facing names of a live member and its direct creator.
123
+ * @param agent - exact live root or resident tree member.
124
+ * @returns `lead` for the root, otherwise the member's and creator's names or Session ids.
125
+ * @throws when the caller has no active runtime owner.
126
+ */
127
+ namesOf(agent: Agent): SubagentMemberNames;
128
+ /**
129
+ * Deliver to another agent in the subagent tree, restoring only the target when absent.
130
+ * @param sender - exact live root or resident continuable Agent.
131
+ * @param targetId - another member's durable Session id.
132
+ * @param content - model-authored message blocks.
133
+ * @param options - cancellation before inbox acceptance.
134
+ * @returns the accepted inbox message id.
108
135
  */
109
136
  sendMessage(sender: Agent, targetId: SessionId, content: ContentBlock[], options: SubagentSendMessageOptions): Promise<MessageId>;
137
+ /** Resolve the live owner through verified creation edges without activating ancestors. */
138
+ private resolveCreationAncestry;
110
139
  /**
111
- * Queue one human-authored prompt as a distinct direct-child turn.
112
- * @param parent - exact live direct parent authorizing delivery.
113
- * @param childId - durable direct-child session id.
114
- * @param content - model-visible prompt blocks.
115
- * @param source - durable attribution for the human prompt.
116
- * @param signal - caller cancellation before inbox acceptance.
117
- * @returns the accepted durable message id.
118
- */
119
- queuePrompt(parent: Agent, childId: SessionId, content: ContentBlock[], source: MessageSource, signal: AbortSignal): Promise<MessageId>;
120
- /**
121
- * Steer one host-authored prompt to a direct continuable child.
122
- * @param parent - exact live direct parent authorizing delivery.
123
- * @param childId - durable direct-child session id.
140
+ * Deliver one host-authored prompt through the target's live subagent tree root.
141
+ * Remote callers must be authorized for the target Session before invoking this operation.
142
+ * @param childId - durable continuable subagent session id.
124
143
  * @param content - model-visible prompt blocks.
125
- * @param source - durable attribution for the host prompt.
126
- * @param signal - caller cancellation before inbox acceptance.
144
+ * @param options - inbox destination, durable attribution, and cancellation before acceptance.
127
145
  * @returns the accepted durable message id.
128
146
  */
129
- steerPrompt(parent: Agent, childId: SessionId, content: ContentBlock[], source: MessageSource, signal: AbortSignal): Promise<MessageId>;
147
+ deliverPrompt(childId: SessionId, content: ContentBlock[], options: Pick<ChildDeliveryOptions, 'delivery' | 'source' | 'signal'>): Promise<MessageId>;
130
148
  /** Admit local input synchronously before any teardown can begin. */
131
149
  private deliver;
132
150
  /**
@@ -134,17 +152,6 @@ export declare class SubagentManager {
134
152
  * @param childId - proposed durable child session id.
135
153
  */
136
154
  private assertChildIdAvailable;
137
- /**
138
- * Pre-register `childId` in a continuation-managed parent's owned set so the
139
- * parent cannot settle while a caller is still establishing or resuming that
140
- * child. Returns a releaser for the failure path; it removes only a hold
141
- * this call added, and leaves ownership in place once a live Activation for
142
- * the child exists.
143
- * @param parent - the live direct parent the operation is admitted under.
144
- * @param childId - the durable child the operation addresses.
145
- * @returns the failure-path releaser; a no-op when nothing was added.
146
- */
147
- private holdOwnership;
148
155
  /**
149
156
  * Apply activation admission to a resident parent before delivering input.
150
157
  * @param parent - exact live Agent receiving the message.
@@ -153,25 +160,18 @@ export declare class SubagentManager {
153
160
  */
154
161
  private sendWaking;
155
162
  /**
156
- * Reject new admission once the manager or this exact parent tree began draining.
157
- * @param agent - exact live Agent whose lineage determines admission.
163
+ * Reject new work from closing members or subagent trees.
164
+ * @param agent - exact live caller whose instance and subagent tree must admit work.
158
165
  */
159
166
  private assertAdmitting;
160
- /**
161
- * Authorize one operation against the durable direct-parent lineage.
162
- * @param parent - exact live Agent claiming direct-parent authority.
163
- * @param childId - durable child session id addressed by the operation.
164
- * @param parentSession - durable direct-parent id recorded by the child.
165
- */
166
- private authorizeLineage;
167
- /** Reject parent authority after the live registry entry changes. */
168
- private assertLiveParent;
169
167
  /**
170
168
  * Create or resume one child Agent and publish its Activation.
171
169
  * @param inputs - reconstruction and admission inputs for the residency epoch.
172
170
  * @returns the published process-local Activation.
173
171
  */
174
172
  private materialize;
173
+ /** Keep subagent tree shutdown and host waits joined to preparation, publication, and rollback. */
174
+ private trackStartup;
175
175
  /**
176
176
  * Stop and release one Activation through its memoized close transaction.
177
177
  * @param activation - exact residency epoch to close.
@@ -182,36 +182,27 @@ export declare class SubagentManager {
182
182
  private close;
183
183
  /** Dispose independent roots and report every branch failure after all settle. */
184
184
  private disposeRoots;
185
- /** Return the retained member set for one exact scoped-teardown root. */
186
- private closingMembers;
187
- /** Return the exact currently resolvable ancestry from `agent` upward. */
188
- private liveLineage;
189
- /** Return the teardown that closed continuable admission for this agent's lineage. */
185
+ /** Return the subagent tree teardown that closed admission for this exact Agent. */
190
186
  private closingTeardownFor;
191
- /** Resolve a root's pool once; descendants inherit their resident parent's pool directly. */
187
+ /** Share one capacity pool across every instance in a subagent tree. */
192
188
  private rootPool;
193
189
  /** Perform one tracked materialization through publication or rollback. */
194
190
  private materializeTracked;
195
- /**
196
- * Begin settlement observation after initial acceptance is recorded.
197
- * @param activation - accepted activation to observe.
198
- */
199
- private announce;
191
+ /** Identity shared by one residency epoch's start/end pair, including cold resumes. */
192
+ private runInfo;
193
+ /** Record acceptance and begin settlement observation before returning the receipt. */
194
+ private accept;
200
195
  /** Release an Activation whose start edge was not published. */
201
196
  private rollbackUnpublished;
202
- /** Register the child in a continuation-managed parent's owned set. */
203
- private acquireOwnership;
204
- /** Remove one child from its live owner's set and let that owner re-check settlement. */
205
- private releaseOwnership;
206
197
  /** Let a settlement watcher re-check residency after relevant state changes. */
207
198
  private wake;
208
199
  /** Follow one Activation to natural settlement. */
209
200
  private watchLocalSettlement;
210
201
  /** Report disposal failure once after the natural settlement observer finishes. */
211
202
  private reportTeardownFailure;
212
- /** Check pending input and owned children before closing admission. */
203
+ /** Check pending input before closing admission. */
213
204
  private settlementState;
214
- /** Propagate stop synchronously and await descendant startup rollback before release. */
205
+ /** Stop and release one instance without affecting its creation descendants. */
215
206
  private finishDisposal;
216
207
  /** Deliver the captured execution result to the durable direct parent after cleanup. */
217
208
  private notifySettlement;
@@ -219,19 +210,12 @@ export declare class SubagentManager {
219
210
  private flushFinalState;
220
211
  /** Return capabilities bound to an exact activation instead of a future same-id instance. */
221
212
  private receipt;
222
- /** Route one parent-originated delivery through residency and cold resume. */
223
- private deliverToChild;
224
- /** The delivery loop behind {@link deliverToChild}, run under the parent hold. */
225
- private deliverFollowup;
226
- /** Deliver one resident continuable child's message to its live direct parent. */
227
- private sendToParent;
228
- /** Send one Agent message while translating only the target's own rejection. */
229
- private sendAgentMessage;
230
- /**
231
- * Cold-resume a persisted child and submit the waiting turn. The descriptor
232
- * supplies every reconstruction input; no subagent provider is dispatched.
233
- */
234
- private coldResume;
213
+ /** Serialize target restoration and inbox admission; closure is awaited outside the lock. */
214
+ private deliverToMember;
215
+ /** Read continuation history, preserving cancellation and reporting unavailable storage. */
216
+ private observeContinuation;
217
+ /** Reconstruct only the target under its subagent tree root; the caller owns acceptance or rollback. */
218
+ private restoreTarget;
235
219
  /** Admit a materialized child, commit its creation fact, and release it on failure. */
236
220
  private submitMaterialized;
237
221
  /** Build and submit one message across the final synchronous admission cutoff. */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAoC,MAAM,w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