@deepseek-ai/dsh-subagent-claude-code 0.2.2-alpha.3 → 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.
- package/README.i18n.yaml +4 -4
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/process.d.ts.map +1 -0
- package/lib/types/process.js.map +1 -0
- package/lib/types/run.d.ts.map +1 -0
- package/lib/types/run.js.map +1 -0
- package/package.json +32 -29
- package/src/index.ts +147 -0
- package/src/process.ts +159 -0
- package/src/run.ts +587 -0
package/README.i18n.yaml
CHANGED
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
en: fbee5e4ab396c184
|
|
25
25
|
zh: dcf94832918d5010
|
|
26
26
|
/deepseek-ai-dsh-subagent-claude-code/use-this-package/exposing-the-tool:
|
|
27
|
-
en:
|
|
28
|
-
zh:
|
|
27
|
+
en: e070599b4ff8dd79
|
|
28
|
+
zh: 105e7a4dfee82efe
|
|
29
29
|
/deepseek-ai-dsh-subagent-claude-code/use-this-package/what-you-get:
|
|
30
30
|
en: a731eabea54893d5
|
|
31
31
|
zh: e370dba101b3a7e8
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
en: 4c391bb16e3cd380
|
|
67
67
|
zh: ab3847efe35fa6dc
|
|
68
68
|
/deepseek-ai-dsh-subagent-claude-code/model-experience/parent-scheduling-and-results-indirectly/what-the-model-sees:
|
|
69
|
-
en:
|
|
70
|
-
zh:
|
|
69
|
+
en: 7e75fac459085412
|
|
70
|
+
zh: 4d8e41b0baada834
|
|
71
71
|
/deepseek-ai-dsh-subagent-claude-code/model-experience/parent-scheduling-and-results-indirectly/token-effect:
|
|
72
72
|
en: 0c436fb0897a6eca
|
|
73
73
|
zh: 7ec0a953d0232af2
|
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ The bundle inserts `tool-subagent-claude-code` as a Host row, so `subagent_claud
|
|
|
72
72
|
maxDepth: provider-managed
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
The tool returns
|
|
75
|
+
The tool returns the child's name after accepting the task and sends its result to the parent Agent on completion. Each external activation executes once and accepts no follow-up input or resume.
|
|
76
76
|
|
|
77
77
|
### What you get
|
|
78
78
|
|
|
@@ -149,7 +149,7 @@ Independent of the parent request cache. Reuse depends only on Claude Code's own
|
|
|
149
149
|
|
|
150
150
|
#### What the model sees
|
|
151
151
|
|
|
152
|
-
Through `dsh-tool-subagent`, the parent model first receives
|
|
152
|
+
Through `dsh-tool-subagent`, the parent model first receives the child's name, then the final Claude Code answer or a failure notice with its stop reason and safe diagnostic. Diagnostics contain only fixed stage, category, and observed protocol or process facts. Product reasoning, intermediate messages, tool activity, stderr, usage, product identifiers, commands, paths, and raw protocol payloads are not copied into the parent Session.
|
|
153
153
|
|
|
154
154
|
#### Token effect
|
|
155
155
|
|
package/README.zh.md
CHANGED
|
@@ -72,7 +72,7 @@ Bundle 将 `tool-subagent-claude-code` 作为 Host 条目插入,因此 `subage
|
|
|
72
72
|
maxDepth: provider-managed
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
工具接受任务后返回子任务名称;任务完成后向父 agent 发送结果通知。外部 activation 只执行一次,不支持追加输入或恢复对话。
|
|
76
76
|
|
|
77
77
|
### 你会得到什么
|
|
78
78
|
|
|
@@ -149,7 +149,7 @@ Claude Code 子级会在一个全新的 SDK query 中接收独立文本任务。
|
|
|
149
149
|
|
|
150
150
|
#### 模型看到什么
|
|
151
151
|
|
|
152
|
-
通过 `dsh-tool-subagent
|
|
152
|
+
通过 `dsh-tool-subagent`,父模型先收到子任务名称,随后收到 Claude Code 最终答案或带停止原因与安全诊断的失败通知。诊断只包含固定的阶段、类别和已观测的协议或进程事实。产品推理、中间消息、工具活动、stderr、用量、产品标识符、命令、路径与原始协议载荷不会复制到父 Session。
|
|
153
153
|
|
|
154
154
|
#### Token 影响
|
|
155
155
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAUxC,OAAO,EAML,KAAK,wBAAwB,EAE9B,MAAM,UAAU,CAAA;AAEjB,eAAO,MAAM,IAAI,yBAAyB,CAAA;AAC1C,eAAO,MAAM,MAAM,UAA8B,CAAA;AAMjD,qFAAqF;AACrF,MAAM,WAAW,MAAM;IACrB,gEAAgE;IAChE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,wBAAwB,CAAA;IACzC,iFAAiF;IACjF,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAO3B,CAAA;AAoDF;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAuBxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,GAIhB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,4BAA4B,EAC5B,mCAAmC,EACnC,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,GAGnB,MAAM,U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,IAAI,EAAE;YACnB,IAAI,CAAC;gBACH,MAAM,sBAAsB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA;YAC9D,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACxB,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;gBAC7B,aAAa,CAAC,OAAO,CAAC,CAAA;gBACtB,MAAM,OAAO,CAAA;YACf,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-claude-code",
|
|
3
3
|
"description": "One-shot Claude Code subagent provider over the official Agent SDK",
|
|
4
|
-
"version": "0.2.2-
|
|
4
|
+
"version": "0.2.2-rc.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -28,7 +28,10 @@
|
|
|
28
28
|
"locale/*.json",
|
|
29
29
|
"lib/index.js",
|
|
30
30
|
"cordis.patch.yml",
|
|
31
|
-
"lib/types/**/*.d.ts"
|
|
31
|
+
"lib/types/**/*.d.ts",
|
|
32
|
+
"lib/types/**/*.d.ts.map",
|
|
33
|
+
"lib/**/*.js.map",
|
|
34
|
+
"src"
|
|
32
35
|
],
|
|
33
36
|
"license": "MIT",
|
|
34
37
|
"dsh": {
|
|
@@ -37,40 +40,40 @@
|
|
|
37
40
|
}
|
|
38
41
|
},
|
|
39
42
|
"peerDependencies": {
|
|
40
|
-
"@deepseek-ai/cordis": "~4.0
|
|
41
|
-
"@deepseek-ai/dsh-llm": "0.2.2-
|
|
42
|
-
"@deepseek-ai/dsh-session": "0.2.2-
|
|
43
|
-
"@deepseek-ai/dsh-subagent": "0.2.2-
|
|
44
|
-
"@deepseek-ai/dsh-subprocess": "0.2.2-
|
|
45
|
-
"@deepseek-ai/dsh-timeout": "0.2.2-
|
|
43
|
+
"@deepseek-ai/cordis": "~4.1.0",
|
|
44
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.2",
|
|
45
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
46
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.2",
|
|
47
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.2",
|
|
48
|
+
"@deepseek-ai/dsh-timeout": "0.2.2-rc.2"
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
51
|
"@anthropic-ai/claude-agent-sdk": "0.3.263",
|
|
49
52
|
"@anthropic-ai/sdk": "0.93.0",
|
|
50
|
-
"@deepseek-ai/dsh-brand": "0.2.2-
|
|
51
|
-
"@deepseek-ai/schemastery": "~3.
|
|
53
|
+
"@deepseek-ai/dsh-brand": "0.2.2-rc.2",
|
|
54
|
+
"@deepseek-ai/schemastery": "~3.19.0",
|
|
52
55
|
"@modelcontextprotocol/sdk": "^1.31.0",
|
|
53
|
-
"zod": "4.
|
|
54
|
-
"@deepseek-ai/dsh-tool-subagent": "0.2.2-
|
|
56
|
+
"zod": "4.6.6",
|
|
57
|
+
"@deepseek-ai/dsh-tool-subagent": "0.2.2-rc.2"
|
|
55
58
|
},
|
|
56
59
|
"devDependencies": {
|
|
57
|
-
"@deepseek-ai/cordis": "~4.0
|
|
58
|
-
"@deepseek-ai/dsh-agent": "0.2.2-
|
|
59
|
-
"@deepseek-ai/dsh-app-boot": "0.2.2-
|
|
60
|
-
"@deepseek-ai/dsh-llm": "0.2.2-
|
|
61
|
-
"@deepseek-ai/dsh-loader-smoke": "0.2.2-
|
|
62
|
-
"@deepseek-ai/dsh-session": "0.2.2-
|
|
63
|
-
"@deepseek-ai/dsh-session-checkpoint-policy": "0.2.2-
|
|
64
|
-
"@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-
|
|
65
|
-
"@deepseek-ai/dsh-session-projection": "0.2.2-
|
|
66
|
-
"@deepseek-ai/dsh-subagent": "0.2.2-
|
|
67
|
-
"@deepseek-ai/dsh-subagent-codex": "0.2.2-
|
|
68
|
-
"@deepseek-ai/dsh-subprocess": "0.2.2-
|
|
69
|
-
"@deepseek-ai/dsh-subprocess-local": "0.2.2-
|
|
70
|
-
"@deepseek-ai/dsh-timeout": "0.2.2-
|
|
71
|
-
"@deepseek-ai/dsh-tool-jobs": "0.2.2-
|
|
72
|
-
"@deepseek-ai/dsh-tools": "0.2.2-
|
|
73
|
-
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-
|
|
60
|
+
"@deepseek-ai/cordis": "~4.1.0",
|
|
61
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.2",
|
|
62
|
+
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.2",
|
|
63
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.2",
|
|
64
|
+
"@deepseek-ai/dsh-loader-smoke": "0.2.2-rc.2",
|
|
65
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
66
|
+
"@deepseek-ai/dsh-session-checkpoint-policy": "0.2.2-rc.2",
|
|
67
|
+
"@deepseek-ai/dsh-session-persistence-jsonl": "0.2.2-rc.2",
|
|
68
|
+
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.2",
|
|
69
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.2",
|
|
70
|
+
"@deepseek-ai/dsh-subagent-codex": "0.2.2-rc.2",
|
|
71
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.2",
|
|
72
|
+
"@deepseek-ai/dsh-subprocess-local": "0.2.2-rc.2",
|
|
73
|
+
"@deepseek-ai/dsh-timeout": "0.2.2-rc.2",
|
|
74
|
+
"@deepseek-ai/dsh-tool-jobs": "0.2.2-rc.2",
|
|
75
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.2",
|
|
76
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-rc.2"
|
|
74
77
|
},
|
|
75
78
|
"icon": "./icon.svg"
|
|
76
79
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile-named Claude Code one-shot subagent provider. Every accepted run
|
|
3
|
+
* invokes the official Agent SDK in the delegating Session's workspace and
|
|
4
|
+
* places the SDK-spawned real CLI under the shared subprocess owner.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent-claude-code
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
10
|
+
import z from '@deepseek-ai/schemastery'
|
|
11
|
+
import { MAX_TIMER_DELAY_MS } from '@deepseek-ai/dsh-timeout'
|
|
12
|
+
import {
|
|
13
|
+
assertPositiveFinite,
|
|
14
|
+
NO_START_CAPABILITIES,
|
|
15
|
+
assertUsableCwd,
|
|
16
|
+
type ResolvedSubagentStartRequest,
|
|
17
|
+
type SubagentCapabilities,
|
|
18
|
+
type SubagentProvider,
|
|
19
|
+
} from '@deepseek-ai/dsh-subagent'
|
|
20
|
+
import {
|
|
21
|
+
CLAUDE_CODE_PERMISSION_MODES,
|
|
22
|
+
DEFAULT_CLAUDE_CODE_PERMISSION_MODE,
|
|
23
|
+
DEFAULT_DISPOSE_GRACE_MS,
|
|
24
|
+
claudeCodeStartupFailure,
|
|
25
|
+
startClaudeCodeRun,
|
|
26
|
+
type ClaudeCodePermissionMode,
|
|
27
|
+
type ClaudeCodeRunSpec,
|
|
28
|
+
} from './run.ts'
|
|
29
|
+
|
|
30
|
+
export const name = 'subagent-claude-code'
|
|
31
|
+
export const inject = ['subagents', 'subprocess']
|
|
32
|
+
|
|
33
|
+
const DEFAULT_PROVIDER_NAME = 'claude-code'
|
|
34
|
+
|
|
35
|
+
/* jscpd:ignore-start -- sibling product providers intentionally expose
|
|
36
|
+
* overlapping deployment-owned fields without adding a shared config owner. */
|
|
37
|
+
/** Deployment-owned model, permission, environment, and process-release settings. */
|
|
38
|
+
export interface Config {
|
|
39
|
+
/** Provider name on `ctx.subagents` (default `claude-code`). */
|
|
40
|
+
providerName?: string
|
|
41
|
+
/** Native Claude model fixed for this instance; omitted to inherit Claude settings. */
|
|
42
|
+
model?: string
|
|
43
|
+
/**
|
|
44
|
+
* Explicit environment entries layered over the subprocess seam's
|
|
45
|
+
* credential-scrubbed parent environment.
|
|
46
|
+
*/
|
|
47
|
+
env?: Record<string, string>
|
|
48
|
+
/**
|
|
49
|
+
* Native non-interactive mode fixed for this Provider instance. Defaults to
|
|
50
|
+
* `dontAsk`; `acceptEdits` accepts edits, `auto` uses the native classifier,
|
|
51
|
+
* `plan` returns a plan without approving execution, and
|
|
52
|
+
* `bypassPermissions` explicitly skips permission checks.
|
|
53
|
+
*/
|
|
54
|
+
permissionMode?: ClaudeCodePermissionMode
|
|
55
|
+
/** Grace in milliseconds between Claude Code managed-range termination tiers. */
|
|
56
|
+
disposeGraceMs?: number
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const Config: z<Config> = z.object({
|
|
60
|
+
providerName: z.string().min(1).default(DEFAULT_PROVIDER_NAME),
|
|
61
|
+
model: z.string().min(1),
|
|
62
|
+
env: z.dict(z.string()).default({}),
|
|
63
|
+
permissionMode: z.union([...CLAUDE_CODE_PERMISSION_MODES])
|
|
64
|
+
.default(DEFAULT_CLAUDE_CODE_PERMISSION_MODE),
|
|
65
|
+
disposeGraceMs: z.number().default(DEFAULT_DISPOSE_GRACE_MS),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
type ResolvedConfig = Omit<Required<Config>, 'model'> & Pick<Config, 'model'>
|
|
69
|
+
/* jscpd:ignore-end */
|
|
70
|
+
|
|
71
|
+
/* jscpd:ignore-start -- Cordis registration and shared-seam plumbing mirror
|
|
72
|
+
* the Codex sibling; each product's lifecycle remains package-private. */
|
|
73
|
+
class ClaudeCodeProvider implements SubagentProvider {
|
|
74
|
+
readonly capabilities: SubagentCapabilities = NO_START_CAPABILITIES
|
|
75
|
+
readonly inheritsParentContext = false
|
|
76
|
+
|
|
77
|
+
constructor(
|
|
78
|
+
readonly name: string,
|
|
79
|
+
private readonly ctx: Context,
|
|
80
|
+
private readonly config: ResolvedConfig,
|
|
81
|
+
) {}
|
|
82
|
+
|
|
83
|
+
async start(request: ResolvedSubagentStartRequest) {
|
|
84
|
+
let cwd: string
|
|
85
|
+
try {
|
|
86
|
+
cwd = assertUsableCwd('subagent-claude-code', 'child cwd', request.cwd)
|
|
87
|
+
} catch (error: unknown) {
|
|
88
|
+
if (request.signal.aborted) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
'subagent-claude-code: request was aborted before SDK startup',
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
const failure = claudeCodeStartupFailure(error)
|
|
94
|
+
this.ctx.logger.warn(
|
|
95
|
+
`subagent-claude-code "${this.name}": child start failed: %o`,
|
|
96
|
+
failure,
|
|
97
|
+
)
|
|
98
|
+
throw failure
|
|
99
|
+
}
|
|
100
|
+
const spec: ClaudeCodeRunSpec = {
|
|
101
|
+
cwd,
|
|
102
|
+
...this.config.model === undefined ? {} : { model: this.config.model },
|
|
103
|
+
permissionMode: this.config.permissionMode,
|
|
104
|
+
env: this.config.env,
|
|
105
|
+
disposeGraceMs: this.config.disposeGraceMs,
|
|
106
|
+
spawn: spawnSpec => this.ctx.subprocess.spawn(spawnSpec),
|
|
107
|
+
onError: (error, stopReason) => {
|
|
108
|
+
this.ctx.logger.warn(
|
|
109
|
+
`subagent-claude-code "${this.name}": child run failed (${stopReason}): %o`,
|
|
110
|
+
error,
|
|
111
|
+
)
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
return startClaudeCodeRun(request, spec)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Register one Profile-named Claude Code provider.
|
|
120
|
+
* @param ctx - context carrying shared subagent and subprocess services.
|
|
121
|
+
* @param config - registry name, optional model, permission mode, child environment, and disposal grace.
|
|
122
|
+
*/
|
|
123
|
+
export function apply(ctx: Context, config: Config): void {
|
|
124
|
+
const resolved: ResolvedConfig = {
|
|
125
|
+
providerName: config.providerName ?? DEFAULT_PROVIDER_NAME,
|
|
126
|
+
...config.model === undefined ? {} : { model: config.model },
|
|
127
|
+
env: config.env as Record<string, string>,
|
|
128
|
+
permissionMode: config.permissionMode ?? DEFAULT_CLAUDE_CODE_PERMISSION_MODE,
|
|
129
|
+
disposeGraceMs: config.disposeGraceMs as number,
|
|
130
|
+
}
|
|
131
|
+
assertPositiveFinite(
|
|
132
|
+
'subagent-claude-code',
|
|
133
|
+
'disposeGraceMs',
|
|
134
|
+
resolved.disposeGraceMs,
|
|
135
|
+
)
|
|
136
|
+
if (resolved.disposeGraceMs > MAX_TIMER_DELAY_MS) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`subagent-claude-code: disposeGraceMs must be no greater than ${MAX_TIMER_DELAY_MS}`,
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
ctx.subagents.registerProvider(new ClaudeCodeProvider(
|
|
142
|
+
resolved.providerName,
|
|
143
|
+
ctx,
|
|
144
|
+
resolved,
|
|
145
|
+
))
|
|
146
|
+
}
|
|
147
|
+
/* jscpd:ignore-end */
|
package/src/process.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Projection from the shared managed-process handle to the official Claude
|
|
3
|
+
* Agent SDK's custom-spawn process interface.
|
|
4
|
+
*
|
|
5
|
+
* @module @deepseek-ai/dsh-subagent-claude-code/process
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { EventEmitter } from 'node:events'
|
|
9
|
+
import type {
|
|
10
|
+
SpawnedProcess,
|
|
11
|
+
SpawnOptions,
|
|
12
|
+
} from '@anthropic-ai/claude-agent-sdk'
|
|
13
|
+
import {
|
|
14
|
+
scrubbedParentEnv,
|
|
15
|
+
type SubprocessHandle,
|
|
16
|
+
type SubprocessOutcome,
|
|
17
|
+
type SubprocessSpawnSpec,
|
|
18
|
+
} from '@deepseek-ai/dsh-subprocess'
|
|
19
|
+
|
|
20
|
+
function thrown(value: unknown): Error {
|
|
21
|
+
/* v8 ignore next -- the subprocess seam rejects with Error. */
|
|
22
|
+
return value instanceof Error ? value : new Error(String(value))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Encode the SDK's complete child environment as a subprocess overlay.
|
|
27
|
+
* @param env - SDK-composed child environment after its removals and replacements.
|
|
28
|
+
* @returns explicit values plus tombstones for surviving ambient names the SDK removed.
|
|
29
|
+
*/
|
|
30
|
+
export function sdkEnvironmentOverlay(
|
|
31
|
+
env: SpawnOptions['env'],
|
|
32
|
+
): NodeJS.ProcessEnv {
|
|
33
|
+
const overlay: NodeJS.ProcessEnv = { ...env }
|
|
34
|
+
for (const name of Object.keys(scrubbedParentEnv())) {
|
|
35
|
+
if (!(name in env)) overlay[name] = undefined
|
|
36
|
+
}
|
|
37
|
+
return overlay
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Translate one official SDK spawn request to the shared process owner.
|
|
42
|
+
* @param options - command, arguments, workspace, environment, and forwarded signal from the SDK.
|
|
43
|
+
* @param graceMs - managed-range termination grace.
|
|
44
|
+
* @returns the fully explicit shared subprocess request.
|
|
45
|
+
*/
|
|
46
|
+
export function claudeSpawnSpec(
|
|
47
|
+
options: SpawnOptions,
|
|
48
|
+
graceMs: number,
|
|
49
|
+
): SubprocessSpawnSpec {
|
|
50
|
+
if (options.cwd === undefined || options.cwd.length === 0) {
|
|
51
|
+
throw new Error('subagent-claude-code: SDK spawn request omitted its workspace')
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
argv: [options.command, ...options.args],
|
|
55
|
+
cwd: options.cwd,
|
|
56
|
+
stdio: { stdin: 'pipe', stdout: 'pipe', stderr: 'inherit' },
|
|
57
|
+
graceMs,
|
|
58
|
+
signal: options.signal,
|
|
59
|
+
env: sdkEnvironmentOverlay(options.env),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* SDK-facing view of one shared managed process. Protocol transport remains
|
|
65
|
+
* in the official SDK; this adapter only projects streams and exit events.
|
|
66
|
+
*/
|
|
67
|
+
export class ManagedClaudeCodeProcess implements SpawnedProcess {
|
|
68
|
+
readonly stdin
|
|
69
|
+
readonly stdout
|
|
70
|
+
private readonly events = new EventEmitter()
|
|
71
|
+
private outcomeValue: SubprocessOutcome | undefined
|
|
72
|
+
private killRequested = false
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Project a managed process with piped stdin and stdout.
|
|
76
|
+
* @param child - shared handle that remains the managed-range authority.
|
|
77
|
+
*/
|
|
78
|
+
constructor(private readonly child: SubprocessHandle) {
|
|
79
|
+
this.stdin = child.stdin as NonNullable<SubprocessHandle['stdin']>
|
|
80
|
+
this.stdout = child.stdout as NonNullable<SubprocessHandle['stdout']>
|
|
81
|
+
// EventEmitter gives `error` special throw semantics without a listener.
|
|
82
|
+
// The SDK attaches its listener synchronously after custom spawn returns,
|
|
83
|
+
// while this no-op also contains an already-rejected spawn handle.
|
|
84
|
+
this.events.on('error', () => {})
|
|
85
|
+
void child.done.then(
|
|
86
|
+
(outcome) => {
|
|
87
|
+
this.outcomeValue = outcome
|
|
88
|
+
this.events.emit('exit', outcome.exitCode, outcome.signal)
|
|
89
|
+
},
|
|
90
|
+
(error: unknown) => {
|
|
91
|
+
this.events.emit('error', thrown(error))
|
|
92
|
+
},
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Whether the SDK has requested managed-range termination. */
|
|
97
|
+
get killed(): boolean {
|
|
98
|
+
return this.killRequested
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Direct-child exit code, or null while running or after signal exit. */
|
|
102
|
+
get exitCode(): number | null {
|
|
103
|
+
return this.outcomeValue?.exitCode ?? null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Direct-child terminating signal, if any. */
|
|
107
|
+
get signalCode(): NodeJS.Signals | null {
|
|
108
|
+
return this.outcomeValue?.signal ?? null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Exact managed-process outcome after exit, or undefined while running. */
|
|
112
|
+
get outcome(): SubprocessOutcome | undefined {
|
|
113
|
+
return this.outcomeValue
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Route the SDK's termination request to the managed-range process owner.
|
|
118
|
+
* @param _signal - SDK-selected signal; the shared seam owns its escalation ladder.
|
|
119
|
+
* @returns false only after exit or a previous termination request.
|
|
120
|
+
*/
|
|
121
|
+
kill(_signal: NodeJS.Signals): boolean {
|
|
122
|
+
if (
|
|
123
|
+
this.killRequested
|
|
124
|
+
|| this.outcomeValue !== undefined
|
|
125
|
+
) {
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
this.killRequested = true
|
|
129
|
+
this.child.terminate()
|
|
130
|
+
return true
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Register a persistent process lifecycle listener. */
|
|
134
|
+
on(
|
|
135
|
+
event: 'exit' | 'error',
|
|
136
|
+
listener: ((code: number | null, signal: NodeJS.Signals | null) => void)
|
|
137
|
+
| ((error: Error) => void),
|
|
138
|
+
): void {
|
|
139
|
+
this.events.on(event, listener)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Register a one-shot process lifecycle listener. */
|
|
143
|
+
once(
|
|
144
|
+
event: 'exit' | 'error',
|
|
145
|
+
listener: ((code: number | null, signal: NodeJS.Signals | null) => void)
|
|
146
|
+
| ((error: Error) => void),
|
|
147
|
+
): void {
|
|
148
|
+
this.events.once(event, listener)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Remove a process lifecycle listener. */
|
|
152
|
+
off(
|
|
153
|
+
event: 'exit' | 'error',
|
|
154
|
+
listener: ((code: number | null, signal: NodeJS.Signals | null) => void)
|
|
155
|
+
| ((error: Error) => void),
|
|
156
|
+
): void {
|
|
157
|
+
this.events.off(event, listener)
|
|
158
|
+
}
|
|
159
|
+
}
|
package/src/run.ts
ADDED
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot Claude Code lifecycle: invoke the official Agent SDK, place its
|
|
3
|
+
* real CLI process under the shared subprocess owner, map only strict SDK
|
|
4
|
+
* success to completion, and dispose to whole-range quiescence.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent-claude-code/run
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { randomUUID } from 'node:crypto'
|
|
10
|
+
import {
|
|
11
|
+
query as officialQuery,
|
|
12
|
+
type Options,
|
|
13
|
+
type Query,
|
|
14
|
+
type SDKMessage,
|
|
15
|
+
type SDKResultMessage,
|
|
16
|
+
type SpawnOptions,
|
|
17
|
+
} from '@anthropic-ai/claude-agent-sdk'
|
|
18
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
|
|
19
|
+
import { brandString } from '@deepseek-ai/dsh-brand'
|
|
20
|
+
import type { SessionId } from '@deepseek-ai/dsh-session'
|
|
21
|
+
import {
|
|
22
|
+
settleRunResult,
|
|
23
|
+
subprocessRunHandle,
|
|
24
|
+
type SubagentResult,
|
|
25
|
+
type SubagentRun,
|
|
26
|
+
type SubagentStartRequest,
|
|
27
|
+
type SubagentStopReason,
|
|
28
|
+
} from '@deepseek-ai/dsh-subagent'
|
|
29
|
+
import {
|
|
30
|
+
scrubbedParentEnv,
|
|
31
|
+
type SubprocessHandle,
|
|
32
|
+
type SubprocessOutcome,
|
|
33
|
+
type SubprocessSpawnSpec,
|
|
34
|
+
} from '@deepseek-ai/dsh-subprocess'
|
|
35
|
+
import {
|
|
36
|
+
claudeSpawnSpec,
|
|
37
|
+
ManagedClaudeCodeProcess,
|
|
38
|
+
} from './process.ts'
|
|
39
|
+
|
|
40
|
+
/** Default POSIX grace between subprocess termination tiers. */
|
|
41
|
+
export const DEFAULT_DISPOSE_GRACE_MS = 3_000
|
|
42
|
+
|
|
43
|
+
/** Claude Code permission modes that cannot wait for a human response. */
|
|
44
|
+
export const CLAUDE_CODE_PERMISSION_MODES = [
|
|
45
|
+
'dontAsk',
|
|
46
|
+
'acceptEdits',
|
|
47
|
+
'auto',
|
|
48
|
+
'plan',
|
|
49
|
+
'bypassPermissions',
|
|
50
|
+
] as const satisfies readonly NonNullable<Options['permissionMode']>[]
|
|
51
|
+
|
|
52
|
+
/** Profile-selectable non-interactive Claude Code permission mode. */
|
|
53
|
+
export type ClaudeCodePermissionMode = typeof CLAUDE_CODE_PERMISSION_MODES[number]
|
|
54
|
+
|
|
55
|
+
/** Safe default for unattended Claude Code runs. */
|
|
56
|
+
export const DEFAULT_CLAUDE_CODE_PERMISSION_MODE: ClaudeCodePermissionMode = 'dontAsk'
|
|
57
|
+
|
|
58
|
+
const SUPPORTED_UNATTENDED_DIALOG_KINDS = [
|
|
59
|
+
'refusal_fallback_prompt',
|
|
60
|
+
] satisfies NonNullable<Options['supportedDialogKinds']>
|
|
61
|
+
|
|
62
|
+
type ClaudeCodeFailureStage =
|
|
63
|
+
| 'query-start'
|
|
64
|
+
| 'query-run'
|
|
65
|
+
| 'process'
|
|
66
|
+
| 'teardown'
|
|
67
|
+
|
|
68
|
+
type ClaudeCodeFailureCategory =
|
|
69
|
+
| 'limit'
|
|
70
|
+
| 'product-error'
|
|
71
|
+
| 'invalid-result'
|
|
72
|
+
| 'process'
|
|
73
|
+
| 'unknown'
|
|
74
|
+
|
|
75
|
+
interface ClaudeCodeFailureFacts {
|
|
76
|
+
readonly stage: ClaudeCodeFailureStage
|
|
77
|
+
readonly category: ClaudeCodeFailureCategory
|
|
78
|
+
readonly outcome?: SubprocessOutcome | undefined
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function failureDiagnostic(facts: ClaudeCodeFailureFacts): string {
|
|
82
|
+
const fields = [
|
|
83
|
+
'product: Claude Code',
|
|
84
|
+
`stage: ${facts.stage}`,
|
|
85
|
+
`category: ${facts.category}`,
|
|
86
|
+
]
|
|
87
|
+
const exitCode = facts.outcome?.exitCode
|
|
88
|
+
if (exitCode !== null && exitCode !== undefined) {
|
|
89
|
+
fields.push(`exit code: ${exitCode}`)
|
|
90
|
+
}
|
|
91
|
+
const signal = facts.outcome?.signal
|
|
92
|
+
if (signal !== null && signal !== undefined) {
|
|
93
|
+
fields.push(`signal: ${signal}`)
|
|
94
|
+
}
|
|
95
|
+
return `Product subagent failure (${fields.join('; ')})`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class ClaudeCodeFailure extends Error {
|
|
99
|
+
constructor(
|
|
100
|
+
readonly facts: ClaudeCodeFailureFacts,
|
|
101
|
+
cause?: unknown,
|
|
102
|
+
) {
|
|
103
|
+
super(
|
|
104
|
+
`subagent-claude-code: ${failureDiagnostic(facts)}`,
|
|
105
|
+
cause === undefined ? undefined : { cause },
|
|
106
|
+
)
|
|
107
|
+
this.name = 'ClaudeCodeFailure'
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function sdkFailureCategory(
|
|
112
|
+
subtype: string,
|
|
113
|
+
): ClaudeCodeFailureCategory {
|
|
114
|
+
switch (subtype) {
|
|
115
|
+
case 'error_max_turns':
|
|
116
|
+
case 'error_max_budget_usd':
|
|
117
|
+
case 'error_max_structured_output_retries':
|
|
118
|
+
return 'limit'
|
|
119
|
+
case 'error_during_execution':
|
|
120
|
+
return 'product-error'
|
|
121
|
+
default:
|
|
122
|
+
return 'unknown'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Hide an unpublished product startup failure behind fixed safe facts.
|
|
128
|
+
* @param cause - original host-side failure retained only on the Error cause chain.
|
|
129
|
+
* @returns a rejection safe to expose through the subagent start boundary.
|
|
130
|
+
*/
|
|
131
|
+
export function claudeCodeStartupFailure(cause: unknown): Error {
|
|
132
|
+
return new ClaudeCodeFailure({
|
|
133
|
+
stage: 'query-start',
|
|
134
|
+
category: 'unknown',
|
|
135
|
+
}, cause)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function unattendedDiagnostic(
|
|
139
|
+
mode: ClaudeCodePermissionMode,
|
|
140
|
+
request: 'tool permission' | 'MCP elicitation' | 'user dialog',
|
|
141
|
+
decision: 'denied' | 'declined' | 'cancelled',
|
|
142
|
+
reason: string,
|
|
143
|
+
): string {
|
|
144
|
+
return `Claude Code unattended decision (mode: ${mode}; request: ${request}; decision: ${decision}): ${reason}`
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* jscpd:ignore-start -- sibling providers intentionally keep product-private
|
|
148
|
+
* run inputs and error normalization instead of adding a shared lifecycle owner. */
|
|
149
|
+
/** Fully resolved inputs for one official Claude Agent SDK query. */
|
|
150
|
+
export interface ClaudeCodeRunSpec {
|
|
151
|
+
/** Selected child working directory supplied to the SDK and real CLI. */
|
|
152
|
+
readonly cwd: string
|
|
153
|
+
/** Profile-selected native model; omitted to preserve Claude settings. */
|
|
154
|
+
readonly model?: string
|
|
155
|
+
/** Profile-selected native non-interactive permission mode. */
|
|
156
|
+
readonly permissionMode: ClaudeCodePermissionMode
|
|
157
|
+
/** Explicit deployment/test environment layered after shared scrubbing. */
|
|
158
|
+
readonly env: Record<string, string>
|
|
159
|
+
/** Subprocess termination grace passed to the shared managed-range owner. */
|
|
160
|
+
readonly disposeGraceMs: number
|
|
161
|
+
/** Shared subprocess service spawn operation. */
|
|
162
|
+
readonly spawn: (spec: SubprocessSpawnSpec) => SubprocessHandle
|
|
163
|
+
/** Host diagnostic sink for a product failure kept outside model-visible text. */
|
|
164
|
+
readonly onError?: (error: Error, stopReason: SubagentStopReason) => void
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function thrown(value: unknown): Error {
|
|
168
|
+
/* v8 ignore next -- typed SDK and subprocess failures reject with Error. */
|
|
169
|
+
return value instanceof Error ? value : new Error(String(value))
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Read live request cancellation across awaited startup cleanup. */
|
|
173
|
+
function isAborted(signal: AbortSignal): boolean {
|
|
174
|
+
return signal.aborted
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* jscpd:ignore-end */
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Validate and preserve the one-shot task before crossing the SDK boundary.
|
|
181
|
+
* @param prompt - task content accepted from the shared subagent service.
|
|
182
|
+
* @returns the exact text sequence as one SDK prompt.
|
|
183
|
+
*/
|
|
184
|
+
export function textTask(prompt: readonly ContentBlock[]): string {
|
|
185
|
+
if (prompt.length === 0) {
|
|
186
|
+
throw new Error('subagent-claude-code: the one-shot task must contain only text blocks')
|
|
187
|
+
}
|
|
188
|
+
const texts: string[] = []
|
|
189
|
+
for (const block of prompt) {
|
|
190
|
+
if (block.type !== 'text') {
|
|
191
|
+
throw new Error('subagent-claude-code: the one-shot task must contain only text blocks')
|
|
192
|
+
}
|
|
193
|
+
texts.push(block.text)
|
|
194
|
+
}
|
|
195
|
+
if (texts.every(text => text.trim().length === 0)) {
|
|
196
|
+
throw new Error('subagent-claude-code: the one-shot task must not be empty')
|
|
197
|
+
}
|
|
198
|
+
return texts.join('')
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Strictly derive the only SDK result that can complete a shared run.
|
|
203
|
+
* @param message - an official discriminated result union.
|
|
204
|
+
* @returns exact final text for a successful, non-error result.
|
|
205
|
+
*/
|
|
206
|
+
export function successfulResult(message: SDKResultMessage): string {
|
|
207
|
+
if (message.subtype !== 'success') {
|
|
208
|
+
const category = sdkFailureCategory(message.subtype)
|
|
209
|
+
const detail = category === 'unknown'
|
|
210
|
+
? undefined
|
|
211
|
+
: message.errors.join('; ')
|
|
212
|
+
throw new ClaudeCodeFailure(
|
|
213
|
+
{ stage: 'query-run', category },
|
|
214
|
+
detail === undefined || detail.length === 0
|
|
215
|
+
? undefined
|
|
216
|
+
: new Error(detail),
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
if (message.is_error || message.result.trim().length === 0) {
|
|
220
|
+
throw new ClaudeCodeFailure({
|
|
221
|
+
stage: 'query-run',
|
|
222
|
+
category: 'invalid-result',
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
return message.result
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Consume the complete SDK stream and require one strict success plus normal
|
|
230
|
+
* iterator completion.
|
|
231
|
+
* @param query - published official SDK query.
|
|
232
|
+
* @param onPermissionDenied - records a safe fact when the SDK reports native denial.
|
|
233
|
+
* @param onResult - records that the SDK supplied a terminal result message.
|
|
234
|
+
* @returns the completed shared result.
|
|
235
|
+
*/
|
|
236
|
+
export async function consumeClaudeQuery(
|
|
237
|
+
query: AsyncIterable<SDKMessage>,
|
|
238
|
+
onPermissionDenied?: () => void,
|
|
239
|
+
onResult?: () => void,
|
|
240
|
+
): Promise<SubagentResult> {
|
|
241
|
+
let answer: string | undefined
|
|
242
|
+
for await (const message of query) {
|
|
243
|
+
if (message.type === 'system' && message.subtype === 'permission_denied') {
|
|
244
|
+
onPermissionDenied?.()
|
|
245
|
+
continue
|
|
246
|
+
}
|
|
247
|
+
if (message.type !== 'result') continue
|
|
248
|
+
onResult?.()
|
|
249
|
+
answer = successfulResult(message)
|
|
250
|
+
}
|
|
251
|
+
if (answer === undefined) {
|
|
252
|
+
throw new ClaudeCodeFailure({
|
|
253
|
+
stage: 'query-run',
|
|
254
|
+
category: 'invalid-result',
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
output: [{ type: 'text', text: answer }],
|
|
259
|
+
stopReason: 'completed',
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Close the official query, terminate the managed range, and wait for the
|
|
265
|
+
* subprocess owner to prove it is quiescent.
|
|
266
|
+
* @param query - official SDK query, when creation reached that point.
|
|
267
|
+
* @param child - shared-service handle that owns the CLI managed range, including
|
|
268
|
+
* a published handle whose direct result later rejects.
|
|
269
|
+
*/
|
|
270
|
+
export async function disposeClaudeCodeChild(
|
|
271
|
+
query: Pick<Query, 'close'> | undefined,
|
|
272
|
+
child: SubprocessHandle,
|
|
273
|
+
): Promise<void> {
|
|
274
|
+
const failures: Error[] = []
|
|
275
|
+
let outcome: SubprocessOutcome | undefined
|
|
276
|
+
void child.done.then(
|
|
277
|
+
(value) => { outcome = value },
|
|
278
|
+
() => {},
|
|
279
|
+
)
|
|
280
|
+
try {
|
|
281
|
+
query?.close()
|
|
282
|
+
} catch (error: unknown) {
|
|
283
|
+
failures.push(thrown(error))
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
child.terminate()
|
|
287
|
+
try {
|
|
288
|
+
await child.waitForExit()
|
|
289
|
+
} catch (error: unknown) {
|
|
290
|
+
failures.push(thrown(error))
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const firstFailure = failures[0]
|
|
294
|
+
if (firstFailure !== undefined) {
|
|
295
|
+
const facts = {
|
|
296
|
+
stage: 'teardown',
|
|
297
|
+
category: 'unknown',
|
|
298
|
+
outcome,
|
|
299
|
+
} as const
|
|
300
|
+
const cause = failures.length === 1
|
|
301
|
+
? firstFailure
|
|
302
|
+
: new AggregateError(failures, 'Claude Code teardown failures')
|
|
303
|
+
throw new ClaudeCodeFailure(facts, cause)
|
|
304
|
+
}
|
|
305
|
+
await child.done.catch(() => {})
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Build the fixed official SDK options for one one-shot provider run.
|
|
310
|
+
* @param spec - Workspace, environment, process service, and disposal policy.
|
|
311
|
+
* @param controller - per-run cancellation owner.
|
|
312
|
+
* @param capture - receives the shared child and SDK-facing process synchronously.
|
|
313
|
+
* @param captureDiagnostic - receives safe facts from unattended interaction callbacks.
|
|
314
|
+
* @returns options that inherit native settings while disabling persistence and user questions.
|
|
315
|
+
*/
|
|
316
|
+
export function claudeQueryOptions(
|
|
317
|
+
spec: ClaudeCodeRunSpec,
|
|
318
|
+
controller: AbortController,
|
|
319
|
+
capture: (
|
|
320
|
+
child: SubprocessHandle,
|
|
321
|
+
process: ManagedClaudeCodeProcess,
|
|
322
|
+
) => void,
|
|
323
|
+
captureDiagnostic: (diagnostic: string) => void,
|
|
324
|
+
): Options {
|
|
325
|
+
return {
|
|
326
|
+
abortController: controller,
|
|
327
|
+
cwd: spec.cwd,
|
|
328
|
+
...spec.model === undefined ? {} : { model: spec.model },
|
|
329
|
+
env: { ...scrubbedParentEnv(), ...spec.env },
|
|
330
|
+
persistSession: false,
|
|
331
|
+
disallowedTools: spec.permissionMode === 'plan'
|
|
332
|
+
? ['AskUserQuestion', 'ExitPlanMode']
|
|
333
|
+
: ['AskUserQuestion'],
|
|
334
|
+
permissionMode: spec.permissionMode,
|
|
335
|
+
...spec.permissionMode === 'bypassPermissions'
|
|
336
|
+
? { allowDangerouslySkipPermissions: true }
|
|
337
|
+
: {
|
|
338
|
+
canUseTool: () => {
|
|
339
|
+
captureDiagnostic(unattendedDiagnostic(
|
|
340
|
+
spec.permissionMode,
|
|
341
|
+
'tool permission',
|
|
342
|
+
'denied',
|
|
343
|
+
'the provider does not request human approval',
|
|
344
|
+
))
|
|
345
|
+
return Promise.resolve({
|
|
346
|
+
behavior: 'deny' as const,
|
|
347
|
+
message: 'This unattended Claude Code subagent cannot request human approval.',
|
|
348
|
+
})
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
onElicitation: () => {
|
|
352
|
+
captureDiagnostic(unattendedDiagnostic(
|
|
353
|
+
spec.permissionMode,
|
|
354
|
+
'MCP elicitation',
|
|
355
|
+
'declined',
|
|
356
|
+
'the provider does not collect interactive MCP input',
|
|
357
|
+
))
|
|
358
|
+
return Promise.resolve({ action: 'decline' })
|
|
359
|
+
},
|
|
360
|
+
onUserDialog: () => {
|
|
361
|
+
captureDiagnostic(unattendedDiagnostic(
|
|
362
|
+
spec.permissionMode,
|
|
363
|
+
'user dialog',
|
|
364
|
+
'cancelled',
|
|
365
|
+
'the provider does not render blocking dialogs',
|
|
366
|
+
))
|
|
367
|
+
return Promise.resolve({ behavior: 'cancelled' as const })
|
|
368
|
+
},
|
|
369
|
+
supportedDialogKinds: SUPPORTED_UNATTENDED_DIALOG_KINDS,
|
|
370
|
+
spawnClaudeCodeProcess: (options: SpawnOptions) => {
|
|
371
|
+
const child = spec.spawn(claudeSpawnSpec(options, spec.disposeGraceMs))
|
|
372
|
+
const process = new ManagedClaudeCodeProcess(child)
|
|
373
|
+
capture(child, process)
|
|
374
|
+
return process
|
|
375
|
+
},
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Start one official Claude Agent SDK query and publish its one-shot run.
|
|
381
|
+
* @param request - resolved shared subagent request.
|
|
382
|
+
* @param spec - Workspace, environment, process service, and diagnostic policy.
|
|
383
|
+
* @returns the published run after both Query and the real CLI handle exist.
|
|
384
|
+
*/
|
|
385
|
+
export async function startClaudeCodeRun(
|
|
386
|
+
request: SubagentStartRequest,
|
|
387
|
+
spec: ClaudeCodeRunSpec,
|
|
388
|
+
): Promise<SubagentRun> {
|
|
389
|
+
const prompt = textTask(request.prompt)
|
|
390
|
+
if (request.signal.aborted) {
|
|
391
|
+
throw new Error('subagent-claude-code: request was aborted before SDK startup')
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const controller = new AbortController()
|
|
395
|
+
const requestCancel = (): void => {
|
|
396
|
+
if (!controller.signal.aborted) {
|
|
397
|
+
controller.abort(new Error('subagent-claude-code: run cancelled locally'))
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const onAbort = (): void => { requestCancel() }
|
|
401
|
+
request.signal.addEventListener('abort', onAbort, { once: true })
|
|
402
|
+
const reportFailure = (error: Error): void => {
|
|
403
|
+
try {
|
|
404
|
+
spec.onError?.(error, 'error')
|
|
405
|
+
} catch {
|
|
406
|
+
// Host diagnostic logging cannot replace the product failure.
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
let child: SubprocessHandle | undefined
|
|
411
|
+
let childFailure: Error | undefined
|
|
412
|
+
let childProcessFailure: Promise<never> | undefined
|
|
413
|
+
let query: Query | undefined
|
|
414
|
+
let managedProcess: ManagedClaudeCodeProcess | undefined
|
|
415
|
+
let diagnostic: string | undefined
|
|
416
|
+
const capturePermissionDiagnostic = (value: string): void => {
|
|
417
|
+
diagnostic = value
|
|
418
|
+
}
|
|
419
|
+
const prependFailureDiagnostic = (facts: ClaudeCodeFailureFacts): void => {
|
|
420
|
+
const failure = failureDiagnostic(facts)
|
|
421
|
+
diagnostic = diagnostic === undefined
|
|
422
|
+
? failure
|
|
423
|
+
: `${failure}\n${diagnostic}`
|
|
424
|
+
}
|
|
425
|
+
const captureChild = (
|
|
426
|
+
captured: SubprocessHandle,
|
|
427
|
+
process: ManagedClaudeCodeProcess,
|
|
428
|
+
): void => {
|
|
429
|
+
child = captured
|
|
430
|
+
managedProcess = process
|
|
431
|
+
childProcessFailure = captured.done.then(
|
|
432
|
+
() => new Promise<never>(() => {}),
|
|
433
|
+
(error: unknown) => {
|
|
434
|
+
childFailure = thrown(error)
|
|
435
|
+
throw childFailure
|
|
436
|
+
},
|
|
437
|
+
)
|
|
438
|
+
void childProcessFailure.catch(() => {})
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
query = officialQuery({
|
|
442
|
+
prompt,
|
|
443
|
+
options: claudeQueryOptions(
|
|
444
|
+
spec,
|
|
445
|
+
controller,
|
|
446
|
+
captureChild,
|
|
447
|
+
capturePermissionDiagnostic,
|
|
448
|
+
),
|
|
449
|
+
})
|
|
450
|
+
if (child === undefined || childProcessFailure === undefined) {
|
|
451
|
+
throw new Error(
|
|
452
|
+
'subagent-claude-code: official SDK did not publish a controllable Claude Code process',
|
|
453
|
+
)
|
|
454
|
+
}
|
|
455
|
+
if (isAborted(controller.signal)) {
|
|
456
|
+
throw new Error('subagent-claude-code: request was aborted before SDK startup')
|
|
457
|
+
}
|
|
458
|
+
} catch (error: unknown) {
|
|
459
|
+
request.signal.removeEventListener('abort', onAbort)
|
|
460
|
+
const cancelledBeforeCleanup = controller.signal.aborted
|
|
461
|
+
// Let child.done publish a concurrently observed exit before classification.
|
|
462
|
+
await Promise.resolve()
|
|
463
|
+
const startupOutcome = managedProcess?.outcome
|
|
464
|
+
const startupFacts = {
|
|
465
|
+
stage: 'query-start',
|
|
466
|
+
category: 'unknown',
|
|
467
|
+
outcome: startupOutcome,
|
|
468
|
+
} as const
|
|
469
|
+
const startupFailure = (cause: unknown = childFailure ?? error): ClaudeCodeFailure => new ClaudeCodeFailure(
|
|
470
|
+
startupFacts,
|
|
471
|
+
thrown(cause),
|
|
472
|
+
)
|
|
473
|
+
requestCancel()
|
|
474
|
+
if (child !== undefined) {
|
|
475
|
+
try {
|
|
476
|
+
await disposeClaudeCodeChild(query, child)
|
|
477
|
+
} catch (disposeError: unknown) {
|
|
478
|
+
const failure = startupFailure()
|
|
479
|
+
const cleanupFailure = thrown(disposeError)
|
|
480
|
+
const aggregate = new AggregateError(
|
|
481
|
+
[failure, cleanupFailure],
|
|
482
|
+
`${failure.message}; ${cleanupFailure.message}`,
|
|
483
|
+
)
|
|
484
|
+
reportFailure(aggregate)
|
|
485
|
+
throw aggregate
|
|
486
|
+
}
|
|
487
|
+
if (cancelledBeforeCleanup || isAborted(request.signal)) {
|
|
488
|
+
throw new Error('subagent-claude-code: request was aborted before SDK startup')
|
|
489
|
+
}
|
|
490
|
+
const failure = startupFailure()
|
|
491
|
+
reportFailure(failure)
|
|
492
|
+
throw failure
|
|
493
|
+
} else if (query !== undefined) {
|
|
494
|
+
try {
|
|
495
|
+
query.close()
|
|
496
|
+
} catch (disposeError: unknown) {
|
|
497
|
+
const failure = startupFailure()
|
|
498
|
+
const cleanupFailure = new ClaudeCodeFailure({
|
|
499
|
+
stage: 'teardown',
|
|
500
|
+
category: 'unknown',
|
|
501
|
+
}, thrown(disposeError))
|
|
502
|
+
const aggregate = new AggregateError(
|
|
503
|
+
[failure, cleanupFailure],
|
|
504
|
+
`${failure.message}; ${cleanupFailure.message}`,
|
|
505
|
+
)
|
|
506
|
+
reportFailure(aggregate)
|
|
507
|
+
throw aggregate
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (cancelledBeforeCleanup || isAborted(request.signal)) {
|
|
511
|
+
throw new Error('subagent-claude-code: request was aborted before SDK startup')
|
|
512
|
+
}
|
|
513
|
+
const failure = startupFailure()
|
|
514
|
+
reportFailure(failure)
|
|
515
|
+
throw failure
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const publishedQuery = query
|
|
519
|
+
const publishedChild = child
|
|
520
|
+
const publishedProcessFailure = childProcessFailure
|
|
521
|
+
let receivedResult = false
|
|
522
|
+
const result = settleRunResult({
|
|
523
|
+
attempt: async () => {
|
|
524
|
+
try {
|
|
525
|
+
return await Promise.race([
|
|
526
|
+
consumeClaudeQuery(publishedQuery, () => {
|
|
527
|
+
capturePermissionDiagnostic(unattendedDiagnostic(
|
|
528
|
+
spec.permissionMode,
|
|
529
|
+
'tool permission',
|
|
530
|
+
'denied',
|
|
531
|
+
'Claude Code denied the request before an interactive prompt',
|
|
532
|
+
))
|
|
533
|
+
}, () => {
|
|
534
|
+
receivedResult = true
|
|
535
|
+
}),
|
|
536
|
+
publishedProcessFailure,
|
|
537
|
+
])
|
|
538
|
+
} catch (error: unknown) {
|
|
539
|
+
const processOutcome = managedProcess?.outcome
|
|
540
|
+
let facts: ClaudeCodeFailureFacts
|
|
541
|
+
if (error instanceof ClaudeCodeFailure) {
|
|
542
|
+
facts = { ...error.facts, outcome: processOutcome }
|
|
543
|
+
} else if (processOutcome !== undefined && !receivedResult) {
|
|
544
|
+
facts = {
|
|
545
|
+
stage: 'process',
|
|
546
|
+
category: 'process',
|
|
547
|
+
outcome: processOutcome,
|
|
548
|
+
}
|
|
549
|
+
} else {
|
|
550
|
+
facts = {
|
|
551
|
+
stage: 'query-run',
|
|
552
|
+
category: 'unknown',
|
|
553
|
+
outcome: processOutcome,
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
prependFailureDiagnostic(facts)
|
|
557
|
+
// Keep the SDK category and cause; the diagnostic adds later process facts.
|
|
558
|
+
throw error instanceof ClaudeCodeFailure
|
|
559
|
+
? error
|
|
560
|
+
: new ClaudeCodeFailure(facts, thrown(error))
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
collectOutput: () => [],
|
|
564
|
+
collectDiagnostic: () => diagnostic,
|
|
565
|
+
cancelled: () => controller.signal.aborted,
|
|
566
|
+
onError: spec.onError,
|
|
567
|
+
signal: request.signal,
|
|
568
|
+
onAbort,
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
return subprocessRunHandle({
|
|
572
|
+
id: brandString<SessionId>(randomUUID()),
|
|
573
|
+
result,
|
|
574
|
+
signal: request.signal,
|
|
575
|
+
onAbort,
|
|
576
|
+
requestCancel,
|
|
577
|
+
teardown: async () => {
|
|
578
|
+
try {
|
|
579
|
+
await disposeClaudeCodeChild(publishedQuery, publishedChild)
|
|
580
|
+
} catch (error: unknown) {
|
|
581
|
+
const failure = thrown(error)
|
|
582
|
+
reportFailure(failure)
|
|
583
|
+
throw failure
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
})
|
|
587
|
+
}
|