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/cli.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn, spawnSync } from "node:child_process";
3
+ import { validateConnection as checkConnection } from "./lib/connection.mjs";
3
4
  import fs from "node:fs";
4
5
  import os from "node:os";
5
6
  import path from "node:path";
@@ -125,36 +126,6 @@ function origin() {
125
126
  ).replace(/\/$/, "");
126
127
  }
127
128
 
128
- async function validateConnection(config) {
129
- if (!config.origin || !config.token) return false;
130
- try {
131
- const response = await fetch(
132
- String(config.origin).replace(/\/$/, "") + "/api/mcp",
133
- {
134
- method: "POST",
135
- headers: {
136
- "content-type": "application/json",
137
- authorization: "Bearer " + config.token,
138
- },
139
- body: JSON.stringify({
140
- jsonrpc: "2.0",
141
- id: 1,
142
- method: "initialize",
143
- params: {
144
- protocolVersion: "2025-06-18",
145
- capabilities: {},
146
- clientInfo: { name: "tryharness", version: VERSION },
147
- },
148
- }),
149
- signal: AbortSignal.timeout(10_000),
150
- }
151
- );
152
- return response.ok && !(await response.json().catch(() => null))?.error;
153
- } catch {
154
- return false;
155
- }
156
- }
157
-
158
129
  // Whether a browser can open here: not over SSH, and on Linux only with a display.
159
130
  const canOpenBrowser = () =>
160
131
  !process.env.SSH_CONNECTION &&
@@ -272,14 +243,19 @@ async function connect() {
272
243
 
273
244
  const pairOrigin = origin();
274
245
  let config = readJson(paths.config, {});
275
- const reusable =
276
- !has("--reconnect") &&
277
- config.origin === pairOrigin &&
278
- (await validateConnection(config));
279
- if (reusable)
246
+ const connection =
247
+ !has("--reconnect") && config.origin === pairOrigin
248
+ ? await checkConnection(config, { version: VERSION })
249
+ : "rejected";
250
+ const reusable = connection !== "rejected";
251
+ if (connection === "ok")
280
252
  ui.success(
281
253
  `Connected to Harness ${pc.dim(`· ${new URL(pairOrigin).host}`)}`
282
254
  );
255
+ else if (connection === "unreachable")
256
+ ui.warn(
257
+ `Harness did not answer just now, so this computer keeps its connection ${pc.dim(`· ${new URL(pairOrigin).host}`)}. If it really stopped working: ${relayCommand()} --reconnect`
258
+ );
283
259
  let setupCode = null;
284
260
  let linkOffered = false;
285
261
  if (!reusable) {
@@ -696,7 +672,7 @@ async function doctor() {
696
672
  console.log(`tryharness ${VERSION}`);
697
673
  const config = readJson(paths.config, {});
698
674
  console.log(
699
- `pairing: ${(await validateConnection(config)) ? "valid" : "missing or invalid"}`
675
+ `pairing: ${{ ok: "valid", rejected: "missing or invalid", unreachable: "kept (Harness did not answer)" }[await checkConnection(config, { version: VERSION })]}`
700
676
  );
701
677
  const service = serviceInfo();
702
678
  console.log(
@@ -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();
@@ -0,0 +1,39 @@
1
+ // Whether this computer's saved connection still works: "ok", "rejected" when Harness refuses its token (setup pairs
2
+ // again), or "unreachable" when Harness did not answer at all (a network blip, a timeout, a server error). An
3
+ // unreachable Harness keeps the connection: setup once opened the Connect page because a fetch failed for a moment
4
+ // (owner, October 28: "why did i get another connect prompt").
5
+ export async function validateConnection(
6
+ config,
7
+ { version, fetchImpl = fetch } = {}
8
+ ) {
9
+ if (!config.origin || !config.token) return "rejected";
10
+ let response;
11
+ try {
12
+ response = await fetchImpl(
13
+ String(config.origin).replace(/\/$/, "") + "/api/mcp",
14
+ {
15
+ method: "POST",
16
+ headers: {
17
+ "content-type": "application/json",
18
+ authorization: "Bearer " + config.token,
19
+ },
20
+ body: JSON.stringify({
21
+ jsonrpc: "2.0",
22
+ id: 1,
23
+ method: "initialize",
24
+ params: {
25
+ protocolVersion: "2025-06-18",
26
+ capabilities: {},
27
+ clientInfo: { name: "tryharness", version },
28
+ },
29
+ }),
30
+ signal: AbortSignal.timeout(10_000),
31
+ }
32
+ );
33
+ } catch {
34
+ return "unreachable";
35
+ }
36
+ if (response.status === 401 || response.status === 403) return "rejected";
37
+ if (!response.ok) return "unreachable";
38
+ return (await response.json().catch(() => null))?.error ? "rejected" : "ok";
39
+ }
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
  }