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
@@ -4,6 +4,9 @@ import { oneLine } from "./oneLine.mjs";
4
4
  // every other agent writes as an agent, and an
5
5
  // agent-written task taints everything posted under it. A label only ever tightens: a parent's
6
6
  // or Harness's 'agent' cannot be lifted by anything below it. The server applies the same rule.
7
+ // Harness writes as the user only from the person's own window, sealed from their device: a post in its name that
8
+ // arrived in the clear through Harness's server (`viaServer`) is the server's word, so it is agent-written like any
9
+ // hosted agent's (security audit S2).
7
10
 
8
11
  const USER_WRITERS = new Set(["user", "harness"]);
9
12
 
@@ -11,7 +14,7 @@ export function provenanceFor(
11
14
  originAgent,
12
15
  parent = null,
13
16
  claimed = null,
14
- { personSession = false } = {}
17
+ { personSession = false, viaServer = false } = {}
15
18
  ) {
16
19
  // A claim counts only when it tightens: an 'agent' label and its chain. A claim of 'user' adds nothing.
17
20
  const taint = claimed?.trust === "agent" ? claimed : null;
@@ -23,6 +26,7 @@ export function provenanceFor(
23
26
  const tainted =
24
27
  parent?.trust === "agent" ||
25
28
  Boolean(taint) ||
29
+ (viaServer && originAgent !== "user") ||
26
30
  (!USER_WRITERS.has(originAgent) && !personSession);
27
31
  return {
28
32
  trust: originAgent === "user" || !tainted ? "user" : "agent",
@@ -0,0 +1,267 @@
1
+ import path from "node:path";
2
+ import { randomBytes } from "node:crypto";
3
+ import { readJson, writeJsonAtomic } from "./files.mjs";
4
+ import { modelCallUrl } from "./lane.mjs";
5
+ import { paths } from "./paths.mjs";
6
+
7
+ // A proxy link, on the computer that reaches the person's own model (docs/cloud-swarm.md, inference boundary): the
8
+ // person lets one of their cloud computers use a model endpoint only this computer reaches (a model server on it, or
9
+ // on their network, or a provider with a key kept here). The cloud computer's agents call a local address on the box
10
+ // (linkRelay.mjs), which sends each call here sealed over the line the two computers share (ownMachines.mjs); Harness
11
+ // carries the envelopes and reads none of them. The address and any key stay here: the cloud computer knows only
12
+ // which link to name.
13
+ //
14
+ // Only the person's own window allows a link, naming the one cloud computer it is for. A call from any other computer,
15
+ // for another link, or for anything but a model call on that endpoint is refused (as lane.mjs keeps Harness's server
16
+ // to the person's endpoint, security audit S11).
17
+ //
18
+ // An answer comes back in parts: the box starts a call, then reads it from an offset until it ends. A read waits for
19
+ // bytes past its offset, and one that went unanswered (each message between computers has the line's own deadline) is
20
+ // asked again from the same offset, so nothing is lost or repeated and no deadline of its own is needed here.
21
+
22
+ /** The model calls a link carries, each with its method, under the endpoint's own path: the agents' three wires. */
23
+ export const LINK_CALLS = new Map([
24
+ ["/chat/completions", "POST"],
25
+ ["/completions", "POST"],
26
+ ["/responses", "POST"],
27
+ ["/messages", "POST"],
28
+ ["/messages/count_tokens", "POST"],
29
+ ["/models", "GET"],
30
+ ]);
31
+ // The request headers a model call needs; the box's own token for its local address never leaves it.
32
+ const PASSED_HEADERS = [
33
+ "content-type",
34
+ "accept",
35
+ "anthropic-version",
36
+ "anthropic-beta",
37
+ "openai-beta",
38
+ ];
39
+ const ID = /^[A-Za-z0-9_-]{8,64}$/;
40
+ // A part of an answer, before it is sealed: small, since home keeps its last answers to repeat one sent twice.
41
+ const PART_BYTES = 64 * 1024;
42
+ // Calls in flight or not yet read to their end; the oldest is dropped past this.
43
+ const OPEN_CALLS = 16;
44
+
45
+ export const proxyLinksFile = () => path.join(paths.home, "proxy-links.json");
46
+
47
+ // What may be said of a link anywhere: never its key.
48
+ const described = ({ key, ...link }) => ({ ...link, hasKey: Boolean(key) });
49
+
50
+ export function createProxyLinks({
51
+ file = proxyLinksFile(),
52
+ log = () => {},
53
+ fetchImpl = fetch,
54
+ // This computer: { id, label }, so the box knows which computer holds the link.
55
+ self = () => ({ id: null, label: null }),
56
+ // Whether a computer is one this computer confirmed with (its home, or a worker of it): only it can call here.
57
+ known = () => true,
58
+ } = {}) {
59
+ const links = () => readJson(file, { links: [] }).links ?? [];
60
+ const keep = (list) => writeJsonAtomic(file, { links: list });
61
+
62
+ /** The person's window allows one cloud computer to use an endpoint this computer reaches. */
63
+ const allow = ({ computer, baseUrl, key = null, label = null }) => {
64
+ const machine = String(computer || "");
65
+ if (!ID.test(machine))
66
+ return { ok: false, error: "Name the cloud computer the link is for." };
67
+ if (!known(machine))
68
+ return {
69
+ ok: false,
70
+ error:
71
+ "That cloud computer is not in your swarm with this computer yet. Add it to your swarm first.",
72
+ };
73
+ let base;
74
+ try {
75
+ base = new URL(String(baseUrl || "").trim());
76
+ } catch {
77
+ return { ok: false, error: "That is not an address." };
78
+ }
79
+ if (!["http:", "https:"].includes(base.protocol) || base.username)
80
+ return {
81
+ ok: false,
82
+ error: "Use an http or https address, with no name or password in it.",
83
+ };
84
+ const secret = key == null ? "" : String(key).trim();
85
+ if (secret && !/^[\x21-\x7e]{8,500}$/.test(secret))
86
+ return { ok: false, error: "That does not look like a key." };
87
+ const baseText = base.href.replace(/\/+$/, "");
88
+ const kept = links().filter(
89
+ (link) => !(link.computer === machine && link.baseUrl === baseText)
90
+ );
91
+ const link = {
92
+ id: randomBytes(12).toString("base64url"),
93
+ computer: machine,
94
+ baseUrl: baseText,
95
+ ...(secret ? { key: secret } : {}),
96
+ label: label ? String(label).slice(0, 80) : null,
97
+ at: new Date().toISOString(),
98
+ };
99
+ keep([...kept, link]);
100
+ log(`proxy link: ${baseText} allowed for cloud computer ${machine}`);
101
+ const here = self();
102
+ return {
103
+ ok: true,
104
+ link: { ...described(link), holder: here.id, holderLabel: here.label },
105
+ };
106
+ };
107
+
108
+ const list = () => ({ ok: true, links: links().map(described) });
109
+
110
+ const forget = (id) => {
111
+ keep(links().filter((link) => link.id !== String(id)));
112
+ for (const [callId, call] of calls)
113
+ if (call.link === String(id)) drop(callId);
114
+ return list();
115
+ };
116
+
117
+ // ---- calls in flight: id -> { link, from, head, parts, total, done, error, waiters, abort } ----
118
+ const calls = new Map();
119
+ const drop = (id) => {
120
+ const call = calls.get(id);
121
+ if (!call) return;
122
+ calls.delete(id);
123
+ call.abort.abort();
124
+ call.done = true;
125
+ for (const wake of call.waiters.splice(0)) wake();
126
+ };
127
+ const changed = (call) => {
128
+ for (const wake of call.waiters.splice(0)) wake();
129
+ };
130
+
131
+ const startCall = (
132
+ from,
133
+ { link: linkId, method = "POST", path: callPath, headers = {}, body = null }
134
+ ) => {
135
+ const link = links().find((each) => each.id === String(linkId));
136
+ if (!link || link.computer !== from)
137
+ return {
138
+ ok: false,
139
+ status: 403,
140
+ error:
141
+ "This proxy link is not allowed for this computer. Set it up again in Harness.",
142
+ };
143
+ const target = modelCallUrl(
144
+ link.baseUrl,
145
+ `${link.baseUrl}${String(callPath || "")}`,
146
+ String(method),
147
+ LINK_CALLS
148
+ );
149
+ if (!target)
150
+ return {
151
+ ok: false,
152
+ status: 403,
153
+ error: `${method} ${callPath} is not a model call this link carries`,
154
+ };
155
+ while (calls.size >= OPEN_CALLS) drop(calls.keys().next().value);
156
+ const id = randomBytes(12).toString("base64url");
157
+ const call = {
158
+ link: link.id,
159
+ from,
160
+ head: null,
161
+ parts: [],
162
+ total: 0,
163
+ done: false,
164
+ error: null,
165
+ waiters: [],
166
+ abort: new AbortController(),
167
+ };
168
+ calls.set(id, call);
169
+ const sent = Object.fromEntries(
170
+ PASSED_HEADERS.filter((name) => headers[name] != null).map((name) => [
171
+ name,
172
+ String(headers[name]),
173
+ ])
174
+ );
175
+ if (link.key) {
176
+ sent.authorization = `Bearer ${link.key}`;
177
+ sent["x-api-key"] = link.key;
178
+ }
179
+ void (async () => {
180
+ try {
181
+ const response = await fetchImpl(target, {
182
+ method,
183
+ headers: sent,
184
+ ...(body != null && method === "POST" ? { body: String(body) } : {}),
185
+ signal: call.abort.signal,
186
+ });
187
+ call.head = {
188
+ status: response.status,
189
+ contentType: response.headers.get("content-type") ?? "",
190
+ };
191
+ changed(call);
192
+ for await (const bytes of response.body ?? []) {
193
+ const part = Buffer.from(bytes);
194
+ call.parts.push(part);
195
+ call.total += part.length;
196
+ changed(call);
197
+ }
198
+ } catch (error) {
199
+ // Said without the address: the words go to the cloud computer, and the address stays here.
200
+ if (!call.abort.signal.aborted)
201
+ call.error = `your model did not answer (${error.message})`;
202
+ }
203
+ call.done = true;
204
+ changed(call);
205
+ })();
206
+ return { ok: true, call: id };
207
+ };
208
+
209
+ // At most one part's bytes from `offset`, taken from the pieces as they came, so a long answer is not copied whole
210
+ // on every read.
211
+ const bytesFrom = (call, offset) => {
212
+ const taken = [];
213
+ let at = 0;
214
+ let room = PART_BYTES;
215
+ for (const piece of call.parts) {
216
+ const end = at + piece.length;
217
+ if (end > offset && room > 0) {
218
+ const from = Math.max(0, offset - at);
219
+ const slice = piece.subarray(from, from + room);
220
+ taken.push(slice);
221
+ room -= slice.length;
222
+ }
223
+ at = end;
224
+ if (room <= 0) break;
225
+ }
226
+ return Buffer.concat(taken);
227
+ };
228
+
229
+ /** Waits for the call's answer past `offset` (or its end), then gives the next part of it. */
230
+ const readCall = async (from, { call: id, offset = 0 }) => {
231
+ const call = calls.get(String(id));
232
+ if (!call || call.from !== from)
233
+ return { ok: false, error: "that call is over here" };
234
+ const at = Math.max(0, Math.floor(Number(offset) || 0));
235
+ while (!call.done && !(call.head && call.total > at))
236
+ await new Promise((wake) => call.waiters.push(wake));
237
+ const data = bytesFrom(call, at);
238
+ const next = at + data.length;
239
+ return {
240
+ ok: true,
241
+ ...(call.head ?? {}),
242
+ data: data.toString("base64"),
243
+ offset: next,
244
+ done: call.done && next >= call.total,
245
+ ...(call.error ? { error: call.error } : {}),
246
+ };
247
+ };
248
+
249
+ /** A call from one of the person's cloud computers, already opened from its sealed message. */
250
+ const answer = async (from, request) => {
251
+ const op = String(request?.op || "");
252
+ if (op === "start") return startCall(String(from), request);
253
+ if (op === "read") return readCall(String(from), request);
254
+ if (op === "close") {
255
+ if (calls.get(String(request.call))?.from === String(from))
256
+ drop(String(request.call));
257
+ return { ok: true };
258
+ }
259
+ return { ok: false, error: "unknown proxy link call" };
260
+ };
261
+
262
+ const close = () => {
263
+ for (const id of [...calls.keys()]) drop(id);
264
+ };
265
+
266
+ return { allow, list, forget, answer, close };
267
+ }
package/lib/reactions.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  // The person's reaction to their agents' work, step 1b of the swarm's learning. When the person posts in a thread after
2
- // agents delivered something since they last wrote, Harness's server reads the post against that work
3
- // (src/server/swarm/reaction.ts): approves, approves with changes, rejects, or not a reaction, and whose work it is
4
- // about (one agent's post, or what they made together). The verdict is kept on this board for each agent it is about,
5
- // and each agent's card counts the verdicts on its work (cards.mjs). Nothing is read on the privacy setting, with this
6
- // computer off Harness, or from a Harness that does not read reactions (swarm_reactions): such a post has no verdict.
2
+ // agents delivered something since they last wrote, Harness's server reads the post against that work: approves,
3
+ // approves with changes, rejects, or not a reaction, and whose work it is about (one agent's post, or what they made
4
+ // together). The verdict is kept on this board for each agent it is about, and each agent's card counts the verdicts on
5
+ // its work (cards.mjs). Nothing is read on the privacy setting, with this computer off Harness, or from a Harness that
6
+ // does not read reactions (swarm_reactions): such a post has no verdict.
7
7
 
8
8
  // What an agent delivers in a thread: its result, a post or a file. Questions, notes and held posts are not work.
9
9
  const WORK_KINDS = new Set(["result", "post", "file"]);
@@ -53,6 +53,7 @@ export function createReactions({
53
53
  readsReactions,
54
54
  isCoordinatorPost,
55
55
  log,
56
+ onVerdict = () => {},
56
57
  }) {
57
58
  /** Read the person's post in a thread; resolves once its verdicts are kept, or there is none to keep. */
58
59
  const heard = async (thread, post) => {
@@ -101,6 +102,7 @@ export function createReactions({
101
102
  verdict: reaction.verdict,
102
103
  judgments: reaction.judgments ?? null,
103
104
  });
105
+ onVerdict(thread.id, agents);
104
106
  return { agents, verdict: reaction.verdict };
105
107
  };
106
108
 
package/lib/readiness.mjs CHANGED
@@ -13,11 +13,10 @@ import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
13
13
  // changes (createAgentWatch below), so an agent installed later joins the swarm by itself.
14
14
 
15
15
  /**
16
- * How long one check may take. Measured October 21, 2026 on the owner's Mac (.harness-runs/measure/agent-probe):
17
- * with the commands below, 12 checks (Claude Code, Codex, Pi, OpenCode, 3 rounds) answered in 2.1-5.2 s; with the
18
- * fuller run commands, 12 answered in 2.2-24.9 s, the slowest Pi's first start. Signed out, checks failed in
19
- * 0.2-14.4 s (Codex retries a 401 for 14 s). 60 s is 2.4x the slowest answer seen. A check that reaches it is
20
- * reported as slow and can be tried again, never as signed out.
16
+ * How long one check may take. Measured on one Mac: with the commands below, 12 checks (Claude Code, Codex, Pi,
17
+ * OpenCode, 3 rounds) answered in 2.1-5.2 s; with the fuller run commands, 12 answered in 2.2-24.9 s, the slowest Pi's
18
+ * first start. Signed out, checks failed in 0.2-14.4 s (Codex retries a 401 for 14 s). 60 s is 2.4x the slowest answer
19
+ * seen. A check that reaches it is reported as slow and can be tried again, never as signed out.
21
20
  */
22
21
  export const CHECK_DEADLINE_MS = 60_000;
23
22
 
@@ -26,6 +25,10 @@ const PROMPT = "Reply with exactly one word: ready";
26
25
  // Each agent's shortest headless run that still goes through its own sign-in: no tools, no Harness MCP server, and no
27
26
  // session saved to the person's history where the agent allows it (OpenCode has no such switch).
28
27
  const CHECKS = {
28
+ // None of the person's hooks either, Harness's own included. Claude Code runs them in a headless run too, and hands a
29
+ // failing Stop hook's error back as a new turn: claude-mem's needs the transcript this run does not save, so the
30
+ // check went 10 turns and ended with an empty answer (Claude Code 2.1.309). `--bare` also skips hooks but reads no
31
+ // OAuth sign-in, the thing checked.
29
32
  "claude-code": () => ({
30
33
  command: "claude",
31
34
  args: [
@@ -37,6 +40,8 @@ const CHECKS = {
37
40
  "--strict-mcp-config",
38
41
  "--tools",
39
42
  "",
43
+ "--settings",
44
+ '{"disableAllHooks":true}',
40
45
  ],
41
46
  }),
42
47
  codex: () => ({
@@ -315,8 +320,8 @@ function signInFiles(agent, home, env) {
315
320
  }
316
321
  }
317
322
  // Claude Code rewrites ~/.claude.json in every session, its own check included, so the file's time changed every minute
318
- // and the daemon checked Claude Code once a minute (October 23: 60 checks an hour, each a session counted where Claude
319
- // Code lives). Only the account in it says a sign-in changed; on a Mac the token itself is in the keychain.
323
+ // and the daemon checked Claude Code once a minute (60 checks an hour, each a session counted where Claude Code lives).
324
+ // Only the account in it says a sign-in changed; on a Mac the token itself is in the keychain.
320
325
  function claudeAccount(home) {
321
326
  try {
322
327
  const config = JSON.parse(
package/lib/record.mjs CHANGED
@@ -1,6 +1,6 @@
1
- // The record (docs/swarm-organization.md, "The record"): an agent's judged runs in one specialty on one model. A run
2
- // counts toward the specialty its step asked for (board_tasks.specialty, written by team.mjs when the step is routed),
3
- // on the model it ran on (board_tasks.run_model). It is judged by, in order:
1
+ // The record: an agent's judged runs in one specialty on one model. A run counts toward the specialty its step asked
2
+ // for (board_tasks.specialty, written by team.mjs when the step is routed), on the model it ran on
3
+ // (board_tasks.run_model). It is judged by, in order:
4
4
  // 1. the person's verdict on it (board_reactions), which overrides everything below;
5
5
  // 2. a check of it by an agent on a different model (board_tasks.checked): passed is accepted, sent back rejected.
6
6
  // A check on the same model does not count, because models favor their own output;
@@ -14,7 +14,7 @@ const JUDGED = 3;
14
14
  const ACCEPTED = new Set(["approves", "approves_with_changes"]);
15
15
 
16
16
  /** Each run the person judged, by run id: the verdict of their latest post after it and before the agent's next run. */
17
- function verdictsByRun(store) {
17
+ export function verdictEntriesByRun(store) {
18
18
  const reports = new Map();
19
19
  for (const run of store.threadReports()) {
20
20
  const key = `${run.goal_id}\u0000${run.agent}`;
@@ -24,12 +24,25 @@ function verdictsByRun(store) {
24
24
  const verdicts = new Map();
25
25
  for (const said of store.verdictsSaid()) {
26
26
  const runs = reports.get(`${said.goal_id}\u0000${said.agent}`) ?? [];
27
- const judged = runs.findLast((run) => run.reported_at <= said.said_at);
28
- if (judged) verdicts.set(judged.id, said.verdict);
27
+ const judged = said.run_id
28
+ ? runs.find((run) => run.id === said.run_id)
29
+ : runs.findLast((run) => run.reported_at <= said.said_at);
30
+ if (!judged) continue;
31
+ const previous = verdicts.get(judged.id);
32
+ const explicit = said.source === "explicit";
33
+ const detected = said.source === "detected";
34
+ if (detected && previous && previous.source !== "detected") continue;
35
+ if (!explicit && previous?.source === "explicit") continue;
36
+ verdicts.set(judged.id, said);
29
37
  }
30
38
  return verdicts;
31
39
  }
32
40
 
41
+ export const verdictsByRun = (store) =>
42
+ new Map(
43
+ [...verdictEntriesByRun(store)].map(([id, entry]) => [id, entry.verdict])
44
+ );
45
+
33
46
  /** A check by an agent on another model: none of its checkers ran on the run's own model, and one's model is known. */
34
47
  const checkedElsewhere = (run) =>
35
48
  Boolean(run.checked?.outcome) &&
package/lib/redact.mjs CHANGED
@@ -71,7 +71,7 @@ const digestRow = (row) =>
71
71
  // SEED_RUN whitespace-separated list words, nearly all different, in lower or upper case (a capital allowed on the
72
72
  // first), with numbering between them however OCR read it ("5.", "5frost", ". tomato"). Words read with one wrong
73
73
  // letter still count. Over 2,326 of this repository's text and code files, the only run of eight or more such words was
74
- // a real test phrase (October 14), so nine is far from prose and below every phrase length.
74
+ // a real test phrase, so nine is far from prose and below every phrase length.
75
75
  const SEED_RUN = 9;
76
76
  let wordlist = null;
77
77
  const bip39 = () =>
@@ -474,9 +474,9 @@ export async function sensitiveSpans(lines, { firewall, lane = "handoff" }) {
474
474
  item: id,
475
475
  });
476
476
  }
477
- // Two-factor recovery and backup codes each work as a password, and look like nothing else: after a heading that names
478
- // them, every code-shaped token (letters and digits, in dashed groups or 8 to 16 long) is covered, row by row, until a
479
- // row holds none (eval image-redaction: the credential model scored them 0.03 to 0.05).
477
+ // Two-factor recovery and backup codes each work as a password, and look like nothing else: after a heading that
478
+ // names them, every code-shaped token (letters and digits, in dashed groups or 8 to 16 long) is covered, row by row,
479
+ // until a row holds none (on test screenshots the credential model scored them 0.03 to 0.05).
480
480
  for (const [index, row] of rows.entries()) {
481
481
  if (!/\b(?:recovery|backup)\s+codes?\b/i.test(row.text)) continue;
482
482
  for (
@@ -0,0 +1,62 @@
1
+ // What one other person's computer may leave on this one through threads with them (security audit P8, October 25:
2
+ // nothing bounded it, and a file can be 45 MB). Past a limit a message or file is refused; Harness keeps it for a few
3
+ // tries, then sets it aside and tells the sender it was not taken. A shared project's own record and posts have their
4
+ // limits in projects.mjs.
5
+ //
6
+ // For owner review: a busy thread is a few hundred messages of at most 50,000 characters each, and files are counted
7
+ // by the bytes that arrived.
8
+ const MB = 1024 * 1024;
9
+ export const RELAY_LIMITS = {
10
+ // Messages in from the other person on one thread, and their characters.
11
+ messages: 2_000,
12
+ messageChars: 10_000_000,
13
+ // Files in from the other person on one thread.
14
+ threadFiles: 50,
15
+ threadBytes: 250 * MB,
16
+ // Files in from one person across every thread with them.
17
+ personFiles: 200,
18
+ personBytes: 1024 * MB,
19
+ };
20
+
21
+ const one = (db, sql, values) => db.all(sql, values)[0] ?? {};
22
+
23
+ /**
24
+ * Why a message or file from the other person on `taskId` is refused, or null. `text` for a message, `bytes` for a
25
+ * file; `handle` is the other person's, from the thread this computer keeps.
26
+ */
27
+ export function relayRefusal(
28
+ db,
29
+ { taskId, handle, text = null, bytes = null }
30
+ ) {
31
+ if (text != null) {
32
+ const sent = one(
33
+ db,
34
+ "select count(*) as n, coalesce(sum(length(text)), 0) as chars from board_messages where task_id = ? and direction = 'in'",
35
+ [taskId]
36
+ );
37
+ if (Number(sent.n) >= RELAY_LIMITS.messages)
38
+ return "more messages than a thread takes from one person";
39
+ if (Number(sent.chars) + text.length > RELAY_LIMITS.messageChars)
40
+ return "more words than a thread takes from one person";
41
+ return null;
42
+ }
43
+ const thread = one(
44
+ db,
45
+ "select count(*) as n, coalesce(sum(bytes), 0) as bytes from board_files where task_id = ? and remote_id is not null",
46
+ [taskId]
47
+ );
48
+ if (Number(thread.n) >= RELAY_LIMITS.threadFiles)
49
+ return "more files than a thread takes from one person";
50
+ if (Number(thread.bytes) + bytes > RELAY_LIMITS.threadBytes)
51
+ return "more file bytes than a thread takes from one person";
52
+ const person = one(
53
+ db,
54
+ "select count(*) as n, coalesce(sum(f.bytes), 0) as bytes from board_files f join board_threads t on t.task_id = f.task_id where f.remote_id is not null and lower(substr(t.with_agent, 1, instr(t.with_agent || '/', '/') - 1)) = ?",
55
+ [String(handle).toLowerCase()]
56
+ );
57
+ if (Number(person.n) >= RELAY_LIMITS.personFiles)
58
+ return "more files than this computer takes from one person";
59
+ if (Number(person.bytes) + bytes > RELAY_LIMITS.personBytes)
60
+ return "more file bytes than this computer takes from one person";
61
+ return null;
62
+ }
@@ -0,0 +1,170 @@
1
+ // A tryharness release's signature: release.json lists every file the package carries with its SHA-256, signed with
2
+ // the owner's ed25519 release key. The key never lives in this repository or on a server; the owner makes it once
3
+ // (packages/desktop/scripts/release-key.mjs) and publish.mjs signs each release with it. Only the public half is here,
4
+ // in releaseKeys.json, which each release's own signature covers: an installed runtime trusts the keys it carries,
5
+ // so a new key is adopted only through a release signed by the old one.
6
+ //
7
+ // The manifest covers the package's own files. Its dependencies are pinned by npm-shrinkwrap.json, which is one of
8
+ // those files, so their integrity hashes are signed too; npm checks them when it installs.
9
+
10
+ import { createHash, createPublicKey, sign, verify } from "node:crypto";
11
+ import fs from "node:fs";
12
+ import path from "node:path";
13
+
14
+ export const RELEASE_FILE = "release.json";
15
+ const KEYS_FILE = path.join("lib", "releaseKeys.json");
16
+ const NAME = "tryharness";
17
+
18
+ // What a release is made of: the package's files (cli/package.json "files") and those npm always packs. The runtime
19
+ // installs exactly these (runtime-install.mjs), so nothing outside the signed set is copied or run.
20
+ export const RELEASE_ENTRIES = [
21
+ "package.json",
22
+ "npm-shrinkwrap.json",
23
+ "README.md",
24
+ "cli.mjs",
25
+ "lib",
26
+ "assets",
27
+ ];
28
+
29
+ const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
30
+ const posix = (relative) => relative.split(path.sep).join("/");
31
+
32
+ /** The id a key is known by in release.json: the start of its hash. A KeyObject (public, or the private key it
33
+ * pairs with) or a public key as releaseKeys.json keeps it (base64 SPKI). */
34
+ export function keyId(key) {
35
+ const publicKey =
36
+ typeof key === "string"
37
+ ? publicKeyOf(key)
38
+ : key?.type === "public"
39
+ ? key
40
+ : createPublicKey(key);
41
+ const der = publicKey.export({ type: "spki", format: "der" });
42
+ return sha256(der).slice(0, 16);
43
+ }
44
+
45
+ /** The public keys a runtime at `root` trusts: those in its own lib/releaseKeys.json. */
46
+ export function trustedKeys(root) {
47
+ try {
48
+ const { keys } = JSON.parse(
49
+ fs.readFileSync(path.join(root, KEYS_FILE), "utf8")
50
+ );
51
+ return Array.isArray(keys)
52
+ ? keys.filter((key) => typeof key === "string" && key)
53
+ : [];
54
+ } catch {
55
+ return [];
56
+ }
57
+ }
58
+
59
+ const publicKeyOf = (base64) =>
60
+ createPublicKey({
61
+ key: Buffer.from(base64, "base64"),
62
+ format: "der",
63
+ type: "spki",
64
+ });
65
+
66
+ // Every file under the release's entries, as relative posix paths. A symlink is refused: it could point anywhere.
67
+ function releaseFiles(root) {
68
+ const files = [];
69
+ const walk = (relative) => {
70
+ const full = path.join(root, relative);
71
+ const stat = fs.lstatSync(full, { throwIfNoEntry: false });
72
+ if (!stat) return;
73
+ if (stat.isSymbolicLink())
74
+ throw new Error(`${posix(relative)} is a symlink`);
75
+ if (stat.isDirectory()) {
76
+ for (const name of fs.readdirSync(full).sort())
77
+ walk(path.join(relative, name));
78
+ return;
79
+ }
80
+ files.push(posix(relative));
81
+ };
82
+ for (const entry of RELEASE_ENTRIES) walk(entry);
83
+ return files.sort();
84
+ }
85
+
86
+ function manifestOf(root) {
87
+ const { name, version } = JSON.parse(
88
+ fs.readFileSync(path.join(root, "package.json"), "utf8")
89
+ );
90
+ const files = Object.fromEntries(
91
+ releaseFiles(root).map((file) => [
92
+ file,
93
+ sha256(fs.readFileSync(path.join(root, file))),
94
+ ])
95
+ );
96
+ return { name, version, files };
97
+ }
98
+
99
+ /** Writes release.json for the package at `root`, signed with `privateKey` (a KeyObject or PEM). */
100
+ export function signRelease({ root, privateKey }) {
101
+ const manifest = manifestOf(root);
102
+ const signature = sign(
103
+ null,
104
+ Buffer.from(JSON.stringify(manifest)),
105
+ privateKey
106
+ );
107
+ const release = {
108
+ manifest,
109
+ key: keyId(privateKey),
110
+ signature: signature.toString("base64"),
111
+ };
112
+ fs.writeFileSync(
113
+ path.join(root, RELEASE_FILE),
114
+ JSON.stringify(release, null, 2) + "\n"
115
+ );
116
+ return release;
117
+ }
118
+
119
+ /**
120
+ * Whether the package or installed runtime at `root` is a release signed by one of `keys` (base64 SPKI), with every
121
+ * file exactly as signed and no file the signature does not list. { ok, version } or { ok: false, reason }.
122
+ */
123
+ export function verifyRelease({ root, keys }) {
124
+ const refuse = (reason) => ({ ok: false, reason });
125
+ let release;
126
+ try {
127
+ release = JSON.parse(
128
+ fs.readFileSync(path.join(root, RELEASE_FILE), "utf8")
129
+ );
130
+ } catch {
131
+ return refuse("it carries no release signature");
132
+ }
133
+ const manifest = release?.manifest;
134
+ if (!manifest || typeof manifest.files !== "object" || !manifest.files)
135
+ return refuse("its release signature is malformed");
136
+ const signed = Buffer.from(JSON.stringify(manifest));
137
+ const signature = Buffer.from(String(release.signature ?? ""), "base64");
138
+ const signer = keys.find((key) => {
139
+ try {
140
+ return verify(null, signed, publicKeyOf(key), signature);
141
+ } catch {
142
+ return false;
143
+ }
144
+ });
145
+ if (!signer) return refuse("it is not signed with Harness's release key");
146
+ if (manifest.name !== NAME)
147
+ return refuse(`it is signed as ${manifest.name}, not ${NAME}`);
148
+ let present;
149
+ try {
150
+ present = releaseFiles(root);
151
+ } catch (error) {
152
+ return refuse(error.message);
153
+ }
154
+ const listed = Object.keys(manifest.files);
155
+ const extra = present.filter((file) => !(file in manifest.files));
156
+ if (extra.length) return refuse(`${extra[0]} is not part of the release`);
157
+ const missing = listed.filter((file) => !present.includes(file));
158
+ if (missing.length) return refuse(`${missing[0]} is missing`);
159
+ const changed = listed.find(
160
+ (file) =>
161
+ sha256(fs.readFileSync(path.join(root, file))) !== manifest.files[file]
162
+ );
163
+ if (changed) return refuse(`${changed} is not the file that was signed`);
164
+ // package.json is one of the signed files, so its version is the signed one.
165
+ return {
166
+ ok: true,
167
+ version: manifest.version,
168
+ key: keyId(publicKeyOf(signer)),
169
+ };
170
+ }