@parcha/agentrun-harness-claude 0.1.0-beta.59 → 0.1.0-beta.61
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 +17 -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 +46 -11
- package/dist/login.js +138 -22
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.61 (2026-11-26)
|
|
6
|
+
|
|
7
|
+
- On macOS, when `security` hangs on the delete of the Keychain item a sign-in left under the account `unknown`, signed-in status checks no longer wait on it each time: checks at once share one delete, and after a delete is killed or fails, status checks leave the item for ten minutes (a sign-in still asks at once). The CLI's own sign-out at AgentRun's own folder now removes that leftover item too. <!-- changes/claude-keychain-drop-backoff.md -->
|
|
8
|
+
- On macOS, a delete of the Keychain item a sign-in left under the account `unknown` that is killed at its limit, or fails, is asked again at the next sign-in or status check, until the item is deleted or found gone. Before, the item was marked dealt with before the delete started, so it stayed for the life of the server. The sign-in's end also settles now should that delete throw before it starts. <!-- changes/claude-keychain-drop-retry.md -->
|
|
9
|
+
|
|
10
|
+
## 0.1.0-beta.60 (2026-11-26)
|
|
11
|
+
|
|
12
|
+
- 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 -->
|
|
13
|
+
- 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.
|
|
14
|
+
- 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.
|
|
15
|
+
- 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.
|
|
16
|
+
- 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.
|
|
17
|
+
- 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.
|
|
18
|
+
- 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 -->
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
5
22
|
## 0.1.0-beta.59 (2026-11-25)
|
|
6
23
|
|
|
7
24
|
**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,24 @@ 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
|
-
|
|
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
|
+
* and at the CLI's own sign-out (claudeLogout), after which no status check reads signed in to call it.
|
|
137
|
+
* Never at the person's own CLI's places, whose "unknown" item may be theirs, never the item with no suffix, never an
|
|
138
|
+
* item of any other account, and never where the user this server runs as is named "unknown" itself. Nothing is thrown.
|
|
139
|
+
* An item deleted, or found gone ("not found", exit 44), is not asked again in this process. One delete runs per item at
|
|
140
|
+
* a time: a call while it runs waits on that one and starts none. One whose delete was killed at its limit, failed or
|
|
141
|
+
* never started is still there: a call that a person made (`asked`: a sign-in that exited 0, a sign-out) asks again at
|
|
142
|
+
* once, a status check only DROP_BACKOFF_MS after that delete ended, measured on `now` (Date.now by default). */
|
|
143
|
+
export declare function dropUnknownItem(login: ClaudeAgentLogin, options: {
|
|
144
|
+
path: string;
|
|
145
|
+
platform?: NodeJS.Platform;
|
|
146
|
+
asked?: boolean;
|
|
147
|
+
now?: () => number;
|
|
148
|
+
}): Promise<void>;
|
|
137
149
|
/** Ask the CLI at `cli` whether it is signed in at `login`: `auth status --json`, with only PATH, the user (loginUser)
|
|
138
150
|
* and the login's variables beside it, in the person's home (personHome) on every place and platform.
|
|
139
151
|
* The CLI rewrites its account file (`.claude.json`, in its config dir) whenever that file's migration number is not its
|
|
@@ -150,11 +162,13 @@ export declare function loginUser(): Record<string, string>;
|
|
|
150
162
|
* once it has exited or was killed, the check waits STATUS_DRAIN_MS more at most for its output, which a process it
|
|
151
163
|
* started may hold open, and then one more pass of the event loop's reads. So a check settles within its limit, 2 s and
|
|
152
164
|
* that pass, whatever the CLI does. A `timeoutMs` that is no whole number of ms from 1 to 2^31 - 1 throws a RangeError
|
|
153
|
-
* before anything starts.
|
|
165
|
+
* before anything starts. Signed in, it drops an item left under "unknown" (dropUnknownItem), up to DROP_MS more, and
|
|
166
|
+
* not within the back-off after a delete of it was killed or failed, measured on `now` (Date.now by default). */
|
|
154
167
|
export declare function claudeLoginStatus(cli: string, login: ClaudeAgentLogin, options?: {
|
|
155
168
|
timeoutMs?: number;
|
|
156
169
|
path?: string;
|
|
157
170
|
platform?: NodeJS.Platform;
|
|
171
|
+
now?: () => number;
|
|
158
172
|
}): Promise<ClaudeLoginStatus>;
|
|
159
173
|
/** How long the CLI's own sign-in waits for its browser before it is ended. */
|
|
160
174
|
export declare const SIGN_IN_MS: number;
|
|
@@ -186,13 +200,34 @@ export interface ClaudeSignIn {
|
|
|
186
200
|
* It dies with this process, as a session's CLI does: started under the kernel's parent watch (parentWatched; `watch`,
|
|
187
201
|
* by default what this machine supports), so a server that is SIGKILLed, and runs no stop or limit timer, leaves no CLI
|
|
188
202
|
* 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.
|
|
203
|
+
* with the server as before, and nothing here kills a group, which would take a browser the CLI started with it.
|
|
204
|
+
* A sign-in that exits 0 at AgentRun's own folder has the item a sign-in left there under "unknown" deleted before
|
|
205
|
+
* `ended` settles (dropUnknownItem), at once, whatever back-off a status check's killed delete left: a person is at the
|
|
206
|
+
* machine. `platform`: the one the CLI runs on, this host's. */
|
|
190
207
|
export declare function startClaudeLogin(cli: string, login: ClaudeAgentLogin, options?: {
|
|
191
208
|
timeoutMs?: number;
|
|
192
209
|
path?: string;
|
|
193
210
|
display?: Readonly<Record<string, string | undefined>>;
|
|
194
211
|
watch?: ParentWatch;
|
|
212
|
+
platform?: NodeJS.Platform;
|
|
195
213
|
}): ClaudeSignIn;
|
|
214
|
+
/** The longest the CLI's own sign-out may take. */
|
|
215
|
+
export declare const LOGOUT_MS = 15000;
|
|
216
|
+
/** The CLI's own sign-out at `login` (`auth logout`), with the sign-in's variables (signInEnv) and user (loginUser) in
|
|
217
|
+
* the person's home (personHome), so it removes what that sign-in kept where it kept it: the credentials file in the
|
|
218
|
+
* login's credentials dir or, on macOS, the Keychain item named from it under that user's account, and the account in
|
|
219
|
+
* the config dir's `.claude.json`. Nothing of it
|
|
220
|
+
* is read but how it ended: true when it exited 0 within `timeoutMs` (LOGOUT_MS by default), false when it exited
|
|
221
|
+
* otherwise, never started, or was ended at the limit (SIGTERM, then SIGKILL a second later). Never throws.
|
|
222
|
+
* Then, at AgentRun's own folder on macOS, the item a sign-in left there under "unknown", which holds a refresh token,
|
|
223
|
+
* is deleted too (dropUnknownItem, with its refusals), whatever the CLI said and whatever back-off a status check's
|
|
224
|
+
* killed delete left, since a person asked and no status check reads signed in after a sign-out to drop it. The answer
|
|
225
|
+
* waits on that delete DROP_MS at most. `platform`: as signInEnv's. */
|
|
226
|
+
export declare function claudeLogout(cli: string, login: ClaudeAgentLogin, options?: {
|
|
227
|
+
timeoutMs?: number;
|
|
228
|
+
path?: string;
|
|
229
|
+
platform?: NodeJS.Platform;
|
|
230
|
+
}): Promise<boolean>;
|
|
196
231
|
/** How a session on a login books its requests: no proxy sees them, so each response the CLI streams is booked from its
|
|
197
232
|
* own events, billed to the plan, at no price here. No proxy can hold a request back either, so a request is admitted
|
|
198
233
|
* 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,72 @@ 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
|
+
/** After a delete of an "unknown" item is killed at its limit or fails, how long a status check leaves that item before
|
|
305
|
+
* it asks again (dropUnknownItem): a `security` that keeps hanging (a login keychain locked, its prompt unanswered)
|
|
306
|
+
* would otherwise cost every signed-in status check DROP_MS. */
|
|
307
|
+
const DROP_BACKOFF_MS = 10 * 60_000;
|
|
308
|
+
/** The items dropUnknownItem has dealt with in this process, by home and service: deleted, or found gone. */
|
|
309
|
+
const dropped = new Set();
|
|
310
|
+
/** The delete running now for each item, by the same key: a call while it runs waits on it and starts none. */
|
|
311
|
+
const dropping = new Map();
|
|
312
|
+
/** For each item whose last delete was killed or failed, by the same key: when a status check may ask again, on the
|
|
313
|
+
* clock of the call that started that delete. */
|
|
314
|
+
const dropAfter = new Map();
|
|
315
|
+
/** On macOS, at AgentRun's own folder (`own`) alone, delete the login's Keychain item under the account "unknown", which
|
|
316
|
+
* a sign-in left there when the CLI was started with no USER (loginUser), and which nothing reads now: `security
|
|
317
|
+
* delete-generic-password -a unknown -s <the item's service>`, the service the CLI names from the folder (`Claude
|
|
318
|
+
* Code-credentials-<first 8 hex of the folder's sha256>`), in the person's home (personHome), whose login keychain holds
|
|
319
|
+
* it. Called once the item under the person's account is there (the sign-in exited 0, a status check read signed in),
|
|
320
|
+
* and at the CLI's own sign-out (claudeLogout), after which no status check reads signed in to call it.
|
|
321
|
+
* Never at the person's own CLI's places, whose "unknown" item may be theirs, never the item with no suffix, never an
|
|
322
|
+
* item of any other account, and never where the user this server runs as is named "unknown" itself. Nothing is thrown.
|
|
323
|
+
* An item deleted, or found gone ("not found", exit 44), is not asked again in this process. One delete runs per item at
|
|
324
|
+
* a time: a call while it runs waits on that one and starts none. One whose delete was killed at its limit, failed or
|
|
325
|
+
* never started is still there: a call that a person made (`asked`: a sign-in that exited 0, a sign-out) asks again at
|
|
326
|
+
* once, a status check only DROP_BACKOFF_MS after that delete ended, measured on `now` (Date.now by default). */
|
|
327
|
+
export async function dropUnknownItem(login, options) {
|
|
328
|
+
if ((options.platform ?? process.platform) !== "darwin" || login.own !== true)
|
|
329
|
+
return;
|
|
330
|
+
const folder = loginEnv(login, "darwin").CLAUDE_SECURESTORAGE_CONFIG_DIR;
|
|
331
|
+
const user = loginUser();
|
|
332
|
+
if (!folder || user.USER === undefined || user.USER === "unknown")
|
|
333
|
+
return;
|
|
334
|
+
const service = `Claude Code-credentials-${createHash("sha256").update(folder).digest("hex").slice(0, 8)}`;
|
|
335
|
+
const HOME = personHome(login);
|
|
336
|
+
const key = JSON.stringify([HOME, service]);
|
|
337
|
+
if (dropped.has(key))
|
|
338
|
+
return;
|
|
339
|
+
const running = dropping.get(key);
|
|
340
|
+
if (running)
|
|
341
|
+
return running;
|
|
342
|
+
const now = options.now ?? Date.now;
|
|
343
|
+
if (options.asked !== true && now() < (dropAfter.get(key) ?? -Infinity))
|
|
344
|
+
return;
|
|
345
|
+
const deleting = new Promise((resolve) => {
|
|
346
|
+
const left = () => {
|
|
347
|
+
dropAfter.set(key, now() + DROP_BACKOFF_MS);
|
|
348
|
+
resolve();
|
|
349
|
+
};
|
|
350
|
+
try {
|
|
351
|
+
const child = spawn("security", ["delete-generic-password", "-a", "unknown", "-s", service], { env: { PATH: options.path, HOME, ...user }, stdio: "ignore", timeout: DROP_MS, killSignal: "SIGKILL" });
|
|
352
|
+
child.once("error", left);
|
|
353
|
+
child.once("close", (code) => {
|
|
354
|
+
if (code !== 0 && code !== 44)
|
|
355
|
+
return left();
|
|
356
|
+
dropped.add(key);
|
|
357
|
+
dropAfter.delete(key);
|
|
358
|
+
resolve();
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
left();
|
|
363
|
+
}
|
|
364
|
+
}).finally(() => dropping.delete(key));
|
|
365
|
+
dropping.set(key, deleting);
|
|
366
|
+
return deleting;
|
|
317
367
|
}
|
|
318
368
|
/** Ask the CLI at `cli` whether it is signed in at `login`: `auth status --json`, with only PATH, the user (loginUser)
|
|
319
369
|
* and the login's variables beside it, in the person's home (personHome) on every place and platform.
|
|
@@ -331,7 +381,8 @@ export function loginUser() {
|
|
|
331
381
|
* once it has exited or was killed, the check waits STATUS_DRAIN_MS more at most for its output, which a process it
|
|
332
382
|
* started may hold open, and then one more pass of the event loop's reads. So a check settles within its limit, 2 s and
|
|
333
383
|
* that pass, whatever the CLI does. A `timeoutMs` that is no whole number of ms from 1 to 2^31 - 1 throws a RangeError
|
|
334
|
-
* before anything starts.
|
|
384
|
+
* before anything starts. Signed in, it drops an item left under "unknown" (dropUnknownItem), up to DROP_MS more, and
|
|
385
|
+
* not within the back-off after a delete of it was killed or failed, measured on `now` (Date.now by default). */
|
|
335
386
|
export async function claudeLoginStatus(cli, login, options = {}) {
|
|
336
387
|
const limitMs = options.timeoutMs ?? LOGIN_STATUS_MS;
|
|
337
388
|
// The limit is the check's timer and, with 2 s more, the end it writes for the sweep, which reads only a whole number
|
|
@@ -398,6 +449,10 @@ export async function claudeLoginStatus(cli, login, options = {}) {
|
|
|
398
449
|
// A whole answer written just before the limit still counts.
|
|
399
450
|
if (!status)
|
|
400
451
|
throw timedOut ? new ClaudeLoginTimedOut(limitMs) : new ClaudeLoginNoStatus();
|
|
452
|
+
// Signed in: the item under the person's account is there, so one a sign-in left under "unknown" goes (AgentRun's
|
|
453
|
+
// own folder alone).
|
|
454
|
+
if (status.signedIn)
|
|
455
|
+
await dropUnknownItem(login, { path: options.path ?? process.env.PATH ?? "/usr/bin:/bin", ...(options.platform ? { platform: options.platform } : {}), ...(options.now ? { now: options.now } : {}) });
|
|
401
456
|
return status;
|
|
402
457
|
}
|
|
403
458
|
finally {
|
|
@@ -508,7 +563,10 @@ function startable(cli, path) {
|
|
|
508
563
|
* It dies with this process, as a session's CLI does: started under the kernel's parent watch (parentWatched; `watch`,
|
|
509
564
|
* by default what this machine supports), so a server that is SIGKILLed, and runs no stop or limit timer, leaves no CLI
|
|
510
565
|
* 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.
|
|
566
|
+
* with the server as before, and nothing here kills a group, which would take a browser the CLI started with it.
|
|
567
|
+
* A sign-in that exits 0 at AgentRun's own folder has the item a sign-in left there under "unknown" deleted before
|
|
568
|
+
* `ended` settles (dropUnknownItem), at once, whatever back-off a status check's killed delete left: a person is at the
|
|
569
|
+
* machine. `platform`: the one the CLI runs on, this host's. */
|
|
512
570
|
export function startClaudeLogin(cli, login, options = {}) {
|
|
513
571
|
// What a browser needs to open on this desktop, when the server has it.
|
|
514
572
|
const display = Object.fromEntries(["DISPLAY", "WAYLAND_DISPLAY", "XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS", "BROWSER"].flatMap((name) => {
|
|
@@ -555,9 +613,67 @@ export function startClaudeLogin(cli, login, options = {}) {
|
|
|
555
613
|
settle(result);
|
|
556
614
|
};
|
|
557
615
|
child.once("error", (error) => finish(ending ? { end: ending } : failed(error)));
|
|
558
|
-
child.once("close", (code, signal) =>
|
|
616
|
+
child.once("close", (code, signal) => {
|
|
617
|
+
const result = ending ? { end: ending } : { end: "exited", code, signal };
|
|
618
|
+
// Signed in: the item under the person's account is there, so one a sign-in left under "unknown" goes first
|
|
619
|
+
// (AgentRun's own folder alone). The end settles however the drop ends: it throws nothing of its own, and should it
|
|
620
|
+
// throw all the same, the sign-in still ended as the CLI exited (a `finally` here would leave that throw unhandled).
|
|
621
|
+
const finished = () => finish(result);
|
|
622
|
+
if (result.end === "exited" && code === 0)
|
|
623
|
+
void dropUnknownItem(login, { path, asked: true, ...(options.platform ? { platform: options.platform } : {}) }).then(finished, finished);
|
|
624
|
+
else
|
|
625
|
+
finish(result);
|
|
626
|
+
});
|
|
559
627
|
return { ended, stop: () => end("stopped") };
|
|
560
628
|
}
|
|
629
|
+
/** The longest the CLI's own sign-out may take. */
|
|
630
|
+
export const LOGOUT_MS = LOGIN_STATUS_MS;
|
|
631
|
+
/** The CLI's own sign-out at `login` (`auth logout`), with the sign-in's variables (signInEnv) and user (loginUser) in
|
|
632
|
+
* the person's home (personHome), so it removes what that sign-in kept where it kept it: the credentials file in the
|
|
633
|
+
* login's credentials dir or, on macOS, the Keychain item named from it under that user's account, and the account in
|
|
634
|
+
* the config dir's `.claude.json`. Nothing of it
|
|
635
|
+
* is read but how it ended: true when it exited 0 within `timeoutMs` (LOGOUT_MS by default), false when it exited
|
|
636
|
+
* otherwise, never started, or was ended at the limit (SIGTERM, then SIGKILL a second later). Never throws.
|
|
637
|
+
* Then, at AgentRun's own folder on macOS, the item a sign-in left there under "unknown", which holds a refresh token,
|
|
638
|
+
* is deleted too (dropUnknownItem, with its refusals), whatever the CLI said and whatever back-off a status check's
|
|
639
|
+
* killed delete left, since a person asked and no status check reads signed in after a sign-out to drop it. The answer
|
|
640
|
+
* waits on that delete DROP_MS at most. `platform`: as signInEnv's. */
|
|
641
|
+
export async function claudeLogout(cli, login, options = {}) {
|
|
642
|
+
const path = options.path ?? process.env.PATH ?? "/usr/bin:/bin";
|
|
643
|
+
// After the CLI's own sign-out, not beside it: both delete in the one login keychain.
|
|
644
|
+
const signedOut = await cliLogout(cli, login, path, options);
|
|
645
|
+
await dropUnknownItem(login, { path, asked: true, ...(options.platform ? { platform: options.platform } : {}) }).catch(() => { });
|
|
646
|
+
return signedOut;
|
|
647
|
+
}
|
|
648
|
+
/** The CLI's own `auth logout` of claudeLogout: true when it exited 0 within its limit. Never throws. */
|
|
649
|
+
function cliLogout(cli, login, path, options) {
|
|
650
|
+
return new Promise((resolve) => {
|
|
651
|
+
let child;
|
|
652
|
+
try {
|
|
653
|
+
child = spawn(cli, ["auth", "logout"], {
|
|
654
|
+
env: { PATH: path, HOME: personHome(login), ...loginUser(), ...signInEnv(login, options.platform), DISABLE_AUTOUPDATER: "1", DISABLE_TELEMETRY: "1", DISABLE_ERROR_REPORTING: "1" },
|
|
655
|
+
stdio: "ignore",
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
catch {
|
|
659
|
+
return resolve(false);
|
|
660
|
+
}
|
|
661
|
+
let timedOut = false;
|
|
662
|
+
let kill;
|
|
663
|
+
const limit = setTimeout(() => {
|
|
664
|
+
timedOut = true;
|
|
665
|
+
child.kill("SIGTERM");
|
|
666
|
+
kill = setTimeout(() => child.kill("SIGKILL"), STATUS_KILL_MS);
|
|
667
|
+
}, options.timeoutMs ?? LOGOUT_MS);
|
|
668
|
+
const done = (confirmed) => {
|
|
669
|
+
clearTimeout(limit);
|
|
670
|
+
clearTimeout(kill);
|
|
671
|
+
resolve(confirmed);
|
|
672
|
+
};
|
|
673
|
+
child.once("error", () => done(false));
|
|
674
|
+
child.once("close", (code) => done(!timedOut && code === 0));
|
|
675
|
+
});
|
|
676
|
+
}
|
|
561
677
|
const count = (value) => (typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined);
|
|
562
678
|
/** How a session on a login books its requests: no proxy sees them, so each response the CLI streams is booked from its
|
|
563
679
|
* 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.61",
|
|
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.61"
|
|
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.61"
|
|
81
81
|
}
|
|
82
82
|
}
|