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.
- package/README.md +21 -19
- package/assets/dsh-plugin.mjs +75 -4
- package/assets/herdr-mod/harness/main.js +367 -0
- package/assets/herdr-mod/harness/mod.json +6 -0
- package/assets/opencode-plugin.js +87 -22
- package/assets/pi-extension.ts +81 -2
- package/cli.mjs +544 -208
- package/lib/adapters.mjs +62 -27
- package/lib/agentBinaries.mjs +6 -8
- package/lib/agentClaims.mjs +168 -0
- package/lib/agentReadTools.json +415 -0
- package/lib/agentSignIn.mjs +17 -18
- package/lib/agentWiring.mjs +114 -0
- package/lib/archetypes.js +10 -11
- package/lib/attention.mjs +100 -0
- package/lib/audit.mjs +1 -1
- package/lib/backupSetup.mjs +6 -28
- package/lib/bankrApprovals.mjs +86 -0
- package/lib/boardAccess.mjs +40 -66
- package/lib/boardBackup.mjs +86 -85
- package/lib/boardCommands.mjs +28 -0
- package/lib/boardFileCommands.mjs +29 -36
- package/lib/boardFiles.mjs +83 -15
- package/lib/boardMirror.mjs +78 -11
- package/lib/boardProtocol.json +191 -123
- package/lib/boardThreads.mjs +19 -37
- package/lib/boardTools.mjs +22 -15
- package/lib/boardWatches.mjs +43 -15
- package/lib/bridge.mjs +7 -3
- package/lib/browserAgentTools.mjs +59 -0
- package/lib/browserWake.mjs +0 -6
- package/lib/cards.mjs +52 -0
- package/lib/circling.mjs +189 -0
- package/lib/cleanup.mjs +234 -0
- package/lib/cloudBoot.mjs +21 -4
- package/lib/cloudSave.mjs +46 -5
- package/lib/compaction.mjs +8 -1
- package/lib/completion.mjs +358 -0
- package/lib/computerDevices.mjs +853 -0
- package/lib/connectionStatus.mjs +34 -0
- package/lib/connectors.mjs +139 -1
- package/lib/coordinator.mjs +108 -14
- package/lib/coreModels.mjs +36 -12
- package/lib/daemon.mjs +2426 -338
- package/lib/daemonLock.mjs +103 -0
- package/lib/deviceDoor.mjs +308 -0
- package/lib/deviceIdentity.mjs +114 -0
- package/lib/deviceList.mjs +172 -0
- package/lib/deviceSeal.mjs +74 -0
- package/lib/dispatcher.mjs +497 -26
- package/lib/dispatches.mjs +3 -3
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +67 -41
- package/lib/events.mjs +318 -0
- package/lib/facts.mjs +170 -0
- package/lib/fileSource.mjs +540 -0
- package/lib/files.mjs +47 -2
- package/lib/gitHost.mjs +39 -1
- package/lib/goalCommands.mjs +12 -80
- package/lib/handover.mjs +21 -16
- package/lib/harnessOffers.mjs +140 -15
- package/lib/herdr.mjs +100 -15
- package/lib/herdrAppCall.mjs +19 -0
- package/lib/herdrCore.mjs +59 -0
- package/lib/herdrRuns.mjs +1126 -0
- package/lib/hookDialects.mjs +235 -50
- package/lib/identityLink.mjs +81 -0
- package/lib/inference.mjs +31 -2
- package/lib/jamAccess.mjs +82 -0
- package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
- package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
- package/lib/jamKey.mjs +274 -0
- package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
- package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
- package/lib/jamStore.mjs +973 -0
- package/lib/jamUpgrade.mjs +112 -0
- package/lib/jams.mjs +3079 -0
- package/lib/kanban.mjs +13 -7
- package/lib/landed.mjs +5 -1
- package/lib/library.mjs +41 -22
- package/lib/limits.mjs +91 -0
- package/lib/lineDiff.mjs +97 -0
- package/lib/lineup.mjs +18 -13
- package/lib/link.mjs +584 -0
- package/lib/localStack.mjs +75 -16
- package/lib/localmodels.mjs +58 -78
- package/lib/loopBackstop.mjs +2 -1
- package/lib/machine.mjs +544 -0
- package/lib/machineLink.mjs +446 -0
- package/lib/machineRoutes.mjs +68 -19
- package/lib/machineRuns.mjs +85 -4
- package/lib/machineSeal.mjs +6 -31
- package/lib/manager.mjs +134 -12
- package/lib/mcp-stdio.mjs +492 -215
- package/lib/mcpRelay.mjs +34 -35
- package/lib/members.json +1 -1
- package/lib/modelRoute.mjs +162 -0
- package/lib/nativeHost.mjs +81 -90
- package/lib/nativeSenses.mjs +258 -0
- package/lib/nerves.mjs +523 -0
- package/lib/network.mjs +117 -278
- package/lib/networkPlaces.mjs +578 -0
- package/lib/nextStep.mjs +95 -0
- package/lib/notify.mjs +2 -2
- package/lib/nudge.mjs +116 -10
- package/lib/originals.mjs +216 -0
- package/lib/outsideEvents.mjs +383 -0
- package/lib/outsideRuns.mjs +230 -0
- package/lib/ownMachines.mjs +674 -256
- package/lib/pain.mjs +215 -0
- package/lib/pairing.mjs +91 -11
- package/lib/paths.mjs +42 -3
- package/lib/peerProcess.mjs +21 -7
- package/lib/peopleLink.mjs +268 -0
- package/lib/personNotices.mjs +3 -2
- package/lib/phones.mjs +252 -542
- package/lib/placeCards.mjs +282 -0
- package/lib/placeChecks.mjs +95 -0
- package/lib/placeCommands.mjs +8 -17
- package/lib/placeRequests.mjs +152 -0
- package/lib/placeStore.mjs +295 -0
- package/lib/placeTool.d.ts +12 -0
- package/lib/placeTool.js +40 -0
- package/lib/places.mjs +63 -14
- package/lib/plans.mjs +53 -8
- package/lib/presence.mjs +270 -0
- package/lib/privateNetwork.d.ts +2 -0
- package/lib/privateNetwork.js +93 -0
- package/lib/proposals.mjs +300 -0
- package/lib/publicFetch.d.ts +32 -0
- package/lib/publicFetch.js +248 -0
- package/lib/reach.mjs +128 -0
- package/lib/rebuildable.mjs +72 -0
- package/lib/recall.mjs +216 -0
- package/lib/record.mjs +13 -0
- package/lib/reflexes.mjs +392 -0
- package/lib/relayLimits.mjs +31 -2
- package/lib/releaseNotice.mjs +198 -0
- package/lib/removeHarness.mjs +15 -4
- package/lib/repoLinks.mjs +204 -35
- package/lib/runAuthority.mjs +102 -39
- package/lib/runBrief.mjs +93 -40
- package/lib/runRequests.mjs +52 -14
- package/lib/runUsage.mjs +31 -0
- package/lib/runWorker.mjs +74 -25
- package/lib/runner.mjs +289 -45
- package/lib/runtime-install.mjs +37 -8
- package/lib/schedules.mjs +171 -47
- package/lib/screenWatches.mjs +221 -0
- package/lib/sealed.mjs +12 -30
- package/lib/sealedThreads.mjs +198 -392
- package/lib/secretStore.mjs +178 -0
- package/lib/secrets.mjs +11 -0
- package/lib/seen.mjs +3 -9
- package/lib/selfUpdate.mjs +51 -15
- package/lib/senseCall.mjs +1514 -0
- package/lib/senseHook.mjs +114 -0
- package/lib/senseTools.mjs +1298 -0
- package/lib/sessionBriefs.mjs +87 -0
- package/lib/sessionControl.mjs +63 -13
- package/lib/sessionFiles.mjs +85 -0
- package/lib/setupChoices.mjs +12 -3
- package/lib/setupMode.mjs +70 -25
- package/lib/sharedKeys.mjs +166 -0
- package/lib/sleep.mjs +396 -0
- package/lib/sources.mjs +306 -0
- package/lib/speech.mjs +166 -411
- package/lib/spoken.mjs +210 -0
- package/lib/steerHook.mjs +3 -1
- package/lib/steerQueue.mjs +40 -11
- package/lib/store.mjs +323 -130
- package/lib/stuck.mjs +85 -7
- package/lib/swarm.mjs +157 -49
- package/lib/swarmDevices.mjs +25 -85
- package/lib/swarmMemory.mjs +93 -9
- package/lib/t3.mjs +73 -3
- package/lib/taskCommands.mjs +51 -60
- package/lib/taskRooms.mjs +30 -4
- package/lib/taskRules.json +29 -0
- package/lib/taskRules.mjs +21 -0
- package/lib/taskRuns.mjs +74 -11
- package/lib/team.mjs +2 -1
- package/lib/threadActions.mjs +37 -9
- package/lib/threadAuthority.mjs +4 -4
- package/lib/threadBriefs.mjs +173 -43
- package/lib/threadNotes.mjs +320 -0
- package/lib/threadRecord.mjs +491 -0
- package/lib/threadRuns.mjs +216 -108
- package/lib/threadView.mjs +27 -30
- package/lib/threadWatches.mjs +1962 -0
- package/lib/timeSense.mjs +839 -0
- package/lib/tripwires.mjs +454 -0
- package/lib/ui.mjs +1 -1
- package/lib/vault.mjs +560 -45
- package/lib/vaultCommands.mjs +5 -3
- package/lib/vaultPeers.mjs +165 -0
- package/lib/vaultTools.d.ts +4 -1
- package/lib/vaultTools.js +22 -1
- package/lib/verdicts.mjs +12 -26
- package/lib/versions.mjs +117 -0
- package/lib/waitTool.mjs +278 -0
- package/lib/wakePicture.mjs +268 -0
- package/lib/wakeQueue.mjs +108 -0
- package/lib/watchResponses.mjs +533 -0
- package/lib/watches.mjs +290 -145
- package/lib/windowAsks.mjs +80 -17
- package/lib/worktrees.mjs +159 -9
- package/npm-shrinkwrap.json +138 -631
- package/package.json +7 -6
- package/release.json +211 -129
- package/lib/callSessions.mjs +0 -51
- package/lib/directLink.mjs +0 -349
- package/lib/peopleBoard.mjs +0 -131
- package/lib/projects.mjs +0 -2917
- package/lib/roomChannels.mjs +0 -667
package/lib/watches.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
1
|
import { randomUUID } from "node:crypto";
|
|
3
2
|
|
|
4
3
|
// Watches: something the person wants kept an eye on, read by a command on this computer on a schedule (a log, a status
|
|
@@ -121,165 +120,273 @@ export function offPattern(samples, { above = null, below = null } = {}) {
|
|
|
121
120
|
return null;
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
123
|
+
// The source a watch reads (sources.mjs): its command, run in its folder on its interval. Two watches on the same command
|
|
124
|
+
// share one run.
|
|
125
|
+
const sourceOf = (watch) => ({
|
|
126
|
+
kind: "command",
|
|
127
|
+
command: watch.command,
|
|
128
|
+
folder: watch.folder || null,
|
|
129
|
+
everySeconds: watch.everySeconds,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// A watch an agent's copy of the board brings a moment after home kept it: followed meanwhile, for at most this long.
|
|
133
|
+
const KEPT_GRACE_MS = 60_000;
|
|
134
|
+
// This computer's watches are looked at again this often, for a start or an end its copy brings from home.
|
|
135
|
+
const RECONCILE_MS = 10_000;
|
|
136
|
+
|
|
137
|
+
const parsed = (text, fallback) => {
|
|
138
|
+
try {
|
|
139
|
+
return JSON.parse(text) ?? fallback;
|
|
140
|
+
} catch {
|
|
141
|
+
return fallback;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** A row of the watch table (threadWatches.mjs) as this module and the buddy read a watch. */
|
|
146
|
+
const watchOf = (row) => {
|
|
147
|
+
const source = parsed(row.source, {});
|
|
148
|
+
const condition = parsed(row.condition, {});
|
|
149
|
+
return {
|
|
150
|
+
id: row.id,
|
|
151
|
+
name: parsed(row.detail, {}).name ?? "",
|
|
152
|
+
command: source.command,
|
|
153
|
+
folder: source.folder ?? null,
|
|
154
|
+
everySeconds: source.everySeconds,
|
|
155
|
+
measure: {
|
|
156
|
+
...(condition.measure ?? {}),
|
|
157
|
+
above: condition.above ?? null,
|
|
158
|
+
below: condition.below ?? null,
|
|
159
|
+
},
|
|
160
|
+
by: row.armed_by,
|
|
161
|
+
state: row.state === "held" ? "suggested" : row.state,
|
|
162
|
+
response: parsed(row.response, { do: "tell" }),
|
|
163
|
+
createdAt: row.created_at,
|
|
164
|
+
};
|
|
165
|
+
};
|
|
162
166
|
|
|
167
|
+
/**
|
|
168
|
+
* The person's watches: rows of kind "watch" in the watch table (threadWatches.mjs), kept on home and copied to every
|
|
169
|
+
* computer, each read on the computer it was set on. Each one on reads its command through a source (sources.mjs); what
|
|
170
|
+
* it says out loud (off, back) is a happening in the log (events.mjs), and the person is told through the response
|
|
171
|
+
* table (watchResponses.mjs). Its readings and alerts stay on the computer that reads it (meta `watch-samples:<id>`,
|
|
172
|
+
* `watch-off:<id>`, `watch-alerts`): the copy carries what a watch is, not every reading. `atHome(request)` takes a
|
|
173
|
+
* keep, a start or an end to home, where the table is written.
|
|
174
|
+
*/
|
|
163
175
|
export function createWatches({
|
|
164
176
|
store,
|
|
177
|
+
sources,
|
|
178
|
+
events,
|
|
179
|
+
machineId,
|
|
180
|
+
atHome,
|
|
181
|
+
responses = null,
|
|
165
182
|
notify = () => {},
|
|
166
183
|
log = () => {},
|
|
167
|
-
|
|
184
|
+
now = () => Date.now(),
|
|
168
185
|
}) {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
186
|
+
const db = store.db;
|
|
187
|
+
const rows = () =>
|
|
188
|
+
db.all(
|
|
189
|
+
"select * from board_watches where kind = 'watch' and machine = ? and state in ('on', 'held') order by created_at",
|
|
190
|
+
[machineId]
|
|
191
|
+
);
|
|
192
|
+
const rowOf = (id) =>
|
|
193
|
+
db.get(
|
|
194
|
+
"select * from board_watches where id = ? and kind = 'watch' and machine = ?",
|
|
195
|
+
[String(id), machineId]
|
|
196
|
+
);
|
|
197
|
+
const samplesOf = (id) => parsed(store.meta(`watch-samples:${id}`), []);
|
|
198
|
+
const offOf = (id) => parsed(store.meta(`watch-off:${id}`), null);
|
|
199
|
+
const setOff = (id, alert) =>
|
|
200
|
+
store.meta(`watch-off:${id}`, alert ? JSON.stringify(alert) : "");
|
|
201
|
+
// What each watch that is on follows: the function that stops following its source.
|
|
202
|
+
const following = new Map();
|
|
203
|
+
// Watches set here that home kept, until this computer's copy of the board brings them.
|
|
204
|
+
const keptHere = new Map();
|
|
205
|
+
let timer = null;
|
|
206
|
+
|
|
207
|
+
const tell = (watch, text, data, cause) =>
|
|
208
|
+
events.append({
|
|
209
|
+
source: "watch",
|
|
210
|
+
kind: "watch",
|
|
211
|
+
subject: watch.id,
|
|
212
|
+
text,
|
|
213
|
+
data,
|
|
214
|
+
cause,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// The person is told through the response table, which keeps the alert and tells them once.
|
|
218
|
+
const answer = (watch, edge, text, cause) => {
|
|
219
|
+
if (!responses) return notify(text);
|
|
220
|
+
responses.fire({
|
|
221
|
+
watch: { id: watch.id, thread: null, response: watch.response },
|
|
222
|
+
edge,
|
|
223
|
+
text,
|
|
224
|
+
cause,
|
|
225
|
+
});
|
|
183
226
|
};
|
|
184
|
-
const timers = new Map();
|
|
185
227
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const result = await run(watch);
|
|
228
|
+
// One reading of a watch's command: the number it holds is kept, and the watch is said out loud once when it goes
|
|
229
|
+
// off and once when it is back, not on every reading while it stays off.
|
|
230
|
+
const record = (watch, reading) => {
|
|
190
231
|
const value =
|
|
191
|
-
|
|
232
|
+
reading.output === null
|
|
233
|
+
? null
|
|
234
|
+
: readNumber(reading.output, watch.measure, reading.at);
|
|
192
235
|
const samples = [
|
|
193
|
-
...samplesOf(id),
|
|
236
|
+
...samplesOf(watch.id),
|
|
194
237
|
{
|
|
195
|
-
at:
|
|
238
|
+
at: reading.at,
|
|
196
239
|
value,
|
|
197
|
-
ms:
|
|
198
|
-
...(
|
|
199
|
-
? { error:
|
|
240
|
+
ms: reading.ms,
|
|
241
|
+
...(reading.error
|
|
242
|
+
? { error: reading.error.slice(0, 300) }
|
|
200
243
|
: value === null
|
|
201
244
|
? { error: "its output had no number to read" }
|
|
202
245
|
: {}),
|
|
203
246
|
},
|
|
204
247
|
].slice(-HISTORY);
|
|
205
|
-
store.meta(`watch-samples:${id}`, JSON.stringify(samples));
|
|
248
|
+
store.meta(`watch-samples:${watch.id}`, JSON.stringify(samples));
|
|
206
249
|
const off = offPattern(samples, watch.measure);
|
|
207
|
-
const
|
|
208
|
-
if (!
|
|
209
|
-
// Said once when it goes off and once when it is back; not on every check while it stays off.
|
|
210
|
-
if (off && !current.off) {
|
|
250
|
+
const wasOff = offOf(watch.id);
|
|
251
|
+
if (off && !wasOff) {
|
|
211
252
|
const alert = {
|
|
212
|
-
at: new Date().toISOString(),
|
|
213
|
-
text: `${
|
|
253
|
+
at: new Date(now()).toISOString(),
|
|
254
|
+
text: `${watch.name} ${off.text}.`,
|
|
214
255
|
kind: off.kind,
|
|
215
256
|
};
|
|
216
|
-
|
|
217
|
-
list().map((entry) =>
|
|
218
|
-
entry.id === id ? { ...entry, off: alert } : entry
|
|
219
|
-
)
|
|
220
|
-
);
|
|
257
|
+
setOff(watch.id, alert);
|
|
221
258
|
store.meta(
|
|
222
259
|
"watch-alerts",
|
|
223
260
|
JSON.stringify(
|
|
224
261
|
[
|
|
225
|
-
...
|
|
226
|
-
{ watch: id, ...alert },
|
|
262
|
+
...parsed(store.meta("watch-alerts"), []),
|
|
263
|
+
{ watch: watch.id, ...alert },
|
|
227
264
|
].slice(-200)
|
|
228
265
|
)
|
|
229
266
|
);
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
entry.id === id ? { ...entry, off: null } : entry
|
|
236
|
-
)
|
|
267
|
+
const told = tell(
|
|
268
|
+
watch,
|
|
269
|
+
alert.text,
|
|
270
|
+
{ state: "off", kind: off.kind, value },
|
|
271
|
+
reading.event
|
|
237
272
|
);
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
273
|
+
answer(watch, "tripped", alert.text, told?.seq ?? reading.event ?? null);
|
|
274
|
+
log(`watch ${watch.name}: ${off.text}`);
|
|
275
|
+
} else if (!off && wasOff) {
|
|
276
|
+
setOff(watch.id, null);
|
|
277
|
+
const text = `${watch.name} is back to normal.`;
|
|
278
|
+
const told = tell(watch, text, { state: "back", value }, reading.event);
|
|
279
|
+
answer(watch, "cleared", text, told?.seq ?? reading.event ?? null);
|
|
242
280
|
}
|
|
243
|
-
return { value, off, ms: result.ms };
|
|
244
281
|
};
|
|
245
282
|
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
283
|
+
const follow = (watch) => {
|
|
284
|
+
if (following.has(watch.id)) return;
|
|
285
|
+
following.set(
|
|
286
|
+
watch.id,
|
|
287
|
+
sources.subscribe(sourceOf(watch), (reading) => {
|
|
288
|
+
try {
|
|
289
|
+
// Read as it stands now: a watch ended a moment ago says nothing more.
|
|
290
|
+
const row = rowOf(watch.id);
|
|
291
|
+
if (row && row.state !== "on") return;
|
|
292
|
+
record(row ? watchOf(row) : watch, reading);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
log(`watch ${watch.name}: ${error.message}`);
|
|
295
|
+
}
|
|
296
|
+
})
|
|
297
|
+
);
|
|
298
|
+
};
|
|
299
|
+
const unfollow = (id) => {
|
|
300
|
+
following.get(id)?.();
|
|
301
|
+
following.delete(id);
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/** Follows this computer's watches that are on, as the table says, and stops following the rest. */
|
|
305
|
+
const reconcile = () => {
|
|
306
|
+
let on;
|
|
307
|
+
try {
|
|
308
|
+
on = rows()
|
|
309
|
+
.filter((row) => row.state === "on")
|
|
310
|
+
.map(watchOf);
|
|
311
|
+
} catch {
|
|
250
312
|
return;
|
|
251
313
|
}
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
watch.id,
|
|
259
|
-
setTimeout(tick, watch.everySeconds * 1000).unref?.() ?? null
|
|
260
|
-
);
|
|
261
|
-
});
|
|
262
|
-
};
|
|
263
|
-
timers.set(watch.id, setTimeout(tick, 0));
|
|
314
|
+
const wanted = new Set(on.map((watch) => watch.id));
|
|
315
|
+
for (const [id, at] of keptHere)
|
|
316
|
+
if (wanted.has(id) || now() - at > KEPT_GRACE_MS) keptHere.delete(id);
|
|
317
|
+
else wanted.add(id);
|
|
318
|
+
for (const id of [...following.keys()]) if (!wanted.has(id)) unfollow(id);
|
|
319
|
+
for (const watch of on) follow(watch);
|
|
264
320
|
};
|
|
265
321
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
322
|
+
const listed = (watch) => ({
|
|
323
|
+
...watch,
|
|
324
|
+
off: offOf(watch.id),
|
|
325
|
+
samples: samplesOf(watch.id).slice(-20),
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Today's watches, kept in this computer's meta before they were rows: each moves in once, with its id, so its
|
|
329
|
+
// readings and alerts go on as they were. The meta is left as it was.
|
|
330
|
+
const moveIn = async () => {
|
|
331
|
+
if (store.meta("watches-moved") === "1") return;
|
|
332
|
+
const before = parsed(store.meta("watches"), []);
|
|
333
|
+
let all = true;
|
|
334
|
+
for (const watch of before) {
|
|
335
|
+
if (db.get("select id from board_watches where id = ?", [watch.id]))
|
|
336
|
+
continue;
|
|
337
|
+
const kept = await keepRow(
|
|
338
|
+
rowFor({ ...watch, state: watch.state === "on" ? "on" : "held" }),
|
|
339
|
+
watch.by || "user"
|
|
340
|
+
);
|
|
341
|
+
if (!kept.ok) {
|
|
342
|
+
all = false;
|
|
343
|
+
log(`watch ${watch.name}: not moved yet: ${kept.error}`);
|
|
344
|
+
continue;
|
|
279
345
|
}
|
|
346
|
+
if (watch.off) setOff(watch.id, watch.off);
|
|
347
|
+
}
|
|
348
|
+
if (all) store.meta("watches-moved", "1");
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
const rowFor = (watch) => ({
|
|
352
|
+
id: watch.id,
|
|
353
|
+
thread: null,
|
|
354
|
+
answers: "user",
|
|
355
|
+
source: sourceOf(watch),
|
|
356
|
+
condition: {
|
|
357
|
+
when: "off",
|
|
358
|
+
measure: Object.fromEntries(
|
|
359
|
+
["field", "count", "age"]
|
|
360
|
+
.filter((name) => watch.measure?.[name])
|
|
361
|
+
.map((name) => [name, watch.measure[name]])
|
|
362
|
+
),
|
|
363
|
+
above: watch.measure?.above ?? null,
|
|
364
|
+
below: watch.measure?.below ?? null,
|
|
280
365
|
},
|
|
366
|
+
kind: "watch",
|
|
367
|
+
response: { do: "tell" },
|
|
368
|
+
detail: { name: watch.name },
|
|
369
|
+
state: watch.state,
|
|
370
|
+
why: watch.state === "held" ? "an agent suggested it" : null,
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const keepRow = async (row, by) => {
|
|
374
|
+
const kept = await atHome({
|
|
375
|
+
command: "board.watch.keep",
|
|
376
|
+
agent: by,
|
|
377
|
+
watch: row,
|
|
378
|
+
});
|
|
379
|
+
return kept?.ok ? kept : { ok: false, error: kept?.error ?? "not kept" };
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
return {
|
|
383
|
+
list: () => rows().map((row) => listed(watchOf(row))),
|
|
384
|
+
alerts: (since = "") =>
|
|
385
|
+
parsed(store.meta("watch-alerts"), []).filter(
|
|
386
|
+
(alert) => alert.at > since
|
|
387
|
+
),
|
|
281
388
|
/** A new watch: the person's starts at once; an agent's waits for the person's start. */
|
|
282
|
-
add({
|
|
389
|
+
async add({
|
|
283
390
|
name,
|
|
284
391
|
command,
|
|
285
392
|
folder = null,
|
|
@@ -325,38 +432,76 @@ export function createWatches({
|
|
|
325
432
|
everySeconds: every,
|
|
326
433
|
measure: clean,
|
|
327
434
|
by,
|
|
328
|
-
state: by === "user" ? "on" : "
|
|
329
|
-
|
|
330
|
-
|
|
435
|
+
state: by === "user" ? "on" : "held",
|
|
436
|
+
response: { do: "tell" },
|
|
437
|
+
};
|
|
438
|
+
const kept = await keepRow(rowFor(watch), by);
|
|
439
|
+
if (!kept.ok) return kept;
|
|
440
|
+
if (watch.state === "on") {
|
|
441
|
+
keptHere.set(watch.id, now());
|
|
442
|
+
follow(watch);
|
|
443
|
+
}
|
|
444
|
+
return {
|
|
445
|
+
ok: true,
|
|
446
|
+
watch: listed({
|
|
447
|
+
...watch,
|
|
448
|
+
state: watch.state === "held" ? "suggested" : "on",
|
|
449
|
+
createdAt: kept.watch?.createdAt ?? null,
|
|
450
|
+
}),
|
|
331
451
|
};
|
|
332
|
-
save([...list(), watch]);
|
|
333
|
-
if (watch.state === "on") schedule(watch);
|
|
334
|
-
return { ok: true, watch };
|
|
335
452
|
},
|
|
336
|
-
start(id) {
|
|
337
|
-
const
|
|
338
|
-
if (!
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
453
|
+
async start(id) {
|
|
454
|
+
const row = rowOf(id);
|
|
455
|
+
if (!row || !["on", "held"].includes(row.state))
|
|
456
|
+
return { ok: false, error: "no such watch" };
|
|
457
|
+
if (row.state === "held") {
|
|
458
|
+
const went = await atHome({
|
|
459
|
+
command: "board.watch.go",
|
|
460
|
+
agent: "user",
|
|
461
|
+
id: row.id,
|
|
462
|
+
});
|
|
463
|
+
if (!went?.ok)
|
|
464
|
+
return { ok: false, error: went?.error ?? "not started" };
|
|
465
|
+
}
|
|
466
|
+
const on = { ...watchOf(row), state: "on" };
|
|
467
|
+
keptHere.set(on.id, now());
|
|
468
|
+
follow(on);
|
|
469
|
+
return { ok: true, watch: listed(on) };
|
|
343
470
|
},
|
|
344
|
-
remove(id) {
|
|
345
|
-
|
|
471
|
+
async remove(id) {
|
|
472
|
+
const row = rowOf(id);
|
|
473
|
+
if (!row || !["on", "held"].includes(row.state))
|
|
346
474
|
return { ok: false, error: "no such watch" };
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
475
|
+
const ended = await atHome({
|
|
476
|
+
command: "board.watch.drop",
|
|
477
|
+
agent: "user",
|
|
478
|
+
id: row.id,
|
|
479
|
+
});
|
|
480
|
+
if (!ended?.ok)
|
|
481
|
+
return { ok: false, error: ended?.error ?? "not removed" };
|
|
482
|
+
keptHere.delete(row.id);
|
|
483
|
+
unfollow(row.id);
|
|
484
|
+
store.meta(`watch-samples:${row.id}`, "[]");
|
|
485
|
+
setOff(row.id, null);
|
|
351
486
|
return { ok: true };
|
|
352
487
|
},
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
488
|
+
reconcile,
|
|
489
|
+
/** Moves today's watches in, then follows this computer's own and looks again for what its copy brings. */
|
|
490
|
+
async resume() {
|
|
491
|
+
await moveIn().catch((error) => log(`watches: ${error.message}`));
|
|
492
|
+
reconcile();
|
|
493
|
+
clearInterval(timer);
|
|
494
|
+
timer = setInterval(() => {
|
|
495
|
+
reconcile();
|
|
496
|
+
if (store.meta("watches-moved") !== "1")
|
|
497
|
+
void moveIn().catch((error) => log(`watches: ${error.message}`));
|
|
498
|
+
}, RECONCILE_MS);
|
|
499
|
+
timer.unref?.();
|
|
356
500
|
},
|
|
357
501
|
stop() {
|
|
358
|
-
|
|
359
|
-
|
|
502
|
+
clearInterval(timer);
|
|
503
|
+
for (const stopFollowing of following.values()) stopFollowing();
|
|
504
|
+
following.clear();
|
|
360
505
|
},
|
|
361
506
|
};
|
|
362
507
|
}
|
package/lib/windowAsks.mjs
CHANGED
|
@@ -1,49 +1,112 @@
|
|
|
1
|
+
import { BROWSER_AGENT_DEADLINES } from "./browserAgentTools.mjs";
|
|
2
|
+
|
|
1
3
|
// This computer asking the person's own Harness window for what only it holds (phones.mjs ask): this computer's own
|
|
2
|
-
// windows first, then those
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// the
|
|
4
|
+
// windows first, then those on the person's other computers, each asked by its own computer over their link
|
|
5
|
+
// (ownMachines.mjs askOtherWindows). A question may name one browser (`device`, by id or name, with the computer it was
|
|
6
|
+
// last known on), and bring its own deadline (`timeoutMs`, a door call's). With no Harness window
|
|
7
|
+
// open, the browser is woken: through the extension when it listens for this computer (browserWake.mjs, its native
|
|
8
|
+
// host brings up its hidden Harness page, out of sight), and otherwise by this computer opening Harness in the default
|
|
9
|
+
// browser (owner, November 12: "the extension is not load bearing in any sense at all since it is inherently opt in").
|
|
10
|
+
// Only an agent's own ask opens a window; a background read (the dream's, seen.mjs) never puts a browser in front of
|
|
11
|
+
// the person. The window is asked again as it comes up, until WAKE_DEADLINE_MS.
|
|
6
12
|
|
|
7
13
|
// How long to keep asking a woken hidden page: one minute, a chosen value. Measured only against a local app on
|
|
8
14
|
// loopback (an end-to-end test: closed page to answer 1.04 to 1.08 s, 5 samples on an M5 Pro), never against
|
|
9
15
|
// tryharness.ai.
|
|
10
16
|
export const WAKE_DEADLINE_MS = 60_000;
|
|
11
|
-
//
|
|
12
|
-
|
|
17
|
+
// The bytes of a document Harness generated in a browser (/api/mcp/file for an outside agent).
|
|
18
|
+
export const FILE_BYTES_TOOL = "get_generated_file_bytes";
|
|
19
|
+
// The reads an agent on one of the person's computers makes of a browser through that computer (deviceDoor.mjs): the
|
|
20
|
+
// same list as src/shared/doorTools.ts DEVICE_READ_TOOLS, which an outside agent makes through Harness.
|
|
21
|
+
export const AGENT_READ_TOOLS = new Set([
|
|
22
|
+
"search_screen_semantic",
|
|
23
|
+
"search_screen_visual",
|
|
24
|
+
"search_screen_text",
|
|
25
|
+
"recall_at_time",
|
|
26
|
+
"get_frames",
|
|
27
|
+
"get_transcript",
|
|
28
|
+
"query_screen_history",
|
|
29
|
+
"read_conversation",
|
|
30
|
+
"search_conversations",
|
|
31
|
+
"recall_memories",
|
|
32
|
+
"list_generated_media",
|
|
33
|
+
"get_generated_image",
|
|
34
|
+
]);
|
|
35
|
+
// What one of the person's computers may ask the windows on another (ownMachines.mjs): the person's screen history, as
|
|
36
|
+
// its agents' tools ask it (boardTools.mjs search_screen, seen.mjs, deviceDoor.mjs), and a door call Harness's server
|
|
37
|
+
// handed home for a browser (`door`, deviceDoor.mjs). A computer refuses any other tool another names (security audit
|
|
13
38
|
// 2026-10-25, M6).
|
|
14
39
|
export const WINDOW_TOOLS = new Set([
|
|
15
40
|
"search_screen_text",
|
|
16
41
|
"search_screen_semantic",
|
|
17
42
|
"screen_seen_since",
|
|
43
|
+
...AGENT_READ_TOOLS,
|
|
44
|
+
// A document Harness made in a browser, downloaded by an agent here (mcpRelay.mjs download, deviceDoor.mjs).
|
|
45
|
+
FILE_BYTES_TOOL,
|
|
46
|
+
// An agent's page read or page task on a browser this computer runs (browserAgentTools.mjs).
|
|
47
|
+
...Object.keys(BROWSER_AGENT_DEADLINES),
|
|
18
48
|
]);
|
|
49
|
+
/** Whether another of the person's computers may ask this one's windows `call`. */
|
|
50
|
+
export const mayAskWindows = (call) =>
|
|
51
|
+
WINDOW_TOOLS.has(call?.tool) ||
|
|
52
|
+
(typeof call?.door?.op === "string" && call.door.caller != null);
|
|
19
53
|
const ASK_EVERY_MS = 1_000;
|
|
20
54
|
|
|
21
55
|
export function createWindowAsks({
|
|
22
56
|
askOwn,
|
|
57
|
+
// The person's other computers' windows, each asked by its own computer (ownMachines.mjs askOtherWindows).
|
|
23
58
|
askWorkers = async () => null,
|
|
24
59
|
browserWake,
|
|
60
|
+
// Opens Harness in this computer's default browser (openHere.mjs); null where nothing can be opened.
|
|
61
|
+
openHarness = null,
|
|
25
62
|
log = () => {},
|
|
26
63
|
now = () => Date.now(),
|
|
27
64
|
wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
28
65
|
}) {
|
|
29
66
|
const nobodyAt = (reply) =>
|
|
30
67
|
reply?.ok === false && ["unpaired", "closed"].includes(reply.code);
|
|
31
|
-
const askAnywhere = async (call) => {
|
|
32
|
-
const here = await askOwn(call);
|
|
33
|
-
return (nobodyAt(here) && (await askWorkers(call))) || here;
|
|
68
|
+
const askAnywhere = async (call, route) => {
|
|
69
|
+
const here = await askOwn(call, route);
|
|
70
|
+
return (nobodyAt(here) && (await askWorkers(call, route))) || here;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// One opened window is waited for, not opened again for every ask that comes meanwhile.
|
|
74
|
+
let openedAt = -Infinity;
|
|
75
|
+
const wake = (call, background) => {
|
|
76
|
+
if (browserWake?.listening()) {
|
|
77
|
+
browserWake.send({ kind: "window" });
|
|
78
|
+
log(`windows: none open, woke the browser for ${call.tool}`);
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (!openHarness || background) return false;
|
|
82
|
+
if (now() - openedAt >= WAKE_DEADLINE_MS) {
|
|
83
|
+
openedAt = now();
|
|
84
|
+
openHarness();
|
|
85
|
+
log(`windows: none open, opened Harness in the browser for ${call.tool}`);
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
34
88
|
};
|
|
35
89
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
90
|
+
/**
|
|
91
|
+
* The window's answer to `call`, waking a browser when no window is open. A question for one named browser wakes
|
|
92
|
+
* nothing: the browser woken here may not be the one named.
|
|
93
|
+
*/
|
|
94
|
+
return async function ask({
|
|
95
|
+
background = false,
|
|
96
|
+
device = null,
|
|
97
|
+
computer = null,
|
|
98
|
+
timeoutMs = undefined,
|
|
99
|
+
...call
|
|
100
|
+
}) {
|
|
101
|
+
const route = { device, computer, timeoutMs };
|
|
102
|
+
const first = await askAnywhere(call, route);
|
|
103
|
+
if (first?.code !== "closed" || device || !wake(call, background))
|
|
104
|
+
return first;
|
|
105
|
+
const until = now() + Math.min(WAKE_DEADLINE_MS, timeoutMs ?? Infinity);
|
|
43
106
|
let reply = first;
|
|
44
107
|
while (reply?.code === "closed" && now() < until) {
|
|
45
108
|
await wait(ASK_EVERY_MS);
|
|
46
|
-
reply = await askAnywhere(call);
|
|
109
|
+
reply = await askAnywhere(call, route);
|
|
47
110
|
}
|
|
48
111
|
return reply;
|
|
49
112
|
};
|