@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,4 +1,4 @@
1
- import { A as AgentCallOpts, h as EngineHandleData, E as EngineCapabilities, P as ProbeReport, a as AgentEvent, k as ResumeAnchor, c as AgentOutcome, I as InteractAction, i as InteractResult, S as SessionView } from './contract-types-sSlgppBC.js';
1
+ import { A as AgentCallOpts, h as EngineHandleData, E as EngineCapabilities, P as ProbeReport, a as AgentEvent, i as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-ByIFoLrY.js';
2
2
 
3
3
  /**
4
4
  * 引擎进程内全量任务声明 = SDK AgentCallOpts 引擎面子集 + 协议 ctx 还原字段(model/
@@ -26,7 +26,16 @@ interface EngineCtxModel {
26
26
  interface EngineStream {
27
27
  onDelta(delta: string): void;
28
28
  }
29
- /** run 的运行期上下文(core RunContext 结构等价镜像;chat? = 会话形态参数,缺省一次性任务)。 */
29
+ /**
30
+ * 无隔离池引擎的恒定池 key(pi / zcode 共用;值锚定):两引擎进程内全局一份运行态
31
+ * (pi = PI_CODING_AGENT_DIR 全局一份,zcode = 共享宿主 HOME + journal 固定分组),
32
+ * poolKey 恒本值。core(PI_POOL_KEY / JOURNAL_INITIAL_POOL_KEY)与两引擎包
33
+ * (PI_POOL_KEY / ZCODE_SHARED_POOL_KEY)的等值异名常量一律 = 本常量——**值逐字
34
+ * 不变**(存量 journal 落盘路径与记录含该值分段,改名不改值)。zcode 池化引擎在
35
+ * prepare 期经 ctx.onPoolResolved retarget 到实际池 key,与本占位值不冲突。
36
+ */
37
+ declare const SHARED_POOL_KEY = "shared";
38
+ /** run 的运行期上下文(core RunContext 结构等价镜像;resume? = 会话形态参数,缺省一次性任务)。 */
30
39
  interface RunContext {
31
40
  taskId: string;
32
41
  poolKey: string;
@@ -39,6 +48,18 @@ interface RunContext {
39
48
  from: string;
40
49
  reason: string;
41
50
  };
51
+ /**
52
+ * [F6] 根 session id(协议 run.params.ctx.sessionRootId 的进程内还原)——pi 引擎
53
+ * relay 归属键 SESSION_ID 的权威来源。additive 可选:宿主缺省不传。
54
+ */
55
+ sessionRootId?: string;
56
+ /**
57
+ * [Option C 协议化] 权威 subagent session 目录(协议 run.params.ctx.sessionDir 的
58
+ * 进程内还原)——pi 引擎组装 `--session-dir` 的唯一权威值(宿主
59
+ * getSubagentSessionDir 推导,引擎不自推导)。additive 可选:缺省走引擎内
60
+ * [LEGACY] fallback(独立运行/测试形态)。
61
+ */
62
+ sessionDir?: string;
42
63
  onPoolResolved?: (poolKey: string) => void;
43
64
  onHandleReady?: (partial: Pick<EngineHandleData, "sessionRef" | "poolKey">) => void;
44
65
  /** 一次性子进程 pid 上报(host/childSpawned 载荷形态;ChildProcess 句柄不跨协议面)。 */
@@ -47,11 +68,24 @@ interface RunContext {
47
68
  killed: boolean;
48
69
  }) => void;
49
70
  /**
50
- * [v1.x] chat 会话形态参数(协议 run.params.chat 的进程内还原;缺省 = 一次性任务
51
- * 形态)。recordId = chat 轮次关联键与 interact 定位键;resume 锚点存在 = 冷续
52
- * (--session 续写原文件),不存在 = 首轮新建。
71
+ * 子进程退出态上报(host/childStateChanged 载荷形态;SR-4 接线:宿主镜像据此取消
72
+ * pid 的挂起 dialog)。引擎侧只在 exited 相位上报——running onChildSpawned 覆盖。
73
+ */
74
+ onChildStateChanged?: (p: {
75
+ pid: number;
76
+ recordId: string;
77
+ state: "running" | "exited";
78
+ killed: boolean;
79
+ exitCode?: number;
80
+ signal?: string;
81
+ }) => void;
82
+ /**
83
+ * [H1 U6 终态] resume 续聊参数(协议 run.params.resume 的进程内还原;唯一会话形态
84
+ * 键——原 v1.x `chat` 字段已随键切换退役)。recordId = 轮次关联键与镜像帧锚定键;
85
+ * resume 锚点存在 = 冷续(--session 续写原文件),不存在 = 首轮新建。缺省 =
86
+ * 一次性任务形态。
53
87
  */
54
- chat?: {
88
+ resume?: {
55
89
  recordId: string;
56
90
  resume?: ResumeAnchor;
57
91
  };
@@ -71,7 +105,6 @@ interface EnginePort {
71
105
  force?: boolean;
72
106
  }): Promise<ProbeReport>;
73
107
  run(task: EngineAgentCallOpts, ctx: RunContext): Promise<EngineRunResult>;
74
- interact(handle: EngineHandle, action: InteractAction): Promise<InteractResult>;
75
108
  read(handle: EngineHandle): Promise<SessionView>;
76
109
  listModels?(): Array<{
77
110
  id: string;
@@ -85,4 +118,4 @@ interface EnginePort {
85
118
  /** ctx.ctxModel("provider/id" canonical 词形)→ EngineCtxModel。 */
86
119
  declare function parseCtxModel(ref: string | undefined): EngineCtxModel | undefined;
87
120
 
88
- export { type EngineAgentCallOpts, type EngineCtxModel, type EngineHandle, type EnginePort, type EngineRunResult, type EngineStream, type RunContext, parseCtxModel };
121
+ export { type EngineAgentCallOpts, type EngineCtxModel, type EngineHandle, type EnginePort, type EngineRunResult, type EngineStream, type RunContext, SHARED_POOL_KEY, parseCtxModel };
@@ -1,7 +1,9 @@
1
1
  import {
2
+ SHARED_POOL_KEY,
2
3
  parseCtxModel
3
- } from "./chunk-RULLX6C6.js";
4
+ } from "./chunk-LQR73V67.js";
4
5
  import "./chunk-JSBRDJBE.js";
5
6
  export {
7
+ SHARED_POOL_KEY,
6
8
  parseCtxModel
7
9
  };
@@ -48,7 +48,6 @@ __export(protocol_exports, {
48
48
  errorResponseFrameSchema: () => errorResponseFrameSchema,
49
49
  isEngineErrorPassthroughCode: () => isEngineErrorPassthroughCode,
50
50
  isEngineProtocolErrorCode: () => isEngineProtocolErrorCode,
51
- isHostRoundLifecycleParams: () => isHostRoundLifecycleParams,
52
51
  isHostStreamDeltaParams: () => isHostStreamDeltaParams,
53
52
  isNotificationFrame: () => isNotificationFrame,
54
53
  isProtocolVersionCompatible: () => isProtocolVersionCompatible,
@@ -59,6 +58,7 @@ __export(protocol_exports, {
59
58
  protocolErrorSchema: () => protocolErrorSchema,
60
59
  requestFrameSchema: () => requestFrameSchema,
61
60
  reverseRequestFrameSchema: () => reverseRequestFrameSchema,
61
+ runSessionParamsSchema: () => runSessionParamsSchema,
62
62
  schemaEmulationFailedDetail: () => schemaEmulationFailedDetail,
63
63
  successResponseFrameSchema: () => successResponseFrameSchema
64
64
  });
@@ -114,7 +114,6 @@ var PROTOCOL_METHODS = [
114
114
  "probe",
115
115
  "run",
116
116
  "cancel",
117
- "interact",
118
117
  "read",
119
118
  "listModels",
120
119
  "validateModel",
@@ -131,8 +130,7 @@ var REVERSE_CHANNELS = [
131
130
  "host/poolResolved",
132
131
  "host/handleReady",
133
132
  "host/childSpawned",
134
- "host/childStateChanged",
135
- "host/roundLifecycle"
133
+ "host/childStateChanged"
136
134
  ];
137
135
  var REVERSE_CHANNEL_TIMEOUT_CLASS = {
138
136
  "host/log": "data-plane",
@@ -141,7 +139,6 @@ var REVERSE_CHANNEL_TIMEOUT_CLASS = {
141
139
  "host/handleReady": "data-plane",
142
140
  "host/childSpawned": "data-plane",
143
141
  "host/childStateChanged": "data-plane",
144
- "host/roundLifecycle": "data-plane",
145
142
  "host/askUser": "interaction",
146
143
  "host/permission": "interaction"
147
144
  };
@@ -153,17 +150,6 @@ function isHostStreamDeltaParams(value) {
153
150
  if (hasRunId === hasRecordId) return false;
154
151
  return typeof v.delta === "string";
155
152
  }
156
- function isHostRoundLifecycleParams(value) {
157
- if (typeof value !== "object" || value === null) return false;
158
- const v = value;
159
- const hasRunId = typeof v.runId === "string";
160
- const hasRecordId = typeof v.recordId === "string";
161
- if (hasRunId === hasRecordId) return false;
162
- if (v.phase === "settled" || v.phase === "idle") return true;
163
- if (v.phase !== "failed") return false;
164
- const err = v.error;
165
- return typeof err === "object" && err !== null && typeof err.code === "string" && typeof err.message === "string";
166
- }
167
153
 
168
154
  // src/protocol/error-codes.ts
169
155
  var ENGINE_PROTOCOL_ERROR_CODES = [
@@ -215,7 +201,7 @@ function engineProtocolMismatchError(engineVersion) {
215
201
  function engineConversationUnsupportedError(engineId) {
216
202
  return new EngineSdkError(
217
203
  "engine_capability_unsupported",
218
- `engine '${engineId}' \u4E0D\u652F\u6301 conversation\uFF08capabilities.conversation = 'unsupported'\uFF0Cmanifest \u65E0 conversation gate \u4F4D\u2014\u2014\u65E0\u540C\u8FDB\u7A0B idle \u590D\u7528\uFF0Cmessage/close \u4EA4\u4E92\u63A7\u5236\u9762\u4E0D\u53EF\u7528\uFF09`,
204
+ `engine '${engineId}' \u4E0D\u652F\u6301 resume \u7EED\u804A\uFF08capabilities.conversation = 'unsupported'\uFF0Cmanifest \u65E0 conversation gate \u4F4D\uFF09`,
219
205
  `\u53BB\u6389 conversation \u53C2\u6570\uFF08\u4E00\u6B21\u6027\u4EFB\u52A1\u9ED8\u8BA4\u5F62\u6001\uFF09\uFF0C\u6216\u4FEE manifest capabilities / \u5347\u7EA7\u5F15\u64CE\u5305\uFF08\u82E5\u5F15\u64CE\u5B9E\u9645\u652F\u6301\u8BE5\u80FD\u529B\uFF09`,
220
206
  { engineId, capability: "conversation", declared: "unsupported" }
221
207
  );
@@ -316,6 +302,7 @@ var notificationFrameSchema = {
316
302
  "turn_end",
317
303
  "message_end",
318
304
  "compaction",
305
+ "activity",
319
306
  "error"
320
307
  ]
321
308
  }
@@ -354,6 +341,27 @@ var FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS = [
354
341
  "secret"
355
342
  ];
356
343
  var REVERSE_CHANNEL_NAMES = REVERSE_CHANNELS;
344
+ var runSessionParamsSchema = {
345
+ $schema: "http://json-schema.org/draft-07/schema#",
346
+ title: "EngineRunSessionParams",
347
+ type: "object",
348
+ additionalProperties: false,
349
+ required: ["recordId"],
350
+ properties: {
351
+ recordId: { type: "string" },
352
+ resume: {
353
+ type: "object",
354
+ additionalProperties: false,
355
+ required: ["sessionRef", "poolKey"],
356
+ properties: {
357
+ // ResumeAnchor.sessionRef = Record<string, string>(引擎定位键值对)
358
+ sessionRef: { type: "object", additionalProperties: { type: "string" } },
359
+ poolKey: { type: "string" },
360
+ journalPath: { type: "string" }
361
+ }
362
+ }
363
+ }
364
+ };
357
365
  // Annotate the CommonJS export names for ESM import in node:
358
366
  0 && (module.exports = {
359
367
  CANCEL_SETTLE_GRACE_MS,
@@ -384,7 +392,6 @@ var REVERSE_CHANNEL_NAMES = REVERSE_CHANNELS;
384
392
  errorResponseFrameSchema,
385
393
  isEngineErrorPassthroughCode,
386
394
  isEngineProtocolErrorCode,
387
- isHostRoundLifecycleParams,
388
395
  isHostStreamDeltaParams,
389
396
  isNotificationFrame,
390
397
  isProtocolVersionCompatible,
@@ -395,6 +402,7 @@ var REVERSE_CHANNEL_NAMES = REVERSE_CHANNELS;
395
402
  protocolErrorSchema,
396
403
  requestFrameSchema,
397
404
  reverseRequestFrameSchema,
405
+ runSessionParamsSchema,
398
406
  schemaEmulationFailedDetail,
399
407
  successResponseFrameSchema
400
408
  });
@@ -1,7 +1,6 @@
1
- import { P as ProtocolError } from '../error-codes-DHco5-i_.cjs';
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-DHco5-i_.cjs';
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.cjs';
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.cjs';
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-DCiilt_8.cjs';
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.cjs';
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.cjs';
5
4
  import { UiRequest, UiResponse } from '../ui-types.cjs';
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 };