tryharness 0.7.53 → 0.7.57

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 (167) hide show
  1. package/README.md +23 -19
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +484 -90
  5. package/lib/activity.mjs +10 -10
  6. package/lib/adapters.mjs +173 -222
  7. package/lib/agentBinaries.mjs +71 -0
  8. package/lib/agentRuntimeConfig.mjs +1 -1
  9. package/lib/agentRuntimes.mjs +34 -18
  10. package/lib/agentSignIn.mjs +456 -0
  11. package/lib/answers.mjs +5 -5
  12. package/lib/archetypes.d.ts +64 -0
  13. package/lib/archetypes.js +989 -0
  14. package/lib/asks.mjs +4 -4
  15. package/lib/audit.mjs +666 -0
  16. package/lib/backupSetup.mjs +143 -0
  17. package/lib/boardAccess.mjs +24 -11
  18. package/lib/boardBackup.mjs +283 -0
  19. package/lib/boardFileCommands.mjs +6 -6
  20. package/lib/boardFiles.mjs +13 -12
  21. package/lib/boardMirror.mjs +124 -25
  22. package/lib/boardProtocol.json +88 -2
  23. package/lib/boardWaits.mjs +101 -0
  24. package/lib/book.mjs +659 -0
  25. package/lib/bridge.mjs +6 -6
  26. package/lib/cards.mjs +138 -28
  27. package/lib/cloudAgents.mjs +216 -0
  28. package/lib/cloudAi.mjs +1312 -0
  29. package/lib/cloudAssistants.mjs +242 -0
  30. package/lib/cloudBoot.mjs +119 -0
  31. package/lib/cloudSave.mjs +197 -0
  32. package/lib/cloudSsh.mjs +178 -0
  33. package/lib/commands.mjs +7 -2
  34. package/lib/context.mjs +19 -5
  35. package/lib/contractGate.mjs +399 -0
  36. package/lib/control-client.mjs +9 -1
  37. package/lib/controlSocket.mjs +86 -0
  38. package/lib/coordinator.mjs +252 -144
  39. package/lib/daemon.mjs +1351 -2767
  40. package/lib/desk.mjs +240 -0
  41. package/lib/desktop.mjs +178 -74
  42. package/lib/directLink.mjs +16 -5
  43. package/lib/environment.mjs +2 -1
  44. package/lib/environments.mjs +247 -9
  45. package/lib/firewall.mjs +9 -9
  46. package/lib/folders.mjs +20 -16
  47. package/lib/frames.mjs +2 -3
  48. package/lib/gitHost.mjs +174 -0
  49. package/lib/goalCommands.mjs +25 -7
  50. package/lib/goals.mjs +7 -7
  51. package/lib/guestRequests.mjs +94 -0
  52. package/lib/handoffs.mjs +8 -7
  53. package/lib/handover.mjs +4 -4
  54. package/lib/harnessModel.mjs +6 -6
  55. package/lib/harnessOffers.mjs +266 -0
  56. package/lib/hookDialects.mjs +298 -0
  57. package/lib/inference.mjs +26 -8
  58. package/lib/jobAnswers.mjs +190 -0
  59. package/lib/landed.mjs +887 -0
  60. package/lib/lane.mjs +42 -11
  61. package/lib/lessons.mjs +16 -16
  62. package/lib/library.mjs +3 -3
  63. package/lib/lineup.mjs +3 -0
  64. package/lib/linkRelay.mjs +574 -0
  65. package/lib/live.mjs +284 -13
  66. package/lib/localAgentAsk.mjs +74 -0
  67. package/lib/localStack.mjs +536 -0
  68. package/lib/localmodels.mjs +6 -4
  69. package/lib/loopBackstop.mjs +4 -4
  70. package/lib/machineIdentity.mjs +9 -1
  71. package/lib/machineRoutes.mjs +181 -2
  72. package/lib/machineRuns.mjs +76 -1
  73. package/lib/machineSeal.mjs +39 -12
  74. package/lib/mcp-stdio.mjs +163 -27
  75. package/lib/mcpRelay.mjs +1 -1
  76. package/lib/members.json +29 -2
  77. package/lib/members.mjs +1 -1
  78. package/lib/models.mjs +85 -31
  79. package/lib/museSession.mjs +21 -13
  80. package/lib/nativeHost.mjs +36 -8
  81. package/lib/neovim.mjs +126 -0
  82. package/lib/network.mjs +50 -5
  83. package/lib/notify.mjs +7 -5
  84. package/lib/nudge.mjs +50 -19
  85. package/lib/ocr.mjs +9 -9
  86. package/lib/onboard.mjs +26 -20
  87. package/lib/oneLine.mjs +7 -7
  88. package/lib/ownMachines.mjs +1223 -140
  89. package/lib/pairing.mjs +60 -16
  90. package/lib/paths.mjs +19 -1
  91. package/lib/peerProcess.mjs +124 -0
  92. package/lib/personModel.mjs +89 -0
  93. package/lib/personNotices.mjs +151 -0
  94. package/lib/phones.mjs +538 -31
  95. package/lib/placeCommands.mjs +4 -4
  96. package/lib/places.mjs +400 -12
  97. package/lib/profile.mjs +67 -14
  98. package/lib/projectGit.mjs +158 -14
  99. package/lib/projectPieces.mjs +902 -0
  100. package/lib/projectSettings.mjs +7 -4
  101. package/lib/projects.mjs +384 -62
  102. package/lib/provenance.mjs +5 -1
  103. package/lib/proxyLinks.mjs +267 -0
  104. package/lib/reactions.mjs +7 -5
  105. package/lib/readiness.mjs +145 -23
  106. package/lib/record.mjs +128 -0
  107. package/lib/redact.mjs +4 -4
  108. package/lib/relayLimits.mjs +62 -0
  109. package/lib/release.mjs +170 -0
  110. package/lib/releaseKeys.json +6 -0
  111. package/lib/repoLinks.mjs +4 -4
  112. package/lib/roomChannels.mjs +24 -0
  113. package/lib/roomPage.mjs +1 -1
  114. package/lib/runAuthority.mjs +101 -0
  115. package/lib/runBrief.mjs +19 -8
  116. package/lib/runWorker.mjs +31 -7
  117. package/lib/runner.mjs +223 -29
  118. package/lib/runtime-install.mjs +143 -9
  119. package/lib/schedules.mjs +2 -2
  120. package/lib/screens.mjs +1 -1
  121. package/lib/sealed.mjs +11 -2
  122. package/lib/sealedThreads.mjs +671 -0
  123. package/lib/secretPatterns.json +1 -1
  124. package/lib/secrets.mjs +4 -4
  125. package/lib/seen.mjs +6 -6
  126. package/lib/serverWords.mjs +175 -0
  127. package/lib/service.mjs +22 -12
  128. package/lib/sessionControl.mjs +378 -90
  129. package/lib/specialties.json +74 -0
  130. package/lib/specialties.mjs +477 -0
  131. package/lib/specialtyKeys.d.ts +3 -0
  132. package/lib/specialtyKeys.js +57 -0
  133. package/lib/specialtyNotice.mjs +147 -0
  134. package/lib/specialtySnapshot.mjs +138 -0
  135. package/lib/speech.mjs +5 -5
  136. package/lib/store.mjs +420 -36
  137. package/lib/stuck.mjs +1 -1
  138. package/lib/swarm.mjs +304 -37
  139. package/lib/swarmDevices.mjs +319 -0
  140. package/lib/swarmMemory.mjs +27 -25
  141. package/lib/t3.mjs +24 -15
  142. package/lib/taskCommands.mjs +80 -20
  143. package/lib/taskRooms.mjs +125 -0
  144. package/lib/taskRuns.mjs +45 -3
  145. package/lib/team.json +255 -148
  146. package/lib/team.mjs +554 -190
  147. package/lib/threadActions.mjs +315 -0
  148. package/lib/threadAuthority.mjs +101 -0
  149. package/lib/threadBriefs.mjs +178 -0
  150. package/lib/threadLine.mjs +116 -0
  151. package/lib/threadRuns.mjs +209 -50
  152. package/lib/threadView.mjs +20 -7
  153. package/lib/usageTotals.mjs +2 -3
  154. package/lib/vault.mjs +101 -10
  155. package/lib/vaultCloud.mjs +2 -2
  156. package/lib/vaultCommands.mjs +15 -6
  157. package/lib/vaultTools.js +2 -2
  158. package/lib/verdicts.mjs +328 -0
  159. package/lib/wakes.mjs +1 -1
  160. package/lib/watches.mjs +2 -2
  161. package/lib/windowAsks.mjs +13 -5
  162. package/lib/worktrees.mjs +157 -25
  163. package/npm-shrinkwrap.json +1093 -0
  164. package/package.json +12 -11
  165. package/release.json +220 -0
  166. package/lib/modelTiers.json +0 -1183
  167. package/lib/modelTiers.mjs +0 -133
@@ -1,9 +1,9 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { paths } from "./paths.mjs";
4
- import { runningPids } from "./runner.mjs";
4
+ import { runningPids, runningProcesses } from "./runner.mjs";
5
5
  import { PROCESS_NAMES, nativeSessionId } from "./swarm.mjs";
6
- import { nameOf } from "./members.mjs";
6
+ import { member, nameOf } from "./members.mjs";
7
7
  import {
8
8
  LIVE_AGENTS,
9
9
  focusTerminal,
@@ -13,24 +13,29 @@ import {
13
13
  processTable,
14
14
  sessionFeed,
15
15
  sessionFile,
16
+ starterIn,
16
17
  workingDirectories,
17
18
  } from "./live.mjs";
18
19
  import {
19
20
  EDITOR_IDS,
20
21
  agentCommand,
22
+ backgroundOf,
21
23
  editorFolder,
22
24
  editorInstall,
23
25
  editorName,
24
26
  editorRunsOpenTasks,
25
27
  editorSessionWorkspace,
26
28
  editorTerminalStarts,
29
+ isTerminalApp,
27
30
  openEditorFolder,
28
31
  panelLink,
32
+ panelLists,
29
33
  placeEnv,
30
34
  placeFrom,
31
35
  placeKey,
32
36
  processEnv,
33
37
  resumeLine,
38
+ setupTerminal,
34
39
  t3App,
35
40
  t3Link,
36
41
  t3OpensLinks,
@@ -38,8 +43,11 @@ import {
38
43
  t3Runs,
39
44
  t3Thread,
40
45
  t3ThreadIn,
46
+ terminalSessions,
41
47
  } from "./places.mjs";
48
+ import { resumeInNeovim, showInNeovim } from "./neovim.mjs";
42
49
  import { detectAgentApps, detectMcpClients } from "./adapters.mjs";
50
+ import { resolveCommand } from "./commands.mjs";
43
51
  import { handedToT3, sendToT3, t3Access } from "./t3.mjs";
44
52
 
45
53
  export function createSessionControl({
@@ -59,7 +67,7 @@ export function createSessionControl({
59
67
  return [];
60
68
  }
61
69
  };
62
- const CODING_AGENTS = ["claude-code", "codex", "pi", "opencode"];
70
+ const CODING_AGENTS = LIVE_AGENTS;
63
71
  const SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
64
72
  const folderOf = (request) =>
65
73
  typeof request.folder === "string" && path.isAbsolute(request.folder)
@@ -70,13 +78,20 @@ export function createSessionControl({
70
78
  // its environment (board.live.place), else it is read here from the running process. Thirty days of them, per agent.
71
79
  const PLACE_MS = 30 * 24 * 3600_000;
72
80
  const placeCache = new Map();
81
+ const harnessFolder = (folder) =>
82
+ Boolean(folder && folder.startsWith(paths.home + path.sep));
73
83
  const placesOf = (agentId) => {
74
84
  if (!placeCache.has(agentId)) {
75
85
  let found = {};
76
86
  try {
77
87
  found = JSON.parse(store.meta(`places:${agentId}`) || "{}");
78
88
  } catch {}
79
- placeCache.set(agentId, found);
89
+ // Sessions in Harness's own folders, kept before notePlace refused them, would still outvote where the person
90
+ // works for thirty days.
91
+ const theirs = Object.entries(found).filter(
92
+ ([, place]) => !harnessFolder(place?.folder)
93
+ );
94
+ placeCache.set(agentId, Object.fromEntries(theirs));
80
95
  }
81
96
  return placeCache.get(agentId);
82
97
  };
@@ -87,12 +102,22 @@ export function createSessionControl({
87
102
  return [];
88
103
  }
89
104
  };
105
+ // The scan of running sessions places any it finds, Harness's own sign-in checks too, and a check started from the
106
+ // Harness app was counted as the agent working in Harness: its home moved there and its runs left T3 Code.
90
107
  const notePlace = (agentId, sessionId, place) => {
91
- if (!place || !SESSION_ID.test(sessionId)) return;
108
+ if (!place || !SESSION_ID.test(sessionId) || harnessFolder(place.folder))
109
+ return;
92
110
  const places = placesOf(agentId);
93
111
  const now = Date.now();
94
112
  const before = places[sessionId];
95
- const next = { ...place, at: before?.at ?? now, seen: now };
113
+ // Who started it, once known, stays known: a later report may come after its starter ended.
114
+ const startedBy = place.startedBy ?? before?.startedBy;
115
+ const next = {
116
+ ...place,
117
+ ...(startedBy ? { startedBy } : {}),
118
+ at: before?.at ?? now,
119
+ seen: now,
120
+ };
96
121
  // The same place, already seen today: nothing worth a write.
97
122
  if (
98
123
  before &&
@@ -117,8 +142,76 @@ export function createSessionControl({
117
142
  };
118
143
  /** A run Harness started itself (in its own folders, or a process it runs) is not where the person works. */
119
144
  const harnessRun = (folder, pids = []) =>
120
- Boolean(folder && folder.startsWith(paths.home + path.sep)) ||
121
- pids.some((pid) => runningPids().includes(pid));
145
+ harnessFolder(folder) || pids.some((pid) => runningPids().includes(pid));
146
+ /** The sessions that named their own process when they started (pi's extension, OpenCode's plugin, hooks). */
147
+ const reportedSessions = () =>
148
+ LIVE_AGENTS.flatMap((agentId) =>
149
+ Object.entries(placesOf(agentId))
150
+ .filter(([, place]) => Number.isInteger(place.pid))
151
+ .map(([sessionId, place]) => ({
152
+ agent: agentId,
153
+ sessionId,
154
+ folder: place.folder || null,
155
+ pid: place.pid,
156
+ comm: place.comm,
157
+ at: place.at,
158
+ }))
159
+ );
160
+ /**
161
+ * Who each process is, for telling who started a session (live.mjs starterIn): every running session, by its process,
162
+ * and every run of Harness's, by its task. A session another agent or a run started is not one the person did.
163
+ */
164
+ const ownersOf = (sessions, table) => {
165
+ const owners = new Map();
166
+ for (const session of sessions) {
167
+ const row = Number.isInteger(session.pid) ? table.get(session.pid) : null;
168
+ const sameProcess =
169
+ row &&
170
+ (!session.comm ||
171
+ path.basename(row.comm) === path.basename(session.comm));
172
+ if (sameProcess)
173
+ owners.set(session.pid, {
174
+ by: session.agent,
175
+ sessionId: session.sessionId,
176
+ });
177
+ }
178
+ for (const { run, pid } of runningProcesses()) {
179
+ const task = store.getTask(run);
180
+ if (task)
181
+ owners.set(pid, {
182
+ by: task.claimed_by || task.target_agent,
183
+ run: task.id,
184
+ thread: task.parent_id ?? null,
185
+ });
186
+ }
187
+ return owners;
188
+ };
189
+ // Whether T3 Code ever ran the agent in a thread of its own. When it never did, a session of the agent placed in T3
190
+ // was started from a shell there, by an agent working in T3 (OpenCode was seen running Claude Code started in /tmp).
191
+ // Read again after ten minutes, or one when it had not.
192
+ let t3Ran = { at: 0, agents: {} };
193
+ const t3RanAgent = (agentId) => {
194
+ const stale = Object.values(t3Ran.agents).includes(false)
195
+ ? 60_000
196
+ : 10 * 60_000;
197
+ if (Date.now() - t3Ran.at > stale) t3Ran = { at: Date.now(), agents: {} };
198
+ t3Ran.agents[agentId] ??=
199
+ Boolean(t3App()) && t3Runs(agentId, "1970-01-01T00:00:00Z") > 0;
200
+ return t3Ran.agents[agentId];
201
+ };
202
+ /**
203
+ * Who started a session that is not running, when it was not the person: what was seen as it started, else what its
204
+ * own record shows (places.mjs backgroundOf). A run Harness started for the person is theirs: work they handed out.
205
+ */
206
+ const starterOf = (agentId, sessionId, folder = null, file = null) => {
207
+ const place = placesOf(agentId)[sessionId];
208
+ if (place?.startedBy) return place.startedBy;
209
+ if (store.runOfSession(agentId, sessionId)) return null;
210
+ if (place?.kind === "t3" && !t3RanAgent(agentId))
211
+ return { by: null, reason: "inside-t3" };
212
+ const reason = backgroundOf(agentId, file, folder ?? place?.folder ?? null);
213
+ return reason ? { by: null, reason } : null;
214
+ };
122
215
  // Whose turn it is in each of the person's sessions, as its own hooks say: a turn that ended with nothing more to do is
123
216
  // the person's, until they type there again; kept while the agent's process runs. No process scan: the buddy reads
124
217
  // the sessions waiting for the person with its board poll. Harness's own runs have no place, so never count.
@@ -182,10 +275,14 @@ export function createSessionControl({
182
275
  let host = pids.map((pid) => hostApp(table, pid)).find(Boolean) ?? null;
183
276
  let tty = pids.map((pid) => table.get(pid)?.tty).find(Boolean) ?? null;
184
277
  // The agent's own process (not the shell a hook ran in), kept with the place: the session runs while it does.
278
+ // An agent may show in ps by another name (its member's alsoRunsAs): on Node as node (Cursor's, Copilot's and
279
+ // DeepSeek Harness's CLIs), or as Kilo's .kilo. Among the hook's own parents, that is the agent.
280
+ const agentProcess = (comm) =>
281
+ comm === PROCESS_NAMES[agentId] ||
282
+ Boolean(member(agentId)?.alsoRunsAs?.includes(comm));
185
283
  let agentPid =
186
- pids.find(
187
- (pid) => path.basename(table.get(pid).comm) === PROCESS_NAMES[agentId]
188
- ) ?? null;
284
+ pids.find((pid) => agentProcess(path.basename(table.get(pid).comm))) ??
285
+ null;
189
286
  if (agentId === "codex" && pids.length && !host && !tty) {
190
287
  const clients = [...table]
191
288
  .filter(([, row]) => path.basename(row.comm) === "codex" && row.tty)
@@ -202,9 +299,18 @@ export function createSessionControl({
202
299
  agentPid = client;
203
300
  }
204
301
  const place = placeFrom({ env, host, tty, folder });
205
- return place && agentPid
206
- ? { ...place, pid: agentPid, comm: table.get(agentPid).comm }
207
- : place;
302
+ if (!place) return null;
303
+ // Started by another agent's session or a run: kept, as it is not where the person works.
304
+ const startedBy = starterIn(
305
+ table,
306
+ agentPid ?? pids[0],
307
+ ownersOf(reportedSessions(), table)
308
+ );
309
+ return {
310
+ ...place,
311
+ ...(agentPid ? { pid: agentPid, comm: table.get(agentPid).comm } : {}),
312
+ ...(startedBy ? { startedBy } : {}),
313
+ };
208
314
  };
209
315
  // A custom harness may say how one of its sessions opens again: a page it serves on this computer, or a command to type.
210
316
  const reopenOf = (value) => {
@@ -240,24 +346,23 @@ export function createSessionControl({
240
346
  };
241
347
  const linksOk = t3LinksOk();
242
348
  const handed = handedToT3();
243
- // The sessions that named their own process when they started (pi's extension, OpenCode's plugin, hooks).
244
- const reported = LIVE_AGENTS.flatMap((agentId) =>
245
- Object.entries(placesOf(agentId))
246
- .filter(([, place]) => Number.isInteger(place.pid))
247
- .map(([sessionId, place]) => ({
248
- agent: agentId,
249
- sessionId,
250
- folder: place.folder || null,
251
- pid: place.pid,
252
- comm: place.comm,
253
- at: place.at,
254
- }))
255
- );
256
- const sessions = liveSessions({
349
+ const table = processTable();
350
+ const found = liveSessions({
257
351
  exclude: new Set(runningPids()),
258
352
  recent,
259
- reported,
260
- })
353
+ reported: reportedSessions(),
354
+ table,
355
+ });
356
+ // Who started each, when another agent's session or one of Harness's runs did: seen now, else as it started.
357
+ const owners = ownersOf(found, table);
358
+ const sessions = found
359
+ .map((session) => ({
360
+ ...session,
361
+ startedBy:
362
+ starterIn(table, session.pid, owners) ??
363
+ placesOf(session.agent)[session.sessionId]?.startedBy ??
364
+ null,
365
+ }))
261
366
  // A T3 thread running a turn Harness handed it is Harness's run, shown in its thread.
262
367
  .filter((session) => !handed.has(session.t3Thread))
263
368
  // A T3 Code that cannot open links is brought forward instead, and messages reach its sessions through their hooks.
@@ -281,30 +386,65 @@ export function createSessionControl({
281
386
  ? { CLAUDE_CODE_ENTRYPOINT: session.entrypoint }
282
387
  : {}),
283
388
  };
389
+ const place = placeFrom({
390
+ env,
391
+ host: session.host,
392
+ tty: session.tty,
393
+ folder: session.folder,
394
+ });
284
395
  notePlace(
285
396
  session.agent,
286
397
  session.sessionId,
287
- placeFrom({
288
- env,
289
- host: session.host,
290
- tty: session.tty,
291
- folder: session.folder,
292
- })
398
+ place && session.startedBy
399
+ ? { ...place, startedBy: session.startedBy }
400
+ : place
293
401
  );
294
402
  }
295
403
  return sessions;
296
404
  };
297
405
 
406
+ /**
407
+ * The terminal app the person works in: the one their agents' sessions ran in most (any agent's, Neovim's included),
408
+ * else the one setup ran in; null when neither is known. Where a session opens when nothing better can show it.
409
+ */
410
+ const personTerminal = () => {
411
+ const tally = new Map();
412
+ for (const agentId of new Set([...CODING_AGENTS, ...placedAgents()]))
413
+ for (const place of Object.values(placesOf(agentId))) {
414
+ if (!["terminal", "nvim"].includes(place?.kind) || place.startedBy)
415
+ continue;
416
+ if (!isTerminalApp(place.app) || !fs.existsSync(place.app)) continue;
417
+ tally.set(place.app, (tally.get(place.app) ?? 0) + 1);
418
+ }
419
+ const [app] = [...tally].sort((a, b) => b[1] - a[1])[0] ?? [];
420
+ return app ? { name: path.basename(app, ".app"), app } : setupTerminal();
421
+ };
422
+ const lastResort = () => personTerminal() ?? { name: "Terminal", app: null };
423
+ const terminalPlace = ({ name, app }) => ({ kind: "terminal", name, app });
424
+
298
425
  // An agent's home: the place most of its sessions started in over the last thirty days (ties: the latest), where its
299
426
  // sessions open when they are not running.
300
427
  let seeded = { at: 0, homes: {} };
301
- /** Before any session was recorded: what this computer already shows, threads run in T3 Code and the agent started in an editor's terminal. */
428
+ /**
429
+ * Before any session was recorded: what this computer already shows. Threads run in T3 Code, the agent started in an
430
+ * editor's terminal, and its own session files' count of sessions run in a terminal (counted for the person's
431
+ * terminal, when one is known). With none of those, a coding agent opens in the person's terminal.
432
+ */
302
433
  const seedHome = (agentId) => {
303
434
  if (Date.now() - seeded.at > 10 * 60_000)
304
435
  seeded = { at: Date.now(), homes: {} };
305
436
  if (agentId in seeded.homes) return seeded.homes[agentId];
306
437
  const command = agentCommand(agentId);
438
+ const terminal = personTerminal();
307
439
  const seeds = [
440
+ ...(terminal
441
+ ? [
442
+ {
443
+ count: terminalSessions(agentId, Date.now() - PLACE_MS),
444
+ place: terminalPlace(terminal),
445
+ },
446
+ ]
447
+ : []),
308
448
  {
309
449
  count: t3App()
310
450
  ? t3Runs(agentId, new Date(Date.now() - PLACE_MS).toISOString())
@@ -323,10 +463,14 @@ export function createSessionControl({
323
463
  }))
324
464
  : []),
325
465
  ];
466
+ const seen = seeds
467
+ .filter((seed) => seed.count > 0)
468
+ .sort((a, b) => b.count - a.count)[0]?.place;
326
469
  return (seeded.homes[agentId] =
327
- seeds
328
- .filter((seed) => seed.count > 0)
329
- .sort((a, b) => b.count - a.count)[0]?.place ?? null);
470
+ seen ??
471
+ (CODING_AGENTS.includes(agentId) && terminal
472
+ ? terminalPlace(terminal)
473
+ : null));
330
474
  };
331
475
  /** A place with the app that opens it now (T3's running build, an editor's install); null when it is not on this computer. */
332
476
  const usable = (place) => {
@@ -339,15 +483,27 @@ export function createSessionControl({
339
483
  const install = editorInstall(place.editor, place.app || "");
340
484
  return install ? { ...place, ...install } : place.app ? place : null;
341
485
  }
486
+ // A terminal app no longer here: the person's terminal (Neovim runs there too).
487
+ const gone = place.app && !fs.existsSync(place.app);
488
+ if (gone && place.kind === "terminal") {
489
+ const { name, app } = lastResort();
490
+ return { ...place, name, app };
491
+ }
492
+ if (gone && place.kind === "nvim")
493
+ return { ...place, app: lastResort().app };
494
+ if (gone && place.kind === "codex-app") return null;
342
495
  return place;
343
496
  };
344
497
  const homeOf = (agentId) => {
345
498
  const tally = new Map();
346
499
  for (const place of Object.values(placesOf(agentId))) {
347
500
  if (!place?.kind || place.kind === "unknown") continue;
348
- // An agent T3 does not run, started from a shell inside T3 Code, is not one T3 can show (October 16: OpenCode's
349
- // home was T3, and Open on it landed on Claude Code's T3 thread).
350
- if (place.kind === "t3" && !t3Provider(agentId)) continue;
501
+ // A session another agent or a run started says nothing of where the person works.
502
+ if (place.startedBy) continue;
503
+ // An agent T3 does not run (or never ran in a thread), started from a shell inside T3 Code, is not one T3 can
504
+ // show (when OpenCode's home was T3, Open on it once landed on Claude Code's T3 thread).
505
+ if (place.kind === "t3" && !(t3Provider(agentId) && t3RanAgent(agentId)))
506
+ continue;
351
507
  const entry = tally.get(placeKey(place)) ?? { place, count: 0 };
352
508
  entry.count += 1;
353
509
  if ((place.seen || 0) >= (entry.place.seen || 0)) entry.place = place;
@@ -386,6 +542,16 @@ export function createSessionControl({
386
542
  !String(row.cwd || "").startsWith(paths.home + path.sep);
387
543
  const short = (name) => String(name || "").replace(/ \(.*\)$/, "");
388
544
 
545
+ /** The Neovims an agent was used in, one per server: `place` first, then the latest. */
546
+ const neovimsFor = (agentId, place) => {
547
+ const others = Object.values(placesOf(agentId))
548
+ .filter((other) => other.kind === "nvim")
549
+ .sort((a, b) => (b.seen || 0) - (a.seen || 0));
550
+ return [place, ...others].filter(
551
+ (one, index, all) =>
552
+ one.server && all.findIndex((x) => x.server === one.server) === index
553
+ );
554
+ };
389
555
  /** Whether one of Harness's runs is still working in this session: it is not resumed beside it. */
390
556
  const runBusy = (sessionId) =>
391
557
  Boolean(sessionId) &&
@@ -405,21 +571,17 @@ export function createSessionControl({
405
571
  if (thread && t3OpensLinks(place.app))
406
572
  return { opensIn: "T3 Code", link: t3Link(thread) };
407
573
  if (thread) return { opensIn: "T3 Code", app: place.app, note: T3_OLD };
408
- // No session of T3's (none yet, or one T3 never had): T3 opens on its thread for the folder, so it shows the right
409
- // workspace; with none there, it comes forward as it is.
410
- const there = t3OpensLinks(place.app) ? t3Link(t3ThreadIn(folder)) : null;
411
- const shown = there ? { link: there } : { app: place.app };
412
- if (!sessionId) return { opensIn: "T3 Code", ...shown };
413
- // A session T3 never had (a run Harness started in its own folder, say) says so, and can still be resumed in a
414
- // terminal instead. Until Harness may send into T3, its threads run in that copy: approving it is what moves them
415
- // into T3 (inT3).
574
+ // A session T3 never had (one another agent started, a run in Harness's own copy) is not shown by any of T3's
575
+ // threads: it is picked up again elsewhere (openPlan), never shown as another thread.
576
+ if (sessionId) return null;
577
+ // The agent itself: T3 on the agent's own thread for the folder, so it shows the right workspace; with none there,
578
+ // T3 comes forward as it is.
579
+ const there = t3OpensLinks(place.app)
580
+ ? t3Link(t3ThreadIn(folder, t3Provider(agentId)))
581
+ : null;
416
582
  return {
417
583
  opensIn: "T3 Code",
418
- ...shown,
419
- resumable: true,
420
- note: harnessRun(folder)
421
- ? `This run happened in Harness's own copy of the repo, which T3 Code doesn't list, so ${there ? "T3 Code opens on its thread for the repository" : "T3 Code is in front as it is"}.${t3Access()?.state === "send" ? "" : " Approve Harness in T3 Code and this thread's next turns run there, where Open finds them."}`
422
- : `T3 Code doesn't list this session, so ${there ? "it opens on T3's thread for its folder" : "it is in front as it is"}.`,
584
+ ...(there ? { link: there } : { app: place.app }),
423
585
  };
424
586
  }
425
587
  if (place.kind === "editor") {
@@ -430,9 +592,11 @@ export function createSessionControl({
430
592
  if (act && window) openEditorFolder(place, window);
431
593
  return { opensIn: name, app: place.app, note: busy };
432
594
  }
433
- const link = sessionId
434
- ? panelLink(agentId, place.editor, sessionId)
435
- : null;
595
+ // Only a session the panel lists: for any other, its link opens an empty conversation in the session's place.
596
+ const link =
597
+ sessionId && panelLists(agentId, sessionId, folder)
598
+ ? panelLink(agentId, place.editor, sessionId)
599
+ : null;
436
600
  if (link) {
437
601
  if (act && window) openEditorFolder(place, window);
438
602
  return { opensIn: name, link };
@@ -473,6 +637,32 @@ export function createSessionControl({
473
637
  : place.app
474
638
  ? { opensIn: "Codex", app: place.app }
475
639
  : null;
640
+ if (place.kind === "nvim") {
641
+ if (!CODING_AGENTS.includes(agentId)) return null;
642
+ if (busy)
643
+ return place.app
644
+ ? { opensIn: name, app: place.app, note: busy }
645
+ : { opensIn: name, note: busy };
646
+ // In a Neovim of theirs still open (this one first, else the latest they used the agent in), in a new tab; with
647
+ // none open, the buddy opens their terminal with Neovim running the session.
648
+ const command = sessionId
649
+ ? resumeLine(agentId, sessionId)
650
+ : agentCommand(agentId);
651
+ for (const open of act ? neovimsFor(agentId, place) : []) {
652
+ const shown = resumeInNeovim(open.server, command, folder);
653
+ if (shown) return { opensIn: name, ...focusTerminal(shown, open) };
654
+ }
655
+ return {
656
+ opensIn: name,
657
+ resume: {
658
+ agent: agentId,
659
+ session: sessionId ?? null,
660
+ cwd: folder ?? null,
661
+ app: place.app ?? null,
662
+ within: "nvim",
663
+ },
664
+ };
665
+ }
476
666
  if (place.kind === "terminal") {
477
667
  if (!CODING_AGENTS.includes(agentId)) return null;
478
668
  if (busy)
@@ -506,6 +696,12 @@ export function createSessionControl({
506
696
  ...(t3Thread(live.sessionId) ? { note: T3_OLD } : {}),
507
697
  };
508
698
  }
699
+ // Its terminal buffer in Neovim, then the terminal Neovim runs in.
700
+ if (place?.kind === "nvim") {
701
+ const shown = act ? showInNeovim(place.server, live.pid) : null;
702
+ if (shown) return { opensIn: "Neovim", ...focusTerminal(shown, place) };
703
+ if (!act) return { opensIn: "Neovim", app: place.app ?? null };
704
+ }
509
705
  if (place?.kind === "editor") {
510
706
  const link =
511
707
  place.surface === "panel"
@@ -535,13 +731,57 @@ export function createSessionControl({
535
731
  : {}),
536
732
  };
537
733
  };
734
+ /**
735
+ * A running session another agent's session or one of Harness's runs started: where that one runs, which shows it at
736
+ * work. Nothing is opened beside it: a second process in a session that runs would each carry on its own way.
737
+ */
738
+ const startedPlan = (live, running, act) => {
739
+ const { by, sessionId, run, thread } = live.startedBy;
740
+ const name = nameOf(live.agent);
741
+ if (run)
742
+ return {
743
+ opensIn: thread ? "the thread" : null,
744
+ run,
745
+ thread: thread ?? null,
746
+ note: thread
747
+ ? `${nameOf(by)}'s run in a thread started this ${name} session, so it opens in that thread.`
748
+ : `One of Harness's runs started this ${name} session. Open it again once the run is done.`,
749
+ };
750
+ const starter = running.find(
751
+ (row) => row.agent === by && row.sessionId === sessionId
752
+ );
753
+ if (starter)
754
+ return {
755
+ ...runningPlan(starter, act),
756
+ note: `${nameOf(by)} started this ${name} session, so ${nameOf(by)}'s session opens: it runs from there.`,
757
+ };
758
+ return {
759
+ opensIn: null,
760
+ note: `This ${name} session runs in the background${by ? `, started by ${nameOf(by)}` : ""}, and no app shows it. Open it again once it's done to pick it up.`,
761
+ };
762
+ };
763
+ /** A session whose folder is gone can't be picked up again: the session that started it opens, when there is one. */
764
+ const goneFolderPlan = (agentId, sessionId, where, act, depth) => {
765
+ const startedBy = starterOf(agentId, sessionId, where);
766
+ const gone = `Its folder, ${where}, is gone, so this ${nameOf(agentId)} session can't be picked up again`;
767
+ if (startedBy?.by && startedBy.sessionId && depth < 1) {
768
+ const plan = openPlan(startedBy.by, startedBy.sessionId, null, act, 1);
769
+ if (plan.opensIn)
770
+ return {
771
+ ...plan,
772
+ note: `${gone}; ${nameOf(startedBy.by)}'s session that started it opens instead.`,
773
+ };
774
+ }
775
+ return { opensIn: null, note: `${gone}.` };
776
+ };
538
777
  /**
539
778
  * How a session opens, or the agent itself with no session: what the app does next (views/ui.ts openPlace). A running
540
- * session opens where it runs; one that ended opens in the agent's home, else where it ran, else a terminal resumes
541
- * it. `act`: the daemon's part happens now (a pane selected, an editor's window brought up); without it, this is only
542
- * where it would open, for Open's label.
779
+ * session opens where it runs (one another agent or a run started, where that one runs); one that ended opens in the
780
+ * agent's home, else where it ran, else a terminal resumes it, and one whose folder is gone says so. `act`: the
781
+ * daemon's part happens now (a pane selected, an editor's window brought up); without it, this is only where it would
782
+ * open, for Open's label.
543
783
  */
544
- const openPlan = (agentId, sessionId, folder, act) => {
784
+ const openPlan = (agentId, sessionId, folder, act, depth = 0) => {
545
785
  // A T3 Code thread itself (a turn Harness handed to T3) opens there, wherever the agent usually works, and even while
546
786
  // the turn runs: T3 runs that one turn and takes what the person types there in turn, so nothing runs twice.
547
787
  if (sessionId && t3Thread(sessionId) === sessionId) {
@@ -555,7 +795,7 @@ export function createSessionControl({
555
795
  if (plan) return plan;
556
796
  }
557
797
  // A session one of Harness's runs is working in on this computer is not opened a second time: two processes in one
558
- // session each finished the job their own way (October 11, two different PRDs from one job). An editor the agent
798
+ // session each finished the job their own way (once two different PRDs from one job). An editor the agent
559
799
  // lives in comes up on the run's folder and says it is still working (placePlan); anywhere else the run is followed
560
800
  // in its thread, which shows its steps as they come, and Stop. Only a run Harness started holds a session: a task
561
801
  // the person's own session claimed through its MCP server is that session at work, opened where it runs.
@@ -580,14 +820,16 @@ export function createSessionControl({
580
820
  : `One of Harness's runs is working in this ${nameOf(agentId)} session right now. Open it again once the run is done.`,
581
821
  };
582
822
  }
583
- const live = sessionId
584
- ? (liveNow().find(
585
- (row) => row.agent === agentId && row.sessionId === sessionId
586
- ) ?? null)
587
- : null;
823
+ const running = sessionId ? liveNow() : [];
824
+ const live = running.find(
825
+ (row) => row.agent === agentId && row.sessionId === sessionId
826
+ );
827
+ if (live?.startedBy) return startedPlan(live, running, act);
588
828
  if (live) return runningPlan(live, act);
589
829
  const own = sessionId ? (placesOf(agentId)[sessionId] ?? null) : null;
590
830
  const where = folder ?? own?.folder ?? null;
831
+ if (sessionId && where && !fs.existsSync(where))
832
+ return goneFolderPlan(agentId, sessionId, where, act, depth);
591
833
  if (own?.reopen?.link)
592
834
  return {
593
835
  opensIn: short(own.name) || nameOf(agentId),
@@ -597,11 +839,30 @@ export function createSessionControl({
597
839
  placePlan(agentId, homeOf(agentId), sessionId, where, act) ??
598
840
  placePlan(agentId, usable(own), sessionId, where, act);
599
841
  if (plan) return plan;
600
- if (CODING_AGENTS.includes(agentId))
842
+ // Nothing else shows it (T3 never had it, say): the exact session, picked up in the person's terminal.
843
+ if (CODING_AGENTS.includes(agentId)) {
844
+ const terminal = lastResort();
845
+ // Until Harness may send into T3, a thread's runs happen in Harness's own copy of the repo, which T3 doesn't list.
846
+ const inCopy =
847
+ sessionId &&
848
+ harnessRun(where) &&
849
+ homeOf(agentId)?.kind === "t3" &&
850
+ t3Access()?.state !== "send";
601
851
  return {
602
- opensIn: "Terminal",
603
- resume: { agent: agentId, session: sessionId, cwd: where, app: null },
852
+ opensIn: terminal.name,
853
+ resume: {
854
+ agent: agentId,
855
+ session: sessionId,
856
+ cwd: where,
857
+ app: terminal.app,
858
+ },
859
+ ...(inCopy
860
+ ? {
861
+ note: `This run happened in Harness's own copy of the repo, which T3 Code doesn't list, so it opens in ${terminal.name}. Approve Harness in T3 Code and this thread's next turns run there.`,
862
+ }
863
+ : {}),
604
864
  };
865
+ }
605
866
  const command = own?.reopen?.command;
606
867
  return command
607
868
  ? {
@@ -612,6 +873,43 @@ export function createSessionControl({
612
873
  : { opensIn: null };
613
874
  };
614
875
 
876
+ /**
877
+ * Each coding agent's sessions that ended, as Open offers them: the person's newest (`last`), where the agent opens when
878
+ * it is not running; and the newest few another agent, a run or a test started (`traces`), each saying who.
879
+ */
880
+ const TRACES = 3;
881
+ const pastSessions = (running) => {
882
+ const last = {};
883
+ const traces = {};
884
+ const runningIds = new Set(
885
+ running.map((session) => `${session.agent}:${session.sessionId}`)
886
+ );
887
+ for (const agentId of LIVE_AGENTS) {
888
+ const found = [];
889
+ for (const row of store.agentSessions(agentId, 300)) {
890
+ // A subagent's transcript is part of the session that ran it, which shows it.
891
+ if (!ownSession(row) || /\/subagents\/[^/]+$/.test(row.source || ""))
892
+ continue;
893
+ const sessionId = nativeSessionId(agentId, row.session_id);
894
+ if (runningIds.has(`${agentId}:${sessionId}`)) continue;
895
+ const folder = row.cwd || null;
896
+ const startedBy = starterOf(agentId, sessionId, folder, row.source);
897
+ if (!startedBy) last[agentId] ??= { sessionId, folder };
898
+ else if (found.length < TRACES)
899
+ found.push({
900
+ sessionId,
901
+ folder,
902
+ title: row.title && !row.title.startsWith("<") ? row.title : null,
903
+ at: Date.parse(row.ended_at || row.started_at) || null,
904
+ startedBy,
905
+ });
906
+ if (last[agentId] && found.length === TRACES) break;
907
+ }
908
+ if (found.length) traces[agentId] = found;
909
+ }
910
+ return { last, traces };
911
+ };
912
+
615
913
  const liveCommand = (request, agent) => {
616
914
  const sessionId = String(request.sessionId || "");
617
915
  if (request.command === "board.live.take") {
@@ -653,24 +951,11 @@ export function createSessionControl({
653
951
  error: "only the person reads or messages their sessions",
654
952
  };
655
953
  if (request.command === "board.live") {
656
- // Each coding agent's newest session too, so one not running now still opens where it last worked.
657
- const last = {};
658
- for (const row of store.recentSessions(200)) {
659
- if (
660
- !LIVE_AGENTS.includes(row.agent) ||
661
- last[row.agent] ||
662
- !ownSession(row)
663
- )
664
- continue;
665
- last[row.agent] = {
666
- sessionId: nativeSessionId(row.agent, row.session_id),
667
- folder: row.cwd || null,
668
- };
669
- }
954
+ const sessions = liveNow();
670
955
  return {
671
956
  ok: true,
672
- sessions: liveNow(),
673
- last,
957
+ sessions,
958
+ ...pastSessions(sessions),
674
959
  homes: homes(),
675
960
  t3: t3Access(),
676
961
  };
@@ -683,12 +968,15 @@ export function createSessionControl({
683
968
  ok: false,
684
969
  error: "only a coding agent's session can be read here",
685
970
  };
686
- if (agentId === "opencode")
971
+ // OpenCode and Kilo keep sessions in their own database; their `export` reads one.
972
+ if (agentId === "opencode" || agentId === "kilo")
687
973
  return {
688
974
  ok: true,
689
975
  items: scrub(
690
976
  opencodeFeed(
691
- opencodeExecutable || "opencode",
977
+ agentId === "opencode"
978
+ ? opencodeExecutable || "opencode"
979
+ : resolveCommand("kilo") || "kilo",
692
980
  sessionId,
693
981
  Math.min(200, Number(request.limit) || 80)
694
982
  )