@parcha/agentrun-serve 0.1.0-beta.61 → 0.1.0-beta.63
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 +113 -0
- package/README.md +128 -20
- package/dist/adapters.js +4 -2
- package/dist/agent-delete.d.ts +3 -3
- package/dist/agent-delete.js +50 -4
- package/dist/api-only.d.ts +4 -0
- package/dist/api-only.js +5 -1
- package/dist/archil-settings.d.ts +9 -0
- package/dist/archil-settings.js +8 -1
- package/dist/bash-read-only.d.ts +3 -0
- package/dist/bash-read-only.js +6 -3
- package/dist/chatgpt-plan.d.ts +33 -8
- package/dist/chatgpt-plan.js +141 -24
- package/dist/claude-login.d.ts +12 -5
- package/dist/claude-login.js +28 -3
- package/dist/cli.js +19 -8
- package/dist/composio-triggers.d.ts +9 -3
- package/dist/computers.d.ts +3 -0
- package/dist/computers.js +2 -1
- package/dist/console/assets/{backend-C9ffXUR5.js → backend-BxQ2G1M0.js} +2 -2
- package/dist/console/assets/index-C8Y5Zl8x.js +639 -0
- package/dist/console/assets/share-CjBJ_rxP.js +6 -0
- package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/cut-pool.d.ts +14 -0
- package/dist/cut-pool.js +98 -0
- package/dist/cut-worker.d.ts +14 -0
- package/dist/cut-worker.js +16 -0
- package/dist/decisions.d.ts +4 -0
- package/dist/decisions.js +9 -1
- package/dist/env-switch.d.ts +3 -0
- package/dist/env-switch.js +3 -0
- package/dist/harness-opencode/adapter.d.ts +3 -1
- package/dist/harness-opencode/adapter.js +6 -2
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +6 -1
- package/dist/harness-table.d.ts +7 -0
- package/dist/harness-table.js +6 -3
- package/dist/host-tools.d.ts +18 -3
- package/dist/host-tools.js +27 -4
- package/dist/import.d.ts +8 -1
- package/dist/import.js +36 -5
- package/dist/key-check.js +22 -8
- package/dist/learn/ledger.d.ts +37 -16
- package/dist/learn/ledger.js +56 -24
- package/dist/learn/promote.d.ts +4 -1
- package/dist/learned-nodes.d.ts +2 -1
- package/dist/learned-nodes.js +2 -1
- package/dist/learning-cost.d.ts +5 -3
- package/dist/learning-model.js +7 -5
- package/dist/learning-work.d.ts +69 -0
- package/dist/learning-work.js +148 -0
- package/dist/mcp-gateway.d.ts +24 -0
- package/dist/mcp-gateway.js +97 -8
- package/dist/mcp-servers-store.d.ts +7 -10
- package/dist/mcp-servers-store.js +15 -9
- package/dist/native/cli.js +5 -1
- package/dist/ollama-provider.d.ts +10 -3
- package/dist/ollama-provider.js +17 -7
- package/dist/openapi.js +51 -20
- package/dist/otel/tracer.d.ts +6 -3
- package/dist/otel/tracer.js +24 -6
- package/dist/page.d.ts +7 -0
- package/dist/page.js +17 -4
- package/dist/place.d.ts +25 -9
- package/dist/place.js +37 -11
- package/dist/print.d.ts +3 -2
- package/dist/print.js +8 -6
- package/dist/run-export.js +7 -4
- package/dist/run-launch.d.ts +6 -1
- package/dist/run-launch.js +26 -6
- package/dist/run-model-key.d.ts +2 -1
- package/dist/run-model-key.js +2 -1
- package/dist/run-reads-over-store.d.ts +7 -0
- package/dist/run-reads-over-store.js +32 -4
- package/dist/run-view.js +9 -3
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +21 -11
- package/dist/runner/adapter-loop.js +95 -28
- package/dist/runner/adapter-run-spec.d.ts +20 -4
- package/dist/runner/adapter-run-spec.js +64 -30
- package/dist/runner/adapters/index.d.ts +6 -0
- package/dist/runner/adapters/index.js +5 -1
- package/dist/runner/adapters/pi.d.ts +42 -3
- package/dist/runner/adapters/pi.js +114 -13
- package/dist/runner/audit.d.ts +8 -2
- package/dist/runner/audit.js +34 -18
- package/dist/runner/book-cut.d.ts +6 -0
- package/dist/runner/book-cut.js +38 -0
- package/dist/runner/claim-secrets.d.ts +12 -5
- package/dist/runner/claim-secrets.js +28 -12
- package/dist/runner/cli-run-spec.d.ts +0 -2
- package/dist/runner/cli-run-spec.js +54 -25
- package/dist/runner/dispatch.js +2 -0
- package/dist/runner/harness-loops.d.ts +5 -0
- package/dist/runner/harness-loops.js +4 -1
- package/dist/runner/held.d.ts +6 -3
- package/dist/runner/learned-first.d.ts +5 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +15 -8
- package/dist/runner/learning-end.js +23 -7
- package/dist/runner/live-ticker.js +3 -1
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/main.js +2 -0
- package/dist/runner/mcp-run.d.ts +5 -0
- package/dist/runner/mcp-run.js +18 -0
- package/dist/runner/meta-tools.js +4 -4
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +5 -3
- package/dist/runner/model-route.d.ts +4 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/native-loop.js +2 -2
- package/dist/runner/pr-checkout.d.ts +12 -0
- package/dist/runner/pr-checkout.js +21 -2
- package/dist/runner/promotion.d.ts +9 -2
- package/dist/runner/promotion.js +79 -28
- package/dist/runner/reflect-hook.d.ts +7 -0
- package/dist/runner/reflect-hook.js +2 -1
- package/dist/runner/run-child-host.d.ts +10 -6
- package/dist/runner/run-child-host.js +65 -41
- package/dist/runner/run-child.js +2 -0
- package/dist/runner/runner.d.ts +9 -0
- package/dist/runner/runner.js +158 -25
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/workflow-calls.d.ts +4 -3
- package/dist/runner/workflow-calls.js +41 -12
- package/dist/runner/workflow-first.js +4 -3
- package/dist/runner/workflow-loop.js +13 -1
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/secret-cut.d.ts +4 -0
- package/dist/secret-cut.js +1 -1
- package/dist/secret-rules.d.ts +2 -1
- package/dist/secret-rules.js +88 -24
- package/dist/server.d.ts +10 -1
- package/dist/server.js +131 -44
- package/dist/share-host.d.ts +111 -0
- package/dist/share-host.js +669 -0
- package/dist/store/schema.d.ts +4 -3
- package/dist/store/schema.js +4 -3
- package/dist/store/seal.d.ts +8 -2
- package/dist/store/seal.js +13 -2
- package/dist/store/sqlite/learning-rows.js +2 -1
- package/dist/store/sqlite/run-patch.js +4 -4
- package/dist/store/sqlite/store.js +28 -4
- package/dist/store/store.d.ts +5 -0
- package/dist/store-reads/analytics.d.ts +15 -0
- package/dist/store-reads/analytics.js +17 -0
- package/dist/store-reads/journal.d.ts +2 -0
- package/dist/store-reads/journal.js +1 -1
- package/dist/store-reads/learning.d.ts +4 -3
- package/dist/store-reads/learning.js +62 -18
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +18 -1
- package/dist/suggestions.js +32 -3
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +7 -3
- package/dist/tool-gate.d.ts +25 -9
- package/dist/tool-gate.js +58 -19
- package/dist/tool-list.d.ts +4 -0
- package/dist/tool-list.js +4 -0
- package/dist/tool-plane.d.ts +1 -0
- package/dist/tool-plane.js +6 -2
- package/dist/tools.js +2 -2
- package/dist/trigger-composio.js +1 -1
- package/dist/webhooks.d.ts +3 -0
- package/dist/webhooks.js +5 -0
- package/dist/workspace/archil-claim.d.ts +7 -3
- package/dist/workspace/archil-claim.js +13 -5
- package/dist/workspace/archil-mount-credential.d.ts +6 -0
- package/dist/workspace/archil-mount-credential.js +11 -0
- package/dist/workspace/attach.js +22 -5
- package/dist/workspace/computer-deps.d.ts +5 -3
- package/dist/workspace/computer-deps.js +11 -9
- package/dist/workspace/computer-for-claim.d.ts +6 -2
- package/dist/workspace/computer-for-claim.js +43 -12
- package/dist/workspace/computer-janitor.d.ts +7 -4
- package/dist/workspace/computer-janitor.js +7 -4
- package/dist/workspace/computer-kept.d.ts +7 -1
- package/dist/workspace/computer-kept.js +7 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +17 -4
- package/dist/workspace/mount-revoke-left.d.ts +16 -4
- package/dist/workspace/mount-revoke-left.js +42 -22
- package/dist/workspace/resolve-computer.d.ts +11 -5
- package/dist/workspace/resolve-computer.js +22 -13
- package/dist/workspace/run-end-computers.js +1 -1
- package/dist/workspace/run-tools.d.ts +10 -3
- package/dist/workspace/run-tools.js +5 -4
- package/dist/wrapped.d.ts +29 -2
- package/dist/wrapped.js +20 -3
- package/launcher/agentrun-serve +1 -1
- package/package.json +12 -12
- package/templates/kyb/agent.md +7 -1
- package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
- package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
- package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
- package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
- package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
- package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
- package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
- package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
- package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
- package/templates/kyb/kyb.schema.json +2 -2
- package/templates/kyb/rules/SANCTIONS.md +82 -13
- package/dist/console/assets/index-BnZV3lvW.js +0 -639
- package/dist/console/assets/share-B1o5mJ56.js +0 -6
- /package/dist/console/assets/{styles-D_znYrHR.js → styles-BGZxYkky.js} +0 -0
package/dist/api-only.js
CHANGED
|
@@ -17,6 +17,10 @@ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-ho
|
|
|
17
17
|
* - a backend reads what its agents learned (loop, promotions, audits, cost per run, a run's learning), cut as the
|
|
18
18
|
* console's, and resets it (deleteAgentLearning: the agent and its runs kept) when it erases what an agent learned;
|
|
19
19
|
* - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is;
|
|
20
|
+
* - a backend shares a run it ran (getRunExport, run-export.ts): an ended run's agentrun.share/1 bundle, every string
|
|
21
|
+
* cut by the scrubber as on the full server, its ?restore= a stateless re-export of cuts a preview may restore. A
|
|
22
|
+
* workflow run's bundle carries its graph, cut, though getRunGraph stays refused here; the share page (/share/{run})
|
|
23
|
+
* is the console's, refused with the rest of it;
|
|
20
24
|
* - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart;
|
|
21
25
|
* - a backend reads the saved MCP servers' names (listMcpServerNames), never a URL or a credential;
|
|
22
26
|
* - a backend uploads an agent's package (importTemplate, as {files} alone: a GitHub source is refused in this profile's
|
|
@@ -52,7 +56,7 @@ export const API_ONLY_ROUTES = new Set([
|
|
|
52
56
|
"getLearningLoop", "listLearningPromotions", "listLearningAudits", "getLearningCost", "getRunLearning",
|
|
53
57
|
"getRun", "getRunUsage", "listRuns", "listAllRuns", "getTimeline",
|
|
54
58
|
"sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
|
|
55
|
-
"listRunFiles", "readRunFile",
|
|
59
|
+
"listRunFiles", "readRunFile", "getRunExport",
|
|
56
60
|
"createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
|
|
57
61
|
"getCapabilities", "getHealth", "getUsage", "getCapacity", "listMcpServerNames",
|
|
58
62
|
"importTemplate", "applyTemplate", "getAgent", "listRevisions", "setCurrent", "archiveAgent", "unarchiveAgent",
|
|
@@ -68,6 +68,15 @@ export declare function saveArchilSettings(store: {
|
|
|
68
68
|
export declare function clearArchilSettings(store: {
|
|
69
69
|
settings: Pick<Settings, "remove">;
|
|
70
70
|
}): Promise<void>;
|
|
71
|
+
/** The Archil region of a Mode 2 server (its settings, `archil`) where the region has no serverless exec
|
|
72
|
+
* (archil-mount-credential.ts archilHasExec): a run there with no computer that mounts its folder has no shell
|
|
73
|
+
* (resolve-computer.ts shellPlaceOf). Undefined in Mode 1 (`archil` undefined) and where the region has exec. */
|
|
74
|
+
export declare const noExecRegionOf: (archil: {
|
|
75
|
+
readonly region: string;
|
|
76
|
+
} | undefined) => string | undefined;
|
|
77
|
+
/** Why a run with no computer has no shell on a Mode 2 server whose Archil region `region` has no serverless exec
|
|
78
|
+
* (noExecRegionOf), in the words each refusal and note of it starts from. */
|
|
79
|
+
export declare const noExecWords: (region: string) => string;
|
|
71
80
|
/** Whether the server is in Mode 2 (the Archil settings are set, in `env` or saved). */
|
|
72
81
|
export declare function inArchilMode(store: {
|
|
73
82
|
settings: Pick<Settings, "get">;
|
package/dist/archil-settings.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { createHash, randomBytes } from "node:crypto";
|
|
13
13
|
import { envValue } from "./key-meta.js";
|
|
14
14
|
import { pinnedImage } from "./workspace/archil-disk.js";
|
|
15
|
-
import { ARCHIL_CONTROL_URLS } from "./workspace/archil-mount-credential.js";
|
|
15
|
+
import { ARCHIL_CONTROL_URLS, archilHasExec } from "./workspace/archil-mount-credential.js";
|
|
16
16
|
/** The settings key the Archil configuration lives under in store.settings. */
|
|
17
17
|
export const ARCHIL_SETTINGS_KEY = "archil";
|
|
18
18
|
/** The sealed-key row of the Archil account key (the file API and exec), saved through server-keys.ts. Named *_ROW: a
|
|
@@ -126,6 +126,13 @@ export async function saveArchilSettings(store, settings) {
|
|
|
126
126
|
export async function clearArchilSettings(store) {
|
|
127
127
|
await store.settings.remove(ARCHIL_SETTINGS_KEY);
|
|
128
128
|
}
|
|
129
|
+
/** The Archil region of a Mode 2 server (its settings, `archil`) where the region has no serverless exec
|
|
130
|
+
* (archil-mount-credential.ts archilHasExec): a run there with no computer that mounts its folder has no shell
|
|
131
|
+
* (resolve-computer.ts shellPlaceOf). Undefined in Mode 1 (`archil` undefined) and where the region has exec. */
|
|
132
|
+
export const noExecRegionOf = (archil) => (archil !== undefined && !archilHasExec(archil.region) ? archil.region : undefined);
|
|
133
|
+
/** Why a run with no computer has no shell on a Mode 2 server whose Archil region `region` has no serverless exec
|
|
134
|
+
* (noExecRegionOf), in the words each refusal and note of it starts from. */
|
|
135
|
+
export const noExecWords = (region) => `this server's Archil region ${region} has no serverless exec`;
|
|
129
136
|
/** Whether the server is in Mode 2 (the Archil settings are set, in `env` or saved). */
|
|
130
137
|
export async function inArchilMode(store, env = {}) {
|
|
131
138
|
return (await loadArchilSettings(store, env)) !== undefined;
|
package/dist/bash-read-only.d.ts
CHANGED
|
@@ -30,6 +30,9 @@ export type Folder = readonly string[];
|
|
|
30
30
|
/** Throws, with the reason, unless `command` is a read-only command line run from `folder`'s first name (relative to the
|
|
31
31
|
* folder: `start`, "" for the folder itself). */
|
|
32
32
|
export declare function checkReadOnly(command: string, folder: Folder, start?: string): void;
|
|
33
|
+
/** Why the read-only policy refuses every call of shell tool `tool`, whatever its arguments (a shell tool but bash and
|
|
34
|
+
* the watchers), or undefined for one whose call it reads: bash, whose command decides (readOnlyReason). */
|
|
35
|
+
export declare function readOnlyToolReason(tool: string): string | undefined;
|
|
33
36
|
/** Why the read-only policy refuses shell tool `tool`'s call with `args`, or undefined when it may go on to the gate's
|
|
34
37
|
* permission. `folder`: the run's folder by its names (the first is where a command starts). */
|
|
35
38
|
export declare function readOnlyReason(tool: string, args: unknown, folder: Folder): string | undefined;
|
package/dist/bash-read-only.js
CHANGED
|
@@ -755,13 +755,16 @@ function commandOf(args, folder) {
|
|
|
755
755
|
}
|
|
756
756
|
return { reason: "it carries no command this policy can read" };
|
|
757
757
|
}
|
|
758
|
+
/** Why the read-only policy refuses every call of shell tool `tool`, whatever its arguments (a shell tool but bash and
|
|
759
|
+
* the watchers), or undefined for one whose call it reads: bash, whose command decides (readOnlyReason). */
|
|
760
|
+
export function readOnlyToolReason(tool) {
|
|
761
|
+
return tool === "bash" || WATCHERS.has(tool) ? undefined : `${tool} is not offered: a read-only shell runs one command at a time, in the foreground, with bash`;
|
|
762
|
+
}
|
|
758
763
|
/** Why the read-only policy refuses shell tool `tool`'s call with `args`, or undefined when it may go on to the gate's
|
|
759
764
|
* permission. `folder`: the run's folder by its names (the first is where a command starts). */
|
|
760
765
|
export function readOnlyReason(tool, args, folder) {
|
|
761
|
-
if (WATCHERS.has(tool))
|
|
762
|
-
return undefined;
|
|
763
766
|
if (tool !== "bash")
|
|
764
|
-
return
|
|
767
|
+
return readOnlyToolReason(tool);
|
|
765
768
|
const read = commandOf(args, folder);
|
|
766
769
|
if ("reason" in read)
|
|
767
770
|
return read.reason;
|
package/dist/chatgpt-plan.d.ts
CHANGED
|
@@ -62,7 +62,8 @@ export declare function signInFailure(error: unknown): {
|
|
|
62
62
|
words: string;
|
|
63
63
|
};
|
|
64
64
|
export interface ChatGPTPlanDeps {
|
|
65
|
-
/** `settings`: where a server keeps its host id, for a sign-in
|
|
65
|
+
/** `settings`: where a server keeps its host id, for a sign-in. A runner's reader may be given a store with settings
|
|
66
|
+
* too (its whole store): it never signs in, and never settles (settleLeft). */
|
|
66
67
|
readonly store: {
|
|
67
68
|
readonly sealedKeys: Pick<SealedKeys, "get" | "put" | "replaceIf" | "removeIf" | "clock">;
|
|
68
69
|
readonly settings?: Pick<Settings, "putIfAbsent">;
|
|
@@ -103,15 +104,23 @@ export declare class ChatGPTPlan implements PlanReader {
|
|
|
103
104
|
private readTaken;
|
|
104
105
|
/** `row` as the snapshot, by a write that knows it is the row's latest (a sign-in kept, a renewal, a sign-out). */
|
|
105
106
|
private wrote;
|
|
106
|
-
/** The row sealed as `bytes`, opened (its tokens held for redaction); none when they
|
|
107
|
+
/** The row sealed as `bytes`, opened (its tokens held for redaction, and those of each pair it carries); none when they
|
|
108
|
+
* do not open. */
|
|
107
109
|
private open;
|
|
108
110
|
/** `row` sealed as the store keeps it: fresh bytes at each seal. */
|
|
109
111
|
private seal;
|
|
110
112
|
/** `row` saved only while the store still holds `was` (SealedKeys.replaceIf): the bytes it was saved as, or none when
|
|
111
113
|
* the row had changed. */
|
|
112
114
|
private swap;
|
|
113
|
-
/** Reads the sealed row into the state a reader sees. Returns this. */
|
|
115
|
+
/** Reads the sealed row into the state a reader sees. Returns this. A read never settles (settleLeft). */
|
|
114
116
|
load(): Promise<this>;
|
|
117
|
+
/** What a stop left in the row (a sign-in it cut off after its save: keep) settled, out of the caller's way: the
|
|
118
|
+
* server's, at its start once its first offers are made, and at a read of a row a reader renewed while it was still
|
|
119
|
+
* unlisted (refresh). Models it lists are told to the server (its change
|
|
120
|
+
* callback, as a sign-in's are), so the offers made from the fallback list are made again. A runner's reader
|
|
121
|
+
* (planReaderOf, at each claim) never calls it, so no runner lists the plan's models or sends a refresh token to
|
|
122
|
+
* OpenAI's revocation endpoint. */
|
|
123
|
+
settleLeft(): void;
|
|
115
124
|
view(): PlanView;
|
|
116
125
|
/** This server's id at OpenAI (its agent host id): a UUID made once and kept in the store's settings. Not a credential. */
|
|
117
126
|
private hostId;
|
|
@@ -130,10 +139,20 @@ export declare class ChatGPTPlan implements PlanReader {
|
|
|
130
139
|
* is refused in words and the sign-in keeps waiting; one OpenAI refuses ends it. */
|
|
131
140
|
finishSignIn(redirectUrl: unknown): Promise<PlanView>;
|
|
132
141
|
/** A credential from the sign-in started at `epoch`, checked and sealed with what a view shows. A sign-out or a newer
|
|
133
|
-
* sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI.
|
|
134
|
-
*
|
|
135
|
-
*
|
|
142
|
+
* sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI. It is saved before anything
|
|
143
|
+
* slow, so a stop that cuts it off never leaves its pair live at OpenAI and saved nowhere: a sign-in it takes the place
|
|
144
|
+
* of rides in the row (`retired`, with any it carried) until it is revoked, and its models are listed after (settle).
|
|
145
|
+
* The row is replaced only while it still holds what was read (a renewal that wrote back meanwhile is read and carried
|
|
146
|
+
* in turn), so no earlier pair is left alive and unsaved. */
|
|
136
147
|
private keep;
|
|
148
|
+
/** What a saved sign-in leaves (keep), done: its models listed (`unlisted`), and each pair it carries (`retired`)
|
|
149
|
+
* revoked at OpenAI and dropped from the row once OpenAI confirms it. `revoked`: whether every carried pair was
|
|
150
|
+
* confirmed, none when the row carried none; `listed`: whether it wrote the models OpenAI listed. The server's alone,
|
|
151
|
+
* one at a time: only a sign-in (keep) and the server's start (settleLeft) settle, and a runner does neither. The row
|
|
152
|
+
* is written only while it holds what was read and no renewal's lease is live (a renewal writes back over the row it
|
|
153
|
+
* leased, and carries these fields); what is left stays for the server's next start. Never throws. */
|
|
154
|
+
private settle;
|
|
155
|
+
private settleOnce;
|
|
137
156
|
/** Tells the server the sign-in changed (its change callback: env read again, the listings relisted, the offers
|
|
138
157
|
* probed). What the server does with it is not the change's to fail: a failure is owed, said in the log (once: not
|
|
139
158
|
* again for `again`, a retry of one owed), and taken again at the server's next read (refresh). */
|
|
@@ -143,8 +162,8 @@ export declare class ChatGPTPlan implements PlanReader {
|
|
|
143
162
|
* what it offers does not wait for a restart. One at a time: a read while one is out waits for that one (the console
|
|
144
163
|
* polls, and each change relists and probes). */
|
|
145
164
|
refresh(): Promise<void>;
|
|
146
|
-
/** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families
|
|
147
|
-
* list when it can't be read
|
|
165
|
+
/** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families (the fallback
|
|
166
|
+
* list when it names none); none when the list can't be read, so the row stays `unlisted`. */
|
|
148
167
|
private listModels;
|
|
149
168
|
/** The access token to send now: the sealed one, renewed first when it ends within 5 minutes. Throws PlanUnavailable,
|
|
150
169
|
* in words, when there is none. */
|
|
@@ -165,6 +184,12 @@ export declare class ChatGPTPlan implements PlanReader {
|
|
|
165
184
|
/** The renewal itself, under this holder's lease on `row` (sealed as `bytes`). Every write back is a compare-and-set
|
|
166
185
|
* against the leased row, so a sign-out or a new sign-in meanwhile is never overwritten: ours is dropped. */
|
|
167
186
|
private renewUnder;
|
|
187
|
+
/** A pair this holder got and could not save (a renewal whose write back lost: renewUnder), whose revocation OpenAI
|
|
188
|
+
* didn't confirm: carried in the row (`retired`), for the server's next settle to revoke, as a replaced sign-in's pair
|
|
189
|
+
* is (keep). Never written over another holder's live lease (its write back would lose in turn): it waits for that
|
|
190
|
+
* write back, or for the lease to lapse, as a renewal waits on one (renew), and gives up only past that bound, said in
|
|
191
|
+
* the log. None with no row (a sign-out says OpenAI's word is not the whole answer while a renewal is out). */
|
|
192
|
+
private carry;
|
|
168
193
|
/** After a renewal whose write back lost its compare-and-set (the owner signed out or in again meanwhile): its result
|
|
169
194
|
* is dropped, and the row's state wins. */
|
|
170
195
|
private adopt;
|
package/dist/chatgpt-plan.js
CHANGED
|
@@ -206,8 +206,16 @@ export class ChatGPTPlan {
|
|
|
206
206
|
#failedChanges = 0;
|
|
207
207
|
/** The server's read in flight (refresh), which a read while it is out waits for. */
|
|
208
208
|
#refreshing;
|
|
209
|
-
/** The
|
|
209
|
+
/** The last settle queued (settle): each waits for the one before it. */
|
|
210
|
+
#settling;
|
|
211
|
+
/** The ends of the sign-ins cancelled and not yet ended, and the start's settle with the change it tells (settleLeft):
|
|
212
|
+
* close waits for them. */
|
|
210
213
|
#ending = new Set();
|
|
214
|
+
/** Set by close(): no read queues a settle after it, so none outlives the server's stop. */
|
|
215
|
+
#closed = false;
|
|
216
|
+
/** When a read last queued a settle (refresh): a list OpenAI keeps failing is asked again at most once a minute,
|
|
217
|
+
* however often the console reads. */
|
|
218
|
+
#readSettledAt = -Infinity;
|
|
211
219
|
#watchers = new Set();
|
|
212
220
|
#deps;
|
|
213
221
|
constructor(deps) {
|
|
@@ -275,13 +283,16 @@ export class ChatGPTPlan {
|
|
|
275
283
|
this.#snapshot = row;
|
|
276
284
|
this.#writes += 1;
|
|
277
285
|
}
|
|
278
|
-
/** The row sealed as `bytes`, opened (its tokens held for redaction); none when they
|
|
286
|
+
/** The row sealed as `bytes`, opened (its tokens held for redaction, and those of each pair it carries); none when they
|
|
287
|
+
* do not open. */
|
|
279
288
|
open(bytes) {
|
|
280
289
|
try {
|
|
281
290
|
const row = JSON.parse(unsealColumn(this.#deps.sealKey, sealedAt.sealedKey(CHATGPT_PLAN_ROW), bytes).toString("utf8"));
|
|
282
291
|
if (row?.v !== 1 || !row.credential?.access || !row.credential.refresh)
|
|
283
292
|
return undefined;
|
|
284
293
|
this.hold(row.credential);
|
|
294
|
+
for (const old of row.retired ?? [])
|
|
295
|
+
this.hold(old);
|
|
285
296
|
return row;
|
|
286
297
|
}
|
|
287
298
|
catch {
|
|
@@ -298,11 +309,23 @@ export class ChatGPTPlan {
|
|
|
298
309
|
const bytes = this.seal(row);
|
|
299
310
|
return (await this.#deps.store.sealedKeys.replaceIf(CHATGPT_PLAN_ROW, was, bytes)) ? bytes : undefined;
|
|
300
311
|
}
|
|
301
|
-
/** Reads the sealed row into the state a reader sees. Returns this. */
|
|
312
|
+
/** Reads the sealed row into the state a reader sees. Returns this. A read never settles (settleLeft). */
|
|
302
313
|
async load() {
|
|
303
314
|
await this.readTaken();
|
|
304
315
|
return this;
|
|
305
316
|
}
|
|
317
|
+
/** What a stop left in the row (a sign-in it cut off after its save: keep) settled, out of the caller's way: the
|
|
318
|
+
* server's, at its start once its first offers are made, and at a read of a row a reader renewed while it was still
|
|
319
|
+
* unlisted (refresh). Models it lists are told to the server (its change
|
|
320
|
+
* callback, as a sign-in's are), so the offers made from the fallback list are made again. A runner's reader
|
|
321
|
+
* (planReaderOf, at each claim) never calls it, so no runner lists the plan's models or sends a refresh token to
|
|
322
|
+
* OpenAI's revocation endpoint. */
|
|
323
|
+
settleLeft() {
|
|
324
|
+
// Its change callback is waited for by close(), as the settle is: the server never closes under a change it owes.
|
|
325
|
+
const told = this.settle().then(({ listed }) => (listed ? this.tellChanged() : undefined));
|
|
326
|
+
this.#ending.add(told);
|
|
327
|
+
void told.then(() => this.#ending.delete(told));
|
|
328
|
+
}
|
|
306
329
|
view() {
|
|
307
330
|
if (this.#pending && this.#pending.expiresAt <= this.now())
|
|
308
331
|
this.expire();
|
|
@@ -456,16 +479,16 @@ export class ChatGPTPlan {
|
|
|
456
479
|
return this.view();
|
|
457
480
|
}
|
|
458
481
|
/** A credential from the sign-in started at `epoch`, checked and sealed with what a view shows. A sign-out or a newer
|
|
459
|
-
* sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI.
|
|
460
|
-
*
|
|
461
|
-
*
|
|
482
|
+
* sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI. It is saved before anything
|
|
483
|
+
* slow, so a stop that cuts it off never leaves its pair live at OpenAI and saved nowhere: a sign-in it takes the place
|
|
484
|
+
* of rides in the row (`retired`, with any it carried) until it is revoked, and its models are listed after (settle).
|
|
485
|
+
* The row is replaced only while it still holds what was read (a renewal that wrote back meanwhile is read and carried
|
|
486
|
+
* in turn), so no earlier pair is left alive and unsaved. */
|
|
462
487
|
async keep(credential, epoch, saved) {
|
|
463
488
|
if (credential.scopes && !credential.scopes.includes(DIRECT_SCOPE))
|
|
464
489
|
throw new Error(`the grant did not include ${DIRECT_SCOPE}`);
|
|
465
490
|
this.hold(credential);
|
|
466
|
-
|
|
467
|
-
const row = { v: 1, state: "signed_in", credential, ...whoOf(credential.access), models };
|
|
468
|
-
let previousRevoked;
|
|
491
|
+
let row;
|
|
469
492
|
for (;;) {
|
|
470
493
|
if (epoch !== this.#epoch) {
|
|
471
494
|
if (!(await this.revoke(credential)))
|
|
@@ -473,27 +496,79 @@ export class ChatGPTPlan {
|
|
|
473
496
|
return;
|
|
474
497
|
}
|
|
475
498
|
const was = await this.#deps.store.sealedKeys.get(CHATGPT_PLAN_ROW);
|
|
499
|
+
const previous = was === undefined ? undefined : this.open(was);
|
|
500
|
+
const retired = [...(previous?.retired ?? []), ...(previous && previous.credential.refresh !== credential.refresh ? [previous.credential] : [])];
|
|
501
|
+
row = { v: 1, state: "signed_in", credential, ...whoOf(credential.access), models: [...PLAN_FALLBACK_MODELS], unlisted: true, ...(retired.length ? { retired } : {}) };
|
|
502
|
+
if (epoch !== this.#epoch)
|
|
503
|
+
continue;
|
|
476
504
|
if (was === undefined) {
|
|
477
505
|
// No row to compare against: only the server signs in, and nothing else makes the row (a runner's renewal
|
|
478
506
|
// replaces one only while it holds its lease), so a plain write.
|
|
479
507
|
await putSealedKey(this.#deps.store, this.#deps.sealKey, CHATGPT_PLAN_ROW, JSON.stringify(row));
|
|
480
508
|
break;
|
|
481
509
|
}
|
|
482
|
-
const previous = this.open(was);
|
|
483
|
-
if (previous && previous.credential.refresh !== credential.refresh)
|
|
484
|
-
previousRevoked = await this.revoke(previous.credential);
|
|
485
|
-
if (epoch !== this.#epoch)
|
|
486
|
-
continue;
|
|
487
510
|
if (await this.swap(was, row))
|
|
488
511
|
break;
|
|
489
512
|
}
|
|
490
513
|
this.wrote(row);
|
|
491
514
|
this.#problem = undefined;
|
|
492
|
-
this.#deps.log?.({ chatgpt: "signed_in"
|
|
493
|
-
// Saved: no longer waiting, so it reads signed in while the server takes the change (`saved`, the
|
|
515
|
+
this.#deps.log?.({ chatgpt: "signed_in" });
|
|
516
|
+
// Saved: no longer waiting, so it reads signed in while it settles and the server takes the change (`saved`, the
|
|
517
|
+
// sign-in's settle).
|
|
494
518
|
saved?.();
|
|
519
|
+
const { revoked: previousRevoked } = await this.settle();
|
|
520
|
+
if (previousRevoked !== undefined)
|
|
521
|
+
this.#deps.log?.({ chatgpt: "previous_revoked", revoked: String(previousRevoked) });
|
|
495
522
|
await this.tellChanged();
|
|
496
523
|
}
|
|
524
|
+
/** What a saved sign-in leaves (keep), done: its models listed (`unlisted`), and each pair it carries (`retired`)
|
|
525
|
+
* revoked at OpenAI and dropped from the row once OpenAI confirms it. `revoked`: whether every carried pair was
|
|
526
|
+
* confirmed, none when the row carried none; `listed`: whether it wrote the models OpenAI listed. The server's alone,
|
|
527
|
+
* one at a time: only a sign-in (keep) and the server's start (settleLeft) settle, and a runner does neither. The row
|
|
528
|
+
* is written only while it holds what was read and no renewal's lease is live (a renewal writes back over the row it
|
|
529
|
+
* leased, and carries these fields); what is left stays for the server's next start. Never throws. */
|
|
530
|
+
settle() {
|
|
531
|
+
const run = (this.#settling ?? Promise.resolve({})).then(() => this.settleOnce()).catch(() => ({}));
|
|
532
|
+
this.#settling = run;
|
|
533
|
+
void run.then(() => (this.#settling === run ? (this.#settling = undefined) : undefined));
|
|
534
|
+
return run;
|
|
535
|
+
}
|
|
536
|
+
async settleOnce() {
|
|
537
|
+
const read = await this.readSealed();
|
|
538
|
+
if (!read || (!read.row.unlisted && !read.row.retired?.length))
|
|
539
|
+
return {};
|
|
540
|
+
const signedIn = read.row.credential.refresh;
|
|
541
|
+
// The list is asked only with a token OpenAI takes (fresh). One that has ended is never renewed here: a renewal can
|
|
542
|
+
// outlast the server's stop, which would spend the refresh token and lose the new pair with the store closed. The row
|
|
543
|
+
// stays unlisted, and the first settle after a reader renewed it (a run's token()) lists.
|
|
544
|
+
const models = read.row.unlisted && read.row.state === "signed_in" && this.fresh(read.row) ? await this.listModels(read.row.credential.access) : undefined;
|
|
545
|
+
const confirmed = new Set();
|
|
546
|
+
for (const old of read.row.retired ?? [])
|
|
547
|
+
if (await this.revoke(old))
|
|
548
|
+
confirmed.add(old.refresh);
|
|
549
|
+
const revoked = read.row.retired?.length ? confirmed.size === read.row.retired.length : undefined;
|
|
550
|
+
const done = revoked === undefined ? {} : { revoked };
|
|
551
|
+
for (;;) {
|
|
552
|
+
const now = await this.readSealed();
|
|
553
|
+
// Signed out meanwhile: the sign-out revoked what the row held.
|
|
554
|
+
if (!now)
|
|
555
|
+
return done;
|
|
556
|
+
if (now.row.lease && now.row.lease.until > (await this.storeNow()))
|
|
557
|
+
return done;
|
|
558
|
+
const { unlisted, retired: carried, ...rest } = now.row;
|
|
559
|
+
const retired = (carried ?? []).filter((old) => !confirmed.has(old.refresh));
|
|
560
|
+
// The models listed are this sign-in's: a newer sign-in's row lists its own.
|
|
561
|
+
const listed = Boolean(unlisted && models && now.row.credential.refresh === signedIn);
|
|
562
|
+
const next = { ...rest, ...(listed && models ? { models } : unlisted ? { unlisted } : {}), ...(retired.length ? { retired } : {}) };
|
|
563
|
+
if (!listed && retired.length === (carried ?? []).length)
|
|
564
|
+
return done;
|
|
565
|
+
const bytes = await this.swap(now.bytes, next);
|
|
566
|
+
if (bytes) {
|
|
567
|
+
this.wrote(next);
|
|
568
|
+
return { ...done, listed };
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
497
572
|
/** Tells the server the sign-in changed (its change callback: env read again, the listings relisted, the offers
|
|
498
573
|
* probed). What the server does with it is not the change's to fail: a failure is owed, said in the log (once: not
|
|
499
574
|
* again for `again`, a retry of one owed), and taken again at the server's next read (refresh). */
|
|
@@ -526,21 +601,29 @@ export class ChatGPTPlan {
|
|
|
526
601
|
await this.tellChanged();
|
|
527
602
|
else if (this.#changeOwed)
|
|
528
603
|
await this.tellChanged(true);
|
|
604
|
+
// A row still on the fallback list whose token a reader renewed lists now, not at the next start: a settle queued
|
|
605
|
+
// as the start's is (settleLeft), with the token as read and no renewal, one at a time, at most once a minute, none
|
|
606
|
+
// after close().
|
|
607
|
+
const row = this.#snapshot;
|
|
608
|
+
if (row?.unlisted && row.state === "signed_in" && this.fresh(row) && !this.#settling && !this.#closed && this.now() - this.#readSettledAt >= 60_000) {
|
|
609
|
+
this.#readSettledAt = this.now();
|
|
610
|
+
this.settleLeft();
|
|
611
|
+
}
|
|
529
612
|
})().finally(() => (this.#refreshing = undefined)));
|
|
530
613
|
}
|
|
531
|
-
/** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families
|
|
532
|
-
* list when it can't be read
|
|
614
|
+
/** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families (the fallback
|
|
615
|
+
* list when it names none); none when the list can't be read, so the row stays `unlisted`. */
|
|
533
616
|
async listModels(token) {
|
|
534
617
|
try {
|
|
535
618
|
const response = await fetch(`${PLAN_ORIGIN}/v1/models`, { headers: { authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(5_000) });
|
|
536
619
|
if (!response.ok)
|
|
537
|
-
return
|
|
620
|
+
return undefined;
|
|
538
621
|
const body = (await response.json());
|
|
539
622
|
const ids = (body.data ?? []).map((model) => model.id).filter((id) => typeof id === "string" && /^gpt-6(?:[.-]|$)/.test(id));
|
|
540
623
|
return ids.length ? [...new Set(ids)] : [...PLAN_FALLBACK_MODELS];
|
|
541
624
|
}
|
|
542
625
|
catch {
|
|
543
|
-
return
|
|
626
|
+
return undefined;
|
|
544
627
|
}
|
|
545
628
|
}
|
|
546
629
|
/** The access token to send now: the sealed one, renewed first when it ends within 5 minutes. Throws PlanUnavailable,
|
|
@@ -644,10 +727,37 @@ export class ChatGPTPlan {
|
|
|
644
727
|
return renewed.credential.access;
|
|
645
728
|
}
|
|
646
729
|
// The owner signed out or in again while OpenAI renewed it: the new pair is the sign-in's no longer, and no one
|
|
647
|
-
// holds it but this renewal, so it is revoked here, never handed out.
|
|
648
|
-
await this.revoke(renewed.credential)
|
|
730
|
+
// holds it but this renewal, so it is revoked here, never handed out. One OpenAI doesn't confirm is carried.
|
|
731
|
+
if (!(await this.revoke(renewed.credential)))
|
|
732
|
+
await this.carry(renewed.credential);
|
|
649
733
|
return this.adopt();
|
|
650
734
|
}
|
|
735
|
+
/** A pair this holder got and could not save (a renewal whose write back lost: renewUnder), whose revocation OpenAI
|
|
736
|
+
* didn't confirm: carried in the row (`retired`), for the server's next settle to revoke, as a replaced sign-in's pair
|
|
737
|
+
* is (keep). Never written over another holder's live lease (its write back would lose in turn): it waits for that
|
|
738
|
+
* write back, or for the lease to lapse, as a renewal waits on one (renew), and gives up only past that bound, said in
|
|
739
|
+
* the log. None with no row (a sign-out says OpenAI's word is not the whole answer while a renewal is out). */
|
|
740
|
+
async carry(credential) {
|
|
741
|
+
const giveUp = this.now() + REFRESH_LEASE_MS + REFRESH_CALL_MS;
|
|
742
|
+
for (;;) {
|
|
743
|
+
const now = await this.readSealed();
|
|
744
|
+
if (!now)
|
|
745
|
+
return;
|
|
746
|
+
if (now.row.lease && now.row.lease.until > (await this.storeNow())) {
|
|
747
|
+
if (this.now() > giveUp) {
|
|
748
|
+
this.#deps.log?.({ chatgpt: "renewed_pair_unsaved" });
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
await sleep(LEASE_WAIT_MS);
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
const next = { ...now.row, retired: [...(now.row.retired ?? []), credential] };
|
|
755
|
+
if (await this.swap(now.bytes, next)) {
|
|
756
|
+
this.wrote(next);
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
}
|
|
651
761
|
/** After a renewal whose write back lost its compare-and-set (the owner signed out or in again meanwhile): its result
|
|
652
762
|
* is dropped, and the row's state wins. */
|
|
653
763
|
async adopt() {
|
|
@@ -686,7 +796,11 @@ export class ChatGPTPlan {
|
|
|
686
796
|
continue;
|
|
687
797
|
// A row that does not open (sealed under another key) is removed, its tokens beyond reach to revoke.
|
|
688
798
|
const removed = row ? (await this.revoke(row.credential)) && !renewing : false;
|
|
689
|
-
|
|
799
|
+
// The pairs of the sign-ins it replaced that it still carries (keep, settle) go with it.
|
|
800
|
+
let carried = true;
|
|
801
|
+
for (const old of row?.retired ?? [])
|
|
802
|
+
carried = (await this.revoke(old)) && carried;
|
|
803
|
+
revoked = revoked && removed && carried;
|
|
690
804
|
break;
|
|
691
805
|
}
|
|
692
806
|
this.wrote(undefined);
|
|
@@ -713,8 +827,11 @@ export class ChatGPTPlan {
|
|
|
713
827
|
/** Stops the sign-in waiting, at the server's close. Resolves once every sign-in cancelled (by this, a newer start, a
|
|
714
828
|
* sign-out or its 10 minutes) has ended, whatever its end said in the log. */
|
|
715
829
|
close() {
|
|
830
|
+
this.#closed = true;
|
|
716
831
|
this.cancel();
|
|
717
|
-
|
|
832
|
+
// A settle out (the start's, a kept sign-in's) is waited for too: the server's stop bounds the wait (planClosed), and
|
|
833
|
+
// what it cuts off stays in the row for the next start.
|
|
834
|
+
return Promise.all([...this.#ending, this.#settling]).then(() => undefined);
|
|
718
835
|
}
|
|
719
836
|
}
|
|
720
837
|
/** For a run on a plan model (`model`, the one its claim chose): the plan's token read once before anything starts, so a
|
package/dist/claude-login.d.ts
CHANGED
|
@@ -278,15 +278,19 @@ export declare const LOGIN_SIGN_OUT_UNCONFIRMED: string;
|
|
|
278
278
|
/** What a sign-out answers beside `confirmed: false` where the CLI's step threw (`failed`, the error's words): the login is
|
|
279
279
|
* gone here all the same, and the CLI's own copy may remain. */
|
|
280
280
|
export declare const signOutCliFailed: (failed: string) => string;
|
|
281
|
+
/** What a sign-out answers beside `confirmed: false` where the CLI confirmed its own sign-out and every removal landed,
|
|
282
|
+
* but that older Keychain item, of the service `service`, may remain (keychainLeftover). */
|
|
283
|
+
export declare const signOutKeychainLeftover: (service: string | undefined) => string;
|
|
281
284
|
/** What a sign-out answers beside `confirmed: false` where some of the login is still there (`left`: each thing, its path
|
|
282
285
|
* and why), and the Keychain's words too where the CLI didn't confirm its own sign-out (`keychain`), naming the CLI
|
|
283
286
|
* step's failure where it threw (`failed`). */
|
|
284
287
|
export declare const signOutLeft: (left: readonly string[], keychain: boolean, failed?: string) => string;
|
|
285
288
|
/** Why a sign-out of this machine's own login (`folder`, the person's `~/.claude` or CLAUDE_CONFIG_DIR) is refused. */
|
|
286
289
|
export declare const machineSignOutRefused: (folder: string) => string;
|
|
287
|
-
/** POST /settings/claude-login/sign-out's answer: whether all of the login is gone (the CLI confirmed its own sign-out
|
|
288
|
-
* every removal landed, whether or not a folder was there
|
|
289
|
-
*
|
|
290
|
+
/** POST /settings/claude-login/sign-out's answer: whether all of the login is gone (the CLI confirmed its own sign-out,
|
|
291
|
+
* every removal landed, whether or not a folder was there, and the harness found no older Keychain item left under
|
|
292
|
+
* "unknown"), else words saying what may remain (LOGIN_SIGN_OUT_UNCONFIRMED, signOutLeft, signOutKeychainLeftover),
|
|
293
|
+
* and the view after it (`off`). */
|
|
290
294
|
export type ClaudeLoginSignOut = {
|
|
291
295
|
confirmed: boolean;
|
|
292
296
|
message?: string;
|
|
@@ -304,7 +308,10 @@ export type ClaudeLoginSignOut = {
|
|
|
304
308
|
* (claude-login-token.ts forgetLoginTokens). Each removal stands alone: one that fails is named in the answer
|
|
305
309
|
* (signOutLeft, `confirmed` false), and the others, the reader's drop and the server's reread of the keys still happen.
|
|
306
310
|
* So with the CLI's step: a throw finding the CLI or loading the harness is named in the answer (signOutCliFailed), and
|
|
307
|
-
* every removal still runs.
|
|
311
|
+
* every removal still runs. On macOS the harness's sign-out also deletes the older Keychain item a sign-in left under
|
|
312
|
+
* "unknown", which holds a refresh token, and says whether it went: where it may remain, the answer is not confirmed
|
|
313
|
+
* and its words say how to delete that item alone, named by its exact service (the harness's claudeKeychainService),
|
|
314
|
+
* in Keychain Access or with one `security` command (signOutKeychainLeftover, or after the other words).
|
|
308
315
|
* Where the folder is a link (put there after the turn-on, which refuses one), the link alone is removed, with the
|
|
309
316
|
* login's signed-in note: no CLI runs through it, nothing it leads to is touched, and the answer names it. Runs already going are left as a turn-off
|
|
310
317
|
* leaves them: each keeps the token its CLI holds, and fails in
|
|
@@ -329,7 +336,7 @@ export declare function startLoginHere(deps: ClaudeLoginDeps): Promise<ClaudeLog
|
|
|
329
336
|
* every change of the setting is. */
|
|
330
337
|
export declare function dropRefusedLogin(signIns: Pick<ClaudeSignIns, "serial">, settings: Pick<Settings, "get" | "remove">, why: string | undefined, env: Readonly<Record<string, string | undefined>>, log: (line: string) => void): Promise<void>;
|
|
331
338
|
/** What the routes and a run's check use of the harness (its login.ts), loaded only when asked. */
|
|
332
|
-
export type ClaudeLoginCli = Pick<typeof import("@parcha/agentrun-harness-claude"), "claudeLoginStatus" | "startClaudeLogin" | "claudeLoginCommand" | "claudeLogout">;
|
|
339
|
+
export type ClaudeLoginCli = Pick<typeof import("@parcha/agentrun-harness-claude"), "claudeLoginStatus" | "startClaudeLogin" | "claudeLoginCommand" | "claudeLogout" | "claudeKeychainService">;
|
|
333
340
|
/** How long a signed-in answer stands in for a check that gives none (loginBeforeRun). */
|
|
334
341
|
export declare const LOGIN_ANSWER_STANDS_MS: number;
|
|
335
342
|
/** The folder in the data folder that holds, per login, when it last answered signed in (noteAnswer). The server and its
|
package/dist/claude-login.js
CHANGED
|
@@ -756,6 +756,16 @@ export const LOGIN_SIGN_OUT_UNCONFIRMED = `Signed out here: AgentRun's copy of t
|
|
|
756
756
|
/** What a sign-out answers beside `confirmed: false` where the CLI's step threw (`failed`, the error's words): the login is
|
|
757
757
|
* gone here all the same, and the CLI's own copy may remain. */
|
|
758
758
|
export const signOutCliFailed = (failed) => `Signed out here: AgentRun's copy of the login is removed. ${keychainWords(failed)}`;
|
|
759
|
+
/** What may remain where the harness's sign-out could not delete the Keychain item a sign-in left under the account
|
|
760
|
+
* "unknown" at AgentRun's own folder (its claudeLogout's `leftoverGone` false), and how to delete that item alone by
|
|
761
|
+
* hand: by its exact service (`service`, the harness's claudeKeychainService for the folder, a hash of it with no path
|
|
762
|
+
* in it), never the bare "Claude Code-credentials", which the person's own CLI's item has, under "unknown" too where it
|
|
763
|
+
* ran with no USER. With no service (none for the folder, where the harness has nothing to drop) the words give no way
|
|
764
|
+
* to delete it, rather than one that may point at another login's item. */
|
|
765
|
+
const keychainLeftover = (service) => `On macOS an older Keychain item of this login, which holds a refresh token, could not be removed${service === undefined ? "." : `: in Keychain Access, search "${service}" and delete the item whose account is "unknown", or run \`security delete-generic-password -a unknown -s "${service}"\` in a terminal.`}`;
|
|
766
|
+
/** What a sign-out answers beside `confirmed: false` where the CLI confirmed its own sign-out and every removal landed,
|
|
767
|
+
* but that older Keychain item, of the service `service`, may remain (keychainLeftover). */
|
|
768
|
+
export const signOutKeychainLeftover = (service) => `Signed out here: AgentRun's copy of the login is removed. ${keychainLeftover(service)}`;
|
|
759
769
|
/** What a sign-out answers beside `confirmed: false` where some of the login is still there (`left`: each thing, its path
|
|
760
770
|
* and why), and the Keychain's words too where the CLI didn't confirm its own sign-out (`keychain`), naming the CLI
|
|
761
771
|
* step's failure where it threw (`failed`). */
|
|
@@ -774,7 +784,10 @@ export const machineSignOutRefused = (folder) => `This is your own Claude Code l
|
|
|
774
784
|
* (claude-login-token.ts forgetLoginTokens). Each removal stands alone: one that fails is named in the answer
|
|
775
785
|
* (signOutLeft, `confirmed` false), and the others, the reader's drop and the server's reread of the keys still happen.
|
|
776
786
|
* So with the CLI's step: a throw finding the CLI or loading the harness is named in the answer (signOutCliFailed), and
|
|
777
|
-
* every removal still runs.
|
|
787
|
+
* every removal still runs. On macOS the harness's sign-out also deletes the older Keychain item a sign-in left under
|
|
788
|
+
* "unknown", which holds a refresh token, and says whether it went: where it may remain, the answer is not confirmed
|
|
789
|
+
* and its words say how to delete that item alone, named by its exact service (the harness's claudeKeychainService),
|
|
790
|
+
* in Keychain Access or with one `security` command (signOutKeychainLeftover, or after the other words).
|
|
778
791
|
* Where the folder is a link (put there after the turn-on, which refuses one), the link alone is removed, with the
|
|
779
792
|
* login's signed-in note: no CLI runs through it, nothing it leads to is touched, and the answer names it. Runs already going are left as a turn-off
|
|
780
793
|
* leaves them: each keeps the token its CLI holds, and fails in
|
|
@@ -787,6 +800,8 @@ export const machineSignOutRefused = (folder) => `This is your own Claude Code l
|
|
|
787
800
|
export async function signOutClaudeLogin(deps) {
|
|
788
801
|
let off = false;
|
|
789
802
|
let signedOut = true;
|
|
803
|
+
let leftoverGone = true;
|
|
804
|
+
let leftoverService;
|
|
790
805
|
let cliFailed;
|
|
791
806
|
const left = [];
|
|
792
807
|
const remove = (what, path, options) => {
|
|
@@ -823,7 +838,15 @@ export async function signOutClaudeLogin(deps) {
|
|
|
823
838
|
try {
|
|
824
839
|
const { login } = loginAt("agentrun", deps.data, deps.env, deps.uid);
|
|
825
840
|
const cli = loginCli(await deps.pinned(), deps.env);
|
|
826
|
-
|
|
841
|
+
if (login && cli) {
|
|
842
|
+
const claude = await deps.claude();
|
|
843
|
+
({ signedOut, leftoverGone } = await claude.claudeLogout(cli, login, pathOf(deps.env)));
|
|
844
|
+
// The service the harness's drop deleted by, so the words name the item alone.
|
|
845
|
+
if (!leftoverGone)
|
|
846
|
+
leftoverService = claude.claudeKeychainService(login);
|
|
847
|
+
}
|
|
848
|
+
else
|
|
849
|
+
signedOut = false;
|
|
827
850
|
}
|
|
828
851
|
catch (error) {
|
|
829
852
|
signedOut = false;
|
|
@@ -851,7 +874,9 @@ export async function signOutClaudeLogin(deps) {
|
|
|
851
874
|
if (off)
|
|
852
875
|
await deps.changed();
|
|
853
876
|
}
|
|
854
|
-
const
|
|
877
|
+
const words = left.length > 0 ? signOutLeft(left, !signedOut, cliFailed) : signedOut ? undefined : cliFailed !== undefined ? signOutCliFailed(cliFailed) : LOGIN_SIGN_OUT_UNCONFIRMED;
|
|
878
|
+
// The older Keychain item the harness could not delete is said after the rest, or alone where nothing else remains.
|
|
879
|
+
const message = leftoverGone ? words : words === undefined ? signOutKeychainLeftover(leftoverService) : `${words} ${keychainLeftover(leftoverService)}`;
|
|
855
880
|
return { confirmed: message === undefined, ...(message ? { message } : {}), login: await claudeLoginView(deps) };
|
|
856
881
|
}
|
|
857
882
|
/** POST /settings/claude-login/login: the CLI's own sign-in, started on this machine, where it opens a browser, with the
|