@deepseek-ai/dsh-subagent 0.2.0-rc.2 → 0.2.1-alpha.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 (44) hide show
  1. package/README.i18n.yaml +36 -36
  2. package/README.md +33 -27
  3. package/README.zh.md +33 -27
  4. package/lib/index.js +1436 -1304
  5. package/lib/typert.host.js +73 -60
  6. package/lib/typert.remote-client.js +2 -2
  7. package/lib/types/activation.d.ts +114 -0
  8. package/lib/types/activation.js +112 -0
  9. package/lib/types/catalog.d.ts +14 -6
  10. package/lib/types/catalog.js +34 -30
  11. package/lib/types/child-agent.d.ts +1 -3
  12. package/lib/types/child-agent.js +1 -3
  13. package/lib/types/continuation-messages.d.ts +4 -3
  14. package/lib/types/continuation-messages.js +13 -5
  15. package/lib/types/control-types.d.ts +7 -0
  16. package/lib/types/descriptor.d.ts +7 -46
  17. package/lib/types/descriptor.js +20 -21
  18. package/lib/types/index.d.ts +52 -53
  19. package/lib/types/index.js +75 -95
  20. package/lib/types/internal.d.ts +1 -1
  21. package/lib/types/lifecycle.d.ts +28 -58
  22. package/lib/types/lifecycle.js +9 -74
  23. package/lib/types/list-children.js +1 -1
  24. package/lib/types/manager.d.ts +247 -0
  25. package/lib/types/manager.js +1294 -0
  26. package/lib/types/out-of-process.d.ts +2 -28
  27. package/lib/types/out-of-process.js +3 -44
  28. package/lib/types/projection-types.d.ts +3 -0
  29. package/lib/types/structured.d.ts +49 -0
  30. package/lib/types/structured.js +130 -0
  31. package/lib/types/types.d.ts +57 -81
  32. package/lib/types/types.js +1 -1
  33. package/package.json +53 -63
  34. package/lib/invariant.js +0 -76
  35. package/lib/types/continuation-activation.d.ts +0 -267
  36. package/lib/types/continuation-activation.js +0 -700
  37. package/lib/types/continuation.d.ts +0 -124
  38. package/lib/types/continuation.js +0 -455
  39. package/lib/types/inbox.d.ts +0 -43
  40. package/lib/types/inbox.js +0 -61
  41. package/lib/types/invariant.d.ts +0 -13
  42. package/lib/types/invariant.js +0 -91
  43. package/lib/types/run-settlement.d.ts +0 -17
  44. package/lib/types/run-settlement.js +0 -70
@@ -2,8 +2,7 @@
2
2
  * Provider-side vocabulary for OUT-OF-PROCESS subagent backends — the pieces
3
3
  * that enforce this seam's own contracts around a child in another process:
4
4
  * the no-capabilities advertisement, timing-bound validation, child
5
- * working-directory resolution (config override, else the delegating parent
6
- * session's workspace), the never-reject result settlement, and the standard
5
+ * working-directory validation, the never-reject result settlement, and the standard
7
6
  * run-handle publication. Backends compose these with their own wire drivers;
8
7
  * the process machinery itself (spawn, env scrub, managed-range teardown)
9
8
  * belongs to the `dsh-subprocess` seam.
@@ -38,31 +37,6 @@ export declare function assertPositiveFinite(prefix: string, name: string, value
38
37
  * @returns `cwd`, validated.
39
38
  */
40
39
  export declare function assertUsableCwd(prefix: string, label: string, cwd: string): string;
41
- /**
42
- * Validate a configured `cwd` override ONCE, at plugin load: reject the empty
43
- * string (`path.resolve('')` is the process cwd — it would silently
44
- * reintroduce the launch-directory fallback this resolution removes),
45
- * interpret a relative path against the harness launch directory, and require
46
- * an enterable directory.
47
- * @param prefix - the consuming plugin's diagnostic prefix.
48
- * @param cwd - the configured override, or `undefined` when the config omits it.
49
- * @returns the validated absolute override, or `undefined` when omitted.
50
- */
51
- export declare function validateConfiguredCwd(prefix: string, cwd: string | undefined): string | undefined;
52
- /**
53
- * Resolve the child's working directory at start: the deployment override
54
- * when configured (already validated at load), else the parent session's
55
- * workspace cwd (validated here, its earliest resolvable point). Fails loud
56
- * when neither exists — falling back to the harness process cwd would
57
- * silently bind the child to the server's launch directory instead of the
58
- * delegating session's workspace (one server process serves many sessions,
59
- * each with its own cwd).
60
- * @param prefix - the consuming plugin's diagnostic prefix.
61
- * @param configured - the load-validated override, or `undefined`.
62
- * @param parentCwd - the delegating parent session's workspace cwd, if any.
63
- * @returns the absolute child working directory.
64
- */
65
- export declare function resolveChildCwd(prefix: string, configured: string | undefined, parentCwd: string | undefined): string;
66
40
  /** Inputs to {@link settleRunResult}. */
67
41
  export interface RunResultSettlement {
68
42
  /** The turn attempt (typically racing local cancellation); returns the terminal result. */
@@ -112,7 +86,7 @@ export interface SubprocessRunHandleParts {
112
86
  * local cancellation — there is no assumption the child cooperates — and then
113
87
  * awaits the backend's teardown to actual exit.
114
88
  * @param parts - the run identity, result, cancellation wiring, and teardown.
115
- * @returns the seam run handle (`localAgent` is `undefined` for remote runs).
89
+ * @returns the external run handle.
116
90
  */
117
91
  export declare function subprocessRunHandle(parts: SubprocessRunHandleParts): SubagentRun;
118
92
  //# sourceMappingURL=out-of-process.d.ts.map
@@ -2,8 +2,7 @@
2
2
  * Provider-side vocabulary for OUT-OF-PROCESS subagent backends — the pieces
3
3
  * that enforce this seam's own contracts around a child in another process:
4
4
  * the no-capabilities advertisement, timing-bound validation, child
5
- * working-directory resolution (config override, else the delegating parent
6
- * session's workspace), the never-reject result settlement, and the standard
5
+ * working-directory validation, the never-reject result settlement, and the standard
7
6
  * run-handle publication. Backends compose these with their own wire drivers;
8
7
  * the process machinery itself (spawn, env scrub, managed-range teardown)
9
8
  * belongs to the `dsh-subprocess` seam.
@@ -11,7 +10,7 @@
11
10
  * @module @deepseek-ai/dsh-subagent/out-of-process
12
11
  */
13
12
  import { accessSync, constants, statSync } from 'node:fs';
14
- import { isAbsolute, resolve } from 'node:path';
13
+ import { isAbsolute } from 'node:path';
15
14
  /** Maximum UTF-8 size of {@link SubagentResult.diagnostic}. */
16
15
  const MAX_SUBAGENT_DIAGNOSTIC_BYTES = 4_096;
17
16
  const DIAGNOSTIC_TRUNCATION_SUFFIX = '\n[diagnostic truncated]';
@@ -103,45 +102,6 @@ export function assertUsableCwd(prefix, label, cwd) {
103
102
  }
104
103
  return cwd;
105
104
  }
106
- /**
107
- * Validate a configured `cwd` override ONCE, at plugin load: reject the empty
108
- * string (`path.resolve('')` is the process cwd — it would silently
109
- * reintroduce the launch-directory fallback this resolution removes),
110
- * interpret a relative path against the harness launch directory, and require
111
- * an enterable directory.
112
- * @param prefix - the consuming plugin's diagnostic prefix.
113
- * @param cwd - the configured override, or `undefined` when the config omits it.
114
- * @returns the validated absolute override, or `undefined` when omitted.
115
- */
116
- export function validateConfiguredCwd(prefix, cwd) {
117
- if (cwd === undefined)
118
- return undefined;
119
- if (cwd === '') {
120
- throw new Error(`${prefix}: config cwd must not be empty — omit the key to inherit the parent session cwd`);
121
- }
122
- return assertUsableCwd(prefix, 'config cwd', resolve(cwd));
123
- }
124
- /**
125
- * Resolve the child's working directory at start: the deployment override
126
- * when configured (already validated at load), else the parent session's
127
- * workspace cwd (validated here, its earliest resolvable point). Fails loud
128
- * when neither exists — falling back to the harness process cwd would
129
- * silently bind the child to the server's launch directory instead of the
130
- * delegating session's workspace (one server process serves many sessions,
131
- * each with its own cwd).
132
- * @param prefix - the consuming plugin's diagnostic prefix.
133
- * @param configured - the load-validated override, or `undefined`.
134
- * @param parentCwd - the delegating parent session's workspace cwd, if any.
135
- * @returns the absolute child working directory.
136
- */
137
- export function resolveChildCwd(prefix, configured, parentCwd) {
138
- if (configured !== undefined)
139
- return configured;
140
- if (parentCwd === undefined) {
141
- throw new Error(`${prefix}: no working directory for the child — configure \`cwd\` or delegate from a parent session that has one`);
142
- }
143
- return assertUsableCwd(prefix, 'parent session cwd', parentCwd);
144
- }
145
105
  /** Normalize an unknown thrown value to an Error (the catch binding is `unknown`). */
146
106
  function toError(value) {
147
107
  // The rejecting surfaces (wire clients, spawn failures) only throw
@@ -198,13 +158,12 @@ export async function settleRunResult(parts) {
198
158
  * local cancellation — there is no assumption the child cooperates — and then
199
159
  * awaits the backend's teardown to actual exit.
200
160
  * @param parts - the run identity, result, cancellation wiring, and teardown.
201
- * @returns the seam run handle (`localAgent` is `undefined` for remote runs).
161
+ * @returns the external run handle.
202
162
  */
203
163
  export function subprocessRunHandle(parts) {
204
164
  let disposal;
205
165
  return {
206
166
  id: parts.id,
207
- localAgent: undefined,
208
167
  result: parts.result,
209
168
  dispose() {
210
169
  if (disposal !== undefined)
@@ -11,6 +11,9 @@ export type SubagentCatalogEntry = {
11
11
  } & ({
12
12
  readonly mode: 'one-shot';
13
13
  readonly label?: string;
14
+ } | {
15
+ readonly mode: 'external';
16
+ readonly label?: string;
14
17
  } | {
15
18
  readonly mode: 'continuable';
16
19
  readonly label: string;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Child-scoped structured-output tool, prompt instruction, terminal guard, and authoritative
3
+ * result capture for in-process subagents. Each child registers its real schema on its own
4
+ * scope, so concurrent runs do not interact and disposal leaves no global residue. The prompt
5
+ * contribution is ordinary reconstructed request state.
6
+ *
7
+ * Capture commits only after the authoritative `tools/result` succeeds; PTC mode capture also
8
+ * waits for the enclosing `run_code` result. The terminal result marker and monotonic tool
9
+ * guard prevent later calls from reopening a completed structured run.
10
+ * @module @deepseek-ai/dsh-subagent/structured
11
+ */
12
+ import type { Context } from '@deepseek-ai/cordis';
13
+ import { type ObjectJsonSchema } from '@deepseek-ai/dsh-tools';
14
+ /** The model-facing tool name a structured child must call to finish. */
15
+ export declare const STRUCTURED_OUTPUT_TOOL = "structured_output";
16
+ /**
17
+ * The instruction registered as the child's trailing scoped prompt section:
18
+ * the demand travels with the
19
+ * tool, as ordinary prompt state of exactly one agent.
20
+ */
21
+ export declare const STRUCTURED_OUTPUT_INSTRUCTION: string;
22
+ /** One structured run's live handle: read the captured value once the child settles. */
23
+ export interface StructuredAttachment {
24
+ /**
25
+ * Input stays closed from capture staging through its final result, including
26
+ * an enclosing PTC execution. A failed result discards its capture and reopens input.
27
+ * @returns whether the activation can accept another message.
28
+ */
29
+ acceptsInput(): boolean;
30
+ /**
31
+ * The captured value, once the child called the tool with valid arguments
32
+ * and the authoritative final tool result accepted that call.
33
+ * @returns the committed value, or undefined while none was accepted.
34
+ */
35
+ captured(): {
36
+ value: unknown;
37
+ } | undefined;
38
+ }
39
+ /**
40
+ * Attach the scoped capture tool, instruction, and enforcement to a child during
41
+ * its creation window. Child disposal removes every registration.
42
+ * @param childCtx - the child agent's scope context (`setup`'s argument).
43
+ * @param schema - the trusted, already-asserted schema subset to enforce (see
44
+ * `assertObjectJsonSchema` in dsh-tools).
45
+ * @param canComplete - whether accepted input and owned child work have finished.
46
+ * @returns the attachment handle (read `captured()` after the child settles).
47
+ */
48
+ export declare function attachStructuredRuntime(childCtx: Context, schema: ObjectJsonSchema, canComplete: () => boolean): StructuredAttachment;
49
+ //# sourceMappingURL=structured.d.ts.map
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Child-scoped structured-output tool, prompt instruction, terminal guard, and authoritative
3
+ * result capture for in-process subagents. Each child registers its real schema on its own
4
+ * scope, so concurrent runs do not interact and disposal leaves no global residue. The prompt
5
+ * contribution is ordinary reconstructed request state.
6
+ *
7
+ * Capture commits only after the authoritative `tools/result` succeeds; PTC mode capture also
8
+ * waits for the enclosing `run_code` result. The terminal result marker and monotonic tool
9
+ * guard prevent later calls from reopening a completed structured run.
10
+ * @module @deepseek-ai/dsh-subagent/structured
11
+ */
12
+ import { ToolArgsError, validateJsonSchemaValue } from '@deepseek-ai/dsh-tools';
13
+ /** The model-facing tool name a structured child must call to finish. */
14
+ export const STRUCTURED_OUTPUT_TOOL = 'structured_output';
15
+ /**
16
+ * The instruction registered as the child's trailing scoped prompt section:
17
+ * the demand travels with the
18
+ * tool, as ordinary prompt state of exactly one agent.
19
+ */
20
+ export const STRUCTURED_OUTPUT_INSTRUCTION = 'When you have your final answer, you MUST report it by calling the '
21
+ + `\`${STRUCTURED_OUTPUT_TOOL}\` tool with arguments matching its parameter schema exactly. `
22
+ + 'Do not finish with a plain text answer: only the tool call counts as your result.';
23
+ /**
24
+ * Attach the scoped capture tool, instruction, and enforcement to a child during
25
+ * its creation window. Child disposal removes every registration.
26
+ * @param childCtx - the child agent's scope context (`setup`'s argument).
27
+ * @param schema - the trusted, already-asserted schema subset to enforce (see
28
+ * `assertObjectJsonSchema` in dsh-tools).
29
+ * @param canComplete - whether accepted input and owned child work have finished.
30
+ * @returns the attachment handle (read `captured()` after the child settles).
31
+ */
32
+ export function attachStructuredRuntime(childCtx, schema, canComplete) {
33
+ /**
34
+ * Validated values staged by the capture tool body, awaiting THEIR OWN
35
+ * authoritative `tools/result` notification. The execution object's identity
36
+ * uniquely identifies a trip through the pipeline: adapter call ids may
37
+ * repeat across steps, but another execution can never reach this Map
38
+ * entry. This is distinct from the opaque `ToolExecutionToken` used to
39
+ * correlate nested transports. The final notification always deletes its own
40
+ * stage, whether the result succeeded or failed.
41
+ */
42
+ const staged = new Map();
43
+ /** Successful nested capture waiting for its enclosing transport to commit. */
44
+ let pending;
45
+ let captured;
46
+ const schemaEntry = {
47
+ name: STRUCTURED_OUTPUT_TOOL,
48
+ description: 'Report your final structured result. Call this exactly once, when your answer is complete; '
49
+ + 'the arguments must match this tool\'s parameter schema exactly.',
50
+ parameters: { ...schema },
51
+ };
52
+ childCtx.tools.register({
53
+ ...schemaEntry,
54
+ output: {
55
+ schema: {
56
+ type: 'object',
57
+ properties: { recorded: { type: 'boolean', const: true } },
58
+ required: ['recorded'],
59
+ additionalProperties: false,
60
+ },
61
+ render: () => [{ type: 'text', text: 'Structured output recorded.' }],
62
+ },
63
+ execute(args, exec) {
64
+ const violations = validateJsonSchemaValue(schema, args);
65
+ // ToolArgsError → isError result with INVALID_ARGS: the model retries
66
+ // within the same turn, exactly like a schema-validated defineTool call.
67
+ if (violations.length > 0)
68
+ throw new ToolArgsError(violations);
69
+ if (!canComplete())
70
+ throw new Error('Wait for all delegated child tasks to finish and process pending messages before submitting structured output.');
71
+ // Two-phase commit, keyed by THIS execution: later transformable
72
+ // waterfalls may still turn the success into an error. ToolRuntime has
73
+ // already frozen model-bound arguments at the actual input boundary.
74
+ staged.set(exec, { value: args });
75
+ exec.concludeTurn();
76
+ return Promise.resolve({ recorded: true });
77
+ },
78
+ });
79
+ childCtx.systemPrompt.section({
80
+ name: `tool:${STRUCTURED_OUTPUT_TOOL}`,
81
+ order: childCtx.systemPrompt.getSectionOrder('STRUCTURED_OUTPUT'),
82
+ text: STRUCTURED_OUTPUT_INSTRUCTION,
83
+ });
84
+ // Terminal WITHIN the step. Guards run after the whole pre-execute
85
+ // waterfall and compose monotonically (deny or abstain, never allow), so a
86
+ // later prepended listener cannot resurrect dispatch. Calls that precede
87
+ // capture in the same response remain untouched.
88
+ childCtx.tools.guard(exec => captured === undefined && pending === undefined
89
+ ? undefined
90
+ : `structured output already recorded: the run is complete, so \`${exec.name}\` is not executed`);
91
+ // The capture COMMIT observes the immutable, authoritative result after the
92
+ // complete pipeline and outer error normalization. This notification cannot
93
+ // transform the outcome, so there is no wrapper outside the commit verdict.
94
+ childCtx.on('tools/result', function (exec, result) {
95
+ if (exec.name === STRUCTURED_OUTPUT_TOOL) {
96
+ const entry = staged.get(exec);
97
+ if (entry === undefined)
98
+ return;
99
+ staged.delete(exec);
100
+ if (result.isError)
101
+ return;
102
+ if (exec.parent === undefined) {
103
+ /* v8 ignore else -- sequential agent-loop dispatch lets the guard block every later supported call */
104
+ if (captured === undefined)
105
+ captured = { value: entry.value };
106
+ }
107
+ else {
108
+ /* v8 ignore else -- PTC mode serializes sub-dispatches, so the guard blocks every later supported call */
109
+ if (captured === undefined && pending === undefined) {
110
+ pending = { parent: exec.parent, value: entry.value };
111
+ }
112
+ }
113
+ return;
114
+ }
115
+ if (pending?.parent !== exec.token)
116
+ return;
117
+ const entry = pending;
118
+ pending = undefined;
119
+ if (result.isError)
120
+ return;
121
+ /* v8 ignore else -- PTC mode serializes outer executions, so the guard blocks every later supported call */
122
+ if (captured === undefined)
123
+ captured = { value: entry.value };
124
+ });
125
+ return {
126
+ captured: () => captured,
127
+ acceptsInput: () => staged.size === 0 && pending === undefined && captured === undefined,
128
+ };
129
+ }
130
+ //# sourceMappingURL=structured.js.map
@@ -3,7 +3,7 @@
3
3
  * for {@link SubagentProvider}, plus the `subagent/start` and `subagent/end`
4
4
  * payloads that plugins and hosts observe. Internal control interfaces belong
5
5
  * with their implementation — the lifecycle observer in `./lifecycle.ts`, the
6
- * continuation host in `./continuation.ts` — so this module stays the published
6
+ * manager host in `./manager.ts` — so this module stays the published
7
7
  * surface rather than a bag of everything type-shaped.
8
8
  *
9
9
  * @module @deepseek-ai/dsh-subagent/types
@@ -13,7 +13,6 @@ import type { Branded } from '@deepseek-ai/dsh-brand';
13
13
  import type { ContentBlock, MessageId } from '@deepseek-ai/dsh-llm';
14
14
  import type { SessionEvent, SessionId } from '@deepseek-ai/dsh-session';
15
15
  import type { ObjectJsonSchema, ToolRestriction } from '@deepseek-ai/dsh-tools';
16
- import type { SubagentDescriptorData } from './descriptor.ts';
17
16
  /** Identifies one accepted subagent run across its lifecycle event pair. */
18
17
  export type SubagentRunId = Branded<'SubagentRunId'>;
19
18
  /**
@@ -22,32 +21,34 @@ export type SubagentRunId = Branded<'SubagentRunId'>;
22
21
  * @returns the same string, branded.
23
22
  */
24
23
  export declare function SubagentRunId(id: string): SubagentRunId;
25
- /** What a caller asks for when starting a continuable background child. */
26
- export interface ContinuableStartSpec {
27
- /** The `ctx.subagents` provider whose continuable-creation capability establishes the child. */
24
+ /** One managed child execution and its result delivery policy. */
25
+ export interface SubagentActivationSpec {
26
+ /** Registered backend to use. */
28
27
  readonly provider: string;
29
- /** The initial delegation's short `description`, persisted as the child's creation label. */
28
+ /** Short task label retained in cataloged child membership. */
30
29
  readonly label: string;
31
- /**
32
- * Optional caller-reserved child identity. Omission preserves the manager's
33
- * UUID allocation; supplying one lets a durable parent record provisioning
34
- * before child materialization without a second identity handshake.
35
- */
30
+ /** Optional reserved identity for a local child; external backends allocate their own ids. */
36
31
  readonly childId?: SessionId;
37
- /**
38
- * The delegation request. The manager reserves the stable child id, resolves
39
- * the durable descriptor, and composes the child itself.
40
- */
41
- readonly request: Omit<SubagentStartRequest, 'label' | 'signal' | 'outputSchema'>;
42
- /** Caller cancellation, owning the operation only until inbox acceptance. */
32
+ /** Task, parent, and backend-supported execution options. */
33
+ readonly request: Omit<SubagentStartRequest, 'label' | 'signal'>;
34
+ /** Cancellation before publication; callers own later cancellation through dispose. */
43
35
  readonly signal: AbortSignal;
36
+ /** Parent delivery notifies the model; caller delivery only returns the result. Local children always enter the parent catalog. */
37
+ readonly delivery: 'parent' | 'caller';
44
38
  }
45
- /** Identities returned once a continuable child accepted its initial prompt. */
46
- export interface ContinuableStart {
47
- /** The durable child session id, stable across activations. */
39
+ /** A managed execution; disposal addresses this exact activation, never a later resume. */
40
+ export interface SubagentActivation {
41
+ /** Stable identity of the child. */
48
42
  readonly childId: SessionId;
49
- /** The accepted initial prompt's inbox message id. */
50
- readonly messageId: MessageId;
43
+ /** Accepted inbox message, when the backend has a local inbox. */
44
+ readonly messageId?: MessageId;
45
+ /**
46
+ * Execution result after teardown settles and notifications are sent; capture failures reject.
47
+ * Teardown failures are reported by dispose() without replacing a captured result.
48
+ */
49
+ readonly result: Promise<SubagentResult>;
50
+ /** Stop and release this activation and its owned descendants; rejects on teardown failure. */
51
+ dispose(): Promise<void>;
51
52
  }
52
53
  /**
53
54
  * Authority under which one interrupt request is admitted. `user` carries the
@@ -68,22 +69,19 @@ export interface SubagentSendMessageOptions {
68
69
  }
69
70
  /**
70
71
  * Observe-only identifying detail for a published subagent run, carried by
71
- * `subagent/start`. One-shot runs and continuable Activation epochs share this
72
- * payload, so an observer sees the same vocabulary for both.
72
+ * `subagent/start`. Local and external activations share this payload.
73
73
  */
74
74
  export interface SubagentRunInfo {
75
75
  /** Unique identity shared with the paired terminal event. */
76
76
  readonly runId: SubagentRunId;
77
77
  /**
78
- * Provider name recorded when the child was first created. The provider may
79
- * be absent when an accepted one-shot run becomes ready or a persisted
80
- * Activation cold-resumes, because neither lifecycle depends on continued
81
- * registration.
78
+ * Provider name recorded when the child was first created, retained even
79
+ * after that provider is unregistered.
82
80
  */
83
81
  readonly provider: string;
84
82
  /** The child agent's id. */
85
83
  readonly id: SessionId;
86
- /** Snapshot of whether `SubagentRun.localAgent` was present when start fulfilled. */
84
+ /** Whether this activation owns a local Agent, fixed at publication. */
87
85
  readonly local: boolean;
88
86
  }
89
87
  /**
@@ -97,7 +95,7 @@ export interface SubagentRunEndInfo {
97
95
  readonly provider: string;
98
96
  /** The child agent's id. */
99
97
  readonly id: SessionId;
100
- /** Snapshot of whether `SubagentRun.localAgent` was present when start fulfilled. */
98
+ /** Whether this activation owns a local Agent, fixed at publication. */
101
99
  readonly local: boolean;
102
100
  /** The terminal stop reason. */
103
101
  readonly stopReason: SubagentResult['stopReason'];
@@ -109,15 +107,10 @@ export interface SubagentRunEndInfo {
109
107
  readonly lastAssistantMessage?: readonly ContentBlock[];
110
108
  }
111
109
  /**
112
- * Which START-TIME features a provider supports. Checked by the service before delegating to
113
- * {@link SubagentProvider.start}: a request that needs a capability the chosen provider lacks
114
- * is rejected with a typed error rather than accepted-then-ignored (the "fail loud, no silent
115
- * degradation" rule). These flags describe the ONE-SHOT
116
- * {@link SubagentProvider.start} path, where the provider composes the child;
117
- * continuable children are composed by the continuation manager itself and are
118
- * gated by {@link SubagentProvider.prepareContinuable} instead. Each flag
119
- * corresponds one-to-one to a {@link SubagentStartRequest} option: `depthLimit`
120
- * to `maxDepth`; the other names match.
110
+ * Start-time options supported by a registered backend. The manager checks
111
+ * every requested option before preparing a local child or starting an external
112
+ * execution. depthLimit controls maxDepth; the remaining flag names match
113
+ * SubagentStartRequest fields.
121
114
  */
122
115
  export interface SubagentCapabilities {
123
116
  readonly agentOptions: boolean;
@@ -127,21 +120,20 @@ export interface SubagentCapabilities {
127
120
  readonly persona: boolean;
128
121
  }
129
122
  /**
130
- * What a caller asks for when starting a ONE-SHOT subagent. The tool layer
131
- * builds this from the model's `{ description, prompt }` plus its own config;
132
- * the service validates {@link SubagentCapabilities} against the named provider
133
- * and resolves the durable descriptor before dispatching to
134
- * {@link SubagentProvider.start}.
123
+ * Task and optional capabilities supplied to a backend. startActivation carries
124
+ * these fields in request while owning its label, cancellation, and delivery
125
+ * policy separately.
135
126
  */
136
127
  export interface SubagentStartRequest {
128
+ /** Initial child directory; relative paths resolve against the parent's current directory. Omitted inherits that directory at start. */
129
+ readonly cwd?: string;
137
130
  /** Optional short display label persisted with a session-backed child. */
138
131
  readonly label?: string;
139
132
  /** Content delivered as the child's user message. */
140
133
  readonly prompt: ContentBlock[];
141
134
  /**
142
- * The spawning agent. In-process providers derive workspace, lineage, and
143
- * delegation depth from its durable session state. ACP reads only its cwd,
144
- * and only when no deployment `cwd` override is configured.
135
+ * The spawning agent. Its effective directory supplies the default cwd;
136
+ * in-process children retain its origin, lineage, and delegation depth.
145
137
  */
146
138
  readonly parent: Agent;
147
139
  /**
@@ -190,13 +182,10 @@ export interface SubagentStartRequest {
190
182
  */
191
183
  readonly persona?: string;
192
184
  }
193
- /**
194
- * Provider-facing one-shot request after {@link SubagentRuntime.start} resolves
195
- * the durable child descriptor.
196
- */
185
+ /** Provider-facing request with an absolute directory selected before startup. */
197
186
  export interface ResolvedSubagentStartRequest extends SubagentStartRequest {
198
- /** Detached descriptor a session-backed provider persists in the child log. */
199
- readonly descriptor: SubagentDescriptorData;
187
+ /** Absolute child directory captured from the parent or explicit request. */
188
+ readonly cwd: string;
200
189
  }
201
190
  /**
202
191
  * What the continuation manager asks a provider for while materializing one
@@ -206,6 +195,8 @@ export interface ResolvedSubagentStartRequest extends SubagentStartRequest {
206
195
  * history.
207
196
  */
208
197
  export interface ContinuableCreateRequest {
198
+ /** Absolute initial directory captured before provider preparation. */
199
+ readonly cwd: string;
209
200
  /** The reserved durable child session id, for provider diagnostics. */
210
201
  readonly sessionId: SessionId;
211
202
  /** The delegating parent agent whose history a seeding provider reads. */
@@ -281,27 +272,15 @@ export interface SubagentResult {
281
272
  readonly stopReason: SubagentStopReason;
282
273
  }
283
274
  /**
284
- * ONE-SHOT child handle returned after publication. Prompt submission, turn
285
- * work, and infrastructure faults after that boundary belong to {@link result}.
286
- * Consumers await that result and must always {@link dispose} to cancel
287
- * remaining work and reach quiescence. A run is one disposable foreground
288
- * delegation with one result; continuable conversations have no run — the
289
- * continuation manager holds their `AgentHandle` directly and orders every
290
- * turn through the child's own inbox.
275
+ * Backend execution handle owned directly by the activation registry.
276
+ * A result may become available before resource release; the manager always
277
+ * disposes the handle and awaits cleanup. Backend startup failures clean up
278
+ * partial resources before rejecting, while accepted execution failures settle
279
+ * through result.
291
280
  */
292
281
  export interface SubagentRun {
293
- /**
294
- * Parent-scoped run id. For a local run, this MUST equal the published child
295
- * session id, whose `parentSession` records `request.parent.session.id`; a
296
- * remote provider mints an id unique in the parent namespace.
297
- */
282
+ /** Provider-minted id, unique across all parents, providers, and local Sessions in this runtime. */
298
283
  readonly id: SessionId;
299
- /**
300
- * The exact published in-process child, or `undefined` for a remote run.
301
- * When present, its id is {@link id}; the provider retains no ownership
302
- * implication beyond the run's ordinary {@link dispose} contract.
303
- */
304
- readonly localAgent: Agent | undefined;
305
284
  /**
306
285
  * Resolves with the child's terminal {@link SubagentResult} when the run
307
286
  * settles. Does NOT reject on a child-level failure — a model/transport
@@ -336,7 +315,7 @@ export interface SubagentProvider {
336
315
  */
337
316
  readonly inheritsParentContext: boolean;
338
317
  /**
339
- * Optional static provider-owned provider/model route for one-shot Agent
318
+ * Optional static provider-owned provider/model route for child Agent
340
319
  * options. Consumers merge tool/model overrides over these values before
341
320
  * preflight; providers whose route derives from the parent omit it. The value
342
321
  * is detached immutable data and requires `agentOptions` support.
@@ -346,24 +325,21 @@ export interface SubagentProvider {
346
325
  model: string;
347
326
  }>;
348
327
  /**
349
- * Establish a ONE-SHOT child and return its handle after publication.
328
+ * Establish one external execution and return its owned handle.
350
329
  * The service has already validated that every requested start-time
351
- * capability is supported and resolved `request.descriptor`, so a
352
- * session-backed implementation appends that descriptor inside the child's
353
- * initial turn. Before fulfillment, the provider owns setup and cleans any
354
- * unpublished partial resources before rejecting. Ownership transfers on
330
+ * capability is supported. Before fulfillment, the provider owns setup and
331
+ * cleans any unpublished partial resources before rejecting. Ownership transfers on
355
332
  * fulfillment; subsequent turn or infrastructure failure settles through
356
333
  * the returned run. Distinct starts may overlap; cancellation, failure,
357
334
  * result settlement, and disposal remain independent for each run.
358
335
  */
359
- start(request: ResolvedSubagentStartRequest): Promise<SubagentRun>;
336
+ start?(request: ResolvedSubagentStartRequest): Promise<SubagentRun>;
360
337
  /**
361
338
  * OPTIONAL (continuable-creation capability): contribute the detached
362
339
  * creation inputs that distinguish this provider's continuable children —
363
340
  * only whether the child session is seeded with parent history. Method
364
- * presence IS the capability: the service rejects continuable starts on
365
- * providers without it, while a provider that has it may still serve
366
- * ordinary one-shot delegations.
341
+ * presence selects local activation execution. Providers without it execute
342
+ * through start and do not accept subsequent messages.
367
343
  *
368
344
  * This is the provider's ONLY participation in a continuable child. The
369
345
  * continuation manager owns identity reservation, composition, Agent
@@ -3,7 +3,7 @@
3
3
  * for {@link SubagentProvider}, plus the `subagent/start` and `subagent/end`
4
4
  * payloads that plugins and hosts observe. Internal control interfaces belong
5
5
  * with their implementation — the lifecycle observer in `./lifecycle.ts`, the
6
- * continuation host in `./continuation.ts` — so this module stays the published
6
+ * manager host in `./manager.ts` — so this module stays the published
7
7
  * surface rather than a bag of everything type-shaped.
8
8
  *
9
9
  * @module @deepseek-ai/dsh-subagent/types