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/daemon.mjs
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
+
import { readConfig, updateConfig } from "./secretStore.mjs";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { createBridge } from "./bridge.mjs";
|
|
7
|
+
import { createComputerDevices } from "./computerDevices.mjs";
|
|
6
8
|
import { createMcpRelay } from "./mcpRelay.mjs";
|
|
9
|
+
import { createDeviceDoor } from "./deviceDoor.mjs";
|
|
10
|
+
import { createAgentWiring } from "./agentWiring.mjs";
|
|
7
11
|
import { createThreadRuns } from "./threadRuns.mjs";
|
|
8
12
|
import { detectAgents } from "./commands.mjs";
|
|
9
13
|
import { appendLog, ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
|
|
10
14
|
import { historyRoots, paths } from "./paths.mjs";
|
|
11
15
|
import { openStore } from "./store.mjs";
|
|
12
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
runningPids,
|
|
18
|
+
runningProcesses,
|
|
19
|
+
stopAgentTask,
|
|
20
|
+
stopAllRuns,
|
|
21
|
+
stopLeftRuns,
|
|
22
|
+
} from "./runner.mjs";
|
|
13
23
|
import { createSwarm } from "./swarm.mjs";
|
|
14
24
|
import { createSpecialtyNotice } from "./specialtyNotice.mjs";
|
|
15
25
|
import { specialtiesOf } from "./specialties.mjs";
|
|
@@ -42,6 +52,7 @@ import { openHere } from "./openHere.mjs";
|
|
|
42
52
|
import { createFolders, repositoryName } from "./folders.mjs";
|
|
43
53
|
import { createRepoLinks } from "./repoLinks.mjs";
|
|
44
54
|
import { notifyDesktop } from "./notify.mjs";
|
|
55
|
+
import { UPGRADE_NOTICE, createJamUpgrade } from "./jamUpgrade.mjs";
|
|
45
56
|
import { provenanceFor } from "./provenance.mjs";
|
|
46
57
|
import { createGoals } from "./goals.mjs";
|
|
47
58
|
import { createTeam } from "./team.mjs";
|
|
@@ -84,9 +95,12 @@ import {
|
|
|
84
95
|
} from "./models.mjs";
|
|
85
96
|
import { forgetT3, startT3SignIn, t3Access, t3Installed } from "./t3.mjs";
|
|
86
97
|
import { createNetwork } from "./network.mjs";
|
|
87
|
-
import {
|
|
98
|
+
import { createJamStore } from "./jamStore.mjs";
|
|
99
|
+
import { loadDeviceIdentity } from "./deviceIdentity.mjs";
|
|
100
|
+
import { createJams } from "./jams.mjs";
|
|
88
101
|
import { createVerdicts } from "./verdicts.mjs";
|
|
89
102
|
import { createPlaceCommands } from "./placeCommands.mjs";
|
|
103
|
+
import { createNetworkPlaces } from "./networkPlaces.mjs";
|
|
90
104
|
import { createSessionControl } from "./sessionControl.mjs";
|
|
91
105
|
import { createSessionIndex } from "./sessionIndex.mjs";
|
|
92
106
|
import { createBoardAccess } from "./boardAccess.mjs";
|
|
@@ -94,7 +108,11 @@ import {
|
|
|
94
108
|
BOARD_PROTOCOL_VERSION as PROTOCOL_VERSION,
|
|
95
109
|
HARNESS_INBOX_VERSION,
|
|
96
110
|
} from "./boardProtocol.mjs";
|
|
97
|
-
import {
|
|
111
|
+
import {
|
|
112
|
+
checkedAsText,
|
|
113
|
+
createBoardFiles,
|
|
114
|
+
MAX_FILE_BYTES,
|
|
115
|
+
} from "./boardFiles.mjs";
|
|
98
116
|
import { relayRefusal } from "./relayLimits.mjs";
|
|
99
117
|
import { createGoalCommands } from "./goalCommands.mjs";
|
|
100
118
|
import { createTaskCommands } from "./taskCommands.mjs";
|
|
@@ -102,17 +120,63 @@ import { createTaskRuns } from "./taskRuns.mjs";
|
|
|
102
120
|
import { createRunRequests } from "./runRequests.mjs";
|
|
103
121
|
import { createRunWorker, restrictedRun } from "./runWorker.mjs";
|
|
104
122
|
import { createVault } from "./vault.mjs";
|
|
123
|
+
import { createVaultPeers } from "./vaultPeers.mjs";
|
|
105
124
|
import { createRunBriefs } from "./runBrief.mjs";
|
|
106
125
|
import { createHandover } from "./handover.mjs";
|
|
107
126
|
import { createCompaction } from "./compaction.mjs";
|
|
108
127
|
import { oneLine } from "./oneLine.mjs";
|
|
109
128
|
import {
|
|
129
|
+
callerRun,
|
|
110
130
|
createRunAuthority,
|
|
111
131
|
HOSTED_CALLER,
|
|
132
|
+
MAX_HANDOFFS,
|
|
112
133
|
RUN_CALLER,
|
|
113
134
|
} from "./runAuthority.mjs";
|
|
135
|
+
import { createEvents } from "./events.mjs";
|
|
136
|
+
import { createSources, subjectFor } from "./sources.mjs";
|
|
137
|
+
import { createFactKind, createFacts } from "./facts.mjs";
|
|
138
|
+
import { connectNativeSenses } from "./nativeSenses.mjs";
|
|
139
|
+
import { createFileKind } from "./fileSource.mjs";
|
|
140
|
+
import {
|
|
141
|
+
createCheckKind,
|
|
142
|
+
createCompletion,
|
|
143
|
+
createProcessKind,
|
|
144
|
+
} from "./completion.mjs";
|
|
145
|
+
import { createLimits } from "./limits.mjs";
|
|
146
|
+
import {
|
|
147
|
+
createThreadWatches,
|
|
148
|
+
processOwnedBy,
|
|
149
|
+
WATCH_KEEPER,
|
|
150
|
+
} from "./threadWatches.mjs";
|
|
151
|
+
import { createWatchResponses } from "./watchResponses.mjs";
|
|
152
|
+
import { createCircling } from "./circling.mjs";
|
|
153
|
+
import { createTripwires } from "./tripwires.mjs";
|
|
154
|
+
import { createPain } from "./pain.mjs";
|
|
155
|
+
import { createReflexes } from "./reflexes.mjs";
|
|
156
|
+
import { createRecall } from "./recall.mjs";
|
|
157
|
+
import { createSenseTools } from "./senseTools.mjs";
|
|
158
|
+
import { createModelRoute } from "./modelRoute.mjs";
|
|
159
|
+
import { putMark, sessionOfPid } from "./senseCall.mjs";
|
|
160
|
+
import { PARENT, SENSE, putSteer, takeSteers } from "./steerQueue.mjs";
|
|
161
|
+
import { HOOK_AGENTS, hookDialect } from "./hookDialects.mjs";
|
|
162
|
+
import { createCleanup } from "./cleanup.mjs";
|
|
163
|
+
import {
|
|
164
|
+
createDiskKind,
|
|
165
|
+
createMachine,
|
|
166
|
+
createMachineKind,
|
|
167
|
+
} from "./machine.mjs";
|
|
168
|
+
import {
|
|
169
|
+
createPersonKind,
|
|
170
|
+
createPresence,
|
|
171
|
+
createRepositoryKind,
|
|
172
|
+
} from "./presence.mjs";
|
|
114
173
|
import { createActorRoster } from "./actorRoster.mjs";
|
|
115
|
-
import {
|
|
174
|
+
import {
|
|
175
|
+
agentsHere,
|
|
176
|
+
createLineup,
|
|
177
|
+
createLineupCommands,
|
|
178
|
+
signedIn,
|
|
179
|
+
} from "./lineup.mjs";
|
|
116
180
|
import { untilSignedIn } from "./setupMode.mjs";
|
|
117
181
|
import { createSetupChoices } from "./setupChoices.mjs";
|
|
118
182
|
import { checkTools, TOOL_CHECK_DEADLINE_MS } from "./toolCheck.mjs";
|
|
@@ -136,7 +200,7 @@ import { createProxyLinks } from "./proxyLinks.mjs";
|
|
|
136
200
|
import { createCloudSsh } from "./cloudSsh.mjs";
|
|
137
201
|
import { loadMachine, saveMachine } from "./machineIdentity.mjs";
|
|
138
202
|
import { createOwnMachines, FROM_MACHINE } from "./ownMachines.mjs";
|
|
139
|
-
import { startUpdate } from "./selfUpdate.mjs";
|
|
203
|
+
import { startUpdate, updateState } from "./selfUpdate.mjs";
|
|
140
204
|
import { createBoardBackup } from "./boardBackup.mjs";
|
|
141
205
|
import { createMachineRuns } from "./machineRuns.mjs";
|
|
142
206
|
import { createPlans } from "./plans.mjs";
|
|
@@ -153,22 +217,35 @@ import {
|
|
|
153
217
|
MERGE_COMMAND,
|
|
154
218
|
MIRROR_COMMAND,
|
|
155
219
|
} from "./boardMirror.mjs";
|
|
156
|
-
import {
|
|
157
|
-
import {
|
|
220
|
+
import { createMachineLink } from "./machineLink.mjs";
|
|
221
|
+
import { createPeopleLink } from "./peopleLink.mjs";
|
|
222
|
+
import { connectorCaller, readsFromCopy } from "./machineRoutes.mjs";
|
|
158
223
|
import { createConnectors } from "./connectors.mjs";
|
|
159
224
|
import { createBrowserWake } from "./browserWake.mjs";
|
|
160
225
|
import { createBrowserPage } from "./browserPage.mjs";
|
|
161
226
|
import { createWindowAsks } from "./windowAsks.mjs";
|
|
227
|
+
import { createConnection } from "./connectionStatus.mjs";
|
|
162
228
|
import { createSeen } from "./seen.mjs";
|
|
163
229
|
import { createAuditor } from "./audit.mjs";
|
|
164
230
|
import { createDesk } from "./desk.mjs";
|
|
165
231
|
import { onchainExecutors } from "./book.mjs";
|
|
166
232
|
import { CALLER_GONE, daemonAnswers, listenControl } from "./controlSocket.mjs";
|
|
233
|
+
import { takeDaemonLock } from "./daemonLock.mjs";
|
|
167
234
|
import { createHarnessOffers } from "./harnessOffers.mjs";
|
|
235
|
+
import { createIceServers, createLink } from "./link.mjs";
|
|
236
|
+
import { createBankrApprovals } from "./bankrApprovals.mjs";
|
|
168
237
|
import { createJobAnswers } from "./jobAnswers.mjs";
|
|
169
238
|
import { createLocalStack } from "./localStack.mjs";
|
|
170
239
|
import { createPersonNotices } from "./personNotices.mjs";
|
|
171
|
-
import {
|
|
240
|
+
import { createReleaseNotice } from "./releaseNotice.mjs";
|
|
241
|
+
import {
|
|
242
|
+
OPENED,
|
|
243
|
+
createSealedThreads,
|
|
244
|
+
handleOf,
|
|
245
|
+
relayPublicKey,
|
|
246
|
+
} from "./sealedThreads.mjs";
|
|
247
|
+
import { followIdentityLinks } from "./identityLink.mjs";
|
|
248
|
+
import { createAgentClaims, aboutOf as claimAbout } from "./agentClaims.mjs";
|
|
172
249
|
import {
|
|
173
250
|
DEFAULT_MAX_POSTS,
|
|
174
251
|
DEFAULT_MAX_WAKES,
|
|
@@ -178,8 +255,29 @@ import { createThreadActions, inRoom, mentionsIn } from "./threadActions.mjs";
|
|
|
178
255
|
import { createThreadAuthority } from "./threadAuthority.mjs";
|
|
179
256
|
import { createDispatches } from "./dispatches.mjs";
|
|
180
257
|
import { createCapabilityCheck } from "./capabilityCheck.mjs";
|
|
181
|
-
import { createDispatcher } from "./dispatcher.mjs";
|
|
258
|
+
import { createDispatcher, mayDownloadModel } from "./dispatcher.mjs";
|
|
259
|
+
import { createSpoken } from "./spoken.mjs";
|
|
182
260
|
import { createThreadBriefs } from "./threadBriefs.mjs";
|
|
261
|
+
import { createWakePicture } from "./wakePicture.mjs";
|
|
262
|
+
import { createTimeSense, TOO_LONG_TIMES } from "./timeSense.mjs";
|
|
263
|
+
import { createOutsideEvents } from "./outsideEvents.mjs";
|
|
264
|
+
import { createSleep } from "./sleep.mjs";
|
|
265
|
+
import { createThreadNotes } from "./threadNotes.mjs";
|
|
266
|
+
import { createProposals } from "./proposals.mjs";
|
|
267
|
+
import { createAttention } from "./attention.mjs";
|
|
268
|
+
import { agentSpecialties, swarmCards } from "./cards.mjs";
|
|
269
|
+
import { createReachKind } from "./reach.mjs";
|
|
270
|
+
import { createOutsideRuns } from "./outsideRuns.mjs";
|
|
271
|
+
import { createScreenWatches, FROM_BROWSER } from "./screenWatches.mjs";
|
|
272
|
+
import { createNerves } from "./nerves.mjs";
|
|
273
|
+
import { createOriginals } from "./originals.mjs";
|
|
274
|
+
import { createThreadRecord } from "./threadRecord.mjs";
|
|
275
|
+
import { createNextSteps } from "./nextStep.mjs";
|
|
276
|
+
|
|
277
|
+
const MODELS_ASK_EVERY_MS = 10 * 60_000;
|
|
278
|
+
// How often the channels with other people are looked at again (threads opened or ended meanwhile); a message for
|
|
279
|
+
// someone with no channel yet looks at once (peopleLink.mjs carry).
|
|
280
|
+
const PEOPLE_LINK_SYNC_MS = 30_000;
|
|
183
281
|
|
|
184
282
|
// claude-mem 13.35.0, scratch worker with 3,000 observations, on the same machine: the whole lookup (git calls,
|
|
185
283
|
// /api/projects, newest-50 search) took p50 29 ms / max 54 ms over 100 idle runs and p50 36 ms / max 59 ms over 100
|
|
@@ -233,14 +331,30 @@ function stuckThresholds() {
|
|
|
233
331
|
return Object.values(given).every((ms) => ms > 0) ? given : STUCK_THRESHOLDS;
|
|
234
332
|
}
|
|
235
333
|
|
|
334
|
+
// Which socket file is at a path (its device and inode), or null: one made again at the same path is another.
|
|
335
|
+
const socketIdentity = (file) => {
|
|
336
|
+
const stat = fs.statSync(file, { throwIfNoEntry: false });
|
|
337
|
+
return stat ? `${stat.dev}:${stat.ino}` : null;
|
|
338
|
+
};
|
|
339
|
+
|
|
236
340
|
export async function startDaemon() {
|
|
237
341
|
ensureDir(paths.home);
|
|
342
|
+
// The key this computer had on HyperDHT, which the link replaced (docs/one-link-plan.md L8.1): nothing reads it now.
|
|
343
|
+
fs.rmSync(path.join(paths.home, "direct-identity.json"), { force: true });
|
|
238
344
|
// One daemon per computer. While setup's daemon hands over to the app's background item, the item's own one starts
|
|
239
|
-
// and finds the other
|
|
345
|
+
// and finds the other holding the lock: it leaves, and launchd starts it again once the other has gone.
|
|
346
|
+
if (!takeDaemonLock(path.join(paths.home, "daemon.pid"))) {
|
|
347
|
+
appendLog(paths.log, "another Harness daemon is running here; leaving it");
|
|
348
|
+
process.exit(0);
|
|
349
|
+
}
|
|
350
|
+
// A daemon from before the lock holds none, but answers.
|
|
240
351
|
if (await daemonAnswers(paths.socket)) {
|
|
241
352
|
appendLog(paths.log, "another Harness daemon is running here; leaving it");
|
|
242
353
|
process.exit(0);
|
|
243
354
|
}
|
|
355
|
+
// What a daemon killed mid-run left going in its runs' folders stops before any new run starts there.
|
|
356
|
+
for (const runId of stopLeftRuns())
|
|
357
|
+
appendLog(paths.log, `stopped what was left of run ${runId}`);
|
|
244
358
|
// Started by the Harness app's launcher (HarnessDaemon.swift): if it goes, this goes too, so the daemon launchd starts
|
|
245
359
|
// next is the only one. The agents this daemon starts do not inherit the mark.
|
|
246
360
|
const launcher = Number(process.env.HARNESS_LAUNCHER_PID);
|
|
@@ -250,19 +364,19 @@ export async function startDaemon() {
|
|
|
250
364
|
if (process.ppid !== launcher) process.exit(0);
|
|
251
365
|
}, 5_000).unref();
|
|
252
366
|
// Not signed in yet: Harness runs anyway, so the buddy can show setup, and carries on from here once signed in.
|
|
253
|
-
if (!
|
|
367
|
+
if (!readConfig(paths.config, {}).token)
|
|
254
368
|
await untilSignedIn({
|
|
255
369
|
paths,
|
|
256
|
-
origin:
|
|
370
|
+
origin: readConfig(paths.config, {}).origin || DEFAULT_ORIGIN,
|
|
257
371
|
agents: agentsHere()
|
|
258
372
|
.filter((entry) => AGENTS.includes(entry.id))
|
|
259
373
|
.map((entry) => entry.id),
|
|
260
374
|
log: (line) => appendLog(paths.log, line),
|
|
261
375
|
});
|
|
262
|
-
const config =
|
|
376
|
+
const config = readConfig(paths.config, {});
|
|
263
377
|
// node-sqlite3-wasm locks with a directory that exists only during a transaction. A daemon
|
|
264
378
|
// killed mid-transaction leaves it behind and every later open fails "database is locked";
|
|
265
|
-
// with no daemon answering, nothing can hold it.
|
|
379
|
+
// with this daemon holding the one daemon lock and no older daemon answering, nothing can hold it.
|
|
266
380
|
const lock = `${paths.database}.lock`;
|
|
267
381
|
if (fs.existsSync(lock) && !(await daemonAnswers(paths.socket))) {
|
|
268
382
|
fs.rmdirSync(lock);
|
|
@@ -271,10 +385,17 @@ export async function startDaemon() {
|
|
|
271
385
|
"removed a stale database lock left by a stopped daemon"
|
|
272
386
|
);
|
|
273
387
|
}
|
|
274
|
-
const store = openStore(paths.database
|
|
388
|
+
const store = openStore(paths.database, {
|
|
389
|
+
hasBlob: (sha256) =>
|
|
390
|
+
Boolean(sha256) && fs.existsSync(path.join(paths.files, String(sha256))),
|
|
391
|
+
});
|
|
275
392
|
// Which of the person's computers this is; ownMachines (created once this computer's key is read) keeps it.
|
|
276
393
|
const machine = loadMachine(paths.machine);
|
|
277
394
|
let ownMachines = null;
|
|
395
|
+
// The nerves between the person's computers (nerves.mjs), started once ownMachines is.
|
|
396
|
+
let nerves = null;
|
|
397
|
+
let originals = null;
|
|
398
|
+
let releaseNotice = null;
|
|
278
399
|
let viewCopies = null;
|
|
279
400
|
// Where an agent calling from a computer is, and the name beside its words ("Codex (linux)") once the person has more
|
|
280
401
|
// than one computer (ownMachines.mjs); before ownMachines starts, this computer alone.
|
|
@@ -288,6 +409,8 @@ export async function startDaemon() {
|
|
|
288
409
|
others: [],
|
|
289
410
|
};
|
|
290
411
|
const computerOf = (id) => ownMachines?.shownLabel(id) ?? null;
|
|
412
|
+
// Made once the machine sense is (below); the wake, stuck and compaction read it when they run.
|
|
413
|
+
let timeSense = null;
|
|
291
414
|
// Whether this computer acts on the board: home, or a worker standing in. A worker's board tables hold a copy of
|
|
292
415
|
// home's (boardMirror.mjs) for reading while home is away; its rounds, sweeps, runs and wakes are home's to do.
|
|
293
416
|
// A worker not confirmed yet works on a board of its own, so it acts on it as home would.
|
|
@@ -351,8 +474,11 @@ export async function startDaemon() {
|
|
|
351
474
|
// On home: workers hear the board changed, once for all the changes made in one turn of the event loop.
|
|
352
475
|
let tellingWorkers = false;
|
|
353
476
|
let toldHead = boardMirror.head();
|
|
477
|
+
// Set once the threads' folders are followed (followThreadFolders below): a change may open or close a thread.
|
|
478
|
+
let threadsMayHaveChanged = () => {};
|
|
354
479
|
const boardChanged = () => {
|
|
355
480
|
boardWaits.changed();
|
|
481
|
+
threadsMayHaveChanged();
|
|
356
482
|
if (tellingWorkers || !ownMachines?.isHome()) return;
|
|
357
483
|
tellingWorkers = true;
|
|
358
484
|
setImmediate(() => {
|
|
@@ -388,8 +514,18 @@ export async function startDaemon() {
|
|
|
388
514
|
})),
|
|
389
515
|
counts: store.counts(),
|
|
390
516
|
};
|
|
517
|
+
// "Connected" for the buddy: a browser here is up, and this computer is reachable (connectionStatus.mjs).
|
|
518
|
+
const connection = createConnection({
|
|
519
|
+
isConnected: () => state.connected,
|
|
520
|
+
machine: () => ({
|
|
521
|
+
id: machine.id,
|
|
522
|
+
label: machine.label,
|
|
523
|
+
role: machine.role,
|
|
524
|
+
}),
|
|
525
|
+
});
|
|
391
526
|
const saveStatus = () => {
|
|
392
527
|
state.counts = store.counts();
|
|
528
|
+
state.release = releaseNotice?.status() ?? null;
|
|
393
529
|
state.machine = ownMachines?.status() ?? {
|
|
394
530
|
id: machine.id,
|
|
395
531
|
label: machine.label,
|
|
@@ -409,12 +545,13 @@ export async function startDaemon() {
|
|
|
409
545
|
notices.approval(operation, connection),
|
|
410
546
|
});
|
|
411
547
|
// The swarm's secrets (vault.mjs). `oneclawUrl` names a self-hosted 1claw for the backup; 1claw's own otherwise.
|
|
548
|
+
let vaultPeers = null;
|
|
412
549
|
const vault = createVault({
|
|
413
550
|
store,
|
|
414
551
|
directory: paths.home,
|
|
415
552
|
log,
|
|
416
553
|
machine,
|
|
417
|
-
cloudUrl:
|
|
554
|
+
cloudUrl: readConfig(paths.config, {}).oneclawUrl,
|
|
418
555
|
notify: (body) => notifyDesktop(body),
|
|
419
556
|
// A worker's run gets its environment grants only for a task that computer took and the person authorized.
|
|
420
557
|
runMayHaveSecrets: (taskId, agent, from) => {
|
|
@@ -464,6 +601,28 @@ export async function startDaemon() {
|
|
|
464
601
|
expectedVersion: task.version,
|
|
465
602
|
});
|
|
466
603
|
},
|
|
604
|
+
// What a secret was passed for: it lasts while this task or thread does.
|
|
605
|
+
workOpen: (id) => {
|
|
606
|
+
const task = store.getTask(String(id));
|
|
607
|
+
if (!task || task.removed_at) return false;
|
|
608
|
+
if (["done", "failed", "unknown"].includes(task.status)) return false;
|
|
609
|
+
return !store.getThread(task.id)?.closed_at;
|
|
610
|
+
},
|
|
611
|
+
noteInWork: (id, text) => {
|
|
612
|
+
const task = store.getTask(String(id));
|
|
613
|
+
const goalId = task?.kind === "goal" ? task.id : task?.parent_id;
|
|
614
|
+
if (goalId && store.getTask(goalId)?.kind === "goal")
|
|
615
|
+
store.roomPost({ goalId, author: DISPATCHER, kind: "note", text });
|
|
616
|
+
},
|
|
617
|
+
runRestricted: (id) => {
|
|
618
|
+
const task = store.getTask(String(id));
|
|
619
|
+
return (
|
|
620
|
+
Boolean(task) &&
|
|
621
|
+
(restrictedRun(store, task) ||
|
|
622
|
+
store.meta(`other-person-run:${task.id}`) === "1")
|
|
623
|
+
);
|
|
624
|
+
},
|
|
625
|
+
peers: () => vaultPeers,
|
|
467
626
|
});
|
|
468
627
|
vault.ready.catch(() => {});
|
|
469
628
|
const nativeRequests = createRunRequests({
|
|
@@ -487,6 +646,8 @@ export async function startDaemon() {
|
|
|
487
646
|
stepTold = Date.now();
|
|
488
647
|
boardWaits.bump();
|
|
489
648
|
};
|
|
649
|
+
let runEnded = () => {};
|
|
650
|
+
let runStepped = () => {};
|
|
490
651
|
const taskRuns = createTaskRuns({
|
|
491
652
|
nativeRequests,
|
|
492
653
|
t3Missed: (...args) => threadRuns.missed(...args),
|
|
@@ -495,6 +656,10 @@ export async function startDaemon() {
|
|
|
495
656
|
inferenceRefusal: (agent) => cloudAi?.refusal(agent) ?? null,
|
|
496
657
|
// And says when any of its calls ran on Harness's AI because the person's own link or key did not answer.
|
|
497
658
|
inferenceNote: (agent, since) => cloudAi?.noteFor(agent, since) ?? null,
|
|
659
|
+
// Each run's end, in the log (completion.mjs), once completion is made below.
|
|
660
|
+
onEnded: (run) => runEnded(run),
|
|
661
|
+
// Each command a run runs and each file it edits, for going in circles (circling.mjs), once that is made below.
|
|
662
|
+
onStep: (run, step) => runStepped(run, step),
|
|
498
663
|
});
|
|
499
664
|
const { validRunId, taskFiles, readTask, taskStatus } = taskRuns;
|
|
500
665
|
|
|
@@ -518,6 +683,7 @@ export async function startDaemon() {
|
|
|
518
683
|
});
|
|
519
684
|
const { sync, sourceRaw } = sessionIndex;
|
|
520
685
|
|
|
686
|
+
// A socket file left by a daemon that stopped: no running daemon listens on it while this one holds the lock.
|
|
521
687
|
if (process.platform !== "win32") {
|
|
522
688
|
try {
|
|
523
689
|
if (fs.existsSync(paths.socket)) fs.unlinkSync(paths.socket);
|
|
@@ -543,18 +709,234 @@ export async function startDaemon() {
|
|
|
543
709
|
// brief, a task for a hosted agent, a folder's README) goes through the firewall's scrub first: keys and passwords
|
|
544
710
|
// become [SECRET_n] and come back restored, since the answer stays on this computer. Sealed relay traffic and keys
|
|
545
711
|
// are not words and pass as they are.
|
|
546
|
-
// What
|
|
547
|
-
//
|
|
548
|
-
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
712
|
+
// What happened on this computer, kept in order (events.mjs); what this computer reads, each read by its source
|
|
713
|
+
// (sources.mjs); and what every computer of the person reads the same (facts.mjs). A chain of happenings, each
|
|
714
|
+
// caused by the one before, stops where a chain of work handed on without the person does.
|
|
715
|
+
const events = createEvents({ store, maxHops: MAX_HANDOFFS, log });
|
|
716
|
+
// Each thread's record (threadRecord.mjs): its waits and watches on now, what woke its agents, who got stuck or went in
|
|
717
|
+
// circles; for the person who opens it from the thread's ···, and what each watch has cost.
|
|
718
|
+
const threadRecord = createThreadRecord({
|
|
719
|
+
store,
|
|
720
|
+
events,
|
|
721
|
+
cuts: () => (nerves?.status() ?? []).filter((nerve) => nerve.cutSince),
|
|
722
|
+
worker: () => (machine.role === "worker" ? machine.id : null),
|
|
723
|
+
});
|
|
724
|
+
// What only native code can sense, over the line of the launcher that started this daemon on a Mac
|
|
725
|
+
// (nativeSenses.mjs); null for a daemon started any other way, whose senses read through Node.
|
|
726
|
+
const native = connectNativeSenses({ log });
|
|
727
|
+
// The runs Harness has going in a folder, by the folder each works in: who is working where files change.
|
|
728
|
+
const realFolder = (folder) => {
|
|
729
|
+
try {
|
|
730
|
+
return fs.realpathSync(folder);
|
|
731
|
+
} catch {
|
|
732
|
+
return path.resolve(folder);
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
const within = (inner, outer) => {
|
|
736
|
+
const relative = path.relative(outer, inner);
|
|
737
|
+
return !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
738
|
+
};
|
|
739
|
+
const runsIn = (folder) =>
|
|
740
|
+
taskRuns
|
|
741
|
+
.running()
|
|
742
|
+
.filter((run) => {
|
|
743
|
+
if (!run.cwd) return false;
|
|
744
|
+
const cwd = realFolder(run.cwd);
|
|
745
|
+
return within(cwd, folder) || within(folder, cwd);
|
|
746
|
+
})
|
|
747
|
+
.map((run) => ({
|
|
748
|
+
run: run.runId,
|
|
749
|
+
agent: run.agent,
|
|
750
|
+
thread: store.getTask(run.runId)?.parent_id ?? null,
|
|
751
|
+
}));
|
|
752
|
+
// Outside events (outsideEvents.mjs, S7.2): addresses this computer makes for threads, and what arrives at them.
|
|
753
|
+
const outsideEvents = createOutsideEvents({
|
|
754
|
+
home: paths.home,
|
|
755
|
+
events,
|
|
756
|
+
identity: () => relayIdentity,
|
|
757
|
+
askHarness: (type, input) => askHarness(type, input),
|
|
758
|
+
origin: () => readConfig(paths.config, {}).origin || DEFAULT_ORIGIN,
|
|
759
|
+
privateMode: () => coordinatorMode() === "local",
|
|
760
|
+
threadOk: (id) => {
|
|
761
|
+
const thread = store.getTask(id);
|
|
762
|
+
return (
|
|
763
|
+
thread?.kind === "goal" &&
|
|
764
|
+
(thread.status === "open" || thread.status === "paused")
|
|
765
|
+
);
|
|
766
|
+
},
|
|
767
|
+
log: (line) => log(line),
|
|
768
|
+
});
|
|
769
|
+
// A thread's screen watches, run by the person's browser (screenWatches.mjs, S7.1).
|
|
770
|
+
const screenWatches = createScreenWatches({
|
|
771
|
+
askWindows: (call) => askWindows(call),
|
|
772
|
+
computer: () => ({
|
|
773
|
+
id: String(machine.id),
|
|
774
|
+
label: String(machine.label || "this computer").slice(0, 120),
|
|
775
|
+
}),
|
|
776
|
+
log: (line) => log(line),
|
|
777
|
+
});
|
|
778
|
+
const sources = createSources({
|
|
779
|
+
events,
|
|
780
|
+
log,
|
|
781
|
+
// What each source keeps across a restart (a mark in the Mac's history, a snapshot), under its own name.
|
|
782
|
+
memory: {
|
|
783
|
+
get: (name) => {
|
|
784
|
+
try {
|
|
785
|
+
return JSON.parse(store.meta(`source-memory:${name}`) || "null");
|
|
786
|
+
} catch {
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
},
|
|
790
|
+
set: (name, value) =>
|
|
791
|
+
store.meta(`source-memory:${name}`, JSON.stringify(value)),
|
|
792
|
+
},
|
|
793
|
+
kinds: {
|
|
794
|
+
// Harness's own home is never said: a thread's folder may hold it.
|
|
795
|
+
files: createFileKind({ native, runsIn, leaveOut: [paths.home] }),
|
|
796
|
+
process: createProcessKind({ native }),
|
|
797
|
+
outside: outsideEvents.kind,
|
|
798
|
+
screen: screenWatches.kind,
|
|
799
|
+
// Reach (reach.mjs, S7.3): a web address, a Quotient market's odds or the person's Bankr wallet, on a timer.
|
|
800
|
+
reach: createReachKind({
|
|
801
|
+
ask: (type, input) => askHarness(type, input),
|
|
802
|
+
// What the person let the thread spend, as swarm.mjs keeps it; null for no limit of its own.
|
|
803
|
+
ceilingOf: (thread) => {
|
|
804
|
+
const kept = store.meta(`spend-ceiling:${thread}`);
|
|
805
|
+
return kept && Number.isFinite(Number(kept)) ? Number(kept) : null;
|
|
806
|
+
},
|
|
807
|
+
}),
|
|
808
|
+
check: createCheckKind(),
|
|
809
|
+
machine: createMachineKind({ native }),
|
|
810
|
+
disk: createDiskKind({ native }),
|
|
811
|
+
// environment.mjs is made further on; the person is first read once presence starts.
|
|
812
|
+
person: createPersonKind({
|
|
813
|
+
environment: { person: () => environment.person() },
|
|
814
|
+
}),
|
|
815
|
+
repository: createRepositoryKind(),
|
|
816
|
+
// facts.mjs is made just below; a fact is first read once a watch follows it.
|
|
817
|
+
fact: createFactKind({
|
|
818
|
+
facts: {
|
|
819
|
+
get: (key, options) => facts.get(key, options),
|
|
820
|
+
onSet: (listener) => facts.onSet(listener),
|
|
821
|
+
},
|
|
822
|
+
}),
|
|
823
|
+
},
|
|
824
|
+
});
|
|
825
|
+
const facts = createFacts({ store });
|
|
826
|
+
// Sleep (sleep.mjs, S8.1): what this computer's days are like, folded from the log before it forgets.
|
|
827
|
+
const sleep = createSleep({ store, facts, log });
|
|
828
|
+
events.onForget((throughSeq) => sleep.fold(throughSeq));
|
|
829
|
+
try {
|
|
830
|
+
sleep.fold();
|
|
831
|
+
} catch (error) {
|
|
832
|
+
log(`sleep: ${error.message}`);
|
|
833
|
+
}
|
|
834
|
+
// Knowing work is done without looking again and again (completion.mjs): each run's end in the log, a process an
|
|
835
|
+
// agent started followed to its end, and what should now be true checked until it is.
|
|
836
|
+
const completion = createCompletion({ sources, events });
|
|
837
|
+
// Going in circles (circling.mjs): a run's own steps, and a thread's folder as it works there. The agent is told at
|
|
838
|
+
// its next step, as the person's own words are kept apart from Harness's readings (steerQueue.mjs SENSE).
|
|
839
|
+
const circling = createCircling({
|
|
840
|
+
events,
|
|
841
|
+
follow: (folder, onChange) =>
|
|
842
|
+
sources.subscribe(
|
|
843
|
+
{ kind: "files", folder: realFolder(folder) },
|
|
844
|
+
onChange
|
|
845
|
+
),
|
|
846
|
+
tell: (run, text) => {
|
|
847
|
+
if (run.sessionId)
|
|
848
|
+
putSteer({
|
|
849
|
+
session: String(run.sessionId),
|
|
850
|
+
agent: PARENT,
|
|
851
|
+
kind: SENSE,
|
|
852
|
+
text,
|
|
853
|
+
});
|
|
854
|
+
},
|
|
855
|
+
log,
|
|
856
|
+
});
|
|
857
|
+
// Tripwires (tripwires.mjs): a change to a file a session read, told at its next step and held at a write that would
|
|
858
|
+
// undo it (senseCall.mjs, at each agent's tool call).
|
|
859
|
+
const tripwires = createTripwires({
|
|
860
|
+
events,
|
|
861
|
+
nameOf,
|
|
862
|
+
follow: (folder, onReading) =>
|
|
863
|
+
sources.subscribe({ kind: "files", folder }, onReading),
|
|
864
|
+
log,
|
|
865
|
+
});
|
|
866
|
+
tripwires.start();
|
|
867
|
+
// Pain told at once (pain.mjs): the computer's and the limits' levels, to the agents at work they touch.
|
|
868
|
+
const pain = createPain({
|
|
869
|
+
events,
|
|
870
|
+
store,
|
|
871
|
+
sessionsOfThread: (thread) =>
|
|
872
|
+
taskRuns
|
|
873
|
+
.running()
|
|
874
|
+
.map((run) => store.getTask(run.runId))
|
|
875
|
+
.filter((task) => task?.parent_id === thread && task.session_id)
|
|
876
|
+
.map((task) => task.session_id),
|
|
877
|
+
});
|
|
878
|
+
pain.start();
|
|
879
|
+
// Reflexes (reflexes.mjs): the body protecting itself in code, through the response table's protective responses.
|
|
880
|
+
const reflexes = createReflexes({
|
|
881
|
+
events,
|
|
882
|
+
store,
|
|
883
|
+
nameOf,
|
|
884
|
+
log,
|
|
885
|
+
threadOfSession: (session) =>
|
|
886
|
+
store.db.get(
|
|
887
|
+
"select parent_id from board_tasks where session_id = ? and parent_id is not null order by updated_at desc limit 1",
|
|
888
|
+
[String(session)]
|
|
889
|
+
)?.parent_id ?? null,
|
|
890
|
+
sessionsOfThread: (thread) =>
|
|
891
|
+
taskRuns
|
|
892
|
+
.running()
|
|
893
|
+
.map((run) => store.getTask(run.runId))
|
|
894
|
+
.filter((task) => task?.parent_id === thread && task.session_id)
|
|
895
|
+
.map((task) => task.session_id),
|
|
896
|
+
});
|
|
897
|
+
reflexes.start();
|
|
898
|
+
// Recall (recall.mjs): an error's shape or a file read for the first time, matched with lessons and the log.
|
|
899
|
+
const recall = createRecall({ store, events, nameOf, log });
|
|
900
|
+
recall.start();
|
|
901
|
+
// The agent's own verbs for its senses (senseTools.mjs): look and wish, from its MCP server.
|
|
902
|
+
const senseTools = createSenseTools({
|
|
903
|
+
store,
|
|
904
|
+
events,
|
|
905
|
+
reached: (id) => ownMachines?.linkedTo(id) === true,
|
|
906
|
+
sources,
|
|
907
|
+
agents: () => installedAgents,
|
|
908
|
+
signedIn: (agent) => signedIn(agent),
|
|
909
|
+
secretsFor: async (agent) =>
|
|
910
|
+
(
|
|
911
|
+
(await vault.command({ command: "board.vault.list" }, { agent }))
|
|
912
|
+
?.secrets ?? []
|
|
913
|
+
).map((secret) => secret.name),
|
|
914
|
+
ruleFor: (agent) =>
|
|
915
|
+
authority.standingRules().find((rule) => rule.agent === agent) ?? null,
|
|
916
|
+
reflexes,
|
|
917
|
+
nameOf,
|
|
918
|
+
});
|
|
919
|
+
senseTools.start();
|
|
920
|
+
runStepped = (run, step) => {
|
|
921
|
+
const task = store.getTask(run.runId);
|
|
922
|
+
const thread = task?.parent_id ? store.getTask(task.parent_id) : null;
|
|
923
|
+
circling.step(
|
|
924
|
+
{ ...run, thread: thread?.kind === "goal" ? thread.id : null },
|
|
925
|
+
step
|
|
926
|
+
);
|
|
927
|
+
};
|
|
928
|
+
runEnded = (run) => {
|
|
929
|
+
circling.ended(run.runId);
|
|
930
|
+
sensesLeft(run);
|
|
931
|
+
return completion.runEnded({
|
|
932
|
+
...run,
|
|
933
|
+
thread: store.getTask(run.runId)?.parent_id ?? null,
|
|
555
934
|
});
|
|
556
|
-
if (localEvents.length > 100) localEvents.shift();
|
|
557
935
|
};
|
|
936
|
+
// What the local stack just did, for the buddy's strip and its notices: each step and how long it took, never
|
|
937
|
+
// anyone's words.
|
|
938
|
+
const localEvent = (kind, text, ms = null) =>
|
|
939
|
+
events.append({ source: "stack", kind, text, ms });
|
|
558
940
|
// `clear`: fields sent as they are, after the scrub (the person's own model lane, whose key must reach the provider).
|
|
559
941
|
const bridge = createBridge({
|
|
560
942
|
config,
|
|
@@ -580,9 +962,25 @@ export async function startDaemon() {
|
|
|
580
962
|
"sealed",
|
|
581
963
|
"sealed_threads",
|
|
582
964
|
"sealed_files",
|
|
965
|
+
// Events Harness sealed to this computer as they arrived at an outside address (outsideEvents.mjs).
|
|
966
|
+
"outside_events",
|
|
967
|
+
// Channels with other people's computers on accepted threads (peopleLink.mjs, Harness's thread_link).
|
|
968
|
+
"people_link",
|
|
583
969
|
"harness_files",
|
|
584
970
|
"lane_fetch",
|
|
585
971
|
"profile",
|
|
972
|
+
// A held read's answer from Harness's server becomes Harness's new turn in its thread (harnessOffers.mjs).
|
|
973
|
+
"held_reads",
|
|
974
|
+
// Harness's turn on its server asks the person here before an app's write (harnessOffers.mjs).
|
|
975
|
+
"harness_permission",
|
|
976
|
+
// The person's apps live here, moved from Harness, and Harness calls them through this computer (connectors.mjs).
|
|
977
|
+
"apps",
|
|
978
|
+
// A Bankr proposal from a thread's work that waits for the person is shown here (bankrApprovals.mjs).
|
|
979
|
+
"bankr_approval",
|
|
980
|
+
// Harness's server reaches the person's browsers through this computer (deviceDoor.mjs device_call).
|
|
981
|
+
"device_door",
|
|
982
|
+
// A jam's sealed store (jamStore.mjs): Harness tells this computer as a jam moves (jam_event, jam_changed).
|
|
983
|
+
"jams",
|
|
586
984
|
],
|
|
587
985
|
identityKey: relayIdentity?.publicKey,
|
|
588
986
|
// Which computer this is, its name and the role it last had (home holds the board; a worker reaches it).
|
|
@@ -593,12 +991,18 @@ export async function startDaemon() {
|
|
|
593
991
|
}),
|
|
594
992
|
}),
|
|
595
993
|
onOpen: () => {
|
|
994
|
+
// A device taken off the person's list while this computer was away from Harness is cut off now.
|
|
995
|
+
void devicesChanged();
|
|
596
996
|
// Threads that went quiet while Harness was out of reach get their round now.
|
|
597
997
|
if (holdsBoard()) {
|
|
598
998
|
for (const thread of store.goals()) coordinator.poke(thread.id);
|
|
599
999
|
for (const message of store.undeliveredMessages())
|
|
600
1000
|
sealed.sendMessage(message);
|
|
601
|
-
|
|
1001
|
+
resendThreadEnds();
|
|
1002
|
+
peopleLink?.sync();
|
|
1003
|
+
void checkPeerKeys().catch(() => undefined);
|
|
1004
|
+
// A friendship that ended while this computer was off ends here too (network.mjs).
|
|
1005
|
+
void network?.friends().catch(() => undefined);
|
|
602
1006
|
}
|
|
603
1007
|
},
|
|
604
1008
|
onMessage: (message) => handleBridgeMessage(message),
|
|
@@ -612,8 +1016,43 @@ export async function startDaemon() {
|
|
|
612
1016
|
threadView: () => threadView,
|
|
613
1017
|
quiet,
|
|
614
1018
|
});
|
|
1019
|
+
// The person's browsers, reached through this computer for Harness's server and for agents here (deviceDoor.mjs).
|
|
1020
|
+
const deviceDoor = createDeviceDoor({
|
|
1021
|
+
askWindows: (call) => askWindows(call),
|
|
1022
|
+
store,
|
|
1023
|
+
// A read of the person's browser through the door, in the log as from outside: what it says is a page's, so a turn
|
|
1024
|
+
// that follows from it has fewer rights (outsideRuns.mjs). Who read what kind, never what it said.
|
|
1025
|
+
noteRead: ({ agent, tool, label }) =>
|
|
1026
|
+
events.append({
|
|
1027
|
+
source: "screen",
|
|
1028
|
+
kind: "read",
|
|
1029
|
+
text: `${nameOf(agent)} read ${label ?? tool.replaceAll("_", " ")} through the door`,
|
|
1030
|
+
data: { agent, tool },
|
|
1031
|
+
trust: "untrusted",
|
|
1032
|
+
}),
|
|
1033
|
+
browsers: () => {
|
|
1034
|
+
const here = link?.browsersHere() ?? new Set();
|
|
1035
|
+
return store
|
|
1036
|
+
.phones()
|
|
1037
|
+
.filter((device) => device.kind === "browser" && !device.revoked_at)
|
|
1038
|
+
.map((device) => ({
|
|
1039
|
+
id: device.id,
|
|
1040
|
+
label: device.label,
|
|
1041
|
+
openHere: here.has(device.id),
|
|
1042
|
+
}));
|
|
1043
|
+
},
|
|
1044
|
+
});
|
|
1045
|
+
// This computer's signed word for which of its agents asked (agentClaims.mjs): Harness and the person's friends
|
|
1046
|
+
// check it. The person's identity is read first if this computer has not yet.
|
|
1047
|
+
const agentClaims = createAgentClaims({
|
|
1048
|
+
device: async () => deviceKeys,
|
|
1049
|
+
identity: async () => {
|
|
1050
|
+
if (!personKeys) await refreshIdentity();
|
|
1051
|
+
return personKeys;
|
|
1052
|
+
},
|
|
1053
|
+
});
|
|
615
1054
|
// Agents' calls to Harness, carried on the bridge (mcp-stdio.mjs asks; nothing on this computer posts to /api/mcp).
|
|
616
|
-
const mcpRelay = createMcpRelay({ config,
|
|
1055
|
+
const mcpRelay = createMcpRelay({ config, log, deviceDoor });
|
|
617
1056
|
// The onchain desk (desk.mjs): the book's commands, Bankr's asks under a strategy carrying its instructions, Bankr's
|
|
618
1057
|
// chain receipts filed in the book, and the contract gate's deploy ask and the check of what was deployed.
|
|
619
1058
|
const desk = createDesk({
|
|
@@ -692,6 +1131,14 @@ export async function startDaemon() {
|
|
|
692
1131
|
return null;
|
|
693
1132
|
}
|
|
694
1133
|
};
|
|
1134
|
+
// A Bankr proposal from one of this computer's threads that waits for the person (bankrApprovals.mjs).
|
|
1135
|
+
const bankrApprovals = createBankrApprovals({
|
|
1136
|
+
store,
|
|
1137
|
+
runRequests: () => nativeRequests,
|
|
1138
|
+
cloudAsked,
|
|
1139
|
+
send: (message) => send(message),
|
|
1140
|
+
log,
|
|
1141
|
+
});
|
|
695
1142
|
const forwardToHarness = (request) => {
|
|
696
1143
|
keepCloudAsked(request);
|
|
697
1144
|
const answered = askHarness("board_call", {
|
|
@@ -718,9 +1165,70 @@ export async function startDaemon() {
|
|
|
718
1165
|
/^[a-z0-9][a-z0-9._-]{0,63}(\/[a-z0-9][a-z0-9._-]{0,63})?$/.test(
|
|
719
1166
|
String(value || "")
|
|
720
1167
|
);
|
|
721
|
-
// This computer's relay key pair, read by the phone desk below:
|
|
722
|
-
// with it (sealedThreads.mjs).
|
|
1168
|
+
// This computer's relay key pair, read by the phone desk below: its phones, browsers and other computers seal to it.
|
|
723
1169
|
let relayIdentity = null;
|
|
1170
|
+
// This computer's device keys (deviceIdentity.mjs): its signing key on the person's device list.
|
|
1171
|
+
let deviceKeys = null;
|
|
1172
|
+
// The person's identity toward other people (computerDevices.mjs personIdentity; owner, November 14): the account
|
|
1173
|
+
// keys every one of their devices holds, which friends pin and jams use. Null while this computer holds no copy;
|
|
1174
|
+
// read again whenever the person's list or keys change (refreshIdentity).
|
|
1175
|
+
let personKeys = null;
|
|
1176
|
+
let refreshIdentity = async () => {};
|
|
1177
|
+
let peopleLink = null;
|
|
1178
|
+
// Reads the person's device list again and closes the channels of every device taken off it (set once the link,
|
|
1179
|
+
// phones and computers exist below).
|
|
1180
|
+
let devicesChanged = async () => {};
|
|
1181
|
+
// A thread's end waits here until Harness has taken it: it closes the thread on Harness too, so it goes there, and
|
|
1182
|
+
// goes again on reconnect (it was sent once and lost when the connection was down).
|
|
1183
|
+
const PENDING_ENDS = "pending-thread-ends";
|
|
1184
|
+
const pendingEnds = () => {
|
|
1185
|
+
try {
|
|
1186
|
+
return JSON.parse(store.meta(PENDING_ENDS) || "{}");
|
|
1187
|
+
} catch {
|
|
1188
|
+
return {};
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
const resendThreadEnds = () => {
|
|
1192
|
+
for (const frame of Object.values(pendingEnds())) send(frame);
|
|
1193
|
+
};
|
|
1194
|
+
// What became of a thread's message, file or end: taken by the other computer over the channel, or by Harness's
|
|
1195
|
+
// mailbox (its thread_ack). A refusal is kept as one, never marked delivered; a message Harness could not store
|
|
1196
|
+
// (no answer, or its storage) stays to go again.
|
|
1197
|
+
const threadTaken = ({ messageId, ok, error, peerConnected }) => {
|
|
1198
|
+
const id = String(messageId || "");
|
|
1199
|
+
if (ok) store.markDelivered(id);
|
|
1200
|
+
else if (error && error !== "storage") store.markRefused(id, error);
|
|
1201
|
+
// An end Harness answered either way is done with; only one it never answered goes again.
|
|
1202
|
+
if ((ok || (error && error !== "storage")) && id.startsWith("end:")) {
|
|
1203
|
+
const ends = pendingEnds();
|
|
1204
|
+
delete ends[id.slice(4)];
|
|
1205
|
+
store.meta(PENDING_ENDS, JSON.stringify(ends));
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
// One thread frame out (sealedThreads.mjs): a message or file over the channel with that person when it takes it,
|
|
1209
|
+
// else to Harness's mailbox; an end always to Harness. Nothing goes to someone whose key waits to be trusted again.
|
|
1210
|
+
const sendThreadFrame = async (frame) => {
|
|
1211
|
+
const thread = store.getThread(String(frame?.taskId || ""));
|
|
1212
|
+
const handle = thread ? handleOf(thread.with_agent) : null;
|
|
1213
|
+
if (frame.type === "thread_end") {
|
|
1214
|
+
store.meta(
|
|
1215
|
+
PENDING_ENDS,
|
|
1216
|
+
JSON.stringify({ ...pendingEnds(), [frame.taskId]: frame })
|
|
1217
|
+
);
|
|
1218
|
+
send(frame);
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
if (handle && store.meta(`relay-key-waiting:${handle}`)) return;
|
|
1222
|
+
const carried =
|
|
1223
|
+
handle && peopleLink ? await peopleLink.carry(handle, frame) : null;
|
|
1224
|
+
if (carried?.ok)
|
|
1225
|
+
return threadTaken({
|
|
1226
|
+
messageId: frame.messageId,
|
|
1227
|
+
ok: true,
|
|
1228
|
+
peerConnected: true,
|
|
1229
|
+
});
|
|
1230
|
+
send(frame);
|
|
1231
|
+
};
|
|
724
1232
|
const boardFiles = createBoardFiles({
|
|
725
1233
|
store,
|
|
726
1234
|
log,
|
|
@@ -737,6 +1245,7 @@ export async function startDaemon() {
|
|
|
737
1245
|
scrubber: local.scrubber(),
|
|
738
1246
|
}),
|
|
739
1247
|
wakeFor: (...args) => actions.wakeFor(...args),
|
|
1248
|
+
fileAdded: (...args) => jams?.fileAdded(...args),
|
|
740
1249
|
});
|
|
741
1250
|
const {
|
|
742
1251
|
command: fileCommand,
|
|
@@ -754,15 +1263,25 @@ export async function startDaemon() {
|
|
|
754
1263
|
|
|
755
1264
|
const sealed = createSealedThreads({
|
|
756
1265
|
store,
|
|
757
|
-
|
|
1266
|
+
// Over the channel with that person when one is open, through Harness's mailbox otherwise (sendThreadFrame).
|
|
1267
|
+
send: (frame) => sendThreadFrame(frame),
|
|
758
1268
|
askHarness,
|
|
759
|
-
|
|
760
|
-
identity: () => relayIdentity,
|
|
761
|
-
projects: () => projects,
|
|
1269
|
+
identity: () => personKeys,
|
|
762
1270
|
notifyBoard: (task) => notifyBoard(task),
|
|
763
1271
|
notify: notices.notify,
|
|
764
1272
|
files: boardFiles,
|
|
765
|
-
|
|
1273
|
+
follow: (handle, keyed) => followPeer(handle, keyed),
|
|
1274
|
+
ensureIdentity: () => refreshIdentity(),
|
|
1275
|
+
claims: { mint: (agent, about) => agentClaims.mint(agent, about) },
|
|
1276
|
+
log,
|
|
1277
|
+
});
|
|
1278
|
+
// A secret passed to another person's agents, inside a jam both people are in (vaultPeers.mjs, docs/jam-plan.md J4).
|
|
1279
|
+
vaultPeers = createVaultPeers({
|
|
1280
|
+
jamWith: (handle, work) => jams?.jamWith(handle, work) ?? null,
|
|
1281
|
+
send: (event) => jams?.vaultSend(event),
|
|
1282
|
+
serve: vault.serveAnotherPerson,
|
|
1283
|
+
onPassed: vault.passedHere,
|
|
1284
|
+
onEnded: vault.endedHere,
|
|
766
1285
|
log,
|
|
767
1286
|
});
|
|
768
1287
|
const local = createLocalStack({
|
|
@@ -771,6 +1290,7 @@ export async function startDaemon() {
|
|
|
771
1290
|
configPath: paths.config,
|
|
772
1291
|
filesRoot: paths.files,
|
|
773
1292
|
folders: () => folders,
|
|
1293
|
+
holdsBoard,
|
|
774
1294
|
roomOf: (task) => roomOf(task),
|
|
775
1295
|
namedPath,
|
|
776
1296
|
quiet,
|
|
@@ -778,6 +1298,16 @@ export async function startDaemon() {
|
|
|
778
1298
|
localEvent,
|
|
779
1299
|
log,
|
|
780
1300
|
});
|
|
1301
|
+
// The route at the model (modelRoute.mjs): the models Harness serves here, at an address an agent can be pointed at,
|
|
1302
|
+
// with what Harness noticed for its session at the end of each request.
|
|
1303
|
+
const modelRoute = createModelRoute({
|
|
1304
|
+
serving: (id) => local.inference.serving(id),
|
|
1305
|
+
models: () => local.inference.chatModels(),
|
|
1306
|
+
log,
|
|
1307
|
+
});
|
|
1308
|
+
void modelRoute
|
|
1309
|
+
.start()
|
|
1310
|
+
.catch((error) => log(`model route: ${error.message}`));
|
|
781
1311
|
// What this computer reads a round Harness's server decided with, before its words reach an agent (serverWords.mjs).
|
|
782
1312
|
const serverWords = createServerWords({
|
|
783
1313
|
store,
|
|
@@ -839,8 +1369,8 @@ export async function startDaemon() {
|
|
|
839
1369
|
store,
|
|
840
1370
|
log,
|
|
841
1371
|
onChange: (threadId) => notifyBoard(store.getTask(threadId)),
|
|
842
|
-
// A
|
|
843
|
-
shared: (threadId) =>
|
|
1372
|
+
// A jam's room keeps its board in the jam's record, the same on every computer in it.
|
|
1373
|
+
shared: (threadId) => jams?.boardOf(threadId) ?? null,
|
|
844
1374
|
});
|
|
845
1375
|
const notifyBoard = (task) => {
|
|
846
1376
|
if (!task) return;
|
|
@@ -926,14 +1456,19 @@ export async function startDaemon() {
|
|
|
926
1456
|
// through any of their own agents), for a coding agent installed here, in a folder the permission covers, starts
|
|
927
1457
|
// without a Start. By default it covers any folder below home, with no daily limit; the person may name folders and a
|
|
928
1458
|
// limit instead (runAuthority.mjs covers). Links are followed, so no path inside a covered folder leads out of it.
|
|
929
|
-
const authority = createRunAuthority({
|
|
1459
|
+
const authority = createRunAuthority({
|
|
1460
|
+
store,
|
|
1461
|
+
installedAgents,
|
|
1462
|
+
runsWorkOn: (id, dir) => ownMachines?.runsWorkIn(id, dir) ?? false,
|
|
1463
|
+
self: () => machine.id,
|
|
1464
|
+
});
|
|
930
1465
|
const { RUNNERS } = authority;
|
|
931
1466
|
const threadAuthority = createThreadAuthority({
|
|
932
1467
|
store,
|
|
933
1468
|
standingRules: authority.standingRules,
|
|
934
1469
|
within: authority.within,
|
|
935
1470
|
worktreeRoot: path.join(paths.home, "worktrees"),
|
|
936
|
-
|
|
1471
|
+
jamRoot: path.join(paths.home, "jams"),
|
|
937
1472
|
});
|
|
938
1473
|
const dispatches = createDispatches({
|
|
939
1474
|
store,
|
|
@@ -943,7 +1478,7 @@ export async function startDaemon() {
|
|
|
943
1478
|
guard: (text) => local.readByGuard(text),
|
|
944
1479
|
notifyBoard,
|
|
945
1480
|
inferenceRefusal: (agent) => cloudAi?.refusal(agent) ?? null,
|
|
946
|
-
|
|
1481
|
+
jamRoom: (id) => jams?.isJamRoom(id) ?? false,
|
|
947
1482
|
});
|
|
948
1483
|
// Threads: one objective the person set for a team, worked in a room. A post wakes the agents it names; a job posted
|
|
949
1484
|
// in the thread runs on the thread's authority; Harness facilitates and answers once. Backstops pause the room
|
|
@@ -975,10 +1510,12 @@ export async function startDaemon() {
|
|
|
975
1510
|
const lineupCommands = createLineupCommands({
|
|
976
1511
|
lineup,
|
|
977
1512
|
readiness,
|
|
978
|
-
runtimeRoot: () =>
|
|
1513
|
+
runtimeRoot: () => readConfig(paths.config, {}).runtimeRoot,
|
|
979
1514
|
// A coding agent added (or installed after the daemon started) is run from now on, and one taken out is not;
|
|
980
1515
|
// reconnecting tells Harness, and so the person's other computers, which agents this one has now.
|
|
1516
|
+
// Every surface that lists the swarm (the "@" menus in the PiP and on pages, the buddy) reads it again at once.
|
|
981
1517
|
onChanged: (agent) => {
|
|
1518
|
+
boardWaits.bump();
|
|
982
1519
|
if (!RUNNERS.has(agent)) return;
|
|
983
1520
|
const at = installedAgents.indexOf(agent);
|
|
984
1521
|
const found = detectAgents().some(
|
|
@@ -1015,6 +1552,9 @@ export async function startDaemon() {
|
|
|
1015
1552
|
log,
|
|
1016
1553
|
});
|
|
1017
1554
|
agentWatch.start();
|
|
1555
|
+
// Harness stays wired into each agent in the swarm through agent updates and Harness releases (agentWiring.mjs).
|
|
1556
|
+
const agentWiring = createAgentWiring({ inSwarm: lineup.has, log });
|
|
1557
|
+
agentWiring.start();
|
|
1018
1558
|
|
|
1019
1559
|
// The auditor: code on every report, and the weekly task for the appointed auditor whose report goes to the person.
|
|
1020
1560
|
auditor = createAuditor({
|
|
@@ -1073,32 +1613,21 @@ export async function startDaemon() {
|
|
|
1073
1613
|
},
|
|
1074
1614
|
timing: handoffTiming(),
|
|
1075
1615
|
});
|
|
1076
|
-
// What this computer hands the person's Harness page through the extension (browserWake.mjs):
|
|
1077
|
-
//
|
|
1616
|
+
// What this computer hands the person's Harness page through the extension (browserWake.mjs): a window waking for
|
|
1617
|
+
// the computer's sealed asks (windowAsks.mjs).
|
|
1078
1618
|
const browserPage = createBrowserPage();
|
|
1079
|
-
const browserWake = createBrowserWake({
|
|
1080
|
-
log,
|
|
1081
|
-
pending: () =>
|
|
1082
|
-
store
|
|
1083
|
-
.listTasks({ agent: "harness", status: "open", limit: 100 })
|
|
1084
|
-
.filter(
|
|
1085
|
-
(task) =>
|
|
1086
|
-
task.target_agent === "harness" &&
|
|
1087
|
-
store.meta(`harness-browser-allowed:${task.id}`)
|
|
1088
|
-
)
|
|
1089
|
-
.map((task) => ({ kind: "board-task", task: task.id })),
|
|
1090
|
-
});
|
|
1619
|
+
const browserWake = createBrowserWake({ log });
|
|
1091
1620
|
// Where the person left each thread, for every list that names threads (threadLine.mjs).
|
|
1092
1621
|
const threadLine = createThreadLine({ store, log });
|
|
1093
1622
|
const threadView = createThreadView({
|
|
1094
1623
|
whereLeft: (id) => threadLine.of(id),
|
|
1095
|
-
browserListening: () => browserWake.listening(),
|
|
1096
1624
|
nativeNeeds: (runId) => nativeRequests.needs(runId),
|
|
1097
1625
|
vaultNeeds: (runId) => vault.needs(runId),
|
|
1626
|
+
threadNeeds: (threadId) => nativeRequests.threadNeeds(threadId),
|
|
1098
1627
|
store,
|
|
1099
1628
|
goals,
|
|
1100
1629
|
handoffs,
|
|
1101
|
-
|
|
1630
|
+
jamNeeds: (threadId) => jams?.needsOf(threadId) ?? [],
|
|
1102
1631
|
agentNeeds: () => [...specialtyNotice.needs(), ...subagentSteering.needs()],
|
|
1103
1632
|
computerOf,
|
|
1104
1633
|
});
|
|
@@ -1123,16 +1652,253 @@ export async function startDaemon() {
|
|
|
1123
1652
|
speaks: () => notices.on() && !quiet(),
|
|
1124
1653
|
phone: (message) => notices.toPhone("needs_you_agent", message),
|
|
1125
1654
|
});
|
|
1655
|
+
// Which sessions' own hooks (or plugin, or extension) are heard on this computer: a session whose start or prompt its
|
|
1656
|
+
// hooks reported takes Harness's readings at its next tool call (steerQueue.mjs SENSE, nudge.mjs --step), as its
|
|
1657
|
+
// hooks run in that very process. Codex runs them only once the person approved them; a session started before an
|
|
1658
|
+
// update runs the hooks it started with. Setup's check asks the same of its own short session (toolCheck). Kept in
|
|
1659
|
+
// memory: after a restart a session's readings wait for its turn's end (sensesLeft), and none is lost.
|
|
1660
|
+
const HEARD_SESSIONS = 500;
|
|
1661
|
+
const AFTER_CALL = new Set([
|
|
1662
|
+
...HOOK_AGENTS.filter((agent) => hookDialect(agent).after),
|
|
1663
|
+
"opencode",
|
|
1664
|
+
"kilo",
|
|
1665
|
+
"pi",
|
|
1666
|
+
"dsh",
|
|
1667
|
+
]);
|
|
1668
|
+
const agentsHeard = new Map();
|
|
1669
|
+
const sessionsHeard = new Map();
|
|
1670
|
+
const heardHooks = (agent, sessionId) => {
|
|
1671
|
+
agentsHeard.set(agent, Date.now());
|
|
1672
|
+
if (!sessionId) return;
|
|
1673
|
+
const key = `${agent}:${sessionId}`;
|
|
1674
|
+
sessionsHeard.delete(key);
|
|
1675
|
+
sessionsHeard.set(key, Date.now());
|
|
1676
|
+
if (sessionsHeard.size > HEARD_SESSIONS)
|
|
1677
|
+
sessionsHeard.delete(sessionsHeard.keys().next().value);
|
|
1678
|
+
};
|
|
1679
|
+
const tappable = (agent, sessionId) =>
|
|
1680
|
+
AFTER_CALL.has(agent) && sessionsHeard.has(`${agent}:${sessionId}`);
|
|
1681
|
+
// Harness's readings no hook took by the time a run ended (its hooks not approved, or gone quiet): one that would
|
|
1682
|
+
// have woken the agent wakes it now, the rest wait for its next wake (wakePicture.mjs). Kept on home, which writes
|
|
1683
|
+
// the agent's next brief; another computer hands them there (board.sense.left).
|
|
1684
|
+
const CARRIED_SENSES = 7;
|
|
1685
|
+
const keepSensesLeft = (thread, agent, items) => {
|
|
1686
|
+
const rest = items.filter((item) => !item.about?.wakes);
|
|
1687
|
+
const wakes = items.filter((item) => item.about?.wakes);
|
|
1688
|
+
if (rest.length) {
|
|
1689
|
+
let carried = [];
|
|
1690
|
+
try {
|
|
1691
|
+
carried = JSON.parse(
|
|
1692
|
+
store.meta(`carried-senses:${thread}:${agent}`) || "[]"
|
|
1693
|
+
);
|
|
1694
|
+
} catch {}
|
|
1695
|
+
store.meta(
|
|
1696
|
+
`carried-senses:${thread}:${agent}`,
|
|
1697
|
+
JSON.stringify(
|
|
1698
|
+
[
|
|
1699
|
+
...carried,
|
|
1700
|
+
...rest.map((item) => ({ text: String(item.text), at: item.at })),
|
|
1701
|
+
].slice(-CARRIED_SENSES)
|
|
1702
|
+
)
|
|
1703
|
+
);
|
|
1704
|
+
}
|
|
1705
|
+
if (wakes.length)
|
|
1706
|
+
actions.wakeFor(
|
|
1707
|
+
thread,
|
|
1708
|
+
{
|
|
1709
|
+
text: wakes.map((item) => `"${item.text}"`).join(" "),
|
|
1710
|
+
kind: "post",
|
|
1711
|
+
mentions: [agent],
|
|
1712
|
+
},
|
|
1713
|
+
DISPATCHER,
|
|
1714
|
+
[agent],
|
|
1715
|
+
{ why: "while you worked, Harness noticed" }
|
|
1716
|
+
);
|
|
1717
|
+
};
|
|
1718
|
+
const sensesLeft = (run) => {
|
|
1719
|
+
const task = store.getTask(run.runId);
|
|
1720
|
+
const session = run.sessionId ?? task?.session_id;
|
|
1721
|
+
if (!session) return;
|
|
1722
|
+
let items = [];
|
|
1723
|
+
try {
|
|
1724
|
+
items = takeSteers(
|
|
1725
|
+
String(session),
|
|
1726
|
+
PARENT,
|
|
1727
|
+
{ event: "run ended" },
|
|
1728
|
+
undefined,
|
|
1729
|
+
{ only: [SENSE] }
|
|
1730
|
+
);
|
|
1731
|
+
} catch (error) {
|
|
1732
|
+
log(`readings left for ${run.runId}: ${error.message}`);
|
|
1733
|
+
}
|
|
1734
|
+
if (!items.length) return;
|
|
1735
|
+
// Another computer's run: home, which holds the run, finds its thread (this copy may not have the run yet).
|
|
1736
|
+
if (machine.role === "worker") {
|
|
1737
|
+
void Promise.resolve(
|
|
1738
|
+
swarmBoard({
|
|
1739
|
+
command: "board.sense.left",
|
|
1740
|
+
agent: run.agent,
|
|
1741
|
+
run: run.runId,
|
|
1742
|
+
items: items.map(({ text, at, about }) => ({ text, at, about })),
|
|
1743
|
+
})
|
|
1744
|
+
).catch(() => {});
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
const thread = task?.parent_id ? store.getTask(task.parent_id) : null;
|
|
1748
|
+
if (thread?.kind === "goal") keepSensesLeft(thread.id, run.agent, items);
|
|
1749
|
+
else log(`readings left for ${run.runId} outside a thread: not kept`);
|
|
1750
|
+
};
|
|
1126
1751
|
// What an agent is told about a thread when it is woken, asked or given work there (threadBriefs.mjs).
|
|
1752
|
+
// Each agent's next step in each thread (nextStep.mjs): kept on home's board, which every computer copies.
|
|
1753
|
+
const nextSteps = createNextSteps({ store });
|
|
1754
|
+
// On home, kept here; from another computer, handed to home (board.next.keep).
|
|
1755
|
+
const keepNextStep = (thread, agent, step) =>
|
|
1756
|
+
machine.role === "worker"
|
|
1757
|
+
? void Promise.resolve(
|
|
1758
|
+
swarmBoard({ command: "board.next.keep", agent, thread, step })
|
|
1759
|
+
).catch(() => {})
|
|
1760
|
+
: nextSteps.keep(thread, agent, step);
|
|
1761
|
+
// What a woken agent reads first (wakePicture.mjs): why, how long it was away, what it said it would do next, and what
|
|
1762
|
+
// changed in its thread, from the log on this computer; the thread's folder is followed under the names below
|
|
1763
|
+
// (followThreadFolders).
|
|
1764
|
+
// The log's names (sources.mjs subjectFor) of what follows a thread's folder here: its files and its repository.
|
|
1765
|
+
const subjectsOfThread = (threadId) => {
|
|
1766
|
+
const thread = store.getTask(threadId);
|
|
1767
|
+
const folder = thread ? threadFolder(thread) : null;
|
|
1768
|
+
if (!folder) return [];
|
|
1769
|
+
const real = realFolder(folder);
|
|
1770
|
+
return [
|
|
1771
|
+
subjectFor({ kind: "files", folder: real }),
|
|
1772
|
+
subjectFor({ kind: "repository", folder: real }),
|
|
1773
|
+
];
|
|
1774
|
+
};
|
|
1775
|
+
// Which thread a happening of this computer touches, as a thread's wake picture reads them (nerves.mjs touches).
|
|
1776
|
+
// The folders' names are looked at again at most every half minute.
|
|
1777
|
+
let threadsBySubject = { at: 0, map: new Map() };
|
|
1778
|
+
const threadOfSubject = (subject) => {
|
|
1779
|
+
if (Date.now() - threadsBySubject.at > 30_000) {
|
|
1780
|
+
const map = new Map();
|
|
1781
|
+
for (const goal of store.goals())
|
|
1782
|
+
if (goal.status === "open")
|
|
1783
|
+
for (const each of subjectsOfThread(goal.id)) map.set(each, goal.id);
|
|
1784
|
+
threadsBySubject = { at: Date.now(), map };
|
|
1785
|
+
}
|
|
1786
|
+
return threadsBySubject.map.get(subject) ?? null;
|
|
1787
|
+
};
|
|
1788
|
+
const threadTouched = (happening) => {
|
|
1789
|
+
switch (happening.source) {
|
|
1790
|
+
case "run":
|
|
1791
|
+
case "thread-watch":
|
|
1792
|
+
case "stuck":
|
|
1793
|
+
case "reflex":
|
|
1794
|
+
case "watch-response":
|
|
1795
|
+
return happening.data?.thread ?? null;
|
|
1796
|
+
case "limits":
|
|
1797
|
+
return (
|
|
1798
|
+
/^limits\.spend\.(.+)$/.exec(happening.subject ?? "")?.[1] ?? null
|
|
1799
|
+
);
|
|
1800
|
+
case "files":
|
|
1801
|
+
case "repository":
|
|
1802
|
+
return threadOfSubject(happening.subject);
|
|
1803
|
+
case "senses": {
|
|
1804
|
+
const session = /^session:(.+)$/.exec(happening.subject ?? "")?.[1];
|
|
1805
|
+
return session ? threadOfSessionHere(session) : null;
|
|
1806
|
+
}
|
|
1807
|
+
default:
|
|
1808
|
+
return null;
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
const threadOfSessionHere = (session) =>
|
|
1812
|
+
store.db.get(
|
|
1813
|
+
"select parent_id from board_tasks where session_id = ? and parent_id is not null order by updated_at desc limit 1",
|
|
1814
|
+
[String(session)]
|
|
1815
|
+
)?.parent_id ?? null;
|
|
1816
|
+
// What arrived from another of the person's computers (nerves.mjs): its levels are facts about it on home (a
|
|
1817
|
+
// worker's board is home's copy), and a change to a file's original reaches the sessions here that read it.
|
|
1818
|
+
const arrived = (_from, happening) => {
|
|
1819
|
+
if (
|
|
1820
|
+
happening.source === "machine" &&
|
|
1821
|
+
happening.kind === "level" &&
|
|
1822
|
+
machine.role !== "worker"
|
|
1823
|
+
) {
|
|
1824
|
+
const { aspect, was: _was, ...value } = happening.data ?? {};
|
|
1825
|
+
if (aspect)
|
|
1826
|
+
facts.set(`machine.${aspect}`, value, {
|
|
1827
|
+
source: "machine",
|
|
1828
|
+
machine: happening.machine,
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
if (happening.source === "files" && happening.kind === "original changed")
|
|
1832
|
+
originals?.changedThere(happening);
|
|
1833
|
+
};
|
|
1834
|
+
// A thread's timeline (timeSense.mjs), from when it began; `until` stops it there.
|
|
1835
|
+
const timelineOf = (threadId, until = null) =>
|
|
1836
|
+
timeSense?.timeline(threadId, {
|
|
1837
|
+
began: store.getTask(threadId)?.created_at ?? null,
|
|
1838
|
+
until,
|
|
1839
|
+
}) ?? [];
|
|
1840
|
+
// Turns that began with something from outside (outsideRuns.mjs, S7.5): fewer rights until the person writes.
|
|
1841
|
+
const outsideRuns = createOutsideRuns({
|
|
1842
|
+
store,
|
|
1843
|
+
events,
|
|
1844
|
+
home: paths.home,
|
|
1845
|
+
threadFolder: (id) => {
|
|
1846
|
+
const thread = store.getTask(id);
|
|
1847
|
+
return thread ? threadFolder(thread) : null;
|
|
1848
|
+
},
|
|
1849
|
+
say: (id, text) => {
|
|
1850
|
+
const thread = store.getTask(id);
|
|
1851
|
+
if (thread?.goal) actions.say(thread, text);
|
|
1852
|
+
},
|
|
1853
|
+
grantsOf: (watch) => threadWatches.grantsOf(watch),
|
|
1854
|
+
});
|
|
1855
|
+
const picture = createWakePicture({
|
|
1856
|
+
store,
|
|
1857
|
+
events,
|
|
1858
|
+
outsideLine: (thread) => outsideRuns.briefLine(thread),
|
|
1859
|
+
nextSteps,
|
|
1860
|
+
timelineOf,
|
|
1861
|
+
machineCard: (agent) => senseTools.card(agent),
|
|
1862
|
+
computerOf: (id) =>
|
|
1863
|
+
String(id).startsWith("person:")
|
|
1864
|
+
? `${String(id).slice("person:".length)}'s computer`
|
|
1865
|
+
: (ownMachines?.labelOf(id) ?? null),
|
|
1866
|
+
// What Harness noticed while the agent last worked that no hook took (keepSensesLeft): the turn that starts with
|
|
1867
|
+
// them takes them, and its brief made again (a start tried again) has the same; a brief made before only looks.
|
|
1868
|
+
takeCarried: (thread, agent, wakeId) => {
|
|
1869
|
+
const read = (key) => {
|
|
1870
|
+
try {
|
|
1871
|
+
return JSON.parse(store.meta(key) || "null");
|
|
1872
|
+
} catch {
|
|
1873
|
+
return null;
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
const key = `carried-senses:${thread}:${agent}`;
|
|
1877
|
+
if (!wakeId) return read(key) ?? [];
|
|
1878
|
+
const given = read(`carried-given:${wakeId}`);
|
|
1879
|
+
if (given) return given;
|
|
1880
|
+
const carried = read(key) ?? [];
|
|
1881
|
+
if (carried.length) {
|
|
1882
|
+
store.meta(`carried-given:${wakeId}`, JSON.stringify(carried));
|
|
1883
|
+
store.meta(key, "");
|
|
1884
|
+
}
|
|
1885
|
+
return carried;
|
|
1886
|
+
},
|
|
1887
|
+
subjectsOf: (threadId) => subjectsOfThread(threadId),
|
|
1888
|
+
});
|
|
1127
1889
|
const briefs = createThreadBriefs({
|
|
1128
1890
|
store,
|
|
1129
1891
|
goals,
|
|
1130
1892
|
teams,
|
|
1131
|
-
|
|
1893
|
+
jams: () => jams,
|
|
1132
1894
|
files: boardFiles,
|
|
1133
1895
|
runsHere: (agent) => RUNNERS.has(agent),
|
|
1134
1896
|
computerOf,
|
|
1135
1897
|
agentText,
|
|
1898
|
+
picture,
|
|
1899
|
+
noteOf: (thread) => threadNotes.noteOf(thread),
|
|
1900
|
+
standingOf: (agent) =>
|
|
1901
|
+
authority.standingRules().find((rule) => rule.agent === agent) ?? null,
|
|
1136
1902
|
});
|
|
1137
1903
|
// A thread's coding agent works in T3 Code when the person uses it there: its home is T3, Harness may send into T3,
|
|
1138
1904
|
// T3 is open with a project for the thread's folder, and the agent has run in T3 before (its model there is the
|
|
@@ -1143,10 +1909,22 @@ export async function startDaemon() {
|
|
|
1143
1909
|
store,
|
|
1144
1910
|
root: path.join(paths.home, "worktrees"),
|
|
1145
1911
|
});
|
|
1912
|
+
// The folder a thread's agents work in on this computer: its copy, or the folder it names until it has one.
|
|
1913
|
+
const threadFolder = (thread) => {
|
|
1914
|
+
const folder = thread.goal?.workspace;
|
|
1915
|
+
if (!folder) return null;
|
|
1916
|
+
const tree = worktrees.record(thread.id);
|
|
1917
|
+
if (tree?.state === "open" && tree.path && fs.existsSync(tree.path))
|
|
1918
|
+
return path.join(tree.path, tree.inside ?? "");
|
|
1919
|
+
if (tree?.state === "t3" && tree.path && fs.existsSync(tree.path))
|
|
1920
|
+
return tree.path;
|
|
1921
|
+
return fs.existsSync(folder) ? folder : null;
|
|
1922
|
+
};
|
|
1146
1923
|
const taskRooms = createTaskRooms({
|
|
1147
1924
|
store,
|
|
1148
1925
|
worktrees,
|
|
1149
1926
|
runsHere: (agent) => RUNNERS.has(agent),
|
|
1927
|
+
self: () => machine.id,
|
|
1150
1928
|
notifyBoard: (task) => notifyBoard(task),
|
|
1151
1929
|
});
|
|
1152
1930
|
// What threads put into the world: landed and in-review pull requests, and work not out yet.
|
|
@@ -1158,12 +1936,13 @@ export async function startDaemon() {
|
|
|
1158
1936
|
outside: () => environments,
|
|
1159
1937
|
log,
|
|
1160
1938
|
});
|
|
1161
|
-
//
|
|
1162
|
-
let
|
|
1939
|
+
// The jams the person is in (jams.mjs), made once the relay is (below), on their sealed store (jamStore).
|
|
1940
|
+
let jams = null;
|
|
1941
|
+
let jamStore = null;
|
|
1163
1942
|
const verdicts = createVerdicts({
|
|
1164
1943
|
store,
|
|
1165
1944
|
log,
|
|
1166
|
-
|
|
1945
|
+
jams: () => jams,
|
|
1167
1946
|
team: teams,
|
|
1168
1947
|
wakeRun: (...args) => threadRuns.wake(...args),
|
|
1169
1948
|
});
|
|
@@ -1174,12 +1953,13 @@ export async function startDaemon() {
|
|
|
1174
1953
|
: stopAgentTask(run.id);
|
|
1175
1954
|
const threadRuns = createThreadRuns({
|
|
1176
1955
|
reported: (thread, post) => void manager.reported(thread, post),
|
|
1956
|
+
nextSteps: { keep: keepNextStep },
|
|
1177
1957
|
store,
|
|
1178
1958
|
log,
|
|
1179
1959
|
installedAgents,
|
|
1180
1960
|
authority,
|
|
1181
1961
|
worktrees,
|
|
1182
|
-
|
|
1962
|
+
jams: () => jams,
|
|
1183
1963
|
verdicts,
|
|
1184
1964
|
notifyBoard: (task) => notifyBoard(task),
|
|
1185
1965
|
swarmBrief: briefs.swarmBrief,
|
|
@@ -1188,6 +1968,7 @@ export async function startDaemon() {
|
|
|
1188
1968
|
restrictedWait: threadAuthority.restrictedWait,
|
|
1189
1969
|
pauseGoal: (...args) => actions.pause(...args),
|
|
1190
1970
|
homeOf: (...args) => homeOf(...args),
|
|
1971
|
+
placesOf: (...args) => placesOf(...args),
|
|
1191
1972
|
placeElsewhere: (agent, workspace) =>
|
|
1192
1973
|
ownMachines?.placeElsewhere(agent, workspace) ?? null,
|
|
1193
1974
|
threadFiles: (thread) => boardFiles.threadFiles(thread).files,
|
|
@@ -1205,6 +1986,7 @@ export async function startDaemon() {
|
|
|
1205
1986
|
ownMachines?.placeOn(agent, workspace, id) ?? {
|
|
1206
1987
|
error: "your other computers are not reachable",
|
|
1207
1988
|
},
|
|
1989
|
+
runsWorkIn: (id, folder) => ownMachines?.runsWorkIn(id, folder) ?? false,
|
|
1208
1990
|
labelOf: (id) => ownMachines?.labelOf(id) ?? null,
|
|
1209
1991
|
withAgent: (agent) =>
|
|
1210
1992
|
(ownMachines?.all() ?? [])
|
|
@@ -1217,6 +1999,8 @@ export async function startDaemon() {
|
|
|
1217
1999
|
// Harness's tasks in threads, taken by its server while no Harness window is open (harnessOffers.mjs).
|
|
1218
2000
|
const harnessOffers = createHarnessOffers({
|
|
1219
2001
|
store,
|
|
2002
|
+
// The person allowed Harness's call to a moved app here: that exact call goes ahead when it comes (connectors.mjs).
|
|
2003
|
+
approvedCall: (tool, input) => connectors.approveCall(tool, input),
|
|
1220
2004
|
askHarness,
|
|
1221
2005
|
connected: () => state.connected,
|
|
1222
2006
|
serverHas: (feature) => bridge.has(feature),
|
|
@@ -1227,6 +2011,9 @@ export async function startDaemon() {
|
|
|
1227
2011
|
lane: harnessLane,
|
|
1228
2012
|
model: harnessModel,
|
|
1229
2013
|
files: boardFiles,
|
|
2014
|
+
postAsk: () => actions.postAsk,
|
|
2015
|
+
runRequests: () => nativeRequests,
|
|
2016
|
+
send: (message) => send(message),
|
|
1230
2017
|
});
|
|
1231
2018
|
// Waking, asking and saying things in a thread (threadActions.mjs).
|
|
1232
2019
|
const actions = createThreadActions({
|
|
@@ -1250,6 +2037,7 @@ export async function startDaemon() {
|
|
|
1250
2037
|
boardCommand: () => boardCommand,
|
|
1251
2038
|
ownMachines: () => ownMachines,
|
|
1252
2039
|
threadView: () => threadView,
|
|
2040
|
+
readingsOf: (thread) => threadWatches.readingsOf(thread),
|
|
1253
2041
|
});
|
|
1254
2042
|
const asks = createAsks({
|
|
1255
2043
|
store,
|
|
@@ -1272,7 +2060,7 @@ export async function startDaemon() {
|
|
|
1272
2060
|
? store.meta(`harness-wait:${earlier.id}`)
|
|
1273
2061
|
: null;
|
|
1274
2062
|
return harnessWait
|
|
1275
|
-
? `Its earlier ask waits
|
|
2063
|
+
? `Its earlier ask waits: ${harnessWait}.`
|
|
1276
2064
|
: earlier
|
|
1277
2065
|
? setupNote(agent)
|
|
1278
2066
|
: null;
|
|
@@ -1302,6 +2090,22 @@ export async function startDaemon() {
|
|
|
1302
2090
|
: taskRuns.lastStepAt(taskId);
|
|
1303
2091
|
},
|
|
1304
2092
|
report: actions.tellStuck,
|
|
2093
|
+
// A run whose session is running a known long command waits for it past its usual, not the flat half hour, when
|
|
2094
|
+
// that is sooner (owner, November 14: "agreed with 3"; timeSense.mjs).
|
|
2095
|
+
usualOf: (task) => {
|
|
2096
|
+
const running = task.session_id
|
|
2097
|
+
? timeSense?.runningLong(task.session_id)
|
|
2098
|
+
: null;
|
|
2099
|
+
return running
|
|
2100
|
+
? {
|
|
2101
|
+
ms: TOO_LONG_TIMES * running.usualMs,
|
|
2102
|
+
usualMs: running.usualMs,
|
|
2103
|
+
what: running.kind,
|
|
2104
|
+
}
|
|
2105
|
+
: null;
|
|
2106
|
+
},
|
|
2107
|
+
// Each finding on the log too, found and cleared, for the picture an agent woken in its thread reads.
|
|
2108
|
+
events,
|
|
1305
2109
|
thresholds: stuckThresholds(),
|
|
1306
2110
|
});
|
|
1307
2111
|
loopBackstop = createLoopBackstop({
|
|
@@ -1336,12 +2140,10 @@ export async function startDaemon() {
|
|
|
1336
2140
|
// One dispatcher per swarm, on whichever computer is home (owner, November 1): the pick is kept on the board, which
|
|
1337
2141
|
// follows home, and only the computer holding the board downloads the local model. A pick made before it was kept
|
|
1338
2142
|
// there (this computer's config) moves onto the board once.
|
|
1339
|
-
const configPick =
|
|
2143
|
+
const configPick = readConfig(paths.config, {}).dispatcher ?? null;
|
|
1340
2144
|
if (configPick && holdsBoard() && !store.boardSetting("dispatcher")) {
|
|
1341
2145
|
store.setBoardSetting("dispatcher", configPick);
|
|
1342
|
-
|
|
1343
|
-
delete config.dispatcher;
|
|
1344
|
-
writeJsonAtomic(paths.config, config);
|
|
2146
|
+
updateConfig(paths.config, ({ dispatcher: _moved, ...config }) => config);
|
|
1345
2147
|
}
|
|
1346
2148
|
const dispatcher = createDispatcher({
|
|
1347
2149
|
root: path.join(paths.home, "local"),
|
|
@@ -1349,12 +2151,38 @@ export async function startDaemon() {
|
|
|
1349
2151
|
write: (value) => store.setBoardSetting("dispatcher", value),
|
|
1350
2152
|
inference: local.inference,
|
|
1351
2153
|
wanted: () =>
|
|
1352
|
-
holdsBoard() &&
|
|
2154
|
+
holdsBoard() && mayDownloadModel(readConfig(paths.config, {})),
|
|
1353
2155
|
installedAgents: () => installedAgents,
|
|
1354
2156
|
askHarness,
|
|
1355
2157
|
log,
|
|
1356
2158
|
});
|
|
1357
2159
|
dispatcher.warm();
|
|
2160
|
+
// What sleep proposes (proposals.mjs, S8.4): replayed on the record, run only once the person starts it.
|
|
2161
|
+
const proposals = createProposals({
|
|
2162
|
+
store,
|
|
2163
|
+
watchesLetPass: () => sleep.letPass(),
|
|
2164
|
+
setResponse: (id, response) => threadWatches.setResponse(id, response),
|
|
2165
|
+
setCondition: (id, condition) => threadWatches.setCondition(id, condition),
|
|
2166
|
+
retireLesson: (id, why) => store.retireLesson(id, why),
|
|
2167
|
+
});
|
|
2168
|
+
if (holdsBoard()) proposals.fromSleep();
|
|
2169
|
+
// A thread's notes (threadNotes.mjs, S8.2): the posts a brief no longer carries, folded on this computer.
|
|
2170
|
+
const threadNotes = createThreadNotes({
|
|
2171
|
+
store,
|
|
2172
|
+
// Where Harness reads for the memory, as the dream does; never on the privacy setting.
|
|
2173
|
+
askNotes: () =>
|
|
2174
|
+
harnessReads("swarm_memory")
|
|
2175
|
+
? (input) =>
|
|
2176
|
+
askHarness("thread_notes", input, 120_000).then((reply) =>
|
|
2177
|
+
reply?.ok === false ? null : (reply?.result ?? reply)
|
|
2178
|
+
)
|
|
2179
|
+
: null,
|
|
2180
|
+
log,
|
|
2181
|
+
});
|
|
2182
|
+
// As it starts, too (a computer that was off at night folds then), once the daemon is all made.
|
|
2183
|
+
setImmediate(() => {
|
|
2184
|
+
if (holdsBoard()) void threadNotes.fold().catch(() => undefined);
|
|
2185
|
+
});
|
|
1358
2186
|
// The swarm's manager (manager.mjs): the person's asks, kept to their words, judged by the dispatcher.
|
|
1359
2187
|
const manager = createManager({
|
|
1360
2188
|
store,
|
|
@@ -1363,6 +2191,12 @@ export async function startDaemon() {
|
|
|
1363
2191
|
settled: (threadId) => coordinator.resumed(threadId),
|
|
1364
2192
|
computerAddress: actions.computerAddress,
|
|
1365
2193
|
agentsIn: (text) => mentionsIn(text, ROOM_AGENTS),
|
|
2194
|
+
// Jev judges results, unless the person keeps their threads off Harness's server or that server doesn't judge.
|
|
2195
|
+
resultsJudge: () => {
|
|
2196
|
+
if (coordinatorMode() === "local") return null;
|
|
2197
|
+
if (state.connected && !bridge.has("swarm_manager")) return null;
|
|
2198
|
+
return (input) => askHarness("manage", input);
|
|
2199
|
+
},
|
|
1366
2200
|
handOn: handOnAgent,
|
|
1367
2201
|
post: (entry) => {
|
|
1368
2202
|
const posted = store.roomPost(entry);
|
|
@@ -1415,7 +2249,11 @@ export async function startDaemon() {
|
|
|
1415
2249
|
swarmAgents: () => available(),
|
|
1416
2250
|
readsLessons: () => harnessReads("swarm_lessons"),
|
|
1417
2251
|
isCoordinatorPost,
|
|
1418
|
-
|
|
2252
|
+
// A round waits on a query: on the background lane it queued behind the whole index.
|
|
2253
|
+
embed: (texts, kind) =>
|
|
2254
|
+
local.embed(texts, kind, {
|
|
2255
|
+
lane: kind === "query" ? "interactive" : "background",
|
|
2256
|
+
}),
|
|
1419
2257
|
log,
|
|
1420
2258
|
});
|
|
1421
2259
|
// The swarm's long-running memory (swarmMemory.mjs): recall for search and briefs, what the person's posts replace or
|
|
@@ -1423,11 +2261,11 @@ export async function startDaemon() {
|
|
|
1423
2261
|
const memory = createSwarmMemory({
|
|
1424
2262
|
store,
|
|
1425
2263
|
askHarness,
|
|
2264
|
+
proposeRetire: (lesson, why) => proposals.retireOffer(lesson, why),
|
|
1426
2265
|
// What the person saw, read from their Harness window at each dream (askWindows is made below, used later).
|
|
1427
2266
|
seenMemory: createSeen({
|
|
1428
2267
|
store,
|
|
1429
2268
|
askWindows: (call) => askWindows(call),
|
|
1430
|
-
canAsk: () => state.connected && bridge.has("sealed_ask"),
|
|
1431
2269
|
log,
|
|
1432
2270
|
}),
|
|
1433
2271
|
readsMemory: () => harnessReads("swarm_memory"),
|
|
@@ -1462,7 +2300,7 @@ export async function startDaemon() {
|
|
|
1462
2300
|
.then((report) => {
|
|
1463
2301
|
if (report.ok)
|
|
1464
2302
|
log(
|
|
1465
|
-
`dream: read ${report.read}, kept ${report.kept.length}, changed ${report.changed.length},
|
|
2303
|
+
`dream: read ${report.read}, kept ${report.kept.length}, changed ${report.changed.length}, proposed ${report.proposed?.length ?? 0} lesson(s) to retire, widened ${report.widened.length}`
|
|
1466
2304
|
);
|
|
1467
2305
|
})
|
|
1468
2306
|
.catch((error) => log(`dream: ${error.message}`));
|
|
@@ -1471,6 +2309,8 @@ export async function startDaemon() {
|
|
|
1471
2309
|
// Everything the person writes in a thread is read for their reaction to the work before it, for lessons, and for what
|
|
1472
2310
|
// it changes in the memory.
|
|
1473
2311
|
const heardPerson = (thread, post) => {
|
|
2312
|
+
// The person's own words end the fewer rights of a turn that began outside (outsideRuns.mjs).
|
|
2313
|
+
outsideRuns.of(thread.id);
|
|
1474
2314
|
void manager.heard(thread, post);
|
|
1475
2315
|
void reactions.heard(thread, post);
|
|
1476
2316
|
void lessons.heard(thread, post);
|
|
@@ -1481,7 +2321,7 @@ export async function startDaemon() {
|
|
|
1481
2321
|
heardRelayed: (thread, post) => void manager.heard(thread, post),
|
|
1482
2322
|
computerOf,
|
|
1483
2323
|
teams,
|
|
1484
|
-
learned: (goalId, agent, text) =>
|
|
2324
|
+
learned: (goalId, agent, text) => jams?.learned(goalId, agent, text),
|
|
1485
2325
|
remembered: (thread, agent, note) => void memory.push(thread, agent, note),
|
|
1486
2326
|
DEFAULT_MAX_POSTS,
|
|
1487
2327
|
DEFAULT_MAX_WAKES,
|
|
@@ -1489,7 +2329,6 @@ export async function startDaemon() {
|
|
|
1489
2329
|
ROOM_AGENTS,
|
|
1490
2330
|
available,
|
|
1491
2331
|
getActiveRuns: () => activeRuns,
|
|
1492
|
-
endGuestThreads: sealed.endGuests,
|
|
1493
2332
|
getFirewall: () => local.firewall,
|
|
1494
2333
|
flagNote: briefs.flagNote,
|
|
1495
2334
|
agentText,
|
|
@@ -1500,17 +2339,18 @@ export async function startDaemon() {
|
|
|
1500
2339
|
mentionsIn,
|
|
1501
2340
|
notifyBoard,
|
|
1502
2341
|
pauseGoal: actions.pause,
|
|
1503
|
-
relayRequest: sealed.request,
|
|
1504
2342
|
replaceHeld,
|
|
1505
|
-
sendThreadMessage: sealed.sendMessage,
|
|
1506
2343
|
setupNote,
|
|
1507
|
-
state,
|
|
1508
2344
|
store,
|
|
1509
2345
|
swarmCommand: (...args) => swarmCommand(...args),
|
|
1510
2346
|
validAgent,
|
|
1511
2347
|
wakeFor: actions.wakeFor,
|
|
1512
2348
|
computerAddress: actions.computerAddress,
|
|
1513
|
-
resumed: (id) =>
|
|
2349
|
+
resumed: (id) => {
|
|
2350
|
+
coordinator.resumed(id);
|
|
2351
|
+
// A one-time check-in held while the thread was paused runs now (schedules.mjs).
|
|
2352
|
+
schedules.tick();
|
|
2353
|
+
},
|
|
1514
2354
|
files: boardFiles,
|
|
1515
2355
|
});
|
|
1516
2356
|
|
|
@@ -1536,7 +2376,7 @@ export async function startDaemon() {
|
|
|
1536
2376
|
// Who coordinates the swarm's threads, as the person picked (owner, October 26: the person picks, Harness stays the
|
|
1537
2377
|
// default). "harness": rounds go to Harness, Jev decides. "local", or a coding agent's id (LOCAL_DECIDERS): an agent on
|
|
1538
2378
|
// this machine decides with its tools off, that one first; nothing in a thread goes to Harness.
|
|
1539
|
-
const coordinatorSetting = () =>
|
|
2379
|
+
const coordinatorSetting = () => readConfig(paths.config, {}).coordinator;
|
|
1540
2380
|
const coordinatorMode = () =>
|
|
1541
2381
|
coordinatorSetting() === "local" ||
|
|
1542
2382
|
LOCAL_DECIDERS.includes(coordinatorSetting())
|
|
@@ -1545,10 +2385,10 @@ export async function startDaemon() {
|
|
|
1545
2385
|
const coordinatorPick = () =>
|
|
1546
2386
|
LOCAL_DECIDERS.includes(coordinatorSetting()) ? coordinatorSetting() : null;
|
|
1547
2387
|
const setCoordinatorMode = (mode) =>
|
|
1548
|
-
|
|
1549
|
-
...
|
|
2388
|
+
updateConfig(paths.config, (saved) => ({
|
|
2389
|
+
...saved,
|
|
1550
2390
|
coordinator: mode,
|
|
1551
|
-
});
|
|
2391
|
+
}));
|
|
1552
2392
|
// The model each run starts with (models.mjs). Auto asks Harness, never on the privacy setting, and only a Harness that
|
|
1553
2393
|
// said it can pick models: one from before that would leave the run waiting for an answer that never comes.
|
|
1554
2394
|
// The agents on Harness's own AI, pointed at Harness's gateway in their own settings with every model the person's
|
|
@@ -1675,15 +2515,160 @@ export async function startDaemon() {
|
|
|
1675
2515
|
return null;
|
|
1676
2516
|
}
|
|
1677
2517
|
};
|
|
2518
|
+
// A command to the watch table on home (threadWatches.mjs: keep, go, drop), from here or from a worker.
|
|
2519
|
+
const watchboardAtHome = async (request) => {
|
|
2520
|
+
const result =
|
|
2521
|
+
machine.role === "worker"
|
|
2522
|
+
? swarmBoard(request)
|
|
2523
|
+
: boardCommand({ ...request, [WATCH_KEEPER]: true });
|
|
2524
|
+
return (
|
|
2525
|
+
(await (result?.pending ?? result)) ?? {
|
|
2526
|
+
ok: false,
|
|
2527
|
+
error: "home did not answer",
|
|
2528
|
+
}
|
|
2529
|
+
);
|
|
2530
|
+
};
|
|
2531
|
+
// A watch's or a check-in's wake (watchResponses.mjs): a check-in's post as the thread's lead; the wake count started
|
|
2532
|
+
// again for one caused from outside the thread, as a check-in always did; then the agents woken with the go of
|
|
2533
|
+
// whoever set it (the dispatcher's for an agent's own watch, which wakes only that agent), or the lead's round.
|
|
2534
|
+
const wakeForWatch = ({
|
|
2535
|
+
thread,
|
|
2536
|
+
agents,
|
|
2537
|
+
round,
|
|
2538
|
+
text,
|
|
2539
|
+
why,
|
|
2540
|
+
by,
|
|
2541
|
+
own,
|
|
2542
|
+
posts,
|
|
2543
|
+
causes = [],
|
|
2544
|
+
}) => {
|
|
2545
|
+
const goal = store.getTask(thread);
|
|
2546
|
+
if (!goal?.goal) throw new Error("the thread is gone");
|
|
2547
|
+
// A wake that began with something from outside gives the turn fewer rights (S7.5).
|
|
2548
|
+
const outside = outsideRuns.trace(causes);
|
|
2549
|
+
if (outside) outsideRuns.mark(thread, outside);
|
|
2550
|
+
const lead = goal.goal.facilitator;
|
|
2551
|
+
for (const post of posts) {
|
|
2552
|
+
const made = store.roomPost({
|
|
2553
|
+
goalId: thread,
|
|
2554
|
+
author: lead,
|
|
2555
|
+
kind: "check_in",
|
|
2556
|
+
text: post.text,
|
|
2557
|
+
mentions: post.mentions,
|
|
2558
|
+
});
|
|
2559
|
+
if (made) store.meta(`coordinator-post:${made.id}`, "1");
|
|
2560
|
+
}
|
|
2561
|
+
if (!own) store.meta(`check-in-at:${thread}`, new Date().toISOString());
|
|
2562
|
+
const author = by === "user" ? "user" : by === "lead" ? lead : DISPATCHER;
|
|
2563
|
+
const told = agents.length
|
|
2564
|
+
? actions.wakeFor(
|
|
2565
|
+
thread,
|
|
2566
|
+
{ text, kind: "post", mentions: agents },
|
|
2567
|
+
author,
|
|
2568
|
+
agents,
|
|
2569
|
+
{ why, causes }
|
|
2570
|
+
)
|
|
2571
|
+
: [];
|
|
2572
|
+
if (round) coordinator.poke(thread);
|
|
2573
|
+
notifyBoard(store.getTask(thread));
|
|
2574
|
+
// What became of it, when not a turn: the thread stopped at its wake limit, or why an agent was not woken.
|
|
2575
|
+
const status = store.getTask(thread)?.status;
|
|
2576
|
+
if (status && status !== "open") return `the thread is ${status} now`;
|
|
2577
|
+
return told.length ? told.join(" ") : null;
|
|
2578
|
+
};
|
|
2579
|
+
// What a watch or a check-in does when it trips (watchResponses.mjs): set a fact, tell the person, tap an agent at
|
|
2580
|
+
// its next step, or wake agents; written down first and carried out once. A worker hands a fact or a wake to home.
|
|
2581
|
+
// Attention (attention.mjs, S9.1): a briefed watch's trip, read by the dispatcher's model on this computer.
|
|
2582
|
+
const attention = createAttention({
|
|
2583
|
+
ask: (context) => dispatcher.attend(context),
|
|
2584
|
+
log,
|
|
2585
|
+
});
|
|
2586
|
+
const responses = createWatchResponses({
|
|
2587
|
+
store,
|
|
2588
|
+
events,
|
|
2589
|
+
maxHops: MAX_HANDOFFS,
|
|
2590
|
+
log,
|
|
2591
|
+
protect: (response, fire) => reflexes.protect(response, fire),
|
|
2592
|
+
isHome: () => machine.role !== "worker",
|
|
2593
|
+
toHome: async (fire) => {
|
|
2594
|
+
const sent = swarmBoard({
|
|
2595
|
+
command: "board.watch.answer",
|
|
2596
|
+
agent: "user",
|
|
2597
|
+
...fire,
|
|
2598
|
+
});
|
|
2599
|
+
return await (sent?.pending ?? sent);
|
|
2600
|
+
},
|
|
2601
|
+
notify: (text) => notices.notify(text),
|
|
2602
|
+
wake: wakeForWatch,
|
|
2603
|
+
// A note the agent's own hook reads at its next step (steerQueue.mjs), for the session's own model.
|
|
2604
|
+
tappable,
|
|
2605
|
+
tap: (running, words) => {
|
|
2606
|
+
try {
|
|
2607
|
+
putSteer({
|
|
2608
|
+
session: running.session,
|
|
2609
|
+
agent: PARENT,
|
|
2610
|
+
kind: SENSE,
|
|
2611
|
+
text: words,
|
|
2612
|
+
// Left untaken when the run ends, it wakes the agent as it would have (sensesLeft).
|
|
2613
|
+
about: { wakes: true },
|
|
2614
|
+
});
|
|
2615
|
+
return true;
|
|
2616
|
+
} catch (error) {
|
|
2617
|
+
log(`watch tap: ${error.message}`);
|
|
2618
|
+
return false;
|
|
2619
|
+
}
|
|
2620
|
+
},
|
|
2621
|
+
setFact: (key, value, options) => facts.set(key, value, options),
|
|
2622
|
+
workingIn: (thread, agent) => {
|
|
2623
|
+
for (const run of taskRuns.running()) {
|
|
2624
|
+
if (run.agent !== agent) continue;
|
|
2625
|
+
const task = store.getTask(run.runId);
|
|
2626
|
+
if (task?.parent_id === thread && task.session_id)
|
|
2627
|
+
return { session: task.session_id, agent };
|
|
2628
|
+
}
|
|
2629
|
+
return null;
|
|
2630
|
+
},
|
|
2631
|
+
teamOf: (thread) => store.getTask(thread)?.goal?.team ?? [],
|
|
2632
|
+
// Attention reads a briefed watch's trip first (S9.1), on the dispatcher's model here.
|
|
2633
|
+
attend: (input) => attention.judge(input),
|
|
2634
|
+
cardOf: (agent) => {
|
|
2635
|
+
const record = swarmCards(store, [{ id: agent }])[0]?.record;
|
|
2636
|
+
return {
|
|
2637
|
+
id: agent,
|
|
2638
|
+
good_at: agentSpecialties(store, agent).specialties.map(
|
|
2639
|
+
(each) => each.specialty ?? each
|
|
2640
|
+
),
|
|
2641
|
+
...(record?.done || record?.failed
|
|
2642
|
+
? {
|
|
2643
|
+
record: {
|
|
2644
|
+
done: record.done,
|
|
2645
|
+
failed: record.failed,
|
|
2646
|
+
...(record.verdicts ? { verdicts: record.verdicts } : {}),
|
|
2647
|
+
...(record.cost
|
|
2648
|
+
? { median_tokens_a_run: record.cost.medianTokens }
|
|
2649
|
+
: {}),
|
|
2650
|
+
},
|
|
2651
|
+
}
|
|
2652
|
+
: {}),
|
|
2653
|
+
};
|
|
2654
|
+
},
|
|
2655
|
+
statusOf: (thread) => {
|
|
2656
|
+
const goal = store.getTask(thread);
|
|
2657
|
+
return goal?.removed_at ? "removed" : (goal?.status ?? null);
|
|
2658
|
+
},
|
|
2659
|
+
});
|
|
2660
|
+
reflexes.useTable(responses);
|
|
1678
2661
|
// Watches (watches.mjs): the person's, and agents' suggestions once the person starts them. An alert is a desktop
|
|
1679
2662
|
// notification at once; the buddy says it out loud when the person is at the computer and not in a call.
|
|
1680
2663
|
const watches = createWatches({
|
|
1681
2664
|
store,
|
|
2665
|
+
sources,
|
|
2666
|
+
events,
|
|
1682
2667
|
log,
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
2668
|
+
machineId: machine.id,
|
|
2669
|
+
atHome: watchboardAtHome,
|
|
2670
|
+
responses,
|
|
2671
|
+
notify: (text) => notices.notify(text),
|
|
1687
2672
|
});
|
|
1688
2673
|
// Code for an agent elsewhere leaves only with the person's OK (snippets.mjs).
|
|
1689
2674
|
const snippets = createSnippets({
|
|
@@ -1736,59 +2721,56 @@ export async function startDaemon() {
|
|
|
1736
2721
|
wake: (goalId, post, names) =>
|
|
1737
2722
|
actions.wakeFor(goalId, post, DISPATCHER, names),
|
|
1738
2723
|
notify: (text) => {
|
|
1739
|
-
|
|
2724
|
+
events.append({ source: "snippet", kind: "snippet", text });
|
|
1740
2725
|
notices.notify(text);
|
|
1741
2726
|
},
|
|
1742
2727
|
});
|
|
1743
|
-
|
|
1744
|
-
//
|
|
1745
|
-
//
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
const
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
}
|
|
1761
|
-
const presenceTimer = setInterval(notePresence, 60_000);
|
|
1762
|
-
presenceTimer.unref?.();
|
|
1763
|
-
// Check-ins (schedules.mjs): a run posts in the thread as its lead and wakes the agents it names, on the person's go
|
|
1764
|
-
// when the person set it and the lead's when the lead did; one that names none gives the lead a round.
|
|
1765
|
-
const checkIn = (schedule, { late }) => {
|
|
1766
|
-
const thread = store.getTask(schedule.threadId);
|
|
1767
|
-
const lead = thread.goal.facilitator;
|
|
2728
|
+
// Whether the person is at the computer and in a call (presence.mjs, from environment.mjs once a minute): away after
|
|
2729
|
+
// 20 minutes without input, back at the next input, each said in this computer's log. The buddy shows what happened
|
|
2730
|
+
// meanwhile when they come back.
|
|
2731
|
+
// Set once cleanup is made (below): the person going away is when the day's trim may run.
|
|
2732
|
+
let personAway = () => {};
|
|
2733
|
+
const presenceSense = createPresence({
|
|
2734
|
+
sources,
|
|
2735
|
+
events,
|
|
2736
|
+
read: () => environment.person(),
|
|
2737
|
+
onAway: () => personAway(),
|
|
2738
|
+
});
|
|
2739
|
+
const presence = presenceSense.presence;
|
|
2740
|
+
const notePresence = () => presenceSense.lookNow();
|
|
2741
|
+
presenceSense.start();
|
|
2742
|
+
// Check-ins (schedules.mjs): a run is a wake through the response table (wakeForWatch): it posts in the thread as its
|
|
2743
|
+
// lead and wakes the agents it names, on the person's go when the person set it and the lead's when the lead did; one
|
|
2744
|
+
// that names none gives the lead a round.
|
|
2745
|
+
const checkIn = (schedule, { late, cause }) => {
|
|
1768
2746
|
const setBy = schedule.by === "user" ? "you set" : "the lead set";
|
|
1769
2747
|
// Named in the words too, as an @mention is: the thread shows who it is for, and Harness takes the person's ask by it.
|
|
1770
2748
|
const named = schedule.agents.map((agent) => `@${agent} `).join("");
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
2749
|
+
responses.fire({
|
|
2750
|
+
watch: {
|
|
2751
|
+
id: schedule.id,
|
|
2752
|
+
thread: schedule.threadId,
|
|
2753
|
+
response: {
|
|
2754
|
+
do: "wake",
|
|
2755
|
+
agents: schedule.agents,
|
|
2756
|
+
by: schedule.by,
|
|
2757
|
+
post: true,
|
|
2758
|
+
},
|
|
2759
|
+
},
|
|
2760
|
+
edge: "due",
|
|
1775
2761
|
text: `${named}Check-in ${setBy} (${schedule.when}): ${schedule.what}${late ? ` It was due at ${late} and ran when the relay was back.` : ""}`,
|
|
1776
|
-
|
|
2762
|
+
cause,
|
|
2763
|
+
own: false,
|
|
1777
2764
|
});
|
|
1778
|
-
if (post) store.meta(`coordinator-post:${post.id}`, "1");
|
|
1779
|
-
store.meta(`check-in-at:${thread.id}`, new Date().toISOString());
|
|
1780
|
-
if (schedule.agents.length)
|
|
1781
|
-
actions.wakeFor(
|
|
1782
|
-
thread.id,
|
|
1783
|
-
{ ...post, kind: "post" },
|
|
1784
|
-
schedule.by === "user" ? "user" : lead,
|
|
1785
|
-
schedule.agents,
|
|
1786
|
-
{ why: `a check-in ${setBy} for this thread` }
|
|
1787
|
-
);
|
|
1788
|
-
else coordinator.poke(thread.id);
|
|
1789
|
-
notifyBoard(store.getTask(thread.id));
|
|
1790
2765
|
};
|
|
1791
|
-
const schedules = createSchedules({
|
|
2766
|
+
const schedules = createSchedules({
|
|
2767
|
+
store,
|
|
2768
|
+
log,
|
|
2769
|
+
fire: checkIn,
|
|
2770
|
+
sources,
|
|
2771
|
+
machineId: machine.id,
|
|
2772
|
+
isHome: () => machine.role !== "worker",
|
|
2773
|
+
});
|
|
1792
2774
|
// The board's finished days as anonymous totals, from home only (usageTotals.mjs).
|
|
1793
2775
|
const usageTotals = createUsageTotals({
|
|
1794
2776
|
store,
|
|
@@ -1798,7 +2780,7 @@ export async function startDaemon() {
|
|
|
1798
2780
|
state.connected &&
|
|
1799
2781
|
bridge.has("usage_totals") &&
|
|
1800
2782
|
machine.role !== "worker",
|
|
1801
|
-
enabled: () =>
|
|
2783
|
+
enabled: () => readConfig(paths.config, {}).usageTotals !== false,
|
|
1802
2784
|
});
|
|
1803
2785
|
// An ask lost on the way to Harness while this computer stayed connected goes again (asks.mjs).
|
|
1804
2786
|
const askRetry = setInterval(() => asks.retry(), 60_000);
|
|
@@ -1854,14 +2836,17 @@ export async function startDaemon() {
|
|
|
1854
2836
|
log,
|
|
1855
2837
|
});
|
|
1856
2838
|
const coordinator = createCoordinator({
|
|
2839
|
+
goalWritten: (thread) => manager.goalWritten(thread),
|
|
1857
2840
|
dispatcher,
|
|
2841
|
+
filePath: namedPath,
|
|
1858
2842
|
moves,
|
|
1859
2843
|
holdsBoard,
|
|
1860
2844
|
store,
|
|
1861
2845
|
serverWords,
|
|
1862
2846
|
pick: coordinatorPick,
|
|
1863
2847
|
lessons,
|
|
1864
|
-
|
|
2848
|
+
fromAnotherPerson: (goalId, post) =>
|
|
2849
|
+
jams?.fromAnotherPerson(goalId, post) ?? false,
|
|
1865
2850
|
team: teams,
|
|
1866
2851
|
headOf: (threadId) => worktrees.head(threadId),
|
|
1867
2852
|
busyInT3: (thread) =>
|
|
@@ -1965,8 +2950,9 @@ export async function startDaemon() {
|
|
|
1965
2950
|
scrub: (value) => vault.scrubDeep(value),
|
|
1966
2951
|
});
|
|
1967
2952
|
const swarmCommand = createSwarm({
|
|
2953
|
+
proposals,
|
|
1968
2954
|
landed,
|
|
1969
|
-
|
|
2955
|
+
fileCommand,
|
|
1970
2956
|
environments,
|
|
1971
2957
|
adoption,
|
|
1972
2958
|
// The coding agents found here that are not in the swarm yet and the person never took out, with their last check:
|
|
@@ -1998,9 +2984,9 @@ export async function startDaemon() {
|
|
|
1998
2984
|
}),
|
|
1999
2985
|
// What the person follows and has seen is kept beside the board, not in its tables: every surface reads again.
|
|
2000
2986
|
notifyFocus: () => boardWaits.bump(),
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2987
|
+
jamOf: (threadId) => jams?.roomInfo(threadId) ?? null,
|
|
2988
|
+
addressesAnotherPerson: (threadId, text) =>
|
|
2989
|
+
jams?.addressesAnotherPerson(threadId, text) ?? false,
|
|
2004
2990
|
withMachines: (card) => actors.withMachines(card),
|
|
2005
2991
|
whereIs,
|
|
2006
2992
|
here: () => machine.id,
|
|
@@ -2067,6 +3053,7 @@ export async function startDaemon() {
|
|
|
2067
3053
|
whyWaiting: (goalId, run) => whyWaiting(goalId, run),
|
|
2068
3054
|
schedules,
|
|
2069
3055
|
threadView,
|
|
3056
|
+
recordOf: (thread) => threadRecord.of(thread),
|
|
2070
3057
|
// A run's subagents: read here, or as the computer the run is on says (subagentSteering.mjs).
|
|
2071
3058
|
subagents: { of: (run) => subagentSteering.of(run) },
|
|
2072
3059
|
});
|
|
@@ -2100,6 +3087,7 @@ export async function startDaemon() {
|
|
|
2100
3087
|
detected.find((entry) => entry.agent === "opencode")?.path || null,
|
|
2101
3088
|
activeRuns: () => activeRuns.values(),
|
|
2102
3089
|
scrub: (value) => vault.scrubDeep(value),
|
|
3090
|
+
keepNextStep,
|
|
2103
3091
|
});
|
|
2104
3092
|
// Open, asked for by the person at another of their computers: planned here, carried out by this computer's buddy.
|
|
2105
3093
|
const openRequests = createOpenRequests({
|
|
@@ -2139,7 +3127,7 @@ export async function startDaemon() {
|
|
|
2139
3127
|
const touchListener = () => {
|
|
2140
3128
|
listenerAt = Date.now();
|
|
2141
3129
|
};
|
|
2142
|
-
//
|
|
3130
|
+
// Friends (network.mjs): set once the relay's helpers below exist.
|
|
2143
3131
|
let network = null;
|
|
2144
3132
|
let places = null;
|
|
2145
3133
|
const watchCommand = createBoardWatches({
|
|
@@ -2148,23 +3136,24 @@ export async function startDaemon() {
|
|
|
2148
3136
|
contextEngine: local.contextEngine,
|
|
2149
3137
|
environment,
|
|
2150
3138
|
frames,
|
|
2151
|
-
|
|
3139
|
+
events,
|
|
2152
3140
|
notePresence,
|
|
2153
3141
|
presence,
|
|
2154
3142
|
store,
|
|
2155
3143
|
watches,
|
|
3144
|
+
startThreadWatch: (id) =>
|
|
3145
|
+
swarmBoard({ command: "board.watch.go", agent: "user", id }),
|
|
2156
3146
|
});
|
|
2157
|
-
// The person's Harness windows
|
|
2158
|
-
const askOwnWindows = (call) =>
|
|
2159
|
-
phones.ask(call, (envelopes) =>
|
|
2160
|
-
askHarness("sealed_ask", { envelopes }, null)
|
|
2161
|
-
);
|
|
3147
|
+
// The person's Harness windows on this computer, asked over their channels with it, sealed (phones.mjs ask).
|
|
3148
|
+
const askOwnWindows = (call, route) => phones.ask(call, route);
|
|
2162
3149
|
// Each window links to the computer it runs on: home's agents' question goes to home's own windows, then to those
|
|
2163
3150
|
// linked to each worker when none here is linked or open, then to the hidden page of the browser listening here.
|
|
2164
3151
|
const askWindows = createWindowAsks({
|
|
2165
3152
|
askOwn: askOwnWindows,
|
|
2166
|
-
askWorkers: (call) => ownMachines?.
|
|
3153
|
+
askWorkers: (call, route) => ownMachines?.askOtherWindows(call, route),
|
|
2167
3154
|
browserWake,
|
|
3155
|
+
openHarness: () =>
|
|
3156
|
+
openHere({ ok: true, link: `${config.origin}/dashboard` }),
|
|
2168
3157
|
log,
|
|
2169
3158
|
});
|
|
2170
3159
|
const toolsCommand = createBoardTools({
|
|
@@ -2178,10 +3167,8 @@ export async function startDaemon() {
|
|
|
2178
3167
|
localReady: local.ready,
|
|
2179
3168
|
ocr: local.ocr,
|
|
2180
3169
|
askWindows,
|
|
2181
|
-
getServerFeatures: () => bridge.features(),
|
|
2182
3170
|
snippets,
|
|
2183
3171
|
roomOf: (task) => roomOf(task),
|
|
2184
|
-
state,
|
|
2185
3172
|
store,
|
|
2186
3173
|
watchOrListen: local.watchOrListen,
|
|
2187
3174
|
});
|
|
@@ -2191,7 +3178,6 @@ export async function startDaemon() {
|
|
|
2191
3178
|
sendThreadEnd: sealed.sendEnd,
|
|
2192
3179
|
sendThreadMessage: sealed.sendMessage,
|
|
2193
3180
|
store,
|
|
2194
|
-
textLike,
|
|
2195
3181
|
visibleFile,
|
|
2196
3182
|
});
|
|
2197
3183
|
|
|
@@ -2224,23 +3210,31 @@ export async function startDaemon() {
|
|
|
2224
3210
|
network
|
|
2225
3211
|
? network.command(request, agent)
|
|
2226
3212
|
: { ok: false, error: "the daemon is still starting" },
|
|
3213
|
+
jams: (request, { agent }) =>
|
|
3214
|
+
jams
|
|
3215
|
+
? jams.command(request, agent)
|
|
3216
|
+
: { ok: false, error: "the daemon is still starting" },
|
|
2227
3217
|
repos: (request, { agent }) => repoLinks.command(request, agent),
|
|
2228
3218
|
verdicts: (request, { agent }) => verdicts.command(request, agent),
|
|
2229
|
-
projects: (request, { agent }) =>
|
|
2230
|
-
projects
|
|
2231
|
-
? projects.command(request, agent)
|
|
2232
|
-
: { ok: false, error: "the daemon is still starting" },
|
|
2233
3219
|
place: (request, { agent }) =>
|
|
2234
3220
|
places
|
|
2235
3221
|
? places.command(request, agent)
|
|
2236
3222
|
: { ok: false, error: "the daemon is still starting" },
|
|
2237
|
-
live: (request, { agent }) =>
|
|
2238
|
-
|
|
3223
|
+
live: (request, { agent }) => {
|
|
3224
|
+
// An agent's own session start or turn end: its hooks (or plugin, or extension) run on this computer.
|
|
3225
|
+
if (
|
|
3226
|
+
agent !== "user" &&
|
|
3227
|
+
["board.live.place", "board.live.turn"].includes(request.command)
|
|
3228
|
+
)
|
|
3229
|
+
heardHooks(agent, request.sessionId);
|
|
3230
|
+
return request.command !== "board.live.opens"
|
|
2239
3231
|
? liveCommand(request, agent)
|
|
2240
3232
|
: agent === "user"
|
|
2241
3233
|
? openRequests.take()
|
|
2242
|
-
: { ok: false, error: "only the person's buddy opens things here" }
|
|
3234
|
+
: { ok: false, error: "only the person's buddy opens things here" };
|
|
3235
|
+
},
|
|
2243
3236
|
prompt: (request, { agent }) => {
|
|
3237
|
+
if (agent !== "user") heardHooks(agent, request.sessionId);
|
|
2244
3238
|
// A session a run started is that run's, never one the person typed in.
|
|
2245
3239
|
if (!request[RUN_CALLER]) authority.markPrompt(request.pids, agent);
|
|
2246
3240
|
// A session that started before its hook said where it runs says so on its next prompt.
|
|
@@ -2252,6 +3246,71 @@ export async function startDaemon() {
|
|
|
2252
3246
|
return { ok: true };
|
|
2253
3247
|
},
|
|
2254
3248
|
watch: watchCommand,
|
|
3249
|
+
facts: (request, context) => facts.command(request, context),
|
|
3250
|
+
completion: (request, context) => completion.command(request, context),
|
|
3251
|
+
watching: (request, context) =>
|
|
3252
|
+
request.command === "board.watch.screen"
|
|
3253
|
+
? request[FROM_BROWSER]
|
|
3254
|
+
? screenWatches.heard(request)
|
|
3255
|
+
: {
|
|
3256
|
+
ok: false,
|
|
3257
|
+
error: "only a browser says what its screen watch saw",
|
|
3258
|
+
}
|
|
3259
|
+
: threadWatches.command(request, context),
|
|
3260
|
+
outside: (request, context) => ({
|
|
3261
|
+
pending: outsideCommand(request, context),
|
|
3262
|
+
}),
|
|
3263
|
+
watchboard: (request, context) => threadWatches.command(request, context),
|
|
3264
|
+
// Readings a run on another computer left untaken (sensesLeft), kept or woken for on home. Only another computer
|
|
3265
|
+
// sends it.
|
|
3266
|
+
senses: (request, { agent, machine: from }) => {
|
|
3267
|
+
if (from === machine.id)
|
|
3268
|
+
return { ok: false, error: "this computer keeps its own readings" };
|
|
3269
|
+
// Only the computer that ran the agent's run. The run has ended, so home no longer names a holder: who claimed
|
|
3270
|
+
// it, and where, stay.
|
|
3271
|
+
const run = store.getTask(String(request.run || ""));
|
|
3272
|
+
const thread = run?.parent_id ? store.getTask(run.parent_id) : null;
|
|
3273
|
+
if (
|
|
3274
|
+
!run ||
|
|
3275
|
+
run.claimed_machine !== from ||
|
|
3276
|
+
(run.claimed_by ?? run.target_agent) !== agent ||
|
|
3277
|
+
thread?.kind !== "goal"
|
|
3278
|
+
)
|
|
3279
|
+
return {
|
|
3280
|
+
ok: false,
|
|
3281
|
+
error: "that run is not this computer's, in a thread",
|
|
3282
|
+
};
|
|
3283
|
+
const items = (Array.isArray(request.items) ? request.items : [])
|
|
3284
|
+
.slice(0, CARRIED_SENSES)
|
|
3285
|
+
.map((item) => ({
|
|
3286
|
+
text: String(item?.text ?? "").slice(0, 2_000),
|
|
3287
|
+
at: item?.at ?? null,
|
|
3288
|
+
about: { wakes: item?.about?.wakes === true },
|
|
3289
|
+
}))
|
|
3290
|
+
.filter((item) => item.text);
|
|
3291
|
+
if (items.length) keepSensesLeft(thread.id, agent, items);
|
|
3292
|
+
return { ok: true };
|
|
3293
|
+
},
|
|
3294
|
+
// A session's step on another computer, kept on home for the agent's thread (nextStep.mjs). Only another
|
|
3295
|
+
// computer sends it: this one keeps its own sessions' steps itself.
|
|
3296
|
+
nextSteps: (request, { agent, machine: from }) => {
|
|
3297
|
+
if (from === machine.id)
|
|
3298
|
+
return { ok: false, error: "this computer keeps its own steps" };
|
|
3299
|
+
const thread = store.getTask(String(request.thread || ""));
|
|
3300
|
+
if (
|
|
3301
|
+
thread?.kind !== "goal" ||
|
|
3302
|
+
!(thread.goal?.team ?? []).includes(agent)
|
|
3303
|
+
)
|
|
3304
|
+
return { ok: false, error: `${agent} is not in that thread` };
|
|
3305
|
+
return {
|
|
3306
|
+
ok: true,
|
|
3307
|
+
step: nextSteps.keep(
|
|
3308
|
+
thread.id,
|
|
3309
|
+
agent,
|
|
3310
|
+
typeof request.step === "string" ? request.step : null
|
|
3311
|
+
),
|
|
3312
|
+
};
|
|
3313
|
+
},
|
|
2255
3314
|
// A surface on this computer waits for the board to move past the revision it last read (boardWaits.mjs).
|
|
2256
3315
|
waits: (request) =>
|
|
2257
3316
|
request.hostedCaller
|
|
@@ -2263,22 +3322,18 @@ export async function startDaemon() {
|
|
|
2263
3322
|
},
|
|
2264
3323
|
plans: (request, { agent }) => plans.command(request, agent),
|
|
2265
3324
|
tools: toolsCommand,
|
|
2266
|
-
// Connected apps
|
|
3325
|
+
// Connected apps are on for every computer (docs/one-link-plan.md settled item 23), never for a restricted run
|
|
3326
|
+
// (mcp-stdio.mjs), held in here or on another computer as that computer sealed it with the call.
|
|
2267
3327
|
connectors: (request, { agent }) =>
|
|
2268
|
-
|
|
3328
|
+
request.restricted === true || callerRun(request)?.restricted === true
|
|
2269
3329
|
? {
|
|
2270
3330
|
ok: false,
|
|
2271
|
-
|
|
2272
|
-
error:
|
|
2273
|
-
"Apps are off on this computer. Turn them on: npx tryharness connections on",
|
|
3331
|
+
error: "A restricted run cannot use the person's connected apps.",
|
|
2274
3332
|
}
|
|
2275
|
-
:
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
"A restricted run cannot use the person's connected apps.",
|
|
2280
|
-
}
|
|
2281
|
-
: connectors.command(request, agent),
|
|
3333
|
+
: connectors.command(
|
|
3334
|
+
connectorCaller(store, request, callerRun(request)),
|
|
3335
|
+
agent
|
|
3336
|
+
),
|
|
2282
3337
|
thread: threadCommand,
|
|
2283
3338
|
file: fileCommand,
|
|
2284
3339
|
desk: (request, { agent }) => desk.command(request, agent),
|
|
@@ -2304,10 +3359,18 @@ export async function startDaemon() {
|
|
|
2304
3359
|
whereIs,
|
|
2305
3360
|
all: () => ownMachines?.all() ?? [],
|
|
2306
3361
|
repositoryOf: (folder) => repositoryName(folder),
|
|
3362
|
+
placeFolder: (place) =>
|
|
3363
|
+
ownMachines?.placeFolder(place) ?? {
|
|
3364
|
+
machine: place.target,
|
|
3365
|
+
folder: place.folder,
|
|
3366
|
+
},
|
|
2307
3367
|
stop: (workerId, taskId) =>
|
|
2308
3368
|
void ownMachines?.noticeTo(workerId, { stop: taskId }),
|
|
2309
3369
|
learn: (id, info) => ownMachines?.learn(id, info),
|
|
2310
|
-
|
|
3370
|
+
// A turn another computer takes: this computer's card is not its computer's; what touched the thread on each
|
|
3371
|
+
// computer is here over the nerves (S6).
|
|
3372
|
+
briefOf: (wake) =>
|
|
3373
|
+
threadRuns.worker.wakeBrief(wake, null, { here: false }),
|
|
2311
3374
|
resumeAfterSteer: (wake, computer) =>
|
|
2312
3375
|
threadRuns.worker.resumeAfterSteer(wake, computer),
|
|
2313
3376
|
wakeEnded: (wake, kind, text) =>
|
|
@@ -2326,11 +3389,10 @@ export async function startDaemon() {
|
|
|
2326
3389
|
lastSeen,
|
|
2327
3390
|
lessons,
|
|
2328
3391
|
madeIn: (...args) => madeIn(...args),
|
|
2329
|
-
getNetwork: () => network,
|
|
2330
|
-
getProjects: () => projects,
|
|
2331
3392
|
notifyBoard,
|
|
2332
3393
|
openTaskRoom: taskRooms.open,
|
|
2333
3394
|
openThreadPost: sealed.openPost,
|
|
3395
|
+
friendshipTaken: () => peopleLink?.sync(),
|
|
2334
3396
|
pauseGoal: actions.pause,
|
|
2335
3397
|
placesOf,
|
|
2336
3398
|
restrictable: threadAuthority.restrictable,
|
|
@@ -2366,6 +3428,28 @@ export async function startDaemon() {
|
|
|
2366
3428
|
// On a worker, a read home cannot answer comes from this computer's copy, saying how old it is, and a write that
|
|
2367
3429
|
// reached home brings the copy up to date.
|
|
2368
3430
|
const swarmBoard = (asked) => {
|
|
3431
|
+
const answered = swarmBoardOnce(asked);
|
|
3432
|
+
// A file attached from a path here, and one an agent here read through Harness (originals.mjs, S6.5).
|
|
3433
|
+
if (
|
|
3434
|
+
(asked.command === "board.file.add" && asked.path != null) ||
|
|
3435
|
+
(asked.command === "board.file.get" && asked.agentPid != null)
|
|
3436
|
+
)
|
|
3437
|
+
void Promise.resolve(answered?.pending ?? answered)
|
|
3438
|
+
.then((answer) => {
|
|
3439
|
+
if (answer?.ok !== true || !answer.file?.id) return;
|
|
3440
|
+
if (asked.command === "board.file.add")
|
|
3441
|
+
originals.attached(answer.file.id, asked.path, answer.file.name);
|
|
3442
|
+
else
|
|
3443
|
+
originals.read(
|
|
3444
|
+
sessionOfPid(asked.agentPid),
|
|
3445
|
+
answer.file.id,
|
|
3446
|
+
answer.file.path
|
|
3447
|
+
);
|
|
3448
|
+
})
|
|
3449
|
+
.catch(() => {});
|
|
3450
|
+
return answered;
|
|
3451
|
+
};
|
|
3452
|
+
const swarmBoardOnce = (asked) => {
|
|
2369
3453
|
const request = ownFilesStayHome(asked);
|
|
2370
3454
|
// Work in this computer's own T3 Code is answered here: home has no such thread.
|
|
2371
3455
|
if (!ownMachines?.forwards(request) || environments.mine(request.id)) {
|
|
@@ -2438,7 +3522,7 @@ export async function startDaemon() {
|
|
|
2438
3522
|
threadFilesNote: briefs.threadFilesNote,
|
|
2439
3523
|
t3CatchUp: threadRuns.worker.t3CatchUp,
|
|
2440
3524
|
wakeBrief: threadRuns.worker.wakeBrief,
|
|
2441
|
-
boardBrief: (threadId) => kanban.brief(threadId),
|
|
3525
|
+
boardBrief: (threadId, options) => kanban.brief(threadId, options),
|
|
2442
3526
|
});
|
|
2443
3527
|
const worker = createRunWorker({
|
|
2444
3528
|
dispatches,
|
|
@@ -2462,16 +3546,225 @@ export async function startDaemon() {
|
|
|
2462
3546
|
vaultEnv: (task, agent) => vault.envFor({ agent, task: task.id }),
|
|
2463
3547
|
// A run's receipt, read after it reported: what it claimed is audited again with it.
|
|
2464
3548
|
onReceipt: (taskId) => auditor?.receiptRead(taskId),
|
|
3549
|
+
// What a turn that ended on a wait says when its agent wrote nothing (threadRecord.mjs).
|
|
3550
|
+
waitingLine: (thread, agent, since) =>
|
|
3551
|
+
threadRecord.waitingLine(thread, agent, since),
|
|
3552
|
+
});
|
|
3553
|
+
// The machine (machine.mjs): memory pressure, heat, battery, lid, network and the disk Harness keeps its things on,
|
|
3554
|
+
// as facts about this computer and happenings when they change. A nearly full disk holds new runs and tells the
|
|
3555
|
+
// person; a tight one lets cleanup clear Harness's own files first (set below).
|
|
3556
|
+
let diskTight = () => {};
|
|
3557
|
+
const machineSense = createMachine({
|
|
3558
|
+
sources,
|
|
3559
|
+
facts,
|
|
3560
|
+
events,
|
|
3561
|
+
store,
|
|
3562
|
+
machineId: machine.id,
|
|
3563
|
+
home: paths.home,
|
|
3564
|
+
native,
|
|
3565
|
+
log,
|
|
3566
|
+
notify: (text) => notices.notify(text),
|
|
3567
|
+
hold: (on, how) => worker.hold(on, how),
|
|
3568
|
+
onTight: (level) => diskTight(level),
|
|
3569
|
+
isHome: () => machine.role !== "worker",
|
|
3570
|
+
});
|
|
3571
|
+
// The sense of time (timeSense.mjs, Phase T): when the computer slept and was busy, a command sent to the background
|
|
3572
|
+
// ending, a known long command running far past its usual, and the person's last words, for the hooks' lines; a
|
|
3573
|
+
// thread's timeline from the log, for its wake and after an agent's context is cut.
|
|
3574
|
+
timeSense = createTimeSense({
|
|
3575
|
+
events,
|
|
3576
|
+
home: paths.home,
|
|
3577
|
+
pressure: () => ["warn", "critical"].includes(machineSense.now().pressure),
|
|
3578
|
+
spokeAt: () =>
|
|
3579
|
+
store.db.get(
|
|
3580
|
+
"select max(created_at) as at from board_contributions where author = 'user' and kind not in ('held', 'note')"
|
|
3581
|
+
)?.at ?? null,
|
|
3582
|
+
awaySince: () => presence.awaySince,
|
|
3583
|
+
touches: (happening) => threadTouched(happening),
|
|
3584
|
+
computerOf,
|
|
3585
|
+
log,
|
|
3586
|
+
});
|
|
3587
|
+
// How close the swarm is to what the person let it do (limits.mjs): each agent's runs today under its standing
|
|
3588
|
+
// permission and each thread's spend against its ceiling, as facts, looked at again when the board changes and at
|
|
3589
|
+
// each local midnight. Home keeps them; a worker reads its copy.
|
|
3590
|
+
// Cleanup (cleanup.mjs): Harness's own scratch and rebuildable files, once a day while the computer is idle and at
|
|
3591
|
+
// once when the disk turns tight; the person's things never, only named to them once large and old.
|
|
3592
|
+
const lastUsed = (threadId) => {
|
|
3593
|
+
const times = [
|
|
3594
|
+
store.getTask(threadId)?.updated_at,
|
|
3595
|
+
...store.threadRuns(threadId).map((run) => run.updated_at),
|
|
3596
|
+
]
|
|
3597
|
+
.map((at) => Date.parse(at ?? ""))
|
|
3598
|
+
.filter(Number.isFinite);
|
|
3599
|
+
return times.length ? Math.max(...times) : 0;
|
|
3600
|
+
};
|
|
3601
|
+
const cleanup = createCleanup({
|
|
3602
|
+
store,
|
|
3603
|
+
events,
|
|
3604
|
+
worktrees,
|
|
3605
|
+
log,
|
|
3606
|
+
lastUsed,
|
|
3607
|
+
inUse: (folder) => runsIn(realFolder(folder)).length > 0,
|
|
3608
|
+
// Idle: nothing running, and the person away where the computer can tell (on one that cannot, nothing running).
|
|
3609
|
+
idle: () =>
|
|
3610
|
+
taskRuns.running().length === 0 &&
|
|
3611
|
+
(!presenceSense.readable() || Boolean(presence.awaySince)),
|
|
3612
|
+
hasRoom: () => machineSense.hasRoom(),
|
|
3613
|
+
notify: (text) => notices.notify(text),
|
|
3614
|
+
// Once a day: what the log holds up to yesterday folded into what this computer's days are like (S8.1).
|
|
3615
|
+
history: () => {
|
|
3616
|
+
sleep.fold();
|
|
3617
|
+
// On the computer that holds the board.
|
|
3618
|
+
if (holdsBoard()) {
|
|
3619
|
+
void threadNotes.fold().catch(() => undefined);
|
|
3620
|
+
proposals.fromSleep();
|
|
3621
|
+
}
|
|
3622
|
+
return tripwires.trim() + outsideEvents.forget();
|
|
3623
|
+
},
|
|
3624
|
+
});
|
|
3625
|
+
diskTight = () => void cleanup.trim("tight");
|
|
3626
|
+
personAway = () => void cleanup.maybeDaily();
|
|
3627
|
+
// Watches that belong to threads (threadWatches.mjs): armed on the computer that reads them, kept on home, followed
|
|
3628
|
+
// by the computer each names.
|
|
3629
|
+
const threadWatches = createThreadWatches({
|
|
3630
|
+
store,
|
|
3631
|
+
// A watch from the person's sentence (S9.2), read by the dispatcher's model here.
|
|
3632
|
+
fromWords: (context) => dispatcher.watchWords(context),
|
|
3633
|
+
sources,
|
|
3634
|
+
events,
|
|
3635
|
+
log,
|
|
3636
|
+
machineId: machine.id,
|
|
3637
|
+
isHome: () => machine.role !== "worker",
|
|
3638
|
+
keepAtHome: (request) =>
|
|
3639
|
+
machine.role === "worker"
|
|
3640
|
+
? swarmBoard(request)
|
|
3641
|
+
: boardCommand({ ...request, [WATCH_KEEPER]: true }),
|
|
3642
|
+
threadFolder: (threadId) => {
|
|
3643
|
+
const thread = store.getTask(threadId);
|
|
3644
|
+
return thread ? threadFolder(thread) : null;
|
|
3645
|
+
},
|
|
3646
|
+
ownedBy: (pid, agent) => {
|
|
3647
|
+
const runs = new Set(
|
|
3648
|
+
taskRuns
|
|
3649
|
+
.running()
|
|
3650
|
+
.filter((run) => run.agent === agent)
|
|
3651
|
+
.map((run) => run.runId)
|
|
3652
|
+
);
|
|
3653
|
+
return processOwnedBy(
|
|
3654
|
+
pid,
|
|
3655
|
+
runningProcesses()
|
|
3656
|
+
.filter((entry) => runs.has(entry.run))
|
|
3657
|
+
.map((entry) => entry.pid)
|
|
3658
|
+
);
|
|
3659
|
+
},
|
|
3660
|
+
outsideThreadOf: (address) => outsideEvents.threadOf(address),
|
|
3661
|
+
// An agent's wait (S3.3) in the thread its run works in, when it names none.
|
|
3662
|
+
threadOfCaller: (request) => {
|
|
3663
|
+
const run = callerRun(request);
|
|
3664
|
+
const parent = run ? store.getTask(run.id)?.parent_id : null;
|
|
3665
|
+
return parent && store.getTask(parent)?.kind === "goal" ? parent : null;
|
|
3666
|
+
},
|
|
3667
|
+
changed: () => boardChanged(),
|
|
3668
|
+
responses,
|
|
3669
|
+
// What each watch has cost, in the thread's list of its watches (threadRecord.mjs).
|
|
3670
|
+
spentOf: (watch) => threadRecord.spentOf(watch),
|
|
3671
|
+
});
|
|
3672
|
+
// An outside address for a thread and what arrives at it (outsideEvents.mjs, S7.2): the person's for any thread, an
|
|
3673
|
+
// agent's for a thread it is in. An agent that makes one is woken by it in that thread unless it says not to.
|
|
3674
|
+
const outsideCommand = async (request, { agent }) => {
|
|
3675
|
+
if (request.hostedCaller)
|
|
3676
|
+
return {
|
|
3677
|
+
ok: false,
|
|
3678
|
+
error:
|
|
3679
|
+
"outside addresses are only for the person and agents on this computer",
|
|
3680
|
+
};
|
|
3681
|
+
const person = agent === "user";
|
|
3682
|
+
const inThread = (thread) =>
|
|
3683
|
+
person ||
|
|
3684
|
+
(store.getTask(thread)?.goal?.team ?? []).includes(String(agent));
|
|
3685
|
+
const command = String(request.command);
|
|
3686
|
+
if (command === "board.outside.read") {
|
|
3687
|
+
const read = outsideEvents.read(String(request.event || ""));
|
|
3688
|
+
return read.ok && !inThread(read.event.thread)
|
|
3689
|
+
? { ok: false, error: "there is no such event" }
|
|
3690
|
+
: read;
|
|
3691
|
+
}
|
|
3692
|
+
if (command === "board.outside.revoke") {
|
|
3693
|
+
const thread = outsideEvents.threadOf(String(request.id || ""));
|
|
3694
|
+
if (!thread || !inThread(thread))
|
|
3695
|
+
return { ok: false, error: "there is no such address" };
|
|
3696
|
+
return outsideEvents.revoke(String(request.id), { by: agent });
|
|
3697
|
+
}
|
|
3698
|
+
const thread = request.thread
|
|
3699
|
+
? String(request.thread)
|
|
3700
|
+
: person
|
|
3701
|
+
? null
|
|
3702
|
+
: (() => {
|
|
3703
|
+
const run = callerRun(request);
|
|
3704
|
+
const parent = run ? store.getTask(run.id)?.parent_id : null;
|
|
3705
|
+
return parent && store.getTask(parent)?.kind === "goal"
|
|
3706
|
+
? parent
|
|
3707
|
+
: null;
|
|
3708
|
+
})();
|
|
3709
|
+
if (command === "board.outside.list") {
|
|
3710
|
+
if (thread && !inThread(thread))
|
|
3711
|
+
return { ok: false, error: `${agent} is not in that thread` };
|
|
3712
|
+
if (!thread && !person) return { ok: false, error: "name the thread" };
|
|
3713
|
+
return { ok: true, addresses: outsideEvents.list({ thread }) };
|
|
3714
|
+
}
|
|
3715
|
+
if (command !== "board.outside.make")
|
|
3716
|
+
return { ok: false, error: "unknown outside command" };
|
|
3717
|
+
if (!thread)
|
|
3718
|
+
return {
|
|
3719
|
+
ok: false,
|
|
3720
|
+
error: "an address belongs to a thread: work in one, or name it",
|
|
3721
|
+
};
|
|
3722
|
+
if (!inThread(thread))
|
|
3723
|
+
return { ok: false, error: `${agent} is not in that thread` };
|
|
3724
|
+
const made = await outsideEvents.make({
|
|
3725
|
+
thread,
|
|
3726
|
+
name: request.name,
|
|
3727
|
+
signedBy: request.signedBy ?? null,
|
|
3728
|
+
by: agent,
|
|
3729
|
+
});
|
|
3730
|
+
if (!made.ok || request.wake === false) return made;
|
|
3731
|
+
const armed = await threadWatches.command(
|
|
3732
|
+
{
|
|
3733
|
+
command: "board.watch.arm",
|
|
3734
|
+
thread,
|
|
3735
|
+
source: { kind: "outside", address: made.address.id },
|
|
3736
|
+
condition: request.type ? { type: request.type } : {},
|
|
3737
|
+
...(person ? { grants: request.grants } : { answers: agent }),
|
|
3738
|
+
},
|
|
3739
|
+
{ agent }
|
|
3740
|
+
);
|
|
3741
|
+
const result = (await armed?.pending) ?? armed;
|
|
3742
|
+
return {
|
|
3743
|
+
...made,
|
|
3744
|
+
watch: result?.ok
|
|
3745
|
+
? result.readBack
|
|
3746
|
+
: `not watched: ${result?.error ?? "the watch was not set"}`,
|
|
3747
|
+
};
|
|
3748
|
+
};
|
|
3749
|
+
const limits = createLimits({
|
|
3750
|
+
store,
|
|
3751
|
+
facts,
|
|
3752
|
+
events,
|
|
3753
|
+
standingRules: () => authority.standingRules(),
|
|
3754
|
+
isHome: () => machine.role !== "worker",
|
|
2465
3755
|
});
|
|
2466
3756
|
// A session's agent hears its work again after its context is compacted (compaction.mjs, the session hook).
|
|
2467
|
-
const compaction = createCompaction({ store, goals });
|
|
3757
|
+
const compaction = createCompaction({ store, goals, timelineOf });
|
|
2468
3758
|
const { activeRuns, whyWaiting, runBoard } = worker;
|
|
2469
3759
|
|
|
2470
3760
|
// The agents the person picked for this cloud computer, installed here and joined to the swarm (cloudAgents.mjs).
|
|
2471
3761
|
const cloudSave = config.cloud
|
|
2472
3762
|
? createCloudSave({
|
|
2473
3763
|
origin: config.origin,
|
|
2474
|
-
token: () =>
|
|
3764
|
+
token: () => readConfig(paths.config, config).token,
|
|
3765
|
+
// One statement on the daemon's one connection: no write lands halfway through it.
|
|
3766
|
+
snapshot: (file) =>
|
|
3767
|
+
store.db.exec(`vacuum into '${file.replaceAll("'", "''")}'`),
|
|
2475
3768
|
log: (line) => log(`cloud copy: ${line}`),
|
|
2476
3769
|
})
|
|
2477
3770
|
: null;
|
|
@@ -2612,11 +3905,35 @@ export async function startDaemon() {
|
|
|
2612
3905
|
setModel: (agent, model) =>
|
|
2613
3906
|
ownModels({ command: "board.swarm.model", target: agent, model }),
|
|
2614
3907
|
};
|
|
3908
|
+
// This computer on the person's device list (src/shared/deviceList.ts): how it reads and signs it.
|
|
3909
|
+
const computerDevices = createComputerDevices({
|
|
3910
|
+
paths,
|
|
3911
|
+
origin: () => config.origin,
|
|
3912
|
+
token: () => readConfig(paths.config, config).token,
|
|
3913
|
+
ask: (type, input) => bridge.ask(type, input),
|
|
3914
|
+
log,
|
|
3915
|
+
});
|
|
3916
|
+
// The person's pages and phones reach this computer over WebRTC, introduced by a sealed call (link.mjs).
|
|
3917
|
+
// The servers every WebRTC channel of this computer uses (link.mjs): STUN, and Cloudflare's TURN from Harness.
|
|
3918
|
+
const iceServers = createIceServers({
|
|
3919
|
+
origin: () => config.origin,
|
|
3920
|
+
token: () => readConfig(paths.config, config).token,
|
|
3921
|
+
});
|
|
3922
|
+
const link = createLink({
|
|
3923
|
+
handle: (input) => {
|
|
3924
|
+
// A browser that calls is here: a screen watch it lost is installed again (screenWatches.mjs).
|
|
3925
|
+
screenWatches.browserCalled();
|
|
3926
|
+
return phones.handle(input);
|
|
3927
|
+
},
|
|
3928
|
+
publicKey: () => phones.publicKey,
|
|
3929
|
+
iceServers,
|
|
3930
|
+
log,
|
|
3931
|
+
});
|
|
2615
3932
|
const phones = await createPhoneDesk({
|
|
3933
|
+
link,
|
|
2616
3934
|
store,
|
|
2617
3935
|
log,
|
|
2618
3936
|
identityFile: paths.phoneIdentity,
|
|
2619
|
-
setupOfferFile: paths.browserOffer,
|
|
2620
3937
|
// A window linked to a worker works the swarm's board, which is home's, not one of its own.
|
|
2621
3938
|
boardCommand: swarmBoard,
|
|
2622
3939
|
version: DAEMON_VERSION,
|
|
@@ -2628,11 +3945,8 @@ export async function startDaemon() {
|
|
|
2628
3945
|
signIn: cloudSignIn,
|
|
2629
3946
|
links: proxyLinks,
|
|
2630
3947
|
ssh: cloudSsh?.allow ?? null,
|
|
2631
|
-
// Said to the person on this computer whatever their notification settings: a device reaching their computer.
|
|
2632
|
-
notify: (line, item) =>
|
|
2633
|
-
notices.tellDesktop("Your devices", line, "devices:", item),
|
|
2634
|
-
origin: () => config.origin,
|
|
2635
3948
|
devices: () => swarmDevices,
|
|
3949
|
+
personsDevices: (deviceId) => computerDevices.deviceOnList(deviceId),
|
|
2636
3950
|
reads: {
|
|
2637
3951
|
"sessions.search": (input) => store.search(input.input || {}),
|
|
2638
3952
|
"sessions.read": (input) => store.read(input.input || {}),
|
|
@@ -2643,26 +3957,23 @@ export async function startDaemon() {
|
|
|
2643
3957
|
.map(taskStatus)
|
|
2644
3958
|
.filter(Boolean),
|
|
2645
3959
|
}),
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
"relay.open": (input) =>
|
|
2655
|
-
sealed.openRequest({ sealed: input.sealed, from: input.from }),
|
|
3960
|
+
// The browser's small jobs on this computer's own model (dispatcher.mjs BROWSER_JOBS).
|
|
3961
|
+
"local.infer": (input) =>
|
|
3962
|
+
dispatcher.browserJob(
|
|
3963
|
+
String(input.job ?? ""),
|
|
3964
|
+
input.context,
|
|
3965
|
+
input.pictures
|
|
3966
|
+
),
|
|
3967
|
+
"local.infer.ready": () => ({ ready: dispatcher.browserReady() }),
|
|
2656
3968
|
},
|
|
2657
3969
|
});
|
|
2658
3970
|
|
|
2659
3971
|
relayIdentity = phones.identity;
|
|
3972
|
+
deviceKeys = await loadDeviceIdentity(paths);
|
|
2660
3973
|
// The person's devices across their computers, one list kept by home; only the person changes it (swarmDevices.mjs).
|
|
2661
3974
|
const swarmDevices = createSwarmDevices({
|
|
2662
3975
|
store,
|
|
2663
3976
|
computers: () => ownMachines,
|
|
2664
|
-
asks: () => phones.linkAsk.list(),
|
|
2665
|
-
answerAsk: (id, allow) => phones.linkAsk.answer(id, allow),
|
|
2666
3977
|
notify: (line, item) =>
|
|
2667
3978
|
notices.tellDesktop("Your devices", line, "devices:", item),
|
|
2668
3979
|
log,
|
|
@@ -2685,13 +3996,274 @@ export async function startDaemon() {
|
|
|
2685
3996
|
return list;
|
|
2686
3997
|
};
|
|
2687
3998
|
// The person's other computers: a worker's agents reach home's board through it, sealed with this computer's key.
|
|
2688
|
-
// The person's computers reach each other
|
|
2689
|
-
const directLink =
|
|
2690
|
-
keyFile: path.join(paths.home, "direct-identity.json"),
|
|
3999
|
+
// The person's computers reach each other over WebRTC, introduced through Harness (machineLink.mjs).
|
|
4000
|
+
const directLink = createMachineLink({
|
|
2691
4001
|
log,
|
|
4002
|
+
iceServers,
|
|
4003
|
+
onChange: (peerId) => {
|
|
4004
|
+
ownMachines?.linkChanged();
|
|
4005
|
+
nerves?.linkChanged(peerId);
|
|
4006
|
+
},
|
|
2692
4007
|
onRequest: (peerId, body) =>
|
|
2693
4008
|
ownMachines?.fromLink(peerId, body) ?? { ok: false },
|
|
4009
|
+
introduce: async (_peerId, call) =>
|
|
4010
|
+
(await ownMachines?.introduceLink(call)) ?? {
|
|
4011
|
+
ok: false,
|
|
4012
|
+
error: "home did not answer",
|
|
4013
|
+
},
|
|
4014
|
+
redial: (peerId) => ownMachines?.listedOn(peerId) === true,
|
|
4015
|
+
});
|
|
4016
|
+
// A device taken off the person's list loses its channels with this computer at once (docs/one-link-plan.md L6.1):
|
|
4017
|
+
// a browser's or phone's pages, and another computer's link. Harness says when the list lost a device; this computer
|
|
4018
|
+
// reads which from the signed list itself.
|
|
4019
|
+
devicesChanged = async () => {
|
|
4020
|
+
const removed = await computerDevices.removedNow().catch(() => null);
|
|
4021
|
+
for (const device of removed ?? []) {
|
|
4022
|
+
if (device.kind === "computer" || device.kind === "cloud")
|
|
4023
|
+
ownMachines?.removedFromList(device.sealingKey);
|
|
4024
|
+
else phones.removedFromList(device.deviceId);
|
|
4025
|
+
}
|
|
4026
|
+
// The person's first device makes their keys; after a device left, the keys change from here unless another
|
|
4027
|
+
// device of theirs changed them already. Either way this computer then reads the identity they hold now.
|
|
4028
|
+
await computerDevices
|
|
4029
|
+
.ensureKeys()
|
|
4030
|
+
.then((made) => {
|
|
4031
|
+
if (made.recoveryCode)
|
|
4032
|
+
notices.tellDesktop(
|
|
4033
|
+
"Your devices",
|
|
4034
|
+
"Harness made your recovery code. Run npx tryharness recovery-code to see it once.",
|
|
4035
|
+
"devices:",
|
|
4036
|
+
"recovery"
|
|
4037
|
+
);
|
|
4038
|
+
})
|
|
4039
|
+
.catch((error) => log(`devices: keys not made: ${error.message}`));
|
|
4040
|
+
await computerDevices
|
|
4041
|
+
.rotateIfDue()
|
|
4042
|
+
.then((changed) => {
|
|
4043
|
+
if (changed.recoveryCode)
|
|
4044
|
+
notices.tellDesktop(
|
|
4045
|
+
"Your devices",
|
|
4046
|
+
"Your keys changed after a device left your list, and so did your recovery code. Run npx tryharness recovery-code to see the new one once.",
|
|
4047
|
+
"devices:",
|
|
4048
|
+
"recovery"
|
|
4049
|
+
);
|
|
4050
|
+
})
|
|
4051
|
+
.catch((error) => log(`devices: keys not changed: ${error.message}`));
|
|
4052
|
+
await refreshIdentity();
|
|
4053
|
+
};
|
|
4054
|
+
// The person's identity as this computer holds it, in the shape their friends' channels and jams use. When it
|
|
4055
|
+
// changed, the signing key before is kept (a jam card or event signed with it still checks), and the jams the person
|
|
4056
|
+
// owns give every member, them included, cards signed with the new keys (jamStore.mjs rekeyOwned).
|
|
4057
|
+
// Keys change after a device leaves the person's list. A change with no device taken off since the last one was
|
|
4058
|
+
// made by a device still on the list, which may be a stolen one: the person is told which device it was.
|
|
4059
|
+
const tellIfUnexpected = async () => {
|
|
4060
|
+
const read = await computerDevices.read().catch(() => null);
|
|
4061
|
+
if (!read) return;
|
|
4062
|
+
const changes = read.records
|
|
4063
|
+
.map((record, at) => ({ record, at }))
|
|
4064
|
+
.filter(({ record }) => record.change.op === "account");
|
|
4065
|
+
const [before, last] = changes.slice(-2);
|
|
4066
|
+
if (!before || !last || last.record.signer === deviceKeys?.deviceId) return;
|
|
4067
|
+
const removedBetween = read.records
|
|
4068
|
+
.slice(before.at + 1, last.at)
|
|
4069
|
+
.some(({ change }) => change.op === "remove" || change.op === "reset");
|
|
4070
|
+
if (removedBetween) return;
|
|
4071
|
+
const by =
|
|
4072
|
+
read.list.devices.find((device) => device.deviceId === last.record.signer)
|
|
4073
|
+
?.label ?? "one of your devices";
|
|
4074
|
+
log(`devices: your keys changed on ${by} with no device removed`);
|
|
4075
|
+
notices.tellDesktop(
|
|
4076
|
+
"Your devices",
|
|
4077
|
+
`Your keys were changed on ${by}, though no device left your list. If that was not you, remove it: npx tryharness devices remove "${by}"`,
|
|
4078
|
+
"devices:",
|
|
4079
|
+
"keys-changed"
|
|
4080
|
+
);
|
|
4081
|
+
};
|
|
4082
|
+
// One read at a time: everything that finds no identity waits for the same read.
|
|
4083
|
+
let identityRead = null;
|
|
4084
|
+
refreshIdentity = () =>
|
|
4085
|
+
(identityRead ??= readIdentity().finally(() => {
|
|
4086
|
+
identityRead = null;
|
|
4087
|
+
}));
|
|
4088
|
+
const readIdentity = async () => {
|
|
4089
|
+
const held = await computerDevices.personIdentity().catch((error) => {
|
|
4090
|
+
log(`devices: your keys could not be read: ${error.message}`);
|
|
4091
|
+
return undefined;
|
|
4092
|
+
});
|
|
4093
|
+
if (held === undefined) return;
|
|
4094
|
+
const before = personKeys;
|
|
4095
|
+
personKeys = held
|
|
4096
|
+
? {
|
|
4097
|
+
publicKey: relayPublicKey(held.publicKey),
|
|
4098
|
+
privateKey: held.privateKey,
|
|
4099
|
+
signingKey: held.signingKey,
|
|
4100
|
+
signingPrivateKey: held.signingPrivateKey,
|
|
4101
|
+
previous: held.previous.map((earlier) => ({
|
|
4102
|
+
publicKey: relayPublicKey(earlier.publicKey),
|
|
4103
|
+
privateKey: earlier.privateKey,
|
|
4104
|
+
})),
|
|
4105
|
+
}
|
|
4106
|
+
: null;
|
|
4107
|
+
// Held for the first time (its keys were sealed to it after it connected): Harness posts the person's friendships
|
|
4108
|
+
// again, which this computer could not take without them, and the channels with their friends can open now.
|
|
4109
|
+
if (!before && personKeys) {
|
|
4110
|
+
void askHarness("relay_network", { op: "repost" }).catch(() => null);
|
|
4111
|
+
peopleLink?.sync();
|
|
4112
|
+
}
|
|
4113
|
+
if (
|
|
4114
|
+
!before?.signingKey ||
|
|
4115
|
+
!personKeys ||
|
|
4116
|
+
before.signingKey === personKeys.signingKey
|
|
4117
|
+
)
|
|
4118
|
+
return;
|
|
4119
|
+
const past = JSON.parse(store.meta("identity-past-signing") || "[]");
|
|
4120
|
+
store.meta(
|
|
4121
|
+
"identity-past-signing",
|
|
4122
|
+
JSON.stringify([...new Set([before.signingKey, ...past])].slice(0, 32))
|
|
4123
|
+
);
|
|
4124
|
+
log("devices: your keys changed; this computer holds the new ones");
|
|
4125
|
+
void tellIfUnexpected();
|
|
4126
|
+
peopleLink?.sync();
|
|
4127
|
+
if (holdsBoard())
|
|
4128
|
+
void jamStore
|
|
4129
|
+
?.rekeyOwned()
|
|
4130
|
+
.catch((error) => log(`jams: not re-keyed: ${error.message}`));
|
|
4131
|
+
};
|
|
4132
|
+
// Other people's computers on accepted threads, over WebRTC introduced through Harness (peopleLink.mjs). Only the
|
|
4133
|
+
// computer that holds the board keeps threads, so only it keeps these channels.
|
|
4134
|
+
peopleLink = createPeopleLink({
|
|
4135
|
+
store,
|
|
4136
|
+
identity: () => (holdsBoard() ? personKeys : null),
|
|
4137
|
+
askHarness,
|
|
4138
|
+
receive: (type, input) =>
|
|
4139
|
+
new Promise((resolve) => sealed.receive(type, input, resolve)),
|
|
4140
|
+
waiting: (handle) => Boolean(store.meta(`relay-key-waiting:${handle}`)),
|
|
4141
|
+
iceServers,
|
|
4142
|
+
log,
|
|
2694
4143
|
});
|
|
4144
|
+
setInterval(() => {
|
|
4145
|
+
if (holdsBoard()) peopleLink.sync();
|
|
4146
|
+
}, PEOPLE_LINK_SYNC_MS).unref();
|
|
4147
|
+
// Another person's keys changed and no links lead to them from the keys pinned here (they started fresh): the
|
|
4148
|
+
// channel with them closes and their threads wait until the person here trusts the new keys (relay.trust); nothing
|
|
4149
|
+
// sealed with either goes or is taken meanwhile.
|
|
4150
|
+
const HANDLE = /^[a-z0-9][a-z0-9-]{2,19}$/;
|
|
4151
|
+
const waitingKey = (handle) => `relay-key-waiting:${handle}`;
|
|
4152
|
+
const openSealedWith = (handle) =>
|
|
4153
|
+
store
|
|
4154
|
+
.relayThreads(1_000)
|
|
4155
|
+
.filter(
|
|
4156
|
+
(thread) => !thread.closed_at && handleOf(thread.with_agent) === handle
|
|
4157
|
+
)
|
|
4158
|
+
.map((thread) => store.getThread(thread.task_id))
|
|
4159
|
+
.filter((thread) => thread?.peer_key);
|
|
4160
|
+
const keyChanged = (handle, reason) => {
|
|
4161
|
+
if (!HANDLE.test(handle) || store.meta(waitingKey(handle))) return;
|
|
4162
|
+
if (!openSealedWith(handle).length) return;
|
|
4163
|
+
store.meta(waitingKey(handle), reason);
|
|
4164
|
+
peopleLink.close(handle);
|
|
4165
|
+
log(`people link: ${handle}'s key ${reason}; their threads wait`);
|
|
4166
|
+
notices.notify(
|
|
4167
|
+
`${handle} started fresh with new keys. Your friendship with them waits until you check them: npx tryharness peers trust ${handle}`
|
|
4168
|
+
);
|
|
4169
|
+
};
|
|
4170
|
+
// The keys Harness gives now against the ones pinned, for everyone with an open thread: a change missed while this
|
|
4171
|
+
// computer was off is found when it connects.
|
|
4172
|
+
const checkPeerKeys = async () => {
|
|
4173
|
+
const byHandle = new Map();
|
|
4174
|
+
for (const thread of store.relayThreads(1_000)) {
|
|
4175
|
+
if (thread.closed_at) continue;
|
|
4176
|
+
const handle = handleOf(thread.with_agent);
|
|
4177
|
+
const kept = store.getThread(thread.task_id);
|
|
4178
|
+
if (kept?.peer_key && !store.meta(waitingKey(handle)))
|
|
4179
|
+
byHandle.set(handle, kept);
|
|
4180
|
+
}
|
|
4181
|
+
for (const [handle, thread] of byHandle) {
|
|
4182
|
+
const keyed = await askHarness("relay_key", { to: handle }).catch(
|
|
4183
|
+
() => null
|
|
4184
|
+
);
|
|
4185
|
+
if (!keyed?.ok || typeof keyed.publicKey !== "string") continue;
|
|
4186
|
+
if (relayPublicKey(keyed.publicKey) === thread.peer_key) continue;
|
|
4187
|
+
if (!(await followPeer(handle))) keyChanged(handle, "replaced");
|
|
4188
|
+
}
|
|
4189
|
+
};
|
|
4190
|
+
/**
|
|
4191
|
+
* Another person's keys changed: this computer asks Harness for the links from the keys it pinned (identityLink.mjs)
|
|
4192
|
+
* and follows them when each is signed by the keys before it, with nothing asked of anyone. Their friendship then
|
|
4193
|
+
* takes the new keys and what waited goes. False when no links lead there (they started fresh) or one does not hold:
|
|
4194
|
+
* then the person here checks the new keys (peers trust). `keyed`: Harness's answer, when the caller has it.
|
|
4195
|
+
*/
|
|
4196
|
+
const followPeer = async (handle, keyed = null) => {
|
|
4197
|
+
const pinned = store.relayPeer(handle);
|
|
4198
|
+
if (!HANDLE.test(handle) || !pinned?.signing_key) return false;
|
|
4199
|
+
const answer =
|
|
4200
|
+
keyed?.links !== undefined
|
|
4201
|
+
? keyed
|
|
4202
|
+
: await askHarness("relay_key", {
|
|
4203
|
+
to: handle,
|
|
4204
|
+
since: pinned.signing_key,
|
|
4205
|
+
}).catch(() => null);
|
|
4206
|
+
if (!answer?.ok || typeof answer.publicKey !== "string") return false;
|
|
4207
|
+
if (!Array.isArray(answer.links) || !answer.links.length) return false;
|
|
4208
|
+
const reached = await followIdentityLinks(
|
|
4209
|
+
{
|
|
4210
|
+
publicKey: Buffer.from(pinned.public_key, "base64url").toString(
|
|
4211
|
+
"base64"
|
|
4212
|
+
),
|
|
4213
|
+
signingKey: pinned.signing_key,
|
|
4214
|
+
},
|
|
4215
|
+
answer.links
|
|
4216
|
+
).catch((error) => {
|
|
4217
|
+
log(`people link: ${handle}'s new keys not followed: ${error.message}`);
|
|
4218
|
+
return null;
|
|
4219
|
+
});
|
|
4220
|
+
if (
|
|
4221
|
+
!reached ||
|
|
4222
|
+
reached.publicKey !== answer.publicKey ||
|
|
4223
|
+
reached.signingKey !== answer.signingKey
|
|
4224
|
+
)
|
|
4225
|
+
return false;
|
|
4226
|
+
const publicKey = relayPublicKey(reached.publicKey);
|
|
4227
|
+
store.followRelayPeer(handle, publicKey, reached.signingKey);
|
|
4228
|
+
takeKeys(handle, publicKey);
|
|
4229
|
+
log(`people link: followed ${handle}'s keys to their new ones`);
|
|
4230
|
+
return true;
|
|
4231
|
+
};
|
|
4232
|
+
/** Their open threads take the keys pinned for them now, and what waited goes. */
|
|
4233
|
+
const takeKeys = (handle, publicKey) => {
|
|
4234
|
+
const open = openSealedWith(handle);
|
|
4235
|
+
store.repinThreads(handle, publicKey);
|
|
4236
|
+
store.forgetMeta(waitingKey(handle));
|
|
4237
|
+
const threads = new Set(open.map((thread) => thread.task_id));
|
|
4238
|
+
for (const message of store.undeliveredMessages())
|
|
4239
|
+
if (threads.has(message.task_id)) sealed.sendMessage(message);
|
|
4240
|
+
peopleLink.close(handle);
|
|
4241
|
+
peopleLink.sync();
|
|
4242
|
+
// A member of the person's jams under their new keys reads on without being invited again (jamStore.mjs).
|
|
4243
|
+
void jamStore
|
|
4244
|
+
?.rekey(handle)
|
|
4245
|
+
.catch((error) => log(`jams: ${handle} not re-keyed: ${error.message}`));
|
|
4246
|
+
};
|
|
4247
|
+
/** The person trusts another person's new key: their open threads take it, and what waited goes. */
|
|
4248
|
+
const trustPeer = async (handle) => {
|
|
4249
|
+
const open = openSealedWith(handle);
|
|
4250
|
+
if (!open.length)
|
|
4251
|
+
return { ok: false, error: `you are not friends with ${handle}` };
|
|
4252
|
+
const keyed = await askHarness("relay_key", { to: handle });
|
|
4253
|
+
if (!keyed?.ok || typeof keyed.publicKey !== "string")
|
|
4254
|
+
return {
|
|
4255
|
+
ok: false,
|
|
4256
|
+
error: keyed?.error || `Harness has no keys for ${handle}`,
|
|
4257
|
+
};
|
|
4258
|
+
const publicKey = relayPublicKey(keyed.publicKey);
|
|
4259
|
+
store.pinRelayPeer(handle, publicKey, keyed.signingKey ?? null);
|
|
4260
|
+
takeKeys(handle, publicKey);
|
|
4261
|
+
return {
|
|
4262
|
+
ok: true,
|
|
4263
|
+
handle,
|
|
4264
|
+
fingerprint: await fingerprint(publicKey),
|
|
4265
|
+
};
|
|
4266
|
+
};
|
|
2695
4267
|
// The board as another computer shows it, answered there (liveViews.mjs): on home, the views it keeps for them; on
|
|
2696
4268
|
// a worker, its copies, which a waiting surface here hears move.
|
|
2697
4269
|
const liveViews = createLiveViews({
|
|
@@ -2705,6 +4277,17 @@ export async function startDaemon() {
|
|
|
2705
4277
|
changed: () => boardWaits.bump(),
|
|
2706
4278
|
});
|
|
2707
4279
|
ownMachines = createOwnMachines({
|
|
4280
|
+
onNerve: (from, body) =>
|
|
4281
|
+
nerves?.receive(from, body) ?? { ok: false, error: "not started" },
|
|
4282
|
+
// Home asks for this computer's claim that one of its own agents wrote words in a jam (agentClaims.mjs): given
|
|
4283
|
+
// only for an agent that runs here.
|
|
4284
|
+
onClaim: async (ask) => {
|
|
4285
|
+
const agent = String(ask?.agent || "");
|
|
4286
|
+
if (!installedAgents.includes(agent))
|
|
4287
|
+
return { ok: false, error: `${agent} does not run on this computer` };
|
|
4288
|
+
const claim = await agentClaims.mint(agent, String(ask?.about || ""));
|
|
4289
|
+
return claim ? { ok: true, claim } : { ok: false, error: "no keys here" };
|
|
4290
|
+
},
|
|
2708
4291
|
liveViews: () => liveViews,
|
|
2709
4292
|
viewCopies: () => viewCopies,
|
|
2710
4293
|
directLink,
|
|
@@ -2715,14 +4298,19 @@ export async function startDaemon() {
|
|
|
2715
4298
|
identity: () => relayIdentity,
|
|
2716
4299
|
agents: installedAgents,
|
|
2717
4300
|
ask: (type, input) => bridge.ask(type, input),
|
|
4301
|
+
devices: computerDevices,
|
|
2718
4302
|
boardCommand: (request) => boardCommand(request),
|
|
2719
4303
|
filesRoot: paths.files,
|
|
2720
4304
|
// A computer that became home fetches the dispatcher's model then (the others never do).
|
|
2721
4305
|
changed: () => {
|
|
2722
4306
|
saveStatus();
|
|
4307
|
+
releaseNotice?.computersChanged();
|
|
2723
4308
|
dispatcher.warm();
|
|
2724
4309
|
// A turn waiting for one of these computers starts there once it is back (threadRuns.mjs).
|
|
2725
4310
|
threadRuns.computersChanged();
|
|
4311
|
+
// A computer that became home runs the check-ins and carries out what waited for home; one that stopped, stops.
|
|
4312
|
+
schedules.lookAgain();
|
|
4313
|
+
responses.resume();
|
|
2726
4314
|
},
|
|
2727
4315
|
folders: (options) => machineFolders(options),
|
|
2728
4316
|
repositoryOf: (folder) => repositoryName(folder),
|
|
@@ -2749,7 +4337,7 @@ export async function startDaemon() {
|
|
|
2749
4337
|
onStoodIn: (forId) => boardMirror.startStandIn(forId),
|
|
2750
4338
|
returning: () => void boardMirror.sync(),
|
|
2751
4339
|
onOwnBoard: () => boardMirror.markBring(),
|
|
2752
|
-
askOwnWindows: (call) => askOwnWindows(call),
|
|
4340
|
+
askOwnWindows: (call, route) => askOwnWindows(call, route),
|
|
2753
4341
|
ownModels,
|
|
2754
4342
|
ownLive,
|
|
2755
4343
|
answerCapability: capabilityCheck.answer,
|
|
@@ -2766,7 +4354,9 @@ export async function startDaemon() {
|
|
|
2766
4354
|
? (from, call) => proxyLinks.answer(from, call)
|
|
2767
4355
|
: null,
|
|
2768
4356
|
ownSsh: cloudSsh?.allow ?? null,
|
|
2769
|
-
ownUpdate: (spec
|
|
4357
|
+
ownUpdate: (spec, { here }) =>
|
|
4358
|
+
startUpdate(spec, { from: DAEMON_VERSION, here, log }),
|
|
4359
|
+
ownUpdateState: updateState,
|
|
2770
4360
|
runningVersion: DAEMON_VERSION,
|
|
2771
4361
|
onNotice: (notice) => {
|
|
2772
4362
|
// Home stopped a run on this computer (the person stopped or removed its task).
|
|
@@ -2779,13 +4369,88 @@ export async function startDaemon() {
|
|
|
2779
4369
|
if (notice?.devices === true) swarmDevices.heard();
|
|
2780
4370
|
},
|
|
2781
4371
|
});
|
|
4372
|
+
// Originals (originals.mjs, S6.5): an agent here that read a file attached on another computer hears when it changes
|
|
4373
|
+
// there, and this computer says when an original kept here changes, to the computers that asked.
|
|
4374
|
+
originals = createOriginals({
|
|
4375
|
+
store,
|
|
4376
|
+
events,
|
|
4377
|
+
follow: (folder, onReading) =>
|
|
4378
|
+
sources.subscribe({ kind: "files", folder }, onReading),
|
|
4379
|
+
originOf: (fileId) => {
|
|
4380
|
+
const row = store.db.get(
|
|
4381
|
+
"select machine from board_contributions where source = ? order by rowid limit 1",
|
|
4382
|
+
[`file:${fileId}`]
|
|
4383
|
+
);
|
|
4384
|
+
if (!row) return null;
|
|
4385
|
+
const origin =
|
|
4386
|
+
row.machine ||
|
|
4387
|
+
(ownMachines.isHome() ? machine.id : ownMachines.nervePeers()[0]?.id);
|
|
4388
|
+
return origin && origin !== machine.id ? origin : null;
|
|
4389
|
+
},
|
|
4390
|
+
want: (peer, files) => nerves?.want(peer, files),
|
|
4391
|
+
labelOf: (id) => ownMachines.labelOf(id) || "another computer",
|
|
4392
|
+
nameOf,
|
|
4393
|
+
log,
|
|
4394
|
+
});
|
|
4395
|
+
originals.start();
|
|
4396
|
+
// The nerves (nerves.mjs, S6): what happened here that the person's other computers asked for, in order, once.
|
|
4397
|
+
nerves = createNerves({
|
|
4398
|
+
events,
|
|
4399
|
+
store,
|
|
4400
|
+
machineId: machine.id,
|
|
4401
|
+
peers: () => ownMachines.nervePeers(),
|
|
4402
|
+
linked: (id) => ownMachines.linkedTo(id),
|
|
4403
|
+
send: (id, message) => ownMachines.nerveOver(id, message),
|
|
4404
|
+
mail: (id, message) => ownMachines.nerveMail(id, message),
|
|
4405
|
+
touches: threadTouched,
|
|
4406
|
+
onArrival: arrived,
|
|
4407
|
+
onWant: (from, files) => originals.wanted(from, files),
|
|
4408
|
+
log,
|
|
4409
|
+
});
|
|
4410
|
+
nerves.start();
|
|
4411
|
+
// The jam's own work, to the other people in it (jams.mjs felt, S6.6): this computer's and its other computers', sent
|
|
4412
|
+
// by the computer that holds the board, as every jam event is.
|
|
4413
|
+
events.follow(
|
|
4414
|
+
(happening) =>
|
|
4415
|
+
holdsBoard() &&
|
|
4416
|
+
jams?.felt(
|
|
4417
|
+
happening,
|
|
4418
|
+
happening.machine ? happening.data?.thread : threadTouched(happening)
|
|
4419
|
+
),
|
|
4420
|
+
{ arrivals: true }
|
|
4421
|
+
);
|
|
4422
|
+
// A newer release of Harness, told once for every computer behind it; Settings at Your devices has Update.
|
|
4423
|
+
// Looked for until it is told: the Mac's buddy may not be up yet when the daemon starts.
|
|
4424
|
+
const askAboutModels = () => {
|
|
4425
|
+
if (quiet()) return;
|
|
4426
|
+
local.tellUpgradeAsks((line) =>
|
|
4427
|
+
notices.tellDesktop("Harness", line, "models:", "local-models")
|
|
4428
|
+
);
|
|
4429
|
+
};
|
|
4430
|
+
askAboutModels();
|
|
4431
|
+
setInterval(askAboutModels, MODELS_ASK_EVERY_MS).unref();
|
|
4432
|
+
releaseNotice = createReleaseNotice({
|
|
4433
|
+
store,
|
|
4434
|
+
log,
|
|
4435
|
+
computers: () => ownMachines.versions(),
|
|
4436
|
+
tellsPerson: () => machine.role !== "worker" || ownMachines.actsAlone(),
|
|
4437
|
+
speaks: notices.on,
|
|
4438
|
+
quiet,
|
|
4439
|
+
tell: (line, item) =>
|
|
4440
|
+
notices.tellDesktop("Harness", line, "devices:", item),
|
|
4441
|
+
changed: saveStatus,
|
|
4442
|
+
});
|
|
2782
4443
|
// The board's encrypted backup, for Residents: home seals it, Harness keeps what it cannot read (boardBackup.mjs).
|
|
2783
4444
|
const boardBackup = createBoardBackup({
|
|
2784
4445
|
store,
|
|
2785
4446
|
log,
|
|
2786
4447
|
mirror: boardMirror,
|
|
2787
4448
|
ask: (type, input) => bridge.ask(type, input),
|
|
2788
|
-
|
|
4449
|
+
sharedBackupKeys: () => computerDevices.sharedBackupKeys(),
|
|
4450
|
+
vault: {
|
|
4451
|
+
backupCopy: () => vault.backupCopy(),
|
|
4452
|
+
restoreCopy: (copy) => vault.restoreCopy(copy),
|
|
4453
|
+
},
|
|
2789
4454
|
holdsBoard: () => machine.role !== "worker",
|
|
2790
4455
|
label: () => machine.label,
|
|
2791
4456
|
});
|
|
@@ -2807,42 +4472,111 @@ export async function startDaemon() {
|
|
|
2807
4472
|
log,
|
|
2808
4473
|
modelFor: modelForRun,
|
|
2809
4474
|
held: () => worker.held(),
|
|
4475
|
+
remembered: () => {
|
|
4476
|
+
try {
|
|
4477
|
+
return JSON.parse(store.meta("machine-runs-taken") || "{}");
|
|
4478
|
+
} catch {
|
|
4479
|
+
return {};
|
|
4480
|
+
}
|
|
4481
|
+
},
|
|
4482
|
+
remember: (runs) => store.meta("machine-runs-taken", JSON.stringify(runs)),
|
|
2810
4483
|
});
|
|
4484
|
+
// A friendship ended by Harness's word (an unfriend or a block, from either side): it closes here, and so does the
|
|
4485
|
+
// channel with that person; Harness introduces none again while it stays ended.
|
|
4486
|
+
// Before friends, two people could hold several threads between them (one per shared project); Harness keeps the
|
|
4487
|
+
// newest as their friendship and ends the others (migration 196). One of those ending leaves the friendship and its
|
|
4488
|
+
// channel standing.
|
|
4489
|
+
const friendshipEnded = (threadId) => {
|
|
4490
|
+
const thread = store.getThread(String(threadId || ""));
|
|
4491
|
+
if (!thread || thread.closed_at) return;
|
|
4492
|
+
const stillFriends = store
|
|
4493
|
+
.relayThreads(1_000)
|
|
4494
|
+
.some(
|
|
4495
|
+
(other) =>
|
|
4496
|
+
other.task_id !== thread.task_id &&
|
|
4497
|
+
!other.closed_at &&
|
|
4498
|
+
other.with_agent === thread.with_agent &&
|
|
4499
|
+
other.target_agent === "person"
|
|
4500
|
+
);
|
|
4501
|
+
const closed = store.closeThread(
|
|
4502
|
+
thread.task_id,
|
|
4503
|
+
stillFriends ? UPGRADE_NOTICE : "The friendship ended."
|
|
4504
|
+
);
|
|
4505
|
+
if (!closed.ok || closed.already) return;
|
|
4506
|
+
notifyBoard(closed.task);
|
|
4507
|
+
if (!stillFriends) peopleLink?.close(handleOf(thread.with_agent));
|
|
4508
|
+
};
|
|
4509
|
+
// What existed before friends and jams ends once, on this computer's first start with them (jamUpgrade.mjs).
|
|
4510
|
+
createJamUpgrade({
|
|
4511
|
+
store,
|
|
4512
|
+
notifyBoard,
|
|
4513
|
+
tell: (line) => notifyDesktop(line),
|
|
4514
|
+
log,
|
|
4515
|
+
}).run();
|
|
2811
4516
|
network = createNetwork({
|
|
2812
4517
|
store,
|
|
2813
4518
|
askHarness,
|
|
2814
|
-
relayRequest: sealed.request,
|
|
2815
|
-
openRelayRequest: sealed.openRequest,
|
|
2816
4519
|
fingerprint,
|
|
2817
|
-
myKey: () =>
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
4520
|
+
myKey: () => personKeys?.publicKey ?? null,
|
|
4521
|
+
ended: friendshipEnded,
|
|
4522
|
+
});
|
|
4523
|
+
// The jams the person is in, sealed at Harness under keys made and kept here (jamStore.mjs, docs/jam-plan.md J3).
|
|
4524
|
+
jamStore = createJamStore({
|
|
4525
|
+
store,
|
|
4526
|
+
ask: askHarness,
|
|
4527
|
+
can: () => bridge.has("jams"),
|
|
4528
|
+
// The person's identity (personKeys): what their cards carry, what keys are wrapped to and what signs, with the
|
|
4529
|
+
// earlier keys so what was wrapped or signed before they changed still opens and checks.
|
|
4530
|
+
identity: async () => {
|
|
4531
|
+
if (!personKeys) await refreshIdentity();
|
|
4532
|
+
if (!personKeys)
|
|
4533
|
+
throw new Error(
|
|
4534
|
+
"this computer does not hold your keys yet; approve it from one of your devices"
|
|
4535
|
+
);
|
|
4536
|
+
return {
|
|
4537
|
+
sealingKey: personKeys.publicKey,
|
|
4538
|
+
sealingPrivateKey: personKeys.privateKey,
|
|
4539
|
+
earlierSealingPrivateKeys: personKeys.previous.map(
|
|
4540
|
+
(earlier) => earlier.privateKey
|
|
4541
|
+
),
|
|
4542
|
+
signingKey: personKeys.signingKey,
|
|
4543
|
+
signingPrivateKey: personKeys.signingPrivateKey,
|
|
4544
|
+
pastSigningKeys: JSON.parse(
|
|
4545
|
+
store.meta("identity-past-signing") || "[]"
|
|
4546
|
+
),
|
|
4547
|
+
};
|
|
4548
|
+
},
|
|
4549
|
+
myHandle: () => network.myHandle(),
|
|
4550
|
+
// A jam moved here: its record and room are read on (jams.mjs), and every surface follows.
|
|
4551
|
+
changed: (jamId) => {
|
|
4552
|
+
boardWaits.bump();
|
|
4553
|
+
void jams?.heard(jamId);
|
|
2831
4554
|
},
|
|
4555
|
+
log,
|
|
2832
4556
|
});
|
|
2833
|
-
//
|
|
2834
|
-
|
|
4557
|
+
// Jams: a record of who builds what, the room everyone in the jam reads and writes, and a check before work, built on
|
|
4558
|
+
// every member's computer from the jam's sealed events (jams.mjs, docs/jam-plan.md J4).
|
|
4559
|
+
jams = createJams({
|
|
2835
4560
|
store,
|
|
4561
|
+
jamStore,
|
|
4562
|
+
// An agent's words in a jam carry the claim of the computer it runs on: this one signs for its own agents and for
|
|
4563
|
+
// Harness here; a worker's agent's words get that worker's claim, asked over the channel to it.
|
|
4564
|
+
claimFor: async (agent, text, machineId) => {
|
|
4565
|
+
const about = claimAbout(text);
|
|
4566
|
+
return !machineId || machineId === machine.id
|
|
4567
|
+
? agentClaims.mint(agent, about)
|
|
4568
|
+
: (ownMachines?.claimFrom(machineId, { agent, about }) ?? null);
|
|
4569
|
+
},
|
|
4570
|
+
feel: (happening) => events.receive(happening),
|
|
2836
4571
|
verdicts,
|
|
2837
|
-
// The local guard reads
|
|
4572
|
+
// The local guard reads other people's words in a jam, as any words from outside.
|
|
2838
4573
|
guard: (text) => local.readByGuard(text),
|
|
4574
|
+
wake: (...args) => actions.wakeFor(...args),
|
|
4575
|
+
vault: () => vaultPeers,
|
|
4576
|
+
// A file attached in a jam's room goes to everyone in the jam, sealed (docs/jam-plan.md J4.9).
|
|
4577
|
+
files: { blobPath, keepBlob, fileName, fileLine, checkedAsText },
|
|
2839
4578
|
log,
|
|
2840
4579
|
myHandle: () => network.myHandle(),
|
|
2841
|
-
relayRequest: sealed.request,
|
|
2842
|
-
decideRequest: (id, decision) => network.decide(id, decision),
|
|
2843
|
-
invites: () => network.invites(),
|
|
2844
|
-
sentInvites: () => network.sentProjects(),
|
|
2845
|
-
sendEvent: sealed.sendProjectEvent,
|
|
2846
4580
|
stopRoom: stopThreadRuns,
|
|
2847
4581
|
stopRun: (goalId, agent) => {
|
|
2848
4582
|
for (const child of store.closeGoalChildren(
|
|
@@ -2854,11 +4588,6 @@ export async function startDaemon() {
|
|
|
2854
4588
|
threadRuns.discard(goalId, agent);
|
|
2855
4589
|
notifyBoard(store.getTask(goalId));
|
|
2856
4590
|
},
|
|
2857
|
-
endChannel: (taskId, outcome) => {
|
|
2858
|
-
if (store.closeThread(taskId, outcome).ok)
|
|
2859
|
-
sealed.sendEnd(taskId, "person", outcome);
|
|
2860
|
-
},
|
|
2861
|
-
wake: actions.wakeFor,
|
|
2862
4591
|
wakeRun: (goalId, agent, reason, options) =>
|
|
2863
4592
|
threadRuns.wake(goalId, agent, reason, options),
|
|
2864
4593
|
notifyBoard,
|
|
@@ -2881,11 +4610,12 @@ export async function startDaemon() {
|
|
|
2881
4610
|
...installedAgents.filter((agent) => RUNNERS.has(agent)),
|
|
2882
4611
|
...(actors.available().includes("harness") ? ["harness"] : []),
|
|
2883
4612
|
],
|
|
2884
|
-
worktreeRoot: path.join(paths.home, "
|
|
4613
|
+
worktreeRoot: path.join(paths.home, "jams"),
|
|
2885
4614
|
maxPosts: DEFAULT_MAX_POSTS,
|
|
2886
4615
|
maxWakes: DEFAULT_MAX_WAKES,
|
|
2887
4616
|
});
|
|
2888
|
-
|
|
4617
|
+
// A post in a jam's room goes to everyone in the jam (jams.mjs posted).
|
|
4618
|
+
store.onRoomPost((goalId, post) => jams?.posted(goalId, post));
|
|
2889
4619
|
store.onRoomPost(() => boardChanged());
|
|
2890
4620
|
// The person wrote in a thread: where they left it is worked out once, from their words and the agent's before them.
|
|
2891
4621
|
store.onRoomPost((goalId, post) => {
|
|
@@ -2909,15 +4639,29 @@ export async function startDaemon() {
|
|
|
2909
4639
|
})
|
|
2910
4640
|
.then((changed) => changed && boardChanged());
|
|
2911
4641
|
});
|
|
2912
|
-
places
|
|
4642
|
+
// The person's places at outside networks, kept on home (networkPlaces.mjs); Harness's server is asked only for what
|
|
4643
|
+
// takes a model and the anonymous count of swarms in a place.
|
|
4644
|
+
const networkPlaces = createNetworkPlaces({
|
|
4645
|
+
db: store.db,
|
|
4646
|
+
keys: vault.placeKeys,
|
|
4647
|
+
askServer: (kind, input) =>
|
|
4648
|
+
askHarness("places", { kind, ...input }).then((answer) => {
|
|
4649
|
+
if (answer?.ok === false)
|
|
4650
|
+
throw new Error(answer.error || "Harness refused the request");
|
|
4651
|
+
return answer;
|
|
4652
|
+
}),
|
|
4653
|
+
log,
|
|
4654
|
+
});
|
|
4655
|
+
places = createPlaceCommands({ places: networkPlaces });
|
|
4656
|
+
const stopPlaceCheckIns = networkPlaces.startCheckIns(
|
|
4657
|
+
() => machine.role !== "worker"
|
|
4658
|
+
);
|
|
2913
4659
|
|
|
2914
4660
|
const { plainBoard, roomOf, madeIn, visibleTo, SEALED_ONLY } =
|
|
2915
4661
|
createBoardAccess({
|
|
2916
4662
|
store,
|
|
2917
4663
|
inRoom,
|
|
2918
4664
|
boardCommand,
|
|
2919
|
-
sendThreadMessage: sealed.sendMessage,
|
|
2920
|
-
notifyBoard,
|
|
2921
4665
|
namedPath,
|
|
2922
4666
|
textLike,
|
|
2923
4667
|
coveredImage,
|
|
@@ -2977,42 +4721,94 @@ export async function startDaemon() {
|
|
|
2977
4721
|
return put.ok ? { ...put, fingerprint: allowed.fingerprint } : put;
|
|
2978
4722
|
};
|
|
2979
4723
|
// What the control socket answers that no module answers itself, by command.
|
|
4724
|
+
const spoken = createSpoken({
|
|
4725
|
+
dispatcher,
|
|
4726
|
+
postsOf: (threadId) => store.recentRoomPosts(threadId).posts,
|
|
4727
|
+
titleOf: (threadId) => {
|
|
4728
|
+
const thread = store.getTask(threadId);
|
|
4729
|
+
return thread ? threadView.row(thread).title : "this thread";
|
|
4730
|
+
},
|
|
4731
|
+
nameOf,
|
|
4732
|
+
root: path.join(paths.home, "local"),
|
|
4733
|
+
log,
|
|
4734
|
+
});
|
|
2980
4735
|
const controlCommands = {
|
|
4736
|
+
// An agent's mark on a file or a service for the next agent near it (senseCall.mjs putMark). The log says who left
|
|
4737
|
+
// one and where, never what it says.
|
|
4738
|
+
"senses.mark": (request) => {
|
|
4739
|
+
const cwd = typeof request.cwd === "string" ? request.cwd : process.cwd();
|
|
4740
|
+
const file = request.file
|
|
4741
|
+
? path.resolve(cwd, String(request.file))
|
|
4742
|
+
: null;
|
|
4743
|
+
const mark = putMark({
|
|
4744
|
+
// An intention with no place named is about the folder the agent works in.
|
|
4745
|
+
file:
|
|
4746
|
+
file ?? (request.intent === true && !request.service ? cwd : null),
|
|
4747
|
+
intent: request.intent === true,
|
|
4748
|
+
service: request.service,
|
|
4749
|
+
text: request.text,
|
|
4750
|
+
hours: request.hours,
|
|
4751
|
+
by: nameOf(request.agent),
|
|
4752
|
+
session: sessionOfPid(request.agentPid),
|
|
4753
|
+
});
|
|
4754
|
+
if (mark.error) return { ok: false, error: mark.error };
|
|
4755
|
+
events.append({
|
|
4756
|
+
source: "senses",
|
|
4757
|
+
kind: "mark",
|
|
4758
|
+
subject: mark.file ? path.relative(cwd, mark.file) : "service",
|
|
4759
|
+
text: `${nameOf(request.agent)} left a mark on ${mark.file ? "a file" : "a service"}, for ${Math.round((Date.parse(mark.until) - Date.parse(mark.at)) / 3_600_000)} h`,
|
|
4760
|
+
});
|
|
4761
|
+
return {
|
|
4762
|
+
ok: true,
|
|
4763
|
+
mark: { id: mark.id, until: mark.until },
|
|
4764
|
+
answer: `Left. The next agent near ${mark.file ? path.relative(cwd, mark.file) || mark.file : mark.service} reads it once, until ${mark.until}.`,
|
|
4765
|
+
};
|
|
4766
|
+
},
|
|
4767
|
+
"voice.say": (request) => spoken.say(request),
|
|
4768
|
+
"voice.quiet": () => spoken.quiet(),
|
|
2981
4769
|
status: () => ({
|
|
2982
4770
|
ok: true,
|
|
2983
4771
|
...state,
|
|
2984
4772
|
counts: store.counts(),
|
|
2985
4773
|
// The app shows its setup until the person finishes it there (setup.finish). A computer set up before the app
|
|
2986
4774
|
// had setup has no such mark, and nothing left to set up.
|
|
2987
|
-
setupDone:
|
|
4775
|
+
setupDone: readConfig(paths.config, {}).setupDone !== false,
|
|
4776
|
+
// The Harness extension in a browser here is asking this computer for work: setup waits on it, the tour skips it.
|
|
4777
|
+
extension: browserWake.listening(),
|
|
4778
|
+
connection: connection.status(),
|
|
2988
4779
|
}),
|
|
2989
4780
|
// "Tell me when an agent needs me" in setup: off stops desktop notices (notify.mjs), never the board's own.
|
|
2990
4781
|
"setup.notify": (request) => {
|
|
2991
|
-
|
|
2992
|
-
...
|
|
4782
|
+
updateConfig(paths.config, (saved) => ({
|
|
4783
|
+
...saved,
|
|
2993
4784
|
desktopNotices: request.on !== false,
|
|
2994
|
-
});
|
|
4785
|
+
}));
|
|
2995
4786
|
return { ok: true };
|
|
2996
4787
|
},
|
|
2997
4788
|
"setup.finish": () => {
|
|
2998
|
-
|
|
2999
|
-
...
|
|
4789
|
+
updateConfig(paths.config, (saved) => ({
|
|
4790
|
+
...saved,
|
|
3000
4791
|
setupDone: true,
|
|
3001
|
-
});
|
|
4792
|
+
}));
|
|
3002
4793
|
return { ok: true };
|
|
3003
4794
|
},
|
|
3004
4795
|
// The buddy's tour: once, on the computer that holds the swarm, after setup. `setup` says it may still come due.
|
|
3005
4796
|
"tour.state": () => {
|
|
3006
|
-
const config =
|
|
4797
|
+
const config = readConfig(paths.config, {});
|
|
3007
4798
|
const setup = config.setupDone === false;
|
|
3008
4799
|
const home = machine.role !== "worker";
|
|
3009
|
-
return {
|
|
4800
|
+
return {
|
|
4801
|
+
ok: true,
|
|
4802
|
+
setup,
|
|
4803
|
+
due: home && !setup && !config.tourDone,
|
|
4804
|
+
extension: browserWake.listening(),
|
|
4805
|
+
};
|
|
3010
4806
|
},
|
|
3011
4807
|
"tour.done": () => {
|
|
3012
|
-
|
|
3013
|
-
...
|
|
4808
|
+
updateConfig(paths.config, (saved) => ({
|
|
4809
|
+
...saved,
|
|
3014
4810
|
tourDone: true,
|
|
3015
|
-
});
|
|
4811
|
+
}));
|
|
3016
4812
|
return { ok: true };
|
|
3017
4813
|
},
|
|
3018
4814
|
doctor: () => ({
|
|
@@ -3030,19 +4826,32 @@ export async function startDaemon() {
|
|
|
3030
4826
|
);
|
|
3031
4827
|
return { ok: true, accepted: true, indexing: true };
|
|
3032
4828
|
},
|
|
3033
|
-
// The board's encrypted backup (npx tryharness backup, and setup): how it stands, turn it on
|
|
4829
|
+
// The board's encrypted backup (npx tryharness backup, and setup): how it stands, turn it on,
|
|
3034
4830
|
// back up now, bring a backup back, turn it off.
|
|
3035
4831
|
"backup.status": () => boardBackup.status(),
|
|
3036
|
-
"backup.on": (
|
|
4832
|
+
"backup.on": () => boardBackup.turnOn(),
|
|
3037
4833
|
"backup.now": () => boardBackup.backUp(),
|
|
3038
4834
|
"backup.restore": (request) =>
|
|
3039
|
-
boardBackup.restore(
|
|
4835
|
+
boardBackup.restore({
|
|
3040
4836
|
version: Number(request.version) || undefined,
|
|
3041
4837
|
}),
|
|
3042
4838
|
"backup.off": () => boardBackup.turnOff(),
|
|
3043
4839
|
// List them, add or confirm a new one on home, name this one, make this one home, take this one off the account
|
|
3044
4840
|
// (npx tryharness uninstall); take another off, and each one's agents' models, set on the computer they run on.
|
|
3045
|
-
|
|
4841
|
+
// With when each computer's link broke, if it is broken now (nerves.mjs).
|
|
4842
|
+
"machines.list": onMachines(async () => {
|
|
4843
|
+
const listed = await ownMachines.list();
|
|
4844
|
+
const cut = new Map(
|
|
4845
|
+
(nerves?.status() ?? []).map((nerve) => [nerve.id, nerve.cutSince])
|
|
4846
|
+
);
|
|
4847
|
+
return {
|
|
4848
|
+
...listed,
|
|
4849
|
+
machines: (listed.machines ?? []).map((each) => ({
|
|
4850
|
+
...each,
|
|
4851
|
+
linkBrokenSince: each.direct ? null : (cut.get(each.id) ?? null),
|
|
4852
|
+
})),
|
|
4853
|
+
};
|
|
4854
|
+
}),
|
|
3046
4855
|
"machines.refresh": onMachines((request) =>
|
|
3047
4856
|
request.agent === "user"
|
|
3048
4857
|
? ownMachines.refreshInventory(String(request.computer || ""), {
|
|
@@ -3059,7 +4868,65 @@ export async function startDaemon() {
|
|
|
3059
4868
|
"machines.add": onMachines((request) =>
|
|
3060
4869
|
ownMachines.add(request.code, { hosted: request.hosted === true })
|
|
3061
4870
|
),
|
|
4871
|
+
// The person compared the code a computer being added shows with this one's (machines.add's "compare").
|
|
4872
|
+
"machines.match": onMachines((request) =>
|
|
4873
|
+
request.agent === "user" || request.agent === undefined
|
|
4874
|
+
? ownMachines.match(String(request.id || ""), request.matches === true)
|
|
4875
|
+
: { ok: false, error: "only the person says whether codes match" }
|
|
4876
|
+
),
|
|
3062
4877
|
"machines.name": onMachines((request) => ownMachines.rename(request.label)),
|
|
4878
|
+
// The person's devices (tryharness devices): read from their signed list, and changed by this computer signing.
|
|
4879
|
+
"devices.list": () => computerDevices.list(),
|
|
4880
|
+
"devices.rename": (request) =>
|
|
4881
|
+
request.agent === "user"
|
|
4882
|
+
? computerDevices.rename(
|
|
4883
|
+
String(request.device || ""),
|
|
4884
|
+
String(request.label || "")
|
|
4885
|
+
)
|
|
4886
|
+
: { ok: false, error: "only the person renames a device" },
|
|
4887
|
+
"devices.remove": async (request) => {
|
|
4888
|
+
if (request.agent !== "user")
|
|
4889
|
+
return { ok: false, error: "only the person removes a device" };
|
|
4890
|
+
const removed = await computerDevices.remove(
|
|
4891
|
+
String(request.device || "")
|
|
4892
|
+
);
|
|
4893
|
+
// The new recovery code is shown by the one who removed the device, so it does not wait to be shown again.
|
|
4894
|
+
if (removed.recoveryCode) computerDevices.takeRecoveryCode();
|
|
4895
|
+
if (removed.keysChanged) await refreshIdentity();
|
|
4896
|
+
return removed;
|
|
4897
|
+
},
|
|
4898
|
+
// The recovery code this computer made for the person (their keys changed here, or it made them), shown once.
|
|
4899
|
+
"devices.recovery-code": (request) =>
|
|
4900
|
+
request.agent === "user"
|
|
4901
|
+
? { ok: true, recovery: computerDevices.takeRecoveryCode() }
|
|
4902
|
+
: { ok: false, error: "only the person sees their recovery code" },
|
|
4903
|
+
// A browser or phone waiting for approval, approved from this computer by comparing codes (owner, November 10:
|
|
4904
|
+
// adding a phone from the buddy should not need a separate browser to finish).
|
|
4905
|
+
"devices.waiting": () =>
|
|
4906
|
+
computerDevices.waiting().then((waiting) => ({ ok: true, waiting })),
|
|
4907
|
+
"devices.compare": (request) =>
|
|
4908
|
+
request.agent === "user"
|
|
4909
|
+
? computerDevices.compareWaiting(String(request.device || ""))
|
|
4910
|
+
: { ok: false, error: "only the person compares codes" },
|
|
4911
|
+
"devices.approve": (request) =>
|
|
4912
|
+
request.agent === "user"
|
|
4913
|
+
? computerDevices.approveWaiting(String(request.id || ""))
|
|
4914
|
+
: { ok: false, error: "only the person approves a device" },
|
|
4915
|
+
"devices.decline": (request) =>
|
|
4916
|
+
request.agent === "user"
|
|
4917
|
+
? computerDevices.declineWaiting(String(request.device || ""))
|
|
4918
|
+
: { ok: false, error: "only the person turns a device down" },
|
|
4919
|
+
// Add a phone in the buddy (device redesign 1.8g): Harness's address for the phone, which signs in there and is
|
|
4920
|
+
// approved like any device. Drawn here, as a QR code's squares, since the buddy has nothing that draws one.
|
|
4921
|
+
"devices.phone": async () => {
|
|
4922
|
+
const url = `${String(config.origin || "https://tryharness.ai").replace(/\/$/, "")}/m`;
|
|
4923
|
+
const { default: encodeQR } = await import("qr");
|
|
4924
|
+
return {
|
|
4925
|
+
ok: true,
|
|
4926
|
+
url,
|
|
4927
|
+
modules: encodeQR(url, "raw", { ecc: "medium", border: 2 }),
|
|
4928
|
+
};
|
|
4929
|
+
},
|
|
3063
4930
|
// This computer, or another of the person's, which is asked to take Home itself (the buddy's Make Home).
|
|
3064
4931
|
"machines.home": onMachines((request) =>
|
|
3065
4932
|
!request.computer || request.agent === "user"
|
|
@@ -3075,9 +4942,12 @@ export async function startDaemon() {
|
|
|
3075
4942
|
// tryharness machines update: one of the person's computers fetches a newer signed release and sets it up.
|
|
3076
4943
|
"machines.update": onMachines((request) =>
|
|
3077
4944
|
request.agent === "user"
|
|
3078
|
-
? ownMachines.update(request)
|
|
4945
|
+
? ownMachines.update(request).finally(() => {
|
|
4946
|
+
releaseNotice.computersChanged();
|
|
4947
|
+
})
|
|
3079
4948
|
: { ok: false, error: "only the person updates a computer" }
|
|
3080
4949
|
),
|
|
4950
|
+
"releases.status": () => releaseNotice.view(),
|
|
3081
4951
|
"machines.models": onMachines((request) =>
|
|
3082
4952
|
ownMachines.models({ refresh: request.refresh === true })
|
|
3083
4953
|
),
|
|
@@ -3111,41 +4981,13 @@ export async function startDaemon() {
|
|
|
3111
4981
|
),
|
|
3112
4982
|
// The runs going on this computer now (tryharness runs), for someone at its terminal.
|
|
3113
4983
|
"runs.here": () => ({ ok: true, runs: taskRuns.running() }),
|
|
3114
|
-
"relay.request": (request) =>
|
|
3115
|
-
sealed.request({
|
|
3116
|
-
to: request.to,
|
|
3117
|
-
fromAgent: request.fromAgent,
|
|
3118
|
-
about: request.about,
|
|
3119
|
-
brief: request.brief,
|
|
3120
|
-
refs: request.refs,
|
|
3121
|
-
trustNewKey: request.trustNewKey === true,
|
|
3122
|
-
readable: request.readable === true,
|
|
3123
|
-
}),
|
|
3124
4984
|
"relay.peers": () => sealed.peers(),
|
|
3125
|
-
"
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
4985
|
+
"relay.trust": (request) =>
|
|
4986
|
+
trustPeer(
|
|
4987
|
+
String(request.handle || "")
|
|
4988
|
+
.toLowerCase()
|
|
4989
|
+
.replace(/^@/, "")
|
|
3130
4990
|
),
|
|
3131
|
-
}),
|
|
3132
|
-
// Which computer this is, for the Harness extension's native host (nativeHost.mjs): the key its window pairs with.
|
|
3133
|
-
"phone.identity": () => {
|
|
3134
|
-
const self = ownMachines?.status();
|
|
3135
|
-
return {
|
|
3136
|
-
ok: true,
|
|
3137
|
-
publicKey: phones.publicKey,
|
|
3138
|
-
hostname: os.hostname().slice(0, 64),
|
|
3139
|
-
label: self?.label ?? null,
|
|
3140
|
-
role: self?.role ?? null,
|
|
3141
|
-
// A window links here only once this computer is in the swarm and on Harness: a worker still waiting for its
|
|
3142
|
-
// code would answer the window's board calls with "not confirmed".
|
|
3143
|
-
joined: !ownMachines || ownMachines.isHome() || ownMachines.joined(),
|
|
3144
|
-
connected: state.connected === true,
|
|
3145
|
-
};
|
|
3146
|
-
},
|
|
3147
|
-
// The Harness extension asking to hold this browser's link itself, from its native host (nativeHost.mjs).
|
|
3148
|
-
"phone.link.extension": () => phones.extensionOffer(config.origin),
|
|
3149
4991
|
// The extension's native host waiting for what this computer hands the Harness page (browserWake.mjs).
|
|
3150
4992
|
"browser.wake.next": (request) =>
|
|
3151
4993
|
browserWake
|
|
@@ -3154,14 +4996,7 @@ export async function startDaemon() {
|
|
|
3154
4996
|
// Which page the person is on, from the extension's native host, for the buddy's chip (browserPage.mjs).
|
|
3155
4997
|
"browser.page.set": (request) => browserPage.set(request),
|
|
3156
4998
|
"browser.page": (request) => browserPage.read(request),
|
|
3157
|
-
//
|
|
3158
|
-
"phone.link.ask": (request) =>
|
|
3159
|
-
phones.linkAsk.request({
|
|
3160
|
-
id: request.id,
|
|
3161
|
-
label: request.label,
|
|
3162
|
-
waitMs: Math.min(Number(request.waitMs) || 0, 25_000),
|
|
3163
|
-
}),
|
|
3164
|
-
// The person's answer to a browser asking, or to a device waiting for them, on this computer or another of theirs.
|
|
4999
|
+
// The person's answer to a device waiting for them, on this computer or another of theirs.
|
|
3165
5000
|
"phone.link.answer": (request) =>
|
|
3166
5001
|
request.agent === "user"
|
|
3167
5002
|
? swarmDevices.decide(
|
|
@@ -3169,11 +5004,10 @@ export async function startDaemon() {
|
|
|
3169
5004
|
request.allow === true ? "allow" : "refuse"
|
|
3170
5005
|
)
|
|
3171
5006
|
: { ok: false, error: "only the person allows a device" },
|
|
3172
|
-
// `swarm`: every device
|
|
5007
|
+
// `swarm`: every device on the person's computers, this one's included, as home keeps the list.
|
|
3173
5008
|
"phone.list": () => ({
|
|
3174
5009
|
ok: true,
|
|
3175
5010
|
phones: phones.list(),
|
|
3176
|
-
asks: phones.linkAsk.list(),
|
|
3177
5011
|
swarm: swarmDevices.list(),
|
|
3178
5012
|
}),
|
|
3179
5013
|
"phone.revoke": (request) => phones.disconnect(String(request.id ?? "")),
|
|
@@ -3200,16 +5034,25 @@ export async function startDaemon() {
|
|
|
3200
5034
|
runs: [...activeRuns.values()].map(({ agent, id }) => ({ agent, id })),
|
|
3201
5035
|
queued: store.runnableTasks(installedAgents, machine.id).length,
|
|
3202
5036
|
agents: installedAgents,
|
|
3203
|
-
})
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
5037
|
+
})
|
|
5038
|
+
.then((activity) => ({
|
|
5039
|
+
ok: true,
|
|
5040
|
+
...activity,
|
|
5041
|
+
agentPids: [...activity.agentPids, ...runningPids(), process.pid],
|
|
5042
|
+
listenerIdleMs: Date.now() - listenerAt,
|
|
5043
|
+
phonesPaired: phones
|
|
5044
|
+
.list()
|
|
5045
|
+
.filter((device) => device.kind === "phone" && !device.revoked_at)
|
|
5046
|
+
.length,
|
|
5047
|
+
}))
|
|
5048
|
+
// The machine for Lid-Closed Mode's loop, read fresh through the launcher when there is one (the battery as
|
|
5049
|
+
// `ioreg` would print it, without starting it every 5 s), else as last read.
|
|
5050
|
+
.then(async (answer) => ({
|
|
5051
|
+
...answer,
|
|
5052
|
+
machine: native?.available()
|
|
5053
|
+
? await native.machine().catch(() => machineSense.now())
|
|
5054
|
+
: machineSense.now(),
|
|
5055
|
+
})),
|
|
3213
5056
|
// The desktop app says how the Mac is (working, standby, or null when Lid-Closed Mode is off), with the battery.
|
|
3214
5057
|
"machine.state": (request) => {
|
|
3215
5058
|
const wasQuiet = quiet();
|
|
@@ -3307,6 +5150,32 @@ export async function startDaemon() {
|
|
|
3307
5150
|
)
|
|
3308
5151
|
toolCallsHeard.set(String(request.agent), Date.now());
|
|
3309
5152
|
if (command === "agent.toolsListed") return { ok: true };
|
|
5153
|
+
// Only Harness keeps a watch it armed (threadWatches.mjs): an agent or the person arms one, never keeps one. Nor
|
|
5154
|
+
// does anyone but Harness say a watch tripped (watchResponses.mjs): a computer tells home what it read itself.
|
|
5155
|
+
if (command === "board.watch.keep")
|
|
5156
|
+
return { ok: false, error: "set a watch with board.watch.arm" };
|
|
5157
|
+
if (command === "board.watch.answer")
|
|
5158
|
+
return { ok: false, error: "only Harness says a watch tripped" };
|
|
5159
|
+
// Nor ends a wait as answered (threadWatches.mjs): the agent that set it, or the person, drops it instead.
|
|
5160
|
+
if (command === "board.watch.end")
|
|
5161
|
+
return { ok: false, error: "only Harness ends a wait it answered" };
|
|
5162
|
+
// A run whose turn began with something from outside waits for the person for what it may not do alone (S7.5).
|
|
5163
|
+
if (
|
|
5164
|
+
command.startsWith("board.") &&
|
|
5165
|
+
request.agent &&
|
|
5166
|
+
request.agent !== "user"
|
|
5167
|
+
) {
|
|
5168
|
+
const run = callerRun(request);
|
|
5169
|
+
const thread = run ? store.getTask(run.id)?.parent_id : null;
|
|
5170
|
+
const held = thread
|
|
5171
|
+
? outsideRuns.check(request, {
|
|
5172
|
+
thread,
|
|
5173
|
+
agent: String(request.agent),
|
|
5174
|
+
name: nameOf(String(request.agent)),
|
|
5175
|
+
})
|
|
5176
|
+
: null;
|
|
5177
|
+
if (held) return held;
|
|
5178
|
+
}
|
|
3310
5179
|
if (command.startsWith("board.")) return answerBoard(request);
|
|
3311
5180
|
if (local.handles(command)) return local.command(request);
|
|
3312
5181
|
if (Object.hasOwn(controlCommands, command))
|
|
@@ -3317,6 +5186,7 @@ export async function startDaemon() {
|
|
|
3317
5186
|
}
|
|
3318
5187
|
// An agent's call to Harness from its MCP server on this computer, carried on the bridge (mcpRelay.mjs).
|
|
3319
5188
|
if (mcpRelay.handles(command)) return mcpRelay.run(request);
|
|
5189
|
+
if (senseTools.handles(command)) return senseTools.run(request);
|
|
3320
5190
|
if (setupChoices.handles(command)) return setupChoices.answer(request);
|
|
3321
5191
|
return { ok: false, error: "unknown command" };
|
|
3322
5192
|
};
|
|
@@ -3324,8 +5194,22 @@ export async function startDaemon() {
|
|
|
3324
5194
|
// (lineup.mjs joinAgent, on Harness's own Node), then checked again.
|
|
3325
5195
|
const toolCallsHeard = new Map();
|
|
3326
5196
|
const heardSince = (agent, at) => (toolCallsHeard.get(agent) ?? 0) >= at;
|
|
3327
|
-
|
|
3328
|
-
|
|
5197
|
+
// Codex runs Harness's hooks only once the person approves them in Codex (hookDialects.mjs): its check runs with its
|
|
5198
|
+
// hooks on, so its session-start hook, heard during the check, says they are approved; not heard, setup asks for it.
|
|
5199
|
+
const NEEDS_HOOK_APPROVAL = new Set(["codex"]);
|
|
5200
|
+
const toolCheck = async (agent) => {
|
|
5201
|
+
const started = Date.now();
|
|
5202
|
+
const result = await checkTools(agent, {
|
|
5203
|
+
heardSince,
|
|
5204
|
+
deadlineMs: TOOL_CHECK_DEADLINE_MS,
|
|
5205
|
+
});
|
|
5206
|
+
if (!NEEDS_HOOK_APPROVAL.has(agent) || result.state !== "loaded")
|
|
5207
|
+
return result;
|
|
5208
|
+
return {
|
|
5209
|
+
...result,
|
|
5210
|
+
hooks: (agentsHeard.get(agent) ?? 0) >= started ? "heard" : "approve",
|
|
5211
|
+
};
|
|
5212
|
+
};
|
|
3329
5213
|
controlCommands["setup.toolCheck"] = (request) =>
|
|
3330
5214
|
toolCheck(String(request.target || "")).then((result) => ({
|
|
3331
5215
|
ok: true,
|
|
@@ -3348,6 +5232,7 @@ export async function startDaemon() {
|
|
|
3348
5232
|
answer: answerControl,
|
|
3349
5233
|
check: (request, socket) => authority.checkCaller(request, socket),
|
|
3350
5234
|
});
|
|
5235
|
+
const socketMade = socketIdentity(paths.socket);
|
|
3351
5236
|
|
|
3352
5237
|
// What Harness's server sends this computer, by type. One that asks for an answer gets one bridge_response with its
|
|
3353
5238
|
// requestId.
|
|
@@ -3376,6 +5261,8 @@ export async function startDaemon() {
|
|
|
3376
5261
|
profile: (message) => keepProfile(message.profile),
|
|
3377
5262
|
// The account's computers, on every hello and goodbye: each one's name, role, key and whether it is on.
|
|
3378
5263
|
machines: (message) => ownMachines?.introduce(message),
|
|
5264
|
+
// The two facts of "connected" for this computer, whenever either changes (src/server/device/connection.ts).
|
|
5265
|
+
connection: (message) => connection.heard(message),
|
|
3379
5266
|
// One of them taken off the account from another (the Swarm map's Remove).
|
|
3380
5267
|
machine_removed: (message) => ownMachines?.removed(message),
|
|
3381
5268
|
// Between this computer and another of the person's: a worker's sealed call (on home), the join, a notice.
|
|
@@ -3402,6 +5289,10 @@ export async function startDaemon() {
|
|
|
3402
5289
|
asks.retry();
|
|
3403
5290
|
void usageTotals.sendDue();
|
|
3404
5291
|
void cloudAgents?.sync();
|
|
5292
|
+
// Every jam read on from where this computer was when it went off (jamStore.mjs).
|
|
5293
|
+
if (holdsBoard()) void jams?.sync().catch(() => undefined);
|
|
5294
|
+
// A thread's notes Harness can read now that it says it reads for the memory (threadNotes.mjs).
|
|
5295
|
+
if (holdsBoard()) void threadNotes.fold().catch(() => undefined);
|
|
3405
5296
|
},
|
|
3406
5297
|
// The person changed what runs on this cloud computer (Harness's server, cloud computers' setup).
|
|
3407
5298
|
cloud_setup: () => void cloudAgents?.sync(),
|
|
@@ -3409,6 +5300,11 @@ export async function startDaemon() {
|
|
|
3409
5300
|
// up, and Harness lets the box sleep then.
|
|
3410
5301
|
cloud_save: () => void cloudSave?.save(),
|
|
3411
5302
|
harness_ready: () => harnessOffers.reofferAll(),
|
|
5303
|
+
// A read Harness held for a browser that was not open came back (src/server/device/heldThreadReads.ts).
|
|
5304
|
+
held_read_result: (message) => harnessOffers.heldAnswer(message),
|
|
5305
|
+
harness_permission: (message) => harnessOffers.permission(message),
|
|
5306
|
+
bankr_approval: (message) => bankrApprovals.asked(message),
|
|
5307
|
+
bankr_approval_settled: (message) => bankrApprovals.settled(message),
|
|
3412
5308
|
agent_setup: (message) => {
|
|
3413
5309
|
if (Array.isArray(message.agents))
|
|
3414
5310
|
actors.updateCloudSetup(message.agents);
|
|
@@ -3468,23 +5364,41 @@ export async function startDaemon() {
|
|
|
3468
5364
|
sealed.receive(message.type, message.input, respondTo(message)),
|
|
3469
5365
|
thread_end: (message) =>
|
|
3470
5366
|
sealed.receive(message.type, message.input, respondTo(message)),
|
|
3471
|
-
thread_ack: (message) =>
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
5367
|
+
thread_ack: (message) => threadTaken(message),
|
|
5368
|
+
// The person's device list lost a device (src/server/device/deviceRecords.ts): its channels here close now.
|
|
5369
|
+
devices_changed: () => void devicesChanged(),
|
|
5370
|
+
// The other person's computer introducing a channel on an accepted thread, carried by Harness (peopleLink.mjs).
|
|
5371
|
+
thread_link: (message) =>
|
|
5372
|
+
void Promise.resolve(peopleLink?.answer(message.input || {}))
|
|
5373
|
+
.then((result) =>
|
|
5374
|
+
respondTo(message)({
|
|
5375
|
+
ok: true,
|
|
5376
|
+
result: result ?? { ok: false, error: "still starting" },
|
|
5377
|
+
})
|
|
5378
|
+
)
|
|
5379
|
+
.catch((error) =>
|
|
5380
|
+
respondTo(message)({ ok: false, error: error.message })
|
|
5381
|
+
),
|
|
5382
|
+
// Another person's keys changed (Harness's tellKeyChanged): followed along their links when they lead from the
|
|
5383
|
+
// keys pinned here, else their friendship waits for the person here to trust them.
|
|
5384
|
+
relay_key_changed: (message) => {
|
|
3477
5385
|
const handle = String(message.input?.handle || "");
|
|
3478
|
-
|
|
3479
|
-
|
|
5386
|
+
void followPeer(handle).then((followed) => {
|
|
5387
|
+
if (!followed) keyChanged(handle, "replaced");
|
|
5388
|
+
});
|
|
3480
5389
|
},
|
|
3481
|
-
//
|
|
5390
|
+
// A friendship ended (unfriended or blocked, from either side; Harness's endFriendship).
|
|
5391
|
+
relay_friend_ended: (message) => friendshipEnded(message.input?.id),
|
|
5392
|
+
// A jam this computer's person is in moved at Harness: an event landed, or its members or key changed.
|
|
5393
|
+
jam_event: (message) =>
|
|
5394
|
+
holdsBoard() ? jamStore?.heard(message) : undefined,
|
|
5395
|
+
jam_changed: (message) =>
|
|
5396
|
+
holdsBoard() ? jamStore?.heard(message) : undefined,
|
|
5397
|
+
// Someone asked to be the person's friend (network.mjs lists it): told on the desktop, answered in Harness.
|
|
3482
5398
|
relay_requested: (message) => {
|
|
3483
|
-
const
|
|
3484
|
-
if (
|
|
3485
|
-
|
|
3486
|
-
`${input.from} asked to reach ${input.to === "person" ? "you" : `your ${nameOf(String(input.to || ""))}`}. Answer it in Swarms.`
|
|
3487
|
-
);
|
|
5399
|
+
const from = String(message.input?.from || "");
|
|
5400
|
+
if (!/^[a-z0-9][a-z0-9-]{2,19}$/.test(from)) return;
|
|
5401
|
+
notices.notify(`${from} asked to be your friend. Answer it in Harness.`);
|
|
3488
5402
|
},
|
|
3489
5403
|
// Harness's own list of paired devices (labels and dates); on a cloud computer, a fresh link offer for one of the
|
|
3490
5404
|
// person's windows. Disconnecting one is the person's alone: on this computer (npx tryharness phone revoke) or
|
|
@@ -3501,20 +5415,79 @@ export async function startDaemon() {
|
|
|
3501
5415
|
error:
|
|
3502
5416
|
"disconnect a device from one you paired, or on this computer: npx tryharness phone revoke <id>",
|
|
3503
5417
|
}
|
|
3504
|
-
:
|
|
3505
|
-
? phones.cloudOffer()
|
|
3506
|
-
: { ok: false, error: "unknown phones command" };
|
|
5418
|
+
: { ok: false, error: "unknown phones command" };
|
|
3507
5419
|
respondTo(message)({ ok: true, result });
|
|
3508
5420
|
},
|
|
3509
|
-
//
|
|
5421
|
+
// What Harness carries sealed for a device: its channel's introduction, and what waited while this computer was
|
|
5422
|
+
// off. Opened, answered and sealed again here.
|
|
3510
5423
|
sealed: (message) =>
|
|
3511
5424
|
answerWith(
|
|
3512
5425
|
message,
|
|
3513
|
-
() => phones.handle(message.input),
|
|
5426
|
+
() => phones.handle(message.input, { relayed: true }),
|
|
3514
5427
|
(error) => `the phone request failed: ${error.message}`
|
|
3515
5428
|
),
|
|
3516
5429
|
harness_file: (message) =>
|
|
3517
5430
|
answerWith(message, () => harnessFile(message.input || {})),
|
|
5431
|
+
// An event that arrived at one of this computer's outside addresses, sealed to it by Harness (S7.2).
|
|
5432
|
+
outside_event: (message) =>
|
|
5433
|
+
answerWith(message, () => outsideEvents.arrived(message.input || {})),
|
|
5434
|
+
// Harness's server's door call for one of the person's browsers: asked here or on the computer it runs on.
|
|
5435
|
+
device_call: (message) =>
|
|
5436
|
+
answerWith(message, () => deviceDoor.fromHarness(message.input)),
|
|
5437
|
+
// The person's apps, held here (docs/one-link-plan.md L3.5): Harness hands one over with its sign-in, or lets one
|
|
5438
|
+
// go; and Harness's turns list and call them through this computer, as the agent "harness", hosted.
|
|
5439
|
+
app_move: (message) =>
|
|
5440
|
+
answerWith(message, () => connectors.adopt(message.input || {})),
|
|
5441
|
+
app_forget: (message) =>
|
|
5442
|
+
answerWith(message, () =>
|
|
5443
|
+
connectors.forget(String(message.input?.serverId || ""))
|
|
5444
|
+
),
|
|
5445
|
+
app_tools: (message) =>
|
|
5446
|
+
answerWith(message, () => {
|
|
5447
|
+
const id = `app:${String(message.input?.serverId || "")}`;
|
|
5448
|
+
connectors.useNamespace(
|
|
5449
|
+
String(message.input?.serverId || ""),
|
|
5450
|
+
String(message.input?.namespace || "")
|
|
5451
|
+
);
|
|
5452
|
+
// Just moved and still being read, it has no grants yet: said so, for Harness to wait for it.
|
|
5453
|
+
const status = connectors.appStatus(
|
|
5454
|
+
String(message.input?.serverId || "")
|
|
5455
|
+
);
|
|
5456
|
+
if (status !== null && status !== "ready")
|
|
5457
|
+
return { ok: true, status, tools: [] };
|
|
5458
|
+
const listed = connectors.command(
|
|
5459
|
+
{ command: "board.connector.tools", id, hostedCaller: true },
|
|
5460
|
+
"harness"
|
|
5461
|
+
);
|
|
5462
|
+
return listed.ok
|
|
5463
|
+
? { ok: true, status: listed.connection.status, tools: listed.tools }
|
|
5464
|
+
: listed;
|
|
5465
|
+
}),
|
|
5466
|
+
app_call: (message) =>
|
|
5467
|
+
answerWith(message, () =>
|
|
5468
|
+
connectors.command(
|
|
5469
|
+
{
|
|
5470
|
+
command: "board.connector.call",
|
|
5471
|
+
id: `app:${String(message.input?.serverId || "")}`,
|
|
5472
|
+
tool: String(message.input?.tool || ""),
|
|
5473
|
+
arguments: message.input?.arguments || {},
|
|
5474
|
+
requestId: message.input?.requestId,
|
|
5475
|
+
hostedCaller: true,
|
|
5476
|
+
},
|
|
5477
|
+
"harness"
|
|
5478
|
+
)
|
|
5479
|
+
),
|
|
5480
|
+
app_result: (message) =>
|
|
5481
|
+
answerWith(message, () =>
|
|
5482
|
+
connectors.command(
|
|
5483
|
+
{
|
|
5484
|
+
command: "board.connector.result",
|
|
5485
|
+
id: String(message.input?.operation || ""),
|
|
5486
|
+
hostedCaller: true,
|
|
5487
|
+
},
|
|
5488
|
+
"harness"
|
|
5489
|
+
)
|
|
5490
|
+
),
|
|
3518
5491
|
// A hosted caller's board call, identified by the name Harness assigns it. The same checks as the local control
|
|
3519
5492
|
// socket apply; the server persists nothing of it.
|
|
3520
5493
|
board: (message) =>
|
|
@@ -3568,48 +5541,140 @@ export async function startDaemon() {
|
|
|
3568
5541
|
schedules.start();
|
|
3569
5542
|
usageTotals.start();
|
|
3570
5543
|
specialtyNotice.start();
|
|
5544
|
+
releaseNotice.start();
|
|
3571
5545
|
const rescan = setInterval(() => {
|
|
3572
5546
|
if (!quiet()) void sync();
|
|
3573
5547
|
}, RESCAN_MS);
|
|
3574
|
-
|
|
5548
|
+
// The agents' history folders, through the file source (fileSource.mjs), quietly: a session file changes with every
|
|
5549
|
+
// message an agent writes, so the log never hears of them, and the sync catches up on its own at each start.
|
|
3575
5550
|
for (const agent of ["claude-code", "codex", "pi"]) {
|
|
3576
5551
|
if (!installedAgents.includes(agent)) continue;
|
|
3577
5552
|
for (const root of historyRoots(agent)) {
|
|
3578
5553
|
try {
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
recursive:
|
|
3583
|
-
process.platform === "darwin" || process.platform === "win32",
|
|
3584
|
-
},
|
|
3585
|
-
() => {
|
|
3586
|
-
clearTimeout(watcher._harnessTimer);
|
|
3587
|
-
if (!quiet())
|
|
3588
|
-
watcher._harnessTimer = setTimeout(() => void sync(agent), 1_000);
|
|
3589
|
-
}
|
|
3590
|
-
);
|
|
3591
|
-
watchers.push(watcher);
|
|
5554
|
+
sources.subscribe({ kind: "files", folder: root, quiet: true }, () => {
|
|
5555
|
+
if (!quiet()) void sync(agent);
|
|
5556
|
+
});
|
|
3592
5557
|
} catch {}
|
|
3593
5558
|
}
|
|
3594
5559
|
}
|
|
5560
|
+
// The folders agents work in: each open thread's copy, or the folder it names until it has one, followed while the
|
|
5561
|
+
// thread is open, so what changes there is in the log with who changed it and what changed while Harness was off
|
|
5562
|
+
// (docs/senses-plan.md S2.1). Threads come and go, so the list is looked at again each minute.
|
|
5563
|
+
const followedFolders = new Map();
|
|
5564
|
+
let foldersStopped = false;
|
|
5565
|
+
const followThreadFolders = () => {
|
|
5566
|
+
if (foldersStopped) return;
|
|
5567
|
+
const wanted = new Set();
|
|
5568
|
+
for (const thread of store.goals()) {
|
|
5569
|
+
const folder = threadFolder(thread);
|
|
5570
|
+
if (folder) wanted.add(realFolder(folder));
|
|
5571
|
+
}
|
|
5572
|
+
for (const [folder, unfollow] of followedFolders)
|
|
5573
|
+
if (!wanted.has(folder)) {
|
|
5574
|
+
unfollow();
|
|
5575
|
+
followedFolders.delete(folder);
|
|
5576
|
+
}
|
|
5577
|
+
for (const folder of wanted)
|
|
5578
|
+
if (!followedFolders.has(folder))
|
|
5579
|
+
try {
|
|
5580
|
+
const unfollowFiles = sources.subscribe(
|
|
5581
|
+
{ kind: "files", folder },
|
|
5582
|
+
() => {}
|
|
5583
|
+
);
|
|
5584
|
+
// Its repository's branch and commits too, when it is in one (presence.mjs).
|
|
5585
|
+
let unfollowRepository = () => {};
|
|
5586
|
+
try {
|
|
5587
|
+
unfollowRepository = sources.subscribe(
|
|
5588
|
+
{ kind: "repository", folder },
|
|
5589
|
+
() => {}
|
|
5590
|
+
);
|
|
5591
|
+
} catch {}
|
|
5592
|
+
followedFolders.set(folder, () => {
|
|
5593
|
+
unfollowFiles();
|
|
5594
|
+
unfollowRepository();
|
|
5595
|
+
});
|
|
5596
|
+
} catch (error) {
|
|
5597
|
+
log(`files: cannot follow ${folder}: ${error.message}`);
|
|
5598
|
+
}
|
|
5599
|
+
};
|
|
5600
|
+
machineSense.start();
|
|
5601
|
+
timeSense.start();
|
|
5602
|
+
cleanup.start();
|
|
5603
|
+
threadWatches.start();
|
|
5604
|
+
// The person's watches move in from before they were rows and are followed; what was written and never carried out
|
|
5605
|
+
// (the daemon stopped in between) is carried out now.
|
|
5606
|
+
void watches.resume();
|
|
5607
|
+
responses.start();
|
|
5608
|
+
limits.look();
|
|
5609
|
+
// A new day starts each agent's runs from none: the limits are looked at again at each local midnight.
|
|
5610
|
+
const nextMidnight = () => {
|
|
5611
|
+
const day = new Date();
|
|
5612
|
+
day.setHours(24, 0, 0, 0);
|
|
5613
|
+
return day.getTime();
|
|
5614
|
+
};
|
|
5615
|
+
const atMidnight = () => {
|
|
5616
|
+
const unfollow = sources.subscribe(
|
|
5617
|
+
{ kind: "clock", at: nextMidnight() },
|
|
5618
|
+
() => {
|
|
5619
|
+
unfollow();
|
|
5620
|
+
limits.look();
|
|
5621
|
+
atMidnight();
|
|
5622
|
+
}
|
|
5623
|
+
);
|
|
5624
|
+
};
|
|
5625
|
+
atMidnight();
|
|
5626
|
+
followThreadFolders();
|
|
5627
|
+
const threadFolders = setInterval(followThreadFolders, 60_000);
|
|
5628
|
+
threadFolders.unref();
|
|
5629
|
+
// A new thread's folder is followed a second after the board changes, all changes of that second taken together.
|
|
5630
|
+
let lookAgain = null;
|
|
5631
|
+
threadsMayHaveChanged = () => {
|
|
5632
|
+
if (lookAgain || foldersStopped) return;
|
|
5633
|
+
lookAgain = setTimeout(() => {
|
|
5634
|
+
lookAgain = null;
|
|
5635
|
+
followThreadFolders();
|
|
5636
|
+
limits.look();
|
|
5637
|
+
threadWatches.threadsChanged();
|
|
5638
|
+
threadWatches.reconcile();
|
|
5639
|
+
}, 1_000);
|
|
5640
|
+
lookAgain.unref?.();
|
|
5641
|
+
};
|
|
3595
5642
|
setImmediate(() => void sync());
|
|
3596
5643
|
setImmediate(() => void listModels());
|
|
3597
5644
|
const relist = setInterval(() => void listModels(), 24 * 60 * 60_000);
|
|
3598
5645
|
specialtySnapshot.start();
|
|
3599
5646
|
|
|
3600
|
-
|
|
3601
|
-
|
|
5647
|
+
let stopping = false;
|
|
5648
|
+
const shutdown = async () => {
|
|
5649
|
+
if (stopping) return;
|
|
5650
|
+
stopping = true;
|
|
5651
|
+
// Nothing new starts while the runs going are stopped and reported.
|
|
5652
|
+
worker.hold(true, {
|
|
5653
|
+
by: "stopping",
|
|
5654
|
+
why: "Harness is stopping",
|
|
5655
|
+
until: "Harness is running again",
|
|
5656
|
+
});
|
|
5657
|
+
await stopAllRuns();
|
|
5658
|
+
// Home hears of every run of its that was going here before this computer goes, while its connection is still up;
|
|
5659
|
+
// as long as one call home takes, which ends in an answer or a report kept for home (ownMachines.mjs callHome).
|
|
5660
|
+
// One the system's own stop deadline cuts off is reported at the next start (machineRuns.mjs reportLeft).
|
|
5661
|
+
await machineRuns.interruptAll().catch(() => {});
|
|
3602
5662
|
agentSignIn?.close();
|
|
3603
5663
|
proxyLinks?.close();
|
|
3604
5664
|
linkRelay?.close();
|
|
3605
5665
|
clearInterval(stuckTimer);
|
|
3606
5666
|
agentWatch.stop();
|
|
5667
|
+
agentWiring.stop();
|
|
5668
|
+
link.close();
|
|
3607
5669
|
localWaker.stop();
|
|
3608
5670
|
clearInterval(dreamTimer);
|
|
5671
|
+
stopPlaceCheckIns();
|
|
3609
5672
|
clearInterval(rescan);
|
|
3610
5673
|
clearInterval(relist);
|
|
3611
5674
|
specialtySnapshot.stop();
|
|
3612
|
-
|
|
5675
|
+
foldersStopped = true;
|
|
5676
|
+
clearInterval(threadFolders);
|
|
5677
|
+
clearTimeout(lookAgain);
|
|
3613
5678
|
try {
|
|
3614
5679
|
bridge.stop();
|
|
3615
5680
|
} catch {}
|
|
@@ -3619,17 +5684,40 @@ export async function startDaemon() {
|
|
|
3619
5684
|
local.stop();
|
|
3620
5685
|
watches.stop();
|
|
3621
5686
|
schedules.stop();
|
|
5687
|
+
completion.stop();
|
|
5688
|
+
threadWatches.stop();
|
|
5689
|
+
responses.stop();
|
|
5690
|
+
cleanup.stop();
|
|
5691
|
+
tripwires.stop();
|
|
5692
|
+
pain.stop();
|
|
5693
|
+
reflexes.stop();
|
|
5694
|
+
nerves?.stop();
|
|
5695
|
+
originals?.stop();
|
|
5696
|
+
recall.stop();
|
|
5697
|
+
senseTools.stop();
|
|
5698
|
+
modelRoute.stop();
|
|
5699
|
+
machineSense.stop();
|
|
5700
|
+
timeSense?.stop();
|
|
5701
|
+
sources.stop();
|
|
5702
|
+
native?.close();
|
|
3622
5703
|
usageTotals.stop();
|
|
3623
5704
|
specialtyNotice.stop();
|
|
5705
|
+
releaseNotice.stop();
|
|
3624
5706
|
void directLink.stop();
|
|
3625
|
-
|
|
5707
|
+
peopleLink?.stop();
|
|
5708
|
+
presenceSense.stop();
|
|
3626
5709
|
clearInterval(askRetry);
|
|
3627
5710
|
control.close();
|
|
3628
5711
|
connectors.close();
|
|
3629
5712
|
// A vault write still in flight finishes or never lands: it is written beside the file and renamed over it.
|
|
3630
5713
|
void vault.close();
|
|
3631
5714
|
store.close();
|
|
3632
|
-
|
|
5715
|
+
// Only the socket this daemon made: never one another daemon listens on now.
|
|
5716
|
+
if (
|
|
5717
|
+
process.platform !== "win32" &&
|
|
5718
|
+
socketMade &&
|
|
5719
|
+
socketIdentity(paths.socket) === socketMade
|
|
5720
|
+
)
|
|
3633
5721
|
try {
|
|
3634
5722
|
fs.unlinkSync(paths.socket);
|
|
3635
5723
|
} catch {}
|