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/lessons.mjs
CHANGED
|
@@ -307,6 +307,12 @@ export function createLessons({
|
|
|
307
307
|
await embedLesson(restored).catch(() => {});
|
|
308
308
|
return restored;
|
|
309
309
|
}
|
|
310
|
+
// One the dream retired as an instruction for one job (swarmMemory.mjs).
|
|
311
|
+
if (change === "retired") {
|
|
312
|
+
const restored = store.restoreLesson(lessonId);
|
|
313
|
+
await embedLesson(restored).catch(() => {});
|
|
314
|
+
return restored;
|
|
315
|
+
}
|
|
310
316
|
if (change === "taken back") {
|
|
311
317
|
const restored = store.restoreLesson(lessonId, { dropTookBack: true });
|
|
312
318
|
await embedLesson(restored).catch(() => {});
|
package/lib/lineup.mjs
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { detectAgents } from "./commands.mjs";
|
|
5
|
+
import { detectLocalAgents, setupHermes, setupOpenClaw } from "./wakes.mjs";
|
|
6
|
+
import { configureAgents } from "./adapters.mjs";
|
|
7
|
+
import { MACHINE_RUNNERS, nameOf } from "./members.mjs";
|
|
8
|
+
import { paths } from "./paths.mjs";
|
|
9
|
+
import { readJson, writeJsonAtomic } from "./files.mjs";
|
|
10
|
+
import { createAgentReadiness, SIGN_IN } from "./readiness.mjs";
|
|
11
|
+
|
|
12
|
+
// The swarm's lineup: the agents the person put in it. Setup offers only the agents installed and signed in on this
|
|
13
|
+
// computer, already ticked, and the person keeps the ones they want; every other agent joins only when they add it
|
|
14
|
+
// (`npx tryharness agents add`, or Add an agent in the buddy's settings). The list lives in the config as
|
|
15
|
+
// `swarmAgents`. A config from before the lineup has none, and its swarm stays as it was: every agent the roster finds.
|
|
16
|
+
// Harness itself is always in the swarm.
|
|
17
|
+
|
|
18
|
+
/** Agents that run on this computer: the coding agents Harness starts, and the assistants it wakes by webhook. */
|
|
19
|
+
const HERE = [...MACHINE_RUNNERS, "openclaw", "hermes"];
|
|
20
|
+
/** Agents that live elsewhere and are added on purpose; Grok Bot and Muse also need their own setup in Harness. */
|
|
21
|
+
const ELSEWHERE = ["grok-bot", "bankr", "quotient", "muse"];
|
|
22
|
+
const NEEDS_SETUP_ELSEWHERE = new Set(["grok-bot", "muse"]);
|
|
23
|
+
|
|
24
|
+
const PROVIDER_KEYS = [
|
|
25
|
+
"ANTHROPIC_API_KEY",
|
|
26
|
+
"OPENAI_API_KEY",
|
|
27
|
+
"GEMINI_API_KEY",
|
|
28
|
+
"OPENROUTER_API_KEY",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether a coding agent here looks signed in: its own sign-in file, or a provider key in the environment it reads.
|
|
33
|
+
* A guess from files, so a "signed out" agent is still offered, only not ticked.
|
|
34
|
+
*/
|
|
35
|
+
export function signedIn(
|
|
36
|
+
agent,
|
|
37
|
+
{ homeDir = os.homedir(), env = process.env } = {}
|
|
38
|
+
) {
|
|
39
|
+
const file = (...parts) => {
|
|
40
|
+
try {
|
|
41
|
+
return fs.readFileSync(path.join(...parts), "utf8");
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const key = (...names) => names.some((name) => Boolean(env[name]?.trim()));
|
|
47
|
+
const dataHome = env.XDG_DATA_HOME || path.join(homeDir, ".local", "share");
|
|
48
|
+
switch (agent) {
|
|
49
|
+
case "claude-code":
|
|
50
|
+
return (
|
|
51
|
+
key("ANTHROPIC_API_KEY") ||
|
|
52
|
+
/"oauthAccount"\s*:\s*\{/.test(file(homeDir, ".claude.json") ?? "") ||
|
|
53
|
+
file(homeDir, ".claude", ".credentials.json") !== null
|
|
54
|
+
);
|
|
55
|
+
case "codex":
|
|
56
|
+
return (
|
|
57
|
+
key("OPENAI_API_KEY") ||
|
|
58
|
+
file(env.CODEX_HOME || path.join(homeDir, ".codex"), "auth.json") !==
|
|
59
|
+
null
|
|
60
|
+
);
|
|
61
|
+
case "pi":
|
|
62
|
+
return (
|
|
63
|
+
key(...PROVIDER_KEYS) ||
|
|
64
|
+
file(homeDir, ".pi", "agent", "auth.json") !== null
|
|
65
|
+
);
|
|
66
|
+
case "opencode":
|
|
67
|
+
return (
|
|
68
|
+
key(...PROVIDER_KEYS) ||
|
|
69
|
+
file(dataHome, "opencode", "auth.json") !== null ||
|
|
70
|
+
/"provider"\s*:/.test(
|
|
71
|
+
file(homeDir, ".config", "opencode", "opencode.json") ?? ""
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
// OpenClaw and Hermes are found by their own setup folders: found is set up.
|
|
75
|
+
case "openclaw":
|
|
76
|
+
case "hermes":
|
|
77
|
+
return true;
|
|
78
|
+
// An agent whose sign-in Harness cannot read (Cursor, Grok Build, Antigravity, Muse Code) is offered unticked.
|
|
79
|
+
default:
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The agents found on this computer, as setup offers them: `ready` when installed and signed in, `signed_out` when
|
|
86
|
+
* installed but not signed in yet. Agents not found here are not listed.
|
|
87
|
+
*/
|
|
88
|
+
export function agentsHere({
|
|
89
|
+
homeDir = os.homedir(),
|
|
90
|
+
env = process.env,
|
|
91
|
+
coding = detectAgents(),
|
|
92
|
+
local = detectLocalAgents({ homeDir }),
|
|
93
|
+
// The last real check of each agent (readiness.mjs): an answer to a prompt outranks a guess from its files.
|
|
94
|
+
checked = createAgentReadiness().all(),
|
|
95
|
+
} = {}) {
|
|
96
|
+
const found = new Set([
|
|
97
|
+
...coding.filter((entry) => entry.path).map((entry) => entry.agent),
|
|
98
|
+
...local.filter((entry) => entry.found).map((entry) => entry.agent),
|
|
99
|
+
]);
|
|
100
|
+
return HERE.filter((id) => found.has(id)).map((id) => {
|
|
101
|
+
const check = checked[id];
|
|
102
|
+
const ready = check
|
|
103
|
+
? check.state === "ready"
|
|
104
|
+
: signedIn(id, { homeDir, env });
|
|
105
|
+
return {
|
|
106
|
+
id,
|
|
107
|
+
name: nameOf(id),
|
|
108
|
+
state: ready ? "ready" : "signed_out",
|
|
109
|
+
hint: ready ? null : signInHint(id, check),
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const signInHint = (id, check) =>
|
|
115
|
+
check && check.state !== "signed_out" && check.detail
|
|
116
|
+
? `${nameOf(id)} did not answer: ${check.detail}`
|
|
117
|
+
: SIGN_IN[id]
|
|
118
|
+
? `sign in to ${nameOf(id)} first: run ${SIGN_IN[id]}`
|
|
119
|
+
: `sign in to ${nameOf(id)} first`;
|
|
120
|
+
|
|
121
|
+
/** The lineup in a config, or null for a config from before it (every agent the roster finds is in). */
|
|
122
|
+
export const lineupOf = (config) =>
|
|
123
|
+
Array.isArray(config?.swarmAgents) ? config.swarmAgents : null;
|
|
124
|
+
|
|
125
|
+
/** One module the daemon, setup and the CLI share: the lineup in the config file, read again only when it changes. */
|
|
126
|
+
export function createLineup({ file = paths.config } = {}) {
|
|
127
|
+
let cached = { mtimeMs: -1, list: null };
|
|
128
|
+
const read = () => {
|
|
129
|
+
let mtimeMs = 0;
|
|
130
|
+
try {
|
|
131
|
+
mtimeMs = fs.statSync(file).mtimeMs;
|
|
132
|
+
} catch {}
|
|
133
|
+
if (mtimeMs !== cached.mtimeMs)
|
|
134
|
+
cached = { mtimeMs, list: lineupOf(readJson(file, {})) };
|
|
135
|
+
return cached.list;
|
|
136
|
+
};
|
|
137
|
+
// `swarmRemoved`: the agents the person took out, which an agent watch (readiness.mjs) never puts back by itself.
|
|
138
|
+
const write = (list, removed) => {
|
|
139
|
+
const config = readJson(file, {});
|
|
140
|
+
const kept = (removed ?? config.swarmRemoved ?? []).filter(
|
|
141
|
+
(id) => !list.includes(id)
|
|
142
|
+
);
|
|
143
|
+
writeJsonAtomic(file, {
|
|
144
|
+
...config,
|
|
145
|
+
swarmAgents: [...new Set(list)],
|
|
146
|
+
swarmRemoved: [...new Set(kept)],
|
|
147
|
+
});
|
|
148
|
+
cached = { mtimeMs: -1, list: null };
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
/** Whether an agent is in the swarm; Harness always is, and so is everyone when there is no lineup yet. */
|
|
152
|
+
has: (agent) => {
|
|
153
|
+
const list = read();
|
|
154
|
+
return agent === "harness" || list === null || list.includes(agent);
|
|
155
|
+
},
|
|
156
|
+
list: () => read(),
|
|
157
|
+
/** Whether the person took this agent out of their swarm themselves. */
|
|
158
|
+
removedByPerson: (agent) =>
|
|
159
|
+
(readJson(file, {}).swarmRemoved ?? []).includes(agent),
|
|
160
|
+
/** Start the lineup (setup) with exactly these agents. */
|
|
161
|
+
set: (agents) => write(agents.filter((id) => id !== "harness")),
|
|
162
|
+
add: (agent) => {
|
|
163
|
+
const list = read();
|
|
164
|
+
// A swarm from before the lineup keeps everything it had; adding to it changes nothing.
|
|
165
|
+
if (list === null || list.includes(agent)) return;
|
|
166
|
+
write([...list, agent]);
|
|
167
|
+
},
|
|
168
|
+
// A swarm from before the lineup had everyone in it: taking one out keeps every other agent, connected or not.
|
|
169
|
+
remove: (agent) => {
|
|
170
|
+
const list = read() ?? [...HERE, ...ELSEWHERE];
|
|
171
|
+
const removed = readJson(file, {}).swarmRemoved ?? [];
|
|
172
|
+
write(
|
|
173
|
+
list.filter((id) => id !== agent),
|
|
174
|
+
[...removed, agent]
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Every agent the person could have in their swarm, as the add-an-agent lists show it: in the swarm or not, and what
|
|
182
|
+
* adding it needs. `here` is agentsHere(); `has` the lineup's.
|
|
183
|
+
*/
|
|
184
|
+
const ORDER = ["ready", "signed_out", "needs_setup", "not_installed"];
|
|
185
|
+
export function addable({ here, has }) {
|
|
186
|
+
const found = new Map(here.map((entry) => [entry.id, entry]));
|
|
187
|
+
return (
|
|
188
|
+
[...HERE, ...ELSEWHERE]
|
|
189
|
+
.map((id) => {
|
|
190
|
+
const local = found.get(id);
|
|
191
|
+
const where = HERE.includes(id) ? "this computer" : "elsewhere";
|
|
192
|
+
const state = HERE.includes(id)
|
|
193
|
+
? (local?.state ?? "not_installed")
|
|
194
|
+
: NEEDS_SETUP_ELSEWHERE.has(id)
|
|
195
|
+
? "needs_setup"
|
|
196
|
+
: "ready";
|
|
197
|
+
return {
|
|
198
|
+
id,
|
|
199
|
+
name: nameOf(id),
|
|
200
|
+
where,
|
|
201
|
+
state,
|
|
202
|
+
// An agent this computer does not have is not in the swarm here, whatever an older lineup kept.
|
|
203
|
+
inSwarm: has(id) && state !== "not_installed",
|
|
204
|
+
hint:
|
|
205
|
+
state === "not_installed"
|
|
206
|
+
? `install ${nameOf(id)} on this computer first`
|
|
207
|
+
: state === "signed_out"
|
|
208
|
+
? `sign in to ${nameOf(id)} first`
|
|
209
|
+
: state === "needs_setup"
|
|
210
|
+
? "set up in Harness once added"
|
|
211
|
+
: null,
|
|
212
|
+
};
|
|
213
|
+
})
|
|
214
|
+
// What can be added now first, what is not installed here last.
|
|
215
|
+
.sort((a, b) => ORDER.indexOf(a.state) - ORDER.indexOf(b.state))
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Put one agent in the swarm, doing what that takes on this computer: a coding agent gets Harness's MCP server and
|
|
221
|
+
* hooks (adapters.mjs), OpenClaw and Hermes their MCP entry and webhook (wakes.mjs). An agent that lives elsewhere is
|
|
222
|
+
* only added; Grok Bot and Muse then wait for their own setup in Harness, as their cards say.
|
|
223
|
+
*/
|
|
224
|
+
export function joinAgent({
|
|
225
|
+
agent,
|
|
226
|
+
lineup,
|
|
227
|
+
runtimeRoot,
|
|
228
|
+
file = paths.config,
|
|
229
|
+
here = agentsHere(),
|
|
230
|
+
configure = configureAgents,
|
|
231
|
+
localSetup = { openclaw: setupOpenClaw, hermes: setupHermes },
|
|
232
|
+
}) {
|
|
233
|
+
const local = here.find((entry) => entry.id === agent);
|
|
234
|
+
if (HERE.includes(agent)) {
|
|
235
|
+
if (!local)
|
|
236
|
+
return {
|
|
237
|
+
ok: false,
|
|
238
|
+
error: `${nameOf(agent)} is not installed on this computer. Install it, then add it again.`,
|
|
239
|
+
};
|
|
240
|
+
if (!runtimeRoot)
|
|
241
|
+
return {
|
|
242
|
+
ok: false,
|
|
243
|
+
error:
|
|
244
|
+
"Harness is not set up on this computer yet. Run: npx tryharness",
|
|
245
|
+
};
|
|
246
|
+
if (MACHINE_RUNNERS.includes(agent)) {
|
|
247
|
+
const state = configure({ runtimeRoot, selected: [agent] }).find(
|
|
248
|
+
(entry) => entry.agent === agent
|
|
249
|
+
);
|
|
250
|
+
if (!state?.configured)
|
|
251
|
+
return {
|
|
252
|
+
ok: false,
|
|
253
|
+
error: `${nameOf(agent)} could not be connected: ${state?.detail ?? "no answer"}`,
|
|
254
|
+
};
|
|
255
|
+
const config = readJson(file, {});
|
|
256
|
+
writeJsonAtomic(file, {
|
|
257
|
+
...config,
|
|
258
|
+
agentStates: { ...config.agentStates, [agent]: state },
|
|
259
|
+
});
|
|
260
|
+
} else {
|
|
261
|
+
const result = localSetup[agent]({ runtimeRoot });
|
|
262
|
+
if (!result.ok) return { ok: false, error: result.detail };
|
|
263
|
+
}
|
|
264
|
+
} else if (!ELSEWHERE.includes(agent))
|
|
265
|
+
return {
|
|
266
|
+
ok: false,
|
|
267
|
+
error: `Harness does not know an agent called ${agent}.`,
|
|
268
|
+
};
|
|
269
|
+
lineup.add(agent);
|
|
270
|
+
return {
|
|
271
|
+
ok: true,
|
|
272
|
+
agent,
|
|
273
|
+
name: nameOf(agent),
|
|
274
|
+
signedOut: local?.state === "signed_out",
|
|
275
|
+
needsSetup: NEEDS_SETUP_ELSEWHERE.has(agent),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** The daemon's lineup commands, for the CLI and the buddy: list, add, remove, and check that an agent takes a prompt. */
|
|
280
|
+
export function createLineupCommands({
|
|
281
|
+
lineup,
|
|
282
|
+
runtimeRoot,
|
|
283
|
+
readiness = createAgentReadiness(),
|
|
284
|
+
onChanged = () => {},
|
|
285
|
+
}) {
|
|
286
|
+
const COMMANDS = new Set([
|
|
287
|
+
"swarm.lineup",
|
|
288
|
+
"swarm.add",
|
|
289
|
+
"swarm.remove",
|
|
290
|
+
"swarm.check",
|
|
291
|
+
]);
|
|
292
|
+
return {
|
|
293
|
+
handles: (command) => COMMANDS.has(command),
|
|
294
|
+
run(request) {
|
|
295
|
+
if (request.command === "swarm.lineup")
|
|
296
|
+
return {
|
|
297
|
+
ok: true,
|
|
298
|
+
agents: addable({ here: agentsHere(), has: lineup.has }),
|
|
299
|
+
};
|
|
300
|
+
// `target`, not `agent`: every surface sends `agent` as who is asking (the person).
|
|
301
|
+
const agent = String(request.target || "");
|
|
302
|
+
if (request.command === "swarm.check")
|
|
303
|
+
return {
|
|
304
|
+
pending: readiness.check(agent).then((entry) => ({
|
|
305
|
+
ok: true,
|
|
306
|
+
agent,
|
|
307
|
+
name: nameOf(agent),
|
|
308
|
+
signIn: SIGN_IN[agent] ?? null,
|
|
309
|
+
...entry,
|
|
310
|
+
})),
|
|
311
|
+
};
|
|
312
|
+
if (request.command === "swarm.add") {
|
|
313
|
+
const joined = joinAgent({ agent, lineup, runtimeRoot: runtimeRoot() });
|
|
314
|
+
if (joined.ok) onChanged(agent);
|
|
315
|
+
return joined;
|
|
316
|
+
}
|
|
317
|
+
if (agent === "harness")
|
|
318
|
+
return { ok: false, error: "Harness is always in your swarm." };
|
|
319
|
+
lineup.remove(agent);
|
|
320
|
+
onChanged(agent);
|
|
321
|
+
return { ok: true, agent, name: nameOf(agent) };
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
}
|
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
|
}
|