@ai-workbench/connect 0.7.9 → 0.7.14
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 +13 -3
- package/client/index.cjs +33 -13
- package/helper/host-directories.cjs +72 -0
- package/helper/remote-command.cjs +1 -1
- package/lib/api.d.ts +44 -1
- package/lib/api.js +1 -1
- package/lib/auth-diagnostics.d.ts +22 -0
- package/lib/auth-diagnostics.js +45 -0
- package/lib/auth-status.js +21 -8
- package/lib/components.d.ts +1 -1
- package/lib/components.js +106 -5
- package/lib/connect.d.ts +3 -0
- package/lib/connect.js +105 -23
- package/lib/connection-messages.d.ts +7 -0
- package/lib/connection-messages.js +6 -0
- package/lib/conversation-details.d.ts +3 -0
- package/lib/conversation-details.js +8 -7
- package/lib/cordis.d.ts +3 -1
- package/lib/defaults.d.ts +6 -0
- package/lib/defaults.js +2 -0
- package/lib/host-directories.d.ts +53 -0
- package/lib/host-directories.js +76 -0
- package/lib/index.d.ts +8 -1
- package/lib/index.js +9 -4
- package/lib/integration.js +6 -3
- package/lib/local-workspace-context.d.ts +46 -0
- package/lib/local-workspace-context.js +17 -0
- package/lib/login-diagnostics.d.ts +26 -0
- package/lib/login-diagnostics.js +42 -0
- package/lib/needs.js +12 -0
- package/lib/ports.d.ts +2 -0
- package/lib/processes.js +6 -5
- package/lib/profile-runtime.js +53 -22
- package/lib/ssh.js +37 -14
- package/lib/startup.d.ts +23 -2
- package/lib/startup.js +152 -41
- package/lib/workspace-bindings.d.ts +30 -1
- package/lib/workspace-bindings.js +1 -0
- package/lib/workspace-location-types.d.ts +65 -0
- package/lib/workspace-location-types.js +1 -0
- package/lib/workspace-locations.d.ts +45 -0
- package/lib/workspace-locations.js +427 -0
- package/node_modules/argparse/CHANGELOG.md +216 -0
- package/package.json +4 -3
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { renameSync } from 'node:fs';
|
|
2
|
+
import { lstat, realpath, open, rm } from 'node:fs/promises';
|
|
3
|
+
import { join, isAbsolute } from 'node:path';
|
|
4
|
+
import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
5
|
+
import { privateDirectory, readPrivate } from "./private-files.js";
|
|
6
|
+
import { fail, ok, need, NeedError } from "./needs.js";
|
|
7
|
+
import { readLocalWorkspaceProcess } from "./local-workspace-context.js";
|
|
8
|
+
const queues = new Map();
|
|
9
|
+
const hash = (v) => createHash('sha256').update(JSON.stringify(v)).digest('hex');
|
|
10
|
+
const token = (v) => typeof v === 'string' && v.length > 0 && !/[\x00-\x1f\x7f]/.test(v);
|
|
11
|
+
const obj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
12
|
+
const checksum = (r) => hash([r.workspaceId, r.localPath, r.localDev, r.localIno, r.bindingId, r.source, r.active, r.remote, r.identity, r.host, r.legacyBindingId]);
|
|
13
|
+
const sameNative = (a, b) => a.workspaceId === b.workspaceId && a.localPath === b.localPath && a.localDev === b.localDev && a.localIno === b.localIno;
|
|
14
|
+
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);
|
|
15
|
+
export function createWorkspaceLocations(o) {
|
|
16
|
+
const controllers = new Set();
|
|
17
|
+
const root = join(o.profileDir, 'ai-workbench-connect'), file = join(root, 'locations.json'), secret = randomBytes(32), listeners = new Set();
|
|
18
|
+
let disposed = false, revision = 0, tail = Promise.resolve();
|
|
19
|
+
let snapshot = { ...connection(), revision: 0, phase: 'loading', pageSize: o.pageSize, items: [] };
|
|
20
|
+
function connection() { const c = o.api.getConnectionState(); return { instanceId: c.instanceId, epoch: c.epoch }; }
|
|
21
|
+
function exact(c) { const now = connection(); return !disposed && now.instanceId === c.instanceId && now.epoch === c.epoch; }
|
|
22
|
+
function reject(code) { throw new NeedError(need(code)); }
|
|
23
|
+
function check(c) {
|
|
24
|
+
if (!exact(c))
|
|
25
|
+
reject(disposed ? 'DISPOSED' : 'WORKSPACE_LOCATION_CONFLICT');
|
|
26
|
+
}
|
|
27
|
+
function publish(items, error) {
|
|
28
|
+
snapshot = { ...connection(), revision: (revision = o.nextRevision?.() ?? revision + 1), phase: disposed ? 'disposed' : error ? 'failed' : 'ready', pageSize: o.pageSize, items, ...(error ? { need: need(error) } : {}) };
|
|
29
|
+
for (const listener of listeners)
|
|
30
|
+
listener(structuredClone(snapshot));
|
|
31
|
+
o.onState?.(structuredClone(snapshot));
|
|
32
|
+
}
|
|
33
|
+
function serial(fn) {
|
|
34
|
+
const before = queues.get(file) ?? Promise.resolve();
|
|
35
|
+
const task = before.then(async () => {
|
|
36
|
+
if (disposed)
|
|
37
|
+
return fail('DISPOSED');
|
|
38
|
+
try {
|
|
39
|
+
return await fn();
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
return e instanceof NeedError ? { ok: false, error: e.need } : fail('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
tail = task.then(() => { }, () => { });
|
|
46
|
+
const settled = tail;
|
|
47
|
+
queues.set(file, settled);
|
|
48
|
+
void settled.then(() => {
|
|
49
|
+
if (queues.get(file) === settled)
|
|
50
|
+
queues.delete(file);
|
|
51
|
+
});
|
|
52
|
+
return task;
|
|
53
|
+
}
|
|
54
|
+
async function prepare() {
|
|
55
|
+
if (!isAbsolute(o.profileDir) || await realpath(o.profileDir) !== o.profileDir)
|
|
56
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
57
|
+
await privateDirectory(root);
|
|
58
|
+
if (await realpath(root) !== root)
|
|
59
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
60
|
+
if (!Number.isSafeInteger(o.pageSize) || o.pageSize < 1)
|
|
61
|
+
reject('SETTINGS_REQUIRED');
|
|
62
|
+
}
|
|
63
|
+
async function records() {
|
|
64
|
+
let raw;
|
|
65
|
+
try {
|
|
66
|
+
raw = await readPrivate(file, o.metadataMaxBytes);
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
if (e.code === 'ENOENT')
|
|
70
|
+
return [];
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
const data = JSON.parse(raw);
|
|
74
|
+
if (!obj(data) || data.schemaVersion !== 1 || !Array.isArray(data.items))
|
|
75
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
76
|
+
const ids = new Set(), active = new Set();
|
|
77
|
+
for (const r of data.items) {
|
|
78
|
+
if (!obj(r) || !token(r.bindingId) || !token(r.workspaceId) || !isAbsolute(r.localPath) || !Number.isSafeInteger(r.localDev) || !Number.isSafeInteger(r.localIno) || !['local', 'host', 'legacy-host'].includes(r.source) || typeof r.active !== 'boolean' || r.source === 'legacy-host' && !token(r.legacyBindingId) || r.source !== 'legacy-host' && r.legacyBindingId !== undefined || r.key !== checksum(r) || ids.has(r.bindingId) || r.active && active.has(r.workspaceId) || r.source !== 'local' && (!obj(r.remote) || !isAbsolute(r.remote.path) || !isAbsolute(r.remote.requestedPath) || !obj(r.remote.identity) || !obj(r.remote.entryIdentity) || !obj(r.remote.permissions) || !obj(r.host) || !token(r.host.host) || !token(r.host.username) || !Number.isSafeInteger(r.host.port) || !(/^[a-f0-9]{64}$/.test(r.identity))))
|
|
79
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
80
|
+
ids.add(r.bindingId);
|
|
81
|
+
if (r.active)
|
|
82
|
+
active.add(r.workspaceId);
|
|
83
|
+
}
|
|
84
|
+
return data.items;
|
|
85
|
+
}
|
|
86
|
+
async function save(items, beforeCommit, context) {
|
|
87
|
+
for (const r of items)
|
|
88
|
+
r.key = checksum(r);
|
|
89
|
+
const bytes = JSON.stringify({ schemaVersion: 1, items }) + '\n';
|
|
90
|
+
if (!Number.isSafeInteger(o.metadataMaxBytes) || o.metadataMaxBytes < 1 || Buffer.byteLength(bytes) > o.metadataMaxBytes)
|
|
91
|
+
reject('WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
92
|
+
const temp = join(root, '.locations-' + randomUUID());
|
|
93
|
+
try {
|
|
94
|
+
const h = await open(temp, 'wx', 0o600);
|
|
95
|
+
try {
|
|
96
|
+
await h.writeFile(bytes);
|
|
97
|
+
await h.sync();
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
await h.close();
|
|
101
|
+
}
|
|
102
|
+
await beforeCommit();
|
|
103
|
+
check(context);
|
|
104
|
+
renameSync(temp, file);
|
|
105
|
+
const d = await open(root, 'r');
|
|
106
|
+
try {
|
|
107
|
+
await d.sync();
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
await d.close();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
await rm(temp, { force: true });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function native(id) {
|
|
118
|
+
const matches = o.registry.list().filter(w => w.id === id);
|
|
119
|
+
if (matches.length !== 1)
|
|
120
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
121
|
+
const w = matches[0], registered = o.registry.get(id);
|
|
122
|
+
if (!registered || registered.path !== w.path || !isAbsolute(w.path))
|
|
123
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
124
|
+
try {
|
|
125
|
+
const localPath = await realpath(w.path), s = await lstat(localPath);
|
|
126
|
+
if (!s.isDirectory() || s.isSymbolicLink())
|
|
127
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
128
|
+
return { workspaceId: id, localPath, localDev: s.dev, localIno: s.ino };
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function context(c) {
|
|
135
|
+
if (!obj(c) || !token(c.workspaceId) || !token(c.instanceId) || !Number.isSafeInteger(c.epoch) || !(c.expectedBindingId === null || token(c.expectedBindingId)))
|
|
136
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
137
|
+
check(c);
|
|
138
|
+
await prepare();
|
|
139
|
+
const stored = await records(), legacy = await o.readLegacy(), n = await native(c.workspaceId);
|
|
140
|
+
check(c);
|
|
141
|
+
const current = stored.find(r => r.active && r.workspaceId === c.workspaceId), old = legacy.find(r => r.workspaceId === c.workspaceId);
|
|
142
|
+
if ((current?.bindingId ?? old?.bindingId ?? null) !== c.expectedBindingId)
|
|
143
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
144
|
+
if (current && !sameNative(current, n) || !current && old && !sameNative(old, n))
|
|
145
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
146
|
+
return { stored, legacy, n, current, old };
|
|
147
|
+
}
|
|
148
|
+
async function remote(c, run) {
|
|
149
|
+
check(c);
|
|
150
|
+
const controller = new AbortController();
|
|
151
|
+
controllers.add(controller);
|
|
152
|
+
try {
|
|
153
|
+
return await run(controller.signal);
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
controllers.delete(controller);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function target(c) {
|
|
160
|
+
const t = o.api.getModelCatalogTarget('codex');
|
|
161
|
+
if (!t.ok)
|
|
162
|
+
throw new NeedError(t.error);
|
|
163
|
+
const trust = await readPrivate(t.value.target.knownHostsFile, o.metadataMaxBytes);
|
|
164
|
+
check(c);
|
|
165
|
+
const value = t.value.target;
|
|
166
|
+
return { value, identity: hash([value.host, value.username, value.port, value.projectRoot, value.session, trust]) };
|
|
167
|
+
}
|
|
168
|
+
const seal = (data) => { const body = Buffer.from(JSON.stringify(data)).toString('base64url'); return body + '.' + createHmac('sha256', secret).update(body).digest('base64url'); };
|
|
169
|
+
function unseal(value) {
|
|
170
|
+
if (!token(value) || Buffer.byteLength(value) > o.metadataMaxBytes)
|
|
171
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
172
|
+
const [body, signature, ...extra] = value.split('.');
|
|
173
|
+
if (extra.length || !body || !signature)
|
|
174
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
175
|
+
const expected = createHmac('sha256', secret).update(body).digest(), actual = Buffer.from(signature, 'base64url');
|
|
176
|
+
if (actual.length !== expected.length || !timingSafeEqual(actual, expected))
|
|
177
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
178
|
+
try {
|
|
179
|
+
return JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async function items(stored, legacy) {
|
|
186
|
+
const result = [];
|
|
187
|
+
for (const w of o.registry.list()) {
|
|
188
|
+
let n;
|
|
189
|
+
try {
|
|
190
|
+
n = await native(w.id);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
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') });
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const r = stored.find(r => r.active && r.workspaceId === w.id), old = legacy.find(r => r.workspaceId === w.id);
|
|
197
|
+
const base = { workspaceId: w.id, workspaceName: w.title || w.id, localPath: n.localPath, bindingId: r?.bindingId ?? old?.bindingId ?? null };
|
|
198
|
+
if (r) {
|
|
199
|
+
let valid = sameNative(r, n);
|
|
200
|
+
if (valid && r.source !== 'local') {
|
|
201
|
+
try {
|
|
202
|
+
valid = (await target(connection())).identity === r.identity;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
valid = false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
result.push({ ...base, source: r.source, status: valid ? 'selected' : 'invalid', execution: r.source === 'local' ? 'local-pending' : r.source === 'host' ? 'host-pending' : 'legacy-confirmed', ...(r.remote ? { remote: r.remote, host: r.host } : {}), ...(!valid ? { need: need('WORKSPACE_LOCATION_INVALID') } : {}) });
|
|
209
|
+
}
|
|
210
|
+
else if (old) {
|
|
211
|
+
result.push({ ...base, source: 'legacy-host', status: 'legacy-confirmation-required', execution: 'not-selected', legacyPath: old.project.path, ...(!sameNative(old, n) ? { need: need('WORKSPACE_LOCATION_INVALID') } : {}) });
|
|
212
|
+
}
|
|
213
|
+
else
|
|
214
|
+
result.push({ ...base, source: null, status: 'unselected', execution: 'not-selected' });
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
async function refresh() {
|
|
219
|
+
try {
|
|
220
|
+
await prepare();
|
|
221
|
+
const stored = await records(), legacy = await o.readLegacy();
|
|
222
|
+
publish(await items(stored, legacy));
|
|
223
|
+
return ok(structuredClone(snapshot));
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
publish(snapshot.items, 'WORKSPACE_LOCATION_STORAGE_FAILED');
|
|
227
|
+
throw e;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function strict(value, keys) {
|
|
231
|
+
if (Object.keys(value).some(k => !keys.includes(k)))
|
|
232
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
233
|
+
}
|
|
234
|
+
async function browse(c) {
|
|
235
|
+
strict(c, ['instanceId', 'epoch', 'workspaceId', 'expectedBindingId', 'path', 'cursor', 'pageSize']);
|
|
236
|
+
if (c.path !== undefined && (!isAbsolute(c.path) || c.path.includes('\0')) || c.path !== undefined && c.cursor !== undefined || c.pageSize !== undefined && (!Number.isSafeInteger(c.pageSize) || c.pageSize < 1))
|
|
237
|
+
reject('HOST_DIRECTORY_INVALID');
|
|
238
|
+
const x = await context(c), t = await target(c);
|
|
239
|
+
if (!o.hostDirectories)
|
|
240
|
+
reject('DEPENDENCY_REQUIRED');
|
|
241
|
+
let request = { pageSize: c.pageSize ?? o.pageSize, ...(c.path !== undefined ? { path: c.path } : {}) };
|
|
242
|
+
if (c.cursor) {
|
|
243
|
+
const saved = unseal(c.cursor);
|
|
244
|
+
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)
|
|
245
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
246
|
+
request = saved.request;
|
|
247
|
+
}
|
|
248
|
+
const page = await remote(c, signal => o.hostDirectories.browse(t.value, request, signal));
|
|
249
|
+
check(c);
|
|
250
|
+
if (!page.ok)
|
|
251
|
+
return page;
|
|
252
|
+
if (!sameNative(await native(c.workspaceId), x.n))
|
|
253
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
254
|
+
check(c);
|
|
255
|
+
const base = { context: { instanceId: c.instanceId, epoch: c.epoch, workspaceId: c.workspaceId, expectedBindingId: c.expectedBindingId }, native: x.n, identity: t.identity };
|
|
256
|
+
const choose = (info) => seal({ kind: 'selection', ...base, info });
|
|
257
|
+
const { entries, nextAfter, ...info } = page.value;
|
|
258
|
+
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 } }) } : {}) });
|
|
259
|
+
}
|
|
260
|
+
async function select(c) {
|
|
261
|
+
if (!obj(c))
|
|
262
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
263
|
+
strict(c, ['instanceId', 'epoch', 'workspaceId', 'expectedBindingId', 'source', ...(c.source === 'host' ? ['selectionToken'] : c.source === 'legacy-host' ? ['confirmLegacy'] : [])]);
|
|
264
|
+
if (!['local', 'host', 'legacy-host'].includes(c.source))
|
|
265
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
266
|
+
const x = await context(c);
|
|
267
|
+
let r = { ...x.n, bindingId: randomUUID(), source: c.source, active: true, key: '' };
|
|
268
|
+
if (c.source !== 'local') {
|
|
269
|
+
const t = await target(c);
|
|
270
|
+
if (!o.hostDirectories)
|
|
271
|
+
reject('DEPENDENCY_REQUIRED');
|
|
272
|
+
let selected;
|
|
273
|
+
if (c.source === 'host') {
|
|
274
|
+
const s = unseal(c.selectionToken);
|
|
275
|
+
if (s.kind !== 'selection' || !sameNative(s.native, x.n) || s.identity !== t.identity || JSON.stringify(s.context) !== JSON.stringify({ instanceId: c.instanceId, epoch: c.epoch, workspaceId: c.workspaceId, expectedBindingId: c.expectedBindingId }))
|
|
276
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
277
|
+
selected = s.info;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
if (c.confirmLegacy !== true || !x.old || x.old.phase !== 'bound' || x.old.identity !== t.identity || !sameNative(x.old, x.n))
|
|
281
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
282
|
+
const inspected = await remote(c, signal => o.hostDirectories.inspect(t.value, x.old.project.path, signal));
|
|
283
|
+
check(c);
|
|
284
|
+
if (!inspected.ok)
|
|
285
|
+
return inspected;
|
|
286
|
+
selected = inspected.value;
|
|
287
|
+
r.legacyBindingId = x.old.bindingId;
|
|
288
|
+
}
|
|
289
|
+
const inspected = await remote(c, signal => o.hostDirectories.inspect(t.value, selected.requestedPath, signal));
|
|
290
|
+
check(c);
|
|
291
|
+
if (!inspected.ok)
|
|
292
|
+
return inspected;
|
|
293
|
+
if (!sameDirectory(selected, inspected.value))
|
|
294
|
+
reject('HOST_DIRECTORY_CHANGED');
|
|
295
|
+
if (inspected.value.permissions.read !== true || inspected.value.permissions.execute !== true)
|
|
296
|
+
reject('HOST_DIRECTORY_UNREADABLE');
|
|
297
|
+
r = { ...r, remote: inspected.value, identity: t.identity, host: { host: t.value.host, username: t.value.username, port: t.value.port } };
|
|
298
|
+
}
|
|
299
|
+
if (!sameNative(await native(c.workspaceId), x.n))
|
|
300
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
301
|
+
check(c);
|
|
302
|
+
if (x.current && x.current.source === r.source && JSON.stringify(x.current.remote) === JSON.stringify(r.remote) && x.current.identity === r.identity)
|
|
303
|
+
return ok(structuredClone(snapshot));
|
|
304
|
+
for (const old of x.stored)
|
|
305
|
+
if (old.active && old.workspaceId === c.workspaceId)
|
|
306
|
+
old.active = false;
|
|
307
|
+
if (x.stored.some(old => old.bindingId === r.bindingId))
|
|
308
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
309
|
+
x.stored.push(r);
|
|
310
|
+
await save(x.stored, async () => {
|
|
311
|
+
if (!sameNative(await native(c.workspaceId), x.n))
|
|
312
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
313
|
+
check(c);
|
|
314
|
+
}, c);
|
|
315
|
+
publish(await items(x.stored, x.legacy));
|
|
316
|
+
check(c);
|
|
317
|
+
return ok(structuredClone(snapshot));
|
|
318
|
+
}
|
|
319
|
+
function checkLocalContext(c) {
|
|
320
|
+
const current = o.api.getConnectionState();
|
|
321
|
+
if (disposed || current.phase === 'disposed')
|
|
322
|
+
reject('DISPOSED');
|
|
323
|
+
if (current.instanceId !== c.instanceId || current.epoch !== c.epoch)
|
|
324
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
325
|
+
}
|
|
326
|
+
function registeredLocalPath(id) {
|
|
327
|
+
const matches = o.registry.list().filter(w => w.id === id), registered = o.registry.get(id);
|
|
328
|
+
if (matches.length !== 1 || !registered || registered.id !== id || !isAbsolute(matches[0].path) || registered.path !== matches[0].path)
|
|
329
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
330
|
+
return matches[0].path;
|
|
331
|
+
}
|
|
332
|
+
async function localContext(c) {
|
|
333
|
+
checkLocalContext(c);
|
|
334
|
+
await prepare();
|
|
335
|
+
const stored = await records();
|
|
336
|
+
checkLocalContext(c);
|
|
337
|
+
const record = stored.find(r => r.active && r.workspaceId === c.workspaceId);
|
|
338
|
+
if (!record || record.bindingId !== c.expectedBindingId)
|
|
339
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
340
|
+
if (record.source !== 'local')
|
|
341
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
342
|
+
const registeredPath = registeredLocalPath(c.workspaceId);
|
|
343
|
+
const first = await native(c.workspaceId);
|
|
344
|
+
checkLocalContext(c);
|
|
345
|
+
if (!sameNative(record, first))
|
|
346
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
347
|
+
const facts = readLocalWorkspaceProcess();
|
|
348
|
+
if (!facts.ok)
|
|
349
|
+
return facts;
|
|
350
|
+
const latest = (await records()).find(r => r.active && r.workspaceId === c.workspaceId);
|
|
351
|
+
checkLocalContext(c);
|
|
352
|
+
if (!latest || latest.bindingId !== record.bindingId || latest.source !== 'local' || !sameNative(record, latest))
|
|
353
|
+
reject('WORKSPACE_LOCATION_CONFLICT');
|
|
354
|
+
const last = await native(c.workspaceId);
|
|
355
|
+
checkLocalContext(c);
|
|
356
|
+
if (!sameNative(record, last))
|
|
357
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
358
|
+
// Final synchronous registry check closes changes during the preceding filesystem awaits.
|
|
359
|
+
if (registeredLocalPath(c.workspaceId) !== registeredPath)
|
|
360
|
+
reject('WORKSPACE_LOCATION_INVALID');
|
|
361
|
+
checkLocalContext(c);
|
|
362
|
+
return ok({ version: 1, instanceId: c.instanceId, epoch: c.epoch, workspaceId: c.workspaceId, bindingId: record.bindingId, source: 'local',
|
|
363
|
+
directory: { path: last.localPath, device: last.localDev, inode: last.localIno }, provenance: 'official-workspace-registry', process: facts.value });
|
|
364
|
+
}
|
|
365
|
+
function getLocalWorkspaceContext(request) {
|
|
366
|
+
if (disposed || o.api.getConnectionState().phase === 'disposed')
|
|
367
|
+
return Promise.resolve(fail('DISPOSED'));
|
|
368
|
+
if (!obj(request) || Object.keys(request).sort().join(',') !== 'epoch,expectedBindingId,instanceId,workspaceId' || !token(request.instanceId) || !Number.isSafeInteger(request.epoch) || request.epoch < 0 || !token(request.workspaceId) || !token(request.expectedBindingId))
|
|
369
|
+
return Promise.resolve(fail('WORKSPACE_LOCATION_INVALID'));
|
|
370
|
+
// Copy before queueing: retaining the caller's input cannot change this operation's scope.
|
|
371
|
+
const c = { instanceId: request.instanceId, epoch: request.epoch, workspaceId: request.workspaceId, expectedBindingId: request.expectedBindingId };
|
|
372
|
+
return serial(() => localContext(c));
|
|
373
|
+
}
|
|
374
|
+
async function guard(sessionId) {
|
|
375
|
+
const c = connection();
|
|
376
|
+
check(c);
|
|
377
|
+
await prepare();
|
|
378
|
+
check(c);
|
|
379
|
+
const workspaces = o.registry.list().filter(w => w.sessionIds.includes(sessionId));
|
|
380
|
+
if (workspaces.length !== 1)
|
|
381
|
+
return fail('WORKSPACE_LOCATION_REQUIRED');
|
|
382
|
+
const stored = await records();
|
|
383
|
+
check(c);
|
|
384
|
+
const r = stored.find(r => r.active && r.workspaceId === workspaces[0].id);
|
|
385
|
+
if (!r)
|
|
386
|
+
return fail('WORKSPACE_LOCATION_REQUIRED');
|
|
387
|
+
if (!sameNative(r, await native(r.workspaceId)))
|
|
388
|
+
return fail('WORKSPACE_LOCATION_INVALID');
|
|
389
|
+
check(c);
|
|
390
|
+
if (r.source === 'local')
|
|
391
|
+
return fail('WORKSPACE_EXECUTION_UNAVAILABLE');
|
|
392
|
+
if (r.source === 'host')
|
|
393
|
+
return fail('WORKSPACE_LOCATION_PROVIDER_REQUIRED');
|
|
394
|
+
const t = await target(c), legacy = (await o.readLegacy()).find(old => old.bindingId === r.legacyBindingId);
|
|
395
|
+
check(c);
|
|
396
|
+
if (!legacy || r.identity !== t.identity || legacy.identity !== t.identity || legacy.project.path !== r.remote?.path)
|
|
397
|
+
return fail('WORKSPACE_LOCATION_INVALID');
|
|
398
|
+
const current = o.hostDirectories ? await remote(c, signal => o.hostDirectories.inspect(t.value, r.remote.requestedPath, signal)) : undefined;
|
|
399
|
+
check(c);
|
|
400
|
+
if (!current?.ok || r.remote.path !== current.value.path || r.remote.requestedPath !== current.value.requestedPath || r.remote.identity.device !== current.value.identity.device || r.remote.identity.inode !== current.value.identity.inode || JSON.stringify(r.remote.entryIdentity) !== JSON.stringify(current.value.entryIdentity))
|
|
401
|
+
return fail('WORKSPACE_LOCATION_INVALID');
|
|
402
|
+
return ok(undefined);
|
|
403
|
+
}
|
|
404
|
+
return { getLocalWorkspaceContext, getWorkspaceLocationState: () => structuredClone(snapshot), onWorkspaceLocationState(listener) { listeners.add(listener); return () => { listeners.delete(listener); }; }, refreshWorkspaceLocations: () => serial(refresh), browseWorkspaceHostDirectories: (c) => serial(() => browse(c)), selectWorkspaceLocation: (c) => serial(() => select(c)), guardLegacySession: (id) => serial(() => guard(id)), resolveLegacySession: (id, resolve) => serial(async () => {
|
|
405
|
+
const c = connection(), before = await guard(id);
|
|
406
|
+
if (!before.ok)
|
|
407
|
+
return before;
|
|
408
|
+
check(c);
|
|
409
|
+
const result = await resolve();
|
|
410
|
+
check(c);
|
|
411
|
+
const after = await guard(id);
|
|
412
|
+
check(c);
|
|
413
|
+
return after.ok ? result : after;
|
|
414
|
+
}), observeConnection() {
|
|
415
|
+
if (disposed)
|
|
416
|
+
return;
|
|
417
|
+
for (const controller of controllers)
|
|
418
|
+
controller.abort();
|
|
419
|
+
publish(snapshot.items.map(i => i.source === 'host' || i.source === 'legacy-host' ? { ...i, status: i.status === 'legacy-confirmation-required' ? i.status : 'invalid', need: need('WORKSPACE_LOCATION_CONFLICT') } : i));
|
|
420
|
+
}, dispose() {
|
|
421
|
+
disposed = true;
|
|
422
|
+
for (const controller of controllers)
|
|
423
|
+
controller.abort();
|
|
424
|
+
listeners.clear();
|
|
425
|
+
return tail;
|
|
426
|
+
} };
|
|
427
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-workbench/connect",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24.13.1"
|
|
@@ -42,13 +42,14 @@
|
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@deepseek-ai/cordis": "4.0.4",
|
|
45
|
-
"@deepseek-ai/
|
|
46
|
-
"@deepseek-ai/
|
|
45
|
+
"@deepseek-ai/dsh-host-directory-picker-native": "0.2.0-rc.2",
|
|
46
|
+
"@deepseek-ai/schemastery": "3.18.4"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@deepseek-ai/cordis": "4.0.4",
|
|
50
50
|
"@deepseek-ai/cordis-plugin-group": "1.0.4",
|
|
51
51
|
"@deepseek-ai/cordis-plugin-include": "1.0.9",
|
|
52
|
+
"@deepseek-ai/cordis-plugin-loader": "1.0.5",
|
|
52
53
|
"@deepseek-ai/schemastery": "3.18.4",
|
|
53
54
|
"@types/js-yaml": "4.0.9",
|
|
54
55
|
"@types/node": "24.0.0",
|