@zhushanwen/subagent-engine-sdk 0.2.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 (139) hide show
  1. package/dist/best-effort.cjs +88 -0
  2. package/dist/best-effort.d.cts +14 -0
  3. package/dist/best-effort.d.ts +14 -0
  4. package/dist/best-effort.js +8 -0
  5. package/dist/chunk-2DIMPZCQ.js +0 -0
  6. package/dist/chunk-365AUV6N.js +67 -0
  7. package/dist/chunk-3K2P2CM2.js +127 -0
  8. package/dist/chunk-75QEMUGV.js +58 -0
  9. package/dist/chunk-7I4XGL5J.js +95 -0
  10. package/dist/chunk-A75XDJIC.js +227 -0
  11. package/dist/chunk-DSQ7JQKM.js +39 -0
  12. package/dist/chunk-EJMF63R5.js +19 -0
  13. package/dist/chunk-GT6YLLN4.js +46 -0
  14. package/dist/chunk-HYES77BR.js +109 -0
  15. package/dist/chunk-JSBRDJBE.js +30 -0
  16. package/dist/chunk-LEOBWKRM.js +128 -0
  17. package/dist/chunk-N3RL6OVM.js +38 -0
  18. package/dist/chunk-OPMY4G4M.js +27 -0
  19. package/dist/chunk-PPEPBVCC.js +120 -0
  20. package/dist/chunk-PYO3YR7W.js +16 -0
  21. package/dist/chunk-RDH3ZOV6.js +46 -0
  22. package/dist/chunk-RULLX6C6.js +11 -0
  23. package/dist/chunk-X24SFZYW.js +6646 -0
  24. package/dist/chunk-YFSN3D5N.js +216 -0
  25. package/dist/chunk-ZOFFJNJD.js +136 -0
  26. package/dist/chunk-ZXEAW25V.js +132 -0
  27. package/dist/cli-entry.cjs +119 -0
  28. package/dist/cli-entry.d.cts +24 -0
  29. package/dist/cli-entry.d.ts +24 -0
  30. package/dist/cli-entry.js +8 -0
  31. package/dist/contract-types-sSlgppBC.d.cts +352 -0
  32. package/dist/contract-types-sSlgppBC.d.ts +352 -0
  33. package/dist/data-dir.cjs +117 -0
  34. package/dist/data-dir.d.cts +20 -0
  35. package/dist/data-dir.d.ts +20 -0
  36. package/dist/data-dir.js +12 -0
  37. package/dist/env.cjs +205 -0
  38. package/dist/env.d.cts +73 -0
  39. package/dist/env.d.ts +73 -0
  40. package/dist/env.js +16 -0
  41. package/dist/error-codes-DHco5-i_.d.cts +118 -0
  42. package/dist/error-codes-Dhss2Kmk.d.ts +118 -0
  43. package/dist/error-message.cjs +40 -0
  44. package/dist/error-message.d.cts +3 -0
  45. package/dist/error-message.d.ts +3 -0
  46. package/dist/error-message.js +7 -0
  47. package/dist/index.cjs +8375 -0
  48. package/dist/index.d.cts +23 -0
  49. package/dist/index.d.ts +23 -0
  50. package/dist/index.js +268 -0
  51. package/dist/journal-io.cjs +70 -0
  52. package/dist/journal-io.d.cts +12 -0
  53. package/dist/journal-io.d.ts +12 -0
  54. package/dist/journal-io.js +7 -0
  55. package/dist/journal-replay.cjs +256 -0
  56. package/dist/journal-replay.d.cts +45 -0
  57. package/dist/journal-replay.d.ts +45 -0
  58. package/dist/journal-replay.js +17 -0
  59. package/dist/kill-chain.cjs +221 -0
  60. package/dist/kill-chain.d.cts +74 -0
  61. package/dist/kill-chain.d.ts +74 -0
  62. package/dist/kill-chain.js +23 -0
  63. package/dist/logger.cjs +84 -0
  64. package/dist/logger.d.cts +24 -0
  65. package/dist/logger.d.ts +24 -0
  66. package/dist/logger.js +11 -0
  67. package/dist/logs/stderr-rotation.cjs +151 -0
  68. package/dist/logs/stderr-rotation.d.cts +37 -0
  69. package/dist/logs/stderr-rotation.d.ts +37 -0
  70. package/dist/logs/stderr-rotation.js +23 -0
  71. package/dist/nesting-guard.cjs +95 -0
  72. package/dist/nesting-guard.d.cts +65 -0
  73. package/dist/nesting-guard.d.ts +65 -0
  74. package/dist/nesting-guard.js +15 -0
  75. package/dist/node-executor.cjs +180 -0
  76. package/dist/node-executor.d.cts +63 -0
  77. package/dist/node-executor.d.ts +63 -0
  78. package/dist/node-executor.js +16 -0
  79. package/dist/paths.cjs +55 -0
  80. package/dist/paths.d.cts +8 -0
  81. package/dist/paths.d.ts +8 -0
  82. package/dist/paths.js +15 -0
  83. package/dist/port-contract.cjs +35 -0
  84. package/dist/port-contract.d.cts +88 -0
  85. package/dist/port-contract.d.ts +88 -0
  86. package/dist/port-contract.js +7 -0
  87. package/dist/protocol/index.cjs +400 -0
  88. package/dist/protocol/index.d.cts +685 -0
  89. package/dist/protocol/index.d.ts +685 -0
  90. package/dist/protocol/index.js +89 -0
  91. package/dist/relay-env.cjs +71 -0
  92. package/dist/relay-env.d.cts +37 -0
  93. package/dist/relay-env.d.ts +37 -0
  94. package/dist/relay-env.js +23 -0
  95. package/dist/schema-emulation.cjs +6680 -0
  96. package/dist/schema-emulation.d.cts +39 -0
  97. package/dist/schema-emulation.d.ts +39 -0
  98. package/dist/schema-emulation.js +11 -0
  99. package/dist/spawn.cjs +200 -0
  100. package/dist/spawn.d.cts +80 -0
  101. package/dist/spawn.d.ts +80 -0
  102. package/dist/spawn.js +16 -0
  103. package/dist/ui-channels.cjs +120 -0
  104. package/dist/ui-channels.d.cts +60 -0
  105. package/dist/ui-channels.d.ts +60 -0
  106. package/dist/ui-channels.js +9 -0
  107. package/dist/ui-types.cjs +18 -0
  108. package/dist/ui-types.d.cts +62 -0
  109. package/dist/ui-types.d.ts +62 -0
  110. package/dist/ui-types.js +1 -0
  111. package/package.json +58 -0
  112. package/src/best-effort.ts +37 -0
  113. package/src/cli-entry.ts +77 -0
  114. package/src/data-dir.ts +88 -0
  115. package/src/env.ts +265 -0
  116. package/src/error-message.ts +22 -0
  117. package/src/index.ts +63 -0
  118. package/src/journal-io.ts +82 -0
  119. package/src/journal-replay.ts +432 -0
  120. package/src/kill-chain.ts +265 -0
  121. package/src/logger.ts +105 -0
  122. package/src/logs/stderr-rotation.ts +166 -0
  123. package/src/nesting-guard.ts +140 -0
  124. package/src/node-executor.ts +272 -0
  125. package/src/paths.ts +48 -0
  126. package/src/port-contract.ts +117 -0
  127. package/src/protocol/contract-types.ts +378 -0
  128. package/src/protocol/engine-protocol.ts +81 -0
  129. package/src/protocol/error-codes.ts +179 -0
  130. package/src/protocol/frames.ts +145 -0
  131. package/src/protocol/index.ts +12 -0
  132. package/src/protocol/methods.ts +229 -0
  133. package/src/protocol/reverse-channels.ts +274 -0
  134. package/src/protocol/schema.ts +154 -0
  135. package/src/relay-env.ts +60 -0
  136. package/src/schema-emulation.ts +192 -0
  137. package/src/spawn.ts +246 -0
  138. package/src/ui-channels.ts +219 -0
  139. package/src/ui-types.ts +84 -0
@@ -0,0 +1,685 @@
1
+ import { P as ProtocolError } from '../error-codes-Dhss2Kmk.js';
2
+ export { A as AnyFrame, E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from '../error-codes-Dhss2Kmk.js';
3
+ import { E as EngineCapabilities, M as ModelCatalogEntry, h as EngineHandleData, I as InteractAction, A as AgentCallOpts, k as ResumeAnchor, P as ProbeReport, c as AgentOutcome, i as InteractResult, S as SessionView, e as AgentUsage } from '../contract-types-sSlgppBC.js';
4
+ export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, j as InternalToolCall, R as ReplayedTurn, T as ToolCall, l as ToolCallEntry, m as ToolCallResult, n as Turn, W as WorktreeHandle } from '../contract-types-sSlgppBC.js';
5
+ import { UiRequest, UiResponse } from '../ui-types.js';
6
+
7
+ /** 协议版本(引擎包 manifest `xyz-agent.subagentEngine.protocol` 与 initialize 应答同值)。 */
8
+ declare const ENGINE_PROTOCOL_VERSION = 1;
9
+ /**
10
+ * core 侧支持的协议版本区间(半开区间 [min, max)):当前 = [1, 2)。
11
+ * 引擎版本落在区间外 → engine_protocol_mismatch。
12
+ */
13
+ declare const SUPPORTED_PROTOCOL_RANGE: {
14
+ readonly min: 1;
15
+ readonly max: 2;
16
+ };
17
+ /** 版本兼容判定(core 握手判据;引擎侧对称用于拒绝过旧/过新宿主)。 */
18
+ declare function isProtocolVersionCompatible(version: number): boolean;
19
+ /** 正向数据面反向请求(帧④数据面类)未应答容忍时长:10s 未答 = 引擎故障 → 杀进程 + 在途 run 失败。 */
20
+ declare const REVERSE_REQUEST_TIMEOUT_MS = 10000;
21
+ /** initialize 握手超时(ms):超时 → engine_handshake_timeout,该引擎不可用。 */
22
+ declare const HANDSHAKE_TIMEOUT_MS = 10000;
23
+ /** cancel 后引擎收敛终态的窗口(ms);超时 core 走杀链。 */
24
+ declare const CANCEL_SETTLE_GRACE_MS = 3000;
25
+ /** engine_crashed 后重建上限与指数退避序列(ms):1s / 2s / 4s,超限标记不可用至宿主重启。 */
26
+ declare const CRASH_REBUILD_MAX_ATTEMPTS = 3;
27
+ declare const CRASH_REBUILD_BACKOFF_MS: readonly [1000, 2000, 4000];
28
+ /** stderr 内存环形缓冲保留的尾部字符数(engine_crashed 帧携带崩溃现场)。 */
29
+ declare const STDERR_TAIL_CHARS = 400;
30
+ /** 事件合并开关 env 名(设计级默认关闭 = 值 "0";A1 要求事件逐字段等价,合并不可开)。 */
31
+ declare const ENGINE_EVENT_COALESCE_ENV = "XYZ_ENGINE_EVENT_COALESCE";
32
+ declare const ENGINE_EVENT_COALESCE_DEFAULT = "0";
33
+ /**
34
+ * 反向请求超时二分(帧④注释,R9-2):
35
+ * - 数据面类(host/log / host/streamDelta / host/poolResolved / host/handleReady /
36
+ * host/childSpawned / host/childStateChanged / host/roundLifecycle[v1.x]):10s 未答 =
37
+ * 引擎故障;
38
+ * - 人机交互类(host/askUser / host/permission):不设统一超时——core 先回 {ack:true},
39
+ * 结果异步到达;按 ADR-0047「静默 ≠ 卡死」用无进展检测/用户取消,不据此判引擎故障。
40
+ */
41
+ type ReverseRequestTimeoutClass = "data-plane" | "interaction";
42
+
43
+ /** 正向方法名联合(恰好 10 个;PROTOCOL_METHODS 常量数组与之同源互证)。 */
44
+ type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "interact" | "read" | "listModels" | "validateModel" | "dispose" | "ping";
45
+ /** 方法名全集(运行时顺序化枚举;与 ProtocolMethod 的同源关系由测试断言)。 */
46
+ declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel", "interact", "read", "listModels", "validateModel", "dispose", "ping"];
47
+ /**
48
+ * run 上下文(RunContext 字段映射的协议承载,设计 §3.3 RunContext 映射表)。
49
+ */
50
+ interface RunContextParams {
51
+ /** 隔离池归属(journal 归属错 = 缺失后果)。 */
52
+ poolKey: string;
53
+ /** 任务工作目录(worktree 隔离时 = worktree 路径)。 */
54
+ cwd: string;
55
+ /** 请求模型 ref(未传 = 引擎缺省模型)。 */
56
+ model?: string;
57
+ /** 结构化输出 schema 的 env 注入形态(schemaEnv 降级通道)。 */
58
+ schemaEnv?: string;
59
+ /** 上下文模型 ref(与 run 模型分离的 ctx 模型)。 */
60
+ ctxModel?: string;
61
+ /** fallback 留痕(引擎回填 outcome.engineFallback 的种子)。 */
62
+ engineFallback?: {
63
+ from: string;
64
+ reason: string;
65
+ };
66
+ /** 事件粒度请求(引擎按 capabilities.eventGranularity 实际能力执行)。 */
67
+ streamMode?: "stream" | "coarse";
68
+ }
69
+ /**
70
+ * [v1.x] chat 会话形态参数——HostChatRoundTicket 五字段过协议映射中「record」的
71
+ * 承载位(docs/design/chat-domain-v1x-liveness-governance.md §3.2 D1 五字段映射):
72
+ * - recordId:core 预建 record 的关联键(引擎据此回填 handle.sessionRef、上报
73
+ * host/childSpawned|childStateChanged 与 host/roundLifecycle 的 record 键形态);
74
+ * - resume:冷续锚点(重开已 idle 的 session 续聊;缺省 = 新 session)。对照
75
+ * core SpawnResumeOpts——sessionFile 经 anchor.sessionRef 携带,model/
76
+ * thinkingLevel 防漂移覆盖走既有 task/ctx 字段,不双写。
77
+ * task.conversation === true 时必传(chat 路由前置 gate:manifest conversation 位
78
+ * unsupported 的引擎同步拒 engine_capability_unsupported——见 error-codes.ts)。
79
+ */
80
+ interface RunChatParams {
81
+ recordId: string;
82
+ resume?: ResumeAnchor;
83
+ }
84
+ /** initialize 参数(engineConfig = L3 显式配置 engines.<id>.config 透传,不放凭据)。 */
85
+ interface InitializeParams {
86
+ protocolVersion: number;
87
+ hostInfo: {
88
+ name: string;
89
+ version: string;
90
+ dataRoot: string;
91
+ };
92
+ engineConfig: Record<string, string>;
93
+ }
94
+ /** initialize 应答(仅诊断面:capabilities/models 与 manifest 不一致 → warn,不参与判据)。 */
95
+ interface InitializeResult {
96
+ protocolVersion: number;
97
+ engineId: string;
98
+ engineVersion: string;
99
+ adapterVersion: string;
100
+ capabilities: EngineCapabilities;
101
+ /** 模型目录(诊断面;省略/null = 无枚举面语义)。 */
102
+ models?: ModelCatalogEntry[] | null;
103
+ }
104
+ interface ProbeParams {
105
+ force?: boolean;
106
+ }
107
+ interface RunParams {
108
+ runId: string;
109
+ task: AgentCallOpts;
110
+ ctx: RunContextParams;
111
+ /**
112
+ * [v1.x 可选增量] chat 会话形态参数(task.conversation=true 的 chat 路由承载)。
113
+ * 缺省 = 一次性任务形态,v1 引擎/宿主语义不变(向后兼容:旧引擎忽略未知字段,
114
+ * 帧级 schema params 不做深校验)。续聊/关断不经此参数——走既有 interact。
115
+ */
116
+ chat?: RunChatParams;
117
+ }
118
+ /** run 终态应答(期间事件经 event 通知;长运行方法,应答到达即终态)。 */
119
+ interface RunResult {
120
+ handle: EngineHandleData;
121
+ outcome: AgentOutcome;
122
+ }
123
+ interface CancelParams {
124
+ runId: string;
125
+ reason: string;
126
+ }
127
+ /**
128
+ * cancel 应答(受理确认)。终态本体由该 run 的 run 终态应答承载(abort 合成终态经
129
+ * event/终态应答到达);引擎须 CANCEL_SETTLE_GRACE_MS(3s)内收敛,超时 core 走杀链。
130
+ */
131
+ interface CancelResult {
132
+ ok: true;
133
+ }
134
+ interface InteractParams {
135
+ handle: EngineHandleData;
136
+ action: InteractAction;
137
+ }
138
+ interface ReadParams {
139
+ handle: EngineHandleData;
140
+ /** 数据根必填:存量池时代引擎自算池/journal 相对 dbPath 的定位需要它(设计钉死)。 */
141
+ dataDir: string;
142
+ }
143
+ interface ListModelsParams {
144
+ /** 占位空参(帧形状一致性;未来诊断参数在此扩展)。 */
145
+ _placeholder?: never;
146
+ }
147
+ interface ListModelsResult {
148
+ /** 数组 = 有枚举面;null = 无枚举面(buildCoreAlignedHint 语义,与 manifest 省略对齐)。 */
149
+ models: ModelCatalogEntry[] | null;
150
+ }
151
+ interface ValidateModelParams {
152
+ modelRef?: string;
153
+ }
154
+ interface ValidateModelResult {
155
+ canonicalRef: string;
156
+ }
157
+ interface DisposeParams {
158
+ /** 占位空参(帧形状一致性;幂等语义)。 */
159
+ _placeholder?: never;
160
+ }
161
+ interface DisposeResult {
162
+ ok: true;
163
+ }
164
+ interface PingParams {
165
+ /** 占位空参(帧形状一致性)。 */
166
+ _placeholder?: never;
167
+ }
168
+ interface PingResult {
169
+ pong: true;
170
+ }
171
+ /** 方法 → params 类型映射。 */
172
+ interface ProtocolParamsMap {
173
+ initialize: InitializeParams;
174
+ probe: ProbeParams;
175
+ run: RunParams;
176
+ cancel: CancelParams;
177
+ interact: InteractParams;
178
+ read: ReadParams;
179
+ listModels: ListModelsParams;
180
+ validateModel: ValidateModelParams;
181
+ dispose: DisposeParams;
182
+ ping: PingParams;
183
+ }
184
+ /** 方法 → result 类型映射。 */
185
+ interface ProtocolResultMap {
186
+ initialize: InitializeResult;
187
+ probe: ProbeReport;
188
+ run: RunResult;
189
+ cancel: CancelResult;
190
+ interact: InteractResult;
191
+ read: SessionView;
192
+ listModels: ListModelsResult;
193
+ validateModel: ValidateModelResult;
194
+ dispose: DisposeResult;
195
+ ping: PingResult;
196
+ }
197
+
198
+ /** 反向通道名联合(恰好 9 个;REVERSE_CHANNELS 常量数组与之同源互证)。 */
199
+ type ReverseChannel = "host/log" | "host/askUser" | "host/permission" | "host/streamDelta" | "host/poolResolved" | "host/handleReady" | "host/childSpawned" | "host/childStateChanged" | "host/roundLifecycle";
200
+ declare const REVERSE_CHANNELS: readonly ["host/log", "host/askUser", "host/permission", "host/streamDelta", "host/poolResolved", "host/handleReady", "host/childSpawned", "host/childStateChanged", "host/roundLifecycle"];
201
+ /**
202
+ * 超时二分归属(10s 数据面 / 不设统一超时的人机交互面)。实现归 W2 EngineClient;
203
+ * 引擎侧自灭计时(W12)复用同表——已 ack 的 askUser 等待不计入 in-flight(R9-2)。
204
+ * host/roundLifecycle 属数据面(终态回执语义:宿主必须确认收到,10s 未答 = 引擎故障)。
205
+ */
206
+ declare const REVERSE_CHANNEL_TIMEOUT_CLASS: Record<ReverseChannel, ReverseRequestTimeoutClass>;
207
+ /** host/log:引擎日志落宿主日志(对齐 core HostServices.log 调用面)。 */
208
+ interface HostLogParams {
209
+ level: "debug" | "warn" | "error";
210
+ component: string;
211
+ message: string;
212
+ data?: unknown;
213
+ }
214
+ /** host/askUser:UI 请求经反向通道送达宿主(core 壳侧 uiRequestHandler 应答)。 */
215
+ interface HostAskUserParams {
216
+ runId: string;
217
+ /** Pi extension_ui_request 平铺形态(类型 SSOT = SDK ui-types.ts,core 反向 re-export)。 */
218
+ request: UiRequest;
219
+ }
220
+ /** host/askUser 的最终结果(ack 两阶段第二阶段,异步应答帧②的 result)。 */
221
+ type HostAskUserResult = UiResponse;
222
+ /**
223
+ * host/permission:权限询问(引擎请求宿主裁决工具执行)。
224
+ * v1 骨架字段(设计未钉死载荷细节,细化归各引擎提取设计;W2 实装 core 应答端时
225
+ * 若需扩展走 additive 演进)。
226
+ */
227
+ interface HostPermissionParams {
228
+ runId: string;
229
+ toolName: string;
230
+ args?: unknown;
231
+ /** 请求方向引擎给出的原因/说明(展示用)。 */
232
+ reason?: string;
233
+ }
234
+ /** host/permission 两阶段结果。 */
235
+ type HostPermissionResult = {
236
+ approved: boolean;
237
+ } | {
238
+ unsupported: true;
239
+ };
240
+ /**
241
+ * host/streamDelta:UI 实时通道(双通道之一;与 event 通知并行的渲染加速面)。
242
+ *
243
+ * [v1.x 关联键扩展——D1-A 裁定,W1 落地不再临场选择]:
244
+ * - run 域轮(含 run 会话形态首轮):runId 关联(v1 现状不变,runId 由 core 在
245
+ * run 帧分配);
246
+ * - interact 发起的续聊轮:**recordId** 关联(续聊轮无独立 runId——InteractParams/
247
+ * InteractResult 均不含,recordId 经 handle.sessionRef 送达引擎)。
248
+ * 两键互斥(undefined 孪生位防双填),消费侧经 isHostStreamDeltaParams 收窄。
249
+ */
250
+ type HostStreamDeltaParams = {
251
+ runId: string;
252
+ recordId?: undefined;
253
+ delta: string;
254
+ } | {
255
+ recordId: string;
256
+ runId?: undefined;
257
+ delta: string;
258
+ };
259
+ /** streamDelta 载荷结构判定(关联键互斥 + delta 形状;消费侧共用,防双侧各写一份)。 */
260
+ declare function isHostStreamDeltaParams(value: unknown): value is HostStreamDeltaParams;
261
+ /**
262
+ * host/poolResolved:journal 落盘路径单一权威(契约:必须在首个事件 emit 前调用——
263
+ * 否则 journal 归属错)。载荷 = core onPoolResolved(poolKey) 的 runId 关联形态。
264
+ */
265
+ interface HostPoolResolvedParams {
266
+ runId: string;
267
+ poolKey: string;
268
+ }
269
+ /**
270
+ * host/handleReady:运行中句柄回填(core onHandleReady 语义:session/create 应答后、
271
+ * 早于 run resolve;AGENTS.md 关键规则 9「重开 session 仍可见」的前提)。
272
+ */
273
+ interface HostHandleReadyParams {
274
+ runId: string;
275
+ sessionRef: Record<string, string>;
276
+ poolKey: string;
277
+ }
278
+ /**
279
+ * host/childSpawned:引擎内一次性子进程 pid 上报。
280
+ * 用途 = isResumable 镜像谓词 + 诊断留痕;**不供杀链/收割**(v6 已删按 pid 补杀,
281
+ * 收割只靠进程组);常驻进程不报(归 dispose)。
282
+ */
283
+ interface HostChildSpawnedParams {
284
+ pid: number;
285
+ recordId: string;
286
+ }
287
+ /**
288
+ * host/childStateChanged:childSpawned 的状态面(core 侧镜像数据源,
289
+ * hasLiveProcessHandle/isResumable 同步读镜像,不跨进程查询)。
290
+ * **killed 必含**(判据 `child !== undefined && !child.killed`)——类型层 required。
291
+ */
292
+ interface HostChildStateChangedParams {
293
+ pid: number;
294
+ recordId: string;
295
+ state: "running" | "exited";
296
+ /** 必含:true = 已被杀/已终止(镜像置死判据)。 */
297
+ killed: boolean;
298
+ exitCode?: number;
299
+ signal?: string;
300
+ }
301
+ /**
302
+ * 轮次关联键(D1-A 裁定的类型面):run 域轮 = runId(v1 现状);interact 续聊轮 =
303
+ * recordId(经 handle.sessionRef)。undefined 孪生位保证两键互斥。
304
+ */
305
+ interface RoundKeyedByRun {
306
+ runId: string;
307
+ recordId?: undefined;
308
+ }
309
+ interface RoundKeyedByRecord {
310
+ recordId: string;
311
+ runId?: undefined;
312
+ }
313
+ /**
314
+ * 轮次终态相位(事件即 record 回写载体——chat 域 record 处置由相位一一映射,
315
+ * 设计 D2 裁决表 conversation 行:settled/idle 轮收口不终态、failed 标 failed):
316
+ * - settled:轮收敛(输出完整)。消费点 = settled-watchdog disarm + D3 abort
317
+ * 收敛判据(cancel 受理后等本事件,超 CANCEL_SETTLE_GRACE_MS 走杀链);
318
+ * - idle:轮收口 + 会话进 idle 稳态(core 侧 doFinalizeRoundToIdle + idle 定时器
319
+ * 锚点)。settled 与 idle 是两个锚点:watchdog 在 settled 即解除,idle 管置闲;
320
+ * - failed:轮异常终止(引擎自知失败,如 EPIPE 兜底耗尽)——error 如实上报,
321
+ * record 标 failed(与 run 域 AgentOutcome.error 的「失败收口」语义对齐)。
322
+ * usage 为本轮 message_end 增量(interact 续聊轮无 event 通知通道,用量经本帧回填)。
323
+ * 不设 seq:stdio NDJSON 单连接有序 + 数据面应答确认,无重排/重放面(与 event
324
+ * 通知的 seq 对照——后者镜像进程内事件流基线,本帧无基线可镜像)。
325
+ */
326
+ interface RoundSettledPhase {
327
+ phase: "settled";
328
+ usage?: AgentUsage;
329
+ }
330
+ interface RoundIdlePhase {
331
+ phase: "idle";
332
+ usage?: AgentUsage;
333
+ /** 冷续锚点回填(session 滚动/compaction 后锚点可能变化,宿主按帧刷新)。 */
334
+ anchor?: ResumeAnchor;
335
+ }
336
+ interface RoundFailedPhase {
337
+ phase: "failed";
338
+ /** 失败原因(结构对齐协议 error 帧——code/message/recovery 可操作闭环)。 */
339
+ error: ProtocolError;
340
+ anchor?: ResumeAnchor;
341
+ }
342
+ /** 相位联合(消费侧 switch(phase) 判别用)。 */
343
+ type RoundLifecyclePhase = RoundSettledPhase | RoundIdlePhase | RoundFailedPhase;
344
+ /** host/roundLifecycle 载荷:关联键(run|record)× 相位(settled|idle|failed)。 */
345
+ type HostRoundLifecycleParams = (RoundKeyedByRun & RoundSettledPhase) | (RoundKeyedByRun & RoundIdlePhase) | (RoundKeyedByRun & RoundFailedPhase) | (RoundKeyedByRecord & RoundSettledPhase) | (RoundKeyedByRecord & RoundIdlePhase) | (RoundKeyedByRecord & RoundFailedPhase);
346
+ /**
347
+ * roundLifecycle 载荷结构判定:关联键互斥 + phase 词表 + 各相位专属形状
348
+ * (failed 必含 error.code/message)。引擎侧发帧前自检与 core 侧消费共用,
349
+ * 防两侧各写一份判别(与 isHostStreamDeltaParams 同理)。
350
+ */
351
+ declare function isHostRoundLifecycleParams(value: unknown): value is HostRoundLifecycleParams;
352
+ /** 通道 → 载荷类型映射。 */
353
+ interface ReverseChannelParamsMap {
354
+ "host/log": HostLogParams;
355
+ "host/askUser": HostAskUserParams;
356
+ "host/permission": HostPermissionParams;
357
+ "host/streamDelta": HostStreamDeltaParams;
358
+ "host/poolResolved": HostPoolResolvedParams;
359
+ "host/handleReady": HostHandleReadyParams;
360
+ "host/childSpawned": HostChildSpawnedParams;
361
+ "host/childStateChanged": HostChildStateChangedParams;
362
+ "host/roundLifecycle": HostRoundLifecycleParams;
363
+ }
364
+ /** 通道 → 异步/同步结果类型映射(ack 两阶段通道的第二阶段 result)。 */
365
+ interface ReverseChannelResultMap {
366
+ "host/log": {
367
+ ok: true;
368
+ };
369
+ "host/askUser": HostAskUserResult;
370
+ "host/permission": HostPermissionResult;
371
+ "host/streamDelta": {
372
+ ok: true;
373
+ };
374
+ "host/poolResolved": {
375
+ ok: true;
376
+ };
377
+ "host/handleReady": {
378
+ ok: true;
379
+ };
380
+ "host/childSpawned": {
381
+ ok: true;
382
+ };
383
+ "host/childStateChanged": {
384
+ ok: true;
385
+ };
386
+ "host/roundLifecycle": {
387
+ ok: true;
388
+ };
389
+ }
390
+
391
+ /** 协议错误对象 schema。 */
392
+ declare const protocolErrorSchema: {
393
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
394
+ readonly title: "EngineProtocolError";
395
+ readonly type: "object";
396
+ readonly additionalProperties: false;
397
+ readonly required: readonly ["code", "message", "recovery"];
398
+ readonly properties: {
399
+ readonly code: {
400
+ readonly type: "string";
401
+ readonly pattern: "^engine_";
402
+ };
403
+ readonly message: {
404
+ readonly type: "string";
405
+ };
406
+ readonly recovery: {
407
+ readonly type: "string";
408
+ };
409
+ readonly data: {
410
+ readonly type: "object";
411
+ };
412
+ };
413
+ };
414
+ /** ① 请求帧(core → 引擎)。 */
415
+ declare const requestFrameSchema: {
416
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
417
+ readonly title: "EngineProtocolRequestFrame";
418
+ readonly type: "object";
419
+ readonly additionalProperties: false;
420
+ readonly required: readonly ["id", "method", "params"];
421
+ readonly properties: {
422
+ readonly id: {
423
+ readonly type: "number";
424
+ };
425
+ readonly method: {
426
+ readonly type: "string";
427
+ readonly enum: readonly ["initialize", "probe", "run", "cancel", "interact", "read", "listModels", "validateModel", "dispose", "ping"];
428
+ };
429
+ readonly params: {};
430
+ };
431
+ };
432
+ /** ② 应答帧(引擎 → core;result 与 error 互斥)。 */
433
+ declare const successResponseFrameSchema: {
434
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
435
+ readonly title: "EngineProtocolSuccessResponseFrame";
436
+ readonly type: "object";
437
+ readonly additionalProperties: false;
438
+ readonly required: readonly ["id", "result"];
439
+ readonly properties: {
440
+ readonly id: {
441
+ readonly type: readonly ["number", "string"];
442
+ };
443
+ readonly result: {};
444
+ };
445
+ };
446
+ declare const errorResponseFrameSchema: {
447
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
448
+ readonly title: "EngineProtocolErrorResponseFrame";
449
+ readonly type: "object";
450
+ readonly additionalProperties: false;
451
+ readonly required: readonly ["id", "error"];
452
+ readonly properties: {
453
+ readonly id: {
454
+ readonly type: readonly ["number", "string"];
455
+ };
456
+ readonly error: {
457
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
458
+ readonly title: "EngineProtocolError";
459
+ readonly type: "object";
460
+ readonly additionalProperties: false;
461
+ readonly required: readonly ["code", "message", "recovery"];
462
+ readonly properties: {
463
+ readonly code: {
464
+ readonly type: "string";
465
+ readonly pattern: "^engine_";
466
+ };
467
+ readonly message: {
468
+ readonly type: "string";
469
+ };
470
+ readonly recovery: {
471
+ readonly type: "string";
472
+ };
473
+ readonly data: {
474
+ readonly type: "object";
475
+ };
476
+ };
477
+ };
478
+ };
479
+ };
480
+ /** ③ 通知帧(引擎 → core,无 id;method 恒 "event")。 */
481
+ declare const notificationFrameSchema: {
482
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
483
+ readonly title: "EngineProtocolNotificationFrame";
484
+ readonly type: "object";
485
+ readonly additionalProperties: false;
486
+ readonly required: readonly ["method", "params"];
487
+ readonly properties: {
488
+ readonly method: {
489
+ readonly type: "string";
490
+ readonly const: "event";
491
+ };
492
+ readonly params: {
493
+ readonly type: "object";
494
+ readonly additionalProperties: false;
495
+ readonly required: readonly ["runId", "seq", "event"];
496
+ readonly properties: {
497
+ readonly runId: {
498
+ readonly type: "string";
499
+ };
500
+ readonly seq: {
501
+ readonly type: "number";
502
+ };
503
+ readonly event: {
504
+ readonly type: "object";
505
+ readonly required: readonly ["type"];
506
+ readonly properties: {
507
+ readonly type: {
508
+ readonly type: "string";
509
+ readonly enum: readonly ["tool_start", "tool_end", "text_delta", "thinking_delta", "turn_end", "message_end", "compaction", "error"];
510
+ };
511
+ };
512
+ };
513
+ };
514
+ };
515
+ };
516
+ };
517
+ /** ④ 反向请求帧(引擎 → core,必须应答;method 恒 host/*)。 */
518
+ declare const reverseRequestFrameSchema: {
519
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
520
+ readonly title: "EngineProtocolReverseRequestFrame";
521
+ readonly type: "object";
522
+ readonly additionalProperties: false;
523
+ readonly required: readonly ["id", "method", "params"];
524
+ readonly properties: {
525
+ readonly id: {
526
+ readonly type: "string";
527
+ };
528
+ readonly method: {
529
+ readonly type: "string";
530
+ readonly enum: readonly ["host/log", "host/askUser", "host/permission", "host/streamDelta", "host/poolResolved", "host/handleReady", "host/childSpawned", "host/childStateChanged", "host/roundLifecycle"];
531
+ };
532
+ readonly params: {};
533
+ };
534
+ };
535
+ /** 帧型 → schema 索引(校验入口按帧型取用)。 */
536
+ declare const ENGINE_PROTOCOL_SCHEMAS: {
537
+ readonly request: {
538
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
539
+ readonly title: "EngineProtocolRequestFrame";
540
+ readonly type: "object";
541
+ readonly additionalProperties: false;
542
+ readonly required: readonly ["id", "method", "params"];
543
+ readonly properties: {
544
+ readonly id: {
545
+ readonly type: "number";
546
+ };
547
+ readonly method: {
548
+ readonly type: "string";
549
+ readonly enum: readonly ["initialize", "probe", "run", "cancel", "interact", "read", "listModels", "validateModel", "dispose", "ping"];
550
+ };
551
+ readonly params: {};
552
+ };
553
+ };
554
+ readonly successResponse: {
555
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
556
+ readonly title: "EngineProtocolSuccessResponseFrame";
557
+ readonly type: "object";
558
+ readonly additionalProperties: false;
559
+ readonly required: readonly ["id", "result"];
560
+ readonly properties: {
561
+ readonly id: {
562
+ readonly type: readonly ["number", "string"];
563
+ };
564
+ readonly result: {};
565
+ };
566
+ };
567
+ readonly errorResponse: {
568
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
569
+ readonly title: "EngineProtocolErrorResponseFrame";
570
+ readonly type: "object";
571
+ readonly additionalProperties: false;
572
+ readonly required: readonly ["id", "error"];
573
+ readonly properties: {
574
+ readonly id: {
575
+ readonly type: readonly ["number", "string"];
576
+ };
577
+ readonly error: {
578
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
579
+ readonly title: "EngineProtocolError";
580
+ readonly type: "object";
581
+ readonly additionalProperties: false;
582
+ readonly required: readonly ["code", "message", "recovery"];
583
+ readonly properties: {
584
+ readonly code: {
585
+ readonly type: "string";
586
+ readonly pattern: "^engine_";
587
+ };
588
+ readonly message: {
589
+ readonly type: "string";
590
+ };
591
+ readonly recovery: {
592
+ readonly type: "string";
593
+ };
594
+ readonly data: {
595
+ readonly type: "object";
596
+ };
597
+ };
598
+ };
599
+ };
600
+ };
601
+ readonly notification: {
602
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
603
+ readonly title: "EngineProtocolNotificationFrame";
604
+ readonly type: "object";
605
+ readonly additionalProperties: false;
606
+ readonly required: readonly ["method", "params"];
607
+ readonly properties: {
608
+ readonly method: {
609
+ readonly type: "string";
610
+ readonly const: "event";
611
+ };
612
+ readonly params: {
613
+ readonly type: "object";
614
+ readonly additionalProperties: false;
615
+ readonly required: readonly ["runId", "seq", "event"];
616
+ readonly properties: {
617
+ readonly runId: {
618
+ readonly type: "string";
619
+ };
620
+ readonly seq: {
621
+ readonly type: "number";
622
+ };
623
+ readonly event: {
624
+ readonly type: "object";
625
+ readonly required: readonly ["type"];
626
+ readonly properties: {
627
+ readonly type: {
628
+ readonly type: "string";
629
+ readonly enum: readonly ["tool_start", "tool_end", "text_delta", "thinking_delta", "turn_end", "message_end", "compaction", "error"];
630
+ };
631
+ };
632
+ };
633
+ };
634
+ };
635
+ };
636
+ };
637
+ readonly reverseRequest: {
638
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
639
+ readonly title: "EngineProtocolReverseRequestFrame";
640
+ readonly type: "object";
641
+ readonly additionalProperties: false;
642
+ readonly required: readonly ["id", "method", "params"];
643
+ readonly properties: {
644
+ readonly id: {
645
+ readonly type: "string";
646
+ };
647
+ readonly method: {
648
+ readonly type: "string";
649
+ readonly enum: readonly ["host/log", "host/askUser", "host/permission", "host/streamDelta", "host/poolResolved", "host/handleReady", "host/childSpawned", "host/childStateChanged", "host/roundLifecycle"];
650
+ };
651
+ readonly params: {};
652
+ };
653
+ };
654
+ readonly protocolError: {
655
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
656
+ readonly title: "EngineProtocolError";
657
+ readonly type: "object";
658
+ readonly additionalProperties: false;
659
+ readonly required: readonly ["code", "message", "recovery"];
660
+ readonly properties: {
661
+ readonly code: {
662
+ readonly type: "string";
663
+ readonly pattern: "^engine_";
664
+ };
665
+ readonly message: {
666
+ readonly type: "string";
667
+ };
668
+ readonly recovery: {
669
+ readonly type: "string";
670
+ };
671
+ readonly data: {
672
+ readonly type: "object";
673
+ };
674
+ };
675
+ };
676
+ };
677
+ /**
678
+ * 协议面凭据禁区键名(不变量 5 的测试断言依据):帧 schema 与深载荷 TS 类型面
679
+ * 不得出现。词表覆盖常见拼写(子串匹配,非精确枚举)。
680
+ */
681
+ declare const FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS: readonly ["apikey", "api_key", "token", "credential", "password", "secret"];
682
+ /** 反向通道名词表导出(schema enum 与 W2 路由同源)。 */
683
+ declare const REVERSE_CHANNEL_NAMES: readonly ReverseChannel[];
684
+
685
+ export { AgentCallOpts, AgentOutcome, AgentUsage, CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, type CancelParams, type CancelResult, type DisposeParams, type DisposeResult, ENGINE_EVENT_COALESCE_DEFAULT, ENGINE_EVENT_COALESCE_ENV, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, EngineCapabilities, EngineHandleData, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, type HostAskUserParams, type HostAskUserResult, type HostChildSpawnedParams, type HostChildStateChangedParams, type HostHandleReadyParams, type HostLogParams, type HostPermissionParams, type HostPermissionResult, type HostPoolResolvedParams, type HostRoundLifecycleParams, type HostStreamDeltaParams, type InitializeParams, type InitializeResult, InteractAction, type InteractParams, InteractResult, type ListModelsParams, type ListModelsResult, ModelCatalogEntry, PROTOCOL_METHODS, type PingParams, type PingResult, type ProbeParams, ProbeReport, ProtocolError, type ProtocolMethod, type ProtocolParamsMap, type ProtocolResultMap, REVERSE_CHANNELS, REVERSE_CHANNEL_NAMES, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, type ReadParams, ResumeAnchor, type ReverseChannel, type ReverseChannelParamsMap, type ReverseChannelResultMap, type ReverseRequestTimeoutClass, type RoundFailedPhase, type RoundIdlePhase, type RoundKeyedByRecord, type RoundKeyedByRun, type RoundLifecyclePhase, type RoundSettledPhase, type RunChatParams, type RunContextParams, type RunParams, type RunResult, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, SessionView, type ValidateModelParams, type ValidateModelResult, errorResponseFrameSchema, isHostRoundLifecycleParams, isHostStreamDeltaParams, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, successResponseFrameSchema };