@ai-workbench/connect 0.7.27 → 0.7.29
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/client/index.cjs +5 -5
- package/helper/host-directories.cjs +7 -12
- package/lib/api.d.ts +2 -7
- package/lib/auth-diagnostics.js +1 -1
- package/lib/host-directories.d.ts +2 -3
- package/lib/host-directories.js +10 -8
- package/lib/host-session-projects.d.ts +2 -13
- package/lib/host-session-projects.js +65 -50
- package/lib/index.d.ts +1 -1
- package/lib/index.js +5 -4
- package/lib/native-workspace.d.ts +1 -0
- package/lib/needs.js +2 -2
- package/lib/profile-runtime.d.ts +1 -1
- package/lib/profile-runtime.js +11 -8
- package/lib/startup.js +2 -2
- package/lib/workspace-directory-picker.js +51 -95
- package/lib/workspace-location-types.d.ts +18 -11
- package/lib/workspace-locations.d.ts +2 -12
- package/lib/workspace-locations.js +81 -208
- package/package.json +1 -1
- package/node_modules/argparse/CHANGELOG.md +0 -216
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renameSync
|
|
1
|
+
import { renameSync } from 'node:fs';
|
|
2
2
|
import { lstat, realpath, open, rm } from 'node:fs/promises';
|
|
3
3
|
import { join, isAbsolute } from 'node:path';
|
|
4
4
|
import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
@@ -10,9 +10,8 @@ const queues = new Map();
|
|
|
10
10
|
const hash = (v) => createHash('sha256').update(JSON.stringify(v)).digest('hex');
|
|
11
11
|
const token = (v) => typeof v === 'string' && v.length > 0 && !/[\x00-\x1f\x7f]/.test(v);
|
|
12
12
|
const obj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
13
|
-
const checksum = (r
|
|
13
|
+
const checksum = (r) => hash([r.workspaceId, r.localPath, r.localDev, r.localIno, r.bindingId, r.source, r.active, r.remote, r.identity, r.host, undefined]);
|
|
14
14
|
const sameNative = (a, b) => a.workspaceId === b.workspaceId && a.localPath === b.localPath && a.localDev === b.localDev && a.localIno === b.localIno;
|
|
15
|
-
const sameDirectory = (a, b) => a.path === b.path && a.requestedPath === b.requestedPath && a.isSymlink === b.isSymlink && JSON.stringify(a.identity) === JSON.stringify(b.identity) && JSON.stringify(a.entryIdentity) === JSON.stringify(b.entryIdentity);
|
|
16
15
|
export function createWorkspaceLocations(o) {
|
|
17
16
|
const controllers = new Set();
|
|
18
17
|
const root = join(o.profileDir, 'ai-workbench-connect'), file = join(root, 'locations.json'), secret = randomBytes(32), listeners = new Set();
|
|
@@ -93,17 +92,28 @@ export function createWorkspaceLocations(o) {
|
|
|
93
92
|
const data = JSON.parse(raw);
|
|
94
93
|
if (!obj(data) || data.schemaVersion !== 1 || !Array.isArray(data.items))
|
|
95
94
|
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
const result = [], ids = new Set(), active = new Set();
|
|
96
|
+
for (const r of data.items) {
|
|
97
|
+
if (r?.source === 'legacy-host' || r?.source === 'host' && r.active === false)
|
|
98
|
+
continue;
|
|
99
|
+
if (!obj(r) || !token(r.workspaceId) || typeof r.active !== 'boolean' || r.active && active.has(r.workspaceId))
|
|
100
100
|
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
101
|
-
|
|
101
|
+
if (r.source === 'host') {
|
|
102
|
+
// 旧记录仅取主机与路径;旧 identity/key/dev/ino 不再属于主机来源合同。
|
|
103
|
+
if (!obj(r.host) || !token(r.host.host) || !obj(r.remote) || !token(r.remote.path) || !isAbsolute(r.remote.path))
|
|
104
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
105
|
+
result.push({ workspaceId: r.workspaceId, source: 'host', active: r.active, host: { host: r.host.host }, remote: { path: r.remote.path } });
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (r.source !== 'local' || !token(r.bindingId) || !isAbsolute(r.localPath) || !Number.isSafeInteger(r.localDev) || !Number.isSafeInteger(r.localIno) || r.key !== checksum(r) || r.legacyBindingId !== undefined || r.revoked !== undefined || ids.has(r.bindingId))
|
|
109
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
110
|
+
ids.add(r.bindingId);
|
|
111
|
+
result.push(r);
|
|
112
|
+
}
|
|
102
113
|
if (r.active)
|
|
103
114
|
active.add(r.workspaceId);
|
|
104
|
-
delete r.revoked;
|
|
105
115
|
}
|
|
106
|
-
return
|
|
116
|
+
return result;
|
|
107
117
|
}
|
|
108
118
|
function guardStoredBinding(expected) {
|
|
109
119
|
const current = parseRecords(readPrivateSync(file, o.metadataMaxBytes)).find(r => r.active && r.workspaceId === expected.workspaceId);
|
|
@@ -114,7 +124,8 @@ export function createWorkspaceLocations(o) {
|
|
|
114
124
|
}
|
|
115
125
|
async function save(items, beforeCommit, context) {
|
|
116
126
|
for (const r of items)
|
|
117
|
-
r.
|
|
127
|
+
if (r.source === 'local')
|
|
128
|
+
r.key = checksum(r);
|
|
118
129
|
const bytes = JSON.stringify({ schemaVersion: 1, items }) + '\n';
|
|
119
130
|
if (!Number.isSafeInteger(o.metadataMaxBytes) || o.metadataMaxBytes < 1 || Buffer.byteLength(bytes) > o.metadataMaxBytes)
|
|
120
131
|
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
@@ -129,7 +140,8 @@ export function createWorkspaceLocations(o) {
|
|
|
129
140
|
await h.close();
|
|
130
141
|
}
|
|
131
142
|
await beforeCommit();
|
|
132
|
-
|
|
143
|
+
if (context)
|
|
144
|
+
check(context);
|
|
133
145
|
renameSync(temp, file);
|
|
134
146
|
const d = await open(root, 'r');
|
|
135
147
|
try {
|
|
@@ -170,7 +182,7 @@ export function createWorkspaceLocations(o) {
|
|
|
170
182
|
const current = stored.find(r => r.active && r.workspaceId === c.workspaceId);
|
|
171
183
|
if ((current?.bindingId ?? null) !== c.expectedBindingId)
|
|
172
184
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
173
|
-
if (current && !sameNative(current, n))
|
|
185
|
+
if (current?.source === 'local' && !sameNative(current, n))
|
|
174
186
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
175
187
|
return { stored, n, current };
|
|
176
188
|
}
|
|
@@ -185,15 +197,8 @@ export function createWorkspaceLocations(o) {
|
|
|
185
197
|
controllers.delete(controller);
|
|
186
198
|
}
|
|
187
199
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (!t.ok)
|
|
191
|
-
throw new NeedError(t.error);
|
|
192
|
-
const trust = await readPrivate(t.value.target.knownHostsFile, o.metadataMaxBytes);
|
|
193
|
-
check(c);
|
|
194
|
-
const value = t.value.target;
|
|
195
|
-
return { value, identity: hash([value.host, value.username, value.port, value.projectRoot, value.session, trust]) };
|
|
196
|
-
}
|
|
200
|
+
function target() { const t = o.api.getModelCatalogTarget('codex'); if (!t.ok)
|
|
201
|
+
throw new NeedError(t.error); return t.value.target; }
|
|
197
202
|
const seal = (data) => { const body = Buffer.from(JSON.stringify(data)).toString('base64url'); return body + '.' + createHmac('sha256', secret).update(body).digest('base64url'); };
|
|
198
203
|
function unseal(value) {
|
|
199
204
|
if (!token(value) || Buffer.byteLength(value) > o.metadataMaxBytes)
|
|
@@ -211,17 +216,17 @@ export function createWorkspaceLocations(o) {
|
|
|
211
216
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
212
217
|
}
|
|
213
218
|
}
|
|
214
|
-
function
|
|
215
|
-
if (a.path !== b.path || a.requestedPath !== b.requestedPath || a.identity.device !== b.identity.device || a.identity.inode !== b.identity.inode || a.entryIdentity.device !== b.entryIdentity.device || a.entryIdentity.inode !== b.entryIdentity.inode || a.isSymlink !== b.isSymlink)
|
|
216
|
-
return 'HOST_DIRECTORY_CHANGED';
|
|
217
|
-
if (b.permissions.read === false || b.permissions.execute === false)
|
|
218
|
-
return 'HOST_DIRECTORY_UNREADABLE';
|
|
219
|
-
if (['read', 'write', 'execute'].some(k => typeof a.permissions[k] === 'boolean' && typeof b.permissions[k] === 'boolean' && a.permissions[k] !== b.permissions[k]))
|
|
220
|
-
return 'HOST_DIRECTORY_CHANGED';
|
|
221
|
-
}
|
|
222
|
-
async function items(stored, inspectHost = false, c = connection()) {
|
|
219
|
+
async function items(stored) {
|
|
223
220
|
const result = [];
|
|
224
221
|
for (const w of o.registry.list()) {
|
|
222
|
+
const r = stored.find(r => r.active && r.workspaceId === w.id);
|
|
223
|
+
if (r?.source === 'host') {
|
|
224
|
+
const title = w.title.replace(/(本机)$|(远程主机)$/u, '') + '(远程主机)';
|
|
225
|
+
if (w.setTitle && w.title !== title)
|
|
226
|
+
await w.setTitle(title);
|
|
227
|
+
result.push({ workspaceId: w.id, workspaceName: title, localPath: w.path, bindingId: null, source: 'host', host: r.host, remote: r.remote });
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
225
230
|
let n;
|
|
226
231
|
try {
|
|
227
232
|
n = await native(w.id);
|
|
@@ -230,131 +235,72 @@ export function createWorkspaceLocations(o) {
|
|
|
230
235
|
result.push({ workspaceId: w.id, workspaceName: w.title, localPath: w.path, bindingId: null, source: null, status: 'invalid', execution: 'not-selected', need: need('WORKSPACE_LOCATION_INVALID') });
|
|
231
236
|
continue;
|
|
232
237
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
valid = (await target(c)).identity === r.identity;
|
|
240
|
-
if (valid && inspectHost && r.source === 'host') {
|
|
241
|
-
const t = await target(c);
|
|
242
|
-
check(c);
|
|
243
|
-
const inspected = o.hostDirectories ? await remote(c, signal => o.hostDirectories.inspect(t.value, r.remote.requestedPath, signal)) : fail('DEPENDENCY_REQUIRED');
|
|
244
|
-
check(c);
|
|
245
|
-
if (!inspected.ok)
|
|
246
|
-
error = inspected.error.code;
|
|
247
|
-
else {
|
|
248
|
-
const changed = directoryChange(r.remote, inspected.value);
|
|
249
|
-
if (changed) {
|
|
250
|
-
error = changed;
|
|
251
|
-
}
|
|
252
|
-
else if (Object.values(inspected.value.permissions).includes(null))
|
|
253
|
-
error = 'HOST_DIRECTORY_UNREADABLE';
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
catch (e) {
|
|
258
|
-
check(c);
|
|
259
|
-
valid = false;
|
|
260
|
-
error = e instanceof NeedError ? e.need.code : 'WORKSPACE_LOCATION_STORAGE_FAILED';
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
result.push({ ...base, source: r.source, status: valid && !error ? 'selected' : 'invalid', execution: r.source === 'local' ? 'local-pending' : 'host-pending', ...(r.remote ? { remote: r.remote, host: r.host } : {}), ...(!valid || error ? { need: need(error ?? 'WORKSPACE_LOCATION_INVALID') } : {}) });
|
|
238
|
+
let title = w.title;
|
|
239
|
+
if (r && w.setTitle) {
|
|
240
|
+
title = w.title.replace(/(本机)$|(远程主机)$/u, '') + '(本机)';
|
|
241
|
+
if (title !== w.title)
|
|
242
|
+
await w.setTitle(title);
|
|
264
243
|
}
|
|
265
|
-
|
|
266
|
-
|
|
244
|
+
const valid = !r || sameNative(r, n);
|
|
245
|
+
result.push({ workspaceId: w.id, workspaceName: title || w.id, localPath: n.localPath, bindingId: r?.bindingId ?? null, source: r ? 'local' : null, status: r ? (valid ? 'selected' : 'invalid') : 'unselected', execution: r ? 'local-pending' : 'not-selected', ...(!valid ? { need: need('WORKSPACE_LOCATION_INVALID') } : {}) });
|
|
267
246
|
}
|
|
268
247
|
return result;
|
|
269
248
|
}
|
|
270
|
-
async function refresh(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const stored = await records();
|
|
275
|
-
const next = await items(stored, true, c);
|
|
276
|
-
check(c);
|
|
277
|
-
publish(next);
|
|
278
|
-
return ok(structuredClone(snapshot));
|
|
279
|
-
}
|
|
280
|
-
catch (e) {
|
|
281
|
-
if (exact(c))
|
|
282
|
-
publish(snapshot.items, e instanceof NeedError ? e.need.code : 'WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
283
|
-
throw e;
|
|
284
|
-
}
|
|
249
|
+
async function refresh() { try {
|
|
250
|
+
await prepare();
|
|
251
|
+
publish(await items(await records()));
|
|
252
|
+
return ok(structuredClone(snapshot));
|
|
285
253
|
}
|
|
254
|
+
catch (e) {
|
|
255
|
+
publish(snapshot.items, e instanceof NeedError ? e.need.code : 'WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
256
|
+
throw e;
|
|
257
|
+
} }
|
|
286
258
|
function strict(value, keys) {
|
|
287
259
|
if (Object.keys(value).some(k => !keys.includes(k)))
|
|
288
260
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
289
261
|
}
|
|
290
262
|
async function browse(c) {
|
|
291
|
-
|
|
292
|
-
if (
|
|
263
|
+
await prepare();
|
|
264
|
+
if (!token(c.workspaceId) || c.path !== undefined && (!token(c.path) || !isAbsolute(c.path)))
|
|
293
265
|
reject('HOST_DIRECTORY_INVALID');
|
|
294
|
-
const
|
|
266
|
+
const t = target();
|
|
295
267
|
if (!o.hostDirectories)
|
|
296
268
|
reject('DEPENDENCY_REQUIRED');
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const saved = unseal(c.cursor);
|
|
300
|
-
if (saved.kind !== 'cursor' || JSON.stringify(saved.context) !== JSON.stringify({ instanceId: c.instanceId, epoch: c.epoch, workspaceId: c.workspaceId, expectedBindingId: c.expectedBindingId }) || !sameNative(saved.native, x.n) || saved.identity !== t.identity || c.pageSize !== undefined && c.pageSize !== saved.request.pageSize)
|
|
301
|
-
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
302
|
-
request = saved.request;
|
|
303
|
-
}
|
|
304
|
-
const page = await remote(c, signal => o.hostDirectories.browse(t.value, request, signal));
|
|
305
|
-
check(c);
|
|
269
|
+
const previous = c.cursor ? unseal(c.cursor) : undefined;
|
|
270
|
+
const page = await remote(connection(), signal => o.hostDirectories.browse(t, { ...(c.path ? { path: c.path } : previous ? { path: previous.path } : {}), pageSize: c.pageSize ?? o.pageSize, ...(previous ? { after: previous.after } : {}) }, signal));
|
|
306
271
|
if (!page.ok)
|
|
307
272
|
return page;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
check(c);
|
|
311
|
-
const base = { context: { instanceId: c.instanceId, epoch: c.epoch, workspaceId: c.workspaceId, expectedBindingId: c.expectedBindingId }, native: x.n, identity: t.identity };
|
|
312
|
-
const choose = (info) => seal({ kind: 'selection', ...base, info });
|
|
313
|
-
const { entries, nextAfter, ...info } = page.value;
|
|
314
|
-
return ok({ ...info, ...connection(), workspaceId: c.workspaceId, bindingId: c.expectedBindingId, host: { host: t.value.host, username: t.value.username, port: t.value.port }, selectionToken: choose(info), pageSize: request.pageSize, entries: entries.map(e => ({ ...e, ...(e.path && e.identity && !e.errorCode ? { selectionToken: choose({ requestedPath: e.requestedPath, path: e.path, parentPath: info.path, identity: e.identity, entryIdentity: e.entryIdentity, isSymlink: e.isSymlink, permissions: e.permissions }) } : {}) })), ...(nextAfter ? { nextCursor: seal({ kind: 'cursor', ...base, request: { path: info.requestedPath, pageSize: request.pageSize, after: nextAfter, expected: info.identity } }) } : {}) });
|
|
273
|
+
const host = { host: t.host, username: t.username, port: t.port };
|
|
274
|
+
return ok({ ...page.value, ...connection(), workspaceId: c.workspaceId, bindingId: c.expectedBindingId, host, pageSize: c.pageSize ?? o.pageSize, selectionToken: seal({ host: t.host, path: page.value.path }), entries: page.value.entries.map(e => ({ ...e, selectionToken: seal({ host: t.host, path: e.path ?? e.requestedPath }) })), ...(page.value.nextAfter ? { nextCursor: seal({ path: page.value.path, after: page.value.nextAfter }) } : {}) });
|
|
315
275
|
}
|
|
316
276
|
async function select(c) {
|
|
317
|
-
if (!obj(c))
|
|
318
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
319
|
-
strict(c, ['instanceId', 'epoch', 'workspaceId', 'expectedBindingId', 'source', ...(c.source === 'host' ? ['selectionToken'] : [])]);
|
|
320
|
-
if (!['local', 'host'].includes(c.source))
|
|
277
|
+
if (!obj(c) || !['local', 'host'].includes(c.source))
|
|
321
278
|
reject('WORKSPACE_LOCATION_INVALID');
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return inspected;
|
|
336
|
-
if (!sameDirectory(selectedInfo, inspected.value))
|
|
337
|
-
reject('HOST_DIRECTORY_CHANGED');
|
|
338
|
-
if (inspected.value.permissions.read !== true || inspected.value.permissions.execute !== true)
|
|
339
|
-
reject('HOST_DIRECTORY_UNREADABLE');
|
|
340
|
-
r = { ...r, remote: inspected.value, identity: t.identity, host: { host: t.value.host, username: t.value.username, port: t.value.port } };
|
|
279
|
+
if (c.source === 'host') {
|
|
280
|
+
await prepare();
|
|
281
|
+
const selected = 'selectionToken' in c ? unseal(c.selectionToken) : c;
|
|
282
|
+
if (!token(c.workspaceId) || !token(selected.host) || !token(selected.path) || !isAbsolute(selected.path))
|
|
283
|
+
reject('HOST_DIRECTORY_INVALID');
|
|
284
|
+
const stored = await records();
|
|
285
|
+
for (const old of stored)
|
|
286
|
+
if (old.workspaceId === c.workspaceId)
|
|
287
|
+
old.active = false;
|
|
288
|
+
stored.push({ workspaceId: c.workspaceId, source: 'host', active: true, host: { host: selected.host }, remote: { path: selected.path } });
|
|
289
|
+
await save(stored, async () => { });
|
|
290
|
+
publish(await items(stored));
|
|
291
|
+
return ok(structuredClone(snapshot));
|
|
341
292
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (x.current && x.current.source === r.source && JSON.stringify(x.current.remote) === JSON.stringify(r.remote) && x.current.identity === r.identity)
|
|
293
|
+
strict(c, ['instanceId', 'epoch', 'workspaceId', 'expectedBindingId', 'source']);
|
|
294
|
+
const x = await context(c);
|
|
295
|
+
if (x.current?.source === 'local')
|
|
346
296
|
return ok(structuredClone(snapshot));
|
|
297
|
+
const r = { ...x.n, bindingId: randomUUID(), source: 'local', active: true, key: '' };
|
|
347
298
|
for (const old of x.stored)
|
|
348
299
|
if (old.active && old.workspaceId === c.workspaceId)
|
|
349
300
|
old.active = false;
|
|
350
|
-
if (x.stored.some(old => old.bindingId === r.bindingId))
|
|
351
|
-
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
352
301
|
x.stored.push(r);
|
|
353
|
-
await save(x.stored, async () => {
|
|
354
|
-
|
|
355
|
-
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
356
|
-
check(c);
|
|
357
|
-
}, c);
|
|
302
|
+
await save(x.stored, async () => { if (!sameNative(await native(c.workspaceId), x.n))
|
|
303
|
+
reject('WORKSPACE_LOCATION_CONFLICT'); check(c); }, c);
|
|
358
304
|
publish(await items(x.stored));
|
|
359
305
|
check(c);
|
|
360
306
|
return ok(structuredClone(snapshot));
|
|
@@ -415,93 +361,20 @@ export function createWorkspaceLocations(o) {
|
|
|
415
361
|
const c = { instanceId: request.instanceId, epoch: request.epoch, workspaceId: request.workspaceId, expectedBindingId: request.expectedBindingId };
|
|
416
362
|
return serial(() => localContext(c));
|
|
417
363
|
}
|
|
418
|
-
function withHostBinding(input, run, finalize = () => { }) {
|
|
419
|
-
const c = structuredClone(input);
|
|
420
|
-
return serial(async () => {
|
|
421
|
-
strict(c, ['instanceId', 'epoch', 'workspaceId', 'expectedBindingId']);
|
|
422
|
-
if (!token(c.expectedBindingId))
|
|
423
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
424
|
-
checkPending(c.workspaceId);
|
|
425
|
-
const x = await context(c), r = x.current;
|
|
426
|
-
if (!r || r.source !== 'host' || !r.remote)
|
|
427
|
-
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
428
|
-
const t = await target(c);
|
|
429
|
-
check(c);
|
|
430
|
-
if (t.identity !== r.identity)
|
|
431
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
432
|
-
const bytes = await readPrivate(file, o.metadataMaxBytes), registeredPath = registeredLocalPath(c.workspaceId);
|
|
433
|
-
const guard = () => {
|
|
434
|
-
checkPending(c.workspaceId);
|
|
435
|
-
check(c);
|
|
436
|
-
const now = o.api.getConnectionState();
|
|
437
|
-
if (now.phase !== 'connected')
|
|
438
|
-
reject('CONNECTION_LOST');
|
|
439
|
-
const latest = o.api.getModelCatalogTarget('codex');
|
|
440
|
-
if (!latest.ok)
|
|
441
|
-
throw new NeedError(latest.error);
|
|
442
|
-
const v = latest.value.target;
|
|
443
|
-
if (hash([v.host, v.username, v.port, v.projectRoot, v.session, readPrivateSync(v.knownHostsFile, o.metadataMaxBytes)]) !== t.identity)
|
|
444
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
445
|
-
if (readPrivateSync(file, o.metadataMaxBytes) !== bytes)
|
|
446
|
-
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
447
|
-
if (registeredLocalPath(c.workspaceId) !== registeredPath)
|
|
448
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
449
|
-
try {
|
|
450
|
-
const path = realpathSync(registeredPath), st = lstatSync(path);
|
|
451
|
-
if (path !== x.n.localPath || !st.isDirectory() || st.dev !== x.n.localDev || st.ino !== x.n.localIno)
|
|
452
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
453
|
-
}
|
|
454
|
-
catch (e) {
|
|
455
|
-
if (e instanceof NeedError)
|
|
456
|
-
throw e;
|
|
457
|
-
reject('WORKSPACE_LOCATION_INVALID');
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
guard();
|
|
461
|
-
if (!o.hostDirectories)
|
|
462
|
-
reject('DEPENDENCY_REQUIRED');
|
|
463
|
-
const current = await remote(c, signal => o.hostDirectories.inspect(t.value, r.remote.requestedPath, signal));
|
|
464
|
-
if (!current.ok)
|
|
465
|
-
throw new NeedError(current.error);
|
|
466
|
-
const changed = directoryChange(r.remote, current.value);
|
|
467
|
-
if (changed)
|
|
468
|
-
reject(changed);
|
|
469
|
-
if (Object.values(current.value.permissions).includes(null))
|
|
470
|
-
reject('HOST_DIRECTORY_UNREADABLE');
|
|
471
|
-
const value = { directory: current.value, target: structuredClone(t.value), local: { path: x.n.localPath, device: x.n.localDev, inode: x.n.localIno }, revision: snapshot.revision };
|
|
472
|
-
const result = await run(value, guard);
|
|
473
|
-
if (!result.ok)
|
|
474
|
-
return result;
|
|
475
|
-
guard();
|
|
476
|
-
finalize();
|
|
477
|
-
return result;
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
364
|
function captureWorkspacePickerGuard(workspaceId, expectedBindingId) {
|
|
481
365
|
const original = parseRecords(readPrivateSync(file, o.metadataMaxBytes)).find(r => r.active && r.workspaceId === workspaceId);
|
|
482
|
-
if (!original || original.bindingId !== expectedBindingId)
|
|
366
|
+
if (!original || original.source !== 'local' || original.bindingId !== expectedBindingId)
|
|
483
367
|
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
484
368
|
const registeredPath = registeredLocalPath(workspaceId);
|
|
485
369
|
return () => { guardStoredBinding(original); if (registeredLocalPath(workspaceId) !== registeredPath)
|
|
486
370
|
reject('WORKSPACE_LOCATION_INVALID'); };
|
|
487
371
|
}
|
|
488
|
-
return { captureWorkspacePickerGuard,
|
|
372
|
+
return { captureWorkspacePickerGuard, getLocalWorkspaceContext, getWorkspaceLocationState: () => ({ ...structuredClone(snapshot), host: currentHost() }), onWorkspaceLocationState(listener) { listeners.add(listener); return () => { listeners.delete(listener); }; }, refreshWorkspaceLocations: () => serial(refresh), browseWorkspaceHostDirectories: (c) => serial(() => browse(c)), selectWorkspaceLocation: (c) => serial(() => select(c)), observeConnection() {
|
|
489
373
|
if (disposed)
|
|
490
374
|
return;
|
|
491
375
|
for (const controller of controllers)
|
|
492
376
|
controller.abort();
|
|
493
|
-
|
|
494
|
-
publish(snapshot.items.map(item => {
|
|
495
|
-
if (item.source !== 'host')
|
|
496
|
-
return item;
|
|
497
|
-
if (!connected)
|
|
498
|
-
return { ...item, need: need('CONNECTION_LOST') };
|
|
499
|
-
if (item.need?.code === 'CONNECTION_LOST' || item.need?.code === 'WORKSPACE_LOCATION_CONFLICT') {
|
|
500
|
-
const { need: _, ...selected } = item;
|
|
501
|
-
return selected;
|
|
502
|
-
}
|
|
503
|
-
return item;
|
|
504
|
-
}));
|
|
377
|
+
publish(snapshot.items);
|
|
505
378
|
}, dispose() {
|
|
506
379
|
disposed = true;
|
|
507
380
|
for (const controller of controllers)
|
package/package.json
CHANGED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## [2.0.1] - 2020-08-29
|
|
10
|
-
### Fixed
|
|
11
|
-
- Fix issue with `process.argv` when used with interpreters (`coffee`, `ts-node`, etc.), #150.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## [2.0.0] - 2020-08-14
|
|
15
|
-
### Changed
|
|
16
|
-
- Full rewrite. Now port from python 3.9.0 & more precise following.
|
|
17
|
-
See [doc](./doc) for difference and migration info.
|
|
18
|
-
- node.js 10+ required
|
|
19
|
-
- Removed most of local docs in favour of original ones.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## [1.0.10] - 2018-02-15
|
|
23
|
-
### Fixed
|
|
24
|
-
- Use .concat instead of + for arrays, #122.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## [1.0.9] - 2016-09-29
|
|
28
|
-
### Changed
|
|
29
|
-
- Rerelease after 1.0.8 - deps cleanup.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
## [1.0.8] - 2016-09-29
|
|
33
|
-
### Changed
|
|
34
|
-
- Maintenance (deps bump, fix node 6.5+ tests, coverage report).
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## [1.0.7] - 2016-03-17
|
|
38
|
-
### Changed
|
|
39
|
-
- Teach `addArgument` to accept string arg names. #97, @tomxtobin.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## [1.0.6] - 2016-02-06
|
|
43
|
-
### Changed
|
|
44
|
-
- Maintenance: moved to eslint & updated CS.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
## [1.0.5] - 2016-02-05
|
|
48
|
-
### Changed
|
|
49
|
-
- Removed lodash dependency to significantly reduce install size.
|
|
50
|
-
Thanks to @mourner.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## [1.0.4] - 2016-01-17
|
|
54
|
-
### Changed
|
|
55
|
-
- Maintenance: lodash update to 4.0.0.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
## [1.0.3] - 2015-10-27
|
|
59
|
-
### Fixed
|
|
60
|
-
- Fix parse `=` in args: `--examplepath="C:\myfolder\env=x64"`. #84, @CatWithApple.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
## [1.0.2] - 2015-03-22
|
|
64
|
-
### Changed
|
|
65
|
-
- Relaxed lodash version dependency.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
## [1.0.1] - 2015-02-20
|
|
69
|
-
### Changed
|
|
70
|
-
- Changed dependencies to be compatible with ancient nodejs.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
## [1.0.0] - 2015-02-19
|
|
74
|
-
### Changed
|
|
75
|
-
- Maintenance release.
|
|
76
|
-
- Replaced `underscore` with `lodash`.
|
|
77
|
-
- Bumped version to 1.0.0 to better reflect semver meaning.
|
|
78
|
-
- HISTORY.md -> CHANGELOG.md
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
## [0.1.16] - 2013-12-01
|
|
82
|
-
### Changed
|
|
83
|
-
- Maintenance release. Updated dependencies and docs.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
## [0.1.15] - 2013-05-13
|
|
87
|
-
### Fixed
|
|
88
|
-
- Fixed #55, @trebor89
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
## [0.1.14] - 2013-05-12
|
|
92
|
-
### Fixed
|
|
93
|
-
- Fixed #62, @maxtaco
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
## [0.1.13] - 2013-04-08
|
|
97
|
-
### Changed
|
|
98
|
-
- Added `.npmignore` to reduce package size
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
## [0.1.12] - 2013-02-10
|
|
102
|
-
### Fixed
|
|
103
|
-
- Fixed conflictHandler (#46), @hpaulj
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
## [0.1.11] - 2013-02-07
|
|
107
|
-
### Added
|
|
108
|
-
- Added 70+ tests (ported from python), @hpaulj
|
|
109
|
-
- Added conflictHandler, @applepicke
|
|
110
|
-
- Added fromfilePrefixChar, @hpaulj
|
|
111
|
-
|
|
112
|
-
### Fixed
|
|
113
|
-
- Multiple bugfixes, @hpaulj
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
## [0.1.10] - 2012-12-30
|
|
117
|
-
### Added
|
|
118
|
-
- Added [mutual exclusion](http://docs.python.org/dev/library/argparse.html#mutual-exclusion)
|
|
119
|
-
support, thanks to @hpaulj
|
|
120
|
-
|
|
121
|
-
### Fixed
|
|
122
|
-
- Fixed options check for `storeConst` & `appendConst` actions, thanks to @hpaulj
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
## [0.1.9] - 2012-12-27
|
|
126
|
-
### Fixed
|
|
127
|
-
- Fixed option dest interferens with other options (issue #23), thanks to @hpaulj
|
|
128
|
-
- Fixed default value behavior with `*` positionals, thanks to @hpaulj
|
|
129
|
-
- Improve `getDefault()` behavior, thanks to @hpaulj
|
|
130
|
-
- Improve negative argument parsing, thanks to @hpaulj
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
## [0.1.8] - 2012-12-01
|
|
134
|
-
### Fixed
|
|
135
|
-
- Fixed parser parents (issue #19), thanks to @hpaulj
|
|
136
|
-
- Fixed negative argument parse (issue #20), thanks to @hpaulj
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
## [0.1.7] - 2012-10-14
|
|
140
|
-
### Fixed
|
|
141
|
-
- Fixed 'choices' argument parse (issue #16)
|
|
142
|
-
- Fixed stderr output (issue #15)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
## [0.1.6] - 2012-09-09
|
|
146
|
-
### Fixed
|
|
147
|
-
- Fixed check for conflict of options (thanks to @tomxtobin)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
## [0.1.5] - 2012-09-03
|
|
151
|
-
### Fixed
|
|
152
|
-
- Fix parser #setDefaults method (thanks to @tomxtobin)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
## [0.1.4] - 2012-07-30
|
|
156
|
-
### Fixed
|
|
157
|
-
- Fixed pseudo-argument support (thanks to @CGamesPlay)
|
|
158
|
-
- Fixed addHelp default (should be true), if not set (thanks to @benblank)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
## [0.1.3] - 2012-06-27
|
|
162
|
-
### Fixed
|
|
163
|
-
- Fixed formatter api name: Formatter -> HelpFormatter
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
## [0.1.2] - 2012-05-29
|
|
167
|
-
### Fixed
|
|
168
|
-
- Removed excess whitespace in help
|
|
169
|
-
- Fixed error reporting, when parcer with subcommands
|
|
170
|
-
called with empty arguments
|
|
171
|
-
|
|
172
|
-
### Added
|
|
173
|
-
- Added basic tests
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
## [0.1.1] - 2012-05-23
|
|
177
|
-
### Fixed
|
|
178
|
-
- Fixed line wrapping in help formatter
|
|
179
|
-
- Added better error reporting on invalid arguments
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
## [0.1.0] - 2012-05-16
|
|
183
|
-
### Added
|
|
184
|
-
- First release.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
[2.0.1]: https://github.com/nodeca/argparse/compare/2.0.0...2.0.1
|
|
188
|
-
[2.0.0]: https://github.com/nodeca/argparse/compare/1.0.10...2.0.0
|
|
189
|
-
[1.0.10]: https://github.com/nodeca/argparse/compare/1.0.9...1.0.10
|
|
190
|
-
[1.0.9]: https://github.com/nodeca/argparse/compare/1.0.8...1.0.9
|
|
191
|
-
[1.0.8]: https://github.com/nodeca/argparse/compare/1.0.7...1.0.8
|
|
192
|
-
[1.0.7]: https://github.com/nodeca/argparse/compare/1.0.6...1.0.7
|
|
193
|
-
[1.0.6]: https://github.com/nodeca/argparse/compare/1.0.5...1.0.6
|
|
194
|
-
[1.0.5]: https://github.com/nodeca/argparse/compare/1.0.4...1.0.5
|
|
195
|
-
[1.0.4]: https://github.com/nodeca/argparse/compare/1.0.3...1.0.4
|
|
196
|
-
[1.0.3]: https://github.com/nodeca/argparse/compare/1.0.2...1.0.3
|
|
197
|
-
[1.0.2]: https://github.com/nodeca/argparse/compare/1.0.1...1.0.2
|
|
198
|
-
[1.0.1]: https://github.com/nodeca/argparse/compare/1.0.0...1.0.1
|
|
199
|
-
[1.0.0]: https://github.com/nodeca/argparse/compare/0.1.16...1.0.0
|
|
200
|
-
[0.1.16]: https://github.com/nodeca/argparse/compare/0.1.15...0.1.16
|
|
201
|
-
[0.1.15]: https://github.com/nodeca/argparse/compare/0.1.14...0.1.15
|
|
202
|
-
[0.1.14]: https://github.com/nodeca/argparse/compare/0.1.13...0.1.14
|
|
203
|
-
[0.1.13]: https://github.com/nodeca/argparse/compare/0.1.12...0.1.13
|
|
204
|
-
[0.1.12]: https://github.com/nodeca/argparse/compare/0.1.11...0.1.12
|
|
205
|
-
[0.1.11]: https://github.com/nodeca/argparse/compare/0.1.10...0.1.11
|
|
206
|
-
[0.1.10]: https://github.com/nodeca/argparse/compare/0.1.9...0.1.10
|
|
207
|
-
[0.1.9]: https://github.com/nodeca/argparse/compare/0.1.8...0.1.9
|
|
208
|
-
[0.1.8]: https://github.com/nodeca/argparse/compare/0.1.7...0.1.8
|
|
209
|
-
[0.1.7]: https://github.com/nodeca/argparse/compare/0.1.6...0.1.7
|
|
210
|
-
[0.1.6]: https://github.com/nodeca/argparse/compare/0.1.5...0.1.6
|
|
211
|
-
[0.1.5]: https://github.com/nodeca/argparse/compare/0.1.4...0.1.5
|
|
212
|
-
[0.1.4]: https://github.com/nodeca/argparse/compare/0.1.3...0.1.4
|
|
213
|
-
[0.1.3]: https://github.com/nodeca/argparse/compare/0.1.2...0.1.3
|
|
214
|
-
[0.1.2]: https://github.com/nodeca/argparse/compare/0.1.1...0.1.2
|
|
215
|
-
[0.1.1]: https://github.com/nodeca/argparse/compare/0.1.0...0.1.1
|
|
216
|
-
[0.1.0]: https://github.com/nodeca/argparse/releases/tag/0.1.0
|