@parcha/agentrun-harness-claude 0.1.0-beta.59 → 0.1.0-beta.60
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/CHANGELOG.md +12 -0
- package/dist/env.d.ts +1 -1
- package/dist/env.js +4 -3
- package/dist/facts.d.ts +1 -0
- package/dist/facts.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/login-user.d.ts +9 -0
- package/dist/login-user.js +24 -0
- package/dist/login.d.ts +33 -10
- package/dist/login.js +92 -21
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.60 (2026-11-26)
|
|
6
|
+
|
|
7
|
+
- Sign out of Claude on this machine: `POST /v2/settings/claude-login/sign-out` (operation `signOutClaudeLogin`), and a Sign out button on Settings → Model keys' Claude login row. Before, the row had no way to sign out or switch accounts: Turn off kept the login as the CLI holds it, so Turn on read the same account again with no sign-in page. <!-- changes/claude-login-sign-out.md -->
|
|
8
|
+
- On AgentRun's own login (`<data>/claude-login`) the sign-out ends a sign-in that waits, turns the mode off, runs the pinned CLI's own `claude auth logout` there (its credentials file and, on macOS, its Keychain item for that folder), then removes the folder, the login's signed-in note and the runner's token reader whatever the CLI said. The next Turn on reads not signed in and offers the CLI's sign-in, for the same account or another. Each removal stands alone: one that fails is named in the answer, and the rest, the reader's drop and the server's reread of the keys still happen. `confirmed` false adds a `message` saying what may remain: the CLI didn't confirm its own sign-out, or its step failed (named), or a file could not be removed. A link found at `<data>/claude-login` is removed alone, with the login's signed-in note, no CLI run through it and nothing it leads to touched.
|
|
9
|
+
- This machine's own login (`place` `machine`, the person's `~/.claude` or `CLAUDE_CONFIG_DIR`) is never signed out: the route answers 403 in words that say to run `claude auth logout` in a terminal there, and the console offers no Sign out on it.
|
|
10
|
+
- Runs already going on the login are left as a turn-off leaves them: each fails saying the login is signed out at its next read of it. Where each run is a user of its own, a run claimed on the login and started while the mode is off is refused at its start ("turned off or moved to another folder since this run's claim"), as after a turn-off. The claim checks the login's folder, not its account: a run claimed before Sign out and started after a new sign-in may run on the new account.
|
|
11
|
+
- Not guaranteed for a run still going where runs stay in the runner's process: its CLI holds the refresh token and may write a renewed pair back into `<data>/claude-login` after the sign-out, and nothing removes it when the run ends. Once such runs end, a turn-on that reads signed in again means Sign out again.
|
|
12
|
+
- The harness exports `claudeLogout(cli, login, { timeoutMs, path, platform })`: the CLI's `auth logout` with the sign-in's variables in the person's home, true when it exited 0 within its limit (15 s), false otherwise; it never throws.
|
|
13
|
+
- On macOS, a native Claude runtime now finds the person's login when the server was started without `USER`, as a service launchd starts may be. The `claude` it starts for the sign-in check and for each turn names its Keychain item's account by `USER`, and without one it looked under `unknown`, read signed out and refused every turn. Where the server's environment has no `USER` or `LOGNAME`, or an empty one, they are now set to the user the server runs as; a `USER` it has is kept as it is. <!-- changes/claude-keychain-native-user.md -->
|
|
14
|
+
|
|
15
|
+
At AgentRun's own login folder, the Keychain item an earlier console sign-in left under the account `unknown` is now deleted once the item under the Mac user is there: after a sign-in from the console, or at the first status check that reads signed in. Items of this machine's own Claude login, and items under any other account, are never touched.
|
|
16
|
+
|
|
5
17
|
## 0.1.0-beta.59 (2026-11-25)
|
|
6
18
|
|
|
7
19
|
**Breaking:**
|
package/dist/env.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export interface DurableEnvOptions {
|
|
|
74
74
|
* cache dirs, which the relay wipes before every spawn (`/var/lib/dh/s`),
|
|
75
75
|
* but `HOME` on macOS on a login: the person's (login.ts personHome);
|
|
76
76
|
* - on a login, `USER` and `LOGNAME`: the user this process runs as
|
|
77
|
-
* (login.ts loginUser), the account of the login's Keychain item on macOS;
|
|
77
|
+
* (login-user.ts loginUser), the account of the login's Keychain item on macOS;
|
|
78
78
|
* - the projects key fixed (`CLAUDE_CODE_PROJECT_DIR_NAME`), so a transcript
|
|
79
79
|
* resumes on any VM, whatever the cwd;
|
|
80
80
|
* - the model through the VM's model port, with the attach's key; the
|
package/dist/env.js
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* about 50 `CLAUDE_*`, `ANTHROPIC_*` and `MCP_*` variables that change the
|
|
11
11
|
* CLI's behavior; none reaches the child unless it is listed here.
|
|
12
12
|
*/
|
|
13
|
-
import { loginEnv,
|
|
13
|
+
import { loginEnv, personHome } from './login.js';
|
|
14
|
+
import { loginUser } from './login-user.js';
|
|
14
15
|
/** What never reaches a CLI that runs on a person's login from the app's own variables: a model URL, key or token of
|
|
15
16
|
* any kind, a refresh token or a token's file descriptor among them. A login handed as a token sets its own
|
|
16
17
|
* CLAUDE_CODE_OAUTH_TOKEN after. */
|
|
@@ -26,7 +27,7 @@ export const PROJECT_DIR_NAME = 'session';
|
|
|
26
27
|
* cache dirs, which the relay wipes before every spawn (`/var/lib/dh/s`),
|
|
27
28
|
* but `HOME` on macOS on a login: the person's (login.ts personHome);
|
|
28
29
|
* - on a login, `USER` and `LOGNAME`: the user this process runs as
|
|
29
|
-
* (login.ts loginUser), the account of the login's Keychain item on macOS;
|
|
30
|
+
* (login-user.ts loginUser), the account of the login's Keychain item on macOS;
|
|
30
31
|
* - the projects key fixed (`CLAUDE_CODE_PROJECT_DIR_NAME`), so a transcript
|
|
31
32
|
* resumes on any VM, whatever the cwd;
|
|
32
33
|
* - the model through the VM's model port, with the attach's key; the
|
|
@@ -70,7 +71,7 @@ export function durableEnv(options) {
|
|
|
70
71
|
// session's it finds none and reads signed out. Its config, XDG and temporary dirs stay the session's.
|
|
71
72
|
HOME: options.login && platform === 'darwin' ? personHome(options.login) : home,
|
|
72
73
|
// On a login, the user it is the login of: on macOS the CLI names the Keychain item's account by USER, and with
|
|
73
|
-
// none it reads the account "unknown", not the one the sign-in saved the tokens under (login.ts loginUser).
|
|
74
|
+
// none it reads the account "unknown", not the one the sign-in saved the tokens under (login-user.ts loginUser).
|
|
74
75
|
...(options.login ? loginUser() : {}),
|
|
75
76
|
TMPDIR: options.tmpDir,
|
|
76
77
|
CLAUDE_CONFIG_DIR: options.configDir,
|
package/dist/facts.d.ts
CHANGED
package/dist/facts.js
CHANGED
|
@@ -46,3 +46,6 @@ export const facts = Object.freeze({
|
|
|
46
46
|
// The pinned CLI's renewal of a login (login-refresh.ts), here too so a host that renews a login in the CLI's place
|
|
47
47
|
// reads it without loading the adapter and its SDK.
|
|
48
48
|
export { LOGIN_REFRESH as loginRefresh } from "./login-refresh.js";
|
|
49
|
+
// The user a CLI on a login runs as (login-user.ts), here too so a host that starts the person's own `claude` gives it
|
|
50
|
+
// the USER its Keychain item is named by without loading the adapter and its SDK.
|
|
51
|
+
export { loginUser } from "./login-user.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { findClaudeExecutable as claudeAgentExecutable, platformSuffix as claude
|
|
|
7
7
|
export { anthropicPolicy, CLAUDE_WEB_SEARCH_TOOL, OWN_TOOL_PREFIX, thinks, withWebSearches } from "./host/policy.js";
|
|
8
8
|
export type { AnthropicPolicyOptions, AnthropicUsage } from "./host/policy.js";
|
|
9
9
|
export type { ChildCommand, ConfineChild } from "./host/machine.js";
|
|
10
|
-
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, LOGIN_TOKEN_REFUSED as CLAUDE_LOGIN_TOKEN_REFUSED, loginByToken as claudeLoginByToken, sweepClaudeStatusFolders, loginCommand as claudeLoginCommand, loginEnv as claudeLoginEnv, parseLoginStatus as parseClaudeLoginStatus, startClaudeLogin } from "./login.js";
|
|
10
|
+
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, claudeLogout, LOGIN_TOKEN_REFUSED as CLAUDE_LOGIN_TOKEN_REFUSED, loginByToken as claudeLoginByToken, sweepClaudeStatusFolders, loginCommand as claudeLoginCommand, loginEnv as claudeLoginEnv, parseLoginStatus as parseClaudeLoginStatus, startClaudeLogin } from "./login.js";
|
|
11
11
|
export type { ClaudeAgentLogin, ClaudeLoginStatus, ClaudeLoginToken } from "./login.js";
|
|
12
12
|
export { LOGIN_REFRESH as CLAUDE_LOGIN_REFRESH } from "./login-refresh.js";
|
|
13
13
|
export { listedTools, MCP_OUTPUT_TOKENS, RESULT_SIZE_KEY, toolServer, type ToolServerModules } from "./host/tool-server.js";
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { CLAUDE_AGENT_PACKAGE, ClaudeAgentNotInstalled, ClaudeAgentPinMismatch,
|
|
|
4
4
|
export { CLAUDE_AGENT_SDK_INSTALL, CLAUDE_AGENT_SDK_VERSION, CLAUDE_AGENT_BASE_INPUT_TOKENS, CLAUDE_CODE_VERSION as CLAUDE_AGENT_CLI_VERSION } from "./versions.js";
|
|
5
5
|
export { findClaudeExecutable as claudeAgentExecutable, platformSuffix as claudeAgentPlatform } from "./binary.js";
|
|
6
6
|
export { anthropicPolicy, CLAUDE_WEB_SEARCH_TOOL, OWN_TOOL_PREFIX, thinks, withWebSearches } from "./host/policy.js";
|
|
7
|
-
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, LOGIN_TOKEN_REFUSED as CLAUDE_LOGIN_TOKEN_REFUSED, loginByToken as claudeLoginByToken, sweepClaudeStatusFolders, loginCommand as claudeLoginCommand, loginEnv as claudeLoginEnv, parseLoginStatus as parseClaudeLoginStatus, startClaudeLogin } from "./login.js";
|
|
7
|
+
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, claudeLogout, LOGIN_TOKEN_REFUSED as CLAUDE_LOGIN_TOKEN_REFUSED, loginByToken as claudeLoginByToken, sweepClaudeStatusFolders, loginCommand as claudeLoginCommand, loginEnv as claudeLoginEnv, parseLoginStatus as parseClaudeLoginStatus, startClaudeLogin } from "./login.js";
|
|
8
8
|
export { LOGIN_REFRESH as CLAUDE_LOGIN_REFRESH } from "./login-refresh.js";
|
|
9
9
|
export { listedTools, MCP_OUTPUT_TOKENS, RESULT_SIZE_KEY, toolServer } from "./host/tool-server.js";
|
|
10
10
|
export { SIGN_IN_MS as CLAUDE_SIGN_IN_MS, signInEnv as claudeSignInEnv } from "./login.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** `USER` and `LOGNAME` for a CLI started on a login, built from nothing (the status check, the sign-in this host starts,
|
|
2
|
+
* a run, the CLI's own sign-out): the user this process runs as, as the system has it (`os.userInfo()`, which reads
|
|
3
|
+
* the user database, never the server's own USER), the user whose home personHome is. On macOS the pinned CLI names
|
|
4
|
+
* its Keychain item's account by `$USER`, else by its runtime's `os.userInfo().username`; it is a Bun binary, whose
|
|
5
|
+
* userInfo reads `$USER` too and says "unknown" without it. So a CLI started with no USER saves and reads the login's
|
|
6
|
+
* tokens under the account "unknown", where the person's own `claude`, run in a terminal that has USER, never looks:
|
|
7
|
+
* it reads signed out while the badge reads signed in. A user the system cannot name (no entry in its user database)
|
|
8
|
+
* is the server's USER or LOGNAME, when it has one. */
|
|
9
|
+
export declare function loginUser(): Record<string, string>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The user a CLI started on a login runs as, for the account of its Keychain item on macOS. Written for AgentRun.
|
|
2
|
+
//
|
|
3
|
+
// Here alone, beside nothing else, so a host that starts the person's own `claude` (serve's native runtimes) reads it
|
|
4
|
+
// without loading the adapter and its SDK (facts.ts).
|
|
5
|
+
import { userInfo } from "node:os";
|
|
6
|
+
/** `USER` and `LOGNAME` for a CLI started on a login, built from nothing (the status check, the sign-in this host starts,
|
|
7
|
+
* a run, the CLI's own sign-out): the user this process runs as, as the system has it (`os.userInfo()`, which reads
|
|
8
|
+
* the user database, never the server's own USER), the user whose home personHome is. On macOS the pinned CLI names
|
|
9
|
+
* its Keychain item's account by `$USER`, else by its runtime's `os.userInfo().username`; it is a Bun binary, whose
|
|
10
|
+
* userInfo reads `$USER` too and says "unknown" without it. So a CLI started with no USER saves and reads the login's
|
|
11
|
+
* tokens under the account "unknown", where the person's own `claude`, run in a terminal that has USER, never looks:
|
|
12
|
+
* it reads signed out while the badge reads signed in. A user the system cannot name (no entry in its user database)
|
|
13
|
+
* is the server's USER or LOGNAME, when it has one. */
|
|
14
|
+
export function loginUser() {
|
|
15
|
+
let name;
|
|
16
|
+
try {
|
|
17
|
+
name = userInfo().username || undefined;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
name = undefined;
|
|
21
|
+
}
|
|
22
|
+
name ??= process.env.USER || process.env.LOGNAME || undefined;
|
|
23
|
+
return name === undefined ? {} : { USER: name, LOGNAME: name };
|
|
24
|
+
}
|
package/dist/login.d.ts
CHANGED
|
@@ -25,6 +25,9 @@ export interface ClaudeAgentLogin {
|
|
|
25
25
|
* another user's, so the server's user's own home was taken): the line a person runs (loginCommand) then carries
|
|
26
26
|
* `HOME`, so it signs in where the server reads, never in that terminal's own home. */
|
|
27
27
|
homeApart?: boolean;
|
|
28
|
+
/** Set only for AgentRun's own login folder (serve's place `agentrun`), which no CLI of the person's uses: the one
|
|
29
|
+
* place whose Keychain item left under the account "unknown" is deleted here (dropUnknownItem). */
|
|
30
|
+
own?: boolean;
|
|
28
31
|
}
|
|
29
32
|
/** A login handed to the CLI as its access token alone, by a host that holds the login itself. `token()` is asked at
|
|
30
33
|
* each start of the CLI and when Anthropic refuses the token the CLI holds: it answers the login's access token as
|
|
@@ -125,15 +128,18 @@ export declare function sweepClaudeStatusFolders(options?: {
|
|
|
125
128
|
* the CLI reads its tokens from the login keychain, which is under that home: in any other home (an empty one, a
|
|
126
129
|
* session's) it finds no keychain and reads signed out, whatever the variables. */
|
|
127
130
|
export declare const personHome: (login: ClaudeAgentLogin) => string;
|
|
128
|
-
/**
|
|
129
|
-
* a
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
export declare function
|
|
131
|
+
/** On macOS, at AgentRun's own folder (`own`) alone, delete the login's Keychain item under the account "unknown", which
|
|
132
|
+
* a sign-in left there when the CLI was started with no USER (loginUser), and which nothing reads now: `security
|
|
133
|
+
* delete-generic-password -a unknown -s <the item's service>`, the service the CLI names from the folder (`Claude
|
|
134
|
+
* Code-credentials-<first 8 hex of the folder's sha256>`), in the person's home (personHome), whose login keychain holds
|
|
135
|
+
* it. Called once the item under the person's account is there (the sign-in exited 0, a status check read signed in).
|
|
136
|
+
* Never at the person's own CLI's places, whose "unknown" item may be theirs, never the item with no suffix, never an
|
|
137
|
+
* item of any other account, and never where the user this server runs as is named "unknown" itself. "Not found" is
|
|
138
|
+
* done, as is any other end: nothing is thrown, and it is asked once per item in this process. */
|
|
139
|
+
export declare function dropUnknownItem(login: ClaudeAgentLogin, options: {
|
|
140
|
+
path: string;
|
|
141
|
+
platform?: NodeJS.Platform;
|
|
142
|
+
}): Promise<void>;
|
|
137
143
|
/** Ask the CLI at `cli` whether it is signed in at `login`: `auth status --json`, with only PATH, the user (loginUser)
|
|
138
144
|
* and the login's variables beside it, in the person's home (personHome) on every place and platform.
|
|
139
145
|
* The CLI rewrites its account file (`.claude.json`, in its config dir) whenever that file's migration number is not its
|
|
@@ -186,13 +192,30 @@ export interface ClaudeSignIn {
|
|
|
186
192
|
* It dies with this process, as a session's CLI does: started under the kernel's parent watch (parentWatched; `watch`,
|
|
187
193
|
* by default what this machine supports), so a server that is SIGKILLed, and runs no stop or limit timer, leaves no CLI
|
|
188
194
|
* waiting on the browser's port. It is not detached: it stays in this process's group, so a terminal's Ctrl-C ends it
|
|
189
|
-
* with the server as before, and nothing here kills a group, which would take a browser the CLI started with it.
|
|
195
|
+
* with the server as before, and nothing here kills a group, which would take a browser the CLI started with it.
|
|
196
|
+
* A sign-in that exits 0 at AgentRun's own folder has the item a sign-in left there under "unknown" deleted before
|
|
197
|
+
* `ended` settles (dropUnknownItem). `platform`: the one the CLI runs on, this host's. */
|
|
190
198
|
export declare function startClaudeLogin(cli: string, login: ClaudeAgentLogin, options?: {
|
|
191
199
|
timeoutMs?: number;
|
|
192
200
|
path?: string;
|
|
193
201
|
display?: Readonly<Record<string, string | undefined>>;
|
|
194
202
|
watch?: ParentWatch;
|
|
203
|
+
platform?: NodeJS.Platform;
|
|
195
204
|
}): ClaudeSignIn;
|
|
205
|
+
/** The longest the CLI's own sign-out may take. */
|
|
206
|
+
export declare const LOGOUT_MS = 15000;
|
|
207
|
+
/** The CLI's own sign-out at `login` (`auth logout`), with the sign-in's variables (signInEnv) and user (loginUser) in
|
|
208
|
+
* the person's home (personHome), so it removes what that sign-in kept where it kept it: the credentials file in the
|
|
209
|
+
* login's credentials dir or, on macOS, the Keychain item named from it under that user's account, and the account in
|
|
210
|
+
* the config dir's `.claude.json`. Nothing of it
|
|
211
|
+
* is read but how it ended: true when it exited 0 within `timeoutMs` (LOGOUT_MS by default), false when it exited
|
|
212
|
+
* otherwise, never started, or was ended at the limit (SIGTERM, then SIGKILL a second later). Never throws.
|
|
213
|
+
* `platform`: as signInEnv's. */
|
|
214
|
+
export declare function claudeLogout(cli: string, login: ClaudeAgentLogin, options?: {
|
|
215
|
+
timeoutMs?: number;
|
|
216
|
+
path?: string;
|
|
217
|
+
platform?: NodeJS.Platform;
|
|
218
|
+
}): Promise<boolean>;
|
|
196
219
|
/** How a session on a login books its requests: no proxy sees them, so each response the CLI streams is booked from its
|
|
197
220
|
* own events, billed to the plan, at no price here. No proxy can hold a request back either, so a request is admitted
|
|
198
221
|
* before the CLI can send it: when a message goes to the CLI (`sending`), and when a response stops for its tool calls,
|
package/dist/login.js
CHANGED
|
@@ -12,11 +12,13 @@
|
|
|
12
12
|
// hold secrets (an API key, exported variables, MCP servers' tokens) and lasts the check.
|
|
13
13
|
// The check runs in the person's own home, as does a run on macOS, where the CLI's tokens are in the login keychain.
|
|
14
14
|
import { spawn } from "node:child_process";
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
15
16
|
import { accessSync, closeSync, constants, mkdtempSync, openSync, readSync, rmSync, statSync } from "node:fs";
|
|
16
17
|
import { lstat, mkdir, open, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
17
|
-
import { homedir, tmpdir
|
|
18
|
+
import { homedir, tmpdir } from "node:os";
|
|
18
19
|
import { delimiter, join } from "node:path";
|
|
19
20
|
import { parentWatched } from "@parcha/agentrun-kernel/host";
|
|
21
|
+
import { loginUser } from "./login-user.js";
|
|
20
22
|
/** Whether `login` is handed as a token (ClaudeLoginToken), not as its directories. */
|
|
21
23
|
export const loginByToken = (login) => typeof login.token === "function";
|
|
22
24
|
/** The words a turn ends in when Anthropic refused the login's access token mid-turn and the host had no newer one. */
|
|
@@ -296,24 +298,42 @@ async function accountCopy(from, to) {
|
|
|
296
298
|
* the CLI reads its tokens from the login keychain, which is under that home: in any other home (an empty one, a
|
|
297
299
|
* session's) it finds no keychain and reads signed out, whatever the variables. */
|
|
298
300
|
export const personHome = (login) => login.userHome ?? login.home ?? homedir();
|
|
299
|
-
/**
|
|
300
|
-
*
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
301
|
+
/** How long the delete of an "unknown" item may take before it is killed (SIGKILL, which a `security` or a wrapper on
|
|
302
|
+
* PATH cannot ignore, as it can SIGTERM) and left (dropUnknownItem): the sign-in's end and the status check wait on it. */
|
|
303
|
+
const DROP_MS = 5_000;
|
|
304
|
+
/** The items dropUnknownItem has dealt with in this process, by home and service: each is deleted once. */
|
|
305
|
+
const dropped = new Set();
|
|
306
|
+
/** On macOS, at AgentRun's own folder (`own`) alone, delete the login's Keychain item under the account "unknown", which
|
|
307
|
+
* a sign-in left there when the CLI was started with no USER (loginUser), and which nothing reads now: `security
|
|
308
|
+
* delete-generic-password -a unknown -s <the item's service>`, the service the CLI names from the folder (`Claude
|
|
309
|
+
* Code-credentials-<first 8 hex of the folder's sha256>`), in the person's home (personHome), whose login keychain holds
|
|
310
|
+
* it. Called once the item under the person's account is there (the sign-in exited 0, a status check read signed in).
|
|
311
|
+
* Never at the person's own CLI's places, whose "unknown" item may be theirs, never the item with no suffix, never an
|
|
312
|
+
* item of any other account, and never where the user this server runs as is named "unknown" itself. "Not found" is
|
|
313
|
+
* done, as is any other end: nothing is thrown, and it is asked once per item in this process. */
|
|
314
|
+
export async function dropUnknownItem(login, options) {
|
|
315
|
+
if ((options.platform ?? process.platform) !== "darwin" || login.own !== true)
|
|
316
|
+
return;
|
|
317
|
+
const folder = loginEnv(login, "darwin").CLAUDE_SECURESTORAGE_CONFIG_DIR;
|
|
318
|
+
const user = loginUser();
|
|
319
|
+
if (!folder || user.USER === undefined || user.USER === "unknown")
|
|
320
|
+
return;
|
|
321
|
+
const service = `Claude Code-credentials-${createHash("sha256").update(folder).digest("hex").slice(0, 8)}`;
|
|
322
|
+
const HOME = personHome(login);
|
|
323
|
+
const key = JSON.stringify([HOME, service]);
|
|
324
|
+
if (dropped.has(key))
|
|
325
|
+
return;
|
|
326
|
+
dropped.add(key);
|
|
327
|
+
await new Promise((resolve) => {
|
|
328
|
+
try {
|
|
329
|
+
const child = spawn("security", ["delete-generic-password", "-a", "unknown", "-s", service], { env: { PATH: options.path, HOME, ...user }, stdio: "ignore", timeout: DROP_MS, killSignal: "SIGKILL" });
|
|
330
|
+
child.once("error", () => resolve());
|
|
331
|
+
child.once("close", () => resolve());
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
resolve();
|
|
335
|
+
}
|
|
336
|
+
});
|
|
317
337
|
}
|
|
318
338
|
/** Ask the CLI at `cli` whether it is signed in at `login`: `auth status --json`, with only PATH, the user (loginUser)
|
|
319
339
|
* and the login's variables beside it, in the person's home (personHome) on every place and platform.
|
|
@@ -398,6 +418,10 @@ export async function claudeLoginStatus(cli, login, options = {}) {
|
|
|
398
418
|
// A whole answer written just before the limit still counts.
|
|
399
419
|
if (!status)
|
|
400
420
|
throw timedOut ? new ClaudeLoginTimedOut(limitMs) : new ClaudeLoginNoStatus();
|
|
421
|
+
// Signed in: the item under the person's account is there, so one a sign-in left under "unknown" goes (AgentRun's
|
|
422
|
+
// own folder alone).
|
|
423
|
+
if (status.signedIn)
|
|
424
|
+
await dropUnknownItem(login, { path: options.path ?? process.env.PATH ?? "/usr/bin:/bin", ...(options.platform ? { platform: options.platform } : {}) });
|
|
401
425
|
return status;
|
|
402
426
|
}
|
|
403
427
|
finally {
|
|
@@ -508,7 +532,9 @@ function startable(cli, path) {
|
|
|
508
532
|
* It dies with this process, as a session's CLI does: started under the kernel's parent watch (parentWatched; `watch`,
|
|
509
533
|
* by default what this machine supports), so a server that is SIGKILLed, and runs no stop or limit timer, leaves no CLI
|
|
510
534
|
* waiting on the browser's port. It is not detached: it stays in this process's group, so a terminal's Ctrl-C ends it
|
|
511
|
-
* with the server as before, and nothing here kills a group, which would take a browser the CLI started with it.
|
|
535
|
+
* with the server as before, and nothing here kills a group, which would take a browser the CLI started with it.
|
|
536
|
+
* A sign-in that exits 0 at AgentRun's own folder has the item a sign-in left there under "unknown" deleted before
|
|
537
|
+
* `ended` settles (dropUnknownItem). `platform`: the one the CLI runs on, this host's. */
|
|
512
538
|
export function startClaudeLogin(cli, login, options = {}) {
|
|
513
539
|
// What a browser needs to open on this desktop, when the server has it.
|
|
514
540
|
const display = Object.fromEntries(["DISPLAY", "WAYLAND_DISPLAY", "XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS", "BROWSER"].flatMap((name) => {
|
|
@@ -555,9 +581,54 @@ export function startClaudeLogin(cli, login, options = {}) {
|
|
|
555
581
|
settle(result);
|
|
556
582
|
};
|
|
557
583
|
child.once("error", (error) => finish(ending ? { end: ending } : failed(error)));
|
|
558
|
-
child.once("close", (code, signal) =>
|
|
584
|
+
child.once("close", (code, signal) => {
|
|
585
|
+
const result = ending ? { end: ending } : { end: "exited", code, signal };
|
|
586
|
+
// Signed in: the item under the person's account is there, so one a sign-in left under "unknown" goes first
|
|
587
|
+
// (AgentRun's own folder alone).
|
|
588
|
+
if (result.end === "exited" && code === 0)
|
|
589
|
+
void dropUnknownItem(login, { path, ...(options.platform ? { platform: options.platform } : {}) }).then(() => finish(result));
|
|
590
|
+
else
|
|
591
|
+
finish(result);
|
|
592
|
+
});
|
|
559
593
|
return { ended, stop: () => end("stopped") };
|
|
560
594
|
}
|
|
595
|
+
/** The longest the CLI's own sign-out may take. */
|
|
596
|
+
export const LOGOUT_MS = LOGIN_STATUS_MS;
|
|
597
|
+
/** The CLI's own sign-out at `login` (`auth logout`), with the sign-in's variables (signInEnv) and user (loginUser) in
|
|
598
|
+
* the person's home (personHome), so it removes what that sign-in kept where it kept it: the credentials file in the
|
|
599
|
+
* login's credentials dir or, on macOS, the Keychain item named from it under that user's account, and the account in
|
|
600
|
+
* the config dir's `.claude.json`. Nothing of it
|
|
601
|
+
* is read but how it ended: true when it exited 0 within `timeoutMs` (LOGOUT_MS by default), false when it exited
|
|
602
|
+
* otherwise, never started, or was ended at the limit (SIGTERM, then SIGKILL a second later). Never throws.
|
|
603
|
+
* `platform`: as signInEnv's. */
|
|
604
|
+
export function claudeLogout(cli, login, options = {}) {
|
|
605
|
+
return new Promise((resolve) => {
|
|
606
|
+
let child;
|
|
607
|
+
try {
|
|
608
|
+
child = spawn(cli, ["auth", "logout"], {
|
|
609
|
+
env: { PATH: options.path ?? process.env.PATH ?? "/usr/bin:/bin", HOME: personHome(login), ...loginUser(), ...signInEnv(login, options.platform), DISABLE_AUTOUPDATER: "1", DISABLE_TELEMETRY: "1", DISABLE_ERROR_REPORTING: "1" },
|
|
610
|
+
stdio: "ignore",
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
catch {
|
|
614
|
+
return resolve(false);
|
|
615
|
+
}
|
|
616
|
+
let timedOut = false;
|
|
617
|
+
let kill;
|
|
618
|
+
const limit = setTimeout(() => {
|
|
619
|
+
timedOut = true;
|
|
620
|
+
child.kill("SIGTERM");
|
|
621
|
+
kill = setTimeout(() => child.kill("SIGKILL"), STATUS_KILL_MS);
|
|
622
|
+
}, options.timeoutMs ?? LOGOUT_MS);
|
|
623
|
+
const done = (confirmed) => {
|
|
624
|
+
clearTimeout(limit);
|
|
625
|
+
clearTimeout(kill);
|
|
626
|
+
resolve(confirmed);
|
|
627
|
+
};
|
|
628
|
+
child.once("error", () => done(false));
|
|
629
|
+
child.once("close", (code) => done(!timedOut && code === 0));
|
|
630
|
+
});
|
|
631
|
+
}
|
|
561
632
|
const count = (value) => (typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined);
|
|
562
633
|
/** How a session on a login books its requests: no proxy sees them, so each response the CLI streams is booked from its
|
|
563
634
|
* own events, billed to the plan, at no price here. No proxy can hold a request back either, so a request is admitted
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-harness-claude",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.60",
|
|
4
4
|
"description": "The Claude Agent SDK as an AgentRun harness: the host's tools as its only tools, its model behind a loopback proxy, durable in AgentRun's own store.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"test": "node --test --test-concurrency=8 'test/*.test.mjs'"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@parcha/agentrun-kernel": "0.1.0-beta.
|
|
51
|
+
"@parcha/agentrun-kernel": "0.1.0-beta.60"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@anthropic-ai/claude-agent-sdk": "0.3.286",
|
|
@@ -77,6 +77,6 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@anthropic-ai/claude-agent-sdk": "0.3.286",
|
|
80
|
-
"@parcha/agentrun-dsl": "0.1.0-beta.
|
|
80
|
+
"@parcha/agentrun-dsl": "0.1.0-beta.60"
|
|
81
81
|
}
|
|
82
82
|
}
|