@zhushanwen/subagent-engine-sdk 0.7.1 → 0.9.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 (53) hide show
  1. package/dist/best-effort.cjs +9 -1
  2. package/dist/best-effort.js +2 -2
  3. package/dist/{chunk-X24IVQKJ.js → chunk-3FVBDH3X.js} +3 -2
  4. package/dist/{chunk-HERD6RIR.js → chunk-6QE3OODO.js} +2 -2
  5. package/dist/{chunk-YL5W5EMV.js → chunk-AF2ETADP.js} +1 -1
  6. package/dist/chunk-D36ZIQQK.js +28 -0
  7. package/dist/{chunk-W23PAAGX.js → chunk-DIIYVO4O.js} +1 -27
  8. package/dist/{chunk-RCT7L777.js → chunk-EF2F5YOM.js} +2 -2
  9. package/dist/{chunk-3WC36CHI.js → chunk-KADRNFG2.js} +1 -1
  10. package/dist/{chunk-75QEMUGV.js → chunk-NXNNXGTY.js} +10 -1
  11. package/dist/{chunk-EJMF63R5.js → chunk-QMEHSKNR.js} +1 -1
  12. package/dist/{chunk-SFNTX7Q3.js → chunk-VDKR7MLG.js} +0 -11
  13. package/dist/{chunk-J4G2MXDS.js → chunk-VE3NVT7K.js} +1 -1
  14. package/dist/cli-entry.cjs +9 -1
  15. package/dist/cli-entry.js +2 -2
  16. package/dist/{contract-types-DiWyGRXr.d.cts → contract-types-DqOD58r-.d.cts} +7 -12
  17. package/dist/{contract-types-DiWyGRXr.d.ts → contract-types-DqOD58r-.d.ts} +7 -12
  18. package/dist/data-dir.cjs +10 -2
  19. package/dist/data-dir.js +2 -2
  20. package/dist/env.cjs +9 -1
  21. package/dist/env.d.cts +6 -6
  22. package/dist/env.d.ts +6 -6
  23. package/dist/env.js +2 -2
  24. package/dist/error-codes-C3oVToMr.d.cts +311 -0
  25. package/dist/error-codes-CiDwaODz.d.ts +311 -0
  26. package/dist/index.cjs +41 -16
  27. package/dist/index.d.cts +31 -3
  28. package/dist/index.d.ts +31 -3
  29. package/dist/index.js +64 -37
  30. package/dist/journal-io.d.cts +1 -1
  31. package/dist/journal-io.d.ts +1 -1
  32. package/dist/journal-replay.d.cts +1 -1
  33. package/dist/journal-replay.d.ts +1 -1
  34. package/dist/kill-chain.cjs +9 -1
  35. package/dist/kill-chain.d.cts +1 -1
  36. package/dist/kill-chain.d.ts +1 -1
  37. package/dist/kill-chain.js +3 -3
  38. package/dist/logger.cjs +11 -1
  39. package/dist/logger.js +1 -1
  40. package/dist/node-executor.js +2 -2
  41. package/dist/port-contract.d.cts +12 -6
  42. package/dist/port-contract.d.ts +12 -6
  43. package/dist/protocol/index.cjs +1 -14
  44. package/dist/protocol/index.d.cts +4 -299
  45. package/dist/protocol/index.d.ts +4 -299
  46. package/dist/protocol/index.js +8 -10
  47. package/dist/server/index.cjs +217 -0
  48. package/dist/server/index.d.cts +146 -0
  49. package/dist/server/index.d.ts +146 -0
  50. package/dist/server/index.js +143 -0
  51. package/dist/spawn.cjs +9 -1
  52. package/dist/spawn.js +4 -4
  53. package/package.json +12 -1
package/dist/index.cjs CHANGED
@@ -6574,8 +6574,6 @@ var src_exports = {};
6574
6574
  __export(src_exports, {
6575
6575
  AGENT_EVENT_TYPE_NAMES: () => AGENT_EVENT_TYPE_NAMES,
6576
6576
  CANCEL_SETTLE_GRACE_MS: () => CANCEL_SETTLE_GRACE_MS,
6577
- CRASH_REBUILD_BACKOFF_MS: () => CRASH_REBUILD_BACKOFF_MS,
6578
- CRASH_REBUILD_MAX_ATTEMPTS: () => CRASH_REBUILD_MAX_ATTEMPTS,
6579
6577
  DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS: () => DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
6580
6578
  DEFAULT_KILL_GRACE_MS: () => DEFAULT_KILL_GRACE_MS,
6581
6579
  DEFAULT_NATIVE_INTERRUPT_GRACE_MS: () => DEFAULT_NATIVE_INTERRUPT_GRACE_MS,
@@ -6617,6 +6615,7 @@ __export(src_exports, {
6617
6615
  SHARED_POOL_KEY: () => SHARED_POOL_KEY,
6618
6616
  STDERR_TAIL_CHARS: () => STDERR_TAIL_CHARS,
6619
6617
  STDOUT_TAIL_ECHO_CHARS: () => STDOUT_TAIL_ECHO_CHARS,
6618
+ SUBAGENT_IDENTITY_ENV: () => SUBAGENT_IDENTITY_ENV,
6620
6619
  SUPPORTED_PROTOCOL_RANGE: () => SUPPORTED_PROTOCOL_RANGE,
6621
6620
  TAIJI_DATA_DIR_ENV: () => TAIJI_DATA_DIR_ENV,
6622
6621
  ZCODE_HOST_DB_SUFFIX: () => ZCODE_HOST_DB_SUFFIX,
@@ -6704,15 +6703,6 @@ function isProtocolVersionCompatible(version) {
6704
6703
  var REVERSE_REQUEST_TIMEOUT_MS = 1e4;
6705
6704
  var HANDSHAKE_TIMEOUT_MS = 1e4;
6706
6705
  var CANCEL_SETTLE_GRACE_MS = 3e3;
6707
- var CRASH_REBUILD_MAX_ATTEMPTS = 3;
6708
- var CRASH_REBUILD_BACKOFF_STEP_1_MS = 1e3;
6709
- var CRASH_REBUILD_BACKOFF_STEP_2_MS = 2e3;
6710
- var CRASH_REBUILD_BACKOFF_STEP_3_MS = 4e3;
6711
- var CRASH_REBUILD_BACKOFF_MS = [
6712
- CRASH_REBUILD_BACKOFF_STEP_1_MS,
6713
- CRASH_REBUILD_BACKOFF_STEP_2_MS,
6714
- CRASH_REBUILD_BACKOFF_STEP_3_MS
6715
- ];
6716
6706
  var STDERR_TAIL_CHARS = 400;
6717
6707
 
6718
6708
  // src/protocol/frames.ts
@@ -6988,7 +6978,7 @@ var runSessionParamsSchema = {
6988
6978
  properties: {
6989
6979
  // ResumeAnchor.sessionRef = Record<string, string>(引擎定位键值对)
6990
6980
  sessionRef: { type: "object", additionalProperties: { type: "string" } },
6991
- journalPath: { type: "string" }
6981
+ eventsPath: { type: "string" }
6992
6982
  }
6993
6983
  }
6994
6984
  }
@@ -7151,8 +7141,16 @@ var ExecutionNestingContext = class {
7151
7141
  }
7152
7142
  };
7153
7143
 
7144
+ // src/global-slots.ts
7145
+ var ENGINE_SDK_SLOT_KEYS = {
7146
+ /** dataDir 缺省告警一次性标记(data-dir.ts)。 */
7147
+ dataDirWarned: "@zhushanwen/subagent-engine-sdk.data-dir-warned",
7148
+ /** logger sink 进程级单例(logger.ts)。 */
7149
+ loggerSink: "@zhushanwen/subagent-engine-sdk.logger-sink"
7150
+ };
7151
+
7154
7152
  // src/logger.ts
7155
- var SINK_SLOT_KEY = /* @__PURE__ */ Symbol.for("@zhushanwen/subagent-engine-sdk.logger-sink");
7153
+ var SINK_SLOT_KEY = Symbol.for(ENGINE_SDK_SLOT_KEYS.loggerSink);
7156
7154
  function getSinkSlot() {
7157
7155
  let slot = Reflect.get(globalThis, SINK_SLOT_KEY);
7158
7156
  if (!slot) {
@@ -7589,7 +7587,7 @@ function sessionIdFromHandle(handle) {
7589
7587
  // src/data-dir.ts
7590
7588
  var logger2 = getLogger("subagents");
7591
7589
  var TAIJI_DATA_DIR_ENV = "TAIJI_AGENT_DATA_DIR";
7592
- var WARNED_SLOT_KEY = /* @__PURE__ */ Symbol.for("@zhushanwen/subagent-engine-sdk.data-dir-warned");
7590
+ var WARNED_SLOT_KEY = Symbol.for(ENGINE_SDK_SLOT_KEYS.dataDirWarned);
7593
7591
  function getWarnedSlot() {
7594
7592
  let slot = Reflect.get(globalThis, WARNED_SLOT_KEY);
7595
7593
  if (!slot) {
@@ -7863,6 +7861,34 @@ function buildOutboundChildEnv(opts) {
7863
7861
  return out;
7864
7862
  }
7865
7863
 
7864
+ // src/identity-env.ts
7865
+ var SUBAGENT_IDENTITY_ENV = {
7866
+ /** 本次 run 的 record id(子进程自身身份;主/子进程判定的唯一标记)。 */
7867
+ selfRecordId: "PI_SUBAGENT_SELF_RECORD_ID",
7868
+ /** 真 ROOT 的 pi session id。 */
7869
+ rootSessionId: "PI_SUBAGENT_ROOT_SESSION_ID",
7870
+ /** 真 ROOT 的工作目录(worktree 场景下≠子进程 cwd)。 */
7871
+ rootCwd: "PI_SUBAGENT_ROOT_CWD",
7872
+ /** 执行嵌套深度(子进程 = 父进程 + 1)。 */
7873
+ depth: "PI_SUBAGENT_DEPTH",
7874
+ /** fork 链深度。 */
7875
+ forkDepth: "PI_SUBAGENT_FORK_DEPTH",
7876
+ /** 父 record id(嵌套时 = 父进程 selfRecordId)。 */
7877
+ parentRecordId: "PI_SUBAGENT_PARENT_RECORD_ID",
7878
+ /** agent 名。 */
7879
+ agent: "PI_SUBAGENT_AGENT",
7880
+ /** 任务文本。 */
7881
+ task: "PI_SUBAGENT_TASK",
7882
+ /** 执行形态(background / chat;壳读者非法值兜底 background)。 */
7883
+ mode: "PI_SUBAGENT_MODE",
7884
+ /** 短标签(可选)。 */
7885
+ slug: "PI_SUBAGENT_SLUG",
7886
+ /** 起始时刻(epoch ms;缺席回落 Date.now())。 */
7887
+ startedAt: "PI_SUBAGENT_STARTED_AT",
7888
+ /** worktree 隔离标志("true" = 是)。 */
7889
+ worktree: "PI_SUBAGENT_WORKTREE"
7890
+ };
7891
+
7866
7892
  // src/spawn.ts
7867
7893
  var import_node_child_process = require("child_process");
7868
7894
  var logger4 = getLogger("engine-sdk/spawn");
@@ -8367,8 +8393,6 @@ function runEngineCliEntry(opts) {
8367
8393
  0 && (module.exports = {
8368
8394
  AGENT_EVENT_TYPE_NAMES,
8369
8395
  CANCEL_SETTLE_GRACE_MS,
8370
- CRASH_REBUILD_BACKOFF_MS,
8371
- CRASH_REBUILD_MAX_ATTEMPTS,
8372
8396
  DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
8373
8397
  DEFAULT_KILL_GRACE_MS,
8374
8398
  DEFAULT_NATIVE_INTERRUPT_GRACE_MS,
@@ -8410,6 +8434,7 @@ function runEngineCliEntry(opts) {
8410
8434
  SHARED_POOL_KEY,
8411
8435
  STDERR_TAIL_CHARS,
8412
8436
  STDOUT_TAIL_ECHO_CHARS,
8437
+ SUBAGENT_IDENTITY_ENV,
8413
8438
  SUPPORTED_PROTOCOL_RANGE,
8414
8439
  TAIJI_DATA_DIR_ENV,
8415
8440
  ZCODE_HOST_DB_SUFFIX,
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- export { CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, CancelParams, CancelResult, DisposeParams, DisposeResult, ENGINE_ERROR_CODE_PREFIX, ENGINE_PROTOCOL_ERROR_CODES, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, ENGINE_TIMEOUT_RECOVERY, EngineProtocolErrorCode, EngineSdkError, ErrorResponseFrame, EventNotificationParams, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, HostAskUserParams, HostAskUserResult, HostChildSpawnedParams, HostChildStateChangedParams, HostHandleReadyParams, HostLogParams, HostStreamDeltaParams, InitializeParams, InitializeResult, ListModelsParams, ListModelsResult, NotificationFrame, PROTOCOL_METHODS, PingParams, PingResult, ProbeParams, ProtocolError, ProtocolMethod, ProtocolParamsMap, ProtocolResultMap, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, ReadParams, RequestFrame, ResponseFrame, ReverseChannel, ReverseRequestFrame, ReverseRequestTimeoutClass, ReverseResponseResult, RunContextParams, RunParams, RunResult, RunResumeParams, STDERR_TAIL_CHARS, STDOUT_TAIL_ECHO_CHARS, SUPPORTED_PROTOCOL_RANGE, SuccessResponseFrame, ValidateModelParams, ValidateModelResult, assertChatConversationSupported, engineConversationUnsupportedError, engineProtocolMismatchError, engineTimeoutDetail, errorResponseFrameSchema, isEngineErrorPassthroughCode, isEngineProtocolErrorCode, isNotificationFrame, isProtocolVersionCompatible, isRequestFrame, isResponseFrame, isReverseRequestFrame, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, schemaEmulationFailedDetail, successResponseFrameSchema } from './protocol/index.cjs';
2
- export { A as AGENT_EVENT_TYPE_NAMES, a as AgentCallOpts, b as AgentEvent, c as AgentEventTypeName, d as AgentFailureKind, e as AgentOutcome, f as AgentOutcomeUsage, g as AgentUsage, h as AgentUsageTotal, i as AssertMutuallyAssignable, E as EngineCapabilities, j as EngineHandleData, k as EngineProcessModel, I as InternalToolCall, M as ModelCatalogEntry, P as ProbeReport, R as ReplayedTurn, l as ResumeAnchor, S as SessionView, T as ToolCall, m as ToolCallEntry, n as ToolCallResult, o as Turn, W as WorktreeHandle } from './contract-types-DiWyGRXr.cjs';
1
+ export { CANCEL_SETTLE_GRACE_MS, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, HostAskUserParams, HostAskUserResult, HostChildSpawnedParams, HostChildStateChangedParams, HostHandleReadyParams, HostLogParams, HostStreamDeltaParams, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, ReverseChannel, ReverseRequestTimeoutClass, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema } from './protocol/index.cjs';
2
+ export { C as CancelParams, b as CancelResult, D as DisposeParams, c as DisposeResult, d as ENGINE_ERROR_CODE_PREFIX, e as ENGINE_PROTOCOL_ERROR_CODES, f as ENGINE_TIMEOUT_RECOVERY, g as EngineProtocolErrorCode, E as EngineSdkError, h as ErrorResponseFrame, i as EventNotificationParams, a as InitializeParams, I as InitializeResult, L as ListModelsParams, j as ListModelsResult, N as NotificationFrame, P as PROTOCOL_METHODS, k as PingParams, l as PingResult, m as ProbeParams, n as ProtocolError, o as ProtocolMethod, p as ProtocolParamsMap, q as ProtocolResultMap, r as ReadParams, s as RequestFrame, t as ResponseFrame, u as ReverseRequestFrame, v as ReverseResponseResult, R as RunContextParams, w as RunParams, x as RunResult, y as RunResumeParams, S as STDOUT_TAIL_ECHO_CHARS, z as SuccessResponseFrame, V as ValidateModelParams, A as ValidateModelResult, B as assertChatConversationSupported, F as engineConversationUnsupportedError, G as engineProtocolMismatchError, H as engineTimeoutDetail, J as isEngineErrorPassthroughCode, K as isEngineProtocolErrorCode, M as isNotificationFrame, O as isRequestFrame, Q as isResponseFrame, T as isReverseRequestFrame, U as schemaEmulationFailedDetail } from './error-codes-C3oVToMr.cjs';
3
+ export { f as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, g as AgentEventTypeName, h as AgentFailureKind, c as AgentOutcome, i as AgentOutcomeUsage, j as AgentUsage, a as AgentUsageTotal, k as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, l as EngineProcessModel, I as InternalToolCall, M as ModelCatalogEntry, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, m as ToolCall, n as ToolCallEntry, o as ToolCallResult, T as Turn, W as WorktreeHandle } from './contract-types-DqOD58r-.cjs';
3
4
  export { SCHEMA_EMULATION_TAIL_CHARS, StructuredOutputResult, buildSchemaEmulationSegment, extractAndValidateStructuredOutput } from './schema-emulation.cjs';
4
5
  export { ExecutionNestingContext, ExecutionNestingState, NESTED_SPAWN_ENV, NestedSpawnRejectedError, SpawnEnv, assertNotNestedSpawn, buildNestedSpawnEnv } from './nesting-guard.cjs';
5
6
  export { CoreLogger, LogLevel, LoggerSink, configureLoggerSink, getLogger, resetLoggerSinkForTests } from './logger.cjs';
@@ -22,6 +23,33 @@ export { EngineAgentCallOpts, EngineCtxModel, EngineHandle, EnginePort, EngineRu
22
23
  export { CliProtocolServerSink, RunEngineCliEntryOptions, runEngineCliEntry } from './cli-entry.cjs';
23
24
  import 'node:child_process';
24
25
 
26
+ declare const SUBAGENT_IDENTITY_ENV: {
27
+ /** 本次 run 的 record id(子进程自身身份;主/子进程判定的唯一标记)。 */
28
+ readonly selfRecordId: "PI_SUBAGENT_SELF_RECORD_ID";
29
+ /** 真 ROOT 的 pi session id。 */
30
+ readonly rootSessionId: "PI_SUBAGENT_ROOT_SESSION_ID";
31
+ /** 真 ROOT 的工作目录(worktree 场景下≠子进程 cwd)。 */
32
+ readonly rootCwd: "PI_SUBAGENT_ROOT_CWD";
33
+ /** 执行嵌套深度(子进程 = 父进程 + 1)。 */
34
+ readonly depth: "PI_SUBAGENT_DEPTH";
35
+ /** fork 链深度。 */
36
+ readonly forkDepth: "PI_SUBAGENT_FORK_DEPTH";
37
+ /** 父 record id(嵌套时 = 父进程 selfRecordId)。 */
38
+ readonly parentRecordId: "PI_SUBAGENT_PARENT_RECORD_ID";
39
+ /** agent 名。 */
40
+ readonly agent: "PI_SUBAGENT_AGENT";
41
+ /** 任务文本。 */
42
+ readonly task: "PI_SUBAGENT_TASK";
43
+ /** 执行形态(background / chat;壳读者非法值兜底 background)。 */
44
+ readonly mode: "PI_SUBAGENT_MODE";
45
+ /** 短标签(可选)。 */
46
+ readonly slug: "PI_SUBAGENT_SLUG";
47
+ /** 起始时刻(epoch ms;缺席回落 Date.now())。 */
48
+ readonly startedAt: "PI_SUBAGENT_STARTED_AT";
49
+ /** worktree 隔离标志("true" = 是)。 */
50
+ readonly worktree: "PI_SUBAGENT_WORKTREE";
51
+ };
52
+
25
53
  /** 帧类型判别值(kind 字段词表)。as const 值即字面量类型——类型位置同样可用。 */
26
54
  declare const RELAY_FRAME_KINDS: {
27
55
  readonly handshake: "handshake";
@@ -55,4 +83,4 @@ type RelayFrameKind = (typeof RELAY_FRAME_KINDS)[keyof typeof RELAY_FRAME_KINDS]
55
83
  type RelayFrameDir = (typeof RELAY_FRAME_DIRS)[keyof typeof RELAY_FRAME_DIRS];
56
84
  type RelayRejectReason = (typeof RELAY_REJECT_REASONS)[keyof typeof RELAY_REJECT_REASONS];
57
85
 
58
- export { RELAY_FRAME_DIRS, RELAY_FRAME_KINDS, RELAY_REJECT_REASONS, type RelayFrameDir, type RelayFrameKind, type RelayRejectReason };
86
+ export { RELAY_FRAME_DIRS, RELAY_FRAME_KINDS, RELAY_REJECT_REASONS, type RelayFrameDir, type RelayFrameKind, type RelayRejectReason, SUBAGENT_IDENTITY_ENV };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export { CANCEL_SETTLE_GRACE_MS, CRASH_REBUILD_BACKOFF_MS, CRASH_REBUILD_MAX_ATTEMPTS, CancelParams, CancelResult, DisposeParams, DisposeResult, ENGINE_ERROR_CODE_PREFIX, ENGINE_PROTOCOL_ERROR_CODES, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, ENGINE_TIMEOUT_RECOVERY, EngineProtocolErrorCode, EngineSdkError, ErrorResponseFrame, EventNotificationParams, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, HostAskUserParams, HostAskUserResult, HostChildSpawnedParams, HostChildStateChangedParams, HostHandleReadyParams, HostLogParams, HostStreamDeltaParams, InitializeParams, InitializeResult, ListModelsParams, ListModelsResult, NotificationFrame, PROTOCOL_METHODS, PingParams, PingResult, ProbeParams, ProtocolError, ProtocolMethod, ProtocolParamsMap, ProtocolResultMap, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, ReadParams, RequestFrame, ResponseFrame, ReverseChannel, ReverseRequestFrame, ReverseRequestTimeoutClass, ReverseResponseResult, RunContextParams, RunParams, RunResult, RunResumeParams, STDERR_TAIL_CHARS, STDOUT_TAIL_ECHO_CHARS, SUPPORTED_PROTOCOL_RANGE, SuccessResponseFrame, ValidateModelParams, ValidateModelResult, assertChatConversationSupported, engineConversationUnsupportedError, engineProtocolMismatchError, engineTimeoutDetail, errorResponseFrameSchema, isEngineErrorPassthroughCode, isEngineProtocolErrorCode, isNotificationFrame, isProtocolVersionCompatible, isRequestFrame, isResponseFrame, isReverseRequestFrame, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, schemaEmulationFailedDetail, successResponseFrameSchema } from './protocol/index.js';
2
- export { A as AGENT_EVENT_TYPE_NAMES, a as AgentCallOpts, b as AgentEvent, c as AgentEventTypeName, d as AgentFailureKind, e as AgentOutcome, f as AgentOutcomeUsage, g as AgentUsage, h as AgentUsageTotal, i as AssertMutuallyAssignable, E as EngineCapabilities, j as EngineHandleData, k as EngineProcessModel, I as InternalToolCall, M as ModelCatalogEntry, P as ProbeReport, R as ReplayedTurn, l as ResumeAnchor, S as SessionView, T as ToolCall, m as ToolCallEntry, n as ToolCallResult, o as Turn, W as WorktreeHandle } from './contract-types-DiWyGRXr.js';
1
+ export { CANCEL_SETTLE_GRACE_MS, ENGINE_PROTOCOL_SCHEMAS, ENGINE_PROTOCOL_VERSION, FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS, HANDSHAKE_TIMEOUT_MS, HostAskUserParams, HostAskUserResult, HostChildSpawnedParams, HostChildStateChangedParams, HostHandleReadyParams, HostLogParams, HostStreamDeltaParams, REVERSE_CHANNELS, REVERSE_CHANNEL_TIMEOUT_CLASS, REVERSE_REQUEST_TIMEOUT_MS, ReverseChannel, ReverseRequestTimeoutClass, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema } from './protocol/index.js';
2
+ export { C as CancelParams, b as CancelResult, D as DisposeParams, c as DisposeResult, d as ENGINE_ERROR_CODE_PREFIX, e as ENGINE_PROTOCOL_ERROR_CODES, f as ENGINE_TIMEOUT_RECOVERY, g as EngineProtocolErrorCode, E as EngineSdkError, h as ErrorResponseFrame, i as EventNotificationParams, a as InitializeParams, I as InitializeResult, L as ListModelsParams, j as ListModelsResult, N as NotificationFrame, P as PROTOCOL_METHODS, k as PingParams, l as PingResult, m as ProbeParams, n as ProtocolError, o as ProtocolMethod, p as ProtocolParamsMap, q as ProtocolResultMap, r as ReadParams, s as RequestFrame, t as ResponseFrame, u as ReverseRequestFrame, v as ReverseResponseResult, R as RunContextParams, w as RunParams, x as RunResult, y as RunResumeParams, S as STDOUT_TAIL_ECHO_CHARS, z as SuccessResponseFrame, V as ValidateModelParams, A as ValidateModelResult, B as assertChatConversationSupported, F as engineConversationUnsupportedError, G as engineProtocolMismatchError, H as engineTimeoutDetail, J as isEngineErrorPassthroughCode, K as isEngineProtocolErrorCode, M as isNotificationFrame, O as isRequestFrame, Q as isResponseFrame, T as isReverseRequestFrame, U as schemaEmulationFailedDetail } from './error-codes-CiDwaODz.js';
3
+ export { f as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, g as AgentEventTypeName, h as AgentFailureKind, c as AgentOutcome, i as AgentOutcomeUsage, j as AgentUsage, a as AgentUsageTotal, k as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, l as EngineProcessModel, I as InternalToolCall, M as ModelCatalogEntry, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, m as ToolCall, n as ToolCallEntry, o as ToolCallResult, T as Turn, W as WorktreeHandle } from './contract-types-DqOD58r-.js';
3
4
  export { SCHEMA_EMULATION_TAIL_CHARS, StructuredOutputResult, buildSchemaEmulationSegment, extractAndValidateStructuredOutput } from './schema-emulation.js';
4
5
  export { ExecutionNestingContext, ExecutionNestingState, NESTED_SPAWN_ENV, NestedSpawnRejectedError, SpawnEnv, assertNotNestedSpawn, buildNestedSpawnEnv } from './nesting-guard.js';
5
6
  export { CoreLogger, LogLevel, LoggerSink, configureLoggerSink, getLogger, resetLoggerSinkForTests } from './logger.js';
@@ -22,6 +23,33 @@ export { EngineAgentCallOpts, EngineCtxModel, EngineHandle, EnginePort, EngineRu
22
23
  export { CliProtocolServerSink, RunEngineCliEntryOptions, runEngineCliEntry } from './cli-entry.js';
23
24
  import 'node:child_process';
24
25
 
26
+ declare const SUBAGENT_IDENTITY_ENV: {
27
+ /** 本次 run 的 record id(子进程自身身份;主/子进程判定的唯一标记)。 */
28
+ readonly selfRecordId: "PI_SUBAGENT_SELF_RECORD_ID";
29
+ /** 真 ROOT 的 pi session id。 */
30
+ readonly rootSessionId: "PI_SUBAGENT_ROOT_SESSION_ID";
31
+ /** 真 ROOT 的工作目录(worktree 场景下≠子进程 cwd)。 */
32
+ readonly rootCwd: "PI_SUBAGENT_ROOT_CWD";
33
+ /** 执行嵌套深度(子进程 = 父进程 + 1)。 */
34
+ readonly depth: "PI_SUBAGENT_DEPTH";
35
+ /** fork 链深度。 */
36
+ readonly forkDepth: "PI_SUBAGENT_FORK_DEPTH";
37
+ /** 父 record id(嵌套时 = 父进程 selfRecordId)。 */
38
+ readonly parentRecordId: "PI_SUBAGENT_PARENT_RECORD_ID";
39
+ /** agent 名。 */
40
+ readonly agent: "PI_SUBAGENT_AGENT";
41
+ /** 任务文本。 */
42
+ readonly task: "PI_SUBAGENT_TASK";
43
+ /** 执行形态(background / chat;壳读者非法值兜底 background)。 */
44
+ readonly mode: "PI_SUBAGENT_MODE";
45
+ /** 短标签(可选)。 */
46
+ readonly slug: "PI_SUBAGENT_SLUG";
47
+ /** 起始时刻(epoch ms;缺席回落 Date.now())。 */
48
+ readonly startedAt: "PI_SUBAGENT_STARTED_AT";
49
+ /** worktree 隔离标志("true" = 是)。 */
50
+ readonly worktree: "PI_SUBAGENT_WORKTREE";
51
+ };
52
+
25
53
  /** 帧类型判别值(kind 字段词表)。as const 值即字面量类型——类型位置同样可用。 */
26
54
  declare const RELAY_FRAME_KINDS: {
27
55
  readonly handshake: "handshake";
@@ -55,4 +83,4 @@ type RelayFrameKind = (typeof RELAY_FRAME_KINDS)[keyof typeof RELAY_FRAME_KINDS]
55
83
  type RelayFrameDir = (typeof RELAY_FRAME_DIRS)[keyof typeof RELAY_FRAME_DIRS];
56
84
  type RelayRejectReason = (typeof RELAY_REJECT_REASONS)[keyof typeof RELAY_REJECT_REASONS];
57
85
 
58
- export { RELAY_FRAME_DIRS, RELAY_FRAME_KINDS, RELAY_REJECT_REASONS, type RelayFrameDir, type RelayFrameKind, type RelayRejectReason };
86
+ export { RELAY_FRAME_DIRS, RELAY_FRAME_KINDS, RELAY_REJECT_REASONS, type RelayFrameDir, type RelayFrameKind, type RelayRejectReason, SUBAGENT_IDENTITY_ENV };
package/dist/index.js CHANGED
@@ -1,6 +1,17 @@
1
+ import {
2
+ RELAY_ENV_NODE,
3
+ RELAY_ENV_RECORD_ID,
4
+ RELAY_ENV_SCRIPT,
5
+ RELAY_ENV_SESSION_ID,
6
+ RELAY_ENV_SOCKET,
7
+ RELAY_EXIT_CODES,
8
+ RELAY_PROTOCOL_VERSION,
9
+ isRelayActive,
10
+ readRelayForwardEnv
11
+ } from "./chunk-GSW3DMN6.js";
1
12
  import {
2
13
  bestEffort
3
- } from "./chunk-EJMF63R5.js";
14
+ } from "./chunk-QMEHSKNR.js";
4
15
  import {
5
16
  replayJournal
6
17
  } from "./chunk-RDH3ZOV6.js";
@@ -10,11 +21,16 @@ import {
10
21
  } from "./chunk-LQR73V67.js";
11
22
  import {
12
23
  runEngineCliEntry
13
- } from "./chunk-J4G2MXDS.js";
24
+ } from "./chunk-VE3NVT7K.js";
14
25
  import {
15
26
  ZCODE_HOST_DB_SUFFIX,
16
27
  ZCODE_ISOLATED_DB_SEGMENTS
17
28
  } from "./chunk-CT3FEBDO.js";
29
+ import {
30
+ TAIJI_DATA_DIR_ENV,
31
+ resetDataDirWarnForTests,
32
+ resolveEngineDataDir
33
+ } from "./chunk-3FVBDH3X.js";
18
34
  import {
19
35
  resolveEngineDir,
20
36
  resolveEnginesRoot,
@@ -35,7 +51,7 @@ import {
35
51
  ENGINE_ENV_PREFIXES,
36
52
  buildEngineChildEnv,
37
53
  buildOutboundChildEnv
38
- } from "./chunk-YL5W5EMV.js";
54
+ } from "./chunk-AF2ETADP.js";
39
55
  import {
40
56
  DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
41
57
  ENGINE_ABORT_KILL_GRACE_MS,
@@ -43,14 +59,14 @@ import {
43
59
  armEngineSelfDestruct,
44
60
  pumpNdjsonLines,
45
61
  spawnEngineChild
46
- } from "./chunk-HERD6RIR.js";
62
+ } from "./chunk-6QE3OODO.js";
47
63
  import {
48
64
  ENGINE_NODE_ENV,
49
65
  hostKindOf,
50
66
  probeNodeExecutor,
51
67
  resetEngineNodeProbeCache,
52
68
  resolveEngineNodeLaunch
53
- } from "./chunk-3WC36CHI.js";
69
+ } from "./chunk-KADRNFG2.js";
54
70
  import {
55
71
  DEFAULT_STDERR_KEEP_DAYS,
56
72
  DEFAULT_STDERR_MAX_BYTES,
@@ -62,17 +78,6 @@ import {
62
78
  stderrLogPidOf,
63
79
  stderrRotationParams
64
80
  } from "./chunk-MSAJXIP4.js";
65
- import {
66
- RELAY_ENV_NODE,
67
- RELAY_ENV_RECORD_ID,
68
- RELAY_ENV_SCRIPT,
69
- RELAY_ENV_SESSION_ID,
70
- RELAY_ENV_SOCKET,
71
- RELAY_EXIT_CODES,
72
- RELAY_PROTOCOL_VERSION,
73
- isRelayActive,
74
- readRelayForwardEnv
75
- } from "./chunk-GSW3DMN6.js";
76
81
  import {
77
82
  AGENT_EVENT_TYPE_NAMES,
78
83
  ENGINE_PROTOCOL_SCHEMAS,
@@ -81,17 +86,19 @@ import {
81
86
  REVERSE_CHANNELS,
82
87
  REVERSE_CHANNEL_TIMEOUT_CLASS,
83
88
  errorResponseFrameSchema,
84
- isNotificationFrame,
85
- isRequestFrame,
86
- isResponseFrame,
87
- isReverseRequestFrame,
88
89
  notificationFrameSchema,
89
90
  protocolErrorSchema,
90
91
  requestFrameSchema,
91
92
  reverseRequestFrameSchema,
92
93
  runSessionParamsSchema,
93
94
  successResponseFrameSchema
94
- } from "./chunk-W23PAAGX.js";
95
+ } from "./chunk-DIIYVO4O.js";
96
+ import {
97
+ isNotificationFrame,
98
+ isRequestFrame,
99
+ isResponseFrame,
100
+ isReverseRequestFrame
101
+ } from "./chunk-D36ZIQQK.js";
95
102
  import {
96
103
  SCHEMA_EMULATION_TAIL_CHARS,
97
104
  buildSchemaEmulationSegment,
@@ -114,14 +121,12 @@ import {
114
121
  probePidAlive,
115
122
  safeKill,
116
123
  synthesizeTimeoutOutcome
117
- } from "./chunk-RCT7L777.js";
124
+ } from "./chunk-EF2F5YOM.js";
118
125
  import {
119
126
  toErrorMessage
120
127
  } from "./chunk-PYO3YR7W.js";
121
128
  import {
122
129
  CANCEL_SETTLE_GRACE_MS,
123
- CRASH_REBUILD_BACKOFF_MS,
124
- CRASH_REBUILD_MAX_ATTEMPTS,
125
130
  ENGINE_ERROR_CODE_PREFIX,
126
131
  ENGINE_PROTOCOL_ERROR_CODES,
127
132
  ENGINE_PROTOCOL_VERSION,
@@ -140,7 +145,12 @@ import {
140
145
  isEngineProtocolErrorCode,
141
146
  isProtocolVersionCompatible,
142
147
  schemaEmulationFailedDetail
143
- } from "./chunk-SFNTX7Q3.js";
148
+ } from "./chunk-VDKR7MLG.js";
149
+ import {
150
+ configureLoggerSink,
151
+ getLogger,
152
+ resetLoggerSinkForTests
153
+ } from "./chunk-NXNNXGTY.js";
144
154
  import {
145
155
  aggregateUsage,
146
156
  createReplayRecord,
@@ -149,18 +159,36 @@ import {
149
159
  toReplayedTurn,
150
160
  updateFromEvent
151
161
  } from "./chunk-SGAIDL63.js";
152
- import {
153
- TAIJI_DATA_DIR_ENV,
154
- resetDataDirWarnForTests,
155
- resolveEngineDataDir
156
- } from "./chunk-X24IVQKJ.js";
157
- import {
158
- configureLoggerSink,
159
- getLogger,
160
- resetLoggerSinkForTests
161
- } from "./chunk-75QEMUGV.js";
162
162
  import "./chunk-JSBRDJBE.js";
163
163
 
164
+ // src/identity-env.ts
165
+ var SUBAGENT_IDENTITY_ENV = {
166
+ /** 本次 run 的 record id(子进程自身身份;主/子进程判定的唯一标记)。 */
167
+ selfRecordId: "PI_SUBAGENT_SELF_RECORD_ID",
168
+ /** 真 ROOT 的 pi session id。 */
169
+ rootSessionId: "PI_SUBAGENT_ROOT_SESSION_ID",
170
+ /** 真 ROOT 的工作目录(worktree 场景下≠子进程 cwd)。 */
171
+ rootCwd: "PI_SUBAGENT_ROOT_CWD",
172
+ /** 执行嵌套深度(子进程 = 父进程 + 1)。 */
173
+ depth: "PI_SUBAGENT_DEPTH",
174
+ /** fork 链深度。 */
175
+ forkDepth: "PI_SUBAGENT_FORK_DEPTH",
176
+ /** 父 record id(嵌套时 = 父进程 selfRecordId)。 */
177
+ parentRecordId: "PI_SUBAGENT_PARENT_RECORD_ID",
178
+ /** agent 名。 */
179
+ agent: "PI_SUBAGENT_AGENT",
180
+ /** 任务文本。 */
181
+ task: "PI_SUBAGENT_TASK",
182
+ /** 执行形态(background / chat;壳读者非法值兜底 background)。 */
183
+ mode: "PI_SUBAGENT_MODE",
184
+ /** 短标签(可选)。 */
185
+ slug: "PI_SUBAGENT_SLUG",
186
+ /** 起始时刻(epoch ms;缺席回落 Date.now())。 */
187
+ startedAt: "PI_SUBAGENT_STARTED_AT",
188
+ /** worktree 隔离标志("true" = 是)。 */
189
+ worktree: "PI_SUBAGENT_WORKTREE"
190
+ };
191
+
164
192
  // src/relay-frames.ts
165
193
  var RELAY_FRAME_KINDS = {
166
194
  handshake: "handshake",
@@ -191,8 +219,6 @@ var RELAY_REJECT_REASONS = {
191
219
  export {
192
220
  AGENT_EVENT_TYPE_NAMES,
193
221
  CANCEL_SETTLE_GRACE_MS,
194
- CRASH_REBUILD_BACKOFF_MS,
195
- CRASH_REBUILD_MAX_ATTEMPTS,
196
222
  DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
197
223
  DEFAULT_KILL_GRACE_MS,
198
224
  DEFAULT_NATIVE_INTERRUPT_GRACE_MS,
@@ -234,6 +260,7 @@ export {
234
260
  SHARED_POOL_KEY,
235
261
  STDERR_TAIL_CHARS,
236
262
  STDOUT_TAIL_ECHO_CHARS,
263
+ SUBAGENT_IDENTITY_ENV,
237
264
  SUPPORTED_PROTOCOL_RANGE,
238
265
  TAIJI_DATA_DIR_ENV,
239
266
  ZCODE_HOST_DB_SUFFIX,
@@ -1,4 +1,4 @@
1
- import { b as AgentEvent } from './contract-types-DiWyGRXr.cjs';
1
+ import { A as AgentEvent } from './contract-types-DqOD58r-.cjs';
2
2
 
3
3
  /**
4
4
  * 重放 journal:读取路径下全部事件,重放即得 AgentEvent 流(read 第②级)。
@@ -1,4 +1,4 @@
1
- import { b as AgentEvent } from './contract-types-DiWyGRXr.js';
1
+ import { A as AgentEvent } from './contract-types-DqOD58r-.js';
2
2
 
3
3
  /**
4
4
  * 重放 journal:读取路径下全部事件,重放即得 AgentEvent 流(read 第②级)。
@@ -1,4 +1,4 @@
1
- import { o as Turn, h as AgentUsageTotal, b as AgentEvent, S as SessionView, j as EngineHandleData, R as ReplayedTurn } from './contract-types-DiWyGRXr.cjs';
1
+ import { T as Turn, a as AgentUsageTotal, A as AgentEvent, S as SessionView, E as EngineHandleData, R as ReplayedTurn } from './contract-types-DqOD58r-.cjs';
2
2
 
3
3
  /**
4
4
  * reducer 的 record 视图(core ExecutionRecord 的结构子集:reducer 只触碰这四个字段)。
@@ -1,4 +1,4 @@
1
- import { o as Turn, h as AgentUsageTotal, b as AgentEvent, S as SessionView, j as EngineHandleData, R as ReplayedTurn } from './contract-types-DiWyGRXr.js';
1
+ import { T as Turn, a as AgentUsageTotal, A as AgentEvent, S as SessionView, E as EngineHandleData, R as ReplayedTurn } from './contract-types-DqOD58r-.js';
2
2
 
3
3
  /**
4
4
  * reducer 的 record 视图(core ExecutionRecord 的结构子集:reducer 只触碰这四个字段)。
@@ -32,8 +32,16 @@ __export(kill_chain_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(kill_chain_exports);
34
34
 
35
+ // src/global-slots.ts
36
+ var ENGINE_SDK_SLOT_KEYS = {
37
+ /** dataDir 缺省告警一次性标记(data-dir.ts)。 */
38
+ dataDirWarned: "@zhushanwen/subagent-engine-sdk.data-dir-warned",
39
+ /** logger sink 进程级单例(logger.ts)。 */
40
+ loggerSink: "@zhushanwen/subagent-engine-sdk.logger-sink"
41
+ };
42
+
35
43
  // src/logger.ts
36
- var SINK_SLOT_KEY = /* @__PURE__ */ Symbol.for("@zhushanwen/subagent-engine-sdk.logger-sink");
44
+ var SINK_SLOT_KEY = Symbol.for(ENGINE_SDK_SLOT_KEYS.loggerSink);
37
45
  function getSinkSlot() {
38
46
  let slot = Reflect.get(globalThis, SINK_SLOT_KEY);
39
47
  if (!slot) {
@@ -1,4 +1,4 @@
1
- import { a as AgentCallOpts, e as AgentOutcome } from './contract-types-DiWyGRXr.cjs';
1
+ import { b as AgentCallOpts, c as AgentOutcome } from './contract-types-DqOD58r-.cjs';
2
2
 
3
3
  /**
4
4
  * 可杀子进程的结构形状(Node ChildProcess 的结构子集)。
@@ -1,4 +1,4 @@
1
- import { a as AgentCallOpts, e as AgentOutcome } from './contract-types-DiWyGRXr.js';
1
+ import { b as AgentCallOpts, c as AgentOutcome } from './contract-types-DqOD58r-.js';
2
2
 
3
3
  /**
4
4
  * 可杀子进程的结构形状(Node ChildProcess 的结构子集)。
@@ -8,10 +8,10 @@ import {
8
8
  probePidAlive,
9
9
  safeKill,
10
10
  synthesizeTimeoutOutcome
11
- } from "./chunk-RCT7L777.js";
11
+ } from "./chunk-EF2F5YOM.js";
12
12
  import "./chunk-PYO3YR7W.js";
13
- import "./chunk-SFNTX7Q3.js";
14
- import "./chunk-75QEMUGV.js";
13
+ import "./chunk-VDKR7MLG.js";
14
+ import "./chunk-NXNNXGTY.js";
15
15
  import "./chunk-JSBRDJBE.js";
16
16
  export {
17
17
  DEFAULT_KILL_GRACE_MS,
package/dist/logger.cjs CHANGED
@@ -25,7 +25,17 @@ __export(logger_exports, {
25
25
  resetLoggerSinkForTests: () => resetLoggerSinkForTests
26
26
  });
27
27
  module.exports = __toCommonJS(logger_exports);
28
- var SINK_SLOT_KEY = /* @__PURE__ */ Symbol.for("@zhushanwen/subagent-engine-sdk.logger-sink");
28
+
29
+ // src/global-slots.ts
30
+ var ENGINE_SDK_SLOT_KEYS = {
31
+ /** dataDir 缺省告警一次性标记(data-dir.ts)。 */
32
+ dataDirWarned: "@zhushanwen/subagent-engine-sdk.data-dir-warned",
33
+ /** logger sink 进程级单例(logger.ts)。 */
34
+ loggerSink: "@zhushanwen/subagent-engine-sdk.logger-sink"
35
+ };
36
+
37
+ // src/logger.ts
38
+ var SINK_SLOT_KEY = Symbol.for(ENGINE_SDK_SLOT_KEYS.loggerSink);
29
39
  function getSinkSlot() {
30
40
  let slot = Reflect.get(globalThis, SINK_SLOT_KEY);
31
41
  if (!slot) {
package/dist/logger.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  configureLoggerSink,
3
3
  getLogger,
4
4
  resetLoggerSinkForTests
5
- } from "./chunk-75QEMUGV.js";
5
+ } from "./chunk-NXNNXGTY.js";
6
6
  import "./chunk-JSBRDJBE.js";
7
7
  export {
8
8
  configureLoggerSink,
@@ -4,8 +4,8 @@ import {
4
4
  probeNodeExecutor,
5
5
  resetEngineNodeProbeCache,
6
6
  resolveEngineNodeLaunch
7
- } from "./chunk-3WC36CHI.js";
8
- import "./chunk-SFNTX7Q3.js";
7
+ } from "./chunk-KADRNFG2.js";
8
+ import "./chunk-VDKR7MLG.js";
9
9
  import "./chunk-JSBRDJBE.js";
10
10
  export {
11
11
  ENGINE_NODE_ENV,
@@ -1,4 +1,4 @@
1
- import { a as AgentCallOpts, j as EngineHandleData, E as EngineCapabilities, P as ProbeReport, b as AgentEvent, l as ResumeAnchor, e as AgentOutcome, S as SessionView } from './contract-types-DiWyGRXr.cjs';
1
+ import { b as AgentCallOpts, E as EngineHandleData, d as EngineCapabilities, P as ProbeReport, A as AgentEvent, e as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-DqOD58r-.cjs';
2
2
 
3
3
  /**
4
4
  * 引擎进程内全量任务声明 = SDK AgentCallOpts 引擎面子集 + 协议 ctx 还原字段(model/
@@ -31,7 +31,7 @@ interface EngineStream {
31
31
  * 本值(pi / zcode 均无池化实现——pi = PI_CODING_AGENT_DIR 全局一份,zcode = 共享
32
32
  * 宿主 HOME)。[池抽象降级 2026-09-13] poolKey 协议面(RunContext/run.params.ctx/
33
33
  * host/poolResolved 通道/EngineHandleData)已整体退役,本常量不再跨进程透传,仅
34
- * 三类消费:① journal 落盘路径构造(core journal-wiring);② 存量 record 兼容
34
+ * 三类消费:① journal 落盘路径构造(core event-journal-wiring);② 存量 record 兼容
35
35
  * (zcode read 旧相对 dbPath 的锚定分支 + 持久化 engineHandle.poolKey 字段——
36
36
  * record-store 读侧守卫要求非空,值恒本常量);③ 引擎数据目录布局 SSOT paths.ts
37
37
  * 的签名参数。**值逐字不变**(存量 journal 落盘路径与记录含该值分段,改名不改值)。
@@ -44,10 +44,6 @@ interface RunContext {
44
44
  onEvent?: (event: AgentEvent) => void;
45
45
  ctxModel?: EngineCtxModel;
46
46
  stream?: EngineStream;
47
- engineFallback?: {
48
- from: string;
49
- reason: string;
50
- };
51
47
  /**
52
48
  * [F6] 根 session id(协议 run.params.ctx.sessionRootId 的进程内还原)——pi 引擎
53
49
  * relay 归属键 SESSION_ID 的权威来源。additive 可选:宿主缺省不传。
@@ -67,6 +63,16 @@ interface RunContext {
67
63
  * 恒无扩展 flag)。additive 可选:宿主缺省不传。
68
64
  */
69
65
  extensionPaths?: string[];
66
+ /**
67
+ * [D4 record 身份信封] 协议 `run.params.ctx.identity` 的进程内还原——引擎把它整封
68
+ * 写进任务子进程的身份 env(`SUBAGENT_IDENTITY_ENV` 的 slug / startedAt / mode)。
69
+ * additive 可选:宿主缺省不传时引擎不写这三个键,读者按回落语义工作。
70
+ */
71
+ identity?: {
72
+ slug?: string;
73
+ startedAt?: number;
74
+ mode?: string;
75
+ };
70
76
  onHandleReady?: (partial: Pick<EngineHandleData, "sessionRef">) => void;
71
77
  /** 一次性子进程 pid 上报(host/childSpawned 载荷形态;ChildProcess 句柄不跨协议面)。 */
72
78
  onChildSpawned?: (child: {
@@ -1,4 +1,4 @@
1
- import { a as AgentCallOpts, j as EngineHandleData, E as EngineCapabilities, P as ProbeReport, b as AgentEvent, l as ResumeAnchor, e as AgentOutcome, S as SessionView } from './contract-types-DiWyGRXr.js';
1
+ import { b as AgentCallOpts, E as EngineHandleData, d as EngineCapabilities, P as ProbeReport, A as AgentEvent, e as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-DqOD58r-.js';
2
2
 
3
3
  /**
4
4
  * 引擎进程内全量任务声明 = SDK AgentCallOpts 引擎面子集 + 协议 ctx 还原字段(model/
@@ -31,7 +31,7 @@ interface EngineStream {
31
31
  * 本值(pi / zcode 均无池化实现——pi = PI_CODING_AGENT_DIR 全局一份,zcode = 共享
32
32
  * 宿主 HOME)。[池抽象降级 2026-09-13] poolKey 协议面(RunContext/run.params.ctx/
33
33
  * host/poolResolved 通道/EngineHandleData)已整体退役,本常量不再跨进程透传,仅
34
- * 三类消费:① journal 落盘路径构造(core journal-wiring);② 存量 record 兼容
34
+ * 三类消费:① journal 落盘路径构造(core event-journal-wiring);② 存量 record 兼容
35
35
  * (zcode read 旧相对 dbPath 的锚定分支 + 持久化 engineHandle.poolKey 字段——
36
36
  * record-store 读侧守卫要求非空,值恒本常量);③ 引擎数据目录布局 SSOT paths.ts
37
37
  * 的签名参数。**值逐字不变**(存量 journal 落盘路径与记录含该值分段,改名不改值)。
@@ -44,10 +44,6 @@ interface RunContext {
44
44
  onEvent?: (event: AgentEvent) => void;
45
45
  ctxModel?: EngineCtxModel;
46
46
  stream?: EngineStream;
47
- engineFallback?: {
48
- from: string;
49
- reason: string;
50
- };
51
47
  /**
52
48
  * [F6] 根 session id(协议 run.params.ctx.sessionRootId 的进程内还原)——pi 引擎
53
49
  * relay 归属键 SESSION_ID 的权威来源。additive 可选:宿主缺省不传。
@@ -67,6 +63,16 @@ interface RunContext {
67
63
  * 恒无扩展 flag)。additive 可选:宿主缺省不传。
68
64
  */
69
65
  extensionPaths?: string[];
66
+ /**
67
+ * [D4 record 身份信封] 协议 `run.params.ctx.identity` 的进程内还原——引擎把它整封
68
+ * 写进任务子进程的身份 env(`SUBAGENT_IDENTITY_ENV` 的 slug / startedAt / mode)。
69
+ * additive 可选:宿主缺省不传时引擎不写这三个键,读者按回落语义工作。
70
+ */
71
+ identity?: {
72
+ slug?: string;
73
+ startedAt?: number;
74
+ mode?: string;
75
+ };
70
76
  onHandleReady?: (partial: Pick<EngineHandleData, "sessionRef">) => void;
71
77
  /** 一次性子进程 pid 上报(host/childSpawned 载荷形态;ChildProcess 句柄不跨协议面)。 */
72
78
  onChildSpawned?: (child: {