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.
- package/README.md +23 -19
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +484 -90
- package/lib/activity.mjs +10 -10
- package/lib/adapters.mjs +173 -222
- package/lib/agentBinaries.mjs +71 -0
- package/lib/agentRuntimeConfig.mjs +1 -1
- package/lib/agentRuntimes.mjs +34 -18
- package/lib/agentSignIn.mjs +456 -0
- package/lib/answers.mjs +5 -5
- package/lib/archetypes.d.ts +64 -0
- package/lib/archetypes.js +989 -0
- package/lib/asks.mjs +4 -4
- package/lib/audit.mjs +666 -0
- package/lib/backupSetup.mjs +143 -0
- package/lib/boardAccess.mjs +24 -11
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardFileCommands.mjs +6 -6
- package/lib/boardFiles.mjs +13 -12
- package/lib/boardMirror.mjs +124 -25
- package/lib/boardProtocol.json +88 -2
- package/lib/boardWaits.mjs +101 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +6 -6
- package/lib/cards.mjs +138 -28
- package/lib/cloudAgents.mjs +216 -0
- package/lib/cloudAi.mjs +1312 -0
- package/lib/cloudAssistants.mjs +242 -0
- package/lib/cloudBoot.mjs +119 -0
- package/lib/cloudSave.mjs +197 -0
- package/lib/cloudSsh.mjs +178 -0
- package/lib/commands.mjs +7 -2
- package/lib/context.mjs +19 -5
- package/lib/contractGate.mjs +399 -0
- package/lib/control-client.mjs +9 -1
- package/lib/controlSocket.mjs +86 -0
- package/lib/coordinator.mjs +252 -144
- package/lib/daemon.mjs +1351 -2767
- package/lib/desk.mjs +240 -0
- package/lib/desktop.mjs +178 -74
- package/lib/directLink.mjs +16 -5
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +247 -9
- package/lib/firewall.mjs +9 -9
- package/lib/folders.mjs +20 -16
- package/lib/frames.mjs +2 -3
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +25 -7
- package/lib/goals.mjs +7 -7
- package/lib/guestRequests.mjs +94 -0
- package/lib/handoffs.mjs +8 -7
- package/lib/handover.mjs +4 -4
- package/lib/harnessModel.mjs +6 -6
- package/lib/harnessOffers.mjs +266 -0
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +26 -8
- package/lib/jobAnswers.mjs +190 -0
- package/lib/landed.mjs +887 -0
- package/lib/lane.mjs +42 -11
- package/lib/lessons.mjs +16 -16
- package/lib/library.mjs +3 -3
- package/lib/lineup.mjs +3 -0
- package/lib/linkRelay.mjs +574 -0
- package/lib/live.mjs +284 -13
- package/lib/localAgentAsk.mjs +74 -0
- package/lib/localStack.mjs +536 -0
- package/lib/localmodels.mjs +6 -4
- package/lib/loopBackstop.mjs +4 -4
- package/lib/machineIdentity.mjs +9 -1
- package/lib/machineRoutes.mjs +181 -2
- package/lib/machineRuns.mjs +76 -1
- package/lib/machineSeal.mjs +39 -12
- package/lib/mcp-stdio.mjs +163 -27
- package/lib/mcpRelay.mjs +1 -1
- package/lib/members.json +29 -2
- package/lib/members.mjs +1 -1
- package/lib/models.mjs +85 -31
- package/lib/museSession.mjs +21 -13
- package/lib/nativeHost.mjs +36 -8
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +50 -5
- package/lib/notify.mjs +7 -5
- package/lib/nudge.mjs +50 -19
- package/lib/ocr.mjs +9 -9
- package/lib/onboard.mjs +26 -20
- package/lib/oneLine.mjs +7 -7
- package/lib/ownMachines.mjs +1223 -140
- package/lib/pairing.mjs +60 -16
- package/lib/paths.mjs +19 -1
- package/lib/peerProcess.mjs +124 -0
- package/lib/personModel.mjs +89 -0
- package/lib/personNotices.mjs +151 -0
- package/lib/phones.mjs +538 -31
- package/lib/placeCommands.mjs +4 -4
- package/lib/places.mjs +400 -12
- package/lib/profile.mjs +67 -14
- package/lib/projectGit.mjs +158 -14
- package/lib/projectPieces.mjs +902 -0
- package/lib/projectSettings.mjs +7 -4
- package/lib/projects.mjs +384 -62
- package/lib/provenance.mjs +5 -1
- package/lib/proxyLinks.mjs +267 -0
- package/lib/reactions.mjs +7 -5
- package/lib/readiness.mjs +145 -23
- package/lib/record.mjs +128 -0
- package/lib/redact.mjs +4 -4
- package/lib/relayLimits.mjs +62 -0
- package/lib/release.mjs +170 -0
- package/lib/releaseKeys.json +6 -0
- package/lib/repoLinks.mjs +4 -4
- package/lib/roomChannels.mjs +24 -0
- package/lib/roomPage.mjs +1 -1
- package/lib/runAuthority.mjs +101 -0
- package/lib/runBrief.mjs +19 -8
- package/lib/runWorker.mjs +31 -7
- package/lib/runner.mjs +223 -29
- package/lib/runtime-install.mjs +143 -9
- package/lib/schedules.mjs +2 -2
- package/lib/screens.mjs +1 -1
- package/lib/sealed.mjs +11 -2
- package/lib/sealedThreads.mjs +671 -0
- package/lib/secretPatterns.json +1 -1
- package/lib/secrets.mjs +4 -4
- package/lib/seen.mjs +6 -6
- package/lib/serverWords.mjs +175 -0
- package/lib/service.mjs +22 -12
- package/lib/sessionControl.mjs +378 -90
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +57 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/speech.mjs +5 -5
- package/lib/store.mjs +420 -36
- package/lib/stuck.mjs +1 -1
- package/lib/swarm.mjs +304 -37
- package/lib/swarmDevices.mjs +319 -0
- package/lib/swarmMemory.mjs +27 -25
- package/lib/t3.mjs +24 -15
- package/lib/taskCommands.mjs +80 -20
- package/lib/taskRooms.mjs +125 -0
- package/lib/taskRuns.mjs +45 -3
- package/lib/team.json +255 -148
- package/lib/team.mjs +554 -190
- package/lib/threadActions.mjs +315 -0
- package/lib/threadAuthority.mjs +101 -0
- package/lib/threadBriefs.mjs +178 -0
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +209 -50
- package/lib/threadView.mjs +20 -7
- package/lib/usageTotals.mjs +2 -3
- package/lib/vault.mjs +101 -10
- package/lib/vaultCloud.mjs +2 -2
- package/lib/vaultCommands.mjs +15 -6
- package/lib/vaultTools.js +2 -2
- package/lib/verdicts.mjs +328 -0
- package/lib/wakes.mjs +1 -1
- package/lib/watches.mjs +2 -2
- package/lib/windowAsks.mjs +13 -5
- package/lib/worktrees.mjs +157 -25
- package/npm-shrinkwrap.json +1093 -0
- package/package.json +12 -11
- package/release.json +220 -0
- package/lib/modelTiers.json +0 -1183
- package/lib/modelTiers.mjs +0 -133
package/lib/live.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
|
+
import zlib from "node:zlib";
|
|
5
6
|
import { readJson } from "./files.mjs";
|
|
6
7
|
import { historyRoots } from "./paths.mjs";
|
|
7
8
|
import { PS } from "./nudge.mjs";
|
|
@@ -14,7 +15,19 @@ import { t3App, t3Link, t3Thread, t3Working } from "./places.mjs";
|
|
|
14
15
|
// Every coding agent here: its hooks (Claude Code, Codex), extension (pi) or plugin (OpenCode) run nudge.mjs, which is
|
|
15
16
|
// how a message from Harness reaches a session. Where each session runs, and how it opens there again, is places.mjs.
|
|
16
17
|
|
|
17
|
-
export const LIVE_AGENTS = [
|
|
18
|
+
export const LIVE_AGENTS = [
|
|
19
|
+
"claude-code",
|
|
20
|
+
"codex",
|
|
21
|
+
"pi",
|
|
22
|
+
"opencode",
|
|
23
|
+
"grok-build",
|
|
24
|
+
"copilot",
|
|
25
|
+
"cursor",
|
|
26
|
+
"antigravity",
|
|
27
|
+
"devin",
|
|
28
|
+
"kilo",
|
|
29
|
+
"dsh",
|
|
30
|
+
];
|
|
18
31
|
const PLAIN_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
19
32
|
|
|
20
33
|
/** Every process: its parent, its terminal (/dev/ttys003, or null) and its executable, by pid. */
|
|
@@ -96,6 +109,19 @@ export function hostApp(table, pid) {
|
|
|
96
109
|
return null;
|
|
97
110
|
}
|
|
98
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Who started a process, when another agent did: the nearest process above it in `owners` (process id → its starter:
|
|
114
|
+
* another session, one of Harness's runs). Null when none is: the person started it.
|
|
115
|
+
*/
|
|
116
|
+
export function starterIn(table, pid, owners) {
|
|
117
|
+
let current = table.get(pid)?.ppid;
|
|
118
|
+
for (let steps = 0; current > 1 && steps < 64; steps++) {
|
|
119
|
+
if (owners.has(current)) return owners.get(current);
|
|
120
|
+
current = table.get(current)?.ppid;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
99
125
|
export function workingDirectories(pids) {
|
|
100
126
|
const found = new Map();
|
|
101
127
|
if (!pids.length) return found;
|
|
@@ -336,6 +362,11 @@ export function sessionFile(agent, sessionId, folder, recent = []) {
|
|
|
336
362
|
entry.source
|
|
337
363
|
);
|
|
338
364
|
if (row && fs.existsSync(row.source)) return row.source;
|
|
365
|
+
if (agent === "grok-build") return grokUpdates(sessionId);
|
|
366
|
+
if (agent === "copilot") return copilotEvents(sessionId);
|
|
367
|
+
if (agent === "cursor") return cursorTranscript(sessionId);
|
|
368
|
+
if (agent === "antigravity") return antigravityTranscript(sessionId);
|
|
369
|
+
if (agent === "dsh") return dshSessionLog(sessionId);
|
|
339
370
|
if (agent === "claude-code" && folder && PLAIN_ID.test(sessionId)) {
|
|
340
371
|
const file = path.join(
|
|
341
372
|
historyRoots("claude-code")[0],
|
|
@@ -347,6 +378,107 @@ export function sessionFile(agent, sessionId, folder, recent = []) {
|
|
|
347
378
|
return null;
|
|
348
379
|
}
|
|
349
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Grok Build's record of a session (its ACP updates, one per line): ~/.grok/sessions/<its folder, encoded>/<id>/. The
|
|
383
|
+
* folder's encoding is Grok's own, so the session is found by its id, which is unique.
|
|
384
|
+
*/
|
|
385
|
+
function grokUpdates(sessionId) {
|
|
386
|
+
if (!PLAIN_ID.test(String(sessionId))) return null;
|
|
387
|
+
const root = path.join(
|
|
388
|
+
process.env.GROK_HOME || path.join(os.homedir(), ".grok"),
|
|
389
|
+
"sessions"
|
|
390
|
+
);
|
|
391
|
+
let folders = [];
|
|
392
|
+
try {
|
|
393
|
+
folders = fs.readdirSync(root);
|
|
394
|
+
} catch {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
for (const folder of folders) {
|
|
398
|
+
const file = path.join(root, folder, sessionId, "updates.jsonl");
|
|
399
|
+
if (fs.existsSync(file)) return file;
|
|
400
|
+
}
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Copilot's record of a session: ~/.copilot/session-state/<id>/events.jsonl ($COPILOT_HOME). */
|
|
405
|
+
function copilotEvents(sessionId) {
|
|
406
|
+
if (!PLAIN_ID.test(String(sessionId))) return null;
|
|
407
|
+
const file = path.join(
|
|
408
|
+
process.env.COPILOT_HOME || path.join(os.homedir(), ".copilot"),
|
|
409
|
+
"session-state",
|
|
410
|
+
sessionId,
|
|
411
|
+
"events.jsonl"
|
|
412
|
+
);
|
|
413
|
+
return fs.existsSync(file) ? file : null;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Cursor's transcript of a chat: ~/.cursor/projects/<its folder, slashes as dashes>/agent-transcripts/<id>/<id>.jsonl,
|
|
418
|
+
* found by the chat's id. Its own store (chats/…/store.db) holds the same in SQLite blobs.
|
|
419
|
+
*/
|
|
420
|
+
function cursorTranscript(sessionId) {
|
|
421
|
+
if (!PLAIN_ID.test(String(sessionId))) return null;
|
|
422
|
+
const root = path.join(os.homedir(), ".cursor", "projects");
|
|
423
|
+
let folders = [];
|
|
424
|
+
try {
|
|
425
|
+
folders = fs.readdirSync(root);
|
|
426
|
+
} catch {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
for (const folder of folders) {
|
|
430
|
+
const file = path.join(
|
|
431
|
+
root,
|
|
432
|
+
folder,
|
|
433
|
+
"agent-transcripts",
|
|
434
|
+
sessionId,
|
|
435
|
+
`${sessionId}.jsonl`
|
|
436
|
+
);
|
|
437
|
+
if (fs.existsSync(file)) return file;
|
|
438
|
+
}
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** Antigravity's full transcript of a conversation (the CLI's own transcript path; a shorter one is rewritten as it compacts). */
|
|
443
|
+
function antigravityTranscript(sessionId) {
|
|
444
|
+
if (!PLAIN_ID.test(String(sessionId))) return null;
|
|
445
|
+
const file = path.join(
|
|
446
|
+
os.homedir(),
|
|
447
|
+
".gemini",
|
|
448
|
+
"antigravity-cli",
|
|
449
|
+
"brain",
|
|
450
|
+
sessionId,
|
|
451
|
+
".system_generated",
|
|
452
|
+
"logs",
|
|
453
|
+
"transcript_full.jsonl"
|
|
454
|
+
);
|
|
455
|
+
return fs.existsSync(file) ? file : null;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* DeepSeek Harness's log of a session: ~/.dsh/sessions/--<its folder>--/<id>/session.v4.jsonl, zstd-compressed by
|
|
460
|
+
* default (.zstd), found by the session's id.
|
|
461
|
+
*/
|
|
462
|
+
function dshSessionLog(sessionId) {
|
|
463
|
+
if (!PLAIN_ID.test(String(sessionId))) return null;
|
|
464
|
+
const root = path.join(
|
|
465
|
+
process.env.DSH_HOME || path.join(os.homedir(), ".dsh"),
|
|
466
|
+
"sessions"
|
|
467
|
+
);
|
|
468
|
+
let folders = [];
|
|
469
|
+
try {
|
|
470
|
+
folders = fs.readdirSync(root);
|
|
471
|
+
} catch {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
for (const folder of folders)
|
|
475
|
+
for (const name of ["session.v4.jsonl.zstd", "session.v4.jsonl"]) {
|
|
476
|
+
const file = path.join(root, folder, sessionId, name);
|
|
477
|
+
if (fs.existsSync(file)) return file;
|
|
478
|
+
}
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
|
|
350
482
|
/** OpenCode's session as the person reads it: OpenCode keeps sessions in its own database, so `opencode export` reads it. */
|
|
351
483
|
export function opencodeFeed(command, sessionId, limit = 80) {
|
|
352
484
|
if (!PLAIN_ID.test(String(sessionId))) return [];
|
|
@@ -386,23 +518,148 @@ export function opencodeFeed(command, sessionId, limit = 80) {
|
|
|
386
518
|
return items.slice(-limit);
|
|
387
519
|
}
|
|
388
520
|
|
|
521
|
+
// One of Grok Build's ACP updates as feed items. The person's prompt and the agent's answer come in chunks, each added to
|
|
522
|
+
// the item the chunk before it began; a tool call is one step. Its timestamps are in seconds.
|
|
523
|
+
function grokSteps(row, last) {
|
|
524
|
+
const update = row.params?.update || {};
|
|
525
|
+
const at = Number.isFinite(row.timestamp)
|
|
526
|
+
? new Date(row.timestamp * 1000).toISOString()
|
|
527
|
+
: null;
|
|
528
|
+
const chunk =
|
|
529
|
+
update.content?.type === "text" ? String(update.content.text || "") : "";
|
|
530
|
+
const kind =
|
|
531
|
+
update.sessionUpdate === "user_message_chunk"
|
|
532
|
+
? "you"
|
|
533
|
+
: update.sessionUpdate === "agent_message_chunk"
|
|
534
|
+
? "say"
|
|
535
|
+
: null;
|
|
536
|
+
if (kind && last?.kind === kind && last.open) {
|
|
537
|
+
last.text += chunk;
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
if (kind) return chunk.trim() ? [{ kind, text: chunk, at, open: true }] : [];
|
|
541
|
+
if (update.sessionUpdate === "tool_call" && update.title)
|
|
542
|
+
return [{ kind: "do", text: String(update.title).slice(0, 200), at }];
|
|
543
|
+
return [];
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// A record of DeepSeek Harness's session log as feed items: the person's own messages (source user; context Harness or
|
|
547
|
+
// the agent added has its own source), the agent's messages, and its tool calls. Its times are in milliseconds.
|
|
548
|
+
function dshSteps(row) {
|
|
549
|
+
const at = Number.isFinite(row.time)
|
|
550
|
+
? new Date(row.time).toISOString()
|
|
551
|
+
: null;
|
|
552
|
+
if (row.type === "user/message" && row.data.source?.kind === "user") {
|
|
553
|
+
const said = promptText(row.data.content);
|
|
554
|
+
return machinery(said) ? [] : [{ kind: "you", text: said.trim(), at }];
|
|
555
|
+
}
|
|
556
|
+
if (row.type === "assistant/message" && row.data.message)
|
|
557
|
+
return stepsOf({ type: "assistant", message: row.data.message }).map(
|
|
558
|
+
(step) => ({ ...step, at })
|
|
559
|
+
);
|
|
560
|
+
if (row.type === "tool/call" && row.data.name)
|
|
561
|
+
return [
|
|
562
|
+
{
|
|
563
|
+
kind: "do",
|
|
564
|
+
text: `${row.data.name}: ${JSON.stringify(row.data.arguments ?? {})
|
|
565
|
+
.replace(/\s+/g, " ")
|
|
566
|
+
.slice(0, 200)}`,
|
|
567
|
+
at,
|
|
568
|
+
},
|
|
569
|
+
];
|
|
570
|
+
return [];
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// A line of Cursor's transcript (Claude Code's shape, { role, message: { content } }) as feed items. The person's
|
|
574
|
+
// words may come wrapped in <user_query>.
|
|
575
|
+
function cursorSteps(row, at) {
|
|
576
|
+
if (row.role === "user") {
|
|
577
|
+
const said = promptText(row.message.content)
|
|
578
|
+
.replace(/^\s*<user_query>\s*|\s*<\/user_query>\s*$/g, "")
|
|
579
|
+
.trim();
|
|
580
|
+
return machinery(said) ? [] : [{ kind: "you", text: said, at }];
|
|
581
|
+
}
|
|
582
|
+
if (row.role !== "assistant") return [];
|
|
583
|
+
return stepsOf({ type: "assistant", message: row.message }).map((step) => ({
|
|
584
|
+
...step,
|
|
585
|
+
at,
|
|
586
|
+
}));
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// A step of Antigravity's transcript as feed items: what the person asked (inside <USER_REQUEST>), and what the agent
|
|
590
|
+
// said and the tools it called.
|
|
591
|
+
function antigravitySteps(row) {
|
|
592
|
+
const at = row.created_at || null;
|
|
593
|
+
if (row.type === "USER_INPUT" && row.source === "USER_EXPLICIT") {
|
|
594
|
+
const said = String(row.content || "");
|
|
595
|
+
const asked =
|
|
596
|
+
said.match(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/)?.[1] ?? said;
|
|
597
|
+
return asked.trim() ? [{ kind: "you", text: asked.trim(), at }] : [];
|
|
598
|
+
}
|
|
599
|
+
if (row.type !== "PLANNER_RESPONSE") return [];
|
|
600
|
+
return [
|
|
601
|
+
...(String(row.content || "").trim()
|
|
602
|
+
? [{ kind: "say", text: String(row.content).trim(), at }]
|
|
603
|
+
: []),
|
|
604
|
+
...(Array.isArray(row.tool_calls) ? row.tool_calls : []).map((call) => ({
|
|
605
|
+
kind: "do",
|
|
606
|
+
text: `${call.name}: ${JSON.stringify(call.args ?? {})
|
|
607
|
+
.replace(/\s+/g, " ")
|
|
608
|
+
.slice(0, 200)}`,
|
|
609
|
+
at,
|
|
610
|
+
})),
|
|
611
|
+
];
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// One of Copilot's session events as feed items, in the shape its SDK declares (github/copilot-sdk, session-events.ts):
|
|
615
|
+
// the person's message (not one Copilot added itself, which names its source), the agent's message, and each tool it
|
|
616
|
+
// starts. A subagent's events carry its agentId and are left out by the caller.
|
|
617
|
+
function copilotSteps(row, at) {
|
|
618
|
+
const data = row.data;
|
|
619
|
+
if (row.type === "user.message" && !data.source) {
|
|
620
|
+
const said = String(data.content || "");
|
|
621
|
+
return machinery(said) ? [] : [{ kind: "you", text: said.trim(), at }];
|
|
622
|
+
}
|
|
623
|
+
if (row.type === "assistant.message" && String(data.content || "").trim())
|
|
624
|
+
return [{ kind: "say", text: String(data.content).trim(), at }];
|
|
625
|
+
if (row.type === "tool.execution_start" && data.toolName)
|
|
626
|
+
return [
|
|
627
|
+
{
|
|
628
|
+
kind: "do",
|
|
629
|
+
text: `${data.toolName}: ${JSON.stringify(data.arguments ?? {})
|
|
630
|
+
.replace(/\s+/g, " ")
|
|
631
|
+
.slice(0, 200)}`,
|
|
632
|
+
at,
|
|
633
|
+
},
|
|
634
|
+
];
|
|
635
|
+
return [];
|
|
636
|
+
}
|
|
637
|
+
|
|
389
638
|
/**
|
|
390
639
|
* The end of a session as the person reads it, oldest first: what they asked ("you"), what the agent said ("say") and
|
|
391
640
|
* the tools it used ("do"). Read from the last part of the session's own file, so a long session costs no more.
|
|
392
641
|
*/
|
|
393
642
|
export function sessionFeed(agent, file, limit = 80) {
|
|
394
643
|
let text = "";
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
644
|
+
// A compressed log is read whole (Node 22.15 and later can decompress zstd).
|
|
645
|
+
if (file.endsWith(".zstd")) {
|
|
646
|
+
try {
|
|
647
|
+
text = zlib.zstdDecompressSync(fs.readFileSync(file)).toString("utf8");
|
|
648
|
+
} catch {
|
|
649
|
+
return [];
|
|
650
|
+
}
|
|
651
|
+
} else
|
|
652
|
+
try {
|
|
653
|
+
const size = fs.statSync(file).size;
|
|
654
|
+
const handle = fs.openSync(file, "r");
|
|
655
|
+
const buffer = Buffer.alloc(Math.min(size, FEED_BYTES));
|
|
656
|
+
fs.readSync(handle, buffer, 0, buffer.length, size - buffer.length);
|
|
657
|
+
fs.closeSync(handle);
|
|
658
|
+
text = buffer.toString("utf8");
|
|
659
|
+
if (size > buffer.length) text = text.slice(text.indexOf("\n") + 1);
|
|
660
|
+
} catch {
|
|
661
|
+
return [];
|
|
662
|
+
}
|
|
406
663
|
const items = [];
|
|
407
664
|
for (const line of text.split("\n")) {
|
|
408
665
|
if (!line.startsWith("{")) continue;
|
|
@@ -443,6 +700,16 @@ export function sessionFeed(agent, file, limit = 80) {
|
|
|
443
700
|
.slice(0, 200)}`,
|
|
444
701
|
at,
|
|
445
702
|
});
|
|
703
|
+
} else if (agent === "dsh" && row.data) {
|
|
704
|
+
items.push(...dshSteps(row));
|
|
705
|
+
} else if (agent === "cursor" && row.message) {
|
|
706
|
+
items.push(...cursorSteps(row, at));
|
|
707
|
+
} else if (agent === "antigravity" && row.type) {
|
|
708
|
+
items.push(...antigravitySteps(row));
|
|
709
|
+
} else if (agent === "copilot" && row.data && !row.agentId) {
|
|
710
|
+
items.push(...copilotSteps(row, at));
|
|
711
|
+
} else if (agent === "grok-build" && row.method === "session/update") {
|
|
712
|
+
items.push(...grokSteps(row, items.at(-1)));
|
|
446
713
|
} else if (agent === "pi" && row.type === "message" && row.message) {
|
|
447
714
|
if (row.message.role === "user") {
|
|
448
715
|
const said = promptText(row.message.content);
|
|
@@ -456,5 +723,9 @@ export function sessionFeed(agent, file, limit = 80) {
|
|
|
456
723
|
);
|
|
457
724
|
}
|
|
458
725
|
}
|
|
459
|
-
return items
|
|
726
|
+
return items
|
|
727
|
+
.slice(-limit)
|
|
728
|
+
.map(({ open, ...item }) =>
|
|
729
|
+
open ? { ...item, text: item.text.trim() } : item
|
|
730
|
+
);
|
|
460
731
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
// The coding agents on this computer that can answer a question with their tools off: Claude Code with no tools, Codex
|
|
5
|
+
// in its read-only sandbox. The coordinator asks them to decide a round on the privacy setting or as Harness's backup
|
|
6
|
+
// (coordinator.mjs), and to read a round Harness's server decided before its words reach an agent (serverWords.mjs).
|
|
7
|
+
export const LOCAL_DECIDERS = ["claude-code", "codex"];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One question to `agent`, answered with one JSON object. It runs in the system's temporary folder, away from any
|
|
11
|
+
* repository, and has no deadline of its own: it ends when the agent answers or exits.
|
|
12
|
+
*/
|
|
13
|
+
export function askLocalAgent(agent, prompt) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const invocation =
|
|
16
|
+
agent === "codex"
|
|
17
|
+
? {
|
|
18
|
+
command: "codex",
|
|
19
|
+
args: [
|
|
20
|
+
"exec",
|
|
21
|
+
"--json",
|
|
22
|
+
"--sandbox",
|
|
23
|
+
"read-only",
|
|
24
|
+
"--skip-git-repo-check",
|
|
25
|
+
"-",
|
|
26
|
+
],
|
|
27
|
+
stdin: prompt,
|
|
28
|
+
}
|
|
29
|
+
: {
|
|
30
|
+
command: "claude",
|
|
31
|
+
args: ["-p", prompt, "--output-format", "json", "--tools", ""],
|
|
32
|
+
};
|
|
33
|
+
let child;
|
|
34
|
+
try {
|
|
35
|
+
child = spawn(invocation.command, invocation.args, { cwd: os.tmpdir() });
|
|
36
|
+
} catch (error) {
|
|
37
|
+
reject(error);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// An agent that exits before reading the prompt breaks the pipe; its exit code rejects below.
|
|
41
|
+
child.stdin.on("error", () => {});
|
|
42
|
+
child.stdin.end(invocation.stdin ?? "");
|
|
43
|
+
let out = "";
|
|
44
|
+
child.stdout.on("data", (chunk) => {
|
|
45
|
+
out += chunk;
|
|
46
|
+
});
|
|
47
|
+
child.on("error", reject);
|
|
48
|
+
child.on("close", (code) => {
|
|
49
|
+
if (code !== 0) {
|
|
50
|
+
reject(new Error(`${agent} exited with code ${code}`));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// Claude answers one JSON object with its text in `result`; Codex streams events, its words in agent_message.
|
|
54
|
+
let text = "";
|
|
55
|
+
for (const line of out.split("\n")) {
|
|
56
|
+
try {
|
|
57
|
+
const event = JSON.parse(line);
|
|
58
|
+
if (typeof event.result === "string") text = event.result;
|
|
59
|
+
if (
|
|
60
|
+
event.type === "item.completed" &&
|
|
61
|
+
event.item?.type === "agent_message"
|
|
62
|
+
)
|
|
63
|
+
text = event.item.text;
|
|
64
|
+
} catch {}
|
|
65
|
+
}
|
|
66
|
+
const match = text.match(/\{[\s\S]*\}/);
|
|
67
|
+
try {
|
|
68
|
+
resolve(JSON.parse(match ? match[0] : text));
|
|
69
|
+
} catch {
|
|
70
|
+
reject(new Error(`${agent} did not answer in the agreed shape`));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|