@zhushanwen/subagent-engine-sdk 0.10.1 → 0.12.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.
- package/dist/{chunk-AF2ETADP.js → chunk-2L3I2TWJ.js} +5 -10
- package/dist/{chunk-HSNDUHFH.js → chunk-3MCOZY3Z.js} +32 -4
- package/dist/{chunk-LM7P7OTA.js → chunk-7R6HYT2A.js} +60 -4
- package/dist/{chunk-JZN76I3S.js → chunk-NVF3PADP.js} +29 -1
- package/dist/{chunk-NTOLHLCL.js → chunk-QGXILDWB.js} +1 -1
- package/dist/{chunk-CNCFMPEH.js → chunk-TJMS3YOR.js} +1 -1
- package/dist/{chunk-SGAIDL63.js → chunk-U5MBAKS5.js} +21 -7
- package/dist/cli-entry.d.cts +1 -1
- package/dist/cli-entry.d.ts +1 -1
- package/dist/{contract-types-jSa1g28F.d.cts → contract-types-C1scOS_M.d.cts} +218 -21
- package/dist/{contract-types-jSa1g28F.d.ts → contract-types-C1scOS_M.d.ts} +218 -21
- package/dist/env.cjs +5 -10
- package/dist/env.d.cts +6 -17
- package/dist/env.d.ts +6 -17
- package/dist/env.js +1 -1
- package/dist/{error-codes-f-UO4a8D.d.cts → error-codes-CgcjlmeD.d.cts} +42 -6
- package/dist/{error-codes-DnFru4L4.d.ts → error-codes-o4rNd1Ee.d.ts} +42 -6
- package/dist/index.cjs +178 -103
- package/dist/index.d.cts +29 -41
- package/dist/index.d.ts +29 -41
- package/dist/index.js +54 -57
- package/dist/journal-io.d.cts +1 -1
- package/dist/journal-io.d.ts +1 -1
- package/dist/journal-replay.cjs +24 -7
- package/dist/journal-replay.d.cts +41 -7
- package/dist/journal-replay.d.ts +41 -7
- package/dist/journal-replay.js +7 -1
- package/dist/kill-chain.d.cts +5 -5
- package/dist/kill-chain.d.ts +5 -5
- package/dist/kill-chain.js +2 -2
- package/dist/logger.d.cts +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logs/stderr-rotation.d.cts +4 -4
- package/dist/logs/stderr-rotation.d.ts +4 -4
- package/dist/{methods-BLxg4ZFr.d.cts → methods-BzvzcCrB.d.cts} +5 -5
- package/dist/{methods-C2zvZqhP.d.ts → methods-CPMc4cvF.d.ts} +5 -5
- package/dist/node-executor.cjs +1 -1
- package/dist/node-executor.d.cts +4 -4
- package/dist/node-executor.d.ts +4 -4
- package/dist/node-executor.js +2 -2
- package/dist/port-contract.d.cts +9 -9
- package/dist/port-contract.d.ts +9 -9
- package/dist/protocol/index.cjs +103 -5
- package/dist/protocol/index.d.cts +59 -16
- package/dist/protocol/index.d.ts +59 -16
- package/dist/protocol/index.js +30 -2
- package/dist/server/index.cjs +1 -1
- package/dist/server/index.d.cts +10 -10
- package/dist/server/index.d.ts +10 -10
- package/dist/server/index.js +1 -1
- package/dist/spawn.cjs +32 -3
- package/dist/spawn.d.cts +34 -8
- package/dist/spawn.d.ts +34 -8
- package/dist/spawn.js +5 -3
- package/dist/ui-types.d.cts +2 -2
- package/dist/ui-types.d.ts +2 -2
- package/package.json +13 -2
- package/dist/chunk-GSW3DMN6.js +0 -39
- package/dist/relay-env.cjs +0 -71
- package/dist/relay-env.d.cts +0 -37
- package/dist/relay-env.d.ts +0 -37
- package/dist/relay-env.js +0 -23
package/dist/index.d.cts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
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
|
|
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-
|
|
4
|
-
export {
|
|
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-CgcjlmeD.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-BzvzcCrB.cjs';
|
|
4
|
+
export { h as AGENT_EVENT_TYPE_NAMES, c as AgentCallOpts, A as AgentEvent, i as AgentEventTypeName, j as AgentFailureKind, d as AgentOutcome, k as AgentOutcomeUsage, a as AgentUsage, b as AgentUsageTotal, l as AssertMutuallyAssignable, e as EngineCapabilities, E as EngineHandleData, m as EngineProcessModel, n as EngineStopReason, F as FAILURE_CAUSE_CLOSED_KINDS, o as FAILURE_CAUSE_KINDS_BY_CLASS, p as FAILURE_CAUSE_KINDS_BY_CLASS_LOCK, q as FAILURE_CAUSE_KIND_VOCAB_LOCK, r as FailureCause, s as FailureCauseClass, t as FailureRetryability, I as InternalToolCall, g as ModelCatalogEntry, M as ModelRef, P as ProbeReport, R as ReplayedTurn, f as ResumeAnchor, S as SessionView, u as ToolCall, v as ToolCallEntry, w as ToolCallResult, T as Turn, W as WorktreeHandle, _ as _EventVocabSyncLock } from './contract-types-C1scOS_M.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';
|
|
8
8
|
export { DEFAULT_KILL_GRACE_MS, DEFAULT_NATIVE_INTERRUPT_GRACE_MS, HOST_TIMEOUT_ABORT_REASON, KillChainOptions, KillableChild, PidChainOptions, abortWithFallback, killChain, killPidChain, probePidAlive, safeKill, synthesizeTimeoutOutcome } from './kill-chain.cjs';
|
|
9
|
-
export { ReplayRecordView, aggregateUsage, createReplayRecord, eventsToSessionView, sessionIdFromHandle, toReplayedTurn, updateFromEvent } from './journal-replay.cjs';
|
|
9
|
+
export { ErrorFact, ReplayRecordView, addUsage, aggregateUsage, appendErrorFact, createReplayRecord, emptyTurn, eventsToSessionView, sessionIdFromHandle, toReplayedTurn, updateFromEvent } from './journal-replay.cjs';
|
|
10
10
|
export { TAIJI_DATA_DIR_ENV, resetDataDirWarnForTests, resolveEngineDataDir } from './data-dir.cjs';
|
|
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,
|
|
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
18
|
export { ZCODE_HOST_DB_SUFFIX, ZCODE_ISOLATED_DB_SEGMENTS, ZCODE_PI_SYNCED_PROVIDER_CONFIG_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';
|
|
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
|
-
/**
|
|
55
|
-
declare const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 {
|
|
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,22 +1,21 @@
|
|
|
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
|
|
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-
|
|
4
|
-
export {
|
|
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-o4rNd1Ee.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-CPMc4cvF.js';
|
|
4
|
+
export { h as AGENT_EVENT_TYPE_NAMES, c as AgentCallOpts, A as AgentEvent, i as AgentEventTypeName, j as AgentFailureKind, d as AgentOutcome, k as AgentOutcomeUsage, a as AgentUsage, b as AgentUsageTotal, l as AssertMutuallyAssignable, e as EngineCapabilities, E as EngineHandleData, m as EngineProcessModel, n as EngineStopReason, F as FAILURE_CAUSE_CLOSED_KINDS, o as FAILURE_CAUSE_KINDS_BY_CLASS, p as FAILURE_CAUSE_KINDS_BY_CLASS_LOCK, q as FAILURE_CAUSE_KIND_VOCAB_LOCK, r as FailureCause, s as FailureCauseClass, t as FailureRetryability, I as InternalToolCall, g as ModelCatalogEntry, M as ModelRef, P as ProbeReport, R as ReplayedTurn, f as ResumeAnchor, S as SessionView, u as ToolCall, v as ToolCallEntry, w as ToolCallResult, T as Turn, W as WorktreeHandle, _ as _EventVocabSyncLock } from './contract-types-C1scOS_M.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';
|
|
8
8
|
export { DEFAULT_KILL_GRACE_MS, DEFAULT_NATIVE_INTERRUPT_GRACE_MS, HOST_TIMEOUT_ABORT_REASON, KillChainOptions, KillableChild, PidChainOptions, abortWithFallback, killChain, killPidChain, probePidAlive, safeKill, synthesizeTimeoutOutcome } from './kill-chain.js';
|
|
9
|
-
export { ReplayRecordView, aggregateUsage, createReplayRecord, eventsToSessionView, sessionIdFromHandle, toReplayedTurn, updateFromEvent } from './journal-replay.js';
|
|
9
|
+
export { ErrorFact, ReplayRecordView, addUsage, aggregateUsage, appendErrorFact, createReplayRecord, emptyTurn, eventsToSessionView, sessionIdFromHandle, toReplayedTurn, updateFromEvent } from './journal-replay.js';
|
|
10
10
|
export { TAIJI_DATA_DIR_ENV, resetDataDirWarnForTests, resolveEngineDataDir } from './data-dir.js';
|
|
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,
|
|
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
18
|
export { ZCODE_HOST_DB_SUFFIX, ZCODE_ISOLATED_DB_SEGMENTS, ZCODE_PI_SYNCED_PROVIDER_CONFIG_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';
|
|
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
|
-
/**
|
|
55
|
-
declare const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 {
|
|
75
|
+
export { CONTROL_ENV_ROOT_SESSION_ID, CONTROL_ENV_SOCKET, PI_SUBAGENT_TASK_MAX_CHARS, SUBAGENT_IDENTITY_ENV, isControlEnvActive };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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";
|
|
12
1
|
import {
|
|
13
2
|
bestEffort
|
|
14
3
|
} from "./chunk-QMEHSKNR.js";
|
|
@@ -52,22 +41,23 @@ import {
|
|
|
52
41
|
ENGINE_ENV_PREFIXES,
|
|
53
42
|
buildEngineChildEnv,
|
|
54
43
|
buildOutboundChildEnv
|
|
55
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-2L3I2TWJ.js";
|
|
56
45
|
import {
|
|
57
46
|
DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
|
|
58
47
|
ENGINE_ABORT_KILL_GRACE_MS,
|
|
59
48
|
ENGINE_HOST_REQUEST_TIMEOUT_ENV,
|
|
60
49
|
armEngineSelfDestruct,
|
|
50
|
+
killOwnProcessGroup,
|
|
61
51
|
pumpNdjsonLines,
|
|
62
52
|
spawnEngineChild
|
|
63
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-3MCOZY3Z.js";
|
|
64
54
|
import {
|
|
65
55
|
ENGINE_NODE_ENV,
|
|
66
56
|
hostKindOf,
|
|
67
57
|
probeNodeExecutor,
|
|
68
58
|
resetEngineNodeProbeCache,
|
|
69
59
|
resolveEngineNodeLaunch
|
|
70
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-QGXILDWB.js";
|
|
71
61
|
import {
|
|
72
62
|
DEFAULT_STDERR_KEEP_DAYS,
|
|
73
63
|
DEFAULT_STDERR_MAX_BYTES,
|
|
@@ -82,18 +72,28 @@ import {
|
|
|
82
72
|
import {
|
|
83
73
|
AGENT_EVENT_TYPE_NAMES,
|
|
84
74
|
ENGINE_PROTOCOL_SCHEMAS,
|
|
75
|
+
FAILURE_CAUSE_CLOSED_KINDS,
|
|
76
|
+
FAILURE_CAUSE_KINDS_BY_CLASS,
|
|
77
|
+
FAILURE_CAUSE_KINDS_BY_CLASS_LOCK,
|
|
78
|
+
FAILURE_CAUSE_KIND_VOCAB_LOCK,
|
|
85
79
|
FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
|
|
86
80
|
PROTOCOL_METHODS,
|
|
87
81
|
REVERSE_CHANNELS,
|
|
88
82
|
REVERSE_CHANNEL_TIMEOUT_CLASS,
|
|
83
|
+
SUBAGENT_CONTROL_CLOSED_REASONS,
|
|
84
|
+
SUBAGENT_CONTROL_FRAME_KINDS,
|
|
85
|
+
SUBAGENT_CONTROL_PROTOCOL_VERSION,
|
|
86
|
+
_EventVocabSyncLock,
|
|
89
87
|
errorResponseFrameSchema,
|
|
88
|
+
isSubagentControlClosedReason,
|
|
89
|
+
isSubagentControlFrameKind,
|
|
90
90
|
notificationFrameSchema,
|
|
91
91
|
protocolErrorSchema,
|
|
92
92
|
requestFrameSchema,
|
|
93
93
|
reverseRequestFrameSchema,
|
|
94
94
|
runSessionParamsSchema,
|
|
95
95
|
successResponseFrameSchema
|
|
96
|
-
} from "./chunk-
|
|
96
|
+
} from "./chunk-7R6HYT2A.js";
|
|
97
97
|
import {
|
|
98
98
|
isNotificationFrame,
|
|
99
99
|
isRequestFrame,
|
|
@@ -122,7 +122,7 @@ import {
|
|
|
122
122
|
probePidAlive,
|
|
123
123
|
safeKill,
|
|
124
124
|
synthesizeTimeoutOutcome
|
|
125
|
-
} from "./chunk-
|
|
125
|
+
} from "./chunk-TJMS3YOR.js";
|
|
126
126
|
import {
|
|
127
127
|
toErrorMessage
|
|
128
128
|
} from "./chunk-PYO3YR7W.js";
|
|
@@ -131,7 +131,11 @@ import {
|
|
|
131
131
|
ENGINE_ERROR_CODE_PREFIX,
|
|
132
132
|
ENGINE_PROTOCOL_ERROR_CODES,
|
|
133
133
|
ENGINE_PROTOCOL_VERSION,
|
|
134
|
+
ENGINE_SPAWN_DELIVERY_ERROR_CODES,
|
|
135
|
+
ENGINE_SPAWN_DELIVERY_ERROR_RECOVERY,
|
|
134
136
|
ENGINE_TIMEOUT_RECOVERY,
|
|
137
|
+
ENGINE_TRANSPORT_ERROR_CODES,
|
|
138
|
+
ENGINE_TRANSPORT_ERROR_RECOVERY,
|
|
135
139
|
EngineSdkError,
|
|
136
140
|
HANDSHAKE_TIMEOUT_MS,
|
|
137
141
|
REVERSE_REQUEST_TIMEOUT_MS,
|
|
@@ -151,20 +155,23 @@ import {
|
|
|
151
155
|
isEngineProtocolErrorCode,
|
|
152
156
|
isProtocolVersionCompatible,
|
|
153
157
|
schemaEmulationFailedDetail
|
|
154
|
-
} from "./chunk-
|
|
158
|
+
} from "./chunk-NVF3PADP.js";
|
|
155
159
|
import {
|
|
156
160
|
configureLoggerSink,
|
|
157
161
|
getLogger,
|
|
158
162
|
resetLoggerSinkForTests
|
|
159
163
|
} from "./chunk-NXNNXGTY.js";
|
|
160
164
|
import {
|
|
165
|
+
addUsage,
|
|
161
166
|
aggregateUsage,
|
|
167
|
+
appendErrorFact,
|
|
162
168
|
createReplayRecord,
|
|
169
|
+
emptyTurn,
|
|
163
170
|
eventsToSessionView,
|
|
164
171
|
sessionIdFromHandle,
|
|
165
172
|
toReplayedTurn,
|
|
166
173
|
updateFromEvent
|
|
167
|
-
} from "./chunk-
|
|
174
|
+
} from "./chunk-U5MBAKS5.js";
|
|
168
175
|
import "./chunk-JSBRDJBE.js";
|
|
169
176
|
|
|
170
177
|
// src/identity-env.ts
|
|
@@ -194,37 +201,19 @@ var SUBAGENT_IDENTITY_ENV = {
|
|
|
194
201
|
/** worktree 隔离标志("true" = 是)。 */
|
|
195
202
|
worktree: "PI_SUBAGENT_WORKTREE"
|
|
196
203
|
};
|
|
204
|
+
var PI_SUBAGENT_TASK_MAX_CHARS = 2e3;
|
|
197
205
|
|
|
198
|
-
// src/
|
|
199
|
-
var
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
exit: "exit",
|
|
205
|
-
/**
|
|
206
|
-
* goodbye(代理 → runtime,v1):代理被宿主终止(SIGTERM/SIGINT)前的预告帧——
|
|
207
|
-
* 宿主侧的正常收割(agent_settled 后杀代理)与异常断连(宿主崩溃/主 pi 死)在
|
|
208
|
-
* runtime 侧都表现为 socket close,无法区分;goodbye 让正常收割显式自报,runtime
|
|
209
|
-
* 据此把后续 close 的日志从 warn(kill-on-disconnect)降级为 info(reaped,正常
|
|
210
|
-
* teardown)。kill 行为本身不变(预告后 child 仍由 runtime 收割)。
|
|
211
|
-
*/
|
|
212
|
-
goodbye: "goodbye"
|
|
213
|
-
};
|
|
214
|
-
var RELAY_FRAME_DIRS = {
|
|
215
|
-
down: "down",
|
|
216
|
-
up: "up",
|
|
217
|
-
upStderr: "up-stderr"
|
|
218
|
-
};
|
|
219
|
-
var RELAY_REJECT_REASONS = {
|
|
220
|
-
version: "version",
|
|
221
|
-
identity: "identity",
|
|
222
|
-
duplicate: "duplicate",
|
|
223
|
-
malformed: "malformed"
|
|
224
|
-
};
|
|
206
|
+
// src/control-env.ts
|
|
207
|
+
var CONTROL_ENV_SOCKET = "TAIJI_SUBAGENT_CONTROL_SOCKET";
|
|
208
|
+
var CONTROL_ENV_ROOT_SESSION_ID = "TAIJI_SUBAGENT_CONTROL_ROOT_SESSION_ID";
|
|
209
|
+
function isControlEnvActive(env) {
|
|
210
|
+
return Boolean(env[CONTROL_ENV_SOCKET]);
|
|
211
|
+
}
|
|
225
212
|
export {
|
|
226
213
|
AGENT_EVENT_TYPE_NAMES,
|
|
227
214
|
CANCEL_SETTLE_GRACE_MS,
|
|
215
|
+
CONTROL_ENV_ROOT_SESSION_ID,
|
|
216
|
+
CONTROL_ENV_SOCKET,
|
|
228
217
|
DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS,
|
|
229
218
|
DEFAULT_KILL_GRACE_MS,
|
|
230
219
|
DEFAULT_NATIVE_INTERRUPT_GRACE_MS,
|
|
@@ -240,25 +229,24 @@ export {
|
|
|
240
229
|
ENGINE_PROTOCOL_ERROR_CODES,
|
|
241
230
|
ENGINE_PROTOCOL_SCHEMAS,
|
|
242
231
|
ENGINE_PROTOCOL_VERSION,
|
|
232
|
+
ENGINE_SPAWN_DELIVERY_ERROR_CODES,
|
|
233
|
+
ENGINE_SPAWN_DELIVERY_ERROR_RECOVERY,
|
|
243
234
|
ENGINE_TIMEOUT_RECOVERY,
|
|
235
|
+
ENGINE_TRANSPORT_ERROR_CODES,
|
|
236
|
+
ENGINE_TRANSPORT_ERROR_RECOVERY,
|
|
244
237
|
EngineSdkError,
|
|
245
238
|
ExecutionNestingContext,
|
|
239
|
+
FAILURE_CAUSE_CLOSED_KINDS,
|
|
240
|
+
FAILURE_CAUSE_KINDS_BY_CLASS,
|
|
241
|
+
FAILURE_CAUSE_KINDS_BY_CLASS_LOCK,
|
|
242
|
+
FAILURE_CAUSE_KIND_VOCAB_LOCK,
|
|
246
243
|
FORBIDDEN_CREDENTIAL_KEY_FRAGMENTS,
|
|
247
244
|
HANDSHAKE_TIMEOUT_MS,
|
|
248
245
|
HOST_TIMEOUT_ABORT_REASON,
|
|
249
246
|
NESTED_SPAWN_ENV,
|
|
250
247
|
NestedSpawnRejectedError,
|
|
248
|
+
PI_SUBAGENT_TASK_MAX_CHARS,
|
|
251
249
|
PROTOCOL_METHODS,
|
|
252
|
-
RELAY_ENV_NODE,
|
|
253
|
-
RELAY_ENV_RECORD_ID,
|
|
254
|
-
RELAY_ENV_SCRIPT,
|
|
255
|
-
RELAY_ENV_SESSION_ID,
|
|
256
|
-
RELAY_ENV_SOCKET,
|
|
257
|
-
RELAY_EXIT_CODES,
|
|
258
|
-
RELAY_FRAME_DIRS,
|
|
259
|
-
RELAY_FRAME_KINDS,
|
|
260
|
-
RELAY_PROTOCOL_VERSION,
|
|
261
|
-
RELAY_REJECT_REASONS,
|
|
262
250
|
REVERSE_CHANNELS,
|
|
263
251
|
REVERSE_CHANNEL_TIMEOUT_CLASS,
|
|
264
252
|
REVERSE_REQUEST_TIMEOUT_MS,
|
|
@@ -270,14 +258,20 @@ export {
|
|
|
270
258
|
SHARED_POOL_KEY,
|
|
271
259
|
STDERR_TAIL_CHARS,
|
|
272
260
|
STDOUT_TAIL_ECHO_CHARS,
|
|
261
|
+
SUBAGENT_CONTROL_CLOSED_REASONS,
|
|
262
|
+
SUBAGENT_CONTROL_FRAME_KINDS,
|
|
263
|
+
SUBAGENT_CONTROL_PROTOCOL_VERSION,
|
|
273
264
|
SUBAGENT_IDENTITY_ENV,
|
|
274
265
|
SUPPORTED_PROTOCOL_RANGE,
|
|
275
266
|
TAIJI_DATA_DIR_ENV,
|
|
276
267
|
ZCODE_HOST_DB_SUFFIX,
|
|
277
268
|
ZCODE_ISOLATED_DB_SEGMENTS,
|
|
278
269
|
ZCODE_PI_SYNCED_PROVIDER_CONFIG_SEGMENTS,
|
|
270
|
+
_EventVocabSyncLock,
|
|
279
271
|
abortWithFallback,
|
|
272
|
+
addUsage,
|
|
280
273
|
aggregateUsage,
|
|
274
|
+
appendErrorFact,
|
|
281
275
|
armEngineSelfDestruct,
|
|
282
276
|
assertChatConversationSupported,
|
|
283
277
|
assertNotNestedSpawn,
|
|
@@ -291,6 +285,7 @@ export {
|
|
|
291
285
|
configureLoggerSink,
|
|
292
286
|
createReplayRecord,
|
|
293
287
|
createUiChannelRegistry,
|
|
288
|
+
emptyTurn,
|
|
294
289
|
engineConversationUnsupportedError,
|
|
295
290
|
engineProtocolMismatchError,
|
|
296
291
|
engineSetModelUnsupportedError,
|
|
@@ -300,17 +295,20 @@ export {
|
|
|
300
295
|
extractAndValidateStructuredOutput,
|
|
301
296
|
getLogger,
|
|
302
297
|
hostKindOf,
|
|
298
|
+
isControlEnvActive,
|
|
303
299
|
isEngineErrorPassthroughCode,
|
|
304
300
|
isEngineProtocolErrorCode,
|
|
305
301
|
isNotificationFrame,
|
|
306
302
|
isPidAlive,
|
|
307
303
|
isProtocolVersionCompatible,
|
|
308
|
-
isRelayActive,
|
|
309
304
|
isRequestFrame,
|
|
310
305
|
isResponseFrame,
|
|
311
306
|
isReverseRequestFrame,
|
|
307
|
+
isSubagentControlClosedReason,
|
|
308
|
+
isSubagentControlFrameKind,
|
|
312
309
|
isUiResponse,
|
|
313
310
|
killChain,
|
|
311
|
+
killOwnProcessGroup,
|
|
314
312
|
killPidChain,
|
|
315
313
|
notificationFrameSchema,
|
|
316
314
|
parseChannel,
|
|
@@ -319,7 +317,6 @@ export {
|
|
|
319
317
|
probePidAlive,
|
|
320
318
|
protocolErrorSchema,
|
|
321
319
|
pumpNdjsonLines,
|
|
322
|
-
readRelayForwardEnv,
|
|
323
320
|
replayJournal,
|
|
324
321
|
requestFrameSchema,
|
|
325
322
|
resetDataDirWarnForTests,
|
package/dist/journal-io.d.cts
CHANGED
package/dist/journal-io.d.ts
CHANGED
package/dist/journal-replay.cjs
CHANGED
|
@@ -20,8 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/journal-replay.ts
|
|
21
21
|
var journal_replay_exports = {};
|
|
22
22
|
__export(journal_replay_exports, {
|
|
23
|
+
addUsage: () => addUsage,
|
|
23
24
|
aggregateUsage: () => aggregateUsage,
|
|
25
|
+
appendErrorFact: () => appendErrorFact,
|
|
24
26
|
createReplayRecord: () => createReplayRecord,
|
|
27
|
+
emptyTurn: () => emptyTurn,
|
|
25
28
|
eventsToSessionView: () => eventsToSessionView,
|
|
26
29
|
sessionIdFromHandle: () => sessionIdFromHandle,
|
|
27
30
|
toReplayedTurn: () => toReplayedTurn,
|
|
@@ -60,7 +63,8 @@ function createReplayRecord() {
|
|
|
60
63
|
turns: [emptyTurn()],
|
|
61
64
|
turnCount: 0,
|
|
62
65
|
totalTokens: 0,
|
|
63
|
-
lastError: void 0
|
|
66
|
+
lastError: void 0,
|
|
67
|
+
errors: []
|
|
64
68
|
};
|
|
65
69
|
}
|
|
66
70
|
function currentTurn(record) {
|
|
@@ -154,7 +158,11 @@ function applyTurnEnd(record) {
|
|
|
154
158
|
turn.closed = true;
|
|
155
159
|
turn.closedTs = Date.now();
|
|
156
160
|
record.turnCount += 1;
|
|
157
|
-
|
|
161
|
+
}
|
|
162
|
+
function appendErrorFact(record, message) {
|
|
163
|
+
if (!message) return;
|
|
164
|
+
(record.errors ??= []).push({ message, at: Date.now() });
|
|
165
|
+
record.lastError = message;
|
|
158
166
|
}
|
|
159
167
|
function applyMessageEnd(record, event) {
|
|
160
168
|
if (event.usage) {
|
|
@@ -163,11 +171,11 @@ function applyMessageEnd(record, event) {
|
|
|
163
171
|
record.totalTokens += (event.usage.input ?? 0) + (event.usage.output ?? 0) + (event.usage.cacheRead ?? 0) + (event.usage.cacheWrite ?? 0);
|
|
164
172
|
}
|
|
165
173
|
if (event.error) {
|
|
166
|
-
record
|
|
174
|
+
appendErrorFact(record, event.error);
|
|
167
175
|
}
|
|
168
176
|
}
|
|
169
177
|
function applyErrorEvent(record, event) {
|
|
170
|
-
record
|
|
178
|
+
appendErrorFact(record, event.message);
|
|
171
179
|
}
|
|
172
180
|
function updateFromEvent(record, event) {
|
|
173
181
|
switch (event.type) {
|
|
@@ -181,13 +189,13 @@ function updateFromEvent(record, event) {
|
|
|
181
189
|
return applyToolStart(record, event);
|
|
182
190
|
case "tool_end":
|
|
183
191
|
return applyToolEnd(record, event);
|
|
184
|
-
// ── turn_end
|
|
192
|
+
// ── turn_end:结束当前 turn ──
|
|
185
193
|
case "turn_end":
|
|
186
194
|
return applyTurnEnd(record);
|
|
187
195
|
// ── message_end:usage 增量累加 + totalTokens 累加 ──
|
|
188
196
|
case "message_end":
|
|
189
197
|
return applyMessageEnd(record, event);
|
|
190
|
-
// ── error
|
|
198
|
+
// ── error:appendErrorFact 入账(errors 只追加 + lastError 派生)──
|
|
191
199
|
case "error":
|
|
192
200
|
return applyErrorEvent(record, event);
|
|
193
201
|
// ── compaction:不产生数据(不变)──
|
|
@@ -197,10 +205,16 @@ function updateFromEvent(record, event) {
|
|
|
197
205
|
case "activity":
|
|
198
206
|
return;
|
|
199
207
|
// ── armed:武装确认回执([D3 协议版 P6],协议语义见 contract-types)——监控
|
|
200
|
-
// 信号不进 record
|
|
208
|
+
// 信号不进 record 派生视图,消费方 = 宿主等待门 + run 事件 journal(C3 第④步
|
|
201
209
|
// 双侧 reducer no-op 义务的 SDK 侧)
|
|
202
210
|
case "armed":
|
|
203
211
|
return;
|
|
212
|
+
// ── auto_retry:pi 原生重试边界帧([subagent-observability §3.3.1 P5])——
|
|
213
|
+
// 观测面(journal 留痕失败尝试轨迹),不进 record 派生视图:失败尝试的
|
|
214
|
+
// turns/usage 切片与 retryAttempts 计数由引擎收尾快照一次产出(outcome
|
|
215
|
+
// 字段承载),reducer 写入会让失败尝试静默混进 turns 聚合,恰违背 P5 计账。
|
|
216
|
+
case "auto_retry":
|
|
217
|
+
return;
|
|
204
218
|
default: {
|
|
205
219
|
const _exhaustive = event;
|
|
206
220
|
return _exhaustive;
|
|
@@ -255,8 +269,11 @@ function sessionIdFromHandle(handle) {
|
|
|
255
269
|
}
|
|
256
270
|
// Annotate the CommonJS export names for ESM import in node:
|
|
257
271
|
0 && (module.exports = {
|
|
272
|
+
addUsage,
|
|
258
273
|
aggregateUsage,
|
|
274
|
+
appendErrorFact,
|
|
259
275
|
createReplayRecord,
|
|
276
|
+
emptyTurn,
|
|
260
277
|
eventsToSessionView,
|
|
261
278
|
sessionIdFromHandle,
|
|
262
279
|
toReplayedTurn,
|
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import { T as Turn, a as AgentUsageTotal, A as AgentEvent, S as SessionView, E as EngineHandleData, R as ReplayedTurn } from './contract-types-
|
|
1
|
+
import { T as Turn, a as AgentUsage, b as AgentUsageTotal, A as AgentEvent, S as SessionView, E as EngineHandleData, R as ReplayedTurn } from './contract-types-C1scOS_M.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 轮失败事实(subagent-observability §3.3.5:失败事实只追加进 errors 数组,
|
|
5
|
+
* lastError 由「最后一个非空轮失败」派生——数组只追加且空串不入账,
|
|
6
|
+
* 尾项即最后一个非空失败)。事实源记录,append-only,不因后续轮终清除。
|
|
7
|
+
*/
|
|
8
|
+
interface ErrorFact {
|
|
9
|
+
/** 错误消息原文(空串 / 缺席不入账——无信息失败事实不占位)。 */
|
|
10
|
+
message: string;
|
|
11
|
+
/** 事实落账墙钟(Date.now(),ms)。 */
|
|
12
|
+
at: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* reducer 的 record 视图(core ExecutionRecord 的结构子集:reducer 只触碰这五个字段)。
|
|
5
16
|
* core ExecutionRecord 满足本视图(W2 断言挂靠点);SDK 内自持 createReplayRecord 产出。
|
|
6
17
|
*/
|
|
7
18
|
interface ReplayRecordView {
|
|
@@ -9,19 +20,42 @@ interface ReplayRecordView {
|
|
|
9
20
|
turnCount: number;
|
|
10
21
|
totalTokens: number;
|
|
11
22
|
lastError: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* 轮失败事实只追加数组(§3.3.5)。缺省 undefined 视为空(磁盘重建的旧 record
|
|
25
|
+
* 兼容——reducer 以 `??=` 兜底初始化,不要求构造方预置)。
|
|
26
|
+
*/
|
|
27
|
+
errors?: ErrorFact[];
|
|
12
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* 累加两个 AgentUsage(field-wise)。prev 为空时返回 next 的拷贝。
|
|
31
|
+
* 供 message_end 把 usage 增量并入 turn.usageDelta。
|
|
32
|
+
*/
|
|
33
|
+
declare function addUsage(prev: AgentUsage | undefined, next: AgentUsage): AgentUsage;
|
|
34
|
+
/** 创建一个空 turn(text/thinking 空,无 toolCalls,未结束)。 */
|
|
35
|
+
declare function emptyTurn(): Turn;
|
|
13
36
|
/** 重放场景的 record 构造(对齐 core eventsToSessionView 内 createRecord 后的 reducer 视图)。 */
|
|
14
37
|
declare function createReplayRecord(): ReplayRecordView;
|
|
15
38
|
/**
|
|
16
|
-
*
|
|
39
|
+
* [§3.3.5] 轮失败事实入账单点:append ErrorFact + lastError 派生刷新(唯一写点)。
|
|
40
|
+
* 空串 / 缺席不入账(无信息失败事实不占位);`??=` 兜底磁盘重建的旧 record
|
|
41
|
+
* (无 errors 字段,缺省 undefined 视为空)。lastError = 最后追加的非空 message
|
|
42
|
+
* ——数组 append-only 且项非空,尾项即「最后一个非空轮失败」。
|
|
43
|
+
*
|
|
44
|
+
* [subagent-observability u3] 导出给 core 轮终写点(record-store-rounds 失败轮
|
|
45
|
+
* settlement)复用——u2 移交的「markRoundIdle 直写 rec.lastError 绕过 errors 数组」
|
|
46
|
+
* 收编:轮终失败事实与流内 error 事件走同一入账通道,写点单点(双写漂移防线)。
|
|
47
|
+
*/
|
|
48
|
+
declare function appendErrorFact(record: ReplayRecordView, message: string | undefined | null): void;
|
|
49
|
+
/**
|
|
50
|
+
* 从 AgentEvent 更新 record。所有数据收敛进 record.turns[]。
|
|
17
51
|
* - text/thinking:流式累积进 currentTurn()(完整内容,非切片)
|
|
18
52
|
* - tool_start/end:push 进 currentTurn().toolCalls(含完整 result)
|
|
19
53
|
* tool_end 跨 turn 扫描找 running 同名 toolCall(兜底滞后事件)
|
|
20
|
-
* - turn_end
|
|
21
|
-
*
|
|
54
|
+
* - turn_end:结束当前 turn,记 closedTs(真实墙钟,供 getEventLog);
|
|
55
|
+
* 不再清 lastError(§3.3.5——error → turn_end 序后 lastError 仍可读)
|
|
22
56
|
* - message_end:usage 增量存进末 turn.usageDelta(直接写末 turn,不开新 turn);
|
|
23
57
|
* totalTokens 累加
|
|
24
|
-
* - error
|
|
58
|
+
* - error:经 appendErrorFact 入账(errors 只追加 + lastError 派生刷新)
|
|
25
59
|
*
|
|
26
60
|
* 唯一写点——replay 与 live 共用(重放等价性的实现体)。
|
|
27
61
|
*
|
|
@@ -42,4 +76,4 @@ declare function eventsToSessionView(events: readonly AgentEvent[], engineId: st
|
|
|
42
76
|
/** handle.sessionRef 的 sessionId 提取(引擎自定义键,运行时 guard)。 */
|
|
43
77
|
declare function sessionIdFromHandle(handle: EngineHandleData): string | undefined;
|
|
44
78
|
|
|
45
|
-
export { type ReplayRecordView, aggregateUsage, createReplayRecord, eventsToSessionView, sessionIdFromHandle, toReplayedTurn, updateFromEvent };
|
|
79
|
+
export { type ErrorFact, type ReplayRecordView, addUsage, aggregateUsage, appendErrorFact, createReplayRecord, emptyTurn, eventsToSessionView, sessionIdFromHandle, toReplayedTurn, updateFromEvent };
|