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
@@ -1,349 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { ASK_TIMEOUT_MS } from "./bridge.mjs";
4
-
5
- // The person's own computers reach each other directly when they can: on the same network, or across the internet
6
- // through a hole punched in each router (HyperDHT, the Holepunch library), and through Harness otherwise, in that
7
- // order. In a trial with a Mac on a phone hotspot and a Linux computer on home wifi, 11 of 11 connections hole-punched,
8
- // about 0.6 s to connect, a reply in about 45 ms.
9
- //
10
- // - Each computer has its own HyperDHT key (direct-identity.json). Two computers swap these keys over the sealed
11
- // channel they already share (ownMachines.mjs), so each admits only the other computers the person confirmed:
12
- // any other key is refused before a byte is read, and the stranger cannot tell.
13
- // - What goes over a link is what Harness carries between them otherwise (machine_relay): calls, notices, questions
14
- // for windows, pages of the board, every one still sealed with the pair's key. The link is a second road, not a
15
- // second set of rules.
16
- // - A worker dials home. A request with no link, or with no answer within the time it has through Harness, gets null
17
- // and goes through Harness; the link itself stays. It closes when HyperDHT's keep-alive finds the other side gone,
18
- // and is dialed again when it is next needed (a connection can freeze for good on some networks:
19
- // holepunchto/libudx#333). A new link counts once one round trip over it answers.
20
-
21
- // The public HyperDHT network's own starting points unless the computer is told others (a local test network).
22
- const bootstrapOf = (value) =>
23
- value
24
- ? value.split(",").map((entry) => {
25
- const [host, port] = entry.trim().split(":");
26
- return { host, port: Number(port) };
27
- })
28
- : undefined;
29
- // A frame larger than this is not one the other computer sent (a sealed message is at most 1.4 MB).
30
- const MAX_FRAME_BYTES = 4 * 1024 * 1024;
31
- // How long a new link has to answer one round trip before it is dropped and dialed again (owner's value, October 28).
32
- // Measured: 2 to 11 ms over 7 links in the direct-link smoke (one Mac, a local HyperDHT network), about 45 ms over the
33
- // internet in the October 21 trial (11 hole-punched links). A half-open first link stayed silent until HyperDHT dropped
34
- // it about 24 s later.
35
- const HELLO_MS = 2_000;
36
-
37
- export function createDirectLink({
38
- keyFile,
39
- log = () => {},
40
- // A request from another computer: (machineId, body) => answer.
41
- onRequest,
42
- // "host:port,..." of the network's starting points; "none" keeps this computer to Harness alone.
43
- bootstrap = process.env.HARNESS_DHT_BOOTSTRAP,
44
- timeoutMs = ASK_TIMEOUT_MS,
45
- }) {
46
- const off = bootstrap === "none";
47
- // machineId -> { key, dialer, socket, pending: Map, dialing }
48
- const peers = new Map();
49
- let DHT = null;
50
- let node = null;
51
- let server = null;
52
- let keyPair = null;
53
- let starting = null;
54
- let sequence = 0;
55
-
56
- const loadKeyPair = () => {
57
- try {
58
- const saved = JSON.parse(fs.readFileSync(keyFile, "utf8"));
59
- return {
60
- publicKey: Buffer.from(saved.publicKey, "hex"),
61
- secretKey: Buffer.from(saved.secretKey, "hex"),
62
- };
63
- } catch {
64
- const made = DHT.keyPair();
65
- fs.mkdirSync(path.dirname(keyFile), { recursive: true });
66
- fs.writeFileSync(
67
- keyFile,
68
- JSON.stringify({
69
- publicKey: made.publicKey.toString("hex"),
70
- secretKey: made.secretKey.toString("hex"),
71
- }),
72
- { mode: 0o600 }
73
- );
74
- return made;
75
- }
76
- };
77
-
78
- const peerOfKey = (hex) =>
79
- [...peers.entries()].find(([, peer]) => peer.key === hex)?.[0] ?? null;
80
-
81
- /** Starts listening, once; null when this computer keeps to Harness (or the library is not here). */
82
- const start = () =>
83
- (starting ??= (async () => {
84
- if (off) return null;
85
- try {
86
- DHT = (await import("hyperdht")).default;
87
- } catch (error) {
88
- log(`direct links are not available here: ${error.message}`);
89
- return null;
90
- }
91
- try {
92
- keyPair = loadKeyPair();
93
- node = new DHT({ bootstrap: bootstrapOf(bootstrap) });
94
- server = node.createServer({
95
- firewall: (remotePublicKey) =>
96
- peerOfKey(remotePublicKey.toString("hex")) === null,
97
- });
98
- server.on("connection", (socket) => {
99
- const id = peerOfKey(socket.remotePublicKey.toString("hex"));
100
- if (id) attach(id, socket);
101
- else socket.destroy();
102
- });
103
- await server.listen(keyPair);
104
- return keyPair.publicKey.toString("hex");
105
- } catch (error) {
106
- // Tried again when next needed, rather than never.
107
- log(`no direct links for now: ${error.message}`);
108
- await node?.destroy().catch(() => {});
109
- node = null;
110
- server = null;
111
- starting = null;
112
- return null;
113
- }
114
- })());
115
-
116
- // The requests waiting on one connection, answered with null: it closed, or another took its place.
117
- const release = (peer, socket) => {
118
- for (const [i, waiting] of peer.pending)
119
- if (waiting.socket === socket) {
120
- clearTimeout(waiting.timer);
121
- peer.pending.delete(i);
122
- waiting.resolve(null);
123
- }
124
- };
125
-
126
- // One link: newline-framed JSON, requests and answers matched by number. The peer is looked up when something
127
- // happens, never kept: a key swap updates it in place (a copied peer once kept a dead link "linked").
128
- const attach = (id, socket, { verified = true } = {}) => {
129
- const peer = peers.get(id);
130
- if (!peer) return socket.destroy();
131
- const before = peer.socket;
132
- peer.socket = socket;
133
- peer.verified = verified;
134
- if (before && before !== socket) {
135
- release(peer, before);
136
- before.destroy();
137
- }
138
- const route = socket.rawStream?.remoteHost ?? null;
139
- log(`linked directly with ${id}${route ? ` at ${route}` : ""}`);
140
- let buffered = "";
141
- socket.on("data", (chunk) => {
142
- const current = peers.get(id);
143
- buffered += chunk.toString("utf8");
144
- if (buffered.length > MAX_FRAME_BYTES) return socket.destroy();
145
- let at;
146
- while ((at = buffered.indexOf("\n")) !== -1) {
147
- const line = buffered.slice(0, at);
148
- buffered = buffered.slice(at + 1);
149
- if (line) void receive(id, socket, line);
150
- }
151
- });
152
- const lost = () => {
153
- const current = peers.get(id);
154
- if (!current) return;
155
- release(current, socket);
156
- if (current.socket === socket) current.socket = null;
157
- };
158
- socket.on("close", lost);
159
- socket.on("error", lost);
160
- };
161
-
162
- const receive = async (id, socket, line) => {
163
- let frame;
164
- try {
165
- frame = JSON.parse(line);
166
- } catch {
167
- frame = null;
168
- }
169
- if (!frame || typeof frame !== "object") return socket.destroy();
170
- const peer = peers.get(id);
171
- if ("a" in frame) {
172
- const waiting = peer?.pending.get(frame.i);
173
- if (waiting) {
174
- clearTimeout(waiting.timer);
175
- peer.pending.delete(frame.i);
176
- waiting.resolve(frame.a);
177
- }
178
- return;
179
- }
180
- let answer;
181
- try {
182
- answer = await onRequest(id, frame.q);
183
- } catch (error) {
184
- answer = { ok: false, error: error.message };
185
- }
186
- if (!socket.destroyed)
187
- socket.write(JSON.stringify({ i: frame.i, a: answer ?? null }) + "\n");
188
- };
189
-
190
- /** This computer's key for direct links, or null when it keeps to Harness. */
191
- const key = async () => start();
192
-
193
- /** Lets another of the person's computers link with this one by its key (both sides of a pair). */
194
- const allow = (id, peerKey, { dialer = false } = {}) => {
195
- if (typeof peerKey !== "string" || !/^[0-9a-f]{64}$/.test(peerKey)) return;
196
- const known = peers.get(id);
197
- if (!known) {
198
- peers.set(id, {
199
- key: peerKey,
200
- dialer,
201
- socket: null,
202
- pending: new Map(),
203
- dialing: null,
204
- });
205
- return;
206
- }
207
- known.dialer ||= dialer;
208
- if (known.key === peerKey) return;
209
- // A new key for the same computer: the old link is not it any more.
210
- known.key = peerKey;
211
- const before = known.socket;
212
- known.socket = null;
213
- if (before) {
214
- release(known, before);
215
- before.destroy();
216
- }
217
- };
218
-
219
- /** That computer is no longer one of the person's (removed, or a home this one no longer follows): its key is refused. */
220
- const disallow = (id) => {
221
- const known = peers.get(id);
222
- if (!known) return;
223
- peers.delete(id);
224
- if (known.socket) {
225
- release(known, known.socket);
226
- known.socket.destroy();
227
- }
228
- };
229
-
230
- /** Links with that computer if not linked already (the worker's side). */
231
- const dial = async (id) => {
232
- const peer = peers.get(id);
233
- if (!peer || peer.socket || peer.dialing) return peer?.dialing;
234
- peer.dialing = (async () => {
235
- if (!(await start())) return;
236
- const socket = node.connect(Buffer.from(peer.key, "hex"), { keyPair });
237
- await new Promise((resolve) => {
238
- const failed = (error) => {
239
- log(
240
- `no direct link with ${id} yet (${error.code || error.message}); going through Harness`
241
- );
242
- resolve();
243
- };
244
- socket.once("error", failed);
245
- socket.once("open", () => {
246
- socket.off("error", failed);
247
- attach(id, socket, { verified: false });
248
- resolve();
249
- });
250
- });
251
- // Open on this side is not yet a link: the other computer sometimes never saw the connection, and every call
252
- // over it waited out the whole timeout before going through Harness (smoke direct-link, one run in two). It counts
253
- // once the other computer answers over it; until then calls go through Harness.
254
- const current = peers.get(id);
255
- if (current?.socket && !current.verified) {
256
- const socket = current.socket;
257
- const openedAt = Date.now();
258
- const heard = await send(current, socket, { kind: "hello" }, HELLO_MS);
259
- const still = peers.get(id);
260
- // Gone, or a newer link took its place; a link the timeout already dropped is still dialed again below.
261
- if (!still || (still.socket && still.socket !== socket)) return;
262
- if (heard === null) {
263
- log(
264
- `the direct link with ${id} did not answer; going through Harness and dialing again`
265
- );
266
- release(still, socket);
267
- still.socket = null;
268
- socket.destroy();
269
- // A half-open link (this side open, the other never saw it) is dialed again at once rather than when the next
270
- // call needs it.
271
- still.redials = (still.redials ?? 0) + 1;
272
- if (still.redials <= 3) setImmediate(() => void dial(id));
273
- } else {
274
- still.verified = true;
275
- still.redials = 0;
276
- log(
277
- `the direct link with ${id} answered in ${Date.now() - openedAt} ms`
278
- );
279
- }
280
- }
281
- })().finally(() => {
282
- peer.dialing = null;
283
- });
284
- return peer.dialing;
285
- };
286
-
287
- /** A request to that computer over the link; null when there is none or it did not answer in time. */
288
- const request = (id, body) => {
289
- const peer = peers.get(id);
290
- if (!peer?.socket || !peer.verified) {
291
- if (peer?.dialer) void dial(id);
292
- return Promise.resolve(null);
293
- }
294
- return send(peer, peer.socket, body);
295
- };
296
- // One request over the link and its answer; null when none came in time. A slow answer is not a dead link: that one
297
- // call goes through Harness instead and the link stays (owner, October 28: links to pop-os and MBP-2 were torn down
298
- // and dialed again about 20 times in 10 minutes, each time one push to a busy computer went 15 s unanswered). The
299
- // link closes when HyperDHT's own keep-alive finds the other side gone (`close` and `error` in attach).
300
- const send = (peer, socket, body, waitMs = timeoutMs) => {
301
- const i = ++sequence;
302
- return new Promise((resolve) => {
303
- const timer = setTimeout(() => {
304
- peer.pending.delete(i);
305
- resolve(null);
306
- }, waitMs);
307
- peer.pending.set(i, { resolve, timer, socket });
308
- socket.write(JSON.stringify({ i, q: body }) + "\n");
309
- });
310
- };
311
-
312
- /** Which computers are linked directly, and where the other end is. */
313
- const status = () =>
314
- [...peers.entries()].map(([id, peer]) => ({
315
- id,
316
- linked: Boolean(peer.socket && peer.verified),
317
- at: peer.socket?.rawStream?.remoteHost ?? null,
318
- }));
319
-
320
- /**
321
- * The listener started afresh, the person's computers' keys kept: on home it once stayed unreachable for 30 minutes
322
- * after a restart (every dial from pop-os HOLEPUNCH_ABORTED) until the daemon restarted again, when both workers
323
- * linked within seconds (owner, October 28: home restarts its listener). Every link drops and is made again.
324
- */
325
- const restart = async () => {
326
- for (const peer of peers.values())
327
- if (peer.socket) {
328
- const socket = peer.socket;
329
- release(peer, socket);
330
- peer.socket = null;
331
- socket.destroy();
332
- }
333
- await server?.close().catch(() => {});
334
- await node?.destroy().catch(() => {});
335
- server = null;
336
- node = null;
337
- starting = null;
338
- log("direct links: started the listener again");
339
- return start();
340
- };
341
-
342
- const stop = async () => {
343
- for (const peer of peers.values()) peer.socket?.destroy();
344
- await server?.close().catch(() => {});
345
- await node?.destroy().catch(() => {});
346
- };
347
-
348
- return { key, allow, disallow, dial, request, status, restart, stop };
349
- }
@@ -1,131 +0,0 @@
1
- // The board of the work between the person's swarm and one other person's (Collab, People): every ask between the
2
- // two swarms as a card, either way. It is read from the asks' own states, which both computers already hold (Harness's
3
- // status of each ask, the messages, its end), so each side shows the same cards and nothing new crosses:
4
- // - To do: asked, not accepted yet. Waiting on the person when it is theirs to accept.
5
- // - In progress: accepted and open. Live while the person's agent works it; waiting on the person when a reply of
6
- // their agent's is held for them to send.
7
- // - Review: the side asked answered last, and the asker has not ended it.
8
- // - Done: ended. One declined, blocked or expired is marked blocked with why.
9
- import { nameOf } from "./members.mjs";
10
- import { oneLine } from "./oneLine.mjs";
11
-
12
- const OPEN = new Set(["accepted", "accepted_pending"]);
13
- const REFUSED = {
14
- declined: (item) =>
15
- item.role === "target" ? "You declined" : `${item.peer.handle} declined`,
16
- blocked: () => "Blocked",
17
- expired: () => "Expired without an answer",
18
- };
19
- const TRAIL = 6;
20
- const LIVE = new Set(["claimed", "running"]);
21
-
22
- const theirs = (item) =>
23
- item.peer.agent === "person"
24
- ? item.peer.handle
25
- : `${item.peer.handle}'s ${nameOf(item.peer.agent)}`;
26
- const yours = (item) =>
27
- item.mine === "person" || item.mine === "user"
28
- ? "you"
29
- : `your ${nameOf(item.mine)}`;
30
- // Only the person's own side starts with a word to capitalize: a handle keeps its own case.
31
- const capital = (text) => (text.startsWith("you") ? `Y${text.slice(1)}` : text);
32
- const day = (at) =>
33
- at
34
- ? new Date(at).toLocaleDateString("en-US", {
35
- month: "short",
36
- day: "numeric",
37
- })
38
- : null;
39
-
40
- /** One ask as its card, from the conversation (network.mjs item) and its messages. */
41
- function cardOf(item, messages) {
42
- const asker = item.role === "asker" ? yours(item) : theirs(item);
43
- const asked = item.role === "asker" ? theirs(item) : yours(item);
44
- const here = item.thread;
45
- const ended =
46
- item.group === "ended" || (here && !here.open) || item.status === "closed";
47
- const last = messages.at(-1) ?? null;
48
- // The side asked answered last: the asked side sends out when it is this side, in when it is theirs.
49
- const answered =
50
- Boolean(last) &&
51
- messages.length > 1 &&
52
- last.direction === (item.role === "target" ? "out" : "in");
53
- const card = {
54
- id: item.id,
55
- title: oneLine(item.about || "A message", 120),
56
- route: `${capital(asker)} → ${asked}`,
57
- column: "doing",
58
- agent: item.role === "target" ? item.mine : null,
59
- holder: null,
60
- status: null,
61
- note: null,
62
- blocked: null,
63
- needsYou: null,
64
- tasks: [item.id],
65
- by: item.role === "asker" ? item.mine : item.peer.handle,
66
- at: item.updatedAt ?? item.createdAt ?? null,
67
- history: messages.slice(-TRAIL).map((message) => ({
68
- at: message.created_at,
69
- by: message.direction === "in" ? item.peer.handle : message.sender,
70
- text: `${capital(message.direction === "in" ? theirs(item) : message.sender === "user" ? "you" : `your ${nameOf(message.sender)}`)}: ${oneLine(message.text, 200)}`,
71
- })),
72
- };
73
- if (REFUSED[item.status]) {
74
- card.column = "done";
75
- card.blocked = REFUSED[item.status](item);
76
- card.status = card.blocked;
77
- } else if (item.status === "requested") {
78
- card.column = "todo";
79
- if (item.role === "target") {
80
- card.needsYou = "accept or decline it";
81
- card.status = "Accept or decline";
82
- } else card.status = `Waiting on ${item.peer.handle}`;
83
- } else if (ended) {
84
- card.column = "done";
85
- const on = day(item.updatedAt);
86
- card.status = on ? `Ended ${on}` : "Ended";
87
- card.note = here?.outcome ? oneLine(here.outcome, 200) : null;
88
- } else if (here?.held) {
89
- card.needsYou = "a reply waits for you to send";
90
- card.status = "Reply to send";
91
- } else if (answered) {
92
- card.column = "review";
93
- card.status =
94
- item.role === "asker"
95
- ? "Answered, yours to close"
96
- : `Answered, ${item.peer.handle}'s to close`;
97
- } else if (!OPEN.has(item.status) && !here) card.status = item.status;
98
- return card;
99
- }
100
-
101
- /**
102
- * The board between this swarm and one other person's: its cards, and as runs the asks the person's own agents are
103
- * working now (the board marks those live).
104
- */
105
- export function peopleBoard(items, { handle, messagesOf, taskOf }) {
106
- const withThem = items.filter(
107
- (item) => item.peer.handle === String(handle).toLowerCase()
108
- );
109
- const cards = withThem.map((item) => cardOf(item, messagesOf(item.id)));
110
- const runs = withThem
111
- .filter((item) => item.role === "target")
112
- .map((item) => ({ item, task: taskOf(item.id) }))
113
- .filter(({ task }) => task && LIVE.has(task.status))
114
- .map(({ item, task }) => ({
115
- id: item.id,
116
- agent: item.mine,
117
- status: task.status,
118
- startedAt: task.claimed_at ?? task.updated_at,
119
- steps: [],
120
- }));
121
- for (const card of cards)
122
- if (runs.some((run) => run.id === card.id))
123
- card.holder = capital(yours(withThem.find((i) => i.id === card.id)));
124
- return {
125
- handle,
126
- cards,
127
- runs,
128
- asks: cards.length,
129
- needsYou: cards.filter((card) => card.needsYou).length,
130
- };
131
- }