tryharness 0.7.53 → 0.7.57
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 +23 -19
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +484 -90
- package/lib/activity.mjs +10 -10
- package/lib/adapters.mjs +173 -222
- package/lib/agentBinaries.mjs +71 -0
- package/lib/agentRuntimeConfig.mjs +1 -1
- package/lib/agentRuntimes.mjs +34 -18
- package/lib/agentSignIn.mjs +456 -0
- package/lib/answers.mjs +5 -5
- package/lib/archetypes.d.ts +64 -0
- package/lib/archetypes.js +989 -0
- package/lib/asks.mjs +4 -4
- package/lib/audit.mjs +666 -0
- package/lib/backupSetup.mjs +143 -0
- package/lib/boardAccess.mjs +24 -11
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardFileCommands.mjs +6 -6
- package/lib/boardFiles.mjs +13 -12
- package/lib/boardMirror.mjs +124 -25
- package/lib/boardProtocol.json +88 -2
- package/lib/boardWaits.mjs +101 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +6 -6
- package/lib/cards.mjs +138 -28
- package/lib/cloudAgents.mjs +216 -0
- package/lib/cloudAi.mjs +1312 -0
- package/lib/cloudAssistants.mjs +242 -0
- package/lib/cloudBoot.mjs +119 -0
- package/lib/cloudSave.mjs +197 -0
- package/lib/cloudSsh.mjs +178 -0
- package/lib/commands.mjs +7 -2
- package/lib/context.mjs +19 -5
- package/lib/contractGate.mjs +399 -0
- package/lib/control-client.mjs +9 -1
- package/lib/controlSocket.mjs +86 -0
- package/lib/coordinator.mjs +252 -144
- package/lib/daemon.mjs +1351 -2767
- package/lib/desk.mjs +240 -0
- package/lib/desktop.mjs +178 -74
- package/lib/directLink.mjs +16 -5
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +247 -9
- package/lib/firewall.mjs +9 -9
- package/lib/folders.mjs +20 -16
- package/lib/frames.mjs +2 -3
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +25 -7
- package/lib/goals.mjs +7 -7
- package/lib/guestRequests.mjs +94 -0
- package/lib/handoffs.mjs +8 -7
- package/lib/handover.mjs +4 -4
- package/lib/harnessModel.mjs +6 -6
- package/lib/harnessOffers.mjs +266 -0
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +26 -8
- package/lib/jobAnswers.mjs +190 -0
- package/lib/landed.mjs +887 -0
- package/lib/lane.mjs +42 -11
- package/lib/lessons.mjs +16 -16
- package/lib/library.mjs +3 -3
- package/lib/lineup.mjs +3 -0
- package/lib/linkRelay.mjs +574 -0
- package/lib/live.mjs +284 -13
- package/lib/localAgentAsk.mjs +74 -0
- package/lib/localStack.mjs +536 -0
- package/lib/localmodels.mjs +6 -4
- package/lib/loopBackstop.mjs +4 -4
- package/lib/machineIdentity.mjs +9 -1
- package/lib/machineRoutes.mjs +181 -2
- package/lib/machineRuns.mjs +76 -1
- package/lib/machineSeal.mjs +39 -12
- package/lib/mcp-stdio.mjs +163 -27
- package/lib/mcpRelay.mjs +1 -1
- package/lib/members.json +29 -2
- package/lib/members.mjs +1 -1
- package/lib/models.mjs +85 -31
- package/lib/museSession.mjs +21 -13
- package/lib/nativeHost.mjs +36 -8
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +50 -5
- package/lib/notify.mjs +7 -5
- package/lib/nudge.mjs +50 -19
- package/lib/ocr.mjs +9 -9
- package/lib/onboard.mjs +26 -20
- package/lib/oneLine.mjs +7 -7
- package/lib/ownMachines.mjs +1223 -140
- package/lib/pairing.mjs +60 -16
- package/lib/paths.mjs +19 -1
- package/lib/peerProcess.mjs +124 -0
- package/lib/personModel.mjs +89 -0
- package/lib/personNotices.mjs +151 -0
- package/lib/phones.mjs +538 -31
- package/lib/placeCommands.mjs +4 -4
- package/lib/places.mjs +400 -12
- package/lib/profile.mjs +67 -14
- package/lib/projectGit.mjs +158 -14
- package/lib/projectPieces.mjs +902 -0
- package/lib/projectSettings.mjs +7 -4
- package/lib/projects.mjs +384 -62
- package/lib/provenance.mjs +5 -1
- package/lib/proxyLinks.mjs +267 -0
- package/lib/reactions.mjs +7 -5
- package/lib/readiness.mjs +145 -23
- package/lib/record.mjs +128 -0
- package/lib/redact.mjs +4 -4
- package/lib/relayLimits.mjs +62 -0
- package/lib/release.mjs +170 -0
- package/lib/releaseKeys.json +6 -0
- package/lib/repoLinks.mjs +4 -4
- package/lib/roomChannels.mjs +24 -0
- package/lib/roomPage.mjs +1 -1
- package/lib/runAuthority.mjs +101 -0
- package/lib/runBrief.mjs +19 -8
- package/lib/runWorker.mjs +31 -7
- package/lib/runner.mjs +223 -29
- package/lib/runtime-install.mjs +143 -9
- package/lib/schedules.mjs +2 -2
- package/lib/screens.mjs +1 -1
- package/lib/sealed.mjs +11 -2
- package/lib/sealedThreads.mjs +671 -0
- package/lib/secretPatterns.json +1 -1
- package/lib/secrets.mjs +4 -4
- package/lib/seen.mjs +6 -6
- package/lib/serverWords.mjs +175 -0
- package/lib/service.mjs +22 -12
- package/lib/sessionControl.mjs +378 -90
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +57 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/speech.mjs +5 -5
- package/lib/store.mjs +420 -36
- package/lib/stuck.mjs +1 -1
- package/lib/swarm.mjs +304 -37
- package/lib/swarmDevices.mjs +319 -0
- package/lib/swarmMemory.mjs +27 -25
- package/lib/t3.mjs +24 -15
- package/lib/taskCommands.mjs +80 -20
- package/lib/taskRooms.mjs +125 -0
- package/lib/taskRuns.mjs +45 -3
- package/lib/team.json +255 -148
- package/lib/team.mjs +554 -190
- package/lib/threadActions.mjs +315 -0
- package/lib/threadAuthority.mjs +101 -0
- package/lib/threadBriefs.mjs +178 -0
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +209 -50
- package/lib/threadView.mjs +20 -7
- package/lib/usageTotals.mjs +2 -3
- package/lib/vault.mjs +101 -10
- package/lib/vaultCloud.mjs +2 -2
- package/lib/vaultCommands.mjs +15 -6
- package/lib/vaultTools.js +2 -2
- package/lib/verdicts.mjs +328 -0
- package/lib/wakes.mjs +1 -1
- package/lib/watches.mjs +2 -2
- package/lib/windowAsks.mjs +13 -5
- package/lib/worktrees.mjs +157 -25
- package/npm-shrinkwrap.json +1093 -0
- package/package.json +12 -11
- package/release.json +220 -0
- package/lib/modelTiers.json +0 -1183
- package/lib/modelTiers.mjs +0 -133
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// What the person sees of the board's backup (boardBackup.mjs does it): one step in setup, and npx tryharness backup.
|
|
2
|
+
// A Resident coming back to a computer with an empty board is offered their backup first; a Resident without one is
|
|
3
|
+
// offered to start it; anyone else is told plainly that their board stays on this computer.
|
|
4
|
+
|
|
5
|
+
import { relayCommand } from "./runtime-install.mjs";
|
|
6
|
+
|
|
7
|
+
const when = (iso) => {
|
|
8
|
+
const at = new Date(iso);
|
|
9
|
+
return Number.isNaN(at.getTime())
|
|
10
|
+
? "earlier"
|
|
11
|
+
: at.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
async function askPassphrase(ui, { twice }) {
|
|
15
|
+
const first = await ui.password({
|
|
16
|
+
message: twice
|
|
17
|
+
? "Choose a backup passphrase (at least 8 characters). Only you will have it: without it the backup cannot be opened, by anyone."
|
|
18
|
+
: "Your backup passphrase",
|
|
19
|
+
});
|
|
20
|
+
if (!first) return null;
|
|
21
|
+
if (!twice) return first;
|
|
22
|
+
const again = await ui.password({ message: "Type it again" });
|
|
23
|
+
if (again !== first) {
|
|
24
|
+
ui.warn("The two did not match, so backups stay off.");
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return first;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Setup's step, on home only: bring a Resident's board back, or offer to start backing it up. */
|
|
31
|
+
export async function offerBackup({ ui, daemonRequest, role, boardIsEmpty }) {
|
|
32
|
+
if (role !== "home") return;
|
|
33
|
+
const status = await daemonRequest({ command: "backup.status" }).catch(
|
|
34
|
+
() => null
|
|
35
|
+
);
|
|
36
|
+
if (!status?.ok || status.entitled === null) return;
|
|
37
|
+
if (status.entitled === false) {
|
|
38
|
+
ui.info(
|
|
39
|
+
"Your board stays on this computer. With Resident, Harness also keeps an encrypted backup of it, so a new computer can bring it back."
|
|
40
|
+
);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (status.on) return;
|
|
44
|
+
if (!ui.interactive) return;
|
|
45
|
+
if (status.latest && boardIsEmpty) {
|
|
46
|
+
ui.info(
|
|
47
|
+
`You have a backup of your board from ${status.latest.fromLabel || "another computer"}, ${when(status.latest.createdAt)}.`
|
|
48
|
+
);
|
|
49
|
+
for (let tries = 0; tries < 3; tries++) {
|
|
50
|
+
const passphrase = await askPassphrase(ui, { twice: false });
|
|
51
|
+
if (!passphrase) break;
|
|
52
|
+
const restored = await daemonRequest(
|
|
53
|
+
{ command: "backup.restore", passphrase },
|
|
54
|
+
120_000
|
|
55
|
+
);
|
|
56
|
+
if (restored.ok) {
|
|
57
|
+
ui.success(
|
|
58
|
+
`Your board is back (${restored.rows} items). It goes on backing up from this computer.`
|
|
59
|
+
);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
ui.warn(restored.error || "That backup could not be opened.");
|
|
63
|
+
if (restored.code !== "wrong_passphrase") break;
|
|
64
|
+
}
|
|
65
|
+
ui.info(`To try again later: ${relayCommand()} backup restore`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const yes = await ui.confirm({
|
|
69
|
+
message:
|
|
70
|
+
"Keep an encrypted backup of your board with Harness? A new computer can bring it back with your passphrase; Harness cannot read it.",
|
|
71
|
+
initialValue: true,
|
|
72
|
+
});
|
|
73
|
+
if (!yes) return;
|
|
74
|
+
const passphrase = await askPassphrase(ui, { twice: true });
|
|
75
|
+
if (!passphrase) return;
|
|
76
|
+
const on = await daemonRequest({ command: "backup.on", passphrase }, 120_000);
|
|
77
|
+
if (on.ok)
|
|
78
|
+
ui.success("Your board is backed up, sealed with your passphrase.");
|
|
79
|
+
else ui.warn(on.error || "The backup did not start.");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** npx tryharness backup [on | now | restore | off] */
|
|
83
|
+
export async function backupCommand({ argv, ui, daemonRequest }) {
|
|
84
|
+
const sub = argv[0];
|
|
85
|
+
const must = (reply) => {
|
|
86
|
+
if (!reply?.ok)
|
|
87
|
+
throw new Error(reply?.error || "the backup did not answer");
|
|
88
|
+
return reply;
|
|
89
|
+
};
|
|
90
|
+
if (sub === "on") {
|
|
91
|
+
const passphrase = await askPassphrase(ui, { twice: true });
|
|
92
|
+
if (!passphrase) return;
|
|
93
|
+
const on = must(
|
|
94
|
+
await daemonRequest({ command: "backup.on", passphrase }, 120_000)
|
|
95
|
+
);
|
|
96
|
+
console.log(
|
|
97
|
+
`Backed up your board, sealed with your passphrase (${on.rows} items). It backs up again by itself when the board changes.`
|
|
98
|
+
);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (sub === "now") {
|
|
102
|
+
const done = must(await daemonRequest({ command: "backup.now" }, 120_000));
|
|
103
|
+
console.log(`Backed up your board (${done.rows} items).`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (sub === "restore") {
|
|
107
|
+
const passphrase = await askPassphrase(ui, { twice: false });
|
|
108
|
+
if (!passphrase) return;
|
|
109
|
+
const restored = must(
|
|
110
|
+
await daemonRequest({ command: "backup.restore", passphrase }, 120_000)
|
|
111
|
+
);
|
|
112
|
+
console.log(
|
|
113
|
+
`Brought back your board from ${restored.from || "another computer"} (${restored.rows} items). Nothing that was already here was removed.`
|
|
114
|
+
);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (sub === "off") {
|
|
118
|
+
must(await daemonRequest({ command: "backup.off" }));
|
|
119
|
+
console.log(
|
|
120
|
+
"Backups are off on this computer. Harness keeps the last ones until a new one replaces them."
|
|
121
|
+
);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (sub)
|
|
125
|
+
throw new Error("usage: tryharness backup [on | now | restore | off]");
|
|
126
|
+
const status = must(await daemonRequest({ command: "backup.status" }));
|
|
127
|
+
if (status.entitled === false) {
|
|
128
|
+
console.log(
|
|
129
|
+
"Your board stays on this computer. An encrypted backup of it is a Resident feature."
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
console.log(
|
|
134
|
+
status.on
|
|
135
|
+
? `Backups are on${status.last ? `: last ${when(status.last.at)}, ${status.last.rows} items` : ""}.`
|
|
136
|
+
: `Backups are off on this computer: ${relayCommand()} backup on`
|
|
137
|
+
);
|
|
138
|
+
if (status.latest)
|
|
139
|
+
console.log(
|
|
140
|
+
`Harness keeps your newest from ${status.latest.fromLabel || "a computer"}, ${when(status.latest.createdAt)} (${status.latest.rows} items).`
|
|
141
|
+
);
|
|
142
|
+
if (status.error) console.log(`Harness did not answer: ${status.error}`);
|
|
143
|
+
}
|
package/lib/boardAccess.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { documentText, isDocument } from "./files.mjs";
|
|
4
4
|
import { secretReason } from "./secrets.mjs";
|
|
5
5
|
import { imageKind } from "./ocr.mjs";
|
|
6
|
+
import { member } from "./members.mjs";
|
|
6
7
|
|
|
7
8
|
export function createBoardAccess({
|
|
8
9
|
store,
|
|
@@ -14,12 +15,14 @@ export function createBoardAccess({
|
|
|
14
15
|
textLike,
|
|
15
16
|
coveredImage,
|
|
16
17
|
}) {
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// results, room posts, folders). The person's and
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
18
|
+
// Harness's server carries; it never acts as the person. A call in the clear naming "user" or "harness" is the
|
|
19
|
+
// server's word for who asks, so it gets metadata only: who, which state, when, the same as every board_changed
|
|
20
|
+
// already carries, and never the words (objectives, briefs, results, room posts, folders). The person's and
|
|
21
|
+
// Harness's own reads and writes come sealed from a paired device. This holds whether or not a browser is paired
|
|
22
|
+
// (security audit S2, October 25): an unpaired relay once gave the server the whole board as the person, a Start
|
|
23
|
+
// included. What still works in the clear, for what runs on Harness's servers: a run's status, the timeline's
|
|
24
|
+
// counts, a trace's timings, a bounty's check that a guest posted, the person's Stop on standing permission; a
|
|
25
|
+
// hosted caller (Muse, Grok Bot, any connector) works the tasks it is part of in full, which it has to read.
|
|
23
26
|
const SEALED_ONLY = {
|
|
24
27
|
ok: false,
|
|
25
28
|
code: "sealed_only",
|
|
@@ -143,7 +146,7 @@ export function createBoardAccess({
|
|
|
143
146
|
(task.kind === "goal" && inRoom(task, agent)) ||
|
|
144
147
|
Boolean(roomOf(task) && inRoom(roomOf(task), agent)));
|
|
145
148
|
// What leaves this computer for an agent through Harness: any text in the answer that looks like a secret (the room's
|
|
146
|
-
// check, cli/lib/secrets.mjs) is replaced with a notice; the person still reads it in full here
|
|
149
|
+
// check, cli/lib/secrets.mjs) is replaced with a notice; the person still reads it in full here.
|
|
147
150
|
const withoutSecrets = (value) => {
|
|
148
151
|
if (typeof value === "string") {
|
|
149
152
|
const flag = secretReason(value);
|
|
@@ -206,11 +209,21 @@ export function createBoardAccess({
|
|
|
206
209
|
};
|
|
207
210
|
const answerPlain = (input) => {
|
|
208
211
|
const agent = String(input.agent || "");
|
|
209
|
-
// The person's and Harness's calls are answered in full only while no browser is paired; a hosted agent is always
|
|
210
|
-
// limited to what it is part of, paired or not.
|
|
211
|
-
if (!store.sealedOnly() && (agent === "user" || agent === "harness"))
|
|
212
|
-
return boardCommand(input);
|
|
213
212
|
const command = String(input.command || "");
|
|
213
|
+
// A member that runs on this computer calls on its own socket here, never through Harness (members.mjs): a call in
|
|
214
|
+
// the clear in its name is someone else using it (security audit S7).
|
|
215
|
+
if (member(agent)?.road === "local")
|
|
216
|
+
return {
|
|
217
|
+
ok: false,
|
|
218
|
+
error: `${agent} runs on this computer, so a call through Harness is never taken for it`,
|
|
219
|
+
};
|
|
220
|
+
// The desk's book and the audits are personal (book.mjs, audit.mjs): never read through Harness in the clear.
|
|
221
|
+
if (command.startsWith("board.desk.") || command.startsWith("board.audit."))
|
|
222
|
+
return {
|
|
223
|
+
ok: false,
|
|
224
|
+
error:
|
|
225
|
+
"the desk's book and the audits stay on the person's computers: only the person and agents there read them",
|
|
226
|
+
};
|
|
214
227
|
// A thread Harness posts on accept: on the asking side, only one this machine asked for (it supplies the words itself).
|
|
215
228
|
if (
|
|
216
229
|
command === "board.post" &&
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import {
|
|
4
|
+
createCipheriv,
|
|
5
|
+
createDecipheriv,
|
|
6
|
+
pbkdf2,
|
|
7
|
+
randomBytes,
|
|
8
|
+
} from "node:crypto";
|
|
9
|
+
import { gunzipSync, gzipSync } from "node:zlib";
|
|
10
|
+
import { readJson, writeJsonAtomic } from "./files.mjs";
|
|
11
|
+
|
|
12
|
+
// The board's encrypted backup, for Residents (Harness's server keeps it). The board survives losing a computer,
|
|
13
|
+
// encrypted as a Resident's browser backup is. Home seals every board row (boardMirror.mjs's tables, as its pages carry
|
|
14
|
+
// them) with a key made from a passphrase only the person knows, and Harness keeps ciphertext it cannot read. Restoring
|
|
15
|
+
// brings the rows into the board here the way a computer joining brings its own (boardMirror.mjs bring): what is
|
|
16
|
+
// missing comes in, nothing here is removed.
|
|
17
|
+
//
|
|
18
|
+
// The key is kept beside the board in Harness's folder (0600), so backups go on by themselves: the board is on that
|
|
19
|
+
// disk unsealed anyway, and the seal is against Harness's servers. The same on every platform. Thread files' bytes
|
|
20
|
+
// (~/.harness/files) are not in it; their records are.
|
|
21
|
+
|
|
22
|
+
const MAGIC = Buffer.from("HRB1");
|
|
23
|
+
const SALT_BYTES = 16;
|
|
24
|
+
const IV_BYTES = 12;
|
|
25
|
+
const TAG_BYTES = 16;
|
|
26
|
+
// As the browser's backup client derives its key, kept in step with it.
|
|
27
|
+
const ITERATIONS = 210_000;
|
|
28
|
+
const PART_BYTES = 512 * 1024;
|
|
29
|
+
const MIN_PASSPHRASE = 8;
|
|
30
|
+
// How often home looks whether the board changed since its last backup. A product cadence, not a deadline.
|
|
31
|
+
export const BACKUP_EVERY_MS = 60 * 60_000;
|
|
32
|
+
const LAST = "board-backup-last";
|
|
33
|
+
|
|
34
|
+
const derive = (passphrase, salt) =>
|
|
35
|
+
promisify(pbkdf2)(String(passphrase), salt, ITERATIONS, 32, "sha256");
|
|
36
|
+
|
|
37
|
+
function seal(key, salt, plain) {
|
|
38
|
+
const iv = randomBytes(IV_BYTES);
|
|
39
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
40
|
+
const sealed = Buffer.concat([cipher.update(plain), cipher.final()]);
|
|
41
|
+
return Buffer.concat([MAGIC, salt, iv, cipher.getAuthTag(), sealed]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The salt a sealed backup was made with, or null when it is not one. */
|
|
45
|
+
function saltOf(blob) {
|
|
46
|
+
if (blob.length < MAGIC.length + SALT_BYTES + IV_BYTES + TAG_BYTES)
|
|
47
|
+
return null;
|
|
48
|
+
if (!blob.subarray(0, MAGIC.length).equals(MAGIC)) return null;
|
|
49
|
+
return blob.subarray(MAGIC.length, MAGIC.length + SALT_BYTES);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The backup opened with this key; throws when the key is not the one it was sealed with. */
|
|
53
|
+
function open(key, blob) {
|
|
54
|
+
let at = MAGIC.length + SALT_BYTES;
|
|
55
|
+
const iv = blob.subarray(at, (at += IV_BYTES));
|
|
56
|
+
const tag = blob.subarray(at, (at += TAG_BYTES));
|
|
57
|
+
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
58
|
+
decipher.setAuthTag(tag);
|
|
59
|
+
return Buffer.concat([decipher.update(blob.subarray(at)), decipher.final()]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function createBoardBackup({
|
|
63
|
+
store,
|
|
64
|
+
log,
|
|
65
|
+
mirror,
|
|
66
|
+
// A request to Harness over this computer's connection (bridge.mjs ask).
|
|
67
|
+
ask,
|
|
68
|
+
keyFile,
|
|
69
|
+
// Whether this computer holds the board: only home backs it up.
|
|
70
|
+
holdsBoard,
|
|
71
|
+
label,
|
|
72
|
+
everyMs = BACKUP_EVERY_MS,
|
|
73
|
+
}) {
|
|
74
|
+
const readKey = () => {
|
|
75
|
+
const saved = readJson(keyFile, null);
|
|
76
|
+
return saved?.salt && saved?.key
|
|
77
|
+
? {
|
|
78
|
+
salt: Buffer.from(saved.salt, "base64"),
|
|
79
|
+
key: Buffer.from(saved.key, "base64"),
|
|
80
|
+
}
|
|
81
|
+
: null;
|
|
82
|
+
};
|
|
83
|
+
const saveKey = ({ salt, key }) =>
|
|
84
|
+
writeJsonAtomic(keyFile, {
|
|
85
|
+
salt: salt.toString("base64"),
|
|
86
|
+
key: key.toString("base64"),
|
|
87
|
+
});
|
|
88
|
+
const last = () => JSON.parse(store.meta(LAST) || "null");
|
|
89
|
+
|
|
90
|
+
// Every row of the board, as the mirror's pages carry them.
|
|
91
|
+
const snapshot = () => {
|
|
92
|
+
const changes = [];
|
|
93
|
+
let after = 0;
|
|
94
|
+
for (;;) {
|
|
95
|
+
const page = mirror.since({ after, feed: mirror.feed() });
|
|
96
|
+
changes.push(...page.changes.filter((change) => change.row));
|
|
97
|
+
if (!page.changes.length || page.to >= page.head) break;
|
|
98
|
+
after = page.to;
|
|
99
|
+
}
|
|
100
|
+
return changes;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** Whether this account keeps a board backup, the newest Harness has, and this computer's last. */
|
|
104
|
+
const status = async () => {
|
|
105
|
+
const server = await ask("board_backup_status", {}).catch((error) => ({
|
|
106
|
+
ok: false,
|
|
107
|
+
error: error.message,
|
|
108
|
+
}));
|
|
109
|
+
return {
|
|
110
|
+
ok: true,
|
|
111
|
+
on: Boolean(readKey()),
|
|
112
|
+
entitled:
|
|
113
|
+
server.ok === true
|
|
114
|
+
? true
|
|
115
|
+
: server.code === "upgrade_required"
|
|
116
|
+
? false
|
|
117
|
+
: null,
|
|
118
|
+
latest: server.ok === true ? (server.latest ?? null) : null,
|
|
119
|
+
last: last(),
|
|
120
|
+
...(server.ok === true || server.code === "upgrade_required"
|
|
121
|
+
? {}
|
|
122
|
+
: { error: server.error || "Harness did not answer" }),
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
let running = null;
|
|
127
|
+
/** Seal the board and hand it to Harness, a part at a time. */
|
|
128
|
+
const backUp = () =>
|
|
129
|
+
(running ??= backUpOnce().finally(() => (running = null)));
|
|
130
|
+
const backUpOnce = async () => {
|
|
131
|
+
if (!holdsBoard())
|
|
132
|
+
return {
|
|
133
|
+
ok: false,
|
|
134
|
+
code: "not_home",
|
|
135
|
+
error: "Your home computer backs up the board.",
|
|
136
|
+
};
|
|
137
|
+
const saved = readKey();
|
|
138
|
+
if (!saved)
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
code: "no_passphrase",
|
|
142
|
+
error:
|
|
143
|
+
"Backups are off on this computer: npx tryharness backup on turns them on.",
|
|
144
|
+
};
|
|
145
|
+
const head = mirror.head();
|
|
146
|
+
const changes = snapshot();
|
|
147
|
+
const plain = gzipSync(
|
|
148
|
+
Buffer.from(
|
|
149
|
+
JSON.stringify({
|
|
150
|
+
format: 1,
|
|
151
|
+
at: new Date().toISOString(),
|
|
152
|
+
from: label(),
|
|
153
|
+
changes,
|
|
154
|
+
})
|
|
155
|
+
)
|
|
156
|
+
);
|
|
157
|
+
const blob = seal(saved.key, saved.salt, plain);
|
|
158
|
+
const uploadId = randomBytes(12).toString("base64url");
|
|
159
|
+
const count = Math.max(1, Math.ceil(blob.length / PART_BYTES));
|
|
160
|
+
let answer = null;
|
|
161
|
+
for (let index = 0; index < count; index++) {
|
|
162
|
+
answer = await ask("board_backup_put", {
|
|
163
|
+
uploadId,
|
|
164
|
+
index,
|
|
165
|
+
count,
|
|
166
|
+
data: blob
|
|
167
|
+
.subarray(index * PART_BYTES, (index + 1) * PART_BYTES)
|
|
168
|
+
.toString("base64"),
|
|
169
|
+
fromLabel: label(),
|
|
170
|
+
rows: changes.length,
|
|
171
|
+
}).catch((error) => ({ ok: false, error: error.message }));
|
|
172
|
+
if (answer?.ok !== true) {
|
|
173
|
+
log(
|
|
174
|
+
`the board's backup did not go to Harness: ${answer?.error || "no answer"}`
|
|
175
|
+
);
|
|
176
|
+
return { ok: false, code: answer?.code, error: answer?.error };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const stored = answer?.stored ?? null;
|
|
180
|
+
store.meta(
|
|
181
|
+
LAST,
|
|
182
|
+
JSON.stringify({
|
|
183
|
+
head,
|
|
184
|
+
at: new Date().toISOString(),
|
|
185
|
+
version: stored?.version ?? null,
|
|
186
|
+
rows: changes.length,
|
|
187
|
+
bytes: blob.length,
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
log(
|
|
191
|
+
`backed up the board, sealed (${changes.length} rows, ${Math.round(blob.length / 1024)} KB)`
|
|
192
|
+
);
|
|
193
|
+
return { ok: true, rows: changes.length, bytes: blob.length, stored };
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/** The person chose a passphrase: backups go on from now, the first one at once. */
|
|
197
|
+
const turnOn = async (passphrase) => {
|
|
198
|
+
if (String(passphrase ?? "").length < MIN_PASSPHRASE)
|
|
199
|
+
return {
|
|
200
|
+
ok: false,
|
|
201
|
+
code: "short",
|
|
202
|
+
error: `A backup passphrase is at least ${MIN_PASSPHRASE} characters.`,
|
|
203
|
+
};
|
|
204
|
+
const salt = randomBytes(SALT_BYTES);
|
|
205
|
+
saveKey({ salt, key: await derive(passphrase, salt) });
|
|
206
|
+
const first = await backUp();
|
|
207
|
+
// Refused (not a Resident, or not home): backups stay off rather than seem on.
|
|
208
|
+
if (!first.ok && first.code !== undefined) turnOff();
|
|
209
|
+
return first;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const turnOff = () => {
|
|
213
|
+
fs.rmSync(keyFile, { force: true });
|
|
214
|
+
return { ok: true };
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/** The newest backup (or the version asked for), opened with the person's passphrase and brought into the board. */
|
|
218
|
+
const restore = async (passphrase, { version } = {}) => {
|
|
219
|
+
const parts = [];
|
|
220
|
+
let count = 1;
|
|
221
|
+
let found = null;
|
|
222
|
+
for (let index = 0; index < count; index++) {
|
|
223
|
+
const answer = await ask("board_backup_get", {
|
|
224
|
+
index,
|
|
225
|
+
...(version ? { version } : {}),
|
|
226
|
+
}).catch((error) => ({ ok: false, error: error.message }));
|
|
227
|
+
if (answer?.ok !== true)
|
|
228
|
+
return {
|
|
229
|
+
ok: false,
|
|
230
|
+
code: answer?.code,
|
|
231
|
+
error: answer?.error || "Harness did not answer",
|
|
232
|
+
};
|
|
233
|
+
count = answer.count;
|
|
234
|
+
found = answer.version;
|
|
235
|
+
parts.push(Buffer.from(String(answer.data), "base64"));
|
|
236
|
+
}
|
|
237
|
+
const blob = Buffer.concat(parts);
|
|
238
|
+
const salt = saltOf(blob);
|
|
239
|
+
if (!salt)
|
|
240
|
+
return { ok: false, error: "That backup is not one Harness can open." };
|
|
241
|
+
const key = await derive(passphrase, salt);
|
|
242
|
+
let plain;
|
|
243
|
+
try {
|
|
244
|
+
plain = open(key, blob);
|
|
245
|
+
} catch {
|
|
246
|
+
return {
|
|
247
|
+
ok: false,
|
|
248
|
+
code: "wrong_passphrase",
|
|
249
|
+
error: "That is not the passphrase this backup was made with.",
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
const backup = JSON.parse(gunzipSync(plain).toString("utf8"));
|
|
253
|
+
mirror.merge({ changes: backup.changes ?? [] }, { bring: true });
|
|
254
|
+
// The same passphrase goes on backing up the board from here.
|
|
255
|
+
saveKey({ salt, key });
|
|
256
|
+
log(
|
|
257
|
+
`brought back the board's backup from ${backup.from || "another computer"} (${backup.at}, ${backup.changes?.length ?? 0} rows)`
|
|
258
|
+
);
|
|
259
|
+
return {
|
|
260
|
+
ok: true,
|
|
261
|
+
version: found,
|
|
262
|
+
from: backup.from ?? null,
|
|
263
|
+
at: backup.at ?? null,
|
|
264
|
+
rows: backup.changes?.length ?? 0,
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// Home looks now and then whether the board changed since its last backup.
|
|
269
|
+
const timer = setInterval(() => {
|
|
270
|
+
if (!readKey() || !holdsBoard() || last()?.head === mirror.head()) return;
|
|
271
|
+
void backUp();
|
|
272
|
+
}, everyMs);
|
|
273
|
+
timer.unref?.();
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
status,
|
|
277
|
+
backUp,
|
|
278
|
+
turnOn,
|
|
279
|
+
turnOff,
|
|
280
|
+
restore,
|
|
281
|
+
stop: () => clearInterval(timer),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
@@ -102,9 +102,9 @@ export function createBoardFileCommands({
|
|
|
102
102
|
: mimeFor(name);
|
|
103
103
|
const limit = fileLimit(mime, bytes);
|
|
104
104
|
if (bytes.length > limit.bytes) return tooBig(bytes.length, limit);
|
|
105
|
-
// Shared with the agents on Harness's side unless whoever attached it keeps it on the computer
|
|
106
|
-
//
|
|
107
|
-
//
|
|
105
|
+
// Shared with the agents on Harness's side unless whoever attached it keeps it on the computer: shared is the
|
|
106
|
+
// default and the person chooses what is not shared. Bytes that came through Harness were readable there already.
|
|
107
|
+
// To another person's computer a file still goes only sealed.
|
|
108
108
|
const file = store.addFile({
|
|
109
109
|
taskId: id,
|
|
110
110
|
name,
|
|
@@ -169,9 +169,9 @@ export function createBoardFileCommands({
|
|
|
169
169
|
ok: false,
|
|
170
170
|
error: "this file is still on its way from the other computer",
|
|
171
171
|
};
|
|
172
|
-
// A part of the file for the person's own phone or linked browser: a sealed answer carries about 1 MB
|
|
173
|
-
//
|
|
174
|
-
// file, which the checks in plainBoard read as a whole.
|
|
172
|
+
// A part of the file for the person's own phone or linked browser: a sealed answer carries about 1 MB (the sealed
|
|
173
|
+
// wire's limit, kept in step with Harness), so a larger file is read in parts. A caller through Harness gets the
|
|
174
|
+
// whole file, which the checks in plainBoard read as a whole.
|
|
175
175
|
if (request.offset !== undefined && !request.hostedCaller) {
|
|
176
176
|
const offset = Number(request.offset),
|
|
177
177
|
length = Number(request.length ?? FILE_PART_BYTES);
|
package/lib/boardFiles.mjs
CHANGED
|
@@ -308,10 +308,10 @@ export function createBoardFiles({
|
|
|
308
308
|
data: out.bytes.toString("base64"),
|
|
309
309
|
};
|
|
310
310
|
};
|
|
311
|
-
// Harness's files on a task given to it, asked by Harness's server for the run or window working it
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
//
|
|
311
|
+
// Harness's files on a task given to it, asked by Harness's server for the run or window working it: it lists and
|
|
312
|
+
// reads what its thread shared with agents on Harness's side, under the checks any agent reading through Harness
|
|
313
|
+
// gets, and adds what it made there. Allowed with a browser paired too: what Harness adds it made on its own servers,
|
|
314
|
+
// as with its answers to the tasks given to it.
|
|
315
315
|
const harnessFile = async (input) => {
|
|
316
316
|
const { scrubber } = processing();
|
|
317
317
|
const task = store.getTask(String(input.taskId || ""));
|
|
@@ -319,9 +319,9 @@ export function createBoardFiles({
|
|
|
319
319
|
return { ok: false, error: "not a task given to Harness" };
|
|
320
320
|
const place = roomOf(task) ?? task;
|
|
321
321
|
// The thread's posts a page at a time, as every agent reads them (roomPage.mjs): its newest, the ones before a post
|
|
322
|
-
// going back, or the ones after one Harness has seen, so it reads the thread again before it answers (
|
|
323
|
-
//
|
|
324
|
-
//
|
|
322
|
+
// going back, or the ones after one Harness has seen, so it reads the thread again before it answers (answers built
|
|
323
|
+
// on the snapshot its task started with once restated what had changed since). Keys are swapped out, as in its
|
|
324
|
+
// task.
|
|
325
325
|
if (input.op === "posts") {
|
|
326
326
|
const page = roomPage(store, place.id, {
|
|
327
327
|
since: Math.max(0, Math.floor(Number(input.since) || 0)),
|
|
@@ -441,7 +441,8 @@ export function createBoardFiles({
|
|
|
441
441
|
place.goal.team.includes(agent)
|
|
442
442
|
),
|
|
443
443
|
});
|
|
444
|
-
|
|
444
|
+
// Said by Harness's server (harness_file comes only from there): it wakes the asker without the person's go.
|
|
445
|
+
wakeFor(place.id, post, "harness", undefined, { hosted: true });
|
|
445
446
|
}
|
|
446
447
|
return { ok: true };
|
|
447
448
|
}
|
|
@@ -449,7 +450,7 @@ export function createBoardFiles({
|
|
|
449
450
|
const bytes = Buffer.from(String(input.data || ""), "base64");
|
|
450
451
|
if (!bytes.length) return { ok: false, error: "the file is empty" };
|
|
451
452
|
// A finished render keeps the name its rendering was given (the shot it is), and no two of Harness's files in a
|
|
452
|
-
// thread share a name (
|
|
453
|
+
// thread share a name (four takes were once all named set-a-tiny-character-on-a.mp4, told apart by guesswork).
|
|
453
454
|
const named = fileName(
|
|
454
455
|
(jobId && rendering.find((each) => each.jobId === jobId)?.name) ||
|
|
455
456
|
input.name
|
|
@@ -503,8 +504,8 @@ export function createBoardFiles({
|
|
|
503
504
|
JSON.stringify(rendering.filter((each) => each.jobId !== jobId))
|
|
504
505
|
);
|
|
505
506
|
// Made after Harness answered (a video renders for minutes): said in the thread, waking whoever asked. Asked by
|
|
506
|
-
// Harness itself (the coordinator handing work on in its name), there is no one else to wake and the file's own
|
|
507
|
-
// shows it (
|
|
507
|
+
// Harness itself (the coordinator handing work on in its name), there is no one else to wake and the file's own
|
|
508
|
+
// post shows it (one thread once had five "Made for Harness" posts, each a copy of the file posted above it).
|
|
508
509
|
if (
|
|
509
510
|
["done", "failed"].includes(task.status) &&
|
|
510
511
|
place.kind === "goal" &&
|
|
@@ -525,7 +526,7 @@ export function createBoardFiles({
|
|
|
525
526
|
place.goal.team.includes(agent)
|
|
526
527
|
),
|
|
527
528
|
});
|
|
528
|
-
wakeFor(place.id, post, "harness");
|
|
529
|
+
wakeFor(place.id, post, "harness", undefined, { hosted: true });
|
|
529
530
|
}
|
|
530
531
|
notifyBoard(store.getTask(place.id));
|
|
531
532
|
return { ok: true, file: harnessFileView(file) };
|