@commonlyai/cli 0.1.251 → 0.1.253
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/lib/adapters/claude.js +40 -5
- package/src/lib/windows-command.js +63 -25
package/package.json
CHANGED
|
@@ -262,7 +262,9 @@ const claudeAuthMetadata = async () => {
|
|
|
262
262
|
// it. Never bind or copy the operator's full file: it contains project paths,
|
|
263
263
|
// MCP configuration, usage history, and other host-private metadata. Public
|
|
264
264
|
// wrappers get a per-identity 0700 HOME carrying only this whitelist.
|
|
265
|
-
|
|
265
|
+
// A seat that reaches the model through the provider proxy (F151) needs no
|
|
266
|
+
// keychain, so its HOME gets no link to one.
|
|
267
|
+
const preparePublicClaudeState = async (ctx, { keychain = true } = {}) => {
|
|
266
268
|
const identity = ctx.agentName || ctx.cwd || 'anonymous';
|
|
267
269
|
const identityHash = createHash('sha256').update(identity).digest('hex').slice(0, 20);
|
|
268
270
|
const statePath = ctx._publicClaudeState
|
|
@@ -283,17 +285,20 @@ const preparePublicClaudeState = async (ctx) => {
|
|
|
283
285
|
// Keep HOME isolated while pointing that one standard location at the
|
|
284
286
|
// operator's encrypted keychain database. Seatbelt admits the keychain
|
|
285
287
|
// directory read-only; no bearer credential is copied into agent state.
|
|
288
|
+
// A key seat creates no link. One a keyless turn of the same agent left is
|
|
289
|
+
// kept for that turn: the key seat's profile admits no keychain file, so the
|
|
290
|
+
// link leads nowhere it can read.
|
|
286
291
|
const keychainLink = await statOrNull(stateKeychains);
|
|
287
292
|
if (keychainLink && !keychainLink.isSymbolicLink()) {
|
|
288
293
|
throw new Error(`refusing to replace non-symlink Claude keychain path: ${stateKeychains}`);
|
|
289
294
|
}
|
|
290
|
-
if (keychainLink) {
|
|
295
|
+
if (keychain && keychainLink) {
|
|
291
296
|
const target = await readlink(stateKeychains);
|
|
292
297
|
if (target !== operatorKeychains) {
|
|
293
298
|
await unlink(stateKeychains);
|
|
294
299
|
await symlink(operatorKeychains, stateKeychains);
|
|
295
300
|
}
|
|
296
|
-
} else {
|
|
301
|
+
} else if (keychain) {
|
|
297
302
|
await symlink(operatorKeychains, stateKeychains);
|
|
298
303
|
}
|
|
299
304
|
|
|
@@ -1201,6 +1206,14 @@ const policyOnlyHost = (ctx) => ctx.hostUnconfined === true
|
|
|
1201
1206
|
&& (ctx._platform || process.platform) === 'win32'
|
|
1202
1207
|
&& isConfinedTrust(ctx.environment?.sandbox?.trust);
|
|
1203
1208
|
|
|
1209
|
+
// The loopback port a provider proxy listens on, for the Seatbelt rule that
|
|
1210
|
+
// admits it. Taken from its base URL when the proxy does not report one.
|
|
1211
|
+
const proxyPort = (proxy) => {
|
|
1212
|
+
if (!proxy) return null;
|
|
1213
|
+
const port = Number(proxy.port ?? new URL(proxy.baseURL).port);
|
|
1214
|
+
return Number.isInteger(port) && port > 0 ? port : null;
|
|
1215
|
+
};
|
|
1216
|
+
|
|
1204
1217
|
const prepareArgv = async (innerArgv, ctx) => {
|
|
1205
1218
|
const env = ctx.environment;
|
|
1206
1219
|
const claudeEnv = withClaudePath(ctx.claudeEnv);
|
|
@@ -1332,7 +1345,11 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1332
1345
|
...commitHookExecutables,
|
|
1333
1346
|
...originalHookExecutables,
|
|
1334
1347
|
],
|
|
1335
|
-
|
|
1348
|
+
// F151: a key seat reaches the model only through the host's loopback
|
|
1349
|
+
// proxy, so its profile admits that port and no keychain; a login seat
|
|
1350
|
+
// keeps the keychain rules and needs no port.
|
|
1351
|
+
allowClaudeRuntimeAccess: !ctx.providerProxyPort,
|
|
1352
|
+
loopbackNetworkPorts: ctx.providerProxyPort ? [ctx.providerProxyPort] : [],
|
|
1336
1353
|
readOnlyDirectories: [
|
|
1337
1354
|
...(ctx.mcpReadDirectories || []),
|
|
1338
1355
|
...(ctx.workspaceGit?.readDirectories || []),
|
|
@@ -1590,7 +1607,23 @@ export default {
|
|
|
1590
1607
|
// bwrap seat needs a host-prepared build exactly as a Seatbelt one does
|
|
1591
1608
|
// (#2247).
|
|
1592
1609
|
if (publicNativeSandbox) {
|
|
1593
|
-
|
|
1610
|
+
// F151: Seatbelt strips the environment to the safe list, so a seat
|
|
1611
|
+
// configured with an API key used to start with neither key nor login
|
|
1612
|
+
// ("Not logged in"). The key stays on the host behind a per-turn
|
|
1613
|
+
// loopback proxy, as on bwrap; the jail gets the proxy's address and
|
|
1614
|
+
// token, and no keychain. Without a key, the keychain login as before.
|
|
1615
|
+
const source = ctx.env || process.env;
|
|
1616
|
+
if (source.ANTHROPIC_API_KEY) {
|
|
1617
|
+
publicClaudeState = await preparePublicClaudeState(ctx, { keychain: false });
|
|
1618
|
+
providerProxy = await (ctx._startProviderProxy || startProviderProxy)({
|
|
1619
|
+
provider: { baseURL: source.ANTHROPIC_BASE_URL || 'https://api.anthropic.com' },
|
|
1620
|
+
keyMaterial: source.ANTHROPIC_API_KEY,
|
|
1621
|
+
wire: 'anthropic-messages',
|
|
1622
|
+
adapterLabel: 'Claude',
|
|
1623
|
+
});
|
|
1624
|
+
} else {
|
|
1625
|
+
publicClaudeState = await preparePublicClaudeState(ctx);
|
|
1626
|
+
}
|
|
1594
1627
|
} else if (workspaceBwrapSandbox) {
|
|
1595
1628
|
// Checked before the state is prepared, so a host that cannot run the
|
|
1596
1629
|
// jail never gets a copy of the login.
|
|
@@ -1684,6 +1717,7 @@ export default {
|
|
|
1684
1717
|
mcpReadDirectories: mcpConfig?.mcpReadDirectories || [],
|
|
1685
1718
|
publicClaudeState,
|
|
1686
1719
|
publicSkillArgs,
|
|
1720
|
+
providerProxyPort: proxyPort(providerProxy),
|
|
1687
1721
|
claudeEnv,
|
|
1688
1722
|
};
|
|
1689
1723
|
const { cmd, args, env, childHome } = await prepareArgv(baseArgs, spawnCtx);
|
|
@@ -1751,6 +1785,7 @@ export default {
|
|
|
1751
1785
|
mcpReadDirectories: mcpConfig?.mcpReadDirectories || [],
|
|
1752
1786
|
publicClaudeState,
|
|
1753
1787
|
publicSkillArgs,
|
|
1788
|
+
providerProxyPort: proxyPort(providerProxy),
|
|
1754
1789
|
claudeEnv: withProvider(buildClaudeEnv(
|
|
1755
1790
|
ctx.env,
|
|
1756
1791
|
publicClaudeState,
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// runs as itself; anything else is refused with a reason, never handed to a
|
|
17
17
|
// shell. On every other platform this module is a passthrough.
|
|
18
18
|
|
|
19
|
+
import { spawnSync as realSpawnSync } from 'child_process';
|
|
19
20
|
import { existsSync as realExistsSync, readFileSync as realReadFileSync } from 'fs';
|
|
20
21
|
import { win32 } from 'path';
|
|
21
22
|
|
|
@@ -113,44 +114,79 @@ const programIsNode = (token, shimDir, text) => {
|
|
|
113
114
|
return false;
|
|
114
115
|
};
|
|
115
116
|
|
|
116
|
-
const envValue = (env, name) => {
|
|
117
|
-
const key = Object.keys(env || {}).find((k) => k.toLowerCase() === name.toLowerCase());
|
|
118
|
-
return key ? env[key] : undefined;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
117
|
// npm's own `npm.cmd` / `npx.cmd` (npm/bin/*.cmd, which the Node installer
|
|
122
118
|
// copies next to node.exe) is hand-written, not a cmd-shim:
|
|
123
119
|
//
|
|
124
120
|
// SET "NODE_EXE=%~dp0\node.exe" (else `node`)
|
|
121
|
+
// SET "NPM_PREFIX_JS=%~dp0\node_modules\npm\bin\npm-prefix.js"
|
|
125
122
|
// SET "NPX_CLI_JS=%~dp0\node_modules\npm\bin\npx-cli.js"
|
|
126
123
|
// FOR /F … ('CALL "%NODE_EXE%" "%NPM_PREFIX_JS%"') … SET "NPM_PREFIX_NPX_CLI_JS=%%F\node_modules\npm\bin\npx-cli.js"
|
|
127
124
|
// IF EXIST "%NPM_PREFIX_NPX_CLI_JS%" ( SET "NPX_CLI_JS=%NPM_PREFIX_NPX_CLI_JS%" )
|
|
128
125
|
// "%NODE_EXE%" "%NPX_CLI_JS%" %*
|
|
129
126
|
//
|
|
130
|
-
// The FOR line
|
|
131
|
-
// person upgraded with `npm i -g npm` wins over the
|
|
132
|
-
// is %APPDATA%\npm unless an npmrc
|
|
133
|
-
//
|
|
127
|
+
// The FOR line asks npm for its global prefix (older npm: `npm-cli.js prefix
|
|
128
|
+
// -g`), so an npm the person upgraded with `npm i -g npm` wins over the
|
|
129
|
+
// bundled one. That prefix is %APPDATA%\npm unless an npmrc or
|
|
130
|
+
// `npm_config_prefix` says otherwise, and npm's config loader is the only
|
|
131
|
+
// thing that knows which. So the same script is asked the same way, as
|
|
132
|
+
// `node.exe <script>` with no shell, in the child's env, and in its folder
|
|
133
|
+
// when the caller passes `cwd` (a project .npmrc counts there). An answer that names no npm, or no answer at all,
|
|
134
|
+
// leaves the bundled npm, as npm.cmd does.
|
|
134
135
|
const NPM_LAUNCH = /^"%NODE_EXE%"\s+"%(NP[MX]_CLI_JS)%"\s+%\*$/i;
|
|
136
|
+
const NPM_PREFIX_FOR = /^FOR\s+\/F\s+"delims="\s+%%F\s+IN\s+\('CALL\s+"%NODE_EXE%"\s+"%([A-Z_]+)%"((?:\s+[A-Za-z0-9-]+)*)'\)\s+DO\s+\($/i;
|
|
137
|
+
const PREFIX_TIMEOUT_MS = 10000;
|
|
138
|
+
|
|
139
|
+
const declaredBesideShim = (lines, variable, shimDir) => {
|
|
140
|
+
const declared = lines
|
|
141
|
+
.map((line) => line.match(new RegExp(`^SET\\s+"${variable}=([^"]*)"$`, 'i')))
|
|
142
|
+
.find((match) => match && DP0_PREFIX.test(match[1]));
|
|
143
|
+
return declared ? fromShimDir(declared[1], shimDir) : null;
|
|
144
|
+
};
|
|
135
145
|
|
|
136
|
-
|
|
146
|
+
// The npm script npm.cmd would switch to after asking for the prefix, or
|
|
147
|
+
// null to keep the bundled one.
|
|
148
|
+
const npmFromPrefix = (lines, variable, shimDir, node, deps) => {
|
|
149
|
+
const forLine = lines.map((line) => line.match(NPM_PREFIX_FOR)).find(Boolean);
|
|
150
|
+
if (!forLine) return null;
|
|
151
|
+
const script = declaredBesideShim(lines, forLine[1], shimDir);
|
|
152
|
+
if (!script || !deps.existsSync(script)) return null;
|
|
153
|
+
const target = lines
|
|
154
|
+
.map((line) => line.match(new RegExp(`^SET\\s+"NPM_PREFIX_${variable}=%%F\\\\([^"%]+)"$`, 'i')))
|
|
155
|
+
.find(Boolean);
|
|
156
|
+
if (!target) return null;
|
|
157
|
+
let result;
|
|
158
|
+
try {
|
|
159
|
+
result = deps.spawnSync(node, [script, ...forLine[2].trim().split(/\s+/).filter(Boolean)], {
|
|
160
|
+
env: deps.env,
|
|
161
|
+
cwd: deps.cwd,
|
|
162
|
+
encoding: 'utf8',
|
|
163
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
164
|
+
timeout: PREFIX_TIMEOUT_MS,
|
|
165
|
+
windowsHide: true,
|
|
166
|
+
});
|
|
167
|
+
} catch {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
if (!result || result.status !== 0) return null;
|
|
171
|
+
// FOR /F runs its body once per line, so the last line is the one that sticks.
|
|
172
|
+
const prefix = String(result.stdout || '').split(/\r?\n/).map((line) => line.trim()).filter(Boolean).pop();
|
|
173
|
+
if (!prefix || !win32.isAbsolute(prefix)) return null;
|
|
174
|
+
const upgraded = win32.join(prefix, target[1]);
|
|
175
|
+
return deps.existsSync(upgraded) ? upgraded : null;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const parseNpmLauncher = (lines, shimPath, deps) => {
|
|
137
179
|
const launch = lines.map((line) => line.match(NPM_LAUNCH)).find(Boolean);
|
|
138
180
|
if (!launch) return null;
|
|
139
181
|
const variable = launch[1];
|
|
140
182
|
const shimDir = win32.dirname(shimPath);
|
|
141
|
-
const
|
|
142
|
-
.map((line) => line.match(new RegExp(`^SET\\s+"${variable}=([^"]*)"$`, 'i')))
|
|
143
|
-
.find((match) => match && DP0_PREFIX.test(match[1]));
|
|
144
|
-
const bundled = declared ? fromShimDir(declared[1], shimDir) : null;
|
|
183
|
+
const bundled = declaredBesideShim(lines, variable, shimDir);
|
|
145
184
|
if (!bundled) return { command: null, reason: `${shimPath} does not name npm's script beside itself` };
|
|
146
|
-
const appData = envValue(env, 'APPDATA');
|
|
147
|
-
const upgraded = appData
|
|
148
|
-
? win32.join(appData, 'npm', 'node_modules', 'npm', 'bin', win32.basename(bundled))
|
|
149
|
-
: null;
|
|
150
|
-
const script = upgraded && existsSync(upgraded) ? upgraded : bundled;
|
|
151
|
-
if (!existsSync(script)) return { command: null, reason: `${shimPath} points at ${script}, which does not exist` };
|
|
152
185
|
const nodeBeside = win32.join(shimDir, 'node.exe');
|
|
153
|
-
|
|
186
|
+
const node = deps.existsSync(nodeBeside) ? nodeBeside : deps.execPath;
|
|
187
|
+
const script = npmFromPrefix(lines, variable, shimDir, node, deps) || bundled;
|
|
188
|
+
if (!deps.existsSync(script)) return { command: null, reason: `${shimPath} points at ${script}, which does not exist` };
|
|
189
|
+
return { command: node, args: [script] };
|
|
154
190
|
};
|
|
155
191
|
|
|
156
192
|
/**
|
|
@@ -166,14 +202,14 @@ const parseNpmLauncher = (lines, shimPath, { existsSync, execPath, env }) => {
|
|
|
166
202
|
* @returns {{ command: string, args: string[] } | { command: null, reason: string }}
|
|
167
203
|
*/
|
|
168
204
|
export const parseCmdShim = (text, shimPath, {
|
|
169
|
-
existsSync = realExistsSync, execPath = process.execPath, env = {},
|
|
205
|
+
existsSync = realExistsSync, execPath = process.execPath, env = {}, spawnSync = realSpawnSync, cwd,
|
|
170
206
|
} = {}) => {
|
|
171
207
|
const shimDir = win32.dirname(shimPath);
|
|
172
208
|
const lines = String(text)
|
|
173
209
|
.split(/\r?\n/)
|
|
174
210
|
.map((line) => line.trim().replace(/^@/, ''))
|
|
175
211
|
.filter(Boolean);
|
|
176
|
-
const npmLauncher = parseNpmLauncher(lines, shimPath, { existsSync, execPath, env });
|
|
212
|
+
const npmLauncher = parseNpmLauncher(lines, shimPath, { existsSync, execPath, env, spawnSync, cwd });
|
|
177
213
|
if (npmLauncher) return npmLauncher;
|
|
178
214
|
// The launch line is the one that forwards the caller's arguments. The
|
|
179
215
|
// legacy shape has two (node beside the shim, else node on PATH) that name
|
|
@@ -256,7 +292,8 @@ const classify = (file, deps) => {
|
|
|
256
292
|
* it cannot be. On anything but win32, `{ command: name, args: [] }`.
|
|
257
293
|
* On win32, `source` is the file found on PATH (the shim, or the .exe).
|
|
258
294
|
* `cwd` is the child's working directory; relative PATH entries are read
|
|
259
|
-
* against it (unset: this process's, as before)
|
|
295
|
+
* against it (unset: this process's, as before), and npm's own launcher asks
|
|
296
|
+
* npm for its prefix there.
|
|
260
297
|
*
|
|
261
298
|
* @returns {{ command: string, args: string[], source?: string }
|
|
262
299
|
* | { command: null, reason: string, source?: string }}
|
|
@@ -267,10 +304,11 @@ export const resolveWindowsCommandWithReason = (name, {
|
|
|
267
304
|
existsSync = realExistsSync,
|
|
268
305
|
readFileSync = realReadFileSync,
|
|
269
306
|
execPath = process.execPath,
|
|
307
|
+
spawnSync = realSpawnSync,
|
|
270
308
|
cwd,
|
|
271
309
|
} = {}) => {
|
|
272
310
|
if (platform !== 'win32') return { command: name, args: [] };
|
|
273
|
-
const deps = { existsSync, readFileSync, execPath, env };
|
|
311
|
+
const deps = { existsSync, readFileSync, execPath, env, spawnSync, cwd };
|
|
274
312
|
const exts = pathExtensions(env);
|
|
275
313
|
const hasKnownExt = [...BINARY_EXTS, ...SHIM_EXTS].includes(extOf(name));
|
|
276
314
|
// PATHEXT is upper case by convention and NTFS ignores case, so the
|