tryharness 0.7.53 → 0.7.54
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 +10 -5
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +115 -36
- package/lib/adapters.mjs +157 -222
- package/lib/agentRuntimes.mjs +26 -16
- package/lib/agentSignIn.mjs +226 -0
- package/lib/audit.mjs +643 -0
- package/lib/backupSetup.mjs +141 -0
- package/lib/boardAccess.mjs +8 -1
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardMirror.mjs +71 -7
- package/lib/boardProtocol.json +59 -2
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +1 -1
- package/lib/cards.mjs +138 -28
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +7 -2
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +149 -43
- package/lib/daemon.mjs +349 -28
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +106 -6
- package/lib/environments.mjs +237 -7
- package/lib/folders.mjs +2 -2
- package/lib/gitHost.mjs +174 -0
- package/lib/hookDialects.mjs +298 -0
- package/lib/landed.mjs +887 -0
- package/lib/live.mjs +284 -13
- package/lib/mcp-stdio.mjs +68 -2
- package/lib/members.json +16 -2
- package/lib/models.mjs +8 -8
- package/lib/museSession.mjs +16 -13
- package/lib/nativeHost.mjs +1 -1
- package/lib/neovim.mjs +126 -0
- package/lib/nudge.mjs +47 -16
- package/lib/ownMachines.mjs +343 -39
- package/lib/pairing.mjs +27 -10
- package/lib/paths.mjs +4 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +66 -11
- package/lib/places.mjs +330 -10
- package/lib/readiness.mjs +135 -18
- package/lib/record.mjs +115 -0
- package/lib/runWorker.mjs +17 -2
- package/lib/runner.mjs +8 -4
- package/lib/sessionControl.mjs +377 -89
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +58 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/store.mjs +284 -1
- package/lib/swarm.mjs +137 -21
- package/lib/t3.mjs +13 -4
- package/lib/taskCommands.mjs +36 -9
- package/lib/taskRuns.mjs +9 -2
- package/lib/team.json +255 -148
- package/lib/team.mjs +529 -188
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +75 -11
- package/lib/threadView.mjs +15 -2
- package/lib/worktrees.mjs +51 -13
- package/package.json +4 -4
- package/lib/modelTiers.json +0 -1183
- package/lib/modelTiers.mjs +0 -133
package/lib/ownMachines.mjs
CHANGED
|
@@ -26,16 +26,25 @@ import {
|
|
|
26
26
|
} from "./machineSeal.mjs";
|
|
27
27
|
import { findMachine, goesHome, queueable } from "./machineRoutes.mjs";
|
|
28
28
|
import { MERGE_COMMAND, MIRROR_COMMAND } from "./boardMirror.mjs";
|
|
29
|
+
import { member } from "./members.mjs";
|
|
29
30
|
|
|
30
31
|
// A worker's key for a direct link, swapped for home's over the sealed channel (directLink.mjs).
|
|
31
32
|
const DIRECT_COMMAND = "machine.direct";
|
|
33
|
+
// The person's model and effort for an agent live on the computer that runs it (models.mjs reads its own store), so
|
|
34
|
+
// the buddy's Swarm tab reads and sets them on each computer: a worker asks home, home asks the worker that has it.
|
|
35
|
+
const MODELS_COMMAND = "machine.models";
|
|
36
|
+
const MODEL_COMMAND = "machine.model";
|
|
37
|
+
// An agent that runs itself (Hermes, OpenClaw) is shown on a computer it called the board from this recently.
|
|
38
|
+
const SELF_RUN_SEEN_MS = 7 * 24 * 60 * 60_000;
|
|
32
39
|
|
|
33
40
|
// The person's other computers (one swarm across them). One computer holds the board ("home"); every other one is a
|
|
34
41
|
// worker: its agents' board calls go to home through Harness, sealed with the key the two computers share
|
|
35
42
|
// (machineSeal.mjs), and home answers them on its board as that agent on that computer. Harness says which computers
|
|
36
43
|
// there are and carries what they send; a computer trusts another only once the person confirmed it on home with the
|
|
37
44
|
// worker's join code. A worker keeps what its agents write while home is out of reach and sends it when home is back.
|
|
38
|
-
//
|
|
45
|
+
// A worker not confirmed yet (new, or its home was set up again with a new key) works on a board of its own until the
|
|
46
|
+
// person types its code on home, then brings that board to home (boardMirror.mjs bring): it is never a computer that
|
|
47
|
+
// cannot work (owner, October 22: "if this is how a worker behaves its fundamentally broken").
|
|
39
48
|
|
|
40
49
|
// Set on a board request by this module alone: the computer the call came from. JSON cannot carry it, so no caller
|
|
41
50
|
// names a computer it is not on.
|
|
@@ -82,12 +91,20 @@ export function createOwnMachines({
|
|
|
82
91
|
onStoodIn = () => {},
|
|
83
92
|
// Another computer stands in for this one: it takes home back (boardMirror.mjs takeBack).
|
|
84
93
|
returning = () => {},
|
|
94
|
+
// This computer works on a board of its own (a worker not confirmed yet), or stopped being home: what it holds goes
|
|
95
|
+
// to home once it is confirmed (boardMirror.mjs bring).
|
|
96
|
+
onOwnBoard = () => {},
|
|
85
97
|
// This computer's own Harness windows, asked a question for their screen history (phones.mjs ask).
|
|
86
98
|
askOwnWindows = async () => ({
|
|
87
99
|
ok: false,
|
|
88
100
|
code: "unpaired",
|
|
89
101
|
error: "no Harness window is linked to this computer",
|
|
90
102
|
}),
|
|
103
|
+
// This computer's own agents' models, read or one set, as the person (swarm.mjs board.swarm.models/model).
|
|
104
|
+
ownModels = async () => ({
|
|
105
|
+
ok: false,
|
|
106
|
+
error: "this computer cannot list its agents' models",
|
|
107
|
+
}),
|
|
91
108
|
}) {
|
|
92
109
|
// On home: each worker's folders and the repository each holds, as it said them.
|
|
93
110
|
const infos = new Map();
|
|
@@ -107,6 +124,16 @@ export function createOwnMachines({
|
|
|
107
124
|
const home = homeListed();
|
|
108
125
|
return home ? store.ownMachine(home.id) : null;
|
|
109
126
|
};
|
|
127
|
+
// Whether this computer was confirmed with another of the person's computers (it joined a home, or confirmed a
|
|
128
|
+
// worker): such a computer never takes home from one that is away (src/server/bridge/machines.ts takesHome).
|
|
129
|
+
const confirmedWithAnother = () =>
|
|
130
|
+
Boolean(store.meta("joined-home")) || store.ownMachines().length > 0;
|
|
131
|
+
// Whether this worker holds home's key. Just started, before Harness lists the computers, a worker that was ever
|
|
132
|
+
// confirmed counts as confirmed, so it never writes on its copy of home's board.
|
|
133
|
+
const trusted = () =>
|
|
134
|
+
homeListed() ? Boolean(pinnedHome()) : confirmedWithAnother();
|
|
135
|
+
/** A worker not confirmed into the swarm yet: its agents work on this computer's own board meanwhile. */
|
|
136
|
+
const actsAlone = () => !isHome() && !trusted();
|
|
110
137
|
const labelOf = (id) =>
|
|
111
138
|
id === machine.id
|
|
112
139
|
? machine.label
|
|
@@ -133,6 +160,7 @@ export function createOwnMachines({
|
|
|
133
160
|
machineId: machine.id,
|
|
134
161
|
label: machine.label,
|
|
135
162
|
...(machine.role ? { role: machine.role } : {}),
|
|
163
|
+
joined: confirmedWithAnother(),
|
|
136
164
|
});
|
|
137
165
|
|
|
138
166
|
/** Harness's answer to this computer's hello: its role on the account. */
|
|
@@ -142,8 +170,10 @@ export function createOwnMachines({
|
|
|
142
170
|
log(
|
|
143
171
|
`this computer is now ${given.role === "home" ? "home: it holds the board" : "a worker: its agents reach the board on your home computer"}`
|
|
144
172
|
);
|
|
173
|
+
const leftHome = machine.role === "home" && given.role === "worker";
|
|
145
174
|
machine.role = given.role;
|
|
146
175
|
saveMachine(machine);
|
|
176
|
+
if (leftHome) onOwnBoard();
|
|
147
177
|
changed();
|
|
148
178
|
};
|
|
149
179
|
|
|
@@ -173,6 +203,7 @@ export function createOwnMachines({
|
|
|
173
203
|
changed();
|
|
174
204
|
retryAdding();
|
|
175
205
|
watchHome();
|
|
206
|
+
if (actsAlone()) void workAlone();
|
|
176
207
|
// Someone stood in for this computer: it takes home back, at once if the stand-in is away too (boardMirror.mjs).
|
|
177
208
|
if (someoneStandsIn()) returning();
|
|
178
209
|
if (!homeListed()?.connected) toldHome = false;
|
|
@@ -269,6 +300,24 @@ export function createOwnMachines({
|
|
|
269
300
|
`did ${kept.length} kept write(s) on the board this computer now holds`
|
|
270
301
|
);
|
|
271
302
|
};
|
|
303
|
+
// A worker whose home is one it does not trust (its home was set up again, or it is new): what it kept for the home
|
|
304
|
+
// it trusted is done on its own board, which it brings to home once confirmed.
|
|
305
|
+
let alone = false;
|
|
306
|
+
const workAlone = async () => {
|
|
307
|
+
if (alone) return;
|
|
308
|
+
alone = true;
|
|
309
|
+
try {
|
|
310
|
+
onOwnBoard();
|
|
311
|
+
const formerHome = store.meta("joined-home");
|
|
312
|
+
if (formerHome && formerHome !== homeListed()?.id)
|
|
313
|
+
await applyKept(formerHome);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
log(`the writes kept for home could not be done here: ${error.message}`);
|
|
316
|
+
} finally {
|
|
317
|
+
alone = false;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
272
321
|
/** Home taking its place back from the computer that stood in, once it has that computer's changes. */
|
|
273
322
|
const reclaim = async () => {
|
|
274
323
|
// Only the computer that stood in may merge its writes here afterwards (answerCall).
|
|
@@ -285,6 +334,51 @@ export function createOwnMachines({
|
|
|
285
334
|
return true;
|
|
286
335
|
};
|
|
287
336
|
|
|
337
|
+
/** Uninstalled: Harness takes this computer off the account, and the pairing it connects with stops working. */
|
|
338
|
+
const leave = async () => {
|
|
339
|
+
const answer = await ask("machine_leave", {}).catch((error) => ({
|
|
340
|
+
ok: false,
|
|
341
|
+
error: error.message,
|
|
342
|
+
}));
|
|
343
|
+
return answer?.left === true
|
|
344
|
+
? { ok: true }
|
|
345
|
+
: { ok: false, error: answer?.error || "Harness did not answer" };
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
/** The person takes another of their computers off the account from the Swarm map. Never home. */
|
|
349
|
+
const remove = async (id) => {
|
|
350
|
+
const target = String(id || "");
|
|
351
|
+
const listed = siblings.find((sibling) => sibling.id === target);
|
|
352
|
+
if (listed?.role === "home")
|
|
353
|
+
return {
|
|
354
|
+
ok: false,
|
|
355
|
+
error: "Home keeps the board: make another computer home first.",
|
|
356
|
+
};
|
|
357
|
+
const answer = await ask("machine_remove", { machineId: target }).catch(
|
|
358
|
+
(error) => ({ ok: false, error: error.message })
|
|
359
|
+
);
|
|
360
|
+
if (answer?.removed !== true)
|
|
361
|
+
return { ok: false, error: answer?.error || "Harness did not answer" };
|
|
362
|
+
removed({ machineId: target });
|
|
363
|
+
return { ok: true };
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
/** Harness says a computer was taken off the account: its key is forgotten here, so it must be added again. */
|
|
367
|
+
const removed = (message) => {
|
|
368
|
+
const id = String(message?.machineId || "");
|
|
369
|
+
if (id === machine.id) {
|
|
370
|
+
log(
|
|
371
|
+
"this computer was removed from your swarm on another of your computers: run npx tryharness setup to add it again"
|
|
372
|
+
);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (!store.ownMachine(id)) return;
|
|
376
|
+
store.unpinOwnMachine(id);
|
|
377
|
+
siblings = siblings.filter((sibling) => sibling.id !== id);
|
|
378
|
+
log(`${labelOf(id) ?? id} was removed from your swarm`);
|
|
379
|
+
changed();
|
|
380
|
+
};
|
|
381
|
+
|
|
288
382
|
/** The person makes this computer home. The board stays on the computer that had it. */
|
|
289
383
|
const makeHome = async () => {
|
|
290
384
|
const answer = await ask("machine_role", { role: "home" });
|
|
@@ -387,6 +481,8 @@ export function createOwnMachines({
|
|
|
387
481
|
}
|
|
388
482
|
store.pinOwnMachine(worker.id, worker.publicKey, worker.label);
|
|
389
483
|
log(`confirmed ${worker.label || worker.id} as one of your computers`);
|
|
484
|
+
// Its first calls may have come before the pin and been refused: it starts over now, sealed, as one of ours.
|
|
485
|
+
void noticeTo(worker.id, { welcome: true });
|
|
390
486
|
changed();
|
|
391
487
|
return {
|
|
392
488
|
ok: true,
|
|
@@ -523,6 +619,7 @@ export function createOwnMachines({
|
|
|
523
619
|
};
|
|
524
620
|
}
|
|
525
621
|
store.pinOwnMachine(home.id, body.homeKey, home.label);
|
|
622
|
+
store.meta("joined-home", home.id);
|
|
526
623
|
store.meta("machine-join", "null");
|
|
527
624
|
log(
|
|
528
625
|
`joined your swarm: ${home.label || "your home computer"} holds the board`
|
|
@@ -778,8 +875,9 @@ export function createOwnMachines({
|
|
|
778
875
|
};
|
|
779
876
|
};
|
|
780
877
|
|
|
781
|
-
/** Whether a board request made on this computer goes to home. */
|
|
782
|
-
const forwards = (request) =>
|
|
878
|
+
/** Whether a board request made on this computer goes to home: not while it works on its own board. */
|
|
879
|
+
const forwards = (request) =>
|
|
880
|
+
!isHome() && trusted() && goesHome(request.command);
|
|
783
881
|
|
|
784
882
|
// ---- on home: a worker's call, opened, answered on the board and sealed back ----
|
|
785
883
|
|
|
@@ -839,26 +937,32 @@ export function createOwnMachines({
|
|
|
839
937
|
const result =
|
|
840
938
|
command === DIRECT_COMMAND
|
|
841
939
|
? await swapDirectKeys(from, call.key)
|
|
842
|
-
: command ===
|
|
843
|
-
?
|
|
844
|
-
: command ===
|
|
845
|
-
?
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
940
|
+
: command === MODELS_COMMAND || command === MODEL_COMMAND
|
|
941
|
+
? await answerModelsCall(call, from)
|
|
942
|
+
: command === MIRROR_COMMAND && answerMirror
|
|
943
|
+
? answerMirror(call)
|
|
944
|
+
: command === MERGE_COMMAND && answerMerge
|
|
945
|
+
? // A confirmed worker brings the board it kept on its own (union only); a stand-in hands back its writes.
|
|
946
|
+
call.bring === true || store.meta("stood-in-by") === from
|
|
947
|
+
? answerMerge(call)
|
|
948
|
+
: {
|
|
949
|
+
ok: false,
|
|
950
|
+
error: "this computer did not stand in for home",
|
|
951
|
+
}
|
|
952
|
+
: !goesHome(command)
|
|
953
|
+
? {
|
|
954
|
+
ok: false,
|
|
955
|
+
error: `${command || "that"} runs on the agent's own computer`,
|
|
956
|
+
}
|
|
957
|
+
: await settle(() =>
|
|
958
|
+
boardCommand({
|
|
959
|
+
...stripLocal(call),
|
|
960
|
+
// A path names a file on the worker; its bytes come as data.
|
|
961
|
+
path: undefined,
|
|
962
|
+
command,
|
|
963
|
+
[FROM_MACHINE]: from,
|
|
964
|
+
})
|
|
965
|
+
);
|
|
862
966
|
return {
|
|
863
967
|
envelope: await sealAnswer(key, from, body.envelope.requestId, result),
|
|
864
968
|
};
|
|
@@ -909,6 +1013,8 @@ export function createOwnMachines({
|
|
|
909
1013
|
),
|
|
910
1014
|
});
|
|
911
1015
|
if (!notice) return { ok: false };
|
|
1016
|
+
// Home confirmed this computer: what it keeps for home, and the board it brings, go now.
|
|
1017
|
+
if (notice.welcome === true) void flush();
|
|
912
1018
|
onNotice(notice);
|
|
913
1019
|
return { ok: true };
|
|
914
1020
|
};
|
|
@@ -949,21 +1055,7 @@ export function createOwnMachines({
|
|
|
949
1055
|
for (const worker of siblings.filter(
|
|
950
1056
|
(sibling) => sibling.role === "worker" && sibling.connected
|
|
951
1057
|
)) {
|
|
952
|
-
const
|
|
953
|
-
if (!pinned) continue;
|
|
954
|
-
const key = await keyFor(pinned.public_key, worker.id);
|
|
955
|
-
const requestId = newRequestId();
|
|
956
|
-
const envelope = await sealAsk(key, worker.id, requestId, call);
|
|
957
|
-
const reply = await relayTo({
|
|
958
|
-
to: worker.id,
|
|
959
|
-
kind: "ask",
|
|
960
|
-
body: { envelope },
|
|
961
|
-
}).catch(() => null);
|
|
962
|
-
if (!reply?.envelope) continue;
|
|
963
|
-
const answer = await openAskAnswer(key, reply.envelope, {
|
|
964
|
-
workerId: worker.id,
|
|
965
|
-
requestId,
|
|
966
|
-
}).catch(() => null);
|
|
1058
|
+
const answer = await askWorker(worker.id, call);
|
|
967
1059
|
if (!answer) continue;
|
|
968
1060
|
if (!nobodyThere(answer)) return answer;
|
|
969
1061
|
found ??= answer;
|
|
@@ -971,6 +1063,24 @@ export function createOwnMachines({
|
|
|
971
1063
|
return found;
|
|
972
1064
|
};
|
|
973
1065
|
|
|
1066
|
+
/** On home: one sealed question for a confirmed worker and its opened answer; null when none came back. */
|
|
1067
|
+
const askWorker = async (workerId, call) => {
|
|
1068
|
+
const pinned = store.ownMachine(workerId);
|
|
1069
|
+
if (!pinned) return null;
|
|
1070
|
+
const key = await keyFor(pinned.public_key, workerId);
|
|
1071
|
+
const requestId = newRequestId();
|
|
1072
|
+
const envelope = await sealAsk(key, workerId, requestId, call);
|
|
1073
|
+
const reply = await relayTo({
|
|
1074
|
+
to: workerId,
|
|
1075
|
+
kind: "ask",
|
|
1076
|
+
body: { envelope },
|
|
1077
|
+
}).catch(() => null);
|
|
1078
|
+
if (!reply?.envelope) return null;
|
|
1079
|
+
return openAskAnswer(key, reply.envelope, { workerId, requestId }).catch(
|
|
1080
|
+
() => null
|
|
1081
|
+
);
|
|
1082
|
+
};
|
|
1083
|
+
|
|
974
1084
|
/** On a worker: home's question for the windows linked here, opened, asked and the answer sealed back. */
|
|
975
1085
|
const onAskFromHome = (body) =>
|
|
976
1086
|
once(`ask:${sealedKey(body?.envelope)}`, () => onAskFromHomeOnce(body));
|
|
@@ -987,7 +1097,10 @@ export function createOwnMachines({
|
|
|
987
1097
|
),
|
|
988
1098
|
});
|
|
989
1099
|
if (!call) return { ok: false, error: "the question could not be opened" };
|
|
990
|
-
|
|
1100
|
+
// Home asking for this computer's agents' models is answered here; anything else goes to the windows.
|
|
1101
|
+
const answer = call.models
|
|
1102
|
+
? await ownModels(call.models)
|
|
1103
|
+
: await askOwnWindows(call);
|
|
991
1104
|
return {
|
|
992
1105
|
envelope: await sealAskAnswer(
|
|
993
1106
|
key,
|
|
@@ -1035,6 +1148,7 @@ export function createOwnMachines({
|
|
|
1035
1148
|
id: machine.id,
|
|
1036
1149
|
label: machine.label,
|
|
1037
1150
|
role: machine.role ?? "home",
|
|
1151
|
+
alone: actsAlone(),
|
|
1038
1152
|
standingInFor: standingIn()
|
|
1039
1153
|
? (labelOf(standingIn()) ?? standingIn())
|
|
1040
1154
|
: null,
|
|
@@ -1064,6 +1178,174 @@ export function createOwnMachines({
|
|
|
1064
1178
|
};
|
|
1065
1179
|
};
|
|
1066
1180
|
|
|
1181
|
+
// ---- every computer's agents and the models they run, for the buddy's Swarm tab ----
|
|
1182
|
+
|
|
1183
|
+
const modelsRead = (refresh) => ({
|
|
1184
|
+
command: "board.swarm.models",
|
|
1185
|
+
...(refresh === true ? { refresh: true } : {}),
|
|
1186
|
+
});
|
|
1187
|
+
|
|
1188
|
+
/** One computer as the Swarm tab shows it: its agents' models as it answered, else the agents Harness last listed. */
|
|
1189
|
+
const computerEntry = (computer, answer) => ({
|
|
1190
|
+
id: computer.id,
|
|
1191
|
+
label: computer.label,
|
|
1192
|
+
role: computer.role ?? "home",
|
|
1193
|
+
online: computer.online,
|
|
1194
|
+
models: answer?.ok ? (answer.agents ?? []) : [],
|
|
1195
|
+
agents: answer?.ok ? (answer.installed ?? []) : (computer.agents ?? []),
|
|
1196
|
+
...(answer?.ok === false ? { error: answer.error } : {}),
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
/** On home: the agents that run themselves, by the computer they last called the board from (home's records). */
|
|
1200
|
+
const selfRunByComputer = () => {
|
|
1201
|
+
const since = new Date(Date.now() - SELF_RUN_SEEN_MS).toISOString();
|
|
1202
|
+
const found = {};
|
|
1203
|
+
for (const { agent, machine: computer } of store.agentsSeenOnComputers(
|
|
1204
|
+
since
|
|
1205
|
+
)) {
|
|
1206
|
+
if (member(agent)?.runs !== "self") continue;
|
|
1207
|
+
(found[computer] ??= []).push(agent);
|
|
1208
|
+
}
|
|
1209
|
+
return found;
|
|
1210
|
+
};
|
|
1211
|
+
const withSelfRun = (computers, selfRun) =>
|
|
1212
|
+
computers.map((computer) => ({
|
|
1213
|
+
...computer,
|
|
1214
|
+
selfRun: selfRun[computer.id] ?? [],
|
|
1215
|
+
}));
|
|
1216
|
+
|
|
1217
|
+
/** On home: home and each confirmed worker but `except` (the worker asking), each read on its own computer. */
|
|
1218
|
+
const everyComputersModels = async (read, except = null) => {
|
|
1219
|
+
const workers = siblings.filter(
|
|
1220
|
+
(sibling) => sibling.id !== except && confirmed(sibling)
|
|
1221
|
+
);
|
|
1222
|
+
const [own, ...answers] = await Promise.all([
|
|
1223
|
+
ownModels(read),
|
|
1224
|
+
...workers.map((worker) =>
|
|
1225
|
+
worker.connected
|
|
1226
|
+
? askWorker(worker.id, { models: read }).then(
|
|
1227
|
+
(answer) =>
|
|
1228
|
+
answer ?? { ok: false, error: `${worker.label} did not answer` }
|
|
1229
|
+
)
|
|
1230
|
+
: null
|
|
1231
|
+
),
|
|
1232
|
+
]);
|
|
1233
|
+
return [
|
|
1234
|
+
computerEntry(
|
|
1235
|
+
{
|
|
1236
|
+
id: machine.id,
|
|
1237
|
+
label: machine.label,
|
|
1238
|
+
role: machine.role ?? "home",
|
|
1239
|
+
online: true,
|
|
1240
|
+
agents,
|
|
1241
|
+
},
|
|
1242
|
+
own
|
|
1243
|
+
),
|
|
1244
|
+
...workers.map((worker, index) =>
|
|
1245
|
+
computerEntry({ ...worker, online: worker.connected }, answers[index])
|
|
1246
|
+
),
|
|
1247
|
+
];
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1250
|
+
// Why the other computers' agents are missing: this one is not joined yet and works on its own, or home is away.
|
|
1251
|
+
const unreachableNote = (answer) =>
|
|
1252
|
+
actsAlone()
|
|
1253
|
+
? "This computer isn't joined to your home computer yet, so only its own agents show here."
|
|
1254
|
+
: (answer ?? offline()).error;
|
|
1255
|
+
|
|
1256
|
+
/** The person's computers, this one first, each with its agents and the model and effort each runs on. */
|
|
1257
|
+
const models = async ({ refresh = false } = {}) => {
|
|
1258
|
+
const read = modelsRead(refresh);
|
|
1259
|
+
if (isHome())
|
|
1260
|
+
return {
|
|
1261
|
+
ok: true,
|
|
1262
|
+
here: machine.id,
|
|
1263
|
+
computers: withSelfRun(
|
|
1264
|
+
await everyComputersModels(read),
|
|
1265
|
+
selfRunByComputer()
|
|
1266
|
+
),
|
|
1267
|
+
};
|
|
1268
|
+
const own = computerEntry(
|
|
1269
|
+
{
|
|
1270
|
+
id: machine.id,
|
|
1271
|
+
label: machine.label,
|
|
1272
|
+
role: "worker",
|
|
1273
|
+
online: true,
|
|
1274
|
+
agents,
|
|
1275
|
+
},
|
|
1276
|
+
await ownModels(read)
|
|
1277
|
+
);
|
|
1278
|
+
const pinned = pinnedHome();
|
|
1279
|
+
const fromHome = pinned
|
|
1280
|
+
? await callOnce(pinned, {
|
|
1281
|
+
command: MODELS_COMMAND,
|
|
1282
|
+
agent: "user",
|
|
1283
|
+
refresh: refresh === true,
|
|
1284
|
+
})
|
|
1285
|
+
: null;
|
|
1286
|
+
const others = fromHome?.ok
|
|
1287
|
+
? fromHome.computers.filter((computer) => computer.id !== machine.id)
|
|
1288
|
+
: siblings.map((sibling) =>
|
|
1289
|
+
computerEntry({ ...sibling, online: false }, null)
|
|
1290
|
+
);
|
|
1291
|
+
return {
|
|
1292
|
+
ok: true,
|
|
1293
|
+
here: machine.id,
|
|
1294
|
+
computers: withSelfRun([own, ...others], fromHome?.selfRun ?? {}),
|
|
1295
|
+
...(fromHome?.ok ? {} : { note: unreachableNote(fromHome) }),
|
|
1296
|
+
};
|
|
1297
|
+
};
|
|
1298
|
+
|
|
1299
|
+
/** On home: a worker asking for every computer's models, or setting one; only as the person. */
|
|
1300
|
+
const answerModelsCall = async (call, from) => {
|
|
1301
|
+
if (call.agent !== "user")
|
|
1302
|
+
return { ok: false, error: "only the person reads or sets models here" };
|
|
1303
|
+
if (call.command === MODEL_COMMAND) return setModel(call);
|
|
1304
|
+
return {
|
|
1305
|
+
ok: true,
|
|
1306
|
+
computers: await everyComputersModels(modelsRead(call.refresh), from),
|
|
1307
|
+
selfRun: selfRunByComputer(),
|
|
1308
|
+
};
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
/** The person's model and effort for one agent on one computer, set on that computer. */
|
|
1312
|
+
const setModel = async (request) => {
|
|
1313
|
+
const pick = {
|
|
1314
|
+
command: "board.swarm.model",
|
|
1315
|
+
target: request.target,
|
|
1316
|
+
model: request.model,
|
|
1317
|
+
effort: request.effort ?? null,
|
|
1318
|
+
};
|
|
1319
|
+
const computer = String(request.computer || machine.id);
|
|
1320
|
+
if (computer === machine.id) return ownModels(pick);
|
|
1321
|
+
if (isHome()) {
|
|
1322
|
+
const worker = siblings.find((sibling) => sibling.id === computer);
|
|
1323
|
+
if (!worker || !confirmed(worker))
|
|
1324
|
+
return {
|
|
1325
|
+
ok: false,
|
|
1326
|
+
error: "that computer is not one of yours confirmed on home",
|
|
1327
|
+
};
|
|
1328
|
+
return (
|
|
1329
|
+
(await askWorker(computer, { models: pick })) ?? {
|
|
1330
|
+
ok: false,
|
|
1331
|
+
error: `${worker.label} did not answer; it may be asleep or offline`,
|
|
1332
|
+
}
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
const pinned = pinnedHome();
|
|
1336
|
+
if (!pinned) return homeListed() ? notJoined() : offline();
|
|
1337
|
+
return (
|
|
1338
|
+
(await callOnce(pinned, {
|
|
1339
|
+
command: MODEL_COMMAND,
|
|
1340
|
+
agent: "user",
|
|
1341
|
+
computer,
|
|
1342
|
+
target: pick.target,
|
|
1343
|
+
model: pick.model,
|
|
1344
|
+
effort: pick.effort,
|
|
1345
|
+
})) ?? offline()
|
|
1346
|
+
);
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1067
1349
|
const status = () => ({
|
|
1068
1350
|
id: machine.id,
|
|
1069
1351
|
label: machine.label,
|
|
@@ -1082,7 +1364,23 @@ export function createOwnMachines({
|
|
|
1082
1364
|
}
|
|
1083
1365
|
: null,
|
|
1084
1366
|
waiting: outbox().length,
|
|
1367
|
+
// Working on its own board until the person types this code on home.
|
|
1368
|
+
...(actsAlone() && joinCode() ? { joinCode: joinCode() } : {}),
|
|
1085
1369
|
}),
|
|
1370
|
+
// On home: the computers connected and waiting for their code to be typed here.
|
|
1371
|
+
...(isHome()
|
|
1372
|
+
? {
|
|
1373
|
+
waitingToJoin: siblings
|
|
1374
|
+
.filter(
|
|
1375
|
+
(sibling) =>
|
|
1376
|
+
sibling.role === "worker" &&
|
|
1377
|
+
sibling.connected &&
|
|
1378
|
+
sibling.publicKey &&
|
|
1379
|
+
!confirmed(sibling)
|
|
1380
|
+
)
|
|
1381
|
+
.map((sibling) => sibling.label),
|
|
1382
|
+
}
|
|
1383
|
+
: {}),
|
|
1086
1384
|
});
|
|
1087
1385
|
|
|
1088
1386
|
/** The person's computers that have this agent, this one first: what its card says. Only confirmed ones. */
|
|
@@ -1190,6 +1488,9 @@ export function createOwnMachines({
|
|
|
1190
1488
|
introduce,
|
|
1191
1489
|
rename,
|
|
1192
1490
|
makeHome,
|
|
1491
|
+
leave,
|
|
1492
|
+
remove,
|
|
1493
|
+
removed,
|
|
1193
1494
|
confirm,
|
|
1194
1495
|
add,
|
|
1195
1496
|
forwards,
|
|
@@ -1203,6 +1504,7 @@ export function createOwnMachines({
|
|
|
1203
1504
|
someoneStandsIn,
|
|
1204
1505
|
// A worker confirmed into the swarm: it holds home's key.
|
|
1205
1506
|
joined: () => Boolean(pinnedHome()),
|
|
1507
|
+
actsAlone,
|
|
1206
1508
|
standInReachable: () => {
|
|
1207
1509
|
const home = homeListed();
|
|
1208
1510
|
return Boolean(
|
|
@@ -1216,6 +1518,8 @@ export function createOwnMachines({
|
|
|
1216
1518
|
reclaim,
|
|
1217
1519
|
directStatus: () => directLink?.status() ?? [],
|
|
1218
1520
|
list,
|
|
1521
|
+
models,
|
|
1522
|
+
setModel,
|
|
1219
1523
|
status,
|
|
1220
1524
|
all,
|
|
1221
1525
|
learn,
|
package/lib/pairing.mjs
CHANGED
|
@@ -14,8 +14,8 @@ import { newPairCode, pairClaim } from "./machineSeal.mjs";
|
|
|
14
14
|
// code's first 4 characters and proof of the whole. A Harness from before this takes neither and makes a code of its
|
|
15
15
|
// own (an 8-character one, for the account only).
|
|
16
16
|
//
|
|
17
|
-
// Once connected, a computer Harness added to an account that already has a home
|
|
18
|
-
//
|
|
17
|
+
// Once connected, a computer Harness added to an account that already has a home is told where to type its code, and
|
|
18
|
+
// works on its own meanwhile (joinSwarm).
|
|
19
19
|
|
|
20
20
|
/** Ask Harness to hold a pairing for this computer. Returns { pairId, code, own } (own: setup made the code). */
|
|
21
21
|
export async function startPairing(origin, agents) {
|
|
@@ -101,14 +101,22 @@ export function hasBattery() {
|
|
|
101
101
|
return true;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// How long setup waits, at its end, for the person to type this computer's code on home. It works on its own meanwhile,
|
|
105
|
+
// so the wait only lets setup say it joined; the person may close it.
|
|
104
106
|
const JOIN_WAIT_MS = 10 * 60_000;
|
|
105
107
|
// How long a computer approved from home's buddy usually takes to be confirmed there, before setup says where to type.
|
|
106
108
|
const JOIN_QUIET_MS = 8_000;
|
|
107
109
|
|
|
110
|
+
const names = (labels) =>
|
|
111
|
+
labels.length > 1
|
|
112
|
+
? `${labels.slice(0, -1).join(", ")} and ${labels.at(-1)}`
|
|
113
|
+
: labels[0];
|
|
114
|
+
|
|
108
115
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
116
|
+
* At the end of setup, once the daemon is connected: Harness has made this computer home or added it. An added one not
|
|
117
|
+
* confirmed yet works on its own board until the person types its code on home (ownMachines.mjs); setup says where and
|
|
118
|
+
* waits for it, then may offer home to a computer that suits that better. On home, the computers that still need their
|
|
119
|
+
* code typed here are named. Returns the role. `daemonRequest` reaches this computer's daemon.
|
|
112
120
|
*/
|
|
113
121
|
export async function joinSwarm({
|
|
114
122
|
ui,
|
|
@@ -121,7 +129,17 @@ export async function joinSwarm({
|
|
|
121
129
|
const read = () =>
|
|
122
130
|
daemonRequest({ command: "machines.list" }).catch(() => null);
|
|
123
131
|
let listed = await read();
|
|
124
|
-
if (!listed?.ok
|
|
132
|
+
if (!listed?.ok) return "home";
|
|
133
|
+
if (listed.self.role !== "worker") {
|
|
134
|
+
const waiting = listed.machines
|
|
135
|
+
.filter((machine) => machine.role === "worker" && !machine.confirmed)
|
|
136
|
+
.map((machine) => machine.label);
|
|
137
|
+
if (waiting.length)
|
|
138
|
+
ui.info(
|
|
139
|
+
`${names(waiting)} ${waiting.length > 1 ? "are" : "is"} on your account but not in your swarm here yet, and ${waiting.length > 1 ? "each works" : "works"} on its own meanwhile. To bring ${waiting.length > 1 ? "each" : "it"} in, run npx tryharness machines there and type the code it shows here: Add a Computer in the Harness menu.`
|
|
140
|
+
);
|
|
141
|
+
return "home";
|
|
142
|
+
}
|
|
125
143
|
const homeName = () =>
|
|
126
144
|
listed.machines.find((machine) => machine.role === "home")?.label ||
|
|
127
145
|
"your home computer";
|
|
@@ -134,7 +152,7 @@ export async function joinSwarm({
|
|
|
134
152
|
if (!told && Date.now() - started > quietMs) {
|
|
135
153
|
told = true;
|
|
136
154
|
spin.message(
|
|
137
|
-
`Waiting for ${homeName()}. There, click the Harness icon in the menu bar, choose Add a Computer, and type ${listed.joinCode}${listed.joinCode === code ? " (the same code)" : ""}. Or run there: npx tryharness machines add ${listed.joinCode}
|
|
155
|
+
`Waiting for ${homeName()}. There, click the Harness icon in the menu bar, choose Add a Computer, and type ${listed.joinCode}${listed.joinCode === code ? " (the same code)" : ""}. Or run there: npx tryharness machines add ${listed.joinCode}. This computer already works on its own, so you can close this.`
|
|
138
156
|
);
|
|
139
157
|
}
|
|
140
158
|
await new Promise((resolve) => setTimeout(resolve, 1_000));
|
|
@@ -142,8 +160,7 @@ export async function joinSwarm({
|
|
|
142
160
|
}
|
|
143
161
|
if (listed.joinCode) {
|
|
144
162
|
spin.stop(
|
|
145
|
-
`
|
|
146
|
-
2
|
|
163
|
+
`This computer works on its own until it joins your swarm. To bring it in, type ${listed.joinCode} on ${homeName()}: Add a Computer in the Harness menu there, or npx tryharness machines add ${listed.joinCode}. What it does meanwhile goes to ${homeName()} when it joins.`
|
|
147
164
|
);
|
|
148
165
|
return "worker";
|
|
149
166
|
}
|
|
@@ -151,7 +168,7 @@ export async function joinSwarm({
|
|
|
151
168
|
} else ui.success(`In your swarm. ${homeName()} holds the board.`);
|
|
152
169
|
if (!ui.interactive || battery()) return "worker";
|
|
153
170
|
const move = await ui.confirm({
|
|
154
|
-
message: `This computer stays on, so work could go on here while ${homeName()} sleeps. Make it your main computer? Your threads and board
|
|
171
|
+
message: `This computer stays on, so work could go on here while ${homeName()} sleeps. Make it your main computer? Your threads and board come with it.`,
|
|
155
172
|
initialValue: false,
|
|
156
173
|
});
|
|
157
174
|
if (!move) return "worker";
|
package/lib/paths.mjs
CHANGED
|
@@ -23,6 +23,10 @@ export const paths = {
|
|
|
23
23
|
machine: path.join(harnessHome, "machine.json"),
|
|
24
24
|
// The person's name and preferences from their Harness profile (profile.mjs).
|
|
25
25
|
profile: path.join(harnessHome, "profile.json"),
|
|
26
|
+
// The terminal app setup last ran in (places.mjs noteSetupTerminal).
|
|
27
|
+
terminal: path.join(harnessHome, "terminal.json"),
|
|
28
|
+
// A cloud computer's seeded link offer (cloudBoot.mjs); absent everywhere else.
|
|
29
|
+
cloud: path.join(harnessHome, "cloud.json"),
|
|
26
30
|
runs: path.join(harnessHome, "runs"),
|
|
27
31
|
files: path.join(harnessHome, "files"),
|
|
28
32
|
runtime: path.join(harnessHome, "runtime"),
|