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.
- package/README.md +239 -14
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +497 -196
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +165 -222
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +570 -0
- package/lib/agentSignIn.mjs +226 -0
- package/lib/atlas.mjs +7 -2
- package/lib/audit.mjs +643 -0
- package/lib/backupSetup.mjs +141 -0
- package/lib/boardAccess.mjs +8 -1
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +523 -0
- package/lib/boardProtocol.json +263 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +26 -4
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +159 -16
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +25 -5
- package/lib/connectionTools.d.ts +13 -0
- package/lib/connectionTools.js +45 -0
- package/lib/connectorAuth.mjs +309 -0
- package/lib/connectorCatalog.json +41 -0
- package/lib/connectorCommands.mjs +121 -0
- package/lib/connectorGoogle.mjs +513 -0
- package/lib/connectors.mjs +805 -0
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +152 -39
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +973 -54
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +113 -8
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +825 -0
- package/lib/folders.mjs +4 -4
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +58 -14
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +263 -152
- package/lib/landed.mjs +887 -0
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- package/lib/live.mjs +284 -13
- package/lib/localmodels.mjs +10 -0
- package/lib/machineIdentity.mjs +3 -0
- package/lib/machineRoutes.mjs +40 -2
- package/lib/machineRuns.mjs +30 -3
- package/lib/machineSeal.mjs +69 -10
- package/lib/mcp-stdio.mjs +189 -120
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +26 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/models.mjs +48 -15
- package/lib/museSession.mjs +122 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +7 -2
- package/lib/nudge.mjs +57 -18
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +828 -39
- package/lib/pairing.mjs +182 -0
- package/lib/paths.mjs +8 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +119 -3
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +337 -9
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projects.mjs +624 -137
- package/lib/readiness.mjs +400 -0
- package/lib/record.mjs +115 -0
- package/lib/repoLinks.mjs +354 -0
- package/lib/roomChannels.mjs +641 -0
- package/lib/runBrief.mjs +32 -2
- package/lib/runRequests.mjs +157 -0
- package/lib/runWorker.mjs +37 -9
- package/lib/runner.mjs +74 -11
- package/lib/secretPatterns.json +55 -0
- package/lib/secrets.mjs +10 -27
- package/lib/seen.mjs +102 -0
- package/lib/service.mjs +11 -6
- package/lib/sessionControl.mjs +386 -96
- package/lib/sessionIndex.mjs +5 -3
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +58 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/store.mjs +829 -29
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +483 -37
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +56 -17
- package/lib/taskCommands.mjs +91 -13
- package/lib/taskRuns.mjs +68 -11
- package/lib/team.json +253 -144
- package/lib/team.mjs +538 -147
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +78 -12
- package/lib/threadView.mjs +66 -16
- package/lib/tokenizer.mjs +405 -0
- package/lib/ui.mjs +16 -2
- package/lib/usageTotals.mjs +148 -0
- package/lib/vault.mjs +1144 -0
- package/lib/vaultCloud.mjs +117 -0
- package/lib/vaultCommands.mjs +201 -0
- package/lib/vaultTools.d.ts +12 -0
- package/lib/vaultTools.js +42 -0
- package/lib/windowAsks.mjs +42 -0
- package/lib/workFocus.mjs +59 -0
- package/lib/workLinks.mjs +90 -0
- package/lib/worktrees.mjs +51 -13
- package/package.json +10 -5
package/lib/places.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import os from "node:os";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { spawn, spawnSync } from "node:child_process";
|
|
6
|
-
import { paths } from "./paths.mjs";
|
|
6
|
+
import { historyRoots, paths } from "./paths.mjs";
|
|
7
7
|
import { agentEnvironment } from "./agentnode.mjs";
|
|
8
8
|
import { mainCheckout } from "./worktrees.mjs";
|
|
9
9
|
|
|
@@ -11,7 +11,8 @@ import { mainCheckout } from "./worktrees.mjs";
|
|
|
11
11
|
// Harness piece inside the agent sends it when the session starts (the Claude Code and Codex hooks, nudge.mjs; the
|
|
12
12
|
// opencode plugin; the pi extension), or the daemon reads it from the running process when nothing did. Terminals and
|
|
13
13
|
// editors put their own ids into everything they start, the same on every OS (TERM_PROGRAM, TMUX_PANE, WEZTERM_PANE,
|
|
14
|
-
// KITTY_WINDOW_ID, VSCODE_GIT_ASKPASS_NODE: the editor's own install); macOS adds the app
|
|
14
|
+
// KITTY_WINDOW_ID, NVIM: Neovim's server, VSCODE_GIT_ASKPASS_NODE: the editor's own install); macOS adds the app
|
|
15
|
+
// (__CFBundleIdentifier).
|
|
15
16
|
//
|
|
16
17
|
// Any other agent (a custom harness) does the same with one line to the daemon's socket as a session starts:
|
|
17
18
|
// {"command":"board.live.place","agent":"<its id>","sessionId":"<id>","folder":"<absolute path>","pids":[<its pid>],
|
|
@@ -31,6 +32,7 @@ export const PLACE_ENV = [
|
|
|
31
32
|
"WEZTERM_PANE",
|
|
32
33
|
"KITTY_WINDOW_ID",
|
|
33
34
|
"KITTY_LISTEN_ON",
|
|
35
|
+
"NVIM",
|
|
34
36
|
"WT_SESSION",
|
|
35
37
|
"VSCODE_GIT_ASKPASS_NODE",
|
|
36
38
|
"CLAUDE_CODE_ENTRYPOINT",
|
|
@@ -313,6 +315,117 @@ export function editorTerminalStarts(editorId, command) {
|
|
|
313
315
|
).length;
|
|
314
316
|
}
|
|
315
317
|
|
|
318
|
+
// How each agent marks a session the person ran in a terminal, in the first lines of its file: Claude Code's
|
|
319
|
+
// entrypoint "cli" (its panel says claude-vscode, the Agent SDK sdk-*), Codex's originator "codex-tui" (codex_exec,
|
|
320
|
+
// T3 Code and the editor extension say otherwise).
|
|
321
|
+
// Each kept at a fixed depth: Claude Code's under its project folders, Codex's under year, month and day (a session's
|
|
322
|
+
// subagents, deeper, are not sessions of the person's).
|
|
323
|
+
const TERMINAL_MARKS = {
|
|
324
|
+
"claude-code": { mark: /"entrypoint":\s*"cli"/, depth: 1 },
|
|
325
|
+
codex: { mark: /"originator":\s*"codex-tui"/, depth: 3 },
|
|
326
|
+
};
|
|
327
|
+
const SESSION_FILES_READ = 300;
|
|
328
|
+
const SESSION_HEAD = 20_000;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* How many of an agent's sessions since `since` (ms) the person ran in a terminal, by the agent's own session files:
|
|
332
|
+
* what is known of where they work before Harness recorded any place. The newest SESSION_FILES_READ files only.
|
|
333
|
+
*/
|
|
334
|
+
export function terminalSessions(agent, since) {
|
|
335
|
+
const { mark, depth: fileDepth } = TERMINAL_MARKS[agent] ?? {};
|
|
336
|
+
const root = mark ? historyRoots(agent)[0] : null;
|
|
337
|
+
if (!root) return 0;
|
|
338
|
+
const files = [];
|
|
339
|
+
const walk = (dir, depth) => {
|
|
340
|
+
let entries = [];
|
|
341
|
+
try {
|
|
342
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
343
|
+
} catch {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
for (const entry of entries) {
|
|
347
|
+
const file = path.join(dir, entry.name);
|
|
348
|
+
if (entry.isDirectory() && depth < fileDepth) walk(file, depth + 1);
|
|
349
|
+
else if (
|
|
350
|
+
depth === fileDepth &&
|
|
351
|
+
entry.isFile() &&
|
|
352
|
+
entry.name.endsWith(".jsonl")
|
|
353
|
+
) {
|
|
354
|
+
const at = fs.statSync(file).mtimeMs;
|
|
355
|
+
if (at >= since) files.push({ file, at });
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
walk(root, 0);
|
|
360
|
+
return files
|
|
361
|
+
.sort((a, b) => b.at - a.at)
|
|
362
|
+
.slice(0, SESSION_FILES_READ)
|
|
363
|
+
.filter(({ file }) => mark.test(fileHead(file, SESSION_HEAD))).length;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Runs nobody typed into, as the agent marks them in its own session file: Claude Code's `claude -p`, `codex exec`.
|
|
367
|
+
const BACKGROUND_MARKS = {
|
|
368
|
+
"claude-code": /"entrypoint":\s*"sdk-cli"/,
|
|
369
|
+
codex: /"originator":\s*"codex_exec"/,
|
|
370
|
+
};
|
|
371
|
+
const TEMP_FOLDERS = [
|
|
372
|
+
...new Set(
|
|
373
|
+
[os.tmpdir(), "/tmp", "/var/folders"].flatMap((folder) => [
|
|
374
|
+
folder,
|
|
375
|
+
realFolder(folder),
|
|
376
|
+
])
|
|
377
|
+
),
|
|
378
|
+
].map((folder) => folder.replace(/\/$/, "") + path.sep);
|
|
379
|
+
|
|
380
|
+
function realFolder(folder) {
|
|
381
|
+
try {
|
|
382
|
+
return fs.realpathSync(folder);
|
|
383
|
+
} catch {
|
|
384
|
+
return folder;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Why a session looks like no person's, from its own record when nothing saw it start: "unattended" when its agent marks
|
|
390
|
+
* it as run without a person; "temporary" when it ran in a temporary folder since deleted (a test's leftovers, or an
|
|
391
|
+
* agent trying something out). Null otherwise. What started it is not in the file.
|
|
392
|
+
*/
|
|
393
|
+
export function backgroundOf(agent, file, folder) {
|
|
394
|
+
if (BACKGROUND_MARKS[agent] && file && unattended(agent, file))
|
|
395
|
+
return "unattended";
|
|
396
|
+
const temporary =
|
|
397
|
+
folder && TEMP_FOLDERS.some((temp) => folder.startsWith(temp));
|
|
398
|
+
return temporary && !fs.existsSync(folder) ? "temporary" : null;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// A session file's start never changes once the agent has written how it runs: each is read until then, then kept
|
|
402
|
+
// (Open's lists ask every few seconds).
|
|
403
|
+
const marked = new Map();
|
|
404
|
+
function unattended(agent, file) {
|
|
405
|
+
if (marked.has(file)) return marked.get(file);
|
|
406
|
+
const head = fileHead(file, SESSION_HEAD);
|
|
407
|
+
const found = BACKGROUND_MARKS[agent].test(head);
|
|
408
|
+
if (/"(entrypoint|originator)"/.test(head)) {
|
|
409
|
+
if (marked.size > 5000) marked.clear();
|
|
410
|
+
marked.set(file, found);
|
|
411
|
+
}
|
|
412
|
+
return found;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function fileHead(file, length) {
|
|
416
|
+
let fd = null;
|
|
417
|
+
try {
|
|
418
|
+
fd = fs.openSync(file, "r");
|
|
419
|
+
const buffer = Buffer.alloc(length);
|
|
420
|
+
const read = fs.readSync(fd, buffer, 0, length, 0);
|
|
421
|
+
return buffer.toString("utf8", 0, read);
|
|
422
|
+
} catch {
|
|
423
|
+
return "";
|
|
424
|
+
} finally {
|
|
425
|
+
if (fd !== null) fs.closeSync(fd);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
316
429
|
// ── The agents ────────────────────────────────────────────────────────────────
|
|
317
430
|
|
|
318
431
|
/** How each agent picks a session up again; its own panel in an editor, when it has one; its name in T3 Code. */
|
|
@@ -325,6 +438,7 @@ const AGENTS = {
|
|
|
325
438
|
extension: "anthropic.claude-code",
|
|
326
439
|
link: (scheme, id) =>
|
|
327
440
|
`${scheme}://anthropic.claude-code/open?session=${id}`,
|
|
441
|
+
lists: claudePanelLists,
|
|
328
442
|
},
|
|
329
443
|
},
|
|
330
444
|
codex: {
|
|
@@ -336,8 +450,29 @@ const AGENTS = {
|
|
|
336
450
|
link: (scheme, id) => `${scheme}://openai.chatgpt/local/${id}`,
|
|
337
451
|
},
|
|
338
452
|
},
|
|
339
|
-
pi: { command: "pi", resume: "pi --session" },
|
|
340
|
-
opencode: {
|
|
453
|
+
pi: { command: "pi", resume: "pi --session", t3: "pi" },
|
|
454
|
+
opencode: {
|
|
455
|
+
command: "opencode",
|
|
456
|
+
resume: "opencode --session",
|
|
457
|
+
t3: "opencode",
|
|
458
|
+
},
|
|
459
|
+
cursor: {
|
|
460
|
+
command: "cursor-agent",
|
|
461
|
+
resume: "cursor-agent --resume",
|
|
462
|
+
t3: "cursor",
|
|
463
|
+
},
|
|
464
|
+
"grok-build": { command: "grok", resume: "grok --resume", t3: "grok" },
|
|
465
|
+
copilot: { command: "copilot", resume: "copilot --resume" },
|
|
466
|
+
devin: { command: "devin", resume: "devin -r" },
|
|
467
|
+
kilo: { command: "kilo", resume: "kilo --session" },
|
|
468
|
+
// DeepSeek Harness's sessions reopen in its web app, which takes no session link here: none to type.
|
|
469
|
+
dsh: { command: "dsh" },
|
|
470
|
+
antigravity: {
|
|
471
|
+
command: "agy",
|
|
472
|
+
resume: "agy --conversation",
|
|
473
|
+
t3: "antigravity",
|
|
474
|
+
},
|
|
475
|
+
"muse-code": { command: "muse", t3: "muse" },
|
|
341
476
|
};
|
|
342
477
|
export const agentCommand = (agent) => AGENTS[agent]?.command ?? null;
|
|
343
478
|
/** An agent's provider in T3 Code ("claudeAgent", "codex"); null for an agent T3 does not run. */
|
|
@@ -443,6 +578,15 @@ export function editorSessionWorkspace(
|
|
|
443
578
|
return file;
|
|
444
579
|
}
|
|
445
580
|
|
|
581
|
+
/**
|
|
582
|
+
* Whether an agent's panel can show a session it is not showing now. Its link opens any session id, but a session the
|
|
583
|
+
* panel leaves out of its list opens as an empty conversation, so Open sends only the ones it lists.
|
|
584
|
+
*/
|
|
585
|
+
export function panelLists(agent, sessionId, folder) {
|
|
586
|
+
const lists = AGENTS[agent]?.panel?.lists;
|
|
587
|
+
return lists ? lists(sessionId, folder) : true;
|
|
588
|
+
}
|
|
589
|
+
|
|
446
590
|
/** A session in its agent's own panel in an editor (Claude Code's, OpenAI's Codex extension), when it is installed there. */
|
|
447
591
|
export function panelLink(agent, editorId, sessionId) {
|
|
448
592
|
const panel = AGENTS[agent]?.panel;
|
|
@@ -457,6 +601,68 @@ export function panelLink(agent, editorId, sessionId) {
|
|
|
457
601
|
return panel.link(editor.scheme, sessionId);
|
|
458
602
|
}
|
|
459
603
|
|
|
604
|
+
// Claude Code's panel leaves out sessions run through the Agent SDK (T3 Code's, Harness's own runs) and its background
|
|
605
|
+
// ones: the entrypoint at the head of the session's file (else at its end), the sessionKind on its first message.
|
|
606
|
+
// Read from the extension itself, anthropic.claude-code 2.1.306 (October 23, 2026).
|
|
607
|
+
const SDK_ENTRYPOINTS = new Set(["sdk-cli", "sdk-ts", "sdk-py"]);
|
|
608
|
+
const BACKGROUND_KINDS = new Set(["daemon", "daemon-worker"]);
|
|
609
|
+
const FILE_END = 65_536;
|
|
610
|
+
|
|
611
|
+
function claudePanelLists(sessionId, folder) {
|
|
612
|
+
const file = claudeSessionFile(sessionId, folder);
|
|
613
|
+
if (!file) return false;
|
|
614
|
+
const [head, tail] = fileEnds(file);
|
|
615
|
+
const entrypoint = fieldIn(head, "entrypoint") ?? fieldIn(tail, "entrypoint");
|
|
616
|
+
if (SDK_ENTRYPOINTS.has(entrypoint)) return false;
|
|
617
|
+
const firstMessage =
|
|
618
|
+
head.split("\n").find((line) => line.includes('"parentUuid":')) ?? head;
|
|
619
|
+
return !BACKGROUND_KINDS.has(fieldIn(firstMessage, "sessionKind"));
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/** A Claude Code session's file: in the projects folder named for its working folder, else in whichever one holds it. */
|
|
623
|
+
function claudeSessionFile(sessionId, folder) {
|
|
624
|
+
if (!UUID.test(String(sessionId || ""))) return null;
|
|
625
|
+
const root = historyRoots("claude-code")[0];
|
|
626
|
+
const name = `${sessionId}.jsonl`;
|
|
627
|
+
const named = folder
|
|
628
|
+
? path.join(root, folder.replace(/[^a-zA-Z0-9]/g, "-"), name)
|
|
629
|
+
: null;
|
|
630
|
+
if (named && fs.existsSync(named)) return named;
|
|
631
|
+
let projects = [];
|
|
632
|
+
try {
|
|
633
|
+
projects = fs.readdirSync(root);
|
|
634
|
+
} catch {
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
return (
|
|
638
|
+
projects
|
|
639
|
+
.map((project) => path.join(root, project, name))
|
|
640
|
+
.find((file) => fs.existsSync(file)) ?? null
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function fileEnds(file) {
|
|
645
|
+
const fd = fs.openSync(file, "r");
|
|
646
|
+
try {
|
|
647
|
+
const size = fs.fstatSync(fd).size;
|
|
648
|
+
const read = (start, length) => {
|
|
649
|
+
const buffer = Buffer.alloc(length);
|
|
650
|
+
fs.readSync(fd, buffer, 0, length, start);
|
|
651
|
+
return buffer.toString("utf8");
|
|
652
|
+
};
|
|
653
|
+
const tailStart = Math.max(0, size - FILE_END);
|
|
654
|
+
return [
|
|
655
|
+
read(0, Math.min(size, FILE_END)),
|
|
656
|
+
read(tailStart, size - tailStart),
|
|
657
|
+
];
|
|
658
|
+
} finally {
|
|
659
|
+
fs.closeSync(fd);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const fieldIn = (text, field) =>
|
|
664
|
+
new RegExp(`"${field}":\\s*"([^"]*)"`).exec(text)?.[1] ?? null;
|
|
665
|
+
|
|
460
666
|
// ── T3 Code ───────────────────────────────────────────────────────────────────
|
|
461
667
|
|
|
462
668
|
const SQLITE = "/usr/bin/sqlite3";
|
|
@@ -497,6 +703,73 @@ const t3Tables = (home) =>
|
|
|
497
703
|
).split("\n")
|
|
498
704
|
);
|
|
499
705
|
|
|
706
|
+
/** A read of T3's record that never holds the daemon (its database is gigabytes; a cold read took 5.7 s). */
|
|
707
|
+
function t3QueryLater(home, sql) {
|
|
708
|
+
const db = t3Database(home);
|
|
709
|
+
if (!db || !fs.existsSync(SQLITE)) return Promise.resolve(null);
|
|
710
|
+
return new Promise((resolve) => {
|
|
711
|
+
const child = spawn(
|
|
712
|
+
SQLITE,
|
|
713
|
+
["-readonly", "-cmd", ".timeout 2000", db, sql],
|
|
714
|
+
{
|
|
715
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
716
|
+
}
|
|
717
|
+
);
|
|
718
|
+
let out = "";
|
|
719
|
+
child.stdout.on("data", (chunk) => (out += chunk));
|
|
720
|
+
child.on("error", () => resolve(null));
|
|
721
|
+
child.on("close", (code) => resolve(code === 0 ? out.trim() : null));
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// What a command that makes a commit looks like in T3's record of a thread's steps.
|
|
726
|
+
const COMMITTING = `type = 'command_execution' and (json_extract(payload_json, '$.input') like '%git%commit%' or json_extract(payload_json, '$.input') like '%git%merge%')`;
|
|
727
|
+
|
|
728
|
+
/** The T3 Code threads that ran a command making a commit: those can have landed work in the project itself. */
|
|
729
|
+
export async function t3Committers(home = t3Home()) {
|
|
730
|
+
const rows = await t3QueryLater(
|
|
731
|
+
home,
|
|
732
|
+
`select distinct thread_id from orchestration_v2_projection_turn_items where ${COMMITTING};`
|
|
733
|
+
);
|
|
734
|
+
return new Set((rows || "").split("\n").filter(Boolean));
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/** A T3 Code thread's commands that made commits, as it ran them: what it typed and what came back. */
|
|
738
|
+
export async function t3CommitCommands(threadId, home = t3Home()) {
|
|
739
|
+
if (!PLAIN_ID.test(String(threadId || ""))) return [];
|
|
740
|
+
const rows = await t3QueryLater(
|
|
741
|
+
home,
|
|
742
|
+
`select json_object('input', json_extract(payload_json, '$.input'), 'output', json_extract(payload_json, '$.output')) from orchestration_v2_projection_turn_items where thread_id = '${threadId}' and ${COMMITTING} order by ordinal;`
|
|
743
|
+
);
|
|
744
|
+
const commands = [];
|
|
745
|
+
for (const line of (rows || "").split("\n"))
|
|
746
|
+
try {
|
|
747
|
+
commands.push(JSON.parse(line));
|
|
748
|
+
} catch {}
|
|
749
|
+
return commands;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* T3 Code's threads that work in a checkout of their own, by thread id: the checkout and its branch, from T3's own
|
|
754
|
+
* record (its thread list over MCP leaves them out; only a thread's full read has them).
|
|
755
|
+
*/
|
|
756
|
+
export function t3Checkouts(home = t3Home()) {
|
|
757
|
+
const found = new Map();
|
|
758
|
+
if (!t3Tables(home).has("orchestration_v2_projection_threads")) return found;
|
|
759
|
+
const rows = t3Query(
|
|
760
|
+
home,
|
|
761
|
+
`select json_object('id', thread_id, 'path', json_extract(payload_json, '$.worktreePath'), 'branch', json_extract(payload_json, '$.branch')) from orchestration_v2_projection_threads where deleted_at is null and json_extract(payload_json, '$.worktreePath') is not null;`
|
|
762
|
+
);
|
|
763
|
+
for (const line of (rows || "").split("\n")) {
|
|
764
|
+
try {
|
|
765
|
+
const row = JSON.parse(line);
|
|
766
|
+
if (row.path && row.branch)
|
|
767
|
+
found.set(row.id, { path: row.path, branch: row.branch });
|
|
768
|
+
} catch {}
|
|
769
|
+
}
|
|
770
|
+
return found;
|
|
771
|
+
}
|
|
772
|
+
|
|
500
773
|
/**
|
|
501
774
|
* The T3 Code thread that has a provider session: the thread T3 ran it in (nightlies record the session on the thread's
|
|
502
775
|
* provider thread; 0.0.45 in provider_session_runtime), else T3's import of it. A T3 thread's own id (a turn Harness
|
|
@@ -585,7 +858,7 @@ export function t3Project(folder, home = t3Home()) {
|
|
|
585
858
|
* T3 Code's thread for a folder, so T3 opens on the right workspace: the newest one in that worktree, else the newest
|
|
586
859
|
* working in its project's own folder when the folder is that, else the newest in its project.
|
|
587
860
|
*/
|
|
588
|
-
export function t3ThreadIn(folder, home = t3Home()) {
|
|
861
|
+
export function t3ThreadIn(folder, provider = null, home = t3Home()) {
|
|
589
862
|
const dir = folder ? realDir(folder) : null;
|
|
590
863
|
if (!dir || !t3Tables(home).has("orchestration_v2_projection_threads"))
|
|
591
864
|
return null;
|
|
@@ -593,12 +866,13 @@ export function t3ThreadIn(folder, home = t3Home()) {
|
|
|
593
866
|
const rows = (
|
|
594
867
|
t3Query(
|
|
595
868
|
home,
|
|
596
|
-
"select thread_id || char(9) || coalesce(project_id, '') || char(9) || coalesce(json_extract(payload_json, '$.worktreePath'), '') from orchestration_v2_projection_threads where deleted_at is null and archived_at is null order by updated_at desc;"
|
|
869
|
+
"select thread_id || char(9) || coalesce(project_id, '') || char(9) || coalesce(json_extract(payload_json, '$.worktreePath'), '') || char(9) || coalesce(default_provider, '') from orchestration_v2_projection_threads where deleted_at is null and archived_at is null order by updated_at desc;"
|
|
597
870
|
) || ""
|
|
598
871
|
)
|
|
599
872
|
.split("\n")
|
|
600
873
|
.map((line) => line.split("\t"))
|
|
601
|
-
|
|
874
|
+
// Only the agent's own threads: another agent's thread in the same folder is not where this one works.
|
|
875
|
+
.filter(([id, , , by]) => id && (!provider || by === provider));
|
|
602
876
|
const inProject = project ? rows.filter(([, id]) => id === project.id) : [];
|
|
603
877
|
const found =
|
|
604
878
|
rows.find(([, , tree]) => tree && realDir(tree) === dir) ??
|
|
@@ -802,11 +1076,19 @@ const TERMINAL_NAMES = {
|
|
|
802
1076
|
alacritty: "Alacritty",
|
|
803
1077
|
};
|
|
804
1078
|
|
|
1079
|
+
/** Whether an app is a terminal app (not an editor or T3 Code, whose own terminals a session can also run in). */
|
|
1080
|
+
export const isTerminalApp = (app) =>
|
|
1081
|
+
typeof app === "string" &&
|
|
1082
|
+
[...Object.values(TERMINAL_NAMES), "iTerm2"].includes(
|
|
1083
|
+
path.basename(app, ".app")
|
|
1084
|
+
);
|
|
1085
|
+
|
|
805
1086
|
/**
|
|
806
1087
|
* Where a session runs, from its environment and the app found up its process tree (`host`, live.mjs hostApp):
|
|
807
1088
|
* t3 T3 Code;
|
|
808
1089
|
* editor an editor built on VS Code: its terminal, or an agent's own panel there ("surface");
|
|
809
1090
|
* codex-app the Codex app;
|
|
1091
|
+
* nvim a Neovim terminal: its server (neovim.mjs), and the terminal app and pane Neovim itself runs in;
|
|
810
1092
|
* terminal a terminal app, with the ids that pick its pane on any OS (tmux, WezTerm, kitty) and its tty;
|
|
811
1093
|
* app any other app.
|
|
812
1094
|
* The environment comes first: the app a process sits under can be a different one (a terminal started from an editor).
|
|
@@ -848,8 +1130,6 @@ export function placeFrom({
|
|
|
848
1130
|
};
|
|
849
1131
|
if (env.T3CODE_CLI_PATH || bundle === T3_BUNDLE)
|
|
850
1132
|
return { kind: "t3", name: "T3 Code", folder };
|
|
851
|
-
const editor = editorOf();
|
|
852
|
-
if (editor) return editorPlace(editor);
|
|
853
1133
|
const ids = {
|
|
854
1134
|
tty,
|
|
855
1135
|
tmux: env.TMUX && /^%\d+$/.test(env.TMUX_PANE || "") ? env.TMUX_PANE : null,
|
|
@@ -858,6 +1138,19 @@ export function placeFrom({
|
|
|
858
1138
|
? { id: env.KITTY_WINDOW_ID, socket: env.KITTY_LISTEN_ON || null }
|
|
859
1139
|
: null,
|
|
860
1140
|
};
|
|
1141
|
+
// Inside Neovim, whatever it runs in (an editor's terminal too): the pane ids are Neovim's own, its tty is not.
|
|
1142
|
+
if (env.NVIM && env.CLAUDE_CODE_ENTRYPOINT !== "claude-vscode")
|
|
1143
|
+
return {
|
|
1144
|
+
kind: "nvim",
|
|
1145
|
+
name: "Neovim",
|
|
1146
|
+
server: env.NVIM,
|
|
1147
|
+
app: host?.app ?? null,
|
|
1148
|
+
...ids,
|
|
1149
|
+
tty: null,
|
|
1150
|
+
folder,
|
|
1151
|
+
};
|
|
1152
|
+
const editor = editorOf();
|
|
1153
|
+
if (editor) return editorPlace(editor);
|
|
861
1154
|
if (env.TERM_PROGRAM && env.TERM_PROGRAM !== "vscode")
|
|
862
1155
|
return {
|
|
863
1156
|
kind: "terminal",
|
|
@@ -884,6 +1177,41 @@ export function placeFrom({
|
|
|
884
1177
|
return host ? { kind: "app", name: hostName, app: host.app, folder } : null;
|
|
885
1178
|
}
|
|
886
1179
|
|
|
1180
|
+
/**
|
|
1181
|
+
* Setup notes the terminal app it runs in (a person types npx tryharness where they work): what Open falls back to
|
|
1182
|
+
* before Harness has seen the person's sessions anywhere. Anything but a terminal app (an editor's terminal, T3) is not
|
|
1183
|
+
* kept.
|
|
1184
|
+
*/
|
|
1185
|
+
export function noteSetupTerminal({
|
|
1186
|
+
env = process.env,
|
|
1187
|
+
host = null,
|
|
1188
|
+
tty = null,
|
|
1189
|
+
}) {
|
|
1190
|
+
const place = placeFrom({ env: placeEnv(env), host, tty });
|
|
1191
|
+
if (place?.kind !== "terminal" || !isTerminalApp(place.app)) return;
|
|
1192
|
+
try {
|
|
1193
|
+
fs.writeFileSync(
|
|
1194
|
+
paths.terminal,
|
|
1195
|
+
JSON.stringify({ name: place.name, app: place.app, at: Date.now() }) +
|
|
1196
|
+
"\n"
|
|
1197
|
+
);
|
|
1198
|
+
} catch {}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/** The terminal app setup last ran in, while it is on this computer; null without one. */
|
|
1202
|
+
export function setupTerminal() {
|
|
1203
|
+
try {
|
|
1204
|
+
const { name, app } = JSON.parse(fs.readFileSync(paths.terminal, "utf8"));
|
|
1205
|
+
return typeof name === "string" &&
|
|
1206
|
+
typeof app === "string" &&
|
|
1207
|
+
fs.existsSync(app)
|
|
1208
|
+
? { name, app }
|
|
1209
|
+
: null;
|
|
1210
|
+
} catch {
|
|
1211
|
+
return null;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
887
1215
|
/** One key per place the person uses an agent in: both T3 builds are T3; an editor's terminal and its panel differ. */
|
|
888
1216
|
export const placeKey = (place) =>
|
|
889
1217
|
place.kind === "editor"
|