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/provenance.mjs
CHANGED
|
@@ -4,6 +4,9 @@ import { oneLine } from "./oneLine.mjs";
|
|
|
4
4
|
// every other agent writes as an agent, and an
|
|
5
5
|
// agent-written task taints everything posted under it. A label only ever tightens: a parent's
|
|
6
6
|
// or Harness's 'agent' cannot be lifted by anything below it. The server applies the same rule.
|
|
7
|
+
// Harness writes as the user only from the person's own window, sealed from their device: a post in its name that
|
|
8
|
+
// arrived in the clear through Harness's server (`viaServer`) is the server's word, so it is agent-written like any
|
|
9
|
+
// hosted agent's (security audit S2).
|
|
7
10
|
|
|
8
11
|
const USER_WRITERS = new Set(["user", "harness"]);
|
|
9
12
|
|
|
@@ -11,7 +14,7 @@ export function provenanceFor(
|
|
|
11
14
|
originAgent,
|
|
12
15
|
parent = null,
|
|
13
16
|
claimed = null,
|
|
14
|
-
{ personSession = false } = {}
|
|
17
|
+
{ personSession = false, viaServer = false } = {}
|
|
15
18
|
) {
|
|
16
19
|
// A claim counts only when it tightens: an 'agent' label and its chain. A claim of 'user' adds nothing.
|
|
17
20
|
const taint = claimed?.trust === "agent" ? claimed : null;
|
|
@@ -23,6 +26,7 @@ export function provenanceFor(
|
|
|
23
26
|
const tainted =
|
|
24
27
|
parent?.trust === "agent" ||
|
|
25
28
|
Boolean(taint) ||
|
|
29
|
+
(viaServer && originAgent !== "user") ||
|
|
26
30
|
(!USER_WRITERS.has(originAgent) && !personSession);
|
|
27
31
|
return {
|
|
28
32
|
trust: originAgent === "user" || !tainted ? "user" : "agent",
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { readJson, writeJsonAtomic } from "./files.mjs";
|
|
4
|
+
import { modelCallUrl } from "./lane.mjs";
|
|
5
|
+
import { paths } from "./paths.mjs";
|
|
6
|
+
|
|
7
|
+
// A proxy link, on the computer that reaches the person's own model (docs/cloud-swarm.md, inference boundary): the
|
|
8
|
+
// person lets one of their cloud computers use a model endpoint only this computer reaches (a model server on it, or
|
|
9
|
+
// on their network, or a provider with a key kept here). The cloud computer's agents call a local address on the box
|
|
10
|
+
// (linkRelay.mjs), which sends each call here sealed over the line the two computers share (ownMachines.mjs); Harness
|
|
11
|
+
// carries the envelopes and reads none of them. The address and any key stay here: the cloud computer knows only
|
|
12
|
+
// which link to name.
|
|
13
|
+
//
|
|
14
|
+
// Only the person's own window allows a link, naming the one cloud computer it is for. A call from any other computer,
|
|
15
|
+
// for another link, or for anything but a model call on that endpoint is refused (as lane.mjs keeps Harness's server
|
|
16
|
+
// to the person's endpoint, security audit S11).
|
|
17
|
+
//
|
|
18
|
+
// An answer comes back in parts: the box starts a call, then reads it from an offset until it ends. A read waits for
|
|
19
|
+
// bytes past its offset, and one that went unanswered (each message between computers has the line's own deadline) is
|
|
20
|
+
// asked again from the same offset, so nothing is lost or repeated and no deadline of its own is needed here.
|
|
21
|
+
|
|
22
|
+
/** The model calls a link carries, each with its method, under the endpoint's own path: the agents' three wires. */
|
|
23
|
+
export const LINK_CALLS = new Map([
|
|
24
|
+
["/chat/completions", "POST"],
|
|
25
|
+
["/completions", "POST"],
|
|
26
|
+
["/responses", "POST"],
|
|
27
|
+
["/messages", "POST"],
|
|
28
|
+
["/messages/count_tokens", "POST"],
|
|
29
|
+
["/models", "GET"],
|
|
30
|
+
]);
|
|
31
|
+
// The request headers a model call needs; the box's own token for its local address never leaves it.
|
|
32
|
+
const PASSED_HEADERS = [
|
|
33
|
+
"content-type",
|
|
34
|
+
"accept",
|
|
35
|
+
"anthropic-version",
|
|
36
|
+
"anthropic-beta",
|
|
37
|
+
"openai-beta",
|
|
38
|
+
];
|
|
39
|
+
const ID = /^[A-Za-z0-9_-]{8,64}$/;
|
|
40
|
+
// A part of an answer, before it is sealed: small, since home keeps its last answers to repeat one sent twice.
|
|
41
|
+
const PART_BYTES = 64 * 1024;
|
|
42
|
+
// Calls in flight or not yet read to their end; the oldest is dropped past this.
|
|
43
|
+
const OPEN_CALLS = 16;
|
|
44
|
+
|
|
45
|
+
export const proxyLinksFile = () => path.join(paths.home, "proxy-links.json");
|
|
46
|
+
|
|
47
|
+
// What may be said of a link anywhere: never its key.
|
|
48
|
+
const described = ({ key, ...link }) => ({ ...link, hasKey: Boolean(key) });
|
|
49
|
+
|
|
50
|
+
export function createProxyLinks({
|
|
51
|
+
file = proxyLinksFile(),
|
|
52
|
+
log = () => {},
|
|
53
|
+
fetchImpl = fetch,
|
|
54
|
+
// This computer: { id, label }, so the box knows which computer holds the link.
|
|
55
|
+
self = () => ({ id: null, label: null }),
|
|
56
|
+
// Whether a computer is one this computer confirmed with (its home, or a worker of it): only it can call here.
|
|
57
|
+
known = () => true,
|
|
58
|
+
} = {}) {
|
|
59
|
+
const links = () => readJson(file, { links: [] }).links ?? [];
|
|
60
|
+
const keep = (list) => writeJsonAtomic(file, { links: list });
|
|
61
|
+
|
|
62
|
+
/** The person's window allows one cloud computer to use an endpoint this computer reaches. */
|
|
63
|
+
const allow = ({ computer, baseUrl, key = null, label = null }) => {
|
|
64
|
+
const machine = String(computer || "");
|
|
65
|
+
if (!ID.test(machine))
|
|
66
|
+
return { ok: false, error: "Name the cloud computer the link is for." };
|
|
67
|
+
if (!known(machine))
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
error:
|
|
71
|
+
"That cloud computer is not in your swarm with this computer yet. Add it to your swarm first.",
|
|
72
|
+
};
|
|
73
|
+
let base;
|
|
74
|
+
try {
|
|
75
|
+
base = new URL(String(baseUrl || "").trim());
|
|
76
|
+
} catch {
|
|
77
|
+
return { ok: false, error: "That is not an address." };
|
|
78
|
+
}
|
|
79
|
+
if (!["http:", "https:"].includes(base.protocol) || base.username)
|
|
80
|
+
return {
|
|
81
|
+
ok: false,
|
|
82
|
+
error: "Use an http or https address, with no name or password in it.",
|
|
83
|
+
};
|
|
84
|
+
const secret = key == null ? "" : String(key).trim();
|
|
85
|
+
if (secret && !/^[\x21-\x7e]{8,500}$/.test(secret))
|
|
86
|
+
return { ok: false, error: "That does not look like a key." };
|
|
87
|
+
const baseText = base.href.replace(/\/+$/, "");
|
|
88
|
+
const kept = links().filter(
|
|
89
|
+
(link) => !(link.computer === machine && link.baseUrl === baseText)
|
|
90
|
+
);
|
|
91
|
+
const link = {
|
|
92
|
+
id: randomBytes(12).toString("base64url"),
|
|
93
|
+
computer: machine,
|
|
94
|
+
baseUrl: baseText,
|
|
95
|
+
...(secret ? { key: secret } : {}),
|
|
96
|
+
label: label ? String(label).slice(0, 80) : null,
|
|
97
|
+
at: new Date().toISOString(),
|
|
98
|
+
};
|
|
99
|
+
keep([...kept, link]);
|
|
100
|
+
log(`proxy link: ${baseText} allowed for cloud computer ${machine}`);
|
|
101
|
+
const here = self();
|
|
102
|
+
return {
|
|
103
|
+
ok: true,
|
|
104
|
+
link: { ...described(link), holder: here.id, holderLabel: here.label },
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const list = () => ({ ok: true, links: links().map(described) });
|
|
109
|
+
|
|
110
|
+
const forget = (id) => {
|
|
111
|
+
keep(links().filter((link) => link.id !== String(id)));
|
|
112
|
+
for (const [callId, call] of calls)
|
|
113
|
+
if (call.link === String(id)) drop(callId);
|
|
114
|
+
return list();
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// ---- calls in flight: id -> { link, from, head, parts, total, done, error, waiters, abort } ----
|
|
118
|
+
const calls = new Map();
|
|
119
|
+
const drop = (id) => {
|
|
120
|
+
const call = calls.get(id);
|
|
121
|
+
if (!call) return;
|
|
122
|
+
calls.delete(id);
|
|
123
|
+
call.abort.abort();
|
|
124
|
+
call.done = true;
|
|
125
|
+
for (const wake of call.waiters.splice(0)) wake();
|
|
126
|
+
};
|
|
127
|
+
const changed = (call) => {
|
|
128
|
+
for (const wake of call.waiters.splice(0)) wake();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const startCall = (
|
|
132
|
+
from,
|
|
133
|
+
{ link: linkId, method = "POST", path: callPath, headers = {}, body = null }
|
|
134
|
+
) => {
|
|
135
|
+
const link = links().find((each) => each.id === String(linkId));
|
|
136
|
+
if (!link || link.computer !== from)
|
|
137
|
+
return {
|
|
138
|
+
ok: false,
|
|
139
|
+
status: 403,
|
|
140
|
+
error:
|
|
141
|
+
"This proxy link is not allowed for this computer. Set it up again in Harness.",
|
|
142
|
+
};
|
|
143
|
+
const target = modelCallUrl(
|
|
144
|
+
link.baseUrl,
|
|
145
|
+
`${link.baseUrl}${String(callPath || "")}`,
|
|
146
|
+
String(method),
|
|
147
|
+
LINK_CALLS
|
|
148
|
+
);
|
|
149
|
+
if (!target)
|
|
150
|
+
return {
|
|
151
|
+
ok: false,
|
|
152
|
+
status: 403,
|
|
153
|
+
error: `${method} ${callPath} is not a model call this link carries`,
|
|
154
|
+
};
|
|
155
|
+
while (calls.size >= OPEN_CALLS) drop(calls.keys().next().value);
|
|
156
|
+
const id = randomBytes(12).toString("base64url");
|
|
157
|
+
const call = {
|
|
158
|
+
link: link.id,
|
|
159
|
+
from,
|
|
160
|
+
head: null,
|
|
161
|
+
parts: [],
|
|
162
|
+
total: 0,
|
|
163
|
+
done: false,
|
|
164
|
+
error: null,
|
|
165
|
+
waiters: [],
|
|
166
|
+
abort: new AbortController(),
|
|
167
|
+
};
|
|
168
|
+
calls.set(id, call);
|
|
169
|
+
const sent = Object.fromEntries(
|
|
170
|
+
PASSED_HEADERS.filter((name) => headers[name] != null).map((name) => [
|
|
171
|
+
name,
|
|
172
|
+
String(headers[name]),
|
|
173
|
+
])
|
|
174
|
+
);
|
|
175
|
+
if (link.key) {
|
|
176
|
+
sent.authorization = `Bearer ${link.key}`;
|
|
177
|
+
sent["x-api-key"] = link.key;
|
|
178
|
+
}
|
|
179
|
+
void (async () => {
|
|
180
|
+
try {
|
|
181
|
+
const response = await fetchImpl(target, {
|
|
182
|
+
method,
|
|
183
|
+
headers: sent,
|
|
184
|
+
...(body != null && method === "POST" ? { body: String(body) } : {}),
|
|
185
|
+
signal: call.abort.signal,
|
|
186
|
+
});
|
|
187
|
+
call.head = {
|
|
188
|
+
status: response.status,
|
|
189
|
+
contentType: response.headers.get("content-type") ?? "",
|
|
190
|
+
};
|
|
191
|
+
changed(call);
|
|
192
|
+
for await (const bytes of response.body ?? []) {
|
|
193
|
+
const part = Buffer.from(bytes);
|
|
194
|
+
call.parts.push(part);
|
|
195
|
+
call.total += part.length;
|
|
196
|
+
changed(call);
|
|
197
|
+
}
|
|
198
|
+
} catch (error) {
|
|
199
|
+
// Said without the address: the words go to the cloud computer, and the address stays here.
|
|
200
|
+
if (!call.abort.signal.aborted)
|
|
201
|
+
call.error = `your model did not answer (${error.message})`;
|
|
202
|
+
}
|
|
203
|
+
call.done = true;
|
|
204
|
+
changed(call);
|
|
205
|
+
})();
|
|
206
|
+
return { ok: true, call: id };
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// At most one part's bytes from `offset`, taken from the pieces as they came, so a long answer is not copied whole
|
|
210
|
+
// on every read.
|
|
211
|
+
const bytesFrom = (call, offset) => {
|
|
212
|
+
const taken = [];
|
|
213
|
+
let at = 0;
|
|
214
|
+
let room = PART_BYTES;
|
|
215
|
+
for (const piece of call.parts) {
|
|
216
|
+
const end = at + piece.length;
|
|
217
|
+
if (end > offset && room > 0) {
|
|
218
|
+
const from = Math.max(0, offset - at);
|
|
219
|
+
const slice = piece.subarray(from, from + room);
|
|
220
|
+
taken.push(slice);
|
|
221
|
+
room -= slice.length;
|
|
222
|
+
}
|
|
223
|
+
at = end;
|
|
224
|
+
if (room <= 0) break;
|
|
225
|
+
}
|
|
226
|
+
return Buffer.concat(taken);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/** Waits for the call's answer past `offset` (or its end), then gives the next part of it. */
|
|
230
|
+
const readCall = async (from, { call: id, offset = 0 }) => {
|
|
231
|
+
const call = calls.get(String(id));
|
|
232
|
+
if (!call || call.from !== from)
|
|
233
|
+
return { ok: false, error: "that call is over here" };
|
|
234
|
+
const at = Math.max(0, Math.floor(Number(offset) || 0));
|
|
235
|
+
while (!call.done && !(call.head && call.total > at))
|
|
236
|
+
await new Promise((wake) => call.waiters.push(wake));
|
|
237
|
+
const data = bytesFrom(call, at);
|
|
238
|
+
const next = at + data.length;
|
|
239
|
+
return {
|
|
240
|
+
ok: true,
|
|
241
|
+
...(call.head ?? {}),
|
|
242
|
+
data: data.toString("base64"),
|
|
243
|
+
offset: next,
|
|
244
|
+
done: call.done && next >= call.total,
|
|
245
|
+
...(call.error ? { error: call.error } : {}),
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/** A call from one of the person's cloud computers, already opened from its sealed message. */
|
|
250
|
+
const answer = async (from, request) => {
|
|
251
|
+
const op = String(request?.op || "");
|
|
252
|
+
if (op === "start") return startCall(String(from), request);
|
|
253
|
+
if (op === "read") return readCall(String(from), request);
|
|
254
|
+
if (op === "close") {
|
|
255
|
+
if (calls.get(String(request.call))?.from === String(from))
|
|
256
|
+
drop(String(request.call));
|
|
257
|
+
return { ok: true };
|
|
258
|
+
}
|
|
259
|
+
return { ok: false, error: "unknown proxy link call" };
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const close = () => {
|
|
263
|
+
for (const id of [...calls.keys()]) drop(id);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
return { allow, list, forget, answer, close };
|
|
267
|
+
}
|
package/lib/reactions.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// The person's reaction to their agents' work, step 1b of the swarm's learning. When the person posts in a thread after
|
|
2
|
-
// agents delivered something since they last wrote, Harness's server reads the post against that work
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
2
|
+
// agents delivered something since they last wrote, Harness's server reads the post against that work: approves,
|
|
3
|
+
// approves with changes, rejects, or not a reaction, and whose work it is about (one agent's post, or what they made
|
|
4
|
+
// together). The verdict is kept on this board for each agent it is about, and each agent's card counts the verdicts on
|
|
5
|
+
// its work (cards.mjs). Nothing is read on the privacy setting, with this computer off Harness, or from a Harness that
|
|
6
|
+
// does not read reactions (swarm_reactions): such a post has no verdict.
|
|
7
7
|
|
|
8
8
|
// What an agent delivers in a thread: its result, a post or a file. Questions, notes and held posts are not work.
|
|
9
9
|
const WORK_KINDS = new Set(["result", "post", "file"]);
|
|
@@ -53,6 +53,7 @@ export function createReactions({
|
|
|
53
53
|
readsReactions,
|
|
54
54
|
isCoordinatorPost,
|
|
55
55
|
log,
|
|
56
|
+
onVerdict = () => {},
|
|
56
57
|
}) {
|
|
57
58
|
/** Read the person's post in a thread; resolves once its verdicts are kept, or there is none to keep. */
|
|
58
59
|
const heard = async (thread, post) => {
|
|
@@ -101,6 +102,7 @@ export function createReactions({
|
|
|
101
102
|
verdict: reaction.verdict,
|
|
102
103
|
judgments: reaction.judgments ?? null,
|
|
103
104
|
});
|
|
105
|
+
onVerdict(thread.id, agents);
|
|
104
106
|
return { agents, verdict: reaction.verdict };
|
|
105
107
|
};
|
|
106
108
|
|
package/lib/readiness.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
4
|
-
import {
|
|
5
|
+
import { runProtocolTask } from "./agentRuntimes.mjs";
|
|
6
|
+
import { MACHINE_RUNNERS, member, nameOf } from "./members.mjs";
|
|
5
7
|
import { paths } from "./paths.mjs";
|
|
6
8
|
import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
|
|
7
9
|
|
|
@@ -11,11 +13,10 @@ import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
|
|
|
11
13
|
// changes (createAgentWatch below), so an agent installed later joins the swarm by itself.
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
|
-
* How long one check may take. Measured
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* reported as slow and can be tried again, never as signed out.
|
|
16
|
+
* How long one check may take. Measured on one Mac: with the commands below, 12 checks (Claude Code, Codex, Pi,
|
|
17
|
+
* OpenCode, 3 rounds) answered in 2.1-5.2 s; with the fuller run commands, 12 answered in 2.2-24.9 s, the slowest Pi's
|
|
18
|
+
* first start. Signed out, checks failed in 0.2-14.4 s (Codex retries a 401 for 14 s). 60 s is 2.4x the slowest answer
|
|
19
|
+
* seen. A check that reaches it is reported as slow and can be tried again, never as signed out.
|
|
19
20
|
*/
|
|
20
21
|
export const CHECK_DEADLINE_MS = 60_000;
|
|
21
22
|
|
|
@@ -24,6 +25,10 @@ const PROMPT = "Reply with exactly one word: ready";
|
|
|
24
25
|
// Each agent's shortest headless run that still goes through its own sign-in: no tools, no Harness MCP server, and no
|
|
25
26
|
// session saved to the person's history where the agent allows it (OpenCode has no such switch).
|
|
26
27
|
const CHECKS = {
|
|
28
|
+
// None of the person's hooks either, Harness's own included. Claude Code runs them in a headless run too, and hands a
|
|
29
|
+
// failing Stop hook's error back as a new turn: claude-mem's needs the transcript this run does not save, so the
|
|
30
|
+
// check went 10 turns and ended with an empty answer (Claude Code 2.1.309). `--bare` also skips hooks but reads no
|
|
31
|
+
// OAuth sign-in, the thing checked.
|
|
27
32
|
"claude-code": () => ({
|
|
28
33
|
command: "claude",
|
|
29
34
|
args: [
|
|
@@ -35,6 +40,8 @@ const CHECKS = {
|
|
|
35
40
|
"--strict-mcp-config",
|
|
36
41
|
"--tools",
|
|
37
42
|
"",
|
|
43
|
+
"--settings",
|
|
44
|
+
'{"disableAllHooks":true}',
|
|
38
45
|
],
|
|
39
46
|
}),
|
|
40
47
|
codex: () => ({
|
|
@@ -61,8 +68,16 @@ const CHECKS = {
|
|
|
61
68
|
}),
|
|
62
69
|
};
|
|
63
70
|
|
|
71
|
+
// An agent Harness runs through its own protocol (ACP, or Muse Code's MSP: `runtime` in members.json, and the person's
|
|
72
|
+
// own ACP agents) takes the same prompt the way it takes work (agentRuntimes.mjs), without Harness's tools. Its session
|
|
73
|
+
// can stay in the agent's own history: neither protocol has a switch to keep one out.
|
|
74
|
+
const byProtocol = (agent) => !CHECKS[agent] && Boolean(member(agent)?.runtime);
|
|
75
|
+
|
|
64
76
|
/** The agents Harness can check by sending them a prompt. */
|
|
65
|
-
export const CHECKABLE =
|
|
77
|
+
export const CHECKABLE = [
|
|
78
|
+
...Object.keys(CHECKS),
|
|
79
|
+
...MACHINE_RUNNERS.filter(byProtocol),
|
|
80
|
+
];
|
|
66
81
|
|
|
67
82
|
/** What the person runs to sign an agent in, as setup and the browser say it. */
|
|
68
83
|
export const SIGN_IN = {
|
|
@@ -73,8 +88,10 @@ export const SIGN_IN = {
|
|
|
73
88
|
};
|
|
74
89
|
|
|
75
90
|
// The words each agent prints when it has no sign-in to use: a missing login, a missing key, or a 401 from its provider.
|
|
91
|
+
// Over ACP and MSP: "Authentication required" (auth_required), Muse Code's authRequired, and Cursor's stale login, which
|
|
92
|
+
// it answers as ordinary text ("Please sign in to continue"; Cursor staff, June 2026).
|
|
76
93
|
const SIGNED_OUT =
|
|
77
|
-
/not logged in|please run \/login|use \/login|no api key|api key not found|missing bearer|401|unauthori[sz]ed|invalid api key|authentication/i;
|
|
94
|
+
/not logged in|please run \/login|use \/login|no api key|api key not found|missing bearer|401|unauthori[sz]ed|invalid api key|authentication|auth[ _-]?required|please sign in|sign in to continue/i;
|
|
78
95
|
|
|
79
96
|
const lastLine = (text) =>
|
|
80
97
|
String(text)
|
|
@@ -104,9 +121,12 @@ export function checkAgent(
|
|
|
104
121
|
{
|
|
105
122
|
cwd = path.join(paths.home, "checks"),
|
|
106
123
|
run = spawn,
|
|
124
|
+
runTask = runProtocolTask,
|
|
107
125
|
deadlineMs = CHECK_DEADLINE_MS,
|
|
108
126
|
} = {}
|
|
109
127
|
) {
|
|
128
|
+
if (byProtocol(agent))
|
|
129
|
+
return checkByProtocol(agent, { cwd, runTask, deadlineMs });
|
|
110
130
|
const invocation = CHECKS[agent]?.();
|
|
111
131
|
if (!invocation)
|
|
112
132
|
return Promise.resolve({
|
|
@@ -150,6 +170,59 @@ export function checkAgent(
|
|
|
150
170
|
});
|
|
151
171
|
}
|
|
152
172
|
|
|
173
|
+
async function checkByProtocol(agent, { cwd, runTask, deadlineMs }) {
|
|
174
|
+
ensureDir(cwd);
|
|
175
|
+
const started = Date.now();
|
|
176
|
+
const stop = new AbortController();
|
|
177
|
+
let timedOut = false;
|
|
178
|
+
const timer = setTimeout(() => {
|
|
179
|
+
timedOut = true;
|
|
180
|
+
stop.abort();
|
|
181
|
+
}, deadlineMs);
|
|
182
|
+
let answer = null;
|
|
183
|
+
let failure = null;
|
|
184
|
+
try {
|
|
185
|
+
await runTask(
|
|
186
|
+
{
|
|
187
|
+
agent,
|
|
188
|
+
cwd,
|
|
189
|
+
brief: PROMPT,
|
|
190
|
+
title: "Harness check",
|
|
191
|
+
runId: "readiness",
|
|
192
|
+
withoutHarnessTools: true,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
emit: (kind, text) => {
|
|
196
|
+
if (kind === "done") answer = text;
|
|
197
|
+
if (kind === "failed") failure = text;
|
|
198
|
+
},
|
|
199
|
+
observe: () => {},
|
|
200
|
+
signal: stop.signal,
|
|
201
|
+
}
|
|
202
|
+
);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
failure = error.message;
|
|
205
|
+
} finally {
|
|
206
|
+
clearTimeout(timer);
|
|
207
|
+
}
|
|
208
|
+
// What agentRuntimes.mjs says when the agent's command is not on this computer.
|
|
209
|
+
const missing =
|
|
210
|
+
answer === null && /^Install and authenticate/.test(failure ?? "");
|
|
211
|
+
return {
|
|
212
|
+
...readCheck({
|
|
213
|
+
code: answer === null ? 1 : 0,
|
|
214
|
+
output: answer ?? failure ?? "",
|
|
215
|
+
timedOut,
|
|
216
|
+
missing,
|
|
217
|
+
}),
|
|
218
|
+
ms: Date.now() - started,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// An agent signed in where Harness cannot see joins within a quarter of an hour, at the cost of starting a signed-out
|
|
223
|
+
// agent four times an hour.
|
|
224
|
+
export const RECHECK_MS = 15 * 60_000;
|
|
225
|
+
|
|
153
226
|
/**
|
|
154
227
|
* The daemon's record of each agent's last check, kept in a file so setup, the CLI and the browser read the same answer.
|
|
155
228
|
* Each record keeps a stamp of the agent's sign-in files at the time, so a later sign-in is noticed. Two checks of one
|
|
@@ -159,6 +232,8 @@ export function createAgentReadiness({
|
|
|
159
232
|
file = path.join(paths.home, "agent-readiness.json"),
|
|
160
233
|
check = checkAgent,
|
|
161
234
|
stampOf = (agent) => signInStamp(agent),
|
|
235
|
+
watchesSignIn = (agent) =>
|
|
236
|
+
signInFiles(agent, process.env.HOME, process.env).length > 0,
|
|
162
237
|
onChange = () => {},
|
|
163
238
|
now = () => new Date(),
|
|
164
239
|
} = {}) {
|
|
@@ -187,11 +262,24 @@ export function createAgentReadiness({
|
|
|
187
262
|
};
|
|
188
263
|
/** Whether the agent's sign-in files changed since its last check (or it was never checked). */
|
|
189
264
|
const signInChanged = (agent) => of(agent)?.signIn !== stampOf(agent);
|
|
265
|
+
// An agent whose sign-in Harness cannot see (in the keychain, or the person's own ACP agent) is checked again while
|
|
266
|
+
// it is signed out, at most every RECHECK_MS, so signing it in later is noticed. A signed-out check stops before any
|
|
267
|
+
// model is asked, so it costs no tokens.
|
|
268
|
+
const signedOutSince = (agent) => {
|
|
269
|
+
const last = of(agent);
|
|
270
|
+
return last?.state === "signed_out" && !watchesSignIn(agent)
|
|
271
|
+
? now() - new Date(last.checkedAt)
|
|
272
|
+
: -1;
|
|
273
|
+
};
|
|
274
|
+
/** Whether the agent should be checked now: its sign-in changed, or it is signed out where Harness cannot see. */
|
|
275
|
+
const due = (agent) =>
|
|
276
|
+
signInChanged(agent) || signedOutSince(agent) >= RECHECK_MS;
|
|
190
277
|
return {
|
|
191
278
|
check: run,
|
|
192
279
|
of,
|
|
193
280
|
all,
|
|
194
281
|
signInChanged,
|
|
282
|
+
due,
|
|
195
283
|
checking: (agent) => running.has(agent),
|
|
196
284
|
};
|
|
197
285
|
}
|
|
@@ -201,10 +289,7 @@ function signInFiles(agent, home, env) {
|
|
|
201
289
|
const dataHome = env.XDG_DATA_HOME || path.join(home, ".local", "share");
|
|
202
290
|
switch (agent) {
|
|
203
291
|
case "claude-code":
|
|
204
|
-
return [
|
|
205
|
-
path.join(home, ".claude.json"),
|
|
206
|
-
path.join(home, ".claude", ".credentials.json"),
|
|
207
|
-
];
|
|
292
|
+
return [path.join(home, ".claude", ".credentials.json")];
|
|
208
293
|
case "codex":
|
|
209
294
|
return [
|
|
210
295
|
path.join(env.CODEX_HOME || path.join(home, ".codex"), "auth.json"),
|
|
@@ -213,20 +298,57 @@ function signInFiles(agent, home, env) {
|
|
|
213
298
|
return [path.join(home, ".pi", "agent", "auth.json")];
|
|
214
299
|
case "opencode":
|
|
215
300
|
return [path.join(dataHome, "opencode", "auth.json")];
|
|
301
|
+
// Also rewritten when Grok refreshes its token, as Codex's is (xai-org/grok-build, xai-grok-login/src/storage.rs).
|
|
302
|
+
case "grok-build":
|
|
303
|
+
return [
|
|
304
|
+
env.GROK_AUTH_PATH ||
|
|
305
|
+
path.join(env.GROK_HOME || path.join(home, ".grok"), "auth.json"),
|
|
306
|
+
];
|
|
307
|
+
case "kilo":
|
|
308
|
+
return [path.join(dataHome, "kilo", "auth.json")];
|
|
309
|
+
case "dsh":
|
|
310
|
+
return [
|
|
311
|
+
path.join(env.DSH_HOME || path.join(home, ".dsh"), ".credentials.yaml"),
|
|
312
|
+
];
|
|
313
|
+
// Devin's token, which does not expire (its auth docs).
|
|
314
|
+
case "devin":
|
|
315
|
+
return [path.join(dataHome, "devin", "credentials.toml")];
|
|
316
|
+
// Cursor, Antigravity, Copilot and Muse Code keep their sign-in in the macOS keychain, with no file that changes
|
|
317
|
+
// only then.
|
|
216
318
|
default:
|
|
217
319
|
return [];
|
|
218
320
|
}
|
|
219
321
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
322
|
+
// Claude Code rewrites ~/.claude.json in every session, its own check included, so the file's time changed every minute
|
|
323
|
+
// and the daemon checked Claude Code once a minute (60 checks an hour, each a session counted where Claude Code lives).
|
|
324
|
+
// Only the account in it says a sign-in changed; on a Mac the token itself is in the keychain.
|
|
325
|
+
function claudeAccount(home) {
|
|
326
|
+
try {
|
|
327
|
+
const config = JSON.parse(
|
|
328
|
+
fs.readFileSync(path.join(home, ".claude.json"), "utf8")
|
|
329
|
+
);
|
|
330
|
+
const account = config.oauthAccount ?? {};
|
|
331
|
+
const signedInAs = [
|
|
332
|
+
account.accountUuid,
|
|
333
|
+
account.organizationUuid,
|
|
334
|
+
config.primaryApiKey ? "key" : "",
|
|
335
|
+
].join("/");
|
|
336
|
+
return createHash("sha256").update(signedInAs).digest("hex").slice(0, 16);
|
|
337
|
+
} catch {
|
|
338
|
+
return "";
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export function signInStamp(agent, home = process.env.HOME, env = process.env) {
|
|
343
|
+
const fileTimes = signInFiles(agent, home, env).map((file) => {
|
|
344
|
+
try {
|
|
345
|
+
return fs.statSync(file).mtimeMs;
|
|
346
|
+
} catch {
|
|
347
|
+
return 0;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
const account = agent === "claude-code" ? [claudeAccount(home)] : [];
|
|
351
|
+
return [...account, ...fileTimes].join(":");
|
|
230
352
|
}
|
|
231
353
|
|
|
232
354
|
/**
|
|
@@ -247,7 +369,7 @@ export function createAgentWatch({
|
|
|
247
369
|
const scan = async () => {
|
|
248
370
|
for (const agent of installed().filter((id) => CHECKABLE.includes(id))) {
|
|
249
371
|
if (removedByPerson(agent) || readiness.checking(agent)) continue;
|
|
250
|
-
const result = readiness.
|
|
372
|
+
const result = readiness.due(agent)
|
|
251
373
|
? await readiness.check(agent)
|
|
252
374
|
: readiness.of(agent);
|
|
253
375
|
if (result?.state !== "ready" || inSwarm(agent)) continue;
|