tryharness 0.7.82 → 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 +193 -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 +57 -2
- 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 +2435 -333
- 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 +2 -2
- 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/onboard.mjs +6 -6
- 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 +212 -130
- 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/vault.mjs
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
// environment grant is the exception the person chooses: the value is in that agent's run, and the run's log and
|
|
11
11
|
// result are scrubbed of it (taskRuns.mjs). A worker computer's run gets it from home, sealed to that computer, for the
|
|
12
12
|
// run (machineRuns.mjs); an agent on a worker uses a secret through home, so the value stays here.
|
|
13
|
+
//
|
|
14
|
+
// An agent may pass a secret it may use to another agent: that one may use it too, at the same websites, until the work
|
|
15
|
+
// it was passed for ends or the grant it came from does. The value does not move. Between the person's own agents this
|
|
16
|
+
// needs nothing from them; another person's agent needs their OK once per secret and person, and uses the secret by
|
|
17
|
+
// asking this computer to make the request (vaultPeers.mjs). A passed secret never goes in a run's environment.
|
|
13
18
|
import fs from "node:fs";
|
|
14
19
|
import path from "node:path";
|
|
15
20
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
@@ -22,6 +27,7 @@ import {
|
|
|
22
27
|
} from "./oneclawLocal.mjs";
|
|
23
28
|
import { createOneclawCloud, OneclawError } from "./vaultCloud.mjs";
|
|
24
29
|
import { member, nameOf } from "./members.mjs";
|
|
30
|
+
import { readSecretFile, writeSecretFile } from "./secretStore.mjs";
|
|
25
31
|
|
|
26
32
|
const STATE = "vault:v1";
|
|
27
33
|
const REF = /\{\{\s*secret:([A-Za-z0-9_\-./]+)\s*\}\}/g;
|
|
@@ -55,6 +61,10 @@ const LOOPBACK = new Set(["127.0.0.1", "localhost", "[::1]"]);
|
|
|
55
61
|
const RESPONSE_CAP = 8_000;
|
|
56
62
|
const MAX_REDIRECTS = 3;
|
|
57
63
|
const OWNER_ONLY = "Only the person can do that, on their home computer.";
|
|
64
|
+
// Agent names as the board takes them, the other person's handle first when there is one.
|
|
65
|
+
const AGENT_NAME = /^[a-z0-9][a-z0-9._-]{0,63}(\/[a-z0-9][a-z0-9._-]{0,63})?$/;
|
|
66
|
+
// What one other person's computer may list here as passed to this person's agents.
|
|
67
|
+
const MAX_RECEIVED_FROM_ONE_PERSON = 200;
|
|
58
68
|
// Where in a request a secret may go. A header is the default: a website keeps what is sent in an address or a body
|
|
59
69
|
// (a gist, an issue, a search log) and anyone who reads it there has the secret. A secret's own setting widens it.
|
|
60
70
|
const PLACES = ["header", "url", "body"];
|
|
@@ -91,6 +101,18 @@ const placesOf = (written) =>
|
|
|
91
101
|
(Array.isArray(written) ? written : []).map(String).includes(place)
|
|
92
102
|
);
|
|
93
103
|
|
|
104
|
+
const EMPTY_STATE = () => ({
|
|
105
|
+
grants: [],
|
|
106
|
+
requests: [],
|
|
107
|
+
shares: [],
|
|
108
|
+
policies: {},
|
|
109
|
+
backup: { status: "off" },
|
|
110
|
+
// The person's OK for another person's agents to be passed a secret: { secret, person }.
|
|
111
|
+
peopleAllowed: [],
|
|
112
|
+
// Secrets another person passed to this person's agents, kept on their computer: { from, secret, agent, hosts, places }.
|
|
113
|
+
received: [],
|
|
114
|
+
});
|
|
115
|
+
|
|
94
116
|
/** Every value in `text` (and its URL-encoded form) replaced by its name's marker. */
|
|
95
117
|
export function scrubValues(text, values) {
|
|
96
118
|
let out = String(text ?? "");
|
|
@@ -136,36 +158,38 @@ export function createVault({
|
|
|
136
158
|
onRequest = () => {},
|
|
137
159
|
// The person allowed what a run stopped to ask them for: the run hears it and carries on.
|
|
138
160
|
continueRun = () => {},
|
|
161
|
+
// Whether the task or thread a secret was passed for is still going, and a line the person sees in it.
|
|
162
|
+
workOpen = () => false,
|
|
163
|
+
noteInWork = () => {},
|
|
164
|
+
// Whether a run works on another agent's or another person's say: what the caller says of itself does not decide it.
|
|
165
|
+
runRestricted = () => false,
|
|
166
|
+
// The road to another person's computer (vaultPeers.mjs), made after this module.
|
|
167
|
+
peers = () => null,
|
|
139
168
|
fetch = globalThis.fetch,
|
|
140
169
|
}) {
|
|
141
170
|
const file = path.join(directory, "vault.enc");
|
|
171
|
+
// The vault file's key: in the keychain for the person's own Harness on a Mac (secretStore.mjs), else this 0600 file.
|
|
142
172
|
const keyFile = path.join(directory, "vault-key");
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
173
|
+
const passphrase = (() => {
|
|
174
|
+
try {
|
|
175
|
+
return readSecretFile(keyFile).trim();
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (error.code !== "ENOENT") throw error;
|
|
178
|
+
const made = randomBytes(32).toString("base64url");
|
|
179
|
+
writeSecretFile(keyFile, made, { exclusive: true });
|
|
180
|
+
return made;
|
|
181
|
+
}
|
|
182
|
+
})();
|
|
149
183
|
const cloud = createOneclawCloud({ base: cloudUrl, fetch });
|
|
150
184
|
|
|
151
185
|
const state = (() => {
|
|
152
186
|
try {
|
|
153
187
|
return {
|
|
154
|
-
|
|
155
|
-
requests: [],
|
|
156
|
-
shares: [],
|
|
157
|
-
policies: {},
|
|
158
|
-
backup: { status: "off" },
|
|
188
|
+
...EMPTY_STATE(),
|
|
159
189
|
...JSON.parse(store.meta(STATE) ?? "{}"),
|
|
160
190
|
};
|
|
161
191
|
} catch {
|
|
162
|
-
return
|
|
163
|
-
grants: [],
|
|
164
|
-
requests: [],
|
|
165
|
-
shares: [],
|
|
166
|
-
policies: {},
|
|
167
|
-
backup: { status: "off" },
|
|
168
|
-
};
|
|
192
|
+
return EMPTY_STATE();
|
|
169
193
|
}
|
|
170
194
|
})();
|
|
171
195
|
const saveState = () => store.meta(STATE, JSON.stringify(state));
|
|
@@ -209,8 +233,15 @@ export function createVault({
|
|
|
209
233
|
};
|
|
210
234
|
|
|
211
235
|
const now = () => new Date().toISOString();
|
|
212
|
-
|
|
213
|
-
|
|
236
|
+
// A passed grant lasts while its work does and while the grant it was passed from does.
|
|
237
|
+
const live = (grant) => {
|
|
238
|
+
if (grant.expiresAt && Date.parse(grant.expiresAt) <= Date.now())
|
|
239
|
+
return false;
|
|
240
|
+
if (grant.work && !workOpen(grant.work)) return false;
|
|
241
|
+
if (!grant.passedFrom) return true;
|
|
242
|
+
const source = state.grants.find((entry) => entry.id === grant.passedFrom);
|
|
243
|
+
return Boolean(source) && live(source);
|
|
244
|
+
};
|
|
214
245
|
const hostsOf = (name) => vault.secrets[name]?.allowed_hosts ?? [];
|
|
215
246
|
const secretPlaces = (name) => state.policies[name]?.places ?? ["header"];
|
|
216
247
|
const keepPolicy = (name, fields) => {
|
|
@@ -236,6 +267,10 @@ export function createVault({
|
|
|
236
267
|
task,
|
|
237
268
|
expiresAt,
|
|
238
269
|
createdAt,
|
|
270
|
+
passedBy,
|
|
271
|
+
work,
|
|
272
|
+
uses,
|
|
273
|
+
lastUsedAt,
|
|
239
274
|
}) => ({
|
|
240
275
|
id,
|
|
241
276
|
agent,
|
|
@@ -247,12 +282,23 @@ export function createVault({
|
|
|
247
282
|
task,
|
|
248
283
|
expiresAt,
|
|
249
284
|
createdAt,
|
|
285
|
+
...(passedBy
|
|
286
|
+
? { passedBy, work, uses: uses ?? 0, lastUsedAt: lastUsedAt ?? null }
|
|
287
|
+
: {}),
|
|
250
288
|
});
|
|
289
|
+
const personOf = (agent) =>
|
|
290
|
+
String(agent).includes("/") ? String(agent).split("/")[0] : null;
|
|
291
|
+
const received = (agent, name) =>
|
|
292
|
+
state.received.find(
|
|
293
|
+
(entry) =>
|
|
294
|
+
entry.agent === agent && `${entry.from}/${entry.secret}` === name
|
|
295
|
+
);
|
|
251
296
|
|
|
252
297
|
// An agent asked for a secret it may not use yet: the person sees it once, and is told.
|
|
253
298
|
const ask = (agent, secret, why, host, runId) => {
|
|
254
299
|
const known = state.requests.find(
|
|
255
|
-
(request) =>
|
|
300
|
+
(request) =>
|
|
301
|
+
request.agent === agent && request.secret === secret && !request.to
|
|
256
302
|
);
|
|
257
303
|
// Asked again for another website: a new request, so a card the person already sees for the first one cannot
|
|
258
304
|
// allow the second.
|
|
@@ -301,7 +347,10 @@ export function createVault({
|
|
|
301
347
|
secret: request.secret,
|
|
302
348
|
host: request.host,
|
|
303
349
|
missing: request.why === "missing",
|
|
304
|
-
|
|
350
|
+
...(request.to ? { passTo: request.to } : {}),
|
|
351
|
+
text: request.to
|
|
352
|
+
? `${nameOf(request.agent)} wants to let ${request.to} use ${request.secret} at ${hostsOf(request.secret).join(", ") || "the websites you named"}. The key stays on this computer, which makes each request.`
|
|
353
|
+
: `${nameOf(request.agent)} ${request.why === "missing" ? "needs" : "asks to use"} ${request.secret}${request.host ? ` for ${request.host}` : ""}.`,
|
|
305
354
|
at: request.at,
|
|
306
355
|
}));
|
|
307
356
|
|
|
@@ -338,11 +387,232 @@ export function createVault({
|
|
|
338
387
|
return { env, values, names };
|
|
339
388
|
};
|
|
340
389
|
|
|
390
|
+
// A passed grant, made and said where the person can see it.
|
|
391
|
+
const makePassedGrant = ({ to, secret, by, source, work }) => {
|
|
392
|
+
state.grants = state.grants.filter(
|
|
393
|
+
(entry) =>
|
|
394
|
+
!(entry.agent === to && entry.secret === secret && entry.work === work)
|
|
395
|
+
);
|
|
396
|
+
const grant = {
|
|
397
|
+
id: randomUUID(),
|
|
398
|
+
agent: to,
|
|
399
|
+
secret,
|
|
400
|
+
mode: "use",
|
|
401
|
+
hosted: (member(to)?.road ?? "local") !== "local",
|
|
402
|
+
machines: "own",
|
|
403
|
+
task: null,
|
|
404
|
+
expiresAt: null,
|
|
405
|
+
createdAt: now(),
|
|
406
|
+
passedBy: by,
|
|
407
|
+
passedFrom: source?.id ?? null,
|
|
408
|
+
work,
|
|
409
|
+
uses: 0,
|
|
410
|
+
lastUsedAt: null,
|
|
411
|
+
};
|
|
412
|
+
state.grants.push(grant);
|
|
413
|
+
saveState();
|
|
414
|
+
noteInWork(
|
|
415
|
+
work,
|
|
416
|
+
`${nameOf(by)} passed ${secret} to ${nameOf(to)} for this work. It stays on this computer and goes only to ${hostsOf(secret).join(", ") || "the websites named for it"}.`
|
|
417
|
+
);
|
|
418
|
+
return grant;
|
|
419
|
+
};
|
|
420
|
+
const tellPassed = (grant) => {
|
|
421
|
+
const handle = personOf(grant.agent);
|
|
422
|
+
return peers()?.tell(
|
|
423
|
+
handle,
|
|
424
|
+
{
|
|
425
|
+
type: "passed",
|
|
426
|
+
secret: grant.secret,
|
|
427
|
+
agent: grant.agent.split("/")[1],
|
|
428
|
+
hosts: hostsOf(grant.secret),
|
|
429
|
+
places: secretPlaces(grant.secret),
|
|
430
|
+
},
|
|
431
|
+
grant.work
|
|
432
|
+
);
|
|
433
|
+
};
|
|
434
|
+
// Another person's computer hears when what it listed is over, so its agent stops being offered it.
|
|
435
|
+
const tellEnded = (grants) => {
|
|
436
|
+
for (const grant of grants)
|
|
437
|
+
if (personOf(grant.agent))
|
|
438
|
+
peers()?.tell(
|
|
439
|
+
personOf(grant.agent),
|
|
440
|
+
{
|
|
441
|
+
type: "ended",
|
|
442
|
+
secret: grant.secret,
|
|
443
|
+
agent: grant.agent.split("/")[1],
|
|
444
|
+
},
|
|
445
|
+
grant.work
|
|
446
|
+
);
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// use_secret's pass: this agent lets another use a secret it may use itself.
|
|
450
|
+
const passSecret = async (
|
|
451
|
+
request,
|
|
452
|
+
agent,
|
|
453
|
+
{ owner, hosted, fromElsewhere, from }
|
|
454
|
+
) => {
|
|
455
|
+
if (request.restricted === true)
|
|
456
|
+
return {
|
|
457
|
+
ok: false,
|
|
458
|
+
error: "A restricted run cannot pass the person's secrets.",
|
|
459
|
+
};
|
|
460
|
+
const name = String(request.secret ?? "");
|
|
461
|
+
const to = String(request.to ?? "")
|
|
462
|
+
.trim()
|
|
463
|
+
.toLowerCase();
|
|
464
|
+
const runId = runOf(agent, from, request.runId);
|
|
465
|
+
if (runId && runRestricted(runId))
|
|
466
|
+
return {
|
|
467
|
+
ok: false,
|
|
468
|
+
error: "A restricted run cannot pass the person's secrets.",
|
|
469
|
+
};
|
|
470
|
+
const namedWork = typeof request.work === "string" ? request.work : null;
|
|
471
|
+
const work = namedWork ?? runId;
|
|
472
|
+
const source = grantFor(agent, name, "use", {
|
|
473
|
+
hosted,
|
|
474
|
+
fromElsewhere,
|
|
475
|
+
task: runId,
|
|
476
|
+
});
|
|
477
|
+
// The same answer whether the secret exists or not: an agent learns of a secret only by being allowed it.
|
|
478
|
+
if (!owner && !source)
|
|
479
|
+
return {
|
|
480
|
+
ok: false,
|
|
481
|
+
error: `You can pass only a secret you may use yourself, and you may not use ${name}.`,
|
|
482
|
+
};
|
|
483
|
+
if (!vault.secrets[name])
|
|
484
|
+
return { ok: false, error: `${name} is not in the vault.` };
|
|
485
|
+
if (!AGENT_NAME.test(to) || to === "user")
|
|
486
|
+
return {
|
|
487
|
+
ok: false,
|
|
488
|
+
error: "Name the agent to pass it to: codex, or ana/claude-code.",
|
|
489
|
+
};
|
|
490
|
+
if (to === agent)
|
|
491
|
+
return { ok: false, error: "You already may use this secret." };
|
|
492
|
+
if (!work)
|
|
493
|
+
return {
|
|
494
|
+
ok: false,
|
|
495
|
+
error:
|
|
496
|
+
"Name the task or thread it is passed for (work): it ends when that ends.",
|
|
497
|
+
};
|
|
498
|
+
if (!workOpen(work))
|
|
499
|
+
return {
|
|
500
|
+
ok: false,
|
|
501
|
+
error: `${work} is not an open task or thread here.`,
|
|
502
|
+
};
|
|
503
|
+
const handle = personOf(to);
|
|
504
|
+
if (!handle) {
|
|
505
|
+
if (!member(to))
|
|
506
|
+
return { ok: false, error: `${to} is not one of the person's agents.` };
|
|
507
|
+
const grant = makePassedGrant({
|
|
508
|
+
to,
|
|
509
|
+
secret: name,
|
|
510
|
+
by: agent,
|
|
511
|
+
source,
|
|
512
|
+
work,
|
|
513
|
+
});
|
|
514
|
+
onRequest(runId ?? null);
|
|
515
|
+
return { ok: true, passed: publicGrant(grant) };
|
|
516
|
+
}
|
|
517
|
+
// Only inside a jam both people are in, the one this work is in (docs/jam-plan.md J4.8).
|
|
518
|
+
if (!peers()?.jamWith(handle, work))
|
|
519
|
+
return {
|
|
520
|
+
ok: false,
|
|
521
|
+
error: `${handle} is not in a jam with you that this work is in, so their agents cannot reach this computer.`,
|
|
522
|
+
};
|
|
523
|
+
const allowed = state.peopleAllowed.some(
|
|
524
|
+
(entry) => entry.secret === name && entry.person === handle
|
|
525
|
+
);
|
|
526
|
+
if (allowed) {
|
|
527
|
+
const grant = makePassedGrant({
|
|
528
|
+
to,
|
|
529
|
+
secret: name,
|
|
530
|
+
by: agent,
|
|
531
|
+
source,
|
|
532
|
+
work,
|
|
533
|
+
});
|
|
534
|
+
tellPassed(grant);
|
|
535
|
+
return { ok: true, passed: publicGrant(grant) };
|
|
536
|
+
}
|
|
537
|
+
const known = state.requests.find(
|
|
538
|
+
(entry) =>
|
|
539
|
+
entry.agent === agent && entry.secret === name && entry.to === to
|
|
540
|
+
);
|
|
541
|
+
if (known) Object.assign(known, { work, runId, at: now() });
|
|
542
|
+
else {
|
|
543
|
+
state.requests.push({
|
|
544
|
+
id: randomUUID(),
|
|
545
|
+
agent,
|
|
546
|
+
secret: name,
|
|
547
|
+
why: "pass",
|
|
548
|
+
to,
|
|
549
|
+
work,
|
|
550
|
+
host: null,
|
|
551
|
+
runId: runId ?? null,
|
|
552
|
+
at: now(),
|
|
553
|
+
});
|
|
554
|
+
notify(`${agent} wants to let ${to} use ${name}.`);
|
|
555
|
+
}
|
|
556
|
+
saveState();
|
|
557
|
+
onRequest(runId ?? null);
|
|
558
|
+
return {
|
|
559
|
+
ok: false,
|
|
560
|
+
error: `The person's OK is needed once to pass ${name} to ${handle}'s agents. Harness asked them; try again once they have.`,
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
// The other person's agent's call, sent to the computer that keeps the secret, which alone puts the value in.
|
|
565
|
+
const sendThroughPerson = async (request, agent, names, signal) => {
|
|
566
|
+
const handles = new Set(names.map((name) => name.split("/")[0]));
|
|
567
|
+
if (handles.size > 1 || names.some((name) => !received(agent, name)))
|
|
568
|
+
return {
|
|
569
|
+
ok: false,
|
|
570
|
+
error:
|
|
571
|
+
"A request can use secrets from one place only: from one person, or from this computer.",
|
|
572
|
+
};
|
|
573
|
+
const [handle] = handles;
|
|
574
|
+
const local = (text) =>
|
|
575
|
+
typeof text === "string"
|
|
576
|
+
? text.replace(REF, (_, name) =>
|
|
577
|
+
received(agent, name)
|
|
578
|
+
? `{{secret:${name.slice(handle.length + 1)}}}`
|
|
579
|
+
: _
|
|
580
|
+
)
|
|
581
|
+
: text;
|
|
582
|
+
const answer = await peers().call(
|
|
583
|
+
handle,
|
|
584
|
+
agent,
|
|
585
|
+
{
|
|
586
|
+
url: local(String(request.url ?? "")),
|
|
587
|
+
method: request.method,
|
|
588
|
+
headers: (Array.isArray(request.headers) ? request.headers : []).map(
|
|
589
|
+
(line) => local(String(line))
|
|
590
|
+
),
|
|
591
|
+
...(typeof request.body === "string"
|
|
592
|
+
? { body: local(request.body) }
|
|
593
|
+
: {}),
|
|
594
|
+
},
|
|
595
|
+
{ signal }
|
|
596
|
+
);
|
|
597
|
+
// Over on the other side: not offered here again.
|
|
598
|
+
if (answer.ended) {
|
|
599
|
+
state.received = state.received.filter(
|
|
600
|
+
(entry) =>
|
|
601
|
+
!(
|
|
602
|
+
entry.agent === agent && names.includes(`${handle}/${entry.secret}`)
|
|
603
|
+
)
|
|
604
|
+
);
|
|
605
|
+
saveState();
|
|
606
|
+
}
|
|
607
|
+
return answer;
|
|
608
|
+
};
|
|
609
|
+
|
|
341
610
|
// use_secret: the request leaves from here, with the values in it, only for websites they are allowed at.
|
|
611
|
+
// `peer`: it was asked for by another person's computer, on the agent's behalf: refused plainly, never asked about.
|
|
342
612
|
const sendWithSecrets = async (
|
|
343
613
|
request,
|
|
344
614
|
agent,
|
|
345
|
-
{ hosted, fromElsewhere, from, signal }
|
|
615
|
+
{ hosted, fromElsewhere, from, signal, peer = false }
|
|
346
616
|
) => {
|
|
347
617
|
if (request.restricted === true)
|
|
348
618
|
return {
|
|
@@ -373,6 +643,17 @@ export function createVault({
|
|
|
373
643
|
error:
|
|
374
644
|
"Put the secret where it goes as {{secret:name}}, in a header (or the url or the body where that secret may go there).",
|
|
375
645
|
};
|
|
646
|
+
const fromPerson = peer
|
|
647
|
+
? []
|
|
648
|
+
: names.filter((name) => !vault.secrets[name] && received(agent, name));
|
|
649
|
+
if (fromPerson.length)
|
|
650
|
+
return fromPerson.length === names.length
|
|
651
|
+
? sendThroughPerson(request, agent, names, signal)
|
|
652
|
+
: {
|
|
653
|
+
ok: false,
|
|
654
|
+
error:
|
|
655
|
+
"A request can use secrets from one place only: from one person, or from this computer.",
|
|
656
|
+
};
|
|
376
657
|
let target;
|
|
377
658
|
try {
|
|
378
659
|
target = new URL(url.replace(REF, "x"));
|
|
@@ -380,12 +661,25 @@ export function createVault({
|
|
|
380
661
|
return { ok: false, error: "That is not a URL." };
|
|
381
662
|
}
|
|
382
663
|
const values = new Map();
|
|
383
|
-
const
|
|
664
|
+
const usedGrants = [];
|
|
665
|
+
const runId = peer ? null : runOf(agent, from, request.runId);
|
|
666
|
+
if (runId && runRestricted(runId))
|
|
667
|
+
return {
|
|
668
|
+
ok: false,
|
|
669
|
+
error: "A restricted run cannot use the person's secrets.",
|
|
670
|
+
};
|
|
384
671
|
const namedIn = (text) =>
|
|
385
672
|
new Set([...String(text ?? "").matchAll(REF)].map((match) => match[1]));
|
|
386
673
|
const where = { url: namedIn(url), body: namedIn(body) };
|
|
387
674
|
for (const name of names) {
|
|
388
675
|
const secret = vault.secrets[name];
|
|
676
|
+
// The same answer for a secret that is gone and one this agent was never passed.
|
|
677
|
+
if (peer && !grantFor(agent, name, "use", { task: null }))
|
|
678
|
+
return {
|
|
679
|
+
ok: false,
|
|
680
|
+
ended: true,
|
|
681
|
+
error: `${name} is no longer passed to you.`,
|
|
682
|
+
};
|
|
389
683
|
if (!secret) {
|
|
390
684
|
ask(agent, name, "missing", target.host, runId);
|
|
391
685
|
return {
|
|
@@ -401,15 +695,19 @@ export function createVault({
|
|
|
401
695
|
ok: false,
|
|
402
696
|
error: `${name} goes only in a request's ${secretPlaces(name).join(" or ")}, not its ${misplaced === "url" ? "URL" : "body"}: a website can keep what is sent there. Put it in a header (Authorization: Bearer {{secret:${name}}}, for example), or the person can allow it with: npx tryharness vault places ${name} ${[...secretPlaces(name), misplaced].join(",")}`,
|
|
403
697
|
};
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
698
|
+
const grant = grantFor(agent, name, "use", {
|
|
699
|
+
hosted,
|
|
700
|
+
fromElsewhere,
|
|
701
|
+
task: runId,
|
|
702
|
+
});
|
|
703
|
+
if (!grant) {
|
|
407
704
|
ask(agent, name, "allow", target.host, runId);
|
|
408
705
|
return {
|
|
409
706
|
ok: false,
|
|
410
707
|
error: `You may not use ${name} yet. Harness asked the person to allow it; try again once they have.`,
|
|
411
708
|
};
|
|
412
709
|
}
|
|
710
|
+
usedGrants.push(grant);
|
|
413
711
|
values.set(name, secret.value);
|
|
414
712
|
}
|
|
415
713
|
const fill = (text) =>
|
|
@@ -445,6 +743,13 @@ export function createVault({
|
|
|
445
743
|
line.slice(colon + 1).trim()
|
|
446
744
|
);
|
|
447
745
|
}
|
|
746
|
+
// The person sees how much a passed secret has been used, whether or not the website answered well.
|
|
747
|
+
const passedUses = usedGrants.filter((grant) => grant.passedBy);
|
|
748
|
+
for (const grant of passedUses) {
|
|
749
|
+
grant.uses = (grant.uses ?? 0) + 1;
|
|
750
|
+
grant.lastUsedAt = now();
|
|
751
|
+
}
|
|
752
|
+
if (passedUses.length) saveState();
|
|
448
753
|
try {
|
|
449
754
|
let address = firstUrl;
|
|
450
755
|
let verb = method;
|
|
@@ -749,6 +1054,49 @@ export function createVault({
|
|
|
749
1054
|
});
|
|
750
1055
|
};
|
|
751
1056
|
|
|
1057
|
+
// The person's one OK for this secret and this person's agents; the agent that asked is passed it straight away.
|
|
1058
|
+
const allowPass = async (asked) => {
|
|
1059
|
+
const settle = () => {
|
|
1060
|
+
state.requests = state.requests.filter((entry) => entry !== asked);
|
|
1061
|
+
saveState();
|
|
1062
|
+
onRequest(asked.runId ?? null);
|
|
1063
|
+
};
|
|
1064
|
+
const source = state.grants.find(
|
|
1065
|
+
(grant) =>
|
|
1066
|
+
grant.agent === asked.agent &&
|
|
1067
|
+
grant.secret === asked.secret &&
|
|
1068
|
+
grant.mode === "use" &&
|
|
1069
|
+
live(grant)
|
|
1070
|
+
);
|
|
1071
|
+
if (!vault.secrets[asked.secret] || !source || !workOpen(asked.work)) {
|
|
1072
|
+
settle();
|
|
1073
|
+
return {
|
|
1074
|
+
ok: false,
|
|
1075
|
+
error: `${asked.agent} can no longer pass ${asked.secret}: its permission or its work has ended.`,
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
state.peopleAllowed.push({
|
|
1079
|
+
secret: asked.secret,
|
|
1080
|
+
person: personOf(asked.to),
|
|
1081
|
+
});
|
|
1082
|
+
const grant = makePassedGrant({
|
|
1083
|
+
to: asked.to,
|
|
1084
|
+
secret: asked.secret,
|
|
1085
|
+
by: asked.agent,
|
|
1086
|
+
source,
|
|
1087
|
+
work: asked.work,
|
|
1088
|
+
});
|
|
1089
|
+
settle();
|
|
1090
|
+
tellPassed(grant);
|
|
1091
|
+
if (asked.runId)
|
|
1092
|
+
continueRun(
|
|
1093
|
+
asked.runId,
|
|
1094
|
+
`${asked.to} may use ${asked.secret} now. Carry on.`,
|
|
1095
|
+
asked.at
|
|
1096
|
+
);
|
|
1097
|
+
return { ok: true, grant: publicGrant(grant) };
|
|
1098
|
+
};
|
|
1099
|
+
|
|
752
1100
|
// ---- Commands ----
|
|
753
1101
|
const ownerCommands = {
|
|
754
1102
|
"board.vault.save": async (request) => {
|
|
@@ -821,7 +1169,11 @@ export function createVault({
|
|
|
821
1169
|
vault.harness.removed.push(name);
|
|
822
1170
|
delete vault.secrets[name];
|
|
823
1171
|
delete state.policies[name];
|
|
1172
|
+
tellEnded(state.grants.filter((grant) => grant.secret === name));
|
|
824
1173
|
state.grants = state.grants.filter((grant) => grant.secret !== name);
|
|
1174
|
+
state.peopleAllowed = state.peopleAllowed.filter(
|
|
1175
|
+
(entry) => entry.secret !== name
|
|
1176
|
+
);
|
|
825
1177
|
saveState();
|
|
826
1178
|
await persist();
|
|
827
1179
|
changed();
|
|
@@ -883,7 +1235,7 @@ export function createVault({
|
|
|
883
1235
|
);
|
|
884
1236
|
state.grants.push(grant);
|
|
885
1237
|
const answered = state.requests.filter(
|
|
886
|
-
(entry) => entry.agent === agent && entry.secret === secret
|
|
1238
|
+
(entry) => entry.agent === agent && entry.secret === secret && !entry.to
|
|
887
1239
|
);
|
|
888
1240
|
state.requests = state.requests.filter(
|
|
889
1241
|
(entry) => !answered.includes(entry)
|
|
@@ -893,12 +1245,27 @@ export function createVault({
|
|
|
893
1245
|
return { ok: true, grant: publicGrant(grant) };
|
|
894
1246
|
},
|
|
895
1247
|
"board.vault.revoke": async (request) => {
|
|
896
|
-
const
|
|
897
|
-
|
|
1248
|
+
const removed = state.grants.find((grant) => grant.id === request.id);
|
|
1249
|
+
if (!removed) return { ok: false, error: "No such permission." };
|
|
1250
|
+
// What was passed on from this grant ends with it. Removing another person's agent's grant takes back the OK for
|
|
1251
|
+
// that person too: passing it to them again asks again.
|
|
1252
|
+
const liveBefore = state.grants.filter(live);
|
|
1253
|
+
state.grants = state.grants.filter((grant) => grant !== removed);
|
|
1254
|
+
const ended = liveBefore.filter(
|
|
1255
|
+
(grant) => grant === removed || !live(grant)
|
|
1256
|
+
);
|
|
1257
|
+
state.grants = state.grants.filter((grant) => !ended.includes(grant));
|
|
1258
|
+
for (const grant of ended.filter((entry) => personOf(entry.agent)))
|
|
1259
|
+
state.peopleAllowed = state.peopleAllowed.filter(
|
|
1260
|
+
(entry) =>
|
|
1261
|
+
!(
|
|
1262
|
+
entry.secret === grant.secret &&
|
|
1263
|
+
entry.person === personOf(grant.agent)
|
|
1264
|
+
)
|
|
1265
|
+
);
|
|
898
1266
|
saveState();
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
: { ok: true };
|
|
1267
|
+
tellEnded(ended);
|
|
1268
|
+
return { ok: true };
|
|
902
1269
|
},
|
|
903
1270
|
"board.vault.dismiss": async (request) => {
|
|
904
1271
|
const settled = state.requests.find((entry) => entry.id === request.id);
|
|
@@ -915,6 +1282,7 @@ export function createVault({
|
|
|
915
1282
|
const asked = state.requests.find((entry) => entry.id === request.id);
|
|
916
1283
|
if (!asked)
|
|
917
1284
|
return { ok: false, error: "That request is already settled." };
|
|
1285
|
+
if (asked.why === "pass") return allowPass(asked);
|
|
918
1286
|
// The card says which website: a request that changed since is not the one the person allowed.
|
|
919
1287
|
if (
|
|
920
1288
|
typeof request.host === "string" &&
|
|
@@ -1123,13 +1491,14 @@ export function createVault({
|
|
|
1123
1491
|
},
|
|
1124
1492
|
};
|
|
1125
1493
|
|
|
1126
|
-
const list = (agent, { owner, hosted, fromElsewhere }) => {
|
|
1494
|
+
const list = (agent, { owner, hosted, fromElsewhere, task }) => {
|
|
1127
1495
|
if (owner)
|
|
1128
1496
|
return {
|
|
1129
1497
|
ok: true,
|
|
1130
1498
|
secrets: Object.entries(vault.secrets).map(publicSecret),
|
|
1131
1499
|
grants: state.grants.filter(live).map(publicGrant),
|
|
1132
1500
|
requests: state.requests,
|
|
1501
|
+
received: state.received,
|
|
1133
1502
|
shares: state.shares.filter(
|
|
1134
1503
|
(share) => Date.parse(share.expiresAt) > Date.now()
|
|
1135
1504
|
),
|
|
@@ -1142,21 +1511,92 @@ export function createVault({
|
|
|
1142
1511
|
message: state.backup.message ?? null,
|
|
1143
1512
|
},
|
|
1144
1513
|
};
|
|
1145
|
-
// An agent sees what it may use, and where.
|
|
1514
|
+
// An agent sees what it may use, and where. A run's own grants count: `task` is the run it is in.
|
|
1146
1515
|
return {
|
|
1147
1516
|
ok: true,
|
|
1148
|
-
secrets:
|
|
1149
|
-
.
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
name
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1517
|
+
secrets: [
|
|
1518
|
+
...Object.keys(vault.secrets)
|
|
1519
|
+
.filter((name) =>
|
|
1520
|
+
grantFor(agent, name, "use", { hosted, fromElsewhere, task })
|
|
1521
|
+
)
|
|
1522
|
+
.map((name) => ({
|
|
1523
|
+
name,
|
|
1524
|
+
hosts: hostsOf(name),
|
|
1525
|
+
places: secretPlaces(name),
|
|
1526
|
+
})),
|
|
1527
|
+
...state.received
|
|
1528
|
+
.filter((entry) => entry.agent === agent)
|
|
1529
|
+
.map((entry) => ({
|
|
1530
|
+
name: `${entry.from}/${entry.secret}`,
|
|
1531
|
+
hosts: entry.hosts,
|
|
1532
|
+
places: entry.places,
|
|
1533
|
+
from: entry.from,
|
|
1534
|
+
})),
|
|
1535
|
+
],
|
|
1157
1536
|
};
|
|
1158
1537
|
};
|
|
1159
1538
|
|
|
1539
|
+
// ---- Another person's computer (vaultPeers.mjs). `handle` comes from the seal on the thread, never from its words. ----
|
|
1540
|
+
const serveAnotherPerson = async (handle, agentName, request, { signal }) => {
|
|
1541
|
+
await ready;
|
|
1542
|
+
const agent = `${handle}/${agentName}`;
|
|
1543
|
+
if (!AGENT_NAME.test(agent) || agentName.includes("/"))
|
|
1544
|
+
return { ok: false, ended: true, error: "That is not an agent's name." };
|
|
1545
|
+
return sendWithSecrets(
|
|
1546
|
+
{
|
|
1547
|
+
url: request?.url,
|
|
1548
|
+
method: request?.method,
|
|
1549
|
+
headers: request?.headers,
|
|
1550
|
+
body: request?.body,
|
|
1551
|
+
},
|
|
1552
|
+
agent,
|
|
1553
|
+
{ hosted: false, fromElsewhere: false, from: null, signal, peer: true }
|
|
1554
|
+
);
|
|
1555
|
+
};
|
|
1556
|
+
const passedHere = async (handle, event) => {
|
|
1557
|
+
await ready;
|
|
1558
|
+
const secret = String(event?.secret ?? "");
|
|
1559
|
+
const agent = String(event?.agent ?? "");
|
|
1560
|
+
if (!NAME.test(secret) || !AGENT_NAME.test(agent) || agent.includes("/"))
|
|
1561
|
+
return;
|
|
1562
|
+
const fromThem = state.received.filter((entry) => entry.from === handle);
|
|
1563
|
+
const already = fromThem.find(
|
|
1564
|
+
(entry) => entry.secret === secret && entry.agent === agent
|
|
1565
|
+
);
|
|
1566
|
+
if (!already && fromThem.length >= MAX_RECEIVED_FROM_ONE_PERSON) {
|
|
1567
|
+
log(`vault: more passed from ${handle} than are kept; one was refused`);
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
const fields = {
|
|
1571
|
+
from: handle,
|
|
1572
|
+
secret,
|
|
1573
|
+
agent,
|
|
1574
|
+
hosts: (Array.isArray(event.hosts) ? event.hosts : [])
|
|
1575
|
+
.map(String)
|
|
1576
|
+
.filter((host) => HOST.test(host)),
|
|
1577
|
+
places: placesOf(event.places),
|
|
1578
|
+
at: now(),
|
|
1579
|
+
};
|
|
1580
|
+
if (already) Object.assign(already, fields);
|
|
1581
|
+
else {
|
|
1582
|
+
state.received.push(fields);
|
|
1583
|
+
notify(`${handle} passed ${secret} to your ${nameOf(agent)}.`);
|
|
1584
|
+
}
|
|
1585
|
+
saveState();
|
|
1586
|
+
};
|
|
1587
|
+
const endedHere = async (handle, event) => {
|
|
1588
|
+
await ready;
|
|
1589
|
+
state.received = state.received.filter(
|
|
1590
|
+
(entry) =>
|
|
1591
|
+
!(
|
|
1592
|
+
entry.from === handle &&
|
|
1593
|
+
entry.secret === String(event?.secret ?? "") &&
|
|
1594
|
+
entry.agent === String(event?.agent ?? "")
|
|
1595
|
+
)
|
|
1596
|
+
);
|
|
1597
|
+
saveState();
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1160
1600
|
/**
|
|
1161
1601
|
* A board.vault.* call. `machine` is the computer it came from when not this one; the person's own changes are
|
|
1162
1602
|
* made here only, by the person (not an agent, not Harness's servers, not another computer).
|
|
@@ -1168,7 +1608,14 @@ export function createVault({
|
|
|
1168
1608
|
const owner = agent === "user" && !hosted && !fromElsewhere;
|
|
1169
1609
|
const name = String(request.command ?? "");
|
|
1170
1610
|
if (name === "board.vault.list")
|
|
1171
|
-
return list(agent, {
|
|
1611
|
+
return list(agent, {
|
|
1612
|
+
owner,
|
|
1613
|
+
hosted,
|
|
1614
|
+
fromElsewhere,
|
|
1615
|
+
task: owner ? null : runOf(agent, from, request.runId),
|
|
1616
|
+
});
|
|
1617
|
+
if (name === "board.vault.pass")
|
|
1618
|
+
return passSecret(request, agent, { owner, hosted, fromElsewhere, from });
|
|
1172
1619
|
if (name === "board.vault.use")
|
|
1173
1620
|
return sendWithSecrets(request, agent, {
|
|
1174
1621
|
hosted,
|
|
@@ -1222,12 +1669,80 @@ export function createVault({
|
|
|
1222
1669
|
return walk(value);
|
|
1223
1670
|
};
|
|
1224
1671
|
|
|
1672
|
+
/** The vault as the board's backup carries it (boardBackup.mjs), sealed there with the person's shared keys. */
|
|
1673
|
+
const backupCopy = async () => {
|
|
1674
|
+
await ready;
|
|
1675
|
+
return Object.keys(vault.secrets).length
|
|
1676
|
+
? JSON.parse(JSON.stringify(vault))
|
|
1677
|
+
: null;
|
|
1678
|
+
};
|
|
1679
|
+
|
|
1680
|
+
/** A backup's vault, brought in only where this computer's is empty: a vault kept here is never replaced. */
|
|
1681
|
+
const restoreCopy = async (copy) => {
|
|
1682
|
+
await ready;
|
|
1683
|
+
if (!copy?.secrets || Object.keys(vault.secrets).length) return false;
|
|
1684
|
+
vault = copy;
|
|
1685
|
+
vault.harness ??= {};
|
|
1686
|
+
vault.harness.removed ??= [];
|
|
1687
|
+
for (const [name, secret] of Object.entries(vault.secrets))
|
|
1688
|
+
state.policies[name] ??= {
|
|
1689
|
+
hosts: secret.allowed_hosts ?? [],
|
|
1690
|
+
places: placesNeededFor(secret.allowed_hosts),
|
|
1691
|
+
};
|
|
1692
|
+
saveState();
|
|
1693
|
+
await persist();
|
|
1694
|
+
log(
|
|
1695
|
+
`vault: brought back ${Object.keys(vault.secrets).length} secrets from the board's backup`
|
|
1696
|
+
);
|
|
1697
|
+
return true;
|
|
1698
|
+
};
|
|
1699
|
+
|
|
1700
|
+
// The keys places issue the swarm when it joins (places.mjs): each kept here as a secret for that place's own site,
|
|
1701
|
+
// which the person sees in their vault. Only the places module sends one, and only to its place.
|
|
1702
|
+
const placeKeyName = (origin) => `place/${new URL(origin).host}`;
|
|
1703
|
+
const placeKeys = {
|
|
1704
|
+
save: async (origin, key) => {
|
|
1705
|
+
await ready;
|
|
1706
|
+
return ownerCommands["board.vault.save"]({
|
|
1707
|
+
name: placeKeyName(origin),
|
|
1708
|
+
value: key,
|
|
1709
|
+
hosts: [new URL(origin).host],
|
|
1710
|
+
places: ["header"],
|
|
1711
|
+
});
|
|
1712
|
+
},
|
|
1713
|
+
/** The header a request to the place carries, or null when the swarm holds no key there. */
|
|
1714
|
+
header: async (origin) => {
|
|
1715
|
+
await ready;
|
|
1716
|
+
const value = vault.secrets[placeKeyName(origin)]?.value;
|
|
1717
|
+
return value ? ["authorization", `Bearer ${value}`] : null;
|
|
1718
|
+
},
|
|
1719
|
+
/** Whether `text` carries the place's key. */
|
|
1720
|
+
holds: async (origin, text) => {
|
|
1721
|
+
await ready;
|
|
1722
|
+
const value = vault.secrets[placeKeyName(origin)]?.value;
|
|
1723
|
+
return Boolean(value) && String(text).includes(value);
|
|
1724
|
+
},
|
|
1725
|
+
forget: async (origin) => {
|
|
1726
|
+
await ready;
|
|
1727
|
+
if (!vault.secrets[placeKeyName(origin)]) return { ok: true };
|
|
1728
|
+
return ownerCommands["board.vault.remove"]({
|
|
1729
|
+
name: placeKeyName(origin),
|
|
1730
|
+
});
|
|
1731
|
+
},
|
|
1732
|
+
};
|
|
1733
|
+
|
|
1225
1734
|
return {
|
|
1735
|
+
backupCopy,
|
|
1736
|
+
restoreCopy,
|
|
1226
1737
|
ready,
|
|
1227
1738
|
command,
|
|
1739
|
+
placeKeys,
|
|
1228
1740
|
envFor,
|
|
1229
1741
|
needs,
|
|
1230
1742
|
scrubDeep,
|
|
1743
|
+
serveAnotherPerson,
|
|
1744
|
+
passedHere,
|
|
1745
|
+
endedHere,
|
|
1231
1746
|
close: async () => {
|
|
1232
1747
|
await writing.catch(() => {});
|
|
1233
1748
|
},
|