tryharness 0.7.67 → 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.
@@ -6,6 +6,7 @@ import { paths } from "./paths.mjs";
6
6
  export function createBoardFileCommands({
7
7
  FILE_LIMITS,
8
8
  FILE_PART_BYTES,
9
+ RAW_FILE_PART_BYTES,
9
10
  MAX_FILE_BYTES,
10
11
  MB,
11
12
  blobPath,
@@ -174,20 +175,17 @@ export function createBoardFileCommands({
174
175
  // whole file, which the checks in plainBoard read as a whole.
175
176
  if (request.offset !== undefined && !request.hostedCaller) {
176
177
  const offset = Number(request.offset),
177
- length = Number(request.length ?? FILE_PART_BYTES);
178
+ length = Number(request.length ?? FILE_PART_BYTES),
179
+ most = request.raw === true ? RAW_FILE_PART_BYTES : FILE_PART_BYTES;
178
180
  if (!Number.isSafeInteger(offset) || offset < 0 || offset >= file.bytes)
179
181
  return {
180
182
  ok: false,
181
183
  error: "offset must be a byte within the file",
182
184
  };
183
- if (
184
- !Number.isSafeInteger(length) ||
185
- length < 1 ||
186
- length > FILE_PART_BYTES
187
- )
185
+ if (!Number.isSafeInteger(length) || length < 1 || length > most)
188
186
  return {
189
187
  ok: false,
190
- error: `a part is 1 to ${FILE_PART_BYTES} bytes`,
188
+ error: `a part is 1 to ${most} bytes`,
191
189
  };
192
190
  const part = Buffer.alloc(Math.min(length, file.bytes - offset));
193
191
  const fd = fs.openSync(blobPath(file.sha256), "r");
@@ -45,6 +45,10 @@ export const MAX_FILE_BYTES = Math.max(
45
45
  );
46
46
  // One part of a file read through the sealed channel: 512 KiB is 683 KiB as base64, inside a sealed answer's 1 MB.
47
47
  export const FILE_PART_BYTES = 512 * 1024;
48
+ // A part sealed as bytes for a phone that asks for it (sealed.mjs sealFilePart): no base64 inside the seal, so a part
49
+ // nearly twice the size still fits the sealed wire's 1.4 MB (src/shared/bridge/sealedWire.ts MAX_CT), and a video
50
+ // takes half the round trips.
51
+ export const RAW_FILE_PART_BYTES = 960 * 1024;
48
52
  // The most files one search across the person's threads answers with.
49
53
  const FOUND_FILES = 20;
50
54
  const fileLimit = (mime, bytes) =>
@@ -597,6 +601,7 @@ export function createBoardFiles({
597
601
  const command = createBoardFileCommands({
598
602
  FILE_LIMITS,
599
603
  FILE_PART_BYTES,
604
+ RAW_FILE_PART_BYTES,
600
605
  MAX_FILE_BYTES,
601
606
  MB,
602
607
  blobPath,
@@ -41,6 +41,7 @@
41
41
  "board.list": "task",
42
42
  "board.live": "live",
43
43
  "board.live.focus": "live",
44
+ "board.live.opens": "live",
44
45
  "board.live.place": "live",
45
46
  "board.live.read": "live",
46
47
  "board.live.say": "live",
@@ -662,6 +663,7 @@
662
663
  "board.live.say",
663
664
  "board.live.read",
664
665
  "board.live.focus",
666
+ "board.live.opens",
665
667
  "t3.connect",
666
668
  "t3.status",
667
669
  "voice.status",
@@ -702,6 +704,7 @@
702
704
  "machines.model",
703
705
  "machines.live",
704
706
  "machines.live.read",
707
+ "machines.live.open",
705
708
  "swarm.lineup",
706
709
  "swarm.add",
707
710
  "swarm.remove",
@@ -23,6 +23,8 @@ export function createBoardWaits({ head }) {
23
23
  const listeners = new Set();
24
24
  let timer = null;
25
25
  let checkQueued = false;
26
+ // When a surface last waited on the local socket: one between two waits is still there.
27
+ let waitedAt = 0;
26
28
 
27
29
  const revision = () => `${seen}.${outside}`;
28
30
 
@@ -71,12 +73,14 @@ export function createBoardWaits({ head }) {
71
73
  },
72
74
  /** The revision once it is not `after`: at once when it already is not, else when it moves or the hold ends. */
73
75
  wait({ after, holdMs = MOST_HOLD_MS } = {}) {
76
+ waitedAt = Date.now();
74
77
  check();
75
78
  if (String(after ?? "") !== revision())
76
79
  return Promise.resolve(revision());
77
80
  const hold = Math.max(0, Math.min(MOST_HOLD_MS, Number(holdMs) || 0));
78
81
  return new Promise((resolve) => {
79
82
  const done = (current) => {
83
+ waitedAt = Date.now();
80
84
  clearTimeout(timeout);
81
85
  waiters.delete(done);
82
86
  keepChecking();
@@ -89,6 +93,8 @@ export function createBoardWaits({ head }) {
89
93
  },
90
94
  /** Whether any surface waits on the local socket now: what is shown beside the board is kept fresh meanwhile. */
91
95
  watched: () => waiters.size > 0,
96
+ /** When a surface last waited on the local socket, or stopped waiting (0: none yet). */
97
+ waitedAt: () => (waiters.size > 0 ? Date.now() : waitedAt),
92
98
  onChange(listener) {
93
99
  listeners.add(listener);
94
100
  keepChecking();
package/lib/context.mjs CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  } from "./learn.mjs";
24
24
  import { repositoryOf } from "./worktrees.mjs";
25
25
  import { createLibrary } from "./library.mjs";
26
+ import { mentions } from "./frames.mjs";
26
27
  import { oneLine } from "./oneLine.mjs";
27
28
 
28
29
  // The context engine. It keeps the atlas of the code the swarm works in, remembers what every coding session on this
@@ -231,7 +232,8 @@ export function createContextEngine({
231
232
 
232
233
  const roots = async () => {
233
234
  const places = [];
234
- for (const place of known()) places.push(await keptPlaceOf(place.path));
235
+ for (const place of await known())
236
+ places.push(await keptPlaceOf(place.path));
235
237
  return [...new Set(places.map((place) => place?.root).filter(Boolean))];
236
238
  };
237
239
 
@@ -257,7 +259,7 @@ export function createContextEngine({
257
259
  ).toISOString();
258
260
  const trees = new Map();
259
261
  let added = 0;
260
- for (const session of store.sessionSources({ since })) {
262
+ for (const session of await store.sessionSources({ since })) {
261
263
  // A session whose source file the agent has since deleted is read from the relay's own copy, once.
262
264
  let mtime = 0;
263
265
  try {
@@ -273,7 +275,7 @@ export function createContextEngine({
273
275
  ? await readTrail(session.agent, session.source)
274
276
  : trailFromTranscript(
275
277
  session.agent,
276
- store.sessionTranscript(session.agent, session.session_id),
278
+ await store.sessionTranscript(session.agent, session.session_id),
277
279
  {
278
280
  cwd: session.cwd,
279
281
  startedAt: Date.parse(session.started_at) || null,
@@ -344,9 +346,9 @@ export function createContextEngine({
344
346
  refreshing ||= (async () => {
345
347
  const power = inference.power;
346
348
  // A first pass over a repository waits for the charger; small catch-ups run on battery too unless it is low.
347
- if (power.paused()) return { skipped: "power" };
349
+ if (await power.paused()) return { skipped: "power" };
348
350
  const first = !atlas.roots().length;
349
- if (first && !power.onCharger())
351
+ if (first && !(await power.onCharger()))
350
352
  return { skipped: "waiting for the charger" };
351
353
  let files = 0;
352
354
  for (const root of await roots()) {
@@ -361,7 +363,7 @@ export function createContextEngine({
361
363
  await embedRuns("background");
362
364
  // The first pass over the person's folders waits for the charger too; after it, changes are read as they come.
363
365
  const read =
364
- !library.status().folderFiles && !power.onCharger()
366
+ !(await library.status()).folderFiles && !(await power.onCharger())
365
367
  ? { skipped: "waiting for the charger" }
366
368
  : await library.refresh({ lane: "background" });
367
369
  return { files, runs, pieces, library: read };
@@ -487,6 +489,20 @@ export function createContextEngine({
487
489
  };
488
490
  };
489
491
 
492
+ /**
493
+ * A folder's files as last indexed ([{ path, blob }]); [] outside a repository, or before its first index, which
494
+ * this starts. A task frame asks without waiting, and a run's pack has indexed its folder just before.
495
+ */
496
+ const scopeOf = (folder) => {
497
+ const place = folder && keptPlaces.get(folder)?.place;
498
+ const rows = place && scopes.get(place.top);
499
+ if (!rows && folder)
500
+ void keptPlaceOf(folder)
501
+ .then((found) => found && indexTree(found.top))
502
+ .catch((error) => log(`context engine: ${error.message}`));
503
+ return rows ?? [];
504
+ };
505
+
490
506
  /** Search for the agents' tool: files and earlier sessions in a repository, best first. */
491
507
  const search = async ({ query, folder, limit = 10 }) => {
492
508
  const result = await pack({ brief: query, folder, lane: "interactive" });
@@ -513,8 +529,8 @@ export function createContextEngine({
513
529
  if (
514
530
  !force &&
515
531
  (Date.now() - last < LEARN_EVERY_MS ||
516
- !inference.power.onCharger() ||
517
- inference.power.paused())
532
+ !(await inference.power.onCharger()) ||
533
+ (await inference.power.paused()))
518
534
  )
519
535
  return null;
520
536
  await refresh();
@@ -629,15 +645,13 @@ export function createContextEngine({
629
645
  * A folder's files as last indexed ([{ path, blob }]); [] outside a repository, or before its first index, which
630
646
  * this starts. A task frame asks without waiting, and a run's pack has indexed its folder just before.
631
647
  */
632
- scope: (folder) => {
633
- const place = folder && keptPlaces.get(folder)?.place;
634
- const rows = place && scopes.get(place.top);
635
- if (!rows && folder)
636
- void keptPlaceOf(folder)
637
- .then((found) => found && indexTree(found.top))
638
- .catch((error) => log(`context engine: ${error.message}`));
639
- return rows ?? [];
640
- },
648
+ scope: scopeOf,
649
+ /**
650
+ * Files and code named in the person's words, resolved in a folder's files as last indexed (frames.mjs mentions):
651
+ * { files, symbols }.
652
+ */
653
+ mentions: (text, folder) =>
654
+ mentions(text, { scope: scopeOf(folder), atlas }),
641
655
  pack,
642
656
  search,
643
657
  /** The person's files and the threads' files closest to a question (library.mjs search). */
@@ -654,10 +668,10 @@ export function createContextEngine({
654
668
  return null;
655
669
  }
656
670
  },
657
- status: () => ({
671
+ status: async () => ({
658
672
  roots: atlas.roots(),
659
673
  pieces: { waiting: atlas.missing(ATLAS_VERSION) },
660
- library: library.status(),
674
+ library: await library.status(),
661
675
  model: model
662
676
  ? {
663
677
  trainedAt: model.trainedAt,
@@ -665,7 +679,7 @@ export function createContextEngine({
665
679
  runs: model.runs,
666
680
  }
667
681
  : null,
668
- device: inference.device(),
682
+ device: await inference.device(),
669
683
  }),
670
684
  start() {
671
685
  const tick = () => {
@@ -0,0 +1,199 @@
1
+ import {
2
+ Worker,
3
+ isMainThread,
4
+ parentPort,
5
+ workerData,
6
+ } from "node:worker_threads";
7
+ import { createContextEngine } from "./context.mjs";
8
+ import { portCalls } from "./portCalls.mjs";
9
+
10
+ // The context engine (context.mjs) in its own thread. Its atlas is a SQLite database of close to a gigabyte, read
11
+ // synchronously page by page; on the daemon's thread one context pack held every reply (the buddy opening a thread,
12
+ // T3's probe, the other computers' calls) for 10 to 60 s. Here the engine owns the atlas, its vectors and its search,
13
+ // and asks the daemon only for what the daemon owns: the store's sessions, the models (inference.mjs), the folders it
14
+ // knows, the firewall's mask, the log.
15
+ //
16
+ // Same interface as createContextEngine, except that every method returns a promise; report() answers at once with
17
+ // the learner's last report as of the previous call.
18
+
19
+ const ENTRY = "context-engine";
20
+ // A worker that dies is started again on the next call, at most this often.
21
+ const RESTART_MS = 10_000;
22
+
23
+ const asBuffer = (bytes) =>
24
+ bytes instanceof Uint8Array && !Buffer.isBuffer(bytes)
25
+ ? Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)
26
+ : bytes;
27
+
28
+ export function createContextWorker({
29
+ store,
30
+ inference,
31
+ home,
32
+ known,
33
+ libraryFolders = () => [],
34
+ threadFiles = () => [],
35
+ mediaReady = () => false,
36
+ wantMedia = () => {},
37
+ ocr = null,
38
+ mask,
39
+ log = () => {},
40
+ notify = () => {},
41
+ }) {
42
+ // What the engine asks the daemon for.
43
+ const served = {
44
+ sessionSources: (options) => store.sessionSources(options),
45
+ sessionTranscript: (agent, sessionId) =>
46
+ store.sessionTranscript(agent, sessionId),
47
+ embed: (items, options) => inference.embed(items, options),
48
+ embedMedia: (items, options) =>
49
+ inference.embedMedia(
50
+ items.map((item) => ({ ...item, data: asBuffer(item.data) })),
51
+ options
52
+ ),
53
+ paused: () => inference.power.paused(),
54
+ onCharger: () => inference.power.onCharger(),
55
+ device: () => inference.device(),
56
+ known: () => known(),
57
+ libraryFolders: () => libraryFolders(),
58
+ threadFiles: () => threadFiles(),
59
+ mediaReady: () => mediaReady(),
60
+ wantMedia: () => wantMedia(),
61
+ ocrRead: (data, options) => ocr.read(asBuffer(data), options),
62
+ mask: (text) => mask(text),
63
+ log: (line) => log(line),
64
+ notify: (text) => notify(text),
65
+ };
66
+
67
+ let worker = null;
68
+ let calls = null;
69
+ let started = false;
70
+ let stopping = false;
71
+ let lastStart = 0;
72
+ let lastReport = null;
73
+
74
+ const spawn = () => {
75
+ lastStart = Date.now();
76
+ const thread = new Worker(new URL(import.meta.url), {
77
+ workerData: { entry: ENTRY, home, ocr: Boolean(ocr) },
78
+ });
79
+ const own = portCalls(thread, served);
80
+ thread.on("error", (error) =>
81
+ log(`context engine: its thread failed: ${error.message}`)
82
+ );
83
+ thread.on("exit", (code) => {
84
+ own.fail("the context engine's thread stopped");
85
+ if (worker === thread) {
86
+ worker = null;
87
+ calls = null;
88
+ }
89
+ if (!stopping) log(`context engine: its thread exited (${code})`);
90
+ });
91
+ thread.unref();
92
+ worker = thread;
93
+ calls = own;
94
+ if (started) void own.call("start").catch(() => {});
95
+ void own.call("report").then(
96
+ (report) => (lastReport = report),
97
+ () => {}
98
+ );
99
+ };
100
+
101
+ const call = (name, ...args) => {
102
+ if (stopping)
103
+ return Promise.reject(new Error("the context engine has stopped"));
104
+ if (!calls) {
105
+ if (Date.now() - lastStart < RESTART_MS)
106
+ return Promise.reject(
107
+ new Error("the context engine's thread is restarting")
108
+ );
109
+ spawn();
110
+ }
111
+ return calls.call(name, ...args);
112
+ };
113
+
114
+ spawn();
115
+
116
+ return {
117
+ pack: (args) => call("pack", args),
118
+ search: (args) => call("search", args),
119
+ searchFiles: (query, options) => call("searchFiles", query, options),
120
+ refreshFiles: () => call("refreshFiles"),
121
+ fileContent: async (file, vec) => {
122
+ const found = await call("fileContent", file, vec);
123
+ return found?.data ? { ...found, data: asBuffer(found.data) } : found;
124
+ },
125
+ refresh: () => call("refresh"),
126
+ learn: async (options) => {
127
+ const report = await call("learn", options);
128
+ if (report) lastReport = report;
129
+ return report;
130
+ },
131
+ report: () => {
132
+ void call("report").then(
133
+ (report) => (lastReport = report),
134
+ () => {}
135
+ );
136
+ return lastReport;
137
+ },
138
+ status: () => call("status"),
139
+ mentions: (text, folder) => call("mentions", text, folder),
140
+ start() {
141
+ started = true;
142
+ void call("start").catch(() => {});
143
+ },
144
+ async stop() {
145
+ if (stopping) return;
146
+ await calls?.call("stop").catch(() => {});
147
+ stopping = true;
148
+ await worker?.terminate();
149
+ },
150
+ };
151
+ }
152
+
153
+ // The worker's side: the engine itself, its daemon-owned parts asked for across the port.
154
+ if (!isMainThread && workerData?.entry === ENTRY) {
155
+ const engineCalls = {};
156
+ const { call } = portCalls(parentPort, engineCalls);
157
+ const engine = createContextEngine({
158
+ store: {
159
+ sessionSources: (options) => call("sessionSources", options),
160
+ sessionTranscript: (agent, sessionId) =>
161
+ call("sessionTranscript", agent, sessionId),
162
+ },
163
+ inference: {
164
+ embed: (items, options) => call("embed", items, options),
165
+ embedMedia: (items, options) => call("embedMedia", items, options),
166
+ power: {
167
+ paused: () => call("paused"),
168
+ onCharger: () => call("onCharger"),
169
+ },
170
+ device: () => call("device"),
171
+ },
172
+ home: workerData.home,
173
+ known: () => call("known"),
174
+ libraryFolders: () => call("libraryFolders"),
175
+ threadFiles: () => call("threadFiles"),
176
+ mediaReady: () => call("mediaReady"),
177
+ wantMedia: () => void call("wantMedia").catch(() => {}),
178
+ ocr: workerData.ocr
179
+ ? { read: (data, options) => call("ocrRead", data, options) }
180
+ : null,
181
+ mask: (text) => call("mask", text),
182
+ log: (line) => void call("log", line).catch(() => {}),
183
+ notify: (text) => void call("notify", text).catch(() => {}),
184
+ });
185
+ Object.assign(engineCalls, {
186
+ pack: (args) => engine.pack(args),
187
+ search: (args) => engine.search(args),
188
+ searchFiles: (query, options) => engine.searchFiles(query, options),
189
+ refreshFiles: () => engine.refreshFiles(),
190
+ fileContent: (file, vec) => engine.fileContent(file, vec),
191
+ refresh: () => engine.refresh(),
192
+ learn: (options) => engine.learn(options),
193
+ report: () => engine.report(),
194
+ status: () => engine.status(),
195
+ mentions: (text, folder) => engine.mentions(text, folder),
196
+ start: () => engine.start(),
197
+ stop: () => engine.stop(),
198
+ });
199
+ }
@@ -386,7 +386,7 @@ export function createCoordinator({
386
386
  }
387
387
  }
388
388
  // The thread's task frame (frames.mjs): each run's receipt, other threads in the repository, its state.
389
- const framed = frame(thread.id);
389
+ const framed = await frame(thread.id);
390
390
  return {
391
391
  ...(framed ? { frame: framed } : {}),
392
392
  ...teamFacts,
@@ -637,6 +637,13 @@ export function createCoordinator({
637
637
  text,
638
638
  }),
639
639
  });
640
+ // When the person sent the message a round answers, or null.
641
+ const askedAt = (thread, asked) => {
642
+ const message = asked?.seq
643
+ ? store.roomPosts(thread.id, asked.seq - 1, 1)[0]
644
+ : null;
645
+ return message?.seq === asked?.seq ? message.created_at : null;
646
+ };
640
647
  const applyTeamPlan = (thread, decision, coordinator, asked = null) => {
641
648
  const proposed = decision.team?.plan;
642
649
  if (
@@ -646,15 +653,15 @@ export function createCoordinator({
646
653
  team.plan(thread.id)
647
654
  )
648
655
  return null;
649
- return team.set(
650
- thread.id,
651
- proposed,
652
- routeFor(thread, coordinator, asked?.named ?? [])
653
- );
656
+ // The route answers the person's message: its first step began when they sent it (team.mjs set).
657
+ return team.set(thread.id, proposed, {
658
+ ...routeFor(thread, coordinator, asked?.named ?? []),
659
+ since: askedAt(thread, asked),
660
+ });
654
661
  };
655
662
  // Where the work went: along the route to the step the round chose, on to the next piece as the round routed it, or,
656
663
  // handed outside the route, to the step of the agents who now have it.
657
- const moveTeam = (thread, decision, agents, coordinator) => {
664
+ const moveTeam = (thread, decision, agents, coordinator, givenAt) => {
658
665
  if (!keepsTeams()) return;
659
666
  const step = decision.team?.step;
660
667
  if (step === "piece")
@@ -668,7 +675,7 @@ export function createCoordinator({
668
675
  outcome: decision.team.outcome ?? null,
669
676
  head: headOf(thread.id),
670
677
  });
671
- else if (agents.length) team.acted(thread.id, agents);
678
+ else if (agents.length) team.acted(thread.id, agents, givenAt);
672
679
  };
673
680
  // The route ended this round (its last check passed, or its last step was done): kept before the goal is, so a goal
674
681
  // reached on the same round reads the check that passed.
@@ -794,8 +801,15 @@ export function createCoordinator({
794
801
  );
795
802
  if (!parts.length) {
796
803
  if (unheard) tellEveryone(thread, asked, null, { decided: true });
804
+ // The agents the person named had the work when they sent the message.
797
805
  else if (planned)
798
- moveTeam(thread, decision, asked?.named ?? [], coordinator);
806
+ moveTeam(
807
+ thread,
808
+ decision,
809
+ asked?.named ?? [],
810
+ coordinator,
811
+ askedAt(thread, asked) ?? undefined
812
+ );
799
813
  notifyBoard(store.getTask(thread.id));
800
814
  return;
801
815
  }
package/lib/daemon.mjs CHANGED
@@ -34,6 +34,8 @@ import { keepProfile } from "./profile.mjs";
34
34
  import { createSwarmMemory } from "./swarmMemory.mjs";
35
35
  import { createWorktrees } from "./worktrees.mjs";
36
36
  import { createLanded } from "./landed.mjs";
37
+ import { createOpenRequests } from "./openRequests.mjs";
38
+ import { openHere } from "./openHere.mjs";
37
39
  import { createFolders, repositoryName } from "./folders.mjs";
38
40
  import { createRepoLinks } from "./repoLinks.mjs";
39
41
  import { notifyDesktop } from "./notify.mjs";
@@ -1357,7 +1359,6 @@ export async function startDaemon() {
1357
1359
  pauseGoal: actions.pause,
1358
1360
  relayRequest: sealed.request,
1359
1361
  replaceHeld,
1360
- searchContext: local.searchContext,
1361
1362
  sendThreadMessage: sealed.sendMessage,
1362
1363
  setupNote,
1363
1364
  slotOf: (...args) => slotOf(...args),
@@ -1517,13 +1518,15 @@ export async function startDaemon() {
1517
1518
  store,
1518
1519
  environment,
1519
1520
  worktrees,
1520
- atlas: () => (local.ready(["search"]) ? local.contextEngine.atlas : null),
1521
- scope: (folder) => local.contextEngine.scope(folder),
1521
+ resolveNamed: (text, folder) =>
1522
+ local.ready(["search"]) && folder
1523
+ ? local.contextEngine.mentions(text, folder)
1524
+ : { files: [], symbols: [] },
1522
1525
  log,
1523
1526
  });
1524
- const frameFor = (threadId, options) => {
1527
+ const frameFor = async (threadId, options) => {
1525
1528
  try {
1526
- return frames.build(threadId, options);
1529
+ return await frames.build(threadId, options);
1527
1530
  } catch (error) {
1528
1531
  log(`task frame for ${threadId}: ${error.message}`);
1529
1532
  return null;
@@ -1722,9 +1725,9 @@ export async function startDaemon() {
1722
1725
  why,
1723
1726
  }),
1724
1727
  log,
1725
- frame: (threadId) =>
1728
+ frame: async (threadId) =>
1726
1729
  coordinatorMode() === "local" || bridge.has("swarm_frame")
1727
- ? frames.roundFacts(frameFor(threadId))
1730
+ ? frames.roundFacts(await frameFor(threadId))
1728
1731
  : null,
1729
1732
  });
1730
1733
  const guestRequests = createGuestRequests({
@@ -1868,6 +1871,38 @@ export async function startDaemon() {
1868
1871
  activeRuns: () => activeRuns.values(),
1869
1872
  scrub: (value) => vault.scrubDeep(value),
1870
1873
  });
1874
+ // Open, asked for by the person at another of their computers: planned here, carried out by this computer's buddy.
1875
+ const openRequests = createOpenRequests({
1876
+ plan: async (open) => {
1877
+ // A thread in this computer's T3 Code opens by T3's own link to it, read here.
1878
+ if (open.thread) {
1879
+ await environments.ready()?.catch(() => null);
1880
+ const thread = environments
1881
+ .roots()
1882
+ .find((root) => root.id === String(open.thread));
1883
+ return thread?.source?.url
1884
+ ? {
1885
+ ok: true,
1886
+ opensIn: thread.source.environmentName,
1887
+ link: thread.source.url,
1888
+ }
1889
+ : { ok: false, error: "that thread is not in T3 Code here" };
1890
+ }
1891
+ return liveCommand(
1892
+ {
1893
+ command: "board.live.focus",
1894
+ to: open.to,
1895
+ sessionId: open.sessionId ?? null,
1896
+ folder: open.folder ?? null,
1897
+ fresh: open.fresh === true,
1898
+ },
1899
+ "user"
1900
+ );
1901
+ },
1902
+ waits: boardWaits,
1903
+ openHere,
1904
+ log,
1905
+ });
1871
1906
 
1872
1907
  // Lid-Closed Mode's Standby: when anything last came in (a phone message, a wake, a new task).
1873
1908
  let listenerAt = Date.now();
@@ -1961,7 +1996,12 @@ export async function startDaemon() {
1961
1996
  places
1962
1997
  ? places.command(request, agent)
1963
1998
  : { ok: false, error: "the daemon is still starting" },
1964
- live: (request, { agent }) => liveCommand(request, agent),
1999
+ live: (request, { agent }) =>
2000
+ request.command !== "board.live.opens"
2001
+ ? liveCommand(request, agent)
2002
+ : agent === "user"
2003
+ ? openRequests.take()
2004
+ : { ok: false, error: "only the person's buddy opens things here" },
1965
2005
  prompt: (request, { agent }) => {
1966
2006
  // A session a run started is that run's, never one the person typed in.
1967
2007
  if (!request[RUN_CALLER]) authority.markPrompt(request.pids, agent);
@@ -2252,6 +2292,7 @@ export async function startDaemon() {
2252
2292
  });
2253
2293
  return result?.pending ? await result.pending : result;
2254
2294
  }
2295
+ if (live?.open) return openRequests.open(live.open);
2255
2296
  if (live?.read)
2256
2297
  return liveCommand(
2257
2298
  {
@@ -2723,6 +2764,11 @@ export async function startDaemon() {
2723
2764
  ? ownMachines.readSession(request)
2724
2765
  : { ok: false, error: "only the person reads their sessions" }
2725
2766
  ),
2767
+ "machines.live.open": onMachines((request) =>
2768
+ request.agent === "user"
2769
+ ? ownMachines.openSession(request)
2770
+ : { ok: false, error: "only the person opens their sessions" }
2771
+ ),
2726
2772
  "machines.model": onMachines((request) =>
2727
2773
  request.agent === "user"
2728
2774
  ? ownMachines.setModel(request)