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
package/lib/desk.mjs
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deskAsk,
|
|
3
|
+
fileBankrReceipt,
|
|
4
|
+
onchainExecutors,
|
|
5
|
+
readBook,
|
|
6
|
+
strategyOfThread,
|
|
7
|
+
treasurerOf,
|
|
8
|
+
writeBook,
|
|
9
|
+
} from "./book.mjs";
|
|
10
|
+
import { RUN_CALLER } from "./runAuthority.mjs";
|
|
11
|
+
import {
|
|
12
|
+
approveDeploy,
|
|
13
|
+
buildAsk,
|
|
14
|
+
contractOfDeploy,
|
|
15
|
+
deployRequest,
|
|
16
|
+
fileBuild,
|
|
17
|
+
fileCheck,
|
|
18
|
+
fileJudge,
|
|
19
|
+
markDeployAsked,
|
|
20
|
+
startContract,
|
|
21
|
+
verifyDeployment,
|
|
22
|
+
view,
|
|
23
|
+
} from "./contractGate.mjs";
|
|
24
|
+
|
|
25
|
+
// The onchain desk on this computer: the book's commands for agents and the person (board.desk.*), each Bankr ask in a
|
|
26
|
+
// thread under a strategy carrying that strategy's high-level instructions instead of the book, Bankr's chain receipts
|
|
27
|
+
// filed into the book when its work comes back, and the contract gate's deploy ask and the check of what was deployed.
|
|
28
|
+
|
|
29
|
+
export function createDesk({
|
|
30
|
+
store,
|
|
31
|
+
log = () => {},
|
|
32
|
+
// What the chain holds at an address, read by Harness's server: { ok, sha256, bytes } (walletReads.ts deployed_code).
|
|
33
|
+
readCode = async () => ({
|
|
34
|
+
ok: false,
|
|
35
|
+
error: "the chain cannot be read here",
|
|
36
|
+
}),
|
|
37
|
+
// Posts an ask for Bankr in a thread in the asker's name; resolves to the posted task or rejects.
|
|
38
|
+
askBankr = async () => {
|
|
39
|
+
throw new Error("Bankr cannot be asked from here");
|
|
40
|
+
},
|
|
41
|
+
}) {
|
|
42
|
+
const executors = () => onchainExecutors();
|
|
43
|
+
|
|
44
|
+
/** A Bankr task about to go to Harness: in a thread under a strategy it carries the strategy's slice, fitted. */
|
|
45
|
+
const forBankr = (request) => {
|
|
46
|
+
if (!executors().includes(String(request.targetAgent || "")))
|
|
47
|
+
return request;
|
|
48
|
+
const refs = Array.isArray(request.contextRefs) ? request.contextRefs : [];
|
|
49
|
+
const askRef = refs.find(
|
|
50
|
+
(ref) => ref?.kind === "ask" && typeof ref.ref === "string"
|
|
51
|
+
);
|
|
52
|
+
const fitted = deskAsk(store, {
|
|
53
|
+
threadId: request.parentId ? String(request.parentId) : null,
|
|
54
|
+
ask: askRef?.ref ?? String(request.objective || ""),
|
|
55
|
+
history: String(request.brief || ""),
|
|
56
|
+
});
|
|
57
|
+
if (!fitted) return request;
|
|
58
|
+
return {
|
|
59
|
+
...request,
|
|
60
|
+
brief: fitted.history,
|
|
61
|
+
contextRefs: [
|
|
62
|
+
...refs.filter((ref) => ref !== askRef),
|
|
63
|
+
{ kind: "ask", ref: fitted.ask },
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// After Bankr deployed reviewed code: what the chain holds at the address it created is compared with that code.
|
|
69
|
+
const verify = async (contract, chain, address) => {
|
|
70
|
+
const read = await readCode(chain, address).catch((error) => ({
|
|
71
|
+
ok: false,
|
|
72
|
+
error: error.message,
|
|
73
|
+
}));
|
|
74
|
+
const checked = verifyDeployment(store, {
|
|
75
|
+
contract: contract.id,
|
|
76
|
+
address,
|
|
77
|
+
deployedSha256: read?.ok ? read.sha256 : null,
|
|
78
|
+
});
|
|
79
|
+
if (checked.status === "mismatch")
|
|
80
|
+
log(
|
|
81
|
+
`contract ${contract.id}: the code at ${address} is not the code reviewed`
|
|
82
|
+
);
|
|
83
|
+
return { ...checked, ...(read?.ok ? {} : { error: read?.error }) };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** A Bankr job in one of the person's threads came back: its chain receipt goes into the book. */
|
|
87
|
+
const cloudJob = (job) => {
|
|
88
|
+
const receipt = fileBankrReceipt(store, job);
|
|
89
|
+
if (!receipt) return null;
|
|
90
|
+
log(`filed Bankr's receipt for ${job.id} in the book (${receipt.outcome})`);
|
|
91
|
+
const contract = contractOfDeploy(store, job.id);
|
|
92
|
+
const created = receipt.operations.flatMap((op) =>
|
|
93
|
+
(op.created ?? []).map((address) => ({ chain: op.chain, address }))
|
|
94
|
+
);
|
|
95
|
+
if (contract && created.length)
|
|
96
|
+
void verify(
|
|
97
|
+
contract,
|
|
98
|
+
created[0].chain ?? contract.chain,
|
|
99
|
+
created[0].address
|
|
100
|
+
);
|
|
101
|
+
return receipt;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const contractCommand = async (request, agent) => {
|
|
105
|
+
const action = String(request.action || "");
|
|
106
|
+
const id = String(request.contract || "");
|
|
107
|
+
if (action === "view") {
|
|
108
|
+
const contract = view(
|
|
109
|
+
store.db.get("select * from book_contracts where id = ?", [id])
|
|
110
|
+
);
|
|
111
|
+
return contract
|
|
112
|
+
? {
|
|
113
|
+
ok: true,
|
|
114
|
+
contract,
|
|
115
|
+
buildAsk: buildAsk(store, id),
|
|
116
|
+
deploy: deployRequest(store, { contract: id }),
|
|
117
|
+
}
|
|
118
|
+
: { ok: false, error: "no contract in the book has that id" };
|
|
119
|
+
}
|
|
120
|
+
if (action === "start")
|
|
121
|
+
return startContract(store, agent, {
|
|
122
|
+
strategy: request.strategy,
|
|
123
|
+
name: request.name,
|
|
124
|
+
chain: request.chain,
|
|
125
|
+
oneGo: request.one_go === true,
|
|
126
|
+
buildChain: request.build_chain,
|
|
127
|
+
});
|
|
128
|
+
if (action === "file_build")
|
|
129
|
+
return fileBuild(store, agent, {
|
|
130
|
+
contract: id,
|
|
131
|
+
source: request.source,
|
|
132
|
+
runtimeCode: request.runtime_code,
|
|
133
|
+
buildTask: request.build_task,
|
|
134
|
+
address: request.address,
|
|
135
|
+
});
|
|
136
|
+
// A verdict is bound to the run that made it and the model Harness chose for that run (contractGate.mjs).
|
|
137
|
+
if (action === "check")
|
|
138
|
+
return fileCheck(store, agent, {
|
|
139
|
+
contract: id,
|
|
140
|
+
run: request[RUN_CALLER],
|
|
141
|
+
sha256: request.sha256,
|
|
142
|
+
passed: request.passed,
|
|
143
|
+
});
|
|
144
|
+
if (action === "judge")
|
|
145
|
+
return fileJudge(store, agent, {
|
|
146
|
+
contract: id,
|
|
147
|
+
run: request[RUN_CALLER],
|
|
148
|
+
sha256: request.sha256,
|
|
149
|
+
accepted: request.accepted,
|
|
150
|
+
});
|
|
151
|
+
if (action === "approve")
|
|
152
|
+
return approveDeploy(store, agent, {
|
|
153
|
+
contract: id,
|
|
154
|
+
sha256: request.sha256,
|
|
155
|
+
});
|
|
156
|
+
if (action === "deploy") {
|
|
157
|
+
if (agent !== "user" && treasurerOf(store).agent !== agent)
|
|
158
|
+
return {
|
|
159
|
+
ok: false,
|
|
160
|
+
error: "the treasurer or the person asks Bankr to deploy",
|
|
161
|
+
};
|
|
162
|
+
const gate = deployRequest(store, { contract: id });
|
|
163
|
+
if (!gate.ok)
|
|
164
|
+
return {
|
|
165
|
+
ok: false,
|
|
166
|
+
error: `not deployed: ${gate.refusals.join("; ")}`,
|
|
167
|
+
refusals: gate.refusals,
|
|
168
|
+
};
|
|
169
|
+
const row = store.db.get(
|
|
170
|
+
"select strategy_id from book_contracts where id = ?",
|
|
171
|
+
[id]
|
|
172
|
+
);
|
|
173
|
+
const thread =
|
|
174
|
+
String(request.thread || "") ||
|
|
175
|
+
store.db.get(
|
|
176
|
+
"select thread_id from book_threads where strategy_id = ? order by created_at limit 1",
|
|
177
|
+
[row.strategy_id]
|
|
178
|
+
)?.thread_id;
|
|
179
|
+
if (!thread || strategyOfThread(store, thread) !== row.strategy_id)
|
|
180
|
+
return {
|
|
181
|
+
ok: false,
|
|
182
|
+
error:
|
|
183
|
+
"name a thread under the contract's strategy for Bankr's deploy ask",
|
|
184
|
+
};
|
|
185
|
+
const task = await askBankr({
|
|
186
|
+
threadId: thread,
|
|
187
|
+
asker: agent,
|
|
188
|
+
words: gate.ask,
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
ok: true,
|
|
192
|
+
contract: markDeployAsked(store, id, task.id),
|
|
193
|
+
task: task.id,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (action === "verify") {
|
|
197
|
+
const contract = view(
|
|
198
|
+
store.db.get("select * from book_contracts where id = ?", [id])
|
|
199
|
+
);
|
|
200
|
+
if (!contract)
|
|
201
|
+
return { ok: false, error: "no contract in the book has that id" };
|
|
202
|
+
const address = String(request.address || contract.address || "");
|
|
203
|
+
if (!address)
|
|
204
|
+
return { ok: false, error: "name the address it was deployed to" };
|
|
205
|
+
return verify(contract, String(request.chain || contract.chain), address);
|
|
206
|
+
}
|
|
207
|
+
return { ok: false, error: `unknown contract action ${action}` };
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/** board.desk.*: any agent reads the book; the treasurer and the person write it; Bankr never reads it. */
|
|
211
|
+
const command = (request, agent) => {
|
|
212
|
+
// Bankr is asked with a strategy's instructions only; work another person's agent asked for (a restricted run) and
|
|
213
|
+
// agents reaching the board through Harness do not read the person's book.
|
|
214
|
+
if (executors().includes(agent))
|
|
215
|
+
return {
|
|
216
|
+
ok: false,
|
|
217
|
+
error:
|
|
218
|
+
"Bankr is asked with a strategy's instructions; the book stays with the treasurer",
|
|
219
|
+
};
|
|
220
|
+
if (request.hostedCaller || request.restricted === true)
|
|
221
|
+
return {
|
|
222
|
+
ok: false,
|
|
223
|
+
error:
|
|
224
|
+
"the desk's book is only for the person and their agents on their computers",
|
|
225
|
+
};
|
|
226
|
+
if (request.command === "board.desk.book")
|
|
227
|
+
return readBook(store, {
|
|
228
|
+
strategy: request.strategy ? String(request.strategy) : null,
|
|
229
|
+
});
|
|
230
|
+
if (request.command === "board.desk.write")
|
|
231
|
+
return writeBook(store, agent, request.entry ?? {});
|
|
232
|
+
if (request.command === "board.desk.treasurer")
|
|
233
|
+
return { ok: true, treasurer: treasurerOf(store) };
|
|
234
|
+
if (request.command === "board.desk.contract")
|
|
235
|
+
return { pending: contractCommand(request, agent) };
|
|
236
|
+
return { ok: false, error: `unknown desk command ${request.command}` };
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
return { command, forBankr, cloudJob };
|
|
240
|
+
}
|
package/lib/desktop.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import os from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
@@ -9,13 +8,25 @@ import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
|
|
|
9
8
|
import { paths } from "./paths.mjs";
|
|
10
9
|
|
|
11
10
|
// The desktop app ships as one npm package per platform (tryharness-desktop-<os>-<cpu>), an optional
|
|
12
|
-
// dependency of tryharness, so `npx tryharness` brings the build for this machine and
|
|
13
|
-
// Setup installs
|
|
14
|
-
//
|
|
15
|
-
//
|
|
11
|
+
// dependency of tryharness pinned to one exact version, so `npx tryharness` brings the build for this machine and
|
|
12
|
+
// nothing else. Setup installs that build and no other: never npm's newest, which would let whoever can publish to
|
|
13
|
+
// npm choose the program that starts at login (the app is the daemon's launcher, service.mjs). On a Mac the app must
|
|
14
|
+
// also carry Harness's Developer ID signature, checked by codesign before it is copied. Setup copies the app to a
|
|
15
|
+
// place it keeps, opens it, and the app registers itself to start at login from there.
|
|
16
|
+
|
|
17
|
+
// The platforms Harness builds a desktop app for (the Linux AppImage since 0.7.57). Harness holds the npm names of the
|
|
18
|
+
// others with empty placeholders; a package for one of them is never installed, whatever it says it carries.
|
|
19
|
+
const BUILT = ["darwin", "linux"];
|
|
20
|
+
// The Apple team whose Developer ID signs every published Mac app (packages/desktop/scripts/build-helper.mjs and
|
|
21
|
+
// npm-package.mjs sign with "Developer ID Application: Sigala Fosam (CYNVUR3WT7)").
|
|
22
|
+
const TEAM = "CYNVUR3WT7";
|
|
23
|
+
// Apple's own requirement for a Developer ID application, narrowed to that team.
|
|
24
|
+
export const DEVELOPER_ID_REQUIREMENT =
|
|
25
|
+
"anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] exists and " +
|
|
26
|
+
`certificate leaf[field.1.2.840.113635.100.6.1.13] exists and certificate leaf[subject.OU] = "${TEAM}"`;
|
|
16
27
|
|
|
17
|
-
const REGISTRY = "https://registry.npmjs.org";
|
|
18
28
|
const marker = () => path.join(paths.home, "desktop.json");
|
|
29
|
+
// Where setups before the pinned-build rule unpacked npm's newest; uninstall still clears it.
|
|
19
30
|
const downloads = () => path.join(paths.home, "desktop-download");
|
|
20
31
|
|
|
21
32
|
/** Whether version `a` is newer than `b`: x.y.z, a prerelease (0.7.13-local.ab12) before its release. */
|
|
@@ -29,66 +40,33 @@ export function newerVersion(a, b) {
|
|
|
29
40
|
return !x[4] && Boolean(y[4]);
|
|
30
41
|
}
|
|
31
42
|
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const response = await fetch(
|
|
45
|
-
`${registry}/${desktopPackageName(platform, arch)}/latest`
|
|
46
|
-
);
|
|
47
|
-
if (!response.ok) return null;
|
|
48
|
-
const meta = await response.json();
|
|
49
|
-
const tarball = String(meta.dist?.tarball ?? "");
|
|
50
|
-
if (
|
|
51
|
-
!meta.harnessDesktop ||
|
|
52
|
-
!newerVersion(meta.version, than) ||
|
|
53
|
-
!tarball.startsWith(`${registry}/`)
|
|
54
|
-
)
|
|
55
|
-
return null;
|
|
56
|
-
const download = await fetch(tarball);
|
|
57
|
-
if (!download.ok) return null;
|
|
58
|
-
const bytes = Buffer.from(await download.arrayBuffer());
|
|
59
|
-
const [algorithm, digest] = String(meta.dist.integrity ?? "").split(
|
|
60
|
-
/-(.*)/s
|
|
61
|
-
);
|
|
62
|
-
if (
|
|
63
|
-
algorithm !== "sha512" ||
|
|
64
|
-
createHash("sha512").update(bytes).digest("base64") !== digest
|
|
65
|
-
)
|
|
66
|
-
return null;
|
|
67
|
-
fs.rmSync(downloads(), { recursive: true, force: true });
|
|
68
|
-
ensureDir(downloads());
|
|
69
|
-
const file = path.join(downloads(), "package.tgz");
|
|
70
|
-
fs.writeFileSync(file, bytes);
|
|
71
|
-
if (!run("tar", ["-xzf", file, "-C", downloads()]).ok) return null;
|
|
72
|
-
const app = path.join(downloads(), "package", String(meta.harnessDesktop));
|
|
73
|
-
return fs.existsSync(app) ? { app, version: String(meta.version) } : null;
|
|
74
|
-
} catch {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
43
|
+
/** Whether a Mac app is signed, intact, by Harness's Developer ID: { ok, detail }. */
|
|
44
|
+
export function verifyMacApp(app, execute = run) {
|
|
45
|
+
const checked = execute("codesign", [
|
|
46
|
+
"--verify",
|
|
47
|
+
"--deep",
|
|
48
|
+
"--strict",
|
|
49
|
+
`-R=${DEVELOPER_ID_REQUIREMENT}`,
|
|
50
|
+
app,
|
|
51
|
+
]);
|
|
52
|
+
const detail = (checked.stderr || checked.error || "").trim().split("\n")[0];
|
|
53
|
+
return { ok: checked.ok, detail };
|
|
77
54
|
}
|
|
78
55
|
|
|
79
56
|
/**
|
|
80
|
-
* Setup's desktop app: the
|
|
81
|
-
*
|
|
82
|
-
* HARNESS_DESKTOP_APP installs that app as
|
|
57
|
+
* Setup's desktop app: the build tryharness pins for this machine, or the one installed when that is newer (a local
|
|
58
|
+
* build stays). Where it is and whether it changed, or null when Harness has no app for this machine. Throws, having
|
|
59
|
+
* installed nothing, when a Mac app is not signed by Harness's Developer ID. HARNESS_DESKTOP_APP installs that app as
|
|
60
|
+
* it is.
|
|
83
61
|
*/
|
|
84
62
|
export async function setupDesktop({
|
|
85
63
|
sourceRoot,
|
|
86
64
|
env = process.env,
|
|
87
65
|
platform = process.platform,
|
|
88
66
|
arch = process.arch,
|
|
89
|
-
registry = REGISTRY,
|
|
90
67
|
execute = run,
|
|
91
68
|
}) {
|
|
69
|
+
if (!BUILT.includes(platform)) return null;
|
|
92
70
|
const bundled = desktopSource({ sourceRoot, env, platform, arch });
|
|
93
71
|
const install = (source) =>
|
|
94
72
|
installDesktop({
|
|
@@ -101,18 +79,18 @@ export async function setupDesktop({
|
|
|
101
79
|
const installed = readJson(marker(), {});
|
|
102
80
|
const have =
|
|
103
81
|
installed.path && fs.existsSync(installed.path) ? installed : null;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
82
|
+
if (have && (!bundled || newerVersion(have.version, bundled.version)))
|
|
83
|
+
return { target: have.path, updated: false };
|
|
84
|
+
if (!bundled) return null;
|
|
85
|
+
// A Mac app must carry Harness's Developer ID. Linux has no such signature: the AppImage is trusted as the exact
|
|
86
|
+
// build tryharness pins, whose npm integrity is in tryharness's own signed release (npm-shrinkwrap.json).
|
|
87
|
+
const signed =
|
|
88
|
+
platform === "darwin" ? verifyMacApp(bundled.app, execute) : { ok: true };
|
|
89
|
+
if (!signed.ok)
|
|
90
|
+
throw new Error(
|
|
91
|
+
`the desktop app ${bundled.version} is not signed by Harness's Developer ID, so it was not installed (${signed.detail || "codesign refused it"})`
|
|
92
|
+
);
|
|
93
|
+
return install(bundled);
|
|
116
94
|
}
|
|
117
95
|
|
|
118
96
|
export function desktopPackageName(
|
|
@@ -195,6 +173,21 @@ function executables(target, platform) {
|
|
|
195
173
|
return [target];
|
|
196
174
|
}
|
|
197
175
|
|
|
176
|
+
function linuxAppImagePids(target) {
|
|
177
|
+
if (!fs.existsSync("/proc")) return [];
|
|
178
|
+
return fs.readdirSync("/proc").flatMap((pid) => {
|
|
179
|
+
if (!/^\d+$/.test(pid)) return [];
|
|
180
|
+
try {
|
|
181
|
+
if (fs.readFileSync(`/proc/${pid}/comm`, "utf8").trim() !== "Harness")
|
|
182
|
+
return [];
|
|
183
|
+
const env = fs.readFileSync(`/proc/${pid}/environ`, "utf8").split("\0");
|
|
184
|
+
return env.includes(`APPIMAGE=${target}`) ? [Number(pid)] : [];
|
|
185
|
+
} catch {
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
198
191
|
export function quitDesktop({
|
|
199
192
|
target,
|
|
200
193
|
platform = process.platform,
|
|
@@ -204,6 +197,15 @@ export function quitDesktop({
|
|
|
204
197
|
execute("taskkill", ["/F", "/IM", path.basename(target)]);
|
|
205
198
|
return;
|
|
206
199
|
}
|
|
200
|
+
// AppRun names the native process "Harness"; its command line no longer
|
|
201
|
+
// contains the AppImage path. Stop it as well as the FUSE launcher.
|
|
202
|
+
const nativePids = () =>
|
|
203
|
+
platform === "linux" ? linuxAppImagePids(target) : [];
|
|
204
|
+
for (const pid of nativePids()) {
|
|
205
|
+
try {
|
|
206
|
+
process.kill(pid, "SIGTERM");
|
|
207
|
+
} catch {}
|
|
208
|
+
}
|
|
207
209
|
// The daemon's launcher keeps running through an update: its next start is the new one.
|
|
208
210
|
const exes = executables(target, platform).filter(
|
|
209
211
|
(exe) => path.basename(exe) !== "HarnessDaemon"
|
|
@@ -217,7 +219,9 @@ export function quitDesktop({
|
|
|
217
219
|
// Opening it again before the old one has gone fails on macOS (LaunchServices error -600).
|
|
218
220
|
for (
|
|
219
221
|
let i = 0;
|
|
220
|
-
i < 50 &&
|
|
222
|
+
i < 50 &&
|
|
223
|
+
(nativePids().length > 0 ||
|
|
224
|
+
processes.some((pattern) => execute("pgrep", ["-f", pattern]).ok));
|
|
221
225
|
i++
|
|
222
226
|
) {
|
|
223
227
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100);
|
|
@@ -282,15 +286,106 @@ export function openDesktop({
|
|
|
282
286
|
child.unref();
|
|
283
287
|
}
|
|
284
288
|
|
|
285
|
-
|
|
286
|
-
|
|
289
|
+
const BUNDLE_ID = "ai.tryharness.desktop";
|
|
290
|
+
// The app's own uninstall run (UNINSTALL_ARG in the app's lib.rs) takes out what macOS registered for it, the
|
|
291
|
+
// Lid-Closed power helper and its backstop job, which nothing outside the app can remove. Buddies up to 0.7.53 don't
|
|
292
|
+
// know the argument and would open instead.
|
|
293
|
+
const UNINSTALL_ARG = "--uninstall";
|
|
294
|
+
const LAST_WITHOUT_UNINSTALL = "0.7.53";
|
|
295
|
+
|
|
296
|
+
/** Where the app keeps its settings, log and web storage (the app's platform/*.rs, and its webview's own folders). */
|
|
297
|
+
export function desktopFolders({
|
|
298
|
+
platform = process.platform,
|
|
299
|
+
env = process.env,
|
|
300
|
+
homeDir = os.homedir(),
|
|
301
|
+
} = {}) {
|
|
302
|
+
if (platform === "darwin") {
|
|
303
|
+
const library = path.join(homeDir, "Library");
|
|
304
|
+
return [
|
|
305
|
+
path.join(library, "Application Support", "Harness Desktop"),
|
|
306
|
+
path.join(library, "Logs", "Harness Desktop"),
|
|
307
|
+
path.join(library, "Caches", BUNDLE_ID),
|
|
308
|
+
path.join(library, "WebKit", BUNDLE_ID),
|
|
309
|
+
path.join(library, "HTTPStorages", BUNDLE_ID),
|
|
310
|
+
path.join(library, "Preferences", `${BUNDLE_ID}.plist`),
|
|
311
|
+
path.join(library, "Saved Application State", `${BUNDLE_ID}.savedState`),
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
if (platform === "linux") {
|
|
315
|
+
const config = env.XDG_CONFIG_HOME || path.join(homeDir, ".config");
|
|
316
|
+
const data = env.XDG_DATA_HOME || path.join(homeDir, ".local", "share");
|
|
317
|
+
const cache = env.XDG_CACHE_HOME || path.join(homeDir, ".cache");
|
|
318
|
+
return [
|
|
319
|
+
path.join(config, "harness-desktop"),
|
|
320
|
+
path.join(data, "harness-desktop"),
|
|
321
|
+
path.join(data, BUNDLE_ID),
|
|
322
|
+
path.join(cache, BUNDLE_ID),
|
|
323
|
+
];
|
|
324
|
+
}
|
|
325
|
+
if (platform === "win32") {
|
|
326
|
+
const roaming = env.APPDATA || path.join(homeDir, "AppData", "Roaming");
|
|
327
|
+
const local = env.LOCALAPPDATA || path.join(homeDir, "AppData", "Local");
|
|
328
|
+
return [
|
|
329
|
+
path.join(roaming, "Harness Desktop"),
|
|
330
|
+
path.join(local, "Harness Desktop"),
|
|
331
|
+
path.join(local, BUNDLE_ID),
|
|
332
|
+
];
|
|
333
|
+
}
|
|
334
|
+
return [];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// A Mac app bundle's Info.plist, or "" when there is none.
|
|
338
|
+
const infoPlist = (app) => {
|
|
339
|
+
try {
|
|
340
|
+
return fs.readFileSync(path.join(app, "Contents", "Info.plist"), "latin1");
|
|
341
|
+
} catch {
|
|
342
|
+
return "";
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
const bundleVersion = (plist) =>
|
|
347
|
+
/CFBundleShortVersionString<\/key>\s*<string>([^<]+)</.exec(plist)?.[1];
|
|
348
|
+
|
|
349
|
+
// The installed app: where setup recorded it, and on a Mac also ~/Applications/Harness.app when it is ours, so an
|
|
350
|
+
// app left after ~/.harness was deleted still goes.
|
|
351
|
+
function installedApps({ platform, env, homeDir }) {
|
|
352
|
+
const apps = new Set();
|
|
353
|
+
const recorded = readJson(marker(), {}).path;
|
|
354
|
+
if (recorded && fs.existsSync(recorded)) apps.add(recorded);
|
|
355
|
+
if (platform === "darwin") {
|
|
356
|
+
const usual = desktopTarget({
|
|
357
|
+
source: { app: "Harness.app" },
|
|
358
|
+
env,
|
|
359
|
+
platform,
|
|
360
|
+
homeDir,
|
|
361
|
+
});
|
|
362
|
+
if (infoPlist(usual).includes(BUNDLE_ID)) apps.add(usual);
|
|
363
|
+
}
|
|
364
|
+
return [...apps];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// The app undoes what it changed and takes out its power helper before it is deleted, when it knows how.
|
|
368
|
+
function cleanUpMacApp(app, execute) {
|
|
369
|
+
const version = bundleVersion(infoPlist(app));
|
|
370
|
+
if (!newerVersion(version, LAST_WITHOUT_UNINSTALL)) return;
|
|
371
|
+
const program = path.join(app, "Contents", "MacOS", "Harness");
|
|
372
|
+
if (fs.existsSync(program)) execute(program, [UNINSTALL_ARG]);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** `tryharness uninstall`: the app quits, cleans up after itself and is deleted with its login item and folders. */
|
|
376
|
+
export function uninstallDesktop({
|
|
287
377
|
platform = process.platform,
|
|
288
378
|
execute = run,
|
|
379
|
+
env = process.env,
|
|
289
380
|
homeDir = os.homedir(),
|
|
290
|
-
}) {
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
381
|
+
} = {}) {
|
|
382
|
+
for (const app of installedApps({ platform, env, homeDir })) {
|
|
383
|
+
quitDesktop({ target: app, platform, execute });
|
|
384
|
+
if (platform === "darwin") cleanUpMacApp(app, execute);
|
|
385
|
+
try {
|
|
386
|
+
fs.rmSync(app, { recursive: true, force: true });
|
|
387
|
+
} catch {}
|
|
388
|
+
}
|
|
294
389
|
// Where the app's own login item lives (tauri-plugin-autostart, named after the product).
|
|
295
390
|
if (platform === "darwin") {
|
|
296
391
|
const agents = path.join(homeDir, "Library", "LaunchAgents");
|
|
@@ -311,4 +406,13 @@ export function retireDesktop({
|
|
|
311
406
|
"Harness",
|
|
312
407
|
"/f",
|
|
313
408
|
]);
|
|
409
|
+
for (const folder of [
|
|
410
|
+
...desktopFolders({ platform, env, homeDir }),
|
|
411
|
+
path.join(paths.home, "desktop"),
|
|
412
|
+
downloads(),
|
|
413
|
+
marker(),
|
|
414
|
+
])
|
|
415
|
+
try {
|
|
416
|
+
fs.rmSync(folder, { recursive: true, force: true });
|
|
417
|
+
} catch {}
|
|
314
418
|
}
|
package/lib/directLink.mjs
CHANGED
|
@@ -3,9 +3,9 @@ import path from "node:path";
|
|
|
3
3
|
import { ASK_TIMEOUT_MS } from "./bridge.mjs";
|
|
4
4
|
|
|
5
5
|
// The person's own computers reach each other directly when they can: on the same network, or across the internet
|
|
6
|
-
// through a hole punched in each router (HyperDHT, the Holepunch library), and through Harness otherwise
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// through a hole punched in each router (HyperDHT, the Holepunch library), and through Harness otherwise, in that
|
|
7
|
+
// order. In a trial with a Mac on a phone hotspot and a Linux computer on home wifi, 11 of 11 connections hole-punched,
|
|
8
|
+
// about 0.6 s to connect, a reply in about 45 ms.
|
|
9
9
|
//
|
|
10
10
|
// - Each computer has its own HyperDHT key (direct-identity.json). Two computers swap these keys over the sealed
|
|
11
11
|
// channel they already share (ownMachines.mjs), so each admits only the other computers the person confirmed:
|
|
@@ -118,7 +118,7 @@ export function createDirectLink({
|
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
// One link: newline-framed JSON, requests and answers matched by number. The peer is looked up when something
|
|
121
|
-
// happens, never kept: a key swap updates it in place (
|
|
121
|
+
// happens, never kept: a key swap updates it in place (a copied peer once kept a dead link "linked").
|
|
122
122
|
const attach = (id, socket) => {
|
|
123
123
|
const peer = peers.get(id);
|
|
124
124
|
if (!peer) return socket.destroy();
|
|
@@ -212,6 +212,17 @@ export function createDirectLink({
|
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
214
|
|
|
215
|
+
/** That computer is no longer one of the person's (removed, or a home this one no longer follows): its key is refused. */
|
|
216
|
+
const disallow = (id) => {
|
|
217
|
+
const known = peers.get(id);
|
|
218
|
+
if (!known) return;
|
|
219
|
+
peers.delete(id);
|
|
220
|
+
if (known.socket) {
|
|
221
|
+
release(known, known.socket);
|
|
222
|
+
known.socket.destroy();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
215
226
|
/** Links with that computer if not linked already (the worker's side). */
|
|
216
227
|
const dial = async (id) => {
|
|
217
228
|
const peer = peers.get(id);
|
|
@@ -279,5 +290,5 @@ export function createDirectLink({
|
|
|
279
290
|
await node?.destroy().catch(() => {});
|
|
280
291
|
};
|
|
281
292
|
|
|
282
|
-
return { key, allow, dial, request, status, stop };
|
|
293
|
+
return { key, allow, disallow, dial, request, status, stop };
|
|
283
294
|
}
|
package/lib/environment.mjs
CHANGED
|
@@ -32,7 +32,8 @@ export function readPerson({
|
|
|
32
32
|
exec = run,
|
|
33
33
|
file = process.env.HARNESS_PRESENCE_FILE,
|
|
34
34
|
} = {}) {
|
|
35
|
-
// Tests stand in for the OS: a JSON file { app, idleSeconds }, read instead of it (
|
|
35
|
+
// Tests stand in for the OS: a JSON file { app, idleSeconds }, read instead of it (Harness's desktop end-to-end test
|
|
36
|
+
// writes it).
|
|
36
37
|
if (file) {
|
|
37
38
|
try {
|
|
38
39
|
const read = JSON.parse(fs.readFileSync(file, "utf8"));
|