@ai-workbench/remote-agent 0.9.0-toolbridge.35 → 0.9.0-toolbridge.37-rc.4

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.
@@ -0,0 +1,67 @@
1
+ export interface NativeContentFile {
2
+ path: string;
3
+ bytes: Uint8Array;
4
+ executable?: boolean;
5
+ }
6
+ export interface NativeSkillPackage {
7
+ name: string;
8
+ description: string;
9
+ files: readonly NativeContentFile[];
10
+ }
11
+ export interface NativeContentSnapshot {
12
+ scopeId: string;
13
+ employeeCwd: string;
14
+ project: readonly NativeContentFile[];
15
+ skills: readonly NativeSkillPackage[];
16
+ }
17
+ export interface NativeContentLayout {
18
+ generation: string;
19
+ hostCwd: string;
20
+ codexSkillsRoot: string;
21
+ claudePluginRoot: string;
22
+ claudeNamespace: string;
23
+ cwdMap: {
24
+ native: string;
25
+ employee: string;
26
+ };
27
+ }
28
+ export interface NativeContentLimits {
29
+ maxBytes: number;
30
+ signal?: AbortSignal;
31
+ }
32
+ /** Reads only an explicitly selected DSH package. Never scans the host native catalog. */
33
+ export declare function captureNativeSkill(input: {
34
+ name: string;
35
+ description: string;
36
+ skillFile: string;
37
+ resourceRoot: string;
38
+ content?: string;
39
+ }, options: NativeContentLimits): Promise<NativeSkillPackage>;
40
+ /** The caller supplies the exact instruction/import closure; no repository-wide copying. */
41
+ export declare function captureNativeProject(employeeCwd: string, paths: readonly string[], options: NativeContentLimits): Promise<NativeContentFile[]>;
42
+ interface WireFile {
43
+ path: string;
44
+ data: string;
45
+ sha256: string;
46
+ executable: boolean;
47
+ }
48
+ export interface NativeContentPlan {
49
+ version: 1;
50
+ generation: string;
51
+ scopeHash: string;
52
+ employeeCwd: string;
53
+ claudeNamespace: string;
54
+ files: readonly WireFile[];
55
+ }
56
+ /** Only native manifest metadata is generated. Skill bodies come verbatim from their provider; project files remain original bytes. */
57
+ export declare function nativeContentPlan(snapshot: NativeContentSnapshot, options: NativeContentLimits): NativeContentPlan;
58
+ /** Immutable generations coexist with user native skills; this never rewrites their files. */
59
+ export declare function materializeNativeContent(plan: NativeContentPlan, root: string, signal?: AbortSignal, employeeProject?: boolean): Promise<NativeContentLayout>;
60
+ /** Maps structured native paths only. Shell source is never searched or rewritten. */
61
+ export declare function employeePathForNative(path: string, map: NativeContentLayout['cwdMap']): string;
62
+ /** Register only this managed generation; user native packages are never overwritten. */
63
+ export declare function registerNativeContent(plan: NativeContentPlan, root: string, home: string): Promise<NativeContentLayout>;
64
+ export declare function activateNativeContent(plan: NativeContentPlan, root: string): Promise<void>;
65
+ /** Collect only project instruction files and their relative native imports. */
66
+ export declare function captureProjectInstructions(cwd: string, options: NativeContentLimits): Promise<NativeContentFile[]>;
67
+ export {};
@@ -0,0 +1,294 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, writeFile, symlink, readlink } from 'node:fs/promises';
3
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
4
+ const hash = (value) => createHash('sha256').update(value).digest('hex');
5
+ const fail = (reason) => { throw Object.assign(new Error('EMPLOYEE_CONTEXT_UNAVAILABLE'), { reason }); };
6
+ const name = (value) => /^[a-z0-9][a-z0-9-]*$/.test(value);
7
+ function subpath(value) {
8
+ if (!value || value.includes('\0') || value.includes('\\') || isAbsolute(value) || value.split('/').some(part => !part || part === '.' || part === '..'))
9
+ fail('PATH_INVALID');
10
+ return value;
11
+ }
12
+ function within(root, path) { const r = relative(root, path); return r === '' || !r.startsWith('..' + sep) && r !== '..' && !isAbsolute(r); }
13
+ function check(options, bytes) { options.signal?.throwIfAborted(); if (!Number.isSafeInteger(options.maxBytes) || options.maxBytes < 1 || bytes > options.maxBytes)
14
+ fail('TOO_LARGE'); }
15
+ /** Reads only an explicitly selected DSH package. Never scans the host native catalog. */
16
+ export async function captureNativeSkill(input, options) {
17
+ if (!name(input.name) || typeof input.description !== 'string' || !input.description)
18
+ fail('SKILL_INVALID');
19
+ const root = await realpath(input.resourceRoot), skill = await realpath(input.skillFile);
20
+ if (dirname(skill) !== root || basename(skill) !== 'SKILL.md')
21
+ fail('PACKAGE_ROOT_REQUIRED');
22
+ const files = [];
23
+ let total = 0;
24
+ const walk = async (directory) => {
25
+ for (const entry of (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
26
+ options.signal?.throwIfAborted();
27
+ const path = join(directory, entry.name), before = await lstat(path);
28
+ if (before.isSymbolicLink())
29
+ fail('RESOURCE_SYMLINK');
30
+ if (before.isDirectory()) {
31
+ await walk(path);
32
+ continue;
33
+ }
34
+ if (!before.isFile())
35
+ fail('RESOURCE_TYPE');
36
+ const bytes = await readFile(path), after = await lstat(path);
37
+ total += bytes.byteLength;
38
+ check(options, total);
39
+ if (before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size || before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs)
40
+ fail('SOURCE_CHANGED');
41
+ files.push({ path: relative(root, path).split(sep).join('/'), bytes, executable: !!(before.mode & 0o111) });
42
+ }
43
+ };
44
+ await walk(root);
45
+ if (await realpath(input.resourceRoot) !== root || await realpath(input.skillFile) !== skill)
46
+ fail('SOURCE_CHANGED');
47
+ if (input.content !== undefined) {
48
+ const index = files.findIndex(file => file.path === 'SKILL.md'), original = files[index];
49
+ if (!original)
50
+ fail('SKILL_INVALID');
51
+ const raw = Buffer.from(original.bytes).toString('utf8'), frontmatter = /^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/u.exec(raw)?.[0];
52
+ const header = frontmatter ?? fail('SKILL_INVALID');
53
+ const bytes = Buffer.from(header + (header.endsWith('\n') ? '' : '\n') + input.content);
54
+ total += bytes.byteLength - original.bytes.byteLength;
55
+ check(options, total);
56
+ files[index] = { ...original, bytes };
57
+ }
58
+ return { name: input.name, description: input.description, files };
59
+ }
60
+ /** The caller supplies the exact instruction/import closure; no repository-wide copying. */
61
+ export async function captureNativeProject(employeeCwd, paths, options) {
62
+ const root = await realpath(employeeCwd), files = [];
63
+ let total = 0;
64
+ for (const item of paths) {
65
+ const path = subpath(item), full = join(root, path), canonical = await realpath(full);
66
+ if (!within(root, canonical))
67
+ fail('PROJECT_ESCAPE');
68
+ const before = await lstat(full);
69
+ if (!before.isFile() || before.isSymbolicLink())
70
+ fail('PROJECT_TYPE');
71
+ const bytes = await readFile(full), after = await lstat(full);
72
+ total += bytes.byteLength;
73
+ check(options, total);
74
+ if (before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size || before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs || await realpath(full) !== canonical)
75
+ fail('SOURCE_CHANGED');
76
+ files.push({ path, bytes });
77
+ }
78
+ return files;
79
+ }
80
+ /** Only native manifest metadata is generated. Skill bodies come verbatim from their provider; project files remain original bytes. */
81
+ export function nativeContentPlan(snapshot, options) {
82
+ if (!snapshot.scopeId || !isAbsolute(snapshot.employeeCwd) || snapshot.employeeCwd.includes('\0'))
83
+ fail('SCOPE_INVALID');
84
+ const files = [], paths = new Set();
85
+ let total = 0;
86
+ const add = (path, file) => { subpath(path); if (paths.has(path))
87
+ fail('DUPLICATE_PATH'); paths.add(path); total += file.bytes.byteLength; check(options, total); files.push({ path, data: Buffer.from(file.bytes).toString('base64'), sha256: hash(file.bytes), executable: !!file.executable }); };
88
+ for (const file of snapshot.project)
89
+ add('project/' + subpath(file.path), file);
90
+ const names = new Set();
91
+ for (const skill of snapshot.skills) {
92
+ if (!name(skill.name) || !skill.description || names.has(skill.name) || !skill.files.some(file => file.path === 'SKILL.md'))
93
+ fail('SKILL_INVALID');
94
+ names.add(skill.name);
95
+ }
96
+ const scopeHash = hash(snapshot.scopeId), claudeNamespace = 'dsh-' + scopeHash.slice(0, 12);
97
+ add('plugin/.claude-plugin/plugin.json', { path: 'plugin.json', bytes: Buffer.from(JSON.stringify({ name: claudeNamespace, version: '1.0.0' })) });
98
+ for (const skill of snapshot.skills)
99
+ for (const file of skill.files) {
100
+ add('skills/' + skill.name + '/' + subpath(file.path), file);
101
+ add('plugin/skills/' + skill.name + '/' + subpath(file.path), file);
102
+ }
103
+ files.sort((a, b) => a.path.localeCompare(b.path));
104
+ const generation = hash(JSON.stringify({ scopeHash, employeeCwd: snapshot.employeeCwd, files: files.map(({ path, sha256, executable }) => ({ path, sha256, executable })) }));
105
+ return { version: 1, generation, scopeHash, employeeCwd: snapshot.employeeCwd, claudeNamespace, files };
106
+ }
107
+ function layout(root, plan) {
108
+ const base = join(root, plan.generation), hostCwd = join(root, 'current', 'project', plan.employeeCwd.replace(/^\/+/, ''));
109
+ return { generation: plan.generation, hostCwd, codexSkillsRoot: join(base, 'skills'), claudePluginRoot: join(base, 'plugin'), claudeNamespace: plan.claudeNamespace, cwdMap: { native: hostCwd, employee: plan.employeeCwd } };
110
+ }
111
+ /** Immutable generations coexist with user native skills; this never rewrites their files. */
112
+ export async function materializeNativeContent(plan, root, signal, employeeProject = false) {
113
+ validatePlan(plan);
114
+ signal?.throwIfAborted();
115
+ root = resolve(root);
116
+ await mkdir(root, { recursive: true, mode: 0o700 });
117
+ const info = await lstat(root);
118
+ if (!info.isDirectory() || info.isSymbolicLink() || info.uid !== process.getuid?.() || info.mode & 0o077 || await realpath(root) !== root)
119
+ fail('DESTINATION_UNSAFE');
120
+ const destination = join(root, plan.generation), expected = JSON.stringify(plan), manifest = 'native-content.json';
121
+ const verify = async () => { if (await readFile(join(destination, manifest), 'utf8') !== expected)
122
+ fail('GENERATION_CONFLICT'); for (const file of plan.files) {
123
+ const p = join(destination, file.path), s = await lstat(p);
124
+ if (!s.isFile() || s.isSymbolicLink() || hash(await readFile(p)) !== file.sha256)
125
+ fail('GENERATION_CONFLICT');
126
+ } };
127
+ try {
128
+ await lstat(destination);
129
+ await verify();
130
+ return layout(root, plan);
131
+ }
132
+ catch (error) {
133
+ if (error.code !== 'ENOENT')
134
+ throw error;
135
+ }
136
+ const stage = await mkdtemp(join(root, '.stage-'));
137
+ try {
138
+ if (employeeProject)
139
+ await symlink('/', join(stage, 'project'));
140
+ for (const file of plan.files) {
141
+ signal?.throwIfAborted();
142
+ if (employeeProject && file.path.startsWith('project/')) {
143
+ if (hash(await readFile('/' + file.path.slice('project/'.length))) !== file.sha256)
144
+ fail('SOURCE_CHANGED');
145
+ continue;
146
+ }
147
+ const path = join(stage, file.path);
148
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
149
+ await writeFile(path, Buffer.from(file.data, 'base64'), { flag: 'wx', mode: file.executable ? 0o700 : 0o600 });
150
+ }
151
+ if (!employeeProject)
152
+ await mkdir(join(stage, 'project', plan.employeeCwd.replace(/^\/+/, '')), { recursive: true, mode: 0o700 });
153
+ await mkdir(join(stage, 'skills'), { recursive: true, mode: 0o700 });
154
+ await mkdir(join(stage, 'plugin', 'skills'), { recursive: true, mode: 0o700 });
155
+ await writeFile(join(stage, manifest), expected, { flag: 'wx', mode: 0o600 });
156
+ signal?.throwIfAborted();
157
+ try {
158
+ await rename(stage, destination);
159
+ }
160
+ catch (error) {
161
+ if (!['EEXIST', 'ENOTEMPTY'].includes(error.code ?? ''))
162
+ throw error;
163
+ await verify();
164
+ }
165
+ return layout(root, plan);
166
+ }
167
+ finally {
168
+ await rm(stage, { recursive: true, force: true });
169
+ }
170
+ }
171
+ function validatePlan(plan) {
172
+ if (plan.version !== 1 || !plan.files.length || !isAbsolute(plan.employeeCwd) || !name(plan.claudeNamespace) || !/^([a-f0-9]{64})$/.test(plan.generation) || !/^([a-f0-9]{64})$/.test(plan.scopeHash))
173
+ fail('PLAN_INVALID');
174
+ const paths = new Set();
175
+ for (const f of plan.files) {
176
+ subpath(f.path);
177
+ if (paths.has(f.path) || !f.path.match(/^(project|skills|plugin)\//) || hash(Buffer.from(f.data, 'base64')) !== f.sha256)
178
+ fail('PLAN_INVALID');
179
+ paths.add(f.path);
180
+ }
181
+ const generation = hash(JSON.stringify({ scopeHash: plan.scopeHash, employeeCwd: plan.employeeCwd, files: plan.files.map(({ path, sha256, executable }) => ({ path, sha256, executable })) }));
182
+ if (generation !== plan.generation)
183
+ fail('PLAN_INVALID');
184
+ }
185
+ /** Maps structured native paths only. Shell source is never searched or rewritten. */
186
+ export function employeePathForNative(path, map) {
187
+ if (!isAbsolute(path))
188
+ return path;
189
+ const p = resolve(path), root = resolve(map.native);
190
+ return within(root, p) ? resolve(map.employee, relative(root, p)) : path;
191
+ }
192
+ /** Register only this managed generation; user native packages are never overwritten. */
193
+ export async function registerNativeContent(plan, root, home) {
194
+ const result = await materializeNativeContent(plan, root);
195
+ const nativeRoots = [join(home, '.agents', 'skills'), join(home, '.claude', 'skills')];
196
+ for (const [index, parent] of nativeRoots.entries()) {
197
+ await mkdir(parent, { recursive: true, mode: 0o700 });
198
+ const link = join(parent, '.aw-dsh-' + plan.scopeHash.slice(0, 24)), target = join(root, plan.generation, index === 0 ? 'skills' : 'plugin');
199
+ try {
200
+ if (await readlink(link) === target)
201
+ continue;
202
+ const info = await lstat(link);
203
+ if (!info.isSymbolicLink() || info.uid !== process.getuid?.())
204
+ fail('DESTINATION_UNSAFE');
205
+ }
206
+ catch (error) {
207
+ if (error.code !== 'ENOENT')
208
+ throw error;
209
+ }
210
+ const staged = link + '.' + randomUUID();
211
+ try {
212
+ await symlink(target, staged);
213
+ await rename(staged, link);
214
+ }
215
+ finally {
216
+ await rm(staged, { force: true });
217
+ }
218
+ }
219
+ await activateNativeContent(plan, root);
220
+ return result;
221
+ }
222
+ export async function activateNativeContent(plan, root) {
223
+ const link = join(root, 'current'), staged = link + '.' + randomUUID();
224
+ try {
225
+ try {
226
+ const stat = await lstat(link);
227
+ if (!stat.isSymbolicLink() || stat.uid !== process.getuid?.())
228
+ fail('DESTINATION_UNSAFE');
229
+ }
230
+ catch (error) {
231
+ if (error.code !== 'ENOENT')
232
+ throw error;
233
+ }
234
+ await symlink(plan.generation, staged);
235
+ await rename(staged, link);
236
+ }
237
+ finally {
238
+ await rm(staged, { force: true });
239
+ }
240
+ }
241
+ /** Collect only project instruction files and their relative native imports. */
242
+ export async function captureProjectInstructions(cwd, options) {
243
+ const files = new Map();
244
+ let total = 0;
245
+ const add = async (path) => {
246
+ options.signal?.throwIfAborted();
247
+ let bytes;
248
+ try {
249
+ bytes = await readFile(path);
250
+ }
251
+ catch (error) {
252
+ if (['ENOENT', 'ENOTDIR', 'EISDIR'].includes(error.code ?? ''))
253
+ return;
254
+ throw error;
255
+ }
256
+ path = resolve(path);
257
+ const key = path.replace(/^\/+/, '');
258
+ if (files.has(key))
259
+ return;
260
+ total += bytes.byteLength;
261
+ check(options, total);
262
+ files.set(key, { path: key, bytes });
263
+ // Native CLAUDE imports are kept as raw files; no rewriting or prose projection.
264
+ for (const match of bytes.toString('utf8').matchAll(/(?:^|\s)@([^\s`]+\.md)(?=\s|$)/gm))
265
+ if (!isAbsolute(match[1]))
266
+ await add(resolve(dirname(path), match[1]));
267
+ };
268
+ const rules = async (path) => {
269
+ let entries;
270
+ try {
271
+ entries = await readdir(path, { withFileTypes: true });
272
+ }
273
+ catch (error) {
274
+ if (['ENOENT', 'ENOTDIR'].includes(error.code ?? ''))
275
+ return;
276
+ throw error;
277
+ }
278
+ for (const entry of entries) {
279
+ const full = join(path, entry.name);
280
+ if (entry.isDirectory())
281
+ await rules(full);
282
+ else if (entry.isFile() && entry.name.endsWith('.md'))
283
+ await add(full);
284
+ }
285
+ };
286
+ for (let path = resolve(cwd);; path = dirname(path)) {
287
+ for (const name of ['AGENTS.md', 'CLAUDE.md', 'CLAUDE.local.md', '.claude/CLAUDE.md'])
288
+ await add(join(path, name));
289
+ await rules(join(path, '.claude/rules'));
290
+ if (path === dirname(path))
291
+ break;
292
+ }
293
+ return [...files.values()].sort((a, b) => a.path.localeCompare(b.path));
294
+ }
@@ -4,7 +4,7 @@ export function validPreflightPayload(value) {
4
4
  const p = value, keys = ['phase', 'stage', 'workspaceId', 'bindingId', 'source', 'status', 'outcome'];
5
5
  const id = (v) => v === null || typeof v === 'string' && v.length > 0 && !/[\x00-\x1f\x7f]/.test(v);
6
6
  return Object.keys(p).length === keys.length && keys.every(key => Object.hasOwn(p, key)) && p.phase === 'workspace-source-admission'
7
- && ['source-context', 'input-acceptance', 'login-readiness', 'local-admission', 'input-prepare', 'model-catalog', 'runtime-resolve'].includes(p.stage)
7
+ && ['source-context', 'input-acceptance', 'login-readiness', 'input-prepare', 'model-catalog', 'runtime-resolve'].includes(p.stage)
8
8
  && id(p.workspaceId) && id(p.bindingId) && [null, 'local', 'host'].includes(p.source)
9
9
  && [null, 'unselected', 'selected', 'legacy-confirmation-required', 'invalid'].includes(p.status)
10
10
  && ['confirmation-required', 'confirmed', 'declined', 'cancelled', 'failed'].includes(p.outcome);
@@ -15,8 +15,6 @@ export function employeeFailure(code, brand = 'codex', promptDispatched = true)
15
15
  WORKSPACE_SOURCE_STORAGE_FAILED: '这条会话的文件来源未能保存,本轮工作区准备失败;请恢复后在原会话重试。',
16
16
  WORKSPACE_LOCATION_REQUIRED: '我需要你确认这个工作区使用哪一个文件夹,本轮未执行;你的原话仍保留。',
17
17
  WORKSPACE_LOCATION_CONFLICT: '工作区来源选择已更新,本次确认不能覆盖新的选择;本轮未执行,你的原话仍保留。',
18
- LOCAL_USER_TURN_CHANGED: '本次输入已变化,本轮已停止,请确认对话后重新发送。',
19
- LOCAL_USER_TURN_UNCONFIRMED: '无法核对本次员工输入,本轮已停止;请在当前会话重新发送。',
20
18
  AW_EMPLOYEE_ENVIRONMENTS_CONFIG_UNSUPPORTED: '主机环境配置会覆盖本机执行位置,本轮已停止;请联系管理员调整后在原会话重试。',
21
19
  EMPLOYEE_CONTEXT_UNAVAILABLE: '我需要远程主机连接组件提供当前本机工作区,本轮未执行。',
22
20
  EMPLOYEE_ENDPOINT_UNAVAILABLE: '我需要员工电脑的执行连接就绪,本轮未执行;请联系管理员检查连接组件。',
@@ -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 type { ColdRound, ColdStore } from './cold-store.ts';
3
4
  import type { ToolBridge } from './toolbridge.ts';
@@ -29,6 +30,8 @@ export interface EmployeeExecution {
29
30
  validate(signal?: AbortSignal): Promise<void>;
30
31
  }
31
32
  export interface Runtime {
33
+ nativeContent?: NativeSessionContent;
34
+ customInstructions?: string;
32
35
  localDirectory?: {
33
36
  path: string;
34
37
  device: number;
@@ -81,6 +84,7 @@ export interface Runtime {
81
84
  closeDiagnostics?: CloseDiagnostics;
82
85
  }
83
86
  export interface RuntimeRequest extends Invocation {
87
+ nativeEmployeeCwd?: string;
84
88
  startupTiming?: StartupTiming;
85
89
  toolBridge?: ToolBridge;
86
90
  workspaceSource?: SessionSource;
@@ -88,17 +92,13 @@ export interface RuntimeRequest extends Invocation {
88
92
  source: 'host';
89
93
  }>;
90
94
  closeDiagnostics?: CloseDiagnostics;
91
- previousContextSha256?: string;
92
95
  preflightFailureRecorded?: boolean;
93
96
  recordEarlyFailure?: (error: unknown, stage: SourceAdmissionStage) => Promise<void>;
94
- userInputIds?: readonly string[];
95
97
  localContext?: Readonly<LocalWorkspaceContext>;
96
98
  localAdmissionCheck?: () => void;
97
- userMessageIds?: readonly string[];
98
99
  detailChannel?: DetailChannel;
99
100
  acpMaxMessageBytes?: number;
100
101
  employeeScope?: string;
101
- contextSha256?: string;
102
102
  resumeSessionId?: string;
103
103
  bindingRevision?: number;
104
104
  currentInputIds?: readonly string[];
@@ -185,9 +185,7 @@ export declare function identity(t: ConnectTarget): string;
185
185
  export declare function requireNativeWorkspace(api: ConnectApi): asserts api is ConnectApi & NativeWorkspaceApi;
186
186
  /** Authorization stays in L; ensureReady only checks and records the need. */
187
187
  export declare function offerLogin(connect: ConnectApi, request: Invocation, currentApi?: () => ConnectApi | undefined, agent?: AgentDefinition): Promise<void>;
188
- export type LocalRuntimeProvider = ((request: RuntimeRequest, api: ConnectApi, connection: ConnectionState, target: ConnectTarget) => Promise<Runtime | undefined>) & {
189
- admit?: (request: RuntimeRequest, api: ConnectApi, connection: ConnectionState, target: ConnectTarget) => Promise<void>;
190
- };
188
+ export type LocalRuntimeProvider = ((request: RuntimeRequest, api: ConnectApi, connection: ConnectionState, target: ConnectTarget) => Promise<Runtime | undefined>);
191
189
  export declare function sameTarget(a: ConnectTarget, b: ConnectTarget): boolean;
192
190
  export declare function connectProvider(get: () => ConnectApi | undefined, options?: {
193
191
  agent?: AgentDefinition;
package/dist/provider.js CHANGED
@@ -202,12 +202,9 @@ export function connectProvider(get, options = {}) {
202
202
  throw new NeedError('SESSION_CONTEXT_MISMATCH', '员工主机与原会话不一致,请新建会话', '原员工主机');
203
203
  request.localAdmissionCheck?.();
204
204
  admissions.set(request, { api, target, connection });
205
- sourceStage = 'local-admission';
206
205
  const locations = !host && api.getContractInfo().workspaceLocations === 1 ? api.getWorkspaceLocationState?.() : undefined;
207
206
  if (!host && locations && (locations.phase === 'failed' || locations.phase === 'disposed') && locations.instanceId === connection.instanceId && locations.epoch === connection.epoch && locations.need)
208
207
  throw connectNeedError(locations.need);
209
- if (!host)
210
- await options.local?.admit?.(request, api, connection, target);
211
208
  if (preparation) {
212
209
  await preparation.ready;
213
210
  preparation.confirm(target, connection);
@@ -183,7 +183,7 @@ export class ToolBridgeLoop {
183
183
  throw new NeedError('ABORTED', '本轮已取消,工具结果没有重放。', '确认主机取消状态');
184
184
  if (run.latest !== options) {
185
185
  for (const m of options.messages)
186
- if (m.role === 'user' && 'source' in m && m.source?.kind === 'user' && 'id' in m && typeof m.id === 'string' && !run.seen.has(m.id) && !this.isInjected?.(key, m)) {
186
+ if (m.role === 'user' && 'id' in m && typeof m.id === 'string' && !run.seen.has(m.id) && !this.isInjected?.(key, m)) {
187
187
  run.seen.add(m.id);
188
188
  run.deferred.push(m);
189
189
  }
@@ -1,4 +1,4 @@
1
- import type { ToolSchema, GenerateOptions } from '@deepseek-ai/dsh-llm';
1
+ import type { ToolSchema } 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", "terminal_open", "terminal_send", "terminal_read", "terminal_signal", "terminal_close", "terminal_list", "run_code"];
@@ -7,5 +7,7 @@ export interface BridgeTool {
7
7
  schema: ToolSchema;
8
8
  wire: Tool;
9
9
  }
10
- export declare function dshSkillCatalog(messages?: GenerateOptions['messages']): readonly string[] | undefined;
11
- export declare function bridgeTable(tools?: readonly ToolSchema[], catalog?: readonly string[], catalogInCurrentPrompt?: boolean): ReadonlyMap<string, BridgeTool>;
10
+ export declare function bridgeTable(tools?: readonly ToolSchema[]): ReadonlyMap<string, BridgeTool>;
11
+ /** Essential bridge entry points have a separate native namespace from deferred tools. */
12
+ export declare const TOOLBRIDGE_ESSENTIAL: readonly ["skill", "load_workspace_dependencies"];
13
+ export declare function essentialBridgeTool(name: string): boolean;
@@ -1,4 +1,3 @@
1
- import { createHash } from 'node:crypto';
2
1
  import { NeedError } from "./remote.js";
3
2
  /** Fixed official tool names; no description heuristics or plugin-name branches. */
4
3
  export const TOOLBRIDGE_EXCLUDED = Object.freeze([
@@ -7,17 +6,7 @@ export const TOOLBRIDGE_EXCLUDED = Object.freeze([
7
6
  'run_code',
8
7
  ]);
9
8
  const excluded = new Set(TOOLBRIDGE_EXCLUDED);
10
- export function dshSkillCatalog(messages = []) {
11
- for (const message of messages.toReversed()) {
12
- const source = message.source;
13
- if (message.role !== 'user' || source?.kind !== 'skill-catalog' || source.form !== 'catalog' || !Array.isArray(source.entries))
14
- continue;
15
- if (!source.entries.every(entry => entry && typeof entry.name === 'string' && typeof entry.description === 'string'))
16
- continue;
17
- return source.entries.map(entry => entry.name);
18
- }
19
- }
20
- export function bridgeTable(tools = [], catalog, catalogInCurrentPrompt = false) {
9
+ export function bridgeTable(tools = []) {
21
10
  const table = new Map(), names = new Set();
22
11
  for (const tool of tools) {
23
12
  if (excluded.has(tool.name))
@@ -25,12 +14,14 @@ export function bridgeTable(tools = [], catalog, catalogInCurrentPrompt = false)
25
14
  if (names.has(tool.name))
26
15
  throw new NeedError('TOOLBRIDGE_TOOL_DUPLICATE', '当前工具表存在重名,工具桥未开始。', '官方唯一工具名称');
27
16
  names.add(tool.name);
28
- const alias = 'dsh_' + createHash('sha256').update(tool.name).digest('hex').slice(0, 32);
17
+ const alias = 'dsh__' + tool.name;
29
18
  if (table.has(alias))
30
19
  throw new NeedError('TOOLBRIDGE_NAME_COLLISION', '工具桥名称冲突,未执行。', '唯一工具桥名称');
31
20
  const schema = structuredClone(tool);
32
- const skill = schema.name === 'skill' ? ' 这是DSH技能加载器,名字取自DSH的<available_skills>目录;主机Claude/Codex的原生技能按各自原生技能指令加载。' + (catalogInCurrentPrompt ? '实际可用性由DSH调用时确认。' : catalog === undefined ? '请以当前DSH技能目录为准。' : '本次DSH公布的目录快照:' + JSON.stringify(catalog) + ';实际可用性由DSH调用时确认。') + '技能资源按返回的<skill_resources>基址读取。' : '';
33
- table.set(alias, { alias, schema, wire: { name: alias, description: 'DSH工具 ' + schema.name + ':' + schema.description + skill, inputSchema: structuredClone(schema.parameters) } });
21
+ table.set(alias, { alias, schema, wire: { name: alias, description: schema.description, inputSchema: structuredClone(schema.parameters) } });
34
22
  }
35
23
  return table;
36
24
  }
25
+ /** Essential bridge entry points have a separate native namespace from deferred tools. */
26
+ export const TOOLBRIDGE_ESSENTIAL = Object.freeze(['skill', 'load_workspace_dependencies']);
27
+ export function essentialBridgeTool(name) { return TOOLBRIDGE_ESSENTIAL.includes(name.replace(/^dsh__/, '')); }