@deepseek-ai/dsh-subagent-acp 0.2.2-rc.1 → 0.2.2-rc.3
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.
- package/README.i18n.yaml +2 -2
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/run.d.ts.map +1 -0
- package/lib/types/run.js.map +1 -0
- package/package.json +25 -22
- package/src/index.ts +129 -0
- package/src/run.ts +618 -0
package/README.i18n.yaml
CHANGED
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
en: 75d061c2151624a7
|
|
70
70
|
zh: 71e58e020b60ff90
|
|
71
71
|
/deepseek-ai-dsh-subagent-acp/model-experience/parent-tool-result-indirectly/what-the-model-sees:
|
|
72
|
-
en:
|
|
73
|
-
zh:
|
|
72
|
+
en: bacf407400c5a362
|
|
73
|
+
zh: 7c9e3daea29508e9
|
|
74
74
|
/deepseek-ai-dsh-subagent-acp/model-experience/parent-tool-result-indirectly/token-effect:
|
|
75
75
|
en: 4fae54e2ff0c4874
|
|
76
76
|
zh: 1574bfe874f66a1f
|
package/README.md
CHANGED
|
@@ -138,7 +138,7 @@ Independent of the parent request cache. Each ACP child can reuse only prefixes
|
|
|
138
138
|
|
|
139
139
|
#### What the model sees
|
|
140
140
|
|
|
141
|
-
Through `dsh-tool-subagent`, the parent model first receives
|
|
141
|
+
Through `dsh-tool-subagent`, the parent model first receives the child's name, then a completion notice containing final or partial assistant text, the stop reason, and safe diagnostic. The parent Session independently retains the external task identity and complete terminal result. Intermediate messages and tool traffic do not enter the parent Session.
|
|
142
142
|
|
|
143
143
|
#### Token effect
|
|
144
144
|
|
package/README.zh.md
CHANGED
|
@@ -138,7 +138,7 @@ spawn、初始化或新建会话失败会在发布前拒绝,通常先证明 ma
|
|
|
138
138
|
|
|
139
139
|
#### 模型看到什么
|
|
140
140
|
|
|
141
|
-
通过 `dsh-tool-subagent
|
|
141
|
+
通过 `dsh-tool-subagent`,父模型先收到子任务名称,随后收到含最终或部分 assistant 文本、停止原因与安全诊断的完成通知。父会话独立保存外部任务身份和完整终态结果。中间消息与工具通信不进入父会话。
|
|
142
142
|
|
|
143
143
|
#### Token 影响
|
|
144
144
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAQxC,OAAO,EAAoG,KAAK,gBAAgB,EAAe,MAAM,UAAU,CAAA;AAE/J,eAAO,MAAM,IAAI,iBAAiB,CAAA;AAClC,eAAO,MAAM,MAAM,UAA8B,CAAA;AAEjD,kEAAkE;AAClE,MAAM,WAAW,MAAM;IACrB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAA;IACpB,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAA;IACf,2CAA2C;IAC3C,IAAI,EAAE,MAAM,EAAE,CAAA;IACd;;;;OAIG;IACH,UAAU,EAAE,gBAAgB,CAAA;IAC5B;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,uGAAuG;IACvG,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAQ3B,CAAA;AA2DF,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAMxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,CAAC,MAAM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EAAE,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc;oBACnE,GAAG,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;iBACrE,EAAE,KAAK,CAAC,CAAA;YACX,CAAC;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-subagent-acp",
|
|
3
3
|
"description": "Out-of-process ACP subagent backend: drives a child agent in a spawned subprocess over the Agent Client Protocol",
|
|
4
|
-
"version": "0.2.2-rc.
|
|
4
|
+
"version": "0.2.2-rc.3",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -25,38 +25,41 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"locale/*.json",
|
|
27
27
|
"lib/index.js",
|
|
28
|
-
"lib/types/**/*.d.ts"
|
|
28
|
+
"lib/types/**/*.d.ts",
|
|
29
|
+
"lib/types/**/*.d.ts.map",
|
|
30
|
+
"lib/**/*.js.map",
|
|
31
|
+
"src"
|
|
29
32
|
],
|
|
30
33
|
"license": "MIT",
|
|
31
34
|
"peerDependencies": {
|
|
32
35
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
33
|
-
"@deepseek-ai/dsh-agent": "0.2.2-rc.
|
|
34
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.
|
|
35
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.
|
|
36
|
-
"@deepseek-ai/dsh-subagent": "0.2.2-rc.
|
|
37
|
-
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.
|
|
38
|
-
"@deepseek-ai/dsh-timeout": "0.2.2-rc.
|
|
36
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.3",
|
|
37
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.3",
|
|
38
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.3",
|
|
39
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.3",
|
|
40
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.3",
|
|
41
|
+
"@deepseek-ai/dsh-timeout": "0.2.2-rc.3"
|
|
39
42
|
},
|
|
40
43
|
"dependencies": {
|
|
41
44
|
"@agentclientprotocol/sdk": "1.4.0",
|
|
42
|
-
"@deepseek-ai/dsh-brand": "0.2.2-rc.
|
|
45
|
+
"@deepseek-ai/dsh-brand": "0.2.2-rc.3",
|
|
43
46
|
"@deepseek-ai/schemastery": "~3.19.0"
|
|
44
47
|
},
|
|
45
48
|
"devDependencies": {
|
|
46
49
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
47
50
|
"@deepseek-ai/cordis-plugin-loader": "~1.1.0",
|
|
48
|
-
"@deepseek-ai/dsh-agent": "0.2.2-rc.
|
|
49
|
-
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.
|
|
50
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.
|
|
51
|
-
"@deepseek-ai/dsh-loader-smoke": "0.2.2-rc.
|
|
52
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.
|
|
53
|
-
"@deepseek-ai/dsh-session-checkpoint-policy": "0.2.2-rc.
|
|
54
|
-
"@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-rc.
|
|
55
|
-
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.
|
|
56
|
-
"@deepseek-ai/dsh-subagent": "0.2.2-rc.
|
|
57
|
-
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.
|
|
58
|
-
"@deepseek-ai/dsh-subprocess-local": "0.2.2-rc.
|
|
59
|
-
"@deepseek-ai/dsh-timeout": "0.2.2-rc.
|
|
60
|
-
"@deepseek-ai/dsh-tool-subagent": "0.2.2-rc.
|
|
51
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.3",
|
|
52
|
+
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.3",
|
|
53
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.3",
|
|
54
|
+
"@deepseek-ai/dsh-loader-smoke": "0.2.2-rc.3",
|
|
55
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.3",
|
|
56
|
+
"@deepseek-ai/dsh-session-checkpoint-policy": "0.2.2-rc.3",
|
|
57
|
+
"@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-rc.3",
|
|
58
|
+
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.3",
|
|
59
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.3",
|
|
60
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.3",
|
|
61
|
+
"@deepseek-ai/dsh-subprocess-local": "0.2.2-rc.3",
|
|
62
|
+
"@deepseek-ai/dsh-timeout": "0.2.2-rc.3",
|
|
63
|
+
"@deepseek-ai/dsh-tool-subagent": "0.2.2-rc.3"
|
|
61
64
|
}
|
|
62
65
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Out-of-process ACP subagent backend. Each child has its own process, session, model, and
|
|
3
|
+
* tools, so it shares no Cordis context and advertises no parent-enforced start capabilities;
|
|
4
|
+
* the subagent service supplies the captured child working directory. This plugin uses
|
|
5
|
+
* named exports only; a default would hide its
|
|
6
|
+
* loader metadata (see `docs/postmortem/0001-acp-default-export-drops-inject.md`).
|
|
7
|
+
* @module @deepseek-ai/dsh-subagent-acp
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
11
|
+
import z from '@deepseek-ai/schemastery'
|
|
12
|
+
import type {
|
|
13
|
+
ResolvedSubagentStartRequest,
|
|
14
|
+
SubagentCapabilities,
|
|
15
|
+
SubagentProvider,
|
|
16
|
+
} from '@deepseek-ai/dsh-subagent'
|
|
17
|
+
import { assertUsableCwd } from '@deepseek-ai/dsh-subagent'
|
|
18
|
+
import { MAX_TIMER_DELAY_MS } from '@deepseek-ai/dsh-timeout'
|
|
19
|
+
import { acpConfigurationFailure, type AcpRunSpec, DEFAULT_DISPOSE_EOF_GRACE_MS, DEFAULT_DISPOSE_GRACE_MS, type PermissionPolicy, startAcpRun } from './run.ts'
|
|
20
|
+
|
|
21
|
+
export const name = 'subagent-acp'
|
|
22
|
+
export const inject = ['subagents', 'subprocess']
|
|
23
|
+
|
|
24
|
+
/** Config: how to spawn and drive the child ACP agent process. */
|
|
25
|
+
export interface Config {
|
|
26
|
+
/** Provider name on `ctx.subagents` (default `acp`). */
|
|
27
|
+
providerName: string
|
|
28
|
+
/** The executable to spawn for each run (the child ACP agent). */
|
|
29
|
+
command: string
|
|
30
|
+
/** Arguments passed to {@link command}. */
|
|
31
|
+
args: string[]
|
|
32
|
+
/**
|
|
33
|
+
* How to auto-answer the child's `session/request_permission` prompts:
|
|
34
|
+
* `reject` (default — decline every prompt) or `allow` (approve via the first
|
|
35
|
+
* `allow_once` or `allow_always` option). No prompt is surfaced to a human.
|
|
36
|
+
*/
|
|
37
|
+
permission: PermissionPolicy
|
|
38
|
+
/**
|
|
39
|
+
* Extra environment variables for the child process — e.g. the child
|
|
40
|
+
* harness's own `DEEPSEEK_API_KEY`. Forwarded on top of a credential-scrubbed
|
|
41
|
+
* copy of the parent env, so an explicit key here reaches the child while
|
|
42
|
+
* ambient secrets do not leak implicitly.
|
|
43
|
+
*/
|
|
44
|
+
env: Record<string, string>
|
|
45
|
+
/**
|
|
46
|
+
* Grace period (ms) for the child's EOF-driven quiesce on dispose — its
|
|
47
|
+
* window to flush persistence and tear down its own nested subprocesses
|
|
48
|
+
* before the parent escalates to a signal. Must not exceed
|
|
49
|
+
* `MAX_TIMER_DELAY_MS`.
|
|
50
|
+
*/
|
|
51
|
+
disposeEofGraceMs?: number
|
|
52
|
+
/** Failure-observation and termination-escalation grace (ms); must not exceed `MAX_TIMER_DELAY_MS`. */
|
|
53
|
+
disposeGraceMs?: number
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const Config: z<Config> = z.object({
|
|
57
|
+
providerName: z.string().default('acp'),
|
|
58
|
+
command: z.string().required(),
|
|
59
|
+
args: z.array(z.string()).default([]),
|
|
60
|
+
permission: z.union(['allow', 'reject'] as const).default('reject'),
|
|
61
|
+
env: z.dict(z.string()).default({}),
|
|
62
|
+
disposeEofGraceMs: z.number().default(DEFAULT_DISPOSE_EOF_GRACE_MS),
|
|
63
|
+
disposeGraceMs: z.number().default(DEFAULT_DISPOSE_GRACE_MS),
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
/** A process grace must fit every Node timer that observes or terminates the child. */
|
|
67
|
+
function assertPositiveFinite(name: string, value: number): void {
|
|
68
|
+
if (!Number.isFinite(value) || value <= 0 || value > MAX_TIMER_DELAY_MS) {
|
|
69
|
+
throw new Error(`subagent-acp: ${name} must be a positive finite number no greater than ${MAX_TIMER_DELAY_MS}`)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type ResolvedConfig = Required<Config>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The ACP provider. Advertises NO start-time capabilities: an out-of-process
|
|
77
|
+
* child cannot honor `agentOptions`/`agentPreset`/`outputSchema`/`maxDepth`.
|
|
78
|
+
* The service rejects a request needing any before execution starts.
|
|
79
|
+
*/
|
|
80
|
+
class AcpProvider implements SubagentProvider {
|
|
81
|
+
readonly capabilities: SubagentCapabilities = {
|
|
82
|
+
agentOptions: false,
|
|
83
|
+
agentPreset: false,
|
|
84
|
+
outputSchema: false,
|
|
85
|
+
depthLimit: false,
|
|
86
|
+
}
|
|
87
|
+
// Context contract: an out-of-process ACP child starts fresh — no parent conversation crosses the process boundary.
|
|
88
|
+
readonly inheritsParentContext = false
|
|
89
|
+
|
|
90
|
+
constructor(readonly name: string, private readonly ctx: Context, private readonly config: ResolvedConfig) {}
|
|
91
|
+
|
|
92
|
+
start(request: ResolvedSubagentStartRequest) {
|
|
93
|
+
if (request.signal.aborted) {
|
|
94
|
+
throw new Error('subagent request was aborted before the ACP child started')
|
|
95
|
+
}
|
|
96
|
+
let cwd: string
|
|
97
|
+
try {
|
|
98
|
+
cwd = assertUsableCwd('subagent-acp', 'child cwd', request.cwd)
|
|
99
|
+
} catch (error: unknown) {
|
|
100
|
+
const failure = acpConfigurationFailure(error)
|
|
101
|
+
this.ctx.logger.warn(`subagent-acp "${this.name}": child start failed: %o`, error)
|
|
102
|
+
throw failure
|
|
103
|
+
}
|
|
104
|
+
const spec: AcpRunSpec = {
|
|
105
|
+
command: this.config.command,
|
|
106
|
+
args: this.config.args,
|
|
107
|
+
cwd,
|
|
108
|
+
permission: this.config.permission,
|
|
109
|
+
env: this.config.env,
|
|
110
|
+
disposeEofGraceMs: this.config.disposeEofGraceMs,
|
|
111
|
+
disposeGraceMs: this.config.disposeGraceMs,
|
|
112
|
+
spawn: spec => this.ctx.subprocess.spawn(spec),
|
|
113
|
+
onError: (error, stopReason) => {
|
|
114
|
+
// The seam forbids `result` rejecting, so a child-level failure is
|
|
115
|
+
// flattened to a stop reason — preserve it here rather than losing it.
|
|
116
|
+
this.ctx.logger.warn(`subagent-acp "${this.name}": child run failed (${stopReason}): ${error.message}`)
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
return startAcpRun(request, spec)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function apply(ctx: Context, config: Config): void {
|
|
124
|
+
// schemastery (Config) has already filled every defaulted field.
|
|
125
|
+
const resolved = config as ResolvedConfig
|
|
126
|
+
assertPositiveFinite('disposeEofGraceMs', resolved.disposeEofGraceMs)
|
|
127
|
+
assertPositiveFinite('disposeGraceMs', resolved.disposeGraceMs)
|
|
128
|
+
ctx.subagents.registerProvider(new AcpProvider(resolved.providerName, ctx, resolved))
|
|
129
|
+
}
|
package/src/run.ts
ADDED
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fresh-process ACP subagent client. Drives one child session and owns cancellation and
|
|
3
|
+
* quiescent disposal.
|
|
4
|
+
*
|
|
5
|
+
* @module @deepseek-ai/dsh-subagent-acp/run
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { randomUUID } from 'node:crypto'
|
|
9
|
+
import { Readable as NodeReadable, Writable as NodeWritable } from 'node:stream'
|
|
10
|
+
import {
|
|
11
|
+
client as createAcpClientApp,
|
|
12
|
+
methods,
|
|
13
|
+
ndJsonStream,
|
|
14
|
+
PROTOCOL_VERSION,
|
|
15
|
+
type ContentBlock as AcpContentBlock,
|
|
16
|
+
type StopReason,
|
|
17
|
+
type ToolKind,
|
|
18
|
+
} from '@agentclientprotocol/sdk'
|
|
19
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
|
|
20
|
+
import { brandString } from '@deepseek-ai/dsh-brand'
|
|
21
|
+
import type { SessionId } from '@deepseek-ai/dsh-session'
|
|
22
|
+
import { AssistantOutputFold, settleRunResult, subprocessRunHandle } from '@deepseek-ai/dsh-subagent'
|
|
23
|
+
import type { SubagentResult, SubagentRun, SubagentStartRequest, SubagentStopReason } from '@deepseek-ai/dsh-subagent'
|
|
24
|
+
import type { SubprocessHandle, SubprocessOutcome, SubprocessSpawnSpec } from '@deepseek-ai/dsh-subprocess'
|
|
25
|
+
|
|
26
|
+
/** Fixed response to child permission requests: reject by default, or select the first allow option. */
|
|
27
|
+
export type PermissionPolicy = 'allow' | 'reject'
|
|
28
|
+
|
|
29
|
+
/** Resolved spawn spec for an ACP child process (no defaults — see Config). */
|
|
30
|
+
export interface AcpRunSpec {
|
|
31
|
+
/** The executable to spawn (the child ACP agent). */
|
|
32
|
+
command: string
|
|
33
|
+
/** Arguments passed to {@link command}. */
|
|
34
|
+
args: string[]
|
|
35
|
+
/**
|
|
36
|
+
* Absolute working directory for the child process AND its ACP session
|
|
37
|
+
* `cwd`, selected before provider startup.
|
|
38
|
+
*/
|
|
39
|
+
cwd: string
|
|
40
|
+
/** How to auto-answer the child's permission prompts. */
|
|
41
|
+
permission: PermissionPolicy
|
|
42
|
+
/**
|
|
43
|
+
* Extra environment variables to ADD for the child (e.g. the child harness's
|
|
44
|
+
* `DEEPSEEK_API_KEY`). Merged on top of the subprocess seam's scrubbed
|
|
45
|
+
* parent env. A value here is forwarded even if its name matches the
|
|
46
|
+
* credential-scrub pattern (an explicit opt-in for the child's own creds).
|
|
47
|
+
* Explicit `DSH_*` entries are deployment-owned facts for the child harness
|
|
48
|
+
* (e.g. `DSH_PERMISSION_MODE`); they simply merge after the scrub that
|
|
49
|
+
* dropped their stale ambient namesakes.
|
|
50
|
+
*/
|
|
51
|
+
env: Record<string, string>
|
|
52
|
+
/**
|
|
53
|
+
* Grace period (ms) for the child's EOF-driven quiesce in
|
|
54
|
+
* {@link SubagentRun.dispose} — the window to flush persistence and tear down
|
|
55
|
+
* its OWN nested subprocesses before the parent escalates to a signal. The
|
|
56
|
+
* plugin fills this from its `disposeEofGraceMs` config.
|
|
57
|
+
*/
|
|
58
|
+
disposeEofGraceMs: number
|
|
59
|
+
/**
|
|
60
|
+
* Process-observation and termination-escalation grace (ms). Failure
|
|
61
|
+
* classification waits at most this long for structured exit facts; POSIX
|
|
62
|
+
* dispose also waits this long after `SIGTERM` before `SIGKILL`, while
|
|
63
|
+
* Windows force-terminates directly. The plugin fills it from
|
|
64
|
+
* `disposeGraceMs`.
|
|
65
|
+
*/
|
|
66
|
+
disposeGraceMs: number
|
|
67
|
+
/**
|
|
68
|
+
* Spawn function from the subprocess seam (`ctx.subprocess.spawn`), so the
|
|
69
|
+
* child rides the shared scrub, managed-range teardown, and service-owned
|
|
70
|
+
* lifetime instead of a package-local child_process path.
|
|
71
|
+
*/
|
|
72
|
+
spawn: (spec: SubprocessSpawnSpec) => SubprocessHandle
|
|
73
|
+
/**
|
|
74
|
+
* Host sink for startup, published-run, or teardown failures. Model-visible
|
|
75
|
+
* text uses fixed safe facts, while this callback retains the original Error
|
|
76
|
+
* when one exists. A throw from the sink itself is contained.
|
|
77
|
+
*/
|
|
78
|
+
onError?: (error: Error, stopReason: SubagentStopReason) => void
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** EOF grace for child flush and nested-process teardown; wider than the signal grace below. */
|
|
82
|
+
export const DEFAULT_DISPOSE_EOF_GRACE_MS = 6_000
|
|
83
|
+
|
|
84
|
+
/** Default POSIX grace between SIGTERM and SIGKILL on dispose (the `disposeGraceMs` config). */
|
|
85
|
+
export const DEFAULT_DISPOSE_GRACE_MS = 3_000
|
|
86
|
+
|
|
87
|
+
type AcpFailureStage = 'initialize' | 'new-session' | 'prompt' | 'process' | 'teardown'
|
|
88
|
+
|
|
89
|
+
type AcpFailureCategory =
|
|
90
|
+
| 'protocol'
|
|
91
|
+
| 'configuration'
|
|
92
|
+
| 'transport'
|
|
93
|
+
| 'process-start'
|
|
94
|
+
| 'process-exit'
|
|
95
|
+
| 'remote-limit'
|
|
96
|
+
| 'unknown'
|
|
97
|
+
|
|
98
|
+
interface AcpFailureFacts {
|
|
99
|
+
readonly stage: AcpFailureStage
|
|
100
|
+
readonly category: AcpFailureCategory
|
|
101
|
+
readonly stopReason?: StopReason | 'unknown'
|
|
102
|
+
readonly outcome?: SubprocessOutcome | undefined
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface AcpPermissionDecision {
|
|
106
|
+
readonly policy: PermissionPolicy
|
|
107
|
+
readonly request: ToolKind | 'unknown'
|
|
108
|
+
readonly decision: 'allowed' | 'denied'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const ACP_TOOL_KINDS: ReadonlySet<string> = new Set([
|
|
112
|
+
'read', 'edit', 'delete', 'move', 'search',
|
|
113
|
+
'execute', 'think', 'fetch', 'switch_mode', 'other',
|
|
114
|
+
])
|
|
115
|
+
|
|
116
|
+
/** Fixed safe failure text derived only from provider-owned structured facts. */
|
|
117
|
+
function failureDiagnostic(facts: AcpFailureFacts): string {
|
|
118
|
+
const fields = [
|
|
119
|
+
'provider: ACP',
|
|
120
|
+
`stage: ${facts.stage}`,
|
|
121
|
+
`category: ${facts.category}`,
|
|
122
|
+
]
|
|
123
|
+
if (facts.stopReason !== undefined) fields.push(`stop reason: ${facts.stopReason}`)
|
|
124
|
+
if (facts.outcome?.exitCode !== null && facts.outcome?.exitCode !== undefined) {
|
|
125
|
+
fields.push(`exit code: ${facts.outcome.exitCode}`)
|
|
126
|
+
}
|
|
127
|
+
/* v8 ignore next -- Windows does not report POSIX child signals in SubprocessOutcome. */
|
|
128
|
+
if (facts.outcome?.signal !== null && facts.outcome?.signal !== undefined) {
|
|
129
|
+
fields.push(`signal: ${facts.outcome.signal}`)
|
|
130
|
+
}
|
|
131
|
+
return `Subagent failure (${fields.join('; ')})`
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Fixed permission fact; ACP tool titles and option text never enter it. */
|
|
135
|
+
function permissionDiagnostic(permission: AcpPermissionDecision): string {
|
|
136
|
+
return `ACP unattended decision (policy: ${permission.policy}; request: ${permission.request}; decision: ${permission.decision})`
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Put the operation failure first, followed by the latest permission decision. */
|
|
140
|
+
function diagnosticText(facts: AcpFailureFacts, permission?: AcpPermissionDecision): string {
|
|
141
|
+
const failure = failureDiagnostic(facts)
|
|
142
|
+
return permission === undefined ? failure : `${failure}\n${permissionDiagnostic(permission)}`
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
class AcpRunFailure extends Error {
|
|
146
|
+
constructor(facts: AcpFailureFacts, cause: unknown) {
|
|
147
|
+
super(
|
|
148
|
+
`subagent-acp: ${failureDiagnostic(facts)}`,
|
|
149
|
+
{ cause },
|
|
150
|
+
)
|
|
151
|
+
this.name = 'AcpRunFailure'
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Hide a pre-spawn workspace/configuration failure behind fixed safe facts.
|
|
157
|
+
* @param cause - original Host failure retained on the Error cause chain.
|
|
158
|
+
* @returns an Error whose message contains only the fixed ACP failure line.
|
|
159
|
+
*/
|
|
160
|
+
export function acpConfigurationFailure(cause: unknown): Error {
|
|
161
|
+
return new AcpRunFailure({ stage: 'initialize', category: 'configuration' }, cause)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Keep only the closed ACP tool-kind vocabulary; future values use a fixed fallback. */
|
|
165
|
+
function permissionRequestKind(kind: ToolKind | null | undefined): ToolKind | 'unknown' {
|
|
166
|
+
const candidate = kind ?? 'unknown'
|
|
167
|
+
return ACP_TOOL_KINDS.has(candidate)
|
|
168
|
+
? candidate
|
|
169
|
+
: 'unknown'
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Bounded managed-range exit wait: observes the handle's range until it is empty or `ms` elapses. */
|
|
173
|
+
async function rangeExitsWithin(child: SubprocessHandle, ms: number): Promise<boolean> {
|
|
174
|
+
const controller = new AbortController()
|
|
175
|
+
const timer = setTimeout(() => { controller.abort() }, ms)
|
|
176
|
+
try {
|
|
177
|
+
return await child.waitForExit(controller.signal)
|
|
178
|
+
} finally {
|
|
179
|
+
clearTimeout(timer)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Cooperative teardown ladder for an out-of-process agent, over the seam's
|
|
185
|
+
* public verbs; resolves only at whole-range quiescence: stdin EOF (the child's
|
|
186
|
+
* window to flush persistence and reap its own descendants), then the
|
|
187
|
+
* terminate() escalation (SIGTERM → spec grace → SIGKILL) and its
|
|
188
|
+
* whole-range exit proof.
|
|
189
|
+
* @param child - the spawned ACP child's handle.
|
|
190
|
+
* @param eofGraceMs - tier-1 window after stdin EOF.
|
|
191
|
+
*/
|
|
192
|
+
export async function disposeAcpChild(child: SubprocessHandle, eofGraceMs: number): Promise<void> {
|
|
193
|
+
const failures: Error[] = []
|
|
194
|
+
child.stdin?.end()
|
|
195
|
+
let exited = false
|
|
196
|
+
try {
|
|
197
|
+
exited = await rangeExitsWithin(child, eofGraceMs)
|
|
198
|
+
} catch (error: unknown) {
|
|
199
|
+
failures.push(toError(error))
|
|
200
|
+
}
|
|
201
|
+
if (exited) return
|
|
202
|
+
// terminate() owns the bounded SIGTERM→SIGKILL timer. Its unbounded wait is
|
|
203
|
+
// the process owner's exit proof, not a second derived grace that can overflow.
|
|
204
|
+
child.terminate()
|
|
205
|
+
try {
|
|
206
|
+
await child.waitForExit()
|
|
207
|
+
} catch (error: unknown) {
|
|
208
|
+
failures.push(toError(error))
|
|
209
|
+
}
|
|
210
|
+
if (failures.length === 1) throw failures[0] as Error
|
|
211
|
+
if (failures.length > 1) throw new AggregateError(failures, 'ACP subprocess teardown failed')
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Map an ACP {@link StopReason} to a harness {@link SubagentStopReason}.
|
|
216
|
+
* @param reason - the terminal reason from the child's `session/prompt` response.
|
|
217
|
+
* @returns the harness equivalent; `max_turn_requests` and any unknown future
|
|
218
|
+
* variant map to `error`, so an unclean stop is never reported as `completed`.
|
|
219
|
+
*/
|
|
220
|
+
export function acpStopReason(reason: StopReason): SubagentStopReason {
|
|
221
|
+
switch (reason) {
|
|
222
|
+
case 'end_turn':
|
|
223
|
+
return 'completed'
|
|
224
|
+
case 'max_tokens':
|
|
225
|
+
return 'max-tokens'
|
|
226
|
+
case 'refusal':
|
|
227
|
+
return 'refusal'
|
|
228
|
+
case 'cancelled':
|
|
229
|
+
return 'aborted'
|
|
230
|
+
// `max_turn_requests` (the child hit its turn-request budget) has no direct
|
|
231
|
+
// harness equivalent and means the task did NOT finish cleanly — surface it
|
|
232
|
+
// as a generic failure so the consumer maps it to an isError result rather
|
|
233
|
+
// than reporting a partial answer as success.
|
|
234
|
+
case 'max_turn_requests':
|
|
235
|
+
return 'error'
|
|
236
|
+
// ACP StopReason is a closed wire union, but a future SDK could add a
|
|
237
|
+
// variant; treat an unknown terminal reason as a failure (never silently
|
|
238
|
+
// 'completed').
|
|
239
|
+
default:
|
|
240
|
+
return 'error'
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Collect the text of an ACP content block (non-text blocks contribute nothing).
|
|
246
|
+
* @param content - the content block off a streamed `agent_message_chunk`.
|
|
247
|
+
* @returns the block's text, or `''` for a non-text block.
|
|
248
|
+
*/
|
|
249
|
+
export function acpContentText(content: AcpContentBlock): string {
|
|
250
|
+
return content.type === 'text' ? content.text : ''
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Translate the harness prompt blocks into ACP prompt blocks (text only).
|
|
255
|
+
* @param prompt - the harness prompt; non-text blocks are dropped.
|
|
256
|
+
* @returns the ACP text blocks, in order.
|
|
257
|
+
*/
|
|
258
|
+
export function toAcpPrompt(prompt: ContentBlock[]): AcpContentBlock[] {
|
|
259
|
+
const blocks: AcpContentBlock[] = []
|
|
260
|
+
for (const block of prompt) {
|
|
261
|
+
if (block.type === 'text') blocks.push({ type: 'text', text: block.text })
|
|
262
|
+
}
|
|
263
|
+
return blocks
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Normalize an unknown thrown value to an Error (the catch binding is `unknown`). */
|
|
267
|
+
function toError(value: unknown): Error {
|
|
268
|
+
// The catch only sees rejections from the ACP SDK RPCs and the spawn `error`
|
|
269
|
+
// event, which are always `Error`s; the `String(value)` arm is a defensive
|
|
270
|
+
// fallback for a non-Error throw that the typed APIs cannot produce.
|
|
271
|
+
/* v8 ignore next */
|
|
272
|
+
return value instanceof Error ? value : new Error(String(value))
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Report an original Host failure without letting the observation sink replace it. */
|
|
276
|
+
function reportFailure(spec: AcpRunSpec, error: unknown): void {
|
|
277
|
+
try {
|
|
278
|
+
spec.onError?.(toError(error), 'error')
|
|
279
|
+
} catch {
|
|
280
|
+
// Host diagnostic logging cannot replace the child failure.
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Classify an unpublished failure from the active protocol operation and observed process facts. */
|
|
285
|
+
function startupFailure(
|
|
286
|
+
error: unknown,
|
|
287
|
+
stage: Extract<AcpFailureStage, 'initialize' | 'new-session'>,
|
|
288
|
+
outcome: SubprocessOutcome | undefined,
|
|
289
|
+
): AcpRunFailure {
|
|
290
|
+
return new AcpRunFailure(
|
|
291
|
+
/* v8 ignore next -- Windows anonymous pipes cannot expose a live-child protocol close during startup. */
|
|
292
|
+
outcome === undefined
|
|
293
|
+
? { stage, category: 'transport' }
|
|
294
|
+
: { stage, category: 'process-exit', outcome },
|
|
295
|
+
error,
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Map one remote terminal reason to the optional safe failure line it needs. */
|
|
300
|
+
function terminalFailure(
|
|
301
|
+
reason: StopReason,
|
|
302
|
+
permission: AcpPermissionDecision | undefined,
|
|
303
|
+
): string | undefined {
|
|
304
|
+
switch (reason) {
|
|
305
|
+
case 'end_turn':
|
|
306
|
+
return undefined
|
|
307
|
+
case 'max_turn_requests':
|
|
308
|
+
return diagnosticText({
|
|
309
|
+
stage: 'prompt',
|
|
310
|
+
category: 'remote-limit',
|
|
311
|
+
stopReason: 'max_turn_requests',
|
|
312
|
+
}, permission)
|
|
313
|
+
case 'max_tokens':
|
|
314
|
+
case 'refusal':
|
|
315
|
+
case 'cancelled':
|
|
316
|
+
return permission === undefined
|
|
317
|
+
? undefined
|
|
318
|
+
: permissionDiagnostic(permission)
|
|
319
|
+
default:
|
|
320
|
+
return diagnosticText({ stage: 'prompt', category: 'unknown', stopReason: 'unknown' }, permission)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Start and publish one ACP child after initialization and session creation.
|
|
326
|
+
* Child failures resolve through the run result. Startup rejects with fixed
|
|
327
|
+
* safe facts after provider-owned cleanup; successful cleanup proves managed
|
|
328
|
+
* range quiescence. Cleanup failure preserves startup plus teardown facts for an ordinary
|
|
329
|
+
* failure, or teardown alone after cancellation, without claiming quiescence.
|
|
330
|
+
* Disposal cancels, terminates, and settles the child's managed range.
|
|
331
|
+
* @param request - the start request; its signal is the cancellation channel.
|
|
332
|
+
* @param spec - the resolved spawn spec: command/args/cwd, env, permission
|
|
333
|
+
* policy, dispose graces, and the optional error sink.
|
|
334
|
+
* @returns the ready run handle for the child subprocess.
|
|
335
|
+
*/
|
|
336
|
+
export async function startAcpRun(request: SubagentStartRequest, spec: AcpRunSpec): Promise<SubagentRun> {
|
|
337
|
+
if (request.signal.aborted) throw new Error('subagent request was aborted before the ACP child started')
|
|
338
|
+
// ACP session ids are unique only within the child server. The lifecycle id
|
|
339
|
+
// is minted in the parent namespace so fresh processes cannot collide with
|
|
340
|
+
// each other or with a local agent that happens to use the same session id.
|
|
341
|
+
const id = brandString<SessionId>(randomUUID())
|
|
342
|
+
|
|
343
|
+
// Keep diagnostics on parent stderr ('inherit'); only ACP output contributes
|
|
344
|
+
// to the result. The seam's scrub drops ambient credentials and DSH_* names
|
|
345
|
+
// while spec.env (the child's own key, its deployment facts) merges after it.
|
|
346
|
+
let child: SubprocessHandle
|
|
347
|
+
try {
|
|
348
|
+
child = spec.spawn({
|
|
349
|
+
argv: [spec.command, ...spec.args],
|
|
350
|
+
cwd: spec.cwd,
|
|
351
|
+
stdio: { stdin: 'pipe', stdout: 'pipe', stderr: 'inherit' },
|
|
352
|
+
graceMs: spec.disposeGraceMs,
|
|
353
|
+
env: spec.env,
|
|
354
|
+
})
|
|
355
|
+
} catch (error: unknown) {
|
|
356
|
+
reportFailure(spec, error)
|
|
357
|
+
throw new AcpRunFailure({ stage: 'process', category: 'process-start' }, error)
|
|
358
|
+
}
|
|
359
|
+
/* v8 ignore start -- 'pipe' dispositions expose both streams by the seam contract; defensive. */
|
|
360
|
+
if (child.stdin === undefined || child.stdout === undefined) {
|
|
361
|
+
throw new Error('subagent-acp: subprocess implementation dropped a piped protocol stream')
|
|
362
|
+
}
|
|
363
|
+
/* v8 ignore stop */
|
|
364
|
+
let processOutcome: SubprocessOutcome | undefined
|
|
365
|
+
let processFailure: Error | undefined
|
|
366
|
+
const processDone = child.done.then(
|
|
367
|
+
(outcome) => {
|
|
368
|
+
processOutcome = outcome
|
|
369
|
+
return outcome
|
|
370
|
+
},
|
|
371
|
+
(error: unknown) => {
|
|
372
|
+
processFailure = toError(error)
|
|
373
|
+
throw processFailure
|
|
374
|
+
},
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
// A rejected direct result surfaces into the startup race; a clean exit must
|
|
378
|
+
// never win it, so the success arm parks forever. (The ACP connection
|
|
379
|
+
// observing its streams closing bounds a child that exits without speaking
|
|
380
|
+
// the protocol.)
|
|
381
|
+
const processRejected: Promise<never> = processDone.then(
|
|
382
|
+
/* v8 ignore next -- the success arm's never-settling executor is intentionally empty. */
|
|
383
|
+
() => new Promise<never>(() => {}),
|
|
384
|
+
(err: unknown) => Promise.reject(toError(err)),
|
|
385
|
+
)
|
|
386
|
+
processRejected.catch(() => { /* observed by the startup race; never unhandled */ })
|
|
387
|
+
|
|
388
|
+
const observeProcessOutcome = async (signal?: AbortSignal): Promise<SubprocessOutcome | undefined> => {
|
|
389
|
+
if (processOutcome !== undefined) return processOutcome
|
|
390
|
+
const timeout = AbortSignal.timeout(Math.ceil(spec.disposeGraceMs))
|
|
391
|
+
const bound = signal === undefined ? timeout : AbortSignal.any([signal, timeout])
|
|
392
|
+
const aborted = Promise.withResolvers<undefined>()
|
|
393
|
+
/* v8 ignore next -- Windows cannot expose the live-child protocol close needed to await this abort. */
|
|
394
|
+
const onObservationAbort = (): void => { aborted.resolve(undefined) }
|
|
395
|
+
bound.addEventListener('abort', onObservationAbort, { once: true })
|
|
396
|
+
/* v8 ignore next -- closes the event-loop race between listener registration and the preceding derived-signal check. */
|
|
397
|
+
if (bound.aborted) onObservationAbort()
|
|
398
|
+
try {
|
|
399
|
+
return await Promise.race([processDone, aborted.promise])
|
|
400
|
+
} catch {
|
|
401
|
+
// A provider rejection after handle publication leaves no direct outcome;
|
|
402
|
+
// the active protocol failure remains authoritative.
|
|
403
|
+
return processOutcome
|
|
404
|
+
} finally {
|
|
405
|
+
bound.removeEventListener('abort', onObservationAbort)
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// Startup rollback and the published handle share one process teardown.
|
|
410
|
+
let processDisposal: Promise<void> | undefined
|
|
411
|
+
const disposeProcess = (): Promise<void> => (processDisposal ??= disposeAcpChild(child, spec.disposeEofGraceMs))
|
|
412
|
+
|
|
413
|
+
// ACP exposes no complete assistant messages, so the shared fold selects its
|
|
414
|
+
// accumulated assistant text.
|
|
415
|
+
const fold = new AssistantOutputFold()
|
|
416
|
+
// Shared mutable state keeps cancellation visible across async closures.
|
|
417
|
+
const flags = { cancelled: false }
|
|
418
|
+
let latestPermission: AcpPermissionDecision | undefined
|
|
419
|
+
|
|
420
|
+
const clientApp = createAcpClientApp({ name: 'deepseek-harness-subagent-acp' })
|
|
421
|
+
.onNotification(methods.client.session.update, ({ params }) => {
|
|
422
|
+
const update = params.update
|
|
423
|
+
if (update.sessionUpdate === 'agent_message_chunk') {
|
|
424
|
+
fold.pushText(acpContentText(update.content))
|
|
425
|
+
}
|
|
426
|
+
// Other updates (thoughts, tool calls, plans) are consumed but not
|
|
427
|
+
// surfaced — the subagent returns only its final answer.
|
|
428
|
+
return Promise.resolve()
|
|
429
|
+
})
|
|
430
|
+
.onRequest(methods.client.session.requestPermission, ({ params }) => {
|
|
431
|
+
// Auto-answer by the configured policy. `allow` selects the first option
|
|
432
|
+
// whose kind is `allow_once` or `allow_always`; if the child offered none (or we
|
|
433
|
+
// reject), answer `cancelled` so the child does not proceed.
|
|
434
|
+
if (spec.permission === 'allow') {
|
|
435
|
+
const allow = params.options.find(o => o.kind === 'allow_once' || o.kind === 'allow_always')
|
|
436
|
+
if (allow !== undefined) {
|
|
437
|
+
latestPermission = {
|
|
438
|
+
policy: 'allow',
|
|
439
|
+
request: permissionRequestKind(params.toolCall.kind),
|
|
440
|
+
decision: 'allowed',
|
|
441
|
+
}
|
|
442
|
+
return Promise.resolve({ outcome: { outcome: 'selected', optionId: allow.optionId } })
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
latestPermission = {
|
|
446
|
+
policy: spec.permission,
|
|
447
|
+
request: permissionRequestKind(params.toolCall.kind),
|
|
448
|
+
decision: 'denied',
|
|
449
|
+
}
|
|
450
|
+
return Promise.resolve({ outcome: { outcome: 'cancelled' } })
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
const connection = clientApp.connect(ndJsonStream(
|
|
454
|
+
NodeWritable.toWeb(child.stdin) as WritableStream<Uint8Array>,
|
|
455
|
+
NodeReadable.toWeb(child.stdout) as ReadableStream<Uint8Array>,
|
|
456
|
+
))
|
|
457
|
+
const agent = connection.agent
|
|
458
|
+
|
|
459
|
+
let sessionId: string | undefined
|
|
460
|
+
let startupStage: Extract<AcpFailureStage, 'initialize' | 'new-session'> = 'initialize'
|
|
461
|
+
// Cancellation settles the result without waiting for a cooperative child.
|
|
462
|
+
let signalCancelSettled!: () => void
|
|
463
|
+
const cancelSettled = new Promise<void>((resolve) => { signalCancelSettled = resolve })
|
|
464
|
+
const requestCancel = (): void => {
|
|
465
|
+
if (flags.cancelled) return
|
|
466
|
+
flags.cancelled = true
|
|
467
|
+
signalCancelSettled()
|
|
468
|
+
// Best-effort ACP cancel; process teardown remains authoritative.
|
|
469
|
+
/* v8 ignore next */
|
|
470
|
+
if (sessionId !== undefined) {
|
|
471
|
+
void agent.notify(methods.agent.session.cancel, { sessionId }).catch(() => { /* child gone / no session */ })
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const onAbort = (): void => { requestCancel() }
|
|
475
|
+
request.signal.addEventListener('abort', onAbort, { once: true })
|
|
476
|
+
|
|
477
|
+
// Read at every return so a partial answer survives a later cancel/error.
|
|
478
|
+
const collectOutput = (): readonly ContentBlock[] => fold.collect() ?? []
|
|
479
|
+
|
|
480
|
+
// Establish the remote session before publishing a handle. Any failure owns
|
|
481
|
+
// the still-private process and therefore reaps it before rejecting.
|
|
482
|
+
try {
|
|
483
|
+
await Promise.race([
|
|
484
|
+
(async (): Promise<void> => {
|
|
485
|
+
await agent.request(methods.agent.initialize, {
|
|
486
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
487
|
+
// Advertise NO optional client capabilities (no fs, no terminal): the
|
|
488
|
+
// child self-serves in its own process.
|
|
489
|
+
clientCapabilities: {},
|
|
490
|
+
})
|
|
491
|
+
startupStage = 'new-session'
|
|
492
|
+
const session = await agent.request(methods.agent.session.new, { cwd: spec.cwd, mcpServers: [] })
|
|
493
|
+
const returnedSessionId: unknown = Reflect.get(session, 'sessionId')
|
|
494
|
+
if (typeof returnedSessionId !== 'string') {
|
|
495
|
+
throw new AcpRunFailure(
|
|
496
|
+
{ stage: 'new-session', category: 'protocol' },
|
|
497
|
+
new Error('ACP child published without a session id'),
|
|
498
|
+
)
|
|
499
|
+
}
|
|
500
|
+
sessionId = returnedSessionId
|
|
501
|
+
/* v8 ignore next -- cancelSettled wins the startup race before this post-response guard can settle it. */
|
|
502
|
+
if (flags.cancelled) throw new Error('subagent cancelled before the ACP session started')
|
|
503
|
+
})(),
|
|
504
|
+
processRejected,
|
|
505
|
+
cancelSettled.then((): never => { throw new Error('subagent cancelled before the ACP session started') }),
|
|
506
|
+
])
|
|
507
|
+
} catch (error: unknown) {
|
|
508
|
+
request.signal.removeEventListener('abort', onAbort)
|
|
509
|
+
const cancelledBeforeCleanup = flags.cancelled
|
|
510
|
+
// A child closing its protocol stream can precede whole-range exit
|
|
511
|
+
// observation. Local cancellation does not need the discarded startup
|
|
512
|
+
// classification; other failures use the configured process grace.
|
|
513
|
+
const observedOutcome = !cancelledBeforeCleanup && !(error instanceof AcpRunFailure)
|
|
514
|
+
? await observeProcessOutcome()
|
|
515
|
+
: undefined
|
|
516
|
+
const startup = cancelledBeforeCleanup
|
|
517
|
+
? { kind: 'cancelled' } as const
|
|
518
|
+
: {
|
|
519
|
+
kind: 'failed',
|
|
520
|
+
failure: error instanceof AcpRunFailure
|
|
521
|
+
? error
|
|
522
|
+
: startupFailure(error, startupStage, observedOutcome),
|
|
523
|
+
} as const
|
|
524
|
+
if (startup.kind === 'cancelled') {
|
|
525
|
+
// Local cancellation owns the startup outcome; only cleanup failure is
|
|
526
|
+
// reported below when teardown itself rejects.
|
|
527
|
+
} else {
|
|
528
|
+
reportFailure(spec, error instanceof AcpRunFailure
|
|
529
|
+
? error.cause
|
|
530
|
+
: processFailure ?? error)
|
|
531
|
+
}
|
|
532
|
+
try {
|
|
533
|
+
await disposeProcess()
|
|
534
|
+
} catch (cleanupError: unknown) {
|
|
535
|
+
reportFailure(spec, cleanupError)
|
|
536
|
+
const cleanupFailure = new AcpRunFailure({
|
|
537
|
+
stage: 'teardown',
|
|
538
|
+
category: processOutcome === undefined ? 'unknown' : 'process-exit',
|
|
539
|
+
...(processOutcome === undefined ? {} : { outcome: processOutcome }),
|
|
540
|
+
}, cleanupError)
|
|
541
|
+
if (startup.kind === 'cancelled') {
|
|
542
|
+
throw new AggregateError([cleanupFailure], cleanupFailure.message)
|
|
543
|
+
}
|
|
544
|
+
throw new AggregateError(
|
|
545
|
+
[startup.failure, cleanupFailure],
|
|
546
|
+
`${startup.failure.message}; ${cleanupFailure.message}`,
|
|
547
|
+
)
|
|
548
|
+
}
|
|
549
|
+
if (startup.kind === 'cancelled') {
|
|
550
|
+
throw new Error('subagent request was aborted before the ACP child started')
|
|
551
|
+
}
|
|
552
|
+
throw startup.failure
|
|
553
|
+
}
|
|
554
|
+
// The startup transaction validates the returned id before it can fulfill.
|
|
555
|
+
// This assertion carries that cross-closure invariant into TypeScript.
|
|
556
|
+
/* v8 ignore next */
|
|
557
|
+
if (sessionId === undefined) throw new Error('unreachable: ACP startup fulfilled without a session id')
|
|
558
|
+
const remoteSessionId = sessionId
|
|
559
|
+
|
|
560
|
+
let diagnostic: string | undefined
|
|
561
|
+
const result: Promise<SubagentResult> = settleRunResult({
|
|
562
|
+
attempt: async (): Promise<SubagentResult> => {
|
|
563
|
+
try {
|
|
564
|
+
const promptResult = await Promise.race([
|
|
565
|
+
agent.request(methods.agent.session.prompt, {
|
|
566
|
+
sessionId: remoteSessionId,
|
|
567
|
+
prompt: toAcpPrompt(request.prompt),
|
|
568
|
+
}),
|
|
569
|
+
cancelSettled.then((): never => { throw new Error('subagent cancelled while the ACP prompt was running') }),
|
|
570
|
+
])
|
|
571
|
+
const stopReason = acpStopReason(promptResult.stopReason)
|
|
572
|
+
diagnostic = terminalFailure(promptResult.stopReason, latestPermission)
|
|
573
|
+
return {
|
|
574
|
+
output: collectOutput(),
|
|
575
|
+
...(diagnostic === undefined ? {} : { diagnostic }),
|
|
576
|
+
stopReason,
|
|
577
|
+
}
|
|
578
|
+
} catch (error: unknown) {
|
|
579
|
+
if (!flags.cancelled) {
|
|
580
|
+
const outcome = await observeProcessOutcome(request.signal)
|
|
581
|
+
const facts = outcome === undefined
|
|
582
|
+
? { stage: 'prompt', category: 'transport' } as const
|
|
583
|
+
: { stage: 'process', category: 'process-exit', outcome } as const
|
|
584
|
+
diagnostic = diagnosticText(facts, latestPermission)
|
|
585
|
+
}
|
|
586
|
+
throw processFailure ?? error
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
collectOutput,
|
|
590
|
+
collectDiagnostic: () => diagnostic,
|
|
591
|
+
cancelled: () => flags.cancelled,
|
|
592
|
+
onError: spec.onError,
|
|
593
|
+
signal: request.signal,
|
|
594
|
+
onAbort,
|
|
595
|
+
})
|
|
596
|
+
|
|
597
|
+
return subprocessRunHandle({
|
|
598
|
+
id,
|
|
599
|
+
result,
|
|
600
|
+
signal: request.signal,
|
|
601
|
+
onAbort,
|
|
602
|
+
requestCancel,
|
|
603
|
+
teardown: async () => {
|
|
604
|
+
try {
|
|
605
|
+
// ACP normally quiesces from stdin EOF, including the final flush, so
|
|
606
|
+
// this backend uses a wider EOF grace before process termination.
|
|
607
|
+
await disposeProcess()
|
|
608
|
+
} catch (error: unknown) {
|
|
609
|
+
reportFailure(spec, error)
|
|
610
|
+
throw new AcpRunFailure({
|
|
611
|
+
stage: 'teardown',
|
|
612
|
+
category: processOutcome === undefined ? 'unknown' : 'process-exit',
|
|
613
|
+
...(processOutcome === undefined ? {} : { outcome: processOutcome }),
|
|
614
|
+
}, error)
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
})
|
|
618
|
+
}
|