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,358 @@
1
+ import fs from "node:fs";
2
+ import net from "node:net";
3
+ import path from "node:path";
4
+ import { execFile } from "node:child_process";
5
+ import { randomUUID } from "node:crypto";
6
+
7
+ // Completion (docs/senses-plan.md S2.2): knowing that work is done without waking to look again and again. Every run's
8
+ // end is a happening in the log. A process an agent started can be followed to its end: on a Mac the kernel says so the
9
+ // moment it happens, through the launcher (nativeSenses.mjs); elsewhere the daemon looks every second, which costs
10
+ // about a microsecond a look (S0.2). What should now be true (a port answering, a file there, an address answering) is
11
+ // checked by the daemon until it is, or until its time runs out, and the log says which. Telling an agent is S3.3's
12
+ // wake; this is what it will be told.
13
+
14
+ const LOOK_EVERY_MS = 1_000;
15
+ const CHECK_EVERY_MS = { port: 1_000, file: 1_000, address: 2_000 };
16
+ const PORT_WAIT_MS = 900;
17
+ export const ADDRESS_WAIT_MS = 1_800;
18
+ const DEFAULT_WITHIN_SECONDS = 60;
19
+ const MOST_WITHIN_SECONDS = 3_600;
20
+ // What one computer follows at once for its agents: enough for every agent's own work, not for a sweep of the machine.
21
+ const MOST_PROCESSES = 100;
22
+ const MOST_EXPECTATIONS = 100;
23
+
24
+ const ago = (ms) =>
25
+ ms < 60_000
26
+ ? `${Math.max(1, Math.round(ms / 1000))} s`
27
+ : ms < 3_600_000
28
+ ? `${Math.round(ms / 60_000)} min`
29
+ : `${(ms / 3_600_000).toFixed(1)} h`;
30
+
31
+ /** The program a process runs, by name, or null where `ps` cannot say. */
32
+ const programOf = (pid) =>
33
+ new Promise((resolve) => {
34
+ if (process.platform === "win32") return resolve(null);
35
+ execFile("ps", ["-o", "comm=", "-p", String(pid)], (error, stdout) =>
36
+ resolve(error ? null : path.basename(String(stdout).trim()) || null)
37
+ );
38
+ });
39
+
40
+ const running = (pid) => {
41
+ try {
42
+ process.kill(pid, 0);
43
+ return true;
44
+ } catch (error) {
45
+ // Another user's process is running all the same.
46
+ return error.code === "EPERM";
47
+ }
48
+ };
49
+
50
+ /** The process kind for sources.mjs: `{ pid }`. A reading says whether it runs; its end is a happening. */
51
+ export function createProcessKind({ native = null, now = () => Date.now() }) {
52
+ return {
53
+ describe: ({ pid }) => `says the moment process ${pid} ends`,
54
+ start(options, io) {
55
+ const pid = Number(options.pid);
56
+ if (!Number.isInteger(pid) || pid <= 0)
57
+ throw new Error("a process is named by its number");
58
+ const since = now();
59
+ let program = null;
60
+ let over = false;
61
+ let look = null;
62
+ let unhear = null;
63
+ const ended = () => {
64
+ if (over) return;
65
+ over = true;
66
+ clearInterval(look);
67
+ unhear?.();
68
+ io.report(
69
+ { at: now(), pid, running: false, program },
70
+ {
71
+ kind: "ended",
72
+ text: `process ${pid}${program ? ` (${program})` : ""} ended`,
73
+ data: { pid, program, followedMs: now() - since },
74
+ }
75
+ );
76
+ };
77
+ const lookEverySecond = () => {
78
+ look = setInterval(() => {
79
+ if (!running(pid)) ended();
80
+ }, LOOK_EVERY_MS);
81
+ look.unref?.();
82
+ };
83
+ void programOf(pid).then((name) => {
84
+ program = name;
85
+ if (over) return;
86
+ if (!running(pid)) return ended();
87
+ io.report({ at: now(), pid, running: true, program });
88
+ if (native?.available()) {
89
+ // A line that closes while it follows the process (the Linux program stopped) hands it back to Node.
90
+ const unclose = native.onClose?.(() => !over && lookEverySecond());
91
+ native
92
+ .onExit(pid, ended)
93
+ .then((stop) => {
94
+ unhear = () => {
95
+ stop();
96
+ unclose?.();
97
+ };
98
+ })
99
+ .catch(() => {
100
+ unclose?.();
101
+ if (!over) lookEverySecond();
102
+ });
103
+ } else lookEverySecond();
104
+ });
105
+ return {
106
+ stop() {
107
+ over = true;
108
+ clearInterval(look);
109
+ unhear?.();
110
+ },
111
+ };
112
+ },
113
+ };
114
+ }
115
+
116
+ const portAnswers = (host, port) =>
117
+ new Promise((resolve) => {
118
+ const socket = net.connect({ host, port });
119
+ const done = (answered) => {
120
+ socket.destroy();
121
+ resolve(answered);
122
+ };
123
+ socket.setTimeout(PORT_WAIT_MS, () => done(false));
124
+ socket.once("connect", () => done(true));
125
+ socket.once("error", () => done(false));
126
+ });
127
+
128
+ const addressAnswers = async (url) => {
129
+ try {
130
+ const response = await fetch(url, {
131
+ redirect: "manual",
132
+ signal: AbortSignal.timeout(ADDRESS_WAIT_MS),
133
+ });
134
+ void response.body?.cancel().catch(() => {});
135
+ return { answered: response.status < 400, status: response.status };
136
+ } catch {
137
+ return { answered: false, status: null };
138
+ }
139
+ };
140
+
141
+ /** What a check is about, in a few words. */
142
+ const thingOf = (check) =>
143
+ check.what === "port"
144
+ ? `port ${check.port}${check.host === "127.0.0.1" ? "" : ` on ${check.host}`}`
145
+ : check.what === "file"
146
+ ? check.file
147
+ : check.address;
148
+
149
+ /** The check kind for sources.mjs: `{ what: "port" | "file" | "address", ... }`, read every second or two. */
150
+ export function createCheckKind({ now = () => Date.now() } = {}) {
151
+ return {
152
+ describe: (check) =>
153
+ `checks every ${CHECK_EVERY_MS[check.what] / 1000} s whether ${thingOf(check)} ${check.what === "file" ? "is there" : "answers"}`,
154
+ start(check, io) {
155
+ if (!CHECK_EVERY_MS[check.what])
156
+ throw new Error(`there is no check for ${check.what}`);
157
+ let stopped = false;
158
+ let timer = null;
159
+ const read = async () => {
160
+ let ok = false;
161
+ let detail = null;
162
+ if (check.what === "port")
163
+ ok = await portAnswers(check.host, check.port);
164
+ else if (check.what === "file") {
165
+ const stat = fs.statSync(check.file, { throwIfNoEntry: false });
166
+ ok = Boolean(stat) && (!check.nonEmpty || stat.size > 0);
167
+ detail = stat ? { size: stat.size } : null;
168
+ } else {
169
+ const answer = await addressAnswers(check.address);
170
+ ok = answer.answered;
171
+ detail = { status: answer.status };
172
+ }
173
+ if (stopped) return;
174
+ io.report({ at: now(), true: ok, detail });
175
+ timer = setTimeout(read, CHECK_EVERY_MS[check.what]);
176
+ timer.unref?.();
177
+ };
178
+ timer = setTimeout(read, 0);
179
+ timer.unref?.();
180
+ return {
181
+ stop() {
182
+ stopped = true;
183
+ clearTimeout(timer);
184
+ },
185
+ };
186
+ },
187
+ };
188
+ }
189
+
190
+ /** The check a request names, or an error saying what it lacks. */
191
+ export function checkOf(request) {
192
+ if (request.port !== undefined) {
193
+ const port = Number(request.port);
194
+ if (!Number.isInteger(port) || port < 1 || port > 65_535)
195
+ return { error: "a port is a number from 1 to 65535" };
196
+ const host = String(request.host || "127.0.0.1").slice(0, 255);
197
+ return { kind: "check", what: "port", host, port };
198
+ }
199
+ if (request.file !== undefined) {
200
+ const file = String(request.file);
201
+ if (!path.isAbsolute(file))
202
+ return { error: "a file is named by its full path" };
203
+ return {
204
+ kind: "check",
205
+ what: "file",
206
+ file: path.normalize(file),
207
+ nonEmpty: request.nonEmpty === true,
208
+ };
209
+ }
210
+ if (request.address !== undefined) {
211
+ let url;
212
+ try {
213
+ url = new URL(String(request.address));
214
+ } catch {
215
+ return { error: "an address is a whole http or https address" };
216
+ }
217
+ if (url.protocol !== "http:" && url.protocol !== "https:")
218
+ return { error: "an address is a whole http or https address" };
219
+ return { kind: "check", what: "address", address: url.toString() };
220
+ }
221
+ return { error: "say what should be true: a port, a file or an address" };
222
+ }
223
+
224
+ /**
225
+ * Completion on this computer: `runEnded(run)` puts a run's end in the log; `command(request, { agent })` answers
226
+ * `board.process.follow` ({ pid }) and `board.expect` ({ port, host } | { file, nonEmpty } | { address },
227
+ * withinSeconds) for the person and the agents on this computer.
228
+ */
229
+ export function createCompletion({ sources, events, now = () => Date.now() }) {
230
+ const followed = new Map();
231
+ const expectations = new Map();
232
+
233
+ const runEnded = ({
234
+ runId,
235
+ agent,
236
+ thread = null,
237
+ startedAt,
238
+ kind,
239
+ failure,
240
+ }) => {
241
+ const ms = startedAt ? Math.max(0, now() - Date.parse(startedAt)) : null;
242
+ const status =
243
+ kind === "done"
244
+ ? "finished"
245
+ : failure === "person"
246
+ ? "was stopped"
247
+ : "failed";
248
+ return events.append({
249
+ source: "run",
250
+ kind: "ended",
251
+ subject: runId,
252
+ text: `${agent}'s run ${status}${ms !== null ? ` after ${ago(ms)}` : ""}`,
253
+ ms,
254
+ data: { run: runId, agent, thread, status, failure: failure ?? null },
255
+ });
256
+ };
257
+
258
+ const follow = (request, agent) => {
259
+ const pid = Number(request.pid);
260
+ if (!Number.isInteger(pid) || pid <= 0)
261
+ return { ok: false, error: "name the process by its number" };
262
+ if (!running(pid))
263
+ return { ok: false, error: `process ${pid} is not running` };
264
+ if (followed.has(pid)) return { ok: true, following: true, pid };
265
+ if (followed.size >= MOST_PROCESSES)
266
+ return {
267
+ ok: false,
268
+ error: `${MOST_PROCESSES} processes are followed already`,
269
+ };
270
+ const spec = { kind: "process", pid };
271
+ let unsubscribe = null;
272
+ unsubscribe = sources.subscribe(spec, (reading) => {
273
+ if (reading.running !== false) return;
274
+ followed.delete(pid);
275
+ queueMicrotask(() => unsubscribe?.());
276
+ });
277
+ followed.set(pid, { unsubscribe, by: agent });
278
+ return { ok: true, following: true, pid, does: sources.describe(spec) };
279
+ };
280
+
281
+ const expect = (request, agent) => {
282
+ const check = checkOf(request);
283
+ if (check.error) return { ok: false, error: check.error };
284
+ if (expectations.size >= MOST_EXPECTATIONS)
285
+ return {
286
+ ok: false,
287
+ error: `${MOST_EXPECTATIONS} expectations are open already`,
288
+ };
289
+ const within = Math.min(
290
+ MOST_WITHIN_SECONDS,
291
+ Math.max(
292
+ 1,
293
+ Math.round(Number(request.withinSeconds) || DEFAULT_WITHIN_SECONDS)
294
+ )
295
+ );
296
+ const id = randomUUID();
297
+ const thing = thingOf(check);
298
+ const verb = check.what === "file" ? "is there" : "answers";
299
+ let settled = false;
300
+ let first = null;
301
+ const answered = new Promise((resolve) => {
302
+ first = resolve;
303
+ });
304
+ const finish = (met, cause = null) => {
305
+ if (settled) return;
306
+ settled = true;
307
+ clearTimeout(deadline);
308
+ expectations.delete(id);
309
+ queueMicrotask(() => unsubscribe?.());
310
+ events.append({
311
+ source: "expect",
312
+ kind: met ? "met" : "unmet",
313
+ subject: id,
314
+ text: met
315
+ ? `${thing} ${verb} now`
316
+ : `${thing} still ${check.what === "file" ? "is not there" : "does not answer"} after ${within} s`,
317
+ data: { check, by: agent, withinSeconds: within },
318
+ cause,
319
+ });
320
+ first?.({ ok: true, id, met, ...(met ? {} : { within }) });
321
+ };
322
+ const deadline = setTimeout(() => finish(false), within * 1000);
323
+ deadline.unref?.();
324
+ let unsubscribe = null;
325
+ unsubscribe = sources.subscribe(check, (reading) => {
326
+ if (reading.true) finish(true, reading.event);
327
+ // Not true at the first look: the caller hears it is followed, and the log says how it ends.
328
+ else if (first) {
329
+ first({ ok: true, id, met: false, following: true, until: within });
330
+ first = null;
331
+ }
332
+ });
333
+ expectations.set(id, { unsubscribe, by: agent });
334
+ return { pending: answered };
335
+ };
336
+
337
+ return {
338
+ runEnded,
339
+ command(request, { agent }) {
340
+ if (request.hostedCaller)
341
+ return {
342
+ ok: false,
343
+ error:
344
+ "only the person and agents on this computer follow what runs here",
345
+ };
346
+ if (request.command === "board.process.follow")
347
+ return follow(request, agent);
348
+ if (request.command === "board.expect") return expect(request, agent);
349
+ return { ok: false, error: `unknown command ${request.command}` };
350
+ },
351
+ stop() {
352
+ for (const { unsubscribe } of followed.values()) unsubscribe?.();
353
+ followed.clear();
354
+ for (const { unsubscribe } of expectations.values()) unsubscribe?.();
355
+ expectations.clear();
356
+ },
357
+ };
358
+ }