tryharness 0.7.78 → 0.7.82

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 (63) hide show
  1. package/README.md +4 -3
  2. package/assets/install.sh +104 -0
  3. package/cli.mjs +203 -321
  4. package/lib/adapters.mjs +7 -6
  5. package/lib/agentRuntimes.mjs +2 -1
  6. package/lib/backupSetup.mjs +0 -52
  7. package/lib/boardProtocol.json +21 -1
  8. package/lib/browserPage.mjs +30 -0
  9. package/lib/coordinator.mjs +0 -2
  10. package/lib/daemon.mjs +117 -7
  11. package/lib/desktop.mjs +7 -1
  12. package/lib/dispatcher.mjs +12 -2
  13. package/lib/environments.mjs +4 -11
  14. package/lib/goalCommands.mjs +18 -8
  15. package/lib/hookDialects.mjs +2 -1
  16. package/lib/jobAnswers.mjs +2 -1
  17. package/lib/kanban.mjs +217 -48
  18. package/lib/localStack.mjs +24 -9
  19. package/lib/machineRoutes.mjs +9 -0
  20. package/lib/machineRuns.mjs +9 -1
  21. package/lib/manager.mjs +60 -2
  22. package/lib/mcp-stdio.mjs +9 -3
  23. package/lib/museSession.mjs +2 -1
  24. package/lib/nativeHost.mjs +11 -2
  25. package/lib/network.mjs +20 -0
  26. package/lib/notify.mjs +48 -16
  27. package/lib/onboard.mjs +71 -366
  28. package/lib/ownMachines.mjs +95 -44
  29. package/lib/pairing.mjs +0 -84
  30. package/lib/paths.mjs +17 -0
  31. package/lib/peopleBoard.mjs +131 -0
  32. package/lib/personNotices.mjs +9 -25
  33. package/lib/phones.mjs +1 -0
  34. package/lib/profile.mjs +0 -109
  35. package/lib/projectBoard.mjs +219 -0
  36. package/lib/projectPieces.mjs +26 -0
  37. package/lib/projects.mjs +37 -4
  38. package/lib/removeHarness.mjs +91 -0
  39. package/lib/roomChannels.mjs +2 -0
  40. package/lib/runAuthority.mjs +23 -9
  41. package/lib/runBrief.mjs +20 -14
  42. package/lib/runner.mjs +3 -3
  43. package/lib/runtime-install.mjs +22 -2
  44. package/lib/screen.mjs +133 -0
  45. package/lib/selfUpdate.mjs +6 -6
  46. package/lib/service.mjs +120 -7
  47. package/lib/sessionControl.mjs +10 -0
  48. package/lib/setupChoices.mjs +400 -0
  49. package/lib/setupMode.mjs +137 -0
  50. package/lib/store.mjs +6 -3
  51. package/lib/swarm.mjs +181 -61
  52. package/lib/t3.mjs +23 -14
  53. package/lib/taskCommands.mjs +25 -15
  54. package/lib/taskRooms.mjs +2 -4
  55. package/lib/threadActions.mjs +16 -4
  56. package/lib/threadAuthority.mjs +28 -10
  57. package/lib/threadRuns.mjs +162 -74
  58. package/lib/toolCheck.mjs +136 -0
  59. package/lib/ui.mjs +15 -1
  60. package/lib/wakes.mjs +3 -3
  61. package/npm-shrinkwrap.json +14 -14
  62. package/package.json +4 -4
  63. package/release.json +64 -55
@@ -0,0 +1,400 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { spawnSync } from "node:child_process";
5
+ import { readJson, writeJsonAtomic } from "./files.mjs";
6
+ import { appDirs, EDITOR_IDS, editorInstall, t3App } from "./places.mjs";
7
+ import { herdrInstalled } from "./herdr.mjs";
8
+ import { processTable } from "./live.mjs";
9
+
10
+ // What the setup screens choose, kept in the config the rest of Harness reads: where threads open (`workplace`,
11
+ // sessionControl.mjs homeOf) and which of the folders macOS guards file search may read (`searchFolders`,
12
+ // localStack.mjs). Asked for by the app's setup window and its settings, on the control socket.
13
+
14
+ // The folders macOS asks about before any program reads them; nothing reads one the person did not pick.
15
+ const ASKED = ["Downloads", "Documents", "Desktop"];
16
+ // Terminals Open can start a session in on a Mac (sessionControl.mjs), by their app's name.
17
+ const MAC_TERMINALS = [
18
+ "Ghostty",
19
+ "iTerm",
20
+ "WezTerm",
21
+ "Warp",
22
+ "kitty",
23
+ "Alacritty",
24
+ "Hyper",
25
+ ];
26
+ const EDITOR_NAMES = {
27
+ cursor: "Cursor",
28
+ windsurf: "Windsurf",
29
+ "vscode-insiders": "VS Code Insiders",
30
+ vscode: "VS Code",
31
+ };
32
+ const FOUND_AT_MOST = 8;
33
+ // A folder as the person reads it: their home as ~.
34
+ const shown = (folder) => {
35
+ const home = os.homedir();
36
+ const inHome = folder === home || folder.startsWith(home + path.sep);
37
+ return {
38
+ path: folder,
39
+ name: inHome ? "~" + folder.slice(home.length) : folder,
40
+ };
41
+ };
42
+
43
+ const COMMANDS = new Set([
44
+ "setup.apps",
45
+ "setup.workplace",
46
+ "setup.folders",
47
+ "setup.folder",
48
+ "setup.findFolders",
49
+ ]);
50
+
51
+ /**
52
+ * Everything Harness can open threads in that is on this computer, open ones first: T3 Code, the editors, the Mac
53
+ * terminals, herdr and Neovim. On Linux only those it can open there: T3 Code, the editors whose command-line tool is
54
+ * installed and herdr (terminals, and so Neovim, do not open from Harness on Linux yet).
55
+ */
56
+ export function appsHere({
57
+ platform = process.platform,
58
+ running = runningApps(),
59
+ } = {}) {
60
+ const apps = [];
61
+ const t3 = t3App();
62
+ if (t3)
63
+ apps.push({
64
+ id: "t3",
65
+ name: "T3 Code",
66
+ app: t3.app,
67
+ place: { kind: "t3", name: "T3 Code" },
68
+ });
69
+ for (const id of EDITOR_IDS) {
70
+ const install =
71
+ platform === "darwin" ? editorInstall(id) : editorOnPath(id);
72
+ if (install)
73
+ apps.push({
74
+ id,
75
+ name: EDITOR_NAMES[id],
76
+ app: install.app,
77
+ place: {
78
+ kind: "editor",
79
+ editor: id,
80
+ name: EDITOR_NAMES[id],
81
+ app: install.app,
82
+ cli: install.cli,
83
+ surface: "terminal",
84
+ },
85
+ });
86
+ }
87
+ if (platform === "darwin") {
88
+ for (const name of MAC_TERMINALS) {
89
+ const app = appIn(`${name}.app`);
90
+ if (app)
91
+ apps.push({
92
+ id: name.toLowerCase(),
93
+ name,
94
+ app,
95
+ place: terminal(name, app),
96
+ });
97
+ }
98
+ const appleTerminal = "/System/Applications/Utilities/Terminal.app";
99
+ apps.push({
100
+ id: "terminal",
101
+ name: "Terminal",
102
+ app: appleTerminal,
103
+ place: terminal("Terminal", appleTerminal),
104
+ });
105
+ }
106
+ // Places Harness opens threads in that are not apps: herdr (its tabs, through its own server) and, on a Mac, Neovim
107
+ // (in a tab of a Neovim already open, else the terminal picked above, or the one open now, running it).
108
+ if (herdrInstalled({}))
109
+ apps.push({
110
+ id: "herdr",
111
+ name: "herdr",
112
+ app: null,
113
+ place: { kind: "herdr", name: "herdr" },
114
+ });
115
+ if (platform === "darwin" && commandOnPath("nvim")) {
116
+ const terminals = apps.filter((entry) => entry.place.kind === "terminal");
117
+ const host =
118
+ terminals.find((entry) =>
119
+ running.some((comm) => comm.startsWith(`${entry.app}/`))
120
+ ) ?? terminals[0];
121
+ apps.push({
122
+ id: "nvim",
123
+ name: "Neovim",
124
+ app: null,
125
+ place: { kind: "nvim", name: "Neovim", app: host?.app ?? null },
126
+ });
127
+ }
128
+ const isOpen = (entry) =>
129
+ Boolean(entry.app) &&
130
+ running.some((comm) => comm.startsWith(`${entry.app}/`));
131
+ return apps
132
+ .map((entry) => ({ ...entry, running: isOpen(entry) }))
133
+ .sort((a, b) => Number(b.running) - Number(a.running))
134
+ .map((entry) => ({ ...entry, icon: appIcon(entry.app) }));
135
+ }
136
+
137
+ // Each app's own icon on a Mac, as a small PNG the setup screen can show: read from the app's icns with sips, which
138
+ // macOS has built in, once per app. Elsewhere, or for an app without an icns, the screen shows its initials.
139
+ const icons = new Map();
140
+ function appIcon(app, platform = process.platform) {
141
+ if (platform !== "darwin" || !app?.endsWith(".app")) return null;
142
+ if (icons.has(app)) return icons.get(app);
143
+ let icon = null;
144
+ try {
145
+ const named = spawnSync(
146
+ "plutil",
147
+ [
148
+ "-extract",
149
+ "CFBundleIconFile",
150
+ "raw",
151
+ path.join(app, "Contents", "Info.plist"),
152
+ ],
153
+ { encoding: "utf8", timeout: 3_000 }
154
+ );
155
+ const file = (named.stdout || "").trim();
156
+ const icns = path.join(
157
+ app,
158
+ "Contents",
159
+ "Resources",
160
+ file.endsWith(".icns") ? file : `${file}.icns`
161
+ );
162
+ if (file && fs.existsSync(icns)) {
163
+ const out = path.join(
164
+ os.tmpdir(),
165
+ `harness-icon-${process.pid}-${icons.size}.png`
166
+ );
167
+ const made = spawnSync(
168
+ "sips",
169
+ ["-s", "format", "png", "-Z", "64", icns, "--out", out],
170
+ { timeout: 5_000 }
171
+ );
172
+ if (made.status === 0 && fs.existsSync(out)) {
173
+ icon = `data:image/png;base64,${fs.readFileSync(out).toString("base64")}`;
174
+ fs.rmSync(out, { force: true });
175
+ }
176
+ }
177
+ } catch {}
178
+ icons.set(app, icon);
179
+ return icon;
180
+ }
181
+
182
+ const terminal = (name, app) => ({ kind: "terminal", name, app });
183
+
184
+ function appIn(file) {
185
+ for (const dir of appDirs()) {
186
+ const at = path.join(dir, file);
187
+ if (fs.existsSync(at)) return at;
188
+ }
189
+ return null;
190
+ }
191
+
192
+ function editorOnPath(id) {
193
+ const cli = { cursor: "cursor", windsurf: "windsurf", vscode: "code" }[id];
194
+ const at = cli ? commandOnPath(cli) : null;
195
+ return at ? { app: path.dirname(at), cli: at } : null;
196
+ }
197
+
198
+ function commandOnPath(name) {
199
+ const found = spawnSync("sh", ["-c", `command -v ${name}`], {
200
+ encoding: "utf8",
201
+ });
202
+ const at = (found.stdout || "").trim();
203
+ return found.status === 0 && at ? at : null;
204
+ }
205
+
206
+ function runningApps() {
207
+ return [...processTable({ fresh: true }).values()].map((row) => row.comm);
208
+ }
209
+
210
+ /**
211
+ * Folders whose name holds `query`'s letters in order, for setup's "+ Add": the folders the person already works in
212
+ * first, then the folders in their home and, on a Mac, the folders Spotlight already knows by name. Never lists the
213
+ * inside of a folder macOS guards, which would set off the very prompt this avoids.
214
+ */
215
+ export function findFolders(query, { known = [], home = os.homedir() } = {}) {
216
+ const wanted = String(query || "").toLowerCase();
217
+ if (!wanted) return known.slice(0, FOUND_AT_MOST);
218
+ const matches = (folder) =>
219
+ inOrder(path.basename(folder).toLowerCase(), wanted);
220
+ const top = topFolders(home);
221
+ const spotlight =
222
+ process.platform === "darwin" ? spotlightFolders(wanted) : [];
223
+ return [...new Set([...known, ...top, ...spotlight])]
224
+ .filter(matches)
225
+ .slice(0, FOUND_AT_MOST);
226
+ }
227
+
228
+ function inOrder(name, letters) {
229
+ let at = 0;
230
+ for (const letter of name) if (letter === letters[at]) at++;
231
+ return at === letters.length;
232
+ }
233
+
234
+ // Folders in the home folder and two levels into each, skipping hidden ones, Library, the folders macOS guards and
235
+ // what holds no one's own work (node_modules), so listing them never sets off a macOS prompt.
236
+ const SKIP = new Set(["Library", "node_modules", ...ASKED]);
237
+ function topFolders(home, depth = 3) {
238
+ const found = [];
239
+ const walk = (dir, level) => {
240
+ let entries = [];
241
+ try {
242
+ entries = fs.readdirSync(dir, { withFileTypes: true });
243
+ } catch {
244
+ return;
245
+ }
246
+ for (const entry of entries) {
247
+ if (!entry.isDirectory() || entry.name.startsWith(".")) continue;
248
+ if (SKIP.has(entry.name)) continue;
249
+ const at = path.join(dir, entry.name);
250
+ found.push(at);
251
+ if (level < depth && found.length < 4_000) walk(at, level + 1);
252
+ }
253
+ };
254
+ walk(home, 1);
255
+ return found;
256
+ }
257
+
258
+ function spotlightFolders(wanted) {
259
+ const found = spawnSync(
260
+ "mdfind",
261
+ [
262
+ "-onlyin",
263
+ os.homedir(),
264
+ `kMDItemContentType == "public.folder" && kMDItemFSName == "*${wanted.replace(/["*\\]/g, "")}*"c`,
265
+ ],
266
+ { encoding: "utf8", timeout: 3_000 }
267
+ );
268
+ return (found.stdout || "")
269
+ .split("\n")
270
+ .filter((line) => line && !line.includes("/Library/") && !/\/\./.test(line))
271
+ .slice(0, 40);
272
+ }
273
+
274
+ /** The setup choices on the control socket. `knownFolders()` is where the person already works (folders.mjs). */
275
+ export function createSetupChoices({
276
+ configPath,
277
+ knownFolders = () => [],
278
+ home = os.homedir(),
279
+ }) {
280
+ const config = () => readJson(configPath, {});
281
+ const save = (change) =>
282
+ writeJsonAtomic(configPath, { ...config(), ...change });
283
+ const pickedNow = () => {
284
+ const current = config();
285
+ return new Set(
286
+ Array.isArray(current.searchFolders) ? current.searchFolders : ASKED
287
+ );
288
+ };
289
+ const savePicked = (picked) =>
290
+ save({ searchFolders: ASKED.filter((entry) => picked.has(entry)) });
291
+
292
+ // A guarded folder is read the moment it is picked, so macOS asks then, beside the tap, not later when the index
293
+ // first reaches it (owner, November 3: "a little jarring"). The read waits off the event loop for the person's
294
+ // answer, which can take longer than the app waits for a reply: the screen follows `asking`. A refusal takes the
295
+ // pick back.
296
+ const asking = new Set();
297
+ const refused = new Set();
298
+ const askMacOS = (name, folder, takeBack) => {
299
+ asking.add(name);
300
+ refused.delete(name);
301
+ fs.promises
302
+ .readdir(folder)
303
+ .catch((error) => {
304
+ if (error?.code !== "EPERM" && error?.code !== "EACCES") return;
305
+ refused.add(name);
306
+ takeBack();
307
+ })
308
+ .finally(() => asking.delete(name));
309
+ };
310
+ const guarded = (folder) =>
311
+ ASKED.some(
312
+ (name) =>
313
+ folder === path.join(home, name) ||
314
+ folder.startsWith(path.join(home, name) + path.sep)
315
+ );
316
+
317
+ const answer = (request) => {
318
+ switch (request.command) {
319
+ case "setup.apps":
320
+ return {
321
+ ok: true,
322
+ apps: appsHere(),
323
+ workplace: config().workplace ?? { all: null, agents: {} },
324
+ };
325
+ case "setup.workplace": {
326
+ // `place` from setup.apps, or null: for one agent, null means it follows the general pick.
327
+ const place = request.place ?? null;
328
+ const workplace = config().workplace ?? { all: null, agents: {} };
329
+ const agent = request.target ? String(request.target) : null;
330
+ const agents = { ...workplace.agents };
331
+ if (agent && place) agents[agent] = place;
332
+ if (agent && !place) delete agents[agent];
333
+ save({
334
+ workplace: { all: agent ? workplace.all : place, agents },
335
+ });
336
+ return { ok: true };
337
+ }
338
+ case "setup.folders": {
339
+ const current = config();
340
+ return {
341
+ ok: true,
342
+ asked: ASKED,
343
+ picked: Array.isArray(current.searchFolders)
344
+ ? current.searchFolders
345
+ : ASKED,
346
+ asking: [...asking],
347
+ refused: [...refused],
348
+ added: (Array.isArray(current.localFolders)
349
+ ? current.localFolders
350
+ : []
351
+ ).map(shown),
352
+ };
353
+ }
354
+ case "setup.folder": {
355
+ const current = config();
356
+ const name = String(request.name || "");
357
+ const on = request.on === true;
358
+ if (ASKED.includes(name)) {
359
+ const picked = pickedNow();
360
+ if (on) picked.add(name);
361
+ else picked.delete(name);
362
+ savePicked(picked);
363
+ if (on)
364
+ askMacOS(name, path.join(home, name), () => {
365
+ const now = pickedNow();
366
+ now.delete(name);
367
+ savePicked(now);
368
+ });
369
+ return { ok: true };
370
+ }
371
+ const folder = path.resolve(name.replace(/^~(?=$|\/)/, home));
372
+ // Inside a guarded folder even a check that it exists makes macOS ask, and would hold the daemon while it
373
+ // does: there the read below, which waits off the event loop, is the check.
374
+ const inGuarded = guarded(folder);
375
+ if (on && !inGuarded && !fs.existsSync(folder))
376
+ return { ok: false, error: "That folder is not on this computer." };
377
+ const added = new Set(current.localFolders ?? []);
378
+ if (on) added.add(folder);
379
+ else added.delete(folder);
380
+ save({ localFolders: [...added] });
381
+ if (on && inGuarded)
382
+ askMacOS(shown(folder).name, folder, () => {
383
+ const now = new Set(config().localFolders ?? []);
384
+ now.delete(folder);
385
+ save({ localFolders: [...now] });
386
+ });
387
+ return { ok: true };
388
+ }
389
+ case "setup.findFolders":
390
+ return {
391
+ ok: true,
392
+ folders: findFolders(request.query, { known: knownFolders() }).map(
393
+ shown
394
+ ),
395
+ };
396
+ }
397
+ return { ok: false, error: "unknown command" };
398
+ };
399
+ return { handles: (command) => COMMANDS.has(command), answer };
400
+ }
@@ -0,0 +1,137 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import { listenControl } from "./controlSocket.mjs";
4
+ import { readJson, writeJsonAtomic } from "./files.mjs";
5
+ import {
6
+ keepJoinCode,
7
+ setupPageUrl,
8
+ startPairing,
9
+ waitForApproval,
10
+ } from "./pairing.mjs";
11
+ import { writeBrowserOffer } from "./phones.mjs";
12
+ import { stopSetupHere } from "./removeHarness.mjs";
13
+
14
+ // Before this computer is signed in, Harness runs here anyway, so the buddy can show setup and the installer can
15
+ // print the code. One pairing is held open at a time and it can be approved two ways: signing in on the page the
16
+ // buddy opens, or typing its code into Add a Computer on a computer already signed in. Whichever happens first
17
+ // signs this computer in; nothing waits on a timer. A pairing that runs out is replaced by a fresh one.
18
+
19
+ // After a pairing fails for a reason other than running out (no network, Harness down), the next try waits this long,
20
+ // doubling up to the cap, so a computer offline overnight does not ask Harness every second.
21
+ const RETRY_FIRST_MS = 2_000;
22
+ const RETRY_MAX_MS = 60_000;
23
+
24
+ /**
25
+ * Hold this computer's sign-in open until the person approves it, answering on the control socket meanwhile:
26
+ * `status` (so the buddy knows setup is showing), `setup.state` (the code and a link to sign in elsewhere) and
27
+ * `setup.signin` (a link that also links the browser it opens in), and `setup.cancel` (the person stopped setup:
28
+ * Harness comes off this computer and this daemon ends). Resolves once signed in, with the socket closed so
29
+ * the daemon proper can take it. `agents` are the coding agents found here, which the pairing names.
30
+ */
31
+ export async function untilSignedIn({ paths, origin, agents = [], log }) {
32
+ const say = (line) => log?.(line);
33
+ const state = {
34
+ code: null,
35
+ own: false,
36
+ pairId: null,
37
+ error: null,
38
+ startedAt: null,
39
+ };
40
+ let signedIn;
41
+ const done = new Promise((resolve) => (signedIn = resolve));
42
+
43
+ const linkFor = async ({ withBrowser }) => {
44
+ if (!state.code) return null;
45
+ const browser = withBrowser
46
+ ? await writeBrowserOffer({
47
+ identityFile: paths.phoneIdentity,
48
+ offerFile: paths.browserOffer,
49
+ }).catch(() => null)
50
+ : null;
51
+ return setupPageUrl(origin, { code: state.code, own: state.own }, browser);
52
+ };
53
+
54
+ const answer = async (request) => {
55
+ if (request.command === "status")
56
+ return { ok: true, setup: true, connected: false, signedIn: false };
57
+ if (request.command === "setup.state")
58
+ return {
59
+ ok: true,
60
+ phase: "signin",
61
+ code: state.own ? state.code : null,
62
+ url: await linkFor({ withBrowser: false }),
63
+ computer: os.hostname().replace(/\.local$/, ""),
64
+ error: state.error,
65
+ };
66
+ if (request.command === "setup.signin") {
67
+ const url = await linkFor({ withBrowser: true });
68
+ return url
69
+ ? { ok: true, url }
70
+ : { ok: false, error: state.error || "Harness is not reachable yet." };
71
+ }
72
+ if (request.command === "setup.cancel") {
73
+ // Answered first: taking the app and the service off this computer ends this process.
74
+ setTimeout(() => {
75
+ say("setup: stopped by the person; taking Harness off this computer");
76
+ stopSetupHere({ paths });
77
+ process.exit(0);
78
+ }, 200);
79
+ return { ok: true };
80
+ }
81
+ return {
82
+ ok: false,
83
+ code: "not_signed_in",
84
+ error: "Harness on this computer is not signed in yet.",
85
+ };
86
+ };
87
+
88
+ if (fs.existsSync(paths.socket)) fs.unlinkSync(paths.socket);
89
+ const server = await listenControl({ socketPath: paths.socket, answer });
90
+
91
+ const hold = async () => {
92
+ let wait = RETRY_FIRST_MS;
93
+ for (;;) {
94
+ try {
95
+ const pairing = await startPairing(origin, agents);
96
+ Object.assign(state, pairing, { error: null, startedAt: Date.now() });
97
+ if (pairing.own) keepJoinCode(paths.machine, pairing.code);
98
+ say(`setup: holding a sign-in for this computer (${pairing.pairId})`);
99
+ wait = RETRY_FIRST_MS;
100
+ const token = await waitForApproval(origin, pairing.pairId);
101
+ return token;
102
+ } catch (error) {
103
+ // A pairing that ran out is replaced at once; anything else waits before asking Harness again.
104
+ const expired = /expired|ended without approval/i.test(error.message);
105
+ state.error = expired ? null : error.message;
106
+ if (expired) continue;
107
+ say(`setup: sign-in not held (${error.message}); trying again`);
108
+ await new Promise((resolve) => setTimeout(resolve, wait));
109
+ wait = Math.min(wait * 2, RETRY_MAX_MS);
110
+ }
111
+ }
112
+ };
113
+
114
+ hold().then((token) => {
115
+ // Signed in through setup: the app's screens come next, until the person presses Start there. None of the folders
116
+ // macOS guards is searched until the person picks it there: a config without the choice means all three, which is
117
+ // what installs from before setup chose (localStack.mjs), so a new one starts with the choice made, empty.
118
+ const before = readJson(paths.config, {});
119
+ writeJsonAtomic(paths.config, {
120
+ ...before,
121
+ origin,
122
+ token,
123
+ setupDone: false,
124
+ searchFolders: Array.isArray(before.searchFolders)
125
+ ? before.searchFolders
126
+ : [],
127
+ });
128
+ say("setup: signed in");
129
+ signedIn();
130
+ });
131
+
132
+ await done;
133
+ // The file goes first, so a caller arriving now fails at once and tries again with the daemon proper, instead of
134
+ // waiting on a socket that is closing.
135
+ if (fs.existsSync(paths.socket)) fs.unlinkSync(paths.socket);
136
+ await new Promise((resolve) => server.close(resolve));
137
+ }
package/lib/store.mjs CHANGED
@@ -2668,14 +2668,17 @@ export function openStore(file) {
2668
2668
  ).n
2669
2669
  );
2670
2670
  },
2671
- postsBy(goalId, author, since) {
2671
+ // `machine`: only posts from that computer, or from none named.
2672
+ postsBy(goalId, author, since, machine = null) {
2672
2673
  return Number(
2673
2674
  execute(
2674
2675
  "get",
2675
- "select count(*) as n from board_contributions where task_id = ? and author = ? and created_at >= ? and kind != 'held'",
2676
+ "select count(*) as n from board_contributions where task_id = ? and author = ? and created_at >= ? and kind != 'held' and (? is null or machine is null or machine = ?)",
2676
2677
  goalId,
2677
2678
  author,
2678
- since
2679
+ since,
2680
+ machine,
2681
+ machine
2679
2682
  ).n
2680
2683
  );
2681
2684
  },