@ai-workbench/remote-agent 0.9.0-toolbridge.11 → 0.9.0-toolbridge.13
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 +9 -5
- package/dist/client.js +1 -1
- package/dist/close-diagnostics.d.ts +1 -1
- package/dist/close-diagnostics.js +1 -1
- package/dist/employee-mcp.js +1 -1
- package/dist/employee-relay.js +148 -1
- package/dist/employee-shell.d.ts +2 -0
- package/dist/employee-shell.js +22 -19
- package/dist/employee-tools.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/input.js +4 -1
- package/dist/toolbridge-table.d.ts +3 -2
- package/dist/toolbridge-table.js +13 -2
- package/dist/toolbridge.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.
|
|
1
|
+
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.13 · 插件 → 添加插件
|
|
2
2
|
|
|
3
3
|
## 含工具桥预发布线
|
|
4
4
|
|
|
5
|
-
本包为 `0.9.0-toolbridge.
|
|
5
|
+
本包为 `0.9.0-toolbridge.13`,从 `v0.9.0-toolbridge.12` 派生,使用 `host-toolbridge` 发布渠道。员工安装由连接组件提供的「AI 写作工作台(含工具桥)」总包 `@ai-workbench/workbench-toolbridge@0.1.10`,与不含工具桥的版本二选一。
|
|
6
6
|
|
|
7
7
|
选择本机文件夹后,Claude 和 Codex 可以把 DSH 已启用的 MCP、web、skill、ask_user、todo/present/goal 等工具交给 DSH 原生执行和审批。内置文件/命令、子代理/agent-team、run_code 不在桥接表;原有文件和命令执行方式保留。plan 不自动放行桥接权限;default 下 Claude 的桥接原生权限由插件单次应答,员工只在 DSH 审批实际工具。主机文件夹不开放工具桥。
|
|
8
8
|
|
|
@@ -16,7 +16,11 @@ Codex 需要 S 后续安装的独立受保护命令 `/usr/local/aw-host/bin/code
|
|
|
16
16
|
|
|
17
17
|
需要远程主机连接组件 0.7.37 或更新的 0.7.x、联网助手 0.4.9,以及支持公开会话归属接口的主机组件 S0.4.26。主机来源保存于官方 storage.domain 的会话元数据表,每轮仅由连接组件检查一次主机目录,不检查本机占位目录。
|
|
18
18
|
|
|
19
|
-
Claude
|
|
19
|
+
Claude 员工MCP的stdio通道保持在当前原生客户端上。底层员工SSH/Unix流断开时,在途工具只返回结果未知,不重放;连接恢复后下一次新工具调用串行重新连接并初始化。同一DSH会话无需新建;若连接/绑定已撤销或DSH桥工具在途结束本轮,网络恢复后在原会话发新消息,沿原生编号续接。只使用原已核验的设备/账户/绑定,不跨代偷接。
|
|
20
|
+
|
|
21
|
+
DSH技能工具仅使用DSH公布的目录,主机原生技能按各自原生指令加载;工具描述标明目录快照与返回的资源基址。
|
|
22
|
+
|
|
23
|
+
Claude 本机 Bash 会单独消费员工桥代理的控制诊断,不把它交给模型当作命令输出;真实传输中断仍提示结果未知。命令自身的标准输出、标准错误与退出码照常返回。非UTF-8流不拒绝,按原始字节base64返回并增加对应stdoutEncoding/stderrEncoding标记;有效UTF-8格式不变。没有新增原始字节上限,编码后的消息沿既有512MB容量核验。
|
|
20
24
|
|
|
21
25
|
模型列表读取会随连接状态或连接代际变化取消,连接恢复时通过官方机制刷新。目录失败原因写入当前 profile 的 `ai-workbench-remote-agent/logs/model-catalog.jsonl`(脱敏);未增加单次读取时限或重试。
|
|
22
26
|
|
|
@@ -47,7 +51,7 @@ Codex 员工端只使用随包提供的原生组件,通道等待本次组件
|
|
|
47
51
|
|
|
48
52
|
| 参数 | 默认值 | 作用 |
|
|
49
53
|
| --- | ---: | --- |
|
|
50
|
-
| acpMaxMessageBytes |
|
|
54
|
+
| acpMaxMessageBytes | 512000000 | 会话消息容量;默认512 MB(十进制),自有Codex适配器接收参数另留协议外壳余量;不代表模型上下文或上游Claude适配器承诺 |
|
|
51
55
|
| brokerMaxFrameBytes | 2097152 | 主机回传单段容量 |
|
|
52
56
|
| brokerControlMaxBytes | 1048576 | 主机会话管理回复容量 |
|
|
53
57
|
| employeeShellKillGraceMs | 1000 | 本机命令连接取消后的清理宽限毫秒 |
|
|
@@ -56,7 +60,7 @@ Codex 员工端只使用随包提供的原生组件,通道等待本次组件
|
|
|
56
60
|
|
|
57
61
|
## 技术详情与交付
|
|
58
62
|
|
|
59
|
-
技术详情只写官方 profile
|
|
63
|
+
技术详情只写官方 profile 下本地私有日志,并由既有技术详情界面展开显示。写入失败不覆盖原始错误、不等待远端投递回执。连接与独立工具操作分别保留首次关闭原因,普通工具退出不再占用连接首因;首先观察到的原因不自动等同跨层根因。
|
|
60
64
|
|
|
61
65
|
工程验证和独立审查见 `docs/evidence/2026-10-25-X-host-source-v2/`;AUTH profile 夹具补齐与最终 main 全套复验见其中的 `auth-profile-return.md`。固定包摘要及真实设备验收状态以项目 X 回执为准。插件不修改 DSH 核心,不添加启动器或自定义 profile。
|
|
62
66
|
|
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":"两位远程助手的完整会话消息;默认
|
|
3
|
+
const settingsFields=[{"key":"acpMaxMessageBytes","name":"完整消息与工具输出容量(字节)","kind":"number","min":1,"max":9007199254740991,"range":"1~9007199254740991 的整数;0不能关闭上限","scope":"两位远程助手的完整会话消息;默认512 MB(512000000字节)。也用于模型目录、本机 MCP、员工执行 RPC 和工具输出容量。","when":"当轮快照不变;下一次独立调用或目录查询读取新值。","consequence":"调大可接收更大消息、占用更多内存;调小更早拒绝超限。超限明确停止,不截断、不自动重试;不能用0取消完整消息保护。","defaultValue":512000000},{"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;
|
|
@@ -31,7 +31,7 @@ export declare class CloseDiagnostics {
|
|
|
31
31
|
get first(): Readonly<Record<string, unknown>> | undefined;
|
|
32
32
|
bind(sink: (detail: DetailObservation) => void): void;
|
|
33
33
|
capture(): CloseObserver;
|
|
34
|
-
child(sink?: (detail: DetailObservation) => void): CloseDiagnostics;
|
|
34
|
+
child(sink?: (detail: DetailObservation) => void, independent?: boolean): CloseDiagnostics;
|
|
35
35
|
record(cause: CloseCause): void;
|
|
36
36
|
private recordUsing;
|
|
37
37
|
}
|
|
@@ -13,7 +13,7 @@ export class CloseDiagnostics {
|
|
|
13
13
|
get first() { return this.state.first; }
|
|
14
14
|
bind(sink) { this.sink = sink; }
|
|
15
15
|
capture() { const sink = this.sink; return cause => this.recordUsing(sink, cause); }
|
|
16
|
-
child(sink = this.sink) { return new CloseDiagnostics(sink, this.state); }
|
|
16
|
+
child(sink = this.sink, independent = false) { return new CloseDiagnostics(sink, independent ? {} : this.state); }
|
|
17
17
|
record(cause) { this.recordUsing(this.sink, cause); }
|
|
18
18
|
recordUsing(sink, cause) {
|
|
19
19
|
if (this.state.first)
|
package/dist/employee-mcp.js
CHANGED
|
@@ -8,7 +8,7 @@ import { createEmployeeTools } from "./employee-tools.js";
|
|
|
8
8
|
import { employeeRouting } from "./employee-relay.js";
|
|
9
9
|
import { NeedError } from "./remote.js";
|
|
10
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 } }; }
|
|
11
|
+
function schema(name, properties, required) { return { name, description: '在员工电脑所选工作区执行' + name + ';不在主机回退。' + (name === 'Bash' ? '输出原样保留:若stdoutEncoding或stderrEncoding为base64,对应字符串为原始字节的base64编码,按标明编码处理;退出状态独立保留。' : ''), inputSchema: { type: 'object', properties, required, additionalProperties: false } }; }
|
|
12
12
|
export const EMPLOYEE_MCP_TOOLS = [
|
|
13
13
|
schema('Read', { file_path: string, offset: integer, limit: integer, pages: string }, ['file_path']),
|
|
14
14
|
schema('Write', { file_path: string, content: string }, ['file_path', 'content']),
|
package/dist/employee-relay.js
CHANGED
|
@@ -37,7 +37,154 @@ export const EMPLOYEE_RELAY_PYTHON = EMPLOYEE_TARGET_PYTHON + String.raw `
|
|
|
37
37
|
socket=x["socketPath"]
|
|
38
38
|
if not isinstance(socket,str) or not socket.startswith("/") or "\x00" in socket:fail("EMPLOYEE_RELAY_SOCKET_INVALID")
|
|
39
39
|
command=shlex.join(["/usr/bin/nc","-U",socket])
|
|
40
|
-
|
|
40
|
+
import asyncio,signal
|
|
41
|
+
class Disconnected(Exception):pass
|
|
42
|
+
class Relay:
|
|
43
|
+
def __init__(self,output):
|
|
44
|
+
self.output=output;self.process=None;self.ready=False;self.initialize=None;self.initialized=None;self.serial=0
|
|
45
|
+
self.pending={};self.front_ids={};self.server_ids={};self.readers=set();self.tasks={}
|
|
46
|
+
self.connect_lock=asyncio.Lock();self.write_lock=asyncio.Lock();self.output_lock=asyncio.Lock()
|
|
47
|
+
def identity(self):
|
|
48
|
+
self.serial+=1
|
|
49
|
+
return "aw-relay-"+str(self.serial)
|
|
50
|
+
def encode(self,message):
|
|
51
|
+
data=(json.dumps(message,ensure_ascii=False,separators=(",",":"))+"\n").encode("utf-8",errors="backslashreplace")
|
|
52
|
+
if len(data)-1>maximum:raise Disconnected()
|
|
53
|
+
return data
|
|
54
|
+
async def emit(self,message):
|
|
55
|
+
async with self.output_lock:
|
|
56
|
+
self.output.write(self.encode(message));await self.output.drain()
|
|
57
|
+
async def write(self,process,message):
|
|
58
|
+
async with self.write_lock:
|
|
59
|
+
if process is not self.process:raise Disconnected()
|
|
60
|
+
process.stdin.write(self.encode(message));await process.stdin.drain()
|
|
61
|
+
async def disconnect(self,process,report=True):
|
|
62
|
+
if self.process is process:
|
|
63
|
+
if self.ready and report:sys.stderr.write("CLAUDE_EMPLOYEE_MCP_UNKNOWN\n");sys.stderr.flush()
|
|
64
|
+
self.process=None;self.ready=False
|
|
65
|
+
for key,(owner,future) in list(self.pending.items()):
|
|
66
|
+
if owner is process:
|
|
67
|
+
self.pending.pop(key,None)
|
|
68
|
+
if not future.done():future.set_exception(Disconnected())
|
|
69
|
+
self.server_ids={key:value for key,value in self.server_ids.items() if value[0] is not process}
|
|
70
|
+
if process.stdin:process.stdin.close()
|
|
71
|
+
if process.returncode is None:
|
|
72
|
+
try:process.kill()
|
|
73
|
+
except ProcessLookupError:pass
|
|
74
|
+
await process.wait()
|
|
75
|
+
async def read(self,process):
|
|
76
|
+
try:
|
|
77
|
+
while True:
|
|
78
|
+
line=await process.stdout.readline()
|
|
79
|
+
if not line:break
|
|
80
|
+
message=json.loads(line)
|
|
81
|
+
if process is not self.process:continue
|
|
82
|
+
key=message.get("id")
|
|
83
|
+
if "method" not in message and key in self.pending:
|
|
84
|
+
owner,future=self.pending.pop(key)
|
|
85
|
+
if owner is process and not future.done():future.set_result(message)
|
|
86
|
+
elif "method" in message and self.ready:
|
|
87
|
+
if message["method"]=="notifications/cancelled":
|
|
88
|
+
original=message.get("params",{}).get("requestId")
|
|
89
|
+
front=next((key for key,value in self.server_ids.items() if value==(process,original)),None)
|
|
90
|
+
if front is None:continue
|
|
91
|
+
message={**message,"params":{**message["params"],"requestId":front}}
|
|
92
|
+
if "id" in message:
|
|
93
|
+
front=self.identity();self.server_ids[front]=(process,key);message={**message,"id":front}
|
|
94
|
+
await self.emit(message)
|
|
95
|
+
except (OSError,ValueError,Disconnected):pass
|
|
96
|
+
finally:await self.disconnect(process)
|
|
97
|
+
async def request(self,process,message):
|
|
98
|
+
key=self.identity();future=asyncio.get_running_loop().create_future();self.pending[key]=(process,future)
|
|
99
|
+
front=message.get("id");self.front_ids[front]=(process,key)
|
|
100
|
+
try:
|
|
101
|
+
try:await self.write(process,{**message,"id":key})
|
|
102
|
+
except (OSError,Disconnected):await self.disconnect(process)
|
|
103
|
+
return await future
|
|
104
|
+
finally:
|
|
105
|
+
self.pending.pop(key,None)
|
|
106
|
+
if self.front_ids.get(front)==(process,key):self.front_ids.pop(front,None)
|
|
107
|
+
async def connect(self):
|
|
108
|
+
async with self.connect_lock:
|
|
109
|
+
if self.process is not None and self.ready:return self.process
|
|
110
|
+
if self.initialize is None:raise Disconnected()
|
|
111
|
+
process=await asyncio.create_subprocess_exec("/usr/bin/ssh","-T",*args,command,stdin=asyncio.subprocess.PIPE,stdout=asyncio.subprocess.PIPE,limit=maximum+1)
|
|
112
|
+
self.process=process;self.ready=False
|
|
113
|
+
reader=asyncio.create_task(self.read(process));self.readers.add(reader);reader.add_done_callback(self.readers.discard)
|
|
114
|
+
try:
|
|
115
|
+
reply=await self.request(process,{"jsonrpc":"2.0","method":"initialize","params":self.initialize})
|
|
116
|
+
if "error" in reply:raise Disconnected()
|
|
117
|
+
await self.write(process,{"jsonrpc":"2.0","method":"notifications/initialized"})
|
|
118
|
+
if process is not self.process:raise Disconnected()
|
|
119
|
+
self.initialized=reply["result"];self.ready=True
|
|
120
|
+
return process
|
|
121
|
+
except asyncio.CancelledError:
|
|
122
|
+
await self.disconnect(process);raise
|
|
123
|
+
except (OSError,KeyError,Disconnected):
|
|
124
|
+
await self.disconnect(process);raise Disconnected()
|
|
125
|
+
async def serve(self,message):
|
|
126
|
+
method=message.get("method");front=message.get("id")
|
|
127
|
+
if method is None:
|
|
128
|
+
owner=self.server_ids.pop(front,None)
|
|
129
|
+
if owner and owner[0] is self.process:
|
|
130
|
+
try:await self.write(owner[0],{**message,"id":owner[1]})
|
|
131
|
+
except (OSError,Disconnected):await self.disconnect(owner[0])
|
|
132
|
+
return
|
|
133
|
+
if "id" not in message:
|
|
134
|
+
if method=="notifications/initialized":return
|
|
135
|
+
if method=="notifications/cancelled":
|
|
136
|
+
request_id=message.get("params",{}).get("requestId");owner=self.front_ids.get(request_id)
|
|
137
|
+
if not owner:
|
|
138
|
+
task=self.tasks.get(request_id)
|
|
139
|
+
if task:task.cancel()
|
|
140
|
+
return
|
|
141
|
+
if owner[0] is not self.process:return
|
|
142
|
+
message={**message,"params":{**message["params"],"requestId":owner[1]}}
|
|
143
|
+
try:await self.write(owner[0],message)
|
|
144
|
+
except (OSError,Disconnected):await self.disconnect(owner[0])
|
|
145
|
+
task=self.tasks.get(request_id)
|
|
146
|
+
if task:task.cancel()
|
|
147
|
+
return
|
|
148
|
+
if self.process is not None and self.ready:
|
|
149
|
+
process=self.process
|
|
150
|
+
try:await self.write(process,message)
|
|
151
|
+
except (OSError,Disconnected):await self.disconnect(process)
|
|
152
|
+
return
|
|
153
|
+
try:
|
|
154
|
+
if method=="initialize":self.initialize=message.get("params",{})
|
|
155
|
+
process=await self.connect()
|
|
156
|
+
reply={"jsonrpc":"2.0","result":self.initialized} if method=="initialize" else await self.request(process,message)
|
|
157
|
+
await self.emit({**reply,"id":front})
|
|
158
|
+
except (OSError,Disconnected):
|
|
159
|
+
text="本机工具连接中断,在途结果未知,没有重放;下一次工具调用会重新建立通道。"
|
|
160
|
+
reply={"result":{"isError":True,"content":[{"type":"text","text":text}]}} if method=="tools/call" else {"error":{"code":-32603,"message":text}}
|
|
161
|
+
await self.emit({"jsonrpc":"2.0","id":front,**reply})
|
|
162
|
+
async def relay():
|
|
163
|
+
loop=asyncio.get_running_loop();current=asyncio.current_task()
|
|
164
|
+
for sig in [signal.SIGTERM,signal.SIGHUP,signal.SIGINT]:loop.add_signal_handler(sig,current.cancel)
|
|
165
|
+
input=asyncio.StreamReader(limit=maximum+1);protocol=asyncio.StreamReaderProtocol(input)
|
|
166
|
+
await loop.connect_read_pipe(lambda:protocol,sys.stdin.buffer)
|
|
167
|
+
transport,protocol=await loop.connect_write_pipe(asyncio.streams.FlowControlMixin,sys.stdout.buffer)
|
|
168
|
+
output=asyncio.StreamWriter(transport,protocol,None,loop);proxy=Relay(output);tasks=set()
|
|
169
|
+
try:
|
|
170
|
+
while True:
|
|
171
|
+
line=await input.readline()
|
|
172
|
+
if not line:break
|
|
173
|
+
message=json.loads(line);task=asyncio.create_task(proxy.serve(message));tasks.add(task)
|
|
174
|
+
if "method" in message and "id" in message:proxy.tasks[message["id"]]=task
|
|
175
|
+
def finished(done,front=message.get("id")):
|
|
176
|
+
tasks.discard(done)
|
|
177
|
+
if proxy.tasks.get(front) is done:proxy.tasks.pop(front,None)
|
|
178
|
+
if not done.cancelled() and done.exception() is not None:current.cancel()
|
|
179
|
+
task.add_done_callback(finished)
|
|
180
|
+
finally:
|
|
181
|
+
for task in tasks:task.cancel()
|
|
182
|
+
await asyncio.gather(*tasks,return_exceptions=True)
|
|
183
|
+
if proxy.process is not None:await proxy.disconnect(proxy.process,False)
|
|
184
|
+
await asyncio.gather(*proxy.readers,return_exceptions=True)
|
|
185
|
+
output.close()
|
|
186
|
+
try:asyncio.run(relay())
|
|
187
|
+
except asyncio.CancelledError:pass
|
|
41
188
|
` + EMPLOYEE_PYTHON_ERRORS;
|
|
42
189
|
export function employeeRouting(target, socketPath, maxBytes) {
|
|
43
190
|
const names = ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash'];
|
package/dist/employee-shell.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type { EmployeeEndpointTarget } from './employee-endpoint.ts';
|
|
|
4
4
|
export interface EmployeeShellResult {
|
|
5
5
|
stdout: string;
|
|
6
6
|
stderr: string;
|
|
7
|
+
stdoutEncoding?: 'base64';
|
|
8
|
+
stderrEncoding?: 'base64';
|
|
7
9
|
stderrSource: 'combined-ssh-and-command';
|
|
8
10
|
exitCode: number;
|
|
9
11
|
signal: null;
|
package/dist/employee-shell.js
CHANGED
|
@@ -32,11 +32,19 @@ try:
|
|
|
32
32
|
sys.exit(code if code>=0 else 255)
|
|
33
33
|
` + EMPLOYEE_PYTHON_ERRORS;
|
|
34
34
|
const unknown = (code) => new NeedError(code, '本机命令结果未知;没有重放,也未改在主机执行。', '员工端真实退出回执');
|
|
35
|
+
function output(bytes) {
|
|
36
|
+
try {
|
|
37
|
+
return { text: new TextDecoder('utf8', { fatal: true, ignoreBOM: true }).decode(bytes) };
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return { text: bytes.toString('base64'), encoding: 'base64' };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
35
43
|
/** Use only the target verified at this round lease opening. Cancellation cannot prove remote exit. */
|
|
36
44
|
export function createEmployeeShell(options) {
|
|
37
45
|
return async ({ command, timeout, signal }) => {
|
|
38
46
|
signal.throwIfAborted();
|
|
39
|
-
const diagnostics = options.closeDiagnostics?.child();
|
|
47
|
+
const diagnostics = options.closeDiagnostics?.child(undefined, true);
|
|
40
48
|
const executionId = randomUUID(), target = options.target;
|
|
41
49
|
const child = await options.attach({ command: '/usr/bin/python3', args: ['-c', SHELL_PYTHON, JSON.stringify({ endpoint: target.endpoint, sshArgs: options.sshArgs, cwd: target.local.directory.path, executionId, maxBytes: options.maxBytes })] });
|
|
42
50
|
return new Promise((yes, no) => {
|
|
@@ -58,51 +66,46 @@ export function createEmployeeShell(options) {
|
|
|
58
66
|
no(error);
|
|
59
67
|
return;
|
|
60
68
|
}
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
out = new TextDecoder('utf8', { fatal: true, ignoreBOM: true }).decode(Buffer.concat(stdout));
|
|
64
|
-
err = new TextDecoder('utf8', { fatal: true, ignoreBOM: true }).decode(Buffer.concat(stderr));
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
no(unknown('EMPLOYEE_OUTPUT_BINARY_UNSUPPORTED'));
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const trailer = '\nAW_EMPLOYEE_BRIDGE_RESULT ' + executionId + ' ', end = err.lastIndexOf(trailer);
|
|
69
|
+
let err = Buffer.concat(stderr);
|
|
70
|
+
const trailer = Buffer.from('\nAW_EMPLOYEE_BRIDGE_RESULT ' + executionId + ' '), end = err.lastIndexOf(trailer);
|
|
71
71
|
let bridgeCode;
|
|
72
72
|
if (end >= 0) {
|
|
73
73
|
try {
|
|
74
|
-
const value = JSON.parse(err.
|
|
74
|
+
const value = JSON.parse(err.subarray(end + trailer.length).toString('utf8'));
|
|
75
75
|
if (typeof value === 'string' && /^[A-Z][A-Z0-9_]{0,63}$/.test(value))
|
|
76
76
|
bridgeCode = value;
|
|
77
77
|
else if (value !== null)
|
|
78
78
|
throw Error();
|
|
79
|
-
err = err.
|
|
79
|
+
err = err.subarray(0, end);
|
|
80
80
|
}
|
|
81
81
|
catch {
|
|
82
82
|
no(unknown('EMPLOYEE_EXIT_UNKNOWN'));
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
const header = 'AW_EMPLOYEE_SHELL_READY ' + executionId + '\n', started = 'AW_EMPLOYEE_SHELL_STARTED ' + executionId + '\n';
|
|
86
|
+
const header = Buffer.from('AW_EMPLOYEE_SHELL_READY ' + executionId + '\n'), started = Buffer.from('AW_EMPLOYEE_SHELL_STARTED ' + executionId + '\n');
|
|
88
87
|
const start = err.indexOf(started, header.length);
|
|
89
|
-
if (!err.
|
|
90
|
-
const raw = err.
|
|
88
|
+
if (!err.subarray(0, header.length).equals(header) || start < header.length || start > header.length && err[start - 1] !== 10) {
|
|
89
|
+
const raw = err.subarray(0, header.length).equals(header) ? err.subarray(header.length) : err;
|
|
91
90
|
let source;
|
|
92
91
|
try {
|
|
93
|
-
const parsed = JSON.parse(raw);
|
|
92
|
+
const parsed = JSON.parse(raw.toString('utf8'));
|
|
94
93
|
if (typeof parsed.code === 'string' && /^[A-Z][A-Z0-9_]{0,63}$/.test(parsed.code))
|
|
95
94
|
source = parsed.code;
|
|
96
95
|
}
|
|
97
96
|
catch { /* Never expose arbitrary transport diagnostics. */ }
|
|
97
|
+
diagnostics?.record({ layer: 'relay', initiator: 'shell.process-close', reason: bridgeCode ?? source ?? 'EMPLOYEE_EXIT_UNKNOWN', action: 'failure', exitCode: code ?? null, signal: exitSignal ?? null });
|
|
98
98
|
no(unknown(bridgeCode ?? source ?? 'EMPLOYEE_EXIT_UNKNOWN'));
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
101
|
if (code === null || code === undefined || code === 255 || end < 0) {
|
|
102
|
+
diagnostics?.record({ layer: 'relay', initiator: 'shell.process-close', reason: bridgeCode ?? 'EMPLOYEE_EXIT_UNKNOWN', action: 'failure', exitCode: code ?? null, signal: exitSignal ?? null });
|
|
102
103
|
no(unknown(bridgeCode ?? 'EMPLOYEE_EXIT_UNKNOWN'));
|
|
103
104
|
return;
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
+
diagnostics?.record({ layer: 'relay', initiator: 'shell.process-close', reason: 'PROCESS_EXIT', operation: 'completed', action: 'exit', exitCode: code, signal: exitSignal ?? null, ...bridgeCode ? { remoteReason: bridgeCode } : {} });
|
|
107
|
+
const out = output(Buffer.concat(stdout)), diagnostic = output(Buffer.concat([err.subarray(header.length, start), err.subarray(start + started.length)]));
|
|
108
|
+
yes({ stdout: out.text, stderr: diagnostic.text, ...out.encoding ? { stdoutEncoding: out.encoding } : {}, ...diagnostic.encoding ? { stderrEncoding: diagnostic.encoding } : {}, stderrSource: 'combined-ssh-and-command', exitCode: code, signal: null });
|
|
106
109
|
};
|
|
107
110
|
const stop = (code) => { diagnostics?.record({ layer: 'executor', initiator: 'shell.stop', reason: code, action: 'terminate', changes: [{ field: 'shell.stop-code', before: reason?.code ?? null, after: settled || reason ? reason?.code ?? null : code }] }); if (settled || reason)
|
|
108
111
|
return; reason = unknown(code); child.kill('SIGTERM'); grace = setTimeout(() => { if (child.exitCode === null && child.signalCode === null) {
|
package/dist/employee-tools.js
CHANGED
|
@@ -94,7 +94,7 @@ export function createEmployeeTools(options) {
|
|
|
94
94
|
throw failure('EMPLOYEE_OUTPUT_TOO_LARGE'); };
|
|
95
95
|
async function run(command, args, signal, detail, timeout) {
|
|
96
96
|
signal.throwIfAborted();
|
|
97
|
-
const diagnostics = options.closeDiagnostics?.child(detail);
|
|
97
|
+
const diagnostics = options.closeDiagnostics?.child(detail, true);
|
|
98
98
|
const operation = new Promise((yes, no) => {
|
|
99
99
|
const child = spawn(command, args, { cwd: options.cwd, env: process.env, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
100
100
|
child.stdin.end();
|
|
@@ -118,7 +118,7 @@ export function createEmployeeTools(options) {
|
|
|
118
118
|
} if (signal.aborted)
|
|
119
119
|
aborted(); });
|
|
120
120
|
child.on('error', e => { diagnostics?.record({ layer: 'executor', initiator: 'tools.process-error', reason: e.code === 'ENOENT' ? 'EMPLOYEE_COMMAND_UNAVAILABLE' : 'EMPLOYEE_PROCESS_FAILED', action: 'failure' }); failed ??= failure(e.code === 'ENOENT' ? 'EMPLOYEE_COMMAND_UNAVAILABLE' : 'EMPLOYEE_PROCESS_FAILED'); });
|
|
121
|
-
child.on('close', (exitCode, exitSignal) => { diagnostics?.record({ layer: 'executor', initiator: 'tools.process-close', reason: failed?.code ?? 'PROCESS_EXIT', action: 'exit', exitCode, signal: exitSignal }); signal.removeEventListener('abort', aborted); if (killTimer)
|
|
121
|
+
child.on('close', (exitCode, exitSignal) => { diagnostics?.record({ layer: 'executor', initiator: 'tools.process-close', reason: failed?.code ?? 'PROCESS_EXIT', ...!failed && !exitSignal && exitCode !== null ? { operation: 'completed' } : {}, action: 'exit', exitCode, signal: exitSignal }); signal.removeEventListener('abort', aborted); if (killTimer)
|
|
122
122
|
clearTimeout(killTimer); if (timeoutTimer)
|
|
123
123
|
clearTimeout(timeoutTimer); failed ? no(failed) : yes({ stdout: Buffer.concat(stdout).toString('utf8'), stderr: Buffer.concat(stderr).toString('utf8'), exitCode, signal: exitSignal }); });
|
|
124
124
|
signal.addEventListener('abort', aborted, { once: true });
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const settingsNamespace = "ai-workbench-codex";
|
|
|
15
15
|
export declare const inject: string[];
|
|
16
16
|
/** Owner-approved defaults; administrators may override through the existing settings. */
|
|
17
17
|
export declare const DEFAULT_CONFIG: Readonly<{
|
|
18
|
-
readonly acpMaxMessageBytes:
|
|
18
|
+
readonly acpMaxMessageBytes: 512000000;
|
|
19
19
|
readonly brokerMaxFrameBytes: 2097152;
|
|
20
20
|
readonly brokerControlMaxBytes: 1048576;
|
|
21
21
|
readonly employeeShellKillGraceMs: 1000;
|
package/dist/index.js
CHANGED
|
@@ -39,9 +39,9 @@ export const settingsNamespace = 'ai-workbench-codex';
|
|
|
39
39
|
// L can be installed/enabled after X; keeping X mounted lets it explain the prerequisite.
|
|
40
40
|
export const inject = ['llm'];
|
|
41
41
|
/** Owner-approved defaults; administrators may override through the existing settings. */
|
|
42
|
-
export const DEFAULT_CONFIG = Object.freeze({ acpMaxMessageBytes:
|
|
42
|
+
export const DEFAULT_CONFIG = Object.freeze({ acpMaxMessageBytes: 512000000, brokerMaxFrameBytes: 2097152, brokerControlMaxBytes: 1048576, employeeShellKillGraceMs: 1000 });
|
|
43
43
|
export const Config = Schema.object({
|
|
44
|
-
acpMaxMessageBytes: Schema.number().min(1).step(1).i18n({ en: 'Session message limit; default
|
|
44
|
+
acpMaxMessageBytes: Schema.number().min(1).step(1).i18n({ en: 'Session message limit; default 512 MB, adjustable by administrators', zh: '会话消息容量;默认512 MB,管理员可调整' }).default(DEFAULT_CONFIG.acpMaxMessageBytes).volatile(),
|
|
45
45
|
brokerMaxFrameBytes: Schema.number().min(1).step(1).i18n({ en: 'Host output chunk limit; default 2 MiB, adjustable by administrators', zh: '主机回传单段容量;默认2 MiB,管理员可调整' }).default(DEFAULT_CONFIG.brokerMaxFrameBytes).volatile(),
|
|
46
46
|
brokerControlMaxBytes: Schema.number().min(1).step(1).i18n({ en: 'Host session control reply limit; default 1 MiB, adjustable by administrators', zh: '主机会话管理回复容量;默认1 MiB,管理员可调整' }).default(DEFAULT_CONFIG.brokerControlMaxBytes).volatile(),
|
|
47
47
|
employeeShellKillGraceMs: Schema.number().min(0).max(2147483647).step(1).i18n({ en: 'Local command SSH cleanup grace in milliseconds; cancellation keeps the remote result unknown', zh: '本机命令SSH取消后的清理宽限毫秒;默认1000,取消仍保留员工端结果未知' }).default(DEFAULT_CONFIG.employeeShellKillGraceMs).volatile(),
|
package/dist/input.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NeedError } from "./remote.js";
|
|
2
|
+
import { dshSkillCatalog } from "./toolbridge-table.js";
|
|
2
3
|
function runtimeSections(message) {
|
|
3
4
|
const source = message.source;
|
|
4
5
|
if (message.role !== 'user' || source?.kind !== 'runtime-context' || source.form !== 'snapshot' || !Array.isArray(source.sections) || message.content.length !== 1 || message.content[0].type !== 'text')
|
|
@@ -138,7 +139,9 @@ export async function prepareInput(options, readImage) {
|
|
|
138
139
|
const before = prompt.length;
|
|
139
140
|
const sections = runtimeSections(message);
|
|
140
141
|
for (const block of message.content) {
|
|
141
|
-
|
|
142
|
+
let prepared = await publicBlock(block, options, readImage);
|
|
143
|
+
if (prepared.type === 'text' && dshSkillCatalog([message]) !== undefined)
|
|
144
|
+
prepared = { ...prepared, text: '以下是DSH的技能目录,供DSH工具skill使用;主机Claude/Codex原生技能按各自原生指令加载。加载后请按<skill_resources>给出的资源基址读取资源。\n' + prepared.text };
|
|
142
145
|
prompt.push(prepared);
|
|
143
146
|
if (sections)
|
|
144
147
|
runtimeSnapshots.set(prepared, sections);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ToolSchema } from '@deepseek-ai/dsh-llm';
|
|
1
|
+
import type { ToolSchema, GenerateOptions } from '@deepseek-ai/dsh-llm';
|
|
2
2
|
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
3
3
|
/** Fixed official tool names; no description heuristics or plugin-name branches. */
|
|
4
4
|
export declare const TOOLBRIDGE_EXCLUDED: readonly ["read", "write", "edit", "read_image", "glob", "grep", "bash", "pwsh", "str_replace_editor", "job_output", "job_list", "job_kill", "load_workspace_dependencies", "terminal_open", "terminal_send", "terminal_read", "terminal_signal", "terminal_close", "terminal_list", "subagent", "list_subagent_models", "send_message", "interrupt_agent", "spawn_teammate", "list_agents", "wait_agent", "team_task_create", "team_task_list", "team_task_get", "team_task_update", "run_code"];
|
|
@@ -7,4 +7,5 @@ export interface BridgeTool {
|
|
|
7
7
|
schema: ToolSchema;
|
|
8
8
|
wire: Tool;
|
|
9
9
|
}
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function dshSkillCatalog(messages?: GenerateOptions['messages']): readonly string[] | undefined;
|
|
11
|
+
export declare function bridgeTable(tools?: readonly ToolSchema[], catalog?: readonly string[]): ReadonlyMap<string, BridgeTool>;
|
package/dist/toolbridge-table.js
CHANGED
|
@@ -9,7 +9,17 @@ export const TOOLBRIDGE_EXCLUDED = Object.freeze([
|
|
|
9
9
|
'team_task_create', 'team_task_list', 'team_task_get', 'team_task_update', 'run_code',
|
|
10
10
|
]);
|
|
11
11
|
const excluded = new Set(TOOLBRIDGE_EXCLUDED);
|
|
12
|
-
export function
|
|
12
|
+
export function dshSkillCatalog(messages = []) {
|
|
13
|
+
for (const message of messages.toReversed()) {
|
|
14
|
+
const source = message.source;
|
|
15
|
+
if (message.role !== 'user' || source?.kind !== 'skill-catalog' || source.form !== 'catalog' || !Array.isArray(source.entries))
|
|
16
|
+
continue;
|
|
17
|
+
if (!source.entries.every(entry => entry && typeof entry.name === 'string' && typeof entry.description === 'string'))
|
|
18
|
+
continue;
|
|
19
|
+
return source.entries.map(entry => entry.name);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function bridgeTable(tools = [], catalog) {
|
|
13
23
|
const table = new Map(), names = new Set();
|
|
14
24
|
for (const tool of tools) {
|
|
15
25
|
if (excluded.has(tool.name))
|
|
@@ -21,7 +31,8 @@ export function bridgeTable(tools = []) {
|
|
|
21
31
|
if (table.has(alias))
|
|
22
32
|
throw new NeedError('TOOLBRIDGE_NAME_COLLISION', '工具桥名称冲突,未执行。', '唯一工具桥名称');
|
|
23
33
|
const schema = structuredClone(tool);
|
|
24
|
-
|
|
34
|
+
const skill = schema.name === 'skill' ? ' 这是DSH技能加载器,名字取自DSH的<available_skills>目录;主机Claude/Codex的原生技能按各自原生技能指令加载。' + (catalog === undefined ? '请以当前DSH技能目录为准。' : '本次DSH公布的目录快照:' + JSON.stringify(catalog) + ';实际可用性由DSH调用时确认。') + '技能资源按返回的<skill_resources>基址读取。' : '';
|
|
35
|
+
table.set(alias, { alias, schema, wire: { name: alias, description: 'DSH工具 ' + schema.name + ':' + schema.description + skill, inputSchema: structuredClone(schema.parameters) } });
|
|
25
36
|
}
|
|
26
37
|
return table;
|
|
27
38
|
}
|
package/dist/toolbridge.js
CHANGED
|
@@ -4,7 +4,7 @@ import { mkdtemp, lstat, rm } from 'node:fs/promises';
|
|
|
4
4
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
5
|
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
import { EmployeeSocketTransport } from "./employee-mcp.js";
|
|
7
|
-
import { bridgeTable } from "./toolbridge-table.js";
|
|
7
|
+
import { bridgeTable, dshSkillCatalog } from "./toolbridge-table.js";
|
|
8
8
|
import { NeedError } from "./remote.js";
|
|
9
9
|
export const TOOLBRIDGE_TIMEOUT_SECONDS = 1800;
|
|
10
10
|
export const TOOLBRIDGE_NOTICE = '含工具桥:本机文件夹的扩展工具由DSH执行并按当前权限审批;文件和命令保持原执行方式。工具表在新一轮主机连接时更新。';
|
|
@@ -16,7 +16,7 @@ export class ToolBridge {
|
|
|
16
16
|
readImage;
|
|
17
17
|
controller = new AbortController();
|
|
18
18
|
snapshot;
|
|
19
|
-
get table() { return this.snapshot ??= bridgeTable(this.options.tools); }
|
|
19
|
+
get table() { return this.snapshot ??= bridgeTable(this.options.tools, dshSkillCatalog(this.options.messages)); }
|
|
20
20
|
calls = new Map();
|
|
21
21
|
enabled = false;
|
|
22
22
|
ended = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-workbench/remote-agent",
|
|
3
|
-
"version": "0.9.0-toolbridge.
|
|
3
|
+
"version": "0.9.0-toolbridge.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"publishConfig": {
|
|
113
113
|
"access": "public",
|
|
114
114
|
"registry": "https://registry.npmjs.org/",
|
|
115
|
-
"tag": "toolbridge"
|
|
115
|
+
"tag": "host-toolbridge"
|
|
116
116
|
},
|
|
117
117
|
"keywords": [
|
|
118
118
|
"dsh",
|