tryharness 0.7.66 → 0.7.68

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/lib/landed.mjs CHANGED
@@ -2,6 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { spawn } from "node:child_process";
4
4
  import { paths } from "./paths.mjs";
5
+ import { openHere } from "./openHere.mjs";
5
6
  import { LIVE_AGENTS } from "./live.mjs";
6
7
  import { nameOf } from "./members.mjs";
7
8
  import {
@@ -858,40 +859,6 @@ export function createLanded({
858
859
  return request.onComputer === true ? openHere(plan) : plan;
859
860
  }
860
861
 
861
- /**
862
- * The phone's Open: this computer opens the work itself, where the buddy would have opened it (a T3 Code or Codex
863
- * link, or the app). The link and the app are this computer's own reading of the work, never the caller's. A test
864
- * stands in for the opener with HARNESS_OPEN_COMMAND, as notify.mjs takes HARNESS_NOTIFY_COMMAND.
865
- */
866
- function openHere(plan) {
867
- if (!plan.ok || (!plan.link && !plan.app)) return plan;
868
- const args =
869
- process.platform === "darwin"
870
- ? plan.link
871
- ? [plan.link]
872
- : ["-a", plan.app]
873
- : plan.link
874
- ? [plan.link]
875
- : null;
876
- if (!args)
877
- return {
878
- ok: false,
879
- error: `${plan.opensIn ?? "Its app"} can only be opened on this computer itself.`,
880
- };
881
- const child = spawn(
882
- process.env.HARNESS_OPEN_COMMAND ||
883
- (process.platform === "darwin" ? "open" : "xdg-open"),
884
- args,
885
- {
886
- detached: true,
887
- stdio: "ignore",
888
- }
889
- );
890
- child.on("error", () => {});
891
- child.unref();
892
- return { ok: true, opensIn: plan.opensIn, openedHere: true };
893
- }
894
-
895
862
  const COMMANDS = new Set([
896
863
  "board.landed.thread",
897
864
  "board.landed.folder",
package/lib/library.mjs CHANGED
@@ -318,7 +318,7 @@ export function createLibrary({
318
318
  store.drop(file);
319
319
  store.put(rows);
320
320
  });
321
- if (mediaReady()) await embedMedia(parts, rows, lane);
321
+ if (await mediaReady()) await embedMedia(parts, rows, lane);
322
322
  cache = null;
323
323
  return parts;
324
324
  };
@@ -359,7 +359,7 @@ export function createLibrary({
359
359
  }
360
360
  // Pictures and sound read before the image and audio part came down: each file read again once.
361
361
  const tried = new Set();
362
- while (mediaReady()) {
362
+ while (await mediaReady()) {
363
363
  const [waiting] = store.toEmbed(version, ["image", "audio"], 1);
364
364
  if (!waiting || tried.has(waiting.file)) break;
365
365
  tried.add(waiting.file);
@@ -451,7 +451,7 @@ export function createLibrary({
451
451
  let added = 0;
452
452
  const seenSkips = [];
453
453
  // The person's folders.
454
- const searched = folders();
454
+ const searched = await folders();
455
455
  const listed = [];
456
456
  for (const folder of searched) {
457
457
  const found = await crawl(folder);
@@ -486,7 +486,9 @@ export function createLibrary({
486
486
  }
487
487
  }
488
488
  // The threads' files: stored once and never changed, so each is read once.
489
- const threadList = threadFiles().filter((file) => fileKind(file.name));
489
+ const threadList = (await threadFiles()).filter((file) =>
490
+ fileKind(file.name)
491
+ );
490
492
  threadPaths.clear();
491
493
  for (const file of threadList) {
492
494
  threadPaths.set(file.id, file.path);
@@ -521,7 +523,10 @@ export function createLibrary({
521
523
  skipped = seenSkips;
522
524
  const embedded = await embedWaiting(lane);
523
525
  // Pictures and sound wait for the image and audio part of the search model.
524
- if (!mediaReady() && store.toEmbed(version, ["image", "audio"], 1).length)
526
+ if (
527
+ !(await mediaReady()) &&
528
+ store.toEmbed(version, ["image", "audio"], 1).length
529
+ )
525
530
  wantMedia();
526
531
  return {
527
532
  files: listed.length + threadList.length,
@@ -535,25 +540,27 @@ export function createLibrary({
535
540
 
536
541
  /**
537
542
  * The files closest to a question, best first, one hit per file at its best part. scope: folders (the person's added
538
- * folders: agents on this computer only) and threads (thread ids whose files to search); allow(file) drops thread
539
- * files a caller may not read. brief: only hits that stand out, for a brief nobody asked for.
543
+ * folders: agents on this computer only) and threads (thread ids whose files to search); allowed, when given, is the
544
+ * only thread files the caller may read (their ids). brief: only hits that stand out, for a brief nobody asked for.
540
545
  */
541
546
  const search = async (
542
547
  query,
543
548
  {
544
549
  folders: inFolders = false,
545
550
  threads = [],
546
- allow = () => true,
551
+ allowed = null,
547
552
  limit = 8,
548
553
  lane = "interactive",
549
554
  brief = false,
550
555
  } = {}
551
556
  ) => {
552
557
  const text = String(query).slice(0, 4_000);
558
+ const readable = allowed ? new Set(allowed) : null;
553
559
  const inScope = (part) =>
554
560
  part.source === "folders"
555
561
  ? inFolders
556
- : threads.includes(part.source) && allow(part.file);
562
+ : threads.includes(part.source) &&
563
+ (!readable || readable.has(part.file));
557
564
  const words = terms(text);
558
565
  const lookup = isLookup(words);
559
566
 
@@ -671,8 +678,8 @@ export function createLibrary({
671
678
  for (const watcher of watchers.values()) watcher.close();
672
679
  watchers.clear();
673
680
  },
674
- status: () => ({
675
- folders: folders(),
681
+ status: async () => ({
682
+ folders: await folders(),
676
683
  files: store.count(),
677
684
  folderFiles: store.files("folders").size,
678
685
  waiting: store.waiting(version),
package/lib/live.mjs CHANGED
@@ -4,10 +4,11 @@ import path from "node:path";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import zlib from "node:zlib";
6
6
  import { readJson } from "./files.mjs";
7
+ import { kept } from "./kept.mjs";
7
8
  import { historyRoots } from "./paths.mjs";
8
9
  import { PS } from "./nudge.mjs";
9
10
  import { stepsOf } from "./runner.mjs";
10
- import { t3App, t3Link, t3Thread, t3Working } from "./places.mjs";
11
+ import { t3App, t3Link, t3ThreadRecent, t3WorkingRecently } from "./places.mjs";
11
12
 
12
13
  // The person's own coding sessions running on this computer right now, each with the app it runs in: a terminal, an
13
14
  // editor or T3 Code, found by walking up the session's process tree to the first process inside an app bundle. A
@@ -30,15 +31,15 @@ export const LIVE_AGENTS = [
30
31
  ];
31
32
  const PLAIN_ID = /^[A-Za-z0-9._:-]{1,128}$/;
32
33
 
33
- /** Every process: its parent, its terminal (/dev/ttys003, Linux's /dev/pts/3, or null) and its executable, by pid. */
34
- export function processTable() {
34
+ // The buddy's live list and every hook placing a session ask for the table, many times a second; it is read again
35
+ // beside the daemon's thread once it is this old (kept.mjs).
36
+ const TABLE_FRESH_MS = 2_000;
37
+ const TABLE_STALE_MS = 30_000;
38
+
39
+ function* processSteps() {
35
40
  const table = new Map();
36
- if (process.platform === "win32") return table;
37
- const ps = spawnSync(PS, ["-axo", "pid=,ppid=,tty=,comm="], {
38
- encoding: "utf8",
39
- maxBuffer: 16 << 20,
40
- });
41
- for (const line of (ps.stdout || "").split("\n")) {
41
+ const ps = yield [PS, ["-axo", "pid=,ppid=,tty=,comm="]];
42
+ for (const line of (ps || "").split("\n")) {
42
43
  const match = line.trim().match(/^(\d+)\s+(\d+)\s+(\S+)\s+(.+)$/);
43
44
  if (match)
44
45
  table.set(Number(match[1]), {
@@ -50,6 +51,24 @@ export function processTable() {
50
51
  return table;
51
52
  }
52
53
 
54
+ const tableKept = kept(processSteps, {
55
+ freshMs: TABLE_FRESH_MS,
56
+ staleMs: TABLE_STALE_MS,
57
+ keyOf: () => "all",
58
+ wanting: (table, { having = [], fresh = false } = {}) =>
59
+ fresh || having.some((pid) => !table.has(pid)),
60
+ });
61
+
62
+ /**
63
+ * Every process: its parent, its terminal (/dev/ttys003, Linux's /dev/pts/3, or null) and its executable, by pid; up
64
+ * to TABLE_FRESH_MS old. `having`: pids that must be in it (a process that started a moment ago), read now if not.
65
+ * `fresh`: read now, for a decision made once (a process that ended a moment ago is still in a kept reading).
66
+ */
67
+ export function processTable({ having = [], fresh = false } = {}) {
68
+ if (process.platform === "win32") return new Map();
69
+ return tableKept({ having, fresh });
70
+ }
71
+
53
72
  /** True when a process runs inside tmux: a tmux server is among its ancestors. */
54
73
  function underTmux(table, pid) {
55
74
  for (let current = pid, steps = 0; current > 1 && steps < 64; steps++) {
@@ -241,7 +260,7 @@ export function liveSessions({
241
260
  // Codex in T3 Code runs on that shared server too, so no process says which T3 thread it works in: T3's own record does.
242
261
  const t3 = t3App();
243
262
  if (t3)
244
- for (const row of t3Working("codex")) {
263
+ for (const row of t3WorkingRecently("codex")) {
245
264
  if (!sessions.some((session) => session.sessionId === row.sessionId))
246
265
  sessions.push({
247
266
  agent: "codex",
@@ -285,7 +304,7 @@ export function liveSessions({
285
304
  session.host ?? tmux?.client?.host ?? hostApp(table, session.pid);
286
305
  const t3 =
287
306
  host && /^T3 Code\b/.test(host.name)
288
- ? t3Link(session.t3Thread ?? t3Thread(session.sessionId))
307
+ ? t3Link(session.t3Thread ?? t3ThreadRecent(session.sessionId))
289
308
  : null;
290
309
  return { ...session, tty, tmux: tmux?.target ?? null, host, t3 };
291
310
  });
@@ -3,7 +3,7 @@ import os from "node:os";
3
3
  import path from "node:path";
4
4
  import { execFile } from "node:child_process";
5
5
  import { ATLAS_VERSION } from "./atlas.mjs";
6
- import { createContextEngine } from "./context.mjs";
6
+ import { createContextWorker } from "./contextWorker.mjs";
7
7
  import { createCoreModels } from "./coreModels.mjs";
8
8
  import { readJson, writeJsonAtomic } from "./files.mjs";
9
9
  import { createFirewall } from "./firewall.mjs";
@@ -41,7 +41,7 @@ const COMMANDS = new Set([
41
41
  *
42
42
  * - The context space (search): the search model embeds it in the background, a batch at a time, so no request waits
43
43
  * on it; until it is present, search answers from words and says so.
44
- * - The context engine (context.mjs): the atlas of the folders the swarm works in, what every coding session there
44
+ * - The context engine (context.mjs, in its own thread: contextWorker.mjs): the atlas of the folders the swarm works in, what every coding session there
45
45
  * needed, a context pack for each local agent's brief, the overnight learner, and the library of the person's own
46
46
  * files. Documents and PDFs need only the search model; pictures, recordings and video wait for its image and audio
47
47
  * part, which comes down on the charger.
@@ -195,7 +195,7 @@ export function createLocalStack({
195
195
  path: namedPath(file),
196
196
  }));
197
197
 
198
- const contextEngine = createContextEngine({
198
+ const contextEngine = createContextWorker({
199
199
  store,
200
200
  inference,
201
201
  home: root,
@@ -248,10 +248,13 @@ export function createLocalStack({
248
248
  const file = store.file(fileId);
249
249
  return Boolean(file) && (!hostedCaller || file.cloud);
250
250
  };
251
+ const allowed = libraryThreadFiles()
252
+ .filter((file) => file.thread === thread && readable(file.id))
253
+ .map((file) => file.id);
251
254
  try {
252
255
  const hits = await contextEngine.searchFiles(query, {
253
256
  threads: [thread],
254
- allow: readable,
257
+ allowed,
255
258
  limit: 5,
256
259
  });
257
260
  return hits.map((hit) =>
@@ -458,12 +461,15 @@ export function createLocalStack({
458
461
  const command = (request) => {
459
462
  switch (request.command) {
460
463
  case "local.status":
461
- return {
462
- ok: true,
463
- ...contextEngine.status(),
464
- coreModels: coreModels.status(),
465
- learning: contextEngine.report(),
466
- };
464
+ return contextEngine.status().then(
465
+ (status) => ({
466
+ ok: true,
467
+ ...status,
468
+ coreModels: coreModels.status(),
469
+ learning: contextEngine.report(),
470
+ }),
471
+ (error) => ({ ok: false, error: error.message })
472
+ );
467
473
  case "local.learn":
468
474
  void contextEngine
469
475
  .learn({ force: true })
@@ -506,9 +512,7 @@ export function createLocalStack({
506
512
 
507
513
  const stop = () => {
508
514
  clearInterval(embedTimer);
509
- try {
510
- contextEngine.stop();
511
- } catch {}
515
+ void contextEngine.stop().catch(() => {});
512
516
  inference.stop();
513
517
  };
514
518
 
package/lib/mcp-stdio.mjs CHANGED
@@ -437,7 +437,7 @@ const LOCAL_TOOLS = [
437
437
  {
438
438
  name: "post_to_room",
439
439
  description:
440
- "Post in a goal's room for the whole team: a finding, partial work, a question or what you did. To ask another agent for help, put its name in ask (claude-code, codex, pi, opencode, grok-bot, openclaw, hermes, bankr, quotient, muse, or harness to have the thread coordinated), say exactly what you need, then stop: you are woken again when it answers you by name. When you answer someone who asked you, name them (@codex) and they are woken. To have a coding agent run on a particular model, write it after the name, @codex:gpt-6-luna or @codex:gpt-6-luna/high with an effort, from list_models. Any other @name, like a thanks, wakes no one. Post results and sources, not secrets: anything that looks like a key is held. For work someone else should do, post_task with parent_id set to the goal id.",
440
+ 'Post in a goal\'s room for the whole team: a finding, partial work, a question or what you did. To ask another agent for help, or to hand it the next step (a review, the next part of the work), put its name in ask (claude-code, codex, pi, opencode, grok-bot, openclaw, hermes, bankr, quotient, muse, or harness to have the thread coordinated), say exactly what you need, then stop: you are woken again when it answers you by name. When you answer someone who asked you, name them (@codex) and they are woken. To have a coding agent run on a particular model, write it after the name, @codex:gpt-6-luna or @codex:gpt-6-luna/high with an effort, from list_models. A name only in your text, like "Next: @codex" or a thanks, wakes no one: the thread then waits for Harness to pass it on. Post results and sources, not secrets: anything that looks like a key is held. For work someone else should do, post_task with parent_id set to the goal id.',
441
441
  inputSchema: {
442
442
  type: "object",
443
443
  properties: {
@@ -0,0 +1,36 @@
1
+ import { spawn } from "node:child_process";
2
+
3
+ /**
4
+ * Open on this computer, by the daemon itself, where the buddy would have opened it: a link (a T3 Code or Codex thread)
5
+ * or an app. For the phone's Open (landed.mjs) and another computer's Open with no buddy running here
6
+ * (openRequests.mjs). The link and the app are this computer's own reading of the work, never the caller's. A test
7
+ * stands in for the opener with HARNESS_OPEN_COMMAND, as notify.mjs takes HARNESS_NOTIFY_COMMAND.
8
+ */
9
+ export function openHere(plan) {
10
+ if (!plan.ok || (!plan.link && !plan.app)) return plan;
11
+ const args =
12
+ process.platform === "darwin"
13
+ ? plan.link
14
+ ? [plan.link]
15
+ : ["-a", plan.app]
16
+ : plan.link
17
+ ? [plan.link]
18
+ : null;
19
+ if (!args)
20
+ return {
21
+ ok: false,
22
+ error: `${plan.opensIn ?? "Its app"} can only be opened on this computer itself.`,
23
+ };
24
+ const child = spawn(
25
+ process.env.HARNESS_OPEN_COMMAND ||
26
+ (process.platform === "darwin" ? "open" : "xdg-open"),
27
+ args,
28
+ {
29
+ detached: true,
30
+ stdio: "ignore",
31
+ }
32
+ );
33
+ child.on("error", () => {});
34
+ child.unref();
35
+ return { ok: true, opensIn: plan.opensIn, openedHere: true };
36
+ }
@@ -0,0 +1,56 @@
1
+ // Open on another of the person's computers (owner, October 28: an agent on another computer opens "on that
2
+ // computer"). That computer plans the Open as its own buddy's Open would (sessionControl.mjs board.live.focus, a T3
3
+ // Code thread by its own link) and its buddy carries it out, so it lands where the person would go to see it there: a
4
+ // T3 thread, a terminal resuming the session, an editor. The buddy hears of it as it hears of any change, from
5
+ // board.wait, and takes it with board.live.opens. With no buddy waiting here, a link or an app opens by the daemon
6
+ // itself, as the phone's Open does (openHere.mjs); anything else says it needs the buddy.
7
+
8
+ // An Open the buddy has not taken within this is dropped, so a buddy started later never opens something the person
9
+ // asked for long before; and a buddy that waited on the board within it is still there, between two of its waits.
10
+ // Measured on this Mac (M5 Pro) with the buddy installed, October 28, 19 samples: handed over to taken 58 to 196 ms
11
+ // (median about 110 ms); one Open arrived while the daemon was busy (3.5 s to answer) and the buddy between waits.
12
+ // 10 s is fifty times the slowest and covers the daemon's stalls of up to 1.8 s after a restart.
13
+ const KEEP_MS = 10_000;
14
+
15
+ /**
16
+ * `plan(open)` plans an Open here as the person: { to, sessionId, folder, fresh } for an agent's session (or, fresh,
17
+ * the agent itself where they use it), { thread } for a thread in this computer's T3 Code. `waits` is the board's
18
+ * (boardWaits.mjs): whether a buddy waits on this computer, and the bump that wakes it.
19
+ */
20
+ export function createOpenRequests({
21
+ plan,
22
+ waits,
23
+ openHere,
24
+ log = () => {},
25
+ now = Date.now,
26
+ keepMs = KEEP_MS,
27
+ }) {
28
+ let queued = [];
29
+
30
+ const open = async (request) => {
31
+ const planned = await plan(request);
32
+ if (!planned?.ok) return planned;
33
+ if (now() - waits.waitedAt() > keepMs) {
34
+ const opened = openHere(planned);
35
+ if (opened.openedHere || !opened.ok) return opened;
36
+ return {
37
+ ok: false,
38
+ error: `${planned.opensIn ?? "It"} opens there only with Harness's buddy running on that computer.`,
39
+ };
40
+ }
41
+ queued.push({ plan: planned, at: now() });
42
+ waits.bump();
43
+ return { ok: true, opensIn: planned.opensIn ?? null, openedThere: true };
44
+ };
45
+
46
+ /** The buddy's: the Opens asked for since it last took them, oldest first. */
47
+ const take = () => {
48
+ const fresh = queued.filter(({ at }) => now() - at <= keepMs);
49
+ for (const { at } of queued)
50
+ log(`open for another computer taken after ${now() - at} ms`);
51
+ queued = [];
52
+ return { ok: true, plans: fresh.map(({ plan: planned }) => planned) };
53
+ };
54
+
55
+ return { open, take };
56
+ }
@@ -2350,10 +2350,63 @@ export function createOwnMachines({
2350
2350
  );
2351
2351
  };
2352
2352
 
2353
- /** On home: a worker's call for every computer's sessions, or for one session read where it runs. */
2353
+ /**
2354
+ * Open, on the computer an agent's session or thread is on, where the person would go to see it there (owner, October
2355
+ * 28): that computer plans and opens it (openRequests.mjs). Home reaches the worker; a worker goes through home.
2356
+ */
2357
+ const openSession = async (request) => {
2358
+ const target = String(request.machine || machine.id);
2359
+ const open = {
2360
+ to: request.to,
2361
+ sessionId: request.sessionId,
2362
+ folder: request.folder,
2363
+ fresh: request.fresh === true,
2364
+ // Or a thread in that computer's T3 Code.
2365
+ thread: request.thread,
2366
+ };
2367
+ if (target === machine.id) return ownLive({ open });
2368
+ if (isHome()) {
2369
+ if (
2370
+ !siblings.some((sibling) => sibling.id === target && confirmed(sibling))
2371
+ )
2372
+ return { ok: false, error: "that computer is not in your swarm" };
2373
+ const answer = await askWorker(target, { live: { open } });
2374
+ if (!answer)
2375
+ return {
2376
+ ok: false,
2377
+ error: `${labelOf(target) ?? "That computer"} did not answer`,
2378
+ };
2379
+ // A computer older than Open there answers that it only lists and reads.
2380
+ if (!answer.ok && /listed or read/.test(String(answer.error)))
2381
+ return {
2382
+ ok: false,
2383
+ error: `${labelOf(target) ?? "That computer"} opens things for you once it has the latest tryharness.`,
2384
+ };
2385
+ return answer;
2386
+ }
2387
+ const pinned = pinnedHome();
2388
+ if (!pinned) return { ok: false, error: unreachableNote(null) };
2389
+ const answer = await callOnce(pinned, {
2390
+ command: LIVE_COMMAND,
2391
+ agent: "user",
2392
+ open,
2393
+ machine: target,
2394
+ });
2395
+ // A home older than Open there answers with every computer's sessions instead.
2396
+ if (answer?.ok && answer.computers)
2397
+ return {
2398
+ ok: false,
2399
+ error:
2400
+ "Your home computer passes this on once it has the latest tryharness.",
2401
+ };
2402
+ return answer ?? offline();
2403
+ };
2404
+
2405
+ /** On home: a worker's call for every computer's sessions, for one session read where it runs, or for an Open there. */
2354
2406
  const answerLiveCall = async (call, from) => {
2355
2407
  if (call.agent !== "user")
2356
2408
  return { ok: false, error: "only the person reads their sessions" };
2409
+ if (call.open) return openSession({ ...call.open, machine: call.machine });
2357
2410
  if (call.read) return readSession({ ...call.read, machine: call.machine });
2358
2411
  return { ok: true, computers: await everyComputersLive(from) };
2359
2412
  };
@@ -2659,6 +2712,47 @@ export function createOwnMachines({
2659
2712
  saveMachine(machine);
2660
2713
  }
2661
2714
 
2715
+ // On home: a computer online through Harness that has not linked directly for UNLINKED_MS, though home admits its
2716
+ // key, gets home's listener started again, at most once every RELINK_EVERY_MS (owner, October 28: the listener once
2717
+ // stayed unreachable for 30 minutes after a restart, and a restart of it was all it needed).
2718
+ const UNLINKED_MS = 2 * 60_000;
2719
+ const RELINK_EVERY_MS = 10 * 60_000;
2720
+ const unlinkedSince = new Map();
2721
+ let relinkedAt = 0;
2722
+ const watchLinks = setInterval(() => {
2723
+ if (!directLink || !isHome()) return;
2724
+ const links = new Map(directLink.status().map((link) => [link.id, link]));
2725
+ const now = Date.now();
2726
+ let stuck = false;
2727
+ for (const sibling of siblings) {
2728
+ const link = links.get(sibling.id);
2729
+ const waiting =
2730
+ sibling.role === "worker" &&
2731
+ sibling.connected &&
2732
+ store.ownMachine(sibling.id) &&
2733
+ link &&
2734
+ !link.linked;
2735
+ if (!waiting) {
2736
+ unlinkedSince.delete(sibling.id);
2737
+ continue;
2738
+ }
2739
+ if (!unlinkedSince.has(sibling.id)) unlinkedSince.set(sibling.id, now);
2740
+ if (now - unlinkedSince.get(sibling.id) >= UNLINKED_MS) stuck = true;
2741
+ }
2742
+ if (!stuck || now - relinkedAt < RELINK_EVERY_MS) return;
2743
+ relinkedAt = now;
2744
+ unlinkedSince.clear();
2745
+ log(
2746
+ "direct links: a computer online through Harness has not linked for 2 min"
2747
+ );
2748
+ void directLink
2749
+ .restart?.()
2750
+ .catch((error) =>
2751
+ log(`direct links: the listener did not start again (${error.message})`)
2752
+ );
2753
+ }, 30_000);
2754
+ watchLinks.unref?.();
2755
+
2662
2756
  return {
2663
2757
  hello,
2664
2758
  adopt,
@@ -2703,6 +2797,7 @@ export function createOwnMachines({
2703
2797
  models,
2704
2798
  sessions,
2705
2799
  readSession,
2800
+ openSession,
2706
2801
  setModel,
2707
2802
  allowSsh,
2708
2803
  status,
package/lib/phones.mjs CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  open,
14
14
  pairProof,
15
15
  seal,
16
+ sealFilePart,
16
17
  } from "./sealed.mjs";
17
18
 
18
19
  // The daemon's side of the person's own devices: pairing offers made on this machine (a QR code
@@ -181,7 +182,11 @@ export async function createPhoneDesk({
181
182
  const identity = await loadOrCreateIdentity(identityFile);
182
183
  const offers = new Map();
183
184
  const keys = new Map();
184
- const hostname = os.hostname().slice(0, 64);
185
+ // The name the person knows this computer by (machine.json's label, which `npx tryharness machines name` changes),
186
+ // not its network name: macOS renames that on its own after a clash on the network, and a phone linking
187
+ // MacBook-Pro-3 said it was linking a MacBook-Pro-4 the person had never heard of.
188
+ const hostname = () =>
189
+ machines()?.status()?.label ?? os.hostname().slice(0, 64);
185
190
 
186
191
  const setupOffer = setupOfferFile ? readSetupOffer(setupOfferFile) : null;
187
192
  if (setupOffer)
@@ -221,7 +226,7 @@ export async function createPhoneDesk({
221
226
  byHarness,
222
227
  expiresAt: Date.now() + ttlMs,
223
228
  });
224
- return { o: offerId, s: secret, k: identity.publicKey, h: hostname };
229
+ return { o: offerId, s: secret, k: identity.publicKey, h: hostname() };
225
230
  };
226
231
 
227
232
  // What the QR code or link carries. The secret and the daemon's key never pass through Harness.
@@ -427,7 +432,7 @@ export async function createPhoneDesk({
427
432
  String(requestId),
428
433
  {
429
434
  paired: true,
430
- hostname,
435
+ hostname: hostname(),
431
436
  label,
432
437
  kind: device.kind,
433
438
  version,
@@ -586,6 +591,26 @@ export async function createPhoneDesk({
586
591
  };
587
592
  }
588
593
  const result = await answer(request.call, device, { holder, gesture });
594
+ // A file part asked for as bytes goes sealed as bytes; anything else, and every older phone, as JSON.
595
+ if (
596
+ request.call?.command === "board.file.get" &&
597
+ request.call.raw === true &&
598
+ result?.ok === true &&
599
+ typeof result.data === "string"
600
+ ) {
601
+ const { data, ...header } = result;
602
+ return {
603
+ ok: true,
604
+ envelope: await sealFilePart(
605
+ key,
606
+ "d2p",
607
+ device.id,
608
+ envelope.requestId,
609
+ header,
610
+ Buffer.from(data, "base64")
611
+ ),
612
+ };
613
+ }
589
614
  return {
590
615
  ok: true,
591
616
  envelope: await seal(key, "d2p", device.id, envelope.requestId, result),
@@ -628,7 +653,7 @@ export async function createPhoneDesk({
628
653
  const answer = async (callInput, device, sealedBy) => {
629
654
  const command = String(callInput?.command || "");
630
655
  if (command === "phone.hello")
631
- return { ok: true, hostname, version, kind: device.kind };
656
+ return { ok: true, hostname: hostname(), version, kind: device.kind };
632
657
  // A device sends a file's bytes. A path names a file already on this computer, which only an agent here may attach.
633
658
  if (command === "board.file.add" && callInput?.path != null)
634
659
  return {