@ai-workbench/remote-agent 0.9.0-toolbridge.7 → 0.9.0-toolbridge.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +2 -11
  2. package/dist/acp.d.ts +0 -4
  3. package/dist/acp.js +6 -42
  4. package/dist/agents.d.ts +0 -2
  5. package/dist/agents.js +3 -4
  6. package/dist/claude-local.d.ts +0 -1
  7. package/dist/claude-local.js +2 -2
  8. package/dist/client.js +1 -1
  9. package/dist/employee-mcp.d.ts +24 -8
  10. package/dist/employee-mcp.js +188 -24
  11. package/dist/employee-tools.d.ts +22 -5
  12. package/dist/employee-tools.js +292 -4
  13. package/dist/index.d.ts +0 -4
  14. package/dist/index.js +15 -31
  15. package/dist/model-catalog.d.ts +1 -1
  16. package/dist/model-catalog.js +0 -4
  17. package/dist/presentation.js +0 -1
  18. package/dist/provider.js +2 -4
  19. package/dist/toolbridge-loop.js +0 -3
  20. package/dist/toolbridge-table.js +1 -4
  21. package/dist/toolbridge.d.ts +0 -1
  22. package/dist/toolbridge.js +0 -1
  23. package/helpers/ripgrep/LICENSE-vscode +13 -0
  24. package/helpers/ripgrep/PROVENANCE.md +9 -0
  25. package/helpers/ripgrep/darwin-arm64/rg +0 -0
  26. package/helpers/ripgrep/darwin-x64/rg +0 -0
  27. package/helpers/ripgrep/manifest.json +56 -0
  28. package/helpers/ripgrep/notices/COPYING-ripgrep +3 -0
  29. package/helpers/ripgrep/notices/DEPENDENCIES.json +946 -0
  30. package/helpers/ripgrep/notices/LICENCE-PCRE2.md +103 -0
  31. package/helpers/ripgrep/notices/LICENSE-MIT-ripgrep +21 -0
  32. package/helpers/ripgrep/notices/UNLICENSE-ripgrep +24 -0
  33. package/helpers/ripgrep/notices/aho-corasick-1.1.3/COPYING +3 -0
  34. package/helpers/ripgrep/notices/aho-corasick-1.1.3/LICENSE-MIT +21 -0
  35. package/helpers/ripgrep/notices/aho-corasick-1.1.3/UNLICENSE +24 -0
  36. package/helpers/ripgrep/notices/anyhow-1.0.100/LICENSE-APACHE +176 -0
  37. package/helpers/ripgrep/notices/anyhow-1.0.100/LICENSE-MIT +23 -0
  38. package/helpers/ripgrep/notices/arbitrary-1.4.2/LICENSE-APACHE +201 -0
  39. package/helpers/ripgrep/notices/arbitrary-1.4.2/LICENSE-MIT +27 -0
  40. package/helpers/ripgrep/notices/bstr-1.12.0/COPYING +8 -0
  41. package/helpers/ripgrep/notices/bstr-1.12.0/LICENSE-APACHE +201 -0
  42. package/helpers/ripgrep/notices/bstr-1.12.0/LICENSE-MIT +21 -0
  43. package/helpers/ripgrep/notices/cc-1.2.41/LICENSE-APACHE +201 -0
  44. package/helpers/ripgrep/notices/cc-1.2.41/LICENSE-MIT +25 -0
  45. package/helpers/ripgrep/notices/cfg-if-1.0.4/LICENSE-APACHE +201 -0
  46. package/helpers/ripgrep/notices/cfg-if-1.0.4/LICENSE-MIT +25 -0
  47. package/helpers/ripgrep/notices/crossbeam-channel-0.5.15/LICENSE-APACHE +201 -0
  48. package/helpers/ripgrep/notices/crossbeam-channel-0.5.15/LICENSE-MIT +27 -0
  49. package/helpers/ripgrep/notices/crossbeam-channel-0.5.15/LICENSE-THIRD-PARTY +593 -0
  50. package/helpers/ripgrep/notices/crossbeam-deque-0.8.6/LICENSE-APACHE +201 -0
  51. package/helpers/ripgrep/notices/crossbeam-deque-0.8.6/LICENSE-MIT +27 -0
  52. package/helpers/ripgrep/notices/crossbeam-epoch-0.9.18/LICENSE-APACHE +201 -0
  53. package/helpers/ripgrep/notices/crossbeam-epoch-0.9.18/LICENSE-MIT +27 -0
  54. package/helpers/ripgrep/notices/crossbeam-utils-0.8.21/LICENSE-APACHE +201 -0
  55. package/helpers/ripgrep/notices/crossbeam-utils-0.8.21/LICENSE-MIT +27 -0
  56. package/helpers/ripgrep/notices/derive_arbitrary-1.4.2/LICENSE-APACHE +201 -0
  57. package/helpers/ripgrep/notices/derive_arbitrary-1.4.2/LICENSE-MIT +27 -0
  58. package/helpers/ripgrep/notices/encoding_rs-0.8.35/COPYRIGHT +17 -0
  59. package/helpers/ripgrep/notices/encoding_rs-0.8.35/LICENSE-APACHE +202 -0
  60. package/helpers/ripgrep/notices/encoding_rs-0.8.35/LICENSE-MIT +25 -0
  61. package/helpers/ripgrep/notices/encoding_rs-0.8.35/LICENSE-WHATWG +26 -0
  62. package/helpers/ripgrep/notices/encoding_rs_io-0.1.7/COPYING +8 -0
  63. package/helpers/ripgrep/notices/encoding_rs_io-0.1.7/LICENSE-APACHE +201 -0
  64. package/helpers/ripgrep/notices/encoding_rs_io-0.1.7/LICENSE-MIT +21 -0
  65. package/helpers/ripgrep/notices/find-msvc-tools-0.1.4/LICENSE-APACHE +201 -0
  66. package/helpers/ripgrep/notices/find-msvc-tools-0.1.4/LICENSE-MIT +25 -0
  67. package/helpers/ripgrep/notices/getrandom-0.3.4/LICENSE-APACHE +201 -0
  68. package/helpers/ripgrep/notices/getrandom-0.3.4/LICENSE-MIT +26 -0
  69. package/helpers/ripgrep/notices/glob-0.3.3/LICENSE-APACHE +201 -0
  70. package/helpers/ripgrep/notices/glob-0.3.3/LICENSE-MIT +25 -0
  71. package/helpers/ripgrep/notices/itoa-1.0.15/LICENSE-APACHE +176 -0
  72. package/helpers/ripgrep/notices/itoa-1.0.15/LICENSE-MIT +23 -0
  73. package/helpers/ripgrep/notices/jobserver-0.1.34/LICENSE-APACHE +201 -0
  74. package/helpers/ripgrep/notices/jobserver-0.1.34/LICENSE-MIT +25 -0
  75. package/helpers/ripgrep/notices/lexopt-0.3.1/LICENSE +19 -0
  76. package/helpers/ripgrep/notices/libc-0.2.177/LICENSE-APACHE +176 -0
  77. package/helpers/ripgrep/notices/libc-0.2.177/LICENSE-MIT +25 -0
  78. package/helpers/ripgrep/notices/log-0.4.28/LICENSE-APACHE +201 -0
  79. package/helpers/ripgrep/notices/log-0.4.28/LICENSE-MIT +25 -0
  80. package/helpers/ripgrep/notices/memchr-2.7.6/COPYING +3 -0
  81. package/helpers/ripgrep/notices/memchr-2.7.6/LICENSE-MIT +21 -0
  82. package/helpers/ripgrep/notices/memchr-2.7.6/UNLICENSE +24 -0
  83. package/helpers/ripgrep/notices/memmap2-0.9.8/LICENSE-APACHE +201 -0
  84. package/helpers/ripgrep/notices/memmap2-0.9.8/LICENSE-MIT +26 -0
  85. package/helpers/ripgrep/notices/msvc_spectre_libs-0.1.3/LICENSE +21 -0
  86. package/helpers/ripgrep/notices/pcre2-0.2.11/COPYING +3 -0
  87. package/helpers/ripgrep/notices/pcre2-0.2.11/LICENSE-MIT +21 -0
  88. package/helpers/ripgrep/notices/pcre2-0.2.11/UNLICENSE +24 -0
  89. package/helpers/ripgrep/notices/pcre2-sys-0.2.10/COPYING +3 -0
  90. package/helpers/ripgrep/notices/pcre2-sys-0.2.10/LICENSE-MIT +21 -0
  91. package/helpers/ripgrep/notices/pcre2-sys-0.2.10/UNLICENSE +24 -0
  92. package/helpers/ripgrep/notices/pkg-config-0.3.32/LICENSE-APACHE +201 -0
  93. package/helpers/ripgrep/notices/pkg-config-0.3.32/LICENSE-MIT +25 -0
  94. package/helpers/ripgrep/notices/proc-macro2-1.0.101/LICENSE-APACHE +176 -0
  95. package/helpers/ripgrep/notices/proc-macro2-1.0.101/LICENSE-MIT +23 -0
  96. package/helpers/ripgrep/notices/quote-1.0.41/LICENSE-APACHE +176 -0
  97. package/helpers/ripgrep/notices/quote-1.0.41/LICENSE-MIT +23 -0
  98. package/helpers/ripgrep/notices/r-efi-5.3.0/AUTHORS +74 -0
  99. package/helpers/ripgrep/notices/regex-1.12.2/LICENSE-APACHE +201 -0
  100. package/helpers/ripgrep/notices/regex-1.12.2/LICENSE-MIT +25 -0
  101. package/helpers/ripgrep/notices/regex-automata-0.4.13/LICENSE-APACHE +201 -0
  102. package/helpers/ripgrep/notices/regex-automata-0.4.13/LICENSE-MIT +25 -0
  103. package/helpers/ripgrep/notices/regex-syntax-0.8.8/LICENSE-APACHE +201 -0
  104. package/helpers/ripgrep/notices/regex-syntax-0.8.8/LICENSE-MIT +25 -0
  105. package/helpers/ripgrep/notices/regex-syntax-0.8.8/src/unicode_tables/LICENSE-UNICODE +57 -0
  106. package/helpers/ripgrep/notices/ryu-1.0.20/LICENSE-APACHE +176 -0
  107. package/helpers/ripgrep/notices/ryu-1.0.20/LICENSE-BOOST +23 -0
  108. package/helpers/ripgrep/notices/same-file-1.0.6/COPYING +3 -0
  109. package/helpers/ripgrep/notices/same-file-1.0.6/LICENSE-MIT +21 -0
  110. package/helpers/ripgrep/notices/same-file-1.0.6/UNLICENSE +24 -0
  111. package/helpers/ripgrep/notices/serde-1.0.228/LICENSE-APACHE +176 -0
  112. package/helpers/ripgrep/notices/serde-1.0.228/LICENSE-MIT +23 -0
  113. package/helpers/ripgrep/notices/serde_core-1.0.228/LICENSE-APACHE +176 -0
  114. package/helpers/ripgrep/notices/serde_core-1.0.228/LICENSE-MIT +23 -0
  115. package/helpers/ripgrep/notices/serde_derive-1.0.228/LICENSE-APACHE +176 -0
  116. package/helpers/ripgrep/notices/serde_derive-1.0.228/LICENSE-MIT +23 -0
  117. package/helpers/ripgrep/notices/serde_json-1.0.145/LICENSE-APACHE +176 -0
  118. package/helpers/ripgrep/notices/serde_json-1.0.145/LICENSE-MIT +23 -0
  119. package/helpers/ripgrep/notices/shlex-1.3.0/LICENSE-APACHE +13 -0
  120. package/helpers/ripgrep/notices/shlex-1.3.0/LICENSE-MIT +21 -0
  121. package/helpers/ripgrep/notices/syn-2.0.106/LICENSE-APACHE +176 -0
  122. package/helpers/ripgrep/notices/syn-2.0.106/LICENSE-MIT +23 -0
  123. package/helpers/ripgrep/notices/termcolor-1.4.1/COPYING +3 -0
  124. package/helpers/ripgrep/notices/termcolor-1.4.1/LICENSE-MIT +21 -0
  125. package/helpers/ripgrep/notices/termcolor-1.4.1/UNLICENSE +24 -0
  126. package/helpers/ripgrep/notices/textwrap-0.16.2/LICENSE +21 -0
  127. package/helpers/ripgrep/notices/tikv-jemalloc-sys-0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7/LICENSE-APACHE +201 -0
  128. package/helpers/ripgrep/notices/tikv-jemalloc-sys-0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7/LICENSE-MIT +25 -0
  129. package/helpers/ripgrep/notices/tikv-jemalloc-sys-0.6.0+5.3.0-1-ge13ca993e8ccb9ba9847cc330696e02839f328f7/jemalloc/COPYING +27 -0
  130. package/helpers/ripgrep/notices/tikv-jemallocator-0.6.0/LICENSE-APACHE +201 -0
  131. package/helpers/ripgrep/notices/tikv-jemallocator-0.6.0/LICENSE-MIT +25 -0
  132. package/helpers/ripgrep/notices/unicode-ident-1.0.19/LICENSE-APACHE +176 -0
  133. package/helpers/ripgrep/notices/unicode-ident-1.0.19/LICENSE-MIT +23 -0
  134. package/helpers/ripgrep/notices/unicode-ident-1.0.19/LICENSE-UNICODE +39 -0
  135. package/helpers/ripgrep/notices/walkdir-2.5.0/COPYING +3 -0
  136. package/helpers/ripgrep/notices/walkdir-2.5.0/LICENSE-MIT +21 -0
  137. package/helpers/ripgrep/notices/walkdir-2.5.0/UNLICENSE +24 -0
  138. package/helpers/ripgrep/notices/wasip2-1.0.1+wasi-0.2.4/LICENSE-APACHE +201 -0
  139. package/helpers/ripgrep/notices/wasip2-1.0.1+wasi-0.2.4/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  140. package/helpers/ripgrep/notices/wasip2-1.0.1+wasi-0.2.4/LICENSE-MIT +23 -0
  141. package/helpers/ripgrep/notices/winapi-util-0.1.11/COPYING +3 -0
  142. package/helpers/ripgrep/notices/winapi-util-0.1.11/LICENSE-MIT +21 -0
  143. package/helpers/ripgrep/notices/winapi-util-0.1.11/UNLICENSE +24 -0
  144. package/helpers/ripgrep/notices/windows-link-0.2.1/license-apache-2.0 +201 -0
  145. package/helpers/ripgrep/notices/windows-link-0.2.1/license-mit +21 -0
  146. package/helpers/ripgrep/notices/windows-sys-0.61.2/license-apache-2.0 +201 -0
  147. package/helpers/ripgrep/notices/windows-sys-0.61.2/license-mit +21 -0
  148. package/helpers/ripgrep/notices/wit-bindgen-0.46.0/LICENSE-APACHE +201 -0
  149. package/helpers/ripgrep/notices/wit-bindgen-0.46.0/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  150. package/helpers/ripgrep/notices/wit-bindgen-0.46.0/LICENSE-MIT +23 -0
  151. package/package.json +18 -21
  152. package/dist/cloud-failure.d.ts +0 -11
  153. package/dist/cloud-failure.js +0 -54
package/README.md CHANGED
@@ -1,16 +1,8 @@
1
- # AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.7 · 插件 → 添加插件
1
+ # AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.8 · 插件 → 添加插件
2
2
 
3
3
  ## 含工具桥预发布线
4
4
 
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 执行。
5
+ 本包为 `0.9.0-toolbridge.8`,在独立 `toolbridge` 分支开发;稳定 main/0.8.x 和原总包保持原样。员工安装由连接组件提供的「AI 写作工作台(含工具桥)」总包,与不含工具桥的版本二选一。预发布渠道为 `toolbridge`,本轮仅提供本地固定包,不发布 npm。
14
6
 
15
7
  选择本机文件夹后,Claude 和 Codex 可以把 DSH 已启用的 MCP、web、skill、ask_user、todo/present/goal 等工具交给 DSH 原生执行和审批。内置文件/命令、子代理/agent-team、run_code 不在桥接表;原有文件和命令执行方式保留。plan 不自动放行桥接权限;default 下 Claude 的桥接原生权限由插件单次应答,员工只在 DSH 审批实际工具。主机文件夹不开放工具桥。
16
8
 
@@ -59,7 +51,6 @@ Codex 员工端只使用随包提供的原生组件,通道等待本次组件
59
51
  | brokerMaxFrameBytes | 2097152 | 主机回传单段容量 |
60
52
  | brokerControlMaxBytes | 1048576 | 主机会话管理回复容量 |
61
53
  | employeeShellKillGraceMs | 1000 | 本机命令连接取消后的清理宽限毫秒 |
62
- | cloudCancelReceiptWaitMs | 10000 | 云取消回执最长等待毫秒;1~2147483647,超时以状态未知结束本轮 |
63
54
 
64
55
  容量超限明确失败,不截断成有效消息。参数范围、生效时机和调整后果由官方 schema 与参数页显示;以上四条执行不变量不可关闭。
65
56
 
package/dist/acp.d.ts CHANGED
@@ -9,7 +9,6 @@ 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;
13
12
  closeDiagnostics?: CloseDiagnostics;
14
13
  onUpdate?: (notification: acp.SessionNotification) => void;
15
14
  onResponse?: (response: acp.PromptResponse) => void;
@@ -38,8 +37,6 @@ export interface EmployeeExecutionMeta {
38
37
  acpMaxMessageBytes: number;
39
38
  }
40
39
  export interface AcpStartContext {
41
- routing?: 'native-exec' | 'mcp';
42
- loginProvider?: 'claude' | 'codex';
43
40
  toolBridgeServers?: EmployeeRouting['mcpServers'];
44
41
  systemPrompt?: string;
45
42
  codexNewSessionOnly?: true;
@@ -56,7 +53,6 @@ export declare class AcpSession {
56
53
  private turnSignal?;
57
54
  private turnToken?;
58
55
  private busy;
59
- private cloudCancelReceiptExpired;
60
56
  private startAttempted;
61
57
  private negotiated;
62
58
  private method?;
package/dist/acp.js CHANGED
@@ -7,7 +7,6 @@ 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";
11
10
  function employeeClaudeOptions(routing) { return { tools: [], disallowedTools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash', 'Agent', 'Task', 'TaskOutput', 'TaskStop'], toolAliases: structuredClone(routing.toolAliases) }; }
12
11
  const permissionRanks = { claude: { plan: 0, default: 1, acceptEdits: 1, bypassPermissions: 2 }, codex: { 'read-only': 0, 'workspace-write': 1, agent: 1, 'agent-full-access': 2 } };
13
12
  /** ACP v1 with explicitly negotiated SDK 2.0 lifecycle/context extensions. */
@@ -19,7 +18,6 @@ export class AcpSession {
19
18
  turnSignal;
20
19
  turnToken;
21
20
  busy = false;
22
- cloudCancelReceiptExpired = false;
23
21
  startAttempted = false;
24
22
  negotiated = {};
25
23
  method;
@@ -276,8 +274,6 @@ export class AcpSession {
276
274
  this.closeDiagnostics = hooks.closeDiagnostics ?? new CloseDiagnostics(event => this.detail(event));
277
275
  const app = acp.client({ name: '@ai-workbench/remote-agent' })
278
276
  .onNotification(acp.methods.client.session.update, ({ params: notification }) => {
279
- if (this.cloudCancelReceiptExpired)
280
- return;
281
277
  if (this.creatingReplacement) {
282
278
  if (notification.sessionId !== this.sessionId && notification.update.sessionUpdate === 'config_option_update')
283
279
  this.pendingConfiguration(notification.sessionId, notification.update.configOptions);
@@ -518,7 +514,7 @@ export class AcpSession {
518
514
  signal?.addEventListener('abort', abort, { once: true });
519
515
  try {
520
516
  const hello = await this.stage('acp-initialize', () => this.connection.agent.request(acp.methods.agent.initialize, {
521
- protocolVersion: acp.PROTOCOL_VERSION, clientInfo: { name: '@ai-workbench/remote-agent', version: '0.9.0-toolbridge.7' },
517
+ protocolVersion: acp.PROTOCOL_VERSION, clientInfo: { name: '@ai-workbench/remote-agent', version: '0.9.0-toolbridge.8' },
522
518
  clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false, session: { notices: {} }, ...(this.employeeMeta ? { _meta: { awEmployeeExecution: { version: 1, closeReason: 1, ...(context?.toolBridgeServers ? { mcpBridge: 1 } : {}) } } } : {}) },
523
519
  }, { cancellationSignal: signal }));
524
520
  if (hello.protocolVersion !== acp.PROTOCOL_VERSION)
@@ -535,9 +531,9 @@ export class AcpSession {
535
531
  this.codexNewSessionOnly = !!context?.codexNewSessionOnly;
536
532
  if (prompt)
537
533
  this.validatePrompt(prompt);
538
- const routing = context?.routing !== 'native-exec' && context?.employeeRouting ? structuredClone(context.employeeRouting) : undefined;
534
+ const routing = context?.employeeRouting ? structuredClone(context.employeeRouting) : undefined;
539
535
  this.employeeRouting = routing;
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 }] } } : {}) };
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 }] } } : {}) };
541
537
  const configRevision = this.resetConfiguration();
542
538
  const restore = async (operation) => {
543
539
  try {
@@ -624,33 +620,16 @@ export class AcpSession {
624
620
  } };
625
621
  const expectedPermission = this.selectedPermission, reportedModes = new Set();
626
622
  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的整数毫秒');
632
623
  this.busy = true;
633
624
  this.turnSignal = signal;
634
625
  this.turnToken = Symbol('turn');
635
- let receiptTimer;
636
- let receiptTimeout;
637
626
  let rejectAbort;
638
627
  const interrupted = new Promise((_resolve, reject) => { rejectAbort = reject; });
639
628
  const cancel = () => {
640
629
  this.closeDiagnostics.record({ layer: 'acp', initiator: 'acp.prompt-cancel', reason: 'ABORTED', operation: 'session/prompt', action: 'abort' });
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', '已请求取消本轮,远端状态需确认', '确认主机取消状态'));
630
+ rejectAbort?.(new NeedError('ABORTED', '已请求取消本轮,远端状态需确认', '确认主机取消状态'));
652
631
  void this.connection.agent.notify(acp.methods.agent.session.cancel, { sessionId: this.sessionId }).catch(() => {
653
- this.need({ code: 'CANCEL_UNCONFIRMED', message: cloud ? '云通道已断开,无法确认云任务已结束。' : '连接中断,无法确认主机已取消本轮', requires: cloud ? '恢复云通道以核对任务状态' : '恢复连接以确认远端状态' });
632
+ this.need({ code: 'CANCEL_UNCONFIRMED', message: '连接中断,无法确认主机已取消本轮', requires: '恢复连接以确认远端状态' });
654
633
  });
655
634
  };
656
635
  signal?.addEventListener('abort', cancel, { once: true });
@@ -659,33 +638,18 @@ export class AcpSession {
659
638
  const result = await this.stage('acp-prompt', () => {
660
639
  this.promptPermissions.set(params, { current, native });
661
640
  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.
664
641
  return signal ? Promise.race([request, interrupted]) : request;
665
642
  });
666
- this.hooks.onResponse?.(result);
667
- if (cloud) {
668
- const failure = cloudTurnFailure(result);
669
- if (failure)
670
- throw failure;
671
- }
672
643
  signal?.throwIfAborted();
644
+ this.hooks.onResponse?.(result);
673
645
  return result.stopReason;
674
646
  }
675
647
  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' });
682
648
  if (signal?.aborted)
683
649
  throw new NeedError('ABORTED', '本轮已取消;已请求主机停止', '确认主机取消状态');
684
650
  throw acpNeed(error);
685
651
  }
686
652
  finally {
687
- if (receiptTimer !== undefined)
688
- clearTimeout(receiptTimer);
689
653
  signal?.removeEventListener('abort', cancel);
690
654
  this.turnSignal = undefined;
691
655
  this.busy = false;
package/dist/agents.d.ts CHANGED
@@ -7,10 +7,8 @@ export interface AgentDefinition {
7
7
  }>;
8
8
  readonly command: string;
9
9
  readonly loginProvider: 'claude' | 'codex';
10
- readonly routing: 'native-exec' | 'mcp';
11
10
  }
12
11
  export declare const CODEX_AGENT: AgentDefinition;
13
12
  export declare const CLAUDE_AGENT: AgentDefinition;
14
- export declare const CODEX_CLOUD_AGENT: AgentDefinition;
15
13
  export declare const AGENTS: readonly AgentDefinition[];
16
14
  export declare function agentForProvider(id: string): AgentDefinition | undefined;
package/dist/agents.js CHANGED
@@ -1,5 +1,4 @@
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]);
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 AGENTS = Object.freeze([CODEX_AGENT, CLAUDE_AGENT]);
5
4
  export function agentForProvider(id) { return AGENTS.find(agent => agent.id === id); }
@@ -13,7 +13,6 @@ interface Configuration {
13
13
  employeeShellKillGraceMs?: number;
14
14
  }
15
15
  interface Options {
16
- readOnly?: (sessionId: string) => boolean;
17
16
  getConnect: () => ConnectApi | undefined;
18
17
  getNetwork: () => EmployeeNetworkApi | undefined;
19
18
  readWorkspace: (sessionId: string) => Promise<EmployeeWorkspace>;
@@ -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)({ ...(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)
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)
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, ...(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)
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)
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},{"key":"cloudCancelReceiptWaitMs","name":"云取消回执最长等待(毫秒)","kind":"number","min":1,"max":2147483647,"range":"1~2147483647 的整数;0不能设为无限等待","scope":"仅协商v1云失败合同的取消回执等待;不改变主机助手取消或云任务执行期限。","when":"每轮读取配置快照;取消时开始计时,改动用于下一轮。","consequence":"默认10000毫秒。到时未收到回执则以状态未知、云任务可能仍在运行结束本轮并关闭该ACP通道;迟到回执不能改写结果。调小会更早失去详细回执,调大增加取消等待;不重提任务。","defaultValue":10000}];
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}];
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;
@@ -1,19 +1,35 @@
1
- import { EmployeeSocketTransport as SocketTransport, EMPLOYEE_MCP_TOOLS } from '@ai-workbench/employee-tools';
2
- import type { Socket } from 'node:net';
1
+ import type { ToolBridge } from './toolbridge.ts';
3
2
  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';
4
6
  import type { EmployeeLease } from './employee-endpoint.ts';
5
7
  import { employeeRouting } from './employee-relay.ts';
6
8
  import type { DetailObservation } from './conversation-details.ts';
7
9
  import type { EmployeeShell } from './employee-shell.ts';
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);
10
+ export declare const EMPLOYEE_MCP_TOOLS: Tool[];
11
+ /** Same newline-delimited MCP messages as stdio, over an employee-only Unix stream. */
12
+ export declare class EmployeeSocketTransport implements Transport {
13
+ private socket;
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>;
12
30
  }
13
31
  export interface EmployeeMcpOptions {
14
32
  bridge?: ToolBridge;
15
- /** Current official sandbox mode; X's cloud caller supplies this live getter. */
16
- readOnly?: () => boolean;
17
33
  closeDiagnostics?: CloseDiagnostics;
18
34
  lease: EmployeeLease;
19
35
  maxBytes: number;
@@ -1,30 +1,194 @@
1
- import { openEmployeeMcp as open, EmployeeSocketTransport as SocketTransport, EMPLOYEE_MCP_TOOLS } from '@ai-workbench/employee-tools';
2
- import { NeedError } from "./remote.js";
3
1
  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";
4
8
  import { employeeRouting } from "./employee-relay.js";
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); }
9
+ import { NeedError } from "./remote.js";
10
+ const string = { type: 'string' }, integer = { type: 'integer' }, boolean = { type: 'boolean' };
11
+ function schema(name, properties, required) { return { name, description: '在员工电脑所选工作区执行' + name + ';不在主机回退。', inputSchema: { type: 'object', properties, required, additionalProperties: false } }; }
12
+ export const EMPLOYEE_MCP_TOOLS = [
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
+ } }
9
94
  }
10
95
  export async function openEmployeeMcp(options) {
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:当前为只读档,此员工写操作未执行。' }] };
96
+ if (process.platform !== 'darwin')
97
+ throw new NeedError('EMPLOYEE_PLATFORM_UNSUPPORTED', '本机执行目前只支持Mac。', '已交Mac员工端合同');
98
+ if (!Number.isSafeInteger(options.maxBytes) || options.maxBytes < 1)
99
+ throw new NeedError('SETTINGS_REQUIRED', '本机工具消息容量无效。', 'acpMaxMessageBytes');
100
+ await access('/usr/bin/nc', constants.X_OK);
101
+ const tools = createEmployeeTools({ closeDiagnostics: options.closeDiagnostics, cwd: options.lease.target.local.directory.path, shell: options.lease.target.endpoint.endpointShell, uid: options.lease.target.endpoint.remoteUid, maxBytes: options.maxBytes, killGraceMs: options.killGraceMs, detail: observe, runShell: options.runShell, validate: async (signal) => { signal?.throwIfAborted(); options.lease.signal.throwIfAborted(); } });
102
+ const root = await mkdtemp('/private/tmp/aw-x87-'), socketPath = root + '/mcp';
103
+ try {
104
+ const info = await lstat(root);
105
+ if ((info.mode & 0o077) !== 0 || info.uid !== process.getuid?.())
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();
21
167
  }
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);
168
+ catch {
169
+ console.warn('EMPLOYEE_MCP_CLEANUP_FAILED');
170
+ } };
171
+ for (const transport of transports)
172
+ await clean(() => transport.close({ layer: 'relay', initiator: 'mcp.cleanup-transport', reason: 'MCP_CLEANUP', action: 'close' }));
173
+ await Promise.all([...clients].map(client => clean(() => client.close())));
174
+ await clean(() => tools.close({ layer: 'executor', initiator: 'mcp.cleanup-tools', reason: 'MCP_CLEANUP', action: 'close' }));
175
+ await clean(() => options.lease.close({ layer: 'endpoint', initiator: 'mcp.cleanup-lease', reason: 'MCP_CLEANUP', action: 'close' }));
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
+ }
30
194
  }
@@ -1,7 +1,23 @@
1
- import { type EmployeeToolsOptions } from '@ai-workbench/employee-tools';
2
- export { EMPLOYEE_TOOL_NAMES, type EmployeeToolName } from '@ai-workbench/employee-tools';
3
- export declare function createEmployeeTools(options: EmployeeToolsOptions): {
4
- call(name: string, input: unknown, requestSignal?: AbortSignal, observer?: EmployeeToolsOptions["detail"]): Promise<{
1
+ import { type CloseCause, type CloseDiagnostics } from './close-diagnostics.ts';
2
+ import type { DetailObservation } from './conversation-details.ts';
3
+ import type { EmployeeShell } from './employee-shell.ts';
4
+ export declare const EMPLOYEE_TOOL_NAMES: readonly ["Read", "Write", "Edit", "Glob", "Grep", "Bash"];
5
+ export type EmployeeToolName = typeof EMPLOYEE_TOOL_NAMES[number];
6
+ interface Options {
7
+ closeDiagnostics?: CloseDiagnostics;
8
+ cwd: string;
9
+ shell: string;
10
+ uid: number;
11
+ maxBytes: number;
12
+ killGraceMs: number;
13
+ validate: (signal?: AbortSignal) => Promise<void>;
14
+ detail: (event: DetailObservation) => void;
15
+ rgPath?: string;
16
+ runShell?: EmployeeShell;
17
+ }
18
+ /** Executed only in the employee DSH process; never creates a host fallback. */
19
+ export declare function createEmployeeTools(options: Options): {
20
+ call(name: string, input: unknown, requestSignal?: AbortSignal, observer?: Options["detail"]): Promise<{
5
21
  [x: string]: unknown;
6
22
  content: ({
7
23
  type: "text";
@@ -98,5 +114,6 @@ export declare function createEmployeeTools(options: EmployeeToolsOptions): {
98
114
  } | undefined;
99
115
  isError?: boolean | undefined;
100
116
  }>;
101
- close(cause?: import("@ai-workbench/employee-tools").CloseCause): Promise<void>;
117
+ close(cause?: CloseCause): Promise<void>;
102
118
  };
119
+ export {};