@ai-workbench/remote-agent 0.9.0-toolbridge.23 → 0.9.0-toolbridge.24
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 +10 -2
- package/dist/acp.d.ts +4 -0
- package/dist/acp.js +7 -3
- package/dist/broker-runtime.js +10 -2
- package/dist/conversation-details.js +21 -8
- package/dist/employee-native.js +7 -1
- package/dist/employee-provider.js +20 -5
- package/dist/index.js +16 -9
- package/dist/provider.d.ts +2 -0
- package/dist/provider.js +3 -2
- package/dist/startup-timing.d.ts +14 -0
- package/dist/startup-timing.js +34 -0
- package/dist/toolbridge-table.d.ts +1 -1
- package/dist/toolbridge-table.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.
|
|
1
|
+
# AI Workbench 远程助手 · @ai-workbench/remote-agent@0.9.0-toolbridge.24 · 插件 → 添加插件
|
|
2
|
+
|
|
3
|
+
## 办公依赖与开工计时(O1,2026-11-15)
|
|
4
|
+
|
|
5
|
+
员工目录模式现在桥接 DSH `load_workspace_dependencies`,由 DSH 原生循环执行、审批并返回员工电脑的 Python/Node 绝对路径;命令仍通过员工执行器执行这些路径。主机目录模式不开放工具桥,不能使用员工运行时路径。Codex 新建线程在主机明确声明能力时,先按本轮所选模型建立原生基础说明,再保留每轮模型、推理与权限的真实设置回执;没有裁剪 DSH、安全或原生说明,恢复与真实换模型维持原语义。需主机含桥适配器 `2.2.2-aw.13`;旧主机照旧运行。
|
|
6
|
+
|
|
7
|
+
技术详情的 `STARTUP_TIMING` 只记录单调时钟与固定阶段,含目录快照、登录、端点、静态执行器元数据、broker、工具桥、ACP 初始化/建会话、模型/权限确认、实际 SDK 派发,以及支持持久消息协议时的 `prompt-delivery`(绑定和输入确认)。`startup` 到实际 SDK 写出,不能直接称为 DSH 提交到主机 task_started;跨机差额需同轮事件另算。静态执行器路径与本轮端点准备并行;每轮目录/登录/端点核验及事件撤销、主机目标绑定保持。
|
|
8
|
+
|
|
9
|
+
新增设置、限制、错误码均为 0。已有会话的历史说明不会被改写;避免初始模型切换冗余的效果从新会话开始。
|
|
2
10
|
|
|
3
11
|
## 含工具桥预发布线
|
|
4
12
|
|
|
5
|
-
本包为 `0.9.0-toolbridge.
|
|
13
|
+
本包为 `0.9.0-toolbridge.24`,从 `v0.9.0-toolbridge.14` 派生,使用 `host-toolbridge` 发布渠道。员工安装由连接组件提供的「AI 写作工作台(含工具桥)」总包 `@ai-workbench/workbench-toolbridge@0.1.24`,与不含工具桥的版本二选一。
|
|
6
14
|
|
|
7
15
|
本轮增加两家运行中插话(DSH 原生 nextStep),保留官方队列和原话;明确 followup 仍排下一轮。Codex 含桥组件需 `2.2.2-aw.12`,Claude 仍为官方 `0.94.0`。插件确定消息未发出时保留排队资格;送达未确认时明确报错且不重放。已注入旧正文不能撤回,编辑版下一步骤交付。
|
|
8
16
|
|
package/dist/acp.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StartupTiming } from './startup-timing.ts';
|
|
1
2
|
import { CloseDiagnostics, type CloseCause } from './close-diagnostics.ts';
|
|
2
3
|
import * as stable from '@agentclientprotocol/sdk';
|
|
3
4
|
import * as acp from '@agentclientprotocol/sdk/unstable';
|
|
@@ -9,6 +10,8 @@ import type { EmployeeRouting } from './employee-relay.ts';
|
|
|
9
10
|
import type { SessionOwnership } from './broker-ownership.ts';
|
|
10
11
|
export type ApprovalOutcome = 'allowed-once' | 'rejected' | 'cancelled' | 'unavailable';
|
|
11
12
|
export interface AcpHooks {
|
|
13
|
+
startupTiming?: StartupTiming;
|
|
14
|
+
onPromptDispatched?: () => void;
|
|
12
15
|
closeDiagnostics?: CloseDiagnostics;
|
|
13
16
|
onUpdate?: (notification: acp.SessionNotification, originSequence?: number) => void;
|
|
14
17
|
onResponse?: (response: acp.PromptResponse) => void;
|
|
@@ -37,6 +40,7 @@ export interface EmployeeExecutionMeta {
|
|
|
37
40
|
acpMaxMessageBytes: number;
|
|
38
41
|
}
|
|
39
42
|
export interface AcpStartContext {
|
|
43
|
+
initialModel?: string;
|
|
40
44
|
toolBridgeServers?: EmployeeRouting['mcpServers'];
|
|
41
45
|
systemPrompt?: string;
|
|
42
46
|
codexNewSessionOnly?: true;
|
package/dist/acp.js
CHANGED
|
@@ -237,7 +237,7 @@ export class AcpSession {
|
|
|
237
237
|
}
|
|
238
238
|
reports = [];
|
|
239
239
|
async stage(phase, operation) { this.closeDiagnostics.stage = phase; try {
|
|
240
|
-
return await this.closeDiagnostics.run(phase, operation);
|
|
240
|
+
return await (this.hooks.startupTiming && phase !== 'acp-prompt' ? this.hooks.startupTiming.run(phase, () => this.closeDiagnostics.run(phase, operation)) : this.closeDiagnostics.run(phase, operation));
|
|
241
241
|
}
|
|
242
242
|
catch (error) {
|
|
243
243
|
if (['acp-session-new', 'acp-session-resume', 'acp-session-load', 'acp-initialize'].includes(phase))
|
|
@@ -507,8 +507,10 @@ export class AcpSession {
|
|
|
507
507
|
catch {
|
|
508
508
|
return false;
|
|
509
509
|
} });
|
|
510
|
-
if (method === 'session/prompt')
|
|
510
|
+
if (method === 'session/prompt') {
|
|
511
511
|
this.dispatchedPrompts++;
|
|
512
|
+
this.hooks.onPromptDispatched?.();
|
|
513
|
+
}
|
|
512
514
|
else
|
|
513
515
|
this.dispatchedSteers++;
|
|
514
516
|
}
|
|
@@ -574,13 +576,15 @@ export class AcpSession {
|
|
|
574
576
|
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'] } });
|
|
575
577
|
}
|
|
576
578
|
const systemPrompt = context?.systemPrompt;
|
|
579
|
+
const initialPolicy = record(this.negotiated._meta?.aiWorkbenchInitialModel);
|
|
580
|
+
const initialModel = !resumeId && context?.codexNewSessionOnly && initialPolicy?.version === 1 && initialPolicy?.scope === 'new-session' ? context.initialModel : undefined;
|
|
577
581
|
this.codexNewSessionOnly = !!context?.codexNewSessionOnly;
|
|
578
582
|
if (prompt)
|
|
579
583
|
this.validatePrompt(prompt);
|
|
580
584
|
const routing = context?.employeeRouting ? structuredClone(context.employeeRouting) : undefined;
|
|
581
585
|
this.employeeRouting = routing;
|
|
582
586
|
const claudeCode = routing ? { options: employeeClaudeOptions(routing) } : this.codexNewSessionOnly ? undefined : { options: { settings: claudeSettings() } };
|
|
583
|
-
const params = { cwd, mcpServers: context?.toolBridgeServers ? structuredClone(context.toolBridgeServers) : routing ? structuredClone(routing.mcpServers) : [], ...((claudeCode || this.employeeMeta) ? { _meta: { ...(this.employeeMeta ? { awEmployeeExecution: this.employeeMeta } : {}), ...(claudeCode ? { claudeCode } : {}) } } : {}), ...(systemPrompt && !(resumeId && this.codexNewSessionOnly) ? { systemPrompt: { mode: 'append', content: [{ type: 'text', text: systemPrompt }] } } : {}) };
|
|
587
|
+
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 && !(resumeId && this.codexNewSessionOnly) ? { systemPrompt: { mode: 'append', content: [{ type: 'text', text: systemPrompt }] } } : {}) };
|
|
584
588
|
const configRevision = this.resetConfiguration();
|
|
585
589
|
const restore = async (operation) => {
|
|
586
590
|
try {
|
package/dist/broker-runtime.js
CHANGED
|
@@ -41,8 +41,11 @@ export function brokerFactory(_get, _ask, configuration, provided) {
|
|
|
41
41
|
void boundOrigin.promise.catch(() => { });
|
|
42
42
|
if (coldStore)
|
|
43
43
|
await coldStore.put({ version: 1, id: roundId, sessionId: request.sessionId, provider: agent.id, brand: agent.loginProvider, phase: 'opening', target: structuredClone(target), brokerId: id, instanceId: started.instanceId, controlMaxBytes: started.controlMaxBytes, heartbeatIntervalMs: started.lifecycle.heartbeatIntervalMs, rpcIds: [], answered: [], inputSequence: 0, outputAfter: 0 });
|
|
44
|
+
let endPromptDelivery;
|
|
44
45
|
const beforeMessage = coldStore ? async (bytes, message) => {
|
|
45
46
|
const rpc = JSON.parse(Buffer.from(bytes).toString('utf8'));
|
|
47
|
+
if (rpc.method === 'session/prompt')
|
|
48
|
+
endPromptDelivery = request.startupTiming?.start('prompt-delivery');
|
|
46
49
|
try {
|
|
47
50
|
let record = await coldStore.update(request.sessionId, agent.id, roundId, row => {
|
|
48
51
|
if (rpc.method && Object.hasOwn(rpc, 'id') && !row.rpcIds.includes(rpc.id))
|
|
@@ -68,14 +71,17 @@ export function brokerFactory(_get, _ask, configuration, provided) {
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
catch (error) {
|
|
71
|
-
if (rpc.method === 'session/prompt')
|
|
74
|
+
if (rpc.method === 'session/prompt') {
|
|
75
|
+
endPromptDelivery?.('failed');
|
|
76
|
+
endPromptDelivery = undefined;
|
|
72
77
|
boundOrigin.reject(error);
|
|
78
|
+
}
|
|
73
79
|
throw error;
|
|
74
80
|
}
|
|
75
81
|
} : undefined;
|
|
76
82
|
const afterMessage = coldStore ? async (sequence) => { await coldStore.update(request.sessionId, agent.id, roundId, row => { if (row.pending && !row.pending.method && row.pending.rpcId !== undefined && !row.answered.includes(row.pending.rpcId))
|
|
77
83
|
row.answered.push(row.pending.rpcId); if (row.pending && ['session/cancel', '$/cancel_request'].includes(row.pending.method ?? '') && row.cancelIntent)
|
|
78
|
-
row.cancelIntent.delivered = true; row.inputSequence = sequence; delete row.pending; }); } : undefined;
|
|
84
|
+
row.cancelIntent.delivered = true; row.inputSequence = sequence; delete row.pending; }); endPromptDelivery?.(); endPromptDelivery = undefined; } : undefined;
|
|
79
85
|
const channel = new BrokerTransport({ observeClose: diagnostics.capture(), maxFrameBytes: settings.brokerMaxFrameBytes, instanceId: started.instanceId, leased: true, controlMaxBytes: started.controlMaxBytes, ...(started.inputProtocolVersion === 2 ? { inputProtocolVersion: 2, recoverDisconnect: true } : {}), ...(coldStore ? { messageInput: true, outputOrigins: true, beforeMessage, afterMessage } : {}), attach: (after = 0) => io.attach(command(['attach', id, '--after', String(after), '--framed', '--leased', ...(started.inputProtocolVersion === 2 ? ['--input-protocol', '2'] : []), ...(coldStore ? ['--message-input'] : []), '--if-instance', started.instanceId])) });
|
|
80
86
|
const reconnectOff = started.inputProtocolVersion === 2 ? _get()?.onConnectionState?.(state => { if (state.phase === 'connected' && !channel.online)
|
|
81
87
|
void channel.connect().catch(() => { }); }) : undefined;
|
|
@@ -84,6 +90,8 @@ export function brokerFactory(_get, _ask, configuration, provided) {
|
|
|
84
90
|
if (ended)
|
|
85
91
|
return;
|
|
86
92
|
ended = true;
|
|
93
|
+
endPromptDelivery?.('failed');
|
|
94
|
+
endPromptDelivery = undefined;
|
|
87
95
|
reconnectOff?.();
|
|
88
96
|
diagnostics.record(cause);
|
|
89
97
|
channel.close(cause);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STARTUP_STAGES } from "./startup-timing.js";
|
|
1
2
|
import { employeeExecutionInfo } from "./employee-info.js";
|
|
2
3
|
const redactionMarkers = new WeakSet();
|
|
3
4
|
function redaction(fields) {
|
|
@@ -349,6 +350,17 @@ function catalogScopeStructure(value, nested = false) {
|
|
|
349
350
|
return [key, opaqueStructure(child)];
|
|
350
351
|
}));
|
|
351
352
|
}
|
|
353
|
+
function startupTimingStructure(value) {
|
|
354
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
355
|
+
return opaqueStructure(value);
|
|
356
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => {
|
|
357
|
+
if (key === 'clock' && child === 'client-monotonic' || key === 'stage' && typeof child === 'string' && STARTUP_STAGES.includes(child) || key === 'outcome' && (child === 'completed' || child === 'failed'))
|
|
358
|
+
return [key, child];
|
|
359
|
+
if (['startMs', 'endMs', 'durationMs'].includes(key) && typeof child === 'number' && Number.isFinite(child) && child >= 0)
|
|
360
|
+
return [key, child];
|
|
361
|
+
return [key, opaqueStructure(child)];
|
|
362
|
+
}));
|
|
363
|
+
}
|
|
352
364
|
export function sanitizeObservation(observation, protectModelMaterial = false) {
|
|
353
365
|
const payload = snapshotPayload(observation.payload, new Set(), protectModelMaterial && observation.kind !== 'commands');
|
|
354
366
|
return freezeDeep({
|
|
@@ -359,13 +371,14 @@ export function sanitizeObservation(observation, protectModelMaterial = false) {
|
|
|
359
371
|
: observation.kind === 'session' && observation.code === 'CATALOG_SCOPE_INFORMATION' ? catalogScopeStructure(payload)
|
|
360
372
|
: observation.kind === 'session' && observation.code === 'CODEX_CONTEXT_SESSION_REPLACED' ? contextTransitionStructure(payload)
|
|
361
373
|
: observation.kind === 'session' && ['MODEL_CONFIGURATION_CONFIRMED', 'MODEL_CONFIGURATION_FAILED', 'MODEL_CONFIGURATION_INFORMATION', 'MODEL_CONFIGURATION_CHANGED_DURING_TURN', 'TURN_GATE_INFORMATION'].includes(observation.code) ? modelConfigurationStructure(payload)
|
|
362
|
-
: observation.kind === 'session' && observation.code === '
|
|
363
|
-
: observation.kind === '
|
|
364
|
-
: observation.kind === '
|
|
365
|
-
: observation.kind === '
|
|
366
|
-
: observation.kind === 'session' &&
|
|
367
|
-
: observation.kind === '
|
|
368
|
-
: observation.kind === '
|
|
369
|
-
:
|
|
374
|
+
: observation.kind === 'session' && observation.code === 'STARTUP_TIMING' ? startupTimingStructure(payload)
|
|
375
|
+
: observation.kind === 'session' && observation.code === 'REMOTE_CLOSE_REASON' ? closeStructure(payload)
|
|
376
|
+
: observation.kind === 'commands' ? catalogStructure(payload)
|
|
377
|
+
: observation.kind === 'usage' ? usageStructure(payload)
|
|
378
|
+
: observation.kind === 'session' && observation.code === 'EMPLOYEE_MCP_INFORMATION' ? (employeeExecutionInfo(observation.payload) ?? { information: 'unconfirmed' })
|
|
379
|
+
: observation.kind === 'session' && ['CLAUDE_EMPLOYEE_OPERATION', 'CLAUDE_EMPLOYEE_PROCESS', 'CLAUDE_EMPLOYEE_REVOKED', 'CLAUDE_EMPLOYEE_SCOPE'].includes(observation.code) ? employeeStructure(payload)
|
|
380
|
+
: observation.kind === 'need' ? payload
|
|
381
|
+
: observation.kind === 'tool' || ['SDK_ITEM', 'SDK_TOOL', 'ACP_SESSION_UPDATE', 'ACP_IDLE_UPDATE'].includes(observation.code) ? toolStructure(payload)
|
|
382
|
+
: opaqueStructure(payload),
|
|
370
383
|
});
|
|
371
384
|
}
|
package/dist/employee-native.js
CHANGED
|
@@ -2,14 +2,20 @@ import { createRequire } from 'node:module';
|
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { NeedError } from "./remote.js";
|
|
4
4
|
const require = createRequire(import.meta.url);
|
|
5
|
+
let installedPath;
|
|
5
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
7
|
/** Resolve the installed executable; no per-turn hash or version probe. */
|
|
7
8
|
export async function resolveEmployeeNative(ports = {}) {
|
|
8
9
|
if ((ports.platform ?? process.platform) !== EMPLOYEE_NATIVE.platform || (ports.arch ?? process.arch) !== EMPLOYEE_NATIVE.arch)
|
|
9
10
|
throw new NeedError('EMPLOYEE_PLATFORM_UNSUPPORTED', '当前设备尚未支持本机执行。', '对应平台执行器');
|
|
11
|
+
if (!ports.resolve && installedPath)
|
|
12
|
+
return { path: installedPath };
|
|
10
13
|
try {
|
|
11
14
|
const manifest = (ports.resolve ?? require.resolve)(EMPLOYEE_NATIVE.package + '/package.json');
|
|
12
|
-
|
|
15
|
+
const path = join(dirname(manifest), 'vendor', EMPLOYEE_NATIVE.triple, 'bin', 'codex');
|
|
16
|
+
if (!ports.resolve)
|
|
17
|
+
installedPath = path;
|
|
18
|
+
return { path };
|
|
13
19
|
}
|
|
14
20
|
catch {
|
|
15
21
|
throw new NeedError('AW_EMPLOYEE_BINARY_MISSING', '本机执行组件没有装齐,请重新安装插件。', '随插件安装的执行组件');
|
|
@@ -52,7 +52,8 @@ export async function inspectEmployeeWorkspace(get, employee, agent, api, reques
|
|
|
52
52
|
const stable = () => { sourceStable(); const now = api.getConnectionState(), location = api.getWorkspaceLocationState(), matches = location.items.filter(x => x.workspaceId === workspace.id); if (get() !== api || now.phase !== 'connected' || now.instanceId !== connection.instanceId || now.epoch !== connection.epoch || location.phase !== 'ready' || location.instanceId !== connection.instanceId || location.epoch !== connection.epoch || matches.length !== 1 || matches[0].source !== 'local' || matches[0].status !== 'selected' || matches[0].bindingId !== row.bindingId)
|
|
53
53
|
throw fail('EMPLOYEE_CONTEXT_CHANGED'); request.signal?.throwIfAborted(); };
|
|
54
54
|
stable();
|
|
55
|
-
const
|
|
55
|
+
const readContext = () => api.getLocalWorkspaceContext({ instanceId: connection.instanceId, epoch: connection.epoch, workspaceId: workspace.id, expectedBindingId: row.bindingId });
|
|
56
|
+
const context = await (request.startupTiming?.run('workspace-context', readContext) ?? readContext());
|
|
56
57
|
if (!context.ok)
|
|
57
58
|
throw connectNeedError(context.error);
|
|
58
59
|
stable();
|
|
@@ -122,6 +123,8 @@ export function createEmployeeProvider(get, options, agent) {
|
|
|
122
123
|
revoke(fail('CONNECTION_LOST'), 'endpoint.connection-change', [{ field: 'connection.instance-id', before: connection.instanceId, after: next.instanceId }, { field: 'connection.epoch', before: connection.epoch, after: next.epoch }, { field: 'connection.phase', before: 'connected', after: next.phase }]); }), network.onState(event => { if (event.kind === 'lost' || employee.getNetwork() !== network)
|
|
123
124
|
revoke(fail('CONNECTION_LOST'), 'endpoint.network-loss', [{ field: 'network.phase', before: null, after: event.state.phase }]); }));
|
|
124
125
|
details = await options.details?.(request, api, connection, target);
|
|
126
|
+
if (details)
|
|
127
|
+
request.startupTiming?.bind(event => details.record(event));
|
|
125
128
|
const sink = details;
|
|
126
129
|
closeDiagnostics = new CloseDiagnostics(event => sink?.record(event));
|
|
127
130
|
closeDiagnostics.bind(event => sink?.record(event));
|
|
@@ -131,11 +134,22 @@ export function createEmployeeProvider(get, options, agent) {
|
|
|
131
134
|
throw fail('EMPLOYEE_OPERATION_UNSUPPORTED');
|
|
132
135
|
if (!Number.isSafeInteger(request.acpMaxMessageBytes) || request.acpMaxMessageBytes < 1)
|
|
133
136
|
throw fail('SETTINGS_REQUIRED');
|
|
134
|
-
const
|
|
137
|
+
const prepareLocation = () => admitEmployeeLocation({ api: api, network, workspace, connection, expectedLocal: { instanceId: context.instanceId, epoch: context.epoch, workspaceId: context.workspaceId, bindingId: context.bindingId, directory: { ...context.directory } }, settingsPath: target.session.settingsPath, signal: roundSignal });
|
|
138
|
+
const resolveNative = () => employee.native();
|
|
139
|
+
// 仅把无授权、无目标的静态包路径解析与本轮N准备重叠。两项都收敛后,
|
|
140
|
+
// 按原顺序处理错误;每轮N准备、事件撤销、执行目标绑定仍完整执行。
|
|
141
|
+
const [locationResult, nativeResult] = await Promise.allSettled([
|
|
142
|
+
request.startupTiming?.run('endpoint-prepare', prepareLocation) ?? prepareLocation(),
|
|
143
|
+
request.startupTiming?.run('native-metadata', resolveNative) ?? resolveNative(),
|
|
144
|
+
]);
|
|
145
|
+
if (locationResult.status === 'rejected')
|
|
146
|
+
throw locationResult.reason;
|
|
147
|
+
if (nativeResult.status === 'rejected')
|
|
148
|
+
throw nativeResult.reason;
|
|
149
|
+
const admitted = locationResult.value, native = nativeResult.value;
|
|
150
|
+
roundSignal.throwIfAborted();
|
|
135
151
|
if (request.cwd && request.cwd !== admitted.cwd || request.bindingId && request.bindingId !== admitted.bindingId || request.workspaceId && request.workspaceId !== admitted.workspaceId)
|
|
136
152
|
throw fail('SESSION_CONTEXT_MISMATCH');
|
|
137
|
-
const native = await employee.native();
|
|
138
|
-
roundSignal.throwIfAborted();
|
|
139
153
|
if (!absolute(native.path))
|
|
140
154
|
throw fail('EMPLOYEE_BINARY_REQUIRED');
|
|
141
155
|
// Only executable identity belongs in this scope. Diagnostic metadata and object key
|
|
@@ -171,7 +185,8 @@ export function createEmployeeProvider(get, options, agent) {
|
|
|
171
185
|
if (!options.open)
|
|
172
186
|
throw fail('RUNTIME_REQUIRED');
|
|
173
187
|
// Host cwd is only the protected agent bootstrap/config directory. Native tools use admitted.cwd.
|
|
174
|
-
const
|
|
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 });
|
|
189
|
+
const host = opening = await (request.startupTiming?.run('broker-open', openHost) ?? openHost());
|
|
175
190
|
roundSignal.throwIfAborted();
|
|
176
191
|
// The old per-RPC identity check belongs once at the end of this round's opening.
|
|
177
192
|
if (get() !== api || employee.getNetwork() !== network)
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StartupTiming } from "./startup-timing.js";
|
|
1
2
|
import { ColdRecovery } from "./cold-recovery.js";
|
|
2
3
|
import { createSteeringReceipts, installLiveSteering, steeringMessageDigest } from "./live-steering.js";
|
|
3
4
|
import { ToolBridgeLoop } from "./toolbridge-loop.js";
|
|
@@ -379,7 +380,8 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
379
380
|
runtime.details.record(entry); };
|
|
380
381
|
const config = this.config();
|
|
381
382
|
const mode = 'session';
|
|
382
|
-
|
|
383
|
+
const startupTiming = new StartupTiming(this.preflightDiagnostics ? event => { void this.preflightDiagnostics.record(request, this.agent.loginProvider, event); } : undefined), endStartup = startupTiming.start('startup');
|
|
384
|
+
request = { sessionId: options.sessionId, mode: mode ?? 'session', signal, toolBridge: bridge, startupTiming };
|
|
383
385
|
const observeAbort = (source, initiator, reason) => { if (!source)
|
|
384
386
|
return; const record = () => { (request?.closeDiagnostics ?? runtime?.closeDiagnostics)?.record({ layer: 'adapter', initiator, reason, action: 'abort', changes: [{ field: 'adapter.turn-aborted', before: false, after: source.aborted }] }); }; source.addEventListener('abort', record, { once: true }); abortOffs.push(() => source.removeEventListener('abort', record)); };
|
|
385
387
|
observeAbort(original.signal, 'signal.caller', 'CALLER_ABORTED');
|
|
@@ -418,7 +420,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
418
420
|
request.userInputIds = Object.freeze(humanIds);
|
|
419
421
|
request.userMessageIds = request.userInputIds;
|
|
420
422
|
earlyStage = 'source-context';
|
|
421
|
-
await this.resolveRuntime.preflight?.(request);
|
|
423
|
+
await startupTiming.run('source-admission', async () => this.resolveRuntime.preflight?.(request));
|
|
422
424
|
options = { ...await this.coldRecovery?.projectCancelledInputs?.(options) ?? options, signal };
|
|
423
425
|
if (!usedColdCheckpoint)
|
|
424
426
|
checkpointIndex = readPointer(options, this.agent)?.index ?? -1;
|
|
@@ -436,7 +438,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
436
438
|
}
|
|
437
439
|
const projected = { ...options, messages: options.messages.filter((m, index) => index <= checkpointIndex || !('id' in m) || typeof m.id !== 'string' || !injected.has(m.id)) };
|
|
438
440
|
earlyStage = 'input-prepare';
|
|
439
|
-
let input = await prepareInput(projected, this.readImage);
|
|
441
|
+
let input = await startupTiming.run('input-prepare', () => prepareInput(projected, this.readImage));
|
|
440
442
|
const contextSha256 = createHash('sha256').update(input.systemPrompt ?? '').digest('hex');
|
|
441
443
|
request.contextSha256 = contextSha256;
|
|
442
444
|
const codex = this.agent.loginProvider === 'codex';
|
|
@@ -452,7 +454,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
452
454
|
options.signal = modelSignal;
|
|
453
455
|
request.signal = modelSignal;
|
|
454
456
|
earlyStage = 'runtime-resolve';
|
|
455
|
-
runtime = await this.resolveRuntime(request);
|
|
457
|
+
runtime = await startupTiming.run('runtime-resolve', () => this.resolveRuntime(request));
|
|
456
458
|
const closeSink = runtime.details;
|
|
457
459
|
runtime.closeDiagnostics ??= new CloseDiagnostics(event => closeSink?.record(event));
|
|
458
460
|
signal.throwIfAborted();
|
|
@@ -468,9 +470,10 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
468
470
|
if (runtime.hostWorkspace && mode === 'session' && Buffer.byteLength(JSON.stringify({ prompt: input.prompt, systemPrompt: input.systemPrompt }), 'utf8') > config.acpMaxMessageBytes)
|
|
469
471
|
throw new NeedError('ACP_MESSAGE_TOO_LARGE', '本轮输入超过已设置的会话消息容量,未截断或发送', '管理员调整acpMaxMessageBytes');
|
|
470
472
|
const details = runtime.details ?? await createRemoteDetails({ warn: line => console.warn(line) }).open({ sessionId: options.sessionId ?? 'unscoped', provider: this.agent.loginProvider, identity: runtime.identity, connection: runtime.connection });
|
|
473
|
+
startupTiming.bind(event => details.record(event));
|
|
471
474
|
if (bridge && runtime.employeeExecutionMeta && !runtime.hostWorkspace && bridge.table.size) {
|
|
472
475
|
bridge.enable(event => details.record(event));
|
|
473
|
-
bridgeMcp = await openToolBridgeMcp(bridge, config.acpMaxMessageBytes);
|
|
476
|
+
bridgeMcp = await startupTiming.run('bridge-open', () => openToolBridgeMcp(bridge, config.acpMaxMessageBytes));
|
|
474
477
|
}
|
|
475
478
|
recordInformation();
|
|
476
479
|
request.recordEarlyFailure = undefined;
|
|
@@ -518,7 +521,8 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
518
521
|
await runtime.cold.store.update(options.sessionId, options.provider, runtime.cold.id, row => { (row.localNotices ??= []).push({ beforeUpdate: nativeUpdates, text }); }); push(mapper.text(text)); });
|
|
519
522
|
let promptPermit;
|
|
520
523
|
let confirmedNativeMode;
|
|
521
|
-
|
|
524
|
+
let endDispatch = () => { };
|
|
525
|
+
const hooks = { closeDiagnostics: runtime.closeDiagnostics, broker: runtime.broker, sessionOwnership: runtime.sessionOwnership, employeeExecution: runtime.employeeExecution, startupTiming, onPromptDispatched: () => { endDispatch(); endStartup(); }, ...this.permissions ? { promptGuard: () => {
|
|
522
526
|
if (!promptPermit)
|
|
523
527
|
throw new NeedError('PERMISSION_POLICY_CHANGED', '当前权限没有保持确认,本次没有继续派发。', '当前权限代次和同值回执');
|
|
524
528
|
return promptPermit;
|
|
@@ -584,12 +588,13 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
584
588
|
return;
|
|
585
589
|
const remoteMode = permissionMode(this.agent.loginProvider, policy);
|
|
586
590
|
details.record({ kind: 'session', severity: 'info', code: 'DSH_PERMISSION_POLICY', summary: '按DSH当前会话权限同步远程工具;不会把关闭审批提示解释为自动批准。', payload: { ...policy, remoteMode } });
|
|
587
|
-
await session.selectPermissionMode(remoteMode, modelSignal, this.agent.loginProvider);
|
|
591
|
+
await startupTiming.run('permission-confirm', () => session.selectPermissionMode(remoteMode, modelSignal, this.agent.loginProvider));
|
|
588
592
|
confirmedNativeMode = remoteMode;
|
|
589
593
|
permissionKey = next;
|
|
590
594
|
});
|
|
591
595
|
};
|
|
592
596
|
const dispatchPrompt = async () => {
|
|
597
|
+
endDispatch = startupTiming.start('prompt-dispatch');
|
|
593
598
|
if (!this.permissions)
|
|
594
599
|
return session.prompt(input.prompt, modelSignal);
|
|
595
600
|
// New official policy events can append work while an ACK is awaited.
|
|
@@ -611,14 +616,14 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
611
616
|
const task = (async () => {
|
|
612
617
|
remoteAttempted = true;
|
|
613
618
|
try {
|
|
614
|
-
await session.start(runtime.execution?.hostCwd ?? runtime.cwd, previous?.sessionId, modelSignal, { systemPrompt: input.systemPrompt, ...(bridgeMcp ? { toolBridgeServers: bridgeMcp.mcpServers } : {}), ...(runtime.execution ? { employeeRouting: runtime.execution.routing } : {}), ...(codex ? { codexNewSessionOnly: true } : {}), ...(runtime.employeeExecutionMeta ? { employeeExecution: runtime.employeeExecutionMeta } : {}) }, input.prompt);
|
|
619
|
+
await session.start(runtime.execution?.hostCwd ?? runtime.cwd, previous?.sessionId, modelSignal, { systemPrompt: input.systemPrompt, ...(bridgeMcp ? { toolBridgeServers: bridgeMcp.mcpServers } : {}), ...(runtime.execution ? { employeeRouting: runtime.execution.routing } : {}), ...(codex ? { codexNewSessionOnly: true, initialModel: selected.value } : {}), ...(runtime.employeeExecutionMeta ? { employeeExecution: runtime.employeeExecutionMeta } : {}) }, input.prompt);
|
|
615
620
|
}
|
|
616
621
|
catch (error) {
|
|
617
622
|
details.record({ kind: 'session', severity: 'action-required', code: 'SESSION_START_FAILED', summary: '远端会话建立或恢复失败,本轮用户输入未发送。', payload: { operation: previous ? 'resume-or-load' : 'new', reason: closeCode(error, 'ACP_FAILED'), promptDispatched: false } });
|
|
618
623
|
throw error;
|
|
619
624
|
}
|
|
620
625
|
try {
|
|
621
|
-
const actual = await session.selectModel(selected.value, options.reasoningEffort, modelSignal);
|
|
626
|
+
const actual = await startupTiming.run('model-confirm', () => session.selectModel(selected.value, options.reasoningEffort, modelSignal));
|
|
622
627
|
// This lease is tied to the trusted host-user and instance/epoch.
|
|
623
628
|
// Its mapping and this turn's exact setter ACK are different facts.
|
|
624
629
|
modelConfiguration = { selected: { ...selected, ...(options.reasoningEffort === undefined ? {} : { effort: options.reasoningEffort }) }, configured: actual, resolvedModel: selected.resolvedModel ?? selected.value, status: 'remote-configured', ...(this.agent.loginProvider === 'claude' ? { resolvedModelSource: 'host-user-catalog', sessionModelReported: false } : {}) };
|
|
@@ -685,6 +690,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
685
690
|
return result;
|
|
686
691
|
}
|
|
687
692
|
catch (error) {
|
|
693
|
+
endDispatch('failed');
|
|
688
694
|
promptFailed = true;
|
|
689
695
|
throw error;
|
|
690
696
|
}
|
|
@@ -753,6 +759,7 @@ export class CodexRemoteAdapter extends LlmAdapter {
|
|
|
753
759
|
runtime?.closeDiagnostics?.record({ layer: 'adapter', initiator: 'adapter.turn-failure', reason: closeCode(error, signal.aborted ? 'ABORTED' : 'TURN_FAILED'), action: 'failure' });
|
|
754
760
|
recordInformation();
|
|
755
761
|
failureCode = error instanceof NeedError || error instanceof ModelConfigurationError ? error.code : error instanceof LlmError ? error.code : 'TURN_PREPARATION_FAILED';
|
|
762
|
+
endStartup('failed');
|
|
756
763
|
withRemoteFailureEvidence(error, runtime?.employeeRemoteCloseReason?.(), failureCode);
|
|
757
764
|
activeMapper?.flushMetadata();
|
|
758
765
|
if (request?.recordEarlyFailure)
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StartupTiming } from './startup-timing.ts';
|
|
1
2
|
import type { ColdRound, ColdStore } from './cold-store.ts';
|
|
2
3
|
import type { ToolBridge } from './toolbridge.ts';
|
|
3
4
|
import { type SessionSource } from './host-workspace.ts';
|
|
@@ -80,6 +81,7 @@ export interface Runtime {
|
|
|
80
81
|
closeDiagnostics?: CloseDiagnostics;
|
|
81
82
|
}
|
|
82
83
|
export interface RuntimeRequest extends Invocation {
|
|
84
|
+
startupTiming?: StartupTiming;
|
|
83
85
|
toolBridge?: ToolBridge;
|
|
84
86
|
workspaceSource?: SessionSource;
|
|
85
87
|
hostSource?: Extract<SessionSource, {
|
package/dist/provider.js
CHANGED
|
@@ -169,7 +169,7 @@ export function connectProvider(get, options = {}) {
|
|
|
169
169
|
request.localContext = await module.inspectEmployeeWorkspace(get, options.employee, agent, api, request);
|
|
170
170
|
}
|
|
171
171
|
sourceStage = 'login-readiness';
|
|
172
|
-
const
|
|
172
|
+
const loginReady = async () => {
|
|
173
173
|
request.localAdmissionCheck?.();
|
|
174
174
|
const before = api.getConnectionState();
|
|
175
175
|
const target = await ensureReady(api, agent.loginProvider, request.signal);
|
|
@@ -179,7 +179,8 @@ export function connectProvider(get, options = {}) {
|
|
|
179
179
|
throw new NeedError('CONNECTION_LOST', '远程主机连接组件已更换', '当前员工连接');
|
|
180
180
|
const connection = await waitForLogin(api, agent.loginProvider, before, get, request.signal);
|
|
181
181
|
return { target, connection };
|
|
182
|
-
}
|
|
182
|
+
};
|
|
183
|
+
const { target, connection } = await (request.startupTiming?.run('login-readiness', loginReady) ?? loginReady());
|
|
183
184
|
if (request.workspaceSource?.source !== 'host' && request.identity && request.identity !== identity(target))
|
|
184
185
|
throw new NeedError('SESSION_CONTEXT_MISMATCH', '员工主机与原会话不一致,请新建会话', '原员工主机');
|
|
185
186
|
request.localAdmissionCheck?.();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DetailObservation } from './conversation-details.ts';
|
|
2
|
+
/** 仅记录单调时钟和固定阶段,不收集命令、路径、正文或授权资料。 */
|
|
3
|
+
export declare const STARTUP_STAGES: readonly ["startup", "source-admission", "workspace-context", "login-readiness", "input-prepare", "runtime-resolve", "endpoint-prepare", "native-metadata", "broker-open", "bridge-open", "acp-initialize", "acp-session-new", "acp-session-load", "acp-session-resume", "model-confirm", "permission-confirm", "prompt-dispatch", "prompt-delivery"];
|
|
4
|
+
export type StartupStage = typeof STARTUP_STAGES[number];
|
|
5
|
+
export declare class StartupTiming {
|
|
6
|
+
private readonly origin;
|
|
7
|
+
private pending;
|
|
8
|
+
private sink?;
|
|
9
|
+
constructor(sink?: (event: DetailObservation) => void);
|
|
10
|
+
bind(sink: (event: DetailObservation) => void): void;
|
|
11
|
+
private send;
|
|
12
|
+
start(stage: StartupStage): (outcome?: 'completed' | 'failed') => void;
|
|
13
|
+
run<T>(stage: StartupStage, operation: () => Promise<T>): Promise<T>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** 仅记录单调时钟和固定阶段,不收集命令、路径、正文或授权资料。 */
|
|
2
|
+
export const STARTUP_STAGES = ['startup', 'source-admission', 'workspace-context', 'login-readiness', 'input-prepare', 'runtime-resolve', 'endpoint-prepare', 'native-metadata', 'broker-open', 'bridge-open', 'acp-initialize', 'acp-session-new', 'acp-session-load', 'acp-session-resume', 'model-confirm', 'permission-confirm', 'prompt-dispatch', 'prompt-delivery'];
|
|
3
|
+
export class StartupTiming {
|
|
4
|
+
origin = performance.now();
|
|
5
|
+
pending = [];
|
|
6
|
+
sink;
|
|
7
|
+
constructor(sink) { this.sink = sink; }
|
|
8
|
+
bind(sink) { this.sink = sink; for (const event of this.pending.splice(0))
|
|
9
|
+
this.send(event); }
|
|
10
|
+
send(event) { if (!this.sink) {
|
|
11
|
+
this.pending.push(event);
|
|
12
|
+
return;
|
|
13
|
+
} try {
|
|
14
|
+
this.sink(event);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
console.warn('[remote-agent] 启动计时未保存');
|
|
18
|
+
} }
|
|
19
|
+
start(stage) {
|
|
20
|
+
const startMs = performance.now() - this.origin;
|
|
21
|
+
let ended = false;
|
|
22
|
+
return (outcome = 'completed') => { if (ended)
|
|
23
|
+
return; ended = true; const endMs = performance.now() - this.origin; this.send({ kind: 'session', severity: 'info', code: 'STARTUP_TIMING', summary: '开工前阶段计时', payload: { clock: 'client-monotonic', stage, startMs, endMs, durationMs: endMs - startMs, outcome } }); };
|
|
24
|
+
}
|
|
25
|
+
async run(stage, operation) { const end = this.start(stage); try {
|
|
26
|
+
const value = await operation();
|
|
27
|
+
end();
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
end('failed');
|
|
32
|
+
throw error;
|
|
33
|
+
} }
|
|
34
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
|
-
export declare const TOOLBRIDGE_EXCLUDED: readonly ["read", "write", "edit", "read_image", "glob", "grep", "bash", "pwsh", "str_replace_editor", "
|
|
4
|
+
export declare const TOOLBRIDGE_EXCLUDED: readonly ["read", "write", "edit", "read_image", "glob", "grep", "bash", "pwsh", "str_replace_editor", "terminal_open", "terminal_send", "terminal_read", "terminal_signal", "terminal_close", "terminal_list", "run_code"];
|
|
5
5
|
export interface BridgeTool {
|
|
6
6
|
alias: string;
|
|
7
7
|
schema: ToolSchema;
|
package/dist/toolbridge-table.js
CHANGED
|
@@ -3,7 +3,6 @@ import { NeedError } from "./remote.js";
|
|
|
3
3
|
/** Fixed official tool names; no description heuristics or plugin-name branches. */
|
|
4
4
|
export const TOOLBRIDGE_EXCLUDED = Object.freeze([
|
|
5
5
|
'read', 'write', 'edit', 'read_image', 'glob', 'grep', 'bash', 'pwsh', 'str_replace_editor',
|
|
6
|
-
'load_workspace_dependencies',
|
|
7
6
|
'terminal_open', 'terminal_send', 'terminal_read', 'terminal_signal', 'terminal_close', 'terminal_list',
|
|
8
7
|
'run_code',
|
|
9
8
|
]);
|