tryharness 0.7.54 → 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 (156) hide show
  1. package/README.md +15 -16
  2. package/cli.mjs +377 -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 +26 -20
  81. package/lib/oneLine.mjs +7 -7
  82. package/lib/ownMachines.mjs +928 -149
  83. package/lib/pairing.mjs +33 -6
  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
package/lib/book.mjs CHANGED
@@ -3,9 +3,9 @@ import { MEMBERS, nameOf } from "./members.mjs";
3
3
  import { agentModelInUse } from "./models.mjs";
4
4
  import { offices, pinnedFor, specialtiesOf } from "./specialties.mjs";
5
5
 
6
- // The onchain desk's book (docs/swarm-organization.md, "The onchain desk"): the lasting record a trader cannot keep in
7
- // its sessions. Per strategy it keeps the grant it sits under and why it was opened, its entry and exit conditions,
8
- // positions, each decision and who took it, the research behind it, and the receipts of what ran on chain.
6
+ // The onchain desk's book: the lasting record a trader cannot keep in its sessions. Per strategy it keeps the grant it
7
+ // sits under and why it was opened, its entry and exit conditions, positions, each decision and who took it, the
8
+ // research behind it, and the receipts of what ran on chain.
9
9
  //
10
10
  // - The book is personal. Its tables are board tables, carried by the encrypted board backup and copied to the
11
11
  // person's other computers like the rest of the board (boardMirror.mjs MIRRORED), and never sent to Harness's server
@@ -131,9 +131,9 @@ export const BOOK_MIRRORED = {
131
131
  book_contracts: ["id"],
132
132
  };
133
133
 
134
- // Bankr's edge refuses a request body over 8 KiB (src/server/bankr/client.ts). The relay's part of an ask (the ask, the
135
- // strategy's instructions and the thread's history) stays well under it, so Harness's own protocol text still fits and
136
- // its server never has to condense away the strategy's instructions.
134
+ // Bankr's edge refuses a request body over 8 KiB (Harness's server holds Bankr's client to it). The relay's part of an
135
+ // ask (the ask, the strategy's instructions and the thread's history) stays well under it, so Harness's own protocol
136
+ // text still fits and its server never has to condense away the strategy's instructions.
137
137
  export const BANKR_ASK_BYTES = 6_144;
138
138
  const SLICE_BYTES = 1_536;
139
139
  const TEXT_CHARS = 4_000;
package/lib/bridge.mjs CHANGED
@@ -10,8 +10,8 @@ export const RECONNECT_FIRST_MS = 1_000;
10
10
  // computers waits as long on the direct link (directLink.mjs) before it goes through Harness.
11
11
  export const ASK_TIMEOUT_MS = 15_000;
12
12
  export const RECONNECT_JITTER = 0.2;
13
- // Harness's answer when another computer paired to this account is connected (HELD_ELSEWHERE in
14
- // src/server/bridge/bridgeHub.ts): 409 on the dial, or close code 4409 when two dials crossed.
13
+ // Harness's answer when another computer paired to this account is connected, kept in step with Harness's server: 409
14
+ // on the dial, or close code 4409 when two dials crossed.
15
15
  const HELD_ELSEWHERE = {
16
16
  status: 409,
17
17
  code: 4409,
@@ -77,9 +77,9 @@ export function createBridge({
77
77
  let offlineSince = Date.now();
78
78
  // Whether this daemon has been on Harness yet: its first connection ends its start, not a time away.
79
79
  let connectedBefore = false;
80
- // What the board said while the connection was down goes once Harness knows this machine again, so a wake or a
81
- // phone notice is not lost to a short outage (October 19: the person's answer to Grok Bot woke no one across a
82
- // reconnect). A restart reads the board afresh instead (handoffs.mjs).
80
+ // What the board said while the connection was down goes once Harness knows this machine again, so a wake or a phone
81
+ // notice is not lost to a short outage (the person's answer to Grok Bot once woke no one across a reconnect). A
82
+ // restart reads the board afresh instead (handoffs.mjs).
83
83
  const KEPT = new Set([
84
84
  "board_changed",
85
85
  "needs_you",
package/lib/cards.mjs CHANGED
@@ -66,8 +66,8 @@ const median = (values) => {
66
66
  return sorted.length ? sorted[Math.floor(sorted.length / 2)] : null;
67
67
  };
68
68
 
69
- // A card's specialties, pins and offices as a coordinator round carries them (src/server/swarm/coordinator.ts
70
- // Candidate): ids for pins and offices, each specialty without its name, which the server takes from the same list.
69
+ // A card's specialties, pins and offices as a coordinator round on Harness's server carries them: ids for pins and
70
+ // offices, each specialty without its name, which the server takes from the same list.
71
71
  const roundSpecialty = (view) => ({
72
72
  id: view.id,
73
73
  source: view.source,
@@ -0,0 +1,216 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ import { spawn } from "node:child_process";
4
+ import { readFileSync } from "node:fs";
5
+ import { resolveCommand } from "./commands.mjs";
6
+
7
+ // The agents on a cloud computer (docs/cloud-swarm.md §4.0, §5.4). The person picks them in their window while the
8
+ // computer builds; Harness keeps the answer, and this module, on the computer itself, asks for it with the computer's
9
+ // own token and installs each chosen agent that is not here yet, as the harness user, then joins it to the swarm the
10
+ // way `tryharness agents add` does. It asks again whenever Harness says the answer changed, so "Add an agent" later is
11
+ // the same path. Nothing is removed here: an agent taken out of the setup stays installed and out of the lineup.
12
+ // Each installed agent then runs on the AI the person chose for it (setup.ai: Harness's, their plan, their key or
13
+ // their proxy link), applied by cloudAi.mjs after every sync.
14
+
15
+ const { cloud: CLOUD_LIST } = JSON.parse(
16
+ readFileSync(new URL("./members.json", import.meta.url), "utf8")
17
+ );
18
+
19
+ const quote = (value) => `'${String(value).replace(/'/g, `'"'"'`)}'`;
20
+
21
+ /** The command that installs one agent from the list: npm into ~/.local, or the agent's own install script. */
22
+ export function installCommand(row, home = os.homedir()) {
23
+ if (row.install.npm)
24
+ return [
25
+ "npm",
26
+ [
27
+ "install",
28
+ "--global",
29
+ "--prefix",
30
+ path.join(home, ".local"),
31
+ "--no-fund",
32
+ "--no-audit",
33
+ row.install.npm,
34
+ ],
35
+ ];
36
+ const args = (row.install.args ?? []).map(quote).join(" ");
37
+ return [
38
+ "bash",
39
+ [
40
+ "-c",
41
+ `set -o pipefail; curl -fsSL ${quote(row.install.script)} | bash${args ? ` -s -- ${args}` : ""}`,
42
+ ],
43
+ ];
44
+ }
45
+
46
+ export function createCloudAgents({
47
+ config,
48
+ log = () => {},
49
+ fetchImpl = fetch,
50
+ run = spawn,
51
+ env = process.env,
52
+ home = os.homedir(),
53
+ // Harness's own copy, in the harness user's home: the machine image may bring its own (Boat ships claude, codex,
54
+ // opencode, pi, hermes and openclaw in /usr/local/bin), which is not the one Harness installed or keeps updated.
55
+ installed = (row) =>
56
+ resolveCommand(row.command, env)?.startsWith(home + path.sep) ?? false,
57
+ // Puts one installed agent in the swarm (lineup.mjs joinAgent through the daemon's lineup commands).
58
+ join = () => ({ ok: true }),
59
+ // After a chat assistant is installed, when the person chose Telegram (cli/lib/cloudAssistants.mjs, another part).
60
+ afterAssistant = async () => {},
61
+ // Telegram moved to another computer or was turned off: the assistant comes off Harness's relay.
62
+ withoutAssistant = async () => {},
63
+ // Points the installed agents at the AI the person chose for each (cloudAi.mjs apply).
64
+ applyAi = async () => ({ failed: {} }),
65
+ }) {
66
+ const states = new Map();
67
+ // Whether each installed chat assistant is on Harness's relay now; unknown after a restart, so the first sync
68
+ // settles it either way.
69
+ const relayed = new Map();
70
+ let chosen = [];
71
+ let telegram = false;
72
+ let answers = {};
73
+ let running = null;
74
+ let again = false;
75
+
76
+ const setState = (agent, state, detail = null) => {
77
+ states.set(agent, { agent, state, detail });
78
+ log(`${agent}: ${state}${detail ? ` (${detail})` : ""}`);
79
+ };
80
+
81
+ const readSetup = async () => {
82
+ const response = await fetchImpl(
83
+ `${String(config.origin).replace(/\/$/, "")}/api/cloud/setup`,
84
+ { headers: { authorization: `Bearer ${config.token}` } }
85
+ );
86
+ if (!response.ok)
87
+ throw new Error(`Harness answered ${response.status} for the setup`);
88
+ const setup = await response.json();
89
+ return {
90
+ agents: Array.isArray(setup.agents) ? setup.agents.map(String) : [],
91
+ telegram: setup.telegram === true,
92
+ ai: setup.ai && typeof setup.ai === "object" ? setup.ai : {},
93
+ };
94
+ };
95
+
96
+ // An install runs to its end; its output stays on this computer, in the daemon's log only when it fails.
97
+ const install = (row) =>
98
+ new Promise((resolve) => {
99
+ const [command, args] = installCommand(row, home);
100
+ let tail = "";
101
+ const child = run(command, args, {
102
+ env: { ...env, HOME: home },
103
+ stdio: ["ignore", "pipe", "pipe"],
104
+ });
105
+ const keep = (chunk) => (tail = (tail + chunk).slice(-2000));
106
+ child.stdout?.on("data", keep);
107
+ child.stderr?.on("data", keep);
108
+ child.on("error", (error) =>
109
+ resolve({ ok: false, detail: error.message })
110
+ );
111
+ child.on("close", (code) =>
112
+ resolve(
113
+ code === 0
114
+ ? { ok: true }
115
+ : {
116
+ ok: false,
117
+ detail: `exit ${code}: ${tail.trim().split("\n").at(-1) ?? ""}`,
118
+ }
119
+ )
120
+ );
121
+ });
122
+
123
+ const bringUp = async (row) => {
124
+ if (!installed(row)) {
125
+ setState(row.agent, "installing");
126
+ const result = await install(row);
127
+ if (!result.ok || !installed(row))
128
+ return setState(
129
+ row.agent,
130
+ "failed",
131
+ result.detail ?? `${row.command} is not on the PATH after its install`
132
+ );
133
+ }
134
+ const joined = join(row.agent);
135
+ if (!joined?.ok)
136
+ return setState(row.agent, "failed", joined?.error ?? null);
137
+ setState(row.agent, "installed");
138
+ };
139
+
140
+ // Telegram can be turned on, moved here, or moved away long after an assistant was installed, so this runs on
141
+ // every sync, not only after an install.
142
+ const settleTelegram = async () => {
143
+ for (const row of CLOUD_LIST) {
144
+ if (row.signIn !== "assistant") continue;
145
+ if (states.get(row.agent)?.state !== "installed") continue;
146
+ const wanted = telegram && chosen.includes(row.agent);
147
+ if (relayed.get(row.agent) === wanted) continue;
148
+ try {
149
+ if (wanted) await afterAssistant({ agent: row.agent });
150
+ else await withoutAssistant({ agent: row.agent });
151
+ relayed.set(row.agent, wanted);
152
+ } catch (error) {
153
+ log(
154
+ `${row.agent}: Telegram not ${wanted ? "set up" : "turned off"}: ${error.message}`
155
+ );
156
+ }
157
+ }
158
+ };
159
+
160
+ const syncOnce = async () => {
161
+ const setup = await readSetup();
162
+ chosen = setup.agents;
163
+ telegram = setup.telegram;
164
+ answers = setup.ai;
165
+ // In the list's order, one at a time: two installers writing ~/.local at once can break each other.
166
+ for (const row of CLOUD_LIST) {
167
+ if (!chosen.includes(row.agent)) continue;
168
+ if (states.get(row.agent)?.state === "installed") continue;
169
+ if (!states.has(row.agent)) setState(row.agent, "waiting");
170
+ await bringUp(row);
171
+ }
172
+ await settleTelegram();
173
+ await applyAi({
174
+ answers,
175
+ agents: chosen.filter(
176
+ (agent) => states.get(agent)?.state === "installed"
177
+ ),
178
+ });
179
+ };
180
+
181
+ /** Ask Harness what the person chose and install what is missing; a call during a sync runs it once more after. */
182
+ const sync = () => {
183
+ if (running) {
184
+ again = true;
185
+ return running;
186
+ }
187
+ running = (async () => {
188
+ do {
189
+ again = false;
190
+ try {
191
+ await syncOnce();
192
+ } catch (error) {
193
+ log(`setup not read: ${error.message}`);
194
+ }
195
+ } while (again);
196
+ running = null;
197
+ })();
198
+ return running;
199
+ };
200
+
201
+ /** Each chosen agent's state, in the list's order, for the person's window. */
202
+ const status = () =>
203
+ CLOUD_LIST.filter((row) => chosen.includes(row.agent)).map(
204
+ (row) =>
205
+ states.get(row.agent) ?? {
206
+ agent: row.agent,
207
+ state: "waiting",
208
+ detail: null,
209
+ }
210
+ );
211
+
212
+ /** The AI the person chose for an agent here: "harness", "plan", "key" or "link"; null before Harness has said. */
213
+ const aiOf = (agent) => answers[agent] ?? null;
214
+
215
+ return { sync, status, aiOf, busy: () => Boolean(running) };
216
+ }