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
@@ -1,8 +1,20 @@
1
1
  import fs from "node:fs";
2
+ import os from "node:os";
2
3
  import path from "node:path";
4
+ import { spawnSync } from "node:child_process";
3
5
  import { createRequire } from "node:module";
4
6
  import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
5
7
  import { paths } from "./paths.mjs";
8
+ import {
9
+ RELEASE_ENTRIES,
10
+ RELEASE_FILE,
11
+ trustedKeys,
12
+ verifyRelease,
13
+ } from "./release.mjs";
14
+
15
+ // The release chain (release.mjs): npm carries releases, the installed runtime decides which it runs. The first
16
+ // install trusts what npx fetched, since nothing is installed yet to check it with. From then on a release is
17
+ // installed, or switched to, only when it is signed with a key the installed runtime already carries.
6
18
 
7
19
  function packageDirectory(packageJson) {
8
20
  return path.dirname(packageJson);
@@ -83,20 +95,53 @@ function copyDependencyClosure(sourceRoot, releaseRoot, roots) {
83
95
  }
84
96
  }
85
97
 
86
- export function installRuntime({ sourceRoot, version }) {
98
+ // A build the person made and chose to install (--local-build) is marked, so setup can switch back to it.
99
+ const LOCAL_BUILD = ".local-build";
100
+
101
+ // Why a release may not be installed or switched to, or null when it may.
102
+ function refusal({ root, keys, allowUnsigned }) {
103
+ if (!keys.length || allowUnsigned) return null;
104
+ if (fs.existsSync(path.join(root, LOCAL_BUILD))) return null;
105
+ const checked = verifyRelease({ root, keys });
106
+ return checked.ok ? null : checked.reason;
107
+ }
108
+
109
+ const refuse = (version, reason) =>
110
+ new Error(
111
+ `this computer's Harness installs only releases signed with Harness's release key, and tryharness ${version} is not: ${reason}. ` +
112
+ "Nothing was changed. If it is a build you made yourself, run it again with --local-build."
113
+ );
114
+
115
+ /** Throws, before setup changes anything, when installRuntime would refuse this release. */
116
+ export function checkRuntime({ sourceRoot, version, allowUnsigned = false }) {
117
+ const installed = currentRuntime();
118
+ const keys = installed ? trustedKeys(installed) : [];
119
+ const release = path.join(paths.runtime, "releases", version);
120
+ const root = fs.existsSync(path.join(release, ".ready"))
121
+ ? release
122
+ : sourceRoot;
123
+ const reason = refusal({ root, keys, allowUnsigned });
124
+ if (reason) throw refuse(version, reason);
125
+ }
126
+
127
+ /**
128
+ * Installs the release at `sourceRoot` as this computer's runtime and switches to it. Refuses (and changes nothing)
129
+ * when a runtime is installed and the release is not signed with a key that runtime trusts; `allowUnsigned` is the
130
+ * person's own --local-build.
131
+ */
132
+ export function installRuntime({ sourceRoot, version, allowUnsigned = false }) {
133
+ const installed = currentRuntime();
134
+ const keys = installed ? trustedKeys(installed) : [];
87
135
  const release = path.join(paths.runtime, "releases", version);
88
136
  const marker = path.join(release, ".ready");
89
- if (!fs.existsSync(marker)) {
137
+ if (fs.existsSync(marker)) {
138
+ const reason = refusal({ root: release, keys, allowUnsigned });
139
+ if (reason) throw refuse(version, reason);
140
+ } else {
90
141
  const staging = `${release}.staging-${process.pid}`;
91
142
  fs.rmSync(staging, { recursive: true, force: true });
92
143
  ensureDir(staging);
93
- for (const entry of [
94
- "cli.mjs",
95
- "package.json",
96
- "README.md",
97
- "lib",
98
- "assets",
99
- ]) {
144
+ for (const entry of [...RELEASE_ENTRIES, RELEASE_FILE]) {
100
145
  const source = path.join(sourceRoot, entry);
101
146
  if (!fs.existsSync(source)) continue;
102
147
  fs.cpSync(source, path.join(staging, entry), {
@@ -104,6 +149,13 @@ export function installRuntime({ sourceRoot, version }) {
104
149
  force: true,
105
150
  });
106
151
  }
152
+ // Checked as copied, so what is checked is what runs.
153
+ const reason = refusal({ root: staging, keys, allowUnsigned });
154
+ if (reason) {
155
+ fs.rmSync(staging, { recursive: true, force: true });
156
+ throw refuse(version, reason);
157
+ }
158
+ if (allowUnsigned) fs.writeFileSync(path.join(staging, LOCAL_BUILD), "");
107
159
  // Everything the package depends on, so a dependency added there cannot be left out here.
108
160
  copyDependencyClosure(
109
161
  sourceRoot,
@@ -123,6 +175,7 @@ export function installRuntime({ sourceRoot, version }) {
123
175
  version,
124
176
  path: release,
125
177
  });
178
+ writeLauncher(release);
126
179
  return release;
127
180
  }
128
181
 
@@ -132,3 +185,84 @@ export function currentRuntime() {
132
185
  ? current.path
133
186
  : null;
134
187
  }
188
+
189
+ // ── The installed command ─────────────────────────────────────────────────────
190
+
191
+ const WINDOWS = process.platform === "win32";
192
+ const launcherFile = () =>
193
+ path.join(paths.home, "bin", WINDOWS ? "tryharness.cmd" : "tryharness");
194
+
195
+ // The person's command for this computer's Harness: it runs the installed release, never whatever npm has newest.
196
+ function writeLauncher(release, nodePath = process.execPath) {
197
+ const entry = path.join(release, "cli.mjs");
198
+ const script = WINDOWS
199
+ ? `@"${nodePath}" "${entry}" %*\r\n`
200
+ : `#!/bin/sh\n# Harness on this computer: the release it checked and installed (runtime-install.mjs).\nexec "${nodePath}" "${entry}" "$@"\n`;
201
+ ensureDir(path.dirname(launcherFile()));
202
+ fs.writeFileSync(launcherFile(), script, { mode: 0o755 });
203
+ }
204
+
205
+ /**
206
+ * How the person runs `tryharness <words>` here: the installed command once Harness is installed, so a hint never
207
+ * sends them to npm for code; `npx tryharness` before that.
208
+ */
209
+ export function relayCommand(words = "") {
210
+ const tail = words ? ` ${words}` : "";
211
+ if (!fs.existsSync(launcherFile())) return `npx tryharness${tail}`;
212
+ const file = launcherFile();
213
+ const homeDir = os.homedir();
214
+ const shown =
215
+ !WINDOWS && file.startsWith(homeDir + path.sep)
216
+ ? `~${file.slice(homeDir.length)}`
217
+ : file;
218
+ return `${shown.includes(" ") ? JSON.stringify(shown) : shown}${tail}`;
219
+ }
220
+
221
+ /**
222
+ * `tryharness upgrade`: fetches a release from npm without running any of it (no install scripts), and keeps it only
223
+ * when it is signed with a key the installed runtime trusts. Returns where it is unpacked, for setup to run from
224
+ * there, and `trusted: false` when no installed runtime carries a key yet (that one is trusted as npx would be).
225
+ */
226
+ export function fetchRelease({
227
+ spec = "latest",
228
+ npm = "npm",
229
+ env = process.env,
230
+ }) {
231
+ const installed = currentRuntime();
232
+ const keys = installed ? trustedKeys(installed) : [];
233
+ const dir = path.join(paths.runtime, `upgrade-${process.pid}`);
234
+ fs.rmSync(dir, { recursive: true, force: true });
235
+ ensureDir(dir);
236
+ const fetched = spawnSync(
237
+ npm,
238
+ [
239
+ "install",
240
+ `tryharness@${spec}`,
241
+ "--prefix",
242
+ dir,
243
+ "--ignore-scripts",
244
+ "--omit=dev",
245
+ "--no-audit",
246
+ "--no-fund",
247
+ "--no-package-lock",
248
+ ],
249
+ { encoding: "utf8", env, shell: WINDOWS }
250
+ );
251
+ const root = path.join(dir, "node_modules", "tryharness");
252
+ if (fetched.status !== 0 || !fs.existsSync(root)) {
253
+ fs.rmSync(dir, { recursive: true, force: true });
254
+ throw new Error(
255
+ `npm could not fetch tryharness@${spec}: ${(fetched.stderr || fetched.error?.message || "").trim().split("\n").pop()}`
256
+ );
257
+ }
258
+ const version = readJson(path.join(root, "package.json"), {}).version;
259
+ if (keys.length) {
260
+ const checked = verifyRelease({ root, keys });
261
+ if (!checked.ok) {
262
+ fs.rmSync(dir, { recursive: true, force: true });
263
+ throw refuse(version, checked.reason);
264
+ }
265
+ return { dir, root, version, trusted: true, key: checked.key };
266
+ }
267
+ return { dir, root, version, trusted: false };
268
+ }
package/lib/schedules.mjs CHANGED
@@ -14,14 +14,14 @@ import { randomUUID } from "node:crypto";
14
14
  const POLL_MS = 30_000;
15
15
  // Within two polls of its time a run is on time; later, its post says it ran late and when it was due.
16
16
  const LATE_AFTER_MS = 2 * POLL_MS;
17
- // The shortest repeat, the same as automations on Harness's server (src/server/schedules/cadence.ts).
17
+ // The shortest repeat, the same as automations on Harness's server (kept in step with it).
18
18
  export const MIN_EVERY_MINUTES = 5;
19
19
  const WHAT_CHARS = 2_000;
20
20
  // A repeating check-in the lead set ends after this many runs; the person can remove it sooner or set their own.
21
21
  export const LEAD_MAX_RUNS = 24;
22
22
  const DAY_NAMES = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
23
23
 
24
- /** The times the lead picks from (src/server/swarm/coordinator.ts COME_BACK), each as the check-in it sets. */
24
+ /** The times the lead picks from (kept in step with Harness's coordinator), each as the check-in it sets. */
25
25
  export const LEAD_TIMES = {
26
26
  in_15_minutes: { kind: "in", minutes: 15 },
27
27
  in_1_hour: { kind: "in", minutes: 60 },
package/lib/screens.mjs CHANGED
@@ -7,7 +7,7 @@ import { decodeImage } from "./ocr.mjs";
7
7
 
8
8
  const CELL = 16;
9
9
  // A cell counts as changed when its pixels differ by more than this on average (0 to 255): re-rendering the same page
10
- // moves anti-aliasing by a little; the ui-checks eval set it against identical renders.
10
+ // moves anti-aliasing by a little; it was set against identical renders.
11
11
  const CELL_DIFF = 6;
12
12
  const MIN_OVERLAP = 0.3;
13
13
 
package/lib/sealed.mjs CHANGED
@@ -2,8 +2,8 @@ import fs from "node:fs";
2
2
  import { timingSafeEqual, webcrypto } from "node:crypto";
3
3
 
4
4
  // Harness sealed channel, version 1 (HSC1): the phone talks to this daemon through Harness, and
5
- // Harness carries only ciphertext. The browser twin is src/shared/crypto/sealedChannel.ts; both
6
- // must produce the same bytes, and smoke `phone-channel` drives one against the other.
5
+ // Harness carries only ciphertext. The Harness app has a browser twin; both must produce the same
6
+ // bytes, and Harness's own release checks drive one against the other.
7
7
  //
8
8
  // - The daemon has a static ECDH P-256 identity. Its public key reaches the phone only inside the
9
9
  // pairing QR code, never through Harness, so Harness cannot stand in for the daemon.
@@ -191,6 +191,15 @@ export async function relayKey(privateKey, peerPublicKey) {
191
191
  ["encrypt", "decrypt"]
192
192
  );
193
193
  }
194
+ // Relay version 2 (security audit K9, October 25). The key two computers share works both ways, so the associated data
195
+ // of every message, file and ending also names the computer that sealed it and the one it is for, by their public keys:
196
+ // one Harness carried back to its sender, or delivered as if from the other direction, does not open. The sealed words
197
+ // say which of the sender's members wrote them; the label Harness carries beside them is not read. The envelope is
198
+ // unchanged (Harness's server carries it as before); the version is the binding that opens it. A computer from before
199
+ // version 2 seals without the direction: what it sends opens only the old way and is refused here, saying why, and it
200
+ // cannot open what this computer sends; both people update Harness.
201
+ export const relayBound = (bound, fromKey, toKey) =>
202
+ `${bound}|v2|${fromKey}>${toKey}`;
194
203
  export async function sealBound(key, bound, value) {
195
204
  const iv = webcrypto.getRandomValues(new Uint8Array(12));
196
205
  const ct = await subtle.encrypt(