@zhushanwen/subagent-engine-sdk 0.4.0 → 0.5.1
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-7I4XGL5J.js → chunk-BBWUC2EE.js} +2 -2
- package/dist/{chunk-3K2P2CM2.js → chunk-CNQTJJF5.js} +1 -1
- package/dist/{chunk-DSQ7JQKM.js → chunk-GSW3DMN6.js} +5 -5
- package/dist/{chunk-BBVZK5DL.js → chunk-M3SZTDNQ.js} +20 -20
- package/dist/{chunk-HYES77BR.js → chunk-MSAJXIP4.js} +2 -2
- package/dist/{chunk-FJT23P7T.js → chunk-QOEXD2FT.js} +1 -1
- package/dist/{chunk-LKPVN3N6.js → chunk-W3BKI2BP.js} +3 -3
- package/dist/{chunk-WS4WAZVR.js → chunk-WMDMXP2F.js} +2 -2
- package/dist/{chunk-GT6YLLN4.js → chunk-X24IVQKJ.js} +5 -5
- package/dist/{chunk-365AUV6N.js → chunk-YE472JOO.js} +2 -2
- package/dist/{contract-types-C71Sqq8d.d.cts → contract-types-Dsvy79r3.d.cts} +9 -10
- package/dist/{contract-types-C71Sqq8d.d.ts → contract-types-Dsvy79r3.d.ts} +9 -10
- package/dist/data-dir.cjs +6 -6
- package/dist/data-dir.d.cts +4 -4
- package/dist/data-dir.d.ts +4 -4
- package/dist/data-dir.js +3 -3
- package/dist/env.cjs +20 -20
- package/dist/env.d.cts +12 -5
- package/dist/env.d.ts +12 -5
- package/dist/env.js +1 -1
- package/dist/{error-codes-D5YlWaBx.d.ts → error-codes-DMGeUUUm.d.ts} +12 -12
- package/dist/{error-codes-CiOO3PMg.d.cts → error-codes-pT7RYTqQ.d.cts} +12 -12
- package/dist/index.cjs +42 -42
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -12
- package/dist/journal-io.d.cts +1 -1
- package/dist/journal-io.d.ts +1 -1
- package/dist/journal-replay.d.cts +1 -1
- package/dist/journal-replay.d.ts +1 -1
- package/dist/kill-chain.d.cts +2 -2
- package/dist/kill-chain.d.ts +2 -2
- package/dist/kill-chain.js +2 -2
- package/dist/logs/stderr-rotation.cjs +2 -2
- package/dist/logs/stderr-rotation.d.cts +1 -1
- package/dist/logs/stderr-rotation.d.ts +1 -1
- package/dist/logs/stderr-rotation.js +1 -1
- package/dist/nesting-guard.cjs +2 -2
- package/dist/nesting-guard.d.cts +2 -2
- package/dist/nesting-guard.d.ts +2 -2
- package/dist/nesting-guard.js +1 -1
- package/dist/node-executor.cjs +2 -2
- package/dist/node-executor.d.cts +5 -5
- package/dist/node-executor.d.ts +5 -5
- package/dist/node-executor.js +2 -2
- package/dist/port-contract.d.cts +1 -1
- package/dist/port-contract.d.ts +1 -1
- package/dist/protocol/index.cjs +2 -2
- package/dist/protocol/index.d.cts +5 -5
- package/dist/protocol/index.d.ts +5 -5
- package/dist/protocol/index.js +1 -1
- package/dist/relay-env.cjs +5 -5
- package/dist/relay-env.d.cts +5 -5
- package/dist/relay-env.d.ts +5 -5
- package/dist/relay-env.js +1 -1
- package/dist/spawn.cjs +1 -1
- package/dist/spawn.d.cts +2 -2
- package/dist/spawn.d.ts +2 -2
- package/dist/spawn.js +1 -1
- package/dist/ui-channels.cjs +2 -2
- package/dist/ui-channels.js +1 -1
- package/package.json +2 -4
- package/src/best-effort.ts +0 -37
- package/src/cli-entry.ts +0 -82
- package/src/data-dir.ts +0 -89
- package/src/env.ts +0 -265
- package/src/error-message.ts +0 -22
- package/src/index.ts +0 -63
- package/src/journal-io.ts +0 -82
- package/src/journal-replay.ts +0 -436
- package/src/kill-chain.ts +0 -265
- package/src/logger.ts +0 -105
- package/src/logs/stderr-rotation.ts +0 -166
- package/src/nesting-guard.ts +0 -140
- package/src/node-executor.ts +0 -272
- package/src/paths.ts +0 -48
- package/src/port-contract.ts +0 -150
- package/src/protocol/contract-types.ts +0 -379
- package/src/protocol/engine-protocol.ts +0 -91
- package/src/protocol/error-codes.ts +0 -180
- package/src/protocol/frames.ts +0 -143
- package/src/protocol/index.ts +0 -12
- package/src/protocol/methods.ts +0 -237
- package/src/protocol/reverse-channels.ts +0 -123
- package/src/protocol/schema.ts +0 -185
- package/src/relay-env.ts +0 -60
- package/src/schema-emulation.ts +0 -192
- package/src/spawn.ts +0 -246
- package/src/ui-channels.ts +0 -219
- package/src/ui-types.ts +0 -101
package/dist/node-executor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/** L0 注入的引擎执行器路径 env(与 relay 的
|
|
2
|
-
declare const ENGINE_NODE_ENV = "
|
|
1
|
+
/** L0 注入的引擎执行器路径 env(与 relay 的 TAIJI_SUBAGENT_RELAY_NODE 不复用)。 */
|
|
2
|
+
declare const ENGINE_NODE_ENV = "TAIJI_AGENT_ENGINE_NODE";
|
|
3
3
|
/**
|
|
4
4
|
* 探针:验证执行器能以纯 node 语义执行 JS(先例 = runtime relay-env.ts:47-90)。
|
|
5
5
|
*
|
|
@@ -20,7 +20,7 @@ interface EngineNodeLaunchOptions {
|
|
|
20
20
|
args?: readonly string[];
|
|
21
21
|
/** 宿主形态。 */
|
|
22
22
|
hostKind: EngineNodeHostKind;
|
|
23
|
-
/** 读取
|
|
23
|
+
/** 读取 TAIJI_AGENT_ENGINE_NODE 的 env 快照(矩阵① 的注入通道)。 */
|
|
24
24
|
env?: Record<string, string | undefined>;
|
|
25
25
|
/** 宿主 process.execPath(缺省 process.execPath)。 */
|
|
26
26
|
execPath?: string;
|
|
@@ -42,7 +42,7 @@ interface EngineNodeLaunch {
|
|
|
42
42
|
*
|
|
43
43
|
* 判定序(与规格逐行对应):
|
|
44
44
|
* Windows + entry .cmd → cmd.exe /c 显式形态(禁 shell:true 的注入面);
|
|
45
|
-
* pi-extension → 注入执行器(env
|
|
45
|
+
* pi-extension → 注入执行器(env TAIJI_AGENT_ENGINE_NODE),缺失/探针失败 =
|
|
46
46
|
* engine_not_found + 指引;
|
|
47
47
|
* runtime-sidecar → process.execPath(Electron 时 electronRunAsNode,探针先行);
|
|
48
48
|
* standalone → PATH node(探针失败 = engine_not_found + 安装指引);
|
|
@@ -54,7 +54,7 @@ declare function resolveEngineNodeLaunch(opts: EngineNodeLaunchOptions): Promise
|
|
|
54
54
|
/**
|
|
55
55
|
* EngineClient 的自由字符串 hostKind('pi' / 'runtime' / …)→ 矩阵行归一:
|
|
56
56
|
* 'runtime*' → runtime-sidecar(②:sidecar execPath 权威);
|
|
57
|
-
* env 已注入
|
|
57
|
+
* env 已注入 TAIJI_AGENT_ENGINE_NODE(打包态 runtime 注入主 pi 进程的通道)→
|
|
58
58
|
* pi-extension(①:必须用注入执行器——pi 宿主自身 execPath 是 pi binary);
|
|
59
59
|
* 其余 → standalone(③:PATH node)。
|
|
60
60
|
*/
|
package/dist/node-executor.js
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
probeNodeExecutor,
|
|
5
5
|
resetEngineNodeProbeCache,
|
|
6
6
|
resolveEngineNodeLaunch
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-W3BKI2BP.js";
|
|
8
|
+
import "./chunk-WMDMXP2F.js";
|
|
9
9
|
import "./chunk-JSBRDJBE.js";
|
|
10
10
|
export {
|
|
11
11
|
ENGINE_NODE_ENV,
|
package/dist/port-contract.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AgentCallOpts, h as EngineHandleData, E as EngineCapabilities, P as ProbeReport, a as AgentEvent, i as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-
|
|
1
|
+
import { A as AgentCallOpts, h as EngineHandleData, E as EngineCapabilities, P as ProbeReport, a as AgentEvent, i as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-Dsvy79r3.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 引擎进程内全量任务声明 = SDK AgentCallOpts 引擎面子集 + 协议 ctx 还原字段(model/
|
package/dist/port-contract.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as AgentCallOpts, h as EngineHandleData, E as EngineCapabilities, P as ProbeReport, a as AgentEvent, i as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-
|
|
1
|
+
import { A as AgentCallOpts, h as EngineHandleData, E as EngineCapabilities, P as ProbeReport, a as AgentEvent, i as ResumeAnchor, c as AgentOutcome, S as SessionView } from './contract-types-Dsvy79r3.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 引擎进程内全量任务声明 = SDK AgentCallOpts 引擎面子集 + 协议 ctx 还原字段(model/
|
package/dist/protocol/index.cjs
CHANGED
|
@@ -81,7 +81,7 @@ var CRASH_REBUILD_BACKOFF_MS = [
|
|
|
81
81
|
CRASH_REBUILD_BACKOFF_STEP_3_MS
|
|
82
82
|
];
|
|
83
83
|
var STDERR_TAIL_CHARS = 400;
|
|
84
|
-
var ENGINE_EVENT_COALESCE_ENV = "
|
|
84
|
+
var ENGINE_EVENT_COALESCE_ENV = "TAIJI_ENGINE_EVENT_COALESCE";
|
|
85
85
|
var ENGINE_EVENT_COALESCE_DEFAULT = "0";
|
|
86
86
|
|
|
87
87
|
// src/protocol/frames.ts
|
|
@@ -188,7 +188,7 @@ function engineConversationUnsupportedError(engineId) {
|
|
|
188
188
|
return new EngineSdkError(
|
|
189
189
|
"engine_capability_unsupported",
|
|
190
190
|
`engine '${engineId}' \u4E0D\u652F\u6301 resume \u7EED\u804A\uFF08capabilities.conversation = 'unsupported'\uFF0Cmanifest \u65E0 conversation gate \u4F4D\uFF09`,
|
|
191
|
-
`\
|
|
191
|
+
`\u6539\u7528\u58F0\u660E conversation \u80FD\u529B\u7684\u5F15\u64CE\u7EED\u804A\uFF08\u6216\u4EE5\u65B0\u4EFB\u52A1\u91CD\u6D3E\uFF09\uFF0C\u6216\u4FEE manifest capabilities / \u5347\u7EA7\u5F15\u64CE\u5305\uFF08\u82E5\u5F15\u64CE\u5B9E\u9645\u652F\u6301\u8BE5\u80FD\u529B\uFF09`,
|
|
192
192
|
{ engineId, capability: "conversation", declared: "unsupported" }
|
|
193
193
|
);
|
|
194
194
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from '../error-codes-
|
|
2
|
-
import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-
|
|
3
|
-
export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-
|
|
1
|
+
export { E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from '../error-codes-pT7RYTqQ.cjs';
|
|
2
|
+
import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-Dsvy79r3.cjs';
|
|
3
|
+
export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-Dsvy79r3.cjs';
|
|
4
4
|
import { UiRequest, UiResponse } from '../ui-types.cjs';
|
|
5
5
|
|
|
6
|
-
/** 协议版本(引擎包 manifest `
|
|
6
|
+
/** 协议版本(引擎包 manifest `taiji.subagentEngine.protocol` 与 initialize 应答同值)。 */
|
|
7
7
|
declare const ENGINE_PROTOCOL_VERSION = 1;
|
|
8
8
|
/**
|
|
9
9
|
* core 侧支持的协议版本区间(半开区间 [min, max)):当前 = [1, 2)。
|
|
@@ -27,7 +27,7 @@ declare const CRASH_REBUILD_BACKOFF_MS: readonly [1000, 2000, 4000];
|
|
|
27
27
|
/** stderr 内存环形缓冲保留的尾部字符数(engine_crashed 帧携带崩溃现场)。 */
|
|
28
28
|
declare const STDERR_TAIL_CHARS = 400;
|
|
29
29
|
/** 事件合并开关 env 名(设计级默认关闭 = 值 "0";A1 要求事件逐字段等价,合并不可开)。 */
|
|
30
|
-
declare const ENGINE_EVENT_COALESCE_ENV = "
|
|
30
|
+
declare const ENGINE_EVENT_COALESCE_ENV = "TAIJI_ENGINE_EVENT_COALESCE";
|
|
31
31
|
declare const ENGINE_EVENT_COALESCE_DEFAULT = "0";
|
|
32
32
|
/**
|
|
33
33
|
* 反向请求超时二分(帧④注释,R9-2):
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from '../error-codes-
|
|
2
|
-
import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-
|
|
3
|
-
export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-
|
|
1
|
+
export { E as ENGINE_ERROR_CODE_PREFIX, a as ENGINE_PROTOCOL_ERROR_CODES, b as ENGINE_TIMEOUT_RECOVERY, c as EngineProtocolErrorCode, d as EngineSdkError, e as ErrorResponseFrame, f as EventNotificationParams, N as NotificationFrame, P as ProtocolError, R as RequestFrame, g as ResponseFrame, h as ReverseRequestFrame, i as ReverseResponseResult, S as STDOUT_TAIL_ECHO_CHARS, j as SuccessResponseFrame, k as assertChatConversationSupported, l as engineConversationUnsupportedError, m as engineProtocolMismatchError, n as engineTimeoutDetail, o as isEngineErrorPassthroughCode, p as isEngineProtocolErrorCode, q as isNotificationFrame, r as isRequestFrame, s as isResponseFrame, t as isReverseRequestFrame, u as schemaEmulationFailedDetail } from '../error-codes-DMGeUUUm.js';
|
|
2
|
+
import { E as EngineCapabilities, M as ModelCatalogEntry, A as AgentCallOpts, i as ResumeAnchor, h as EngineHandleData, P as ProbeReport, c as AgentOutcome, S as SessionView } from '../contract-types-Dsvy79r3.js';
|
|
3
|
+
export { a as AgentEvent, b as AgentFailureKind, d as AgentOutcomeUsage, e as AgentUsage, f as AgentUsageTotal, g as AssertMutuallyAssignable, I as InternalToolCall, R as ReplayedTurn, T as ToolCall, j as ToolCallEntry, k as ToolCallResult, l as Turn, W as WorktreeHandle } from '../contract-types-Dsvy79r3.js';
|
|
4
4
|
import { UiRequest, UiResponse } from '../ui-types.js';
|
|
5
5
|
|
|
6
|
-
/** 协议版本(引擎包 manifest `
|
|
6
|
+
/** 协议版本(引擎包 manifest `taiji.subagentEngine.protocol` 与 initialize 应答同值)。 */
|
|
7
7
|
declare const ENGINE_PROTOCOL_VERSION = 1;
|
|
8
8
|
/**
|
|
9
9
|
* core 侧支持的协议版本区间(半开区间 [min, max)):当前 = [1, 2)。
|
|
@@ -27,7 +27,7 @@ declare const CRASH_REBUILD_BACKOFF_MS: readonly [1000, 2000, 4000];
|
|
|
27
27
|
/** stderr 内存环形缓冲保留的尾部字符数(engine_crashed 帧携带崩溃现场)。 */
|
|
28
28
|
declare const STDERR_TAIL_CHARS = 400;
|
|
29
29
|
/** 事件合并开关 env 名(设计级默认关闭 = 值 "0";A1 要求事件逐字段等价,合并不可开)。 */
|
|
30
|
-
declare const ENGINE_EVENT_COALESCE_ENV = "
|
|
30
|
+
declare const ENGINE_EVENT_COALESCE_ENV = "TAIJI_ENGINE_EVENT_COALESCE";
|
|
31
31
|
declare const ENGINE_EVENT_COALESCE_DEFAULT = "0";
|
|
32
32
|
/**
|
|
33
33
|
* 反向请求超时二分(帧④注释,R9-2):
|
package/dist/protocol/index.js
CHANGED
package/dist/relay-env.cjs
CHANGED
|
@@ -31,11 +31,11 @@ __export(relay_env_exports, {
|
|
|
31
31
|
readRelayForwardEnv: () => readRelayForwardEnv
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(relay_env_exports);
|
|
34
|
-
var RELAY_ENV_SOCKET = "
|
|
35
|
-
var RELAY_ENV_NODE = "
|
|
36
|
-
var RELAY_ENV_SCRIPT = "
|
|
37
|
-
var RELAY_ENV_SESSION_ID = "
|
|
38
|
-
var RELAY_ENV_RECORD_ID = "
|
|
34
|
+
var RELAY_ENV_SOCKET = "TAIJI_SUBAGENT_RELAY_SOCKET";
|
|
35
|
+
var RELAY_ENV_NODE = "TAIJI_SUBAGENT_RELAY_NODE";
|
|
36
|
+
var RELAY_ENV_SCRIPT = "TAIJI_SUBAGENT_RELAY_SCRIPT";
|
|
37
|
+
var RELAY_ENV_SESSION_ID = "TAIJI_SUBAGENT_RELAY_SESSION_ID";
|
|
38
|
+
var RELAY_ENV_RECORD_ID = "TAIJI_SUBAGENT_RELAY_RECORD_ID";
|
|
39
39
|
var RELAY_PROTOCOL_VERSION = 1;
|
|
40
40
|
var RELAY_EXIT_CODES = {
|
|
41
41
|
/** 握手被拒:协议版本不匹配(安装损坏,重装应用)。 */
|
package/dist/relay-env.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare const RELAY_ENV_SOCKET = "
|
|
2
|
-
declare const RELAY_ENV_NODE = "
|
|
3
|
-
declare const RELAY_ENV_SCRIPT = "
|
|
4
|
-
declare const RELAY_ENV_SESSION_ID = "
|
|
5
|
-
declare const RELAY_ENV_RECORD_ID = "
|
|
1
|
+
declare const RELAY_ENV_SOCKET = "TAIJI_SUBAGENT_RELAY_SOCKET";
|
|
2
|
+
declare const RELAY_ENV_NODE = "TAIJI_SUBAGENT_RELAY_NODE";
|
|
3
|
+
declare const RELAY_ENV_SCRIPT = "TAIJI_SUBAGENT_RELAY_SCRIPT";
|
|
4
|
+
declare const RELAY_ENV_SESSION_ID = "TAIJI_SUBAGENT_RELAY_SESSION_ID";
|
|
5
|
+
declare const RELAY_ENV_RECORD_ID = "TAIJI_SUBAGENT_RELAY_RECORD_ID";
|
|
6
6
|
/** relay 协议版本(握手帧 v 字段;runtime 与代理同包分发,不匹配=安装损坏)。 */
|
|
7
7
|
declare const RELAY_PROTOCOL_VERSION = 1;
|
|
8
8
|
/** 代理专用退出码(extension/引擎侧表现为「子进程非零退出」→ engine_run_failed 语义)。 */
|
package/dist/relay-env.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare const RELAY_ENV_SOCKET = "
|
|
2
|
-
declare const RELAY_ENV_NODE = "
|
|
3
|
-
declare const RELAY_ENV_SCRIPT = "
|
|
4
|
-
declare const RELAY_ENV_SESSION_ID = "
|
|
5
|
-
declare const RELAY_ENV_RECORD_ID = "
|
|
1
|
+
declare const RELAY_ENV_SOCKET = "TAIJI_SUBAGENT_RELAY_SOCKET";
|
|
2
|
+
declare const RELAY_ENV_NODE = "TAIJI_SUBAGENT_RELAY_NODE";
|
|
3
|
+
declare const RELAY_ENV_SCRIPT = "TAIJI_SUBAGENT_RELAY_SCRIPT";
|
|
4
|
+
declare const RELAY_ENV_SESSION_ID = "TAIJI_SUBAGENT_RELAY_SESSION_ID";
|
|
5
|
+
declare const RELAY_ENV_RECORD_ID = "TAIJI_SUBAGENT_RELAY_RECORD_ID";
|
|
6
6
|
/** relay 协议版本(握手帧 v 字段;runtime 与代理同包分发,不匹配=安装损坏)。 */
|
|
7
7
|
declare const RELAY_PROTOCOL_VERSION = 1;
|
|
8
8
|
/** 代理专用退出码(extension/引擎侧表现为「子进程非零退出」→ engine_run_failed 语义)。 */
|
package/dist/relay-env.js
CHANGED
package/dist/spawn.cjs
CHANGED
|
@@ -106,7 +106,7 @@ function spawnEngineChild(opts) {
|
|
|
106
106
|
return child;
|
|
107
107
|
}
|
|
108
108
|
var DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS = 3e4;
|
|
109
|
-
var ENGINE_HOST_REQUEST_TIMEOUT_ENV = "
|
|
109
|
+
var ENGINE_HOST_REQUEST_TIMEOUT_ENV = "TAIJI_ENGINE_HOST_REQUEST_TIMEOUT_MS";
|
|
110
110
|
var SWEEP_INTERVAL_MS = 1e3;
|
|
111
111
|
function resolveHostRequestTimeoutMs(opts) {
|
|
112
112
|
if (opts.hostRequestTimeoutMs !== void 0) return opts.hostRequestTimeoutMs;
|
package/dist/spawn.d.cts
CHANGED
|
@@ -27,7 +27,7 @@ declare function spawnEngineChild(opts: SpawnEngineChildOptions): ChildProcess;
|
|
|
27
27
|
/** in-flight 未 ack 反向请求的计时超时缺省值(辅助判据,30s)。 */
|
|
28
28
|
declare const DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS = 30000;
|
|
29
29
|
/** 计时超时覆盖 env 名(引擎 CLI 启动时读;非法值 warn + 回落缺省)。 */
|
|
30
|
-
declare const ENGINE_HOST_REQUEST_TIMEOUT_ENV = "
|
|
30
|
+
declare const ENGINE_HOST_REQUEST_TIMEOUT_ENV = "TAIJI_ENGINE_HOST_REQUEST_TIMEOUT_MS";
|
|
31
31
|
/** 反向请求计时面操作接口(消费方 = 引擎 CLI 的反向通道分发层)。 */
|
|
32
32
|
interface ReverseRequestClock {
|
|
33
33
|
/** 反向请求已发出(未 ack)——进入计时面。 */
|
|
@@ -46,7 +46,7 @@ interface ReverseRequestClock {
|
|
|
46
46
|
interface EngineSelfDestructOptions {
|
|
47
47
|
/** 主判据数据源:宿主→引擎的协议 stdin(EOF = 宿主死亡 → 立即自灭)。 */
|
|
48
48
|
stdin: NodeJS.ReadableStream;
|
|
49
|
-
/** 辅助判据超时(缺省 30s;显式传值优先于 env
|
|
49
|
+
/** 辅助判据超时(缺省 30s;显式传值优先于 env TAIJI_ENGINE_HOST_REQUEST_TIMEOUT_MS)。 */
|
|
50
50
|
hostRequestTimeoutMs?: number;
|
|
51
51
|
/** 计时超时的 env 覆盖源(缺省读 process.env;测试注入用)。 */
|
|
52
52
|
timeoutEnv?: Record<string, string | undefined>;
|
package/dist/spawn.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ declare function spawnEngineChild(opts: SpawnEngineChildOptions): ChildProcess;
|
|
|
27
27
|
/** in-flight 未 ack 反向请求的计时超时缺省值(辅助判据,30s)。 */
|
|
28
28
|
declare const DEFAULT_ENGINE_HOST_REQUEST_TIMEOUT_MS = 30000;
|
|
29
29
|
/** 计时超时覆盖 env 名(引擎 CLI 启动时读;非法值 warn + 回落缺省)。 */
|
|
30
|
-
declare const ENGINE_HOST_REQUEST_TIMEOUT_ENV = "
|
|
30
|
+
declare const ENGINE_HOST_REQUEST_TIMEOUT_ENV = "TAIJI_ENGINE_HOST_REQUEST_TIMEOUT_MS";
|
|
31
31
|
/** 反向请求计时面操作接口(消费方 = 引擎 CLI 的反向通道分发层)。 */
|
|
32
32
|
interface ReverseRequestClock {
|
|
33
33
|
/** 反向请求已发出(未 ack)——进入计时面。 */
|
|
@@ -46,7 +46,7 @@ interface ReverseRequestClock {
|
|
|
46
46
|
interface EngineSelfDestructOptions {
|
|
47
47
|
/** 主判据数据源:宿主→引擎的协议 stdin(EOF = 宿主死亡 → 立即自灭)。 */
|
|
48
48
|
stdin: NodeJS.ReadableStream;
|
|
49
|
-
/** 辅助判据超时(缺省 30s;显式传值优先于 env
|
|
49
|
+
/** 辅助判据超时(缺省 30s;显式传值优先于 env TAIJI_ENGINE_HOST_REQUEST_TIMEOUT_MS)。 */
|
|
50
50
|
hostRequestTimeoutMs?: number;
|
|
51
51
|
/** 计时超时的 env 覆盖源(缺省读 process.env;测试注入用)。 */
|
|
52
52
|
timeoutEnv?: Record<string, string | undefined>;
|
package/dist/spawn.js
CHANGED
package/dist/ui-channels.cjs
CHANGED
|
@@ -27,8 +27,8 @@ module.exports = __toCommonJS(ui_channels_exports);
|
|
|
27
27
|
var NUL = "\0";
|
|
28
28
|
function normalizeChannelName(markerLiteral) {
|
|
29
29
|
let name = markerLiteral;
|
|
30
|
-
if (name.startsWith("
|
|
31
|
-
name = name.slice("
|
|
30
|
+
if (name.startsWith("TAIJI_")) {
|
|
31
|
+
name = name.slice("TAIJI_".length);
|
|
32
32
|
}
|
|
33
33
|
if (name.endsWith(":")) {
|
|
34
34
|
name = name.slice(0, -1);
|
package/dist/ui-channels.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/subagent-engine-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Engine-side SDK for the subagent engine protocol: NDJSON stdio contract types, engine primitives (schema emulation, nesting guard, kill chain, journal replay projection, data-dir/paths resolution) — the shared contract root between subagent-core and engine CLI packages (engines import SDK only, never core)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,10 +34,8 @@
|
|
|
34
34
|
"default": "./dist/protocol/index.js"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"$comment": "W1 骨架(docs/design/subagent-engine-protocolization.impl-plan.md §2.1)。双形态同 subagent-core 先例(D4):workspace 消费走 import 条件 -> src;npm 消费走 publishConfig -> dist。exports 面先收窄到 ./ 与 ./protocol(exports = semver 契约,收窄不放宽;引擎包 W5/W7 消费经主 barrel)。协议版本独立于包版本:ENGINE_PROTOCOL_VERSION = 1(src/protocol/engine-protocol.ts)。不变量:本包禁止 import @zhushanwen/subagent-core(守卫 .githooks/check-engine-sdk-boundary.mjs)。src/env.ts 与 src/spawn.ts 是 W12 领地(impl-plan §2.12),本单元仅空骨架占位。tsup entry 逐模块具名登记(§2.1 末行),新增模块必须同步登记。",
|
|
37
|
+
"$comment": "W1 骨架(docs/design/subagent-engine-protocolization.impl-plan.md §2.1)。双形态同 subagent-core 先例(D4):workspace 消费走 import 条件 -> src;npm 消费走 publishConfig -> dist。exports 面先收窄到 ./ 与 ./protocol(exports = semver 契约,收窄不放宽;引擎包 W5/W7 消费经主 barrel)。协议版本独立于包版本:ENGINE_PROTOCOL_VERSION = 1(src/protocol/engine-protocol.ts)。不变量:本包禁止 import @zhushanwen/subagent-core(守卫 .githooks/check-engine-sdk-boundary.mjs)。src/env.ts 与 src/spawn.ts 是 W12 领地(impl-plan §2.12),本单元仅空骨架占位。tsup entry 逐模块具名登记(§2.1 末行),新增模块必须同步登记。files 不含 src/(对齐 subagent-core 2026-09-16 同型收敛):npm 消费面经 publishConfig 整体替换后全指 dist,TS 源仅服务 workspace(node_modules symlink 直读磁盘源文件,不经 tarball);dist 产物无 sourcemap/sourceMappingURL,移除 src 零断链。已知残留:顶层 main(src/index.ts,workspace 形态载体)被 npm files 规则强制隐含打进 tarball,对 npm 消费者不可达,纯体积噪声。",
|
|
38
38
|
"files": [
|
|
39
|
-
"src/",
|
|
40
|
-
"!src/__tests__",
|
|
41
39
|
"dist/"
|
|
42
40
|
],
|
|
43
41
|
"dependencies": {
|
package/src/best-effort.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// src/best-effort.ts
|
|
2
|
-
//
|
|
3
|
-
// best-effort IO 清理的错误吞咽 helper 单源(round1-reuse R11 微副本收编,实现体
|
|
4
|
-
// 自 core src/execution/best-effort.ts 迁移;pi 引擎包 best-effort.ts 副本自本模块
|
|
5
|
-
// re-export 收编。core 版保留自持:其 logger 经 configureCore HostServices 通道解析,
|
|
6
|
-
// 与 SDK LoggerSink 通道是真差异,非可消副本)。
|
|
7
|
-
//
|
|
8
|
-
// 用途:sidecar 写入 / worktree remove / alive marker 删除等次要 IO,失败不影响
|
|
9
|
-
// 主流程(session 已完成或正在收尾)。这类 catch 故意吞错——但 taste/no-silent-catch
|
|
10
|
-
// 规则禁止空 catch 或仅 console 的 catch。本 helper 提供一条「实质调用语句」让
|
|
11
|
-
// catch 合规,同时把错误记录到 debug/error 便于排查(经共享 logger 路由,不裸 console)。
|
|
12
|
-
|
|
13
|
-
import { getLogger } from "./logger.ts";
|
|
14
|
-
|
|
15
|
-
const logger = getLogger("subagents");
|
|
16
|
-
|
|
17
|
-
/** 错误日志级别。debug = 次要清理(默认);error = 关键步骤但需继续后续清理。 */
|
|
18
|
-
export type BestEffortLevel = "debug" | "error";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 吞咽 best-effort IO 的错误,按 level 经共享 logger 记录。
|
|
22
|
-
*
|
|
23
|
-
* - debug(默认):次要清理(sidecar/worktree/alive marker),失败属预期路径
|
|
24
|
-
* - error:关键步骤抛错但需继续后续清理(如 finalizeRecord 的 B9 链:completeRecord
|
|
25
|
-
* 抛错后仍要执行 finalized/cleanup,错误需可见但不阻断)
|
|
26
|
-
*
|
|
27
|
-
* 错误对象优先取 message(避免打印巨大堆栈/对象),其他类型原样传入。
|
|
28
|
-
*/
|
|
29
|
-
export function bestEffort(err: unknown, context: string, level: BestEffortLevel = "debug"): void {
|
|
30
|
-
const detail = err instanceof Error ? err.message : err;
|
|
31
|
-
const msg = `[subagents] best-effort ${context} failed`;
|
|
32
|
-
if (level === "error") {
|
|
33
|
-
logger.error(msg, { detail });
|
|
34
|
-
} else {
|
|
35
|
-
logger.debug(msg, { detail });
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/cli-entry.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// src/cli-entry.ts
|
|
2
|
-
//
|
|
3
|
-
// 引擎 CLI 进程入口样板单源(S4 簇 2 收编:pi/zcode 两包 main.ts 的逐字同构段
|
|
4
|
-
// 迁移——差异仅 component 字符串与各包自己的 EngineProtocolServer;实现以 pi
|
|
5
|
-
// main.ts 为基线逐字迁移,坏行截断长度 200、日志格式、启动序逐字节保持)。
|
|
6
|
-
//
|
|
7
|
-
// 职界分割:armEngineSelfDestruct 与 EngineProtocolServer 构造留调用方薄层——
|
|
8
|
-
// server 构造需要 arm 产出的 ReverseRequestClock,实例传入后无法回补。本入口承接
|
|
9
|
-
// 其余启动序:configureLoggerSink(stderr 兜底 + host/log 反向请求)→ readline
|
|
10
|
-
// NDJSON 行循环 → close 留痕。
|
|
11
|
-
//
|
|
12
|
-
// stdout/stdin 用 process 全局(与 spawn.ts 同款先例——入口函数只在进程入口调用)。
|
|
13
|
-
// 进程退出面:宿主 stdin EOF → 自灭守卫(薄层 arm)杀进程组;正常 dispose 不退进程。
|
|
14
|
-
|
|
15
|
-
import * as readline from "node:readline";
|
|
16
|
-
|
|
17
|
-
import { configureLoggerSink, getLogger } from "./logger.ts";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 引擎协议服务器的结构化最小接口(调用方薄层注入本包 EngineProtocolServer 实例;
|
|
21
|
-
* 结构子集避免 SDK 反向依赖各包 server 类型)。
|
|
22
|
-
*/
|
|
23
|
-
export interface CliProtocolServerSink {
|
|
24
|
-
/** 入站协议帧处理(readline 已拆行 + JSON.parse 后的帧)。 */
|
|
25
|
-
handleFrame(frame: unknown): void;
|
|
26
|
-
/** 数据面反向请求(host/log 等;应答分类由各包 server 实现承载)。 */
|
|
27
|
-
reverseRequest(method: string, params: unknown): Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** runEngineCliEntry 参数。 */
|
|
31
|
-
export interface RunEngineCliEntryOptions {
|
|
32
|
-
/** logger component 标签(如 "pi-engine-cli" / "zcode-engine-cli")。 */
|
|
33
|
-
component: string;
|
|
34
|
-
/** 调用方构造的协议服务器实例(构造参数含 armEngineSelfDestruct 产出的 reverseClock)。 */
|
|
35
|
-
server: CliProtocolServerSink;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** 坏行进日志的截断长度(够诊断、不刷屏)。 */
|
|
39
|
-
const INBOUND_LOG_CHARS = 200;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 引擎 CLI 进程入口样板(行为与收编前两包 main.ts 逐字节等价):
|
|
43
|
-
* configureLoggerSink → stdin 行解析(NDJSON)→ server.handleFrame → close 留痕。
|
|
44
|
-
*/
|
|
45
|
-
export function runEngineCliEntry(opts: RunEngineCliEntryOptions): void {
|
|
46
|
-
const logger = getLogger(opts.component);
|
|
47
|
-
const server = opts.server;
|
|
48
|
-
|
|
49
|
-
// stdout 是协议独占通道:应用日志一律走 host/log 反向请求 + stderr 兜底,禁写 stdout。
|
|
50
|
-
configureLoggerSink({
|
|
51
|
-
log(level, component, message, data) {
|
|
52
|
-
// stderr 兜底先落(反向通道未就绪/失败时日志不丢);host/log 为数据面反向请求
|
|
53
|
-
// (10s 应答分类),失败吞掉——日志面不能拖垮主链路。
|
|
54
|
-
// debug 不写 stderr:对齐 logger.ts CONSOLE_SINK 的「debug no-op」语义——
|
|
55
|
-
// 引擎 stderr 落宿主 [rpc:stderr] 全量 ERROR 级链路,debug 刷屏会淹没真异常
|
|
56
|
-
// (常态路径的分级降噪依赖此跳过);host/log 反向请求仍全级别透传。
|
|
57
|
-
if (level !== "debug") {
|
|
58
|
-
process.stderr.write(`[${level}] [${component}] ${message}${data !== undefined ? ` ${JSON.stringify(data)}` : ""}\n`);
|
|
59
|
-
}
|
|
60
|
-
void server.reverseRequest("host/log", { level, component, message }).catch(() => undefined);
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
65
|
-
rl.on("line", (line) => {
|
|
66
|
-
const text = line.trim();
|
|
67
|
-
if (text === "") return;
|
|
68
|
-
try {
|
|
69
|
-
server.handleFrame(JSON.parse(text));
|
|
70
|
-
} catch (err) {
|
|
71
|
-
// 坏行跳过不断流(对端 EngineClient 同款纪律);stdout 协议通道不回显坏行。
|
|
72
|
-
logger.warn(`unparseable inbound protocol line (ignored): ${text.slice(0, INBOUND_LOG_CHARS)}`, {
|
|
73
|
-
reason: err instanceof Error ? err.message : String(err),
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
rl.on("close", () => {
|
|
78
|
-
// stdin EOF:自灭守卫已挂(armEngineSelfDestruct 的 once('close') 杀进程组);
|
|
79
|
-
// 此处仅留痕(守卫先注册,杀链不依赖本 handler)。
|
|
80
|
-
logger.debug("stdin closed (host exit path)");
|
|
81
|
-
});
|
|
82
|
-
}
|
package/src/data-dir.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// src/data-dir.ts
|
|
2
|
-
//
|
|
3
|
-
// 引擎数据目录解析(引擎侧原语,自 core execution/engine/common/data-dir.ts 迁入
|
|
4
|
-
// @zhushanwen/subagent-engine-sdk)。迁移处置(impl-plan §2.1 data-dir 行):**拆
|
|
5
|
-
// seam**——今天 core 版缺 env 时回退 getHostServices().dataRoot()(引擎进程无
|
|
6
|
-
// configureCore 通道,不可复制);SDK 版 = **参数化/env 优先**,core 侧保留
|
|
7
|
-
// getHostServices() 绑定(core 文件不动,引用切换归 W2+)。
|
|
8
|
-
//
|
|
9
|
-
// SDK 版缺省语义(impl-plan §2.9 数据根注入矩阵,写死):env 优先;缺 env 且调用方
|
|
10
|
-
// 未显式注入 fallback → **显式报错**(错误信息可操作:env 名 + 期望注入动作),不留
|
|
11
|
-
// 静默漂目录。带 fallback 注入(pi 扩展宿主 = core 侧解析后显式传入)时保留
|
|
12
|
-
// warn-once 语义(回退非权威通道必须可观测),与 core 版行为逐字对齐。
|
|
13
|
-
//
|
|
14
|
-
// 通道调查结论(2026-08-25,P2 实测证据链,自 core 版头部保留):
|
|
15
|
-
// - runtime spawn pi 主会话时 RpcClient 出站 env 从 runtime process.env 继承
|
|
16
|
-
// XYZ_ 前缀白名单变量(调查当时经私有 buildSafeEnv,现已被 buildPiOutboundEnv
|
|
17
|
-
// → buildOutboundChildEnv 共享构建器取代),且显式设置 PI_CODING_AGENT_DIR;
|
|
18
|
-
// - dev 模式 Electron main 设置 XYZ_AGENT_DATA_DIR(apps/electron/main/main.ts:122),
|
|
19
|
-
// 经 process-control.ts:262 透传给 runtime → 透传链成立;
|
|
20
|
-
// - prod 默认路径(~/.xyz-agent 缺省)下 runtime 进程 env 中**没有**该变量
|
|
21
|
-
// → runtime 侧 process-manager.ts spawn env 补注入 XYZ_AGENT_DATA_DIR 修复。
|
|
22
|
-
|
|
23
|
-
import { getLogger } from "./logger.ts";
|
|
24
|
-
|
|
25
|
-
const logger = getLogger("subagents");
|
|
26
|
-
|
|
27
|
-
/** xyz-agent 数据目录 env 名(与 packages/shared/src/paths.ts 的 SSOT 变量同名)。 */
|
|
28
|
-
export const XYZ_DATA_DIR_ENV = "XYZ_AGENT_DATA_DIR";
|
|
29
|
-
|
|
30
|
-
// warn-once 配置态:globalThis[Symbol.for] slot(core host-services 同款范式)——
|
|
31
|
-
// CJS 多 entry 内联副本下模块级 `let` 会分裂成多份(每份各 warn 一次),slot 跨副本一致。
|
|
32
|
-
const WARNED_SLOT_KEY = Symbol.for("@zhushanwen/subagent-engine-sdk.data-dir-warned");
|
|
33
|
-
|
|
34
|
-
function getWarnedSlot(): { current: boolean } {
|
|
35
|
-
let slot = Reflect.get(globalThis, WARNED_SLOT_KEY) as { current: boolean } | undefined;
|
|
36
|
-
if (!slot) {
|
|
37
|
-
slot = { current: false };
|
|
38
|
-
Reflect.set(globalThis, WARNED_SLOT_KEY, slot);
|
|
39
|
-
}
|
|
40
|
-
return slot;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** 测试隔离专用:重置 warn-once 标记(生产禁用)。 */
|
|
44
|
-
export function resetDataDirWarnForTests(): void {
|
|
45
|
-
getWarnedSlot().current = false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 解析引擎数据目录(journal 落盘 / 隔离池的根):
|
|
50
|
-
* 1. env[XYZ_AGENT_DATA_DIR](宿主注入,权威通道);
|
|
51
|
-
* 2. 缺失 + opts.fallbackDataRoot 显式传入(宿主解析过的数据根)→ 用之 + warn 一次
|
|
52
|
-
* (非权威通道回退必须可观测——journal 落点变化不留静默漂移);
|
|
53
|
-
* 3. 两者皆缺 → 抛错(engine_not_found 语义:错误含 env 名、期望值示例与恢复动作;
|
|
54
|
-
* impl-plan §2.9「缺 env 且无注入 → 显式报错(附期望路径)」)。
|
|
55
|
-
*
|
|
56
|
-
* 每次调用重新解析(env 读取是零成本操作,不缓存路径防测试/宿主切换时读到旧值)。
|
|
57
|
-
*/
|
|
58
|
-
export function resolveEngineDataDir(
|
|
59
|
-
env: NodeJS.ProcessEnv,
|
|
60
|
-
opts: { fallbackDataRoot?: string; warn?: (msg: string) => void } = {},
|
|
61
|
-
): string {
|
|
62
|
-
const fromEnv = env[XYZ_DATA_DIR_ENV]?.trim();
|
|
63
|
-
if (fromEnv !== undefined && fromEnv !== "") return fromEnv;
|
|
64
|
-
|
|
65
|
-
const fallback = opts.fallbackDataRoot?.trim();
|
|
66
|
-
if (fallback === undefined || fallback === "") {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`[subagent-engine-sdk] engine_not_found: ${XYZ_DATA_DIR_ENV} is not set and no fallback data root was injected. ` +
|
|
69
|
-
`Recovery: the host must inject ${XYZ_DATA_DIR_ENV} into the engine process env ` +
|
|
70
|
-
`(xyz-agent runtime / pi extension host do this at spawn), or pass ` +
|
|
71
|
-
`{ fallbackDataRoot } when calling resolveEngineDataDir from a host that resolves the data root itself.`,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (!getWarnedSlot().current) {
|
|
76
|
-
getWarnedSlot().current = true;
|
|
77
|
-
const warn = opts.warn ?? defaultWarn;
|
|
78
|
-
warn(
|
|
79
|
-
`[engine-data-dir] ${XYZ_DATA_DIR_ENV} is not set; engine journal/pool fall back to the injected data root ` +
|
|
80
|
-
`(${fallback}). The xyz-agent host normally injects this env — if you are running inside xyz-agent, ` +
|
|
81
|
-
`check the runtime spawn env; standalone installs intentionally use the injected root.`,
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return fallback;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function defaultWarn(msg: string): void {
|
|
88
|
-
logger.warn(msg);
|
|
89
|
-
}
|