tryharness 0.7.54 → 0.7.58

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 (156) hide show
  1. package/README.md +15 -16
  2. package/cli.mjs +384 -62
  3. package/lib/activity.mjs +10 -10
  4. package/lib/adapters.mjs +16 -0
  5. package/lib/agentBinaries.mjs +71 -0
  6. package/lib/agentRuntimeConfig.mjs +1 -1
  7. package/lib/agentRuntimes.mjs +9 -3
  8. package/lib/agentSignIn.mjs +271 -41
  9. package/lib/answers.mjs +5 -5
  10. package/lib/archetypes.d.ts +64 -0
  11. package/lib/archetypes.js +989 -0
  12. package/lib/asks.mjs +4 -4
  13. package/lib/audit.mjs +36 -13
  14. package/lib/backupSetup.mjs +4 -2
  15. package/lib/boardAccess.mjs +17 -11
  16. package/lib/boardBackup.mjs +6 -6
  17. package/lib/boardFileCommands.mjs +6 -6
  18. package/lib/boardFiles.mjs +13 -12
  19. package/lib/boardMirror.mjs +82 -47
  20. package/lib/boardProtocol.json +30 -1
  21. package/lib/boardWaits.mjs +2 -3
  22. package/lib/book.mjs +6 -6
  23. package/lib/bridge.mjs +5 -5
  24. package/lib/cards.mjs +2 -2
  25. package/lib/cloudAgents.mjs +216 -0
  26. package/lib/cloudAi.mjs +1312 -0
  27. package/lib/cloudAssistants.mjs +242 -0
  28. package/lib/cloudBoot.mjs +81 -86
  29. package/lib/cloudSave.mjs +197 -0
  30. package/lib/cloudSsh.mjs +178 -0
  31. package/lib/context.mjs +3 -3
  32. package/lib/contractGate.mjs +34 -12
  33. package/lib/control-client.mjs +9 -1
  34. package/lib/controlSocket.mjs +86 -0
  35. package/lib/coordinator.mjs +103 -101
  36. package/lib/daemon.mjs +1128 -2865
  37. package/lib/desk.mjs +7 -6
  38. package/lib/desktop.mjs +72 -68
  39. package/lib/directLink.mjs +16 -5
  40. package/lib/environment.mjs +2 -1
  41. package/lib/environments.mjs +14 -6
  42. package/lib/firewall.mjs +9 -9
  43. package/lib/folders.mjs +18 -14
  44. package/lib/frames.mjs +2 -3
  45. package/lib/gitHost.mjs +3 -3
  46. package/lib/goalCommands.mjs +25 -7
  47. package/lib/goals.mjs +7 -7
  48. package/lib/guestRequests.mjs +94 -0
  49. package/lib/handoffs.mjs +8 -7
  50. package/lib/handover.mjs +4 -4
  51. package/lib/harnessModel.mjs +6 -6
  52. package/lib/harnessOffers.mjs +266 -0
  53. package/lib/inference.mjs +26 -8
  54. package/lib/jobAnswers.mjs +190 -0
  55. package/lib/landed.mjs +1 -1
  56. package/lib/lane.mjs +42 -11
  57. package/lib/lessons.mjs +16 -16
  58. package/lib/library.mjs +3 -3
  59. package/lib/lineup.mjs +3 -0
  60. package/lib/linkRelay.mjs +574 -0
  61. package/lib/localAgentAsk.mjs +74 -0
  62. package/lib/localStack.mjs +536 -0
  63. package/lib/localmodels.mjs +6 -4
  64. package/lib/loopBackstop.mjs +4 -4
  65. package/lib/machineIdentity.mjs +9 -1
  66. package/lib/machineRoutes.mjs +181 -2
  67. package/lib/machineRuns.mjs +76 -1
  68. package/lib/machineSeal.mjs +39 -12
  69. package/lib/mcp-stdio.mjs +96 -26
  70. package/lib/mcpRelay.mjs +1 -1
  71. package/lib/members.json +13 -0
  72. package/lib/members.mjs +1 -1
  73. package/lib/models.mjs +77 -23
  74. package/lib/museSession.mjs +6 -1
  75. package/lib/nativeHost.mjs +35 -7
  76. package/lib/network.mjs +50 -5
  77. package/lib/notify.mjs +7 -5
  78. package/lib/nudge.mjs +3 -3
  79. package/lib/ocr.mjs +9 -9
  80. package/lib/onboard.mjs +141 -50
  81. package/lib/oneLine.mjs +7 -7
  82. package/lib/ownMachines.mjs +928 -149
  83. package/lib/pairing.mjs +39 -8
  84. package/lib/paths.mjs +15 -1
  85. package/lib/peerProcess.mjs +124 -0
  86. package/lib/personModel.mjs +3 -3
  87. package/lib/personNotices.mjs +151 -0
  88. package/lib/phones.mjs +490 -38
  89. package/lib/placeCommands.mjs +4 -4
  90. package/lib/places.mjs +70 -2
  91. package/lib/profile.mjs +67 -14
  92. package/lib/projectGit.mjs +158 -14
  93. package/lib/projectPieces.mjs +902 -0
  94. package/lib/projectSettings.mjs +7 -4
  95. package/lib/projects.mjs +384 -62
  96. package/lib/provenance.mjs +5 -1
  97. package/lib/proxyLinks.mjs +267 -0
  98. package/lib/reactions.mjs +7 -5
  99. package/lib/readiness.mjs +12 -7
  100. package/lib/record.mjs +19 -6
  101. package/lib/redact.mjs +4 -4
  102. package/lib/relayLimits.mjs +62 -0
  103. package/lib/release.mjs +170 -0
  104. package/lib/releaseKeys.json +6 -0
  105. package/lib/repoLinks.mjs +4 -4
  106. package/lib/roomChannels.mjs +24 -0
  107. package/lib/roomPage.mjs +1 -1
  108. package/lib/runAuthority.mjs +101 -0
  109. package/lib/runBrief.mjs +19 -8
  110. package/lib/runWorker.mjs +14 -5
  111. package/lib/runner.mjs +215 -25
  112. package/lib/runtime-install.mjs +143 -9
  113. package/lib/schedules.mjs +2 -2
  114. package/lib/screens.mjs +1 -1
  115. package/lib/sealed.mjs +11 -2
  116. package/lib/sealedThreads.mjs +671 -0
  117. package/lib/secretPatterns.json +1 -1
  118. package/lib/secrets.mjs +4 -4
  119. package/lib/seen.mjs +6 -6
  120. package/lib/serverWords.mjs +175 -0
  121. package/lib/service.mjs +22 -12
  122. package/lib/sessionControl.mjs +6 -6
  123. package/lib/specialties.mjs +6 -6
  124. package/lib/specialtyKeys.js +4 -5
  125. package/lib/specialtyNotice.mjs +7 -7
  126. package/lib/specialtySnapshot.mjs +5 -5
  127. package/lib/speech.mjs +5 -5
  128. package/lib/store.mjs +140 -39
  129. package/lib/stuck.mjs +1 -1
  130. package/lib/swarm.mjs +167 -16
  131. package/lib/swarmDevices.mjs +319 -0
  132. package/lib/swarmMemory.mjs +27 -25
  133. package/lib/t3.mjs +13 -13
  134. package/lib/taskCommands.mjs +44 -11
  135. package/lib/taskRooms.mjs +125 -0
  136. package/lib/taskRuns.mjs +36 -1
  137. package/lib/team.mjs +41 -18
  138. package/lib/threadActions.mjs +315 -0
  139. package/lib/threadAuthority.mjs +101 -0
  140. package/lib/threadBriefs.mjs +178 -0
  141. package/lib/threadLine.mjs +2 -2
  142. package/lib/threadRuns.mjs +138 -43
  143. package/lib/threadView.mjs +5 -5
  144. package/lib/usageTotals.mjs +2 -3
  145. package/lib/vault.mjs +101 -10
  146. package/lib/vaultCloud.mjs +2 -2
  147. package/lib/vaultCommands.mjs +15 -6
  148. package/lib/vaultTools.js +2 -2
  149. package/lib/verdicts.mjs +328 -0
  150. package/lib/wakes.mjs +1 -1
  151. package/lib/watches.mjs +2 -2
  152. package/lib/windowAsks.mjs +13 -5
  153. package/lib/worktrees.mjs +112 -18
  154. package/npm-shrinkwrap.json +1093 -0
  155. package/package.json +11 -10
  156. package/release.json +220 -0
package/lib/activity.mjs CHANGED
@@ -13,8 +13,8 @@ import { runningPids } from "./runner.mjs";
13
13
  // only while it uses CPU. An open turn with nothing running and nothing written is waiting,
14
14
  // most often at a permission prompt that nobody can answer with the lid closed.
15
15
 
16
- // Measured 2026-10-10 on the owner's transcripts, from a prompt or tool result to the model's next
17
- // write: p99.9 131 s for Claude Code (n=14,783), 310 s for Codex (n=3,673); 9 of 18,456 exceed 5 min.
16
+ // Measured on real transcripts, from a prompt or tool result to the model's next write: p99.9 131 s for Claude Code
17
+ // (n=14,783), 310 s for Codex (n=3,673); 9 of 18,456 exceed 5 min.
18
18
  export const QUIET_MS = 5 * 60_000;
19
19
  // Measured 2026-10-10 with ps: an idle server with a file watcher reads 0.0-0.1 %, a working process 99.9-100 %.
20
20
  export const CPU_BUSY = 5;
@@ -32,10 +32,10 @@ const SHELLS = new Set(["sh", "bash", "zsh", "fish", "dash", "ksh"]);
32
32
  // Started by Codex or pi during a turn without being a command it ran. A shell may exec the command itself, so any other child counts.
33
33
  const HELPERS = new Set(["caffeinate"]);
34
34
  const TAIL_BYTES = 256 << 10;
35
- // How far back a turn is looked for when the tail holds no row of one, its newest rows all being huge (a tool result,
36
- // a request). Measured 2026-10-16 on the owner's transcripts (Claude Code for a week, Codex for two): at the 2,435
37
- // moments in an open turn when the tail held none, the newest row of the turn began at most 2.3 MB (Claude Code) and
38
- // 4.5 MB (Codex, a single item) from the end.
35
+ // How far back a turn is looked for when the tail holds no row of one, its newest rows all being huge (a tool result, a
36
+ // request). Measured on real transcripts (Claude Code for a week, Codex for two): at the 2,435 moments in an open turn
37
+ // when the tail held none, the newest row of the turn began at most 2.3 MB (Claude Code) and 4.5 MB (Codex, a single
38
+ // item) from the end.
39
39
  const FAR_TAIL_BYTES = 8 << 20;
40
40
 
41
41
  const base = (token) => path.basename(String(token || "")).replace(/^-/, "");
@@ -123,7 +123,7 @@ export function turnOf(agent, rows) {
123
123
  const content = row.message?.content;
124
124
  if (row.type === "assistant") {
125
125
  const stop = row.message?.stop_reason;
126
- // Claude Code retries a refused answer itself: in the owner's transcripts (2026-10-16), each of the 4 refusals
126
+ // Claude Code retries a refused answer itself: in a week of real transcripts, each of the 4 refusals
127
127
  // that was not its own error row was followed by more of the same turn.
128
128
  const retried = stop === "refusal" && !row.isApiErrorMessage;
129
129
  // Any other answer that calls no tool ends the turn: end_turn, max_tokens, or Claude Code's own error row
@@ -198,9 +198,9 @@ const stat = (file) => {
198
198
 
199
199
  /**
200
200
  * A recorded Claude Code session's transcript and its subagents'. A subagent writes its own transcript under the
201
- * session's folder, and one run in the background works on after the session's own turn has ended. Measured 2026-10-16
202
- * on the owner's 14 sessions with subagents: 42% of subagent rows were written while the session's transcript alone
203
- * read finished or quiet for 5 minutes. Subagent transcripts older than the process are an earlier run's.
201
+ * session's folder, and one run in the background works on after the session's own turn has ended. Measured on 14 real
202
+ * sessions with subagents: 42% of subagent rows were written while the session's transcript alone read finished or
203
+ * quiet for 5 minutes. Subagent transcripts older than the process are an earlier run's.
204
204
  */
205
205
  function recordedTranscripts(folder, sessionId, startedAt) {
206
206
  const own = stat(path.join(folder, `${sessionId}.jsonl`));
package/lib/adapters.mjs CHANGED
@@ -28,6 +28,22 @@ const MCP_CLIENT_APPS = {
28
28
  // Agents that run in their own cloud but have an app here, where Open brings them forward. The app is checked to be that
29
29
  // agent's (its bundle id is in Info.plist, binary or XML), so another app with the same name is never opened as it.
30
30
  const AGENT_APPS = {
31
+ "claude-app": {
32
+ name: "Claude",
33
+ bundle: "com.anthropic.claudefordesktop",
34
+ darwin: [
35
+ "/Applications/Claude.app",
36
+ path.join(os.homedir(), "Applications", "Claude.app"),
37
+ ],
38
+ },
39
+ chatgpt: {
40
+ name: "ChatGPT",
41
+ bundle: "com.openai.chat",
42
+ darwin: [
43
+ "/Applications/ChatGPT.app",
44
+ path.join(os.homedir(), "Applications", "ChatGPT.app"),
45
+ ],
46
+ },
31
47
  muse: {
32
48
  name: "Muse",
33
49
  bundle: "com.meta.endo",
@@ -0,0 +1,71 @@
1
+ // The program Harness runs for each coding agent: the absolute path recorded when the person set the agent up (setup,
2
+ // agents add, agents confirm), never whatever the daemon's PATH finds first at run time. The service's PATH holds
3
+ // folders other programs can write to (Homebrew's, a Node version's), so a program planted there under an agent's
4
+ // name used to run in that agent's place, with the agent's unrestricted flags. Now it never runs; and when the
5
+ // recorded program is gone, the run is refused until the person confirms the one they have now.
6
+
7
+ import { AGENT_COMMANDS, resolveCommand } from "./commands.mjs";
8
+ import { runtimeOf } from "./agentRuntimeConfig.mjs";
9
+ import { readJson, writeJsonAtomic } from "./files.mjs";
10
+ import { paths } from "./paths.mjs";
11
+ import { relayCommand } from "./runtime-install.mjs";
12
+
13
+ /** The command an agent is started by: the person's configured executable, else its usual name. */
14
+ export function agentCommand(agent) {
15
+ return runtimeOf(agent)?.command || AGENT_COMMANDS[agent] || null;
16
+ }
17
+
18
+ /**
19
+ * Records the program `agent` runs as, found the way the person's own terminal finds it (`env`'s PATH). Returns
20
+ * { path, previous } (previous: the program recorded before, when it was another), or null when there is none.
21
+ */
22
+ export function confirmAgentBinary(
23
+ agent,
24
+ { env = process.env, file = paths.config } = {}
25
+ ) {
26
+ const command = agentCommand(agent);
27
+ const found = command && resolveCommand(command, env);
28
+ if (!found) return null;
29
+ const config = readJson(file, {});
30
+ const before = config.agentBinaries?.[agent]?.path ?? null;
31
+ writeJsonAtomic(file, {
32
+ ...config,
33
+ agentBinaries: {
34
+ ...config.agentBinaries,
35
+ [agent]: { command, path: found },
36
+ },
37
+ });
38
+ return { path: found, previous: before && before !== found ? before : null };
39
+ }
40
+
41
+ /**
42
+ * The absolute program to start for `agent`, whose command is `command`: the recorded one. An agent set up before
43
+ * Harness recorded programs, or whose command the person has since changed, is recorded at this first run. Null when
44
+ * the agent is not installed at all; throws when the recorded program is gone.
45
+ */
46
+ export function agentBinary(
47
+ agent,
48
+ command,
49
+ { env = process.env, file = paths.config } = {}
50
+ ) {
51
+ const recorded = readJson(file, {}).agentBinaries?.[agent];
52
+ if (!recorded || recorded.command !== command) {
53
+ const found = resolveCommand(command, env);
54
+ if (!found) return null;
55
+ const config = readJson(file, {});
56
+ writeJsonAtomic(file, {
57
+ ...config,
58
+ agentBinaries: {
59
+ ...config.agentBinaries,
60
+ [agent]: { command, path: found },
61
+ },
62
+ });
63
+ return found;
64
+ }
65
+ if (resolveCommand(recorded.path, env)) return recorded.path;
66
+ const now = resolveCommand(command, env);
67
+ throw new Error(
68
+ `Harness starts ${agent} only from ${recorded.path}, the program confirmed for it, and that is no longer there` +
69
+ `${now ? ` (${command} is now ${now})` : ""}. If you installed ${agent} again yourself, confirm it: ${relayCommand(`agents confirm ${agent}`)}`
70
+ );
71
+ }
@@ -2,7 +2,7 @@ import { readFileSync } from "node:fs";
2
2
  import { member } from "./members.mjs";
3
3
  import { paths } from "./paths.mjs";
4
4
 
5
- /** Installed agents only: the owner's executable selection never comes from a model or task. */
5
+ /** Installed agents only: the person's executable selection never comes from a model or task. */
6
6
  export function runtimeOf(agent) {
7
7
  const runtime = member(agent)?.runtime;
8
8
  if (!runtime) return null;
@@ -4,7 +4,7 @@ import { Readable, Writable } from "node:stream";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { tmpdir } from "node:os";
6
6
  import { agentEnvironment } from "./agentnode.mjs";
7
- import { resolveCommand } from "./commands.mjs";
7
+ import { agentBinary } from "./agentBinaries.mjs";
8
8
  import { runtimeOf } from "./agentRuntimeConfig.mjs";
9
9
  import { openMuseSession } from "./museSession.mjs";
10
10
 
@@ -28,7 +28,8 @@ const optionsOf = (option) =>
28
28
  (option?.options ?? []).flatMap((entry) => entry.options ?? [entry]);
29
29
  const selectedRuntime = (agent, grantedEnv = null) => {
30
30
  const runtime = runtimeOf(agent);
31
- const command = runtime && resolveCommand(runtime.command);
31
+ // The program confirmed for this agent, not the first one on PATH (agentBinaries.mjs).
32
+ const command = runtime && agentBinary(agent, runtime.command);
32
33
  if (!command)
33
34
  throw new Error(
34
35
  `Install and authenticate ${agent}, or configure its executable in Harness.`
@@ -287,7 +288,12 @@ async function runAcp(task, runtime, hooks) {
287
288
  "--agent",
288
289
  task.agent,
289
290
  ],
290
- env: [{ name: "HARNESS_RUN_ID", value: task.runId }],
291
+ env: [
292
+ { name: "HARNESS_RUN_ID", value: task.runId },
293
+ ...(task.capability
294
+ ? [{ name: "HARNESS_RUN_TOKEN", value: task.capability }]
295
+ : []),
296
+ ],
291
297
  },
292
298
  ],
293
299
  ...(task.sessionId ? { sessionId: task.sessionId } : {}),
@@ -5,19 +5,41 @@ import { spawn, spawnSync } from "node:child_process";
5
5
  import { randomBytes } from "node:crypto";
6
6
  import { secretReason } from "./secrets.mjs";
7
7
 
8
+ const { cloud: CLOUD_LIST } = JSON.parse(
9
+ fs.readFileSync(new URL("./members.json", import.meta.url), "utf8")
10
+ );
11
+
8
12
  // Signing the agents on a cloud computer in, from the person's window (docs/cloud-swarm.md §5.6). The box has no
9
13
  // screen and no terminal the person can reach, so each agent's OWN sign-in runs here and its words (a link, a code, a
10
14
  // question) go to the window sealed, and the one line it may ask for (a pasted code) comes back. Nothing here parses a
11
15
  // provider's flow beyond its status command: what the person reads is the provider's text. A line that looks like a
12
- // secret is never sent; a key the person gives is handed to the agent's own login (Codex) or settings (Claude Code)
13
- // and never stored by Harness. Where `script` exists (Linux) the sign-in gets a terminal of its own, since some
14
- // sign-ins only talk to one.
16
+ // secret is never sent; a key the person gives is handed to the agent's own login (Codex) or settings (Claude Code,
17
+ // OpenCode, Kilo, Pi) and never stored by Harness. Where `script` exists (Linux) the sign-in gets a terminal of its
18
+ // own, since some sign-ins only talk to one. Each kind of sign-in is listed in docs/cloud-swarm.md §5.6; an agent with
19
+ // no status command of its own counts as signed in once its sign-in here ended well (kept in signed-in.json).
20
+ // An agent the person put on Harness's AI or their proxy link (cloudAi.mjs) counts as signed in once Harness's settings
21
+ // point it there.
15
22
 
16
23
  const MAX_LINES = 200;
17
24
  const SESSIONS = 4;
18
25
  // ANSI colour and cursor sequences, which a terminal sign-in prints and a window cannot show.
19
26
  const ANSI = /\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\u0007|\r/g;
20
27
 
28
+ // OpenClaw's whole setup in one command, with no wizard (Boat test, October 25); --auth-choice picks the plan.
29
+ const OPENCLAW_ONBOARD = [
30
+ "onboard",
31
+ "--non-interactive",
32
+ "--accept-risk",
33
+ "--flow",
34
+ "quickstart",
35
+ "--install-daemon",
36
+ "--skip-ui",
37
+ "--auth-choice",
38
+ ];
39
+
40
+ // Each agent's own sign-in, by the plan it signs in with (the first is the default). `status` is the agent's own
41
+ // command that says whether it is signed in; null where none is known. `enterFirst`: the sign-in waits for Enter (or
42
+ // takes its highlighted first choice) before it shows anything.
21
43
  export const SIGN_IN_AGENTS = {
22
44
  "claude-code": {
23
45
  command: "claude",
@@ -29,16 +51,96 @@ export const SIGN_IN_AGENTS = {
29
51
  return false;
30
52
  }
31
53
  },
32
- subscription: ["auth", "login", "--claudeai"],
54
+ plans: { claude: ["auth", "login", "--claudeai"] },
33
55
  },
34
56
  codex: {
35
57
  command: "codex",
36
58
  status: ["login", "status"],
37
59
  signedIn: (result) => result.status === 0,
38
- subscription: ["login", "--device-auth"],
60
+ plans: { chatgpt: ["login", "--device-auth"] },
61
+ },
62
+ cursor: {
63
+ command: "cursor-agent",
64
+ status: ["status"],
65
+ signedIn: (result) =>
66
+ result.status === 0 &&
67
+ !/not (logged|signed) in|unauthenticated/i.test(result.stdout),
68
+ plans: { cursor: ["login"] },
69
+ // Without it Cursor tries to open a browser on a computer that has none.
70
+ env: { NO_OPEN_BROWSER: "1" },
39
71
  },
72
+ "grok-build": { command: "grok", status: null, plans: { grok: ["login"] } },
73
+ "muse-code": {
74
+ command: "muse",
75
+ status: null,
76
+ plans: { meta: ["login"] },
77
+ enterFirst: true,
78
+ },
79
+ // Antigravity's first start asks how to sign in, Google first; its -p mode gives up after 60 s, so the normal start.
80
+ antigravity: {
81
+ command: "agy",
82
+ status: null,
83
+ plans: { google: [] },
84
+ enterFirst: true,
85
+ },
86
+ openclaw: {
87
+ command: "openclaw",
88
+ status: null,
89
+ plans: {
90
+ chatgpt: [...OPENCLAW_ONBOARD, "openai-device-code"],
91
+ // Reuses Claude Code's sign-in on this computer.
92
+ claude: [...OPENCLAW_ONBOARD, "anthropic-cli"],
93
+ },
94
+ },
95
+ hermes: {
96
+ command: "hermes",
97
+ status: null,
98
+ plans: {
99
+ chatgpt: [
100
+ "auth",
101
+ "add",
102
+ "openai-codex",
103
+ "--type",
104
+ "oauth",
105
+ "--no-browser",
106
+ ],
107
+ claude: ["auth", "add", "anthropic", "--type", "oauth", "--no-browser"],
108
+ },
109
+ // Hermes picks its AI by provider; once a plan signs in it is the one used.
110
+ after: {
111
+ chatgpt: ["config", "set", "model.provider", "openai-codex"],
112
+ claude: ["config", "set", "model.provider", "anthropic"],
113
+ },
114
+ },
115
+ };
116
+
117
+ // Where agents with no sign-in of their own keep a key (their own auth files, read on this Mac October 25), and which
118
+ // provider a key is for, by its prefix.
119
+ const KEY_FILES = {
120
+ opencode: { file: [".local", "share", "opencode", "auth.json"], type: "api" },
121
+ kilo: { file: [".local", "share", "kilo", "auth.json"], type: "api" },
122
+ pi: { file: [".pi", "agent", "auth.json"], type: "api_key" },
123
+ };
124
+ // The agents with no sign-in of their own, which the window still lists: on Harness, or on a key.
125
+ const SETTINGS_AGENTS = { opencode: "opencode", kilo: "kilo", pi: "pi" };
126
+
127
+ // What an agent runs on before Harness has said, as src/shared/cloudAgents.ts defaultAi has it.
128
+ const defaultAi = (agent) => {
129
+ const row = CLOUD_LIST.find((each) => each.agent === agent);
130
+ return row?.harness ? "harness" : row?.plan ? "plan" : "key";
40
131
  };
41
132
 
133
+ const providerOf = (key) =>
134
+ key.startsWith("sk-ant-")
135
+ ? "anthropic"
136
+ : key.startsWith("sk-or-")
137
+ ? "openrouter"
138
+ : key.startsWith("xai-")
139
+ ? "xai"
140
+ : key.startsWith("sk-")
141
+ ? "openai"
142
+ : null;
143
+
42
144
  const clean = (text) =>
43
145
  String(text)
44
146
  .replace(ANSI, "")
@@ -57,8 +159,45 @@ export function createAgentSignIn({
57
159
  run = spawn,
58
160
  runSync = spawnSync,
59
161
  log = () => {},
162
+ // The AI the person chose for an agent ("harness", "plan", "key" or "link"), and what Harness's settings point it
163
+ // at now (cloudAi.mjs): Harness's AI, or the person's proxy link.
164
+ aiOf = () => null,
165
+ onHarness = () => false,
166
+ written = onHarness,
167
+ linkOf = () => null,
168
+ // Tests a proxy link for an agent and keeps it once a real call through it answered (cloudAi.mjs useLink), and how
169
+ // that test went, read with the agent's row.
170
+ useLink = () => ({
171
+ ok: false,
172
+ error: "This computer does not take proxy links.",
173
+ }),
174
+ linkTestOf = () => null,
175
+ // What Harness's settings point an agent at here (cloudAi.mjs kindOf): "harness", "link", "standin", "key" or null.
176
+ kindOf = () => null,
177
+ // Keeps the person's key for an agent on this computer, so its calls go through this computer's model address and
178
+ // to Harness's AI when the key does not answer (cloudAi.mjs keepKey).
179
+ keepKey = async () => {},
180
+ // Whether an agent's calls are on Harness's AI just now because its own link or key did not answer, and why.
181
+ switchOf = () => null,
60
182
  } = {}) {
61
183
  const sessions = new Map();
184
+ // Agents whose sign-in here ended well, for those with no status command.
185
+ const recordFile = path.join(home, ".harness", "signed-in.json");
186
+ const recorded = () => {
187
+ try {
188
+ return JSON.parse(fs.readFileSync(recordFile, "utf8"));
189
+ } catch {
190
+ return {};
191
+ }
192
+ };
193
+ const record = (agent) => {
194
+ fs.mkdirSync(path.dirname(recordFile), { recursive: true, mode: 0o700 });
195
+ fs.writeFileSync(
196
+ recordFile,
197
+ JSON.stringify({ ...recorded(), [agent]: new Date().toISOString() }),
198
+ { mode: 0o600 }
199
+ );
200
+ };
62
201
  const hasScript =
63
202
  process.platform === "linux" &&
64
203
  runSync("script", ["--version"], { stdio: "ignore" }).status === 0;
@@ -84,24 +223,79 @@ export function createAgentSignIn({
84
223
  child.stdin.end(input ?? "");
85
224
  });
86
225
 
87
- /** Which agents are signed in, by each agent's own status command. */
226
+ const hasKey = (agent) => {
227
+ const keyed = KEY_FILES[agent];
228
+ if (!keyed) return false;
229
+ try {
230
+ const saved = JSON.parse(
231
+ fs.readFileSync(path.join(home, ...keyed.file), "utf8")
232
+ );
233
+ return Object.values(saved).some((entry) => entry?.key);
234
+ } catch {
235
+ return false;
236
+ }
237
+ };
238
+
239
+ /** One agent's row: whether it is here and signed in, its plans, and the AI the person chose for it. */
240
+ const rowOf = async (agent, flow) => {
241
+ const answered = aiOf(agent);
242
+ const ai = answered ?? defaultAi(agent);
243
+ const result = await runToEnd(flow.command, flow.status ?? ["--version"]);
244
+ const installed = !result.error;
245
+ // By what the person chose (the inference boundary, cloudAi.mjs): on Harness's AI or a proxy link, signed in once
246
+ // Harness's settings point it there; on a plan or key, the agent's own sign-in decides, with none of Harness's
247
+ // settings left to take its place. An agent the person said nothing about here is signed in either way.
248
+ const ownSignIn = flow.status
249
+ ? flow.signedIn(result)
250
+ : Boolean(recorded()[agent]) || hasKey(agent);
251
+ const link = linkOf(agent);
252
+ const kind = kindOf(agent);
253
+ const ready = !answered
254
+ ? written(agent) || ownSignIn
255
+ : ai === "harness"
256
+ ? onHarness(agent)
257
+ : ai === "link"
258
+ ? Boolean(link) && kind === "link"
259
+ : ai === "key"
260
+ ? ownSignIn && kind === "key"
261
+ : ownSignIn && !written(agent);
262
+ return {
263
+ agent,
264
+ installed,
265
+ signedIn: installed && ready,
266
+ plans: Object.keys(flow.plans ?? {}),
267
+ ai,
268
+ ...(link
269
+ ? { link: { holder: link.holderLabel ?? null, model: link.model } }
270
+ : {}),
271
+ ...(linkTestOf(agent) ? { linkTest: linkTestOf(agent) } : {}),
272
+ ...(switchOf(agent) ? { onHarnessNow: switchOf(agent) } : {}),
273
+ };
274
+ };
275
+
276
+ /**
277
+ * Which agents are signed in, by each agent's own status command, a sign-in here that ended well, a key it keeps,
278
+ * or Harness's settings for an agent on Harness's AI.
279
+ */
88
280
  const status = async () => ({
89
281
  ok: true,
90
- agents: await Promise.all(
91
- Object.entries(SIGN_IN_AGENTS).map(async ([agent, flow]) => {
92
- const result = await runToEnd(flow.command, flow.status);
93
- return {
94
- agent,
95
- installed: !result.error,
96
- signedIn: !result.error && flow.signedIn(result),
97
- };
98
- })
99
- ),
282
+ agents: await Promise.all([
283
+ ...Object.entries(SIGN_IN_AGENTS).map(([agent, flow]) =>
284
+ rowOf(agent, flow)
285
+ ),
286
+ ...Object.entries(SETTINGS_AGENTS).map(([agent, command]) =>
287
+ rowOf(agent, { command, status: null, plans: {} })
288
+ ),
289
+ ]),
100
290
  });
101
291
 
102
- /** Start an agent's own subscription sign-in; its words are read with read(). */
103
- const start = (agent) => {
292
+ /** Start an agent's own sign-in with one of its plans (its first by default); its words are read with read(). */
293
+ const start = (agent, plan) => {
104
294
  const flow = flowOf(agent);
295
+ const chosen = plan ?? Object.keys(flow.plans)[0];
296
+ const signInArgs = flow.plans[chosen];
297
+ if (!signInArgs)
298
+ throw new Error(`${agent} does not sign in with ${String(plan)}`);
105
299
  for (const [id, session] of sessions)
106
300
  if (session.agent === agent && session.state === "running") stop(id);
107
301
  // The oldest sign-in makes room, stopped first so no sign-in runs on unseen.
@@ -114,17 +308,15 @@ export function createAgentSignIn({
114
308
  const [command, args] = hasScript
115
309
  ? [
116
310
  "script",
117
- [
118
- "-qfec",
119
- [flow.command, ...flow.subscription].join(" "),
120
- "/dev/null",
121
- ],
311
+ ["-qfec", [flow.command, ...signInArgs].join(" "), "/dev/null"],
122
312
  ]
123
- : [flow.command, flow.subscription];
313
+ : [flow.command, signInArgs];
124
314
  const child = run(command, args, {
125
- env: { ...env, BROWSER: "/bin/true" },
315
+ env: { ...env, BROWSER: "/bin/true", ...flow.env },
126
316
  stdio: ["pipe", "pipe", "pipe"],
127
317
  });
318
+ // Enter, as the sign-in reads it: through `script` the terminal turns a return into a newline, on a pipe it does not.
319
+ if (flow.enterFirst) child.stdin.write(hasScript ? "\r" : "\n");
128
320
  const session = { agent, child, lines: [], state: "running", code: null };
129
321
  const take = (chunk) => {
130
322
  session.lines.push(...clean(chunk));
@@ -138,10 +330,13 @@ export function createAgentSignIn({
138
330
  session.state = "failed";
139
331
  session.lines.push(`${flow.command} could not start: ${error.message}`);
140
332
  });
141
- child.on("close", (code) => {
333
+ child.on("close", async (code) => {
334
+ if (session.state === "running" && code === 0 && flow.after?.[chosen])
335
+ await runToEnd(flow.command, flow.after[chosen]);
142
336
  if (session.state === "running")
143
337
  session.state = code === 0 ? "done" : "failed";
144
338
  session.code = code;
339
+ if (session.state === "done" && !flow.status) record(agent);
145
340
  log(`${agent} sign-in ended (${session.state})`);
146
341
  });
147
342
  sessions.set(id, session);
@@ -188,9 +383,32 @@ export function createAgentSignIn({
188
383
  return { ok: true };
189
384
  };
190
385
 
191
- /** An API key instead of a subscription: given to the agent's own login, or its own settings file. */
386
+ const writeJson = (file, value) => {
387
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
388
+ fs.writeFileSync(file, JSON.stringify(value, null, 2) + "\n", {
389
+ mode: 0o600,
390
+ });
391
+ };
392
+ const readJson = (file) => {
393
+ try {
394
+ return JSON.parse(fs.readFileSync(file, "utf8"));
395
+ } catch {
396
+ return {};
397
+ }
398
+ };
399
+
400
+ /**
401
+ * An API key instead of a plan: given to the agent's own login, or its own settings file, and kept on this computer
402
+ * for its calls to go through this computer's model address (cloudAi.mjs keepKey), where Harness's AI answers a call
403
+ * the key does not. It never leaves this computer but to its own provider.
404
+ */
192
405
  const useKey = async (agent, key) => {
193
- flowOf(agent);
406
+ const given = await giveKey(agent, key);
407
+ if (given.ok)
408
+ await keepKey(agent, { provider: given.provider, key: given.key });
409
+ return given.ok ? { ok: true } : given;
410
+ };
411
+ const giveKey = async (agent, key) => {
194
412
  const value = String(key || "").trim();
195
413
  if (!/^[\x21-\x7e]{20,300}$/.test(value))
196
414
  return { ok: false, error: "That does not look like an API key." };
@@ -201,26 +419,38 @@ export function createAgentSignIn({
201
419
  value
202
420
  );
203
421
  return result.status === 0
204
- ? { ok: true }
422
+ ? { ok: true, provider: providerOf(value) ?? "openai", key: value }
205
423
  : { ok: false, error: "Codex did not take that key." };
206
424
  }
207
- // Claude Code reads the env block of its user settings for every run (code.claude.com settings).
208
- const file = path.join(home, ".claude", "settings.json");
209
- let settings = {};
210
- try {
211
- settings = JSON.parse(fs.readFileSync(file, "utf8"));
212
- } catch {}
213
- settings.env = { ...(settings.env || {}), ANTHROPIC_API_KEY: value };
214
- fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
215
- fs.writeFileSync(file, JSON.stringify(settings, null, 2) + "\n", {
216
- mode: 0o600,
425
+ if (agent === "claude-code") {
426
+ // Claude Code reads the env block of its user settings for every run (code.claude.com settings).
427
+ const file = path.join(home, ".claude", "settings.json");
428
+ const settings = readJson(file);
429
+ settings.env = { ...(settings.env || {}), ANTHROPIC_API_KEY: value };
430
+ writeJson(file, settings);
431
+ return { ok: true, provider: "anthropic", key: value };
432
+ }
433
+ const keyed = KEY_FILES[agent];
434
+ if (!keyed)
435
+ return { ok: false, error: "This agent signs in with its plan only." };
436
+ const provider = providerOf(value);
437
+ if (!provider)
438
+ return {
439
+ ok: false,
440
+ error:
441
+ "Use a key from Anthropic, OpenAI, OpenRouter or xAI for this agent.",
442
+ };
443
+ const file = path.join(home, ...keyed.file);
444
+ writeJson(file, {
445
+ ...readJson(file),
446
+ [provider]: { type: keyed.type, key: value },
217
447
  });
218
- return { ok: true };
448
+ return { ok: true, provider, key: value };
219
449
  };
220
450
 
221
451
  const close = () => {
222
452
  for (const id of sessions.keys()) stop(id);
223
453
  };
224
454
 
225
- return { status, start, read, send, stop, useKey, close };
455
+ return { status, start, read, send, stop, useKey, useLink, close };
226
456
  }
package/lib/answers.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { TAGGED_ONLY } from "./members.mjs";
2
2
 
3
- // Who hears a task's outcome. One rule for the whole swarm (owner, October 20: "behavior like this should be consistent
4
- // across the swarm"): when a task finishes, fails or asks back, the agent that posted it gets a turn, whatever it is,
5
- // wherever it runs and whether or not the task opened its own thread. How the turn reaches it differs by where the agent
6
- // runs (a coding agent's turn in the task's thread, OpenClaw's and Hermes's gateway, Grok Bot's and Muse's wake from
7
- // Harness, Harness's conversation or its thread); who gets one does not.
3
+ // Who hears a task's outcome. One rule for the whole swarm, so the behavior is consistent across it: when a task
4
+ // finishes, fails or asks back, the agent that posted it gets a turn, whatever it is, wherever it runs and whether or
5
+ // not the task opened its own thread. How the turn reaches it differs by where the agent runs (a coding agent's turn in
6
+ // the task's thread, OpenClaw's and Hermes's gateway, Grok Bot's and Muse's wake from Harness, Harness's conversation
7
+ // or its thread); who gets one does not.
8
8
  //
9
9
  // Never the person (their surfaces show the outcome), never the agent that did the work itself, and never an agent
10
10
  // that moves money or takes positions (Bankr, Quotient): an answer coming back does not start one of them; only the