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.
Files changed (125) hide show
  1. package/README.md +239 -14
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +497 -196
  5. package/lib/actorRoster.mjs +28 -5
  6. package/lib/adapters.mjs +165 -222
  7. package/lib/agentRuntimeConfig.mjs +36 -0
  8. package/lib/agentRuntimes.mjs +570 -0
  9. package/lib/agentSignIn.mjs +226 -0
  10. package/lib/atlas.mjs +7 -2
  11. package/lib/audit.mjs +643 -0
  12. package/lib/backupSetup.mjs +141 -0
  13. package/lib/boardAccess.mjs +8 -1
  14. package/lib/boardBackup.mjs +283 -0
  15. package/lib/boardCommands.mjs +5 -10
  16. package/lib/boardFileCommands.mjs +2 -1
  17. package/lib/boardMirror.mjs +523 -0
  18. package/lib/boardProtocol.json +263 -6
  19. package/lib/boardTools.mjs +2 -6
  20. package/lib/boardWaits.mjs +102 -0
  21. package/lib/book.mjs +659 -0
  22. package/lib/bridge.mjs +26 -4
  23. package/lib/browserWake.mjs +60 -0
  24. package/lib/cards.mjs +159 -16
  25. package/lib/cloudBoot.mjs +124 -0
  26. package/lib/commands.mjs +25 -5
  27. package/lib/connectionTools.d.ts +13 -0
  28. package/lib/connectionTools.js +45 -0
  29. package/lib/connectorAuth.mjs +309 -0
  30. package/lib/connectorCatalog.json +41 -0
  31. package/lib/connectorCommands.mjs +121 -0
  32. package/lib/connectorGoogle.mjs +513 -0
  33. package/lib/connectors.mjs +805 -0
  34. package/lib/context.mjs +18 -4
  35. package/lib/contractGate.mjs +377 -0
  36. package/lib/coordinator.mjs +152 -39
  37. package/lib/coreModels.mjs +78 -0
  38. package/lib/daemon.mjs +973 -54
  39. package/lib/desk.mjs +239 -0
  40. package/lib/desktop.mjs +113 -8
  41. package/lib/digest.mjs +32 -0
  42. package/lib/directLink.mjs +283 -0
  43. package/lib/environments.mjs +825 -0
  44. package/lib/folders.mjs +4 -4
  45. package/lib/gitHost.mjs +174 -0
  46. package/lib/goalCommands.mjs +58 -14
  47. package/lib/hookDialects.mjs +298 -0
  48. package/lib/inference.mjs +263 -152
  49. package/lib/landed.mjs +887 -0
  50. package/lib/lessons.mjs +6 -0
  51. package/lib/lineup.mjs +324 -0
  52. package/lib/live.mjs +284 -13
  53. package/lib/localmodels.mjs +10 -0
  54. package/lib/machineIdentity.mjs +3 -0
  55. package/lib/machineRoutes.mjs +40 -2
  56. package/lib/machineRuns.mjs +30 -3
  57. package/lib/machineSeal.mjs +69 -10
  58. package/lib/mcp-stdio.mjs +189 -120
  59. package/lib/mcpRelay.mjs +119 -0
  60. package/lib/members.json +26 -0
  61. package/lib/members.mjs +33 -0
  62. package/lib/modelMemory.mjs +100 -0
  63. package/lib/models.mjs +48 -15
  64. package/lib/museSession.mjs +122 -0
  65. package/lib/nativeHost.mjs +203 -0
  66. package/lib/neovim.mjs +126 -0
  67. package/lib/network.mjs +7 -2
  68. package/lib/nudge.mjs +57 -18
  69. package/lib/onboard.mjs +430 -1
  70. package/lib/oneclawLocal.mjs +150 -0
  71. package/lib/ownMachines.mjs +828 -39
  72. package/lib/pairing.mjs +182 -0
  73. package/lib/paths.mjs +8 -0
  74. package/lib/personModel.mjs +89 -0
  75. package/lib/phones.mjs +119 -3
  76. package/lib/placeCommands.mjs +27 -0
  77. package/lib/places.mjs +337 -9
  78. package/lib/plans.mjs +151 -27
  79. package/lib/profile.mjs +152 -0
  80. package/lib/projects.mjs +624 -137
  81. package/lib/readiness.mjs +400 -0
  82. package/lib/record.mjs +115 -0
  83. package/lib/repoLinks.mjs +354 -0
  84. package/lib/roomChannels.mjs +641 -0
  85. package/lib/runBrief.mjs +32 -2
  86. package/lib/runRequests.mjs +157 -0
  87. package/lib/runWorker.mjs +37 -9
  88. package/lib/runner.mjs +74 -11
  89. package/lib/secretPatterns.json +55 -0
  90. package/lib/secrets.mjs +10 -27
  91. package/lib/seen.mjs +102 -0
  92. package/lib/service.mjs +11 -6
  93. package/lib/sessionControl.mjs +386 -96
  94. package/lib/sessionIndex.mjs +5 -3
  95. package/lib/specialties.json +74 -0
  96. package/lib/specialties.mjs +477 -0
  97. package/lib/specialtyKeys.d.ts +3 -0
  98. package/lib/specialtyKeys.js +58 -0
  99. package/lib/specialtyNotice.mjs +147 -0
  100. package/lib/specialtySnapshot.mjs +138 -0
  101. package/lib/store.mjs +829 -29
  102. package/lib/subagents.mjs +8 -4
  103. package/lib/swarm.mjs +483 -37
  104. package/lib/swarmMemory.mjs +947 -0
  105. package/lib/t3.mjs +56 -17
  106. package/lib/taskCommands.mjs +91 -13
  107. package/lib/taskRuns.mjs +68 -11
  108. package/lib/team.json +253 -144
  109. package/lib/team.mjs +538 -147
  110. package/lib/threadLine.mjs +116 -0
  111. package/lib/threadRuns.mjs +78 -12
  112. package/lib/threadView.mjs +66 -16
  113. package/lib/tokenizer.mjs +405 -0
  114. package/lib/ui.mjs +16 -2
  115. package/lib/usageTotals.mjs +148 -0
  116. package/lib/vault.mjs +1144 -0
  117. package/lib/vaultCloud.mjs +117 -0
  118. package/lib/vaultCommands.mjs +201 -0
  119. package/lib/vaultTools.d.ts +12 -0
  120. package/lib/vaultTools.js +42 -0
  121. package/lib/windowAsks.mjs +42 -0
  122. package/lib/workFocus.mjs +59 -0
  123. package/lib/workLinks.mjs +90 -0
  124. package/lib/worktrees.mjs +51 -13
  125. package/package.json +10 -5
@@ -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
+ }
package/lib/atlas.mjs CHANGED
@@ -503,6 +503,11 @@ const git = (cwd, args, input) =>
503
503
  maxBuffer: 256 * 2 ** 20,
504
504
  });
505
505
 
506
+ // A part of a larger string is kept by V8 as a slice that holds the whole string alive. The rows below outlive git's
507
+ // output (a commit's file list is kept while history is read), so each path and blob is its own copy, or every list
508
+ // kept holds that commit's entire `git ls-tree` output.
509
+ const own = (text) => structuredClone(text);
510
+
506
511
  /** The repository's files at a commit (or the working tree when commit is null): [{ path, blob, size }]. */
507
512
  export function treeFiles(root, commit = null) {
508
513
  if (commit) {
@@ -515,7 +520,7 @@ export function treeFiles(root, commit = null) {
515
520
  const [meta, rel] = line.split("\t");
516
521
  const [, type, blob, size] = meta.split(/\s+/);
517
522
  return type === "blob"
518
- ? { path: rel, blob, size: Number(size) || 0 }
523
+ ? { path: own(rel), blob: own(blob), size: Number(size) || 0 }
519
524
  : null;
520
525
  })
521
526
  .filter((row) => row && indexable(row.path, row.size));
@@ -529,7 +534,7 @@ export function treeFiles(root, commit = null) {
529
534
  const tab = entry.indexOf("\t");
530
535
  if (tab < 0) continue;
531
536
  const [, blob, stage] = entry.slice(0, tab).split(" ");
532
- if (stage === "0") blobs.set(entry.slice(tab + 1), blob);
537
+ if (stage === "0") blobs.set(own(entry.slice(tab + 1)), own(blob));
533
538
  }
534
539
  const changed = git(root, ["diff", "--name-only", "-z"])
535
540
  .stdout.split("\0")