tryharness 0.7.53 → 0.7.57

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 (167) hide show
  1. package/README.md +23 -19
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +484 -90
  5. package/lib/activity.mjs +10 -10
  6. package/lib/adapters.mjs +173 -222
  7. package/lib/agentBinaries.mjs +71 -0
  8. package/lib/agentRuntimeConfig.mjs +1 -1
  9. package/lib/agentRuntimes.mjs +34 -18
  10. package/lib/agentSignIn.mjs +456 -0
  11. package/lib/answers.mjs +5 -5
  12. package/lib/archetypes.d.ts +64 -0
  13. package/lib/archetypes.js +989 -0
  14. package/lib/asks.mjs +4 -4
  15. package/lib/audit.mjs +666 -0
  16. package/lib/backupSetup.mjs +143 -0
  17. package/lib/boardAccess.mjs +24 -11
  18. package/lib/boardBackup.mjs +283 -0
  19. package/lib/boardFileCommands.mjs +6 -6
  20. package/lib/boardFiles.mjs +13 -12
  21. package/lib/boardMirror.mjs +124 -25
  22. package/lib/boardProtocol.json +88 -2
  23. package/lib/boardWaits.mjs +101 -0
  24. package/lib/book.mjs +659 -0
  25. package/lib/bridge.mjs +6 -6
  26. package/lib/cards.mjs +138 -28
  27. package/lib/cloudAgents.mjs +216 -0
  28. package/lib/cloudAi.mjs +1312 -0
  29. package/lib/cloudAssistants.mjs +242 -0
  30. package/lib/cloudBoot.mjs +119 -0
  31. package/lib/cloudSave.mjs +197 -0
  32. package/lib/cloudSsh.mjs +178 -0
  33. package/lib/commands.mjs +7 -2
  34. package/lib/context.mjs +19 -5
  35. package/lib/contractGate.mjs +399 -0
  36. package/lib/control-client.mjs +9 -1
  37. package/lib/controlSocket.mjs +86 -0
  38. package/lib/coordinator.mjs +252 -144
  39. package/lib/daemon.mjs +1351 -2767
  40. package/lib/desk.mjs +240 -0
  41. package/lib/desktop.mjs +178 -74
  42. package/lib/directLink.mjs +16 -5
  43. package/lib/environment.mjs +2 -1
  44. package/lib/environments.mjs +247 -9
  45. package/lib/firewall.mjs +9 -9
  46. package/lib/folders.mjs +20 -16
  47. package/lib/frames.mjs +2 -3
  48. package/lib/gitHost.mjs +174 -0
  49. package/lib/goalCommands.mjs +25 -7
  50. package/lib/goals.mjs +7 -7
  51. package/lib/guestRequests.mjs +94 -0
  52. package/lib/handoffs.mjs +8 -7
  53. package/lib/handover.mjs +4 -4
  54. package/lib/harnessModel.mjs +6 -6
  55. package/lib/harnessOffers.mjs +266 -0
  56. package/lib/hookDialects.mjs +298 -0
  57. package/lib/inference.mjs +26 -8
  58. package/lib/jobAnswers.mjs +190 -0
  59. package/lib/landed.mjs +887 -0
  60. package/lib/lane.mjs +42 -11
  61. package/lib/lessons.mjs +16 -16
  62. package/lib/library.mjs +3 -3
  63. package/lib/lineup.mjs +3 -0
  64. package/lib/linkRelay.mjs +574 -0
  65. package/lib/live.mjs +284 -13
  66. package/lib/localAgentAsk.mjs +74 -0
  67. package/lib/localStack.mjs +536 -0
  68. package/lib/localmodels.mjs +6 -4
  69. package/lib/loopBackstop.mjs +4 -4
  70. package/lib/machineIdentity.mjs +9 -1
  71. package/lib/machineRoutes.mjs +181 -2
  72. package/lib/machineRuns.mjs +76 -1
  73. package/lib/machineSeal.mjs +39 -12
  74. package/lib/mcp-stdio.mjs +163 -27
  75. package/lib/mcpRelay.mjs +1 -1
  76. package/lib/members.json +29 -2
  77. package/lib/members.mjs +1 -1
  78. package/lib/models.mjs +85 -31
  79. package/lib/museSession.mjs +21 -13
  80. package/lib/nativeHost.mjs +36 -8
  81. package/lib/neovim.mjs +126 -0
  82. package/lib/network.mjs +50 -5
  83. package/lib/notify.mjs +7 -5
  84. package/lib/nudge.mjs +50 -19
  85. package/lib/ocr.mjs +9 -9
  86. package/lib/onboard.mjs +26 -20
  87. package/lib/oneLine.mjs +7 -7
  88. package/lib/ownMachines.mjs +1223 -140
  89. package/lib/pairing.mjs +60 -16
  90. package/lib/paths.mjs +19 -1
  91. package/lib/peerProcess.mjs +124 -0
  92. package/lib/personModel.mjs +89 -0
  93. package/lib/personNotices.mjs +151 -0
  94. package/lib/phones.mjs +538 -31
  95. package/lib/placeCommands.mjs +4 -4
  96. package/lib/places.mjs +400 -12
  97. package/lib/profile.mjs +67 -14
  98. package/lib/projectGit.mjs +158 -14
  99. package/lib/projectPieces.mjs +902 -0
  100. package/lib/projectSettings.mjs +7 -4
  101. package/lib/projects.mjs +384 -62
  102. package/lib/provenance.mjs +5 -1
  103. package/lib/proxyLinks.mjs +267 -0
  104. package/lib/reactions.mjs +7 -5
  105. package/lib/readiness.mjs +145 -23
  106. package/lib/record.mjs +128 -0
  107. package/lib/redact.mjs +4 -4
  108. package/lib/relayLimits.mjs +62 -0
  109. package/lib/release.mjs +170 -0
  110. package/lib/releaseKeys.json +6 -0
  111. package/lib/repoLinks.mjs +4 -4
  112. package/lib/roomChannels.mjs +24 -0
  113. package/lib/roomPage.mjs +1 -1
  114. package/lib/runAuthority.mjs +101 -0
  115. package/lib/runBrief.mjs +19 -8
  116. package/lib/runWorker.mjs +31 -7
  117. package/lib/runner.mjs +223 -29
  118. package/lib/runtime-install.mjs +143 -9
  119. package/lib/schedules.mjs +2 -2
  120. package/lib/screens.mjs +1 -1
  121. package/lib/sealed.mjs +11 -2
  122. package/lib/sealedThreads.mjs +671 -0
  123. package/lib/secretPatterns.json +1 -1
  124. package/lib/secrets.mjs +4 -4
  125. package/lib/seen.mjs +6 -6
  126. package/lib/serverWords.mjs +175 -0
  127. package/lib/service.mjs +22 -12
  128. package/lib/sessionControl.mjs +378 -90
  129. package/lib/specialties.json +74 -0
  130. package/lib/specialties.mjs +477 -0
  131. package/lib/specialtyKeys.d.ts +3 -0
  132. package/lib/specialtyKeys.js +57 -0
  133. package/lib/specialtyNotice.mjs +147 -0
  134. package/lib/specialtySnapshot.mjs +138 -0
  135. package/lib/speech.mjs +5 -5
  136. package/lib/store.mjs +420 -36
  137. package/lib/stuck.mjs +1 -1
  138. package/lib/swarm.mjs +304 -37
  139. package/lib/swarmDevices.mjs +319 -0
  140. package/lib/swarmMemory.mjs +27 -25
  141. package/lib/t3.mjs +24 -15
  142. package/lib/taskCommands.mjs +80 -20
  143. package/lib/taskRooms.mjs +125 -0
  144. package/lib/taskRuns.mjs +45 -3
  145. package/lib/team.json +255 -148
  146. package/lib/team.mjs +554 -190
  147. package/lib/threadActions.mjs +315 -0
  148. package/lib/threadAuthority.mjs +101 -0
  149. package/lib/threadBriefs.mjs +178 -0
  150. package/lib/threadLine.mjs +116 -0
  151. package/lib/threadRuns.mjs +209 -50
  152. package/lib/threadView.mjs +20 -7
  153. package/lib/usageTotals.mjs +2 -3
  154. package/lib/vault.mjs +101 -10
  155. package/lib/vaultCloud.mjs +2 -2
  156. package/lib/vaultCommands.mjs +15 -6
  157. package/lib/vaultTools.js +2 -2
  158. package/lib/verdicts.mjs +328 -0
  159. package/lib/wakes.mjs +1 -1
  160. package/lib/watches.mjs +2 -2
  161. package/lib/windowAsks.mjs +13 -5
  162. package/lib/worktrees.mjs +157 -25
  163. package/npm-shrinkwrap.json +1093 -0
  164. package/package.json +12 -11
  165. package/release.json +220 -0
  166. package/lib/modelTiers.json +0 -1183
  167. package/lib/modelTiers.mjs +0 -133
@@ -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.`
@@ -259,30 +260,45 @@ async function runAcp(task, runtime, hooks) {
259
260
  terminal: false,
260
261
  },
261
262
  });
262
- if (task.sessionId && !initialized.agentCapabilities?.loadSession)
263
+ // An existing session is loaded (its history replayed) or, where the agent offers only that, resumed without its
264
+ // history (session/resume, as DeepSeek Harness's ACP does).
265
+ const capabilities = initialized.agentCapabilities ?? {};
266
+ const reopen = !task.sessionId
267
+ ? "session/new"
268
+ : capabilities.loadSession
269
+ ? "session/load"
270
+ : capabilities.sessionCapabilities?.resume
271
+ ? "session/resume"
272
+ : null;
273
+ if (!reopen)
263
274
  throw new Error(
264
275
  "This ACP agent cannot resume its existing session; Harness did not start a replacement."
265
276
  );
266
277
  const args = {
267
278
  cwd: task.cwd,
268
- mcpServers: [
269
- {
270
- name: "harness",
271
- command: process.execPath,
272
- args: [
273
- fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)),
274
- "--agent",
275
- task.agent,
279
+ // A readiness check (readiness.mjs) runs without Harness's tools.
280
+ mcpServers: task.withoutHarnessTools
281
+ ? []
282
+ : [
283
+ {
284
+ name: "harness",
285
+ command: process.execPath,
286
+ args: [
287
+ fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)),
288
+ "--agent",
289
+ task.agent,
290
+ ],
291
+ env: [
292
+ { name: "HARNESS_RUN_ID", value: task.runId },
293
+ ...(task.capability
294
+ ? [{ name: "HARNESS_RUN_TOKEN", value: task.capability }]
295
+ : []),
296
+ ],
297
+ },
276
298
  ],
277
- env: [{ name: "HARNESS_RUN_ID", value: task.runId }],
278
- },
279
- ],
280
299
  ...(task.sessionId ? { sessionId: task.sessionId } : {}),
281
300
  };
282
- const session = await connection.agent.request(
283
- task.sessionId ? "session/load" : "session/new",
284
- args
285
- );
301
+ const session = await connection.agent.request(reopen, args);
286
302
  sessionId = task.sessionId || session.sessionId;
287
303
  if (!sessionId)
288
304
  throw new Error("The ACP agent did not identify its session.");
@@ -0,0 +1,456 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { spawn, spawnSync } from "node:child_process";
5
+ import { randomBytes } from "node:crypto";
6
+ import { secretReason } from "./secrets.mjs";
7
+
8
+ const { cloud: CLOUD_LIST } = JSON.parse(
9
+ fs.readFileSync(new URL("./members.json", import.meta.url), "utf8")
10
+ );
11
+
12
+ // Signing the agents on a cloud computer in, from the person's window (docs/cloud-swarm.md §5.6). The box has no
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
14
+ // question) go to the window sealed, and the one line it may ask for (a pasted code) comes back. Nothing here parses a
15
+ // provider's flow beyond its status command: what the person reads is the provider's text. A line that looks like a
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.
22
+
23
+ const MAX_LINES = 200;
24
+ const SESSIONS = 4;
25
+ // ANSI colour and cursor sequences, which a terminal sign-in prints and a window cannot show.
26
+ const ANSI = /\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\u0007|\r/g;
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.
43
+ export const SIGN_IN_AGENTS = {
44
+ "claude-code": {
45
+ command: "claude",
46
+ status: ["auth", "status", "--json"],
47
+ signedIn: (result) => {
48
+ try {
49
+ return JSON.parse(result.stdout).loggedIn === true;
50
+ } catch {
51
+ return false;
52
+ }
53
+ },
54
+ plans: { claude: ["auth", "login", "--claudeai"] },
55
+ },
56
+ codex: {
57
+ command: "codex",
58
+ status: ["login", "status"],
59
+ signedIn: (result) => result.status === 0,
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" },
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";
131
+ };
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
+
144
+ const clean = (text) =>
145
+ String(text)
146
+ .replace(ANSI, "")
147
+ .split("\n")
148
+ .map((line) => line.trimEnd())
149
+ .filter(Boolean)
150
+ .map((line) =>
151
+ secretReason(line)
152
+ ? "(something secret was printed here; it stays on this computer)"
153
+ : line
154
+ );
155
+
156
+ export function createAgentSignIn({
157
+ home = os.homedir(),
158
+ env = process.env,
159
+ run = spawn,
160
+ runSync = spawnSync,
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,
182
+ } = {}) {
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
+ };
201
+ const hasScript =
202
+ process.platform === "linux" &&
203
+ runSync("script", ["--version"], { stdio: "ignore" }).status === 0;
204
+
205
+ const flowOf = (agent) => {
206
+ const flow = SIGN_IN_AGENTS[agent];
207
+ if (!flow) throw new Error(`there is no sign-in here for ${agent}`);
208
+ return flow;
209
+ };
210
+
211
+ // A command run to its end without holding the daemon up: its output, exit code, or the error it could not start with.
212
+ const runToEnd = (command, args, input) =>
213
+ new Promise((resolve) => {
214
+ let stdout = "";
215
+ const child = run(command, args, {
216
+ env,
217
+ stdio: ["pipe", "pipe", "ignore"],
218
+ });
219
+ child.stdout.on("data", (chunk) => (stdout += chunk));
220
+ child.stdin.on("error", () => {});
221
+ child.on("error", (error) => resolve({ error, stdout, status: null }));
222
+ child.on("close", (status) => resolve({ stdout, status }));
223
+ child.stdin.end(input ?? "");
224
+ });
225
+
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
+ */
280
+ const status = async () => ({
281
+ ok: true,
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
+ ]),
290
+ });
291
+
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) => {
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)}`);
299
+ for (const [id, session] of sessions)
300
+ if (session.agent === agent && session.state === "running") stop(id);
301
+ // The oldest sign-in makes room, stopped first so no sign-in runs on unseen.
302
+ if (sessions.size >= SESSIONS) {
303
+ const oldest = sessions.keys().next().value;
304
+ stop(oldest);
305
+ sessions.delete(oldest);
306
+ }
307
+ const id = randomBytes(9).toString("base64url");
308
+ const [command, args] = hasScript
309
+ ? [
310
+ "script",
311
+ ["-qfec", [flow.command, ...signInArgs].join(" "), "/dev/null"],
312
+ ]
313
+ : [flow.command, signInArgs];
314
+ const child = run(command, args, {
315
+ env: { ...env, BROWSER: "/bin/true", ...flow.env },
316
+ stdio: ["pipe", "pipe", "pipe"],
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");
320
+ const session = { agent, child, lines: [], state: "running", code: null };
321
+ const take = (chunk) => {
322
+ session.lines.push(...clean(chunk));
323
+ if (session.lines.length > MAX_LINES)
324
+ session.lines.splice(0, session.lines.length - MAX_LINES);
325
+ };
326
+ child.stdout.on("data", take);
327
+ child.stderr.on("data", take);
328
+ child.stdin.on("error", () => {});
329
+ child.on("error", (error) => {
330
+ session.state = "failed";
331
+ session.lines.push(`${flow.command} could not start: ${error.message}`);
332
+ });
333
+ child.on("close", async (code) => {
334
+ if (session.state === "running" && code === 0 && flow.after?.[chosen])
335
+ await runToEnd(flow.command, flow.after[chosen]);
336
+ if (session.state === "running")
337
+ session.state = code === 0 ? "done" : "failed";
338
+ session.code = code;
339
+ if (session.state === "done" && !flow.status) record(agent);
340
+ log(`${agent} sign-in ended (${session.state})`);
341
+ });
342
+ sessions.set(id, session);
343
+ log(`${agent} sign-in started`);
344
+ return { ok: true, id };
345
+ };
346
+
347
+ const sessionOf = (id) => {
348
+ const session = sessions.get(String(id));
349
+ if (!session) throw new Error("that sign-in is over; start it again");
350
+ return session;
351
+ };
352
+
353
+ const read = (id) => {
354
+ const session = sessionOf(id);
355
+ return {
356
+ ok: true,
357
+ agent: session.agent,
358
+ state: session.state,
359
+ lines: session.lines,
360
+ };
361
+ };
362
+
363
+ /** One line for the sign-in that asked for it (a code pasted from the provider's page). */
364
+ const send = (id, text) => {
365
+ const session = sessionOf(id);
366
+ if (session.state !== "running")
367
+ return { ok: false, error: "that sign-in is over" };
368
+ session.child.stdin.write(
369
+ `${String(text)
370
+ .replace(/[\r\n]/g, "")
371
+ .slice(0, 2000)}\n`
372
+ );
373
+ return { ok: true };
374
+ };
375
+
376
+ const stop = (id) => {
377
+ const session = sessions.get(String(id));
378
+ if (!session) return { ok: true };
379
+ if (session.state === "running") {
380
+ session.state = "stopped";
381
+ session.child.kill("SIGTERM");
382
+ }
383
+ return { ok: true };
384
+ };
385
+
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
+ */
405
+ const useKey = async (agent, key) => {
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) => {
412
+ const value = String(key || "").trim();
413
+ if (!/^[\x21-\x7e]{20,300}$/.test(value))
414
+ return { ok: false, error: "That does not look like an API key." };
415
+ if (agent === "codex") {
416
+ const result = await runToEnd(
417
+ "codex",
418
+ ["login", "--with-api-key"],
419
+ value
420
+ );
421
+ return result.status === 0
422
+ ? { ok: true, provider: providerOf(value) ?? "openai", key: value }
423
+ : { ok: false, error: "Codex did not take that key." };
424
+ }
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 },
447
+ });
448
+ return { ok: true, provider, key: value };
449
+ };
450
+
451
+ const close = () => {
452
+ for (const id of sessions.keys()) stop(id);
453
+ };
454
+
455
+ return { status, start, read, send, stop, useKey, useLink, close };
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
@@ -0,0 +1,64 @@
1
+ export const ARCHETYPE_IDS: readonly [
2
+ "general",
3
+ "software",
4
+ "trading",
5
+ "content",
6
+ "writing",
7
+ "research",
8
+ ];
9
+ export type Archetype = (typeof ARCHETYPE_IDS)[number];
10
+ export type ArchetypeSkill = {
11
+ name: string;
12
+ description: string;
13
+ instructions: string;
14
+ source?: string;
15
+ hosts?: string[];
16
+ };
17
+ export const ARCHETYPES: Record<
18
+ Archetype,
19
+ {
20
+ name: string;
21
+ description: string;
22
+ guidance: string;
23
+ tools: string[];
24
+ skills: Record<string, ArchetypeSkill>;
25
+ }
26
+ >;
27
+ export const ARCHETYPE_TOOL: {
28
+ name: "archetype";
29
+ description: string;
30
+ inputSchema: Record<string, unknown>;
31
+ };
32
+ export const ARCHETYPE_HOSTS: string[];
33
+ export function resolveArchetype(value?: unknown): Archetype;
34
+ export function archetypeBrief(
35
+ profile?: { archetype?: Archetype } | null
36
+ ): string;
37
+ export function readArchetype(
38
+ profile?: { archetype?: Archetype } | null,
39
+ input?: unknown,
40
+ options?: { liveData?: boolean }
41
+ ):
42
+ | { ok: false; error: string }
43
+ | {
44
+ ok: true;
45
+ selected: Archetype;
46
+ skill: ArchetypeSkill & { id: string; pack: Archetype };
47
+ calling?: string;
48
+ }
49
+ | {
50
+ ok: true;
51
+ selected: Archetype;
52
+ pack: Archetype;
53
+ name: string;
54
+ guidance: string;
55
+ tools: string[];
56
+ toolAvailability: string;
57
+ skills: Array<{
58
+ id: string;
59
+ name: string;
60
+ description: string;
61
+ liveData?: true;
62
+ }>;
63
+ otherPacks: Array<{ id: Archetype; name: string; description: string }>;
64
+ };