@parcha/agentrun-serve 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.
Files changed (179) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/README.md +139 -22
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/api-only.d.ts +23 -1
  5. package/dist/api-only.js +43 -4
  6. package/dist/archil-settings.d.ts +9 -0
  7. package/dist/archil-settings.js +8 -1
  8. package/dist/bash-read-only.d.ts +3 -0
  9. package/dist/bash-read-only.js +6 -3
  10. package/dist/browser-person.d.ts +1 -1
  11. package/dist/browser-person.js +1 -1
  12. package/dist/calendar/tools.js +1 -1
  13. package/dist/chatgpt-plan.d.ts +26 -8
  14. package/dist/chatgpt-plan.js +89 -21
  15. package/dist/claude-login.d.ts +12 -5
  16. package/dist/claude-login.js +28 -3
  17. package/dist/cli.js +61 -18
  18. package/dist/composio-triggers.d.ts +9 -3
  19. package/dist/computers.d.ts +3 -0
  20. package/dist/computers.js +2 -1
  21. package/dist/console/assets/{backend-QnwGVBeU.js → backend-DEgVn5lC.js} +1 -1
  22. package/dist/console/assets/index-CG5tELph.js +639 -0
  23. package/dist/console/assets/share-CIeFK2Oe.js +6 -0
  24. package/dist/console/assets/{styles-CcceGcu2.js → styles-BGZxYkky.js} +2 -2
  25. package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
  26. package/dist/console/index.html +3 -3
  27. package/dist/console/share.html +3 -3
  28. package/dist/cut-pool.d.ts +14 -0
  29. package/dist/cut-pool.js +98 -0
  30. package/dist/cut-worker.d.ts +14 -0
  31. package/dist/cut-worker.js +16 -0
  32. package/dist/decisions.d.ts +4 -0
  33. package/dist/decisions.js +9 -1
  34. package/dist/env-switch.d.ts +3 -0
  35. package/dist/env-switch.js +3 -0
  36. package/dist/errors.d.ts +1 -0
  37. package/dist/errors.js +2 -0
  38. package/dist/harness-check.js +2 -1
  39. package/dist/harness-recipe.d.ts +13 -2
  40. package/dist/harness-recipe.js +30 -7
  41. package/dist/harness-sign-in.js +2 -1
  42. package/dist/harness-table.d.ts +12 -3
  43. package/dist/harness-table.js +13 -8
  44. package/dist/import.d.ts +8 -1
  45. package/dist/import.js +36 -5
  46. package/dist/key-check.js +22 -8
  47. package/dist/key-refusal.js +6 -4
  48. package/dist/learn/secrets.d.ts +2 -1
  49. package/dist/learn/secrets.js +2 -2
  50. package/dist/learned-nodes.d.ts +37 -0
  51. package/dist/learned-nodes.js +24 -0
  52. package/dist/local-model.d.ts +144 -0
  53. package/dist/local-model.js +214 -0
  54. package/dist/mcp-gateway.d.ts +24 -0
  55. package/dist/mcp-gateway.js +97 -8
  56. package/dist/mcp-probe.d.ts +7 -0
  57. package/dist/mcp-probe.js +7 -0
  58. package/dist/mcp-servers-store.d.ts +7 -10
  59. package/dist/mcp-servers-store.js +15 -9
  60. package/dist/native/cli.js +5 -1
  61. package/dist/ollama-provider.d.ts +42 -0
  62. package/dist/ollama-provider.js +118 -2
  63. package/dist/openapi.js +85 -16
  64. package/dist/otel/tracer.d.ts +6 -3
  65. package/dist/otel/tracer.js +24 -6
  66. package/dist/page.d.ts +7 -0
  67. package/dist/page.js +17 -4
  68. package/dist/place.d.ts +28 -11
  69. package/dist/place.js +43 -14
  70. package/dist/print.d.ts +3 -2
  71. package/dist/print.js +8 -6
  72. package/dist/redact/match.d.ts +17 -4
  73. package/dist/redact/match.js +57 -15
  74. package/dist/run-export.js +4 -2
  75. package/dist/run-launch.js +16 -3
  76. package/dist/run-model-key.d.ts +2 -1
  77. package/dist/run-model-key.js +2 -1
  78. package/dist/run-reads-over-store.d.ts +7 -0
  79. package/dist/run-reads-over-store.js +32 -4
  80. package/dist/run-usage.js +3 -2
  81. package/dist/runnable.d.ts +6 -3
  82. package/dist/runnable.js +16 -6
  83. package/dist/runner/adapter-loop.d.ts +8 -1
  84. package/dist/runner/adapter-loop.js +148 -29
  85. package/dist/runner/adapter-run-spec.d.ts +9 -6
  86. package/dist/runner/adapter-run-spec.js +38 -52
  87. package/dist/runner/adapters/index.d.ts +4 -0
  88. package/dist/runner/adapters/index.js +2 -1
  89. package/dist/runner/adapters/pi.d.ts +3 -2
  90. package/dist/runner/adapters/pi.js +3 -1
  91. package/dist/runner/audit.d.ts +1 -1
  92. package/dist/runner/claim-secrets.d.ts +3 -1
  93. package/dist/runner/claim-secrets.js +18 -7
  94. package/dist/runner/cli-run-spec.js +24 -17
  95. package/dist/runner/compare-end.d.ts +1 -1
  96. package/dist/runner/dispatch.js +4 -2
  97. package/dist/runner/harness-loops.d.ts +14 -0
  98. package/dist/runner/harness-loops.js +51 -5
  99. package/dist/runner/held.d.ts +4 -1
  100. package/dist/runner/live-ticker.js +5 -4
  101. package/dist/runner/loop-contract.d.ts +4 -1
  102. package/dist/runner/mcp-claim.js +3 -2
  103. package/dist/runner/mcp-run.d.ts +24 -4
  104. package/dist/runner/mcp-run.js +47 -2
  105. package/dist/runner/meta-tools.js +4 -4
  106. package/dist/runner/metrics.d.ts +6 -0
  107. package/dist/runner/metrics.js +12 -4
  108. package/dist/runner/monid-run.js +3 -1
  109. package/dist/runner/native-loop.js +3 -3
  110. package/dist/runner/redact.d.ts +3 -0
  111. package/dist/runner/redact.js +7 -0
  112. package/dist/runner/run-child-host.d.ts +10 -6
  113. package/dist/runner/run-child-host.js +44 -29
  114. package/dist/runner/run-child.js +1 -0
  115. package/dist/runner/runner.js +2 -0
  116. package/dist/runner/sdk-loop.js +5 -3
  117. package/dist/runner/workflow-calls.d.ts +5 -1
  118. package/dist/runner/workflow-calls.js +65 -19
  119. package/dist/runner/workflow-loop.d.ts +1 -1
  120. package/dist/runner/workflow-loop.js +3 -1
  121. package/dist/runner/workflow-spec.d.ts +4 -0
  122. package/dist/runner/workflow-spec.js +18 -13
  123. package/dist/runs-over-store.d.ts +2 -2
  124. package/dist/runs-over-store.js +1 -1
  125. package/dist/secret-cut.js +7 -4
  126. package/dist/secret-rules.d.ts +0 -1
  127. package/dist/secret-rules.js +122 -88
  128. package/dist/server.d.ts +17 -1
  129. package/dist/server.js +208 -69
  130. package/dist/share-host.d.ts +111 -0
  131. package/dist/share-host.js +666 -0
  132. package/dist/slack.js +2 -1
  133. package/dist/store/postgres/migrate.js +3 -1
  134. package/dist/store-reads/analytics.d.ts +15 -0
  135. package/dist/store-reads/analytics.js +17 -0
  136. package/dist/store-reads/learning.d.ts +5 -4
  137. package/dist/store-reads/learning.js +7 -4
  138. package/dist/suggestions.js +32 -3
  139. package/dist/templates.d.ts +3 -1
  140. package/dist/templates.js +7 -3
  141. package/dist/tool-gate.d.ts +25 -9
  142. package/dist/tool-gate.js +58 -19
  143. package/dist/tool-plane.d.ts +24 -1
  144. package/dist/tool-plane.js +75 -3
  145. package/dist/tools.d.ts +12 -2
  146. package/dist/tools.js +42 -7
  147. package/dist/trigger-composio.js +1 -1
  148. package/dist/trigger-launch-hook.d.ts +2 -2
  149. package/dist/trigger-launch-hook.js +1 -1
  150. package/dist/triggers.d.ts +7 -4
  151. package/dist/triggers.js +4 -4
  152. package/dist/webhooks.d.ts +3 -0
  153. package/dist/webhooks.js +5 -0
  154. package/dist/workspace/archil-claim.d.ts +7 -3
  155. package/dist/workspace/archil-claim.js +13 -5
  156. package/dist/workspace/archil-mount-credential.d.ts +6 -0
  157. package/dist/workspace/archil-mount-credential.js +11 -0
  158. package/dist/workspace/computer-deps.d.ts +5 -3
  159. package/dist/workspace/computer-deps.js +11 -9
  160. package/dist/workspace/computer-for-claim.d.ts +6 -2
  161. package/dist/workspace/computer-for-claim.js +43 -12
  162. package/dist/workspace/computer-janitor.d.ts +7 -4
  163. package/dist/workspace/computer-janitor.js +7 -4
  164. package/dist/workspace/computer-kept.d.ts +7 -1
  165. package/dist/workspace/computer-kept.js +7 -1
  166. package/dist/workspace/kind-skills/desktop/SKILL.md +12 -3
  167. package/dist/workspace/mount-revoke-left.d.ts +16 -4
  168. package/dist/workspace/mount-revoke-left.js +42 -22
  169. package/dist/workspace/resolve-computer.d.ts +11 -5
  170. package/dist/workspace/resolve-computer.js +22 -13
  171. package/dist/workspace/run-end-computers.js +1 -1
  172. package/dist/workspace/run-tools.d.ts +10 -3
  173. package/dist/workspace/run-tools.js +5 -4
  174. package/dist/wrapped.d.ts +29 -2
  175. package/dist/wrapped.js +20 -3
  176. package/launcher/agentrun-serve +1 -1
  177. package/package.json +12 -12
  178. package/dist/console/assets/index-DZi-muIj.js +0 -629
  179. package/dist/console/assets/share-pz61zIn9.js +0 -6
package/dist/api-only.js CHANGED
@@ -2,8 +2,8 @@
2
2
  // deploy's routes alone, and refuses every other address before anything else reads the request: the console at "/" and
3
3
  // its assets, sign-in and setup, settings but the MCP servers' names, a Composio server's save and the delete of a server
4
4
  // (the secret-write gate lets the token save over or delete only a server it saved, mcp-secret-writes.ts), the MCP
5
- // endpoint, triggers and their webhook hooks (all but a firing's release, which the launch hook's host sends), the rest
6
- // of agents and templates. Off by default.
5
+ // endpoint, triggers but their reads, their turn on or off (apiOnlyTriggerEdit) and a firing's release (which the launch
6
+ // hook's host sends), their webhook hooks, the rest of agents and templates. Off by default.
7
7
  import { API_ONLY_ENV } from "./env-switch.js";
8
8
  import { NOT_SET_UP } from "./runnable.js";
9
9
  import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-hook.js";
@@ -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
@@ -27,7 +31,12 @@ import { LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV } from "./trigger-launch-ho
27
31
  * agents and revisions that stay, archives and deletes any agent made here and purges any run of one, as the whole
28
32
  * server's token does, and with the launch hook its apply makes schedule and feed triggers. A trigger the apply can't
29
33
  * make here is skipped, and said (apiOnlyTriggerSkipped). One the agent had before the profile stays as it was:
30
- * without the hook, an enabled one still fires here on this server's keys until the agent is archived;
34
+ * without the hook, an enabled one still fires here on this server's keys until it is turned off (below) or the agent
35
+ * is archived;
36
+ * - a backend reads the triggers (their list, one, its firings) and turns one on or off (updateTrigger, `enabled` alone:
37
+ * apiOnlyTriggerEdit), since a trigger whose firings failed FAILURES_TO_PAUSE times in a row turns itself off and
38
+ * there is no console here to turn it on in. It turns one on under the apply's rule: a schedule or a feed, with the
39
+ * launch hook. Making, deleting, firing a trigger and its secret stay refused;
31
40
  * - an API-only server has no owner, so the token is the backend's own, as with take-over: it saves the Composio servers
32
41
  * its agents need through the preset (saveComposioServer), saves over or deletes only a server it saved
33
42
  * (mcp-secret-writes.ts tokenWriteOverRefused), and never writes a secret (secret-writes.ts). A Composio server names
@@ -47,11 +56,12 @@ export const API_ONLY_ROUTES = new Set([
47
56
  "getLearningLoop", "listLearningPromotions", "listLearningAudits", "getLearningCost", "getRunLearning",
48
57
  "getRun", "getRunUsage", "listRuns", "listAllRuns", "getTimeline",
49
58
  "sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
50
- "listRunFiles", "readRunFile",
59
+ "listRunFiles", "readRunFile", "getRunExport",
51
60
  "createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
52
61
  "getCapabilities", "getHealth", "getUsage", "getCapacity", "listMcpServerNames",
53
62
  "importTemplate", "applyTemplate", "getAgent", "listRevisions", "setCurrent", "archiveAgent", "unarchiveAgent",
54
63
  "saveComposioServer", "deleteMcpServer", "releaseTriggerFiring",
64
+ "listTriggers", "getTrigger", "listTriggerFirings", "updateTrigger",
55
65
  // Refused in its own words (403): it reads the machine's session files, which a server behind a backend does not have to give.
56
66
  "getWrapped",
57
67
  ]);
@@ -73,6 +83,35 @@ export function apiOnlyTriggerSkipped(packageName, trigger, hooked) {
73
83
  return undefined;
74
84
  return { reason: NOT_SET_UP, message: `${named} and has no launch hook, so its firings have nowhere to go. Start its runs through the API, or set the launch hook (${LAUNCH_HOOK_URL_ENV} and ${LAUNCH_HOOK_SECRET_ENV}) and apply again: each firing then goes to your backend, which starts its run.` };
75
85
  }
86
+ /** Whether an API-only server turns on a trigger whose source is `kind` and whose target is `target` (its PATCH, its
87
+ * agent's unarchive): only one the apply would make, a source of API_ONLY_HOOKED_KINDS aimed at an agent (start_run),
88
+ * with the launch hook `hooked`, so each firing goes to the backend. A message_run firing never goes to the hook
89
+ * (triggers.ts): on, it would open its run on this server's keys. */
90
+ export function apiOnlyTurnsOn(kind, target, hooked) {
91
+ return hooked && API_ONLY_HOOKED_KINDS.has(kind) && target === "start_run";
92
+ }
93
+ /** Why an API-only server refuses `body`, a PATCH of a trigger whose source is `kind` and whose target is `target`, each
94
+ * an issue (none: it goes on to the trigger's own checks). It takes `enabled` alone: a new source or target would let
95
+ * the token aim a trigger at an address or an agent of its own choosing (a feed's urls fetched by this server, a run of
96
+ * another agent), which no route here lets it make, and a name or a cap is the console's to edit. Turned off: always,
97
+ * it stops firings. Turned on: only where the apply would make it (apiOnlyTurnsOn), so its firings go to the backend;
98
+ * any other would start or open runs on this server's keys, or wait on a hook or setting this profile refuses. */
99
+ export function apiOnlyTriggerEdit(body, kind, hooked, target) {
100
+ if (body === null || typeof body !== "object" || Array.isArray(body))
101
+ return [];
102
+ const issues = Object.keys(body).filter((key) => key !== "enabled").map((field) => ({ field, reason: "not_allowed", message: `This server serves the run API only (${API_ONLY_ENV}=1), where a trigger is turned on or off alone: send {"enabled": true} or {"enabled": false}, without ${field}.` }));
103
+ if (body.enabled !== true || apiOnlyTurnsOn(kind, target, hooked))
104
+ return issues;
105
+ const named = `This server serves the run API only (${API_ONLY_ENV}=1)`;
106
+ if (target !== "start_run") {
107
+ issues.push({ field: "enabled", reason: "not_an_option", message: `${named}, and this trigger messages a run: its firings never go to the launch hook, so each would open that run on this server's keys. It is not turned on here. Send the run its messages through the API instead.` });
108
+ return issues;
109
+ }
110
+ issues.push(API_ONLY_HOOKED_KINDS.has(kind)
111
+ ? { field: "enabled", reason: NOT_SET_UP, message: `${named} and has no launch hook, so this ${kind} trigger's firings would start runs on this server's keys: set the launch hook (${LAUNCH_HOOK_URL_ENV} and ${LAUNCH_HOOK_SECRET_ENV}), then turn it on.` }
112
+ : { field: "enabled", reason: "not_an_option", message: `${named}, which serves no route or setting a ${kind} trigger needs, so it is not turned on here. Start its runs through the API instead.` });
113
+ return issues;
114
+ }
76
115
  /** Whether an API-only server saves `body` through the generic save (saveMcpServer) over the name its path gives: a
77
116
  * per_run server (no credential kept) whose url's origin is one of `origins`, under a name that is not a Composio
78
117
  * preset's (`preset`; Composio's own route saves those). Checked before anything reaches the address. A body that
@@ -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">;
@@ -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;
@@ -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;
@@ -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 `${tool} is not offered: a read-only shell runs one command at a time, in the foreground, with bash`;
767
+ return readOnlyToolReason(tool);
765
768
  const read = commandOf(args, folder);
766
769
  if ("reason" in read)
767
770
  return read.reason;
@@ -71,7 +71,7 @@ export declare function personHands(options: {
71
71
  /** For tests: the clock the person's time is measured by. */
72
72
  now?: () => number;
73
73
  /** The run's held values cut from the ask's words, whole, before they are cut to their bound and written. */
74
- redact?: (text: string) => string;
74
+ redact: (text: string) => string;
75
75
  /** The person's time on a session that just ended, `seconds` of it, to hold until a charge books it (browser-cost.ts
76
76
  * carry): the up-front holds go as it ends, the time it took stays counted. */
77
77
  carry?(tag: string, seconds: number): void;
@@ -475,7 +475,7 @@ export function personHands(options) {
475
475
  const hold = { drop: () => release(ask.sessionTag, user) };
476
476
  const at = Date.now();
477
477
  // Redacted whole, then cut to their bound: a held value the cut would split never leaves its head in the record.
478
- const shown = (text) => (options.redact ? options.redact(text) : text).slice(0, MAX_TEXT);
478
+ const shown = (text) => options.redact(text).slice(0, MAX_TEXT);
479
479
  const record = { id, tag: ask.sessionTag, instruction: shown(ask.instruction), completion_condition: shown(ask.completionCondition), asked_at: new Date(at).toISOString(), expires_at: new Date(at + holdMs).toISOString() };
480
480
  open.set(id, { tag: ask.sessionTag, expiresAt: at + holdMs, drop: () => hold.drop() });
481
481
  watch();
@@ -76,7 +76,7 @@ function calendarTool(host) {
76
76
  let secret = [saved.url];
77
77
  const clean = (text) => {
78
78
  const cut = scrubAddress(text, secret);
79
- return host.redact ? host.redact(cut) : cut;
79
+ return host.redact(cut);
80
80
  };
81
81
  const failed = (words) => forModel(clean(calendarError(`${CALENDAR_EVENTS}: ${words}`)), { isError: true });
82
82
  const given = (isObject(args) ? args : {});
@@ -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; a runner, which never signs in, has none. */
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,22 @@ 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 do not open. */
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, once, at its start, once its first offers are made. Models it lists are told to the server (its change
119
+ * callback, as a sign-in's are), so the offers made from the fallback list are made again. A runner's reader
120
+ * (planReaderOf, at each claim) never calls it, so no runner lists the plan's models or sends a refresh token to
121
+ * OpenAI's revocation endpoint. */
122
+ settleLeft(): void;
115
123
  view(): PlanView;
116
124
  /** 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
125
  private hostId;
@@ -130,10 +138,20 @@ export declare class ChatGPTPlan implements PlanReader {
130
138
  * is refused in words and the sign-in keeps waiting; one OpenAI refuses ends it. */
131
139
  finishSignIn(redirectUrl: unknown): Promise<PlanView>;
132
140
  /** 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. A sign-in it takes the place
134
- * of is revoked first, then replaced only while the row still holds it (a renewal of it that wrote back meanwhile is
135
- * read, revoked and replaced in turn), so no earlier pair is left alive. */
141
+ * sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI. It is saved before anything
142
+ * 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
143
+ * of rides in the row (`retired`, with any it carried) until it is revoked, and its models are listed after (settle).
144
+ * The row is replaced only while it still holds what was read (a renewal that wrote back meanwhile is read and carried
145
+ * in turn), so no earlier pair is left alive and unsaved. */
136
146
  private keep;
147
+ /** What a saved sign-in leaves (keep), done: its models listed (`unlisted`), and each pair it carries (`retired`)
148
+ * revoked at OpenAI and dropped from the row once OpenAI confirms it. `revoked`: whether every carried pair was
149
+ * confirmed, none when the row carried none; `listed`: whether it wrote the models OpenAI listed. The server's alone,
150
+ * one at a time: only a sign-in (keep) and the server's start (settleLeft) settle, and a runner does neither. The row
151
+ * is written only while it holds what was read and no renewal's lease is live (a renewal writes back over the row it
152
+ * leased, and carries these fields); what is left stays for the server's next start. Never throws. */
153
+ private settle;
154
+ private settleOnce;
137
155
  /** Tells the server the sign-in changed (its change callback: env read again, the listings relisted, the offers
138
156
  * 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
157
  * again for `again`, a retry of one owed), and taken again at the server's next read (refresh). */
@@ -143,8 +161,8 @@ export declare class ChatGPTPlan implements PlanReader {
143
161
  * 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
162
  * polls, and each change relists and probes). */
145
163
  refresh(): Promise<void>;
146
- /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families; the fallback
147
- * list when it can't be read. */
164
+ /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families (the fallback
165
+ * list when it names none); none when the list can't be read, so the row stays `unlisted`. */
148
166
  private listModels;
149
167
  /** The access token to send now: the sealed one, renewed first when it ends within 5 minutes. Throws PlanUnavailable,
150
168
  * in words, when there is none. */
@@ -206,6 +206,8 @@ 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 last settle queued (settle): each waits for the one before it. */
210
+ #settling;
209
211
  /** The ends of the sign-ins cancelled and not yet ended (close waits for them). */
210
212
  #ending = new Set();
211
213
  #watchers = new Set();
@@ -275,13 +277,16 @@ export class ChatGPTPlan {
275
277
  this.#snapshot = row;
276
278
  this.#writes += 1;
277
279
  }
278
- /** The row sealed as `bytes`, opened (its tokens held for redaction); none when they do not open. */
280
+ /** The row sealed as `bytes`, opened (its tokens held for redaction, and those of each pair it carries); none when they
281
+ * do not open. */
279
282
  open(bytes) {
280
283
  try {
281
284
  const row = JSON.parse(unsealColumn(this.#deps.sealKey, sealedAt.sealedKey(CHATGPT_PLAN_ROW), bytes).toString("utf8"));
282
285
  if (row?.v !== 1 || !row.credential?.access || !row.credential.refresh)
283
286
  return undefined;
284
287
  this.hold(row.credential);
288
+ for (const old of row.retired ?? [])
289
+ this.hold(old);
285
290
  return row;
286
291
  }
287
292
  catch {
@@ -298,11 +303,19 @@ export class ChatGPTPlan {
298
303
  const bytes = this.seal(row);
299
304
  return (await this.#deps.store.sealedKeys.replaceIf(CHATGPT_PLAN_ROW, was, bytes)) ? bytes : undefined;
300
305
  }
301
- /** Reads the sealed row into the state a reader sees. Returns this. */
306
+ /** Reads the sealed row into the state a reader sees. Returns this. A read never settles (settleLeft). */
302
307
  async load() {
303
308
  await this.readTaken();
304
309
  return this;
305
310
  }
311
+ /** 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
312
+ * server's, once, at its start, once its first offers are made. Models it lists are told to the server (its change
313
+ * callback, as a sign-in's are), so the offers made from the fallback list are made again. A runner's reader
314
+ * (planReaderOf, at each claim) never calls it, so no runner lists the plan's models or sends a refresh token to
315
+ * OpenAI's revocation endpoint. */
316
+ settleLeft() {
317
+ void this.settle().then(({ listed }) => (listed ? this.tellChanged() : undefined));
318
+ }
306
319
  view() {
307
320
  if (this.#pending && this.#pending.expiresAt <= this.now())
308
321
  this.expire();
@@ -456,16 +469,16 @@ export class ChatGPTPlan {
456
469
  return this.view();
457
470
  }
458
471
  /** 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. A sign-in it takes the place
460
- * of is revoked first, then replaced only while the row still holds it (a renewal of it that wrote back meanwhile is
461
- * read, revoked and replaced in turn), so no earlier pair is left alive. */
472
+ * sign-in since then wins: the credential is dropped, never written, and revoked at OpenAI. It is saved before anything
473
+ * 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
474
+ * of rides in the row (`retired`, with any it carried) until it is revoked, and its models are listed after (settle).
475
+ * The row is replaced only while it still holds what was read (a renewal that wrote back meanwhile is read and carried
476
+ * in turn), so no earlier pair is left alive and unsaved. */
462
477
  async keep(credential, epoch, saved) {
463
478
  if (credential.scopes && !credential.scopes.includes(DIRECT_SCOPE))
464
479
  throw new Error(`the grant did not include ${DIRECT_SCOPE}`);
465
480
  this.hold(credential);
466
- const models = await this.listModels(credential.access);
467
- const row = { v: 1, state: "signed_in", credential, ...whoOf(credential.access), models };
468
- let previousRevoked;
481
+ let row;
469
482
  for (;;) {
470
483
  if (epoch !== this.#epoch) {
471
484
  if (!(await this.revoke(credential)))
@@ -473,27 +486,76 @@ export class ChatGPTPlan {
473
486
  return;
474
487
  }
475
488
  const was = await this.#deps.store.sealedKeys.get(CHATGPT_PLAN_ROW);
489
+ const previous = was === undefined ? undefined : this.open(was);
490
+ const retired = [...(previous?.retired ?? []), ...(previous && previous.credential.refresh !== credential.refresh ? [previous.credential] : [])];
491
+ row = { v: 1, state: "signed_in", credential, ...whoOf(credential.access), models: [...PLAN_FALLBACK_MODELS], unlisted: true, ...(retired.length ? { retired } : {}) };
492
+ if (epoch !== this.#epoch)
493
+ continue;
476
494
  if (was === undefined) {
477
495
  // No row to compare against: only the server signs in, and nothing else makes the row (a runner's renewal
478
496
  // replaces one only while it holds its lease), so a plain write.
479
497
  await putSealedKey(this.#deps.store, this.#deps.sealKey, CHATGPT_PLAN_ROW, JSON.stringify(row));
480
498
  break;
481
499
  }
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
500
  if (await this.swap(was, row))
488
501
  break;
489
502
  }
490
503
  this.wrote(row);
491
504
  this.#problem = undefined;
492
- this.#deps.log?.({ chatgpt: "signed_in", ...(previousRevoked === undefined ? {} : { previous_revoked: String(previousRevoked) }) });
493
- // Saved: no longer waiting, so it reads signed in while the server takes the change (`saved`, the sign-in's settle).
505
+ this.#deps.log?.({ chatgpt: "signed_in" });
506
+ // Saved: no longer waiting, so it reads signed in while it settles and the server takes the change (`saved`, the
507
+ // sign-in's settle).
494
508
  saved?.();
509
+ const { revoked: previousRevoked } = await this.settle();
510
+ if (previousRevoked !== undefined)
511
+ this.#deps.log?.({ chatgpt: "previous_revoked", revoked: String(previousRevoked) });
495
512
  await this.tellChanged();
496
513
  }
514
+ /** What a saved sign-in leaves (keep), done: its models listed (`unlisted`), and each pair it carries (`retired`)
515
+ * revoked at OpenAI and dropped from the row once OpenAI confirms it. `revoked`: whether every carried pair was
516
+ * confirmed, none when the row carried none; `listed`: whether it wrote the models OpenAI listed. The server's alone,
517
+ * one at a time: only a sign-in (keep) and the server's start (settleLeft) settle, and a runner does neither. The row
518
+ * is written only while it holds what was read and no renewal's lease is live (a renewal writes back over the row it
519
+ * leased, and carries these fields); what is left stays for the server's next start. Never throws. */
520
+ settle() {
521
+ const run = (this.#settling ?? Promise.resolve({})).then(() => this.settleOnce()).catch(() => ({}));
522
+ this.#settling = run;
523
+ void run.then(() => (this.#settling === run ? (this.#settling = undefined) : undefined));
524
+ return run;
525
+ }
526
+ async settleOnce() {
527
+ const read = await this.readSealed();
528
+ if (!read || (!read.row.unlisted && !read.row.retired?.length))
529
+ return {};
530
+ const signedIn = read.row.credential.refresh;
531
+ const models = read.row.unlisted && read.row.state === "signed_in" ? await this.listModels(read.row.credential.access) : undefined;
532
+ const confirmed = new Set();
533
+ for (const old of read.row.retired ?? [])
534
+ if (await this.revoke(old))
535
+ confirmed.add(old.refresh);
536
+ const revoked = read.row.retired?.length ? confirmed.size === read.row.retired.length : undefined;
537
+ const done = revoked === undefined ? {} : { revoked };
538
+ for (;;) {
539
+ const now = await this.readSealed();
540
+ // Signed out meanwhile: the sign-out revoked what the row held.
541
+ if (!now)
542
+ return done;
543
+ if (now.row.lease && now.row.lease.until > (await this.storeNow()))
544
+ return done;
545
+ const { unlisted, retired: carried, ...rest } = now.row;
546
+ const retired = (carried ?? []).filter((old) => !confirmed.has(old.refresh));
547
+ // The models listed are this sign-in's: a newer sign-in's row lists its own.
548
+ const listed = Boolean(unlisted && models && now.row.credential.refresh === signedIn);
549
+ const next = { ...rest, ...(listed && models ? { models } : unlisted ? { unlisted } : {}), ...(retired.length ? { retired } : {}) };
550
+ if (!listed && retired.length === (carried ?? []).length)
551
+ return done;
552
+ const bytes = await this.swap(now.bytes, next);
553
+ if (bytes) {
554
+ this.wrote(next);
555
+ return { ...done, listed };
556
+ }
557
+ }
558
+ }
497
559
  /** Tells the server the sign-in changed (its change callback: env read again, the listings relisted, the offers
498
560
  * 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
561
  * again for `again`, a retry of one owed), and taken again at the server's next read (refresh). */
@@ -528,19 +590,19 @@ export class ChatGPTPlan {
528
590
  await this.tellChanged(true);
529
591
  })().finally(() => (this.#refreshing = undefined)));
530
592
  }
531
- /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families; the fallback
532
- * list when it can't be read. */
593
+ /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families (the fallback
594
+ * list when it names none); none when the list can't be read, so the row stays `unlisted`. */
533
595
  async listModels(token) {
534
596
  try {
535
597
  const response = await fetch(`${PLAN_ORIGIN}/v1/models`, { headers: { authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(5_000) });
536
598
  if (!response.ok)
537
- return [...PLAN_FALLBACK_MODELS];
599
+ return undefined;
538
600
  const body = (await response.json());
539
601
  const ids = (body.data ?? []).map((model) => model.id).filter((id) => typeof id === "string" && /^gpt-6(?:[.-]|$)/.test(id));
540
602
  return ids.length ? [...new Set(ids)] : [...PLAN_FALLBACK_MODELS];
541
603
  }
542
604
  catch {
543
- return [...PLAN_FALLBACK_MODELS];
605
+ return undefined;
544
606
  }
545
607
  }
546
608
  /** The access token to send now: the sealed one, renewed first when it ends within 5 minutes. Throws PlanUnavailable,
@@ -686,7 +748,11 @@ export class ChatGPTPlan {
686
748
  continue;
687
749
  // A row that does not open (sealed under another key) is removed, its tokens beyond reach to revoke.
688
750
  const removed = row ? (await this.revoke(row.credential)) && !renewing : false;
689
- revoked = revoked && removed;
751
+ // The pairs of the sign-ins it replaced that it still carries (keep, settle) go with it.
752
+ let carried = true;
753
+ for (const old of row?.retired ?? [])
754
+ carried = (await this.revoke(old)) && carried;
755
+ revoked = revoked && removed && carried;
690
756
  break;
691
757
  }
692
758
  this.wrote(undefined);
@@ -714,7 +780,9 @@ export class ChatGPTPlan {
714
780
  * sign-out or its 10 minutes) has ended, whatever its end said in the log. */
715
781
  close() {
716
782
  this.cancel();
717
- return Promise.all([...this.#ending]).then(() => undefined);
783
+ // A settle out (the start's, a kept sign-in's) is waited for too: the server's stop bounds the wait (planClosed), and
784
+ // what it cuts off stays in the row for the next start.
785
+ return Promise.all([...this.#ending, this.#settling]).then(() => undefined);
718
786
  }
719
787
  }
720
788
  /** For a run on a plan model (`model`, the one its claim chose): the plan's token read once before anything starts, so a
@@ -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 and
288
- * every removal landed, whether or not a folder was there), else words saying what may remain
289
- * (LOGIN_SIGN_OUT_UNCONFIRMED, signOutLeft), and the view after it (`off`). */
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
@@ -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
- signedOut = login && cli ? await (await deps.claude()).claudeLogout(cli, login, pathOf(deps.env)) : false;
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 message = left.length > 0 ? signOutLeft(left, !signedOut, cliFailed) : signedOut ? undefined : cliFailed !== undefined ? signOutCliFailed(cliFailed) : LOGIN_SIGN_OUT_UNCONFIRMED;
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