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
package/lib/record.mjs ADDED
@@ -0,0 +1,128 @@
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
+ // 1. the person's verdict on it (board_reactions), which overrides everything below;
5
+ // 2. a check of it by an agent on a different model (board_tasks.checked): passed is accepted, sent back rejected.
6
+ // A check on the same model does not count, because models favor their own output;
7
+ // 3. the auditor's code (board_tasks.audit, cli/lib/audit.mjs): a report whose own claims its receipts do not bear out
8
+ // is rejected. A change not committed on the thread's branch is not made, so that mismatch rejects the run even when
9
+ // a check passed it.
10
+ // Silence counts neither way. Being tagged by the person is not a verdict.
11
+
12
+ // At least this many judged runs before a record earns, or questions, a specialty.
13
+ const JUDGED = 3;
14
+ const ACCEPTED = new Set(["approves", "approves_with_changes"]);
15
+
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
+ export function verdictEntriesByRun(store) {
18
+ const reports = new Map();
19
+ for (const run of store.threadReports()) {
20
+ const key = `${run.goal_id}\u0000${run.agent}`;
21
+ if (!reports.has(key)) reports.set(key, []);
22
+ reports.get(key).push(run);
23
+ }
24
+ const verdicts = new Map();
25
+ for (const said of store.verdictsSaid()) {
26
+ const runs = reports.get(`${said.goal_id}\u0000${said.agent}`) ?? [];
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);
37
+ }
38
+ return verdicts;
39
+ }
40
+
41
+ export const verdictsByRun = (store) =>
42
+ new Map(
43
+ [...verdictEntriesByRun(store)].map(([id, entry]) => [id, entry.verdict])
44
+ );
45
+
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. */
47
+ const checkedElsewhere = (run) =>
48
+ Boolean(run.checked?.outcome) &&
49
+ Boolean(run.model) &&
50
+ run.checked.by?.some((checker) => checker.model) &&
51
+ !run.checked.by.some((checker) => checker.model === run.model);
52
+
53
+ // The auditor's code (audit.mjs) found a claim of the agent's own its receipts do not bear out. A mismatch against the
54
+ // dispatcher (work assigned while the agent was offline) is not the agent's, and receipts still landing (the claims
55
+ // `waiting` lists) count neither way.
56
+ const auditFailed = (audit) =>
57
+ Boolean(audit) &&
58
+ !audit.waiting?.length &&
59
+ (audit.mismatches ?? []).some((mismatch) => mismatch.against === "agent");
60
+ const notCommitted = (audit) =>
61
+ (audit?.mismatches ?? []).some(
62
+ (mismatch) => mismatch.kind === "not_committed"
63
+ );
64
+
65
+ /** How one run was judged: "accepted", "rejected" or null for silence. */
66
+ function judgmentOf(run, verdict) {
67
+ if (verdict) return ACCEPTED.has(verdict) ? "accepted" : "rejected";
68
+ if (notCommitted(run.audit)) return "rejected";
69
+ if (checkedElsewhere(run))
70
+ return run.checked.outcome === "passed" ? "accepted" : "rejected";
71
+ if (auditFailed(run.audit)) return "rejected";
72
+ return null;
73
+ }
74
+
75
+ /** Every agent's record: agent -> model -> specialty -> { accepted, rejected, judged }. */
76
+ function records(store) {
77
+ const verdicts = verdictsByRun(store);
78
+ const all = new Map();
79
+ for (const run of store.routedRuns()) {
80
+ if (!run.model) continue;
81
+ const judged = judgmentOf(run, verdicts.get(run.id));
82
+ if (!judged) continue;
83
+ const byModel = all.get(run.agent) ?? new Map();
84
+ all.set(run.agent, byModel);
85
+ const bySpecialty = byModel.get(run.model) ?? new Map();
86
+ byModel.set(run.model, bySpecialty);
87
+ const entry = bySpecialty.get(run.specialty) ?? {
88
+ accepted: 0,
89
+ rejected: 0,
90
+ judged: 0,
91
+ };
92
+ entry[judged]++;
93
+ entry.judged++;
94
+ bySpecialty.set(run.specialty, entry);
95
+ }
96
+ return all;
97
+ }
98
+
99
+ /** An agent's record on a model: specialty id -> { accepted, rejected, judged }. */
100
+ export function recordFor(store, agentId, model) {
101
+ return new Map(records(store).get(agentId)?.get(model) ?? []);
102
+ }
103
+
104
+ /** The specialties an agent has earned on a model: at least three judged runs, more accepted than rejected. */
105
+ export function earned(store, agentId, model) {
106
+ return [...recordFor(store, agentId, model)]
107
+ .filter(
108
+ ([, entry]) => entry.judged >= JUDGED && entry.accepted > entry.rejected
109
+ )
110
+ .map(([specialty]) => specialty);
111
+ }
112
+
113
+ /** Records that question a specialty: at least three judged runs, more rejected than accepted. */
114
+ export function underperforming(store) {
115
+ const found = [];
116
+ for (const [agent, byModel] of records(store))
117
+ for (const [model, bySpecialty] of byModel)
118
+ for (const [specialty, entry] of bySpecialty)
119
+ if (entry.judged >= JUDGED && entry.rejected > entry.accepted)
120
+ found.push({
121
+ agent,
122
+ model,
123
+ specialty,
124
+ accepted: entry.accepted,
125
+ judged: entry.judged,
126
+ });
127
+ return found;
128
+ }
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
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "about": "The public halves of Harness's release keys (release.mjs). An installed runtime installs only releases signed by one of these. Empty until the owner runs packages/desktop/scripts/release-key.mjs.",
3
+ "keys": [
4
+ "MCowBQYDK2VwAyEArul+f77Jncfc+LSz3rmeNdNWxGbbEuxxIgT4OePwpEU="
5
+ ]
6
+ }
package/lib/repoLinks.mjs CHANGED
@@ -13,7 +13,7 @@ import { randomUUID } from "node:crypto";
13
13
  // board.repo.find { link } → { repo, here: folder | null, places: [folders to clone into] }
14
14
  // board.repo.clone { link, parent } → { folder }
15
15
  // With detached:true, clone returns {operation,state:"cloning"}; board.repo.clone.read {operation} returns progress
16
- // or the final result. Short calls fit existing browser/buddy transports while the owner's clone deadline runs here.
16
+ // or the final result. Short calls fit existing browser/buddy transports while the clone's own deadline runs here.
17
17
  // Then board.project.create { folder } (or board.project.join { folder }) starts or joins the room as for any folder.
18
18
 
19
19
  const HOSTS = ["github.com", "gitlab.com", "bitbucket.org", "codeberg.org"];
@@ -175,9 +175,9 @@ export function findHere({ link, folders = [], homeDir = os.homedir() }) {
175
175
  return null;
176
176
  }
177
177
 
178
- // How long a clone may wait for the remote to answer: 2 minutes, the owner's value, not yet measured against real
179
- // GitHub clones. It covers only the wait for the remote's first byte; once the remote is answering, a large
180
- // repository takes as long as its transfer does.
178
+ // How long a clone may wait for the remote to answer: 2 minutes, a chosen value, not yet measured against real GitHub
179
+ // clones. It covers only the wait for the remote's first byte; once the remote is answering, a large repository takes
180
+ // as long as its transfer does.
181
181
  export const FIRST_BYTE_MS = 120_000;
182
182
 
183
183
  // What git says before the remote has answered: its own "Cloning into '<folder>'..." line.
@@ -505,6 +505,27 @@ export function createRoomChannels({
505
505
  publish(updated, [...peersFor(id), peer]);
506
506
  notify(room, updated);
507
507
  };
508
+ // The person blocked someone: the owner takes them out of the room; anyone else ends their pair channel with them
509
+ // and keeps it ended (sync never links an errored peer again).
510
+ const block = (id, peer) => {
511
+ const room = read(id);
512
+ if (!room || !joined(room)) return;
513
+ if (
514
+ room.owner === room.me &&
515
+ room.members.some(
516
+ (member) =>
517
+ member.handle === peer &&
518
+ ["invited", "joined"].includes(member.status)
519
+ )
520
+ )
521
+ remove(id, peer);
522
+ for (const route of routes(id).filter((entry) => entry.peer === peer)) {
523
+ end(route.id, "Blocked.");
524
+ forget(route);
525
+ }
526
+ const fresh = read(id);
527
+ save(fresh, { errors: { ...fresh.errors, [peer]: "Blocked." } });
528
+ };
508
529
  const closed = (channelId) => {
509
530
  const route = channel(channelId);
510
531
  if (!route) return false;
@@ -620,12 +641,15 @@ export function createRoomChannels({
620
641
  knowsChannel: (id) =>
621
642
  Boolean(channel(id) || store.meta(`shared-room-channel:${id}`)),
622
643
  invite,
644
+ // Whether an invitation names its real sender and this person, as join requires; throws why not.
645
+ validate: validateInvite,
623
646
  join,
624
647
  setAgents,
625
648
  opened,
626
649
  receive,
627
650
  leave,
628
651
  remove,
652
+ block,
629
653
  closed,
630
654
  sync,
631
655
  retry,
package/lib/roomPage.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // One page of a thread's room as any agent reads it: its newest posts, the ones before a post (`before`) going back, or
2
2
  // the ones after a post (`since`) catching up. Each page says where the posts on either side of it start, and fits in
3
- // one tool result (October 17: 27 posts of a video thread came to 64,553 characters, more than Claude Code takes in one).
3
+ // one tool result (27 posts of one video thread came to 64,553 characters, more than Claude Code takes in one).
4
4
  const PAGE_CHARS = 30_000;
5
5
  const PAGE_POSTS = 50;
6
6
 
@@ -5,6 +5,65 @@ import { spawnSync } from "node:child_process";
5
5
  import { PS } from "./nudge.mjs";
6
6
  import { paths } from "./paths.mjs";
7
7
  import { MACHINE_RUNNERS } from "./members.mjs";
8
+ import { runCapability, runningPids } from "./runner.mjs";
9
+ import {
10
+ descendsFrom,
11
+ peerPids,
12
+ processParents,
13
+ seesPeers,
14
+ } from "./peerProcess.mjs";
15
+
16
+ /** The run Harness started that made a socket call, set by checkCaller; no JSON a caller writes can set it. */
17
+ export const RUN_CALLER = Symbol("the run that called");
18
+ /** How the run that made a call was held in, so what it asks for is held in too: "review", "restricted" or null. */
19
+ export const callerLimit = (request) => {
20
+ const run = request?.[RUN_CALLER];
21
+ return run?.review ? "review" : run?.restricted ? "restricted" : null;
22
+ };
23
+ /** Whether a call came from a run that may not act on the person's go: a restricted run or a read-only review. */
24
+ export const limitedCaller = (request) => callerLimit(request) !== null;
25
+
26
+ // What a run Harness started may ask on the daemon's socket: the board (as itself, under its own limits), Harness's
27
+ // tools through the relay, and reading how things stand. Everything else there is the person's: pairing a phone,
28
+ // backups, computers, local folders, stopping runs, Lid-Closed Mode, shutting the daemon down.
29
+ const RUN_COMMANDS = new Set([
30
+ "status",
31
+ "doctor",
32
+ "activity",
33
+ "sync",
34
+ "local.status",
35
+ "voice.status",
36
+ "image.read",
37
+ "session.compacted",
38
+ "tasks.get",
39
+ "runs.here",
40
+ "wake.local",
41
+ "t3.status",
42
+ "phone.identity",
43
+ "machine.report",
44
+ ]);
45
+ // Reading the board as the person: what these answer is already in the board's own file, which a program a run starts
46
+ // outside its sandbox can read anyway, while a sandboxed run's shell cannot reach this socket at all. They skip the
47
+ // check of who called (a lookup of the socket's other end, ~35 ms), which the buddy's reads would otherwise pay on
48
+ // every call while a run is going; anything that acts, or reads more than the board, keeps it.
49
+ const PERSON_READS = new Set([
50
+ "status",
51
+ "board.list",
52
+ "board.get",
53
+ "board.children",
54
+ "board.agents",
55
+ "board.wait",
56
+ "board.goal.list",
57
+ "board.goal.get",
58
+ "board.room.read",
59
+ "board.thread.read",
60
+ "board.swarm.list",
61
+ "board.swarm.read",
62
+ ]);
63
+ const runMayAsk = (command) =>
64
+ command.startsWith("board.") ||
65
+ command.startsWith("mcp.") ||
66
+ RUN_COMMANDS.has(command);
8
67
 
9
68
  export function createRunAuthority({ store, installedAgents }) {
10
69
  const RUNNERS = new Set(MACHINE_RUNNERS);
@@ -91,6 +150,47 @@ export function createRunAuthority({ store, installedAgents }) {
91
150
  : { started: false, reason: `It could not be authorized. ${start}` };
92
151
  };
93
152
 
153
+ /**
154
+ * Who a call on the local socket is, before anything acts on it; a refusal to answer with, or null. A call carrying a
155
+ * run's capability is that run's agent with that run's limits, whatever agent it names. Without one, a call as the
156
+ * person (or for something only the person does) is refused when the program that made it is inside a run this
157
+ * daemon started: its capability was dropped on the way. The person's own sessions and terminal are not runs.
158
+ */
159
+ const checkCaller = async (request, socket) => {
160
+ const command = String(request.command || "");
161
+ if (request.runToken !== undefined) {
162
+ const run = runCapability(request.runToken);
163
+ delete request.runToken;
164
+ if (!run)
165
+ return "That run has ended, so Harness does not take its calls.";
166
+ request.agent = run.agent;
167
+ if (run.restricted) request.restricted = true;
168
+ request[RUN_CALLER] = run;
169
+ if (!runMayAsk(command))
170
+ return "A run Harness started cannot do that; only the person can.";
171
+ if (run.restricted && command.startsWith("mcp."))
172
+ return "A restricted run reaches this computer's board, not the person's Harness.";
173
+ return null;
174
+ }
175
+ if (request.agent !== "user" && runMayAsk(command)) return null;
176
+ if (PERSON_READS.has(command)) return null;
177
+ const runs = runningPids();
178
+ // Windows has no tool here that names a named pipe's client; there the capability alone tells a run's calls apart.
179
+ if (!runs.length || !seesPeers) return null;
180
+ // A caller that cannot be found (it hung up as soon as it wrote) is not taken as the person either.
181
+ const [peers, parents] = await Promise.all([
182
+ peerPids(socket),
183
+ processParents(),
184
+ ]);
185
+ const inside =
186
+ peers?.length && parents ? descendsFrom(peers, runs, parents) : null;
187
+ if (inside === null)
188
+ return "Harness could not tell which program asked, so it did not act as the person. Try again.";
189
+ return inside
190
+ ? "A program inside a run Harness started cannot act as the person."
191
+ : null;
192
+ };
193
+
94
194
  const markPrompt = (pids, agent) => {
95
195
  for (const pid of Array.isArray(pids) ? pids.slice(0, 2) : [])
96
196
  if (Number.isInteger(pid) && pid > 1) promptedBy.set(pid, agent);
@@ -104,6 +204,7 @@ export function createRunAuthority({ store, installedAgents }) {
104
204
  standingRules,
105
205
  standingVerdict,
106
206
  applyStanding,
207
+ checkCaller,
107
208
  markPrompt,
108
209
  };
109
210
  }
package/lib/runBrief.mjs CHANGED
@@ -11,13 +11,13 @@ import { profileBrief, readProfile } from "./profile.mjs";
11
11
  // largest sections give way to their pointers. Every run keeps what each section weighed and what was sent of it
12
12
  // (`brief-sections:<run>`), and `tryharness board brief <task> --dry-run` shows the same brief before any run.
13
13
 
14
- // The budget, measured on the owner's board, October 20, 2026: the briefs 52 runs of Claude Code and Codex actually got
15
- // (read from their own session files) were 7,173 characters at the median, 21,279 at p90 and 31,725 at most; the core
16
- // (provenance, objective, the task's brief or the thread's wake brief) made up 6,790 / 18,660 / 29,745 of that, the room
17
- // digest inside the wake brief alone up to 15,136. The other parts were small: room guide up to 3,236, task frame 946,
18
- // lessons 306, context pack files 869, earlier sessions 844, library 301; no run carried claude-mem notes, which
19
- // can reach 20,000 on their own (claudemem.mjs). The budget keeps every brief a run worked from whole, and gives way
20
- // beyond it: a large claude-mem note or a growing roster no longer stacks on top of a full thread.
14
+ // The budget, measured on one real board: the briefs 52 runs of Claude Code and Codex actually got (read from their own
15
+ // session files) were 7,173 characters at the median, 21,279 at p90 and 31,725 at most; the core (provenance,
16
+ // objective, the task's brief or the thread's wake brief) made up 6,790 / 18,660 / 29,745 of that, the room digest
17
+ // inside the wake brief alone up to 15,136. The other parts were small: room guide up to 3,236, task frame 946, lessons
18
+ // 306, context pack files 869, earlier sessions 844, library 301; no run carried claude-mem notes, which can reach
19
+ // 20,000 on their own (claudemem.mjs). The budget keeps every brief a run worked from whole, and gives way beyond it: a
20
+ // large claude-mem note or a growing roster no longer stacks on top of a full thread.
21
21
  export const BRIEF_BUDGET = 32_000;
22
22
 
23
23
  export function createRunBriefs({
@@ -210,7 +210,18 @@ export function createRunBriefs({
210
210
  priority: "recommended",
211
211
  source: "Harness profile",
212
212
  text: person ? profileBrief(person) : "",
213
- pointer: person ? `You are working for ${person.displayName}.` : "",
213
+ pointer: person
214
+ ? [
215
+ person.displayName
216
+ ? `You are working for ${person.displayName}.`
217
+ : "",
218
+ person.archetype
219
+ ? `Primary archetype: ${person.archetype}. Read its workflows with archetype.`
220
+ : "",
221
+ ]
222
+ .filter(Boolean)
223
+ .join(" ")
224
+ : "",
214
225
  },
215
226
  {
216
227
  name: "task frame",