@zhushanwen/subagent-engine-sdk 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/best-effort.cjs +9 -1
  2. package/dist/best-effort.js +2 -2
  3. package/dist/{chunk-X24IVQKJ.js → chunk-3FVBDH3X.js} +3 -2
  4. package/dist/{chunk-YL5W5EMV.js → chunk-AF2ETADP.js} +1 -1
  5. package/dist/chunk-D36ZIQQK.js +28 -0
  6. package/dist/{chunk-W23PAAGX.js → chunk-DIIYVO4O.js} +1 -27
  7. package/dist/{chunk-RCT7L777.js → chunk-F7VDVSBZ.js} +1 -1
  8. package/dist/{chunk-HERD6RIR.js → chunk-MQPASWMA.js} +2 -2
  9. package/dist/{chunk-75QEMUGV.js → chunk-NXNNXGTY.js} +10 -1
  10. package/dist/{chunk-EJMF63R5.js → chunk-QMEHSKNR.js} +1 -1
  11. package/dist/{chunk-J4G2MXDS.js → chunk-VE3NVT7K.js} +1 -1
  12. package/dist/cli-entry.cjs +9 -1
  13. package/dist/cli-entry.js +2 -2
  14. package/dist/{contract-types-DiWyGRXr.d.cts → contract-types-DqOD58r-.d.cts} +7 -12
  15. package/dist/{contract-types-DiWyGRXr.d.ts → contract-types-DqOD58r-.d.ts} +7 -12
  16. package/dist/data-dir.cjs +10 -2
  17. package/dist/data-dir.js +2 -2
  18. package/dist/env.cjs +9 -1
  19. package/dist/env.d.cts +6 -6
  20. package/dist/env.d.ts +6 -6
  21. package/dist/env.js +2 -2
  22. package/dist/error-codes-C3oVToMr.d.cts +311 -0
  23. package/dist/error-codes-CiDwaODz.d.ts +311 -0
  24. package/dist/index.cjs +41 -3
  25. package/dist/index.d.cts +31 -3
  26. package/dist/index.d.ts +31 -3
  27. package/dist/index.js +62 -31
  28. package/dist/journal-io.d.cts +1 -1
  29. package/dist/journal-io.d.ts +1 -1
  30. package/dist/journal-replay.d.cts +1 -1
  31. package/dist/journal-replay.d.ts +1 -1
  32. package/dist/kill-chain.cjs +9 -1
  33. package/dist/kill-chain.d.cts +1 -1
  34. package/dist/kill-chain.d.ts +1 -1
  35. package/dist/kill-chain.js +2 -2
  36. package/dist/logger.cjs +11 -1
  37. package/dist/logger.js +1 -1
  38. package/dist/port-contract.d.cts +12 -6
  39. package/dist/port-contract.d.ts +12 -6
  40. package/dist/protocol/index.cjs +1 -1
  41. package/dist/protocol/index.d.cts +4 -296
  42. package/dist/protocol/index.d.ts +4 -296
  43. package/dist/protocol/index.js +7 -5
  44. package/dist/server/index.cjs +217 -0
  45. package/dist/server/index.d.cts +146 -0
  46. package/dist/server/index.d.ts +146 -0
  47. package/dist/server/index.js +143 -0
  48. package/dist/spawn.cjs +9 -1
  49. package/dist/spawn.js +3 -3
  50. package/package.json +12 -1
@@ -0,0 +1,311 @@
1
+ import { A as AgentEvent, d as EngineCapabilities, M as ModelCatalogEntry, b as AgentCallOpts, e as ResumeAnchor, E as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from './contract-types-DqOD58r-.cjs';
2
+
3
+ /** 协议错误对象(error 帧载荷与反向请求错误应答共用形态)。 */
4
+ interface ProtocolError {
5
+ /** 错误码(error-codes.ts 词表 + 其余 engine_* 引擎自报透传)。 */
6
+ code: string;
7
+ /** 人类可读详情。 */
8
+ message: string;
9
+ /** 恢复指引:指向具体下一步(命令 / 配置路径 / 升级动作),非安慰性文案。 */
10
+ recovery: string;
11
+ /** 结构化附参(如 engine_protocol_mismatch 的双方版本)。 */
12
+ data?: Record<string, unknown>;
13
+ }
14
+ interface RequestFrame {
15
+ id: number;
16
+ method: string;
17
+ params: unknown;
18
+ }
19
+ interface SuccessResponseFrame {
20
+ id: number | string;
21
+ result: unknown;
22
+ }
23
+ interface ErrorResponseFrame {
24
+ id: number | string;
25
+ error: ProtocolError;
26
+ }
27
+ type ResponseFrame = SuccessResponseFrame | ErrorResponseFrame;
28
+ /** event 通知载荷:runId 关联在途 run;seq 单调递增(基线①结构等价断言对象)。 */
29
+ interface EventNotificationParams {
30
+ runId: string;
31
+ seq: number;
32
+ event: AgentEvent;
33
+ }
34
+ interface NotificationFrame {
35
+ method: "event";
36
+ params: EventNotificationParams;
37
+ }
38
+ interface ReverseRequestFrame {
39
+ id: string;
40
+ method: string;
41
+ params: unknown;
42
+ }
43
+ /** 反向请求的应答(core → 引擎,沿 ResponseFrame 通道回传;id = 反向请求 id 原样)。 */
44
+ type ReverseResponseResult =
45
+ /** 数据面类:处理确认。 */
46
+ {
47
+ ok: true;
48
+ }
49
+ /** 人机交互类(askUser)两阶段第一阶段:已受理,结果异步到达(R9-2)。 */
50
+ | {
51
+ ack: true;
52
+ }
53
+ /** 未实现或宿主未知的通道(宽容语义③:由 askUser 语境泛化到全通道——宿主对未知 host/* 通道回 unsupported,引擎自行降级)。 */
54
+ | {
55
+ unsupported: true;
56
+ };
57
+ /** ① 请求:有数字 id + method + params,且无 result/error(与②应答区分)。 */
58
+ declare function isRequestFrame(frame: unknown): frame is RequestFrame;
59
+ /** ② 应答:有 id(number|string)且 result/error 二选一。 */
60
+ declare function isResponseFrame(frame: unknown): frame is ResponseFrame;
61
+ /** ③ 通知:无 id,method === "event",params 含 runId/seq/event。 */
62
+ declare function isNotificationFrame(frame: unknown): frame is NotificationFrame;
63
+ /** ④ 反向请求:有字符串 id + host/* method + params(与①的区别 = id 形态与 method 前缀)。 */
64
+ declare function isReverseRequestFrame(frame: unknown): frame is ReverseRequestFrame;
65
+
66
+ /**
67
+ * 正向方法名联合(恰好 9 个;PROTOCOL_METHODS 常量数组与之同源互证)。
68
+ * [H1] `interact` 成员已随 chat-run 统一退役(docs/architecture/subagent-chat-run-unification.md
69
+ * §3.3 D5:续聊轮统一为「新 run + resume 锚点」,U5 删除)。
70
+ */
71
+ type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "read" | "listModels" | "validateModel" | "dispose" | "ping";
72
+ /** 方法名全集(运行时顺序化枚举;与 ProtocolMethod 的同源关系由测试断言)。 */
73
+ declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
74
+ /**
75
+ * run 上下文(RunContext 字段映射的协议承载,设计 §3.3 RunContext 映射表)。
76
+ */
77
+ interface RunContextParams {
78
+ /** 任务工作目录(worktree 隔离时 = worktree 路径)。缺省不上 wire——引擎侧
79
+ * 回退自身进程 cwd(spawn 继承语义)。 */
80
+ cwd?: string;
81
+ /** 请求模型 ref(未传 = 引擎缺省模型)。 */
82
+ model?: string;
83
+ /** 上下文模型 ref(与 run 模型分离的 ctx 模型)。 */
84
+ ctxModel?: string;
85
+ /** 事件粒度请求(引擎按 capabilities.eventGranularity 实际能力执行)。 */
86
+ streamMode?: "stream" | "coarse";
87
+ /**
88
+ * [F6] 根 session id——pi 引擎 relay 归属键 SESSION_ID 的权威来源(生产三来源
89
+ * ①本字段 ②宿主 env ③根进程 env 中,宿主派发恒走①)。additive 可选:旧引擎忽略
90
+ * 未知字段,undefined 不上 wire。
91
+ */
92
+ sessionRootId?: string;
93
+ /**
94
+ * [Option C 协议化] 权威 subagent session 目录——宿主以 getSubagentSessionDir
95
+ * (agentDir, rootCwd) 推导(宿主单一权威,Fix Gate B S6:引擎本地推导与宿主布局
96
+ * 三处不等价 → 跨重启续聊链断裂)。引擎用它组装 pi `--session-dir`,不自推导;
97
+ * 缺省(独立运行/测试)走引擎内 [LEGACY] fallback。additive 可选:旧引擎忽略
98
+ * 未知字段,undefined 不上 wire。
99
+ */
100
+ sessionDir?: string;
101
+ /**
102
+ * [D2 扩展加载显式化] 孙进程显式加载的扩展路径集(pi 引擎侧逐项拼
103
+ * `--extension` argv)。per-host 常量而非 per-run 变量,故落 ctx。宿主侧来源
104
+ * 双形态:taiji 宿主 = extension-service 下发的白名单收窄集(经 pi-host 注入);
105
+ * 独立 pi = subagent-workflow 自身 optional peerDep 解析回退。additive 可选:
106
+ * 旧引擎忽略未知字段,undefined 不上 wire。
107
+ */
108
+ extensionPaths?: string[];
109
+ /**
110
+ * [D4 record 身份信封] 本次 run 的 **record 级身份**(引擎把它整封写进任务子进程的
111
+ * 身份 env;见 SDK `identity-env.ts` 的 `SUBAGENT_IDENTITY_ENV`)。
112
+ *
113
+ * 为什么是信封而不是三个平铺键:`slug` 与 task 侧 `description` 是同一语义的两种写法,
114
+ * 平铺进 ctx 会撞 wire 层绝对条款「同一语义不得 task/ctx 双写」(`wire-field-locks.test.ts`
115
+ * 的 `keyof AgentCallOpts & keyof RunContextParams = never`);信封把「record 身份」立成
116
+ * 一个独立概念(与「怎么执行这次调用」的 task 面正交),也给后续身份字段一个归处。
117
+ *
118
+ * 字段语义(缺省即不写该键,读者按各自回落语义工作):
119
+ * - `slug`:record 短标签(宿主侧由 record 的 description 派生的展示标签);
120
+ * - `startedAt`:record 起始时刻(epoch ms;宿主派发时刻即权威值,引擎不得改写);
121
+ * - `mode`:执行形态(`background` / `chat`,record 级事实)。
122
+ *
123
+ * additive 可选:旧引擎忽略未知字段,undefined 不上 wire。
124
+ */
125
+ identity?: {
126
+ slug?: string;
127
+ startedAt?: number;
128
+ mode?: string;
129
+ };
130
+ }
131
+ /**
132
+ * [H1] run 的 resume 会话形态参数(设计 docs/architecture/subagent-chat-run-unification.md
133
+ * §3.3 D3 + §5 U1/U6 行):原 RunChatParams(v1.x chat 会话形态参数)的泛化改名终态,
134
+ * 载荷同形(recordId + resume 锚点,ResumeAnchor 不变),仅键名从「chat 会话形态」
135
+ * 泛化为「resume 续聊」。
136
+ * - recordId:core 预建 record 的关联键(引擎据此回填 handle.sessionRef、上报
137
+ * host/childSpawned|childStateChanged 的 record 键形态);
138
+ * - resume:冷续锚点(重开已 idle 的 session 续聊;缺省 = 新 session)。对照
139
+ * core SpawnResumeOpts——sessionFile 经 anchor.sessionRef 携带,model/
140
+ * thinkingLevel 防漂移覆盖走既有 task/ctx 字段,不双写。
141
+ * [H1 U6 已切换] `chat` 键整体退役(读写端同批切换,无「写新读旧」窗口),本键为
142
+ * 唯一会话形态参数。载荷 schema 权威 = runSessionParamsSchema(schema.ts)。
143
+ */
144
+ interface RunResumeParams {
145
+ recordId: string;
146
+ resume?: ResumeAnchor;
147
+ }
148
+ /** initialize 参数(engineConfig = L3 显式配置 engines.<id>.config 透传,不放凭据)。 */
149
+ interface InitializeParams {
150
+ protocolVersion: number;
151
+ hostInfo: {
152
+ name: string;
153
+ version: string;
154
+ dataRoot: string;
155
+ };
156
+ engineConfig: Record<string, string>;
157
+ }
158
+ /** initialize 应答(仅诊断面:capabilities/models 与 manifest 不一致 → warn,不参与判据)。 */
159
+ interface InitializeResult {
160
+ protocolVersion: number;
161
+ engineId: string;
162
+ engineVersion: string;
163
+ adapterVersion: string;
164
+ capabilities: EngineCapabilities;
165
+ /** 模型目录(诊断面;省略/null = 无枚举面语义)。 */
166
+ models?: ModelCatalogEntry[] | null;
167
+ }
168
+ interface ProbeParams {
169
+ force?: boolean;
170
+ }
171
+ interface RunParams {
172
+ runId: string;
173
+ task: AgentCallOpts;
174
+ ctx: RunContextParams;
175
+ /**
176
+ * [H1 U6 终态] resume 续聊参数(唯一会话形态键;原 v1.x `chat` 键已随键切换退役,
177
+ * 见 RunResumeParams)。缺省 = 一次性任务形态(向后兼容:旧引擎忽略未知字段,
178
+ * 帧级 schema params 不做深校验)。additive 可选:undefined 不上 wire。
179
+ */
180
+ resume?: RunResumeParams;
181
+ }
182
+ /** run 终态应答(期间事件经 event 通知;长运行方法,应答到达即终态)。 */
183
+ interface RunResult {
184
+ handle: EngineHandleData;
185
+ outcome: AgentOutcome;
186
+ }
187
+ interface CancelParams {
188
+ runId: string;
189
+ reason: string;
190
+ }
191
+ /**
192
+ * cancel 应答(受理确认)。终态本体由该 run 的 run 终态应答承载(abort 合成终态经
193
+ * event/终态应答到达);引擎须 CANCEL_SETTLE_GRACE_MS(3s)内收敛,超时 core 走杀链。
194
+ */
195
+ interface CancelResult {
196
+ ok: true;
197
+ }
198
+ interface ReadParams {
199
+ handle: EngineHandleData;
200
+ /** 数据根(core 每次 read 都发送——remote-engine 构造注入的数据目录)。两引擎
201
+ * server 现行均不消费该字段:定位走 handle.data(recordPath 等)或引擎自身
202
+ * 数据目录。保留为协议帧字段(历史:存量池时代引擎自算池/journal 相对 dbPath
203
+ * 的定位需要它)。 */
204
+ dataDir: string;
205
+ }
206
+ interface ListModelsParams {
207
+ /** 占位空参(帧形状一致性;未来诊断参数在此扩展)。 */
208
+ _placeholder?: never;
209
+ }
210
+ interface ListModelsResult {
211
+ /** 数组 = 有枚举面;null = 无枚举面(buildCoreAlignedHint 语义,与 manifest 省略对齐)。 */
212
+ models: ModelCatalogEntry[] | null;
213
+ }
214
+ interface ValidateModelParams {
215
+ modelRef?: string;
216
+ }
217
+ interface ValidateModelResult {
218
+ canonicalRef: string;
219
+ }
220
+ interface DisposeParams {
221
+ /** 占位空参(帧形状一致性;幂等语义)。 */
222
+ _placeholder?: never;
223
+ }
224
+ interface DisposeResult {
225
+ ok: true;
226
+ }
227
+ interface PingParams {
228
+ /** 占位空参(帧形状一致性)。 */
229
+ _placeholder?: never;
230
+ }
231
+ interface PingResult {
232
+ pong: true;
233
+ }
234
+ /** 方法 → params 类型映射。 */
235
+ interface ProtocolParamsMap {
236
+ initialize: InitializeParams;
237
+ probe: ProbeParams;
238
+ run: RunParams;
239
+ cancel: CancelParams;
240
+ read: ReadParams;
241
+ listModels: ListModelsParams;
242
+ validateModel: ValidateModelParams;
243
+ dispose: DisposeParams;
244
+ ping: PingParams;
245
+ }
246
+ /** 方法 → result 类型映射。 */
247
+ interface ProtocolResultMap {
248
+ initialize: InitializeResult;
249
+ probe: ProbeReport;
250
+ run: RunResult;
251
+ cancel: CancelResult;
252
+ read: SessionView;
253
+ listModels: ListModelsResult;
254
+ validateModel: ValidateModelResult;
255
+ dispose: DisposeResult;
256
+ ping: PingResult;
257
+ }
258
+
259
+ /** 协议核心错误码(引擎 error 帧 + core 同步拦截共用的固定词表)。 */
260
+ declare const ENGINE_PROTOCOL_ERROR_CODES: readonly ["engine_not_found", "engine_protocol_mismatch", "engine_capability_unsupported", "engine_capability_mismatch", "engine_model_unknown", "engine_model_mismatch", "engine_handshake_timeout", "engine_crashed", "engine_probe_failed"];
261
+ type EngineProtocolErrorCode = (typeof ENGINE_PROTOCOL_ERROR_CODES)[number];
262
+ /** unknown → 协议错误码收窄(外部输入携带错误码时的运行时 guard;其余 engine_* 走透传)。 */
263
+ declare function isEngineProtocolErrorCode(value: unknown): value is EngineProtocolErrorCode;
264
+ /** 其余引擎自报错误码的前缀契约(透传面;core 不解释文案)。 */
265
+ declare const ENGINE_ERROR_CODE_PREFIX = "engine_";
266
+ declare function isEngineErrorPassthroughCode(value: string): boolean;
267
+
268
+ /**
269
+ * 结构化引擎错误(message 恒为 `<code>: <detail>` 前缀格式——AgentOutcome.error 与
270
+ * 协议 error 帧共用的错误码前缀约定);recovery 指向恢复动作。
271
+ * toStructured() 产出即协议 ProtocolError 形态(error 帧载荷直用)。
272
+ */
273
+ declare class EngineSdkError extends Error {
274
+ readonly code: string;
275
+ readonly recovery: string;
276
+ readonly data?: Record<string, unknown>;
277
+ constructor(code: string, detail: string, recovery: string, data?: Record<string, unknown>);
278
+ /** 协议 error 帧载荷投影。 */
279
+ toStructured(): ProtocolError;
280
+ }
281
+ declare function engineProtocolMismatchError(engineVersion: number): EngineSdkError;
282
+ /**
283
+ * 引擎 conversation 位拒绝的具名错误([modeless 波2] 语义:无 resume 续聊通道的
284
+ * 引擎,message 续聊资格被拒——manifest conversation 能力轴消费;[modeless 波5
285
+ * 收尾] core capability-gate 的显式参数分支随派发参数删除退役,本构造器消费方 =
286
+ * 引擎侧 resume gate(assertChatConversationSupported)与 message 资格门)。
287
+ * 文案契约:错误码 engine_capability_unsupported + 「换引擎续聊 / 修 manifest /
288
+ * 升级引擎包」恢复指引,两侧一致防漂移。
289
+ */
290
+ declare function engineConversationUnsupportedError(engineId: string): EngineSdkError;
291
+ /**
292
+ * resume 会话形态(run.params.resume——唯一会话形态键)派发前的同步 gate:
293
+ * manifest conversation 位 unsupported 即抛 engineConversationUnsupportedError
294
+ * ——进程/record 创建前同步拒(A6 方向防御:manifest/实装漂移时引擎侧自拒,
295
+ * 与 core capability-gate 同一能力位,防两侧判据漂移)。[modeless 波2] 协议
296
+ * task 的 conversation 键已删,本 gate 只对 resume 形态键生效。
297
+ */
298
+ declare function assertChatConversationSupported(engineId: string, capabilities: Pick<EngineCapabilities, "conversation">): void;
299
+ /** stdout 尾部回显上限(engine_timeout / engine_run_failed 的错误规格载体系数)。 */
300
+ declare const STDOUT_TAIL_ECHO_CHARS = 2000;
301
+ /** engine_timeout 的恢复指引(kill-chain 超时杀链收尾文案)。 */
302
+ declare const ENGINE_TIMEOUT_RECOVERY: string;
303
+ /**
304
+ * engine_timeout 的 outcome.error 文案:含 stdout 尾部 2000 字 + 恢复指引
305
+ * (kill-chain synthesizeTimeoutOutcome 消费;与 core errors.ts engineTimeoutDetail 逐字等价)。
306
+ */
307
+ declare function engineTimeoutDetail(stdoutTail: string): string;
308
+ /** schema_emulation_failed 的终报文案(宿主编排层「重试一次仍失败」后消费)。 */
309
+ declare function schemaEmulationFailedDetail(error: string, tail: string): string;
310
+
311
+ export { type ValidateModelResult as A, assertChatConversationSupported as B, type CancelParams as C, type DisposeParams as D, EngineSdkError as E, engineConversationUnsupportedError as F, engineProtocolMismatchError as G, engineTimeoutDetail as H, type InitializeResult as I, isEngineErrorPassthroughCode as J, isEngineProtocolErrorCode as K, type ListModelsParams as L, isNotificationFrame as M, type NotificationFrame as N, isRequestFrame as O, PROTOCOL_METHODS as P, isResponseFrame as Q, type RunContextParams as R, STDOUT_TAIL_ECHO_CHARS as S, isReverseRequestFrame as T, schemaEmulationFailedDetail as U, type ValidateModelParams as V, type InitializeParams as a, type CancelResult as b, type DisposeResult as c, ENGINE_ERROR_CODE_PREFIX as d, ENGINE_PROTOCOL_ERROR_CODES as e, ENGINE_TIMEOUT_RECOVERY as f, type EngineProtocolErrorCode as g, type ErrorResponseFrame as h, type EventNotificationParams as i, type ListModelsResult as j, type PingParams as k, type PingResult as l, type ProbeParams as m, type ProtocolError as n, type ProtocolMethod as o, type ProtocolParamsMap as p, type ProtocolResultMap as q, type ReadParams as r, type RequestFrame as s, type ResponseFrame as t, type ReverseRequestFrame as u, type ReverseResponseResult as v, type RunParams as w, type RunResult as x, type RunResumeParams as y, type SuccessResponseFrame as z };
@@ -0,0 +1,311 @@
1
+ import { A as AgentEvent, d as EngineCapabilities, M as ModelCatalogEntry, b as AgentCallOpts, e as ResumeAnchor, E as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from './contract-types-DqOD58r-.js';
2
+
3
+ /** 协议错误对象(error 帧载荷与反向请求错误应答共用形态)。 */
4
+ interface ProtocolError {
5
+ /** 错误码(error-codes.ts 词表 + 其余 engine_* 引擎自报透传)。 */
6
+ code: string;
7
+ /** 人类可读详情。 */
8
+ message: string;
9
+ /** 恢复指引:指向具体下一步(命令 / 配置路径 / 升级动作),非安慰性文案。 */
10
+ recovery: string;
11
+ /** 结构化附参(如 engine_protocol_mismatch 的双方版本)。 */
12
+ data?: Record<string, unknown>;
13
+ }
14
+ interface RequestFrame {
15
+ id: number;
16
+ method: string;
17
+ params: unknown;
18
+ }
19
+ interface SuccessResponseFrame {
20
+ id: number | string;
21
+ result: unknown;
22
+ }
23
+ interface ErrorResponseFrame {
24
+ id: number | string;
25
+ error: ProtocolError;
26
+ }
27
+ type ResponseFrame = SuccessResponseFrame | ErrorResponseFrame;
28
+ /** event 通知载荷:runId 关联在途 run;seq 单调递增(基线①结构等价断言对象)。 */
29
+ interface EventNotificationParams {
30
+ runId: string;
31
+ seq: number;
32
+ event: AgentEvent;
33
+ }
34
+ interface NotificationFrame {
35
+ method: "event";
36
+ params: EventNotificationParams;
37
+ }
38
+ interface ReverseRequestFrame {
39
+ id: string;
40
+ method: string;
41
+ params: unknown;
42
+ }
43
+ /** 反向请求的应答(core → 引擎,沿 ResponseFrame 通道回传;id = 反向请求 id 原样)。 */
44
+ type ReverseResponseResult =
45
+ /** 数据面类:处理确认。 */
46
+ {
47
+ ok: true;
48
+ }
49
+ /** 人机交互类(askUser)两阶段第一阶段:已受理,结果异步到达(R9-2)。 */
50
+ | {
51
+ ack: true;
52
+ }
53
+ /** 未实现或宿主未知的通道(宽容语义③:由 askUser 语境泛化到全通道——宿主对未知 host/* 通道回 unsupported,引擎自行降级)。 */
54
+ | {
55
+ unsupported: true;
56
+ };
57
+ /** ① 请求:有数字 id + method + params,且无 result/error(与②应答区分)。 */
58
+ declare function isRequestFrame(frame: unknown): frame is RequestFrame;
59
+ /** ② 应答:有 id(number|string)且 result/error 二选一。 */
60
+ declare function isResponseFrame(frame: unknown): frame is ResponseFrame;
61
+ /** ③ 通知:无 id,method === "event",params 含 runId/seq/event。 */
62
+ declare function isNotificationFrame(frame: unknown): frame is NotificationFrame;
63
+ /** ④ 反向请求:有字符串 id + host/* method + params(与①的区别 = id 形态与 method 前缀)。 */
64
+ declare function isReverseRequestFrame(frame: unknown): frame is ReverseRequestFrame;
65
+
66
+ /**
67
+ * 正向方法名联合(恰好 9 个;PROTOCOL_METHODS 常量数组与之同源互证)。
68
+ * [H1] `interact` 成员已随 chat-run 统一退役(docs/architecture/subagent-chat-run-unification.md
69
+ * §3.3 D5:续聊轮统一为「新 run + resume 锚点」,U5 删除)。
70
+ */
71
+ type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "read" | "listModels" | "validateModel" | "dispose" | "ping";
72
+ /** 方法名全集(运行时顺序化枚举;与 ProtocolMethod 的同源关系由测试断言)。 */
73
+ declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
74
+ /**
75
+ * run 上下文(RunContext 字段映射的协议承载,设计 §3.3 RunContext 映射表)。
76
+ */
77
+ interface RunContextParams {
78
+ /** 任务工作目录(worktree 隔离时 = worktree 路径)。缺省不上 wire——引擎侧
79
+ * 回退自身进程 cwd(spawn 继承语义)。 */
80
+ cwd?: string;
81
+ /** 请求模型 ref(未传 = 引擎缺省模型)。 */
82
+ model?: string;
83
+ /** 上下文模型 ref(与 run 模型分离的 ctx 模型)。 */
84
+ ctxModel?: string;
85
+ /** 事件粒度请求(引擎按 capabilities.eventGranularity 实际能力执行)。 */
86
+ streamMode?: "stream" | "coarse";
87
+ /**
88
+ * [F6] 根 session id——pi 引擎 relay 归属键 SESSION_ID 的权威来源(生产三来源
89
+ * ①本字段 ②宿主 env ③根进程 env 中,宿主派发恒走①)。additive 可选:旧引擎忽略
90
+ * 未知字段,undefined 不上 wire。
91
+ */
92
+ sessionRootId?: string;
93
+ /**
94
+ * [Option C 协议化] 权威 subagent session 目录——宿主以 getSubagentSessionDir
95
+ * (agentDir, rootCwd) 推导(宿主单一权威,Fix Gate B S6:引擎本地推导与宿主布局
96
+ * 三处不等价 → 跨重启续聊链断裂)。引擎用它组装 pi `--session-dir`,不自推导;
97
+ * 缺省(独立运行/测试)走引擎内 [LEGACY] fallback。additive 可选:旧引擎忽略
98
+ * 未知字段,undefined 不上 wire。
99
+ */
100
+ sessionDir?: string;
101
+ /**
102
+ * [D2 扩展加载显式化] 孙进程显式加载的扩展路径集(pi 引擎侧逐项拼
103
+ * `--extension` argv)。per-host 常量而非 per-run 变量,故落 ctx。宿主侧来源
104
+ * 双形态:taiji 宿主 = extension-service 下发的白名单收窄集(经 pi-host 注入);
105
+ * 独立 pi = subagent-workflow 自身 optional peerDep 解析回退。additive 可选:
106
+ * 旧引擎忽略未知字段,undefined 不上 wire。
107
+ */
108
+ extensionPaths?: string[];
109
+ /**
110
+ * [D4 record 身份信封] 本次 run 的 **record 级身份**(引擎把它整封写进任务子进程的
111
+ * 身份 env;见 SDK `identity-env.ts` 的 `SUBAGENT_IDENTITY_ENV`)。
112
+ *
113
+ * 为什么是信封而不是三个平铺键:`slug` 与 task 侧 `description` 是同一语义的两种写法,
114
+ * 平铺进 ctx 会撞 wire 层绝对条款「同一语义不得 task/ctx 双写」(`wire-field-locks.test.ts`
115
+ * 的 `keyof AgentCallOpts & keyof RunContextParams = never`);信封把「record 身份」立成
116
+ * 一个独立概念(与「怎么执行这次调用」的 task 面正交),也给后续身份字段一个归处。
117
+ *
118
+ * 字段语义(缺省即不写该键,读者按各自回落语义工作):
119
+ * - `slug`:record 短标签(宿主侧由 record 的 description 派生的展示标签);
120
+ * - `startedAt`:record 起始时刻(epoch ms;宿主派发时刻即权威值,引擎不得改写);
121
+ * - `mode`:执行形态(`background` / `chat`,record 级事实)。
122
+ *
123
+ * additive 可选:旧引擎忽略未知字段,undefined 不上 wire。
124
+ */
125
+ identity?: {
126
+ slug?: string;
127
+ startedAt?: number;
128
+ mode?: string;
129
+ };
130
+ }
131
+ /**
132
+ * [H1] run 的 resume 会话形态参数(设计 docs/architecture/subagent-chat-run-unification.md
133
+ * §3.3 D3 + §5 U1/U6 行):原 RunChatParams(v1.x chat 会话形态参数)的泛化改名终态,
134
+ * 载荷同形(recordId + resume 锚点,ResumeAnchor 不变),仅键名从「chat 会话形态」
135
+ * 泛化为「resume 续聊」。
136
+ * - recordId:core 预建 record 的关联键(引擎据此回填 handle.sessionRef、上报
137
+ * host/childSpawned|childStateChanged 的 record 键形态);
138
+ * - resume:冷续锚点(重开已 idle 的 session 续聊;缺省 = 新 session)。对照
139
+ * core SpawnResumeOpts——sessionFile 经 anchor.sessionRef 携带,model/
140
+ * thinkingLevel 防漂移覆盖走既有 task/ctx 字段,不双写。
141
+ * [H1 U6 已切换] `chat` 键整体退役(读写端同批切换,无「写新读旧」窗口),本键为
142
+ * 唯一会话形态参数。载荷 schema 权威 = runSessionParamsSchema(schema.ts)。
143
+ */
144
+ interface RunResumeParams {
145
+ recordId: string;
146
+ resume?: ResumeAnchor;
147
+ }
148
+ /** initialize 参数(engineConfig = L3 显式配置 engines.<id>.config 透传,不放凭据)。 */
149
+ interface InitializeParams {
150
+ protocolVersion: number;
151
+ hostInfo: {
152
+ name: string;
153
+ version: string;
154
+ dataRoot: string;
155
+ };
156
+ engineConfig: Record<string, string>;
157
+ }
158
+ /** initialize 应答(仅诊断面:capabilities/models 与 manifest 不一致 → warn,不参与判据)。 */
159
+ interface InitializeResult {
160
+ protocolVersion: number;
161
+ engineId: string;
162
+ engineVersion: string;
163
+ adapterVersion: string;
164
+ capabilities: EngineCapabilities;
165
+ /** 模型目录(诊断面;省略/null = 无枚举面语义)。 */
166
+ models?: ModelCatalogEntry[] | null;
167
+ }
168
+ interface ProbeParams {
169
+ force?: boolean;
170
+ }
171
+ interface RunParams {
172
+ runId: string;
173
+ task: AgentCallOpts;
174
+ ctx: RunContextParams;
175
+ /**
176
+ * [H1 U6 终态] resume 续聊参数(唯一会话形态键;原 v1.x `chat` 键已随键切换退役,
177
+ * 见 RunResumeParams)。缺省 = 一次性任务形态(向后兼容:旧引擎忽略未知字段,
178
+ * 帧级 schema params 不做深校验)。additive 可选:undefined 不上 wire。
179
+ */
180
+ resume?: RunResumeParams;
181
+ }
182
+ /** run 终态应答(期间事件经 event 通知;长运行方法,应答到达即终态)。 */
183
+ interface RunResult {
184
+ handle: EngineHandleData;
185
+ outcome: AgentOutcome;
186
+ }
187
+ interface CancelParams {
188
+ runId: string;
189
+ reason: string;
190
+ }
191
+ /**
192
+ * cancel 应答(受理确认)。终态本体由该 run 的 run 终态应答承载(abort 合成终态经
193
+ * event/终态应答到达);引擎须 CANCEL_SETTLE_GRACE_MS(3s)内收敛,超时 core 走杀链。
194
+ */
195
+ interface CancelResult {
196
+ ok: true;
197
+ }
198
+ interface ReadParams {
199
+ handle: EngineHandleData;
200
+ /** 数据根(core 每次 read 都发送——remote-engine 构造注入的数据目录)。两引擎
201
+ * server 现行均不消费该字段:定位走 handle.data(recordPath 等)或引擎自身
202
+ * 数据目录。保留为协议帧字段(历史:存量池时代引擎自算池/journal 相对 dbPath
203
+ * 的定位需要它)。 */
204
+ dataDir: string;
205
+ }
206
+ interface ListModelsParams {
207
+ /** 占位空参(帧形状一致性;未来诊断参数在此扩展)。 */
208
+ _placeholder?: never;
209
+ }
210
+ interface ListModelsResult {
211
+ /** 数组 = 有枚举面;null = 无枚举面(buildCoreAlignedHint 语义,与 manifest 省略对齐)。 */
212
+ models: ModelCatalogEntry[] | null;
213
+ }
214
+ interface ValidateModelParams {
215
+ modelRef?: string;
216
+ }
217
+ interface ValidateModelResult {
218
+ canonicalRef: string;
219
+ }
220
+ interface DisposeParams {
221
+ /** 占位空参(帧形状一致性;幂等语义)。 */
222
+ _placeholder?: never;
223
+ }
224
+ interface DisposeResult {
225
+ ok: true;
226
+ }
227
+ interface PingParams {
228
+ /** 占位空参(帧形状一致性)。 */
229
+ _placeholder?: never;
230
+ }
231
+ interface PingResult {
232
+ pong: true;
233
+ }
234
+ /** 方法 → params 类型映射。 */
235
+ interface ProtocolParamsMap {
236
+ initialize: InitializeParams;
237
+ probe: ProbeParams;
238
+ run: RunParams;
239
+ cancel: CancelParams;
240
+ read: ReadParams;
241
+ listModels: ListModelsParams;
242
+ validateModel: ValidateModelParams;
243
+ dispose: DisposeParams;
244
+ ping: PingParams;
245
+ }
246
+ /** 方法 → result 类型映射。 */
247
+ interface ProtocolResultMap {
248
+ initialize: InitializeResult;
249
+ probe: ProbeReport;
250
+ run: RunResult;
251
+ cancel: CancelResult;
252
+ read: SessionView;
253
+ listModels: ListModelsResult;
254
+ validateModel: ValidateModelResult;
255
+ dispose: DisposeResult;
256
+ ping: PingResult;
257
+ }
258
+
259
+ /** 协议核心错误码(引擎 error 帧 + core 同步拦截共用的固定词表)。 */
260
+ declare const ENGINE_PROTOCOL_ERROR_CODES: readonly ["engine_not_found", "engine_protocol_mismatch", "engine_capability_unsupported", "engine_capability_mismatch", "engine_model_unknown", "engine_model_mismatch", "engine_handshake_timeout", "engine_crashed", "engine_probe_failed"];
261
+ type EngineProtocolErrorCode = (typeof ENGINE_PROTOCOL_ERROR_CODES)[number];
262
+ /** unknown → 协议错误码收窄(外部输入携带错误码时的运行时 guard;其余 engine_* 走透传)。 */
263
+ declare function isEngineProtocolErrorCode(value: unknown): value is EngineProtocolErrorCode;
264
+ /** 其余引擎自报错误码的前缀契约(透传面;core 不解释文案)。 */
265
+ declare const ENGINE_ERROR_CODE_PREFIX = "engine_";
266
+ declare function isEngineErrorPassthroughCode(value: string): boolean;
267
+
268
+ /**
269
+ * 结构化引擎错误(message 恒为 `<code>: <detail>` 前缀格式——AgentOutcome.error 与
270
+ * 协议 error 帧共用的错误码前缀约定);recovery 指向恢复动作。
271
+ * toStructured() 产出即协议 ProtocolError 形态(error 帧载荷直用)。
272
+ */
273
+ declare class EngineSdkError extends Error {
274
+ readonly code: string;
275
+ readonly recovery: string;
276
+ readonly data?: Record<string, unknown>;
277
+ constructor(code: string, detail: string, recovery: string, data?: Record<string, unknown>);
278
+ /** 协议 error 帧载荷投影。 */
279
+ toStructured(): ProtocolError;
280
+ }
281
+ declare function engineProtocolMismatchError(engineVersion: number): EngineSdkError;
282
+ /**
283
+ * 引擎 conversation 位拒绝的具名错误([modeless 波2] 语义:无 resume 续聊通道的
284
+ * 引擎,message 续聊资格被拒——manifest conversation 能力轴消费;[modeless 波5
285
+ * 收尾] core capability-gate 的显式参数分支随派发参数删除退役,本构造器消费方 =
286
+ * 引擎侧 resume gate(assertChatConversationSupported)与 message 资格门)。
287
+ * 文案契约:错误码 engine_capability_unsupported + 「换引擎续聊 / 修 manifest /
288
+ * 升级引擎包」恢复指引,两侧一致防漂移。
289
+ */
290
+ declare function engineConversationUnsupportedError(engineId: string): EngineSdkError;
291
+ /**
292
+ * resume 会话形态(run.params.resume——唯一会话形态键)派发前的同步 gate:
293
+ * manifest conversation 位 unsupported 即抛 engineConversationUnsupportedError
294
+ * ——进程/record 创建前同步拒(A6 方向防御:manifest/实装漂移时引擎侧自拒,
295
+ * 与 core capability-gate 同一能力位,防两侧判据漂移)。[modeless 波2] 协议
296
+ * task 的 conversation 键已删,本 gate 只对 resume 形态键生效。
297
+ */
298
+ declare function assertChatConversationSupported(engineId: string, capabilities: Pick<EngineCapabilities, "conversation">): void;
299
+ /** stdout 尾部回显上限(engine_timeout / engine_run_failed 的错误规格载体系数)。 */
300
+ declare const STDOUT_TAIL_ECHO_CHARS = 2000;
301
+ /** engine_timeout 的恢复指引(kill-chain 超时杀链收尾文案)。 */
302
+ declare const ENGINE_TIMEOUT_RECOVERY: string;
303
+ /**
304
+ * engine_timeout 的 outcome.error 文案:含 stdout 尾部 2000 字 + 恢复指引
305
+ * (kill-chain synthesizeTimeoutOutcome 消费;与 core errors.ts engineTimeoutDetail 逐字等价)。
306
+ */
307
+ declare function engineTimeoutDetail(stdoutTail: string): string;
308
+ /** schema_emulation_failed 的终报文案(宿主编排层「重试一次仍失败」后消费)。 */
309
+ declare function schemaEmulationFailedDetail(error: string, tail: string): string;
310
+
311
+ export { type ValidateModelResult as A, assertChatConversationSupported as B, type CancelParams as C, type DisposeParams as D, EngineSdkError as E, engineConversationUnsupportedError as F, engineProtocolMismatchError as G, engineTimeoutDetail as H, type InitializeResult as I, isEngineErrorPassthroughCode as J, isEngineProtocolErrorCode as K, type ListModelsParams as L, isNotificationFrame as M, type NotificationFrame as N, isRequestFrame as O, PROTOCOL_METHODS as P, isResponseFrame as Q, type RunContextParams as R, STDOUT_TAIL_ECHO_CHARS as S, isReverseRequestFrame as T, schemaEmulationFailedDetail as U, type ValidateModelParams as V, type InitializeParams as a, type CancelResult as b, type DisposeResult as c, ENGINE_ERROR_CODE_PREFIX as d, ENGINE_PROTOCOL_ERROR_CODES as e, ENGINE_TIMEOUT_RECOVERY as f, type EngineProtocolErrorCode as g, type ErrorResponseFrame as h, type EventNotificationParams as i, type ListModelsResult as j, type PingParams as k, type PingResult as l, type ProbeParams as m, type ProtocolError as n, type ProtocolMethod as o, type ProtocolParamsMap as p, type ProtocolResultMap as q, type ReadParams as r, type RequestFrame as s, type ResponseFrame as t, type ReverseRequestFrame as u, type ReverseResponseResult as v, type RunParams as w, type RunResult as x, type RunResumeParams as y, type SuccessResponseFrame as z };