@commonlyai/cli 0.1.343 → 0.1.345
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/package.json +1 -1
- package/src/commands/daemon.js +19 -8
- package/src/lib/adapter-login.js +13 -0
- package/src/lib/adapters/opencode.js +192 -43
- package/src/lib/runtime-inventory.js +11 -4
package/package.json
CHANGED
package/src/commands/daemon.js
CHANGED
|
@@ -26,7 +26,8 @@ import {
|
|
|
26
26
|
import { loadAgentToken, saveAgentToken } from './agent.js';
|
|
27
27
|
import { getLastTurn } from '../lib/session-store.js';
|
|
28
28
|
import { getAdapter, providerKeyEnvNames, seatProviderKeyEnv } from '../lib/adapters/index.js';
|
|
29
|
-
import { runLoginStatus, signedOutAdapters, signedOutHint } from '../lib/adapter-login.js';
|
|
29
|
+
import { loginState, runLoginStatus, signedOutAdapters, signedOutHint } from '../lib/adapter-login.js';
|
|
30
|
+
|
|
30
31
|
import {
|
|
31
32
|
installDaemonService,
|
|
32
33
|
installSummary,
|
|
@@ -59,6 +60,9 @@ import { machineHostReport } from '../lib/machine-host.js';
|
|
|
59
60
|
import { orchestrateDaemonSetup } from '../lib/stable-install.js';
|
|
60
61
|
import { CLI } from '../lib/cli-hint.js';
|
|
61
62
|
|
|
63
|
+
// Set on the steps `daemon setup` runs, so a step can leave a line to setup.
|
|
64
|
+
const SETUP_CHILD_ENV = 'COMMONLY_DAEMON_SETUP_STEP';
|
|
65
|
+
|
|
62
66
|
// launchd, systemd and Task Scheduler hold one Commonly daemon per computer
|
|
63
67
|
// account. Install refuses to stop another HOME's; this flag takes it over.
|
|
64
68
|
const REPLACE_FLAG = '--replace';
|
|
@@ -371,6 +375,10 @@ export const firstSupervisionPass = async ({
|
|
|
371
375
|
|
|
372
376
|
export const registerDaemon = (program) => {
|
|
373
377
|
const daemon = program.command('daemon').description('Manage the local Commonly daemon');
|
|
378
|
+
const signedOutNotes = async () => (await signedOutAdapters({
|
|
379
|
+
detect: (name) => getAdapter(name)?.detect(),
|
|
380
|
+
runStatus: runLoginStatus,
|
|
381
|
+
})).map((name) => `Note: ${signedOutHint(name)}.`);
|
|
374
382
|
|
|
375
383
|
daemon.addHelpText('after', `
|
|
376
384
|
The daemon token is scoped to this machine and stored in a 0600 file under
|
|
@@ -411,7 +419,8 @@ Examples:
|
|
|
411
419
|
// device-auth and any prompts work; reject on a non-zero exit so a
|
|
412
420
|
// failed step stops the chain before the next one.
|
|
413
421
|
runCli: (entry, args) => new Promise((resolve, reject) => {
|
|
414
|
-
|
|
422
|
+
// SETUP_CHILD_ENV: register leaves the signed-out note to setup's last line.
|
|
423
|
+
const child = spawn(process.execPath, [entry, ...args], { stdio: 'inherit', env: { ...process.env, [SETUP_CHILD_ENV]: '1' } });
|
|
415
424
|
child.on('error', reject);
|
|
416
425
|
child.on('close', (code) => (code === 0
|
|
417
426
|
? resolve()
|
|
@@ -420,11 +429,7 @@ Examples:
|
|
|
420
429
|
});
|
|
421
430
|
// Growth's F370 walk: setup said all was well, and the first @mention
|
|
422
431
|
// then failed with "claude exited 1: Not logged in".
|
|
423
|
-
const
|
|
424
|
-
detect: (name) => getAdapter(name)?.detect(),
|
|
425
|
-
runStatus: runLoginStatus,
|
|
426
|
-
});
|
|
427
|
-
for (const name of signedOut) console.log(`Note: ${signedOutHint(name)}.`);
|
|
432
|
+
for (const line of await signedOutNotes()) console.log(line);
|
|
428
433
|
} catch (error) {
|
|
429
434
|
console.error(`Daemon setup failed: ${error.message}`);
|
|
430
435
|
process.exitCode = 1;
|
|
@@ -472,6 +477,12 @@ Examples:
|
|
|
472
477
|
if (existing && existsSync(servicePaths(process.platform, homedir()).file)) {
|
|
473
478
|
console.log(`Restart the installed daemon to use the new key: ${CLI} daemon restart`);
|
|
474
479
|
}
|
|
480
|
+
// F458: register run by hand (the F454 walk) said nothing, and the
|
|
481
|
+
// agent looked healthy until its first message failed. Setup prints
|
|
482
|
+
// this itself, after the install step, so its own register doesn't.
|
|
483
|
+
if (!process.env[SETUP_CHILD_ENV]) {
|
|
484
|
+
for (const line of await signedOutNotes()) console.log(line);
|
|
485
|
+
}
|
|
475
486
|
} catch (error) {
|
|
476
487
|
console.error(`Daemon registration failed: ${error.message}`);
|
|
477
488
|
process.exitCode = 1;
|
|
@@ -740,7 +751,7 @@ Examples:
|
|
|
740
751
|
// exit parks it on macOS; systemd honors 77 directly.
|
|
741
752
|
process.exitCode = saved || process.platform !== 'darwin' ? 77 : 0;
|
|
742
753
|
};
|
|
743
|
-
const runtimeInventory = createInventoryCache((harnesses) => collectRuntimeInventory(getAdapter, undefined, harnesses));
|
|
754
|
+
const runtimeInventory = createInventoryCache((harnesses) => collectRuntimeInventory(getAdapter, undefined, harnesses, { loginState }));
|
|
744
755
|
supervisor = createDaemonSupervisor({
|
|
745
756
|
record,
|
|
746
757
|
client,
|
package/src/lib/adapter-login.js
CHANGED
|
@@ -47,6 +47,19 @@ export const signedOutAdapters = async ({ detect, runStatus, env = process.env,
|
|
|
47
47
|
return out;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* One harness's login, for the daemon's inventory (F458): true signed in (exit
|
|
52
|
+
* 0), false signed out (exit 1), null when there is no verdict: no checked
|
|
53
|
+
* probe for it, a key in the environment it runs on instead, or a probe that
|
|
54
|
+
* couldn't run. Only the exit code is read, as above.
|
|
55
|
+
*/
|
|
56
|
+
export const loginState = async (name, { runStatus = runLoginStatus, env = process.env } = {}) => {
|
|
57
|
+
if (!LOGIN_STATUS_ARGS[name] || (KEY_ENV[name] || []).some((key) => envSet(env, key))) return null;
|
|
58
|
+
const code = await runStatus(name, LOGIN_STATUS_ARGS[name]).catch(() => null);
|
|
59
|
+
if (code === 0) return true;
|
|
60
|
+
return code === SIGNED_OUT_EXIT ? false : null;
|
|
61
|
+
};
|
|
62
|
+
|
|
50
63
|
// The exit code of `<name> <args>`, with every stream discarded. null when it
|
|
51
64
|
// cannot run or takes longer than `timeoutMs` (a CLI that opens a prompt).
|
|
52
65
|
export const runLoginStatus = (name, args, { timeoutMs = 10_000, spawnFn = spawn } = {}) => new Promise((done) => {
|
|
@@ -24,7 +24,9 @@ import { requireSeatModel, seatModelRequired } from './seat-model.js';
|
|
|
24
24
|
import { isPatchAfterNewestTested } from './tested-version.js';
|
|
25
25
|
import { spawn as childSpawn, spawnSync } from 'child_process';
|
|
26
26
|
import { createHash, randomUUID } from 'crypto';
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
existsSync, lstatSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync,
|
|
29
|
+
} from 'fs';
|
|
28
30
|
import {
|
|
29
31
|
chmod,
|
|
30
32
|
lstat,
|
|
@@ -39,7 +41,7 @@ import {
|
|
|
39
41
|
import { homedir, tmpdir } from 'os';
|
|
40
42
|
import { fileURLToPath } from 'url';
|
|
41
43
|
import {
|
|
42
|
-
dirname, isAbsolute, join, relative, resolve as pathResolve,
|
|
44
|
+
basename, dirname, isAbsolute, join, relative, resolve as pathResolve,
|
|
43
45
|
} from 'path';
|
|
44
46
|
import { writeCredentialFile } from '../credential-file.js';
|
|
45
47
|
import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credential-delivery.js';
|
|
@@ -193,17 +195,138 @@ const gitReportedWorktree = (holder, env) => {
|
|
|
193
195
|
};
|
|
194
196
|
|
|
195
197
|
// Bounds for the pre-spawn symlink walk. Reaching either one leaves the
|
|
196
|
-
// workspace unproven, and a seat
|
|
198
|
+
// workspace unproven, and a public seat then refuses
|
|
197
199
|
// (`assertSpawnRootOutsideWorkspace`), so the depth sits well above real source
|
|
198
200
|
// trees: it guards against a pathological tree, not an ordinary one.
|
|
199
201
|
const SYMLINK_WALK_BOUNDS = Object.freeze({ maxDepth: 32, maxEntries: 20000 });
|
|
200
|
-
// CodeRabbit round 4 (#3487):
|
|
201
|
-
//
|
|
202
|
+
// CodeRabbit round 4 (#3487): the walk also covers every dependency tree,
|
|
203
|
+
// links only, under its own bound (every public spawn since F185). Measured 2026-11-05 on
|
|
202
204
|
// this repo's backend/node_modules: 44,664 entries, 63 symlinks (none leaving
|
|
203
205
|
// the workspace), 0.5-1.4 s on a host at load average ~90.
|
|
204
206
|
const DEPENDENCY_WALK_BOUNDS = Object.freeze({ maxDepth: 64, maxEntries: 200000 });
|
|
205
207
|
const SYMLINK_WALK_SKIP = new Set(['.git']);
|
|
206
|
-
|
|
208
|
+
// Package-manager trees: their contents are walked links-only under the
|
|
209
|
+
// dependency budget, never as source. A Python environment is one too, by
|
|
210
|
+
// name or by its marker (`pyvenv.cfg`, conda's `conda-meta`), whatever its
|
|
211
|
+
// folder is called: its files would exhaust the source budget (F185).
|
|
212
|
+
const DEPENDENCY_DIRS = new Set(['node_modules', '.venv']);
|
|
213
|
+
const isPythonEnvironment = (entries) => entries.some((entry) => (
|
|
214
|
+
(entry.name === 'pyvenv.cfg' && entry.isFile()) || (entry.name === 'conda-meta' && entry.isDirectory())
|
|
215
|
+
));
|
|
216
|
+
// Pseudo-file systems: a path in them names something per process (an open
|
|
217
|
+
// descriptor, a device), so where it leads in OpenCode is not where it leads
|
|
218
|
+
// here. No link may go there.
|
|
219
|
+
const SPECIAL_ROOTS = ['/proc', '/dev'];
|
|
220
|
+
const underSpecial = (path) => SPECIAL_ROOTS.some((root) => isWithin(root, path));
|
|
221
|
+
const MAX_LINK_HOPS = 40;
|
|
222
|
+
|
|
223
|
+
const isRegularFile = (path) => {
|
|
224
|
+
try { return statSync(path).isFile(); } catch { return false; }
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* F185. Matches a resolved path against the folders holding this spawn's
|
|
229
|
+
* secrets: it lies inside one, or holds one. The same three tests as the
|
|
230
|
+
* provider key file check (keyFileReadableRoot, F453): the paths as written,
|
|
231
|
+
* real-pathed, and by file identity, so another spelling of the same place
|
|
232
|
+
* (case, a firmlink) is the same place. Each path's identity is looked up once
|
|
233
|
+
* per walk; a dependency tree shares most of its ancestors.
|
|
234
|
+
*/
|
|
235
|
+
const secretMatcher = (secretRoots) => {
|
|
236
|
+
const ids = new Map();
|
|
237
|
+
const idOf = (path) => {
|
|
238
|
+
if (!ids.has(path)) {
|
|
239
|
+
let id = null;
|
|
240
|
+
try {
|
|
241
|
+
const details = statSync(path, { bigint: true });
|
|
242
|
+
id = `${details.dev}:${details.ino}`;
|
|
243
|
+
} catch { /* absent: no identity */ }
|
|
244
|
+
ids.set(path, id);
|
|
245
|
+
}
|
|
246
|
+
return ids.get(path);
|
|
247
|
+
};
|
|
248
|
+
const chainIds = (path) => {
|
|
249
|
+
const out = new Set();
|
|
250
|
+
for (let current = path; ; current = dirname(current)) {
|
|
251
|
+
const id = idOf(current);
|
|
252
|
+
if (id) out.add(id);
|
|
253
|
+
if (dirname(current) === current) break;
|
|
254
|
+
}
|
|
255
|
+
return out;
|
|
256
|
+
};
|
|
257
|
+
const secrets = secretRoots.map((root) => ({
|
|
258
|
+
root,
|
|
259
|
+
spellings: [...new Set([pathResolve(root), realOrSelf(root)])],
|
|
260
|
+
id: idOf(root),
|
|
261
|
+
ancestorIds: chainIds(root),
|
|
262
|
+
}));
|
|
263
|
+
return (resolved) => {
|
|
264
|
+
const ancestors = chainIds(resolved);
|
|
265
|
+
const own = idOf(resolved);
|
|
266
|
+
const found = secrets.find((secret) => (
|
|
267
|
+
secret.spellings.some((spelling) => isWithin(spelling, resolved) || isWithin(resolved, spelling))
|
|
268
|
+
|| (secret.id && ancestors.has(secret.id))
|
|
269
|
+
|| (own && secret.ancestorIds.has(own))
|
|
270
|
+
));
|
|
271
|
+
return found ? found.root : null;
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Where a link lands, resolved one component at a time the way the kernel
|
|
277
|
+
* does it, so every step is seen: `special` is set when any step (a hop's
|
|
278
|
+
* target, or a folder passed through) is under /proc or /dev. There a path
|
|
279
|
+
* names something per process (an open descriptor, a process's root), so
|
|
280
|
+
* where it leads for OpenCode is not where it leads for this check, whether or
|
|
281
|
+
* not it resolves here. `..` applies to the real path reached so far, never
|
|
282
|
+
* to the text.
|
|
283
|
+
*
|
|
284
|
+
* `{ resolved, exists: true }` when every component exists (`resolved` is the
|
|
285
|
+
* canonical spelling). When one is missing, `{ resolved, exists: false }`
|
|
286
|
+
* gives where it would land: the real prefix with the rest appended. A missing
|
|
287
|
+
* target is not proof of no route: the seat's data home gets files during the
|
|
288
|
+
* turn. Throws ELOOP past MAX_LINK_HOPS, and any lstat or readlink error other
|
|
289
|
+
* than a missing component.
|
|
290
|
+
*/
|
|
291
|
+
const linkLanding = (path) => {
|
|
292
|
+
let special = false;
|
|
293
|
+
let hops = 0;
|
|
294
|
+
// The walk only reaches real directories, so the link's own folder is real.
|
|
295
|
+
let done = realOrSelf(dirname(pathResolve(path)));
|
|
296
|
+
special = special || underSpecial(done);
|
|
297
|
+
const pending = [basename(path)];
|
|
298
|
+
while (pending.length) {
|
|
299
|
+
const part = pending.shift();
|
|
300
|
+
if (part === '' || part === '.') continue;
|
|
301
|
+
if (part === '..') {
|
|
302
|
+
done = dirname(done);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const next = join(done, part);
|
|
306
|
+
special = special || underSpecial(next);
|
|
307
|
+
let details;
|
|
308
|
+
try {
|
|
309
|
+
details = lstatSync(next);
|
|
310
|
+
} catch (err) {
|
|
311
|
+
if (err?.code !== 'ENOENT' && err?.code !== 'ENOTDIR') throw err;
|
|
312
|
+
const rest = pending.filter((piece) => piece && piece !== '.');
|
|
313
|
+
const resolved = pathResolve(next, ...(rest.length ? [rest.join('/')] : []));
|
|
314
|
+
return { resolved, exists: false, special: special || underSpecial(resolved) };
|
|
315
|
+
}
|
|
316
|
+
if (details.isSymbolicLink()) {
|
|
317
|
+
hops += 1;
|
|
318
|
+
if (hops > MAX_LINK_HOPS) throw Object.assign(new Error(`too many symlink hops resolving ${path}`), { code: 'ELOOP' });
|
|
319
|
+
const text = readlinkSync(next);
|
|
320
|
+
if (isAbsolute(text)) done = '/';
|
|
321
|
+
special = special || underSpecial(pathResolve(done, text));
|
|
322
|
+
pending.unshift(...text.split('/'));
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
done = next;
|
|
326
|
+
}
|
|
327
|
+
// Case and firmlinks: the canonical spelling, for the boundary comparison.
|
|
328
|
+
return { resolved: realOrSelf(done), exists: true, special: special || underSpecial(done) };
|
|
329
|
+
};
|
|
207
330
|
|
|
208
331
|
/**
|
|
209
332
|
* Scan `workspace` for a symlink OpenCode's tools could follow to the per-spawn
|
|
@@ -213,10 +336,12 @@ const DEPENDENCY_DIR = 'node_modules';
|
|
|
213
336
|
* `path: <workspace link to the temp root>` searches the credential's contents
|
|
214
337
|
* with nothing asked. This walk is what stops that, not a permission pattern.
|
|
215
338
|
*
|
|
216
|
-
* Returns `{ link, reason }` for the first offending link, `{ incomplete }`
|
|
217
|
-
* a bound stopped the walk before it saw the whole tree, or null.
|
|
218
|
-
* - `reaches_spawn_root`: the link's
|
|
219
|
-
*
|
|
339
|
+
* Returns `{ link, reason, secret? }` for the first offending link, `{ incomplete }`
|
|
340
|
+
* when a bound stopped the walk before it saw the whole tree, or null.
|
|
341
|
+
* - `reaches_spawn_root`: the link's landing holds or lies inside `spawnRoot`
|
|
342
|
+
* or one of `secretRoots` (named in `secret`). A dangling link is judged by
|
|
343
|
+
* where it would land (`linkLanding`).
|
|
344
|
+
* - `special_filesystem`: the link leads, at any hop, under /proc or /dev.
|
|
220
345
|
* - `outside_workspace`: a link AT a node_modules top level (or under an
|
|
221
346
|
* @scope there) leading out of `boundary`. node_modules is not walked into,
|
|
222
347
|
* since a typical one exhausts the entry bound on every spawn; its packages'
|
|
@@ -224,8 +349,8 @@ const DEPENDENCY_DIR = 'node_modules';
|
|
|
224
349
|
* link out (`npm link`, a `file:` dependency) reaches a tree this walk never
|
|
225
350
|
* read.
|
|
226
351
|
*
|
|
227
|
-
* `deepDependencies` (
|
|
228
|
-
* every workspace link is held to `boundary` as well, and every node_modules tree, nested ones and @scopes included, is walked too,
|
|
352
|
+
* `deepDependencies` (every public spawn since F185; the default stays off for
|
|
353
|
+
* direct callers): every workspace link is held to `boundary` as well, and every node_modules tree, nested ones and @scopes included, is walked too,
|
|
229
354
|
* links only, under `dependencyBounds`, its own budget. A link anywhere in it
|
|
230
355
|
* that reaches the spawn root, or that leaves `boundary`, is refused, since a
|
|
231
356
|
* package tarball or postinstall script can plant `dist/x -> /tmp`, or a chain
|
|
@@ -238,16 +363,19 @@ const DEPENDENCY_DIR = 'node_modules';
|
|
|
238
363
|
* OS) or a link realpath cannot resolve for a reason other than a missing
|
|
239
364
|
* target (`incomplete: 'unresolvable'`, a loop say), each with `problem:
|
|
240
365
|
* { path, code }`. `root` is where the walk starts: the git worktree root for a
|
|
241
|
-
*
|
|
366
|
+
* public seat, since OpenCode's tools reach the whole worktree. A link to a
|
|
367
|
+
* regular file outside `boundary` and every secret folder passes: a file holds
|
|
368
|
+
* no further link.
|
|
242
369
|
*/
|
|
243
370
|
const scanWorkspaceLinks = (workspace, spawnRoot, {
|
|
244
371
|
boundary = workspace,
|
|
245
372
|
root = workspace,
|
|
373
|
+
secretRoots = [],
|
|
246
374
|
bounds = SYMLINK_WALK_BOUNDS,
|
|
247
375
|
deepDependencies = false,
|
|
248
376
|
dependencyBounds = DEPENDENCY_WALK_BOUNDS,
|
|
249
377
|
} = {}) => {
|
|
250
|
-
const
|
|
378
|
+
const matchSecret = secretMatcher([...new Set([spawnRoot, ...secretRoots].filter(Boolean))]);
|
|
251
379
|
const inside = realOrSelf(boundary);
|
|
252
380
|
let budget = bounds.maxEntries;
|
|
253
381
|
let dependencyBudget = dependencyBounds.maxEntries;
|
|
@@ -261,15 +389,23 @@ const scanWorkspaceLinks = (workspace, spawnRoot, {
|
|
|
261
389
|
problem = problem || { path, code: err?.code || String(err) };
|
|
262
390
|
};
|
|
263
391
|
const linkFinding = (path, { dependencyTop }) => {
|
|
264
|
-
let
|
|
392
|
+
let landing;
|
|
265
393
|
try {
|
|
266
|
-
|
|
394
|
+
landing = linkLanding(path);
|
|
267
395
|
} catch (err) {
|
|
268
396
|
unproven('unresolvable', path, err);
|
|
269
397
|
return null;
|
|
270
398
|
}
|
|
271
|
-
|
|
272
|
-
if (
|
|
399
|
+
const { resolved, exists, special } = landing;
|
|
400
|
+
if (special) return { link: path, reason: 'special_filesystem' };
|
|
401
|
+
const secret = matchSecret(resolved);
|
|
402
|
+
if (secret) return { link: path, reason: 'reaches_spawn_root', secret };
|
|
403
|
+
if (!exists) return null;
|
|
404
|
+
// A regular file outside every secret folder holds no further link, so a
|
|
405
|
+
// link to one leads nowhere else (a virtualenv's bin/python -> /usr/bin).
|
|
406
|
+
if (dependencyTop && !isWithin(inside, resolved) && !isRegularFile(resolved)) {
|
|
407
|
+
return { link: path, reason: 'outside_workspace' };
|
|
408
|
+
}
|
|
273
409
|
return null;
|
|
274
410
|
};
|
|
275
411
|
const readEntries = (dir) => {
|
|
@@ -341,6 +477,8 @@ const scanWorkspaceLinks = (workspace, spawnRoot, {
|
|
|
341
477
|
}
|
|
342
478
|
const entries = readEntries(dir);
|
|
343
479
|
if (incomplete) return null;
|
|
480
|
+
// A Python environment under any name: links only, on the dependency budget.
|
|
481
|
+
if (deepDependencies && isPythonEnvironment(entries)) return scanDependencyTree(dir);
|
|
344
482
|
for (const entry of entries) {
|
|
345
483
|
budget -= 1;
|
|
346
484
|
if (budget < 0) {
|
|
@@ -349,17 +487,17 @@ const scanWorkspaceLinks = (workspace, spawnRoot, {
|
|
|
349
487
|
}
|
|
350
488
|
const path = join(dir, entry.name);
|
|
351
489
|
if (entry.isSymbolicLink()) {
|
|
352
|
-
//
|
|
353
|
-
//
|
|
354
|
-
//
|
|
490
|
+
// Every workspace link is held to the boundary: a chain through a tree
|
|
491
|
+
// outside it (src/vendor -> /outside, a node_modules that is itself a
|
|
492
|
+
// link) is resolved by the OS, unread by this walk.
|
|
355
493
|
const hit = linkFinding(path, { dependencyTop: deepDependencies });
|
|
356
494
|
if (hit || incomplete) return hit;
|
|
357
|
-
} else if (entry.isDirectory() && entry.name
|
|
495
|
+
} else if (entry.isDirectory() && DEPENDENCY_DIRS.has(entry.name)) {
|
|
358
496
|
const hit = scanDependencyTop(path) || (!incomplete && deepDependencies ? scanDependencyTree(path) : null);
|
|
359
497
|
if (hit || incomplete) return hit;
|
|
360
498
|
} else if (deepDependencies && entry.isDirectory() && SYMLINK_WALK_SKIP.has(entry.name)) {
|
|
361
|
-
// `.git
|
|
362
|
-
//
|
|
499
|
+
// `.git`: links only, under the dependency budget (8,243 entries in
|
|
500
|
+
// this repo's own checkout, no links).
|
|
363
501
|
const hit = scanDependencyTree(path);
|
|
364
502
|
if (hit || incomplete) return hit;
|
|
365
503
|
} else if (entry.isDirectory() && !SYMLINK_WALK_SKIP.has(entry.name)) {
|
|
@@ -377,13 +515,15 @@ const scanWorkspaceLinks = (workspace, spawnRoot, {
|
|
|
377
515
|
|
|
378
516
|
/**
|
|
379
517
|
* Refuse a public seat whose workspace lets OpenCode's tools reach the
|
|
380
|
-
* per-spawn credential directory
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
518
|
+
* per-spawn credential directory, or another folder holding this spawn's
|
|
519
|
+
* secrets (`secretRoots`, the seat's data home). Every public spawn holds a
|
|
520
|
+
* live Commonly token and a provider-proxy token there, so every one gets the
|
|
521
|
+
* same walk (F185): from the worktree root, node_modules, .venv and .git
|
|
522
|
+
* links-only, every link held to the worktree, and a walk its bound stopped
|
|
523
|
+
* refuses.
|
|
384
524
|
*/
|
|
385
525
|
const assertSpawnRootOutsideWorkspace = (workspace, spawnRoot, {
|
|
386
|
-
|
|
526
|
+
secretRoots = [],
|
|
387
527
|
bounds = SYMLINK_WALK_BOUNDS,
|
|
388
528
|
dependencyBounds = DEPENDENCY_WALK_BOUNDS,
|
|
389
529
|
gitEnv = null,
|
|
@@ -441,14 +581,14 @@ const assertSpawnRootOutsideWorkspace = (workspace, spawnRoot, {
|
|
|
441
581
|
// OpenCode counts the whole git worktree as inside the project, so a
|
|
442
582
|
// node_modules link into it is not a link out.
|
|
443
583
|
const boundary = toplevels[0]?.[0] || gitToplevel(pathResolve(workspace)) || workspace;
|
|
444
|
-
//
|
|
445
|
-
//
|
|
446
|
-
// workspace.
|
|
584
|
+
// The whole worktree OpenCode's tools can reach, sibling packages and .git
|
|
585
|
+
// included (Opus review, #3487; every public spawn since F185).
|
|
447
586
|
const finding = scanWorkspaceLinks(workspace, spawnRoot, {
|
|
448
587
|
boundary,
|
|
449
|
-
root:
|
|
588
|
+
root: realOrSelf(boundary),
|
|
589
|
+
secretRoots,
|
|
450
590
|
bounds,
|
|
451
|
-
deepDependencies:
|
|
591
|
+
deepDependencies: true,
|
|
452
592
|
dependencyBounds,
|
|
453
593
|
});
|
|
454
594
|
if (finding?.incomplete === 'unreadable' || finding?.incomplete === 'unresolvable') {
|
|
@@ -456,14 +596,22 @@ const assertSpawnRootOutsideWorkspace = (workspace, spawnRoot, {
|
|
|
456
596
|
throw new Error(
|
|
457
597
|
`public OpenCode agents could not ${finding.incomplete === 'unreadable' ? 'list the directory' : 'resolve the symlink'} `
|
|
458
598
|
+ `${path} (${code}) while checking the workspace (${workspace}) for symlinks to the per-spawn credential directory; `
|
|
459
|
-
+ 'what the walk cannot see is not proven clean
|
|
460
|
-
+ 'remove it, or drop the grant broker from this seat',
|
|
599
|
+
+ 'what the walk cannot see is not proven clean; fix its permissions, or remove it',
|
|
461
600
|
);
|
|
462
601
|
}
|
|
463
602
|
if (finding?.reason === 'reaches_spawn_root') {
|
|
603
|
+
const folder = !finding.secret || finding.secret === spawnRoot
|
|
604
|
+
? `the per-spawn credential directory (${spawnRoot})`
|
|
605
|
+
: `the seat's data folder (${finding.secret})`;
|
|
606
|
+
throw new Error(
|
|
607
|
+
`public OpenCode agents refuse a workspace (${workspace}) holding a symlink (${finding.link}) that reaches `
|
|
608
|
+
+ `${folder}: OpenCode's tools could read this spawn's credentials through it; remove the link`,
|
|
609
|
+
);
|
|
610
|
+
}
|
|
611
|
+
if (finding?.reason === 'special_filesystem') {
|
|
464
612
|
throw new Error(
|
|
465
|
-
`public OpenCode agents refuse a workspace (${workspace}) holding a symlink (${finding.link}) that
|
|
466
|
-
+
|
|
613
|
+
`public OpenCode agents refuse a workspace (${workspace}) holding a symlink (${finding.link}) that leads into `
|
|
614
|
+
+ '/proc or /dev, where a path names something per process and the check cannot follow it; remove the link',
|
|
467
615
|
);
|
|
468
616
|
}
|
|
469
617
|
if (finding?.reason === 'outside_workspace') {
|
|
@@ -478,15 +626,15 @@ const assertSpawnRootOutsideWorkspace = (workspace, spawnRoot, {
|
|
|
478
626
|
`public OpenCode agents could not finish checking the workspace's node_modules and .git trees (${workspace}) for symlinks `
|
|
479
627
|
+ `to the per-spawn credential directory: the link walk stopped at its ${finding.incomplete === 'dependency_depth'
|
|
480
628
|
? `depth bound (${dependencyBounds.maxDepth} levels)` : `entry bound (${dependencyBounds.maxEntries} entries)`}, `
|
|
481
|
-
+ '
|
|
629
|
+
+ 'prune the dependency tree, or choose a smaller workspace',
|
|
482
630
|
);
|
|
483
631
|
}
|
|
484
|
-
if (finding?.incomplete
|
|
632
|
+
if (finding?.incomplete) {
|
|
485
633
|
throw new Error(
|
|
486
634
|
`public OpenCode agents could not finish checking the workspace (${workspace}) for symlinks to the per-spawn `
|
|
487
635
|
+ `credential directory: the walk stopped at its ${finding.incomplete === 'depth'
|
|
488
|
-
? `depth bound (${bounds.maxDepth} levels)` : `entry bound (${bounds.maxEntries} entries)`}
|
|
489
|
-
+ '
|
|
636
|
+
? `depth bound (${bounds.maxDepth} levels)` : `entry bound (${bounds.maxEntries} entries)`}; `
|
|
637
|
+
+ 'choose a smaller workspace',
|
|
490
638
|
);
|
|
491
639
|
}
|
|
492
640
|
};
|
|
@@ -1361,7 +1509,7 @@ export default {
|
|
|
1361
1509
|
// After the child env exists: the git check runs under the very env
|
|
1362
1510
|
// OpenCode gets (its HOME, its XDG config, no GIT_* from the launcher).
|
|
1363
1511
|
assertSpawnRootOutsideWorkspace(ctx.cwd || process.cwd(), tempDir, {
|
|
1364
|
-
|
|
1512
|
+
secretRoots: [openCodeHome.root],
|
|
1365
1513
|
bounds: ctx._symlinkWalkBounds || SYMLINK_WALK_BOUNDS,
|
|
1366
1514
|
dependencyBounds: ctx._dependencyWalkBounds || DEPENDENCY_WALK_BOUNDS,
|
|
1367
1515
|
gitEnv: childEnv,
|
|
@@ -1503,5 +1651,6 @@ export {
|
|
|
1503
1651
|
qualifiedProviderModel,
|
|
1504
1652
|
resolveProviderKeyFile,
|
|
1505
1653
|
scanWorkspaceLinks,
|
|
1654
|
+
assertSpawnRootOutsideWorkspace,
|
|
1506
1655
|
startProviderProxy,
|
|
1507
1656
|
};
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
// Probe only the walked adapter's version command. Never enumerate workspace
|
|
2
2
|
// extensions to discover models: a model picker must not execute project code.
|
|
3
3
|
export const WALKED_HARNESSES = ['claude', 'codex', 'opencode', 'hermes', 'dsh'];
|
|
4
|
-
|
|
4
|
+
// `loginState` (F458), when given, adds `signedIn` to an installed harness it
|
|
5
|
+
// has a verdict for, so the page can say "not signed in" before the first
|
|
6
|
+
// message fails instead of after.
|
|
7
|
+
export const collectRuntimeInventory = async (getAdapter, capabilities, harnesses = WALKED_HARNESSES, { loginState } = {}) => Promise.all(harnesses.map(async (harness) => {
|
|
5
8
|
const adapter = getAdapter(harness);
|
|
6
9
|
let detected = null;
|
|
7
10
|
try { detected = await adapter?.detect(); } catch { /* unavailable */ }
|
|
8
11
|
let choices = { models: null, efforts: [] };
|
|
9
12
|
if (detected) { try { choices = (await (capabilities ? capabilities(harness) : adapter?.inventory?.())) || choices; } catch { /* unavailable */ } }
|
|
13
|
+
let signedIn = null;
|
|
14
|
+
if (detected && loginState) { try { signedIn = await loginState(harness); } catch { /* no verdict */ } }
|
|
10
15
|
return { harness, installed: Boolean(detected), version: detected?.version || null,
|
|
11
|
-
models: choices.models, efforts: choices.efforts };
|
|
16
|
+
models: choices.models, efforts: choices.efforts, ...(typeof signedIn === 'boolean' ? { signedIn } : {}) };
|
|
12
17
|
}));
|
|
13
18
|
|
|
14
19
|
// The daemon's inventory, refreshed in full every five minutes. A harness it
|
|
15
20
|
// didn't find is probed again sooner, so one installed while the BYO page is
|
|
16
|
-
// open shows up within a heartbeat or two, without a reload (F370 #8).
|
|
21
|
+
// open shows up within a heartbeat or two, without a reload (F370 #8). One
|
|
22
|
+
// that reported signed out is rechecked the same way, so a sign-in does too (F458).
|
|
17
23
|
// Probes are synchronous: a binary that isn't there fails at once, but one
|
|
18
24
|
// that's there and hangs on --version blocks the daemon for its timeout. A
|
|
19
25
|
// re-probe slower than INVENTORY_SLOW_MS waits for the full refresh instead.
|
|
@@ -34,7 +40,8 @@ export const createInventoryCache = (collect, { now = Date.now } = {}) => {
|
|
|
34
40
|
slow = new Set();
|
|
35
41
|
return cached;
|
|
36
42
|
}
|
|
37
|
-
const missing = cached.filter((row) => !row.installed && !slow.has(row.harness))
|
|
43
|
+
const missing = cached.filter((row) => (!row.installed || row.signedIn === false) && !slow.has(row.harness))
|
|
44
|
+
.map((row) => row.harness);
|
|
38
45
|
if (missing.length && at - missingAt > INVENTORY_MISSING_MS) {
|
|
39
46
|
missingAt = at;
|
|
40
47
|
for (const harness of missing) {
|