tryharness 0.7.45 → 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 (125) hide show
  1. package/README.md +239 -14
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +497 -196
  5. package/lib/actorRoster.mjs +28 -5
  6. package/lib/adapters.mjs +165 -222
  7. package/lib/agentRuntimeConfig.mjs +36 -0
  8. package/lib/agentRuntimes.mjs +570 -0
  9. package/lib/agentSignIn.mjs +226 -0
  10. package/lib/atlas.mjs +7 -2
  11. package/lib/audit.mjs +643 -0
  12. package/lib/backupSetup.mjs +141 -0
  13. package/lib/boardAccess.mjs +8 -1
  14. package/lib/boardBackup.mjs +283 -0
  15. package/lib/boardCommands.mjs +5 -10
  16. package/lib/boardFileCommands.mjs +2 -1
  17. package/lib/boardMirror.mjs +523 -0
  18. package/lib/boardProtocol.json +263 -6
  19. package/lib/boardTools.mjs +2 -6
  20. package/lib/boardWaits.mjs +102 -0
  21. package/lib/book.mjs +659 -0
  22. package/lib/bridge.mjs +26 -4
  23. package/lib/browserWake.mjs +60 -0
  24. package/lib/cards.mjs +159 -16
  25. package/lib/cloudBoot.mjs +124 -0
  26. package/lib/commands.mjs +25 -5
  27. package/lib/connectionTools.d.ts +13 -0
  28. package/lib/connectionTools.js +45 -0
  29. package/lib/connectorAuth.mjs +309 -0
  30. package/lib/connectorCatalog.json +41 -0
  31. package/lib/connectorCommands.mjs +121 -0
  32. package/lib/connectorGoogle.mjs +513 -0
  33. package/lib/connectors.mjs +805 -0
  34. package/lib/context.mjs +18 -4
  35. package/lib/contractGate.mjs +377 -0
  36. package/lib/coordinator.mjs +152 -39
  37. package/lib/coreModels.mjs +78 -0
  38. package/lib/daemon.mjs +973 -54
  39. package/lib/desk.mjs +239 -0
  40. package/lib/desktop.mjs +113 -8
  41. package/lib/digest.mjs +32 -0
  42. package/lib/directLink.mjs +283 -0
  43. package/lib/environments.mjs +825 -0
  44. package/lib/folders.mjs +4 -4
  45. package/lib/gitHost.mjs +174 -0
  46. package/lib/goalCommands.mjs +58 -14
  47. package/lib/hookDialects.mjs +298 -0
  48. package/lib/inference.mjs +263 -152
  49. package/lib/landed.mjs +887 -0
  50. package/lib/lessons.mjs +6 -0
  51. package/lib/lineup.mjs +324 -0
  52. package/lib/live.mjs +284 -13
  53. package/lib/localmodels.mjs +10 -0
  54. package/lib/machineIdentity.mjs +3 -0
  55. package/lib/machineRoutes.mjs +40 -2
  56. package/lib/machineRuns.mjs +30 -3
  57. package/lib/machineSeal.mjs +69 -10
  58. package/lib/mcp-stdio.mjs +189 -120
  59. package/lib/mcpRelay.mjs +119 -0
  60. package/lib/members.json +26 -0
  61. package/lib/members.mjs +33 -0
  62. package/lib/modelMemory.mjs +100 -0
  63. package/lib/models.mjs +48 -15
  64. package/lib/museSession.mjs +122 -0
  65. package/lib/nativeHost.mjs +203 -0
  66. package/lib/neovim.mjs +126 -0
  67. package/lib/network.mjs +7 -2
  68. package/lib/nudge.mjs +57 -18
  69. package/lib/onboard.mjs +430 -1
  70. package/lib/oneclawLocal.mjs +150 -0
  71. package/lib/ownMachines.mjs +828 -39
  72. package/lib/pairing.mjs +182 -0
  73. package/lib/paths.mjs +8 -0
  74. package/lib/personModel.mjs +89 -0
  75. package/lib/phones.mjs +119 -3
  76. package/lib/placeCommands.mjs +27 -0
  77. package/lib/places.mjs +337 -9
  78. package/lib/plans.mjs +151 -27
  79. package/lib/profile.mjs +152 -0
  80. package/lib/projects.mjs +624 -137
  81. package/lib/readiness.mjs +400 -0
  82. package/lib/record.mjs +115 -0
  83. package/lib/repoLinks.mjs +354 -0
  84. package/lib/roomChannels.mjs +641 -0
  85. package/lib/runBrief.mjs +32 -2
  86. package/lib/runRequests.mjs +157 -0
  87. package/lib/runWorker.mjs +37 -9
  88. package/lib/runner.mjs +74 -11
  89. package/lib/secretPatterns.json +55 -0
  90. package/lib/secrets.mjs +10 -27
  91. package/lib/seen.mjs +102 -0
  92. package/lib/service.mjs +11 -6
  93. package/lib/sessionControl.mjs +386 -96
  94. package/lib/sessionIndex.mjs +5 -3
  95. package/lib/specialties.json +74 -0
  96. package/lib/specialties.mjs +477 -0
  97. package/lib/specialtyKeys.d.ts +3 -0
  98. package/lib/specialtyKeys.js +58 -0
  99. package/lib/specialtyNotice.mjs +147 -0
  100. package/lib/specialtySnapshot.mjs +138 -0
  101. package/lib/store.mjs +829 -29
  102. package/lib/subagents.mjs +8 -4
  103. package/lib/swarm.mjs +483 -37
  104. package/lib/swarmMemory.mjs +947 -0
  105. package/lib/t3.mjs +56 -17
  106. package/lib/taskCommands.mjs +91 -13
  107. package/lib/taskRuns.mjs +68 -11
  108. package/lib/team.json +253 -144
  109. package/lib/team.mjs +538 -147
  110. package/lib/threadLine.mjs +116 -0
  111. package/lib/threadRuns.mjs +78 -12
  112. package/lib/threadView.mjs +66 -16
  113. package/lib/tokenizer.mjs +405 -0
  114. package/lib/ui.mjs +16 -2
  115. package/lib/usageTotals.mjs +148 -0
  116. package/lib/vault.mjs +1144 -0
  117. package/lib/vaultCloud.mjs +117 -0
  118. package/lib/vaultCommands.mjs +201 -0
  119. package/lib/vaultTools.d.ts +12 -0
  120. package/lib/vaultTools.js +42 -0
  121. package/lib/windowAsks.mjs +42 -0
  122. package/lib/workFocus.mjs +59 -0
  123. package/lib/workLinks.mjs +90 -0
  124. package/lib/worktrees.mjs +51 -13
  125. package/package.json +10 -5
@@ -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({
@@ -48,6 +56,8 @@ export function createSessionControl({
48
56
  validAgent,
49
57
  opencodeExecutable,
50
58
  activeRuns,
59
+ // Every value in the person's vault out of what a live read shows (vault.mjs).
60
+ scrub = (value) => value,
51
61
  }) {
52
62
  const saidKey = (agent, sessionId) => `said:${agent}:${sessionId}`;
53
63
  const said = (agent, sessionId) => {
@@ -57,7 +67,7 @@ export function createSessionControl({
57
67
  return [];
58
68
  }
59
69
  };
60
- const CODING_AGENTS = ["claude-code", "codex", "pi", "opencode"];
70
+ const CODING_AGENTS = LIVE_AGENTS;
61
71
  const SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
62
72
  const folderOf = (request) =>
63
73
  typeof request.folder === "string" && path.isAbsolute(request.folder)
@@ -68,13 +78,20 @@ export function createSessionControl({
68
78
  // its environment (board.live.place), else it is read here from the running process. Thirty days of them, per agent.
69
79
  const PLACE_MS = 30 * 24 * 3600_000;
70
80
  const placeCache = new Map();
81
+ const harnessFolder = (folder) =>
82
+ Boolean(folder && folder.startsWith(paths.home + path.sep));
71
83
  const placesOf = (agentId) => {
72
84
  if (!placeCache.has(agentId)) {
73
85
  let found = {};
74
86
  try {
75
87
  found = JSON.parse(store.meta(`places:${agentId}`) || "{}");
76
88
  } catch {}
77
- 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));
78
95
  }
79
96
  return placeCache.get(agentId);
80
97
  };
@@ -85,12 +102,22 @@ export function createSessionControl({
85
102
  return [];
86
103
  }
87
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.
88
107
  const notePlace = (agentId, sessionId, place) => {
89
- if (!place || !SESSION_ID.test(sessionId)) return;
108
+ if (!place || !SESSION_ID.test(sessionId) || harnessFolder(place.folder))
109
+ return;
90
110
  const places = placesOf(agentId);
91
111
  const now = Date.now();
92
112
  const before = places[sessionId];
93
- 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
+ };
94
121
  // The same place, already seen today: nothing worth a write.
95
122
  if (
96
123
  before &&
@@ -115,8 +142,76 @@ export function createSessionControl({
115
142
  };
116
143
  /** A run Harness started itself (in its own folders, or a process it runs) is not where the person works. */
117
144
  const harnessRun = (folder, pids = []) =>
118
- Boolean(folder && folder.startsWith(paths.home + path.sep)) ||
119
- 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 was
190
+ // started from a shell there, by an agent working in T3 (October 23: OpenCode runs Claude Code started in /tmp). Read
191
+ // 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
+ };
120
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
121
216
  // the person's, until they type there again; kept while the agent's process runs. No process scan: the buddy reads
122
217
  // the sessions waiting for the person with its board poll. Harness's own runs have no place, so never count.
@@ -180,10 +275,14 @@ export function createSessionControl({
180
275
  let host = pids.map((pid) => hostApp(table, pid)).find(Boolean) ?? null;
181
276
  let tty = pids.map((pid) => table.get(pid)?.tty).find(Boolean) ?? null;
182
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));
183
283
  let agentPid =
184
- pids.find(
185
- (pid) => path.basename(table.get(pid).comm) === PROCESS_NAMES[agentId]
186
- ) ?? null;
284
+ pids.find((pid) => agentProcess(path.basename(table.get(pid).comm))) ??
285
+ null;
187
286
  if (agentId === "codex" && pids.length && !host && !tty) {
188
287
  const clients = [...table]
189
288
  .filter(([, row]) => path.basename(row.comm) === "codex" && row.tty)
@@ -200,9 +299,18 @@ export function createSessionControl({
200
299
  agentPid = client;
201
300
  }
202
301
  const place = placeFrom({ env, host, tty, folder });
203
- return place && agentPid
204
- ? { ...place, pid: agentPid, comm: table.get(agentPid).comm }
205
- : 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
+ };
206
314
  };
207
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.
208
316
  const reopenOf = (value) => {
@@ -238,24 +346,23 @@ export function createSessionControl({
238
346
  };
239
347
  const linksOk = t3LinksOk();
240
348
  const handed = handedToT3();
241
- // The sessions that named their own process when they started (pi's extension, OpenCode's plugin, hooks).
242
- const reported = LIVE_AGENTS.flatMap((agentId) =>
243
- Object.entries(placesOf(agentId))
244
- .filter(([, place]) => Number.isInteger(place.pid))
245
- .map(([sessionId, place]) => ({
246
- agent: agentId,
247
- sessionId,
248
- folder: place.folder || null,
249
- pid: place.pid,
250
- comm: place.comm,
251
- at: place.at,
252
- }))
253
- );
254
- const sessions = liveSessions({
349
+ const table = processTable();
350
+ const found = liveSessions({
255
351
  exclude: new Set(runningPids()),
256
352
  recent,
257
- reported,
258
- })
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
+ }))
259
366
  // A T3 thread running a turn Harness handed it is Harness's run, shown in its thread.
260
367
  .filter((session) => !handed.has(session.t3Thread))
261
368
  // A T3 Code that cannot open links is brought forward instead, and messages reach its sessions through their hooks.
@@ -279,30 +386,65 @@ export function createSessionControl({
279
386
  ? { CLAUDE_CODE_ENTRYPOINT: session.entrypoint }
280
387
  : {}),
281
388
  };
389
+ const place = placeFrom({
390
+ env,
391
+ host: session.host,
392
+ tty: session.tty,
393
+ folder: session.folder,
394
+ });
282
395
  notePlace(
283
396
  session.agent,
284
397
  session.sessionId,
285
- placeFrom({
286
- env,
287
- host: session.host,
288
- tty: session.tty,
289
- folder: session.folder,
290
- })
398
+ place && session.startedBy
399
+ ? { ...place, startedBy: session.startedBy }
400
+ : place
291
401
  );
292
402
  }
293
403
  return sessions;
294
404
  };
295
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
+
296
425
  // An agent's home: the place most of its sessions started in over the last thirty days (ties: the latest), where its
297
426
  // sessions open when they are not running.
298
427
  let seeded = { at: 0, homes: {} };
299
- /** 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
+ */
300
433
  const seedHome = (agentId) => {
301
434
  if (Date.now() - seeded.at > 10 * 60_000)
302
435
  seeded = { at: Date.now(), homes: {} };
303
436
  if (agentId in seeded.homes) return seeded.homes[agentId];
304
437
  const command = agentCommand(agentId);
438
+ const terminal = personTerminal();
305
439
  const seeds = [
440
+ ...(terminal
441
+ ? [
442
+ {
443
+ count: terminalSessions(agentId, Date.now() - PLACE_MS),
444
+ place: terminalPlace(terminal),
445
+ },
446
+ ]
447
+ : []),
306
448
  {
307
449
  count: t3App()
308
450
  ? t3Runs(agentId, new Date(Date.now() - PLACE_MS).toISOString())
@@ -321,10 +463,14 @@ export function createSessionControl({
321
463
  }))
322
464
  : []),
323
465
  ];
466
+ const seen = seeds
467
+ .filter((seed) => seed.count > 0)
468
+ .sort((a, b) => b.count - a.count)[0]?.place;
324
469
  return (seeded.homes[agentId] =
325
- seeds
326
- .filter((seed) => seed.count > 0)
327
- .sort((a, b) => b.count - a.count)[0]?.place ?? null);
470
+ seen ??
471
+ (CODING_AGENTS.includes(agentId) && terminal
472
+ ? terminalPlace(terminal)
473
+ : null));
328
474
  };
329
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. */
330
476
  const usable = (place) => {
@@ -337,15 +483,27 @@ export function createSessionControl({
337
483
  const install = editorInstall(place.editor, place.app || "");
338
484
  return install ? { ...place, ...install } : place.app ? place : null;
339
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;
340
495
  return place;
341
496
  };
342
497
  const homeOf = (agentId) => {
343
498
  const tally = new Map();
344
499
  for (const place of Object.values(placesOf(agentId))) {
345
500
  if (!place?.kind || place.kind === "unknown") continue;
346
- // An agent T3 does not run, started from a shell inside T3 Code, is not one T3 can show (October 16: OpenCode's
347
- // home was T3, and Open on it landed on Claude Code's T3 thread).
348
- 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 show
504
+ // (October 16: OpenCode's home was T3, and Open on it landed on Claude Code's T3 thread).
505
+ if (place.kind === "t3" && !(t3Provider(agentId) && t3RanAgent(agentId)))
506
+ continue;
349
507
  const entry = tally.get(placeKey(place)) ?? { place, count: 0 };
350
508
  entry.count += 1;
351
509
  if ((place.seen || 0) >= (entry.place.seen || 0)) entry.place = place;
@@ -384,6 +542,16 @@ export function createSessionControl({
384
542
  !String(row.cwd || "").startsWith(paths.home + path.sep);
385
543
  const short = (name) => String(name || "").replace(/ \(.*\)$/, "");
386
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
+ };
387
555
  /** Whether one of Harness's runs is still working in this session: it is not resumed beside it. */
388
556
  const runBusy = (sessionId) =>
389
557
  Boolean(sessionId) &&
@@ -403,21 +571,17 @@ export function createSessionControl({
403
571
  if (thread && t3OpensLinks(place.app))
404
572
  return { opensIn: "T3 Code", link: t3Link(thread) };
405
573
  if (thread) return { opensIn: "T3 Code", app: place.app, note: T3_OLD };
406
- // 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
407
- // workspace; with none there, it comes forward as it is.
408
- const there = t3OpensLinks(place.app) ? t3Link(t3ThreadIn(folder)) : null;
409
- const shown = there ? { link: there } : { app: place.app };
410
- if (!sessionId) return { opensIn: "T3 Code", ...shown };
411
- // A session T3 never had (a run Harness started in its own folder, say) says so, and can still be resumed in a
412
- // terminal instead. Until Harness may send into T3, its threads run in that copy: approving it is what moves them
413
- // 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;
414
582
  return {
415
583
  opensIn: "T3 Code",
416
- ...shown,
417
- resumable: true,
418
- note: harnessRun(folder)
419
- ? `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."}`
420
- : `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 }),
421
585
  };
422
586
  }
423
587
  if (place.kind === "editor") {
@@ -428,9 +592,11 @@ export function createSessionControl({
428
592
  if (act && window) openEditorFolder(place, window);
429
593
  return { opensIn: name, app: place.app, note: busy };
430
594
  }
431
- const link = sessionId
432
- ? panelLink(agentId, place.editor, sessionId)
433
- : 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;
434
600
  if (link) {
435
601
  if (act && window) openEditorFolder(place, window);
436
602
  return { opensIn: name, link };
@@ -471,6 +637,32 @@ export function createSessionControl({
471
637
  : place.app
472
638
  ? { opensIn: "Codex", app: place.app }
473
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
+ }
474
666
  if (place.kind === "terminal") {
475
667
  if (!CODING_AGENTS.includes(agentId)) return null;
476
668
  if (busy)
@@ -504,6 +696,12 @@ export function createSessionControl({
504
696
  ...(t3Thread(live.sessionId) ? { note: T3_OLD } : {}),
505
697
  };
506
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
+ }
507
705
  if (place?.kind === "editor") {
508
706
  const link =
509
707
  place.surface === "panel"
@@ -533,13 +731,57 @@ export function createSessionControl({
533
731
  : {}),
534
732
  };
535
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
+ };
536
777
  /**
537
778
  * How a session opens, or the agent itself with no session: what the app does next (views/ui.ts openPlace). A running
538
- * session opens where it runs; one that ended opens in the agent's home, else where it ran, else a terminal resumes
539
- * it. `act`: the daemon's part happens now (a pane selected, an editor's window brought up); without it, this is only
540
- * 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.
541
783
  */
542
- const openPlan = (agentId, sessionId, folder, act) => {
784
+ const openPlan = (agentId, sessionId, folder, act, depth = 0) => {
543
785
  // A T3 Code thread itself (a turn Harness handed to T3) opens there, wherever the agent usually works, and even while
544
786
  // the turn runs: T3 runs that one turn and takes what the person types there in turn, so nothing runs twice.
545
787
  if (sessionId && t3Thread(sessionId) === sessionId) {
@@ -578,14 +820,16 @@ export function createSessionControl({
578
820
  : `One of Harness's runs is working in this ${nameOf(agentId)} session right now. Open it again once the run is done.`,
579
821
  };
580
822
  }
581
- const live = sessionId
582
- ? (liveNow().find(
583
- (row) => row.agent === agentId && row.sessionId === sessionId
584
- ) ?? null)
585
- : 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);
586
828
  if (live) return runningPlan(live, act);
587
829
  const own = sessionId ? (placesOf(agentId)[sessionId] ?? null) : null;
588
830
  const where = folder ?? own?.folder ?? null;
831
+ if (sessionId && where && !fs.existsSync(where))
832
+ return goneFolderPlan(agentId, sessionId, where, act, depth);
589
833
  if (own?.reopen?.link)
590
834
  return {
591
835
  opensIn: short(own.name) || nameOf(agentId),
@@ -595,11 +839,30 @@ export function createSessionControl({
595
839
  placePlan(agentId, homeOf(agentId), sessionId, where, act) ??
596
840
  placePlan(agentId, usable(own), sessionId, where, act);
597
841
  if (plan) return plan;
598
- 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";
599
851
  return {
600
- opensIn: "Terminal",
601
- 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
+ : {}),
602
864
  };
865
+ }
603
866
  const command = own?.reopen?.command;
604
867
  return command
605
868
  ? {
@@ -610,6 +873,43 @@ export function createSessionControl({
610
873
  : { opensIn: null };
611
874
  };
612
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
+
613
913
  const liveCommand = (request, agent) => {
614
914
  const sessionId = String(request.sessionId || "");
615
915
  if (request.command === "board.live.take") {
@@ -651,24 +951,11 @@ export function createSessionControl({
651
951
  error: "only the person reads or messages their sessions",
652
952
  };
653
953
  if (request.command === "board.live") {
654
- // Each coding agent's newest session too, so one not running now still opens where it last worked.
655
- const last = {};
656
- for (const row of store.recentSessions(200)) {
657
- if (
658
- !LIVE_AGENTS.includes(row.agent) ||
659
- last[row.agent] ||
660
- !ownSession(row)
661
- )
662
- continue;
663
- last[row.agent] = {
664
- sessionId: nativeSessionId(row.agent, row.session_id),
665
- folder: row.cwd || null,
666
- };
667
- }
954
+ const sessions = liveNow();
668
955
  return {
669
956
  ok: true,
670
- sessions: liveNow(),
671
- last,
957
+ sessions,
958
+ ...pastSessions(sessions),
672
959
  homes: homes(),
673
960
  t3: t3Access(),
674
961
  };
@@ -681,13 +968,18 @@ export function createSessionControl({
681
968
  ok: false,
682
969
  error: "only a coding agent's session can be read here",
683
970
  };
684
- if (agentId === "opencode")
971
+ // OpenCode and Kilo keep sessions in their own database; their `export` reads one.
972
+ if (agentId === "opencode" || agentId === "kilo")
685
973
  return {
686
974
  ok: true,
687
- items: opencodeFeed(
688
- opencodeExecutable || "opencode",
689
- sessionId,
690
- Math.min(200, Number(request.limit) || 80)
975
+ items: scrub(
976
+ opencodeFeed(
977
+ agentId === "opencode"
978
+ ? opencodeExecutable || "opencode"
979
+ : resolveCommand("kilo") || "kilo",
980
+ sessionId,
981
+ Math.min(200, Number(request.limit) || 80)
982
+ )
691
983
  ),
692
984
  };
693
985
  const file = sessionFile(
@@ -699,10 +991,8 @@ export function createSessionControl({
699
991
  if (!file) return { ok: true, items: [] };
700
992
  return {
701
993
  ok: true,
702
- items: sessionFeed(
703
- agentId,
704
- file,
705
- Math.min(200, Number(request.limit) || 80)
994
+ items: scrub(
995
+ sessionFeed(agentId, file, Math.min(200, Number(request.limit) || 80))
706
996
  ),
707
997
  };
708
998
  }