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,839 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { harnessHome } from "./paths.mjs";
6
+ import { nameOf } from "./members.mjs";
7
+ import { PARENT, SENSE, putSteer } from "./steerQueue.mjs";
8
+
9
+ // The sense of time (docs/senses-plan.md Phase T, ledger row 34): how long what an agent ran took and what is usual,
10
+ // how long it has been quiet, and how old what it knows is, said only when that should change what it does.
11
+ //
12
+ // One table on each computer, kept where it was measured and sent nowhere: each command an agent ran, as a shape with
13
+ // its values taken out, how long it took while the computer was awake, whether it worked and whether the computer was
14
+ // busy. The hooks around each tool call write it and read it (senseCall.mjs); the daemon keeps what only a running
15
+ // process can know: when the computer slept, when it was busy, when a command sent to the background ended, a known
16
+ // command running far past its usual, and the person's last word (createTimeSense below).
17
+ //
18
+ // Kept on the computer, under senses/time:
19
+ // runs/<key>.json one command in one folder: { cwd, shape, kind, runs: [{ ms, ok, busy, at }] }
20
+ // long.json, long.sh the commands whose usual is long, and the shell test the hook before a call runs on them
21
+ // open/<id>.json a known long command running now: { session, agent, cwd, shape, startedAt, usualMs }
22
+ // pending/<id>.json a command sent to the background, until its processes end
23
+ // took/<id>.json a long command that ended, for the daemon to put in the log
24
+ // slept.json when the computer slept: [{ from, to }]
25
+ // busy.json when it was busy: [{ from, to }] (to null while it still is)
26
+ // person.json { spokeAt, awaySince }: the person's last own words to Harness, and whether they are away
27
+ // and in each session's folder (senseCall.mjs readsRoot) time.json: its calls, its turn and what it was told.
28
+
29
+ // The thresholds, measured November 14 from the agents' own session records on the owner's Mac, the last 30 days
30
+ // (scripts/measure-time-thresholds.py; .harness-runs/senses-time/20261114-thresholds/thresholds.json): 54,778 shell
31
+ // calls, 67,001 gaps between a result and the next call, 5,976 turns.
32
+ // - A call's time is said from 30 s: 7.4% of calls take that long (p50 0.1 s, p90 17 s, p95 56 s).
33
+ export const TOOK_SAID_MS = 30_000;
34
+ // - Too long is 5 times the usual: of commands run 5 times or more in one folder whose usual is 30 s or more (46 runs,
35
+ // a thin sample), a run strayed to 3.3 times its usual at p90, 4.6 at p95, 9.6 at most.
36
+ export const TOO_LONG_TIMES = 5;
37
+ // - A real gap is 5 minutes between steps: within a turn the model's own gap is p99 71 s and 0.03% of gaps reach 5 min.
38
+ export const GAP_MS = 5 * 60_000;
39
+ // - A long turn is 20 minutes: p50 42 s, p90 12 min, p95 20 min.
40
+ export const LONG_TURN_MS = 20 * 60_000;
41
+ // The owner's line (November 14, "agreeed with 2"): the hook before a call says a command's usual only from 2 minutes.
42
+ export const LONG_MS = 2 * 60_000;
43
+ // A computer is busy when more is waiting to run than it has cores (load average per core at 1 or more), or while its
44
+ // memory is under pressure: what ran then is kept but does not move the usual.
45
+ export const BUSY_LOAD = 1;
46
+ // The daemon's look: how soon it hears a sleep, a background command's end, a long command's overrun.
47
+ export const LOOK_MS = 15_000;
48
+ // The wall clock moving this much further than the computer's own counter means it slept between two looks.
49
+ const SLEPT_MS = 10_000;
50
+ // A usual needs this many runs; it reads the last this many runs made while the computer was not busy.
51
+ const USUAL_FROM = 3;
52
+ const USUAL_OF = 20;
53
+ const KEPT_RUNS = 30;
54
+ const KEPT_PERIODS = 500;
55
+ const PERIODS_FOR_MS = 30 * 24 * 3_600_000;
56
+ // A long command's own record goes after this long (its agent stopped without its hook after the call).
57
+ const OPEN_MOST_MS = 6 * 3_600_000;
58
+ const SHAPE_CHARS = 120;
59
+
60
+ export const timeRoot = (home = harnessHome) =>
61
+ path.join(home, "senses", "time");
62
+ const fileIn = (home, ...parts) => path.join(timeRoot(home), ...parts);
63
+
64
+ const readJson = (file, fallback = null) => {
65
+ try {
66
+ return JSON.parse(fs.readFileSync(file, "utf8"));
67
+ } catch {
68
+ return fallback;
69
+ }
70
+ };
71
+ const writeJson = (file, value) => {
72
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
73
+ const part = `${file}.${process.pid}.part`;
74
+ fs.writeFileSync(part, JSON.stringify(value), { mode: 0o600 });
75
+ fs.renameSync(part, file);
76
+ };
77
+ const hash = (text) =>
78
+ crypto.createHash("sha1").update(text).digest("hex").slice(0, 20);
79
+ const namesIn = (folder) => {
80
+ try {
81
+ return fs.readdirSync(folder).filter((name) => name.endsWith(".json"));
82
+ } catch {
83
+ return [];
84
+ }
85
+ };
86
+
87
+ // --- words for a time ---
88
+
89
+ /** A span as an agent reads it: "45 s", "4 min", "1 h 10 min". */
90
+ export function spanOf(ms) {
91
+ const seconds = Math.max(0, Math.round(ms / 1000));
92
+ if (seconds < 60) return `${seconds} s`;
93
+ const minutes = Math.round(seconds / 60);
94
+ if (minutes < 60) return `${minutes} min`;
95
+ const hours = Math.floor(minutes / 60);
96
+ return `${hours} h${minutes % 60 ? ` ${minutes % 60} min` : ""}`;
97
+ }
98
+ const hhmm = (at) =>
99
+ new Date(at).toLocaleTimeString("en-GB", {
100
+ hour: "2-digit",
101
+ minute: "2-digit",
102
+ });
103
+ const dayOf = (at) =>
104
+ new Date(at).toLocaleDateString("en-GB", {
105
+ weekday: "long",
106
+ day: "numeric",
107
+ month: "long",
108
+ });
109
+ const sameDay = (a, b) =>
110
+ new Date(a).toDateString() === new Date(b).toDateString();
111
+
112
+ // --- a command's shape ---
113
+
114
+ /**
115
+ * A command as one run of it is like the next: the folder it changes into, the values it sets and the words it quotes
116
+ * taken out, so the table keeps no secret, path or message, and `npm test` in a folder is one command however it was
117
+ * typed.
118
+ */
119
+ export function shapeOf(command) {
120
+ return String(command ?? "")
121
+ .trim()
122
+ .replace(/^(cd\s+\S+\s*(&&|;)\s*)+/, "")
123
+ .replace(/^(\w+=\S*\s+)+/, "")
124
+ .replace(/\w+:\/\/\S+/g, "<url>")
125
+ .replace(/=\S+/g, "=…")
126
+ .replace(/'[^']*'|"[^"]*"/g, "…")
127
+ .replace(/\s+/g, " ")
128
+ .slice(0, SHAPE_CHARS);
129
+ }
130
+
131
+ const TESTS =
132
+ /\b(test|tests|jest|vitest|pytest|mocha|playwright|rspec|phpunit|smoke|e2e)\b/i;
133
+ const BUILDS =
134
+ /\b(build|tsc|compile|webpack|vite build|make|cargo b|gradle)\b/i;
135
+ const INSTALLS = /\b(install|npm ci|pnpm i|yarn add|pip install|brew)\b/i;
136
+ /** What a command is, for words that leave the table: "test", "build", "install" or "other". */
137
+ export const kindOf = (shape) =>
138
+ TESTS.test(shape)
139
+ ? "test"
140
+ : BUILDS.test(shape)
141
+ ? "build"
142
+ : INSTALLS.test(shape)
143
+ ? "install"
144
+ : "other";
145
+ const commandWord = (kind) =>
146
+ kind === "other" ? "command" : `${kind} command`;
147
+
148
+ // --- the computer asleep and busy ---
149
+
150
+ const overlap = (periods, from, to, at) =>
151
+ periods.reduce(
152
+ (sum, each) =>
153
+ sum +
154
+ Math.max(0, Math.min(to, each.to ?? at) - Math.max(from, each.from)),
155
+ 0
156
+ );
157
+
158
+ /** How long the computer slept between two times. */
159
+ export function sleptBetween(from, to, home = harnessHome) {
160
+ return overlap(readJson(fileIn(home, "slept.json"), []), from, to, to);
161
+ }
162
+
163
+ /** Whether the computer was busy for a part of a span, or is now. */
164
+ export function busyBetween(from, to, home = harnessHome) {
165
+ const now = Date.now();
166
+ const load = os.loadavg()[0] / Math.max(1, os.cpus().length);
167
+ if (to >= now - LOOK_MS && load >= BUSY_LOAD) return true;
168
+ return overlap(readJson(fileIn(home, "busy.json"), []), from, to, now) > 0;
169
+ }
170
+
171
+ /** How long a span lasted while the computer was awake. */
172
+ export const awakeBetween = (from, to, home = harnessHome) =>
173
+ Math.max(0, to - from - sleptBetween(from, to, home));
174
+
175
+ // --- the table ---
176
+
177
+ const runsFile = (cwd, shape, home) =>
178
+ fileIn(home, "runs", `${hash(`${cwd ?? ""}\0${shape}`)}.json`);
179
+
180
+ /**
181
+ * What a command usually takes in a folder, from its last runs while the computer was not busy: `{ ms, low, high,
182
+ * runs, longest, last }` (the middle, the middle half, how many, the longest, the last run), or null before it has
183
+ * three such runs. `last` is there from one run.
184
+ */
185
+ export function usualOf(cwd, shape, home = harnessHome) {
186
+ const kept = readJson(runsFile(cwd, shape, home));
187
+ if (!kept?.runs?.length) return null;
188
+ const last = kept.runs.at(-1);
189
+ const counted = kept.runs.filter((run) => !run.busy).slice(-USUAL_OF);
190
+ if (counted.length < USUAL_FROM)
191
+ return { ms: null, last, runs: counted.length };
192
+ const sorted = counted.map((run) => run.ms).sort((a, b) => a - b);
193
+ return {
194
+ ms: sorted[Math.floor(sorted.length / 2)],
195
+ low: sorted[Math.floor(sorted.length / 4)],
196
+ high: sorted[Math.ceil((sorted.length * 3) / 4) - 1],
197
+ runs: sorted.length,
198
+ longest: sorted.at(-1),
199
+ last,
200
+ };
201
+ }
202
+
203
+ // A long command's shell test: the part of its shape before anything taken out, if the raw call can be matched on it.
204
+ const patternOf = (shape) => {
205
+ const literal = shape.split(/…|<url>/)[0].trim();
206
+ return literal.length >= 4 && !/['"\\]/.test(literal) ? literal : null;
207
+ };
208
+
209
+ // The hook before a call starts Node for a command whose usual is long (hookDialects.mjs reads long.sh), and only then.
210
+ function keepLong(key, entry, home) {
211
+ const file = fileIn(home, "long.json");
212
+ const long = readJson(file, {});
213
+ const was = JSON.stringify(long[key] ?? null);
214
+ if (entry) long[key] = entry;
215
+ else delete long[key];
216
+ if (JSON.stringify(long[key] ?? null) === was) return;
217
+ writeJson(file, long);
218
+ const patterns = [
219
+ ...new Set(
220
+ Object.values(long)
221
+ .map((each) => each.pattern)
222
+ .filter(Boolean)
223
+ ),
224
+ ];
225
+ const test = patterns.length
226
+ ? `case "$input" in ${patterns.map((each) => `*'${each}'*`).join("|")}) risky=1;; esac\n`
227
+ : "";
228
+ fs.writeFileSync(`${fileIn(home, "long.sh")}.part`, test, { mode: 0o600 });
229
+ fs.renameSync(`${fileIn(home, "long.sh")}.part`, fileIn(home, "long.sh"));
230
+ }
231
+
232
+ /** Keeps one run of a command in its folder. Returns the usual before this run. */
233
+ export function noteRun({ cwd, shape, ms, ok, busy }, home = harnessHome) {
234
+ const before = usualOf(cwd, shape, home);
235
+ const file = runsFile(cwd, shape, home);
236
+ const kept = readJson(file) ?? { cwd, shape, kind: kindOf(shape), runs: [] };
237
+ kept.runs.push({
238
+ ms: Math.round(ms),
239
+ ok: ok ?? null,
240
+ busy: Boolean(busy),
241
+ at: new Date().toISOString(),
242
+ });
243
+ kept.runs = kept.runs.slice(-KEPT_RUNS);
244
+ writeJson(file, kept);
245
+ const after = usualOf(cwd, shape, home);
246
+ const key = path.basename(file, ".json");
247
+ keepLong(
248
+ key,
249
+ after?.ms >= LONG_MS
250
+ ? { cwd, shape, pattern: patternOf(shape), usualMs: after.ms }
251
+ : null,
252
+ home
253
+ );
254
+ return before;
255
+ }
256
+
257
+ /** "usually 4 min here (14 runs)", or "the last time 40 s", or null. */
258
+ function usualWords(usual) {
259
+ if (!usual) return null;
260
+ if (!usual.ms) return `the last time ${spanOf(usual.last.ms)}`;
261
+ const range =
262
+ spanOf(usual.low) === spanOf(usual.high)
263
+ ? spanOf(usual.ms)
264
+ : `${spanOf(usual.low)} to ${spanOf(usual.high)}`;
265
+ return `usually ${range} here (${usual.runs} runs)`;
266
+ }
267
+
268
+ /**
269
+ * The line after a call: how long it took, against its usual. Said from 30 s, or for a quicker command that took
270
+ * five times its usual; nothing otherwise.
271
+ */
272
+ export function tookLine({ ms, usual, busy }) {
273
+ const strayed = usual?.ms && ms >= 10_000 && ms >= TOO_LONG_TIMES * usual.ms;
274
+ if (ms < TOOK_SAID_MS && !strayed) return "";
275
+ const words = usualWords(usual);
276
+ return `That took ${spanOf(ms)}${words ? ` (${words})` : ""}${busy ? ", while the computer was busy" : ""}.`;
277
+ }
278
+
279
+ // --- one session's time ---
280
+
281
+ const sessionTime = (session, home) =>
282
+ path.join(home, "senses", "reads", session, "time.json");
283
+
284
+ /** The person's message began a turn: the hook on their prompt notes when (nudge.mjs). */
285
+ export function notePrompt(session, home = harnessHome) {
286
+ if (!/^[A-Za-z0-9._:-]{1,128}$/.test(String(session ?? ""))) return;
287
+ const file = sessionTime(String(session), home);
288
+ const kept = readJson(file, {});
289
+ writeJson(file, {
290
+ ...kept,
291
+ turn: { at: Date.now(), toolMs: 0, thinkMs: 0, told: false },
292
+ });
293
+ }
294
+
295
+ /** A session's time: `{ calls, toolMs, thinkMs, turn, toldAt, told }`. */
296
+ export const timeOf = (session, home = harnessHome) =>
297
+ readJson(sessionTime(session, home), {});
298
+
299
+ /**
300
+ * One tool call ended: kept in the session's time. `started` is when the call began (null when no hook noted it),
301
+ * `previousStep` when the call before it ended. Returns the lines the agent reads about time now.
302
+ */
303
+ export function noteCall(
304
+ session,
305
+ { started, previousStep, ms, now = Date.now() },
306
+ home = harnessHome
307
+ ) {
308
+ const file = sessionTime(session, home);
309
+ const kept = readJson(file, {});
310
+ const turn = kept.turn ?? { at: null, toolMs: 0, thinkMs: 0, told: false };
311
+ // The model's own time: from the result before to this call's start, in the same turn, while the computer was awake.
312
+ // A gap of 5 minutes or more is a break, not thinking (0.03% of gaps within a turn reach it): an agent whose hook does
313
+ // not hear the person's message (Grok Build, Copilot) would otherwise count the time between turns.
314
+ const thought =
315
+ started &&
316
+ previousStep &&
317
+ started > previousStep &&
318
+ started - previousStep < GAP_MS &&
319
+ !(turn.at > previousStep)
320
+ ? awakeBetween(previousStep, started, home)
321
+ : 0;
322
+ const next = {
323
+ ...kept,
324
+ calls: (kept.calls ?? 0) + 1,
325
+ toolMs: (kept.toolMs ?? 0) + (ms ?? 0),
326
+ thinkMs: (kept.thinkMs ?? 0) + thought,
327
+ turn: {
328
+ ...turn,
329
+ toolMs: (turn.toolMs ?? 0) + (ms ?? 0),
330
+ thinkMs: (turn.thinkMs ?? 0) + thought,
331
+ },
332
+ toldAt: kept.toldAt ?? now,
333
+ };
334
+ const lines = [];
335
+ const since = started ?? now;
336
+ // A real gap since its last step, or a new day: the time, and the person's.
337
+ const gap = previousStep ? since - previousStep : 0;
338
+ if (gap >= GAP_MS || (previousStep && !sameDay(next.toldAt, now))) {
339
+ const slept = previousStep ? sleptBetween(previousStep, since, home) : 0;
340
+ lines.push(
341
+ `It is ${hhmm(now)} on ${dayOf(now)}, by this computer's clock.${gap >= GAP_MS ? ` Your step before this one was ${spanOf(gap)} ago${slept >= 60_000 ? ` (the computer slept ${spanOf(slept)} of it)` : ""}.` : ""}`
342
+ );
343
+ next.toldAt = now;
344
+ const person = personLine(now, home);
345
+ if (person) lines.push(person);
346
+ }
347
+ // A long turn, once.
348
+ if (turn.at && !turn.told && now - turn.at >= LONG_TURN_MS) {
349
+ next.turn.told = true;
350
+ lines.push(
351
+ `This turn has run ${spanOf(now - turn.at)} since the message that began it (${spanOf(next.turn.toolMs)} in tool calls, ${spanOf(next.turn.thinkMs)} thinking).`
352
+ );
353
+ if (!lines.some((line) => line.startsWith("The person"))) {
354
+ const person = personLine(now, home);
355
+ if (person) lines.push(person);
356
+ }
357
+ }
358
+ writeJson(file, next);
359
+ return lines;
360
+ }
361
+
362
+ // The person's last words to Harness and whether they are at this computer, as the daemon keeps them.
363
+ function personLine(now, home) {
364
+ const person = readJson(fileIn(home, "person.json"));
365
+ if (!person?.spokeAt) return "";
366
+ const ago = now - Date.parse(person.spokeAt);
367
+ if (ago < GAP_MS) return "";
368
+ const away = person.awaySince
369
+ ? `, and has been away from this computer for ${spanOf(now - Date.parse(person.awaySince))}`
370
+ : "";
371
+ return `The person last wrote to Harness ${spanOf(ago)} ago${away}.`;
372
+ }
373
+
374
+ // --- before a call ---
375
+
376
+ /**
377
+ * Before a shell command whose usual here is long: the hold that says so, once a session for each command, unless
378
+ * the agent already planned for it (sent it to the background, or gave it a timeout past its usual). A known long
379
+ * command that runs is noted as running, so the daemon can say when it runs far past its usual.
380
+ */
381
+ export function beforeLong(
382
+ { session, agent, cwd, command, input, callId, notes = null },
383
+ home = harnessHome
384
+ ) {
385
+ const shape = shapeOf(command);
386
+ const usual = usualOf(cwd, shape, home);
387
+ if (!usual?.ms || usual.ms < LONG_MS) return null;
388
+ const key = hash(`${cwd ?? ""}\0${shape}`);
389
+ const file = sessionTime(session, home);
390
+ const kept = readJson(file, {});
391
+ const told = new Set(kept.told ?? []);
392
+ const timeout = Number(input?.timeout ?? input?.timeout_ms ?? 0);
393
+ const planned =
394
+ input?.run_in_background === true || timeout >= 1.5 * usual.ms;
395
+ const sayUsual = !told.has(key) && !planned;
396
+ // What waits for the session would wait behind the whole command: handed over now (`notes` takes it).
397
+ const waiting = notes ? notes() : "";
398
+ if (sayUsual || waiting) {
399
+ if (sayUsual) {
400
+ told.add(key);
401
+ writeJson(file, { ...kept, told: [...told].slice(-200) });
402
+ }
403
+ const longest =
404
+ usual.longest > usual.high
405
+ ? `, the longest ${spanOf(usual.longest)}`
406
+ : "";
407
+ return {
408
+ hold: [
409
+ waiting,
410
+ sayUsual
411
+ ? `This command ${usualWords(usual)}${longest}. It was not run, so you can choose how to wait for it: in the background, or with a timeout past that. Make it again to run it.`
412
+ : "This call was not run, so that you read this first. Make it again if it still stands.",
413
+ ]
414
+ .filter(Boolean)
415
+ .join("\n"),
416
+ };
417
+ }
418
+ writeJson(
419
+ fileIn(home, "open", `${hash(`${session}\0${callId ?? key}`)}.json`),
420
+ {
421
+ session,
422
+ agent,
423
+ cwd,
424
+ shape,
425
+ kind: kindOf(shape),
426
+ startedAt: Date.now(),
427
+ usualMs: usual.ms,
428
+ }
429
+ );
430
+ return null;
431
+ }
432
+
433
+ /** The command ended: it is no longer running. */
434
+ export function endLong({ session, cwd, command, callId }, home = harnessHome) {
435
+ const key = hash(`${cwd ?? ""}\0${shapeOf(command)}`);
436
+ fs.rmSync(
437
+ fileIn(home, "open", `${hash(`${session}\0${callId ?? key}`)}.json`),
438
+ {
439
+ force: true,
440
+ }
441
+ );
442
+ }
443
+
444
+ /** A command sent to the background: its time is kept when its processes end (the daemon looks). */
445
+ export function notePending(
446
+ { session, agent, cwd, command, startedAt, pids },
447
+ home = harnessHome
448
+ ) {
449
+ if (!pids.length) return;
450
+ writeJson(
451
+ fileIn(
452
+ home,
453
+ "pending",
454
+ `${hash(`${session}\0${startedAt}\0${command}`)}.json`
455
+ ),
456
+ {
457
+ session,
458
+ agent,
459
+ cwd,
460
+ shape: shapeOf(command),
461
+ startedAt,
462
+ pids,
463
+ }
464
+ );
465
+ }
466
+
467
+ /** A long command ended: the daemon says so in the log, for the thread's timeline. */
468
+ export function noteTook(
469
+ { session, agent, shape, ms, ok, usualMs = null },
470
+ home = harnessHome
471
+ ) {
472
+ if (ms < LONG_MS) return;
473
+ writeJson(
474
+ fileIn(home, "took", `${hash(`${session}\0${Date.now()}\0${shape}`)}.json`),
475
+ {
476
+ session,
477
+ agent,
478
+ kind: kindOf(shape),
479
+ ms: Math.round(ms),
480
+ ok: ok ?? null,
481
+ usualMs,
482
+ at: new Date().toISOString(),
483
+ }
484
+ );
485
+ }
486
+
487
+ /**
488
+ * Before a commit or a push: the session's last test or build came before files it changed since. Once for each such
489
+ * run, as a hold; null when it never ran one or changed nothing since.
490
+ */
491
+ export function staleResult({ session, ran, writes }, home = harnessHome) {
492
+ const last = [...ran]
493
+ .reverse()
494
+ .find(
495
+ (each) =>
496
+ kindOf(shapeOf(each.command)) === "test" ||
497
+ kindOf(shapeOf(each.command)) === "build"
498
+ );
499
+ if (!last) return null;
500
+ const changed = writes
501
+ .filter((seen) => Date.parse(seen.at) > last.at)
502
+ // In the order the session changed them.
503
+ .sort((a, b) => Date.parse(a.at) - Date.parse(b.at))
504
+ .map((seen) => path.basename(seen.file));
505
+ if (!changed.length) return null;
506
+ const file = sessionTime(session, home);
507
+ const kept = readJson(file, {});
508
+ if (kept.staleTold === last.at) return null;
509
+ writeJson(file, { ...kept, staleTold: last.at });
510
+ const named = changed.slice(0, 3).join(", ");
511
+ const more = changed.length > 3 ? ` and ${changed.length - 3} more` : "";
512
+ const outcome =
513
+ last.ok === true ? "passed" : last.ok === false ? "failed" : "ran";
514
+ return {
515
+ hold: `Your last ${kindOf(shapeOf(last.command))} run (${shapeOf(last.command)}, ${outcome} at ${hhmm(last.at)}) came before you changed ${changed.length} file${changed.length === 1 ? "" : "s"}: ${named}${more}. This call was not run, so you can decide whether to run it again first. Make it again to go ahead.`,
516
+ };
517
+ }
518
+
519
+ // --- asked: how long ---
520
+
521
+ /** What an agent asks: how long a command takes here, or, with none named, its own session and turn. */
522
+ export function howLong({ session, cwd, command }, home = harnessHome) {
523
+ if (command) {
524
+ const shape = shapeOf(command);
525
+ const usual = usualOf(cwd, shape, home);
526
+ if (!usual)
527
+ return `Harness has no record of ${shape} in ${cwd ?? "this folder"} on this computer.`;
528
+ const kept = readJson(runsFile(cwd, shape, home));
529
+ const busy = kept.runs.filter((run) => run.busy).length;
530
+ const last = usual.last;
531
+ return [
532
+ usual.ms
533
+ ? `${shape} ${usualWords(usual)}, the longest ${spanOf(usual.longest)}.`
534
+ : `${shape} has run ${kept.runs.length} time${kept.runs.length === 1 ? "" : "s"} here: too few for a usual.`,
535
+ `The last run took ${spanOf(last.ms)} at ${hhmm(last.at)}${last.ok === true ? " and worked" : last.ok === false ? " and failed" : ""}.`,
536
+ ...(busy
537
+ ? [
538
+ `${busy} run${busy === 1 ? " was" : "s were"} made while the computer was busy and ${busy === 1 ? "is" : "are"} not counted in the usual.`,
539
+ ]
540
+ : []),
541
+ ].join(" ");
542
+ }
543
+ if (!session)
544
+ return "Harness has not seen this session make a tool call yet.";
545
+ const kept = timeOf(session, home);
546
+ if (!kept.calls) return "Harness has no record of this session's calls yet.";
547
+ const turn = kept.turn?.at
548
+ ? ` This turn began ${spanOf(Date.now() - kept.turn.at)} ago: ${spanOf(kept.turn.toolMs ?? 0)} in tool calls, ${spanOf(kept.turn.thinkMs ?? 0)} thinking.`
549
+ : "";
550
+ return `This session has made ${kept.calls} tool call${kept.calls === 1 ? "" : "s"}: ${spanOf(kept.toolMs ?? 0)} in them and ${spanOf(kept.thinkMs ?? 0)} thinking between them, while the computer was awake.${turn}`;
551
+ }
552
+
553
+ // --- the daemon's part ---
554
+
555
+ const alive = (pid) => {
556
+ try {
557
+ process.kill(pid, 0);
558
+ return true;
559
+ } catch (error) {
560
+ return error.code === "EPERM";
561
+ }
562
+ };
563
+
564
+ /**
565
+ * The daemon's part of the sense of time. `pressure()`: whether memory is under pressure now (machine.mjs);
566
+ * `spokeAt()`: when the person last wrote to Harness; `awaySince()`: since when they are away from this computer, or
567
+ * null; `touches(happening)`: the thread a happening touches (daemon.mjs threadTouched); `clock` the wall and the
568
+ * computer's own counter, which stops while it sleeps.
569
+ */
570
+ export function createTimeSense({
571
+ events,
572
+ home = harnessHome,
573
+ pressure = () => false,
574
+ spokeAt = () => null,
575
+ awaySince = () => null,
576
+ touches = () => null,
577
+ computerOf = () => null,
578
+ log = () => {},
579
+ clock = { wall: () => Date.now(), counter: () => performance.now() },
580
+ }) {
581
+ let timer = null;
582
+ let last = null;
583
+
584
+ const keepPeriods = (name, change) => {
585
+ const file = fileIn(home, name);
586
+ const now = clock.wall();
587
+ const periods = change(readJson(file, []))
588
+ .filter((each) => (each.to ?? now) > now - PERIODS_FOR_MS)
589
+ .slice(-KEPT_PERIODS);
590
+ writeJson(file, periods);
591
+ };
592
+
593
+ // The wall clock against the computer's own counter: a jump between two looks is time the computer slept.
594
+ const hearSleep = () => {
595
+ const wall = clock.wall();
596
+ const offset = wall - clock.counter();
597
+ if (last && offset - last.offset >= SLEPT_MS) {
598
+ const slept = offset - last.offset;
599
+ keepPeriods("slept.json", (periods) => [
600
+ ...periods,
601
+ { from: wall - slept, to: wall },
602
+ ]);
603
+ events.append({
604
+ source: "machine",
605
+ kind: "slept",
606
+ text: `this computer slept ${spanOf(slept)}`,
607
+ data: { ms: Math.round(slept) },
608
+ });
609
+ }
610
+ last = { offset };
611
+ };
612
+
613
+ let busySince = null;
614
+ const hearBusy = () => {
615
+ const load = os.loadavg()[0] / Math.max(1, os.cpus().length);
616
+ const busy = load >= BUSY_LOAD || pressure();
617
+ const now = clock.wall();
618
+ if (busy && busySince == null) {
619
+ busySince = now;
620
+ keepPeriods("busy.json", (periods) => [
621
+ ...periods,
622
+ { from: now, to: null },
623
+ ]);
624
+ } else if (!busy && busySince != null) {
625
+ busySince = null;
626
+ keepPeriods("busy.json", (periods) =>
627
+ periods.map((each) => (each.to == null ? { ...each, to: now } : each))
628
+ );
629
+ }
630
+ };
631
+
632
+ const tookText = (agent, kind, ms, ok, usualMs) =>
633
+ `${nameOf(agent)}'s ${commandWord(kind)} took ${spanOf(ms)}${ok === true ? " and worked" : ok === false ? " and failed" : ""}${usualMs ? ` (usually ${spanOf(usualMs)})` : ""}`;
634
+
635
+ // A command sent to the background ended once its processes have.
636
+ const hearPending = () => {
637
+ for (const name of namesIn(fileIn(home, "pending"))) {
638
+ const file = fileIn(home, "pending", name);
639
+ const pending = readJson(file);
640
+ const now = clock.wall();
641
+ if (!pending || now - pending.startedAt > OPEN_MOST_MS * 4) {
642
+ fs.rmSync(file, { force: true });
643
+ continue;
644
+ }
645
+ if (pending.pids.some(alive)) continue;
646
+ fs.rmSync(file, { force: true });
647
+ const ms = awakeBetween(pending.startedAt, now, home);
648
+ const busy = busyBetween(pending.startedAt, now, home);
649
+ const usual = noteRun(
650
+ { cwd: pending.cwd, shape: pending.shape, ms, ok: null, busy },
651
+ home
652
+ );
653
+ noteTook(
654
+ {
655
+ session: pending.session,
656
+ agent: pending.agent,
657
+ shape: pending.shape,
658
+ ms,
659
+ ok: null,
660
+ usualMs: usual?.ms ?? null,
661
+ },
662
+ home
663
+ );
664
+ }
665
+ };
666
+
667
+ // A known long command running far past its usual: its agent hears it at its next step, the log says it (the
668
+ // thread's record and stuck read it there), once. Not while the computer is busy, which slows everything.
669
+ const hearOverrun = () => {
670
+ for (const name of namesIn(fileIn(home, "open"))) {
671
+ const file = fileIn(home, "open", name);
672
+ const open = readJson(file);
673
+ const now = clock.wall();
674
+ if (!open || now - open.startedAt > OPEN_MOST_MS) {
675
+ fs.rmSync(file, { force: true });
676
+ continue;
677
+ }
678
+ if (open.toldAt) continue;
679
+ const ms = awakeBetween(open.startedAt, now, home);
680
+ if (ms < TOO_LONG_TIMES * open.usualMs) continue;
681
+ if (busyBetween(now - LOOK_MS, now, home)) continue;
682
+ writeJson(file, { ...open, toldAt: now });
683
+ putSteer(
684
+ {
685
+ session: open.session,
686
+ agent: PARENT,
687
+ kind: SENSE,
688
+ text: `Your ${open.shape} has run ${spanOf(ms)} here; it usually takes ${spanOf(open.usualMs)}. It may be stuck.`,
689
+ },
690
+ home
691
+ );
692
+ events.append({
693
+ source: "senses",
694
+ kind: "running long",
695
+ subject: `session:${open.session}`,
696
+ text: `${nameOf(open.agent)}'s ${commandWord(open.kind)} has run ${spanOf(ms)}, usually ${spanOf(open.usualMs)}`,
697
+ data: {
698
+ agent: open.agent,
699
+ what: open.kind,
700
+ ms: Math.round(ms),
701
+ usualMs: open.usualMs,
702
+ },
703
+ });
704
+ }
705
+ };
706
+
707
+ // Long commands that ended, from the hooks: in the log, for the thread's timeline.
708
+ const hearTook = () => {
709
+ for (const name of namesIn(fileIn(home, "took"))) {
710
+ const file = fileIn(home, "took", name);
711
+ const took = readJson(file);
712
+ fs.rmSync(file, { force: true });
713
+ if (!took) continue;
714
+ events.append({
715
+ source: "senses",
716
+ kind: "took",
717
+ subject: `session:${took.session}`,
718
+ text: tookText(took.agent, took.kind, took.ms, took.ok, took.usualMs),
719
+ data: { agent: took.agent, what: took.kind, ms: took.ms, ok: took.ok },
720
+ });
721
+ }
722
+ };
723
+
724
+ // The person's last words and whether they are away, for the hooks' lines.
725
+ const hearPerson = () => {
726
+ const person = { spokeAt: spokeAt(), awaySince: awaySince() };
727
+ const file = fileIn(home, "person.json");
728
+ if (JSON.stringify(readJson(file)) !== JSON.stringify(person))
729
+ writeJson(file, person);
730
+ };
731
+
732
+ const look = () => {
733
+ for (const part of [
734
+ hearSleep,
735
+ hearBusy,
736
+ hearPending,
737
+ hearOverrun,
738
+ hearTook,
739
+ hearPerson,
740
+ ])
741
+ try {
742
+ part();
743
+ } catch (error) {
744
+ log(`time: ${part.name} ${error.message}`);
745
+ }
746
+ };
747
+
748
+ /** The known long command a session is running now: `{ shape, kind, startedAt, usualMs }`, or null. */
749
+ const runningLong = (session) => {
750
+ for (const name of namesIn(fileIn(home, "open"))) {
751
+ const open = readJson(fileIn(home, "open", name));
752
+ if (open?.session === session) return open;
753
+ }
754
+ return null;
755
+ };
756
+
757
+ // What a thread's timeline reads: runs, long commands, the computer asleep, the person away, work that got stuck.
758
+ const TIMELINE_SOURCES = ["run", "senses", "machine", "stuck"];
759
+ const PAGE = 100;
760
+ const inTimeline = (happening) =>
761
+ (happening.source === "run" && happening.kind === "ended") ||
762
+ (happening.source === "senses" &&
763
+ ["took", "running long"].includes(happening.kind)) ||
764
+ (happening.source === "machine" &&
765
+ happening.kind === "slept" &&
766
+ (happening.data?.ms ?? 0) >= 30 * 60_000) ||
767
+ (happening.source === "stuck" && happening.kind === "found");
768
+
769
+ /**
770
+ * A thread's dated timeline, oldest first, from the log: when it began, each run's end, each long command, the
771
+ * computer asleep for half an hour or more, work that got stuck; `until` stops it there. Each time is on the clock of
772
+ * the computer it happened on, which it names.
773
+ */
774
+ const timeline = (thread, { began = null, until = null, most = 12 } = {}) => {
775
+ const found = [];
776
+ let after = 0;
777
+ // Oldest first from the thread's start (the log reads from its end when it is given no start).
778
+ const since = began ?? new Date(0).toISOString();
779
+ for (let read = 0; read < 5_000; read += PAGE) {
780
+ const page = events.read({
781
+ after,
782
+ since,
783
+ sources: TIMELINE_SOURCES,
784
+ limit: PAGE,
785
+ });
786
+ for (const happening of page) {
787
+ if (until && happening.at >= until) continue;
788
+ if (!inTimeline(happening)) continue;
789
+ const touched = happening.machine
790
+ ? happening.data?.thread
791
+ : happening.source === "machine"
792
+ ? thread
793
+ : touches(happening);
794
+ if (touched === thread) found.push(happening);
795
+ }
796
+ if (page.length < PAGE) break;
797
+ after = page.at(-1).seq;
798
+ }
799
+ // A sleep counts only within the thread's own work: after its first and before its last other line.
800
+ const work = found.filter((each) => each.source !== "machine");
801
+ if (!work.length && !began) return [];
802
+ const first = work[0]?.at;
803
+ const lastAt = work.at(-1)?.at;
804
+ const kept = found.filter(
805
+ (each) =>
806
+ each.source !== "machine" ||
807
+ (first && each.at > first && each.at < lastAt)
808
+ );
809
+ const shown = kept.slice(-most);
810
+ const now = clock.wall();
811
+ const when = (at) =>
812
+ sameDay(at, now) ? hhmm(at) : `${dayOf(at)} ${hhmm(at)}`;
813
+ return [
814
+ ...(began ? [`- ${when(began)} the thread began`] : []),
815
+ ...(kept.length > shown.length
816
+ ? [`- (${kept.length - shown.length} earlier not shown)`]
817
+ : []),
818
+ ...shown.map(
819
+ (each) =>
820
+ `- ${when(each.at)}${each.machine ? ` on ${computerOf(each.machine) || "another computer"}` : ""} ${each.text}`
821
+ ),
822
+ ];
823
+ };
824
+
825
+ return {
826
+ start() {
827
+ look();
828
+ timer = setInterval(look, LOOK_MS);
829
+ timer.unref?.();
830
+ },
831
+ stop() {
832
+ clearInterval(timer);
833
+ timer = null;
834
+ },
835
+ look,
836
+ runningLong,
837
+ timeline,
838
+ };
839
+ }