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/sealedThreads.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { aboutOf, claimHolds } from "./agentClaims.mjs";
|
|
1
2
|
import fs from "node:fs";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { mimeFor } from "./files.mjs";
|
|
4
4
|
import {
|
|
5
5
|
fingerprint,
|
|
@@ -11,26 +11,28 @@ import {
|
|
|
11
11
|
sealBytes,
|
|
12
12
|
} from "./sealed.mjs";
|
|
13
13
|
import { MAX_FILE_BYTES } from "./boardFiles.mjs";
|
|
14
|
-
import { relayRefusal } from "./relayLimits.mjs";
|
|
14
|
+
import { createPerMinute, PER_MINUTE, relayRefusal } from "./relayLimits.mjs";
|
|
15
15
|
|
|
16
|
-
// What may be referenced
|
|
17
|
-
//
|
|
16
|
+
// What may be referenced in a message to a friend. A message is opened only on the two computers, so they alone
|
|
17
|
+
// enforce it; Harness carries nothing it could read (docs/jam-plan.md J2).
|
|
18
18
|
const RELAY_REF_KINDS = new Set(["log", "repro", "link", "file"]);
|
|
19
19
|
|
|
20
20
|
// Marks a thread post this daemon prepared itself; nothing that arrives over the wire can carry it.
|
|
21
21
|
export const OPENED = Symbol("opened");
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* A person's identity key as their friends' computers seal to it: base64url, as every relay key travels (sealed.mjs).
|
|
25
|
+
* Harness and the person's shared keys carry it as standard base64.
|
|
26
|
+
*/
|
|
27
|
+
export const relayPublicKey = (key) =>
|
|
28
|
+
Buffer.from(String(key), "base64").toString("base64url");
|
|
29
|
+
|
|
30
|
+
// "ana/person" is the person whose handle is "ana".
|
|
24
31
|
export const handleOf = (identityName) =>
|
|
25
32
|
String(identityName || "")
|
|
26
33
|
.split("/")[0]
|
|
27
34
|
.toLowerCase();
|
|
28
35
|
|
|
29
|
-
const refusedKinds = (refs) =>
|
|
30
|
-
(Array.isArray(refs) ? refs : [])
|
|
31
|
-
.filter((ref) => !RELAY_REF_KINDS.has(ref?.kind))
|
|
32
|
-
.map((ref) => String(ref?.kind));
|
|
33
|
-
|
|
34
36
|
const crossRefs = (refs) =>
|
|
35
37
|
(Array.isArray(refs) ? refs : [])
|
|
36
38
|
.filter(
|
|
@@ -39,27 +41,41 @@ const crossRefs = (refs) =>
|
|
|
39
41
|
)
|
|
40
42
|
.slice(0, 20);
|
|
41
43
|
|
|
44
|
+
const HANDLE = /^[a-z0-9][a-z0-9-]{2,19}$/;
|
|
45
|
+
|
|
42
46
|
/**
|
|
43
|
-
*
|
|
44
|
-
* Harness
|
|
47
|
+
* Friendships with other people's computers, both ways (docs/jam-plan.md J1, J2). A friendship is a thread between two
|
|
48
|
+
* persons that Harness posts to both computers on accept; each pins the other's key as it takes it. Its messages,
|
|
49
|
+
* files and end go only sealed to that key, from one person to the other: nothing is sent or taken on a thread with
|
|
50
|
+
* an agent (one from before friends), without the other computer's key, or unsealed, and a message whose seal names
|
|
51
|
+
* an agent is refused. Harness relays only ciphertext.
|
|
45
52
|
*
|
|
46
|
-
* `identity()` is
|
|
47
|
-
*
|
|
53
|
+
* `identity()` is the person's identity toward other people (computerDevices.mjs personIdentity): the account key
|
|
54
|
+
* pair every one of their devices holds, with the earlier ones, so what a friend sealed before the keys changed still
|
|
55
|
+
* opens. Null while this computer holds no copy. `follow(handle, keyed)` takes a friend's new keys when their links
|
|
56
|
+
* lead to them from the keys pinned here (daemon.mjs followPeer); false when they do not.
|
|
48
57
|
*/
|
|
49
58
|
export function createSealedThreads({
|
|
50
59
|
store,
|
|
51
60
|
send,
|
|
52
61
|
askHarness,
|
|
53
|
-
connected,
|
|
54
62
|
identity,
|
|
55
|
-
projects,
|
|
56
63
|
notifyBoard,
|
|
57
64
|
notify,
|
|
58
65
|
files,
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
follow = async () => false,
|
|
67
|
+
// This computer's signed claim that it sent the person's words (agentClaims.mjs): every message carries one, and the
|
|
68
|
+
// other computer checks it against the identity it pinned for them.
|
|
69
|
+
claims = null,
|
|
70
|
+
// Reads the person's identity again when this computer holds none yet (it was approved after it connected).
|
|
71
|
+
ensureIdentity = async () => {},
|
|
61
72
|
log,
|
|
62
73
|
}) {
|
|
74
|
+
const perMinute = createPerMinute();
|
|
75
|
+
const tooFast = (handle) =>
|
|
76
|
+
perMinute.take(handle)
|
|
77
|
+
? null
|
|
78
|
+
: `more than ${PER_MINUTE} messages a minute from ${handle}`;
|
|
63
79
|
const threadKey = async (thread) =>
|
|
64
80
|
thread?.peer_key && identity()
|
|
65
81
|
? relayKey(identity().privateKey, thread.peer_key)
|
|
@@ -82,6 +98,18 @@ export function createSealedThreads({
|
|
|
82
98
|
try {
|
|
83
99
|
return await open(key, inward(thread, bound), sealedPart);
|
|
84
100
|
} catch {
|
|
101
|
+
// Sealed to the person's keys before they changed (a device left their list): the earlier keys open it.
|
|
102
|
+
for (const earlier of identity()?.previous ?? []) {
|
|
103
|
+
const opened = await open(
|
|
104
|
+
await relayKey(earlier.privateKey, thread.peer_key),
|
|
105
|
+
relayBound(bound, thread.peer_key, earlier.publicKey),
|
|
106
|
+
sealedPart
|
|
107
|
+
).then(
|
|
108
|
+
(value) => ({ value }),
|
|
109
|
+
() => null
|
|
110
|
+
);
|
|
111
|
+
if (opened) return opened.value;
|
|
112
|
+
}
|
|
85
113
|
const old = await open(key, bound, sealedPart).then(
|
|
86
114
|
() => true,
|
|
87
115
|
() => false
|
|
@@ -93,67 +121,62 @@ export function createSealedThreads({
|
|
|
93
121
|
);
|
|
94
122
|
}
|
|
95
123
|
};
|
|
96
|
-
// The
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
124
|
+
// The friendship a message, file or end goes on: a thread with the other person themselves whose computer's key
|
|
125
|
+
// this one holds. A thread with another person's agent, from before friends, is none.
|
|
126
|
+
const friendship = (taskId) => {
|
|
127
|
+
const thread = store.getThread(String(taskId || ""));
|
|
128
|
+
const [handle, member] = String(thread?.with_agent || "").split("/");
|
|
129
|
+
return thread?.peer_key && HANDLE.test(handle) && member === "person"
|
|
130
|
+
? thread
|
|
131
|
+
: null;
|
|
100
132
|
};
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
133
|
+
// The friendship something arrived on, or the refusal: only a friend's computer, only sealed.
|
|
134
|
+
const arrivedOn = (input, what) => {
|
|
135
|
+
const thread = friendship(input.taskId);
|
|
136
|
+
if (!thread) throw new Error(`a ${what} comes only on a friendship`);
|
|
137
|
+
if (!input.sealed) throw new Error(`a ${what} comes only sealed`);
|
|
138
|
+
// Harness's label beside it names the friend; one naming an agent did not come from a person.
|
|
139
|
+
const label = input.from ?? input.by;
|
|
140
|
+
if (label != null && String(label) !== thread.with_agent)
|
|
141
|
+
throw new Error(`a ${what} names only people`);
|
|
142
|
+
return thread;
|
|
108
143
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
throw new Error(
|
|
115
|
-
`the key Harness gave for ${handle}'s computer is not the one this computer saw before. If they reinstalled Harness, compare fingerprints with them (npx tryharness peers), then: npx tryharness connect ${handle}/<agent> --about <text> --trust-new-key`
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
if (!pinned || pinned.public_key !== publicKey)
|
|
119
|
-
store.pinRelayPeer(handle, publicKey);
|
|
120
|
-
return publicKey;
|
|
144
|
+
// Who sent it, as sealed: the friend themselves, never one of their agents, whatever label Harness carried beside it.
|
|
145
|
+
const sealedSender = (thread, from) => {
|
|
146
|
+
if (String(from || "") !== "person")
|
|
147
|
+
throw new Error("a message comes only from a person, never an agent");
|
|
148
|
+
return thread.with_agent;
|
|
121
149
|
};
|
|
122
150
|
|
|
123
|
-
// A message the person
|
|
124
|
-
//
|
|
151
|
+
// A message the person sent goes to the other computer: over the channel with that
|
|
152
|
+
// person when one is open, else through Harness's mailbox (daemon.mjs sendThreadFrame), each file ahead of the message
|
|
153
|
+
// that names it. Unacknowledged messages go again on reconnect, so a dropped socket never loses a reply.
|
|
125
154
|
const sendMessage = (message) =>
|
|
126
155
|
void (async () => {
|
|
127
|
-
|
|
156
|
+
if (!identity()) await ensureIdentity();
|
|
157
|
+
const thread = friendship(message.task_id);
|
|
158
|
+
if (!thread)
|
|
159
|
+
throw new Error("a message goes only sealed, on a friendship");
|
|
128
160
|
const key = await threadKey(thread);
|
|
129
161
|
const base = {
|
|
130
162
|
type: "thread_message",
|
|
131
163
|
taskId: message.task_id,
|
|
132
164
|
messageId: message.id,
|
|
133
165
|
seq: message.seq,
|
|
134
|
-
to:
|
|
166
|
+
to: thread.with_agent,
|
|
135
167
|
sentAt: message.sent_at,
|
|
136
168
|
};
|
|
137
|
-
// A file never goes readable: a thread without the other computer's key sends the words alone.
|
|
138
|
-
if (!key) {
|
|
139
|
-
send({
|
|
140
|
-
...base,
|
|
141
|
-
text: message.text,
|
|
142
|
-
refs: message.refs.filter((ref) => !ref.file),
|
|
143
|
-
});
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
169
|
// Each file goes ahead of the message that names it, sealed on its own; the message carries its hash.
|
|
147
170
|
for (const ref of message.refs) {
|
|
148
171
|
const file =
|
|
149
172
|
ref.kind === "file" && ref.file ? store.file(ref.file) : null;
|
|
150
173
|
if (!file?.present) continue;
|
|
151
|
-
send({
|
|
174
|
+
await send({
|
|
152
175
|
type: "thread_file",
|
|
153
176
|
taskId: message.task_id,
|
|
154
177
|
messageId: `file:${message.id}:${file.id}`,
|
|
155
178
|
seq: message.seq,
|
|
156
|
-
to:
|
|
179
|
+
to: thread.with_agent,
|
|
157
180
|
sealed: {
|
|
158
181
|
fileId: file.id,
|
|
159
182
|
...(await sealBytes(
|
|
@@ -164,17 +187,19 @@ export function createSealedThreads({
|
|
|
164
187
|
},
|
|
165
188
|
});
|
|
166
189
|
}
|
|
167
|
-
send({
|
|
190
|
+
await send({
|
|
168
191
|
...base,
|
|
169
|
-
text: "",
|
|
170
|
-
refs: [],
|
|
171
192
|
sealed: await sealBound(
|
|
172
193
|
key,
|
|
173
194
|
outward(thread, `message|${message.task_id}|${message.id}`),
|
|
174
195
|
{
|
|
175
196
|
text: message.text,
|
|
176
197
|
refs: message.refs,
|
|
177
|
-
from:
|
|
198
|
+
from: "person",
|
|
199
|
+
claim: await claims?.mint(
|
|
200
|
+
"person",
|
|
201
|
+
aboutOf(String(message.text ?? ""))
|
|
202
|
+
),
|
|
178
203
|
}
|
|
179
204
|
),
|
|
180
205
|
});
|
|
@@ -182,74 +207,30 @@ export function createSealedThreads({
|
|
|
182
207
|
log(`thread message ${message.id} not sent: ${error.message}`)
|
|
183
208
|
);
|
|
184
209
|
|
|
185
|
-
const sendEnd = (taskId,
|
|
210
|
+
const sendEnd = (taskId, outcome) =>
|
|
186
211
|
void (async () => {
|
|
187
|
-
|
|
212
|
+
if (!identity()) await ensureIdentity();
|
|
213
|
+
const thread = friendship(taskId);
|
|
214
|
+
if (!thread) throw new Error("an end goes only sealed, on a friendship");
|
|
188
215
|
const key = await threadKey(thread);
|
|
189
216
|
send({
|
|
190
217
|
type: "thread_end",
|
|
191
218
|
taskId,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
outcome: "",
|
|
196
|
-
sealed: await sealBound(key, outward(thread, `end|${taskId}`), {
|
|
197
|
-
outcome,
|
|
198
|
-
}),
|
|
199
|
-
}
|
|
200
|
-
: { outcome }),
|
|
219
|
+
sealed: await sealBound(key, outward(thread, `end|${taskId}`), {
|
|
220
|
+
outcome,
|
|
221
|
+
}),
|
|
201
222
|
});
|
|
202
223
|
})().catch((error) =>
|
|
203
224
|
log(`thread end ${taskId} not sent: ${error.message}`)
|
|
204
225
|
);
|
|
205
226
|
|
|
206
|
-
// A
|
|
207
|
-
const endGuests = (goal, outcome) => {
|
|
208
|
-
for (const guest of goal.goal.guests) {
|
|
209
|
-
const closed = store.getThread(guest.thread)
|
|
210
|
-
? store.closeThread(guest.thread, outcome)
|
|
211
|
-
: null;
|
|
212
|
-
if (closed?.ok && !closed.already) sendEnd(guest.thread, "user", outcome);
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// A shared project's event on the person thread under it: sealed to the other computer, never readable. Harness
|
|
217
|
-
// acknowledges it once it holds it, and keeps it until the other computer has it.
|
|
218
|
-
const sendProjectEvent = ({ projectId, to, messageId, seq, body }) =>
|
|
219
|
-
void (async () => {
|
|
220
|
-
const thread = store.getThread(projectId);
|
|
221
|
-
const key = await threadKey(thread);
|
|
222
|
-
if (!key)
|
|
223
|
-
throw new Error(
|
|
224
|
-
"the project's thread has no key for the other computer"
|
|
225
|
-
);
|
|
226
|
-
send({
|
|
227
|
-
type: "thread_message",
|
|
228
|
-
taskId: projectId,
|
|
229
|
-
messageId,
|
|
230
|
-
seq,
|
|
231
|
-
to,
|
|
232
|
-
sentAt: new Date().toISOString(),
|
|
233
|
-
text: "",
|
|
234
|
-
refs: [],
|
|
235
|
-
sealed: await sealBound(
|
|
236
|
-
key,
|
|
237
|
-
outward(thread, `message|${projectId}|${messageId}`),
|
|
238
|
-
{ text: "", refs: [], from: memberHere(projectId), project: body }
|
|
239
|
-
),
|
|
240
|
-
});
|
|
241
|
-
})().catch((error) =>
|
|
242
|
-
log(`project event ${messageId} not sent: ${error.message}`)
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
// A file the message names is this computer's own row, matched to the id the other computer gave it; only a sealed
|
|
246
|
-
// thread brings files.
|
|
227
|
+
// A file the message names is this computer's own row, matched to the id the other computer gave it.
|
|
247
228
|
// `sender`: who sent the message, as sealed (sealedSender), never the label Harness carried beside it.
|
|
248
|
-
const ownRefs = (refs,
|
|
229
|
+
const ownRefs = (refs, input, sender) =>
|
|
249
230
|
crossRefs(refs).map((ref) => {
|
|
250
231
|
if (!ref.file) return ref;
|
|
251
232
|
const { file: remoteId, ...named } = ref;
|
|
252
|
-
if (
|
|
233
|
+
if (!/^[0-9a-f]{64}$/.test(String(ref.sha256)))
|
|
253
234
|
return { kind: named.kind, ref: named.ref };
|
|
254
235
|
const expected = store.expectFile({
|
|
255
236
|
taskId: String(input.taskId),
|
|
@@ -278,97 +259,74 @@ export function createSealedThreads({
|
|
|
278
259
|
});
|
|
279
260
|
|
|
280
261
|
const receiveMessage = async (input, respond) => {
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
262
|
+
const thread = arrivedOn(input, "message");
|
|
263
|
+
const handle = handleOf(thread.with_agent);
|
|
264
|
+
const opened = await openInward(
|
|
265
|
+
thread,
|
|
266
|
+
`message|${input.taskId}|${input.messageId}`,
|
|
267
|
+
input.sealed,
|
|
268
|
+
"message"
|
|
269
|
+
);
|
|
270
|
+
const sender = sealedSender(thread, opened.from);
|
|
271
|
+
// Which of their computers sent it, signed by that computer's key, which their identity certified.
|
|
272
|
+
const pinned = store.relayPeer(handle);
|
|
273
|
+
const claimed =
|
|
274
|
+
opened.claim?.agent === "person" &&
|
|
275
|
+
(await claimHolds(opened.claim, {
|
|
276
|
+
identitySigningKeys: [
|
|
277
|
+
pinned?.signing_key,
|
|
278
|
+
...(pinned?.past_signing_keys ?? []),
|
|
279
|
+
].filter(Boolean),
|
|
280
|
+
about: aboutOf(String(opened.text ?? "")),
|
|
281
|
+
}));
|
|
282
|
+
if (!claimed)
|
|
283
|
+
throw new Error(
|
|
284
|
+
"the message was refused: it comes without the claim of the computer that sent it"
|
|
296
285
|
);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
String(input.taskId),
|
|
307
|
-
opened.project,
|
|
308
|
-
String(input.messageId)
|
|
309
|
-
)
|
|
310
|
-
: { ok: false, error: "the daemon is still starting" };
|
|
311
|
-
respond(acknowledged(kept, input));
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
286
|
+
// A use of a passed secret rides a jam now, never a friendship (docs/jam-plan.md J4.8: "agents arent in dms").
|
|
287
|
+
if (opened.vault) {
|
|
288
|
+
respond(
|
|
289
|
+
acknowledged(
|
|
290
|
+
{ ok: false, error: "a secret is used only inside a jam" },
|
|
291
|
+
input
|
|
292
|
+
)
|
|
293
|
+
);
|
|
294
|
+
return;
|
|
314
295
|
}
|
|
296
|
+
const text = String(opened.text || "").slice(0, 50_000);
|
|
315
297
|
const known = store.db.all("select 1 from board_messages where id = ?", [
|
|
316
298
|
String(input.messageId || ""),
|
|
317
299
|
]).length;
|
|
318
|
-
const over =
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
: null;
|
|
300
|
+
const over = known
|
|
301
|
+
? null
|
|
302
|
+
: (relayRefusal(store.db, {
|
|
303
|
+
taskId: String(input.taskId),
|
|
304
|
+
handle,
|
|
305
|
+
text,
|
|
306
|
+
}) ?? tooFast(handle));
|
|
326
307
|
if (over) throw new Error(`the message was refused: ${over}`);
|
|
327
308
|
const received = store.receiveMessage({
|
|
328
309
|
id: String(input.messageId || ""),
|
|
329
310
|
taskId: String(input.taskId || ""),
|
|
330
311
|
seq: input.seq,
|
|
331
312
|
sender,
|
|
332
|
-
text
|
|
333
|
-
refs: ownRefs(
|
|
313
|
+
text,
|
|
314
|
+
refs: ownRefs(
|
|
315
|
+
Array.isArray(opened.refs) ? opened.refs : [],
|
|
316
|
+
input,
|
|
317
|
+
sender
|
|
318
|
+
),
|
|
334
319
|
sentAt: input.sentAt,
|
|
335
320
|
});
|
|
336
321
|
respond(acknowledged(received, input));
|
|
337
322
|
if (!received.ok || received.duplicate) return;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
// A guest's message lands in its goal's room as a stranger's words; it wakes the facilitator, never a run here.
|
|
341
|
-
const guestGoal = store.guestGoalFor(String(input.taskId));
|
|
342
|
-
if (guestGoal && store.getTask(guestGoal)?.status === "open") {
|
|
343
|
-
const post = store.roomPost({
|
|
344
|
-
goalId: guestGoal,
|
|
345
|
-
author: sender,
|
|
346
|
-
kind: "guest",
|
|
347
|
-
text: words.text.slice(0, 20_000),
|
|
348
|
-
});
|
|
349
|
-
// A stranger's words are read by the guard like any words from outside; a brief marks what it flagged.
|
|
350
|
-
void guard(post.text)
|
|
351
|
-
.then((reading) => {
|
|
352
|
-
if (reading?.verdict === "flag" || reading?.verdict === "hold")
|
|
353
|
-
store.meta(`flagged:${post.id}`, String(reading.score));
|
|
354
|
-
})
|
|
355
|
-
.catch(() => undefined);
|
|
356
|
-
notifyBoard(store.getTask(guestGoal));
|
|
357
|
-
}
|
|
358
|
-
notify(
|
|
359
|
-
sender.endsWith("/person")
|
|
360
|
-
? `${handleOf(sender)} wrote to you: ${words.text.slice(0, 100)}`
|
|
361
|
-
: `${sender} replied on: ${String(task?.objective || "").slice(0, 80)}`
|
|
362
|
-
);
|
|
323
|
+
notifyBoard(store.getTask(String(input.taskId)));
|
|
324
|
+
notify(`${handle} wrote to you: ${text.slice(0, 100)}`);
|
|
363
325
|
};
|
|
364
326
|
|
|
365
327
|
const receiveFile = async (input, respond) => {
|
|
366
328
|
const taskId = String(input.taskId || "");
|
|
367
|
-
const thread =
|
|
368
|
-
if (!thread?.peer_key || !input.sealed)
|
|
369
|
-
throw new Error(
|
|
370
|
-
"files come only sealed, on a thread with the other computer's key"
|
|
371
|
-
);
|
|
329
|
+
const thread = arrivedOn(input, "file");
|
|
372
330
|
const remoteId = String(input.sealed.fileId || "").slice(0, 128);
|
|
373
331
|
const bytes = await openInward(
|
|
374
332
|
thread,
|
|
@@ -385,37 +343,32 @@ export function createSealedThreads({
|
|
|
385
343
|
).length;
|
|
386
344
|
const over = arrived
|
|
387
345
|
? null
|
|
388
|
-
: relayRefusal(store.db, {
|
|
346
|
+
: (relayRefusal(store.db, {
|
|
389
347
|
taskId,
|
|
390
348
|
handle: handleOf(thread.with_agent),
|
|
391
349
|
bytes: bytes.length,
|
|
392
|
-
});
|
|
350
|
+
}) ?? tooFast(handleOf(thread.with_agent)));
|
|
393
351
|
if (over) throw new Error(`the file was refused: ${over}`);
|
|
394
352
|
const received = store.receiveFile({
|
|
395
353
|
taskId,
|
|
396
354
|
remoteId,
|
|
397
355
|
sha256: files.keepBlob(bytes),
|
|
398
356
|
bytes: bytes.length,
|
|
399
|
-
author:
|
|
357
|
+
author: thread.with_agent,
|
|
400
358
|
});
|
|
401
359
|
respond(acknowledged(received, input));
|
|
402
360
|
if (received.ok && !received.duplicate) notifyBoard(store.getTask(taskId));
|
|
403
361
|
};
|
|
404
362
|
|
|
405
363
|
const receiveEnd = async (input, respond) => {
|
|
406
|
-
const thread =
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
input.sealed,
|
|
415
|
-
"ending"
|
|
416
|
-
);
|
|
417
|
-
outcome = String(opened.outcome || "");
|
|
418
|
-
}
|
|
364
|
+
const thread = arrivedOn(input, "end");
|
|
365
|
+
const opened = await openInward(
|
|
366
|
+
thread,
|
|
367
|
+
`end|${input.taskId}`,
|
|
368
|
+
input.sealed,
|
|
369
|
+
"ending"
|
|
370
|
+
);
|
|
371
|
+
const outcome = String(opened.outcome || "");
|
|
419
372
|
const closed = store.closeThread(
|
|
420
373
|
String(input.taskId || ""),
|
|
421
374
|
outcome.slice(0, 20_000) || null
|
|
@@ -425,10 +378,9 @@ export function createSealedThreads({
|
|
|
425
378
|
result: closed.ok ? { closed: input.taskId } : null,
|
|
426
379
|
});
|
|
427
380
|
if (!closed.ok || closed.already) return;
|
|
428
|
-
projects()?.channelEnded(String(input.taskId || ""));
|
|
429
381
|
notifyBoard(closed.task);
|
|
430
382
|
notify(
|
|
431
|
-
`${
|
|
383
|
+
`${thread.with_agent} ended the thread on: ${String(closed.task?.objective || "").slice(0, 80)}`
|
|
432
384
|
);
|
|
433
385
|
};
|
|
434
386
|
|
|
@@ -443,206 +395,64 @@ export function createSealedThreads({
|
|
|
443
395
|
* the acknowledgement Harness relays back, before the board moves; a failure is answered as one.
|
|
444
396
|
*/
|
|
445
397
|
const receive = (type, input, respond) =>
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
// A request to another person's agent. Their computer's key comes from Harness and is pinned here; the request, its
|
|
451
|
-
// brief and its references go sealed to it, and this computer keeps its own copy for the thread.
|
|
452
|
-
const request = async ({
|
|
453
|
-
to,
|
|
454
|
-
fromAgent,
|
|
455
|
-
about,
|
|
456
|
-
brief,
|
|
457
|
-
refs,
|
|
458
|
-
trustNewKey = false,
|
|
459
|
-
// A shared project's offer (projects.mjs): it goes only sealed, to a computer that has a key.
|
|
460
|
-
project = null,
|
|
461
|
-
// The person agreed to a first contact Harness can read, with a computer that has no key (security audit S8).
|
|
462
|
-
readable = false,
|
|
463
|
-
}) => {
|
|
464
|
-
if (!connected()) throw new Error("the daemon is not connected to Harness");
|
|
465
|
-
const target = String(to || "").toLowerCase();
|
|
466
|
-
const subject = String(about || "").slice(0, 500);
|
|
467
|
-
const text = String(brief || "").slice(0, 200_000);
|
|
468
|
-
if (!subject.trim()) throw new Error("about is required");
|
|
469
|
-
const refused = refusedKinds(refs);
|
|
470
|
-
if (refused.length)
|
|
471
|
-
throw new Error(
|
|
472
|
-
`references of kind ${refused.join(", ")} cannot cross accounts`
|
|
473
|
-
);
|
|
474
|
-
const attached = crossRefs(refs);
|
|
475
|
-
const keyed = await askHarness("relay_key", { to: target });
|
|
476
|
-
if (!keyed.ok)
|
|
477
|
-
throw new Error(keyed.error || "Harness could not find that agent");
|
|
478
|
-
let targetKey = null;
|
|
479
|
-
let input = {
|
|
480
|
-
to: target,
|
|
481
|
-
fromAgent: String(fromAgent || ""),
|
|
482
|
-
about: subject,
|
|
483
|
-
brief: text,
|
|
484
|
-
refs: attached,
|
|
485
|
-
};
|
|
486
|
-
// Harness cannot quietly turn a sealed contact into a readable one: a computer that had a key keeps needing one.
|
|
487
|
-
if (
|
|
488
|
-
typeof keyed.publicKey !== "string" &&
|
|
489
|
-
store.relayPeer(handleOf(target))
|
|
490
|
-
)
|
|
491
|
-
throw new Error(
|
|
492
|
-
`Harness gave no key for ${handleOf(target)}'s computer, which had one before; the request was not sent`
|
|
493
|
-
);
|
|
494
|
-
if (project && typeof keyed.publicKey !== "string")
|
|
495
|
-
throw new Error(
|
|
496
|
-
`${handleOf(target)}'s computer can't take a sealed project yet. Ask them to update Harness.`
|
|
497
|
-
);
|
|
498
|
-
// No key from Harness for someone new: Harness could be holding it back to read the contact, so it goes readable
|
|
499
|
-
// only once the person says so.
|
|
500
|
-
if (typeof keyed.publicKey !== "string" && !readable)
|
|
501
|
-
throw new Error(
|
|
502
|
-
`Harness gave no key for ${handleOf(target)}'s computer (a Harness from before sealed threads, or one that has not connected), so Harness could read this. Ask them to update Harness, or send it readable only if you agree (tryharness connect --readable).`
|
|
503
|
-
);
|
|
504
|
-
if (typeof keyed.publicKey === "string") {
|
|
505
|
-
targetKey = peerKeyFor(handleOf(target), keyed.publicKey, trustNewKey);
|
|
506
|
-
const sealId = randomUUID();
|
|
507
|
-
const sealed = await sealBound(
|
|
508
|
-
await relayKey(identity().privateKey, targetKey),
|
|
509
|
-
`request|${sealId}`,
|
|
510
|
-
{
|
|
511
|
-
about: subject,
|
|
512
|
-
brief: text,
|
|
513
|
-
refs: attached,
|
|
514
|
-
...(project ? { project } : {}),
|
|
515
|
-
}
|
|
516
|
-
);
|
|
517
|
-
input = {
|
|
518
|
-
to: target,
|
|
519
|
-
fromAgent: String(fromAgent || ""),
|
|
520
|
-
about: "",
|
|
521
|
-
brief: "",
|
|
522
|
-
refs: [],
|
|
523
|
-
sealed: {
|
|
524
|
-
v: 1,
|
|
525
|
-
sealId,
|
|
526
|
-
key: identity().publicKey,
|
|
527
|
-
targetKey,
|
|
528
|
-
...sealed,
|
|
529
|
-
},
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
// No key: their computer runs a Harness from before sealed threads, and the request goes readable by Harness, as
|
|
533
|
-
// it says.
|
|
534
|
-
const response = await askHarness("relay_request", input);
|
|
535
|
-
if (!response.ok)
|
|
536
|
-
throw new Error(response.error || "the request was refused");
|
|
537
|
-
if (response.threadId)
|
|
538
|
-
store.meta(
|
|
539
|
-
`relay_pending:${response.threadId}`,
|
|
540
|
-
JSON.stringify({
|
|
541
|
-
about: subject,
|
|
542
|
-
brief: text,
|
|
543
|
-
refs: attached,
|
|
544
|
-
targetKey,
|
|
545
|
-
})
|
|
546
|
-
);
|
|
547
|
-
return {
|
|
548
|
-
...response,
|
|
549
|
-
sealed: Boolean(targetKey),
|
|
550
|
-
...(targetKey ? { fingerprint: await fingerprint(targetKey) } : {}),
|
|
551
|
-
};
|
|
552
|
-
};
|
|
398
|
+
(identity() ? Promise.resolve() : ensureIdentity())
|
|
399
|
+
.then(() => RECEIVERS[type](input || {}, respond))
|
|
400
|
+
.catch((error) => respond({ ok: false, error: error.message }));
|
|
553
401
|
|
|
554
|
-
// A
|
|
555
|
-
// the
|
|
402
|
+
// A friendship Harness posts on accept, to both computers. Each takes the other's key from Harness and pins it. With
|
|
403
|
+
// no key yet the friendship is not taken here, so nothing can be sent; Harness posts it again on the next
|
|
404
|
+
// connection. A key other than the one pinned before is L5's changed key: the friendship keeps the pinned key and
|
|
405
|
+
// waits, sending and taking nothing, until the person checks the new one (npx tryharness peers trust).
|
|
556
406
|
const openPost = async (post) => {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
if (thread.role === "asker") {
|
|
560
|
-
const pending = JSON.parse(store.meta(`relay_pending:${id}`) || "null");
|
|
561
|
-
if (!pending)
|
|
562
|
-
throw new Error("this computer did not ask for that thread");
|
|
563
|
-
if ((thread.sealed?.targetKey ?? null) !== (pending.targetKey ?? null))
|
|
564
|
-
throw new Error(
|
|
565
|
-
"the thread names another key than the one this computer sealed its request to"
|
|
566
|
-
);
|
|
567
|
-
return {
|
|
568
|
-
...post,
|
|
569
|
-
objective: pending.about,
|
|
570
|
-
brief: pending.brief,
|
|
571
|
-
contextRefs: pending.refs,
|
|
572
|
-
thread: {
|
|
573
|
-
with: thread.with,
|
|
574
|
-
role: "asker",
|
|
575
|
-
peerKey: pending.targetKey,
|
|
576
|
-
[OPENED]: true,
|
|
577
|
-
},
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
const sealed = thread.sealed;
|
|
581
|
-
// The key the person was shown when the request was listed is the one accepting pins (S8): Harness can't swap in
|
|
582
|
-
// another between the two.
|
|
583
|
-
const shown = store.meta(`relay-shown-key:${id}`);
|
|
584
|
-
if (shown && shown !== String(sealed.key || ""))
|
|
407
|
+
if (!identity()) await ensureIdentity();
|
|
408
|
+
if (!identity())
|
|
585
409
|
throw new Error(
|
|
586
|
-
"
|
|
587
|
-
);
|
|
588
|
-
const peer = peerKeyFor(handleOf(thread.with), String(sealed.key || ""));
|
|
589
|
-
let opened;
|
|
590
|
-
try {
|
|
591
|
-
opened = await openBound(
|
|
592
|
-
await relayKey(identity().privateKey, peer),
|
|
593
|
-
`request|${sealed.sealId}`,
|
|
594
|
-
sealed
|
|
410
|
+
"this computer does not hold your keys yet; the friendship waits until one of your devices approves it"
|
|
595
411
|
);
|
|
596
|
-
|
|
412
|
+
const thread = post.thread;
|
|
413
|
+
const handle = handleOf(thread.with);
|
|
414
|
+
const member = String(thread.with || "").split("/")[1];
|
|
415
|
+
if (!HANDLE.test(handle) || member !== "person")
|
|
416
|
+
throw new Error("a thread is only ever between two people");
|
|
417
|
+
let pinned = store.relayPeer(handle);
|
|
418
|
+
const keyed = await askHarness("relay_key", {
|
|
419
|
+
to: handle,
|
|
420
|
+
...(pinned?.signing_key ? { since: pinned.signing_key } : {}),
|
|
421
|
+
});
|
|
422
|
+
if (!keyed.ok || typeof keyed.publicKey !== "string")
|
|
597
423
|
throw new Error(
|
|
598
|
-
|
|
424
|
+
`Harness has no keys for ${handle} yet; the friendship waits until one of their devices makes them`
|
|
599
425
|
);
|
|
426
|
+
const publicKey = relayPublicKey(keyed.publicKey);
|
|
427
|
+
// Its signing key is pinned with it: what checks that a jam's event is theirs (jamKey.mjs).
|
|
428
|
+
if (!pinned)
|
|
429
|
+
store.pinRelayPeer(handle, publicKey, keyed.signingKey ?? null);
|
|
430
|
+
else if (pinned.public_key !== publicKey) {
|
|
431
|
+
// Their keys changed: followed when the links lead from the keys pinned here, else the friendship waits.
|
|
432
|
+
if (await follow(handle, keyed)) pinned = store.relayPeer(handle);
|
|
433
|
+
else {
|
|
434
|
+
store.meta(`relay-key-waiting:${handle}`, "replaced");
|
|
435
|
+
notify(
|
|
436
|
+
`${handle}'s keys changed. Your friendship with them waits until you check them: npx tryharness peers trust ${handle}`
|
|
437
|
+
);
|
|
438
|
+
}
|
|
600
439
|
}
|
|
440
|
+
const peer = pinned?.public_key ?? publicKey;
|
|
601
441
|
return {
|
|
602
442
|
...post,
|
|
603
|
-
objective:
|
|
604
|
-
brief:
|
|
605
|
-
contextRefs:
|
|
443
|
+
objective: handle,
|
|
444
|
+
brief: "",
|
|
445
|
+
contextRefs: [],
|
|
446
|
+
targetAgent: "person",
|
|
606
447
|
thread: {
|
|
607
|
-
with:
|
|
608
|
-
role: "target",
|
|
448
|
+
with: `${handle}/person`,
|
|
449
|
+
role: thread.role === "asker" ? "asker" : "target",
|
|
609
450
|
peerKey: peer,
|
|
610
451
|
[OPENED]: true,
|
|
611
452
|
},
|
|
612
453
|
};
|
|
613
454
|
};
|
|
614
455
|
|
|
615
|
-
// A sealed request shown before it is accepted: its subject, opened here for the person's own device.
|
|
616
|
-
// Showing a request pins nothing (security audit S8: listing alone once pinned whatever key Harness gave for a
|
|
617
|
-
// stranger); a key pinned before must still match, and the one shown is kept so that accepting pins that same key.
|
|
618
|
-
const openRequest = async ({ sealed, from, id = null }) => {
|
|
619
|
-
if (!sealed || typeof sealed !== "object")
|
|
620
|
-
throw new Error("nothing sealed to open");
|
|
621
|
-
const mine = sealed.key === identity().publicKey;
|
|
622
|
-
const pinned = store.relayPeer(handleOf(from));
|
|
623
|
-
if (!mine && pinned && pinned.public_key !== String(sealed.key || ""))
|
|
624
|
-
throw new Error(
|
|
625
|
-
`the key Harness gave for ${handleOf(from)}'s computer is not the one this computer saw before`
|
|
626
|
-
);
|
|
627
|
-
const peer = mine
|
|
628
|
-
? String(sealed.targetKey || "")
|
|
629
|
-
: String(sealed.key || "");
|
|
630
|
-
if (!mine && id && /^[0-9a-f-]{36}$/.test(String(id)))
|
|
631
|
-
store.meta(`relay-shown-key:${id}`, peer);
|
|
632
|
-
const opened = await openBound(
|
|
633
|
-
await relayKey(identity().privateKey, peer),
|
|
634
|
-
`request|${sealed.sealId}`,
|
|
635
|
-
sealed
|
|
636
|
-
);
|
|
637
|
-
return {
|
|
638
|
-
about: String(opened.about || "").slice(0, 500),
|
|
639
|
-
fingerprint: await fingerprint(peer),
|
|
640
|
-
...(opened.project && typeof opened.project === "object"
|
|
641
|
-
? { project: opened.project }
|
|
642
|
-
: {}),
|
|
643
|
-
};
|
|
644
|
-
};
|
|
645
|
-
|
|
646
456
|
// The other people's computers this one has pinned a key for, and this computer's own fingerprint.
|
|
647
457
|
const peers = async () => ({
|
|
648
458
|
ok: true,
|
|
@@ -659,13 +469,9 @@ export function createSealedThreads({
|
|
|
659
469
|
return {
|
|
660
470
|
sendMessage,
|
|
661
471
|
sendEnd,
|
|
662
|
-
endGuests,
|
|
663
|
-
sendProjectEvent,
|
|
664
472
|
receive,
|
|
665
473
|
receives: (type) => Object.hasOwn(RECEIVERS, type),
|
|
666
|
-
request,
|
|
667
474
|
openPost,
|
|
668
|
-
openRequest,
|
|
669
475
|
peers,
|
|
670
476
|
};
|
|
671
477
|
}
|