tryharness 0.7.53 → 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 +10 -5
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +115 -36
- package/lib/adapters.mjs +157 -222
- package/lib/agentRuntimes.mjs +26 -16
- package/lib/agentSignIn.mjs +226 -0
- 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/boardMirror.mjs +71 -7
- package/lib/boardProtocol.json +59 -2
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +1 -1
- package/lib/cards.mjs +138 -28
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +7 -2
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +149 -43
- package/lib/daemon.mjs +349 -28
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +106 -6
- package/lib/environments.mjs +237 -7
- package/lib/folders.mjs +2 -2
- package/lib/gitHost.mjs +174 -0
- package/lib/hookDialects.mjs +298 -0
- package/lib/landed.mjs +887 -0
- package/lib/live.mjs +284 -13
- package/lib/mcp-stdio.mjs +68 -2
- package/lib/members.json +16 -2
- package/lib/models.mjs +8 -8
- package/lib/museSession.mjs +16 -13
- package/lib/nativeHost.mjs +1 -1
- package/lib/neovim.mjs +126 -0
- package/lib/nudge.mjs +47 -16
- package/lib/ownMachines.mjs +343 -39
- package/lib/pairing.mjs +27 -10
- package/lib/paths.mjs +4 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +66 -11
- package/lib/places.mjs +330 -10
- package/lib/readiness.mjs +135 -18
- package/lib/record.mjs +115 -0
- package/lib/runWorker.mjs +17 -2
- package/lib/runner.mjs +8 -4
- package/lib/sessionControl.mjs +377 -89
- 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 +284 -1
- package/lib/swarm.mjs +137 -21
- package/lib/t3.mjs +13 -4
- package/lib/taskCommands.mjs +36 -9
- package/lib/taskRuns.mjs +9 -2
- package/lib/team.json +255 -148
- package/lib/team.mjs +529 -188
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +75 -11
- package/lib/threadView.mjs +15 -2
- package/lib/worktrees.mjs +51 -13
- package/package.json +4 -4
- package/lib/modelTiers.json +0 -1183
- package/lib/modelTiers.mjs +0 -133
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
5
|
+
import { randomBytes } from "node:crypto";
|
|
6
|
+
import { secretReason } from "./secrets.mjs";
|
|
7
|
+
|
|
8
|
+
// Signing the agents on a cloud computer in, from the person's window (docs/cloud-swarm.md §5.6). The box has no
|
|
9
|
+
// screen and no terminal the person can reach, so each agent's OWN sign-in runs here and its words (a link, a code, a
|
|
10
|
+
// question) go to the window sealed, and the one line it may ask for (a pasted code) comes back. Nothing here parses a
|
|
11
|
+
// provider's flow beyond its status command: what the person reads is the provider's text. A line that looks like a
|
|
12
|
+
// secret is never sent; a key the person gives is handed to the agent's own login (Codex) or settings (Claude Code)
|
|
13
|
+
// and never stored by Harness. Where `script` exists (Linux) the sign-in gets a terminal of its own, since some
|
|
14
|
+
// sign-ins only talk to one.
|
|
15
|
+
|
|
16
|
+
const MAX_LINES = 200;
|
|
17
|
+
const SESSIONS = 4;
|
|
18
|
+
// ANSI colour and cursor sequences, which a terminal sign-in prints and a window cannot show.
|
|
19
|
+
const ANSI = /\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\u0007|\r/g;
|
|
20
|
+
|
|
21
|
+
export const SIGN_IN_AGENTS = {
|
|
22
|
+
"claude-code": {
|
|
23
|
+
command: "claude",
|
|
24
|
+
status: ["auth", "status", "--json"],
|
|
25
|
+
signedIn: (result) => {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(result.stdout).loggedIn === true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
subscription: ["auth", "login", "--claudeai"],
|
|
33
|
+
},
|
|
34
|
+
codex: {
|
|
35
|
+
command: "codex",
|
|
36
|
+
status: ["login", "status"],
|
|
37
|
+
signedIn: (result) => result.status === 0,
|
|
38
|
+
subscription: ["login", "--device-auth"],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const clean = (text) =>
|
|
43
|
+
String(text)
|
|
44
|
+
.replace(ANSI, "")
|
|
45
|
+
.split("\n")
|
|
46
|
+
.map((line) => line.trimEnd())
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.map((line) =>
|
|
49
|
+
secretReason(line)
|
|
50
|
+
? "(something secret was printed here; it stays on this computer)"
|
|
51
|
+
: line
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export function createAgentSignIn({
|
|
55
|
+
home = os.homedir(),
|
|
56
|
+
env = process.env,
|
|
57
|
+
run = spawn,
|
|
58
|
+
runSync = spawnSync,
|
|
59
|
+
log = () => {},
|
|
60
|
+
} = {}) {
|
|
61
|
+
const sessions = new Map();
|
|
62
|
+
const hasScript =
|
|
63
|
+
process.platform === "linux" &&
|
|
64
|
+
runSync("script", ["--version"], { stdio: "ignore" }).status === 0;
|
|
65
|
+
|
|
66
|
+
const flowOf = (agent) => {
|
|
67
|
+
const flow = SIGN_IN_AGENTS[agent];
|
|
68
|
+
if (!flow) throw new Error(`there is no sign-in here for ${agent}`);
|
|
69
|
+
return flow;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// A command run to its end without holding the daemon up: its output, exit code, or the error it could not start with.
|
|
73
|
+
const runToEnd = (command, args, input) =>
|
|
74
|
+
new Promise((resolve) => {
|
|
75
|
+
let stdout = "";
|
|
76
|
+
const child = run(command, args, {
|
|
77
|
+
env,
|
|
78
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
79
|
+
});
|
|
80
|
+
child.stdout.on("data", (chunk) => (stdout += chunk));
|
|
81
|
+
child.stdin.on("error", () => {});
|
|
82
|
+
child.on("error", (error) => resolve({ error, stdout, status: null }));
|
|
83
|
+
child.on("close", (status) => resolve({ stdout, status }));
|
|
84
|
+
child.stdin.end(input ?? "");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/** Which agents are signed in, by each agent's own status command. */
|
|
88
|
+
const status = async () => ({
|
|
89
|
+
ok: true,
|
|
90
|
+
agents: await Promise.all(
|
|
91
|
+
Object.entries(SIGN_IN_AGENTS).map(async ([agent, flow]) => {
|
|
92
|
+
const result = await runToEnd(flow.command, flow.status);
|
|
93
|
+
return {
|
|
94
|
+
agent,
|
|
95
|
+
installed: !result.error,
|
|
96
|
+
signedIn: !result.error && flow.signedIn(result),
|
|
97
|
+
};
|
|
98
|
+
})
|
|
99
|
+
),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/** Start an agent's own subscription sign-in; its words are read with read(). */
|
|
103
|
+
const start = (agent) => {
|
|
104
|
+
const flow = flowOf(agent);
|
|
105
|
+
for (const [id, session] of sessions)
|
|
106
|
+
if (session.agent === agent && session.state === "running") stop(id);
|
|
107
|
+
// The oldest sign-in makes room, stopped first so no sign-in runs on unseen.
|
|
108
|
+
if (sessions.size >= SESSIONS) {
|
|
109
|
+
const oldest = sessions.keys().next().value;
|
|
110
|
+
stop(oldest);
|
|
111
|
+
sessions.delete(oldest);
|
|
112
|
+
}
|
|
113
|
+
const id = randomBytes(9).toString("base64url");
|
|
114
|
+
const [command, args] = hasScript
|
|
115
|
+
? [
|
|
116
|
+
"script",
|
|
117
|
+
[
|
|
118
|
+
"-qfec",
|
|
119
|
+
[flow.command, ...flow.subscription].join(" "),
|
|
120
|
+
"/dev/null",
|
|
121
|
+
],
|
|
122
|
+
]
|
|
123
|
+
: [flow.command, flow.subscription];
|
|
124
|
+
const child = run(command, args, {
|
|
125
|
+
env: { ...env, BROWSER: "/bin/true" },
|
|
126
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
127
|
+
});
|
|
128
|
+
const session = { agent, child, lines: [], state: "running", code: null };
|
|
129
|
+
const take = (chunk) => {
|
|
130
|
+
session.lines.push(...clean(chunk));
|
|
131
|
+
if (session.lines.length > MAX_LINES)
|
|
132
|
+
session.lines.splice(0, session.lines.length - MAX_LINES);
|
|
133
|
+
};
|
|
134
|
+
child.stdout.on("data", take);
|
|
135
|
+
child.stderr.on("data", take);
|
|
136
|
+
child.stdin.on("error", () => {});
|
|
137
|
+
child.on("error", (error) => {
|
|
138
|
+
session.state = "failed";
|
|
139
|
+
session.lines.push(`${flow.command} could not start: ${error.message}`);
|
|
140
|
+
});
|
|
141
|
+
child.on("close", (code) => {
|
|
142
|
+
if (session.state === "running")
|
|
143
|
+
session.state = code === 0 ? "done" : "failed";
|
|
144
|
+
session.code = code;
|
|
145
|
+
log(`${agent} sign-in ended (${session.state})`);
|
|
146
|
+
});
|
|
147
|
+
sessions.set(id, session);
|
|
148
|
+
log(`${agent} sign-in started`);
|
|
149
|
+
return { ok: true, id };
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const sessionOf = (id) => {
|
|
153
|
+
const session = sessions.get(String(id));
|
|
154
|
+
if (!session) throw new Error("that sign-in is over; start it again");
|
|
155
|
+
return session;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const read = (id) => {
|
|
159
|
+
const session = sessionOf(id);
|
|
160
|
+
return {
|
|
161
|
+
ok: true,
|
|
162
|
+
agent: session.agent,
|
|
163
|
+
state: session.state,
|
|
164
|
+
lines: session.lines,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/** One line for the sign-in that asked for it (a code pasted from the provider's page). */
|
|
169
|
+
const send = (id, text) => {
|
|
170
|
+
const session = sessionOf(id);
|
|
171
|
+
if (session.state !== "running")
|
|
172
|
+
return { ok: false, error: "that sign-in is over" };
|
|
173
|
+
session.child.stdin.write(
|
|
174
|
+
`${String(text)
|
|
175
|
+
.replace(/[\r\n]/g, "")
|
|
176
|
+
.slice(0, 2000)}\n`
|
|
177
|
+
);
|
|
178
|
+
return { ok: true };
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const stop = (id) => {
|
|
182
|
+
const session = sessions.get(String(id));
|
|
183
|
+
if (!session) return { ok: true };
|
|
184
|
+
if (session.state === "running") {
|
|
185
|
+
session.state = "stopped";
|
|
186
|
+
session.child.kill("SIGTERM");
|
|
187
|
+
}
|
|
188
|
+
return { ok: true };
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/** An API key instead of a subscription: given to the agent's own login, or its own settings file. */
|
|
192
|
+
const useKey = async (agent, key) => {
|
|
193
|
+
flowOf(agent);
|
|
194
|
+
const value = String(key || "").trim();
|
|
195
|
+
if (!/^[\x21-\x7e]{20,300}$/.test(value))
|
|
196
|
+
return { ok: false, error: "That does not look like an API key." };
|
|
197
|
+
if (agent === "codex") {
|
|
198
|
+
const result = await runToEnd(
|
|
199
|
+
"codex",
|
|
200
|
+
["login", "--with-api-key"],
|
|
201
|
+
value
|
|
202
|
+
);
|
|
203
|
+
return result.status === 0
|
|
204
|
+
? { ok: true }
|
|
205
|
+
: { ok: false, error: "Codex did not take that key." };
|
|
206
|
+
}
|
|
207
|
+
// Claude Code reads the env block of its user settings for every run (code.claude.com settings).
|
|
208
|
+
const file = path.join(home, ".claude", "settings.json");
|
|
209
|
+
let settings = {};
|
|
210
|
+
try {
|
|
211
|
+
settings = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
212
|
+
} catch {}
|
|
213
|
+
settings.env = { ...(settings.env || {}), ANTHROPIC_API_KEY: value };
|
|
214
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
215
|
+
fs.writeFileSync(file, JSON.stringify(settings, null, 2) + "\n", {
|
|
216
|
+
mode: 0o600,
|
|
217
|
+
});
|
|
218
|
+
return { ok: true };
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const close = () => {
|
|
222
|
+
for (const id of sessions.keys()) stop(id);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
return { status, start, read, send, stop, useKey, close };
|
|
226
|
+
}
|