@commonlyai/cli 0.1.339 → 0.1.341
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 +3 -10
- package/src/lib/adapters/pi.js +23 -10
- package/src/lib/runtime-inventory.js +38 -1
- package/src/lib/sandbox/seatbelt.js +53 -0
package/package.json
CHANGED
package/src/commands/daemon.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { collectRuntimeInventory } from '../lib/runtime-inventory.js';
|
|
1
|
+
import { collectRuntimeInventory, createInventoryCache } from '../lib/runtime-inventory.js';
|
|
2
2
|
/**
|
|
3
3
|
* commonly daemon <subcommand>
|
|
4
4
|
*
|
|
@@ -740,8 +740,7 @@ Examples:
|
|
|
740
740
|
// exit parks it on macOS; systemd honors 77 directly.
|
|
741
741
|
process.exitCode = saved || process.platform !== 'darwin' ? 77 : 0;
|
|
742
742
|
};
|
|
743
|
-
|
|
744
|
-
let inventoryCheckedAt = 0;
|
|
743
|
+
const runtimeInventory = createInventoryCache((harnesses) => collectRuntimeInventory(getAdapter, undefined, harnesses));
|
|
745
744
|
supervisor = createDaemonSupervisor({
|
|
746
745
|
record,
|
|
747
746
|
client,
|
|
@@ -767,13 +766,7 @@ Examples:
|
|
|
767
766
|
loadToken: loadAgentToken,
|
|
768
767
|
saveToken: saveAgentToken,
|
|
769
768
|
machineReport: daemonMachineReport,
|
|
770
|
-
runtimeInventory
|
|
771
|
-
if (!cachedInventory || Date.now() - inventoryCheckedAt > 300_000) {
|
|
772
|
-
cachedInventory = await collectRuntimeInventory(getAdapter);
|
|
773
|
-
inventoryCheckedAt = Date.now();
|
|
774
|
-
}
|
|
775
|
-
return cachedInventory;
|
|
776
|
-
},
|
|
769
|
+
runtimeInventory,
|
|
777
770
|
resolveAdapter: (runtime) => resolveAdapterForRuntime(runtime),
|
|
778
771
|
log: stampLog,
|
|
779
772
|
persistState: (seats) => saveDaemonState({
|
package/src/lib/adapters/pi.js
CHANGED
|
@@ -71,7 +71,7 @@ import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credent
|
|
|
71
71
|
import { prepareMcpSpawn, publicMcpUnavailableError, selectedMcpVersionDir } from '../mcp-home.js';
|
|
72
72
|
import { removeCredentialFile, writeCredentialFile } from '../credential-file.js';
|
|
73
73
|
import { resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
74
|
-
import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
74
|
+
import { seatbeltSystemReadRoots, wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
75
75
|
import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
|
|
76
76
|
import { publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
77
77
|
import { promptTokens } from '../session-recycle.js';
|
|
@@ -344,16 +344,29 @@ const sharedProviderKeyFile = async (environment, workspacePath) => {
|
|
|
344
344
|
|
|
345
345
|
/**
|
|
346
346
|
* The proxy reads a public seat's key file from this process, so the file stays
|
|
347
|
-
* out of the jail, and nothing here admits it. The jail does admit
|
|
348
|
-
* directories
|
|
349
|
-
*
|
|
347
|
+
* out of the jail, and nothing here admits it. The jail does admit the seat's
|
|
348
|
+
* own directories (the seat home is a stable path a key file could be put in),
|
|
349
|
+
* and the Seatbelt baseline admits system trees such as /etc, /opt/homebrew/lib
|
|
350
|
+
* and /usr/local/lib (seatbeltSystemReadRoots, read from the profile itself).
|
|
351
|
+
* A key under any of them would be readable from inside, so it is refused.
|
|
352
|
+
* Each root is compared as written and through its real path (/etc is
|
|
353
|
+
* /private/etc on macOS); a root that does not exist is compared as written.
|
|
350
354
|
*/
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
const realOrSelf = (path) => { try { return realpathSync(path); } catch { return path; } };
|
|
356
|
+
const within = (root, path) => {
|
|
357
|
+
const fromRoot = relative(root, path);
|
|
358
|
+
return fromRoot !== '..' && !fromRoot.startsWith(`..${sep}`) && !isAbsolute(fromRoot);
|
|
359
|
+
};
|
|
360
|
+
export const refuseKeyFileInJail = (keyFile, readableDirectories, systemRoots = seatbeltSystemReadRoots()) => {
|
|
361
|
+
const refuse = (root) => {
|
|
362
|
+
throw new Error(`pi adapter: provider.keyFile ${keyFile} is inside the sandbox of a public seat; move it outside ${root}`);
|
|
363
|
+
};
|
|
364
|
+
const forms = (root) => [...new Set([root, realOrSelf(root)])];
|
|
365
|
+
for (const directory of [...readableDirectories, ...systemRoots.subpaths]) {
|
|
366
|
+
if (forms(directory).some((root) => within(root, keyFile))) refuse(directory);
|
|
367
|
+
}
|
|
368
|
+
for (const literal of systemRoots.literals) {
|
|
369
|
+
if (forms(literal).includes(keyFile)) refuse(literal);
|
|
357
370
|
}
|
|
358
371
|
};
|
|
359
372
|
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
export const collectRuntimeInventory = async (getAdapter, capabilities) => Promise.all(
|
|
4
|
+
export const collectRuntimeInventory = async (getAdapter, capabilities, harnesses = WALKED_HARNESSES) => Promise.all(harnesses.map(async (harness) => {
|
|
5
5
|
const adapter = getAdapter(harness);
|
|
6
6
|
let detected = null;
|
|
7
7
|
try { detected = await adapter?.detect(); } catch { /* unavailable */ }
|
|
@@ -10,3 +10,40 @@ export const collectRuntimeInventory = async (getAdapter, capabilities) => Promi
|
|
|
10
10
|
return { harness, installed: Boolean(detected), version: detected?.version || null,
|
|
11
11
|
models: choices.models, efforts: choices.efforts };
|
|
12
12
|
}));
|
|
13
|
+
|
|
14
|
+
// The daemon's inventory, refreshed in full every five minutes. A harness it
|
|
15
|
+
// 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).
|
|
17
|
+
// Probes are synchronous: a binary that isn't there fails at once, but one
|
|
18
|
+
// that's there and hangs on --version blocks the daemon for its timeout. A
|
|
19
|
+
// re-probe slower than INVENTORY_SLOW_MS waits for the full refresh instead.
|
|
20
|
+
export const INVENTORY_FULL_MS = 300_000;
|
|
21
|
+
export const INVENTORY_MISSING_MS = 25_000;
|
|
22
|
+
export const INVENTORY_SLOW_MS = 1_000;
|
|
23
|
+
export const createInventoryCache = (collect, { now = Date.now } = {}) => {
|
|
24
|
+
let cached;
|
|
25
|
+
let fullAt = 0;
|
|
26
|
+
let missingAt = 0;
|
|
27
|
+
let slow = new Set();
|
|
28
|
+
return async () => {
|
|
29
|
+
const at = now();
|
|
30
|
+
if (!cached || at - fullAt > INVENTORY_FULL_MS) {
|
|
31
|
+
cached = await collect(WALKED_HARNESSES);
|
|
32
|
+
fullAt = at;
|
|
33
|
+
missingAt = at;
|
|
34
|
+
slow = new Set();
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
37
|
+
const missing = cached.filter((row) => !row.installed && !slow.has(row.harness)).map((row) => row.harness);
|
|
38
|
+
if (missing.length && at - missingAt > INVENTORY_MISSING_MS) {
|
|
39
|
+
missingAt = at;
|
|
40
|
+
for (const harness of missing) {
|
|
41
|
+
const started = now();
|
|
42
|
+
const [fresh] = await collect([harness]);
|
|
43
|
+
if (now() - started > INVENTORY_SLOW_MS) slow.add(harness);
|
|
44
|
+
if (fresh) cached = cached.map((row) => (row.harness === harness ? fresh : row));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return cached;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -299,6 +299,59 @@ const OPEN_NETWORK = String.raw`
|
|
|
299
299
|
(global-name "com.apple.securityd.xpc"))
|
|
300
300
|
`;
|
|
301
301
|
|
|
302
|
+
// The static paths the baseline lets a jail READ (file-read* or file-read-data),
|
|
303
|
+
// as `subpaths` (whole trees) and `literals` (one file or directory entry).
|
|
304
|
+
// Read from PLATFORM_BASELINE itself, so a caller keeping a secret out of the
|
|
305
|
+
// jail (a public seat's provider key file) checks what the profile actually
|
|
306
|
+
// admits rather than a copy that drifts. Metadata-only grants are not reads;
|
|
307
|
+
// regex grants cover /dev only and are left out. Dynamic per-turn paths
|
|
308
|
+
// (workspace, state, executables, read-only directories) are the caller's.
|
|
309
|
+
const READ_OPERATIONS = ['file-read*', 'file-read-data'];
|
|
310
|
+
export const parseSeatbeltReadRoots = (profile) => {
|
|
311
|
+
const subpaths = new Set();
|
|
312
|
+
const literals = new Set();
|
|
313
|
+
const text = profile.replace(/;[^\n]*/g, '');
|
|
314
|
+
let at = text.indexOf('(allow ');
|
|
315
|
+
while (at !== -1) {
|
|
316
|
+
// The rule's balanced s-expression; parentheses inside a string don't count.
|
|
317
|
+
let depth = 0;
|
|
318
|
+
let end = at;
|
|
319
|
+
let inString = false;
|
|
320
|
+
for (; end < text.length; end += 1) {
|
|
321
|
+
const ch = text[end];
|
|
322
|
+
if (inString) { if (ch === '\\') end += 1; else if (ch === '"') inString = false; continue; }
|
|
323
|
+
if (ch === '"') inString = true;
|
|
324
|
+
else if (ch === '(') depth += 1;
|
|
325
|
+
else if (ch === ')') { depth -= 1; if (depth === 0) break; }
|
|
326
|
+
}
|
|
327
|
+
const rule = text.slice(at, end + 1);
|
|
328
|
+
const operations = rule.slice('(allow '.length).split('(')[0].trim().split(/\s+/);
|
|
329
|
+
if (operations.some((op) => READ_OPERATIONS.includes(op))) {
|
|
330
|
+
for (const match of rule.matchAll(/\((subpath|literal) "([^"]+)"\)/g)) {
|
|
331
|
+
(match[1] === 'subpath' ? subpaths : literals).add(match[2]);
|
|
332
|
+
}
|
|
333
|
+
// Fail closed: a read filter this cannot turn into a root would be a
|
|
334
|
+
// readable path the key-file check never sees. Regex grants are known
|
|
335
|
+
// to cover /dev only, and are held to that.
|
|
336
|
+
for (const filter of rule.matchAll(/\((path|prefix|regex|home-subpath|home-literal|home-prefix)\s+(#?"[^"]*")/g)) {
|
|
337
|
+
if (filter[1] !== 'regex' || !/^#?"\^\/dev\//.test(filter[2])) {
|
|
338
|
+
throw new Error(`seatbeltSystemReadRoots: a read rule uses a filter it cannot check: (${filter[1]} ${filter[2]})`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
at = text.indexOf('(allow ', end + 1);
|
|
343
|
+
}
|
|
344
|
+
return Object.freeze({
|
|
345
|
+
subpaths: Object.freeze([...subpaths]),
|
|
346
|
+
literals: Object.freeze([...literals]),
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
let systemReadRoots = null;
|
|
350
|
+
export const seatbeltSystemReadRoots = () => {
|
|
351
|
+
if (!systemReadRoots) systemReadRoots = parseSeatbeltReadRoots(PLATFORM_BASELINE);
|
|
352
|
+
return systemReadRoots;
|
|
353
|
+
};
|
|
354
|
+
|
|
302
355
|
// Both network modes. On macOS, c-ares (node's dns.Resolver and dns.resolve*)
|
|
303
356
|
// reads the resolver list from configd's DNSConfiguration service while the
|
|
304
357
|
// Resolver is constructed. Denied, that lookup does not always fail: at
|