@commonlyai/cli 0.1.405 → 0.1.406
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/agent.js +1 -0
- package/src/lib/adapters/claude.js +35 -0
- package/src/lib/run-preflight.js +46 -20
- package/src/lib/sandbox/seatbelt.js +34 -2
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -6188,6 +6188,7 @@ Docs:
|
|
|
6188
6188
|
adapterName: record.adapter,
|
|
6189
6189
|
adapter: getAdapter(record.adapter),
|
|
6190
6190
|
environment: record.environment,
|
|
6191
|
+
agentName: record.agentName,
|
|
6191
6192
|
checkInstalled: !bootstrapped,
|
|
6192
6193
|
});
|
|
6193
6194
|
const harnessOutcome = preflightOutcome(harnessProblems, { firstRun: bootstrapped });
|
|
@@ -1512,6 +1512,41 @@ const resolveClaudeInstall = (env) => {
|
|
|
1512
1512
|
}
|
|
1513
1513
|
};
|
|
1514
1514
|
|
|
1515
|
+
/**
|
|
1516
|
+
* F647: how the sign-in probe (`claude auth status`) runs for a seat, so it
|
|
1517
|
+
* reads the login the way the seat's turn does. A seat confined by Seatbelt
|
|
1518
|
+
* (public or workspace trust on macOS) gets its turn's state folder as HOME,
|
|
1519
|
+
* its turn's stripped environment and its turn's Seatbelt profile; a login the
|
|
1520
|
+
* jail can't read then reports signed out at setup, not at the first mention.
|
|
1521
|
+
* null for every other seat, which keeps the plain probe. `_prepareState` is a
|
|
1522
|
+
* test seam for the state folder.
|
|
1523
|
+
*/
|
|
1524
|
+
export const claudeLoginProbeLaunch = async (args, {
|
|
1525
|
+
environment = null,
|
|
1526
|
+
agentName = null,
|
|
1527
|
+
env = process.env,
|
|
1528
|
+
platform = process.platform,
|
|
1529
|
+
_prepareState = preparePublicClaudeState,
|
|
1530
|
+
} = {}) => {
|
|
1531
|
+
// Normalized as `spawn` does: a saved `internal` seat's turn runs as `public`,
|
|
1532
|
+
// so its probe must too, or it reports signed in without the jail's view.
|
|
1533
|
+
const sandbox = normalizeSandboxTrust(environment?.sandbox);
|
|
1534
|
+
if (platform !== 'darwin' || !isConfinedTrust(sandbox?.trust)
|
|
1535
|
+
|| !PUBLIC_SANDBOX_MODES.has(resolvePublicSandboxMode(sandbox, platform))) return null;
|
|
1536
|
+
// The turn's own state folder, keyed on the same name, with its keychain link.
|
|
1537
|
+
const state = await _prepareState({ agentName });
|
|
1538
|
+
const claudeEnv = withClaudePath(buildClaudeEnv(env, state, {}, null, true, platform));
|
|
1539
|
+
const claudeBin = resolveClaudePath(claudeEnv);
|
|
1540
|
+
const wrapped = wrapArgvWithSeatbelt([claudeBin, ...args], {
|
|
1541
|
+
workspacePath: state.tmpPath,
|
|
1542
|
+
workspaceAccess: 'read',
|
|
1543
|
+
executablePath: claudeBin,
|
|
1544
|
+
statePath: state.statePath,
|
|
1545
|
+
allowClaudeRuntimeAccess: true,
|
|
1546
|
+
});
|
|
1547
|
+
return { command: wrapped[0], args: wrapped.slice(1), env: claudeEnv, cwd: state.tmpPath };
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1515
1550
|
// A jail that cannot carry claude would fail inside at every spawn.
|
|
1516
1551
|
const claudeInstallRefusal = (claudeBin) => new Error(
|
|
1517
1552
|
'Claude agents on Linux need Claude Code on PATH, so the sandbox can carry its install; '
|
package/src/lib/run-preflight.js
CHANGED
|
@@ -15,7 +15,7 @@ import { readFileSync } from 'fs';
|
|
|
15
15
|
import { checkNode, FAIL } from './doctor.js';
|
|
16
16
|
import { loginState } from './adapter-login.js';
|
|
17
17
|
import { missingHarnessHint } from './missing-harness.js';
|
|
18
|
-
import { withClaudePath } from './adapters/claude.js';
|
|
18
|
+
import { claudeLoginProbeLaunch, withClaudePath } from './adapters/claude.js';
|
|
19
19
|
import { resolveWindowsCommandWithReason } from './windows-command.js';
|
|
20
20
|
|
|
21
21
|
// The reason codes the instance accepts (POST /api/agents/runtime/listen-blocked).
|
|
@@ -66,33 +66,57 @@ export const nodeFinding = ({ nodeVersion = process.versions.node, enginesRange
|
|
|
66
66
|
* on Windows a name cmd can't find exits 1, which is the signed-out code, and
|
|
67
67
|
* would stop a run that is signed in. null when the command can't be resolved
|
|
68
68
|
* or the probe can't run or times out (no verdict).
|
|
69
|
+
*
|
|
70
|
+
* F647: given the seat's `environment` and name, a Claude seat confined by
|
|
71
|
+
* Seatbelt is probed inside its own sandbox (the turn's profile, HOME and
|
|
72
|
+
* environment), so a login the jail can't read is not reported signed in. A
|
|
73
|
+
* sandboxed probe that can't be prepared is no verdict, as any other.
|
|
69
74
|
*/
|
|
70
|
-
|
|
75
|
+
const plainProbeLaunch = (name, args, { env, platform, resolve }) => {
|
|
76
|
+
const childEnv = name === 'claude' ? withClaudePath(env) : env;
|
|
77
|
+
const located = resolve(name, { env: childEnv, platform });
|
|
78
|
+
if (!located?.command) return null;
|
|
79
|
+
return { command: located.command, args: [...(located.args || []), ...args], env: childEnv };
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const runHarnessLoginStatus = async (name, args, {
|
|
71
83
|
env = process.env,
|
|
72
84
|
platform = process.platform,
|
|
73
85
|
resolve = resolveWindowsCommandWithReason,
|
|
74
86
|
spawnFn = spawn,
|
|
75
87
|
timeoutMs = 10_000,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
let child;
|
|
88
|
+
environment = null,
|
|
89
|
+
agentName = null,
|
|
90
|
+
_prepareClaudeState,
|
|
91
|
+
} = {}) => {
|
|
92
|
+
let launch = null;
|
|
84
93
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
if (name === 'claude' && environment) {
|
|
95
|
+
launch = await claudeLoginProbeLaunch(args, {
|
|
96
|
+
environment, agentName, env, platform,
|
|
97
|
+
...(_prepareClaudeState ? { _prepareState: _prepareClaudeState } : {}),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
88
100
|
} catch {
|
|
89
|
-
|
|
90
|
-
return;
|
|
101
|
+
return null;
|
|
91
102
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
launch = launch || plainProbeLaunch(name, args, { env, platform, resolve });
|
|
104
|
+
if (!launch) return null;
|
|
105
|
+
return new Promise((done) => {
|
|
106
|
+
let child;
|
|
107
|
+
try {
|
|
108
|
+
child = spawnFn(launch.command, launch.args, {
|
|
109
|
+
stdio: 'ignore', windowsHide: true, env: launch.env, shell: false, ...(launch.cwd ? { cwd: launch.cwd } : {}),
|
|
110
|
+
});
|
|
111
|
+
} catch {
|
|
112
|
+
done(null);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const timer = setTimeout(() => { child.kill(); done(null); }, timeoutMs);
|
|
116
|
+
child.on('error', () => { clearTimeout(timer); done(null); });
|
|
117
|
+
child.on('exit', (code) => { clearTimeout(timer); done(typeof code === 'number' ? code : null); });
|
|
118
|
+
});
|
|
119
|
+
};
|
|
96
120
|
|
|
97
121
|
/**
|
|
98
122
|
* The harness findings for one adapter: not installed, or installed and not
|
|
@@ -105,9 +129,11 @@ export const harnessFindings = async ({
|
|
|
105
129
|
adapterName,
|
|
106
130
|
adapter,
|
|
107
131
|
environment = null,
|
|
132
|
+
// The seat's name, which keys its sandbox state folder (F647).
|
|
133
|
+
agentName = null,
|
|
108
134
|
checkInstalled = true,
|
|
109
135
|
env = process.env,
|
|
110
|
-
runStatus = (name, args) => runHarnessLoginStatus(name, args, { env }),
|
|
136
|
+
runStatus = (name, args) => runHarnessLoginStatus(name, args, { env, environment, agentName }),
|
|
111
137
|
}) => {
|
|
112
138
|
if (!adapter || !adapterName) return [];
|
|
113
139
|
if (checkInstalled) {
|
|
@@ -431,6 +431,30 @@ const isSymlink = (path) => {
|
|
|
431
431
|
}
|
|
432
432
|
};
|
|
433
433
|
|
|
434
|
+
// F647: a confined Claude seat's HOME is its own state folder, whose
|
|
435
|
+
// Library/Keychains is a link to the person's real one (preparePublicClaudeState
|
|
436
|
+
// in adapters/claude.js). Seatbelt checks the path a link resolves to, so the
|
|
437
|
+
// login keychain is admitted at that resolved path too, resolved once here. It
|
|
438
|
+
// is admitted only when it is the login keychain directly inside the person's
|
|
439
|
+
// own Library/Keychains: a link the seat's folder holds to anywhere else adds
|
|
440
|
+
// nothing, and never a folder.
|
|
441
|
+
const LOGIN_KEYCHAIN = 'login.keychain-db';
|
|
442
|
+
const linkedLoginKeychain = (seatHome, personHome) => {
|
|
443
|
+
const seatKeychains = join(seatHome, 'Library', 'Keychains');
|
|
444
|
+
const seatLogin = join(seatKeychains, LOGIN_KEYCHAIN);
|
|
445
|
+
if (!isSymlink(seatKeychains) && !isSymlink(seatLogin)) return null;
|
|
446
|
+
let resolved;
|
|
447
|
+
try {
|
|
448
|
+
resolved = realpathSync(seatLogin);
|
|
449
|
+
} catch {
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
const personKeychains = join(personHome, 'Library', 'Keychains');
|
|
453
|
+
const allowedFolders = new Set([personKeychains, realpathOrSelf(personKeychains)]);
|
|
454
|
+
if (basename(resolved) !== LOGIN_KEYCHAIN || !allowedFolders.has(dirname(resolved))) return null;
|
|
455
|
+
return resolved;
|
|
456
|
+
};
|
|
457
|
+
|
|
434
458
|
// The two xcode-select links. The xcrun shim reads developer_dir; both name
|
|
435
459
|
// the same folder on a normal install, and a turn admits each target.
|
|
436
460
|
const XCODE_SELECT_LINKS = Object.freeze(['/private/var/select/developer_dir', '/private/var/db/xcode_select_link']);
|
|
@@ -664,6 +688,9 @@ export const buildSeatbeltProfile = ({
|
|
|
664
688
|
hostReadDirectories = [],
|
|
665
689
|
// The home folder those rules are judged against. Tests pass a temp one.
|
|
666
690
|
hostReadHome = homedir(),
|
|
691
|
+
// The person whose login keychain a Claude seat reads (F647). Tests pass a
|
|
692
|
+
// temp one.
|
|
693
|
+
keychainHome = homedir(),
|
|
667
694
|
loopbackNetworkPorts = [],
|
|
668
695
|
allowClaudeRuntimeAccess = false,
|
|
669
696
|
// 'open' (the default) or 'loopback': only the listed loopback ports.
|
|
@@ -826,11 +853,16 @@ export const buildSeatbeltProfile = ({
|
|
|
826
853
|
// temp files on the machine, so it is not admitted.
|
|
827
854
|
// Claude's security helper needs the encrypted login-keychain database and
|
|
828
855
|
// this non-secret locale file: that one file, not the Keychains folder.
|
|
829
|
-
const loginKeychain = join(
|
|
830
|
-
const textEncoding = join(
|
|
856
|
+
const loginKeychain = join(keychainHome, 'Library', 'Keychains', LOGIN_KEYCHAIN);
|
|
857
|
+
const textEncoding = join(keychainHome, '.CFUserTextEncoding');
|
|
858
|
+
const linked = linkedLoginKeychain(resolvedState, keychainHome);
|
|
831
859
|
return [
|
|
832
860
|
`(allow file-read* file-test-existence ${literal(loginKeychain)} ${literal(textEncoding)})`,
|
|
833
861
|
`(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(loginKeychain)}"))`,
|
|
862
|
+
...(linked && linked !== loginKeychain ? [
|
|
863
|
+
`(allow file-read* file-test-existence ${literal(linked)})`,
|
|
864
|
+
`(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(linked)}"))`,
|
|
865
|
+
] : []),
|
|
834
866
|
];
|
|
835
867
|
})() : [];
|
|
836
868
|
|