@ai-workbench/remote-agent 0.9.0-toolbridge.36 → 0.9.0-toolbridge.37-rc.5

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 CHANGED
@@ -1,7 +1,14 @@
1
- # AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.36 · 插件 → 添加插件
1
+ # AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.37-rc.5 · 插件 → 添加插件
2
2
 
3
- S7 按 owner 11-15 裁定撤除:删除 `local-user-turn` 及其轮次证明、Claude 专用接纳入口、持久输入核对、历史人类输入回退和专用字段。DSH 原生交给模型的人类输入、子任务通知、代理来信、审批续接及自动轮,统一走原生处理,不另设输入授权门;工具等待与混合插话批仍完整交付通知。L 的 0.7.17 接纳账本已在 0.7.27 删除,不恢复。新增设置、限制、错误码均为0。编排已锁定正式版本X.36/总包0.3.7;验证与历史证据见 `TESTS.md`。
3
+ 本版为 0.3.8 配套的预发布验证版本,正式渠道仍为总包 0.3.7 / X.36。只有三版 DSH、真实模型、主机与独审门全部通过后才转正式。
4
4
 
5
+ 本版撤除插件自行拼写的系统规则、位置说明和技能目录说明。模型接收员工输入、原工具描述、CLI 原生上下文,以及员工显式配置的自定义指令原文。DSH 系统规则不转送;同一 DSH 会话切换品牌时仍补带可见对话及角色结构。插件控制诊断留在技术详情,不混入模型回复或下一轮历史。I3 规则重注入、摘要回执与 v2 协商已整体删除。
6
+
7
+ DSH 已公布目录的技能与资源同步到两端同一受控绝对路径,SKILL 正文使用同一作用域的官方 skills.get() 原文,原 frontmatter、资源文件字节与可执行位保留;项目 AGENTS.md/CLAUDE.md 原文镜像后由 CLI 原生读取。Claude 使用原生插件技能入口,Codex 使用原生 skills/extraRoots/set;新轮次与冷恢复均更新原生目录。实际文件和命令仍由员工执行器执行。纯正文虚拟技能保留官方正文;未提供可镜像出口的 URL/opaque 资源明确报既有上下文不可用;主机原有技能中写死的任意主机脚本路径尚未证明可在员工端使用。
8
+
9
+ Claude 原生 Agent/TaskStop 与 Codex 原生子代理首轮可用。Codex 只把技能、办公依赖必需桥工具置于 employee 首轮分组,DSH 子代理及其余工具在 dsh 分组按需发现。保留 B6 原生插话、冷恢复、防重放、U1 每次 prompt 用量和原生型号、推理档、权限设置。含桥主机需 2.2.2-aw.17(Codex 0.162.0);不含桥通道不变。没有新增设置项或自定义错误码。
10
+
11
+ 上一轮正常结束仍异步清理,不延迟已完成回复。下一次同一可信主机、DSH会话、品牌、原生线程及连接代次打开前,只等待本插件已经发出的那一次释放操作;取消等待不取消释放,失败仍走原有归属校验,不增加模型重试或重复发送任务。
5
12
 
6
13
  ## 办公依赖与开工计时(O1,2026-11-15)
7
14
 
@@ -13,7 +20,7 @@ S7 按 owner 11-15 裁定撤除:删除 `local-user-turn` 及其轮次证明、
13
20
 
14
21
  ## 含工具桥预发布线
15
22
 
16
- 本包为 `0.9.0-toolbridge.36`,从 `v0.9.0-toolbridge.14` 派生,使用 `host-toolbridge` 发布渠道。员工安装由连接组件提供的「AI 写作工作台(含工具桥)」总包 `@ai-workbench/workbench-toolbridge@0.3.7`,与不含工具桥的版本二选一。
23
+ 本包为 `0.9.0-toolbridge.37-rc.5`,从 `v0.9.0-toolbridge.14` 派生,使用 `host-toolbridge` 发布渠道。员工安装由连接组件提供的「AI 写作工作台(含工具桥)」总包 `@ai-workbench/workbench-toolbridge@0.3.7`;0.3.8 尚未转正式,与不含工具桥的版本二选一。
17
24
 
18
25
  本轮增加两家运行中插话(DSH 原生 nextStep),保留官方队列和原话;明确 followup 仍排下一轮。Codex 含桥组件需 `2.2.2-aw.12`,Claude 仍为官方 `0.94.0`。插件确定消息未发出时保留排队资格;送达未确认时明确报错且不重放。已注入旧正文不能撤回,编辑版下一步骤交付。
19
26
 
@@ -40,7 +47,7 @@ Codex 需要 S 后续安装的独立受保护命令 `/usr/local/aw-host/bin/code
40
47
 
41
48
  Claude 员工MCP的stdio通道保持在当前原生客户端上。底层员工SSH/Unix流断开时,在途工具只返回结果未知,不重放;连接恢复后下一次新工具调用串行重新连接并初始化。同一DSH会话无需新建;若连接/绑定已撤销或DSH桥工具在途结束本轮,网络恢复后在原会话发新消息,沿原生编号续接。只使用原已核验的设备/账户/绑定,不跨代偷接。
42
49
 
43
- DSH技能工具仅使用DSH公布的目录,主机原生技能按各自原生指令加载;本机文件夹下主机 Claude 的主会话和子代理都能用原生 Skill 加载主机账户的用户级技能(0.9.0-toolbridge.20 起),技能里的 `!` 内联命令需要原生 Bash,原生 Bash 仍关闭,所以不会在主机执行,该技能加载失败并明确报错;工具描述标明目录快照与返回的资源基址。
50
+ DSH技能工具仅使用DSH公布的目录,主机原生技能按各自原生指令加载;本机文件夹下主机 Claude 的主会话和子代理都能用原生 Skill 加载主机账户的用户级技能(0.9.0-toolbridge.20 起),技能里的 `!` 内联命令需要原生 Bash,原生 Bash 仍关闭,所以不会在主机执行,该技能加载失败并明确报错;桥接工具描述仅使用 DSH 原文;同步后的原生技能入口提供资源路径。
44
51
 
45
52
  Claude 本机 Bash 会单独消费员工桥代理的控制诊断,不把它交给模型当作命令输出;真实传输中断仍提示结果未知。命令自身的标准输出、标准错误与退出码照常返回。非UTF-8流不拒绝,按原始字节base64返回并增加对应stdoutEncoding/stderrEncoding标记;有效UTF-8格式不变。没有新增原始字节上限,编码后的消息沿既有512MB容量核验。
46
53
 
@@ -90,7 +97,7 @@ Codex 员工端只使用随包提供的原生组件,通道等待本次组件
90
97
 
91
98
  模型目录在官方启动读取时获取,并在连接变为 connected 时经官方注册刷新;官方菜单打开或重试读取缓存是 DSH 官方限制,本插件不改官方菜单或核心。真正不支持的推理档位由 DSH 预检,其英文提示保留为观察项。
92
99
 
93
- I3(0.9.0-toolbridge.27):同一 DSH 对话的系统规则更新后,续接原 Codex native 线程并在实际模型请求应用新版规则;需要主机含桥 Codex ACP aw.15。规则未变不重复追加历史;每次恢复仍带当前配置以支持压缩重建。用量说明已由 U1(0.9.0-toolbridge.28)更正:Codex aw.15 和 Claude 0.94.0 的 ACP 回执均按本次 prompt 统计,逐轮全额结算一次,不减历史基线;旧累计快照不再参与计算。冷接回只减同一 prompt 已在 DSH 落盘的部分,可靠终态先持久化,原 broker 回收后仍可补记其未落盘用量。订阅额度卡仍读取官方额度窗口,不能由 token 数推算百分比。Claude 的规则传递保持。无新增设置、限制或错误码。
100
+ U1(本版保留):Codex 和 Claude 的 ACP 用量按本次 prompt 逐轮全额结算一次,不减历史基线。冷接回只减同一 prompt 已在 DSH 落盘的部分;可靠终态先持久化,原 broker 回收后仍可补记未落盘用量。订阅额度卡读取官方额度窗口,不由 token 数推算百分比。旧 I3 系统规则传递机制已删除。
94
101
 
95
102
  T3(0.9.0-toolbridge.33):在已连接、当前员工目录已接纳的 Codex 路径,同轮登录核验与端点准备重叠;两项均成功并再次核对目标、连接代次与物理目录后才开工,每轮核验与正常完成后结束 broker 的做法保留。当前输入已完整列出同一技能目录时,skill 工具省去重复名字数组;目录不完整或只有历史目录时保留原快照。未改变首轮工具可见性,没有新增设置、限制或错误码。本机受控时延与工具字节测量不代表远机实测速率或实际 API token 节省;DSH 原生本轮因缺独立登录未测。
96
103
 
package/dist/acp.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { NativeSessionContent } from './native-content-transport.ts';
1
2
  import type { StartupTiming } from './startup-timing.ts';
2
3
  import { CloseDiagnostics, type CloseCause } from './close-diagnostics.ts';
3
4
  import * as stable from '@agentclientprotocol/sdk';
@@ -40,10 +41,10 @@ export interface EmployeeExecutionMeta {
40
41
  acpMaxMessageBytes: number;
41
42
  }
42
43
  export interface AcpStartContext {
44
+ nativeContent?: NativeSessionContent;
43
45
  initialModel?: string;
44
46
  toolBridgeServers?: EmployeeRouting['mcpServers'];
45
- systemPrompt?: string;
46
- systemPromptChanged?: boolean;
47
+ customInstructions?: string;
47
48
  codexNewSessionOnly?: true;
48
49
  employeeExecution?: EmployeeExecutionMeta;
49
50
  employeeRouting?: EmployeeRouting;
@@ -129,7 +130,7 @@ export declare class AcpSession {
129
130
  setHooks(hooks: AcpHooks): void;
130
131
  get closed(): Promise<void>;
131
132
  start(cwd: string, resumeId?: string, signal?: AbortSignal, context?: AcpStartContext, prompt?: acp.ContentBlock[]): Promise<string>;
132
- /** 续接保留原生线程;规则变化由 session/resume 或 session/load 的原生 developer 指令覆盖。 */
133
+ /** 续接保留原生线程,不向既有历史注入插件规则。 */
133
134
  prompt(input: string | acp.ContentBlock[], signal?: AbortSignal): Promise<acp.StopReason>;
134
135
  steer(prompt: acp.ContentBlock[], signal?: AbortSignal, isCurrent?: () => boolean, maxBytes?: number): Promise<'injected' | 'promptRequired'>;
135
136
  close(cause?: CloseCause, error?: Error): void;
package/dist/acp.js CHANGED
@@ -34,7 +34,7 @@ t=$(printf '%s' "$t" | z)
34
34
  printf '%s\\n' "$c" | while IFS= read -r v; do v=\${v#C}; case $v in ''|*[!A-Za-z0-9._+@/\\ -]*) echo hit;; *) [ "$(printf '%s' "$v" | z)" = "$t" ] && echo hit;; esac; done | /usr/bin/grep -q hit && deny
35
35
  exit 0`;
36
36
  const claudeSettings = () => ({ hooks: { PreToolUse: [{ matcher: 'Agent', hooks: [{ type: 'command', command: cloudSubagentHook }] }] } });
37
- function employeeClaudeOptions(routing) { return { tools: ['Agent', 'TaskStop', 'Skill'], disallowedTools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash'], toolAliases: structuredClone(routing.toolAliases), settings: claudeSettings() }; }
37
+ function employeeClaudeOptions(routing) { return { tools: ['Agent', 'TaskStop', 'Skill', 'ToolSearch'], disallowedTools: ['Read', 'Write', 'Edit', 'Glob', 'Grep', 'Bash'], toolAliases: structuredClone(routing.toolAliases), settings: claudeSettings() }; }
38
38
  const permissionRanks = { claude: { plan: 0, default: 1, acceptEdits: 1, bypassPermissions: 2 }, codex: { 'read-only': 0, 'workspace-write': 1, agent: 1, 'agent-full-access': 2 } };
39
39
  /** ACP v1 with explicitly negotiated SDK 2.0 lifecycle/context extensions. */
40
40
  export class AcpSession {
@@ -556,22 +556,20 @@ export class AcpSession {
556
556
  this.steeringSupported = steering?.supported === true && (!context?.codexNewSessionOnly || steering.idleBehavior === 'promptRequired');
557
557
  if (this.employeeMeta) {
558
558
  const policy = record(hello._meta?.awEmployeeExecution);
559
- if (!this.hooks.employeeExecution || !policy || Object.keys(policy).length !== (context?.toolBridgeServers ? 6 : 5) || context?.toolBridgeServers && policy.mcpBridge !== 1 || policy.version !== 1 || policy.nativeCliVersion !== '0.160.1' || policy.native !== true || policy.perRpcGate !== true || policy.noHostFallback !== true)
559
+ if (!this.hooks.employeeExecution || !policy || Object.keys(policy).length !== (context?.toolBridgeServers ? 6 : 5) || context?.toolBridgeServers && policy.mcpBridge !== 1 || policy.version !== 1 || policy.nativeCliVersion !== '0.162.0' || policy.native !== true || policy.perRpcGate !== true || policy.noHostFallback !== true)
560
560
  throw new NeedError('EMPLOYEE_EXECUTION_UNSUPPORTED', '当前主机尚不支持在你的电脑执行Codex原生工具,本轮没有执行。', 'Codex员工端原生执行适配器与明确能力声明');
561
561
  this.employeeNegotiated = true;
562
- this.detail({ kind: 'session', severity: 'info', code: 'EMPLOYEE_EXECUTION_SELECTED', summary: '文件和命令在员工电脑的选定目录执行;订阅凭据留在主机,本机扩展的忽略详情单独记录。', payload: { bindingId: this.employeeMeta.bindingId, workspaceId: this.employeeMeta.workspaceId, cwd: this.employeeMeta.cwd, nativeCliVersion: '0.160.1', noHostFallback: true, agentConfigSource: 'host CODEX_HOME', unsupportedLocalFeatures: ['http-mcp-execution', 'hooks', 'plugins', 'cold-resume', 'slash-commands', 'host-file-reports'] } });
562
+ this.detail({ kind: 'session', severity: 'info', code: 'EMPLOYEE_EXECUTION_SELECTED', summary: '文件和命令在员工电脑的选定目录执行;订阅凭据留在主机,本机扩展的忽略详情单独记录。', payload: { bindingId: this.employeeMeta.bindingId, workspaceId: this.employeeMeta.workspaceId, cwd: this.employeeMeta.cwd, nativeCliVersion: '0.162.0', noHostFallback: true, agentConfigSource: 'host CODEX_HOME', unsupportedLocalFeatures: ['http-mcp-execution', 'hooks', 'plugins', 'cold-resume', 'slash-commands', 'host-file-reports'] } });
563
563
  }
564
- const systemPrompt = context?.systemPrompt;
565
- const resumePolicy = record(this.negotiated._meta?.aiWorkbenchSystemPrompt);
566
- const nativeContext = !!resumeId && !!context?.codexNewSessionOnly && resumePolicy?.version === 2;
567
564
  const initialPolicy = record(this.negotiated._meta?.aiWorkbenchInitialModel);
568
565
  const initialModel = !resumeId && context?.codexNewSessionOnly && initialPolicy?.version === 1 && initialPolicy?.scope === 'new-session' ? context.initialModel : undefined;
569
566
  this.codexNewSessionOnly = !!context?.codexNewSessionOnly;
570
567
  if (prompt)
571
568
  this.validatePrompt(prompt);
572
569
  const routing = context?.employeeRouting ? structuredClone(context.employeeRouting) : undefined;
573
- const claudeCode = routing ? { options: employeeClaudeOptions(routing) } : this.codexNewSessionOnly ? undefined : { options: { settings: claudeSettings() } };
574
- const params = { cwd, mcpServers: context?.toolBridgeServers ? structuredClone(context.toolBridgeServers) : routing ? structuredClone(routing.mcpServers) : [], ...((claudeCode || this.employeeMeta || initialModel) ? { _meta: { ...(initialModel ? { awInitialModel: { version: 1, model: initialModel } } : {}), ...(this.employeeMeta ? { awEmployeeExecution: this.employeeMeta } : {}), ...(claudeCode ? { claudeCode } : {}) } } : {}), ...((systemPrompt !== undefined || context?.systemPromptChanged || nativeContext) && !(resumeId && this.codexNewSessionOnly && !context?.systemPromptChanged && !nativeContext) ? { systemPrompt: { mode: 'append', content: [{ type: 'text', text: systemPrompt ?? '' }] } } : {}) };
570
+ const plugins = context?.nativeContent ? [{ type: 'local', path: context.nativeContent.claudePluginRoot }] : undefined;
571
+ const claudeCode = routing ? { options: { ...employeeClaudeOptions(routing), ...(plugins ? { plugins } : {}) } } : this.codexNewSessionOnly ? undefined : { options: { settings: claudeSettings(), ...(plugins ? { plugins } : {}) } };
572
+ const params = { cwd, mcpServers: context?.toolBridgeServers ? structuredClone(context.toolBridgeServers) : routing ? structuredClone(routing.mcpServers) : [], ...((claudeCode || this.employeeMeta || initialModel || context?.customInstructions !== undefined || context?.nativeContent) ? { _meta: { ...(this.codexNewSessionOnly && context?.nativeContent ? { awNativeSkills: { root: context.nativeContent.codexSkillsRoot } } : {}), ...(context?.customInstructions === undefined ? {} : { jetbrains: { air: { customInstructions: context.customInstructions } } }), ...(initialModel ? { awInitialModel: { version: 1, model: initialModel } } : {}), ...(this.employeeMeta ? { awEmployeeExecution: this.employeeMeta } : {}), ...(claudeCode ? { claudeCode } : {}) } } : {}) };
575
573
  const configRevision = this.resetConfiguration();
576
574
  const restore = async (operation) => {
577
575
  try {
@@ -637,7 +635,7 @@ export class AcpSession {
637
635
  signal?.removeEventListener('abort', abort);
638
636
  }
639
637
  }
640
- /** 续接保留原生线程;规则变化由 session/resume 或 session/load 的原生 developer 指令覆盖。 */
638
+ /** 续接保留原生线程,不向既有历史注入插件规则。 */
641
639
  async prompt(input, signal) {
642
640
  if (!this.ready || !this.sessionId)
643
641
  throw new NeedError('SESSION_REQUIRED', '我需要先建立远端会话', 'ACP 会话');
@@ -8,14 +8,32 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
8
8
  };
9
9
  import { newColdId } from "./cold-store.js";
10
10
  import { randomUUID } from 'node:crypto';
11
- import { CloseDiagnostics } from "./close-diagnostics.js";
11
+ import { CloseDiagnostics, closeCode } from "./close-diagnostics.js";
12
12
  import { BrokerTransport, brokerCommand, brokerId, sshIo, controlJson } from "./broker.js";
13
13
  import { CODEX_AGENT } from "./agents.js";
14
14
  import { NeedError } from "./remote.js";
15
15
  import { identity } from "./provider.js";
16
16
  import { brokerOwnership } from "./broker-ownership.js";
17
+ /** Wait only for our own already-issued release; aborting the waiter never cancels it. */
18
+ async function awaitRelease(release, signal) {
19
+ signal?.throwIfAborted();
20
+ if (!signal) {
21
+ await release;
22
+ return;
23
+ }
24
+ const aborted = Promise.withResolvers(), onAbort = () => aborted.reject(signal.reason ?? new DOMException('Aborted', 'AbortError'));
25
+ signal.addEventListener('abort', onAbort, { once: true });
26
+ try {
27
+ signal.throwIfAborted();
28
+ await Promise.race([release, aborted.promise]);
29
+ }
30
+ finally {
31
+ signal.removeEventListener('abort', onAbort);
32
+ }
33
+ }
17
34
  /** Each invocation owns a new agent. Context resumes by native session ID, never by reattaching a broker. */
18
35
  export function brokerFactory(_get, _ask, configuration, provided) {
36
+ const pendingReleases = new Map();
19
37
  return async (target, project, request) => {
20
38
  const agent = request.agent ?? CODEX_AGENT, settings = request.brokerSettings ?? (typeof configuration === 'function' ? configuration() : configuration);
21
39
  let argv = provided?.argv;
@@ -26,6 +44,17 @@ export function brokerFactory(_get, _ask, configuration, provided) {
26
44
  const io = provided?.io?.(target) ?? sshIo(target, argv, settings.brokerControlMaxBytes);
27
45
  const command = (args) => brokerCommand(target, args);
28
46
  const diagnostics = request.closeDiagnostics ?? new CloseDiagnostics(detail => request.detailChannel?.record(detail));
47
+ const api = _get(), connection = api?.getConnectionState(), generation = JSON.stringify(connection ? [connection.instanceId, connection.epoch, connection.phase] : null);
48
+ const releaseKey = JSON.stringify([identity(target), target.session.root, request.sessionId, agent.loginProvider]), previousRelease = pendingReleases.get(releaseKey);
49
+ if (request.resumeSessionId !== undefined && previousRelease && previousRelease.nativeId === request.resumeSessionId && previousRelease.api === api && previousRelease.generation === generation) {
50
+ try {
51
+ await awaitRelease(previousRelease.promise, request.signal);
52
+ }
53
+ catch (error) {
54
+ request.signal?.throwIfAborted();
55
+ diagnostics.record({ layer: 'broker', initiator: 'broker.previous-release', reason: closeCode(error, 'BROKER_CONTROL_FAILED'), action: 'failure' });
56
+ }
57
+ }
29
58
  const id = brokerId(request.sessionId + '/' + randomUUID(), agent.id);
30
59
  const startCommand = command(['start', id, '--cwd', project.path, '--settings', target.session.settingsPath, '--dsh-session-id', request.sessionId, '--provider', agent.loginProvider, '--', agent.command]);
31
60
  // environments.toml overrides CODEX_EXEC_SERVER_URL. Refuse that host default rather
@@ -96,23 +125,34 @@ export function brokerFactory(_get, _ask, configuration, provided) {
96
125
  diagnostics.record(cause);
97
126
  channel.close(cause);
98
127
  };
99
- const dispose = async (cause = { layer: 'broker', initiator: 'broker.dispose', reason: 'BROKER_DISPOSE', action: 'dispose' }) => {
128
+ let disposing, nativeSessionId;
129
+ const dispose = (cause = { layer: 'broker', initiator: 'broker.dispose', reason: 'BROKER_DISPOSE', action: 'dispose' }) => {
130
+ if (disposing)
131
+ return disposing;
100
132
  if (ended)
101
- return;
102
- // Ending the round ends its host agent, so the native thread writer is free for the next round.
103
- await detach(cause);
104
- void io.run(command(['kill', id, '--if-instance', started.instanceId])).catch(() => console.warn('[remote-agent] 旧主机会话暂未清理,将由主机自动回收'));
133
+ return Promise.resolve();
134
+ // Register synchronously before detach yields. Only the next same-thread open
135
+ // waits; the completed official turn keeps its non-blocking cleanup contract.
136
+ const release = Promise.resolve().then(async () => { await detach(cause); await io.run(command(['kill', id, '--if-instance', started.instanceId])); });
137
+ disposing = release.catch(() => console.warn('[remote-agent] 旧主机会话暂未清理,将由主机自动回收'));
138
+ const entry = { promise: release, nativeId: nativeSessionId, api, generation };
139
+ pendingReleases.set(releaseKey, entry);
140
+ const clear = () => { if (pendingReleases.get(releaseKey) === entry)
141
+ pendingReleases.delete(releaseKey); };
142
+ void release.then(clear, clear);
143
+ return disposing;
105
144
  };
106
145
  const aborted = () => channel.fail(new NeedError('ABORTED', '本轮已取消。', '确认主机状态'), { layer: 'broker', initiator: 'broker.open-signal', reason: 'ABORTED', action: 'abort' });
107
146
  request.signal?.addEventListener('abort', aborted, { once: true });
108
147
  let sessionOwnership;
109
148
  try {
110
- sessionOwnership = brokerOwnership(io, command, { id, instanceId: started.instanceId }, started, request.sessionId, agent.loginProvider);
149
+ const ownership = brokerOwnership(io, command, { id, instanceId: started.instanceId }, started, request.sessionId, agent.loginProvider);
150
+ sessionOwnership = { ...ownership, async bind(nativeId, signal) { await ownership.bind(nativeId, signal); nativeSessionId = nativeId; } };
111
151
  request.signal?.throwIfAborted();
112
152
  await channel.connect();
113
153
  }
114
154
  catch (error) {
115
- await dispose();
155
+ void dispose().catch(() => console.warn('[remote-agent] 旧主机会话暂未清理,将由主机自动回收'));
116
156
  throw error;
117
157
  }
118
158
  finally {
@@ -49,7 +49,7 @@ export function createClaudeLocalProvider(options) {
49
49
  closeDiagnostics.bind(event => details.record(event));
50
50
  request.closeDiagnostics = closeDiagnostics;
51
51
  details.record({ kind: 'session', severity: 'info', code: 'CLAUDE_EMPLOYEE_VALIDATION_POLICY', summary: '本机执行不可改到主机:每轮开始从L读取一次本机工作区上下文,核验所选物理目录、N端点与主机目标,并新建本轮工具通道。之后不逐消息、审批或工具重复核验;既有连接、位置、网络事件和通道关闭只终止本轮,下一轮重新核验。' });
52
- const openRequest = () => ({ ...request, detailChannel: details, bindingId: item.bindingId, workspaceId: workspace.workspaceId, bindingRevision: state.revision });
52
+ const openRequest = () => ({ ...request, detailChannel: details, bindingId: item.bindingId, workspaceId: workspace.workspaceId, nativeEmployeeCwd: workspace.directory.path, bindingRevision: state.revision });
53
53
  let io;
54
54
  const transport = async () => { if (!io) {
55
55
  const name = '@ai-workbench/connect';
@@ -105,7 +105,7 @@ export function createClaudeLocalProvider(options) {
105
105
  });
106
106
  };
107
107
  const executionSignal = modelLifetime.signal;
108
- row.runtime = { ...underlying, localDirectory: { ...workspace.directory }, 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: ['internal-direct-calls', 'binary-read', 'background-shell'] }, validate: async (signal) => { signal?.throwIfAborted(); lease.signal.throwIfAborted(); executionSignal.throwIfAborted(); }, beginTurn: async (signal) => { signal?.throwIfAborted(); lease.signal.throwIfAborted(); executionSignal.throwIfAborted(); if (row.closing || row.active)
108
+ row.runtime = { ...underlying, localDirectory: { ...workspace.directory }, closeDiagnostics, cwd: workspace.directory.path, details, connection: { ...connection }, binding: { bindingId: item.bindingId, workspaceId: workspace.workspaceId, revision: state.revision }, execution: { hostCwd: base.nativeContent?.hostCwd ?? target.session.root, routing: mcp.routing, notice: NOTICE, signal: executionSignal, scope: { source: 'local', cwd: workspace.directory.path, hostCwd: base.nativeContent?.hostCwd ?? target.session.root, uid: lease.target.endpoint.remoteUid, claudeAcpVersion: '0.94.0', sdkVersion: '0.3.303', unsupported: ['internal-direct-calls', 'binary-read', 'background-shell'] }, validate: async (signal) => { signal?.throwIfAborted(); lease.signal.throwIfAborted(); executionSignal.throwIfAborted(); }, beginTurn: async (signal) => { signal?.throwIfAborted(); lease.signal.throwIfAborted(); executionSignal.throwIfAborted(); if (row.closing || row.active)
109
109
  throw failure('TURN_BUSY'); row.active = { signal, details: row.details }; }, endTurn: () => { row.active = undefined; } }, dispose: cause => close(false, cause), detach: cause => close(true, cause) };
110
110
  entries.set(request.sessionId, row);
111
111
  const endpointAborted = () => {
@@ -11,6 +11,7 @@ export declare function recoverColdProtocol(record: ColdRound, store: ColdStore,
11
11
  maxMessageBytes: number;
12
12
  signal?: AbortSignal;
13
13
  markerId?: string;
14
+ notice?: (text: string) => void;
14
15
  cancelOnly?: boolean;
15
16
  }): AsyncGenerator<StreamChunk>;
16
17
  /** 本地未派发取消的证明来自写前记录或S消息回执,不伪造原生RPC终态。 */
@@ -63,7 +63,7 @@ const LOGIN_ENDED = '\n上一轮因主机会话的登录已失效没有完成,
63
63
  /** The checkpoint that commits the original round and lets the next round resume its native thread. */
64
64
  function coldPointer(record, outputAfter) {
65
65
  const snapshot = record.meta;
66
- return { ...(snapshot.hostSource ? { hostSource: snapshot.hostSource } : {}), ...(snapshot.modelConfiguration ? { modelConfiguration: snapshot.modelConfiguration } : {}), version: 2, agent: record.provider, contextSha256: snapshot.contextSha256, dshSessionId: record.sessionId, identity: snapshot.identity, cwd: snapshot.cwd, sessionId: record.nativeId, ...(snapshot.binding ? { bindingId: snapshot.binding.bindingId, workspaceId: snapshot.binding.workspaceId } : {}), coldRoundId: record.id, coldPromptId: record.promptId, coldRoundTerminal: true, coldOutputAfter: outputAfter };
66
+ return { ...(snapshot.hostSource ? { hostSource: snapshot.hostSource } : {}), ...(snapshot.modelConfiguration ? { modelConfiguration: snapshot.modelConfiguration } : {}), version: 2, agent: record.provider, dshSessionId: record.sessionId, identity: snapshot.identity, cwd: snapshot.cwd, sessionId: record.nativeId, ...(snapshot.binding ? { bindingId: snapshot.binding.bindingId, workspaceId: snapshot.binding.workspaceId } : {}), coldRoundId: record.id, coldPromptId: record.promptId, coldRoundTerminal: true, coldOutputAfter: outputAfter };
67
67
  }
68
68
  export async function* recoverColdProtocol(record, store, prefix, options) {
69
69
  options.signal?.throwIfAborted();
@@ -91,7 +91,7 @@ export async function* recoverColdProtocol(record, store, prefix, options) {
91
91
  for (const chunk of ended.acpResponse(record.terminal.value))
92
92
  if (chunk.type === 'usage')
93
93
  yield* remainingUsage(chunk.usage, prefix.usage);
94
- yield* ended.text(HOST_ROUND_ENDED);
94
+ options.notice?.(HOST_ROUND_ENDED);
95
95
  yield* ended.flush();
96
96
  yield { type: 'finish', reason: { kind: 'stop' }, replayState: { response: coldPointer(record, record.terminalAfter ?? record.outputStart ?? record.outputAfter) } };
97
97
  return;
@@ -272,13 +272,20 @@ export async function* recoverColdProtocol(record, store, prefix, options) {
272
272
  })();
273
273
  // Keep the reader alive independently while outgoing controls await a new replay barrier.
274
274
  activePump = pump;
275
- for await (const chunk of projection(mapper.text(record.meta.prelude ?? '')))
276
- yield chunk;
275
+ if (record.meta.prelude) {
276
+ trim.take('text', record.meta.prelude);
277
+ options.notice?.(record.meta.prelude);
278
+ }
277
279
  mapper.flush();
278
280
  let nativeUpdates = 0, noticeIndex = 0;
279
281
  const notices = function* () { while (record.localNotices?.[noticeIndex]?.beforeUpdate === nativeUpdates) {
280
282
  const notice = record.localNotices[noticeIndex++];
281
- yield* projection(mapper.text(notice.text, notice.kind === 'reasoning'));
283
+ if (notice.kind === undefined) {
284
+ trim.take('text', notice.text);
285
+ options.notice?.(notice.text);
286
+ }
287
+ else
288
+ yield* projection(mapper.text(notice.text, notice.kind === 'reasoning'));
282
289
  } };
283
290
  yield* notices();
284
291
  for (;;) {
@@ -337,7 +344,7 @@ export async function* recoverColdProtocol(record, store, prefix, options) {
337
344
  if (options.markerId && acpNeed(new acp.RequestError(m.error.code, m.error.message, m.error.data)).code === 'LOGIN_REQUIRED') {
338
345
  await options.io.run(command(['kill', record.brokerId, '--if-instance', record.instanceId]), options.signal).catch(() => { options.signal?.throwIfAborted(); console.warn('[remote-agent] 旧主机会话暂未清理,将由主机自动回收'); });
339
346
  yield* output.flush();
340
- yield* output.text(LOGIN_ENDED);
347
+ options.notice?.(LOGIN_ENDED);
341
348
  yield* output.flush();
342
349
  yield { type: 'finish', reason: { kind: 'stop' }, replayState: { response: coldPointer(record, broker.lastSequence) } };
343
350
  return;
@@ -360,7 +367,7 @@ export async function* recoverColdProtocol(record, store, prefix, options) {
360
367
  throw new LlmError(message, 'ABORTED');
361
368
  }
362
369
  if (m.result.stopReason === 'refusal')
363
- yield* projection(mapper.text('\n[远端拒绝] 此请求未执行。\n'));
370
+ options.notice?.('远端拒绝此请求,未执行。');
364
371
  trim.finish();
365
372
  yield* output.flush();
366
373
  delivered = true;
@@ -33,6 +33,7 @@ export declare class ColdRecovery {
33
33
  brokerControlMaxBytes?: number;
34
34
  }, provided?: {
35
35
  store?: ColdStore;
36
+ notice?: (row: ColdRound, text: string) => Promise<void>;
36
37
  readSource?: (id: string) => Promise<unknown>;
37
38
  io?: (r: ColdRound) => BrokerIo;
38
39
  argv?: SshArgv;
@@ -351,7 +351,7 @@ export class ColdRecovery {
351
351
  const m = row.meta;
352
352
  if (!row.nativeId)
353
353
  return { index, pointer: undefined };
354
- return { index, pointer: { version: 2, agent: row.provider, dshSessionId: row.sessionId, identity: m.identity, cwd: m.cwd, sessionId: row.nativeId, contextSha256: m.contextSha256, ...(m.binding ? { bindingId: m.binding.bindingId, workspaceId: m.binding.workspaceId } : {}), ...(m.hostSource ? { hostSource: m.hostSource } : {}), ...(m.modelConfiguration ? { modelConfiguration: m.modelConfiguration } : {}) } };
354
+ return { index, pointer: { version: 2, agent: row.provider, dshSessionId: row.sessionId, identity: m.identity, cwd: m.cwd, sessionId: row.nativeId, ...(m.binding ? { bindingId: m.binding.bindingId, workspaceId: m.binding.workspaceId } : {}), ...(m.hostSource ? { hostSource: m.hostSource } : {}), ...(m.modelConfiguration ? { modelConfiguration: m.modelConfiguration } : {}) } };
355
355
  }
356
356
  release(sessionId, id) { if (this.live.get(sessionId) === id)
357
357
  this.live.delete(sessionId); }
@@ -578,7 +578,7 @@ export class ColdRecovery {
578
578
  revoke();
579
579
  signal.throwIfAborted();
580
580
  this.live.set(row.sessionId, row.id);
581
- yield* recoverColdProtocol(row, this.store, { blocks, usage }, { io, maxFrameBytes: this.config().brokerMaxFrameBytes, maxMessageBytes: this.config().acpMaxMessageBytes, signal, markerId: selected.markerId });
581
+ yield* recoverColdProtocol(row, this.store, { blocks, usage }, { io, maxFrameBytes: this.config().brokerMaxFrameBytes, maxMessageBytes: this.config().acpMaxMessageBytes, signal, markerId: selected.markerId, notice: text => { void this.provided?.notice?.(row, text).catch(() => console.warn('[remote-agent] 恢复诊断未保存')); } });
582
582
  if (revoked)
583
583
  throw revoked;
584
584
  }
@@ -42,7 +42,6 @@ export interface ColdRound {
42
42
  revision: number;
43
43
  };
44
44
  hostSource?: unknown;
45
- contextSha256: string;
46
45
  modelConfiguration?: unknown;
47
46
  header: unknown;
48
47
  model: string;
@@ -0,0 +1,6 @@
1
+ /** Only active official instruction plugins' explicit raw profile overrides. */
2
+ export declare function readCustomInstructions(context: {
3
+ get(name: string): unknown;
4
+ }, scope?: {
5
+ ctx?: unknown;
6
+ }): string | undefined;
@@ -0,0 +1,21 @@
1
+ import { symbols } from '@deepseek-ai/cordis';
2
+ import { scopeOf, scopeChainOf } from '@deepseek-ai/dsh-scope';
3
+ /** Only active official instruction plugins' explicit raw profile overrides. */
4
+ export function readCustomInstructions(context, scope) {
5
+ const editor = context.get('configEditor');
6
+ if (typeof editor?.configuration !== 'function')
7
+ return;
8
+ const chain = scope?.ctx ? scopeChainOf(scopeOf(scope.ctx)) : [];
9
+ const rows = editor.configuration().filter(({ entry }) => !entry.disabled && !!entry.fiber);
10
+ const personas = rows.filter(({ entry }) => entry.options.name === '@deepseek-ai/dsh-persona' && entry.context && chain.includes(scopeOf(entry.context)));
11
+ personas.sort((a, b) => chain.indexOf(scopeOf(a.entry.context)) - chain.indexOf(scopeOf(b.entry.context)));
12
+ const original = (value) => value && typeof value === 'object' ? value[symbols.original] ?? value : value;
13
+ const registry = original(context.get('systemPrompt'));
14
+ const globals = rows.filter(({ entry }) => entry.options.name === '@deepseek-ai/dsh-system-prompt' && (!entry.context || original(entry.context.get('systemPrompt')) === registry));
15
+ const selected = personas[0] ?? globals[0];
16
+ if (!selected)
17
+ return;
18
+ const keys = selected.entry.options.name === '@deepseek-ai/dsh-persona' ? ['prefix', 'suffix'] : ['personaPrefix', 'personaSuffix'];
19
+ const parts = keys.filter(key => Object.hasOwn(selected.override, key) && typeof selected.override[key] === 'string').map(key => selected.override[key]);
20
+ return parts.length ? parts.join('') : undefined;
21
+ }
@@ -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 + ';不在主机回退。' + (name === 'Bash' ? '输出原样保留:若stdoutEncoding或stderrEncoding为base64,对应字符串为原始字节的base64编码,按标明编码处理;退出状态独立保留。' : ''), inputSchema: { type: 'object', properties, required, additionalProperties: false } }; }
11
+ function schema(name, properties, required) { return { name, _meta: { 'anthropic/alwaysLoad': true }, 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']),
@@ -140,7 +140,7 @@ export async function openEmployeeMcp(options) {
140
140
  mcp.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
141
141
  const active = options.activeSignal();
142
142
  if (!active || active.aborted)
143
- return { isError: true, content: [{ type: 'text', text: 'EMPLOYEE_NO_ACTIVE_TURN:当前没有已接纳的用户轮次,本机工具未执行。' }] };
143
+ return { isError: true, content: [{ type: 'text', text: JSON.stringify({ code: 'EMPLOYEE_NO_ACTIVE_TURN' }) }] };
144
144
  const signal = AbortSignal.any([active, extra.signal, transport.signal, options.lease.signal]);
145
145
  if (options.bridge?.isBridge(request.params.name))
146
146
  return options.bridge.call(request.params.name, request.params.arguments ?? {}, signal);
@@ -1,9 +1,9 @@
1
1
  export declare const EMPLOYEE_NATIVE: Readonly<{
2
- version: "0.160.1";
2
+ version: "0.162.0";
3
3
  platform: "darwin";
4
4
  arch: "arm64";
5
5
  package: "@openai/codex-darwin-arm64";
6
- packageVersion: "0.160.1-darwin-arm64";
6
+ packageVersion: "0.162.0-darwin-arm64";
7
7
  triple: "aarch64-apple-darwin";
8
8
  }>;
9
9
  /** Resolve the installed executable; no per-turn hash or version probe. */
@@ -3,7 +3,7 @@ import { dirname, join } from 'node:path';
3
3
  import { NeedError } from "./remote.js";
4
4
  const require = createRequire(import.meta.url);
5
5
  let installedPath;
6
- export const EMPLOYEE_NATIVE = Object.freeze({ version: '0.160.1', platform: 'darwin', arch: 'arm64', package: '@openai/codex-darwin-arm64', packageVersion: '0.160.1-darwin-arm64', triple: 'aarch64-apple-darwin' });
6
+ export const EMPLOYEE_NATIVE = Object.freeze({ version: '0.162.0', platform: 'darwin', arch: 'arm64', package: '@openai/codex-darwin-arm64', packageVersion: '0.162.0-darwin-arm64', triple: 'aarch64-apple-darwin' });
7
7
  /** Resolve the installed executable; no per-turn hash or version probe. */
8
8
  export async function resolveEmployeeNative(ports = {}) {
9
9
  if ((ports.platform ?? process.platform) !== EMPLOYEE_NATIVE.platform || (ports.arch ?? process.arch) !== EMPLOYEE_NATIVE.arch)
@@ -185,7 +185,7 @@ export function createEmployeeProvider(get, options, agent) {
185
185
  if (!options.open)
186
186
  throw fail('RUNTIME_REQUIRED');
187
187
  // Host cwd is only the protected agent bootstrap/config directory. Native tools use admitted.cwd.
188
- const openHost = () => options.open(target, { name: 'employee', path: target.projectRoot }, { ...request, signal: roundSignal, agent, employeeScope: scope, bindingId: admitted.bindingId, workspaceId: admitted.workspaceId, bindingRevision: state.revision, closeDiagnostics, detailChannel: details, resumeSessionId: request.resumeSessionId });
188
+ const openHost = () => options.open(target, { name: 'employee', path: target.projectRoot }, { ...request, signal: roundSignal, agent, employeeScope: scope, nativeEmployeeCwd: admitted.cwd, bindingId: admitted.bindingId, workspaceId: admitted.workspaceId, bindingRevision: state.revision, closeDiagnostics, detailChannel: details, resumeSessionId: request.resumeSessionId });
189
189
  const host = opening = await (request.startupTiming?.run('broker-open', openHost) ?? openHost());
190
190
  roundSignal.throwIfAborted();
191
191
  // The old per-RPC identity check belongs once at the end of this round's opening.
@@ -156,7 +156,7 @@ export const EMPLOYEE_RELAY_PYTHON = EMPLOYEE_TARGET_PYTHON + String.raw `
156
156
  reply={"jsonrpc":"2.0","result":self.initialized} if method=="initialize" else await self.request(process,message)
157
157
  await self.emit({**reply,"id":front})
158
158
  except (OSError,Disconnected):
159
- text="本机工具连接中断,在途结果未知,没有重放;下一次工具调用会重新建立通道。"
159
+ text=json.dumps({"code":-32603,"data":{"result":"unknown","replayed":False}},separators=(",",":"))
160
160
  reply={"result":{"isError":True,"content":[{"type":"text","text":text}]}} if method=="tools/call" else {"error":{"code":-32603,"message":text}}
161
161
  await self.emit({"jsonrpc":"2.0","id":front,**reply})
162
162
  async def relay():
@@ -283,7 +283,7 @@ export function createEmployeeTools(options) {
283
283
  catch (error) {
284
284
  const code = error instanceof NeedError ? error.code : signal.aborted ? 'EMPLOYEE_CANCELLED_UNKNOWN' : typeof error?.code === 'string' ? 'EMPLOYEE_IO_' + error.code : 'EMPLOYEE_OPERATION_FAILED';
285
285
  detail(submitted && signal.aborted ? 'unknown' : 'failed', code);
286
- return { isError: true, content: [{ type: 'text', text: code + ':本机操作未完成;没有在主机代跑。' }] };
286
+ return { isError: true, content: [{ type: 'text', text: JSON.stringify({ code }) }] };
287
287
  }
288
288
  }
289
289
  return {
package/dist/index.d.ts CHANGED
@@ -70,8 +70,6 @@ export declare class CodexRemoteAdapter extends LlmAdapter {
70
70
  private shuttingDown;
71
71
  private detached;
72
72
  private modelPresentation;
73
- private employeeNoticeSessions;
74
- private pendingEmployeeNotices;
75
73
  constructor(config: PluginConfig | (() => PluginConfig), resolveRuntime: RuntimeProvider, approve?: InvocationApproval | undefined, providerName?: () => string, agent?: AgentDefinition, readImage?: ImageReader | undefined, reportLoginFailure?: LoginFailureReporter | undefined, directory?: ModelDirectory | undefined, preflightDiagnostics?: PreflightDiagnostics | undefined, permissions?: PermissionSource | undefined, bridgeStopped?: (sessionId: string, notice: string) => void, steeringReceipts?: SteeringReceipts | undefined, coldRecovery?: ColdRecovery | undefined);
76
74
  providerInfo(provider: string): {
77
75
  id: string;