tryharness 0.7.53 → 0.7.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +10 -5
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +115 -36
  5. package/lib/adapters.mjs +157 -222
  6. package/lib/agentRuntimes.mjs +26 -16
  7. package/lib/agentSignIn.mjs +226 -0
  8. package/lib/audit.mjs +643 -0
  9. package/lib/backupSetup.mjs +141 -0
  10. package/lib/boardAccess.mjs +8 -1
  11. package/lib/boardBackup.mjs +283 -0
  12. package/lib/boardMirror.mjs +71 -7
  13. package/lib/boardProtocol.json +59 -2
  14. package/lib/boardWaits.mjs +102 -0
  15. package/lib/book.mjs +659 -0
  16. package/lib/bridge.mjs +1 -1
  17. package/lib/cards.mjs +138 -28
  18. package/lib/cloudBoot.mjs +124 -0
  19. package/lib/commands.mjs +7 -2
  20. package/lib/context.mjs +18 -4
  21. package/lib/contractGate.mjs +377 -0
  22. package/lib/coordinator.mjs +149 -43
  23. package/lib/daemon.mjs +349 -28
  24. package/lib/desk.mjs +239 -0
  25. package/lib/desktop.mjs +106 -6
  26. package/lib/environments.mjs +237 -7
  27. package/lib/folders.mjs +2 -2
  28. package/lib/gitHost.mjs +174 -0
  29. package/lib/hookDialects.mjs +298 -0
  30. package/lib/landed.mjs +887 -0
  31. package/lib/live.mjs +284 -13
  32. package/lib/mcp-stdio.mjs +68 -2
  33. package/lib/members.json +16 -2
  34. package/lib/models.mjs +8 -8
  35. package/lib/museSession.mjs +16 -13
  36. package/lib/nativeHost.mjs +1 -1
  37. package/lib/neovim.mjs +126 -0
  38. package/lib/nudge.mjs +47 -16
  39. package/lib/ownMachines.mjs +343 -39
  40. package/lib/pairing.mjs +27 -10
  41. package/lib/paths.mjs +4 -0
  42. package/lib/personModel.mjs +89 -0
  43. package/lib/phones.mjs +66 -11
  44. package/lib/places.mjs +330 -10
  45. package/lib/readiness.mjs +135 -18
  46. package/lib/record.mjs +115 -0
  47. package/lib/runWorker.mjs +17 -2
  48. package/lib/runner.mjs +8 -4
  49. package/lib/sessionControl.mjs +377 -89
  50. package/lib/specialties.json +74 -0
  51. package/lib/specialties.mjs +477 -0
  52. package/lib/specialtyKeys.d.ts +3 -0
  53. package/lib/specialtyKeys.js +58 -0
  54. package/lib/specialtyNotice.mjs +147 -0
  55. package/lib/specialtySnapshot.mjs +138 -0
  56. package/lib/store.mjs +284 -1
  57. package/lib/swarm.mjs +137 -21
  58. package/lib/t3.mjs +13 -4
  59. package/lib/taskCommands.mjs +36 -9
  60. package/lib/taskRuns.mjs +9 -2
  61. package/lib/team.json +255 -148
  62. package/lib/team.mjs +529 -188
  63. package/lib/threadLine.mjs +116 -0
  64. package/lib/threadRuns.mjs +75 -11
  65. package/lib/threadView.mjs +15 -2
  66. package/lib/worktrees.mjs +51 -13
  67. package/package.json +4 -4
  68. package/lib/modelTiers.json +0 -1183
  69. package/lib/modelTiers.mjs +0 -133
package/lib/cards.mjs CHANGED
@@ -1,15 +1,16 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { member, nameOf } from "./members.mjs";
3
3
  import { agentModelInUse, describeAgentModel } from "./models.mjs";
4
- import { tierOf } from "./modelTiers.mjs";
4
+ import { offices, pins, specialtiesOf } from "./specialties.mjs";
5
5
  import { oneLine } from "./oneLine.mjs";
6
6
 
7
7
  // Each of the person's agents as the others see it: one card, written the same way for every reader (the block an agent
8
8
  // is told when its session starts, list_agents, a thread's brief, the coordinator's round), so work goes to the agent
9
9
  // that fits. The roster says what it is for, what it cannot do, where it runs and whether it can review without changing
10
- // files; this machine adds its model (the person's choice in the relay, else the one its own settings name), how its
11
- // work on this board went, what it holds now, when it last looked, and the person's own note. Facts only: nothing here
12
- // says one agent is better than another.
10
+ // files; this machine adds its model and effort (the person's choice in the relay, else what its own settings name), its
11
+ // specialties with their evidence (specialties.mjs), the specialties the person pinned it for and the offices it holds,
12
+ // how its work on this board went, what it holds now, when it last looked, and the person's own note. Facts only:
13
+ // nothing here says one agent is better than another.
13
14
 
14
15
  // How a member hears that work is waiting for it: how it is set up to be woken (its setup from the daemon, { state, how }),
15
16
  // else its roster wake.
@@ -32,12 +33,21 @@ export const answersFor = (entry) =>
32
33
  const NOTE_LIMIT = 300;
33
34
  const noteKey = (id) => `agent-note:${id}`;
34
35
  export const noteOf = (store, id) => store.meta(noteKey(id)) || null;
35
- /** The tier the person set for an agent (top, middle or bottom), or null for the benchmark's. */
36
- export const tierChoice = (store, id) =>
37
- store.meta(`tier-choice:${id}`) || null;
38
- export function setTier(store, id, tier) {
39
- store.meta(`tier-choice:${id}`, tier ?? "");
40
- return tier ?? null;
36
+
37
+ /** An agent's specialties on the model and effort it runs on now (the person's choice, Auto, or its own settings). */
38
+ export function agentSpecialties(store, id, home) {
39
+ const roster = member(id) ?? {};
40
+ const inUse =
41
+ roster.runs === "machine" || id === "harness"
42
+ ? agentModelInUse(store, id, home)
43
+ : {};
44
+ const model = inUse.model ?? null;
45
+ const effort = inUse.effort ?? null;
46
+ return {
47
+ model,
48
+ effort,
49
+ specialties: specialtiesOf(store, id, { model, effort, harness: id }),
50
+ };
41
51
  }
42
52
 
43
53
  /** The person's own words about one agent ("use it for reviews"); empty clears it. */
@@ -56,6 +66,27 @@ const median = (values) => {
56
66
  return sorted.length ? sorted[Math.floor(sorted.length / 2)] : null;
57
67
  };
58
68
 
69
+ // A card's specialties, pins and offices as a coordinator round carries them (src/server/swarm/coordinator.ts
70
+ // Candidate): ids for pins and offices, each specialty without its name, which the server takes from the same list.
71
+ const roundSpecialty = (view) => ({
72
+ id: view.id,
73
+ source: view.source,
74
+ primary: view.primary,
75
+ evidence: view.evidence.slice(0, 300),
76
+ record: view.record
77
+ ? {
78
+ accepted: view.record.accepted,
79
+ rejected: view.record.rejected,
80
+ judged: view.record.judged,
81
+ }
82
+ : null,
83
+ });
84
+ export const roundFields = (card) => ({
85
+ specialties: card.specialties?.map(roundSpecialty),
86
+ pinned: card.pinned?.map((pin) => pin.id),
87
+ offices: card.offices?.map((office) => office.id),
88
+ });
89
+
59
90
  /** Cards for the given roster entries ({ id, setup? }), in their order. A card's setup is its state alone ("not_set_up"). */
60
91
  // `lessons`: what the person has said about each agent (lessons.mjs), left off a card going to a caller off this computer.
61
92
  export function swarmCards(store, entries, { home, lessons = true } = {}) {
@@ -95,6 +126,8 @@ export function swarmCards(store, entries, { home, lessons = true } = {}) {
95
126
  const checks = store.receiptCounts?.() ?? {};
96
127
  // The person's verdicts on its work (reactions.mjs; a store from before reactions has none).
97
128
  const verdicts = store.verdictCounts?.() ?? {};
129
+ const pinned = pins(store);
130
+ const held = offices(store);
98
131
  return entries.map((entry) => {
99
132
  const roster = member(entry.id) ?? {};
100
133
  const done = work.get(entry.id) ?? {
@@ -120,13 +153,14 @@ export function swarmCards(store, entries, { home, lessons = true } = {}) {
120
153
  : entry.id === "harness" && describeAgentModel(store, entry.id, home)
121
154
  ? { model: describeAgentModel(store, entry.id, home) }
122
155
  : {}),
123
- // How strong its model is, for the roles with a floor (team.json): the person's tier for it, else the benchmark's.
124
- tier: tierOf({
125
- ...(roster.runs === "machine" || entry.id === "harness"
126
- ? agentModelInUse(store, entry.id, home)
127
- : {}),
128
- chosen: tierChoice(store, entry.id),
129
- }),
156
+ // What it is shown to do well on its model, each with its evidence, primary first.
157
+ specialties: agentSpecialties(store, entry.id, home).specialties,
158
+ pinned: pinned
159
+ .filter((pin) => pin.agent === entry.id)
160
+ .map((pin) => ({ id: pin.specialty, name: pin.name })),
161
+ offices: held
162
+ .filter((office) => office.holder === entry.id)
163
+ .map((office) => ({ id: office.id, name: office.name })),
130
164
  answers: answersFor(entry),
131
165
  record: {
132
166
  done: done.done,
@@ -160,8 +194,48 @@ const span = (minutes) =>
160
194
  const sentence = (text) =>
161
195
  `${text.charAt(0).toUpperCase()}${text.slice(1)}${/[.!?]$/.test(text) ? "" : "."}`;
162
196
 
163
- /** One card as one line of plain text. */
164
- export function cardLine(card, now = Date.now()) {
197
+ const names = (entries) => entries.map((entry) => entry.name).join(", ");
198
+
199
+ /**
200
+ * What a card says of an agent's specialties, the specialties the person pinned it for and the offices it holds.
201
+ * `evidence`: each specialty with where it comes from (list_agents), else its name alone (a session start).
202
+ */
203
+ export function specialtiesLine(card, { evidence = true } = {}) {
204
+ const views = card.specialties;
205
+ if (!views) return "";
206
+ const parts = [];
207
+ if (!views.length)
208
+ parts.push(
209
+ !evidence
210
+ ? "No specialties yet."
211
+ : card.model
212
+ ? "No specialties yet: none from the benchmarks Harness tracks for its model, and no record here."
213
+ : "No specialties yet: no record here, and the person has added none."
214
+ );
215
+ else {
216
+ const shown = (view) =>
217
+ evidence && view.evidence ? `${view.name} (${view.evidence})` : view.name;
218
+ const primary = views.find((view) => view.primary) ?? views[0];
219
+ const others = views.filter((view) => view !== primary);
220
+ parts.push(`Primary: ${shown(primary)}.`);
221
+ if (others.length) parts.push(`Also: ${others.map(shown).join(", ")}.`);
222
+ // Its earned specialties came with it from its last model; its record on this one starts over.
223
+ if (
224
+ views.some((view) => view.earnedOn) &&
225
+ !views.some((view) => view.record?.judged)
226
+ )
227
+ parts.push("New model, earning its record here.");
228
+ }
229
+ if (card.pinned?.length) parts.push(`Pinned: ${names(card.pinned)}.`);
230
+ if (card.offices?.length)
231
+ parts.push(
232
+ `${card.offices.length > 1 ? "Offices" : "Office"}: ${names(card.offices)}.`
233
+ );
234
+ return parts.join(" ");
235
+ }
236
+
237
+ /** One card as one line of plain text; `evidence: false` names its specialties without their evidence. */
238
+ export function cardLine(card, now = Date.now(), { evidence = true } = {}) {
165
239
  const parts = [`@${card.id} (${card.name}): ${sentence(card.about)}`];
166
240
  if (card.limits) parts.push(card.limits);
167
241
  if (card.review !== undefined)
@@ -170,11 +244,19 @@ export function cardLine(card, now = Date.now()) {
170
244
  ? "Can review without changing files."
171
245
  : "Has no review-only mode: its runs may change files."
172
246
  );
173
- // The model is read from the agent's own settings, so it is one line like every other agent-written field here.
174
- if (card.where)
175
- parts.push(
176
- `Runs ${card.where}${card.model ? `, model ${oneLine(card.model)}` : ""}.`
177
- );
247
+ // The model and effort are read from the agent's own settings, so they are one line like every other agent-written
248
+ // field here. A setting that names an effort and no model says the effort alone.
249
+ if (card.where) {
250
+ const model = card.model ? oneLine(card.model) : "";
251
+ const named = !model
252
+ ? ""
253
+ : model.startsWith("effort ")
254
+ ? `, ${model}`
255
+ : `, model ${model}`;
256
+ parts.push(`Runs ${card.where}${named}.`);
257
+ }
258
+ const specialties = specialtiesLine(card, { evidence });
259
+ if (specialties) parts.push(specialties);
178
260
  if (card.machines?.length)
179
261
  parts.push(
180
262
  `On the person's computers: ${card.machines.map((computer) => `${card.name} (${computer.label}${computer.online ? "" : ", offline"})`).join(", ")}; name one with target_machine.`
@@ -220,7 +302,9 @@ export function cardLine(card, now = Date.now()) {
220
302
  /** One card in short form, for a session start short of room: who it is and what it is for. list_agents has the rest. */
221
303
  export function shortCardLine(card) {
222
304
  const unset = card.setup ? ` ${sentence(card.answers)}` : "";
223
- return `- @${card.id} (${card.name}): ${sentence(card.about)}${unset}`;
305
+ const primary = card.specialties?.find((view) => view.primary);
306
+ const known = primary ? ` Primary: ${primary.name}.` : "";
307
+ return `- @${card.id} (${card.name}): ${sentence(card.about)}${known}${unset}`;
224
308
  }
225
309
 
226
310
  /**
@@ -262,12 +346,20 @@ export const toldBlock = (told) =>
262
346
  ].join("\n")
263
347
  : "";
264
348
 
265
- /** The block an agent is told when its session starts: every other agent's card, and what the person has told the swarm. */
266
- export function swarmBlock(cards, now = Date.now(), told = []) {
349
+ /**
350
+ * Every other agent's card, and what the person has told the swarm: the block an agent is told when its session starts
351
+ * (`evidence: false`, specialties by name) and list_agents' text (each specialty with its evidence).
352
+ */
353
+ export function swarmBlock(
354
+ cards,
355
+ now = Date.now(),
356
+ told = [],
357
+ { evidence = true } = {}
358
+ ) {
267
359
  if (!cards.length) return toldBlock(told);
268
360
  return [
269
361
  SWARM_HEADER,
270
- ...cards.map((card) => cardLine(card, now)),
362
+ ...cards.map((card) => cardLine(card, now, { evidence })),
271
363
  ...(told.length ? ["", toldBlock(told)] : []),
272
364
  ].join("\n");
273
365
  }
@@ -291,6 +383,24 @@ export const swarmDigest = (cards, told = []) =>
291
383
  ...(card.machines ? [card.machines] : []),
292
384
  // Only when there are some, so a swarm with no lessons keeps the digest it had and is not told again.
293
385
  ...(card.lessons ? [card.lessons] : []),
386
+ // What it is good at, with each record, and the person's pins and appointments: agents are told again when
387
+ // any of it changes. Only when there are some, like the lessons.
388
+ ...(card.specialties?.length
389
+ ? [
390
+ card.specialties.map((view) => [
391
+ view.id,
392
+ view.source,
393
+ view.primary,
394
+ view.evidence,
395
+ ]),
396
+ ]
397
+ : []),
398
+ ...(card.pinned?.length
399
+ ? [card.pinned.map((pin) => `pin:${pin.id}`)]
400
+ : []),
401
+ ...(card.offices?.length
402
+ ? [card.offices.map((office) => `office:${office.id}`)]
403
+ : []),
294
404
  ])
295
405
  .concat(told.length ? [told.map((lesson) => lesson.text)] : [])
296
406
  )
@@ -0,0 +1,124 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { randomBytes } from "node:crypto";
4
+ import { spawnSync } from "node:child_process";
5
+ import { readJson, writeJsonAtomic } from "./files.mjs";
6
+
7
+ // A cloud computer's enrollment (docs/cloud-swarm.md §5.3), run as root by the harness-cloud service before the daemon
8
+ // starts (src/server/cloud/bootScript.ts). The boot script left the origin, this computer's id and a single-use
9
+ // bootstrap token in /etc/harness/boot.json; the box proves it is the server Harness made by sending that token with its
10
+ // own instance id, read from the provider's metadata service, and gets back its connection token, its role in the
11
+ // swarm, its join code (a worker) and the link offer the person's window pairs with. They are written into the
12
+ // harness user's ~/.harness exactly as setup writes them, so from here the daemon is the same as on any computer.
13
+ // After enrolling, the metadata service is closed to the harness user: it serves the boot script, token and all, to
14
+ // any local process, agents included.
15
+
16
+ const METADATA = "http://169.254.169.254/hetzner/v1/metadata/instance-id";
17
+ const METADATA_ADDRESS = "169.254.169.254";
18
+
19
+ const ownerOf = (dir) => {
20
+ const stat = fs.statSync(dir);
21
+ return { uid: stat.uid, gid: stat.gid };
22
+ };
23
+
24
+ function writeOwned(file, value, owner) {
25
+ writeJsonAtomic(file, value);
26
+ fs.chmodSync(file, 0o600);
27
+ if (owner && process.getuid?.() === 0)
28
+ fs.chownSync(file, owner.uid, owner.gid);
29
+ }
30
+
31
+ // Best effort: a container in tests has no iptables, and the rule does not survive a reboot, so it is put back on
32
+ // every start (the service runs this before each daemon start).
33
+ function closeMetadata(owner, log) {
34
+ if (!owner || process.getuid?.() !== 0) return;
35
+ const rule = [
36
+ "OUTPUT",
37
+ "-d",
38
+ METADATA_ADDRESS,
39
+ "-m",
40
+ "owner",
41
+ "--uid-owner",
42
+ String(owner.uid),
43
+ "-j",
44
+ "REJECT",
45
+ ];
46
+ const present = spawnSync("iptables", ["-C", ...rule], { stdio: "ignore" });
47
+ if (present.error)
48
+ return log("iptables is missing; the metadata service stays open");
49
+ if (present.status === 0) return;
50
+ const added = spawnSync("iptables", ["-I", ...rule], { stdio: "ignore" });
51
+ if (added.status !== 0)
52
+ log("could not close the metadata service to the harness user");
53
+ }
54
+
55
+ /**
56
+ * Enroll this cloud computer once; later starts find it enrolled and only close the metadata service again.
57
+ * home is the harness user's ~/.harness; its parent directory's owner is who the files belong to.
58
+ */
59
+ export async function cloudEnroll({
60
+ bootFile = "/etc/harness/boot.json",
61
+ home = "/home/harness/.harness",
62
+ metadataUrl,
63
+ fetchImpl = fetch,
64
+ log = (line) => console.log(`harness cloud: ${line}`),
65
+ } = {}) {
66
+ fs.mkdirSync(home, { recursive: true, mode: 0o700 });
67
+ const owner = ownerOf(path.dirname(home));
68
+ if (process.getuid?.() === 0) fs.chownSync(home, owner.uid, owner.gid);
69
+ const config = readJson(path.join(home, "config.json"), {});
70
+ if (config.origin && config.token) {
71
+ closeMetadata(owner, log);
72
+ return { ok: true, already: true };
73
+ }
74
+ const boot = readJson(bootFile, null);
75
+ if (!boot?.origin || !boot?.bootstrap)
76
+ throw new Error(`${bootFile} has no enrollment in it`);
77
+ const metadata = await fetchImpl(
78
+ metadataUrl || boot.instanceIdUrl || METADATA
79
+ );
80
+ if (!metadata.ok)
81
+ throw new Error(`the metadata service answered ${metadata.status}`);
82
+ const instanceId = (await metadata.text()).trim();
83
+ const response = await fetchImpl(
84
+ `${String(boot.origin).replace(/\/$/, "")}/api/cloud/enroll`,
85
+ {
86
+ method: "POST",
87
+ headers: { "content-type": "application/json" },
88
+ body: JSON.stringify({ bootstrap: boot.bootstrap, instanceId }),
89
+ }
90
+ );
91
+ const answer = await response.json().catch(() => ({}));
92
+ if (!response.ok)
93
+ throw new Error(
94
+ `Harness refused this computer (${response.status}): ${answer.error || "no reason given"}`
95
+ );
96
+ writeOwned(
97
+ path.join(home, "machine.json"),
98
+ {
99
+ id: randomBytes(16).toString("base64url"),
100
+ label: answer.label || "Cloud computer",
101
+ role: answer.role,
102
+ ...(answer.joinCode ? { joinCode: answer.joinCode } : {}),
103
+ },
104
+ owner
105
+ );
106
+ writeOwned(path.join(home, "cloud.json"), { link: answer.link }, owner);
107
+ // Written last: a config with a token is what marks this computer enrolled.
108
+ writeOwned(
109
+ path.join(home, "config.json"),
110
+ { origin: answer.origin, token: answer.token, cloud: true },
111
+ owner
112
+ );
113
+ log(`enrolled as ${answer.role === "home" ? "home" : "a worker"}`);
114
+ closeMetadata(owner, log);
115
+ return { ok: true, role: answer.role };
116
+ }
117
+
118
+ /** The seeded link offer a cloud computer's daemon keeps for the person's windows, or null on any other computer. */
119
+ export function cloudLinkOffer(file) {
120
+ const link = readJson(file, null)?.link;
121
+ return typeof link?.offerId === "string" && typeof link?.secret === "string"
122
+ ? { offerId: link.offerId, secret: link.secret }
123
+ : null;
124
+ }
package/lib/commands.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { spawnSync } from "node:child_process";
4
- import { MEMBERS } from "./members.mjs";
4
+ import { MEMBERS, member } from "./members.mjs";
5
5
  import { runtimeOf } from "./agentRuntimeConfig.mjs";
6
6
 
7
7
  export function resolveCommand(command, env = process.env) {
@@ -72,9 +72,14 @@ export const AGENT_COMMANDS = {
72
72
  ),
73
73
  };
74
74
 
75
+ // An agent whose protocol server is a download of its own (Antigravity's ACP server) is still found by the command the
76
+ // person runs (its member's `cli`), so setup connects their own sessions.
75
77
  export function detectAgents() {
76
78
  return Object.entries(AGENT_COMMANDS).map(([agent, defaultCommand]) => {
77
79
  const command = runtimeOf(agent)?.command || defaultCommand;
78
- return { agent, command, path: resolveCommand(command) };
80
+ const found = resolveCommand(command);
81
+ const cli = member(agent)?.cli;
82
+ if (found || !cli) return { agent, command, path: found };
83
+ return { agent, command: cli, path: resolveCommand(cli) };
79
84
  });
80
85
  }
package/lib/context.mjs CHANGED
@@ -35,6 +35,8 @@ const PACK_FILES = 8;
35
35
  const POOL = 60;
36
36
  const HISTORY_DAYS = 60;
37
37
  const REFRESH_MS = 15 * 60_000;
38
+ // How long the background pass trusts which repository a folder is in; a new repository joins on the next asking.
39
+ const PLACE_KEPT_MS = 60 * 60_000;
38
40
  const LEARN_EVERY_MS = 20 * 3_600_000;
39
41
  // Vectors of the pieces packs search stay in memory while packs are being made, and go after this long without one.
40
42
  const VECTORS_IDLE_MS = 5 * 60_000;
@@ -212,11 +214,22 @@ export function createContextEngine({
212
214
  : repo.root;
213
215
  return { root, top: repo.root };
214
216
  };
217
+ // The background pass keeps each folder's place for a while: asking git blocks the daemon, and the pass asked three
218
+ // times for each of 683 sessions every 15 minutes, holding everything else (T3, the buddy, hooks) for up to 11 s
219
+ // (October 23, .harness-runs/measure/t3-probe). A brief's pack still asks fresh.
220
+ const keptPlaces = new Map();
221
+ const keptPlaceOf = (folder) => {
222
+ const kept = keptPlaces.get(folder);
223
+ if (kept && Date.now() - kept.at < PLACE_KEPT_MS) return kept.place;
224
+ const place = placeOf(folder);
225
+ keptPlaces.set(folder, { place, at: Date.now() });
226
+ return place;
227
+ };
215
228
 
216
229
  const roots = () => [
217
230
  ...new Set(
218
231
  known()
219
- .map((place) => placeOf(place.path)?.root)
232
+ .map((place) => keptPlaceOf(place.path)?.root)
220
233
  .filter(Boolean)
221
234
  ),
222
235
  ];
@@ -237,14 +250,15 @@ export function createContextEngine({
237
250
  const trees = new Map();
238
251
  let added = 0;
239
252
  for (const session of store.sessionSources({ since })) {
240
- const place = placeOf(session.cwd);
241
- if (!place || !rootList.includes(place.root)) continue;
242
253
  // A session whose source file the agent has since deleted is read from the relay's own copy, once.
243
254
  let mtime = 0;
244
255
  try {
245
256
  mtime = fs.statSync(session.source).mtimeMs;
246
257
  } catch {}
258
+ // Seen as it is now: nothing to read, and no need to ask git where it ran.
247
259
  if (atlas.runSeen(session.agent, session.session_id) === mtime) continue;
260
+ const place = keptPlaceOf(session.cwd);
261
+ if (!place || !rootList.includes(place.root)) continue;
248
262
  const trail = mtime
249
263
  ? await readTrail(session.agent, session.source)
250
264
  : trailFromTranscript(
@@ -267,7 +281,7 @@ export function createContextEngine({
267
281
  {
268
282
  ...trail,
269
283
  cwd:
270
- trail.cwd && placeOf(trail.cwd)?.top === place.top
284
+ trail.cwd && keptPlaceOf(trail.cwd)?.top === place.top
271
285
  ? path.join(place.root, path.relative(place.top, trail.cwd))
272
286
  : trail.cwd,
273
287
  },