tryharness 0.7.53 → 0.7.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +10 -5
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +115 -36
  5. package/lib/adapters.mjs +157 -222
  6. package/lib/agentRuntimes.mjs +26 -16
  7. package/lib/agentSignIn.mjs +226 -0
  8. package/lib/audit.mjs +643 -0
  9. package/lib/backupSetup.mjs +141 -0
  10. package/lib/boardAccess.mjs +8 -1
  11. package/lib/boardBackup.mjs +283 -0
  12. package/lib/boardMirror.mjs +71 -7
  13. package/lib/boardProtocol.json +59 -2
  14. package/lib/boardWaits.mjs +102 -0
  15. package/lib/book.mjs +659 -0
  16. package/lib/bridge.mjs +1 -1
  17. package/lib/cards.mjs +138 -28
  18. package/lib/cloudBoot.mjs +124 -0
  19. package/lib/commands.mjs +7 -2
  20. package/lib/context.mjs +18 -4
  21. package/lib/contractGate.mjs +377 -0
  22. package/lib/coordinator.mjs +149 -43
  23. package/lib/daemon.mjs +349 -28
  24. package/lib/desk.mjs +239 -0
  25. package/lib/desktop.mjs +106 -6
  26. package/lib/environments.mjs +237 -7
  27. package/lib/folders.mjs +2 -2
  28. package/lib/gitHost.mjs +174 -0
  29. package/lib/hookDialects.mjs +298 -0
  30. package/lib/landed.mjs +887 -0
  31. package/lib/live.mjs +284 -13
  32. package/lib/mcp-stdio.mjs +68 -2
  33. package/lib/members.json +16 -2
  34. package/lib/models.mjs +8 -8
  35. package/lib/museSession.mjs +16 -13
  36. package/lib/nativeHost.mjs +1 -1
  37. package/lib/neovim.mjs +126 -0
  38. package/lib/nudge.mjs +47 -16
  39. package/lib/ownMachines.mjs +343 -39
  40. package/lib/pairing.mjs +27 -10
  41. package/lib/paths.mjs +4 -0
  42. package/lib/personModel.mjs +89 -0
  43. package/lib/phones.mjs +66 -11
  44. package/lib/places.mjs +330 -10
  45. package/lib/readiness.mjs +135 -18
  46. package/lib/record.mjs +115 -0
  47. package/lib/runWorker.mjs +17 -2
  48. package/lib/runner.mjs +8 -4
  49. package/lib/sessionControl.mjs +377 -89
  50. package/lib/specialties.json +74 -0
  51. package/lib/specialties.mjs +477 -0
  52. package/lib/specialtyKeys.d.ts +3 -0
  53. package/lib/specialtyKeys.js +58 -0
  54. package/lib/specialtyNotice.mjs +147 -0
  55. package/lib/specialtySnapshot.mjs +138 -0
  56. package/lib/store.mjs +284 -1
  57. package/lib/swarm.mjs +137 -21
  58. package/lib/t3.mjs +13 -4
  59. package/lib/taskCommands.mjs +36 -9
  60. package/lib/taskRuns.mjs +9 -2
  61. package/lib/team.json +255 -148
  62. package/lib/team.mjs +529 -188
  63. package/lib/threadLine.mjs +116 -0
  64. package/lib/threadRuns.mjs +75 -11
  65. package/lib/threadView.mjs +15 -2
  66. package/lib/worktrees.mjs +51 -13
  67. package/package.json +4 -4
  68. package/lib/modelTiers.json +0 -1183
  69. package/lib/modelTiers.mjs +0 -133
package/lib/desk.mjs ADDED
@@ -0,0 +1,239 @@
1
+ import {
2
+ deskAsk,
3
+ fileBankrReceipt,
4
+ onchainExecutors,
5
+ readBook,
6
+ strategyOfThread,
7
+ treasurerOf,
8
+ writeBook,
9
+ } from "./book.mjs";
10
+ import {
11
+ approveDeploy,
12
+ buildAsk,
13
+ contractOfDeploy,
14
+ deployRequest,
15
+ fileBuild,
16
+ fileCheck,
17
+ fileJudge,
18
+ markDeployAsked,
19
+ startContract,
20
+ verifyDeployment,
21
+ view,
22
+ } from "./contractGate.mjs";
23
+
24
+ // The onchain desk on this computer (docs/swarm-organization.md, "The onchain desk"): the book's commands for agents
25
+ // and the person (board.desk.*), each Bankr ask in a thread under a strategy carrying that strategy's high-level
26
+ // instructions instead of the book, Bankr's chain receipts filed into the book when its work comes back, and the
27
+ // 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
+ if (action === "check")
137
+ return fileCheck(store, agent, {
138
+ contract: id,
139
+ model: request.model,
140
+ sha256: request.sha256,
141
+ passed: request.passed,
142
+ });
143
+ if (action === "judge")
144
+ return fileJudge(store, agent, {
145
+ contract: id,
146
+ model: request.model,
147
+ sha256: request.sha256,
148
+ accepted: request.accepted,
149
+ });
150
+ if (action === "approve")
151
+ return approveDeploy(store, agent, {
152
+ contract: id,
153
+ sha256: request.sha256,
154
+ });
155
+ if (action === "deploy") {
156
+ if (agent !== "user" && treasurerOf(store).agent !== agent)
157
+ return {
158
+ ok: false,
159
+ error: "the treasurer or the person asks Bankr to deploy",
160
+ };
161
+ const gate = deployRequest(store, { contract: id });
162
+ if (!gate.ok)
163
+ return {
164
+ ok: false,
165
+ error: `not deployed: ${gate.refusals.join("; ")}`,
166
+ refusals: gate.refusals,
167
+ };
168
+ const row = store.db.get(
169
+ "select strategy_id from book_contracts where id = ?",
170
+ [id]
171
+ );
172
+ const thread =
173
+ String(request.thread || "") ||
174
+ store.db.get(
175
+ "select thread_id from book_threads where strategy_id = ? order by created_at limit 1",
176
+ [row.strategy_id]
177
+ )?.thread_id;
178
+ if (!thread || strategyOfThread(store, thread) !== row.strategy_id)
179
+ return {
180
+ ok: false,
181
+ error:
182
+ "name a thread under the contract's strategy for Bankr's deploy ask",
183
+ };
184
+ const task = await askBankr({
185
+ threadId: thread,
186
+ asker: agent,
187
+ words: gate.ask,
188
+ });
189
+ return {
190
+ ok: true,
191
+ contract: markDeployAsked(store, id, task.id),
192
+ task: task.id,
193
+ };
194
+ }
195
+ if (action === "verify") {
196
+ const contract = view(
197
+ store.db.get("select * from book_contracts where id = ?", [id])
198
+ );
199
+ if (!contract)
200
+ return { ok: false, error: "no contract in the book has that id" };
201
+ const address = String(request.address || contract.address || "");
202
+ if (!address)
203
+ return { ok: false, error: "name the address it was deployed to" };
204
+ return verify(contract, String(request.chain || contract.chain), address);
205
+ }
206
+ return { ok: false, error: `unknown contract action ${action}` };
207
+ };
208
+
209
+ /** board.desk.*: any agent reads the book; the treasurer and the person write it; Bankr never reads it. */
210
+ const command = (request, agent) => {
211
+ // Bankr is asked with a strategy's instructions only; work another person's agent asked for (a restricted run) and
212
+ // agents reaching the board through Harness do not read the person's book.
213
+ if (executors().includes(agent))
214
+ return {
215
+ ok: false,
216
+ error:
217
+ "Bankr is asked with a strategy's instructions; the book stays with the treasurer",
218
+ };
219
+ if (request.hostedCaller || request.restricted === true)
220
+ return {
221
+ ok: false,
222
+ error:
223
+ "the desk's book is only for the person and their agents on their computers",
224
+ };
225
+ if (request.command === "board.desk.book")
226
+ return readBook(store, {
227
+ strategy: request.strategy ? String(request.strategy) : null,
228
+ });
229
+ if (request.command === "board.desk.write")
230
+ return writeBook(store, agent, request.entry ?? {});
231
+ if (request.command === "board.desk.treasurer")
232
+ return { ok: true, treasurer: treasurerOf(store) };
233
+ if (request.command === "board.desk.contract")
234
+ return { pending: contractCommand(request, agent) };
235
+ return { ok: false, error: `unknown desk command ${request.command}` };
236
+ };
237
+
238
+ return { command, forBankr, cloudJob };
239
+ }
package/lib/desktop.mjs CHANGED
@@ -282,15 +282,106 @@ export function openDesktop({
282
282
  child.unref();
283
283
  }
284
284
 
285
- /** Disconnecting stops the app and takes it out of login items; the app itself stays. */
286
- export function retireDesktop({
285
+ const BUNDLE_ID = "ai.tryharness.desktop";
286
+ // The app's own uninstall run (UNINSTALL_ARG in the app's lib.rs) takes out what macOS registered for it, the
287
+ // Lid-Closed power helper and its backstop job, which nothing outside the app can remove. Buddies up to 0.7.53 don't
288
+ // know the argument and would open instead.
289
+ const UNINSTALL_ARG = "--uninstall";
290
+ const LAST_WITHOUT_UNINSTALL = "0.7.53";
291
+
292
+ /** Where the app keeps its settings, log and web storage (the app's platform/*.rs, and its webview's own folders). */
293
+ export function desktopFolders({
294
+ platform = process.platform,
295
+ env = process.env,
296
+ homeDir = os.homedir(),
297
+ } = {}) {
298
+ if (platform === "darwin") {
299
+ const library = path.join(homeDir, "Library");
300
+ return [
301
+ path.join(library, "Application Support", "Harness Desktop"),
302
+ path.join(library, "Logs", "Harness Desktop"),
303
+ path.join(library, "Caches", BUNDLE_ID),
304
+ path.join(library, "WebKit", BUNDLE_ID),
305
+ path.join(library, "HTTPStorages", BUNDLE_ID),
306
+ path.join(library, "Preferences", `${BUNDLE_ID}.plist`),
307
+ path.join(library, "Saved Application State", `${BUNDLE_ID}.savedState`),
308
+ ];
309
+ }
310
+ if (platform === "linux") {
311
+ const config = env.XDG_CONFIG_HOME || path.join(homeDir, ".config");
312
+ const data = env.XDG_DATA_HOME || path.join(homeDir, ".local", "share");
313
+ const cache = env.XDG_CACHE_HOME || path.join(homeDir, ".cache");
314
+ return [
315
+ path.join(config, "harness-desktop"),
316
+ path.join(data, "harness-desktop"),
317
+ path.join(data, BUNDLE_ID),
318
+ path.join(cache, BUNDLE_ID),
319
+ ];
320
+ }
321
+ if (platform === "win32") {
322
+ const roaming = env.APPDATA || path.join(homeDir, "AppData", "Roaming");
323
+ const local = env.LOCALAPPDATA || path.join(homeDir, "AppData", "Local");
324
+ return [
325
+ path.join(roaming, "Harness Desktop"),
326
+ path.join(local, "Harness Desktop"),
327
+ path.join(local, BUNDLE_ID),
328
+ ];
329
+ }
330
+ return [];
331
+ }
332
+
333
+ // A Mac app bundle's Info.plist, or "" when there is none.
334
+ const infoPlist = (app) => {
335
+ try {
336
+ return fs.readFileSync(path.join(app, "Contents", "Info.plist"), "latin1");
337
+ } catch {
338
+ return "";
339
+ }
340
+ };
341
+
342
+ const bundleVersion = (plist) =>
343
+ /CFBundleShortVersionString<\/key>\s*<string>([^<]+)</.exec(plist)?.[1];
344
+
345
+ // The installed app: where setup recorded it, and on a Mac also ~/Applications/Harness.app when it is ours, so an
346
+ // app left after ~/.harness was deleted still goes.
347
+ function installedApps({ platform, env, homeDir }) {
348
+ const apps = new Set();
349
+ const recorded = readJson(marker(), {}).path;
350
+ if (recorded && fs.existsSync(recorded)) apps.add(recorded);
351
+ if (platform === "darwin") {
352
+ const usual = desktopTarget({
353
+ source: { app: "Harness.app" },
354
+ env,
355
+ platform,
356
+ homeDir,
357
+ });
358
+ if (infoPlist(usual).includes(BUNDLE_ID)) apps.add(usual);
359
+ }
360
+ return [...apps];
361
+ }
362
+
363
+ // The app undoes what it changed and takes out its power helper before it is deleted, when it knows how.
364
+ function cleanUpMacApp(app, execute) {
365
+ const version = bundleVersion(infoPlist(app));
366
+ if (!newerVersion(version, LAST_WITHOUT_UNINSTALL)) return;
367
+ const program = path.join(app, "Contents", "MacOS", "Harness");
368
+ if (fs.existsSync(program)) execute(program, [UNINSTALL_ARG]);
369
+ }
370
+
371
+ /** `tryharness uninstall`: the app quits, cleans up after itself and is deleted with its login item and folders. */
372
+ export function uninstallDesktop({
287
373
  platform = process.platform,
288
374
  execute = run,
375
+ env = process.env,
289
376
  homeDir = os.homedir(),
290
- }) {
291
- const installed = readJson(marker(), {});
292
- if (installed.path)
293
- quitDesktop({ target: installed.path, platform, execute });
377
+ } = {}) {
378
+ for (const app of installedApps({ platform, env, homeDir })) {
379
+ quitDesktop({ target: app, platform, execute });
380
+ if (platform === "darwin") cleanUpMacApp(app, execute);
381
+ try {
382
+ fs.rmSync(app, { recursive: true, force: true });
383
+ } catch {}
384
+ }
294
385
  // Where the app's own login item lives (tauri-plugin-autostart, named after the product).
295
386
  if (platform === "darwin") {
296
387
  const agents = path.join(homeDir, "Library", "LaunchAgents");
@@ -311,4 +402,13 @@ export function retireDesktop({
311
402
  "Harness",
312
403
  "/f",
313
404
  ]);
405
+ for (const folder of [
406
+ ...desktopFolders({ platform, env, homeDir }),
407
+ path.join(paths.home, "desktop"),
408
+ downloads(),
409
+ marker(),
410
+ ])
411
+ try {
412
+ fs.rmSync(folder, { recursive: true, force: true });
413
+ } catch {}
314
414
  }