@ai-workbench/remote-agent 0.9.0-toolbridge.3 → 0.9.0-toolbridge.7
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/README.md +11 -2
- package/dist/acp.d.ts +4 -0
- package/dist/acp.js +42 -6
- package/dist/agents.d.ts +2 -0
- package/dist/agents.js +4 -3
- package/dist/claude-local.d.ts +1 -0
- package/dist/claude-local.js +2 -2
- package/dist/client.js +1 -1
- package/dist/cloud-failure.d.ts +11 -0
- package/dist/cloud-failure.js +54 -0
- package/dist/employee-mcp.d.ts +8 -24
- package/dist/employee-mcp.js +24 -188
- package/dist/employee-tools.d.ts +5 -22
- package/dist/employee-tools.js +4 -292
- package/dist/index.d.ts +4 -0
- package/dist/index.js +31 -15
- package/dist/model-catalog.d.ts +1 -1
- package/dist/model-catalog.js +4 -0
- package/dist/presentation.js +1 -0
- package/dist/provider.js +4 -2
- package/dist/toolbridge-loop.js +3 -0
- package/dist/toolbridge-table.js +4 -1
- package/dist/toolbridge.d.ts +1 -0
- package/dist/toolbridge.js +1 -0
- package/package.json +10 -6
- package/helpers/ripgrep/LICENSE-vscode +0 -13
- package/helpers/ripgrep/PROVENANCE.md +0 -9
- package/helpers/ripgrep/darwin-arm64/rg +0 -0
- package/helpers/ripgrep/darwin-x64/rg +0 -0
- package/helpers/ripgrep/manifest.json +0 -56
- package/helpers/ripgrep/notices/COPYING-ripgrep +0 -3
- package/helpers/ripgrep/notices/DEPENDENCIES.json +0 -946
- package/helpers/ripgrep/notices/LICENCE-PCRE2.md +0 -103
- package/helpers/ripgrep/notices/LICENSE-MIT-ripgrep +0 -21
- package/helpers/ripgrep/notices/UNLICENSE-ripgrep +0 -24
- package/helpers/ripgrep/notices/aho-corasick-1.1.3/COPYING +0 -3
- package/helpers/ripgrep/notices/aho-corasick-1.1.3/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/aho-corasick-1.1.3/UNLICENSE +0 -24
- package/helpers/ripgrep/notices/anyhow-1.0.100/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/anyhow-1.0.100/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/arbitrary-1.4.2/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/arbitrary-1.4.2/LICENSE-MIT +0 -27
- package/helpers/ripgrep/notices/bstr-1.12.0/COPYING +0 -8
- package/helpers/ripgrep/notices/bstr-1.12.0/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/bstr-1.12.0/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/cc-1.2.41/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/cc-1.2.41/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/cfg-if-1.0.4/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/cfg-if-1.0.4/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/crossbeam-channel-0.5.15/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/crossbeam-channel-0.5.15/LICENSE-MIT +0 -27
- package/helpers/ripgrep/notices/crossbeam-channel-0.5.15/LICENSE-THIRD-PARTY +0 -593
- package/helpers/ripgrep/notices/crossbeam-deque-0.8.6/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/crossbeam-deque-0.8.6/LICENSE-MIT +0 -27
- package/helpers/ripgrep/notices/crossbeam-epoch-0.9.18/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/crossbeam-epoch-0.9.18/LICENSE-MIT +0 -27
- package/helpers/ripgrep/notices/crossbeam-utils-0.8.21/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/crossbeam-utils-0.8.21/LICENSE-MIT +0 -27
- package/helpers/ripgrep/notices/derive_arbitrary-1.4.2/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/derive_arbitrary-1.4.2/LICENSE-MIT +0 -27
- package/helpers/ripgrep/notices/encoding_rs-0.8.35/COPYRIGHT +0 -17
- package/helpers/ripgrep/notices/encoding_rs-0.8.35/LICENSE-APACHE +0 -202
- package/helpers/ripgrep/notices/encoding_rs-0.8.35/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/encoding_rs-0.8.35/LICENSE-WHATWG +0 -26
- package/helpers/ripgrep/notices/encoding_rs_io-0.1.7/COPYING +0 -8
- package/helpers/ripgrep/notices/encoding_rs_io-0.1.7/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/encoding_rs_io-0.1.7/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/find-msvc-tools-0.1.4/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/find-msvc-tools-0.1.4/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/getrandom-0.3.4/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/getrandom-0.3.4/LICENSE-MIT +0 -26
- package/helpers/ripgrep/notices/glob-0.3.3/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/glob-0.3.3/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/itoa-1.0.15/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/itoa-1.0.15/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/jobserver-0.1.34/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/jobserver-0.1.34/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/lexopt-0.3.1/LICENSE +0 -19
- package/helpers/ripgrep/notices/libc-0.2.177/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/libc-0.2.177/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/log-0.4.28/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/log-0.4.28/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/memchr-2.7.6/COPYING +0 -3
- package/helpers/ripgrep/notices/memchr-2.7.6/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/memchr-2.7.6/UNLICENSE +0 -24
- package/helpers/ripgrep/notices/memmap2-0.9.8/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/memmap2-0.9.8/LICENSE-MIT +0 -26
- package/helpers/ripgrep/notices/msvc_spectre_libs-0.1.3/LICENSE +0 -21
- package/helpers/ripgrep/notices/pcre2-0.2.11/COPYING +0 -3
- package/helpers/ripgrep/notices/pcre2-0.2.11/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/pcre2-0.2.11/UNLICENSE +0 -24
- package/helpers/ripgrep/notices/pcre2-sys-0.2.10/COPYING +0 -3
- package/helpers/ripgrep/notices/pcre2-sys-0.2.10/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/pcre2-sys-0.2.10/UNLICENSE +0 -24
- package/helpers/ripgrep/notices/pkg-config-0.3.32/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/pkg-config-0.3.32/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/proc-macro2-1.0.101/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/proc-macro2-1.0.101/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/quote-1.0.41/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/quote-1.0.41/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/r-efi-5.3.0/AUTHORS +0 -74
- package/helpers/ripgrep/notices/regex-1.12.2/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/regex-1.12.2/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/regex-automata-0.4.13/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/regex-automata-0.4.13/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/regex-syntax-0.8.8/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/regex-syntax-0.8.8/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/regex-syntax-0.8.8/src/unicode_tables/LICENSE-UNICODE +0 -57
- package/helpers/ripgrep/notices/ryu-1.0.20/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/ryu-1.0.20/LICENSE-BOOST +0 -23
- package/helpers/ripgrep/notices/same-file-1.0.6/COPYING +0 -3
- package/helpers/ripgrep/notices/same-file-1.0.6/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/same-file-1.0.6/UNLICENSE +0 -24
- package/helpers/ripgrep/notices/serde-1.0.228/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/serde-1.0.228/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/serde_core-1.0.228/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/serde_core-1.0.228/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/serde_derive-1.0.228/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/serde_derive-1.0.228/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/serde_json-1.0.145/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/serde_json-1.0.145/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/shlex-1.3.0/LICENSE-APACHE +0 -13
- package/helpers/ripgrep/notices/shlex-1.3.0/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/syn-2.0.106/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/syn-2.0.106/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/termcolor-1.4.1/COPYING +0 -3
- package/helpers/ripgrep/notices/termcolor-1.4.1/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/termcolor-1.4.1/UNLICENSE +0 -24
- package/helpers/ripgrep/notices/textwrap-0.16.2/LICENSE +0 -21
- package/helpers/ripgrep/notices/tikv-jemalloc-sys-0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/tikv-jemalloc-sys-0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/tikv-jemalloc-sys-0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7/jemalloc/COPYING +0 -27
- package/helpers/ripgrep/notices/tikv-jemallocator-0.6.0/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/tikv-jemallocator-0.6.0/LICENSE-MIT +0 -25
- package/helpers/ripgrep/notices/unicode-ident-1.0.19/LICENSE-APACHE +0 -176
- package/helpers/ripgrep/notices/unicode-ident-1.0.19/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/unicode-ident-1.0.19/LICENSE-UNICODE +0 -39
- package/helpers/ripgrep/notices/walkdir-2.5.0/COPYING +0 -3
- package/helpers/ripgrep/notices/walkdir-2.5.0/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/walkdir-2.5.0/UNLICENSE +0 -24
- package/helpers/ripgrep/notices/wasip2-1.0.1+wasi-0.2.4/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/wasip2-1.0.1+wasi-0.2.4/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
- package/helpers/ripgrep/notices/wasip2-1.0.1+wasi-0.2.4/LICENSE-MIT +0 -23
- package/helpers/ripgrep/notices/winapi-util-0.1.11/COPYING +0 -3
- package/helpers/ripgrep/notices/winapi-util-0.1.11/LICENSE-MIT +0 -21
- package/helpers/ripgrep/notices/winapi-util-0.1.11/UNLICENSE +0 -24
- package/helpers/ripgrep/notices/windows-link-0.2.1/license-apache-2.0 +0 -201
- package/helpers/ripgrep/notices/windows-link-0.2.1/license-mit +0 -21
- package/helpers/ripgrep/notices/windows-sys-0.61.2/license-apache-2.0 +0 -201
- package/helpers/ripgrep/notices/windows-sys-0.61.2/license-mit +0 -21
- package/helpers/ripgrep/notices/wit-bindgen-0.46.0/LICENSE-APACHE +0 -201
- package/helpers/ripgrep/notices/wit-bindgen-0.46.0/LICENSE-Apache-2.0_WITH_LLVM-exception +0 -220
- package/helpers/ripgrep/notices/wit-bindgen-0.46.0/LICENSE-MIT +0 -23
package/README.md
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.
|
|
1
|
+
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.7 · 插件 → 添加插件
|
|
2
2
|
|
|
3
3
|
## 含工具桥预发布线
|
|
4
4
|
|
|
5
|
-
本包为 `0.9.0-toolbridge.
|
|
5
|
+
本包为 `0.9.0-toolbridge.7`,在独立 `toolbridge` 分支开发;稳定 main/0.8.x 和原总包保持原样。员工安装由连接组件提供的「AI 写作工作台(含工具桥)」总包,与不含工具桥的版本二选一。预发布渠道为 `toolbridge`,本轮仅提供本地固定包,不发布 npm。
|
|
6
|
+
|
|
7
|
+
含桥线新增模型菜单 **Codex(云)**(英文 Codex (Cloud)),只用于本机文件夹。它由主机 `aw-session` 启动 `/usr/local/aw-host/bin/aw-cloud-acp`,每轮新建云任务并带入可见历史;写入审批沿现有 DSH 入口。任务创建/中继失败会显示本轮已停止,取消只停止中继和员工调用,**云任务可能继续运行至结束**。不自动重提或切到主机 Codex。云端目前仅接受文本,图片输入会明确失败。
|
|
8
|
+
|
|
9
|
+
云链路按 R2 ACP v1 合同返回结构化失败:失败为 `refusal`、取消为 `cancelled`;DSH 显示失败分类与“云任务可能继续运行至结束”或“本轮未提交云任务”,技术详情保留 `causeCode`。只读档只暴露实际存在的 Read/Glob/Grep,以及显式声明 `annotations.readOnlyHint === true` 的 D31 桥工具;未标记、false 或字符串标记不算只读。桥的原生许可由 X 单次应答,实际工具仍由 DSH 审批。没有从工具名称或说明猜测只读权限。只读工具声明不会扩大 DSH 权限。接线及离线证据见 `docs/evidence/2026-10-28-K4-cancel-timeout/REPORT.md`;真实云组合/界面验收仍由编排安排。
|
|
10
|
+
|
|
11
|
+
云通道取消时最多等待 `cloudCancelReceiptWaitMs`(默认10000毫秒)消费 v1 结构化回执,保留 causeCode、run 和 taskMayContinue;超时或通道断开无法收到回执时,按“状态未知,云任务可能仍在运行”结束本轮;超时关闭该ACP通道,迟到回执不能改写结果。X 员工 MCP 还会按当前 DSH 只读档直接拒绝 Write/Edit/Bash,并拒绝这些写操作的原生审批请求,不创建审批卡。权限改变后按当前档位处理。
|
|
12
|
+
|
|
13
|
+
升级验收须遵循 P1–P4:完全退出 DSH(⌘Q)后重开并新建会话;两个总包二选一(不新增第三包);DSH 版本保持不变,24h 内连续升级须由编排清理 `minimumReleaseAgeExclude` 中该包旧同名行或等满 24h;云路径直接走 aw-cloud-acp,不依赖主机 Codex 的 MCP 首轮发现修复。发布只由编排在中性目录使用 npmrc-publish 执行。
|
|
6
14
|
|
|
7
15
|
选择本机文件夹后,Claude 和 Codex 可以把 DSH 已启用的 MCP、web、skill、ask_user、todo/present/goal 等工具交给 DSH 原生执行和审批。内置文件/命令、子代理/agent-team、run_code 不在桥接表;原有文件和命令执行方式保留。plan 不自动放行桥接权限;default 下 Claude 的桥接原生权限由插件单次应答,员工只在 DSH 审批实际工具。主机文件夹不开放工具桥。
|
|
8
16
|
|
|
@@ -51,6 +59,7 @@ Codex 员工端只使用随包提供的原生组件,通道等待本次组件
|
|
|
51
59
|
| brokerMaxFrameBytes | 2097152 | 主机回传单段容量 |
|
|
52
60
|
| brokerControlMaxBytes | 1048576 | 主机会话管理回复容量 |
|
|
53
61
|
| employeeShellKillGraceMs | 1000 | 本机命令连接取消后的清理宽限毫秒 |
|
|
62
|
+
| cloudCancelReceiptWaitMs | 10000 | 云取消回执最长等待毫秒;1~2147483647,超时以状态未知结束本轮 |
|
|
54
63
|
|
|
55
64
|
容量超限明确失败,不截断成有效消息。参数范围、生效时机和调整后果由官方 schema 与参数页显示;以上四条执行不变量不可关闭。
|
|
56
65
|
|
package/dist/acp.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { EmployeeRouting } from './employee-relay.ts';
|
|
|
9
9
|
import type { SessionOwnership } from './broker-ownership.ts';
|
|
10
10
|
export type ApprovalOutcome = 'allowed-once' | 'rejected' | 'cancelled' | 'unavailable';
|
|
11
11
|
export interface AcpHooks {
|
|
12
|
+
cloudCancelReceiptWaitMs?: number;
|
|
12
13
|
closeDiagnostics?: CloseDiagnostics;
|
|
13
14
|
onUpdate?: (notification: acp.SessionNotification) => void;
|
|
14
15
|
onResponse?: (response: acp.PromptResponse) => void;
|
|
@@ -37,6 +38,8 @@ export interface EmployeeExecutionMeta {
|
|
|
37
38
|
acpMaxMessageBytes: number;
|
|
38
39
|
}
|
|
39
40
|
export interface AcpStartContext {
|
|
41
|
+
routing?: 'native-exec' | 'mcp';
|
|
42
|
+
loginProvider?: 'claude' | 'codex';
|
|
40
43
|
toolBridgeServers?: EmployeeRouting['mcpServers'];
|
|
41
44
|
systemPrompt?: string;
|
|
42
45
|
codexNewSessionOnly?: true;
|
|
@@ -53,6 +56,7 @@ export declare class AcpSession {
|
|
|
53
56
|
private turnSignal?;
|
|
54
57
|
private turnToken?;
|
|
55
58
|
private busy;
|
|
59
|
+
private cloudCancelReceiptExpired;
|
|
56
60
|
private startAttempted;
|
|
57
61
|
private negotiated;
|
|
58
62
|
private method?;
|
package/dist/acp.js
CHANGED
|
@@ -7,6 +7,7 @@ import { employeeFailure } from "./presentation.js";
|
|
|
7
7
|
import { isolateRpcIds } from "./rpc-namespace.js";
|
|
8
8
|
import { sanitizeObservation, sanitizeDisplayLabel } from "./conversation-details.js";
|
|
9
9
|
import { ModelConfiguration, ModelConfigurationError } from "./model-configuration.js";
|
|
10
|
+
import { CloudTurnFailure, CLOUD_FAILURE_META_KEY, cloudTurnFailure, cloudCancelReceiptTimeout, DEFAULT_CLOUD_CANCEL_RECEIPT_WAIT_MS } from "./cloud-failure.js";
|
|
10
11
|
function employeeClaudeOptions(routing) { return { tools: [], disallowedTools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash', 'Agent', 'Task', 'TaskOutput', 'TaskStop'], toolAliases: structuredClone(routing.toolAliases) }; }
|
|
11
12
|
const permissionRanks = { claude: { plan: 0, default: 1, acceptEdits: 1, bypassPermissions: 2 }, codex: { 'read-only': 0, 'workspace-write': 1, agent: 1, 'agent-full-access': 2 } };
|
|
12
13
|
/** ACP v1 with explicitly negotiated SDK 2.0 lifecycle/context extensions. */
|
|
@@ -18,6 +19,7 @@ export class AcpSession {
|
|
|
18
19
|
turnSignal;
|
|
19
20
|
turnToken;
|
|
20
21
|
busy = false;
|
|
22
|
+
cloudCancelReceiptExpired = false;
|
|
21
23
|
startAttempted = false;
|
|
22
24
|
negotiated = {};
|
|
23
25
|
method;
|
|
@@ -274,6 +276,8 @@ export class AcpSession {
|
|
|
274
276
|
this.closeDiagnostics = hooks.closeDiagnostics ?? new CloseDiagnostics(event => this.detail(event));
|
|
275
277
|
const app = acp.client({ name: '@ai-workbench/remote-agent' })
|
|
276
278
|
.onNotification(acp.methods.client.session.update, ({ params: notification }) => {
|
|
279
|
+
if (this.cloudCancelReceiptExpired)
|
|
280
|
+
return;
|
|
277
281
|
if (this.creatingReplacement) {
|
|
278
282
|
if (notification.sessionId !== this.sessionId && notification.update.sessionUpdate === 'config_option_update')
|
|
279
283
|
this.pendingConfiguration(notification.sessionId, notification.update.configOptions);
|
|
@@ -514,7 +518,7 @@ export class AcpSession {
|
|
|
514
518
|
signal?.addEventListener('abort', abort, { once: true });
|
|
515
519
|
try {
|
|
516
520
|
const hello = await this.stage('acp-initialize', () => this.connection.agent.request(acp.methods.agent.initialize, {
|
|
517
|
-
protocolVersion: acp.PROTOCOL_VERSION, clientInfo: { name: '@ai-workbench/remote-agent', version: '0.9.0-toolbridge.
|
|
521
|
+
protocolVersion: acp.PROTOCOL_VERSION, clientInfo: { name: '@ai-workbench/remote-agent', version: '0.9.0-toolbridge.7' },
|
|
518
522
|
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false, session: { notices: {} }, ...(this.employeeMeta ? { _meta: { awEmployeeExecution: { version: 1, closeReason: 1, ...(context?.toolBridgeServers ? { mcpBridge: 1 } : {}) } } } : {}) },
|
|
519
523
|
}, { cancellationSignal: signal }));
|
|
520
524
|
if (hello.protocolVersion !== acp.PROTOCOL_VERSION)
|
|
@@ -531,9 +535,9 @@ export class AcpSession {
|
|
|
531
535
|
this.codexNewSessionOnly = !!context?.codexNewSessionOnly;
|
|
532
536
|
if (prompt)
|
|
533
537
|
this.validatePrompt(prompt);
|
|
534
|
-
const routing = context?.employeeRouting ? structuredClone(context.employeeRouting) : undefined;
|
|
538
|
+
const routing = context?.routing !== 'native-exec' && context?.employeeRouting ? structuredClone(context.employeeRouting) : undefined;
|
|
535
539
|
this.employeeRouting = routing;
|
|
536
|
-
const params = { cwd, mcpServers: context?.toolBridgeServers ? structuredClone(context.toolBridgeServers) : routing ? structuredClone(routing.mcpServers) : [], ...((routing || this.employeeMeta) ? { _meta: { ...(this.employeeMeta ? { awEmployeeExecution: this.employeeMeta } : {}), ...(routing ? { claudeCode: { options: employeeClaudeOptions(routing) } } : {}) } } : {}), ...(systemPrompt && !(resumeId && this.codexNewSessionOnly) ? { systemPrompt: { mode: 'append', content: [{ type: 'text', text: systemPrompt }] } } : {}) };
|
|
540
|
+
const params = { cwd, mcpServers: context?.toolBridgeServers ? structuredClone(context.toolBridgeServers) : routing ? structuredClone(routing.mcpServers) : [], ...((routing || this.employeeMeta) ? { _meta: { ...(this.employeeMeta ? { awEmployeeExecution: this.employeeMeta } : {}), ...(routing && context?.loginProvider !== 'codex' ? { claudeCode: { options: employeeClaudeOptions(routing) } } : {}) } } : {}), ...(systemPrompt && !(resumeId && this.codexNewSessionOnly) ? { systemPrompt: { mode: 'append', content: [{ type: 'text', text: systemPrompt }] } } : {}) };
|
|
537
541
|
const configRevision = this.resetConfiguration();
|
|
538
542
|
const restore = async (operation) => {
|
|
539
543
|
try {
|
|
@@ -620,16 +624,33 @@ export class AcpSession {
|
|
|
620
624
|
} };
|
|
621
625
|
const expectedPermission = this.selectedPermission, reportedModes = new Set();
|
|
622
626
|
const native = () => this.validateNativePermission(expectedPermission, reportedModes);
|
|
627
|
+
const cloudContract = record(this.negotiated._meta?.aiWorkbenchCloudFailure);
|
|
628
|
+
const cloud = cloudContract?.schemaVersion === 1 && cloudContract.metaKey === CLOUD_FAILURE_META_KEY;
|
|
629
|
+
const receiptWaitMs = this.hooks.cloudCancelReceiptWaitMs ?? DEFAULT_CLOUD_CANCEL_RECEIPT_WAIT_MS;
|
|
630
|
+
if (cloud && (!Number.isSafeInteger(receiptWaitMs) || receiptWaitMs < 1 || receiptWaitMs > 2147483647))
|
|
631
|
+
throw new NeedError('SETTINGS_REQUIRED', '云取消回执等待设置无效,本轮未发送。', 'cloudCancelReceiptWaitMs:1~2147483647的整数毫秒');
|
|
623
632
|
this.busy = true;
|
|
624
633
|
this.turnSignal = signal;
|
|
625
634
|
this.turnToken = Symbol('turn');
|
|
635
|
+
let receiptTimer;
|
|
636
|
+
let receiptTimeout;
|
|
626
637
|
let rejectAbort;
|
|
627
638
|
const interrupted = new Promise((_resolve, reject) => { rejectAbort = reject; });
|
|
628
639
|
const cancel = () => {
|
|
629
640
|
this.closeDiagnostics.record({ layer: 'acp', initiator: 'acp.prompt-cancel', reason: 'ABORTED', operation: 'session/prompt', action: 'abort' });
|
|
630
|
-
|
|
641
|
+
if (cloud) {
|
|
642
|
+
receiptTimer = setTimeout(() => {
|
|
643
|
+
this.cloudCancelReceiptExpired = true;
|
|
644
|
+
receiptTimeout = cloudCancelReceiptTimeout(receiptWaitMs);
|
|
645
|
+
this.detail({ kind: 'need', severity: 'action-required', code: receiptTimeout.code, summary: receiptTimeout.message, payload: receiptTimeout.info });
|
|
646
|
+
rejectAbort?.(receiptTimeout);
|
|
647
|
+
this.close({ layer: 'acp', initiator: 'acp.cloud-cancel-receipt-timeout', reason: receiptTimeout.code, action: 'close' });
|
|
648
|
+
}, receiptWaitMs);
|
|
649
|
+
}
|
|
650
|
+
else
|
|
651
|
+
rejectAbort?.(new NeedError('ABORTED', '已请求取消本轮,远端状态需确认', '确认主机取消状态'));
|
|
631
652
|
void this.connection.agent.notify(acp.methods.agent.session.cancel, { sessionId: this.sessionId }).catch(() => {
|
|
632
|
-
this.need({ code: 'CANCEL_UNCONFIRMED', message: '连接中断,无法确认主机已取消本轮', requires: '恢复连接以确认远端状态' });
|
|
653
|
+
this.need({ code: 'CANCEL_UNCONFIRMED', message: cloud ? '云通道已断开,无法确认云任务已结束。' : '连接中断,无法确认主机已取消本轮', requires: cloud ? '恢复云通道以核对任务状态' : '恢复连接以确认远端状态' });
|
|
633
654
|
});
|
|
634
655
|
};
|
|
635
656
|
signal?.addEventListener('abort', cancel, { once: true });
|
|
@@ -638,18 +659,33 @@ export class AcpSession {
|
|
|
638
659
|
const result = await this.stage('acp-prompt', () => {
|
|
639
660
|
this.promptPermissions.set(params, { current, native });
|
|
640
661
|
const request = this.connection.agent.request(acp.methods.agent.session.prompt, params, { cancellationSignal: signal });
|
|
662
|
+
// Cloud cancellation keeps the receipt RPC only for the configured
|
|
663
|
+
// interval; host adapters retain their immediate cancellation path.
|
|
641
664
|
return signal ? Promise.race([request, interrupted]) : request;
|
|
642
665
|
});
|
|
643
|
-
signal?.throwIfAborted();
|
|
644
666
|
this.hooks.onResponse?.(result);
|
|
667
|
+
if (cloud) {
|
|
668
|
+
const failure = cloudTurnFailure(result);
|
|
669
|
+
if (failure)
|
|
670
|
+
throw failure;
|
|
671
|
+
}
|
|
672
|
+
signal?.throwIfAborted();
|
|
645
673
|
return result.stopReason;
|
|
646
674
|
}
|
|
647
675
|
catch (error) {
|
|
676
|
+
if (receiptTimeout)
|
|
677
|
+
throw receiptTimeout;
|
|
678
|
+
if (error instanceof CloudTurnFailure)
|
|
679
|
+
throw error;
|
|
680
|
+
if (cloud && signal?.aborted)
|
|
681
|
+
throw cloudTurnFailure({ stopReason: 'cancelled' });
|
|
648
682
|
if (signal?.aborted)
|
|
649
683
|
throw new NeedError('ABORTED', '本轮已取消;已请求主机停止', '确认主机取消状态');
|
|
650
684
|
throw acpNeed(error);
|
|
651
685
|
}
|
|
652
686
|
finally {
|
|
687
|
+
if (receiptTimer !== undefined)
|
|
688
|
+
clearTimeout(receiptTimer);
|
|
653
689
|
signal?.removeEventListener('abort', cancel);
|
|
654
690
|
this.turnSignal = undefined;
|
|
655
691
|
this.busy = false;
|
package/dist/agents.d.ts
CHANGED
|
@@ -7,8 +7,10 @@ export interface AgentDefinition {
|
|
|
7
7
|
}>;
|
|
8
8
|
readonly command: string;
|
|
9
9
|
readonly loginProvider: 'claude' | 'codex';
|
|
10
|
+
readonly routing: 'native-exec' | 'mcp';
|
|
10
11
|
}
|
|
11
12
|
export declare const CODEX_AGENT: AgentDefinition;
|
|
12
13
|
export declare const CLAUDE_AGENT: AgentDefinition;
|
|
14
|
+
export declare const CODEX_CLOUD_AGENT: AgentDefinition;
|
|
13
15
|
export declare const AGENTS: readonly AgentDefinition[];
|
|
14
16
|
export declare function agentForProvider(id: string): AgentDefinition | undefined;
|
package/dist/agents.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export const CODEX_AGENT = Object.freeze({ id: 'codex-remote', name: Object.freeze({ zh: 'Codex(远程主机)', en: 'Codex (Remote Host)' }), command: '/usr/local/aw-host/bin/codex-acp-toolbridge', loginProvider: 'codex' });
|
|
2
|
-
export const CLAUDE_AGENT = Object.freeze({ id: 'claude-code-workbench', name: Object.freeze({ zh: 'Claude(远程主机)', en: 'Claude (Remote Host)' }), command: '/usr/local/aw-host/bin/claude-agent-acp', loginProvider: 'claude' });
|
|
3
|
-
export const
|
|
1
|
+
export const CODEX_AGENT = Object.freeze({ id: 'codex-remote', name: Object.freeze({ zh: 'Codex(远程主机)', en: 'Codex (Remote Host)' }), command: '/usr/local/aw-host/bin/codex-acp-toolbridge', loginProvider: 'codex', routing: 'native-exec' });
|
|
2
|
+
export const CLAUDE_AGENT = Object.freeze({ id: 'claude-code-workbench', name: Object.freeze({ zh: 'Claude(远程主机)', en: 'Claude (Remote Host)' }), command: '/usr/local/aw-host/bin/claude-agent-acp', loginProvider: 'claude', routing: 'mcp' });
|
|
3
|
+
export const CODEX_CLOUD_AGENT = Object.freeze({ id: 'codex-cloud', name: Object.freeze({ zh: 'Codex(云)', en: 'Codex (Cloud)' }), command: '/usr/local/aw-host/bin/aw-cloud-acp', loginProvider: 'codex', routing: 'mcp' });
|
|
4
|
+
export const AGENTS = Object.freeze([CODEX_AGENT, CLAUDE_AGENT, CODEX_CLOUD_AGENT]);
|
|
4
5
|
export function agentForProvider(id) { return AGENTS.find(agent => agent.id === id); }
|
package/dist/claude-local.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ interface Configuration {
|
|
|
13
13
|
employeeShellKillGraceMs?: number;
|
|
14
14
|
}
|
|
15
15
|
interface Options {
|
|
16
|
+
readOnly?: (sessionId: string) => boolean;
|
|
16
17
|
getConnect: () => ConnectApi | undefined;
|
|
17
18
|
getNetwork: () => EmployeeNetworkApi | undefined;
|
|
18
19
|
readWorkspace: (sessionId: string) => Promise<EmployeeWorkspace>;
|
package/dist/claude-local.js
CHANGED
|
@@ -116,7 +116,7 @@ export function createClaudeLocalProvider(options) {
|
|
|
116
116
|
lease = await (options.ports?.lease ?? openEmployeeLease)({ closeDiagnostics, getConnect: () => options.getConnect(), getNetwork: options.getNetwork, readWorkspace: () => options.readWorkspace(request.sessionId), host: target, sessionId: request.sessionId, control: async (_target, command, signal) => (await transport()).run(command, signal), detail: unscoped }, request.signal);
|
|
117
117
|
const shell = (options.ports?.shell ?? createEmployeeShell)({ closeDiagnostics, target: lease.target, sshArgs: lease.sshArgs, maxBytes: maximum, killGraceMs: grace, attach: async (spec) => (await transport()).attach([spec.command, ...spec.args].map(shellQuote).join(' ')) });
|
|
118
118
|
request.toolBridge?.enable(event => details.record(event));
|
|
119
|
-
mcp = await (options.ports?.mcp ?? openEmployeeMcp)({ bridge: request.toolBridge, closeDiagnostics, lease, maxBytes: maximum, killGraceMs: grace, runShell: shell, activeSignal: () => entry?.active?.signal, captureDetail: () => { const sink = entry?.active?.details; if (!sink)
|
|
119
|
+
mcp = await (options.ports?.mcp ?? openEmployeeMcp)({ ...(options.readOnly ? { readOnly: () => options.readOnly(request.sessionId) } : {}), bridge: request.toolBridge, closeDiagnostics, lease, maxBytes: maximum, killGraceMs: grace, runShell: shell, activeSignal: () => entry?.active?.signal, captureDetail: () => { const sink = entry?.active?.details; if (!sink)
|
|
120
120
|
throw failure('EMPLOYEE_NO_ACTIVE_TURN'); return observation => sink.record(observation); }, detail: unscoped });
|
|
121
121
|
entry = { runtime: undefined, scope, lease, details, request };
|
|
122
122
|
const row = entry;
|
|
@@ -144,7 +144,7 @@ export function createClaudeLocalProvider(options) {
|
|
|
144
144
|
});
|
|
145
145
|
};
|
|
146
146
|
const executionSignal = AbortSignal.any([lease.signal, ...mcp.signal ? [mcp.signal] : []]);
|
|
147
|
-
row.runtime = { ...underlying, closeDiagnostics, cwd: workspace.directory.path, details, connection: { ...connection }, binding: { bindingId: item.bindingId, workspaceId: workspace.workspaceId, revision: state.revision }, execution: { hostCwd: target.session.root, routing: mcp.routing, notice: NOTICE, signal: executionSignal, scope: { source: 'local', cwd: workspace.directory.path, hostCwd: target.session.root, uid: lease.target.endpoint.remoteUid, claudeAcpVersion: '0.94.0', sdkVersion: '0.3.303', unsupported: ['subagents', 'internal-direct-calls', 'binary-read', 'background-shell'] }, validate: async (signal) => { signal?.throwIfAborted(); executionSignal.throwIfAborted(); }, beginTurn: async (signal) => { signal?.throwIfAborted(); executionSignal.throwIfAborted(); if (row.closing || row.active)
|
|
147
|
+
row.runtime = { ...underlying, closeDiagnostics, cwd: workspace.directory.path, details, connection: { ...connection }, binding: { bindingId: item.bindingId, workspaceId: workspace.workspaceId, revision: state.revision }, execution: { hostCwd: target.session.root, routing: mcp.routing, notice: NOTICE, signal: executionSignal, scope: { source: 'local', cwd: workspace.directory.path, hostCwd: target.session.root, uid: lease.target.endpoint.remoteUid, ...(request.agent?.loginProvider === 'codex' ? { acpAgent: 'aw-cloud-acp', acpVersion: '0.1.2' } : { claudeAcpVersion: '0.94.0', sdkVersion: '0.3.303' }), unsupported: ['subagents', 'internal-direct-calls', 'binary-read', 'background-shell'] }, validate: async (signal) => { signal?.throwIfAborted(); executionSignal.throwIfAborted(); }, beginTurn: async (signal) => { signal?.throwIfAborted(); executionSignal.throwIfAborted(); if (row.closing || row.active)
|
|
148
148
|
throw failure('TURN_BUSY'); row.active = { signal, details: row.details }; }, endTurn: () => { row.active = undefined; } }, dispose: cause => close(false, cause), detach: cause => close(true, cause) };
|
|
149
149
|
entries.set(request.sessionId, row);
|
|
150
150
|
lease.signal.addEventListener('abort', () => { void close(false, { layer: 'endpoint', initiator: 'claude.lease-abort', reason: closeCode(lease?.signal.reason, 'EMPLOYEE_CONTEXT_CHANGED'), action: 'abort' }).catch(() => console.warn('CLAUDE_CLEANUP_FAILED')); }, { once: true });
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
window.__ModuleLoader__.load({id:'@ai-workbench/remote-agent',factory(require){
|
|
2
2
|
const messages={"en":{"administratorNote":"Settings → Built-in plugins → 远程助手参数. Eight named settings with defaults, scope and effects.","providerName":"Codex (Remote Host)"},"zh":{"administratorNote":"管理员:设置 → 内置插件 → 远程助手参数。八项设置含默认值、范围、生效和后果说明。","providerName":"Codex(远程主机)"}};
|
|
3
|
-
const settingsFields=[{"key":"acpMaxMessageBytes","name":"完整消息与工具输出容量(字节)","kind":"number","min":1,"max":9007199254740991,"range":"1~9007199254740991 的整数;0不能关闭上限","scope":"两位远程助手的完整会话消息;也用于模型目录、本机 MCP、员工执行 RPC 和工具输出容量。","when":"当轮快照不变;下一次独立目录查询读取新值;已有会话需新建后使用。","consequence":"调大可接收更大消息、占用更多内存;调小更早拒绝超限。超限明确停止,不截断、不自动重试;不能用0取消完整消息保护。","defaultValue":4194304},{"key":"brokerMaxFrameBytes","name":"主机会话回传单段容量(字节)","kind":"number","min":1,"max":9007199254740991,"range":"1~9007199254740991 的整数;0不能关闭上限","scope":"本插件接收主机会话单段输出的容量;不会替主机修改它自己的输出策略。","when":"当轮快照不变;更改后已有会话需新建。","consequence":"调大允许更大回传段、占用更多内存;调小可能拒绝主机合法输出。超限停止,不截断;不能关闭协议帧核验。","defaultValue":2097152},{"key":"brokerControlMaxBytes","name":"主机会话管理回复容量(字节)","kind":"number","min":1,"max":9007199254740991,"range":"1~9007199254740991 的整数;0不能关闭上限","scope":"主机会话管理命令的标准输出、标准错误各自容量;也用于本机执行桥的管理回复。","when":"当轮快照不变;更改后已有会话需新建。","consequence":"调大允许更长管理回复、占用更多内存;调小可能无法核实状态。超限明确停止,不能把不完整回复当成功;0不表示无限。","defaultValue":1048576},{"key":"employeeShellKillGraceMs","name":"本机命令外层连接清理宽限(毫秒)","kind":"number","min":0,"max":2147483647,"range":"0~2147483647 的整数","scope":"仅 Claude 本机 Bash 取消后,本插件自己的外层 SSH 进程清理;不控制员工命令或 Codex 执行器。","when":"当轮快照不变;更改后已有会话需新建。","consequence":"大于0时先请求外层连接退出,再等待所设毫秒后强制清理;0表示不留宽限、立即强制清理外层连接,不是关闭取消。没有员工端退出确认时结果仍未知,不能据此自动重放或声称命令已停止。","defaultValue":1000}];
|
|
3
|
+
const settingsFields=[{"key":"acpMaxMessageBytes","name":"完整消息与工具输出容量(字节)","kind":"number","min":1,"max":9007199254740991,"range":"1~9007199254740991 的整数;0不能关闭上限","scope":"两位远程助手的完整会话消息;也用于模型目录、本机 MCP、员工执行 RPC 和工具输出容量。","when":"当轮快照不变;下一次独立目录查询读取新值;已有会话需新建后使用。","consequence":"调大可接收更大消息、占用更多内存;调小更早拒绝超限。超限明确停止,不截断、不自动重试;不能用0取消完整消息保护。","defaultValue":4194304},{"key":"brokerMaxFrameBytes","name":"主机会话回传单段容量(字节)","kind":"number","min":1,"max":9007199254740991,"range":"1~9007199254740991 的整数;0不能关闭上限","scope":"本插件接收主机会话单段输出的容量;不会替主机修改它自己的输出策略。","when":"当轮快照不变;更改后已有会话需新建。","consequence":"调大允许更大回传段、占用更多内存;调小可能拒绝主机合法输出。超限停止,不截断;不能关闭协议帧核验。","defaultValue":2097152},{"key":"brokerControlMaxBytes","name":"主机会话管理回复容量(字节)","kind":"number","min":1,"max":9007199254740991,"range":"1~9007199254740991 的整数;0不能关闭上限","scope":"主机会话管理命令的标准输出、标准错误各自容量;也用于本机执行桥的管理回复。","when":"当轮快照不变;更改后已有会话需新建。","consequence":"调大允许更长管理回复、占用更多内存;调小可能无法核实状态。超限明确停止,不能把不完整回复当成功;0不表示无限。","defaultValue":1048576},{"key":"employeeShellKillGraceMs","name":"本机命令外层连接清理宽限(毫秒)","kind":"number","min":0,"max":2147483647,"range":"0~2147483647 的整数","scope":"仅 Claude 本机 Bash 取消后,本插件自己的外层 SSH 进程清理;不控制员工命令或 Codex 执行器。","when":"当轮快照不变;更改后已有会话需新建。","consequence":"大于0时先请求外层连接退出,再等待所设毫秒后强制清理;0表示不留宽限、立即强制清理外层连接,不是关闭取消。没有员工端退出确认时结果仍未知,不能据此自动重放或声称命令已停止。","defaultValue":1000},{"key":"cloudCancelReceiptWaitMs","name":"云取消回执最长等待(毫秒)","kind":"number","min":1,"max":2147483647,"range":"1~2147483647 的整数;0不能设为无限等待","scope":"仅协商v1云失败合同的取消回执等待;不改变主机助手取消或云任务执行期限。","when":"每轮读取配置快照;取消时开始计时,改动用于下一轮。","consequence":"默认10000毫秒。到时未收到回执则以状态未知、云任务可能仍在运行结束本轮并关闭该ACP通道;迟到回执不能改写结果。调小会更早失去详细回执,调大增加取消等待;不重提任务。","defaultValue":10000}];
|
|
4
4
|
/* Public settings.plugins.tab + shared ConfigForms. No private client services. */
|
|
5
5
|
function mountRuntimeSettings(ctx,React,fields){
|
|
6
6
|
const h=React.createElement;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PromptResponse } from '@agentclientprotocol/sdk/unstable';
|
|
2
|
+
import { NeedError } from './remote.ts';
|
|
3
|
+
export declare const CLOUD_FAILURE_META_KEY = "ai-workbench/cloud-turn";
|
|
4
|
+
export declare const DEFAULT_CLOUD_CANCEL_RECEIPT_WAIT_MS = 10000;
|
|
5
|
+
export declare class CloudTurnFailure extends NeedError {
|
|
6
|
+
readonly info: Readonly<Record<string, unknown>>;
|
|
7
|
+
constructor(info: Readonly<Record<string, unknown>>, message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare function cloudCancelReceiptTimeout(waitMs: number): CloudTurnFailure;
|
|
10
|
+
/** Read only the v1 contract. Never classify a cloud turn by its prose. */
|
|
11
|
+
export declare function cloudTurnFailure(response: PromptResponse): CloudTurnFailure | undefined;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NeedError } from "./remote.js";
|
|
2
|
+
export const CLOUD_FAILURE_META_KEY = 'ai-workbench/cloud-turn';
|
|
3
|
+
export const DEFAULT_CLOUD_CANCEL_RECEIPT_WAIT_MS = 10000;
|
|
4
|
+
const messages = {
|
|
5
|
+
CLOUD_TASK_CREATE_FAILED: '云任务创建失败或结果未知,本轮已停止。',
|
|
6
|
+
CLOUD_RELAY_DISCONNECTED: '云中继连接已断开,本轮已停止。',
|
|
7
|
+
CLOUD_CANCELLED: '云任务本轮已取消派发。',
|
|
8
|
+
CLOUD_DEADLINE_EXCEEDED: '云任务本轮已到截止时间。',
|
|
9
|
+
CLOUD_ENDPOINT_DISCONNECTED: '员工工具通道不可用,本轮已停止。',
|
|
10
|
+
CLOUD_TOOL_UNAVAILABLE: '本轮权限或工具表不包含此工具,未执行。',
|
|
11
|
+
CLOUD_PERMISSION_DENIED: '本次操作没有获得授权,未执行。',
|
|
12
|
+
CLOUD_TASK_FAILED: '云任务失败或状态无法确认,本轮已停止。',
|
|
13
|
+
CLOUD_REPORT_UNAVAILABLE: '云任务最终报告未能确认,本轮已停止。',
|
|
14
|
+
CLOUD_TURN_FAILED: '云任务本轮未完成。',
|
|
15
|
+
};
|
|
16
|
+
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
17
|
+
const machineCode = (value) => typeof value === 'string' && /^[A-Z][A-Z0-9_]{0,79}$/.test(value) ? value : undefined;
|
|
18
|
+
export class CloudTurnFailure extends NeedError {
|
|
19
|
+
info;
|
|
20
|
+
constructor(info, message) {
|
|
21
|
+
super(String(info.code), message, JSON.stringify(info));
|
|
22
|
+
this.info = info;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function cloudCancelReceiptTimeout(waitMs) {
|
|
26
|
+
return new CloudTurnFailure(Object.freeze({ schemaVersion: 1, status: 'unknown', code: 'CLOUD_CANCEL_RECEIPT_TIMEOUT', causeCode: 'CLOUD_CANCEL_RECEIPT_TIMEOUT', origin: 'client', stopReason: 'cancelled', taskMayContinue: true, retryable: false, waitMs }), '取消回执等待已到上限;状态未知,云任务可能仍在运行。不会自动重提或改用主机 Codex。');
|
|
27
|
+
}
|
|
28
|
+
/** Read only the v1 contract. Never classify a cloud turn by its prose. */
|
|
29
|
+
export function cloudTurnFailure(response) {
|
|
30
|
+
const meta = object(response._meta?.[CLOUD_FAILURE_META_KEY]);
|
|
31
|
+
if (!meta && response.stopReason !== 'refusal' && response.stopReason !== 'cancelled')
|
|
32
|
+
return;
|
|
33
|
+
if (meta?.status !== 'failed' && response.stopReason !== 'refusal' && response.stopReason !== 'cancelled')
|
|
34
|
+
return;
|
|
35
|
+
const supported = meta?.schemaVersion === 1 && meta.status === 'failed';
|
|
36
|
+
const reported = supported ? machineCode(meta.code) : undefined;
|
|
37
|
+
const code = reported && Object.hasOwn(messages, reported) ? reported : response.stopReason === 'cancelled' ? 'CLOUD_CANCELLED' : 'CLOUD_TURN_FAILED';
|
|
38
|
+
const taskMayContinue = supported && typeof meta.taskMayContinue === 'boolean' ? meta.taskMayContinue : true;
|
|
39
|
+
const info = { schemaVersion: 1, status: 'failed', code, stopReason: response.stopReason, taskMayContinue, retryable: false };
|
|
40
|
+
if (supported) {
|
|
41
|
+
const causeCode = machineCode(meta.causeCode);
|
|
42
|
+
if (causeCode)
|
|
43
|
+
info.causeCode = causeCode;
|
|
44
|
+
if (reported && reported !== code)
|
|
45
|
+
info.reportedCode = reported;
|
|
46
|
+
if (typeof meta.stage === 'string' && ['registration', 'relay', 'submission', 'task', 'endpoint', 'turn'].includes(meta.stage))
|
|
47
|
+
info.stage = meta.stage;
|
|
48
|
+
for (const field of ['run', 'taskId'])
|
|
49
|
+
if (typeof meta[field] === 'string' && /^[A-Za-z0-9_.:-]{1,128}$/.test(meta[field]))
|
|
50
|
+
info[field] = meta[field];
|
|
51
|
+
}
|
|
52
|
+
const message = messages[code] + (taskMayContinue ? ' 云任务可能继续运行至结束。' : ' 本轮未提交云任务。') + ' 不会自动重提或改用主机 Codex。';
|
|
53
|
+
return new CloudTurnFailure(Object.freeze(info), message);
|
|
54
|
+
}
|
package/dist/employee-mcp.d.ts
CHANGED
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EmployeeSocketTransport as SocketTransport, EMPLOYEE_MCP_TOOLS } from '@ai-workbench/employee-tools';
|
|
2
|
+
import type { Socket } from 'node:net';
|
|
2
3
|
import { type CloseCause, type CloseDiagnostics, type CloseObserver } from './close-diagnostics.ts';
|
|
3
|
-
import { type Socket } from 'node:net';
|
|
4
|
-
import { type JSONRPCMessage, type Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
-
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
6
4
|
import type { EmployeeLease } from './employee-endpoint.ts';
|
|
7
5
|
import { employeeRouting } from './employee-relay.ts';
|
|
8
6
|
import type { DetailObservation } from './conversation-details.ts';
|
|
9
7
|
import type { EmployeeShell } from './employee-shell.ts';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare class EmployeeSocketTransport
|
|
13
|
-
|
|
14
|
-
private maxBytes;
|
|
15
|
-
private observeClose?;
|
|
16
|
-
onclose?: () => void;
|
|
17
|
-
onerror?: (error: Error) => void;
|
|
18
|
-
onmessage?: (message: JSONRPCMessage) => void;
|
|
19
|
-
private pending;
|
|
20
|
-
private ended;
|
|
21
|
-
private failure?;
|
|
22
|
-
get error(): Error | undefined;
|
|
23
|
-
private readonly lifetime;
|
|
24
|
-
readonly signal: AbortSignal;
|
|
25
|
-
constructor(socket: Socket, maxBytes: number, observeClose?: CloseObserver | undefined);
|
|
26
|
-
private failed;
|
|
27
|
-
start(): Promise<void>;
|
|
28
|
-
send(message: JSONRPCMessage): Promise<void>;
|
|
29
|
-
close(cause?: CloseCause): Promise<void>;
|
|
8
|
+
import type { ToolBridge } from './toolbridge.ts';
|
|
9
|
+
export { EMPLOYEE_MCP_TOOLS };
|
|
10
|
+
export declare class EmployeeSocketTransport extends SocketTransport {
|
|
11
|
+
constructor(socket: Socket, maxBytes: number, observeClose?: CloseObserver);
|
|
30
12
|
}
|
|
31
13
|
export interface EmployeeMcpOptions {
|
|
32
14
|
bridge?: ToolBridge;
|
|
15
|
+
/** Current official sandbox mode; X's cloud caller supplies this live getter. */
|
|
16
|
+
readOnly?: () => boolean;
|
|
33
17
|
closeDiagnostics?: CloseDiagnostics;
|
|
34
18
|
lease: EmployeeLease;
|
|
35
19
|
maxBytes: number;
|
package/dist/employee-mcp.js
CHANGED
|
@@ -1,194 +1,30 @@
|
|
|
1
|
+
import { openEmployeeMcp as open, EmployeeSocketTransport as SocketTransport, EMPLOYEE_MCP_TOOLS } from '@ai-workbench/employee-tools';
|
|
2
|
+
import { NeedError } from "./remote.js";
|
|
1
3
|
import { closeCode } from "./close-diagnostics.js";
|
|
2
|
-
import { createServer } from 'node:net';
|
|
3
|
-
import { mkdtemp, lstat, rm, access } from 'node:fs/promises';
|
|
4
|
-
import { constants } from 'node:fs';
|
|
5
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
6
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
7
|
-
import { createEmployeeTools } from "./employee-tools.js";
|
|
8
4
|
import { employeeRouting } from "./employee-relay.js";
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
schema('Read', { file_path: string, offset: integer, limit: integer, pages: string }, ['file_path']),
|
|
14
|
-
schema('Write', { file_path: string, content: string }, ['file_path', 'content']),
|
|
15
|
-
schema('Edit', { file_path: string, old_string: string, new_string: string, replace_all: boolean }, ['file_path', 'old_string', 'new_string']),
|
|
16
|
-
schema('Glob', { pattern: string, path: string }, ['pattern']),
|
|
17
|
-
schema('Grep', { pattern: string, path: string, glob: string, output_mode: string, '-B': integer, '-A': integer, '-C': integer, '-n': boolean, '-i': boolean, type: string, head_limit: integer, offset: integer, multiline: boolean }, ['pattern']),
|
|
18
|
-
schema('Bash', { command: string, timeout: integer, description: string, run_in_background: boolean, dangerouslyDisableSandbox: boolean }, ['command']),
|
|
19
|
-
];
|
|
20
|
-
/** Same newline-delimited MCP messages as stdio, over an employee-only Unix stream. */
|
|
21
|
-
export class EmployeeSocketTransport {
|
|
22
|
-
socket;
|
|
23
|
-
maxBytes;
|
|
24
|
-
observeClose;
|
|
25
|
-
onclose;
|
|
26
|
-
onerror;
|
|
27
|
-
onmessage;
|
|
28
|
-
pending = Buffer.alloc(0);
|
|
29
|
-
ended = false;
|
|
30
|
-
failure;
|
|
31
|
-
get error() { return this.failure; }
|
|
32
|
-
lifetime = new AbortController();
|
|
33
|
-
signal = this.lifetime.signal;
|
|
34
|
-
constructor(socket, maxBytes, observeClose) {
|
|
35
|
-
this.socket = socket;
|
|
36
|
-
this.maxBytes = maxBytes;
|
|
37
|
-
this.observeClose = observeClose;
|
|
38
|
-
}
|
|
39
|
-
failed(error) { this.failure ??= error; try {
|
|
40
|
-
this.onerror?.(error);
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
console.warn('EMPLOYEE_MCP_DIAGNOSTIC_DROPPED');
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
void this.close({ layer: 'relay', initiator: 'mcp.socket-failure', reason: closeCode(error, 'EMPLOYEE_MCP_PROTOCOL_OR_SOCKET_ERROR'), action: 'failure' });
|
|
47
|
-
} }
|
|
48
|
-
async start() {
|
|
49
|
-
this.socket.on('error', error => this.failed(error));
|
|
50
|
-
this.socket.on('close', () => void this.close({ layer: 'relay', initiator: 'mcp.socket-peer-close', reason: 'MCP_SOCKET_CLOSED', action: 'close' }));
|
|
51
|
-
this.socket.on('data', (bytes) => {
|
|
52
|
-
try {
|
|
53
|
-
let cursor = 0;
|
|
54
|
-
while (cursor < bytes.length) {
|
|
55
|
-
const newline = bytes.indexOf(10, cursor), end = newline < 0 ? bytes.length : newline;
|
|
56
|
-
if (this.pending.length + end - cursor > this.maxBytes)
|
|
57
|
-
throw new NeedError('EMPLOYEE_MCP_MESSAGE_TOO_LARGE', '本机工具消息超过acpMaxMessageBytes,未截断。', '调整具名会话消息容量');
|
|
58
|
-
this.pending = Buffer.concat([this.pending, bytes.subarray(cursor, end)]);
|
|
59
|
-
cursor = newline < 0 ? bytes.length : newline + 1;
|
|
60
|
-
if (newline >= 0) {
|
|
61
|
-
const line = new TextDecoder('utf8', { fatal: true }).decode(this.pending);
|
|
62
|
-
this.pending = Buffer.alloc(0);
|
|
63
|
-
this.onmessage?.(JSONRPCMessageSchema.parse(JSON.parse(line)));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
this.failed(error);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
async send(message) {
|
|
73
|
-
if (this.ended)
|
|
74
|
-
throw new Error('EMPLOYEE_MCP_CLOSED');
|
|
75
|
-
const wire = Buffer.from(JSON.stringify(message) + '\n');
|
|
76
|
-
if (wire.length - 1 > this.maxBytes) {
|
|
77
|
-
await this.close({ layer: 'relay', initiator: 'mcp.send-capacity', reason: 'EMPLOYEE_MCP_MESSAGE_TOO_LARGE', action: 'close' });
|
|
78
|
-
throw new Error('EMPLOYEE_MCP_MESSAGE_TOO_LARGE');
|
|
79
|
-
}
|
|
80
|
-
await new Promise((yes, no) => this.socket.write(wire, error => error ? no(error) : yes()));
|
|
81
|
-
}
|
|
82
|
-
async close(cause = { layer: 'relay', initiator: 'mcp.transport-close', reason: 'MCP_TRANSPORT_CLOSED', action: 'close' }) { try {
|
|
83
|
-
this.observeClose?.({ ...cause, changes: cause.changes ?? [{ field: 'mcp.ended', before: this.ended, after: true }] });
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
console.warn('EMPLOYEE_MCP_DIAGNOSTIC_DROPPED');
|
|
87
|
-
} if (this.ended)
|
|
88
|
-
return; this.ended = true; this.lifetime.abort(); this.socket.destroy(); try {
|
|
89
|
-
this.onclose?.();
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
console.warn('EMPLOYEE_MCP_CLOSE_OBSERVER_FAILED');
|
|
93
|
-
} }
|
|
5
|
+
export { EMPLOYEE_MCP_TOOLS };
|
|
6
|
+
const runtime = { NeedError, closeCode };
|
|
7
|
+
export class EmployeeSocketTransport extends SocketTransport {
|
|
8
|
+
constructor(socket, maxBytes, observeClose) { super(socket, maxBytes, runtime, observeClose); }
|
|
94
9
|
}
|
|
95
10
|
export async function openEmployeeMcp(options) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
throw new NeedError('EMPLOYEE_MCP_STORAGE_INVALID', '本机工具私有通道不可用。', '当前员工的700私有Unix目录');
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
options.closeDiagnostics?.record({ layer: 'relay', initiator: 'mcp.storage-failure', reason: closeCode(error), action: 'failure' });
|
|
110
|
-
for (const clean of [() => tools.close({ layer: 'executor', initiator: 'mcp.storage-cleanup', reason: 'MCP_STORAGE_FAILED', action: 'close' }), () => rm(root, { recursive: true })]) {
|
|
111
|
-
try {
|
|
112
|
-
await clean();
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
console.warn('EMPLOYEE_MCP_CLEANUP_FAILED');
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
throw error;
|
|
119
|
-
}
|
|
120
|
-
const clients = new Set(), transports = new Set();
|
|
121
|
-
let closing;
|
|
122
|
-
function observeUsing(event, sink) { try {
|
|
123
|
-
sink(event);
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
console.warn('EMPLOYEE_MCP_DIAGNOSTIC_DROPPED');
|
|
127
|
-
} }
|
|
128
|
-
function observe(event) { observeUsing(event, options.detail); }
|
|
129
|
-
const server = createServer(socket => {
|
|
130
|
-
if (closing || options.lease.signal.aborted) {
|
|
131
|
-
options.closeDiagnostics?.record({ layer: 'relay', initiator: 'mcp.reject-late-socket', reason: 'MCP_CLOSING', action: 'close' });
|
|
132
|
-
socket.destroy();
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const observeConnection = options.closeDiagnostics?.child().capture();
|
|
136
|
-
const mcp = new Server({ name: 'ai-workbench-employee', version: '0.8.14' }, { capabilities: { tools: {} } }), transport = new EmployeeSocketTransport(socket, options.maxBytes, observeConnection);
|
|
137
|
-
clients.add(mcp);
|
|
138
|
-
transports.add(transport);
|
|
139
|
-
mcp.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [...EMPLOYEE_MCP_TOOLS, ...options.bridge?.tools ?? []] }));
|
|
140
|
-
mcp.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
141
|
-
const active = options.activeSignal();
|
|
142
|
-
if (!active || active.aborted)
|
|
143
|
-
return { isError: true, content: [{ type: 'text', text: 'EMPLOYEE_NO_ACTIVE_TURN:当前没有已接纳的用户轮次,本机工具未执行。' }] };
|
|
144
|
-
const signal = AbortSignal.any([active, extra.signal, transport.signal, options.lease.signal]);
|
|
145
|
-
if (options.bridge?.isBridge(request.params.name))
|
|
146
|
-
return options.bridge.call(request.params.name, request.params.arguments ?? {}, signal);
|
|
147
|
-
let sink;
|
|
148
|
-
try {
|
|
149
|
-
sink = options.captureDetail?.() ?? options.detail;
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
console.warn('EMPLOYEE_MCP_DIAGNOSTIC_DROPPED');
|
|
153
|
-
}
|
|
154
|
-
return tools.call(request.params.name, request.params.arguments ?? {}, signal, event => { if (sink)
|
|
155
|
-
observeUsing(event, sink); });
|
|
156
|
-
});
|
|
157
|
-
mcp.onerror = () => { observeConnection?.({ layer: 'relay', initiator: 'mcp.server-error', reason: 'EMPLOYEE_MCP_PROTOCOL_OR_TRANSPORT_ERROR', action: 'failure' }); observe({ kind: 'session', severity: 'warning', code: 'CLAUDE_EMPLOYEE_MCP_UNKNOWN', summary: '本机工具连接中断,在途结果未知,没有重放;恢复后可在原会话继续。' }); };
|
|
158
|
-
mcp.onclose = () => { observeConnection?.({ layer: 'relay', initiator: 'mcp.client-closed', reason: 'MCP_CLIENT_CLOSED', action: 'close' }); clients.delete(mcp); transports.delete(transport); };
|
|
159
|
-
void mcp.connect(transport).catch(error => { observeConnection?.({ layer: 'relay', initiator: 'mcp.connect-failure', reason: closeCode(error, 'MCP_CONNECT_FAILED'), action: 'close' }); socket.destroy(); });
|
|
160
|
-
});
|
|
161
|
-
const close = (cause = { layer: 'relay', initiator: 'mcp.close', reason: 'MCP_CLOSE_REQUESTED', action: 'close' }) => {
|
|
162
|
-
options.closeDiagnostics?.record({ ...cause, changes: cause.changes ?? [{ field: 'mcp.closing', before: !!closing, after: true }] });
|
|
163
|
-
return closing ??= Promise.resolve().then(async () => {
|
|
164
|
-
options.lease.signal.removeEventListener('abort', aborted);
|
|
165
|
-
const clean = async (operation) => { try {
|
|
166
|
-
await operation();
|
|
11
|
+
// Compose with the existing request-dispatch port without changing the frozen
|
|
12
|
+
// shared executor or its six schemas. No approval/executor is entered here.
|
|
13
|
+
const writes = new Set(['Write', 'Edit', 'Bash']);
|
|
14
|
+
const guarded = options.readOnly ? {
|
|
15
|
+
get tools() { return options.bridge?.tools ?? []; },
|
|
16
|
+
isBridge: (name) => writes.has(name) && options.readOnly() || options.bridge?.isBridge(name) === true,
|
|
17
|
+
call: async (name, input, signal) => {
|
|
18
|
+
if (writes.has(name)) {
|
|
19
|
+
options.detail({ kind: 'tool', severity: 'info', code: 'EMPLOYEE_READ_ONLY', summary: '当前为只读档,员工写操作已拒绝,未请求审批。', payload: { tool: name } });
|
|
20
|
+
return { isError: true, content: [{ type: 'text', text: 'EMPLOYEE_READ_ONLY:当前为只读档,此员工写操作未执行。' }] };
|
|
167
21
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
options.closeDiagnostics?.record({ layer: 'relay', initiator: 'mcp.server-close', reason: 'MCP_CLEANUP', action: 'close' });
|
|
177
|
-
if (server.listening)
|
|
178
|
-
await clean(() => new Promise((yes, no) => server.close(error => error ? no(error) : yes())));
|
|
179
|
-
await clean(() => rm(root, { recursive: true }));
|
|
180
|
-
});
|
|
181
|
-
};
|
|
182
|
-
const aborted = () => { void close({ layer: 'endpoint', initiator: 'mcp.lease-abort', reason: closeCode(options.lease.signal.reason, 'EMPLOYEE_CONTEXT_CHANGED'), action: 'abort' }).catch(() => console.warn('EMPLOYEE_MCP_CLEANUP_FAILED')); };
|
|
183
|
-
try {
|
|
184
|
-
await new Promise((yes, no) => { server.once('error', no); server.listen(socketPath, () => { server.removeListener('error', no); yes(); }); });
|
|
185
|
-
options.lease.signal.addEventListener('abort', aborted, { once: true });
|
|
186
|
-
if (options.lease.signal.aborted)
|
|
187
|
-
throw options.lease.signal.reason;
|
|
188
|
-
return { routing: employeeRouting(options.lease.target, socketPath, options.maxBytes), signal: options.lease.signal, close };
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
await close({ layer: 'relay', initiator: 'mcp.open-failure', reason: closeCode(error, 'MCP_OPEN_FAILED'), action: 'failure' });
|
|
192
|
-
throw error;
|
|
193
|
-
}
|
|
22
|
+
return options.bridge.call(name, input, signal);
|
|
23
|
+
},
|
|
24
|
+
} : undefined;
|
|
25
|
+
return open({ get bridge() { return guarded ?? options.bridge; }, get closeDiagnostics() { return options.closeDiagnostics; },
|
|
26
|
+
context: { get cwd() { return options.lease.target.local.directory.path; }, get shell() { return options.lease.target.endpoint.endpointShell; }, get uid() { return options.lease.target.endpoint.remoteUid; }, get signal() { return options.lease.signal; }, close: cause => options.lease.close(cause) },
|
|
27
|
+
routing: socketPath => employeeRouting(options.lease.target, socketPath, options.maxBytes),
|
|
28
|
+
get maxBytes() { return options.maxBytes; }, get killGraceMs() { return options.killGraceMs; }, activeSignal: () => options.activeSignal(),
|
|
29
|
+
get detail() { return options.detail; }, get captureDetail() { return options.captureDetail ? () => options.captureDetail() : undefined; }, get runShell() { return options.runShell; }, }, runtime);
|
|
194
30
|
}
|