tryharness 0.7.45 → 0.7.53
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 +232 -12
- package/cli.mjs +406 -184
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +9 -1
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +560 -0
- package/lib/atlas.mjs +7 -2
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +459 -0
- package/lib/boardProtocol.json +206 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/bridge.mjs +25 -3
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +35 -2
- package/lib/commands.mjs +20 -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/coordinator.mjs +8 -1
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +643 -45
- package/lib/desktop.mjs +7 -2
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +595 -0
- package/lib/folders.mjs +2 -2
- package/lib/goalCommands.mjs +58 -14
- package/lib/inference.mjs +263 -152
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- 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 +121 -118
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +12 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/modelTiers.json +1183 -0
- package/lib/modelTiers.mjs +133 -0
- package/lib/models.mjs +41 -8
- package/lib/museSession.mjs +119 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/network.mjs +7 -2
- package/lib/nudge.mjs +10 -2
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +521 -36
- package/lib/pairing.mjs +165 -0
- package/lib/paths.mjs +4 -0
- package/lib/phones.mjs +61 -0
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +10 -2
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projects.mjs +624 -137
- package/lib/readiness.mjs +283 -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 +20 -7
- package/lib/runner.mjs +67 -8
- 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 +10 -8
- package/lib/sessionIndex.mjs +5 -3
- package/lib/store.mjs +546 -29
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +367 -37
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +43 -13
- package/lib/taskCommands.mjs +56 -5
- package/lib/taskRuns.mjs +61 -11
- package/lib/team.json +17 -15
- package/lib/team.mjs +68 -18
- package/lib/threadRuns.mjs +3 -1
- package/lib/threadView.mjs +51 -14
- 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/package.json +9 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
|
|
3
|
+
// How strong the model an agent runs on is, by an independent benchmark, so the team's important roles go to agents
|
|
4
|
+
// that can hold them (owner, October 20: "higher tier models get more important roles", "the most important roles ...
|
|
5
|
+
// must have a floor", "where each model sits on an independent third party benchmark to create standard deviations of
|
|
6
|
+
// groups"; the person overrides any of it). modelTiers.json is a snapshot of that benchmark with its source and date and
|
|
7
|
+
// the cutoffs worked out from it; it is updated on purpose, so roles do not move when the benchmark adds a model.
|
|
8
|
+
//
|
|
9
|
+
// A tier is top, middle or bottom by the snapshot, or unknown when the agent's model is not on it (or Auto picks a model
|
|
10
|
+
// per run): an unknown agent may hold any role whose floor is not top. The person's own tier for an agent wins.
|
|
11
|
+
|
|
12
|
+
const SNAPSHOT = JSON.parse(
|
|
13
|
+
readFileSync(new URL("./modelTiers.json", import.meta.url), "utf8")
|
|
14
|
+
);
|
|
15
|
+
export const TIERS = ["top", "middle", "bottom"];
|
|
16
|
+
// Lowest first. A score named with no effort is the model's one variant. "minimal" sits under low; the benchmark lists
|
|
17
|
+
// none, so it takes low's score (the nearest stronger), never medium's (review, October 21).
|
|
18
|
+
const EFFORT_ORDER = [
|
|
19
|
+
"none",
|
|
20
|
+
"minimal",
|
|
21
|
+
"low",
|
|
22
|
+
"medium",
|
|
23
|
+
"high",
|
|
24
|
+
"xhigh",
|
|
25
|
+
"max",
|
|
26
|
+
];
|
|
27
|
+
// What the agents call the same settings: Pi's "off" is no reasoning.
|
|
28
|
+
const EFFORT_NAMES = { off: "none", "non-reasoning": "none" };
|
|
29
|
+
// An agent whose effort is not set is read at medium: neither its best nor its worst.
|
|
30
|
+
const UNSET_EFFORT = "medium";
|
|
31
|
+
|
|
32
|
+
const variants = new Map();
|
|
33
|
+
for (const entry of SNAPSHOT.entries) {
|
|
34
|
+
const [, family, inner] =
|
|
35
|
+
entry.name.match(/^(.*?)(?:\s*\(([^)]*)\))?$/) ?? [];
|
|
36
|
+
const effort = !inner
|
|
37
|
+
? null
|
|
38
|
+
: /non-reasoning/.test(inner)
|
|
39
|
+
? "none"
|
|
40
|
+
: (EFFORT_ORDER.find((level) => inner.startsWith(level)) ?? null);
|
|
41
|
+
const key = family.trim().toLowerCase();
|
|
42
|
+
variants.set(key, [...(variants.get(key) ?? []), { ...entry, effort }]);
|
|
43
|
+
}
|
|
44
|
+
const familyOf = new Map(
|
|
45
|
+
Object.entries(SNAPSHOT.models).flatMap(([family, ids]) =>
|
|
46
|
+
ids.map((id) => [id, family])
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const levelOf = (score) =>
|
|
51
|
+
score >= SNAPSHOT.cutoffs.top
|
|
52
|
+
? "top"
|
|
53
|
+
: score < SNAPSHOT.cutoffs.bottom
|
|
54
|
+
? "bottom"
|
|
55
|
+
: "middle";
|
|
56
|
+
|
|
57
|
+
// The variant at the effort asked; else the nearest stronger setting's weakest score; else the nearest weaker one.
|
|
58
|
+
function variantAt(list, effort) {
|
|
59
|
+
const single = list.find((variant) => variant.effort === null);
|
|
60
|
+
if (single) return single;
|
|
61
|
+
const wanted = EFFORT_ORDER.indexOf(effort);
|
|
62
|
+
const ranked = list
|
|
63
|
+
.map((variant) => ({
|
|
64
|
+
variant,
|
|
65
|
+
at: EFFORT_ORDER.indexOf(variant.effort),
|
|
66
|
+
}))
|
|
67
|
+
.filter((each) => each.at >= 0);
|
|
68
|
+
const exact = ranked.find((each) => each.at === wanted);
|
|
69
|
+
if (exact) return exact.variant;
|
|
70
|
+
const above = ranked
|
|
71
|
+
.filter((each) => each.at > wanted)
|
|
72
|
+
.sort((a, b) => a.at - b.at)[0];
|
|
73
|
+
if (above) return above.variant;
|
|
74
|
+
return ranked.sort((a, b) => b.at - a.at)[0]?.variant ?? null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* An agent's tier: { level, because, score?, benchmark? }. `model` as its settings or the person's choice name it (a
|
|
79
|
+
* provider prefix is dropped), `effort` likewise; `auto` when Auto picks per run; `chosen` the person's own tier.
|
|
80
|
+
*/
|
|
81
|
+
export function tierOf({
|
|
82
|
+
model = null,
|
|
83
|
+
effort = null,
|
|
84
|
+
auto = false,
|
|
85
|
+
chosen = null,
|
|
86
|
+
}) {
|
|
87
|
+
if (TIERS.includes(chosen))
|
|
88
|
+
return { level: chosen, because: "the tier you set for it" };
|
|
89
|
+
if (auto)
|
|
90
|
+
return {
|
|
91
|
+
level: "unknown",
|
|
92
|
+
because:
|
|
93
|
+
"Auto picks its model for each run; choose a model for it or set its tier",
|
|
94
|
+
};
|
|
95
|
+
// The model's own name: no provider ("anthropic/"), no context mark ("[1m]"), no ":free", no release date.
|
|
96
|
+
const id = String(model ?? "")
|
|
97
|
+
.trim()
|
|
98
|
+
.toLowerCase()
|
|
99
|
+
.split("/")
|
|
100
|
+
.pop()
|
|
101
|
+
.replace(/\[[^\]]*\]$/, "")
|
|
102
|
+
.replace(/:[a-z0-9-]+$/, "")
|
|
103
|
+
.replace(/-20\d{6}$/, "");
|
|
104
|
+
const family = familyOf.get(id);
|
|
105
|
+
const named = String(effort ?? UNSET_EFFORT).toLowerCase();
|
|
106
|
+
const level = EFFORT_NAMES[named] ?? named;
|
|
107
|
+
const variant = family
|
|
108
|
+
? variantAt(
|
|
109
|
+
variants.get(family) ?? [],
|
|
110
|
+
EFFORT_ORDER.includes(level) ? level : UNSET_EFFORT
|
|
111
|
+
)
|
|
112
|
+
: null;
|
|
113
|
+
if (!variant)
|
|
114
|
+
return {
|
|
115
|
+
level: "unknown",
|
|
116
|
+
because: model
|
|
117
|
+
? `${model} is not on the ${SNAPSHOT.index} snapshot (${SNAPSHOT.fetched})`
|
|
118
|
+
: "its model is not known here",
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
level: levelOf(variant.score),
|
|
122
|
+
score: variant.score,
|
|
123
|
+
benchmark: variant.name,
|
|
124
|
+
because: `${variant.name} scores ${variant.score} on the ${SNAPSHOT.index} (${SNAPSHOT.fetched}; top from ${SNAPSHOT.cutoffs.top}, bottom under ${SNAPSHOT.cutoffs.bottom})`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Whether an agent at `level` may hold a role with this floor: top, middle (anything known not to be weak) or any. */
|
|
129
|
+
export function meetsFloor(level, floor = "any") {
|
|
130
|
+
if (floor === "top") return level === "top";
|
|
131
|
+
if (floor === "middle") return level !== "bottom";
|
|
132
|
+
return true;
|
|
133
|
+
}
|
package/lib/models.mjs
CHANGED
|
@@ -3,8 +3,9 @@ import os from "node:os";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { agentEnvironment } from "./agentnode.mjs";
|
|
6
|
-
import { nameOf } from "./members.mjs";
|
|
6
|
+
import { MACHINE_RUNNERS, member, nameOf } from "./members.mjs";
|
|
7
7
|
import { trackHelper } from "./runner.mjs";
|
|
8
|
+
import { listProtocolModels } from "./agentRuntimes.mjs";
|
|
8
9
|
|
|
9
10
|
// Which model and effort each coding agent runs with, owned by the relay. Every agent lists its own models (Codex,
|
|
10
11
|
// Pi and OpenCode have a command for it; Claude Code has none, so its list is its own short names plus the Anthropic
|
|
@@ -156,15 +157,23 @@ export const catalogOf = (store, agent) =>
|
|
|
156
157
|
* Asks each installed agent for its models, all at once so one slow agent holds up no other, and keeps the lists; an
|
|
157
158
|
* agent whose command fails keeps its last list and the error.
|
|
158
159
|
*/
|
|
159
|
-
export async function refreshCatalogs(
|
|
160
|
+
export async function refreshCatalogs(
|
|
161
|
+
store,
|
|
162
|
+
agents,
|
|
163
|
+
log = () => {},
|
|
164
|
+
{ protocols = false } = {}
|
|
165
|
+
) {
|
|
160
166
|
await Promise.all(
|
|
161
167
|
agents
|
|
162
|
-
.filter((name) => LISTS[name])
|
|
168
|
+
.filter((name) => LISTS[name] || (protocols && member(name)?.runtime))
|
|
163
169
|
.map(async (agent) => {
|
|
164
170
|
try {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
const offered = LISTS[agent]
|
|
172
|
+
? LISTS[agent].parse(
|
|
173
|
+
await capture(LISTS[agent].command, LISTS[agent].args)
|
|
174
|
+
)
|
|
175
|
+
: await listProtocolModels(agent, trackHelper);
|
|
176
|
+
const models = offered.filter((entry) => entry.id);
|
|
168
177
|
store.meta(
|
|
169
178
|
catalogKey(agent),
|
|
170
179
|
JSON.stringify({ at: new Date().toISOString(), models })
|
|
@@ -267,14 +276,22 @@ export function resolveSpec(store, agent, spec) {
|
|
|
267
276
|
}
|
|
268
277
|
|
|
269
278
|
/** The agents whose model the relay sets. */
|
|
270
|
-
export const PICKABLE = new Set(
|
|
279
|
+
export const PICKABLE = new Set(MACHINE_RUNNERS);
|
|
271
280
|
const PICKED = /(?:^|\s)@([a-z][a-z0-9-]*):([^\s]+)/g;
|
|
272
281
|
/** The picks a post names, `@codex:gpt-6-luna/high`, by agent: { picks: Map, error? }. Only agents in `agents` count. */
|
|
273
282
|
export function picksIn(store, text, agents) {
|
|
274
283
|
const picks = new Map();
|
|
275
284
|
for (const match of String(text || "").matchAll(PICKED)) {
|
|
276
285
|
const agent = match[1] === "claude" ? "claude-code" : match[1];
|
|
277
|
-
if (!agents.includes(agent)
|
|
286
|
+
if (!agents.includes(agent)) continue;
|
|
287
|
+
if (!PICKABLE.has(agent)) {
|
|
288
|
+
if (member(agent)?.runtime)
|
|
289
|
+
return {
|
|
290
|
+
picks,
|
|
291
|
+
error: `${nameOf(agent)}'s model picker is not available yet. Select its model in the installed agent; Harness did not start a run with another model.`,
|
|
292
|
+
};
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
278
295
|
const spec = match[2].replace(/[.,;:!?)]+$/, "");
|
|
279
296
|
const resolved = resolveSpec(store, agent, spec);
|
|
280
297
|
if (!resolved.ok)
|
|
@@ -403,6 +420,22 @@ export const describeAgentModel = (store, id, home) => {
|
|
|
403
420
|
: agentModelSettings(id, home).model;
|
|
404
421
|
};
|
|
405
422
|
|
|
423
|
+
/** What an agent runs on now, for its tier (modelTiers.mjs): the person's choice, Auto, or its own settings. */
|
|
424
|
+
export const agentModelInUse = (store, id, home) => {
|
|
425
|
+
const choice = choiceOf(store, id);
|
|
426
|
+
if (choice?.auto) return { auto: true };
|
|
427
|
+
// A choice with no effort runs at its model's default (chooseForRun), so it is rated there.
|
|
428
|
+
if (choice?.model)
|
|
429
|
+
return {
|
|
430
|
+
model: choice.model,
|
|
431
|
+
effort:
|
|
432
|
+
choice.effort ??
|
|
433
|
+
findModel(store, id, choice.model)?.entry?.defaultEffort ??
|
|
434
|
+
null,
|
|
435
|
+
};
|
|
436
|
+
return agentModelSettings(id, home);
|
|
437
|
+
};
|
|
438
|
+
|
|
406
439
|
/** The pick named for one run (a post, post_task), kept with the run until it starts. */
|
|
407
440
|
export const setRunPick = (store, runId, pick, by) =>
|
|
408
441
|
store.meta(`model:${runId}`, JSON.stringify({ ...pick, by }));
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
|
|
3
|
+
/** One owned Muse session, including tools and frames sent during its opening handshake. */
|
|
4
|
+
export async function openMuseSession({
|
|
5
|
+
host,
|
|
6
|
+
task,
|
|
7
|
+
signal,
|
|
8
|
+
onApproval,
|
|
9
|
+
onApprovalError,
|
|
10
|
+
observe = () => {},
|
|
11
|
+
}) {
|
|
12
|
+
const { Session, MspError, readSessionDurability } =
|
|
13
|
+
await import("@muse-code/sdk");
|
|
14
|
+
if (!host.initializeResult.grantedCapabilities.includes("sessionMcp"))
|
|
15
|
+
throw new Error(
|
|
16
|
+
"This Muse Code host does not offer session MCP tools. Update the installed CLI before running it with Harness."
|
|
17
|
+
);
|
|
18
|
+
const durability = readSessionDurability(host.initializeResult);
|
|
19
|
+
if (task.sessionId && durability.kind !== "durable")
|
|
20
|
+
throw new Error(
|
|
21
|
+
"This Muse host does not preserve sessions across processes. Harness did not start a replacement conversation."
|
|
22
|
+
);
|
|
23
|
+
const connection = host.connection;
|
|
24
|
+
let session = null;
|
|
25
|
+
let opening = true;
|
|
26
|
+
let closing = false;
|
|
27
|
+
let ended = false;
|
|
28
|
+
const held = [];
|
|
29
|
+
const route = (frame) => {
|
|
30
|
+
if (session && frame.params?.sessionId === session.sessionId) {
|
|
31
|
+
observe(
|
|
32
|
+
"stdout",
|
|
33
|
+
JSON.stringify({ type: "msp.notification", ...frame }) + "\n"
|
|
34
|
+
);
|
|
35
|
+
session.apply(frame);
|
|
36
|
+
} else if (opening) held.push(frame);
|
|
37
|
+
};
|
|
38
|
+
connection.onNotification(route);
|
|
39
|
+
connection.onServerRequest(async (request) => {
|
|
40
|
+
if (request.method === "approval/request") {
|
|
41
|
+
if (session && request.params?.sessionId !== session.sessionId)
|
|
42
|
+
throw new MspError({
|
|
43
|
+
code: -32602,
|
|
44
|
+
message: "This request belongs to another Muse session.",
|
|
45
|
+
data: { kind: "invalidParams", retryable: false },
|
|
46
|
+
});
|
|
47
|
+
route(request);
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
throw new MspError({
|
|
51
|
+
code: -32601,
|
|
52
|
+
message: `Unsupported Muse request: ${request.method}`,
|
|
53
|
+
data: { kind: "methodNotFound", retryable: false },
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
void connection.closed.then(() => {
|
|
57
|
+
ended = true;
|
|
58
|
+
if (!closing) session?.hostExited({ kind: "transportEof" });
|
|
59
|
+
});
|
|
60
|
+
void host.child.exit.then((exit) => {
|
|
61
|
+
ended = true;
|
|
62
|
+
session?.hostExited(exit);
|
|
63
|
+
});
|
|
64
|
+
const verb = task.sessionId ? "session/resume" : "session/start";
|
|
65
|
+
const config = {
|
|
66
|
+
mcpServers: {
|
|
67
|
+
harness: {
|
|
68
|
+
transport: "stdio",
|
|
69
|
+
mode: "required",
|
|
70
|
+
command: process.execPath,
|
|
71
|
+
args: [
|
|
72
|
+
fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)),
|
|
73
|
+
"--agent",
|
|
74
|
+
task.agent,
|
|
75
|
+
],
|
|
76
|
+
env: { HARNESS_RUN_ID: task.runId },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
signal.throwIfAborted();
|
|
81
|
+
const result = await connection.command(verb, {
|
|
82
|
+
config,
|
|
83
|
+
...(task.sessionId
|
|
84
|
+
? { sessionId: task.sessionId, excludeItems: true }
|
|
85
|
+
: {
|
|
86
|
+
workspaceRoot: task.cwd,
|
|
87
|
+
...(task.model ? { modelId: task.model } : {}),
|
|
88
|
+
...(task.approvalMode ? { approvalMode: task.approvalMode } : {}),
|
|
89
|
+
}),
|
|
90
|
+
});
|
|
91
|
+
signal.throwIfAborted();
|
|
92
|
+
if (ended)
|
|
93
|
+
throw new Error("The Muse host closed while opening this session.");
|
|
94
|
+
const sessionId = result.session?.sessionId;
|
|
95
|
+
if (!sessionId || (task.sessionId && sessionId !== task.sessionId))
|
|
96
|
+
throw new Error(
|
|
97
|
+
"Muse returned a different session identity. Harness did not submit the turn."
|
|
98
|
+
);
|
|
99
|
+
session = new Session({
|
|
100
|
+
connection,
|
|
101
|
+
durability,
|
|
102
|
+
sessionId,
|
|
103
|
+
opening: { verb, result },
|
|
104
|
+
});
|
|
105
|
+
if (onApproval) session.onApproval(onApproval);
|
|
106
|
+
if (onApprovalError) session.onApprovalError(onApprovalError);
|
|
107
|
+
opening = false;
|
|
108
|
+
for (const frame of held)
|
|
109
|
+
if (frame.params?.sessionId === sessionId) route(frame);
|
|
110
|
+
held.length = 0;
|
|
111
|
+
return {
|
|
112
|
+
session,
|
|
113
|
+
resumable: durability.kind === "durable",
|
|
114
|
+
close: async () => {
|
|
115
|
+
closing = true;
|
|
116
|
+
await host.close();
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { paths } from "./paths.mjs";
|
|
5
|
+
|
|
6
|
+
// The Harness extension finds the daemon on its own computer through Chrome's native messaging: Chrome starts this
|
|
7
|
+
// host for the extension, one message in and one answer out, so the Harness window links to the computer it runs on
|
|
8
|
+
// with no `tryharness link`. The host says which computer this is (its public key and name) and, asked, makes a link
|
|
9
|
+
// offer for this browser exactly as `tryharness link` does; the page pairs with it through Harness, sealed.
|
|
10
|
+
//
|
|
11
|
+
// Only the extension named in the manifest's allowed_origins can start the host (Chrome enforces it). Its ID is fixed
|
|
12
|
+
// by the public key in packages/browser-extension/manifest.json, the Chrome Web Store item's.
|
|
13
|
+
|
|
14
|
+
export const HOST_NAME = "ai.tryharness.daemon";
|
|
15
|
+
export const EXTENSION_IDS = ["ekdjlnkjchjplkadglnaolilhpnokgok"];
|
|
16
|
+
// Chrome refuses a message from a host larger than 1 MB; ours are a few hundred bytes.
|
|
17
|
+
const MAX_MESSAGE_BYTES = 64 * 1024;
|
|
18
|
+
|
|
19
|
+
// Where each Chromium browser reads a person's own host manifests: its user data folder's NativeMessagingHosts.
|
|
20
|
+
// A browser that is not installed (its folder absent) gets none.
|
|
21
|
+
function browserFolders(platform, home) {
|
|
22
|
+
if (platform === "darwin") {
|
|
23
|
+
const support = path.join(home, "Library", "Application Support");
|
|
24
|
+
return [
|
|
25
|
+
"Google/Chrome",
|
|
26
|
+
"Google/Chrome Beta",
|
|
27
|
+
"Google/Chrome Canary",
|
|
28
|
+
"Chromium",
|
|
29
|
+
"BraveSoftware/Brave-Browser",
|
|
30
|
+
"Microsoft Edge",
|
|
31
|
+
"Vivaldi",
|
|
32
|
+
].map((folder) => path.join(support, folder));
|
|
33
|
+
}
|
|
34
|
+
if (platform === "linux") {
|
|
35
|
+
const config = process.env.XDG_CONFIG_HOME || path.join(home, ".config");
|
|
36
|
+
return [
|
|
37
|
+
"google-chrome",
|
|
38
|
+
"google-chrome-beta",
|
|
39
|
+
"chromium",
|
|
40
|
+
"BraveSoftware/Brave-Browser",
|
|
41
|
+
"microsoft-edge",
|
|
42
|
+
"vivaldi",
|
|
43
|
+
].map((folder) => path.join(config, folder));
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const manifestFor = (program) => ({
|
|
49
|
+
name: HOST_NAME,
|
|
50
|
+
description:
|
|
51
|
+
"Harness: links the Harness window to the daemon on this computer",
|
|
52
|
+
path: program,
|
|
53
|
+
type: "stdio",
|
|
54
|
+
allowed_origins: EXTENSION_IDS.map((id) => `chrome-extension://${id}/`),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Installs the host for every Chromium browser on this computer: a launcher in Harness's folder that runs this
|
|
59
|
+
* runtime's CLI, and a manifest beside each browser's profiles. Windows registers hosts in the registry instead, which
|
|
60
|
+
* this does not do yet; there the person links with `tryharness link`.
|
|
61
|
+
*/
|
|
62
|
+
export function installNativeHost({
|
|
63
|
+
runtimeRoot,
|
|
64
|
+
nodePath = process.execPath,
|
|
65
|
+
platform = process.platform,
|
|
66
|
+
home = os.homedir(),
|
|
67
|
+
folders = browserFolders(platform, home),
|
|
68
|
+
}) {
|
|
69
|
+
if (platform !== "darwin" && platform !== "linux")
|
|
70
|
+
return {
|
|
71
|
+
installed: [],
|
|
72
|
+
skipped: `native messaging is not set up on ${platform}`,
|
|
73
|
+
};
|
|
74
|
+
const program = path.join(paths.home, "native-host");
|
|
75
|
+
fs.mkdirSync(paths.home, { recursive: true });
|
|
76
|
+
fs.writeFileSync(
|
|
77
|
+
program,
|
|
78
|
+
`#!/bin/sh\nexec ${shellQuote(nodePath)} ${shellQuote(path.join(runtimeRoot, "cli.mjs"))} native-host "$@"\n`,
|
|
79
|
+
{ mode: 0o700 }
|
|
80
|
+
);
|
|
81
|
+
const installed = [];
|
|
82
|
+
for (const folder of folders) {
|
|
83
|
+
if (!fs.existsSync(folder)) continue;
|
|
84
|
+
const hosts = path.join(folder, "NativeMessagingHosts");
|
|
85
|
+
fs.mkdirSync(hosts, { recursive: true });
|
|
86
|
+
fs.writeFileSync(
|
|
87
|
+
path.join(hosts, `${HOST_NAME}.json`),
|
|
88
|
+
JSON.stringify(manifestFor(program), null, 2) + "\n"
|
|
89
|
+
);
|
|
90
|
+
installed.push(hosts);
|
|
91
|
+
}
|
|
92
|
+
return { installed, program };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Takes the host out of every browser and Harness's folder (`tryharness disconnect`). */
|
|
96
|
+
export function removeNativeHost({
|
|
97
|
+
platform = process.platform,
|
|
98
|
+
home = os.homedir(),
|
|
99
|
+
folders = browserFolders(platform, home),
|
|
100
|
+
} = {}) {
|
|
101
|
+
for (const folder of folders)
|
|
102
|
+
fs.rmSync(path.join(folder, "NativeMessagingHosts", `${HOST_NAME}.json`), {
|
|
103
|
+
force: true,
|
|
104
|
+
});
|
|
105
|
+
fs.rmSync(path.join(paths.home, "native-host"), { force: true });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const shellQuote = (value) => `'${String(value).replaceAll("'", `'\\''`)}'`;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The host itself, run by Chrome: reads length-prefixed JSON messages on `input` and answers each on `output`.
|
|
112
|
+
* `daemon(request)` is the daemon's control socket. Answers: `this-computer` with {publicKey, hostname, label, role},
|
|
113
|
+
* `computer-offer` with a pairing link's fragment for this browser.
|
|
114
|
+
*/
|
|
115
|
+
export async function serveNativeHost({
|
|
116
|
+
input,
|
|
117
|
+
output,
|
|
118
|
+
daemon,
|
|
119
|
+
pauseMs = 10_000,
|
|
120
|
+
}) {
|
|
121
|
+
let closed = false;
|
|
122
|
+
let listening = false;
|
|
123
|
+
// `listen` (the extension's computerWake.js): from now on what this computer hands the Harness page is passed on as
|
|
124
|
+
// it comes. The daemon not running is waited out, never answered by closing: the open port is how the browser hears.
|
|
125
|
+
const listen = async () => {
|
|
126
|
+
while (!closed) {
|
|
127
|
+
const asked = await daemon(
|
|
128
|
+
{ command: "browser.wake.next", waitMs: 25_000 },
|
|
129
|
+
30_000
|
|
130
|
+
).catch(() => null);
|
|
131
|
+
for (const message of asked?.messages ?? [])
|
|
132
|
+
if (!closed) writeMessage(output, { type: "for-harness", message });
|
|
133
|
+
if (!asked?.ok && !closed)
|
|
134
|
+
await new Promise((resolve) => setTimeout(resolve, pauseMs));
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const answer = async (message) => {
|
|
138
|
+
if (message?.type === "listen") {
|
|
139
|
+
if (!listening) {
|
|
140
|
+
listening = true;
|
|
141
|
+
void listen();
|
|
142
|
+
}
|
|
143
|
+
return { ok: true, listening: true };
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
if (message?.type === "this-computer") {
|
|
147
|
+
const found = await daemon({ command: "phone.identity" });
|
|
148
|
+
return found?.ok
|
|
149
|
+
? {
|
|
150
|
+
ok: true,
|
|
151
|
+
computer: {
|
|
152
|
+
publicKey: found.publicKey,
|
|
153
|
+
hostname: found.hostname,
|
|
154
|
+
label: found.label ?? null,
|
|
155
|
+
role: found.role ?? null,
|
|
156
|
+
joined: found.joined !== false,
|
|
157
|
+
connected: found.connected !== false,
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
: { ok: false, error: found?.error || "the daemon did not say" };
|
|
161
|
+
}
|
|
162
|
+
if (message?.type === "computer-offer") {
|
|
163
|
+
const made = await daemon({ command: "phone.offer", kind: "browser" });
|
|
164
|
+
if (!made?.ok || typeof made.url !== "string")
|
|
165
|
+
return { ok: false, error: made?.error || "no offer was made" };
|
|
166
|
+
return { ok: true, fragment: new URL(made.url).hash };
|
|
167
|
+
}
|
|
168
|
+
return { ok: false, error: "unknown message" };
|
|
169
|
+
} catch (error) {
|
|
170
|
+
// The daemon not running is the common case: setup was never finished here, or it stopped.
|
|
171
|
+
return {
|
|
172
|
+
ok: false,
|
|
173
|
+
error: `the Harness daemon on this computer is not running (${error.message})`,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
let buffered = Buffer.alloc(0);
|
|
178
|
+
for await (const chunk of input) {
|
|
179
|
+
buffered = Buffer.concat([buffered, chunk]);
|
|
180
|
+
while (buffered.length >= 4) {
|
|
181
|
+
const length = buffered.readUInt32LE(0);
|
|
182
|
+
if (length > MAX_MESSAGE_BYTES) return;
|
|
183
|
+
if (buffered.length < 4 + length) break;
|
|
184
|
+
const body = buffered.subarray(4, 4 + length).toString("utf8");
|
|
185
|
+
buffered = buffered.subarray(4 + length);
|
|
186
|
+
let message = null;
|
|
187
|
+
try {
|
|
188
|
+
message = JSON.parse(body);
|
|
189
|
+
} catch {
|
|
190
|
+
/* answered as unknown */
|
|
191
|
+
}
|
|
192
|
+
writeMessage(output, await answer(message));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
closed = true;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function writeMessage(output, message) {
|
|
199
|
+
const body = Buffer.from(JSON.stringify(message), "utf8");
|
|
200
|
+
const header = Buffer.alloc(4);
|
|
201
|
+
header.writeUInt32LE(body.length, 0);
|
|
202
|
+
output.write(Buffer.concat([header, body]));
|
|
203
|
+
}
|
package/lib/network.mjs
CHANGED
|
@@ -67,9 +67,14 @@ export function createNetwork({
|
|
|
67
67
|
thread.role === "target" &&
|
|
68
68
|
thread.status === "requested"
|
|
69
69
|
)
|
|
70
|
-
invited.push({
|
|
70
|
+
invited.push({
|
|
71
|
+
id: thread.id,
|
|
72
|
+
project,
|
|
73
|
+
sender: peer.handle,
|
|
74
|
+
fingerprint: keyPrint,
|
|
75
|
+
});
|
|
71
76
|
if (thread.role === "asker")
|
|
72
|
-
sent.push({ id: thread.id, status: thread.status });
|
|
77
|
+
sent.push({ id: thread.id, status: thread.status, project });
|
|
73
78
|
continue;
|
|
74
79
|
}
|
|
75
80
|
items.push(
|
package/lib/nudge.mjs
CHANGED
|
@@ -89,8 +89,9 @@ const shorterLists = (render, count, from) =>
|
|
|
89
89
|
);
|
|
90
90
|
|
|
91
91
|
// The session start as sections (fit.mjs): the queue first and always; the goal rooms, newest first, down to a count
|
|
92
|
-
// and list_tasks;
|
|
93
|
-
//
|
|
92
|
+
// and list_tasks; who this agent is and the computer it runs on, always; the swarm's cards whole, then short, then
|
|
93
|
+
// list_agents; what the person told the swarm, then list_agents. `swarm` is the daemon's block
|
|
94
|
+
// ({ text, cards, short, told, you }), or its text alone from an older daemon.
|
|
94
95
|
function sessionSections(agent, tasks, unread, goals, swarm) {
|
|
95
96
|
const queue = {
|
|
96
97
|
waiting: (tasks || []).filter(
|
|
@@ -143,6 +144,13 @@ function sessionSections(agent, tasks, unread, goals, swarm) {
|
|
|
143
144
|
},
|
|
144
145
|
]
|
|
145
146
|
: [];
|
|
147
|
+
if (swarm?.you)
|
|
148
|
+
sections.push({
|
|
149
|
+
name: "you",
|
|
150
|
+
priority: "core",
|
|
151
|
+
source: "board",
|
|
152
|
+
text: swarm.you,
|
|
153
|
+
});
|
|
146
154
|
if (typeof swarm === "string")
|
|
147
155
|
return [
|
|
148
156
|
...sections,
|