@zhushanwen/subagent-engine-sdk 0.10.0 → 0.11.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 (67) hide show
  1. package/dist/{chunk-AF2ETADP.js → chunk-2L3I2TWJ.js} +5 -10
  2. package/dist/{chunk-HSNDUHFH.js → chunk-3MCOZY3Z.js} +32 -4
  3. package/dist/{chunk-JZN76I3S.js → chunk-NVF3PADP.js} +29 -1
  4. package/dist/{chunk-LM7P7OTA.js → chunk-QBXDEF4N.js} +35 -3
  5. package/dist/{chunk-NTOLHLCL.js → chunk-QGXILDWB.js} +1 -1
  6. package/dist/{chunk-CT3FEBDO.js → chunk-QOFFM5YW.js} +7 -1
  7. package/dist/{chunk-CNCFMPEH.js → chunk-TJMS3YOR.js} +1 -1
  8. package/dist/{chunk-SGAIDL63.js → chunk-YFSNX3N3.js} +2 -2
  9. package/dist/cli-entry.d.cts +1 -1
  10. package/dist/cli-entry.d.ts +1 -1
  11. package/dist/{contract-types-jSa1g28F.d.cts → contract-types-BUHUMF9R.d.cts} +17 -17
  12. package/dist/{contract-types-jSa1g28F.d.ts → contract-types-BUHUMF9R.d.ts} +17 -17
  13. package/dist/env.cjs +5 -10
  14. package/dist/env.d.cts +6 -17
  15. package/dist/env.d.ts +6 -17
  16. package/dist/env.js +1 -1
  17. package/dist/{error-codes-f-UO4a8D.d.cts → error-codes-D_aPibUt.d.cts} +42 -6
  18. package/dist/{error-codes-DnFru4L4.d.ts → error-codes-DrNf0gwT.d.ts} +42 -6
  19. package/dist/index.cjs +133 -97
  20. package/dist/index.d.cts +29 -41
  21. package/dist/index.d.ts +29 -41
  22. package/dist/index.js +42 -59
  23. package/dist/journal-io.d.cts +1 -1
  24. package/dist/journal-io.d.ts +1 -1
  25. package/dist/journal-replay.cjs +2 -2
  26. package/dist/journal-replay.d.cts +4 -4
  27. package/dist/journal-replay.d.ts +4 -4
  28. package/dist/journal-replay.js +1 -1
  29. package/dist/kill-chain.d.cts +5 -5
  30. package/dist/kill-chain.d.ts +5 -5
  31. package/dist/kill-chain.js +2 -2
  32. package/dist/logger.d.cts +1 -1
  33. package/dist/logger.d.ts +1 -1
  34. package/dist/logs/stderr-rotation.d.cts +4 -4
  35. package/dist/logs/stderr-rotation.d.ts +4 -4
  36. package/dist/{methods-C2zvZqhP.d.ts → methods-BdIH3FwS.d.ts} +5 -5
  37. package/dist/{methods-BLxg4ZFr.d.cts → methods-CHiDwvRK.d.cts} +5 -5
  38. package/dist/node-executor.cjs +1 -1
  39. package/dist/node-executor.d.cts +4 -4
  40. package/dist/node-executor.d.ts +4 -4
  41. package/dist/node-executor.js +2 -2
  42. package/dist/port-contract.d.cts +9 -9
  43. package/dist/port-contract.d.ts +9 -9
  44. package/dist/protocol/index.cjs +73 -4
  45. package/dist/protocol/index.d.cts +57 -14
  46. package/dist/protocol/index.d.ts +57 -14
  47. package/dist/protocol/index.js +20 -2
  48. package/dist/server/index.cjs +1 -1
  49. package/dist/server/index.d.cts +10 -10
  50. package/dist/server/index.d.ts +10 -10
  51. package/dist/server/index.js +1 -1
  52. package/dist/spawn.cjs +32 -3
  53. package/dist/spawn.d.cts +34 -8
  54. package/dist/spawn.d.ts +34 -8
  55. package/dist/spawn.js +5 -3
  56. package/dist/ui-types.d.cts +2 -2
  57. package/dist/ui-types.d.ts +2 -2
  58. package/dist/zcode-db-paths.cjs +9 -2
  59. package/dist/zcode-db-paths.d.cts +11 -1
  60. package/dist/zcode-db-paths.d.ts +11 -1
  61. package/dist/zcode-db-paths.js +5 -3
  62. package/package.json +2 -2
  63. package/dist/chunk-GSW3DMN6.js +0 -39
  64. package/dist/relay-env.cjs +0 -71
  65. package/dist/relay-env.d.cts +0 -37
  66. package/dist/relay-env.d.ts +0 -37
  67. package/dist/relay-env.js +0 -23
package/dist/index.cjs CHANGED
@@ -6574,6 +6574,8 @@ 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
+ CONTROL_ENV_ROOT_SESSION_ID: () => CONTROL_ENV_ROOT_SESSION_ID,
6578
+ CONTROL_ENV_SOCKET: () => CONTROL_ENV_SOCKET,
6577
6579
  DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS: () => DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
6578
6580
  DEFAULT_KILL_GRACE_MS: () => DEFAULT_KILL_GRACE_MS,
6579
6581
  DEFAULT_NATIVE_INTERRUPT_GRACE_MS: () => DEFAULT_NATIVE_INTERRUPT_GRACE_MS,
@@ -6589,7 +6591,11 @@ __export(src_exports, {
6589
6591
  ENGINE_PROTOCOL_ERROR_CODES: () => ENGINE_PROTOCOL_ERROR_CODES,
6590
6592
  ENGINE_PROTOCOL_SCHEMAS: () => ENGINE_PROTOCOL_SCHEMAS,
6591
6593
  ENGINE_PROTOCOL_VERSION: () => ENGINE_PROTOCOL_VERSION,
6594
+ ENGINE_SPAWN_DELIVERY_ERROR_CODES: () => ENGINE_SPAWN_DELIVERY_ERROR_CODES,
6595
+ ENGINE_SPAWN_DELIVERY_ERROR_RECOVERY: () => ENGINE_SPAWN_DELIVERY_ERROR_RECOVERY,
6592
6596
  ENGINE_TIMEOUT_RECOVERY: () => ENGINE_TIMEOUT_RECOVERY,
6597
+ ENGINE_TRANSPORT_ERROR_CODES: () => ENGINE_TRANSPORT_ERROR_CODES,
6598
+ ENGINE_TRANSPORT_ERROR_RECOVERY: () => ENGINE_TRANSPORT_ERROR_RECOVERY,
6593
6599
  EngineSdkError: () => EngineSdkError,
6594
6600
  ExecutionNestingContext: () => ExecutionNestingContext,
6595
6601
  FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS: () => FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
@@ -6597,17 +6603,8 @@ __export(src_exports, {
6597
6603
  HOST_TIMEOUT_ABORT_REASON: () => HOST_TIMEOUT_ABORT_REASON,
6598
6604
  NESTED_SPAWN_ENV: () => NESTED_SPAWN_ENV,
6599
6605
  NestedSpawnRejectedError: () => NestedSpawnRejectedError,
6606
+ PI_SUBAGENT_TASK_MAX_CHARS: () => PI_SUBAGENT_TASK_MAX_CHARS,
6600
6607
  PROTOCOL_METHODS: () => PROTOCOL_METHODS,
6601
- RELAY_ENV_NODE: () => RELAY_ENV_NODE,
6602
- RELAY_ENV_RECORD_ID: () => RELAY_ENV_RECORD_ID,
6603
- RELAY_ENV_SCRIPT: () => RELAY_ENV_SCRIPT,
6604
- RELAY_ENV_SESSION_ID: () => RELAY_ENV_SESSION_ID,
6605
- RELAY_ENV_SOCKET: () => RELAY_ENV_SOCKET,
6606
- RELAY_EXIT_CODES: () => RELAY_EXIT_CODES,
6607
- RELAY_FRAME_DIRS: () => RELAY_FRAME_DIRS,
6608
- RELAY_FRAME_KINDS: () => RELAY_FRAME_KINDS,
6609
- RELAY_PROTOCOL_VERSION: () => RELAY_PROTOCOL_VERSION,
6610
- RELAY_REJECT_REASONS: () => RELAY_REJECT_REASONS,
6611
6608
  REVERSE_CHANNELS: () => REVERSE_CHANNELS,
6612
6609
  REVERSE_CHANNEL_TIMEOUT_CLASS: () => REVERSE_CHANNEL_TIMEOUT_CLASS,
6613
6610
  REVERSE_REQUEST_TIMEOUT_MS: () => REVERSE_REQUEST_TIMEOUT_MS,
@@ -6619,11 +6616,15 @@ __export(src_exports, {
6619
6616
  SHARED_POOL_KEY: () => SHARED_POOL_KEY,
6620
6617
  STDERR_TAIL_CHARS: () => STDERR_TAIL_CHARS,
6621
6618
  STDOUT_TAIL_ECHO_CHARS: () => STDOUT_TAIL_ECHO_CHARS,
6619
+ SUBAGENT_CONTROL_CLOSED_REASONS: () => SUBAGENT_CONTROL_CLOSED_REASONS,
6620
+ SUBAGENT_CONTROL_FRAME_KINDS: () => SUBAGENT_CONTROL_FRAME_KINDS,
6621
+ SUBAGENT_CONTROL_PROTOCOL_VERSION: () => SUBAGENT_CONTROL_PROTOCOL_VERSION,
6622
6622
  SUBAGENT_IDENTITY_ENV: () => SUBAGENT_IDENTITY_ENV,
6623
6623
  SUPPORTED_PROTOCOL_RANGE: () => SUPPORTED_PROTOCOL_RANGE,
6624
6624
  TAIJI_DATA_DIR_ENV: () => TAIJI_DATA_DIR_ENV,
6625
6625
  ZCODE_HOST_DB_SUFFIX: () => ZCODE_HOST_DB_SUFFIX,
6626
6626
  ZCODE_ISOLATED_DB_SEGMENTS: () => ZCODE_ISOLATED_DB_SEGMENTS,
6627
+ ZCODE_PI_SYNCED_PROVIDER_CONFIG_SEGMENTS: () => ZCODE_PI_SYNCED_PROVIDER_CONFIG_SEGMENTS,
6627
6628
  abortWithFallback: () => abortWithFallback,
6628
6629
  aggregateUsage: () => aggregateUsage,
6629
6630
  armEngineSelfDestruct: () => armEngineSelfDestruct,
@@ -6648,17 +6649,20 @@ __export(src_exports, {
6648
6649
  extractAndValidateStructuredOutput: () => extractAndValidateStructuredOutput,
6649
6650
  getLogger: () => getLogger,
6650
6651
  hostKindOf: () => hostKindOf,
6652
+ isControlEnvActive: () => isControlEnvActive,
6651
6653
  isEngineErrorPassthroughCode: () => isEngineErrorPassthroughCode,
6652
6654
  isEngineProtocolErrorCode: () => isEngineProtocolErrorCode,
6653
6655
  isNotificationFrame: () => isNotificationFrame,
6654
6656
  isPidAlive: () => isPidAlive,
6655
6657
  isProtocolVersionCompatible: () => isProtocolVersionCompatible,
6656
- isRelayActive: () => isRelayActive,
6657
6658
  isRequestFrame: () => isRequestFrame,
6658
6659
  isResponseFrame: () => isResponseFrame,
6659
6660
  isReverseRequestFrame: () => isReverseRequestFrame,
6661
+ isSubagentControlClosedReason: () => isSubagentControlClosedReason,
6662
+ isSubagentControlFrameKind: () => isSubagentControlFrameKind,
6660
6663
  isUiResponse: () => isUiResponse,
6661
6664
  killChain: () => killChain,
6665
+ killOwnProcessGroup: () => killOwnProcessGroup,
6662
6666
  killPidChain: () => killPidChain,
6663
6667
  notificationFrameSchema: () => notificationFrameSchema,
6664
6668
  parseChannel: () => parseChannel,
@@ -6667,7 +6671,6 @@ __export(src_exports, {
6667
6671
  probePidAlive: () => probePidAlive,
6668
6672
  protocolErrorSchema: () => protocolErrorSchema,
6669
6673
  pumpNdjsonLines: () => pumpNdjsonLines,
6670
- readRelayForwardEnv: () => readRelayForwardEnv,
6671
6674
  replayJournal: () => replayJournal,
6672
6675
  requestFrameSchema: () => requestFrameSchema,
6673
6676
  resetDataDirWarnForTests: () => resetDataDirWarnForTests,
@@ -6767,6 +6770,30 @@ var REVERSE_CHANNEL_TIMEOUT_CLASS = {
6767
6770
  };
6768
6771
 
6769
6772
  // src/protocol/error-codes.ts
6773
+ var ENGINE_SPAWN_DELIVERY_ERROR_CODES = [
6774
+ "engine_prompt_not_delivered",
6775
+ "engine_prompt_rejected",
6776
+ "engine_spawn_handshake_timeout"
6777
+ ];
6778
+ var ENGINE_TRANSPORT_ERROR_CODES = [
6779
+ "engine_transport_unavailable",
6780
+ "engine_transport_lost",
6781
+ "engine_open_timeout",
6782
+ "engine_frame_too_large",
6783
+ "engine_backpressure_overflow"
6784
+ ];
6785
+ var ENGINE_SPAWN_DELIVERY_ERROR_RECOVERY = {
6786
+ engine_prompt_not_delivered: "The task never reached the child pi (zero stdout after the prompt write, or the engine stdin was unavailable). Re-run the task; if it recurs, inspect the engine/pi logs (the failure carries the delivery diagnostics) and the runtime log.",
6787
+ engine_prompt_rejected: "The child pi explicitly rejected the prompt command (success:false). Check the pi-side reason carried in the error detail (busy/queue/extension takeover states are reported by pi itself), then re-run.",
6788
+ engine_spawn_handshake_timeout: "The engine spawn handshake did not complete in time. Check the runtime log for a spawn/handshake stall, then restart taiji and re-run the task."
6789
+ };
6790
+ var ENGINE_TRANSPORT_ERROR_RECOVERY = {
6791
+ engine_transport_unavailable: "The runtime control socket is unreachable (connect or hello failed). The runtime side is failing explicitly instead of silently falling back to local spawn \u2014 restart taiji and re-run the task.",
6792
+ engine_transport_lost: "The control connection to the runtime was lost mid-flight (runtime restart or crash). In-flight requests were rejected; restart taiji (or wait for the runtime to come back) and re-run the task \u2014 the connection is not retried in place.",
6793
+ engine_open_timeout: "The runtime did not finish opening the engine channel in time (spawn/attribution stalled). Check the runtime log (engine opened / kill decision lines), then re-run the task.",
6794
+ engine_frame_too_large: "A single frame exceeded the control-plane size limit and the channel was closed without truncation. Shrink the task/result payload (e.g. point the agent at files instead of inlining them) and re-run.",
6795
+ engine_backpressure_overflow: "The control-plane write queue overflowed (engine consumed frames too slowly) and the overflowed scope was torn down without dropping frames silently. Re-run the task; if it recurs, reduce concurrent subagent fan-out."
6796
+ };
6770
6797
  var SET_MODEL_ERROR_CODES = [
6771
6798
  /** 目标模型不在当前进程快照(子进程模型快照冻结于 spawn 时刻——模型本身有效,
6772
6799
  * 下一轮 spawn 现取目录即可用;宿主按「写覆盖意图」处置,设计 §7.2 快照型失败行)。 */
@@ -6811,7 +6838,7 @@ var EngineSdkError = class extends Error {
6811
6838
  this.recovery = recovery;
6812
6839
  this.data = data;
6813
6840
  }
6814
- /** 协议 error 帧载荷投影。 */
6841
+ /** 协议 error 帧载荷派生视图。 */
6815
6842
  toStructured() {
6816
6843
  return { code: this.code, message: this.message, recovery: this.recovery, data: this.data };
6817
6844
  }
@@ -6862,12 +6889,39 @@ function schemaEmulationFailedDetail(error, tail) {
6862
6889
  return `structured output emulation failed after tolerant extraction and one host-side retry: ${error}. Raw output tail: ${truncate(tail, DETAIL_ECHO_MAX_CHARS)}. Recovery: retry with a strengthened prompt or relax the schema; if it still fails switch to a schema-native engine (engine: pi).`;
6863
6890
  }
6864
6891
 
6892
+ // src/protocol/control-protocol.ts
6893
+ var SUBAGENT_CONTROL_PROTOCOL_VERSION = 1;
6894
+ var SUBAGENT_CONTROL_FRAME_KINDS = {
6895
+ hello: "hello",
6896
+ helloOk: "hello_ok",
6897
+ helloReject: "hello_reject",
6898
+ engineOpen: "engine_open",
6899
+ engineOpened: "engine_opened",
6900
+ engineOpenFailed: "engine_open_failed",
6901
+ engineFrame: "engine_frame",
6902
+ engineClose: "engine_close",
6903
+ engineClosed: "engine_closed",
6904
+ error: "error"
6905
+ };
6906
+ function isSubagentControlFrameKind(value) {
6907
+ return typeof value === "string" && Object.values(SUBAGENT_CONTROL_FRAME_KINDS).includes(value);
6908
+ }
6909
+ var SUBAGENT_CONTROL_CLOSED_REASONS = {
6910
+ engineExit: "engine_exit",
6911
+ engineSignal: "engine_signal",
6912
+ killedByControl: "killed_by_control",
6913
+ openTimeout: "open_timeout"
6914
+ };
6915
+ function isSubagentControlClosedReason(value) {
6916
+ return typeof value === "string" && Object.values(SUBAGENT_CONTROL_CLOSED_REASONS).includes(value);
6917
+ }
6918
+
6865
6919
  // src/protocol/contract-types.ts
6866
6920
  var AGENT_EVENT_TYPE_NAMES = [
6867
6921
  "tool_start",
6868
6922
  // noop-safe: 旧宿主 default 分支零写入——丢弃仅缺 tool 起始占位(显示降级),turn 结构不受损
6869
6923
  "tool_end",
6870
- // noop-safe: 旧宿主 default 分支零写入——丢弃仅缺 result,turn 收口由 turn_end/message_end 承担
6924
+ // noop-safe: 旧宿主 default 分支零写入——丢弃仅缺 result,turn 收尾由 turn_end/message_end 承担
6871
6925
  "text_delta",
6872
6926
  // noop-safe: 旧宿主 default 分支零写入——丢弃仅缺正文增量,不产生半解析状态
6873
6927
  "thinking_delta",
@@ -6875,7 +6929,7 @@ var AGENT_EVENT_TYPE_NAMES = [
6875
6929
  "turn_end",
6876
6930
  // noop-safe: 旧宿主 default 分支零写入——丢弃则该 turn 滞留进行态,journal 重放仍按序重建
6877
6931
  "message_end",
6878
- // noop-safe: 旧宿主 default 分支零写入——丢弃仅缺 usage 聚合与闭合计量,已累积内容不回滚
6932
+ // noop-safe: 旧宿主 default 分支零写入——丢弃仅缺 usage 聚合与结束计量,已累积内容不回滚
6879
6933
  "compaction",
6880
6934
  // noop-safe: 事件无载荷且现行 reducer 即直接 return——丢弃与处理零差异
6881
6935
  "activity",
@@ -6957,7 +7011,7 @@ var notificationFrameSchema = {
6957
7011
  type: {
6958
7012
  type: "string",
6959
7013
  // 事件 enum 从词表 SSOT 派生(U2 词表锁:union⟷词表互证后,此处不再
6960
- // 手写字面量集合——手写即漂移面,病灶 1 的第三处同步点)
7014
+ // 手写字面量集合——手写即漂移点,问题点 1 的第三处同步点)
6961
7015
  enum: [...AGENT_EVENT_TYPE_NAMES]
6962
7016
  }
6963
7017
  }
@@ -7542,7 +7596,7 @@ function updateFromEvent(record, event) {
7542
7596
  return applyToolStart(record, event);
7543
7597
  case "tool_end":
7544
7598
  return applyToolEnd(record, event);
7545
- // ── turn_end:闭合当前 turn ──
7599
+ // ── turn_end:结束当前 turn ──
7546
7600
  case "turn_end":
7547
7601
  return applyTurnEnd(record);
7548
7602
  // ── message_end:usage 增量累加 + totalTokens 累加 ──
@@ -7558,7 +7612,7 @@ function updateFromEvent(record, event) {
7558
7612
  case "activity":
7559
7613
  return;
7560
7614
  // ── armed:武装确认回执([D3 协议版 P6],协议语义见 contract-types)——监控
7561
- // 信号不进 record 投影,消费方 = 宿主等待门 + run 事件 journal(C3 第④步
7615
+ // 信号不进 record 派生视图,消费方 = 宿主等待门 + run 事件 journal(C3 第④步
7562
7616
  // 双侧 reducer no-op 义务的 SDK 侧)
7563
7617
  case "armed":
7564
7618
  return;
@@ -7781,8 +7835,6 @@ var ENGINE_ENV_DENY_LIST = [
7781
7835
  "TAIJI_AGENT_PACKAGED",
7782
7836
  "TAIJI_RUNTIME_TOKEN",
7783
7837
  "TAIJI_AGENT_API_KEY",
7784
- "TAIJI_SUBAGENT_RELAY_SESSION_ID",
7785
- "TAIJI_SUBAGENT_RELAY_RECORD_ID",
7786
7838
  // 预设回落事实(env 名 SSOT = shared PRESET_FALLBACK_ENV_KEYS):「本进程本次运行」
7787
7839
  // 事实只对 runtime 直接 spawn 的 pi 成立,引擎一跳继承会造成子 agent pi 假披露
7788
7840
  "TAIJI_PRESET_FALLBACK_FROM",
@@ -7793,9 +7845,11 @@ var ENGINE_ENV_L0_INFRA_KEYS = [
7793
7845
  "TAIJI_AGENT_ENGINE_NODE",
7794
7846
  "ELECTRON_RUN_AS_NODE",
7795
7847
  "TAIJI_AGENT_SUBAGENT",
7796
- "TAIJI_SUBAGENT_RELAY_SOCKET",
7797
- "TAIJI_SUBAGENT_RELAY_NODE",
7798
- "TAIJI_SUBAGENT_RELAY_SCRIPT"
7848
+ // [M3] control 两键(键名 SSOT = src/control-env.ts):runtime 注入主 pi 与引擎的
7849
+ // L0 基础设施键,嵌套 task pi 经引擎出站 env 继承同值。刻意不进 ENGINE_ENV_DENY_LIST:
7850
+ // 引擎/嵌套 extension 是合法读者(transport 选择谓词 + engine_open 归属键)。
7851
+ "TAIJI_SUBAGENT_CONTROL_SOCKET",
7852
+ "TAIJI_SUBAGENT_CONTROL_ROOT_SESSION_ID"
7799
7853
  ];
7800
7854
  var ENV_PREFIX_SHAPE_RE = /^[A-Za-z0-9_]+$/;
7801
7855
  function deleteEnvKeysCaseInsensitive(env, names) {
@@ -7849,11 +7903,6 @@ function injectL0InfraKeys(env, opts) {
7849
7903
  if (opts.engineNode !== void 0) env.TAIJI_AGENT_ENGINE_NODE = opts.engineNode;
7850
7904
  if (opts.electronRunAsNode === true) env.ELECTRON_RUN_AS_NODE = "1";
7851
7905
  env.TAIJI_AGENT_SUBAGENT = "1";
7852
- if (opts.relay !== void 0) {
7853
- env.TAIJI_SUBAGENT_RELAY_SOCKET = opts.relay.socket;
7854
- env.TAIJI_SUBAGENT_RELAY_NODE = opts.relay.node;
7855
- env.TAIJI_SUBAGENT_RELAY_SCRIPT = opts.relay.script;
7856
- }
7857
7906
  if (opts.identityEnv !== void 0) {
7858
7907
  for (const [key, value] of Object.entries(opts.identityEnv)) {
7859
7908
  if (value !== void 0) env[key] = value;
@@ -7919,6 +7968,7 @@ var SUBAGENT_IDENTITY_ENV = {
7919
7968
  /** worktree 隔离标志("true" = 是)。 */
7920
7969
  worktree: "PI_SUBAGENT_WORKTREE"
7921
7970
  };
7971
+ var PI_SUBAGENT_TASK_MAX_CHARS = 2e3;
7922
7972
 
7923
7973
  // src/spawn.ts
7924
7974
  var import_node_child_process = require("child_process");
@@ -7972,13 +8022,40 @@ function resolveHostRequestTimeoutMs(opts) {
7972
8022
  }
7973
8023
  return parsed;
7974
8024
  }
7975
- function killOwnProcessGroup() {
8025
+ function killOwnProcessGroup(deps = {}) {
7976
8026
  const pid = process.pid;
8027
+ const kill = deps.killFn ?? ((targetPid, signal) => process.kill(targetPid, signal));
8028
+ if ((deps.platform ?? process.platform) === "win32") {
8029
+ const fallbackSelfKill = (reason) => {
8030
+ logger4.warn(`taskkill self-tree failed (${reason}); falling back to self SIGKILL`);
8031
+ try {
8032
+ kill(pid, "SIGKILL");
8033
+ } catch (err) {
8034
+ logger4.warn(
8035
+ `self SIGKILL fallback failed (${String(err)}); descendant pi may linger until runtime sweep`
8036
+ );
8037
+ }
8038
+ };
8039
+ const spawnFn = deps.spawnFn ?? ((command, args, options) => (0, import_node_child_process.spawn)(command, [...args], options));
8040
+ try {
8041
+ const child = spawnFn("taskkill", ["/PID", String(pid), "/T", "/F"], {
8042
+ stdio: "ignore",
8043
+ windowsHide: true
8044
+ });
8045
+ child.on("error", (err) => {
8046
+ fallbackSelfKill(String(err));
8047
+ });
8048
+ child.unref?.();
8049
+ } catch (err) {
8050
+ fallbackSelfKill(`spawn threw: ${String(err)}`);
8051
+ }
8052
+ return;
8053
+ }
7977
8054
  try {
7978
- process.kill(-pid, "SIGKILL");
8055
+ kill(-pid, "SIGKILL");
7979
8056
  } catch (err) {
7980
8057
  logger4.warn(`process-group kill failed (${String(err)}), falling back to self kill`);
7981
- process.kill(pid, "SIGKILL");
8058
+ kill(pid, "SIGKILL");
7982
8059
  }
7983
8060
  }
7984
8061
  function armEngineSelfDestruct(opts) {
@@ -8268,63 +8345,19 @@ function cleanupSiblingStderrLogs(logPath, env, prefix, now) {
8268
8345
  // src/zcode-db-paths.ts
8269
8346
  var ZCODE_HOST_DB_SUFFIX = [".zcode", "cli", "db", "db.sqlite"];
8270
8347
  var ZCODE_ISOLATED_DB_SEGMENTS = ["engines", "zcode", "session-db", "db.sqlite"];
8348
+ var ZCODE_PI_SYNCED_PROVIDER_CONFIG_SEGMENTS = [
8349
+ "engines",
8350
+ "zcode",
8351
+ "pi-synced-provider-config.json"
8352
+ ];
8271
8353
 
8272
- // src/relay-env.ts
8273
- var RELAY_ENV_SOCKET = "TAIJI_SUBAGENT_RELAY_SOCKET";
8274
- var RELAY_ENV_NODE = "TAIJI_SUBAGENT_RELAY_NODE";
8275
- var RELAY_ENV_SCRIPT = "TAIJI_SUBAGENT_RELAY_SCRIPT";
8276
- var RELAY_ENV_SESSION_ID = "TAIJI_SUBAGENT_RELAY_SESSION_ID";
8277
- var RELAY_ENV_RECORD_ID = "TAIJI_SUBAGENT_RELAY_RECORD_ID";
8278
- var RELAY_PROTOCOL_VERSION = 1;
8279
- var RELAY_EXIT_CODES = {
8280
- /** 握手被拒:协议版本不匹配(安装损坏,重装应用)。 */
8281
- VERSION_MISMATCH: 10,
8282
- /** relay socket 不可达(runtime 未运行或已重启)。 */
8283
- SOCKET_UNREACHABLE: 11,
8284
- /** socket 中途断开(runtime 崩溃等)——代理生命线断即退。 */
8285
- SOCKET_CLOSED: 12,
8286
- /** 归属 env(SESSION_ID/RECORD_ID)缺失——防无归属帧污染广播。 */
8287
- MISSING_IDENTITY: 13
8288
- };
8289
- function isRelayActive(env) {
8290
- return Boolean(env[RELAY_ENV_SOCKET] && env[RELAY_ENV_NODE] && env[RELAY_ENV_SCRIPT]);
8291
- }
8292
- function readRelayForwardEnv(env) {
8293
- const socket = env[RELAY_ENV_SOCKET];
8294
- const node = env[RELAY_ENV_NODE];
8295
- const script = env[RELAY_ENV_SCRIPT];
8296
- if (!isRelayActive(env)) return void 0;
8297
- return { socket, node, script };
8354
+ // src/control-env.ts
8355
+ var CONTROL_ENV_SOCKET = "TAIJI_SUBAGENT_CONTROL_SOCKET";
8356
+ var CONTROL_ENV_ROOT_SESSION_ID = "TAIJI_SUBAGENT_CONTROL_ROOT_SESSION_ID";
8357
+ function isControlEnvActive(env) {
8358
+ return Boolean(env[CONTROL_ENV_SOCKET]);
8298
8359
  }
8299
8360
 
8300
- // src/relay-frames.ts
8301
- var RELAY_FRAME_KINDS = {
8302
- handshake: "handshake",
8303
- accept: "accept",
8304
- reject: "reject",
8305
- data: "data",
8306
- exit: "exit",
8307
- /**
8308
- * goodbye(代理 → runtime,v1):代理被宿主终止(SIGTERM/SIGINT)前的预告帧——
8309
- * 宿主侧的正常收割(agent_settled 后杀代理)与异常断连(宿主崩溃/主 pi 死)在
8310
- * runtime 侧都表现为 socket close,无法区分;goodbye 让正常收割显式自报,runtime
8311
- * 据此把后续 close 的日志从 warn(kill-on-disconnect)降级为 info(reaped,正常
8312
- * teardown)。kill 行为本身不变(预告后 child 仍由 runtime 收割)。
8313
- */
8314
- goodbye: "goodbye"
8315
- };
8316
- var RELAY_FRAME_DIRS = {
8317
- down: "down",
8318
- up: "up",
8319
- upStderr: "up-stderr"
8320
- };
8321
- var RELAY_REJECT_REASONS = {
8322
- version: "version",
8323
- identity: "identity",
8324
- duplicate: "duplicate",
8325
- malformed: "malformed"
8326
- };
8327
-
8328
8361
  // src/best-effort.ts
8329
8362
  var logger5 = getLogger("subagents");
8330
8363
  function bestEffort(err, context, level = "debug") {
@@ -8424,6 +8457,8 @@ function runEngineCliEntry(opts) {
8424
8457
  0 && (module.exports = {
8425
8458
  AGENT_EVENT_TYPE_NAMES,
8426
8459
  CANCEL_SETTLE_GRACE_MS,
8460
+ CONTROL_ENV_ROOT_SESSION_ID,
8461
+ CONTROL_ENV_SOCKET,
8427
8462
  DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
8428
8463
  DEFAULT_KILL_GRACE_MS,
8429
8464
  DEFAULT_NATIVE_INTERRUPT_GRACE_MS,
@@ -8439,7 +8474,11 @@ function runEngineCliEntry(opts) {
8439
8474
  ENGINE_PROTOCOL_ERROR_CODES,
8440
8475
  ENGINE_PROTOCOL_SCHEMAS,
8441
8476
  ENGINE_PROTOCOL_VERSION,
8477
+ ENGINE_SPAWN_DELIVERY_ERROR_CODES,
8478
+ ENGINE_SPAWN_DELIVERY_ERROR_RECOVERY,
8442
8479
  ENGINE_TIMEOUT_RECOVERY,
8480
+ ENGINE_TRANSPORT_ERROR_CODES,
8481
+ ENGINE_TRANSPORT_ERROR_RECOVERY,
8443
8482
  EngineSdkError,
8444
8483
  ExecutionNestingContext,
8445
8484
  FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
@@ -8447,17 +8486,8 @@ function runEngineCliEntry(opts) {
8447
8486
  HOST_TIMEOUT_ABORT_REASON,
8448
8487
  NESTED_SPAWN_ENV,
8449
8488
  NestedSpawnRejectedError,
8489
+ PI_SUBAGENT_TASK_MAX_CHARS,
8450
8490
  PROTOCOL_METHODS,
8451
- RELAY_ENV_NODE,
8452
- RELAY_ENV_RECORD_ID,
8453
- RELAY_ENV_SCRIPT,
8454
- RELAY_ENV_SESSION_ID,
8455
- RELAY_ENV_SOCKET,
8456
- RELAY_EXIT_CODES,
8457
- RELAY_FRAME_DIRS,
8458
- RELAY_FRAME_KINDS,
8459
- RELAY_PROTOCOL_VERSION,
8460
- RELAY_REJECT_REASONS,
8461
8491
  REVERSE_CHANNELS,
8462
8492
  REVERSE_CHANNEL_TIMEOUT_CLASS,
8463
8493
  REVERSE_REQUEST_TIMEOUT_MS,
@@ -8469,11 +8499,15 @@ function runEngineCliEntry(opts) {
8469
8499
  SHARED_POOL_KEY,
8470
8500
  STDERR_TAIL_CHARS,
8471
8501
  STDOUT_TAIL_ECHO_CHARS,
8502
+ SUBAGENT_CONTROL_CLOSED_REASONS,
8503
+ SUBAGENT_CONTROL_FRAME_KINDS,
8504
+ SUBAGENT_CONTROL_PROTOCOL_VERSION,
8472
8505
  SUBAGENT_IDENTITY_ENV,
8473
8506
  SUPPORTED_PROTOCOL_RANGE,
8474
8507
  TAIJI_DATA_DIR_ENV,
8475
8508
  ZCODE_HOST_DB_SUFFIX,
8476
8509
  ZCODE_ISOLATED_DB_SEGMENTS,
8510
+ ZCODE_PI_SYNCED_PROVIDER_CONFIG_SEGMENTS,
8477
8511
  abortWithFallback,
8478
8512
  aggregateUsage,
8479
8513
  armEngineSelfDestruct,
@@ -8498,17 +8532,20 @@ function runEngineCliEntry(opts) {
8498
8532
  extractAndValidateStructuredOutput,
8499
8533
  getLogger,
8500
8534
  hostKindOf,
8535
+ isControlEnvActive,
8501
8536
  isEngineErrorPassthroughCode,
8502
8537
  isEngineProtocolErrorCode,
8503
8538
  isNotificationFrame,
8504
8539
  isPidAlive,
8505
8540
  isProtocolVersionCompatible,
8506
- isRelayActive,
8507
8541
  isRequestFrame,
8508
8542
  isResponseFrame,
8509
8543
  isReverseRequestFrame,
8544
+ isSubagentControlClosedReason,
8545
+ isSubagentControlFrameKind,
8510
8546
  isUiResponse,
8511
8547
  killChain,
8548
+ killOwnProcessGroup,
8512
8549
  killPidChain,
8513
8550
  notificationFrameSchema,
8514
8551
  parseChannel,
@@ -8517,7 +8554,6 @@ function runEngineCliEntry(opts) {
8517
8554
  probePidAlive,
8518
8555
  protocolErrorSchema,
8519
8556
  pumpNdjsonLines,
8520
- readRelayForwardEnv,
8521
8557
  replayJournal,
8522
8558
  requestFrameSchema,
8523
8559
  resetDataDirWarnForTests,
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
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, SET_MODEL_REQUEST_TIMEOUT_MS, SET_MODEL_STAGE_TIMEOUT_MS, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema } from './protocol/index.cjs';
2
- export { a as ENGINE_ERROR_CODE_PREFIX, b as ENGINE_PROTOCOL_ERROR_CODES, c as ENGINE_TIMEOUT_RECOVERY, d as EngineProtocolErrorCode, E 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 SET_MODEL_ERROR_CODES, j as SET_MODEL_NOT_ACTIVE_CODE, k as STDOUT_TAIL_ECHO_CHARS, l as SetModelErrorCode, m as SuccessResponseFrame, n as assertChatConversationSupported, o as engineConversationUnsupportedError, p as engineProtocolMismatchError, q as engineSetModelUnsupportedError, r as engineTimeoutDetail, s as isEngineErrorPassthroughCode, t as isEngineProtocolErrorCode, u as isNotificationFrame, v as isRequestFrame, w as isResponseFrame, x as isReverseRequestFrame, y as schemaEmulationFailedDetail } from './error-codes-f-UO4a8D.cjs';
3
- export { C as CancelParams, c as CancelResult, D as DisposeParams, d as DisposeResult, b as InitializeParams, I as InitializeResult, L as ListModelsParams, e as ListModelsResult, P as PROTOCOL_METHODS, f as PingParams, g as PingResult, h as ProbeParams, i as ProtocolMethod, j as ProtocolParamsMap, k as ProtocolResultMap, l as ReadParams, R as RunContextParams, m as RunParams, n as RunResult, o as RunResumeParams, S as SetModelParams, a as SetModelResult, V as ValidateModelParams, p as ValidateModelResult } from './methods-BLxg4ZFr.cjs';
4
- export { g as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, h as AgentEventTypeName, i as AgentFailureKind, c as AgentOutcome, j as AgentOutcomeUsage, k as AgentUsage, a as AgentUsageTotal, l as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, m as EngineProcessModel, I as InternalToolCall, f as ModelCatalogEntry, M as ModelRef, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, n as ToolCall, o as ToolCallEntry, p as ToolCallResult, T as Turn, W as WorktreeHandle } from './contract-types-jSa1g28F.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, SET_MODEL_REQUEST_TIMEOUT_MS, SET_MODEL_STAGE_TIMEOUT_MS, STDERR_TAIL_CHARS, SUBAGENT_CONTROL_CLOSED_REASONS, SUBAGENT_CONTROL_FRAME_KINDS, SUBAGENT_CONTROL_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_RANGE, SubagentControlClosedReason, SubagentControlFrameKind, errorResponseFrameSchema, isProtocolVersionCompatible, isSubagentControlClosedReason, isSubagentControlFrameKind, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema } from './protocol/index.cjs';
2
+ export { a as ENGINE_ERROR_CODE_PREFIX, b as ENGINE_PROTOCOL_ERROR_CODES, c as ENGINE_SPAWN_DELIVERY_ERROR_CODES, d as ENGINE_SPAWN_DELIVERY_ERROR_RECOVERY, e as ENGINE_TIMEOUT_RECOVERY, f as ENGINE_TRANSPORT_ERROR_CODES, g as ENGINE_TRANSPORT_ERROR_RECOVERY, h as EngineProtocolErrorCode, E as EngineSdkError, i as EngineSpawnDeliveryErrorCode, j as EngineTransportErrorCode, k as ErrorResponseFrame, l as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, m as ResponseFrame, n as ReverseRequestFrame, o as ReverseResponseResult, S as SET_MODEL_ERROR_CODES, p as SET_MODEL_NOT_ACTIVE_CODE, q as STDOUT_TAIL_ECHO_CHARS, r as SetModelErrorCode, s as SuccessResponseFrame, t as assertChatConversationSupported, u as engineConversationUnsupportedError, v as engineProtocolMismatchError, w as engineSetModelUnsupportedError, x as engineTimeoutDetail, y as isEngineErrorPassthroughCode, z as isEngineProtocolErrorCode, A as isNotificationFrame, B as isRequestFrame, C as isResponseFrame, D as isReverseRequestFrame, F as schemaEmulationFailedDetail } from './error-codes-D_aPibUt.cjs';
3
+ export { C as CancelParams, c as CancelResult, D as DisposeParams, d as DisposeResult, b as InitializeParams, I as InitializeResult, L as ListModelsParams, e as ListModelsResult, P as PROTOCOL_METHODS, f as PingParams, g as PingResult, h as ProbeParams, i as ProtocolMethod, j as ProtocolParamsMap, k as ProtocolResultMap, l as ReadParams, R as RunContextParams, m as RunParams, n as RunResult, o as RunResumeParams, S as SetModelParams, a as SetModelResult, V as ValidateModelParams, p as ValidateModelResult } from './methods-CHiDwvRK.cjs';
4
+ export { g as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, h as AgentEventTypeName, i as AgentFailureKind, c as AgentOutcome, j as AgentOutcomeUsage, k as AgentUsage, a as AgentUsageTotal, l as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, m as EngineProcessModel, I as InternalToolCall, f as ModelCatalogEntry, M as ModelRef, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, n as ToolCall, o as ToolCallEntry, p as ToolCallResult, T as Turn, W as WorktreeHandle } from './contract-types-BUHUMF9R.cjs';
5
5
  export { SCHEMA_EMULATION_TAIL_CHARS, StructuredOutputResult, buildSchemaEmulationSegment, extractAndValidateStructuredOutput } from './schema-emulation.cjs';
6
6
  export { ExecutionNestingContext, ExecutionNestingState, NESTED_SPAWN_ENV, NestedSpawnRejectedError, SpawnEnv, assertNotNestedSpawn, buildNestedSpawnEnv } from './nesting-guard.cjs';
7
7
  export { CoreLogger, LogLevel, LoggerSink, configureLoggerSink, getLogger, resetLoggerSinkForTests } from './logger.cjs';
@@ -11,12 +11,11 @@ export { TAIJI_DATA_DIR_ENV, resetDataDirWarnForTests, resolveEngineDataDir } fr
11
11
  export { resolveEngineDir, resolveEnginesRoot, resolveJournalPath, resolvePoolDir, sanitizeSeg } from './paths.cjs';
12
12
  export { UiMethod, UiRequest, UiRequestHandler, UiResponse, isUiResponse } from './ui-types.cjs';
13
13
  export { ChannelHandler, ExtensionUiRequestLike, ParsedChannel, UiChannelRegistry, createUiChannelRegistry, parseChannel } from './ui-channels.cjs';
14
- export { BuildOutboundChildEnvOptions, ENGINE_ENV_DENY_LIST, ENGINE_ENV_L0_INFRA_KEYS, ENGINE_ENV_PREFIXES, EngineChildEnvOptions, EngineRelayEnv, buildEngineChildEnv, buildOutboundChildEnv } from './env.cjs';
15
- export { DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS, ENGINE_ABORT_KILL_GRACE_MS, ENGINE_HOST_REQUEST_TIMEOUT_ENV, EngineChildEnv, EngineSelfDestructOptions, ReverseRequestClock, SpawnEngineChildOptions, armEngineSelfDestruct, pumpNdjsonLines, spawnEngineChild } from './spawn.cjs';
14
+ export { BuildOutboundChildEnvOptions, ENGINE_ENV_DENY_LIST, ENGINE_ENV_L0_INFRA_KEYS, ENGINE_ENV_PREFIXES, EngineChildEnvOptions, buildEngineChildEnv, buildOutboundChildEnv } from './env.cjs';
15
+ export { DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS, ENGINE_ABORT_KILL_GRACE_MS, ENGINE_HOST_REQUEST_TIMEOUT_ENV, EngineChildEnv, EngineSelfDestructOptions, KillOwnProcessGroupDeps, KillOwnProcessGroupSpawnResult, ReverseRequestClock, SpawnEngineChildOptions, armEngineSelfDestruct, killOwnProcessGroup, pumpNdjsonLines, spawnEngineChild } from './spawn.cjs';
16
16
  export { ENGINE_NODE_ENV, EngineNodeHostKind, EngineNodeLaunch, EngineNodeLaunchOptions, hostKindOf, probeNodeExecutor, resetEngineNodeProbeCache, resolveEngineNodeLaunch } from './node-executor.cjs';
17
17
  export { CleanupResult, DEFAULT_STDERR_KEEP_DAYS, DEFAULT_STDERR_MAX_BYTES, StderrRotationParams, cleanupSiblingStderrLogs, cleanupStaleStderrLogs, isPidAlive, rotateStderrLogIfNeeded, stderrLogPathFor, stderrLogPidOf, stderrRotationParams } from './logs/stderr-rotation.cjs';
18
- export { ZCODE_HOST_DB_SUFFIX, ZCODE_ISOLATED_DB_SEGMENTS } from './zcode-db-paths.cjs';
19
- export { RELAY_ENV_NODE, RELAY_ENV_RECORD_ID, RELAY_ENV_SCRIPT, RELAY_ENV_SESSION_ID, RELAY_ENV_SOCKET, RELAY_EXIT_CODES, RELAY_PROTOCOL_VERSION, isRelayActive, readRelayForwardEnv } from './relay-env.cjs';
18
+ export { ZCODE_HOST_DB_SUFFIX, ZCODE_ISOLATED_DB_SEGMENTS, ZCODE_PI_SYNCED_PROVIDER_CONFIG_SEGMENTS } from './zcode-db-paths.cjs';
20
19
  export { toErrorMessage } from './error-message.cjs';
21
20
  export { BestEffortLevel, bestEffort } from './best-effort.cjs';
22
21
  export { replayJournal } from './journal-io.cjs';
@@ -50,38 +49,27 @@ declare const SUBAGENT_IDENTITY_ENV: {
50
49
  /** worktree 隔离标志("true" = 是)。 */
51
50
  readonly worktree: "PI_SUBAGENT_WORKTREE";
52
51
  };
52
+ /**
53
+ * [M1 D2] 任务文本进 env 的截断上限(字符数):写入点 = pi 引擎 spawn-runner 的
54
+ * applyContentIdentityKeys——写 `params.task` 前 2000 字符 + 截断标记
55
+ * `…[truncated N chars]`;env 读取点(appendSubagentIdentityEntry)零改动(读 env 值
56
+ * 即用)。全文以 pi session 文件首条 user 消息与父侧 manifest 为准(manifest 主路径
57
+ * 保留全文;截断只影响 manifest 缺席时的重建链/P-fallback 投影,降级面逐层判定登记
58
+ * 见设计 D2 消费方矩阵与 §3.7)。目的:控制面(握手帧)与 execve env 不再随任务正文
59
+ * 线性膨胀(ARG_MAX/E2BIG 族无界暴露的写入点根因修复)。
60
+ */
61
+ declare const PI_SUBAGENT_TASK_MAX_CHARS = 2000;
53
62
 
54
- /** 帧类型判别值(kind 字段词表)。as const 值即字面量类型——类型位置同样可用。 */
55
- declare const RELAY_FRAME_KINDS: {
56
- readonly handshake: "handshake";
57
- readonly accept: "accept";
58
- readonly reject: "reject";
59
- readonly data: "data";
60
- readonly exit: "exit";
61
- /**
62
- * goodbye(代理 → runtime,v1):代理被宿主终止(SIGTERM/SIGINT)前的预告帧——
63
- * 宿主侧的正常收割(agent_settled 后杀代理)与异常断连(宿主崩溃/主 pi 死)在
64
- * runtime 侧都表现为 socket close,无法区分;goodbye 让正常收割显式自报,runtime
65
- * 据此把后续 close 的日志从 warn(kill-on-disconnect)降级为 info(reaped,正常
66
- * teardown)。kill 行为本身不变(预告后 child 仍由 runtime 收割)。
67
- */
68
- readonly goodbye: "goodbye";
69
- };
70
- /** 数据泵方向(data 帧 dir 字段词表)。 */
71
- declare const RELAY_FRAME_DIRS: {
72
- readonly down: "down";
73
- readonly up: "up";
74
- readonly upStderr: "up-stderr";
75
- };
76
- /** reject 帧 reason 词表(runtime→代理的拒绝理由;代理对 version 以退出码 10 应答)。 */
77
- declare const RELAY_REJECT_REASONS: {
78
- readonly version: "version";
79
- readonly identity: "identity";
80
- readonly duplicate: "duplicate";
81
- readonly malformed: "malformed";
82
- };
83
- type RelayFrameKind = (typeof RELAY_FRAME_KINDS)[keyof typeof RELAY_FRAME_KINDS];
84
- type RelayFrameDir = (typeof RELAY_FRAME_DIRS)[keyof typeof RELAY_FRAME_DIRS];
85
- type RelayRejectReason = (typeof RELAY_REJECT_REASONS)[keyof typeof RELAY_REJECT_REASONS];
63
+ /** control socket 路径(runtime 监听 `<dataDir>/run/subagent-<pid>.sock`;Windows 为 named pipe)。 */
64
+ declare const CONTROL_ENV_SOCKET = "TAIJI_SUBAGENT_CONTROL_SOCKET";
65
+ /** 主会话根 id(runtime 注入;嵌套链所有层同值——连接归属与 channel 树的归属键)。 */
66
+ declare const CONTROL_ENV_ROOT_SESSION_ID = "TAIJI_SUBAGENT_CONTROL_ROOT_SESSION_ID";
67
+ /**
68
+ * transport 选择谓词(D5 选择逻辑的单一实现):SOCKET 非空 = 托管态 → runtime
69
+ * transport;空串/缺失 = standalone → local transport(调用方 warn)。消费方 =
70
+ * EngineClient transport 选择(u-m3-rt-transport);缺失即 local,不存在
71
+ * 「注入了一半」的中间态。
72
+ */
73
+ declare function isControlEnvActive(env: NodeJS.ProcessEnv | Record<string, string | undefined>): boolean;
86
74
 
87
- export { RELAY_FRAME_DIRS, RELAY_FRAME_KINDS, RELAY_REJECT_REASONS, type RelayFrameDir, type RelayFrameKind, type RelayRejectReason, SUBAGENT_IDENTITY_ENV };
75
+ export { CONTROL_ENV_ROOT_SESSION_ID, CONTROL_ENV_SOCKET, PI_SUBAGENT_TASK_MAX_CHARS, SUBAGENT_IDENTITY_ENV, isControlEnvActive };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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, SET_MODEL_REQUEST_TIMEOUT_MS, SET_MODEL_STAGE_TIMEOUT_MS, STDERR_TAIL_CHARS, SUPPORTED_PROTOCOL_RANGE, errorResponseFrameSchema, isProtocolVersionCompatible, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema } from './protocol/index.js';
2
- export { a as ENGINE_ERROR_CODE_PREFIX, b as ENGINE_PROTOCOL_ERROR_CODES, c as ENGINE_TIMEOUT_RECOVERY, d as EngineProtocolErrorCode, E 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 SET_MODEL_ERROR_CODES, j as SET_MODEL_NOT_ACTIVE_CODE, k as STDOUT_TAIL_ECHO_CHARS, l as SetModelErrorCode, m as SuccessResponseFrame, n as assertChatConversationSupported, o as engineConversationUnsupportedError, p as engineProtocolMismatchError, q as engineSetModelUnsupportedError, r as engineTimeoutDetail, s as isEngineErrorPassthroughCode, t as isEngineProtocolErrorCode, u as isNotificationFrame, v as isRequestFrame, w as isResponseFrame, x as isReverseRequestFrame, y as schemaEmulationFailedDetail } from './error-codes-DnFru4L4.js';
3
- export { C as CancelParams, c as CancelResult, D as DisposeParams, d as DisposeResult, b as InitializeParams, I as InitializeResult, L as ListModelsParams, e as ListModelsResult, P as PROTOCOL_METHODS, f as PingParams, g as PingResult, h as ProbeParams, i as ProtocolMethod, j as ProtocolParamsMap, k as ProtocolResultMap, l as ReadParams, R as RunContextParams, m as RunParams, n as RunResult, o as RunResumeParams, S as SetModelParams, a as SetModelResult, V as ValidateModelParams, p as ValidateModelResult } from './methods-C2zvZqhP.js';
4
- export { g as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, h as AgentEventTypeName, i as AgentFailureKind, c as AgentOutcome, j as AgentOutcomeUsage, k as AgentUsage, a as AgentUsageTotal, l as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, m as EngineProcessModel, I as InternalToolCall, f as ModelCatalogEntry, M as ModelRef, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, n as ToolCall, o as ToolCallEntry, p as ToolCallResult, T as Turn, W as WorktreeHandle } from './contract-types-jSa1g28F.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, SET_MODEL_REQUEST_TIMEOUT_MS, SET_MODEL_STAGE_TIMEOUT_MS, STDERR_TAIL_CHARS, SUBAGENT_CONTROL_CLOSED_REASONS, SUBAGENT_CONTROL_FRAME_KINDS, SUBAGENT_CONTROL_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_RANGE, SubagentControlClosedReason, SubagentControlFrameKind, errorResponseFrameSchema, isProtocolVersionCompatible, isSubagentControlClosedReason, isSubagentControlFrameKind, notificationFrameSchema, protocolErrorSchema, requestFrameSchema, reverseRequestFrameSchema, runSessionParamsSchema, successResponseFrameSchema } from './protocol/index.js';
2
+ export { a as ENGINE_ERROR_CODE_PREFIX, b as ENGINE_PROTOCOL_ERROR_CODES, c as ENGINE_SPAWN_DELIVERY_ERROR_CODES, d as ENGINE_SPAWN_DELIVERY_ERROR_RECOVERY, e as ENGINE_TIMEOUT_RECOVERY, f as ENGINE_TRANSPORT_ERROR_CODES, g as ENGINE_TRANSPORT_ERROR_RECOVERY, h as EngineProtocolErrorCode, E as EngineSdkError, i as EngineSpawnDeliveryErrorCode, j as EngineTransportErrorCode, k as ErrorResponseFrame, l as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, m as ResponseFrame, n as ReverseRequestFrame, o as ReverseResponseResult, S as SET_MODEL_ERROR_CODES, p as SET_MODEL_NOT_ACTIVE_CODE, q as STDOUT_TAIL_ECHO_CHARS, r as SetModelErrorCode, s as SuccessResponseFrame, t as assertChatConversationSupported, u as engineConversationUnsupportedError, v as engineProtocolMismatchError, w as engineSetModelUnsupportedError, x as engineTimeoutDetail, y as isEngineErrorPassthroughCode, z as isEngineProtocolErrorCode, A as isNotificationFrame, B as isRequestFrame, C as isResponseFrame, D as isReverseRequestFrame, F as schemaEmulationFailedDetail } from './error-codes-DrNf0gwT.js';
3
+ export { C as CancelParams, c as CancelResult, D as DisposeParams, d as DisposeResult, b as InitializeParams, I as InitializeResult, L as ListModelsParams, e as ListModelsResult, P as PROTOCOL_METHODS, f as PingParams, g as PingResult, h as ProbeParams, i as ProtocolMethod, j as ProtocolParamsMap, k as ProtocolResultMap, l as ReadParams, R as RunContextParams, m as RunParams, n as RunResult, o as RunResumeParams, S as SetModelParams, a as SetModelResult, V as ValidateModelParams, p as ValidateModelResult } from './methods-BdIH3FwS.js';
4
+ export { g as AGENT_EVENT_TYPE_NAMES, b as AgentCallOpts, A as AgentEvent, h as AgentEventTypeName, i as AgentFailureKind, c as AgentOutcome, j as AgentOutcomeUsage, k as AgentUsage, a as AgentUsageTotal, l as AssertMutuallyAssignable, d as EngineCapabilities, E as EngineHandleData, m as EngineProcessModel, I as InternalToolCall, f as ModelCatalogEntry, M as ModelRef, P as ProbeReport, R as ReplayedTurn, e as ResumeAnchor, S as SessionView, n as ToolCall, o as ToolCallEntry, p as ToolCallResult, T as Turn, W as WorktreeHandle } from './contract-types-BUHUMF9R.js';
5
5
  export { SCHEMA_EMULATION_TAIL_CHARS, StructuredOutputResult, buildSchemaEmulationSegment, extractAndValidateStructuredOutput } from './schema-emulation.js';
6
6
  export { ExecutionNestingContext, ExecutionNestingState, NESTED_SPAWN_ENV, NestedSpawnRejectedError, SpawnEnv, assertNotNestedSpawn, buildNestedSpawnEnv } from './nesting-guard.js';
7
7
  export { CoreLogger, LogLevel, LoggerSink, configureLoggerSink, getLogger, resetLoggerSinkForTests } from './logger.js';
@@ -11,12 +11,11 @@ export { TAIJI_DATA_DIR_ENV, resetDataDirWarnForTests, resolveEngineDataDir } fr
11
11
  export { resolveEngineDir, resolveEnginesRoot, resolveJournalPath, resolvePoolDir, sanitizeSeg } from './paths.js';
12
12
  export { UiMethod, UiRequest, UiRequestHandler, UiResponse, isUiResponse } from './ui-types.js';
13
13
  export { ChannelHandler, ExtensionUiRequestLike, ParsedChannel, UiChannelRegistry, createUiChannelRegistry, parseChannel } from './ui-channels.js';
14
- export { BuildOutboundChildEnvOptions, ENGINE_ENV_DENY_LIST, ENGINE_ENV_L0_INFRA_KEYS, ENGINE_ENV_PREFIXES, EngineChildEnvOptions, EngineRelayEnv, buildEngineChildEnv, buildOutboundChildEnv } from './env.js';
15
- export { DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS, ENGINE_ABORT_KILL_GRACE_MS, ENGINE_HOST_REQUEST_TIMEOUT_ENV, EngineChildEnv, EngineSelfDestructOptions, ReverseRequestClock, SpawnEngineChildOptions, armEngineSelfDestruct, pumpNdjsonLines, spawnEngineChild } from './spawn.js';
14
+ export { BuildOutboundChildEnvOptions, ENGINE_ENV_DENY_LIST, ENGINE_ENV_L0_INFRA_KEYS, ENGINE_ENV_PREFIXES, EngineChildEnvOptions, buildEngineChildEnv, buildOutboundChildEnv } from './env.js';
15
+ export { DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS, ENGINE_ABORT_KILL_GRACE_MS, ENGINE_HOST_REQUEST_TIMEOUT_ENV, EngineChildEnv, EngineSelfDestructOptions, KillOwnProcessGroupDeps, KillOwnProcessGroupSpawnResult, ReverseRequestClock, SpawnEngineChildOptions, armEngineSelfDestruct, killOwnProcessGroup, pumpNdjsonLines, spawnEngineChild } from './spawn.js';
16
16
  export { ENGINE_NODE_ENV, EngineNodeHostKind, EngineNodeLaunch, EngineNodeLaunchOptions, hostKindOf, probeNodeExecutor, resetEngineNodeProbeCache, resolveEngineNodeLaunch } from './node-executor.js';
17
17
  export { CleanupResult, DEFAULT_STDERR_KEEP_DAYS, DEFAULT_STDERR_MAX_BYTES, StderrRotationParams, cleanupSiblingStderrLogs, cleanupStaleStderrLogs, isPidAlive, rotateStderrLogIfNeeded, stderrLogPathFor, stderrLogPidOf, stderrRotationParams } from './logs/stderr-rotation.js';
18
- export { ZCODE_HOST_DB_SUFFIX, ZCODE_ISOLATED_DB_SEGMENTS } from './zcode-db-paths.js';
19
- export { RELAY_ENV_NODE, RELAY_ENV_RECORD_ID, RELAY_ENV_SCRIPT, RELAY_ENV_SESSION_ID, RELAY_ENV_SOCKET, RELAY_EXIT_CODES, RELAY_PROTOCOL_VERSION, isRelayActive, readRelayForwardEnv } from './relay-env.js';
18
+ export { ZCODE_HOST_DB_SUFFIX, ZCODE_ISOLATED_DB_SEGMENTS, ZCODE_PI_SYNCED_PROVIDER_CONFIG_SEGMENTS } from './zcode-db-paths.js';
20
19
  export { toErrorMessage } from './error-message.js';
21
20
  export { BestEffortLevel, bestEffort } from './best-effort.js';
22
21
  export { replayJournal } from './journal-io.js';
@@ -50,38 +49,27 @@ declare const SUBAGENT_IDENTITY_ENV: {
50
49
  /** worktree 隔离标志("true" = 是)。 */
51
50
  readonly worktree: "PI_SUBAGENT_WORKTREE";
52
51
  };
52
+ /**
53
+ * [M1 D2] 任务文本进 env 的截断上限(字符数):写入点 = pi 引擎 spawn-runner 的
54
+ * applyContentIdentityKeys——写 `params.task` 前 2000 字符 + 截断标记
55
+ * `…[truncated N chars]`;env 读取点(appendSubagentIdentityEntry)零改动(读 env 值
56
+ * 即用)。全文以 pi session 文件首条 user 消息与父侧 manifest 为准(manifest 主路径
57
+ * 保留全文;截断只影响 manifest 缺席时的重建链/P-fallback 投影,降级面逐层判定登记
58
+ * 见设计 D2 消费方矩阵与 §3.7)。目的:控制面(握手帧)与 execve env 不再随任务正文
59
+ * 线性膨胀(ARG_MAX/E2BIG 族无界暴露的写入点根因修复)。
60
+ */
61
+ declare const PI_SUBAGENT_TASK_MAX_CHARS = 2000;
53
62
 
54
- /** 帧类型判别值(kind 字段词表)。as const 值即字面量类型——类型位置同样可用。 */
55
- declare const RELAY_FRAME_KINDS: {
56
- readonly handshake: "handshake";
57
- readonly accept: "accept";
58
- readonly reject: "reject";
59
- readonly data: "data";
60
- readonly exit: "exit";
61
- /**
62
- * goodbye(代理 → runtime,v1):代理被宿主终止(SIGTERM/SIGINT)前的预告帧——
63
- * 宿主侧的正常收割(agent_settled 后杀代理)与异常断连(宿主崩溃/主 pi 死)在
64
- * runtime 侧都表现为 socket close,无法区分;goodbye 让正常收割显式自报,runtime
65
- * 据此把后续 close 的日志从 warn(kill-on-disconnect)降级为 info(reaped,正常
66
- * teardown)。kill 行为本身不变(预告后 child 仍由 runtime 收割)。
67
- */
68
- readonly goodbye: "goodbye";
69
- };
70
- /** 数据泵方向(data 帧 dir 字段词表)。 */
71
- declare const RELAY_FRAME_DIRS: {
72
- readonly down: "down";
73
- readonly up: "up";
74
- readonly upStderr: "up-stderr";
75
- };
76
- /** reject 帧 reason 词表(runtime→代理的拒绝理由;代理对 version 以退出码 10 应答)。 */
77
- declare const RELAY_REJECT_REASONS: {
78
- readonly version: "version";
79
- readonly identity: "identity";
80
- readonly duplicate: "duplicate";
81
- readonly malformed: "malformed";
82
- };
83
- type RelayFrameKind = (typeof RELAY_FRAME_KINDS)[keyof typeof RELAY_FRAME_KINDS];
84
- type RelayFrameDir = (typeof RELAY_FRAME_DIRS)[keyof typeof RELAY_FRAME_DIRS];
85
- type RelayRejectReason = (typeof RELAY_REJECT_REASONS)[keyof typeof RELAY_REJECT_REASONS];
63
+ /** control socket 路径(runtime 监听 `<dataDir>/run/subagent-<pid>.sock`;Windows 为 named pipe)。 */
64
+ declare const CONTROL_ENV_SOCKET = "TAIJI_SUBAGENT_CONTROL_SOCKET";
65
+ /** 主会话根 id(runtime 注入;嵌套链所有层同值——连接归属与 channel 树的归属键)。 */
66
+ declare const CONTROL_ENV_ROOT_SESSION_ID = "TAIJI_SUBAGENT_CONTROL_ROOT_SESSION_ID";
67
+ /**
68
+ * transport 选择谓词(D5 选择逻辑的单一实现):SOCKET 非空 = 托管态 → runtime
69
+ * transport;空串/缺失 = standalone → local transport(调用方 warn)。消费方 =
70
+ * EngineClient transport 选择(u-m3-rt-transport);缺失即 local,不存在
71
+ * 「注入了一半」的中间态。
72
+ */
73
+ declare function isControlEnvActive(env: NodeJS.ProcessEnv | Record<string, string | undefined>): boolean;
86
74
 
87
- export { RELAY_FRAME_DIRS, RELAY_FRAME_KINDS, RELAY_REJECT_REASONS, type RelayFrameDir, type RelayFrameKind, type RelayRejectReason, SUBAGENT_IDENTITY_ENV };
75
+ export { CONTROL_ENV_ROOT_SESSION_ID, CONTROL_ENV_SOCKET, PI_SUBAGENT_TASK_MAX_CHARS, SUBAGENT_IDENTITY_ENV, isControlEnvActive };