@parcha/agentrun-harness-claude 0.1.0-beta.60 → 0.1.0-beta.62
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 +16 -0
- package/dist/adapter.d.ts +3 -0
- package/dist/adapter.js +7 -0
- package/dist/env.d.ts +6 -0
- package/dist/env.js +2 -0
- package/dist/harness.d.ts +3 -0
- package/dist/harness.js +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/login.d.ts +46 -12
- package/dist/login.js +105 -33
- package/dist/testing/fake-sdk.js +17 -0
- package/dist/transcript.d.ts +21 -1
- package/dist/transcript.js +47 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.62 (2026-11-26)
|
|
6
|
+
|
|
7
|
+
**Breaking:**
|
|
8
|
+
|
|
9
|
+
- `claudeLogout` answers `{ signedOut, leftoverGone }` (the exported type `ClaudeLogout`) where it answered a boolean. `signedOut` is the boolean it answered before: the CLI's own sign-out exited 0 within its limit. `leftoverGone` says whether the Keychain item a sign-in left under the account `unknown` at AgentRun's own folder on macOS is gone. Who breaks: a caller that reads the answer as a boolean, since an object is always truthy. What to do: read `signedOut` where you read the answer, and tell the person to delete the item in Keychain Access when `leftoverGone` is false. <!-- changes/claude-logout-answer-object.md -->
|
|
10
|
+
|
|
11
|
+
**Changes:**
|
|
12
|
+
|
|
13
|
+
- A claude-agent run on a local model (an Ollama model, or any model AgentRun's route translates onto Anthropic's Messages) no longer ends with no answer. On a slow machine such a model can send nothing on its stream for over five minutes while it loads, reads its prompt or thinks. The CLI gave the stream up at five minutes, asked again without streaming, and got the answer whole. AgentRun only heard the streamed text, so the run completed at $0 with `final_answer: null` and no answer on its timeline. The text of a message that comes whole is now said once, as the turn's answer, and a message whose text did stream is never said twice. This holds on any model: a claude-agent run whose CLI fell back to a non-streaming retry on a provider's own Anthropic model lost its answer the same way. On a translated model the CLI now waits up to 30 minutes on a silent stream (`CLAUDE_STREAM_IDLE_TIMEOUT_MS`), so the first request is no longer thrown away. On a provider's own Messages the CLI keeps its default. <!-- changes/claude-local-answer.md -->
|
|
14
|
+
- On macOS, a sign-out that arrives while a status check is deleting the Keychain item a sign-in left under the account `unknown` waits on that delete, and when it fails or is killed at its limit, tries once more itself. Before, the sign-out answered with the item, which holds a refresh token, still in the login keychain. When the item may remain, serve's sign-out is not confirmed, and its words name the item's exact service, to search in Keychain Access or delete with one `security` command, so they never point at the person's own CLI's item. The harness exports that service as `claudeKeychainService`. It hashes the folder in Unicode's composed form (NFC), as the CLI does, so a folder path with a decomposed character no longer sends the delete to a service no item has, which answered the item gone while it stayed. <!-- changes/claude-signout-drop-retry.md -->
|
|
15
|
+
|
|
16
|
+
## 0.1.0-beta.61 (2026-11-26)
|
|
17
|
+
|
|
18
|
+
- 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 -->
|
|
19
|
+
- 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 -->
|
|
20
|
+
|
|
5
21
|
## 0.1.0-beta.60 (2026-11-26)
|
|
6
22
|
|
|
7
23
|
- 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 -->
|
package/dist/adapter.d.ts
CHANGED
|
@@ -113,6 +113,9 @@ export interface ClaudeAgentAdapterOptions {
|
|
|
113
113
|
/** The IANA zone a user turn's day is read in (harness.ts dateLine), the one the host's environment line names. Default UTC. */
|
|
114
114
|
zone?: string;
|
|
115
115
|
}
|
|
116
|
+
/** How long the CLI waits on a silent stream from a model the host's route translates: the longest the CLI takes
|
|
117
|
+
* (CLAUDE_STREAM_IDLE_TIMEOUT_MS, 30 minutes). */
|
|
118
|
+
export declare const TRANSLATED_STREAM_IDLE_MS: number;
|
|
116
119
|
/** The thinking levels a session runs at: the SDK's effort levels, with adaptive thinking. There is no off. */
|
|
117
120
|
export type ClaudeAgentThinking = "low" | "medium" | "high" | "xhigh" | "max";
|
|
118
121
|
/** A session's level: the node's thinking, else its effort (minimal thinks at low, never at nothing), else the adapter's. */
|
package/dist/adapter.js
CHANGED
|
@@ -58,6 +58,9 @@ export const CLAUDE_AGENT_DIGESTS = Object.freeze({
|
|
|
58
58
|
const TOOL_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
59
59
|
/** How often one send rebuilds a drive whose CLI exited mid-turn. */
|
|
60
60
|
const RESTARTS = 3;
|
|
61
|
+
/** How long the CLI waits on a silent stream from a model the host's route translates: the longest the CLI takes
|
|
62
|
+
* (CLAUDE_STREAM_IDLE_TIMEOUT_MS, 30 minutes). */
|
|
63
|
+
export const TRANSLATED_STREAM_IDLE_MS = 30 * 60_000;
|
|
61
64
|
const THINKING = new Set(["low", "medium", "high", "xhigh", "max"]);
|
|
62
65
|
/** A session's level: the node's thinking, else its effort (minimal thinks at low, never at nothing), else the adapter's. */
|
|
63
66
|
export function thinkingOf(spec, fallback) {
|
|
@@ -363,6 +366,10 @@ export function claudeAgentAdapter(options) {
|
|
|
363
366
|
model: modelFor(spec),
|
|
364
367
|
...(skills.length ? { skills: { plugin: join(dir, "plugin"), names: writeSkillsPlugin(join(dir, "plugin"), skills) } } : {}),
|
|
365
368
|
...(options.smallModel ? { smallModel: options.smallModel } : {}),
|
|
369
|
+
// A model the host's route translates (an Ollama model) sends nothing while it loads, reads its prompt or thinks
|
|
370
|
+
// (the route holds its thinking to redact it whole): the CLI waits its longest on it, never dropping the stream
|
|
371
|
+
// at 5 minutes to ask again without one.
|
|
372
|
+
...(options.fetch ? { streamIdleMs: TRANSLATED_STREAM_IDLE_MS } : {}),
|
|
366
373
|
...(spec.system.length ? { instructions: spec.system.join("\n\n") } : {}),
|
|
367
374
|
...(provider ? { credential: async () => provider.credential(), gatewayUrl: provider.origin } : { login: { at: login, models: io.models } }),
|
|
368
375
|
executable,
|
package/dist/env.d.ts
CHANGED
|
@@ -57,6 +57,12 @@ export interface DurableEnvOptions {
|
|
|
57
57
|
* `CLAUDE_CODE_MAX_MCP_DESCRIPTION_LENGTH` says more; above that, it's set to this, so the model reads each one whole.
|
|
58
58
|
*/
|
|
59
59
|
toolDescriptionMax?: number;
|
|
60
|
+
/**
|
|
61
|
+
* How long the CLI waits on a streamed answer that sends nothing (`CLAUDE_STREAM_IDLE_TIMEOUT_MS`; the CLI's own
|
|
62
|
+
* floor is 5 minutes, its ceiling 30). Unset: the CLI's default, 5 minutes, after which it drops the stream and asks
|
|
63
|
+
* again without streaming.
|
|
64
|
+
*/
|
|
65
|
+
streamIdleMs?: number;
|
|
60
66
|
/**
|
|
61
67
|
* The most tokens an MCP tool's result may take (`MAX_MCP_OUTPUT_TOKENS`). Past it the CLI saves the result to a file
|
|
62
68
|
* and tells the model to read it, or cuts a result that holds an image; its default is 25,000.
|
package/dist/env.js
CHANGED
|
@@ -99,6 +99,8 @@ export function durableEnv(options) {
|
|
|
99
99
|
});
|
|
100
100
|
if (options.toolDescriptionMax !== undefined && options.toolDescriptionMax > MCP_DESCRIPTION_CUT)
|
|
101
101
|
env.CLAUDE_CODE_MAX_MCP_DESCRIPTION_LENGTH = String(options.toolDescriptionMax);
|
|
102
|
+
if (options.streamIdleMs !== undefined)
|
|
103
|
+
env.CLAUDE_STREAM_IDLE_TIMEOUT_MS = String(Math.max(1, Math.floor(options.streamIdleMs)));
|
|
102
104
|
if (options.mcpOutputTokens !== undefined)
|
|
103
105
|
env.MAX_MCP_OUTPUT_TOKENS = String(Math.max(1, Math.floor(options.mcpOutputTokens)));
|
|
104
106
|
if (options.bashTimeoutMs !== undefined) {
|
package/dist/harness.d.ts
CHANGED
|
@@ -191,6 +191,9 @@ export interface ClaudeCodeHarnessOptions {
|
|
|
191
191
|
model?: string;
|
|
192
192
|
/** The model of the CLI's small background calls (`nativeModelId` too). Default `model`. */
|
|
193
193
|
smallModel?: string;
|
|
194
|
+
/** How long the CLI waits on a silent streamed answer before it gives the stream up (durableEnv's `streamIdleMs`).
|
|
195
|
+
* Default the CLI's own, 5 minutes. */
|
|
196
|
+
streamIdleMs?: number;
|
|
194
197
|
/** Appended to Claude Code's own system prompt (the `claude_code` preset). */
|
|
195
198
|
instructions?: string;
|
|
196
199
|
/** The provider credential, read per model request, in the Function. Default `gatewayCredential`. */
|
package/dist/harness.js
CHANGED
|
@@ -513,6 +513,7 @@ export function claudeCodeHarness(options = {}) {
|
|
|
513
513
|
model,
|
|
514
514
|
...(smallModel ? { smallModel } : {}),
|
|
515
515
|
...(sandbox.commandTimeoutMs ? { bashTimeoutMs: sandbox.commandTimeoutMs } : {}),
|
|
516
|
+
...(options.streamIdleMs !== undefined ? { streamIdleMs: options.streamIdleMs } : {}),
|
|
516
517
|
...(sandbox.env ? { extra: sandbox.env } : {}),
|
|
517
518
|
toolDescriptionMax: Math.max(0, ...bridge.tools.map((t) => t.description.length)),
|
|
518
519
|
// A host tool's result within the host's bound reaches the model whole (each tool is listed with it, too).
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ 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, 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
|
-
export type { ClaudeAgentLogin, ClaudeLoginStatus, ClaudeLoginToken } from "./login.js";
|
|
10
|
+
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, claudeLogout, keychainService as claudeKeychainService, 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
|
+
export type { ClaudeAgentLogin, ClaudeLoginStatus, ClaudeLoginToken, ClaudeLogout } 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";
|
|
14
14
|
export type { ServedTool } 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, 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";
|
|
7
|
+
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, claudeLogout, keychainService as claudeKeychainService, 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";
|
package/dist/login.d.ts
CHANGED
|
@@ -128,18 +128,36 @@ export declare function sweepClaudeStatusFolders(options?: {
|
|
|
128
128
|
* the CLI reads its tokens from the login keychain, which is under that home: in any other home (an empty one, a
|
|
129
129
|
* session's) it finds no keychain and reads signed out, whatever the variables. */
|
|
130
130
|
export declare const personHome: (login: ClaudeAgentLogin) => string;
|
|
131
|
+
/** The service of `login`'s Keychain items on macOS, as the CLI names it from the login's credentials dir there
|
|
132
|
+
* (loginEnv): `Claude Code-credentials-<first 8 hex of the folder's sha256>`, or undefined where that dir is empty (the
|
|
133
|
+
* item with no suffix, the person's own CLI's on its default folder). The CLI hashes the folder in Unicode's composed
|
|
134
|
+
* form (`.normalize("NFC")`), so a path with a decomposed character (as a folder name from macOS's Finder may have)
|
|
135
|
+
* names the same item as its composed form; hashed as written it would name a service no item has. A hash of the
|
|
136
|
+
* folder, so it holds no path and no secret, and words for a person may name it. */
|
|
137
|
+
export declare function keychainService(login: ClaudeAgentLogin): string | undefined;
|
|
131
138
|
/** On macOS, at AgentRun's own folder (`own`) alone, delete the login's Keychain item under the account "unknown", which
|
|
132
139
|
* 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
|
|
134
|
-
*
|
|
135
|
-
* it. Called once the item under the person's account is there (the sign-in exited 0, a status check read signed in)
|
|
140
|
+
* delete-generic-password -a unknown -s <the item's service>`, the service the CLI names from the folder
|
|
141
|
+
* (keychainService), in the person's home (personHome), whose login keychain holds
|
|
142
|
+
* it. Called once the item under the person's account is there (the sign-in exited 0, a status check read signed in),
|
|
143
|
+
* and at the CLI's own sign-out (claudeLogout), after which no status check reads signed in to call it.
|
|
136
144
|
* 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.
|
|
138
|
-
*
|
|
145
|
+
* item of any other account, and never where the user this server runs as is named "unknown" itself. Nothing is thrown.
|
|
146
|
+
* An item deleted, or found gone ("not found", exit 44), is not asked again in this process. One delete runs per item at
|
|
147
|
+
* a time: a call while it runs waits on that one and starts none of its own beside it. One whose delete was killed at its
|
|
148
|
+
* limit, failed or never started is still there: a call that a person made (`asked`: a sign-in that exited 0, a
|
|
149
|
+
* sign-out) asks again at once, and so does one that waited on a delete that left it, once (a status check's, say, that
|
|
150
|
+
* a sign-out arrived during); a status check only DROP_BACKOFF_MS after that delete ended, measured on `now` (Date.now
|
|
151
|
+
* by default), and never after one it waited on.
|
|
152
|
+
* Answers whether no such item is left: true once it was deleted or found gone, in this call or before in this process,
|
|
153
|
+
* and where there is none for it to drop (another platform or place, the user named "unknown" or not named); false
|
|
154
|
+
* where it may remain (its delete was killed, failed or never started, or a status check left it to the back-off). */
|
|
139
155
|
export declare function dropUnknownItem(login: ClaudeAgentLogin, options: {
|
|
140
156
|
path: string;
|
|
141
157
|
platform?: NodeJS.Platform;
|
|
142
|
-
|
|
158
|
+
asked?: boolean;
|
|
159
|
+
now?: () => number;
|
|
160
|
+
}): Promise<boolean>;
|
|
143
161
|
/** Ask the CLI at `cli` whether it is signed in at `login`: `auth status --json`, with only PATH, the user (loginUser)
|
|
144
162
|
* and the login's variables beside it, in the person's home (personHome) on every place and platform.
|
|
145
163
|
* The CLI rewrites its account file (`.claude.json`, in its config dir) whenever that file's migration number is not its
|
|
@@ -156,11 +174,13 @@ export declare function dropUnknownItem(login: ClaudeAgentLogin, options: {
|
|
|
156
174
|
* once it has exited or was killed, the check waits STATUS_DRAIN_MS more at most for its output, which a process it
|
|
157
175
|
* 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
|
|
158
176
|
* that pass, whatever the CLI does. A `timeoutMs` that is no whole number of ms from 1 to 2^31 - 1 throws a RangeError
|
|
159
|
-
* before anything starts.
|
|
177
|
+
* before anything starts. Signed in, it drops an item left under "unknown" (dropUnknownItem), up to DROP_MS more, and
|
|
178
|
+
* not within the back-off after a delete of it was killed or failed, measured on `now` (Date.now by default). */
|
|
160
179
|
export declare function claudeLoginStatus(cli: string, login: ClaudeAgentLogin, options?: {
|
|
161
180
|
timeoutMs?: number;
|
|
162
181
|
path?: string;
|
|
163
182
|
platform?: NodeJS.Platform;
|
|
183
|
+
now?: () => number;
|
|
164
184
|
}): Promise<ClaudeLoginStatus>;
|
|
165
185
|
/** How long the CLI's own sign-in waits for its browser before it is ended. */
|
|
166
186
|
export declare const SIGN_IN_MS: number;
|
|
@@ -194,7 +214,8 @@ export interface ClaudeSignIn {
|
|
|
194
214
|
* 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
|
|
195
215
|
* with the server as before, and nothing here kills a group, which would take a browser the CLI started with it.
|
|
196
216
|
* 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)
|
|
217
|
+
* `ended` settles (dropUnknownItem), at once, whatever back-off a status check's killed delete left: a person is at the
|
|
218
|
+
* machine. `platform`: the one the CLI runs on, this host's. */
|
|
198
219
|
export declare function startClaudeLogin(cli: string, login: ClaudeAgentLogin, options?: {
|
|
199
220
|
timeoutMs?: number;
|
|
200
221
|
path?: string;
|
|
@@ -208,14 +229,27 @@ export declare const LOGOUT_MS = 15000;
|
|
|
208
229
|
* the person's home (personHome), so it removes what that sign-in kept where it kept it: the credentials file in the
|
|
209
230
|
* login's credentials dir or, on macOS, the Keychain item named from it under that user's account, and the account in
|
|
210
231
|
* 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
|
|
212
|
-
* otherwise, never started, or was ended at the limit (SIGTERM, then SIGKILL a second later). Never throws.
|
|
213
|
-
*
|
|
232
|
+
* is read but how it ended: `signedOut` true when it exited 0 within `timeoutMs` (LOGOUT_MS by default), false when it
|
|
233
|
+
* exited otherwise, never started, or was ended at the limit (SIGTERM, then SIGKILL a second later). Never throws.
|
|
234
|
+
* Then, at AgentRun's own folder on macOS, the item a sign-in left there under "unknown", which holds a refresh token,
|
|
235
|
+
* is deleted too (dropUnknownItem, with its refusals), whatever the CLI said and whatever back-off a status check's
|
|
236
|
+
* killed delete left, since a person asked and no status check reads signed in after a sign-out to drop it; where a
|
|
237
|
+
* status check's delete of it runs, the sign-out waits on that one and asks once more should it leave the item.
|
|
238
|
+
* `leftoverGone` says whether no such item is left (dropUnknownItem's answer: true where there is none to drop, false
|
|
239
|
+
* where its delete was killed or failed, or threw), so the caller can tell the person to delete it by hand. Values
|
|
240
|
+
* only: no name or token. The answer waits on that delete DROP_MS at most, twice that where it waited on a status
|
|
241
|
+
* check's first. `platform`: as signInEnv's. */
|
|
214
242
|
export declare function claudeLogout(cli: string, login: ClaudeAgentLogin, options?: {
|
|
215
243
|
timeoutMs?: number;
|
|
216
244
|
path?: string;
|
|
217
245
|
platform?: NodeJS.Platform;
|
|
218
|
-
}): Promise<
|
|
246
|
+
}): Promise<ClaudeLogout>;
|
|
247
|
+
/** claudeLogout's answer: the CLI confirmed its own sign-out (`signedOut`), and no Keychain item a sign-in left under
|
|
248
|
+
* "unknown" at AgentRun's own folder is left (`leftoverGone`). */
|
|
249
|
+
export type ClaudeLogout = {
|
|
250
|
+
signedOut: boolean;
|
|
251
|
+
leftoverGone: boolean;
|
|
252
|
+
};
|
|
219
253
|
/** How a session on a login books its requests: no proxy sees them, so each response the CLI streams is booked from its
|
|
220
254
|
* own events, billed to the plan, at no price here. No proxy can hold a request back either, so a request is admitted
|
|
221
255
|
* 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
|
@@ -301,39 +301,92 @@ export const personHome = (login) => login.userHome ?? login.home ?? homedir();
|
|
|
301
301
|
/** How long the delete of an "unknown" item may take before it is killed (SIGKILL, which a `security` or a wrapper on
|
|
302
302
|
* PATH cannot ignore, as it can SIGTERM) and left (dropUnknownItem): the sign-in's end and the status check wait on it. */
|
|
303
303
|
const DROP_MS = 5_000;
|
|
304
|
-
/**
|
|
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. */
|
|
305
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
|
+
/** The service of `login`'s Keychain items on macOS, as the CLI names it from the login's credentials dir there
|
|
316
|
+
* (loginEnv): `Claude Code-credentials-<first 8 hex of the folder's sha256>`, or undefined where that dir is empty (the
|
|
317
|
+
* item with no suffix, the person's own CLI's on its default folder). The CLI hashes the folder in Unicode's composed
|
|
318
|
+
* form (`.normalize("NFC")`), so a path with a decomposed character (as a folder name from macOS's Finder may have)
|
|
319
|
+
* names the same item as its composed form; hashed as written it would name a service no item has. A hash of the
|
|
320
|
+
* folder, so it holds no path and no secret, and words for a person may name it. */
|
|
321
|
+
export function keychainService(login) {
|
|
322
|
+
const folder = loginEnv(login, "darwin").CLAUDE_SECURESTORAGE_CONFIG_DIR;
|
|
323
|
+
return folder ? `Claude Code-credentials-${createHash("sha256").update(folder.normalize("NFC")).digest("hex").slice(0, 8)}` : undefined;
|
|
324
|
+
}
|
|
306
325
|
/** On macOS, at AgentRun's own folder (`own`) alone, delete the login's Keychain item under the account "unknown", which
|
|
307
326
|
* 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
|
|
309
|
-
*
|
|
310
|
-
* it. Called once the item under the person's account is there (the sign-in exited 0, a status check read signed in)
|
|
327
|
+
* delete-generic-password -a unknown -s <the item's service>`, the service the CLI names from the folder
|
|
328
|
+
* (keychainService), in the person's home (personHome), whose login keychain holds
|
|
329
|
+
* it. Called once the item under the person's account is there (the sign-in exited 0, a status check read signed in),
|
|
330
|
+
* and at the CLI's own sign-out (claudeLogout), after which no status check reads signed in to call it.
|
|
311
331
|
* 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.
|
|
313
|
-
*
|
|
332
|
+
* item of any other account, and never where the user this server runs as is named "unknown" itself. Nothing is thrown.
|
|
333
|
+
* An item deleted, or found gone ("not found", exit 44), is not asked again in this process. One delete runs per item at
|
|
334
|
+
* a time: a call while it runs waits on that one and starts none of its own beside it. One whose delete was killed at its
|
|
335
|
+
* limit, failed or never started is still there: a call that a person made (`asked`: a sign-in that exited 0, a
|
|
336
|
+
* sign-out) asks again at once, and so does one that waited on a delete that left it, once (a status check's, say, that
|
|
337
|
+
* a sign-out arrived during); a status check only DROP_BACKOFF_MS after that delete ended, measured on `now` (Date.now
|
|
338
|
+
* by default), and never after one it waited on.
|
|
339
|
+
* Answers whether no such item is left: true once it was deleted or found gone, in this call or before in this process,
|
|
340
|
+
* and where there is none for it to drop (another platform or place, the user named "unknown" or not named); false
|
|
341
|
+
* where it may remain (its delete was killed, failed or never started, or a status check left it to the back-off). */
|
|
314
342
|
export async function dropUnknownItem(login, options) {
|
|
315
343
|
if ((options.platform ?? process.platform) !== "darwin" || login.own !== true)
|
|
316
|
-
return;
|
|
317
|
-
const
|
|
344
|
+
return true;
|
|
345
|
+
const service = keychainService(login);
|
|
318
346
|
const user = loginUser();
|
|
319
|
-
if (
|
|
320
|
-
return;
|
|
321
|
-
const service = `Claude Code-credentials-${createHash("sha256").update(folder).digest("hex").slice(0, 8)}`;
|
|
347
|
+
if (service === undefined || user.USER === undefined || user.USER === "unknown")
|
|
348
|
+
return true;
|
|
322
349
|
const HOME = personHome(login);
|
|
323
350
|
const key = JSON.stringify([HOME, service]);
|
|
324
351
|
if (dropped.has(key))
|
|
325
|
-
return;
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
352
|
+
return true;
|
|
353
|
+
const now = options.now ?? Date.now;
|
|
354
|
+
const start = () => {
|
|
355
|
+
const deleting = new Promise((resolve) => {
|
|
356
|
+
const left = () => {
|
|
357
|
+
dropAfter.set(key, now() + DROP_BACKOFF_MS);
|
|
358
|
+
resolve();
|
|
359
|
+
};
|
|
360
|
+
try {
|
|
361
|
+
const child = spawn("security", ["delete-generic-password", "-a", "unknown", "-s", service], { env: { PATH: options.path, HOME, ...user }, stdio: "ignore", timeout: DROP_MS, killSignal: "SIGKILL" });
|
|
362
|
+
child.once("error", left);
|
|
363
|
+
child.once("close", (code) => {
|
|
364
|
+
if (code !== 0 && code !== 44)
|
|
365
|
+
return left();
|
|
366
|
+
dropped.add(key);
|
|
367
|
+
dropAfter.delete(key);
|
|
368
|
+
resolve();
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
left();
|
|
373
|
+
}
|
|
374
|
+
}).finally(() => dropping.delete(key));
|
|
375
|
+
dropping.set(key, deleting);
|
|
376
|
+
return deleting;
|
|
377
|
+
};
|
|
378
|
+
const running = dropping.get(key);
|
|
379
|
+
if (running) {
|
|
380
|
+
await running;
|
|
381
|
+
// A status check only waits. A call a person made, whose wait left the item (that delete was killed or failed), asks
|
|
382
|
+
// once more: after a sign-out no status check reads signed in to ask again. Once, joining a delete another such call
|
|
383
|
+
// started meanwhile rather than starting a second.
|
|
384
|
+
if (options.asked === true && !dropped.has(key))
|
|
385
|
+
await (dropping.get(key) ?? start());
|
|
386
|
+
}
|
|
387
|
+
else if (options.asked === true || now() >= (dropAfter.get(key) ?? -Infinity))
|
|
388
|
+
await start();
|
|
389
|
+
return dropped.has(key);
|
|
337
390
|
}
|
|
338
391
|
/** Ask the CLI at `cli` whether it is signed in at `login`: `auth status --json`, with only PATH, the user (loginUser)
|
|
339
392
|
* and the login's variables beside it, in the person's home (personHome) on every place and platform.
|
|
@@ -351,7 +404,8 @@ export async function dropUnknownItem(login, options) {
|
|
|
351
404
|
* once it has exited or was killed, the check waits STATUS_DRAIN_MS more at most for its output, which a process it
|
|
352
405
|
* 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
|
|
353
406
|
* that pass, whatever the CLI does. A `timeoutMs` that is no whole number of ms from 1 to 2^31 - 1 throws a RangeError
|
|
354
|
-
* before anything starts.
|
|
407
|
+
* before anything starts. Signed in, it drops an item left under "unknown" (dropUnknownItem), up to DROP_MS more, and
|
|
408
|
+
* not within the back-off after a delete of it was killed or failed, measured on `now` (Date.now by default). */
|
|
355
409
|
export async function claudeLoginStatus(cli, login, options = {}) {
|
|
356
410
|
const limitMs = options.timeoutMs ?? LOGIN_STATUS_MS;
|
|
357
411
|
// 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
|
|
@@ -421,7 +475,7 @@ export async function claudeLoginStatus(cli, login, options = {}) {
|
|
|
421
475
|
// Signed in: the item under the person's account is there, so one a sign-in left under "unknown" goes (AgentRun's
|
|
422
476
|
// own folder alone).
|
|
423
477
|
if (status.signedIn)
|
|
424
|
-
await dropUnknownItem(login, { path: options.path ?? process.env.PATH ?? "/usr/bin:/bin", ...(options.platform ? { platform: options.platform } : {}) });
|
|
478
|
+
await dropUnknownItem(login, { path: options.path ?? process.env.PATH ?? "/usr/bin:/bin", ...(options.platform ? { platform: options.platform } : {}), ...(options.now ? { now: options.now } : {}) });
|
|
425
479
|
return status;
|
|
426
480
|
}
|
|
427
481
|
finally {
|
|
@@ -534,7 +588,8 @@ function startable(cli, path) {
|
|
|
534
588
|
* 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
|
|
535
589
|
* with the server as before, and nothing here kills a group, which would take a browser the CLI started with it.
|
|
536
590
|
* 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)
|
|
591
|
+
* `ended` settles (dropUnknownItem), at once, whatever back-off a status check's killed delete left: a person is at the
|
|
592
|
+
* machine. `platform`: the one the CLI runs on, this host's. */
|
|
538
593
|
export function startClaudeLogin(cli, login, options = {}) {
|
|
539
594
|
// What a browser needs to open on this desktop, when the server has it.
|
|
540
595
|
const display = Object.fromEntries(["DISPLAY", "WAYLAND_DISPLAY", "XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS", "BROWSER"].flatMap((name) => {
|
|
@@ -584,9 +639,11 @@ export function startClaudeLogin(cli, login, options = {}) {
|
|
|
584
639
|
child.once("close", (code, signal) => {
|
|
585
640
|
const result = ending ? { end: ending } : { end: "exited", code, signal };
|
|
586
641
|
// 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).
|
|
642
|
+
// (AgentRun's own folder alone). The end settles however the drop ends: it throws nothing of its own, and should it
|
|
643
|
+
// throw all the same, the sign-in still ended as the CLI exited (a `finally` here would leave that throw unhandled).
|
|
644
|
+
const finished = () => finish(result);
|
|
588
645
|
if (result.end === "exited" && code === 0)
|
|
589
|
-
void dropUnknownItem(login, { path, ...(options.platform ? { platform: options.platform } : {}) }).then(
|
|
646
|
+
void dropUnknownItem(login, { path, asked: true, ...(options.platform ? { platform: options.platform } : {}) }).then(finished, finished);
|
|
590
647
|
else
|
|
591
648
|
finish(result);
|
|
592
649
|
});
|
|
@@ -598,15 +655,30 @@ export const LOGOUT_MS = LOGIN_STATUS_MS;
|
|
|
598
655
|
* the person's home (personHome), so it removes what that sign-in kept where it kept it: the credentials file in the
|
|
599
656
|
* login's credentials dir or, on macOS, the Keychain item named from it under that user's account, and the account in
|
|
600
657
|
* 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
|
|
602
|
-
* otherwise, never started, or was ended at the limit (SIGTERM, then SIGKILL a second later). Never throws.
|
|
603
|
-
*
|
|
604
|
-
|
|
658
|
+
* is read but how it ended: `signedOut` true when it exited 0 within `timeoutMs` (LOGOUT_MS by default), false when it
|
|
659
|
+
* exited otherwise, never started, or was ended at the limit (SIGTERM, then SIGKILL a second later). Never throws.
|
|
660
|
+
* Then, at AgentRun's own folder on macOS, the item a sign-in left there under "unknown", which holds a refresh token,
|
|
661
|
+
* is deleted too (dropUnknownItem, with its refusals), whatever the CLI said and whatever back-off a status check's
|
|
662
|
+
* killed delete left, since a person asked and no status check reads signed in after a sign-out to drop it; where a
|
|
663
|
+
* status check's delete of it runs, the sign-out waits on that one and asks once more should it leave the item.
|
|
664
|
+
* `leftoverGone` says whether no such item is left (dropUnknownItem's answer: true where there is none to drop, false
|
|
665
|
+
* where its delete was killed or failed, or threw), so the caller can tell the person to delete it by hand. Values
|
|
666
|
+
* only: no name or token. The answer waits on that delete DROP_MS at most, twice that where it waited on a status
|
|
667
|
+
* check's first. `platform`: as signInEnv's. */
|
|
668
|
+
export async function claudeLogout(cli, login, options = {}) {
|
|
669
|
+
const path = options.path ?? process.env.PATH ?? "/usr/bin:/bin";
|
|
670
|
+
// After the CLI's own sign-out, not beside it: both delete in the one login keychain.
|
|
671
|
+
const signedOut = await cliLogout(cli, login, path, options);
|
|
672
|
+
const leftoverGone = await dropUnknownItem(login, { path, asked: true, ...(options.platform ? { platform: options.platform } : {}) }).catch(() => false);
|
|
673
|
+
return { signedOut, leftoverGone };
|
|
674
|
+
}
|
|
675
|
+
/** The CLI's own `auth logout` of claudeLogout: true when it exited 0 within its limit. Never throws. */
|
|
676
|
+
function cliLogout(cli, login, path, options) {
|
|
605
677
|
return new Promise((resolve) => {
|
|
606
678
|
let child;
|
|
607
679
|
try {
|
|
608
680
|
child = spawn(cli, ["auth", "logout"], {
|
|
609
|
-
env: { PATH:
|
|
681
|
+
env: { PATH: path, HOME: personHome(login), ...loginUser(), ...signInEnv(login, options.platform), DISABLE_AUTOUPDATER: "1", DISABLE_TELEMETRY: "1", DISABLE_ERROR_REPORTING: "1" },
|
|
610
682
|
stdio: "ignore",
|
|
611
683
|
});
|
|
612
684
|
}
|
package/dist/testing/fake-sdk.js
CHANGED
|
@@ -387,6 +387,23 @@ export function fakeSdk(fake = {}) {
|
|
|
387
387
|
await mirror([{ type: 'last-prompt' }]);
|
|
388
388
|
continue;
|
|
389
389
|
}
|
|
390
|
+
// `whole <json>` (`{ thinking?, text }`): the answer as Claude Code hands on its non-streaming retry of a stalled
|
|
391
|
+
// stream: the stalled message's start, then the answer's `assistant` messages (its thinking block, then its text
|
|
392
|
+
// block, one message id), with no stream deltas.
|
|
393
|
+
const whole = /^whole (.*)$/s.exec(command);
|
|
394
|
+
if (whole) {
|
|
395
|
+
const answer = JSON.parse(whole[1]);
|
|
396
|
+
yield { type: 'stream_event', parent_tool_use_id: null, event: { type: 'message_start', message: { id: `msg_${uuid().slice(0, 8)}`, role: 'assistant', content: [] } } };
|
|
397
|
+
const id = `msg_${uuid().slice(0, 8)}`;
|
|
398
|
+
const blocks = [...(answer.thinking ? [{ type: 'thinking', thinking: answer.thinking, signature: '' }] : []), { type: 'text', text: answer.text }];
|
|
399
|
+
const b = entry('assistant', { message: { id, role: 'assistant', content: blocks, stop_reason: 'end_turn' } });
|
|
400
|
+
await mirror([b]);
|
|
401
|
+
for (const block of blocks)
|
|
402
|
+
yield { type: 'assistant', parent_tool_use_id: null, uuid: b.uuid, session_id: sessionId, message: { id, role: 'assistant', content: [block] } };
|
|
403
|
+
yield { type: 'result', subtype: 'success', is_error: false, result: answer.text, session_id: sessionId, user_message_uuids: consumed, queued_turn_count: 0 };
|
|
404
|
+
await mirror([{ type: 'last-prompt' }]);
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
390
407
|
const batching = /^batch (.*)$/s.exec(command);
|
|
391
408
|
if (batching) {
|
|
392
409
|
const spec = JSON.parse(batching[1]);
|
package/dist/transcript.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ import type { TranscriptEntry } from './host/process.js';
|
|
|
8
8
|
* (with `includePartialMessages`), and one `result` per turn. This keeps the
|
|
9
9
|
* text said since the last tool call, writes it with the call that follows it
|
|
10
10
|
* (`{ role: 'assistant', text, toolCalls }`), and writes the rest and a `turn`
|
|
11
|
-
* entry at the result. Text deltas go to the live stream
|
|
11
|
+
* entry at the result. Text deltas go to the live stream, and the text of a
|
|
12
|
+
* message that came whole (no deltas: the CLI's non-streaming retry of a
|
|
13
|
+
* stalled request) goes there from its blocks. Subagent messages
|
|
12
14
|
* (`parent_tool_use_id` set) are left out.
|
|
13
15
|
*
|
|
14
16
|
* Pure: the drive hands it SDK messages and gets entries back through `sink`,
|
|
@@ -57,6 +59,17 @@ export declare class TranscriptBuilder {
|
|
|
57
59
|
/** The model's last message was cut at its output limit, and the turn has not ended: the CLI resumes it itself, so the
|
|
58
60
|
* next text the model says is a message of its own (`text_end` before it). */
|
|
59
61
|
private cutPending;
|
|
62
|
+
/** The streamed message (its `message_start` id), and the ids of the messages whose text streamed: a message the CLI
|
|
63
|
+
* got whole (its non-streaming retry of a stalled stream) has no deltas, and its text is said live from its blocks. */
|
|
64
|
+
private streaming;
|
|
65
|
+
private readonly streamed;
|
|
66
|
+
/** Text deltas no `assistant` text block has claimed yet: how a message with no id reads as streamed. */
|
|
67
|
+
private unclaimed;
|
|
68
|
+
/** Text was said live since the last message boundary: a whole answer after it is a message of its own. */
|
|
69
|
+
private saying;
|
|
70
|
+
/** The message whose whole text was said last: its next text block is more of that message, as a streamed message's
|
|
71
|
+
* blocks are, never a message of its own. */
|
|
72
|
+
private wholeId;
|
|
60
73
|
constructor(sink: TranscriptSink);
|
|
61
74
|
/** One message from `query()`. Returns how the turn ended for a `result`. */
|
|
62
75
|
observe(m: SdkMessage): TurnEnd | undefined;
|
|
@@ -75,6 +88,13 @@ export declare class TranscriptBuilder {
|
|
|
75
88
|
* block before it calls the tool); after `waitMs`, by this.
|
|
76
89
|
*/
|
|
77
90
|
beforeCall(id: string, name: string, waitMs?: number): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* A text block of an `assistant` message, said live when none of its text streamed: the CLI asks again without
|
|
93
|
+
* streaming when a streamed request stalls, and that answer comes whole. A message with an id streamed when a delta
|
|
94
|
+
* came under its `message_start`; one with none, when deltas came since the last text block. A whole message's text
|
|
95
|
+
* blocks are one message live, as a streamed one's are.
|
|
96
|
+
*/
|
|
97
|
+
private sayUnstreamed;
|
|
78
98
|
private call;
|
|
79
99
|
}
|
|
80
100
|
export {};
|
package/dist/transcript.js
CHANGED
|
@@ -17,6 +17,17 @@ export class TranscriptBuilder {
|
|
|
17
17
|
/** The model's last message was cut at its output limit, and the turn has not ended: the CLI resumes it itself, so the
|
|
18
18
|
* next text the model says is a message of its own (`text_end` before it). */
|
|
19
19
|
cutPending = false;
|
|
20
|
+
/** The streamed message (its `message_start` id), and the ids of the messages whose text streamed: a message the CLI
|
|
21
|
+
* got whole (its non-streaming retry of a stalled stream) has no deltas, and its text is said live from its blocks. */
|
|
22
|
+
streaming;
|
|
23
|
+
streamed = new Set();
|
|
24
|
+
/** Text deltas no `assistant` text block has claimed yet: how a message with no id reads as streamed. */
|
|
25
|
+
unclaimed = false;
|
|
26
|
+
/** Text was said live since the last message boundary: a whole answer after it is a message of its own. */
|
|
27
|
+
saying = false;
|
|
28
|
+
/** The message whose whole text was said last: its next text block is more of that message, as a streamed message's
|
|
29
|
+
* blocks are, never a message of its own. */
|
|
30
|
+
wholeId;
|
|
20
31
|
constructor(sink) {
|
|
21
32
|
this.sink = sink;
|
|
22
33
|
}
|
|
@@ -26,6 +37,8 @@ export class TranscriptBuilder {
|
|
|
26
37
|
return undefined;
|
|
27
38
|
if (m.type === 'stream_event') {
|
|
28
39
|
const ev = m.event;
|
|
40
|
+
if (ev?.type === 'message_start')
|
|
41
|
+
this.streaming = typeof ev.message?.id === 'string' ? ev.message.id : undefined;
|
|
29
42
|
// A message the model's output limit cut: the CLI resumes it in the same turn ("Output token limit hit"), and the
|
|
30
43
|
// message that follows is the model's next one, not more of this one.
|
|
31
44
|
if (ev?.type === 'message_delta' && ev.delta?.stop_reason === 'max_tokens')
|
|
@@ -34,15 +47,23 @@ export class TranscriptBuilder {
|
|
|
34
47
|
if (this.cutPending)
|
|
35
48
|
this.sink.live({ type: 'text_end' });
|
|
36
49
|
this.cutPending = false;
|
|
50
|
+
if (this.streaming !== undefined)
|
|
51
|
+
this.streamed.add(this.streaming);
|
|
52
|
+
this.unclaimed = true;
|
|
53
|
+
this.saying = true;
|
|
54
|
+
this.wholeId = undefined;
|
|
37
55
|
this.sink.live({ type: 'text', delta: ev.delta.text });
|
|
38
56
|
}
|
|
39
57
|
return undefined;
|
|
40
58
|
}
|
|
41
59
|
if (m.type === 'assistant') {
|
|
42
|
-
const
|
|
60
|
+
const message = m.message;
|
|
61
|
+
const content = message?.content;
|
|
43
62
|
for (const block of Array.isArray(content) ? content : []) {
|
|
44
|
-
if (block.type === 'text' && block.text)
|
|
63
|
+
if (block.type === 'text' && block.text) {
|
|
45
64
|
this.said = this.said ? `${this.said}\n\n${block.text}` : block.text;
|
|
65
|
+
this.sayUnstreamed(typeof message?.id === 'string' ? message.id : undefined, block.text);
|
|
66
|
+
}
|
|
46
67
|
else if (block.type === 'tool_use' && block.id) {
|
|
47
68
|
this.asked.set(block.id, { name: bareToolName(block.name ?? 'tool'), input: block.input });
|
|
48
69
|
this.call(block.id, bareToolName(block.name ?? 'tool'));
|
|
@@ -75,6 +96,9 @@ export class TranscriptBuilder {
|
|
|
75
96
|
? [m.user_message_uuid]
|
|
76
97
|
: undefined;
|
|
77
98
|
this.cutPending = false;
|
|
99
|
+
this.saying = false;
|
|
100
|
+
this.unclaimed = false;
|
|
101
|
+
this.wholeId = undefined;
|
|
78
102
|
// The turn's final answer still cut: the CLI's recovery of it was spent.
|
|
79
103
|
const output = m.usage?.output_tokens;
|
|
80
104
|
const cut = !isError && m.stop_reason === 'max_tokens' ? { stopReason: 'length', ...(typeof output === 'number' ? { outputTokens: output } : {}) } : {};
|
|
@@ -120,10 +144,31 @@ export class TranscriptBuilder {
|
|
|
120
144
|
});
|
|
121
145
|
this.call(id, name);
|
|
122
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* A text block of an `assistant` message, said live when none of its text streamed: the CLI asks again without
|
|
149
|
+
* streaming when a streamed request stalls, and that answer comes whole. A message with an id streamed when a delta
|
|
150
|
+
* came under its `message_start`; one with none, when deltas came since the last text block. A whole message's text
|
|
151
|
+
* blocks are one message live, as a streamed one's are.
|
|
152
|
+
*/
|
|
153
|
+
sayUnstreamed(id, text) {
|
|
154
|
+
const streamed = id === undefined ? this.unclaimed : this.streamed.has(id);
|
|
155
|
+
this.unclaimed = false;
|
|
156
|
+
if (streamed)
|
|
157
|
+
return;
|
|
158
|
+
const more = id !== undefined && id === this.wholeId;
|
|
159
|
+
if (this.cutPending || (this.saying && !more))
|
|
160
|
+
this.sink.live({ type: 'text_end' });
|
|
161
|
+
this.cutPending = false;
|
|
162
|
+
this.saying = true;
|
|
163
|
+
this.wholeId = id;
|
|
164
|
+
this.sink.live({ type: 'text', delta: text });
|
|
165
|
+
}
|
|
123
166
|
call(id, name) {
|
|
124
167
|
if (this.written.has(id))
|
|
125
168
|
return;
|
|
126
169
|
this.written.add(id);
|
|
170
|
+
this.saying = false;
|
|
171
|
+
this.wholeId = undefined;
|
|
127
172
|
this.sink.message({ type: 'message', role: 'assistant', text: this.said, toolCalls: [{ id, name }] });
|
|
128
173
|
this.said = '';
|
|
129
174
|
for (const w of this.waiters.get(id) ?? [])
|
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.62",
|
|
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.62"
|
|
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.62"
|
|
81
81
|
}
|
|
82
82
|
}
|