tryharness 0.7.83 → 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 (215) 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 +191 -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 +52 -0
  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 +2426 -338
  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 +1 -1
  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/originals.mjs +216 -0
  107. package/lib/outsideEvents.mjs +383 -0
  108. package/lib/outsideRuns.mjs +230 -0
  109. package/lib/ownMachines.mjs +674 -256
  110. package/lib/pain.mjs +215 -0
  111. package/lib/pairing.mjs +91 -11
  112. package/lib/paths.mjs +42 -3
  113. package/lib/peerProcess.mjs +21 -7
  114. package/lib/peopleLink.mjs +268 -0
  115. package/lib/personNotices.mjs +3 -2
  116. package/lib/phones.mjs +252 -542
  117. package/lib/placeCards.mjs +282 -0
  118. package/lib/placeChecks.mjs +95 -0
  119. package/lib/placeCommands.mjs +8 -17
  120. package/lib/placeRequests.mjs +152 -0
  121. package/lib/placeStore.mjs +295 -0
  122. package/lib/placeTool.d.ts +12 -0
  123. package/lib/placeTool.js +40 -0
  124. package/lib/places.mjs +63 -14
  125. package/lib/plans.mjs +53 -8
  126. package/lib/presence.mjs +270 -0
  127. package/lib/privateNetwork.d.ts +2 -0
  128. package/lib/privateNetwork.js +93 -0
  129. package/lib/proposals.mjs +300 -0
  130. package/lib/publicFetch.d.ts +32 -0
  131. package/lib/publicFetch.js +248 -0
  132. package/lib/reach.mjs +128 -0
  133. package/lib/rebuildable.mjs +72 -0
  134. package/lib/recall.mjs +216 -0
  135. package/lib/record.mjs +13 -0
  136. package/lib/reflexes.mjs +392 -0
  137. package/lib/relayLimits.mjs +31 -2
  138. package/lib/releaseNotice.mjs +198 -0
  139. package/lib/removeHarness.mjs +15 -4
  140. package/lib/repoLinks.mjs +204 -35
  141. package/lib/runAuthority.mjs +102 -39
  142. package/lib/runBrief.mjs +93 -40
  143. package/lib/runRequests.mjs +52 -14
  144. package/lib/runUsage.mjs +31 -0
  145. package/lib/runWorker.mjs +74 -25
  146. package/lib/runner.mjs +289 -45
  147. package/lib/runtime-install.mjs +37 -8
  148. package/lib/schedules.mjs +171 -47
  149. package/lib/screenWatches.mjs +221 -0
  150. package/lib/sealed.mjs +12 -30
  151. package/lib/sealedThreads.mjs +198 -392
  152. package/lib/secretStore.mjs +178 -0
  153. package/lib/secrets.mjs +11 -0
  154. package/lib/seen.mjs +3 -9
  155. package/lib/selfUpdate.mjs +51 -15
  156. package/lib/senseCall.mjs +1514 -0
  157. package/lib/senseHook.mjs +114 -0
  158. package/lib/senseTools.mjs +1298 -0
  159. package/lib/sessionBriefs.mjs +87 -0
  160. package/lib/sessionControl.mjs +63 -13
  161. package/lib/sessionFiles.mjs +85 -0
  162. package/lib/setupChoices.mjs +12 -3
  163. package/lib/setupMode.mjs +70 -25
  164. package/lib/sharedKeys.mjs +166 -0
  165. package/lib/sleep.mjs +396 -0
  166. package/lib/sources.mjs +306 -0
  167. package/lib/speech.mjs +166 -411
  168. package/lib/spoken.mjs +210 -0
  169. package/lib/steerHook.mjs +3 -1
  170. package/lib/steerQueue.mjs +40 -11
  171. package/lib/store.mjs +323 -130
  172. package/lib/stuck.mjs +85 -7
  173. package/lib/swarm.mjs +157 -49
  174. package/lib/swarmDevices.mjs +25 -85
  175. package/lib/swarmMemory.mjs +93 -9
  176. package/lib/t3.mjs +73 -3
  177. package/lib/taskCommands.mjs +51 -60
  178. package/lib/taskRooms.mjs +30 -4
  179. package/lib/taskRules.json +29 -0
  180. package/lib/taskRules.mjs +21 -0
  181. package/lib/taskRuns.mjs +74 -11
  182. package/lib/team.mjs +2 -1
  183. package/lib/threadActions.mjs +37 -9
  184. package/lib/threadAuthority.mjs +4 -4
  185. package/lib/threadBriefs.mjs +173 -43
  186. package/lib/threadNotes.mjs +320 -0
  187. package/lib/threadRecord.mjs +491 -0
  188. package/lib/threadRuns.mjs +216 -108
  189. package/lib/threadView.mjs +27 -30
  190. package/lib/threadWatches.mjs +1962 -0
  191. package/lib/timeSense.mjs +839 -0
  192. package/lib/tripwires.mjs +454 -0
  193. package/lib/ui.mjs +1 -1
  194. package/lib/vault.mjs +560 -45
  195. package/lib/vaultCommands.mjs +5 -3
  196. package/lib/vaultPeers.mjs +165 -0
  197. package/lib/vaultTools.d.ts +4 -1
  198. package/lib/vaultTools.js +22 -1
  199. package/lib/verdicts.mjs +12 -26
  200. package/lib/versions.mjs +117 -0
  201. package/lib/waitTool.mjs +278 -0
  202. package/lib/wakePicture.mjs +268 -0
  203. package/lib/wakeQueue.mjs +108 -0
  204. package/lib/watchResponses.mjs +533 -0
  205. package/lib/watches.mjs +290 -145
  206. package/lib/windowAsks.mjs +80 -17
  207. package/lib/worktrees.mjs +159 -9
  208. package/npm-shrinkwrap.json +138 -631
  209. package/package.json +7 -6
  210. package/release.json +211 -129
  211. package/lib/callSessions.mjs +0 -51
  212. package/lib/directLink.mjs +0 -349
  213. package/lib/peopleBoard.mjs +0 -131
  214. package/lib/projects.mjs +0 -2917
  215. package/lib/roomChannels.mjs +0 -667
@@ -0,0 +1,306 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+
4
+ // Sources: each reads one thing on this computer and reports it (docs/senses-plan.md, "How the parts fit"). A source
5
+ // starts when its first subscriber comes and stops when its last one goes, so nothing is read that nobody follows, and
6
+ // two subscribers asking for the same thing share one source. What a source reads is a state: each reading goes to its
7
+ // subscribers and is kept as what it is now. What happens (a time came, it can no longer read, it reads again) is a
8
+ // happening in the log (events.mjs), and the reading names it, so whatever answers the reading can name its cause.
9
+ //
10
+ // A kind of source is an adapter at this seam: `describe(options)` says in one line what it will do before it starts;
11
+ // `start(options, io)` begins reading, never reports before it returns, reports with `io.report(reading, happened)` and
12
+ // returns `{ stop }`. A reading with an `error` means the source cannot read: the log says so once when that starts and
13
+ // once when it reads again. What a source must know across a restart to say what changed while the daemon was off (a
14
+ // mark, a snapshot) it keeps with `io.remember(value)` and finds again with `io.remembered()`, under its own name. A
15
+ // source an agent sets up is the command kind, run in the folder it names, never as daemon code.
16
+
17
+ // The clock reads the wall clock this often while a time is waited for (schedules.mjs read it on the same look for
18
+ // check-ins before): Node's timers stop counting while the Mac sleeps, so a long timer would fire hours late.
19
+ export const CLOCK_LOOK_MS = 30_000;
20
+
21
+ // A source's options as one key, the same whatever order they were given in.
22
+ const keyOf = (spec) =>
23
+ JSON.stringify(
24
+ Object.keys(spec)
25
+ .sort()
26
+ .map((name) => [name, spec[name]])
27
+ );
28
+ // What the log calls a source: its kind and a short name for its options, which may hold a whole command.
29
+ const subjectOf = (kind, key) =>
30
+ `${kind}:${createHash("sha256").update(key).digest("hex").slice(0, 12)}`;
31
+ /** What the log calls the source a spec names, so a reader can find that source's happenings. */
32
+ export const subjectFor = (spec) => subjectOf(spec.kind, keyOf(spec));
33
+
34
+ /**
35
+ * The clock: tells a subscriber when a time on the wall clock comes (`{ at }`, ms or ISO). The wall clock is read on a
36
+ * short look, and a time due before the next look gets a timer of its own, so it comes on time while the Mac is awake
37
+ * and as soon as it wakes otherwise. The look runs only while some time is waited for.
38
+ */
39
+ export function createClock({ now = () => Date.now() } = {}) {
40
+ const waiting = new Set();
41
+ let look = null;
42
+ let soon = null;
43
+
44
+ const arm = () => {
45
+ clearTimeout(soon);
46
+ soon = null;
47
+ if (!waiting.size) {
48
+ clearInterval(look);
49
+ look = null;
50
+ return;
51
+ }
52
+ if (!look) {
53
+ look = setInterval(comeDue, CLOCK_LOOK_MS);
54
+ look.unref?.();
55
+ }
56
+ const next = Math.min(...[...waiting].map((entry) => entry.at));
57
+ const wait = next - now();
58
+ if (wait < CLOCK_LOOK_MS) {
59
+ soon = setTimeout(comeDue, Math.max(0, wait));
60
+ soon.unref?.();
61
+ }
62
+ };
63
+
64
+ function comeDue() {
65
+ const at = now();
66
+ for (const entry of [...waiting]) {
67
+ if (entry.at > at) continue;
68
+ waiting.delete(entry);
69
+ const lateMs = at - entry.at;
70
+ const dueAt = new Date(entry.at).toISOString();
71
+ entry.io.report(
72
+ { at, dueAt: entry.at, lateMs },
73
+ { kind: "due", text: `${dueAt} came`, data: { dueAt, lateMs } }
74
+ );
75
+ }
76
+ arm();
77
+ }
78
+
79
+ return {
80
+ describe: ({ at }) =>
81
+ `says when ${new Date(at).toISOString()} comes on this computer's clock`,
82
+ start({ at }, io) {
83
+ const time = typeof at === "number" ? at : Date.parse(at);
84
+ if (!Number.isFinite(time)) throw new Error("a clock needs a time");
85
+ const entry = { at: time, io };
86
+ waiting.add(entry);
87
+ arm();
88
+ return {
89
+ stop() {
90
+ waiting.delete(entry);
91
+ arm();
92
+ },
93
+ };
94
+ },
95
+ };
96
+ }
97
+
98
+ /** Runs a command in its folder: its output, or an error. A run never lasts longer than its own interval. */
99
+ function runCommand({ command, folder, everySeconds }, shell) {
100
+ return new Promise((resolve) => {
101
+ const started = performance.now();
102
+ let out = "";
103
+ let err = "";
104
+ let done = false;
105
+ const child = spawn(shell, ["-lc", command], {
106
+ cwd: folder || undefined,
107
+ stdio: ["ignore", "pipe", "pipe"],
108
+ });
109
+ const timer = setTimeout(() => {
110
+ child.kill("SIGKILL");
111
+ finish(null, `it took longer than its ${everySeconds} s interval`);
112
+ }, everySeconds * 1000);
113
+ const finish = (output, error) => {
114
+ if (done) return;
115
+ done = true;
116
+ clearTimeout(timer);
117
+ resolve({ output, error, ms: Math.round(performance.now() - started) });
118
+ };
119
+ child.stdout.on("data", (chunk) => {
120
+ out = (out + chunk).slice(-200_000);
121
+ });
122
+ child.stderr.on("data", (chunk) => {
123
+ err = (err + chunk).slice(-4_000);
124
+ });
125
+ child.on("error", (error) => finish(null, error.message));
126
+ child.on("close", (code) =>
127
+ finish(
128
+ code === 0 || out ? out : null,
129
+ code === 0 || out
130
+ ? null
131
+ : err.trim().split("\n").at(-1) || `it exited with code ${code}`
132
+ )
133
+ );
134
+ });
135
+ }
136
+
137
+ /**
138
+ * A command run on this computer on an interval (`{ command, folder, everySeconds }`): each reading is its output, or
139
+ * the error that kept it from having one. The first run starts at once; each next one an interval after the last ended.
140
+ */
141
+ export function createCommand({
142
+ shell = process.env.SHELL || "/bin/sh",
143
+ now = () => Date.now(),
144
+ } = {}) {
145
+ return {
146
+ describe: ({ command, folder, everySeconds }) =>
147
+ `runs ${command}${folder ? ` in ${folder}` : ""} every ${everySeconds} s`,
148
+ start(options, io) {
149
+ let stopped = false;
150
+ let timer = null;
151
+ const read = () =>
152
+ runCommand(options, shell).then((result) => {
153
+ if (stopped) return;
154
+ io.report({ at: now(), ...result });
155
+ timer = setTimeout(read, options.everySeconds * 1000);
156
+ timer.unref?.();
157
+ });
158
+ timer = setTimeout(read, 0);
159
+ timer.unref?.();
160
+ return {
161
+ stop() {
162
+ stopped = true;
163
+ clearTimeout(timer);
164
+ },
165
+ };
166
+ },
167
+ };
168
+ }
169
+
170
+ /**
171
+ * The sources on this computer. `subscribe(spec, onReading)` starts the source `spec` names (`{ kind, ...options }`) if
172
+ * none runs yet and hands each reading to `onReading`; the function it returns stops following, and the source stops
173
+ * with its last subscriber. `describe(spec)` says in one line what it does; `now(spec)` is its latest reading, or null.
174
+ * `kinds` adds kinds to the clock and the command; `memory` (`get(name)`, `set(name, value)`) keeps what sources
175
+ * remember across restarts.
176
+ */
177
+ export function createSources({
178
+ events,
179
+ log = () => {},
180
+ now = () => Date.now(),
181
+ kinds: added = {},
182
+ memory = null,
183
+ }) {
184
+ const kinds = {
185
+ clock: createClock({ now }),
186
+ command: createCommand({ now }),
187
+ ...added,
188
+ };
189
+ const running = new Map();
190
+
191
+ const kindOf = (spec) => {
192
+ const kind = kinds[spec?.kind];
193
+ if (!kind) throw new Error(`no source of kind ${spec?.kind}`);
194
+ return kind;
195
+ };
196
+
197
+ // Whether the source can read changed: said once in the log each way, with what the source does.
198
+ const noteSight = (source, reading) => {
199
+ const blind = Boolean(reading.error);
200
+ if (blind === source.blind) return null;
201
+ source.blind = blind;
202
+ return events.append({
203
+ source: source.spec.kind,
204
+ kind: blind ? "blind" : "sees",
205
+ subject: source.subject,
206
+ text: blind ? `cannot read: ${reading.error}` : "reads again",
207
+ data: { does: source.does },
208
+ });
209
+ };
210
+
211
+ // A report never throws back into its source: a log that cannot be written still lets the reading through.
212
+ const written = (source, write) => {
213
+ try {
214
+ return write();
215
+ } catch (error) {
216
+ log(`${source.subject}: the log: ${error.message}`);
217
+ return null;
218
+ }
219
+ };
220
+
221
+ const reporter =
222
+ (source) =>
223
+ (reading, happened = null) => {
224
+ if (running.get(source.key) !== source) return;
225
+ const said = happened
226
+ ? written(source, () =>
227
+ events.append({
228
+ source: source.spec.kind,
229
+ subject: source.subject,
230
+ ...happened,
231
+ })
232
+ )
233
+ : null;
234
+ const sight = written(source, () => noteSight(source, reading));
235
+ const kept = { ...reading, event: said?.seq ?? sight?.seq ?? null };
236
+ source.latest = kept;
237
+ for (const subscriber of [...source.subscribers]) {
238
+ try {
239
+ subscriber(kept);
240
+ } catch (error) {
241
+ log(`${source.subject}: ${error.message}`);
242
+ }
243
+ }
244
+ };
245
+
246
+ return {
247
+ subscribe(spec, onReading) {
248
+ const kind = kindOf(spec);
249
+ const key = keyOf(spec);
250
+ let source = running.get(key);
251
+ const subscriber = (reading) => onReading(reading);
252
+ if (!source) {
253
+ source = {
254
+ key,
255
+ spec,
256
+ subject: subjectOf(spec.kind, key),
257
+ does: kind.describe(spec),
258
+ subscribers: new Set([subscriber]),
259
+ latest: null,
260
+ blind: false,
261
+ handle: null,
262
+ };
263
+ running.set(key, source);
264
+ const name = source.subject;
265
+ try {
266
+ source.handle = kind.start(spec, {
267
+ report: reporter(source),
268
+ remembered: () => memory?.get(name) ?? null,
269
+ remember: (value) => memory?.set(name, value),
270
+ });
271
+ } catch (error) {
272
+ running.delete(key);
273
+ throw error;
274
+ }
275
+ } else {
276
+ source.subscribers.add(subscriber);
277
+ // One that joins a source already reading hears what it read last, as the others heard it.
278
+ const latest = source.latest;
279
+ const joined = source;
280
+ if (latest)
281
+ queueMicrotask(() => {
282
+ if (!joined.subscribers.has(subscriber)) return;
283
+ try {
284
+ subscriber(latest);
285
+ } catch (error) {
286
+ log(`${joined.subject}: ${error.message}`);
287
+ }
288
+ });
289
+ }
290
+ const followed = source;
291
+ return () => {
292
+ followed.subscribers.delete(subscriber);
293
+ if (followed.subscribers.size || running.get(key) !== followed) return;
294
+ running.delete(key);
295
+ followed.handle?.stop();
296
+ };
297
+ },
298
+ describe: (spec) => kindOf(spec).describe(spec),
299
+ now: (spec) => running.get(keyOf(spec))?.latest ?? null,
300
+ /** Stops every source (the daemon stopping). */
301
+ stop() {
302
+ for (const source of running.values()) source.handle?.stop();
303
+ running.clear();
304
+ },
305
+ };
306
+ }