tryharness 0.7.44 → 0.7.53

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 (101) hide show
  1. package/README.md +232 -12
  2. package/cli.mjs +406 -184
  3. package/lib/actorRoster.mjs +28 -5
  4. package/lib/adapters.mjs +9 -1
  5. package/lib/agentRuntimeConfig.mjs +36 -0
  6. package/lib/agentRuntimes.mjs +560 -0
  7. package/lib/atlas.mjs +7 -2
  8. package/lib/boardCommands.mjs +5 -10
  9. package/lib/boardFileCommands.mjs +2 -1
  10. package/lib/boardMirror.mjs +459 -0
  11. package/lib/boardProtocol.json +259 -6
  12. package/lib/boardTools.mjs +2 -6
  13. package/lib/bridge.mjs +27 -3
  14. package/lib/browserWake.mjs +60 -0
  15. package/lib/cards.mjs +35 -2
  16. package/lib/commands.mjs +20 -5
  17. package/lib/connectionTools.d.ts +13 -0
  18. package/lib/connectionTools.js +45 -0
  19. package/lib/connectorAuth.mjs +309 -0
  20. package/lib/connectorCatalog.json +41 -0
  21. package/lib/connectorCommands.mjs +121 -0
  22. package/lib/connectorGoogle.mjs +513 -0
  23. package/lib/connectors.mjs +805 -0
  24. package/lib/coordinator.mjs +16 -2
  25. package/lib/coreModels.mjs +78 -0
  26. package/lib/daemon.mjs +775 -46
  27. package/lib/desktop.mjs +7 -2
  28. package/lib/digest.mjs +32 -0
  29. package/lib/directLink.mjs +283 -0
  30. package/lib/environments.mjs +595 -0
  31. package/lib/folders.mjs +2 -2
  32. package/lib/goalCommands.mjs +61 -12
  33. package/lib/inference.mjs +263 -152
  34. package/lib/lessons.mjs +6 -0
  35. package/lib/lineup.mjs +324 -0
  36. package/lib/localmodels.mjs +10 -0
  37. package/lib/machineIdentity.mjs +3 -0
  38. package/lib/machineRoutes.mjs +40 -2
  39. package/lib/machineRuns.mjs +30 -3
  40. package/lib/machineSeal.mjs +69 -10
  41. package/lib/mcp-stdio.mjs +180 -98
  42. package/lib/mcpRelay.mjs +119 -0
  43. package/lib/members.json +12 -0
  44. package/lib/members.mjs +33 -0
  45. package/lib/modelMemory.mjs +100 -0
  46. package/lib/modelTiers.json +1183 -0
  47. package/lib/modelTiers.mjs +133 -0
  48. package/lib/models.mjs +41 -8
  49. package/lib/museSession.mjs +119 -0
  50. package/lib/nativeHost.mjs +203 -0
  51. package/lib/network.mjs +38 -1
  52. package/lib/nudge.mjs +10 -2
  53. package/lib/onboard.mjs +430 -1
  54. package/lib/oneclawLocal.mjs +150 -0
  55. package/lib/ownMachines.mjs +521 -36
  56. package/lib/pairing.mjs +165 -0
  57. package/lib/paths.mjs +4 -0
  58. package/lib/phones.mjs +61 -0
  59. package/lib/placeCommands.mjs +27 -0
  60. package/lib/places.mjs +10 -2
  61. package/lib/plans.mjs +151 -27
  62. package/lib/profile.mjs +152 -0
  63. package/lib/projectGit.mjs +328 -0
  64. package/lib/projectSettings.mjs +120 -0
  65. package/lib/projects.mjs +2539 -0
  66. package/lib/readiness.mjs +283 -0
  67. package/lib/repoLinks.mjs +354 -0
  68. package/lib/roomChannels.mjs +641 -0
  69. package/lib/runBrief.mjs +32 -2
  70. package/lib/runRequests.mjs +157 -0
  71. package/lib/runWorker.mjs +20 -7
  72. package/lib/runner.mjs +67 -8
  73. package/lib/secretPatterns.json +55 -0
  74. package/lib/secrets.mjs +10 -27
  75. package/lib/seen.mjs +102 -0
  76. package/lib/service.mjs +11 -6
  77. package/lib/sessionControl.mjs +10 -8
  78. package/lib/sessionIndex.mjs +5 -3
  79. package/lib/store.mjs +559 -30
  80. package/lib/subagents.mjs +8 -4
  81. package/lib/swarm.mjs +379 -38
  82. package/lib/swarmMemory.mjs +947 -0
  83. package/lib/t3.mjs +43 -13
  84. package/lib/taskCommands.mjs +58 -5
  85. package/lib/taskRuns.mjs +61 -11
  86. package/lib/team.json +17 -15
  87. package/lib/team.mjs +68 -18
  88. package/lib/threadRuns.mjs +50 -7
  89. package/lib/threadView.mjs +68 -15
  90. package/lib/tokenizer.mjs +405 -0
  91. package/lib/ui.mjs +16 -2
  92. package/lib/usageTotals.mjs +148 -0
  93. package/lib/vault.mjs +1144 -0
  94. package/lib/vaultCloud.mjs +117 -0
  95. package/lib/vaultCommands.mjs +201 -0
  96. package/lib/vaultTools.d.ts +12 -0
  97. package/lib/vaultTools.js +42 -0
  98. package/lib/windowAsks.mjs +42 -0
  99. package/lib/workFocus.mjs +59 -0
  100. package/lib/workLinks.mjs +90 -0
  101. package/package.json +9 -4
package/lib/lineup.mjs ADDED
@@ -0,0 +1,324 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { detectAgents } from "./commands.mjs";
5
+ import { detectLocalAgents, setupHermes, setupOpenClaw } from "./wakes.mjs";
6
+ import { configureAgents } from "./adapters.mjs";
7
+ import { MACHINE_RUNNERS, nameOf } from "./members.mjs";
8
+ import { paths } from "./paths.mjs";
9
+ import { readJson, writeJsonAtomic } from "./files.mjs";
10
+ import { createAgentReadiness, SIGN_IN } from "./readiness.mjs";
11
+
12
+ // The swarm's lineup: the agents the person put in it. Setup offers only the agents installed and signed in on this
13
+ // computer, already ticked, and the person keeps the ones they want; every other agent joins only when they add it
14
+ // (`npx tryharness agents add`, or Add an agent in the buddy's settings). The list lives in the config as
15
+ // `swarmAgents`. A config from before the lineup has none, and its swarm stays as it was: every agent the roster finds.
16
+ // Harness itself is always in the swarm.
17
+
18
+ /** Agents that run on this computer: the coding agents Harness starts, and the assistants it wakes by webhook. */
19
+ const HERE = [...MACHINE_RUNNERS, "openclaw", "hermes"];
20
+ /** Agents that live elsewhere and are added on purpose; Grok Bot and Muse also need their own setup in Harness. */
21
+ const ELSEWHERE = ["grok-bot", "bankr", "quotient", "muse"];
22
+ const NEEDS_SETUP_ELSEWHERE = new Set(["grok-bot", "muse"]);
23
+
24
+ const PROVIDER_KEYS = [
25
+ "ANTHROPIC_API_KEY",
26
+ "OPENAI_API_KEY",
27
+ "GEMINI_API_KEY",
28
+ "OPENROUTER_API_KEY",
29
+ ];
30
+
31
+ /**
32
+ * Whether a coding agent here looks signed in: its own sign-in file, or a provider key in the environment it reads.
33
+ * A guess from files, so a "signed out" agent is still offered, only not ticked.
34
+ */
35
+ export function signedIn(
36
+ agent,
37
+ { homeDir = os.homedir(), env = process.env } = {}
38
+ ) {
39
+ const file = (...parts) => {
40
+ try {
41
+ return fs.readFileSync(path.join(...parts), "utf8");
42
+ } catch {
43
+ return null;
44
+ }
45
+ };
46
+ const key = (...names) => names.some((name) => Boolean(env[name]?.trim()));
47
+ const dataHome = env.XDG_DATA_HOME || path.join(homeDir, ".local", "share");
48
+ switch (agent) {
49
+ case "claude-code":
50
+ return (
51
+ key("ANTHROPIC_API_KEY") ||
52
+ /"oauthAccount"\s*:\s*\{/.test(file(homeDir, ".claude.json") ?? "") ||
53
+ file(homeDir, ".claude", ".credentials.json") !== null
54
+ );
55
+ case "codex":
56
+ return (
57
+ key("OPENAI_API_KEY") ||
58
+ file(env.CODEX_HOME || path.join(homeDir, ".codex"), "auth.json") !==
59
+ null
60
+ );
61
+ case "pi":
62
+ return (
63
+ key(...PROVIDER_KEYS) ||
64
+ file(homeDir, ".pi", "agent", "auth.json") !== null
65
+ );
66
+ case "opencode":
67
+ return (
68
+ key(...PROVIDER_KEYS) ||
69
+ file(dataHome, "opencode", "auth.json") !== null ||
70
+ /"provider"\s*:/.test(
71
+ file(homeDir, ".config", "opencode", "opencode.json") ?? ""
72
+ )
73
+ );
74
+ // OpenClaw and Hermes are found by their own setup folders: found is set up.
75
+ case "openclaw":
76
+ case "hermes":
77
+ return true;
78
+ // An agent whose sign-in Harness cannot read (Cursor, Grok Build, Antigravity, Muse Code) is offered unticked.
79
+ default:
80
+ return false;
81
+ }
82
+ }
83
+
84
+ /**
85
+ * The agents found on this computer, as setup offers them: `ready` when installed and signed in, `signed_out` when
86
+ * installed but not signed in yet. Agents not found here are not listed.
87
+ */
88
+ export function agentsHere({
89
+ homeDir = os.homedir(),
90
+ env = process.env,
91
+ coding = detectAgents(),
92
+ local = detectLocalAgents({ homeDir }),
93
+ // The last real check of each agent (readiness.mjs): an answer to a prompt outranks a guess from its files.
94
+ checked = createAgentReadiness().all(),
95
+ } = {}) {
96
+ const found = new Set([
97
+ ...coding.filter((entry) => entry.path).map((entry) => entry.agent),
98
+ ...local.filter((entry) => entry.found).map((entry) => entry.agent),
99
+ ]);
100
+ return HERE.filter((id) => found.has(id)).map((id) => {
101
+ const check = checked[id];
102
+ const ready = check
103
+ ? check.state === "ready"
104
+ : signedIn(id, { homeDir, env });
105
+ return {
106
+ id,
107
+ name: nameOf(id),
108
+ state: ready ? "ready" : "signed_out",
109
+ hint: ready ? null : signInHint(id, check),
110
+ };
111
+ });
112
+ }
113
+
114
+ const signInHint = (id, check) =>
115
+ check && check.state !== "signed_out" && check.detail
116
+ ? `${nameOf(id)} did not answer: ${check.detail}`
117
+ : SIGN_IN[id]
118
+ ? `sign in to ${nameOf(id)} first: run ${SIGN_IN[id]}`
119
+ : `sign in to ${nameOf(id)} first`;
120
+
121
+ /** The lineup in a config, or null for a config from before it (every agent the roster finds is in). */
122
+ export const lineupOf = (config) =>
123
+ Array.isArray(config?.swarmAgents) ? config.swarmAgents : null;
124
+
125
+ /** One module the daemon, setup and the CLI share: the lineup in the config file, read again only when it changes. */
126
+ export function createLineup({ file = paths.config } = {}) {
127
+ let cached = { mtimeMs: -1, list: null };
128
+ const read = () => {
129
+ let mtimeMs = 0;
130
+ try {
131
+ mtimeMs = fs.statSync(file).mtimeMs;
132
+ } catch {}
133
+ if (mtimeMs !== cached.mtimeMs)
134
+ cached = { mtimeMs, list: lineupOf(readJson(file, {})) };
135
+ return cached.list;
136
+ };
137
+ // `swarmRemoved`: the agents the person took out, which an agent watch (readiness.mjs) never puts back by itself.
138
+ const write = (list, removed) => {
139
+ const config = readJson(file, {});
140
+ const kept = (removed ?? config.swarmRemoved ?? []).filter(
141
+ (id) => !list.includes(id)
142
+ );
143
+ writeJsonAtomic(file, {
144
+ ...config,
145
+ swarmAgents: [...new Set(list)],
146
+ swarmRemoved: [...new Set(kept)],
147
+ });
148
+ cached = { mtimeMs: -1, list: null };
149
+ };
150
+ return {
151
+ /** Whether an agent is in the swarm; Harness always is, and so is everyone when there is no lineup yet. */
152
+ has: (agent) => {
153
+ const list = read();
154
+ return agent === "harness" || list === null || list.includes(agent);
155
+ },
156
+ list: () => read(),
157
+ /** Whether the person took this agent out of their swarm themselves. */
158
+ removedByPerson: (agent) =>
159
+ (readJson(file, {}).swarmRemoved ?? []).includes(agent),
160
+ /** Start the lineup (setup) with exactly these agents. */
161
+ set: (agents) => write(agents.filter((id) => id !== "harness")),
162
+ add: (agent) => {
163
+ const list = read();
164
+ // A swarm from before the lineup keeps everything it had; adding to it changes nothing.
165
+ if (list === null || list.includes(agent)) return;
166
+ write([...list, agent]);
167
+ },
168
+ // A swarm from before the lineup had everyone in it: taking one out keeps every other agent, connected or not.
169
+ remove: (agent) => {
170
+ const list = read() ?? [...HERE, ...ELSEWHERE];
171
+ const removed = readJson(file, {}).swarmRemoved ?? [];
172
+ write(
173
+ list.filter((id) => id !== agent),
174
+ [...removed, agent]
175
+ );
176
+ },
177
+ };
178
+ }
179
+
180
+ /**
181
+ * Every agent the person could have in their swarm, as the add-an-agent lists show it: in the swarm or not, and what
182
+ * adding it needs. `here` is agentsHere(); `has` the lineup's.
183
+ */
184
+ const ORDER = ["ready", "signed_out", "needs_setup", "not_installed"];
185
+ export function addable({ here, has }) {
186
+ const found = new Map(here.map((entry) => [entry.id, entry]));
187
+ return (
188
+ [...HERE, ...ELSEWHERE]
189
+ .map((id) => {
190
+ const local = found.get(id);
191
+ const where = HERE.includes(id) ? "this computer" : "elsewhere";
192
+ const state = HERE.includes(id)
193
+ ? (local?.state ?? "not_installed")
194
+ : NEEDS_SETUP_ELSEWHERE.has(id)
195
+ ? "needs_setup"
196
+ : "ready";
197
+ return {
198
+ id,
199
+ name: nameOf(id),
200
+ where,
201
+ state,
202
+ // An agent this computer does not have is not in the swarm here, whatever an older lineup kept.
203
+ inSwarm: has(id) && state !== "not_installed",
204
+ hint:
205
+ state === "not_installed"
206
+ ? `install ${nameOf(id)} on this computer first`
207
+ : state === "signed_out"
208
+ ? `sign in to ${nameOf(id)} first`
209
+ : state === "needs_setup"
210
+ ? "set up in Harness once added"
211
+ : null,
212
+ };
213
+ })
214
+ // What can be added now first, what is not installed here last.
215
+ .sort((a, b) => ORDER.indexOf(a.state) - ORDER.indexOf(b.state))
216
+ );
217
+ }
218
+
219
+ /**
220
+ * Put one agent in the swarm, doing what that takes on this computer: a coding agent gets Harness's MCP server and
221
+ * hooks (adapters.mjs), OpenClaw and Hermes their MCP entry and webhook (wakes.mjs). An agent that lives elsewhere is
222
+ * only added; Grok Bot and Muse then wait for their own setup in Harness, as their cards say.
223
+ */
224
+ export function joinAgent({
225
+ agent,
226
+ lineup,
227
+ runtimeRoot,
228
+ file = paths.config,
229
+ here = agentsHere(),
230
+ configure = configureAgents,
231
+ localSetup = { openclaw: setupOpenClaw, hermes: setupHermes },
232
+ }) {
233
+ const local = here.find((entry) => entry.id === agent);
234
+ if (HERE.includes(agent)) {
235
+ if (!local)
236
+ return {
237
+ ok: false,
238
+ error: `${nameOf(agent)} is not installed on this computer. Install it, then add it again.`,
239
+ };
240
+ if (!runtimeRoot)
241
+ return {
242
+ ok: false,
243
+ error:
244
+ "Harness is not set up on this computer yet. Run: npx tryharness",
245
+ };
246
+ if (MACHINE_RUNNERS.includes(agent)) {
247
+ const state = configure({ runtimeRoot, selected: [agent] }).find(
248
+ (entry) => entry.agent === agent
249
+ );
250
+ if (!state?.configured)
251
+ return {
252
+ ok: false,
253
+ error: `${nameOf(agent)} could not be connected: ${state?.detail ?? "no answer"}`,
254
+ };
255
+ const config = readJson(file, {});
256
+ writeJsonAtomic(file, {
257
+ ...config,
258
+ agentStates: { ...config.agentStates, [agent]: state },
259
+ });
260
+ } else {
261
+ const result = localSetup[agent]({ runtimeRoot });
262
+ if (!result.ok) return { ok: false, error: result.detail };
263
+ }
264
+ } else if (!ELSEWHERE.includes(agent))
265
+ return {
266
+ ok: false,
267
+ error: `Harness does not know an agent called ${agent}.`,
268
+ };
269
+ lineup.add(agent);
270
+ return {
271
+ ok: true,
272
+ agent,
273
+ name: nameOf(agent),
274
+ signedOut: local?.state === "signed_out",
275
+ needsSetup: NEEDS_SETUP_ELSEWHERE.has(agent),
276
+ };
277
+ }
278
+
279
+ /** The daemon's lineup commands, for the CLI and the buddy: list, add, remove, and check that an agent takes a prompt. */
280
+ export function createLineupCommands({
281
+ lineup,
282
+ runtimeRoot,
283
+ readiness = createAgentReadiness(),
284
+ onChanged = () => {},
285
+ }) {
286
+ const COMMANDS = new Set([
287
+ "swarm.lineup",
288
+ "swarm.add",
289
+ "swarm.remove",
290
+ "swarm.check",
291
+ ]);
292
+ return {
293
+ handles: (command) => COMMANDS.has(command),
294
+ run(request) {
295
+ if (request.command === "swarm.lineup")
296
+ return {
297
+ ok: true,
298
+ agents: addable({ here: agentsHere(), has: lineup.has }),
299
+ };
300
+ // `target`, not `agent`: every surface sends `agent` as who is asking (the person).
301
+ const agent = String(request.target || "");
302
+ if (request.command === "swarm.check")
303
+ return {
304
+ pending: readiness.check(agent).then((entry) => ({
305
+ ok: true,
306
+ agent,
307
+ name: nameOf(agent),
308
+ signIn: SIGN_IN[agent] ?? null,
309
+ ...entry,
310
+ })),
311
+ };
312
+ if (request.command === "swarm.add") {
313
+ const joined = joinAgent({ agent, lineup, runtimeRoot: runtimeRoot() });
314
+ if (joined.ok) onChanged(agent);
315
+ return joined;
316
+ }
317
+ if (agent === "harness")
318
+ return { ok: false, error: "Harness is always in your swarm." };
319
+ lineup.remove(agent);
320
+ onChanged(agent);
321
+ return { ok: true, agent, name: nameOf(agent) };
322
+ },
323
+ };
324
+ }
@@ -73,12 +73,17 @@ export const LLAMA = {
73
73
  },
74
74
  };
75
75
 
76
+ // memoryMb: the model's peak added memory (phys_footprint, MallocLargeCache=0) alone through the relay's host at a
77
+ // representative job, measured on an M5 Pro on October 22 (.harness-runs/relay-memory-20261022/cost-probe.mjs): what the
78
+ // memory ceiling (modelMemory.mjs) charges while it is loaded. The llama models include the llama-server router, the
79
+ // guards their shared tokenizer.
76
80
  export const MODELS = [
77
81
  {
78
82
  id: "search",
79
83
  name: "EmbeddingGemma 2 (text)",
80
84
  purpose: "One search space over code, agent sessions and board posts",
81
85
  tier: "core",
86
+ memoryMb: 280,
82
87
  runtime: "llama",
83
88
  licence: "apache-2.0",
84
89
  repo: "ggml-org/embeddinggemma-2-GGUF",
@@ -98,6 +103,7 @@ export const MODELS = [
98
103
  name: "Wolf Defender small",
99
104
  purpose: "Spots instructions hidden in what one agent hands another",
100
105
  tier: "core",
106
+ memoryMb: 144,
101
107
  runtime: "onnx",
102
108
  licence: "apache-2.0",
103
109
  repo: "patronus-studio/wolf-defender-prompt-injection-small",
@@ -137,6 +143,7 @@ export const MODELS = [
137
143
  name: "Horizon PI guard small",
138
144
  purpose: "Finds one planted instruction in a long page or post",
139
145
  tier: "core",
146
+ memoryMb: 226,
140
147
  runtime: "onnx",
141
148
  licence: "apache-2.0",
142
149
  repo: "Horizon-Labs/prompt-injection-guard-small",
@@ -162,6 +169,7 @@ export const MODELS = [
162
169
  name: "credential-line 32M",
163
170
  purpose: "Spots keys and passwords before a brief leaves the computer",
164
171
  tier: "core",
172
+ memoryMb: 128,
165
173
  runtime: "onnx",
166
174
  licence: "mit",
167
175
  repo: "zaindanaharper/credential-line-32m",
@@ -207,6 +215,7 @@ export const MODELS = [
207
215
  purpose:
208
216
  "Finds the minute of a recording or the screenshot a request is about, in folders the person adds",
209
217
  tier: "extended",
218
+ memoryMb: 857,
210
219
  runtime: "llama",
211
220
  licence: "apache-2.0",
212
221
  repo: "ggml-org/embeddinggemma-2-GGUF",
@@ -229,6 +238,7 @@ export const MODELS = [
229
238
  purpose:
230
239
  "Reads screenshots so keys and personal details are hidden before an image leaves the computer",
231
240
  tier: "core",
241
+ memoryMb: 307,
232
242
  runtime: "onnx",
233
243
  licence: "apache-2.0",
234
244
  repo: "PaddlePaddle/en_PP-OCRv5_mobile_rec_onnx",
@@ -5,6 +5,7 @@ import { readJson, writeJsonAtomic } from "./files.mjs";
5
5
  // Which of the person's computers this is (machine.json, beside its key in ~/.harness): a fixed id made once, the name
6
6
  // the person reads it by (the hostname until they rename it: npx tryharness machines name <name>), and the role
7
7
  // Harness last gave it, home or worker (src/server/bridge/machines.ts decides; this is its memory between starts).
8
+ // Setup leaves the code it showed here (joinCode) for the daemon, which takes it as this computer's join code.
8
9
 
9
10
  const ID = /^[A-Za-z0-9_-]{8,64}$/;
10
11
  const ROLES = new Set(["home", "worker"]);
@@ -28,6 +29,7 @@ export function loadMachine(file) {
28
29
  ? saved.label.trim().slice(0, 64)
29
30
  : hostname(),
30
31
  role: ROLES.has(saved.role) ? saved.role : null,
32
+ joinCode: typeof saved.joinCode === "string" ? saved.joinCode : null,
31
33
  };
32
34
  if (saved.id !== machine.id || saved.label !== machine.label)
33
35
  saveMachine(file, machine);
@@ -39,5 +41,6 @@ export function saveMachine(file, machine) {
39
41
  id: machine.id,
40
42
  label: machine.label,
41
43
  ...(machine.role ? { role: machine.role } : {}),
44
+ ...(machine.joinCode ? { joinCode: machine.joinCode } : {}),
42
45
  });
43
46
  }
@@ -1,4 +1,5 @@
1
1
  import { boardCommandOwner } from "./boardProtocol.mjs";
2
+ import { member } from "./members.mjs";
2
3
 
3
4
  // Where board work goes when the person's agents live on several computers. The board is home's; an agent keeps its
4
5
  // id and a task names the computer it is for (target_machine) and the one that took it (claimed_machine). People and
@@ -6,16 +7,29 @@ import { boardCommandOwner } from "./boardProtocol.mjs";
6
7
 
7
8
  // What an agent does on its own computer: its tools on local files, its live session, the watches set there, its
8
9
  // prompts. Everything else on the board is home's.
9
- const LOCAL_OWNERS = new Set(["tools", "live", "watch", "prompt"]);
10
+ // `repos`: a repository link is found on, and cloned onto, the computer the person is at, never home's disk.
11
+ // `nativeRequests`: an agent's permission request lives in the memory of the computer whose run asked (runRequests.mjs).
12
+ const LOCAL_OWNERS = new Set([
13
+ "tools",
14
+ "live",
15
+ "watch",
16
+ "prompt",
17
+ "repos",
18
+ "nativeRequests",
19
+ ]);
10
20
 
11
21
  /** Whether a worker sends this board command to home. */
12
22
  export const goesHome = (command) =>
13
23
  String(command).startsWith("board.") &&
24
+ // The board copy's own calls go between computers only, never on an agent's behalf (boardMirror.mjs).
25
+ !String(command).startsWith("board.mirror.") &&
14
26
  !LOCAL_OWNERS.has(boardCommandOwner(String(command)));
15
27
 
16
28
  // Writes an agent need not wait on: while home is out of reach the worker keeps them, sealed, and sends them when it is
17
- // back. A claim or a post waits for its answer instead.
29
+ // back. A post is one: any computer can start a task (owner, October 21), with its id chosen there. A claim waits for
30
+ // its answer instead, since two computers could take the same task.
18
31
  const QUEUEABLE = new Set([
32
+ "board.post",
19
33
  "board.report",
20
34
  "board.answer",
21
35
  "board.release",
@@ -26,6 +40,19 @@ const QUEUEABLE = new Set([
26
40
  ]);
27
41
  export const queueable = (command) => QUEUEABLE.has(String(command));
28
42
 
43
+ // Reads a worker answers from its copy of the board (boardMirror.mjs) while home is out of reach, saying how old it is.
44
+ // What is not copied (agents' last reads, the coordinator's rounds, search vectors) is never answered from it.
45
+ const FROM_COPY = new Set([
46
+ "board.list",
47
+ "board.get",
48
+ "board.children",
49
+ "board.thread.read",
50
+ "board.room.read",
51
+ "board.goal.get",
52
+ "board.goal.list",
53
+ ]);
54
+ export const readsFromCopy = (command) => FROM_COPY.has(String(command));
55
+
29
56
  /** Whether a caller on `machine` may take this task: work meant for one computer is taken only there. */
30
57
  export const mayClaim = (task, machine) =>
31
58
  !task?.target_machine || task.target_machine === machine;
@@ -95,3 +122,14 @@ export function placeTask({
95
122
 
96
123
  /** How people and agents read an agent on a computer: "Codex (linux)". */
97
124
  export const onMachine = (name, label) => (label ? `${name} (${label})` : name);
125
+
126
+ /**
127
+ * A post as readers get it: words from an agent that runs on the person's computers say which one wrote them
128
+ * (`computer`, read "Codex (linux)"), once the person has more than one. `computerOf` gives that name for a computer's
129
+ * id, or null while there is only one.
130
+ */
131
+ export function withComputer(post, computerOf) {
132
+ if (!post?.machine || member(post.author)?.home !== "machine") return post;
133
+ const computer = computerOf(post.machine);
134
+ return computer ? { ...post, computer } : post;
135
+ }
@@ -51,9 +51,32 @@ export function createMachineRuns({ callHome, taskRuns, agents, log }) {
51
51
  .join("\n\n");
52
52
  };
53
53
 
54
- const start = (task, slot) => {
54
+ // The person's environment grants for this run, from home's vault (vault.mjs), sealed to this computer like every
55
+ // answer from home. Without home there are none: the run starts without them.
56
+ const secretsFor = async (task, agent) => {
57
+ const answer = await callHome({
58
+ command: "board.vault.env",
59
+ agent,
60
+ runAgent: agent,
61
+ task: task.id,
62
+ }).catch(() => null);
63
+ if (answer?.ok !== true || !Object.keys(answer.env ?? {}).length) return {};
64
+ const scrub = new Map(
65
+ Object.entries(answer.names ?? {}).map(([variable, secret]) => [
66
+ secret,
67
+ answer.env[variable],
68
+ ])
69
+ );
70
+ return { env: answer.env, scrub };
71
+ };
72
+
73
+ const start = async (task, slot) => {
55
74
  const agent = task.target_agent;
56
75
  log(`running ${agent}'s task ${task.id} from your home computer`);
76
+ const secrets = await secretsFor(task, agent);
77
+ // Sent again with the finish: the two calls go to home at once, and a finish that arrives first closes the run to
78
+ // the session call (two-machines: home kept no session, one run in four).
79
+ let session = null;
57
80
  taskRuns.startTask(
58
81
  {
59
82
  runId: task.id,
@@ -61,15 +84,18 @@ export function createMachineRuns({ callHome, taskRuns, agents, log }) {
61
84
  title: String(task.objective || "").slice(0, 120),
62
85
  brief: briefOf(task),
63
86
  cwd: task.run_workspace,
87
+ ...secrets,
64
88
  },
65
89
  (kind, text, extra) => {
66
- if (kind === "session" && text)
90
+ if (kind === "session" && text) {
91
+ session = text;
67
92
  void callHome({
68
93
  command: "board.machine.session",
69
94
  agent,
70
95
  id: task.id,
71
96
  session: text,
72
97
  });
98
+ }
73
99
  if (kind === "progress") tellStep(task.id, agent);
74
100
  if (kind !== "done" && kind !== "failed") return;
75
101
  stopSteps(task.id);
@@ -82,6 +108,7 @@ export function createMachineRuns({ callHome, taskRuns, agents, log }) {
82
108
  result: text || "",
83
109
  failure: extra?.failure ?? "exit",
84
110
  ...(extra?.usage ? { usage: extra.usage } : {}),
111
+ ...(session ? { session } : {}),
85
112
  }).then((answer) => {
86
113
  if (answer?.ok === false)
87
114
  log(
@@ -118,7 +145,7 @@ export function createMachineRuns({ callHome, taskRuns, agents, log }) {
118
145
  });
119
146
  if (!taken?.ok) continue;
120
147
  active.set(slot, task.id);
121
- start(taken.task, slot);
148
+ void start(taken.task, slot);
122
149
  }
123
150
  } finally {
124
151
  asking = false;
@@ -7,38 +7,64 @@ import {
7
7
  seal,
8
8
  } from "./sealed.mjs";
9
9
 
10
- // Calls between the person's own computers (HSC1, cli/lib/sealed.mjs): a worker's board calls to home and home's
11
- // notices to a worker go through Harness, which carries them and cannot read or forge them.
10
+ // Calls between the person's own computers (HSC1, cli/lib/sealed.mjs): a worker's board calls to home, home's notices to
11
+ // a worker, and home's questions for the windows linked to a worker go through Harness, which carries them and cannot
12
+ // read or forge them.
12
13
  //
13
14
  // - Each computer has its static ECDH identity (phone-identity.json). The two keys of a home and a worker give one
14
15
  // AES-256-GCM key for the pair; every message binds its direction, the worker's id and its request id.
15
- // - Keys are pinned once (own_machines) by the join handshake: the worker shows a 12-character join code, the person
16
- // types it on home, and each side proves it holds the code by an HMAC over both computers' ids and keys. Harness
17
- // never sees the code, so it cannot stand in for either computer with a key of its own.
16
+ // - Keys are pinned once (own_machines) by the join handshake: the worker shows a join code, the person types it on
17
+ // home, and each side proves it holds the code by an HMAC over both computers' ids and keys. Harness never sees the
18
+ // code, so it cannot stand in for either computer with a key of its own.
19
+ // - Setup shows one 16-character code that is both the pairing code and the join code. Harness hears only its first 4
20
+ // characters, to find the waiting computer, and a verifier only the whole code makes, so approving it needs the
21
+ // code the person read; the 12 characters it never hears keep the join's 60 secret bits.
18
22
  // - A call is refused when it is stale (five minutes either way, seven days for a write queued while the worker was
19
23
  // offline), replayed, or sealed for another worker or direction.
20
24
 
21
25
  export const QUEUED_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
22
26
  const CODE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
23
- const CODE_LENGTH = 12;
27
+ const JOIN_LENGTH = 12;
28
+ const PAIR_LENGTH = 16;
29
+ const LOOKUP_LENGTH = 4;
24
30
 
25
- /** A new join code: 60 random bits, shown as XXXX-XXXX-XXXX. */
26
- export function newJoinCode() {
27
- const bytes = randomBytes(CODE_LENGTH);
31
+ function randomCode(length) {
32
+ const bytes = randomBytes(length);
28
33
  const letters = [...bytes].map((byte) => CODE_ALPHABET[byte & 31]).join("");
29
34
  return letters.match(/.{4}/g).join("-");
30
35
  }
31
36
 
37
+ /** A new join code: 60 random bits, shown as XXXX-XXXX-XXXX. */
38
+ export const newJoinCode = () => randomCode(JOIN_LENGTH);
39
+
40
+ /** Setup's one code, for pairing and joining: 80 random bits, shown as XXXX-XXXX-XXXX-XXXX. */
41
+ export const newPairCode = () => randomCode(PAIR_LENGTH);
42
+
32
43
  /** The code as typed (any case, with or without dashes), or null when it is not one. */
33
44
  export function normalizeJoinCode(text) {
34
45
  const letters = String(text ?? "")
35
46
  .toUpperCase()
36
47
  .replace(/[^A-Z2-7]/g, "");
37
- return letters.length === CODE_LENGTH
48
+ return [JOIN_LENGTH, PAIR_LENGTH].includes(letters.length)
38
49
  ? letters.match(/.{4}/g).join("-")
39
50
  : null;
40
51
  }
41
52
 
53
+ /** Whether a normalized code is setup's pairing code, which Harness can look up. */
54
+ export const isPairCode = (code) =>
55
+ code?.replace(/-/g, "").length === PAIR_LENGTH;
56
+
57
+ /** What Harness hears of a pairing code: the part it finds the waiting computer by, and proof of the whole code. */
58
+ export function pairClaim(code) {
59
+ const normal = normalizeJoinCode(code);
60
+ return {
61
+ lookup: normal.slice(0, LOOKUP_LENGTH),
62
+ verifier: createHmac("sha256", normal)
63
+ .update("HSC1-pair-verifier")
64
+ .digest("base64url"),
65
+ };
66
+ }
67
+
42
68
  /** What a side of the join proves: it holds the code, over both computers' ids and keys. */
43
69
  export function joinProof(
44
70
  code,
@@ -155,3 +181,36 @@ export async function openNotice(
155
181
  if (!firstSeen(envelope.requestId)) return null;
156
182
  return opened.notice;
157
183
  }
184
+
185
+ /** Home asking a worker to put a question to the Harness windows linked to it (their screen history). */
186
+ export const sealAsk = (key, workerId, requestId, call, now = Date.now()) =>
187
+ seal(key, "h2a", workerId, requestId, { ts: now, call });
188
+
189
+ /** The worker opening home's question: fresh and never twice, as a call is. Null when it is not one. */
190
+ export async function openAsk(
191
+ key,
192
+ envelope,
193
+ { workerId, firstSeen, now = Date.now() }
194
+ ) {
195
+ if (envelope?.deviceId !== workerId) return null;
196
+ let opened;
197
+ try {
198
+ opened = await open(key, "h2a", envelope);
199
+ } catch {
200
+ return null;
201
+ }
202
+ if (Math.abs(age(opened.ts, now)) > MAX_SKEW_MS) return null;
203
+ if (!firstSeen(envelope.requestId)) return null;
204
+ return opened.call ?? null;
205
+ }
206
+
207
+ /** The worker's windows' answer to home's question. */
208
+ export const sealAskAnswer = (key, workerId, requestId, value) =>
209
+ seal(key, "a2h", workerId, requestId, value);
210
+
211
+ /** Home opening a worker's answer to its own question: anything else is refused. */
212
+ export async function openAskAnswer(key, envelope, { workerId, requestId }) {
213
+ if (envelope?.deviceId !== workerId || envelope?.requestId !== requestId)
214
+ throw new Error("the answer was for another question");
215
+ return open(key, "a2h", envelope);
216
+ }