tryharness 0.7.82 → 0.7.86

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 (216) hide show
  1. package/README.md +21 -19
  2. package/assets/dsh-plugin.mjs +75 -4
  3. package/assets/herdr-mod/harness/main.js +367 -0
  4. package/assets/herdr-mod/harness/mod.json +6 -0
  5. package/assets/opencode-plugin.js +87 -22
  6. package/assets/pi-extension.ts +81 -2
  7. package/cli.mjs +544 -208
  8. package/lib/adapters.mjs +62 -27
  9. package/lib/agentBinaries.mjs +6 -8
  10. package/lib/agentClaims.mjs +168 -0
  11. package/lib/agentReadTools.json +415 -0
  12. package/lib/agentSignIn.mjs +17 -18
  13. package/lib/agentWiring.mjs +114 -0
  14. package/lib/archetypes.js +10 -11
  15. package/lib/attention.mjs +100 -0
  16. package/lib/audit.mjs +1 -1
  17. package/lib/backupSetup.mjs +6 -28
  18. package/lib/bankrApprovals.mjs +86 -0
  19. package/lib/boardAccess.mjs +40 -66
  20. package/lib/boardBackup.mjs +86 -85
  21. package/lib/boardCommands.mjs +28 -0
  22. package/lib/boardFileCommands.mjs +29 -36
  23. package/lib/boardFiles.mjs +83 -15
  24. package/lib/boardMirror.mjs +78 -11
  25. package/lib/boardProtocol.json +193 -123
  26. package/lib/boardThreads.mjs +19 -37
  27. package/lib/boardTools.mjs +22 -15
  28. package/lib/boardWatches.mjs +43 -15
  29. package/lib/bridge.mjs +7 -3
  30. package/lib/browserAgentTools.mjs +59 -0
  31. package/lib/browserWake.mjs +0 -6
  32. package/lib/cards.mjs +57 -2
  33. package/lib/circling.mjs +189 -0
  34. package/lib/cleanup.mjs +234 -0
  35. package/lib/cloudBoot.mjs +21 -4
  36. package/lib/cloudSave.mjs +46 -5
  37. package/lib/compaction.mjs +8 -1
  38. package/lib/completion.mjs +358 -0
  39. package/lib/computerDevices.mjs +853 -0
  40. package/lib/connectionStatus.mjs +34 -0
  41. package/lib/connectors.mjs +139 -1
  42. package/lib/coordinator.mjs +108 -14
  43. package/lib/coreModels.mjs +36 -12
  44. package/lib/daemon.mjs +2435 -333
  45. package/lib/daemonLock.mjs +103 -0
  46. package/lib/deviceDoor.mjs +308 -0
  47. package/lib/deviceIdentity.mjs +114 -0
  48. package/lib/deviceList.mjs +172 -0
  49. package/lib/deviceSeal.mjs +74 -0
  50. package/lib/dispatcher.mjs +497 -26
  51. package/lib/dispatches.mjs +3 -3
  52. package/lib/environment.mjs +2 -1
  53. package/lib/environments.mjs +67 -41
  54. package/lib/events.mjs +318 -0
  55. package/lib/facts.mjs +170 -0
  56. package/lib/fileSource.mjs +540 -0
  57. package/lib/files.mjs +47 -2
  58. package/lib/gitHost.mjs +39 -1
  59. package/lib/goalCommands.mjs +12 -80
  60. package/lib/handover.mjs +21 -16
  61. package/lib/harnessOffers.mjs +140 -15
  62. package/lib/herdr.mjs +100 -15
  63. package/lib/herdrAppCall.mjs +19 -0
  64. package/lib/herdrCore.mjs +59 -0
  65. package/lib/herdrRuns.mjs +1126 -0
  66. package/lib/hookDialects.mjs +235 -50
  67. package/lib/identityLink.mjs +81 -0
  68. package/lib/inference.mjs +31 -2
  69. package/lib/jamAccess.mjs +82 -0
  70. package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
  71. package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
  72. package/lib/jamKey.mjs +274 -0
  73. package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
  74. package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
  75. package/lib/jamStore.mjs +973 -0
  76. package/lib/jamUpgrade.mjs +112 -0
  77. package/lib/jams.mjs +3079 -0
  78. package/lib/kanban.mjs +13 -7
  79. package/lib/landed.mjs +5 -1
  80. package/lib/library.mjs +41 -22
  81. package/lib/limits.mjs +91 -0
  82. package/lib/lineDiff.mjs +97 -0
  83. package/lib/lineup.mjs +18 -13
  84. package/lib/link.mjs +584 -0
  85. package/lib/localStack.mjs +75 -16
  86. package/lib/localmodels.mjs +58 -78
  87. package/lib/loopBackstop.mjs +2 -1
  88. package/lib/machine.mjs +544 -0
  89. package/lib/machineLink.mjs +446 -0
  90. package/lib/machineRoutes.mjs +68 -19
  91. package/lib/machineRuns.mjs +85 -4
  92. package/lib/machineSeal.mjs +6 -31
  93. package/lib/manager.mjs +134 -12
  94. package/lib/mcp-stdio.mjs +492 -215
  95. package/lib/mcpRelay.mjs +34 -35
  96. package/lib/members.json +2 -2
  97. package/lib/modelRoute.mjs +162 -0
  98. package/lib/nativeHost.mjs +81 -90
  99. package/lib/nativeSenses.mjs +258 -0
  100. package/lib/nerves.mjs +523 -0
  101. package/lib/network.mjs +117 -278
  102. package/lib/networkPlaces.mjs +578 -0
  103. package/lib/nextStep.mjs +95 -0
  104. package/lib/notify.mjs +2 -2
  105. package/lib/nudge.mjs +116 -10
  106. package/lib/onboard.mjs +6 -6
  107. package/lib/originals.mjs +216 -0
  108. package/lib/outsideEvents.mjs +383 -0
  109. package/lib/outsideRuns.mjs +230 -0
  110. package/lib/ownMachines.mjs +674 -256
  111. package/lib/pain.mjs +215 -0
  112. package/lib/pairing.mjs +91 -11
  113. package/lib/paths.mjs +42 -3
  114. package/lib/peerProcess.mjs +21 -7
  115. package/lib/peopleLink.mjs +268 -0
  116. package/lib/personNotices.mjs +3 -2
  117. package/lib/phones.mjs +252 -542
  118. package/lib/placeCards.mjs +282 -0
  119. package/lib/placeChecks.mjs +95 -0
  120. package/lib/placeCommands.mjs +8 -17
  121. package/lib/placeRequests.mjs +152 -0
  122. package/lib/placeStore.mjs +295 -0
  123. package/lib/placeTool.d.ts +12 -0
  124. package/lib/placeTool.js +40 -0
  125. package/lib/places.mjs +63 -14
  126. package/lib/plans.mjs +53 -8
  127. package/lib/presence.mjs +270 -0
  128. package/lib/privateNetwork.d.ts +2 -0
  129. package/lib/privateNetwork.js +93 -0
  130. package/lib/proposals.mjs +300 -0
  131. package/lib/publicFetch.d.ts +32 -0
  132. package/lib/publicFetch.js +248 -0
  133. package/lib/reach.mjs +128 -0
  134. package/lib/rebuildable.mjs +72 -0
  135. package/lib/recall.mjs +216 -0
  136. package/lib/record.mjs +13 -0
  137. package/lib/reflexes.mjs +392 -0
  138. package/lib/relayLimits.mjs +31 -2
  139. package/lib/releaseNotice.mjs +198 -0
  140. package/lib/removeHarness.mjs +15 -4
  141. package/lib/repoLinks.mjs +204 -35
  142. package/lib/runAuthority.mjs +102 -39
  143. package/lib/runBrief.mjs +93 -40
  144. package/lib/runRequests.mjs +52 -14
  145. package/lib/runUsage.mjs +31 -0
  146. package/lib/runWorker.mjs +74 -25
  147. package/lib/runner.mjs +289 -45
  148. package/lib/runtime-install.mjs +37 -8
  149. package/lib/schedules.mjs +171 -47
  150. package/lib/screenWatches.mjs +221 -0
  151. package/lib/sealed.mjs +12 -30
  152. package/lib/sealedThreads.mjs +198 -392
  153. package/lib/secretStore.mjs +178 -0
  154. package/lib/secrets.mjs +11 -0
  155. package/lib/seen.mjs +3 -9
  156. package/lib/selfUpdate.mjs +51 -15
  157. package/lib/senseCall.mjs +1514 -0
  158. package/lib/senseHook.mjs +114 -0
  159. package/lib/senseTools.mjs +1298 -0
  160. package/lib/sessionBriefs.mjs +87 -0
  161. package/lib/sessionControl.mjs +63 -13
  162. package/lib/sessionFiles.mjs +85 -0
  163. package/lib/setupChoices.mjs +12 -3
  164. package/lib/setupMode.mjs +70 -25
  165. package/lib/sharedKeys.mjs +166 -0
  166. package/lib/sleep.mjs +396 -0
  167. package/lib/sources.mjs +306 -0
  168. package/lib/speech.mjs +166 -411
  169. package/lib/spoken.mjs +210 -0
  170. package/lib/steerHook.mjs +3 -1
  171. package/lib/steerQueue.mjs +40 -11
  172. package/lib/store.mjs +323 -130
  173. package/lib/stuck.mjs +85 -7
  174. package/lib/swarm.mjs +157 -49
  175. package/lib/swarmDevices.mjs +25 -85
  176. package/lib/swarmMemory.mjs +93 -9
  177. package/lib/t3.mjs +73 -3
  178. package/lib/taskCommands.mjs +51 -60
  179. package/lib/taskRooms.mjs +30 -4
  180. package/lib/taskRules.json +29 -0
  181. package/lib/taskRules.mjs +21 -0
  182. package/lib/taskRuns.mjs +74 -11
  183. package/lib/team.mjs +2 -1
  184. package/lib/threadActions.mjs +37 -9
  185. package/lib/threadAuthority.mjs +4 -4
  186. package/lib/threadBriefs.mjs +173 -43
  187. package/lib/threadNotes.mjs +320 -0
  188. package/lib/threadRecord.mjs +491 -0
  189. package/lib/threadRuns.mjs +216 -108
  190. package/lib/threadView.mjs +27 -30
  191. package/lib/threadWatches.mjs +1962 -0
  192. package/lib/timeSense.mjs +839 -0
  193. package/lib/tripwires.mjs +454 -0
  194. package/lib/ui.mjs +1 -1
  195. package/lib/vault.mjs +560 -45
  196. package/lib/vaultCommands.mjs +5 -3
  197. package/lib/vaultPeers.mjs +165 -0
  198. package/lib/vaultTools.d.ts +4 -1
  199. package/lib/vaultTools.js +22 -1
  200. package/lib/verdicts.mjs +12 -26
  201. package/lib/versions.mjs +117 -0
  202. package/lib/waitTool.mjs +278 -0
  203. package/lib/wakePicture.mjs +268 -0
  204. package/lib/wakeQueue.mjs +108 -0
  205. package/lib/watchResponses.mjs +533 -0
  206. package/lib/watches.mjs +290 -145
  207. package/lib/windowAsks.mjs +80 -17
  208. package/lib/worktrees.mjs +159 -9
  209. package/npm-shrinkwrap.json +138 -631
  210. package/package.json +7 -6
  211. package/release.json +212 -130
  212. package/lib/callSessions.mjs +0 -51
  213. package/lib/directLink.mjs +0 -349
  214. package/lib/peopleBoard.mjs +0 -131
  215. package/lib/projects.mjs +0 -2917
  216. package/lib/roomChannels.mjs +0 -667
@@ -0,0 +1,268 @@
1
+ // This computer and a friend's (docs/one-link-plan.md L5; docs/jam-plan.md J2): once a friendship is accepted, one
2
+ // WebRTC channel between the two people's home computers carries their messages and files. It opens as the
3
+ // friendship is taken (the side that asked dials) and closes on unfriend, block or a changed key.
4
+ //
5
+ // The channel is introduced by two sealed calls carried by Harness ("person.link.offer", "person.link.candidates",
6
+ // Harness's `thread_link`), sealed under the thread's own key (the one each computer pinned for the other when the thread
7
+ // was accepted, sealedThreads.mjs) and bound to their direction, so Harness routes them unread and only for an accepted,
8
+ // unblocked thread. The side that asked dials; when each asked the other on some thread, the lower key dials, so only
9
+ // one does. The other side is sent no local-network address (settled item 10): only its public address and the
10
+ // fallback's, with the local address a public one was found from taken out.
11
+ //
12
+ // Over the channel go the thread's messages and files, already sealed end to end, as Harness's mailbox would hand them
13
+ // over (sealedThreads.mjs receive); what the channel cannot carry now goes to the mailbox. A channel is kept while a
14
+ // thread with that person is open and its key is the one pinned; it closes when the last one ends, on a block, and when
15
+ // Harness says their key was replaced or revoked.
16
+
17
+ import { randomBytes } from "node:crypto";
18
+ import {
19
+ MAX_SKEW_MS,
20
+ openBound,
21
+ relayBound,
22
+ relayKey,
23
+ sealBound,
24
+ } from "./sealed.mjs";
25
+ import { createMachineLink } from "./machineLink.mjs";
26
+ import { handleOf } from "./sealedThreads.mjs";
27
+
28
+ export const PERSON_LABEL = "harness-person";
29
+ // A sealed file of the board's largest size (32 MiB) is about 45 M characters (Harness's own cap, threads.ts).
30
+ const MAX_MESSAGE_CHARS = 48_000_000;
31
+ // Carried over the channel: what Harness's mailbox carries for a thread, less its end (which closes the thread on
32
+ // Harness too, so it goes there).
33
+ const CARRIED = new Set(["thread_message", "thread_file"]);
34
+ // The time to carry one message: a 32 MiB file at a home connection's upload speed. Past it the mailbox takes it.
35
+ const CARRY_MS = 120_000;
36
+
37
+ const ADDRESS = /^(\S+ \d+ \S+ \d+ )(\S+)( \d+ typ )(\S+)(.*)$/;
38
+ const PUBLIC_TYPES = new Set(["srflx", "relay"]);
39
+
40
+ /**
41
+ * An address found here as another person's computer may see it: its public address or the fallback's, never a
42
+ * local-network one, nor the local address a public one was found from ("raddr"). Null to keep it here.
43
+ */
44
+ export function publicOnly(item) {
45
+ const line = String(item?.candidate ?? "");
46
+ const match = line.replace(/^candidate:/, "").match(ADDRESS);
47
+ if (!match || !PUBLIC_TYPES.has(match[4])) return null;
48
+ const withoutLocal = line.replace(
49
+ /\sraddr \S+ rport \d+/,
50
+ " raddr 0.0.0.0 rport 0"
51
+ );
52
+ return { ...item, candidate: withoutLocal };
53
+ }
54
+
55
+ /** An offer or answer with no address in it: addresses go one by one, through publicOnly. */
56
+ export function sdpWithoutAddresses(sdp) {
57
+ return String(sdp)
58
+ .split(/\r?\n/)
59
+ .filter((line) => line && !line.startsWith("a=candidate"))
60
+ .map((line) =>
61
+ line.startsWith("c=IN IP4 ")
62
+ ? "c=IN IP4 0.0.0.0"
63
+ : line.startsWith("c=IN IP6 ")
64
+ ? "c=IN IP6 ::"
65
+ : line.startsWith("a=rtcp:")
66
+ ? line.replace(/IN IP[46] \S+/, "IN IP4 0.0.0.0")
67
+ : line
68
+ )
69
+ .join("\r\n")
70
+ .concat("\r\n");
71
+ }
72
+
73
+ /**
74
+ * - `identity()`: this computer's relay key pair (the one its threads are sealed with).
75
+ * - `askHarness(type, input)`: one request to Harness (bridge.mjs), for `thread_link`.
76
+ * - `receive(type, input)`: what this computer answers for a message or file the other person's computer carried
77
+ * (sealedThreads.mjs receive), as `{ ok, result?, error? }`.
78
+ * - `waiting(handle)`: whether that person's key is waiting to be trusted again (their computer's was replaced): no
79
+ * channel with them meanwhile.
80
+ */
81
+ export function createPeopleLink({
82
+ store,
83
+ identity,
84
+ askHarness,
85
+ receive,
86
+ waiting = () => false,
87
+ iceServers,
88
+ log = () => {},
89
+ Peer,
90
+ }) {
91
+ // The open friendships that a channel may carry: with the person themselves (never a thread with an agent from before
92
+ // friends), sealed, open, and with a key not waiting to be trusted.
93
+ const openThreads = (handle = null) =>
94
+ store
95
+ .relayThreads(1_000)
96
+ .filter((thread) => !thread.closed_at)
97
+ .map((thread) => store.getThread(thread.task_id))
98
+ .filter(
99
+ (thread) =>
100
+ thread?.peer_key &&
101
+ String(thread.with_agent).endsWith("/person") &&
102
+ !thread.closed_at &&
103
+ !waiting(handleOf(thread.with_agent)) &&
104
+ (handle === null || handleOf(thread.with_agent) === handle)
105
+ );
106
+
107
+ const keyOf = (thread) => relayKey(identity().privateKey, thread.peer_key);
108
+ const outward = (thread, bound) =>
109
+ relayBound(bound, identity().publicKey, thread.peer_key);
110
+ const inward = (thread, bound) =>
111
+ relayBound(bound, thread.peer_key, identity().publicKey);
112
+
113
+ // On the dialing side: one introduction call, sealed under an open thread's key, carried by Harness to the other
114
+ // person's home and answered sealed back for this call alone.
115
+ const introduce = async (handle, call) => {
116
+ const thread = openThreads(handle)[0];
117
+ if (!thread || !identity())
118
+ return { ok: false, error: "no open thread with them" };
119
+ const key = await keyOf(thread);
120
+ const nonce = randomBytes(12).toString("base64url");
121
+ const envelope = await sealBound(
122
+ key,
123
+ outward(thread, `link|${thread.task_id}`),
124
+ { ts: Date.now(), nonce, call }
125
+ );
126
+ const reply = await askHarness("thread_link", {
127
+ threadId: thread.task_id,
128
+ envelope,
129
+ });
130
+ if (!reply?.ok || !reply.envelope)
131
+ return { ok: false, error: reply?.error ?? "no answer" };
132
+ const opened = await openBound(
133
+ key,
134
+ inward(thread, `link-answer|${thread.task_id}`),
135
+ reply.envelope
136
+ ).catch(() => null);
137
+ if (!opened || opened.re !== nonce)
138
+ return { ok: false, error: "the answer was not for this introduction" };
139
+ return opened.answer ?? { ok: false, error: "no answer" };
140
+ };
141
+
142
+ const link = createMachineLink({
143
+ log,
144
+ iceServers,
145
+ label: PERSON_LABEL,
146
+ name: "people link",
147
+ maxMessageChars: MAX_MESSAGE_CHARS,
148
+ share: publicOnly,
149
+ shareSdp: sdpWithoutAddresses,
150
+ commands: {
151
+ offer: "person.link.offer",
152
+ candidates: "person.link.candidates",
153
+ },
154
+ timeoutMs: CARRY_MS,
155
+ introduce,
156
+ ...(Peer === undefined ? {} : { Peer }),
157
+ // A message or file the other person's computer carried: taken only for an open thread with that very person.
158
+ onRequest: async (handle, body) => {
159
+ const type = String(body?.type ?? "");
160
+ const input = body?.input ?? {};
161
+ const thread = store.getThread(String(input.taskId ?? ""));
162
+ if (
163
+ !CARRIED.has(type) ||
164
+ !thread?.peer_key ||
165
+ thread.closed_at ||
166
+ handleOf(thread.with_agent) !== handle ||
167
+ waiting(handle)
168
+ )
169
+ return { ok: false, error: "no open thread with you for that" };
170
+ return receive(type, input);
171
+ },
172
+ });
173
+
174
+ /**
175
+ * On the side that answers: Harness's `thread_link`, from the person whose handle Harness names. Opened only with an
176
+ * open thread's key in their direction, answered sealed back; anything else is refused.
177
+ */
178
+ const answer = async ({ threadId, from, envelope }) => {
179
+ const handle = String(from ?? "").toLowerCase();
180
+ const thread = store.getThread(String(threadId ?? ""));
181
+ if (
182
+ !identity() ||
183
+ !thread?.peer_key ||
184
+ thread.closed_at ||
185
+ handleOf(thread.with_agent) !== handle ||
186
+ waiting(handle)
187
+ )
188
+ return { ok: false, error: "no open thread with you" };
189
+ const key = await keyOf(thread);
190
+ const opened = await openBound(
191
+ key,
192
+ inward(thread, `link|${thread.task_id}`),
193
+ envelope
194
+ ).catch(() => null);
195
+ if (!opened || Math.abs(Date.now() - Number(opened.ts)) > MAX_SKEW_MS)
196
+ return { ok: false, error: "the introduction could not be opened" };
197
+ const call = opened.call ?? {};
198
+ const given =
199
+ call.command === "person.link.offer"
200
+ ? await link.offer(handle, call)
201
+ : call.command === "person.link.candidates"
202
+ ? await link.candidates(handle, call)
203
+ : { ok: false, error: "unknown introduction" };
204
+ return {
205
+ ok: true,
206
+ envelope: await sealBound(
207
+ key,
208
+ outward(thread, `link-answer|${thread.task_id}`),
209
+ { re: opened.nonce, answer: given }
210
+ ),
211
+ };
212
+ };
213
+
214
+ // The people a channel is kept with, and the ones this computer dials.
215
+ let kept = new Set();
216
+ /** Looks again at the open threads: dials whom this side should, closes channels with nobody left to carry. */
217
+ const sync = () => {
218
+ if (!identity()) return;
219
+ const now = new Map();
220
+ for (const thread of openThreads()) {
221
+ const handle = handleOf(thread.with_agent);
222
+ const seen = now.get(handle) ?? {
223
+ asked: false,
224
+ wasAsked: false,
225
+ key: thread.peer_key,
226
+ };
227
+ if (thread.role === "asker") seen.asked = true;
228
+ else seen.wasAsked = true;
229
+ now.set(handle, seen);
230
+ }
231
+ for (const handle of kept)
232
+ if (!now.has(handle)) {
233
+ link.disallow(handle);
234
+ log(`people link: no open thread with ${handle}, channel closed`);
235
+ }
236
+ kept = new Set(now.keys());
237
+ const mine = identity()?.publicKey ?? "";
238
+ for (const [handle, seen] of now) {
239
+ const dials = seen.asked && (!seen.wasAsked || mine < seen.key);
240
+ if (dials) void link.dial(handle);
241
+ }
242
+ };
243
+
244
+ return {
245
+ answer,
246
+ sync,
247
+ /**
248
+ * One message or file over the channel with that person: their computer's answer, or null when no channel is
249
+ * open (one is dialed for the next) or none came in time; the mailbox takes it then.
250
+ */
251
+ carry: (handle, frame) => {
252
+ if (!CARRIED.has(frame?.type) || !identity())
253
+ return Promise.resolve(null);
254
+ if (!kept.has(handle)) sync();
255
+ return kept.has(handle)
256
+ ? link.request(handle, { type: frame.type, input: frame })
257
+ : Promise.resolve(null);
258
+ },
259
+ /** Closes the channel with that person now (an unfriend, a block, or their key replaced or revoked). */
260
+ close: (handle) => {
261
+ kept.delete(handle);
262
+ link.disallow(handle);
263
+ log(`people link: channel with ${handle} closed`);
264
+ },
265
+ status: () => link.status(),
266
+ stop: () => link.stop(),
267
+ };
268
+ }
@@ -1,3 +1,4 @@
1
+ import { taskEnded } from "./taskRules.mjs";
1
2
  import { readJson } from "./files.mjs";
2
3
  import { nameOf } from "./members.mjs";
3
4
  import { notificationFor, notifyDesktop, takeNotices } from "./notify.mjs";
@@ -116,9 +117,9 @@ export function createPersonNotices({
116
117
  if (
117
118
  task.origin_agent === "user" &&
118
119
  task.kind === "task" &&
119
- ["done", "failed"].includes(task.status) &&
120
+ taskEnded(task.status) &&
120
121
  previous &&
121
- !["done", "failed"].includes(previous.status)
122
+ !taskEnded(previous.status)
122
123
  )
123
124
  send({ type: "finished" });
124
125
  };