@zhushanwen/subagent-engine-sdk 0.2.1 → 0.3.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 (59) hide show
  1. package/dist/{chunk-A75XDJIC.js → chunk-AIG5LSGK.js} +3 -0
  2. package/dist/{chunk-ZXEAW25V.js → chunk-BBVZK5DL.js} +1 -4
  3. package/dist/chunk-EUSM6ZX4.js +10 -0
  4. package/dist/{chunk-LEOBWKRM.js → chunk-FJT23P7T.js} +1 -1
  5. package/dist/{chunk-N3RL6OVM.js → chunk-J4G2MXDS.js} +3 -1
  6. package/dist/{chunk-ZOFFJNJD.js → chunk-LKPVN3N6.js} +1 -1
  7. package/dist/{chunk-RULLX6C6.js → chunk-LQR73V67.js} +2 -0
  8. package/dist/{chunk-YFSN3D5N.js → chunk-TGDMOLZU.js} +25 -17
  9. package/dist/{chunk-PPEPBVCC.js → chunk-WS4WAZVR.js} +1 -1
  10. package/dist/cli-entry.cjs +3 -1
  11. package/dist/cli-entry.js +1 -1
  12. package/dist/{contract-types-sSlgppBC.d.cts → contract-types-ByIFoLrY.d.cts} +18 -34
  13. package/dist/{contract-types-sSlgppBC.d.ts → contract-types-ByIFoLrY.d.ts} +18 -34
  14. package/dist/env.cjs +1 -4
  15. package/dist/env.d.cts +4 -1
  16. package/dist/env.d.ts +4 -1
  17. package/dist/env.js +1 -1
  18. package/dist/{error-codes-Dhss2Kmk.d.ts → error-codes-BUx92qYi.d.ts} +5 -4
  19. package/dist/{error-codes-DHco5-i_.d.cts → error-codes-DCiilt_8.d.cts} +5 -4
  20. package/dist/index.cjs +45 -23
  21. package/dist/index.d.cts +5 -5
  22. package/dist/index.d.ts +5 -5
  23. package/dist/index.js +16 -11
  24. package/dist/journal-io.d.cts +1 -1
  25. package/dist/journal-io.d.ts +1 -1
  26. package/dist/journal-replay.cjs +3 -0
  27. package/dist/journal-replay.d.cts +1 -1
  28. package/dist/journal-replay.d.ts +1 -1
  29. package/dist/journal-replay.js +1 -1
  30. package/dist/kill-chain.d.cts +2 -2
  31. package/dist/kill-chain.d.ts +2 -2
  32. package/dist/kill-chain.js +2 -2
  33. package/dist/node-executor.js +2 -2
  34. package/dist/port-contract.cjs +3 -0
  35. package/dist/port-contract.d.cts +41 -8
  36. package/dist/port-contract.d.ts +41 -8
  37. package/dist/port-contract.js +3 -1
  38. package/dist/protocol/index.cjs +26 -18
  39. package/dist/protocol/index.d.cts +95 -96
  40. package/dist/protocol/index.d.ts +95 -96
  41. package/dist/protocol/index.js +4 -4
  42. package/dist/ui-types.cjs +16 -0
  43. package/dist/ui-types.d.cts +13 -6
  44. package/dist/ui-types.d.ts +13 -6
  45. package/dist/ui-types.js +7 -1
  46. package/package.json +1 -1
  47. package/src/cli-entry.ts +6 -1
  48. package/src/data-dir.ts +3 -2
  49. package/src/env.ts +4 -4
  50. package/src/journal-replay.ts +4 -0
  51. package/src/port-contract.ts +40 -8
  52. package/src/protocol/contract-types.ts +20 -23
  53. package/src/protocol/engine-protocol.ts +19 -9
  54. package/src/protocol/error-codes.ts +7 -6
  55. package/src/protocol/methods.ts +38 -28
  56. package/src/protocol/reverse-channels.ts +15 -103
  57. package/src/protocol/schema.ts +36 -0
  58. package/src/ui-types.ts +22 -5
  59. package/dist/chunk-2DIMPZCQ.js +0 -0
@@ -1,7 +1,6 @@
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';
1
+ 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, P as ProtocolError, 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-BUx92qYi.js';
2
+ import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-ByIFoLrY.js';
3
+ export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-ByIFoLrY.js';
5
4
  import { UiRequest, UiResponse } from '../ui-types.js';
6
5
 
7
6
  /** 协议版本(引擎包 manifest `xyz-agent.subagentEngine.protocol` 与 initialize 应答同值)。 */
@@ -33,17 +32,20 @@ declare const ENGINE_EVENT_COALESCE_DEFAULT = "0";
33
32
  /**
34
33
  * 反向请求超时二分(帧④注释,R9-2):
35
34
  * - 数据面类(host/log / host/streamDelta / host/poolResolved / host/handleReady /
36
- * host/childSpawned / host/childStateChanged / host/roundLifecycle[v1.x]):10s 未答 =
37
- * 引擎故障;
35
+ * host/childSpawned / host/childStateChanged):10s 未答 = 引擎故障;
38
36
  * - 人机交互类(host/askUser / host/permission):不设统一超时——core 先回 {ack:true},
39
37
  * 结果异步到达;按 ADR-0047「静默 ≠ 卡死」用无进展检测/用户取消,不据此判引擎故障。
40
38
  */
41
39
  type ReverseRequestTimeoutClass = "data-plane" | "interaction";
42
40
 
43
- /** 正向方法名联合(恰好 10 个;PROTOCOL_METHODS 常量数组与之同源互证)。 */
44
- type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "interact" | "read" | "listModels" | "validateModel" | "dispose" | "ping";
41
+ /**
42
+ * 正向方法名联合(恰好 9 个;PROTOCOL_METHODS 常量数组与之同源互证)。
43
+ * [H1] `interact` 成员已随 chat-run 统一退役(docs/design/subagent-chat-run-unification.md
44
+ * §3.3 D5:续聊轮统一为「新 run + resume 锚点」,U5 删除)。
45
+ */
46
+ type ProtocolMethod = "initialize" | "probe" | "run" | "cancel" | "read" | "listModels" | "validateModel" | "dispose" | "ping";
45
47
  /** 方法名全集(运行时顺序化枚举;与 ProtocolMethod 的同源关系由测试断言)。 */
46
- declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel", "interact", "read", "listModels", "validateModel", "dispose", "ping"];
48
+ declare const PROTOCOL_METHODS: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
47
49
  /**
48
50
  * run 上下文(RunContext 字段映射的协议承载,设计 §3.3 RunContext 映射表)。
49
51
  */
@@ -65,19 +67,35 @@ interface RunContextParams {
65
67
  };
66
68
  /** 事件粒度请求(引擎按 capabilities.eventGranularity 实际能力执行)。 */
67
69
  streamMode?: "stream" | "coarse";
70
+ /**
71
+ * [F6] 根 session id——pi 引擎 relay 归属键 SESSION_ID 的权威来源(生产三来源
72
+ * ①本字段 ②宿主 env ③根进程 env 中,宿主派发恒走①)。additive 可选:旧引擎忽略
73
+ * 未知字段,undefined 不上 wire。
74
+ */
75
+ sessionRootId?: string;
76
+ /**
77
+ * [Option C 协议化] 权威 subagent session 目录——宿主以 getSubagentSessionDir
78
+ * (agentDir, rootCwd) 推导(宿主单一权威,Fix Gate B S6:引擎本地推导与宿主布局
79
+ * 三处不等价 → 跨重启续聊链断裂)。引擎用它组装 pi `--session-dir`,不自推导;
80
+ * 缺省(独立运行/测试)走引擎内 [LEGACY] fallback。additive 可选:旧引擎忽略
81
+ * 未知字段,undefined 不上 wire。
82
+ */
83
+ sessionDir?: string;
68
84
  }
69
85
  /**
70
- * [v1.x] chat 会话形态参数——HostChatRoundTicket 五字段过协议映射中「record」的
71
- * 承载位(docs/design/chat-domain-v1x-liveness-governance.md §3.2 D1 五字段映射):
86
+ * [H1] run resume 会话形态参数(设计 docs/design/subagent-chat-run-unification.md
87
+ * §3.3 D3 + §5 U1/U6 行):原 RunChatParams(v1.x chat 会话形态参数)的泛化改名终态,
88
+ * 载荷同形(recordId + resume 锚点,ResumeAnchor 不变),仅键名从「chat 会话形态」
89
+ * 泛化为「resume 续聊」。
72
90
  * - recordId:core 预建 record 的关联键(引擎据此回填 handle.sessionRef、上报
73
- * host/childSpawned|childStateChanged 与 host/roundLifecycle 的 record 键形态);
91
+ * host/childSpawned|childStateChanged 的 record 键形态);
74
92
  * - resume:冷续锚点(重开已 idle 的 session 续聊;缺省 = 新 session)。对照
75
93
  * core SpawnResumeOpts——sessionFile 经 anchor.sessionRef 携带,model/
76
94
  * thinkingLevel 防漂移覆盖走既有 task/ctx 字段,不双写。
77
- * task.conversation === true 时必传(chat 路由前置 gate:manifest conversation 位
78
- * unsupported 的引擎同步拒 engine_capability_unsupported——见 error-codes.ts)。
95
+ * [H1 U6 已切换] `chat` 键整体退役(读写端同批切换,无「写新读旧」窗口),本键为
96
+ * 唯一会话形态参数。载荷 schema 权威 = runSessionParamsSchema(schema.ts)。
79
97
  */
80
- interface RunChatParams {
98
+ interface RunResumeParams {
81
99
  recordId: string;
82
100
  resume?: ResumeAnchor;
83
101
  }
@@ -109,11 +127,11 @@ interface RunParams {
109
127
  task: AgentCallOpts;
110
128
  ctx: RunContextParams;
111
129
  /**
112
- * [v1.x 可选增量] chat 会话形态参数(task.conversation=true chat 路由承载)。
113
- * 缺省 = 一次性任务形态,v1 引擎/宿主语义不变(向后兼容:旧引擎忽略未知字段,
114
- * 帧级 schema params 不做深校验)。续聊/关断不经此参数——走既有 interact
130
+ * [H1 U6 终态] resume 续聊参数(唯一会话形态键;原 v1.x `chat` 键已随键切换退役,
131
+ * RunResumeParams)。缺省 = 一次性任务形态(向后兼容:旧引擎忽略未知字段,
132
+ * 帧级 schema params 不做深校验)。additive 可选:undefined 不上 wire
115
133
  */
116
- chat?: RunChatParams;
134
+ resume?: RunResumeParams;
117
135
  }
118
136
  /** run 终态应答(期间事件经 event 通知;长运行方法,应答到达即终态)。 */
119
137
  interface RunResult {
@@ -131,10 +149,6 @@ interface CancelParams {
131
149
  interface CancelResult {
132
150
  ok: true;
133
151
  }
134
- interface InteractParams {
135
- handle: EngineHandleData;
136
- action: InteractAction;
137
- }
138
152
  interface ReadParams {
139
153
  handle: EngineHandleData;
140
154
  /** 数据根必填:存量池时代引擎自算池/journal 相对 dbPath 的定位需要它(设计钉死)。 */
@@ -174,7 +188,6 @@ interface ProtocolParamsMap {
174
188
  probe: ProbeParams;
175
189
  run: RunParams;
176
190
  cancel: CancelParams;
177
- interact: InteractParams;
178
191
  read: ReadParams;
179
192
  listModels: ListModelsParams;
180
193
  validateModel: ValidateModelParams;
@@ -187,7 +200,6 @@ interface ProtocolResultMap {
187
200
  probe: ProbeReport;
188
201
  run: RunResult;
189
202
  cancel: CancelResult;
190
- interact: InteractResult;
191
203
  read: SessionView;
192
204
  listModels: ListModelsResult;
193
205
  validateModel: ValidateModelResult;
@@ -195,13 +207,17 @@ interface ProtocolResultMap {
195
207
  ping: PingResult;
196
208
  }
197
209
 
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"];
210
+ /**
211
+ * 反向通道名联合(恰好 8 个;REVERSE_CHANNELS 常量数组与之同源互证)。
212
+ */
213
+ type ReverseChannel = "host/log" | "host/askUser" | "host/permission" | "host/streamDelta" | "host/poolResolved" | "host/handleReady" | "host/childSpawned" | "host/childStateChanged";
214
+ /**
215
+ * 通道名全集(运行时顺序化枚举;与 ReverseChannel 的同源关系由测试断言)。
216
+ */
217
+ declare const REVERSE_CHANNELS: readonly ["host/log", "host/askUser", "host/permission", "host/streamDelta", "host/poolResolved", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
201
218
  /**
202
219
  * 超时二分归属(10s 数据面 / 不设统一超时的人机交互面)。实现归 W2 EngineClient;
203
220
  * 引擎侧自灭计时(W12)复用同表——已 ack 的 askUser 等待不计入 in-flight(R9-2)。
204
- * host/roundLifecycle 属数据面(终态回执语义:宿主必须确认收到,10s 未答 = 引擎故障)。
205
221
  */
206
222
  declare const REVERSE_CHANNEL_TIMEOUT_CLASS: Record<ReverseChannel, ReverseRequestTimeoutClass>;
207
223
  /** host/log:引擎日志落宿主日志(对齐 core HostServices.log 调用面)。 */
@@ -240,11 +256,9 @@ type HostPermissionResult = {
240
256
  /**
241
257
  * host/streamDelta:UI 实时通道(双通道之一;与 event 通知并行的渲染加速面)。
242
258
  *
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 送达引擎)。
259
+ * [H1 U6 现行语义] 关联键恒 runId(run 域轮与 chat 续聊轮已统一为 run——续聊轮
260
+ * 是携带 resume 锚点的新 runrunId 由 core 在 run 帧分配)。recordId 键分支是
261
+ * v1.x 旧引擎的兼容载荷形态(存量兼容读,现行引擎不写)。
248
262
  * 两键互斥(undefined 孪生位防双填),消费侧经 isHostStreamDeltaParams 收窄。
249
263
  */
250
264
  type HostStreamDeltaParams = {
@@ -298,57 +312,6 @@ interface HostChildStateChangedParams {
298
312
  exitCode?: number;
299
313
  signal?: string;
300
314
  }
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
315
  /** 通道 → 载荷类型映射。 */
353
316
  interface ReverseChannelParamsMap {
354
317
  "host/log": HostLogParams;
@@ -359,7 +322,6 @@ interface ReverseChannelParamsMap {
359
322
  "host/handleReady": HostHandleReadyParams;
360
323
  "host/childSpawned": HostChildSpawnedParams;
361
324
  "host/childStateChanged": HostChildStateChangedParams;
362
- "host/roundLifecycle": HostRoundLifecycleParams;
363
325
  }
364
326
  /** 通道 → 异步/同步结果类型映射(ack 两阶段通道的第二阶段 result)。 */
365
327
  interface ReverseChannelResultMap {
@@ -383,9 +345,6 @@ interface ReverseChannelResultMap {
383
345
  "host/childStateChanged": {
384
346
  ok: true;
385
347
  };
386
- "host/roundLifecycle": {
387
- ok: true;
388
- };
389
348
  }
390
349
 
391
350
  /** 协议错误对象 schema。 */
@@ -424,7 +383,7 @@ declare const requestFrameSchema: {
424
383
  };
425
384
  readonly method: {
426
385
  readonly type: "string";
427
- readonly enum: readonly ["initialize", "probe", "run", "cancel", "interact", "read", "listModels", "validateModel", "dispose", "ping"];
386
+ readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
428
387
  };
429
388
  readonly params: {};
430
389
  };
@@ -506,7 +465,7 @@ declare const notificationFrameSchema: {
506
465
  readonly properties: {
507
466
  readonly type: {
508
467
  readonly type: "string";
509
- readonly enum: readonly ["tool_start", "tool_end", "text_delta", "thinking_delta", "turn_end", "message_end", "compaction", "error"];
468
+ readonly enum: readonly ["tool_start", "tool_end", "text_delta", "thinking_delta", "turn_end", "message_end", "compaction", "activity", "error"];
510
469
  };
511
470
  };
512
471
  };
@@ -527,7 +486,7 @@ declare const reverseRequestFrameSchema: {
527
486
  };
528
487
  readonly method: {
529
488
  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"];
489
+ readonly enum: readonly ["host/log", "host/askUser", "host/permission", "host/streamDelta", "host/poolResolved", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
531
490
  };
532
491
  readonly params: {};
533
492
  };
@@ -546,7 +505,7 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
546
505
  };
547
506
  readonly method: {
548
507
  readonly type: "string";
549
- readonly enum: readonly ["initialize", "probe", "run", "cancel", "interact", "read", "listModels", "validateModel", "dispose", "ping"];
508
+ readonly enum: readonly ["initialize", "probe", "run", "cancel", "read", "listModels", "validateModel", "dispose", "ping"];
550
509
  };
551
510
  readonly params: {};
552
511
  };
@@ -626,7 +585,7 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
626
585
  readonly properties: {
627
586
  readonly type: {
628
587
  readonly type: "string";
629
- readonly enum: readonly ["tool_start", "tool_end", "text_delta", "thinking_delta", "turn_end", "message_end", "compaction", "error"];
588
+ readonly enum: readonly ["tool_start", "tool_end", "text_delta", "thinking_delta", "turn_end", "message_end", "compaction", "activity", "error"];
630
589
  };
631
590
  };
632
591
  };
@@ -646,7 +605,7 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
646
605
  };
647
606
  readonly method: {
648
607
  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"];
608
+ readonly enum: readonly ["host/log", "host/askUser", "host/permission", "host/streamDelta", "host/poolResolved", "host/handleReady", "host/childSpawned", "host/childStateChanged"];
650
609
  };
651
610
  readonly params: {};
652
611
  };
@@ -681,5 +640,45 @@ declare const ENGINE_PROTOCOL_SCHEMAS: {
681
640
  declare const FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS: readonly ["apikey", "api_key", "token", "credential", "password", "secret"];
682
641
  /** 反向通道名词表导出(schema enum 与 W2 路由同源)。 */
683
642
  declare const REVERSE_CHANNEL_NAMES: readonly ReverseChannel[];
643
+ /**
644
+ * run.params 的会话形态参数载荷 schema(draft-07 深载荷片段)。设计权威源:
645
+ * docs/design/subagent-chat-run-unification.md §3.3 D3 + §5 U1/U6 行。
646
+ *
647
+ * [H1 U6 已切换] 键切换单批完成后本 schema 面向唯一键 `resume`(RunResumeParams:
648
+ * recordId + 可选 ResumeAnchor),形状不变。帧级 schema(requestFrameSchema.params)
649
+ * 刻意不做深校验(见本文件头注释),本片段供消费方(引擎读端结构化报错 / 测试正负
650
+ * 样本)按需深校验。
651
+ */
652
+ declare const runSessionParamsSchema: {
653
+ readonly $schema: "http://json-schema.org/draft-07/schema#";
654
+ readonly title: "EngineRunSessionParams";
655
+ readonly type: "object";
656
+ readonly additionalProperties: false;
657
+ readonly required: readonly ["recordId"];
658
+ readonly properties: {
659
+ readonly recordId: {
660
+ readonly type: "string";
661
+ };
662
+ readonly resume: {
663
+ readonly type: "object";
664
+ readonly additionalProperties: false;
665
+ readonly required: readonly ["sessionRef", "poolKey"];
666
+ readonly properties: {
667
+ readonly sessionRef: {
668
+ readonly type: "object";
669
+ readonly additionalProperties: {
670
+ readonly type: "string";
671
+ };
672
+ };
673
+ readonly poolKey: {
674
+ readonly type: "string";
675
+ };
676
+ readonly journalPath: {
677
+ readonly type: "string";
678
+ };
679
+ };
680
+ };
681
+ };
682
+ };
684
683
 
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 };
684
+ export { AgentCallOpts, AgentOutcome, 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 HostStreamDeltaParams, type InitializeParams, type InitializeResult, type ListModelsParams, type ListModelsResult, ModelCatalogEntry, PROTOCOL_METHODS, type PingParams, type PingResult, type ProbeParams, ProbeReport, 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 RunContextParams, type RunParams, type RunResult, type RunResumeParams, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, SessionView, type ValidateModelParams, type ValidateModelResult, errorResponseFrameSchema, isHostStreamDeltaParams, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema };
@@ -6,7 +6,6 @@ import {
6
6
  REVERSE_CHANNEL_NAMES,
7
7
  REVERSE_CHANNEL_TIMEOUT_CLASS,
8
8
  errorResponseFrameSchema,
9
- isHostRoundLifecycleParams,
10
9
  isHostStreamDeltaParams,
11
10
  isNotificationFrame,
12
11
  isRequestFrame,
@@ -16,8 +15,9 @@ import {
16
15
  protocolErrorSchema,
17
16
  requestFrameSchema,
18
17
  reverseRequestFrameSchema,
18
+ runSessionParamsSchema,
19
19
  successResponseFrameSchema
20
- } from "../chunk-YFSN3D5N.js";
20
+ } from "../chunk-TGDMOLZU.js";
21
21
  import {
22
22
  CANCEL_SETTLE_GRACE_MS,
23
23
  CRASH_REBUILD_BACKOFF_MS,
@@ -42,7 +42,7 @@ import {
42
42
  isEngineProtocolErrorCode,
43
43
  isProtocolVersionCompatible,
44
44
  schemaEmulationFailedDetail
45
- } from "../chunk-PPEPBVCC.js";
45
+ } from "../chunk-WS4WAZVR.js";
46
46
  import "../chunk-JSBRDJBE.js";
47
47
  export {
48
48
  CANCEL_SETTLE_GRACE_MS,
@@ -73,7 +73,6 @@ export {
73
73
  errorResponseFrameSchema,
74
74
  isEngineErrorPassthroughCode,
75
75
  isEngineProtocolErrorCode,
76
- isHostRoundLifecycleParams,
77
76
  isHostStreamDeltaParams,
78
77
  isNotificationFrame,
79
78
  isProtocolVersionCompatible,
@@ -84,6 +83,7 @@ export {
84
83
  protocolErrorSchema,
85
84
  requestFrameSchema,
86
85
  reverseRequestFrameSchema,
86
+ runSessionParamsSchema,
87
87
  schemaEmulationFailedDetail,
88
88
  successResponseFrameSchema
89
89
  };
package/dist/ui-types.cjs CHANGED
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
6
10
  var __copyProps = (to, from, except, desc) => {
7
11
  if (from && typeof from === "object" || typeof from === "function") {
8
12
  for (let key of __getOwnPropNames(from))
@@ -15,4 +19,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
19
 
16
20
  // src/ui-types.ts
17
21
  var ui_types_exports = {};
22
+ __export(ui_types_exports, {
23
+ isUiResponse: () => isUiResponse
24
+ });
18
25
  module.exports = __toCommonJS(ui_types_exports);
26
+ function isUiResponse(value) {
27
+ if (typeof value !== "object" || value === null) return false;
28
+ const v = value;
29
+ return typeof v.value === "string" || typeof v.confirmed === "boolean" || v.cancelled === true || v.ack === true;
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ isUiResponse
34
+ });
@@ -3,11 +3,12 @@
3
3
  * fire-and-forget 类:notify/setStatus/setWidget/setTitle/set_editor_text(纯展示/写入)。
4
4
  * (string & {}) 兜底:Pi 未来新增 method 或未知 method 走字符串字面量类型。 */
5
5
  type UiMethod = "select" | "confirm" | "input" | "editor" | "notify" | "setStatus" | "setWidget" | "setTitle" | "set_editor_text" | (string & {});
6
- /** UI 请求(session-runner 构造后传给 handler)。
6
+ /** UI 请求(引擎侧构造后经 host/askUser 送达宿主 handler)。
7
7
  *
8
8
  * method 是判别字段,决定排队策略(dialog 排队)和业务路由(channel 分发)。
9
- * method 特定字段按 method 可选出现(与 ExtensionUiRequest 1:1,由 session-runner 从
10
- * ExtensionUiRequest 平铺构造)。channel/channelPayload 由 parseChannel 填充。
9
+ * method 特定字段按 method 可选出现(与 ExtensionUiRequest 1:1,由引擎侧
10
+ * ui-request-queue 从 ExtensionUiRequest 平铺构造)。channel/channelPayload 由
11
+ * parseChannel 填充。
11
12
  *
12
13
  * 契约来源:.fix-plans/00-master-summary.md §二 2.2。 */
13
14
  interface UiRequest {
@@ -35,8 +36,10 @@ interface UiRequest {
35
36
  /** channel 解析后的结构化 payload(已 JSON.parse)。
36
37
  * ask_user: {questions, allowCancel};gui_widget: {component};无 channel: undefined。 */
37
38
  channelPayload?: unknown;
38
- /** 内部元数据字段:发起该 UI 请求的子进程 pid(由 session-runner.handleUiRequest
39
- * child.pid 填入)。L2 队列据此关联 rejectChildDialogs(child close 时批量 reject)。
39
+ /** 内部元数据字段:发起该 UI 请求的子进程 pid(由引擎侧 ui-request-queue
40
+ * child.pid 填入——session-runner 已随协议化重构删除,填充点现住 pi 引擎包)。
41
+ * L2 队列据此关联 rejectChildDialogs(子进程退出时批量取消,见
42
+ * notifyChildProcessExited 的接线链)。
40
43
  * 下划线前缀表示内部字段,非 Pi 协议字段,不参与 stdin 回写。 */
41
44
  _childPid?: number;
42
45
  }
@@ -54,9 +57,13 @@ type UiResponse = {
54
57
  } | {
55
58
  ack: true;
56
59
  };
60
+ /** UiResponse 载荷结构判定(四成员判别;形态对齐 reverse-channels 的
61
+ * isHostStreamDeltaParams 先例)。消费方:引擎侧应答落位前守卫,防宿主畸形帧
62
+ * 静默流入 UI 队列(S7:askUser 应答跨界无守卫)。 */
63
+ declare function isUiResponse(value: unknown): value is UiResponse;
57
64
  /** UI 请求 handler 签名(单函数,按 req.method 内部路由)。
58
65
  * 实现方负责:channel 业务路由(ask_user → AskUserComponent)+ 默认转发(ctx.ui.*)。
59
66
  * 抛错由调用方(DialogGlobalQueue / session-runner)兜底为 {cancelled:true}。 */
60
67
  type UiRequestHandler = (req: UiRequest) => Promise<UiResponse>;
61
68
 
62
- export type { UiMethod, UiRequest, UiRequestHandler, UiResponse };
69
+ export { type UiMethod, type UiRequest, type UiRequestHandler, type UiResponse, isUiResponse };
@@ -3,11 +3,12 @@
3
3
  * fire-and-forget 类:notify/setStatus/setWidget/setTitle/set_editor_text(纯展示/写入)。
4
4
  * (string & {}) 兜底:Pi 未来新增 method 或未知 method 走字符串字面量类型。 */
5
5
  type UiMethod = "select" | "confirm" | "input" | "editor" | "notify" | "setStatus" | "setWidget" | "setTitle" | "set_editor_text" | (string & {});
6
- /** UI 请求(session-runner 构造后传给 handler)。
6
+ /** UI 请求(引擎侧构造后经 host/askUser 送达宿主 handler)。
7
7
  *
8
8
  * method 是判别字段,决定排队策略(dialog 排队)和业务路由(channel 分发)。
9
- * method 特定字段按 method 可选出现(与 ExtensionUiRequest 1:1,由 session-runner 从
10
- * ExtensionUiRequest 平铺构造)。channel/channelPayload 由 parseChannel 填充。
9
+ * method 特定字段按 method 可选出现(与 ExtensionUiRequest 1:1,由引擎侧
10
+ * ui-request-queue 从 ExtensionUiRequest 平铺构造)。channel/channelPayload 由
11
+ * parseChannel 填充。
11
12
  *
12
13
  * 契约来源:.fix-plans/00-master-summary.md §二 2.2。 */
13
14
  interface UiRequest {
@@ -35,8 +36,10 @@ interface UiRequest {
35
36
  /** channel 解析后的结构化 payload(已 JSON.parse)。
36
37
  * ask_user: {questions, allowCancel};gui_widget: {component};无 channel: undefined。 */
37
38
  channelPayload?: unknown;
38
- /** 内部元数据字段:发起该 UI 请求的子进程 pid(由 session-runner.handleUiRequest
39
- * child.pid 填入)。L2 队列据此关联 rejectChildDialogs(child close 时批量 reject)。
39
+ /** 内部元数据字段:发起该 UI 请求的子进程 pid(由引擎侧 ui-request-queue
40
+ * child.pid 填入——session-runner 已随协议化重构删除,填充点现住 pi 引擎包)。
41
+ * L2 队列据此关联 rejectChildDialogs(子进程退出时批量取消,见
42
+ * notifyChildProcessExited 的接线链)。
40
43
  * 下划线前缀表示内部字段,非 Pi 协议字段,不参与 stdin 回写。 */
41
44
  _childPid?: number;
42
45
  }
@@ -54,9 +57,13 @@ type UiResponse = {
54
57
  } | {
55
58
  ack: true;
56
59
  };
60
+ /** UiResponse 载荷结构判定(四成员判别;形态对齐 reverse-channels 的
61
+ * isHostStreamDeltaParams 先例)。消费方:引擎侧应答落位前守卫,防宿主畸形帧
62
+ * 静默流入 UI 队列(S7:askUser 应答跨界无守卫)。 */
63
+ declare function isUiResponse(value: unknown): value is UiResponse;
57
64
  /** UI 请求 handler 签名(单函数,按 req.method 内部路由)。
58
65
  * 实现方负责:channel 业务路由(ask_user → AskUserComponent)+ 默认转发(ctx.ui.*)。
59
66
  * 抛错由调用方(DialogGlobalQueue / session-runner)兜底为 {cancelled:true}。 */
60
67
  type UiRequestHandler = (req: UiRequest) => Promise<UiResponse>;
61
68
 
62
- export type { UiMethod, UiRequest, UiRequestHandler, UiResponse };
69
+ export { type UiMethod, type UiRequest, type UiRequestHandler, type UiResponse, isUiResponse };
package/dist/ui-types.js CHANGED
@@ -1 +1,7 @@
1
- import "./chunk-2DIMPZCQ.js";
1
+ import {
2
+ isUiResponse
3
+ } from "./chunk-EUSM6ZX4.js";
4
+ import "./chunk-JSBRDJBE.js";
5
+ export {
6
+ isUiResponse
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/subagent-engine-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Engine-side SDK for the subagent engine protocol: NDJSON stdio contract types, engine primitives (schema emulation, nesting guard, kill chain, journal replay projection, data-dir/paths resolution) — the shared contract root between subagent-core and engine CLI packages (engines import SDK only, never core)",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/cli-entry.ts CHANGED
@@ -51,7 +51,12 @@ export function runEngineCliEntry(opts: RunEngineCliEntryOptions): void {
51
51
  log(level, component, message, data) {
52
52
  // stderr 兜底先落(反向通道未就绪/失败时日志不丢);host/log 为数据面反向请求
53
53
  // (10s 应答分类),失败吞掉——日志面不能拖垮主链路。
54
- process.stderr.write(`[${level}] [${component}] ${message}${data !== undefined ? ` ${JSON.stringify(data)}` : ""}\n`);
54
+ // debug 不写 stderr:对齐 logger.ts CONSOLE_SINK 的「debug no-op」语义——
55
+ // 引擎 stderr 落宿主 [rpc:stderr] 全量 ERROR 级链路,debug 刷屏会淹没真异常
56
+ // (常态路径的分级降噪依赖此跳过);host/log 反向请求仍全级别透传。
57
+ if (level !== "debug") {
58
+ process.stderr.write(`[${level}] [${component}] ${message}${data !== undefined ? ` ${JSON.stringify(data)}` : ""}\n`);
59
+ }
55
60
  void server.reverseRequest("host/log", { level, component, message }).catch(() => undefined);
56
61
  },
57
62
  });
package/src/data-dir.ts CHANGED
@@ -12,8 +12,9 @@
12
12
  // warn-once 语义(回退非权威通道必须可观测),与 core 版行为逐字对齐。
13
13
  //
14
14
  // 通道调查结论(2026-08-25,P2 实测证据链,自 core 版头部保留):
15
- // - runtime spawn pi 主会话时 RpcClient.buildSafeEnv 从 runtime process.env 继承
16
- // XYZ_ 前缀白名单变量(rpc-client.ts:14-30),且显式设置 PI_CODING_AGENT_DIR;
15
+ // - runtime spawn pi 主会话时 RpcClient 出站 env 从 runtime process.env 继承
16
+ // XYZ_ 前缀白名单变量(调查当时经私有 buildSafeEnv,现已被 buildPiOutboundEnv
17
+ // → buildOutboundChildEnv 共享构建器取代),且显式设置 PI_CODING_AGENT_DIR;
17
18
  // - dev 模式 Electron main 设置 XYZ_AGENT_DATA_DIR(apps/electron/main/main.ts:122),
18
19
  // 经 process-control.ts:262 透传给 runtime → 透传链成立;
19
20
  // - prod 默认路径(~/.xyz-agent 缺省)下 runtime 进程 env 中**没有**该变量
package/src/env.ts CHANGED
@@ -23,16 +23,16 @@ export const ENGINE_ENV_PREFIXES: readonly string[] = [
23
23
  'XYZ_', 'XYZ_AGENT_', 'XYZ_SUBAGENT_',
24
24
  ];
25
25
 
26
- /** L1 deny + 显式剥除键集(镜像 shared SSOT,勿单独改动)。 */
26
+ /** L1 deny + 显式剥除键集(镜像 shared SSOT,勿单独改动)。
27
+ * 互引(场景域分化,勿互混):dev 装配器(apps/electron/scripts/dev-instance-lib.mjs
28
+ * `LEAK_ENV_KEYS`)仍剥 RELAY_STD* 三键——dev 宿主进程环境防泄漏口径独立于引擎
29
+ * spawn 面;本清单(引擎侧)已退役同名三键,写入方已清零。 */
27
30
  export const ENGINE_ENV_DENY_LIST: readonly string[] = [
28
31
  'XYZ_AGENT_PACKAGED',
29
32
  'XYZ_RUNTIME_TOKEN',
30
33
  'XYZ_AGENT_API_KEY',
31
34
  'XYZ_SUBAGENT_RELAY_SESSION_ID',
32
35
  'XYZ_SUBAGENT_RELAY_RECORD_ID',
33
- 'XYZ_SUBAGENT_RELAY_STDIN',
34
- 'XYZ_SUBAGENT_RELAY_STDOUT',
35
- 'XYZ_SUBAGENT_RELAY_STDERR',
36
36
  ];
37
37
 
38
38
  // ─────────────────────────────────────────────────────────────────────────────
@@ -349,6 +349,10 @@ export function updateFromEvent(record: ReplayRecordView, event: AgentEvent): vo
349
349
  case "compaction":
350
350
  return;
351
351
 
352
+ // ── activity:纯活性信号,reducer no-op(协议语义见 contract-types)──
353
+ case "activity":
354
+ return;
355
+
352
356
  default: {
353
357
  // 穷尽性检查:新增 AgentEvent variant 时编译期报错
354
358
  const _exhaustive: never = event;