@commonlyai/cli 0.1.400 → 0.1.401

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.400",
3
+ "version": "0.1.401",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -2358,6 +2358,13 @@ export const performRun = ({
2358
2358
  .then(() => revokeOrphansImpl({ client, log }))
2359
2359
  .catch((err) => log(`spawn credential boot sweep failed (${err?.message ?? err})`));
2360
2360
 
2361
+ // F661: Commonly keeps no copy of a person's Claude login. A CLI before F661
2362
+ // left one in each Linux seat's state folder; this removes those, at their
2363
+ // exact paths only, once per process. Best-effort, like the sweep above.
2364
+ void Promise.resolve()
2365
+ .then(() => adapter?.removeLegacyLoginCopies?.())
2366
+ .catch((err) => log(`legacy login copy cleanup failed (${err?.message ?? err})`));
2367
+
2361
2368
  // The bounds the server will clamp to. READ ONLY IF THERE IS AN ASK TO CLAMP:
2362
2369
  // with no `COMMONLY_SPAWN_TTL_SECONDS` the cli sends no `ttlSeconds` at all
2363
2370
  // and the server's default is what it is, so a per-run read would be a request
@@ -347,8 +347,8 @@ const STAGED_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{1
347
347
  const isStagedCopyOf = (name) => (entry) => entry.startsWith(`.${name}.`) && entry.endsWith('.tmp')
348
348
  && STAGED_UUID.test(entry.slice(name.length + 2, -4));
349
349
 
350
- // The login copy and any staged copy of it a failed or killed turn left: both
351
- // hold the access token.
350
+ // The login copy a CLI before F661 wrote, and any staged copy of it a failed or
351
+ // killed turn left: both hold an access token, and no current turn writes either.
352
352
  const removeLoginCopy = async (configDir) => {
353
353
  await removePrivateFile(configDir, '.credentials.json');
354
354
  await removePrivateFile(configDir, '.credentials.json', { match: isStagedCopyOf('.credentials.json') });
@@ -472,120 +472,114 @@ export const loginRouteBaseUrl = (source = {}) => {
472
472
  }
473
473
  };
474
474
 
475
- // Two turns of one public agent share its folder (a daemon and a separate
476
- // `agent run`, or two events at once). Each registers itself in a sibling of
477
- // that folder, outside the jail's writable bind so a turn cannot forge one,
478
- // and the login copy is removed only by the last live turn to finish.
479
- const registerLoginTurn = async (statePath) => {
480
- const dir = `${statePath}.login-turns`;
481
- await mkdir(dir, { recursive: true, mode: 0o700 });
482
- const marker = join(dir, `${process.pid}-${randomUUID()}`);
483
- await writeFile(marker, '', { mode: 0o600, flag: 'wx' });
484
- return marker;
485
- };
486
- const pidAlive = (pid) => {
475
+ // F661: Commonly keeps no copy of a Claude login. Anthropic's terms let a
476
+ // person sign the unmodified `claude` binary in with their own subscription,
477
+ // and forbid a developer to collect, store or intermediate Claude.ai
478
+ // credentials, so nothing here reads ~/.claude/.credentials.json or writes a
479
+ // login file. Up to F661 a bwrap seat got an access-only copy of that file in
480
+ // its state folder (<state>/.claude/.credentials.json, staged beside it as
481
+ // .credentials.json.<uuid>.tmp) and a public seat registered its turns in
482
+ // <state>.login-turns so the last one could delete it. Those exact paths are
483
+ // what a previous CLI version may have left, and only they are removed.
484
+ const LEGACY_LOGIN_TURNS = '.login-turns';
485
+ // The marker name registerLoginTurn used: `<pid>-<uuid>`.
486
+ const LEGACY_TURN_MARKER = /^\d+-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
487
+
488
+ // Only Linux seats ever had a copy (bwrap has no keychain). On macOS a Seatbelt
489
+ // seat can write its whole state folder, so a confined child could swap
490
+ // `<seat>/.claude` for a link to the person's own ~/.claude between the host's
491
+ // check and its removal; nothing there is ours to delete, so nothing is.
492
+ // On Linux the host removes these paths outside any jail, and while a jail of
493
+ // the seat is live its .claude is a mount point the child cannot rename or
494
+ // replace (EBUSY), and `<seat>.login-turns` sits outside its writable bind.
495
+ const legacyCopiesPossible = (platform = process.platform) => platform === 'linux';
496
+
497
+ // The boot sweep and a turn's preparation can both clear the same seat's
498
+ // markers; when the other one removed the folder between this one's check and
499
+ // its read, the folder is already cleared, so that read is an empty list.
500
+ // Any other read failure still rejects.
501
+ export const readdirIfPresent = async (path, read = readdir) => {
487
502
  try {
488
- process.kill(pid, 0);
489
- return true;
503
+ return await read(path);
490
504
  } catch (err) {
491
- return err?.code === 'EPERM';
492
- }
493
- };
494
- const releaseLoginTurn = async (marker, loginPath) => {
495
- await rm(marker, { force: true });
496
- const dir = dirname(marker);
497
- let others = [];
498
- try {
499
- others = await readdir(dir);
500
- } catch { /* gone: nobody else is registered */ }
501
- let live = 0;
502
- for (const name of others) {
503
- const pid = Number(name.split('-')[0]);
504
- if (Number.isInteger(pid) && pid > 0 && pidAlive(pid)) live += 1;
505
- else await rm(join(dir, name), { force: true });
506
- }
507
- if (!live) {
508
- await removeLoginCopy(dirname(loginPath));
509
- // Only an empty folder goes: a turn registering at this moment keeps it.
510
- try { await rmdir(dir); } catch { /* not empty, or already gone */ }
505
+ if (err?.code === 'ENOENT') return [];
506
+ throw err;
511
507
  }
512
508
  };
513
509
 
514
- // A seat on Linux runs under bwrap, which has no keychain. Claude Code on
515
- // Linux keeps its login in <config dir>/.credentials.json, so the seat's own
516
- // state dir gets a copy of the person's, taken fresh each spawn. Only the copy
517
- // is inside the jail. Nothing is written back: the jail can write its copy, and
518
- // a write-back would let it replace the person's login with one of its
519
- // choosing. Since F96 the copy is access-only for every seat, workspace ones
520
- // included: a jail that refreshed would spend the host's refresh token and
521
- // leave the person signed out (CI, 11-04: Claude Code rewrites the jail's copy
522
- // when its session check fails). A missing login removes the copy, so a person
523
- // who logged out is not still signed in here.
524
- const claudeLoginSource = (env) => join(
525
- env?.CLAUDE_CONFIG_DIR || process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude'),
526
- '.credentials.json',
527
- );
528
-
529
- // Opened once, without following a symlink, and checked on the open handle,
530
- // so the file read is the file checked (a FIFO cannot hold the open either).
531
- // A public seat's copy (F96) holds the access token alone. Claude Code
532
- // rotates the refresh token when it refreshes, so a jail holding one could
533
- // spend it and leave the host signed out; without one it cannot refresh at
534
- // all, so a login that would expire mid-turn is refused here instead.
535
- // What a public seat's access-only login keeps: the token and the account
536
- // metadata Claude Code reads beside it.
537
- const ACCESS_ONLY_LOGIN_FIELDS = ['accessToken', 'expiresAt', 'scopes', 'subscriptionType', 'rateLimitTier'];
538
-
539
- const accessOnlyLogin = (text, { source, mustOutlastMs, apiKeyHint = true }) => {
540
- let login;
541
- try {
542
- login = JSON.parse(text);
543
- } catch {
544
- throw new Error(`refusing a Claude login that is not JSON: ${source}`);
545
- }
546
- const oauth = login?.claudeAiOauth;
547
- if (!oauth || typeof oauth.accessToken !== 'string' || !oauth.accessToken) {
548
- throw new Error(`refusing a Claude login with no access token: ${source}`);
510
+ const removeLegacyLoginTurns = async (statePath) => {
511
+ const turns = `${statePath}${LEGACY_LOGIN_TURNS}`;
512
+ const stat = await statOrNull(turns);
513
+ if (!stat) return;
514
+ // A link at the name is removed as a link, never followed.
515
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
516
+ await rm(turns, { force: true });
517
+ return;
549
518
  }
550
- if (typeof oauth.expiresAt === 'number' && oauth.expiresAt - Date.now() < mustOutlastMs) {
551
- const minutes = Math.max(0, Math.floor((oauth.expiresAt - Date.now()) / 60000));
552
- throw new Error(`the Claude login on this machine expires in ${minutes} min, before this turn could end. `
553
- + 'Sign in again in your own terminal on this machine, outside the agent: run `claude`, then /login'
554
- + `${apiKeyHint ? '. Or set ANTHROPIC_API_KEY for the agent' : ''}.`);
519
+ // Its markers were empty files named `<pid>-<uuid>`; anything else in it is
520
+ // left, and so is the folder.
521
+ for (const name of await readdirIfPresent(turns)) {
522
+ if (!LEGACY_TURN_MARKER.test(name)) continue;
523
+ const entry = join(turns, name);
524
+ const entryStat = await statOrNull(entry);
525
+ if (entryStat?.isFile() && !entryStat.isSymbolicLink()) await rm(entry, { force: true });
555
526
  }
556
- // An allowlist, not "everything but refreshToken": a field the host record
557
- // gains later, secret or not, never reaches the seat's writable HOME.
558
- const access = Object.fromEntries(ACCESS_ONLY_LOGIN_FIELDS
559
- .filter((field) => oauth[field] !== undefined)
560
- .map((field) => [field, oauth[field]]));
561
- return `${JSON.stringify({ claudeAiOauth: access })}\n`;
527
+ try { await rmdir(turns); } catch { /* not empty: not ours to clear */ }
562
528
  };
563
529
 
564
- const carryClaudeLogin = async (env, configDir, { accessOnly = false, mustOutlastMs = 0, apiKeyHint = true } = {}) => {
565
- const source = claudeLoginSource(env);
566
- const refuse = () => new Error(`refusing a Claude login that is not a regular file: ${source}`);
567
- let handle;
568
- try {
569
- handle = await open(source, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
570
- } catch (err) {
571
- if (err?.code === 'ENOENT') {
572
- await removeLoginCopy(configDir);
573
- return null;
530
+ /**
531
+ * Removes every login copy a CLI before F661 left under the Claude seat state
532
+ * root (~/.commonly/claude-homes): `<seat>/.claude/.credentials.json`, its
533
+ * staged copies, and the `<seat>.login-turns` markers. Nothing else in a seat
534
+ * folder, and nothing outside the root, is touched. Run once per seat process.
535
+ * Linux only: off Linux it returns before touching the filesystem at all.
536
+ */
537
+ export const removeLegacyClaudeLoginCopies = async (opts = {}) => {
538
+ if (!legacyCopiesPossible(opts.platform || process.platform)) return;
539
+ const root = opts.root || dirname(publicClaudeStateRoot('x'));
540
+ const rootStat = await statOrNull(root);
541
+ if (!rootStat || rootStat.isSymbolicLink() || !rootStat.isDirectory()) return;
542
+ for (const name of await readdir(root)) {
543
+ const entry = join(root, name);
544
+ if (name.endsWith(LEGACY_LOGIN_TURNS)) {
545
+ await removeLegacyLoginTurns(entry.slice(0, -LEGACY_LOGIN_TURNS.length));
546
+ continue;
574
547
  }
575
- if (err?.code === 'ELOOP') throw refuse();
576
- throw err;
548
+ const stat = await statOrNull(entry);
549
+ if (!stat || stat.isSymbolicLink() || !stat.isDirectory()) continue;
550
+ await removeLoginCopy(join(entry, '.claude'));
577
551
  }
578
- try {
579
- if (!(await handle.stat()).isFile()) throw refuse();
580
- const text = await handle.readFile('utf8');
581
- return replacePrivateFile(configDir, '.credentials.json', accessOnly
582
- ? accessOnlyLogin(text, { source, mustOutlastMs, apiKeyHint })
583
- : text);
584
- } finally {
585
- await handle.close();
552
+ };
553
+
554
+ // A bwrap workspace seat signs in with the person's own long-lived token from
555
+ // `claude setup-token`, which they export as CLAUDE_CODE_OAUTH_TOKEN for the
556
+ // agent. Claude Code reads it from its environment; Commonly passes the value
557
+ // through to the jail and writes it nowhere.
558
+ // F661: what a Linux workspace seat with neither its own token nor a key is
559
+ // told. A seat the daemon runs (COMMONLY_MANAGED_RUNNER, set on every child it
560
+ // spawns) can't get either: the service carries only the provider keys
561
+ // adapters declare, and Commonly never writes a token or key into the service
562
+ // file. So it is sent to a foreground `agent run`, as F171 does for keys.
563
+ const WORKSPACE_LOGIN_PREFIX = 'workspace Claude agents on Linux need your own Claude token or an API key';
564
+ const workspaceLoginRefusal = (ctx) => {
565
+ const managed = (ctx.env || process.env).COMMONLY_MANAGED_RUNNER === '1'
566
+ || process.env.COMMONLY_MANAGED_RUNNER === '1';
567
+ if (managed) {
568
+ return new Error(`${WORKSPACE_LOGIN_PREFIX}, and this agent runs under the background daemon, which carries `
569
+ + 'neither: Commonly never writes your token or key into its service file. Run it with '
570
+ + `\`${CLI} agent run ${ctx.seatKey || ctx.agentName || '<name>'}\` from a shell where you have exported `
571
+ + 'CLAUDE_CODE_OAUTH_TOKEN (from `claude setup-token`) or ANTHROPIC_API_KEY.');
586
572
  }
573
+ return new Error(`${WORKSPACE_LOGIN_PREFIX}: run \`claude setup-token\` in your own terminal on this machine `
574
+ + 'and set CLAUDE_CODE_OAUTH_TOKEN to it in the agent\'s environment, or set ANTHROPIC_API_KEY (it stays on '
575
+ + 'this computer behind a per-turn proxy). Commonly passes your token to Claude Code and keeps no copy.');
587
576
  };
588
577
 
578
+ const ownClaudeToken = (source = {}) => (
579
+ typeof source.CLAUDE_CODE_OAUTH_TOKEN === 'string' && source.CLAUDE_CODE_OAUTH_TOKEN.trim()
580
+ ? source.CLAUDE_CODE_OAUTH_TOKEN : null
581
+ );
582
+
589
583
  // The per-seat folder a bwrap seat runs in. A public seat (F96) gets its own,
590
584
  // never the workspace seat's: that one holds the transcripts of private-pod
591
585
  // turns, and the same agent can run both kinds of
@@ -598,30 +592,24 @@ export const bwrapClaudeStatePath = (ctx, seat = 'workspace') => {
598
592
  };
599
593
 
600
594
  // State for a seat under bwrap, outside the person's project, with the auth
601
- // metadata whitelist and the login copy. The jail binds this folder writable
602
- // and makes it HOME, so transcripts land here rather than in the project.
603
- // Every seat carries an access-only copy of the login, or a public seat none
604
- // when an API key reaches the model through the provider proxy instead.
605
- const prepareWorkspaceBwrapClaudeState = async (ctx, { login = 'carry', seat = 'workspace' } = {}) => {
595
+ // metadata whitelist and no login (F661). The jail binds this folder writable
596
+ // and makes it HOME, so transcripts land here rather than in the project. A
597
+ // login copy or turn marker an older CLI left for this seat is removed first.
598
+ const prepareWorkspaceBwrapClaudeState = async (ctx, { seat = 'workspace' } = {}) => {
606
599
  const statePath = bwrapClaudeStatePath(ctx, seat);
607
600
  const tmpPath = join(statePath, 'tmp');
608
601
  const configDir = join(statePath, '.claude');
609
602
  await ensureStateFolder(statePath);
610
603
  for (const dir of [tmpPath, configDir]) await ensurePrivateDir(dir);
604
+ if (legacyCopiesPossible(ctx._platform || process.platform)) {
605
+ await removeLoginCopy(configDir);
606
+ await removeLegacyLoginTurns(statePath);
607
+ }
611
608
 
612
609
  const configPath = await replacePrivateFile(
613
610
  statePath, '.claude.json', `${JSON.stringify(await claudeAuthMetadata(), null, 2)}\n`,
614
611
  );
615
- if (login === 'none') {
616
- await removeLoginCopy(configDir);
617
- return { statePath, tmpPath, configPath, loginPath: null };
618
- }
619
- const loginPath = await carryClaudeLogin(ctx.env, configDir, login === 'access-only'
620
- // A workspace seat's jail never sees the host's API key, so only a public
621
- // seat is told to set one.
622
- ? { accessOnly: true, mustOutlastMs: ctx.timeoutMs || DEFAULT_TIMEOUT_MS, apiKeyHint: seat === 'public' }
623
- : {});
624
- return { statePath, tmpPath, configPath, loginPath };
612
+ return { statePath, tmpPath, configPath };
625
613
  };
626
614
 
627
615
  const buildClaudeEnv = (input, state, expansionEnv = {}, credentialFile = null, publicSeat = false, platform = process.platform) => {
@@ -1889,6 +1877,9 @@ const prepareArgv = async (innerArgv, ctx) => {
1889
1877
  export default {
1890
1878
  get requiresModel() { return seatModelRequired(); },
1891
1879
  name: 'claude',
1880
+ // F661: run once when a seat process starts; removes login copies an older
1881
+ // CLI left under ~/.commonly/claude-homes, at their exact paths only.
1882
+ removeLegacyLoginCopies: () => removeLegacyClaudeLoginCopies(),
1892
1883
  // Identity-bearing runtime tag written into AgentInstallation.config.runtime
1893
1884
  // by `commonly agent attach`. The CLI command stays `commonly agent attach
1894
1885
  // claude` (ergonomic) but the persisted runtimeType matches AGENT_TYPES so
@@ -2062,7 +2053,9 @@ export default {
2062
2053
  let providerProxy = null;
2063
2054
  // A login seat's gateway, when the host names one: config, not a secret.
2064
2055
  let publicLoginBaseUrl = null;
2065
- let loginTurn = null;
2056
+ // F661: a workspace bwrap seat's own CLAUDE_CODE_OAUTH_TOKEN, passed
2057
+ // through to the jail's environment and written nowhere.
2058
+ let ownLoginToken = null;
2066
2059
  let publicSkillArgs = [];
2067
2060
  // No jail to prepare for on a policy-only Windows host.
2068
2061
  const jailed = !policyOnlyHost(ctx);
@@ -2088,12 +2081,14 @@ export default {
2088
2081
  if (providerProxy) {
2089
2082
  return Object.assign(env, { ANTHROPIC_BASE_URL: providerProxy.baseURL, ANTHROPIC_API_KEY: providerProxy.token });
2090
2083
  }
2084
+ if (ownLoginToken) Object.assign(env, { CLAUDE_CODE_OAUTH_TOKEN: ownLoginToken });
2091
2085
  return publicLoginBaseUrl ? Object.assign(env, { ANTHROPIC_BASE_URL: publicLoginBaseUrl }) : env;
2092
2086
  };
2093
- // The values a failure tail or reply must never echo: the seat's own, and
2094
- // the per-turn proxy token the child was handed in place of the host key.
2087
+ // The values a failure tail or reply must never echo: the seat's own, the
2088
+ // per-turn proxy token the child was handed in place of the host key, and
2089
+ // the person's own Claude token.
2095
2090
  const turnCredentials = (spawnContext) => [
2096
- ...spawnCredentials(spawnContext), providerProxy?.token,
2091
+ ...spawnCredentials(spawnContext), providerProxy?.token, ownLoginToken,
2097
2092
  ].filter(Boolean);
2098
2093
  try {
2099
2094
  // Checked (and recorded, the first time) before the state is prepared
@@ -2164,21 +2159,42 @@ export default {
2164
2159
  }
2165
2160
  } else if (workspaceBwrapSandbox) {
2166
2161
  // Checked before the state is prepared, so a host that cannot run the
2167
- // jail never gets a copy of the login.
2162
+ // jail gets no state folder.
2168
2163
  const bwrap = (ctx._detectBwrap || detectBwrap)();
2169
2164
  if (!bwrap.available) throw new Error(`workspace Claude agents require bwrap: ${bwrap.error}`);
2170
2165
  const { claudeBin, claudeInstall } = resolveClaudeInstall(withClaudePath(ctx.env));
2171
2166
  if (!claudeInstall) throw claudeInstallRefusal(claudeBin);
2172
- publicClaudeState = await prepareWorkspaceBwrapClaudeState(ctx, { login: 'access-only' });
2173
- // The host's model route, when it is the one the login uses.
2174
- publicLoginBaseUrl = loginRouteBaseUrl(ctx.env || process.env);
2167
+ // F661: the jail's HOME is the seat's own folder, which holds no login.
2168
+ // Claude Code signs in there with the person's own token, from their
2169
+ // environment; Commonly never reads or copies ~/.claude/.credentials.json.
2170
+ // An API key is the other way in, kept on the host behind a per-turn
2171
+ // proxy as on a public seat. The token wins when both are set.
2172
+ const source = ctx.env || process.env;
2173
+ ownLoginToken = ownClaudeToken(source);
2174
+ if (!ownLoginToken && !source.ANTHROPIC_API_KEY) throw workspaceLoginRefusal(ctx);
2175
+ if (!ownLoginToken && ctx.environment?.sandbox?.network?.policy === 'restricted') {
2176
+ throw new Error('workspace Claude agents on Linux on an API key need shared bwrap networking to reach '
2177
+ + 'the key\'s proxy; sandbox.network.policy "restricted" cuts it off.');
2178
+ }
2179
+ publicClaudeState = await prepareWorkspaceBwrapClaudeState(ctx);
2180
+ if (ownLoginToken) {
2181
+ // The host's model route, when it is the one the login uses.
2182
+ publicLoginBaseUrl = loginRouteBaseUrl(source);
2183
+ } else {
2184
+ providerProxy = await (ctx._startProviderProxy || startProviderProxy)({
2185
+ provider: { baseURL: source.ANTHROPIC_BASE_URL || 'https://api.anthropic.com' },
2186
+ keyMaterial: source.ANTHROPIC_API_KEY,
2187
+ wire: 'anthropic-messages',
2188
+ adapterLabel: 'Claude',
2189
+ });
2190
+ }
2175
2191
  } else if (publicBwrapSandbox) {
2176
- // F96: the workspace tier's jail, reaching the model one of two ways.
2177
- // An API key stays on the host behind a per-turn proxy; without one,
2178
- // the seat gets an access-only copy of the login, deleted after the turn.
2179
- // Either way the model is across the network: restricted networking
2180
- // (--unshare-net) cuts off the host proxy and the vendor alike, so the
2181
- // seat is refused before a proxy starts or a login is copied.
2192
+ // F96: the workspace tier's jail. Since F661 it reaches the model only
2193
+ // on an API key, which stays on the host behind a per-turn proxy:
2194
+ // strangers drive this seat, so it never runs on the person's own
2195
+ // Claude subscription, and Commonly holds no copy of their login. The
2196
+ // model is across the network: restricted networking (--unshare-net)
2197
+ // cuts off the host proxy, so the seat is refused before a proxy starts.
2182
2198
  if (ctx.environment?.sandbox?.network?.policy === 'restricted') {
2183
2199
  throw new Error('public Claude agents on Linux need shared bwrap networking to reach the model; '
2184
2200
  + 'sandbox.network.policy "restricted" cuts it off.');
@@ -2196,23 +2212,18 @@ export default {
2196
2212
  const { claudeBin, claudeInstall } = resolveClaudeInstall(withClaudePath(ctx.env));
2197
2213
  if (!claudeInstall) throw claudeInstallRefusal(claudeBin);
2198
2214
  const source = ctx.env || process.env;
2199
- if (source.ANTHROPIC_API_KEY) {
2200
- publicClaudeState = await prepareWorkspaceBwrapClaudeState(ctx, { login: 'none', seat: 'public' });
2201
- providerProxy = await (ctx._startProviderProxy || startProviderProxy)({
2202
- provider: { baseURL: source.ANTHROPIC_BASE_URL || 'https://api.anthropic.com' },
2203
- keyMaterial: source.ANTHROPIC_API_KEY,
2204
- wire: 'anthropic-messages',
2205
- adapterLabel: 'Claude',
2206
- });
2207
- } else {
2208
- publicClaudeState = await prepareWorkspaceBwrapClaudeState(ctx, { login: 'access-only', seat: 'public' });
2209
- publicLoginBaseUrl = loginRouteBaseUrl(source);
2210
- if (!publicClaudeState.loginPath) {
2211
- throw new Error('public Claude agents on Linux need ANTHROPIC_API_KEY in the agent\'s environment, '
2212
- + 'or sign in with `claude` on this machine first.');
2213
- }
2214
- loginTurn = await registerLoginTurn(publicClaudeState.statePath);
2215
+ if (!source.ANTHROPIC_API_KEY) {
2216
+ throw new Error('public Claude agents on Linux need ANTHROPIC_API_KEY in the agent\'s environment. '
2217
+ + 'Strangers can drive a public agent, so it never runs on your own Claude login; the key stays on '
2218
+ + 'this computer and the agent gets a per-turn proxy token.');
2215
2219
  }
2220
+ publicClaudeState = await prepareWorkspaceBwrapClaudeState(ctx, { seat: 'public' });
2221
+ providerProxy = await (ctx._startProviderProxy || startProviderProxy)({
2222
+ provider: { baseURL: source.ANTHROPIC_BASE_URL || 'https://api.anthropic.com' },
2223
+ keyMaterial: source.ANTHROPIC_API_KEY,
2224
+ wire: 'anthropic-messages',
2225
+ adapterLabel: 'Claude',
2226
+ });
2216
2227
  }
2217
2228
  if (publicTrust) {
2218
2229
  const prompt = await publicSkillPromptArgs(mountedSkills, seatPermissionsText({
@@ -2469,12 +2480,6 @@ export default {
2469
2480
  }
2470
2481
  try { await providerProxy?.close(); } catch { /* ignore */ }
2471
2482
  try { await microvm?.close?.(); } catch { /* ignore */ }
2472
- // A public seat's login copy lives for its turns (F96): the last live
2473
- // turn of the agent to finish removes it.
2474
- if (publicBwrapSandbox && !workspaceBwrapSandbox && publicClaudeState?.loginPath) {
2475
- if (loginTurn) await releaseLoginTurn(loginTurn, publicClaudeState.loginPath);
2476
- else await removeLoginCopy(dirname(publicClaudeState.loginPath));
2477
- }
2478
2483
  }
2479
2484
  },
2480
2485
  };
@@ -36,6 +36,12 @@ const LOGIN_FAILED_WORDINGS = [
36
36
  // The wrapper's own refusals of a Claude login (adapters/claude.js).
37
37
  /the Claude login on this machine expires in/,
38
38
  /refusing a Claude login/,
39
+ // F661: a Linux seat with no token or key of its own to sign in with. These
40
+ // two are ^-anchored: they match the adapter's own refusal, thrown before
41
+ // anything spawns and so reaching here unprefixed (no "claude exited …:"),
42
+ // and never the same words echoed in a model's or tool's output.
43
+ /^workspace Claude agents on Linux need your own Claude token or an API key/,
44
+ /^public Claude agents on Linux need ANTHROPIC_API_KEY/,
39
45
  ];
40
46
  // F436: what Claude Code prints, and exits 1 on, when it has no login on the
41
47
  // computer (2.1.318, walked on windows-latest). No key is wrong and no allowance