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.
Files changed (167) hide show
  1. package/README.md +23 -19
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +484 -90
  5. package/lib/activity.mjs +10 -10
  6. package/lib/adapters.mjs +173 -222
  7. package/lib/agentBinaries.mjs +71 -0
  8. package/lib/agentRuntimeConfig.mjs +1 -1
  9. package/lib/agentRuntimes.mjs +34 -18
  10. package/lib/agentSignIn.mjs +456 -0
  11. package/lib/answers.mjs +5 -5
  12. package/lib/archetypes.d.ts +64 -0
  13. package/lib/archetypes.js +989 -0
  14. package/lib/asks.mjs +4 -4
  15. package/lib/audit.mjs +666 -0
  16. package/lib/backupSetup.mjs +143 -0
  17. package/lib/boardAccess.mjs +24 -11
  18. package/lib/boardBackup.mjs +283 -0
  19. package/lib/boardFileCommands.mjs +6 -6
  20. package/lib/boardFiles.mjs +13 -12
  21. package/lib/boardMirror.mjs +124 -25
  22. package/lib/boardProtocol.json +88 -2
  23. package/lib/boardWaits.mjs +101 -0
  24. package/lib/book.mjs +659 -0
  25. package/lib/bridge.mjs +6 -6
  26. package/lib/cards.mjs +138 -28
  27. package/lib/cloudAgents.mjs +216 -0
  28. package/lib/cloudAi.mjs +1312 -0
  29. package/lib/cloudAssistants.mjs +242 -0
  30. package/lib/cloudBoot.mjs +119 -0
  31. package/lib/cloudSave.mjs +197 -0
  32. package/lib/cloudSsh.mjs +178 -0
  33. package/lib/commands.mjs +7 -2
  34. package/lib/context.mjs +19 -5
  35. package/lib/contractGate.mjs +399 -0
  36. package/lib/control-client.mjs +9 -1
  37. package/lib/controlSocket.mjs +86 -0
  38. package/lib/coordinator.mjs +252 -144
  39. package/lib/daemon.mjs +1351 -2767
  40. package/lib/desk.mjs +240 -0
  41. package/lib/desktop.mjs +178 -74
  42. package/lib/directLink.mjs +16 -5
  43. package/lib/environment.mjs +2 -1
  44. package/lib/environments.mjs +247 -9
  45. package/lib/firewall.mjs +9 -9
  46. package/lib/folders.mjs +20 -16
  47. package/lib/frames.mjs +2 -3
  48. package/lib/gitHost.mjs +174 -0
  49. package/lib/goalCommands.mjs +25 -7
  50. package/lib/goals.mjs +7 -7
  51. package/lib/guestRequests.mjs +94 -0
  52. package/lib/handoffs.mjs +8 -7
  53. package/lib/handover.mjs +4 -4
  54. package/lib/harnessModel.mjs +6 -6
  55. package/lib/harnessOffers.mjs +266 -0
  56. package/lib/hookDialects.mjs +298 -0
  57. package/lib/inference.mjs +26 -8
  58. package/lib/jobAnswers.mjs +190 -0
  59. package/lib/landed.mjs +887 -0
  60. package/lib/lane.mjs +42 -11
  61. package/lib/lessons.mjs +16 -16
  62. package/lib/library.mjs +3 -3
  63. package/lib/lineup.mjs +3 -0
  64. package/lib/linkRelay.mjs +574 -0
  65. package/lib/live.mjs +284 -13
  66. package/lib/localAgentAsk.mjs +74 -0
  67. package/lib/localStack.mjs +536 -0
  68. package/lib/localmodels.mjs +6 -4
  69. package/lib/loopBackstop.mjs +4 -4
  70. package/lib/machineIdentity.mjs +9 -1
  71. package/lib/machineRoutes.mjs +181 -2
  72. package/lib/machineRuns.mjs +76 -1
  73. package/lib/machineSeal.mjs +39 -12
  74. package/lib/mcp-stdio.mjs +163 -27
  75. package/lib/mcpRelay.mjs +1 -1
  76. package/lib/members.json +29 -2
  77. package/lib/members.mjs +1 -1
  78. package/lib/models.mjs +85 -31
  79. package/lib/museSession.mjs +21 -13
  80. package/lib/nativeHost.mjs +36 -8
  81. package/lib/neovim.mjs +126 -0
  82. package/lib/network.mjs +50 -5
  83. package/lib/notify.mjs +7 -5
  84. package/lib/nudge.mjs +50 -19
  85. package/lib/ocr.mjs +9 -9
  86. package/lib/onboard.mjs +26 -20
  87. package/lib/oneLine.mjs +7 -7
  88. package/lib/ownMachines.mjs +1223 -140
  89. package/lib/pairing.mjs +60 -16
  90. package/lib/paths.mjs +19 -1
  91. package/lib/peerProcess.mjs +124 -0
  92. package/lib/personModel.mjs +89 -0
  93. package/lib/personNotices.mjs +151 -0
  94. package/lib/phones.mjs +538 -31
  95. package/lib/placeCommands.mjs +4 -4
  96. package/lib/places.mjs +400 -12
  97. package/lib/profile.mjs +67 -14
  98. package/lib/projectGit.mjs +158 -14
  99. package/lib/projectPieces.mjs +902 -0
  100. package/lib/projectSettings.mjs +7 -4
  101. package/lib/projects.mjs +384 -62
  102. package/lib/provenance.mjs +5 -1
  103. package/lib/proxyLinks.mjs +267 -0
  104. package/lib/reactions.mjs +7 -5
  105. package/lib/readiness.mjs +145 -23
  106. package/lib/record.mjs +128 -0
  107. package/lib/redact.mjs +4 -4
  108. package/lib/relayLimits.mjs +62 -0
  109. package/lib/release.mjs +170 -0
  110. package/lib/releaseKeys.json +6 -0
  111. package/lib/repoLinks.mjs +4 -4
  112. package/lib/roomChannels.mjs +24 -0
  113. package/lib/roomPage.mjs +1 -1
  114. package/lib/runAuthority.mjs +101 -0
  115. package/lib/runBrief.mjs +19 -8
  116. package/lib/runWorker.mjs +31 -7
  117. package/lib/runner.mjs +223 -29
  118. package/lib/runtime-install.mjs +143 -9
  119. package/lib/schedules.mjs +2 -2
  120. package/lib/screens.mjs +1 -1
  121. package/lib/sealed.mjs +11 -2
  122. package/lib/sealedThreads.mjs +671 -0
  123. package/lib/secretPatterns.json +1 -1
  124. package/lib/secrets.mjs +4 -4
  125. package/lib/seen.mjs +6 -6
  126. package/lib/serverWords.mjs +175 -0
  127. package/lib/service.mjs +22 -12
  128. package/lib/sessionControl.mjs +378 -90
  129. package/lib/specialties.json +74 -0
  130. package/lib/specialties.mjs +477 -0
  131. package/lib/specialtyKeys.d.ts +3 -0
  132. package/lib/specialtyKeys.js +57 -0
  133. package/lib/specialtyNotice.mjs +147 -0
  134. package/lib/specialtySnapshot.mjs +138 -0
  135. package/lib/speech.mjs +5 -5
  136. package/lib/store.mjs +420 -36
  137. package/lib/stuck.mjs +1 -1
  138. package/lib/swarm.mjs +304 -37
  139. package/lib/swarmDevices.mjs +319 -0
  140. package/lib/swarmMemory.mjs +27 -25
  141. package/lib/t3.mjs +24 -15
  142. package/lib/taskCommands.mjs +80 -20
  143. package/lib/taskRooms.mjs +125 -0
  144. package/lib/taskRuns.mjs +45 -3
  145. package/lib/team.json +255 -148
  146. package/lib/team.mjs +554 -190
  147. package/lib/threadActions.mjs +315 -0
  148. package/lib/threadAuthority.mjs +101 -0
  149. package/lib/threadBriefs.mjs +178 -0
  150. package/lib/threadLine.mjs +116 -0
  151. package/lib/threadRuns.mjs +209 -50
  152. package/lib/threadView.mjs +20 -7
  153. package/lib/usageTotals.mjs +2 -3
  154. package/lib/vault.mjs +101 -10
  155. package/lib/vaultCloud.mjs +2 -2
  156. package/lib/vaultCommands.mjs +15 -6
  157. package/lib/vaultTools.js +2 -2
  158. package/lib/verdicts.mjs +328 -0
  159. package/lib/wakes.mjs +1 -1
  160. package/lib/watches.mjs +2 -2
  161. package/lib/windowAsks.mjs +13 -5
  162. package/lib/worktrees.mjs +157 -25
  163. package/npm-shrinkwrap.json +1093 -0
  164. package/package.json +12 -11
  165. package/release.json +220 -0
  166. package/lib/modelTiers.json +0 -1183
  167. package/lib/modelTiers.mjs +0 -133
package/lib/runWorker.mjs CHANGED
@@ -8,7 +8,7 @@ import { sessionFile } from "./live.mjs";
8
8
  import { oneLine } from "./oneLine.mjs";
9
9
 
10
10
  // `briefs` (runBrief.mjs) says what each run is told and which session it continues.
11
- /** Another agent's words on a goal's authority, without the person's tap or go (person-wake): restricted (docs/member-runs.md). */
11
+ /** Another agent's words on a goal's authority, without the person's tap or go (person-wake): restricted. */
12
12
  export const restrictedRun = (store, task) =>
13
13
  task.trust !== "user" &&
14
14
  task.run_authorized_by === "goal" &&
@@ -33,9 +33,11 @@ export function createRunWorker({
33
33
  taskRuns,
34
34
  threadRuns,
35
35
  vaultEnv = () => null,
36
+ // A run's receipt was just kept (audit.mjs audits the run's claims with it).
37
+ onReceipt = () => {},
36
38
  }) {
37
39
  const { RUNNERS, standingRules } = authority;
38
- const { commitWake, settleWake, ranOutsideT3, t3Turn, taskInT3 } =
40
+ const { startTurn, commitRun, settleWake, ranOutsideT3, t3Turn, taskInT3 } =
39
41
  threadRuns.worker;
40
42
  const activeRuns = new Map();
41
43
  const lastStepNotice = new Map();
@@ -54,7 +56,7 @@ export function createRunWorker({
54
56
  }
55
57
  // Where a run works, one at a time: its folder, or for a turn T3 Code carries out, its thread (T3 keeps the checkout).
56
58
  // A review changes nothing (runner.mjs runs it read-only), so it goes beside whoever writes there: one review per
57
- // agent per thread, as its session is one (October 19: reviews waited 168 min behind other agents' turns in 3 days).
59
+ // agent per thread, as its session is one (reviews once waited 168 min behind other agents' turns in 3 days).
58
60
  const slotOf = (task) =>
59
61
  store.meta(`review:${task.id}`) === "1"
60
62
  ? `review:${task.target_agent}:${task.parent_id}`
@@ -121,6 +123,13 @@ export function createRunWorker({
121
123
  noteWaiting(task, activeRuns.get(slot));
122
124
  continue;
123
125
  }
126
+ // A task T3 carries out still waits for a run working in its folder, such as the turn of the agent that handed it
127
+ // on: two runs never work one checkout at once.
128
+ const folder =
129
+ task.kind === "task" && slot.startsWith("t3:") && task.run_workspace
130
+ ? path.resolve(task.run_workspace)
131
+ : null;
132
+ if (folder && activeRuns.has(folder)) continue;
124
133
  // An agent resumes one session per thread: its review waits while its own turn there runs.
125
134
  if (slot.startsWith("review:") && runsInThread(agent, task.parent_id))
126
135
  continue;
@@ -150,12 +159,15 @@ export function createRunWorker({
150
159
  } = await briefs.prepare(task, agent);
151
160
  const startedAt = new Date().toISOString();
152
161
  const stoppedFor = Boolean(again);
153
- // The session it resumes is the run's from its first moment, so Open never resumes it beside the run before the agent
154
- // says which session it is in (October 16: OpenCode said so only minutes into its turn).
162
+ // The session it resumes is the run's from its first moment, so Open never resumes it beside the run before the
163
+ // agent says which session it is in (OpenCode once said so only minutes into its turn).
155
164
  if (resumeSession && !task.session_id)
156
165
  store.setRunSession(task.id, resumeSession);
157
166
  const readOnly = store.meta(`review:${task.id}`) === "1";
158
167
  const restricted = restrictedRun(store, task);
168
+ // Work another person asked for runs with only this person's own agent settings: the repository's own (its
169
+ // .claude hooks, .pi, opencode.json) can be that person's, and would run here (security audit P4, October 25).
170
+ const ownSettingsOnly = store.meta(`other-person-run:${task.id}`) === "1";
159
171
  const chosen = await modelForRun(task, agent);
160
172
  store.setRunModel(task.id, chosen);
161
173
  const { model, effort } = chosen;
@@ -164,6 +176,7 @@ export function createRunWorker({
164
176
  // run's environment, and what it says is scrubbed of them.
165
177
  const secrets = restricted ? null : vaultEnv(task, agent);
166
178
  const granted = secrets && Object.keys(secrets.env).length ? secrets : null;
179
+ startTurn(task);
167
180
  taskRuns.startTask(
168
181
  {
169
182
  runId: task.id,
@@ -173,10 +186,13 @@ export function createRunWorker({
173
186
  cwd: task.run_workspace,
174
187
  ...(model ? { model } : {}),
175
188
  ...(effort ? { effort } : {}),
189
+ // A model of Harness's AI says its window and longest answer, for an agent told them per run (runner.mjs).
190
+ ...(model && chosen.limits ? { limits: chosen.limits } : {}),
176
191
  ...(stoppedFor ? { again: true } : {}),
177
192
  ...(resumeSession && !t3 ? { resumeSession } : {}),
178
193
  ...(readOnly ? { readOnly } : {}),
179
194
  ...(restricted ? { restricted } : {}),
195
+ ...(ownSettingsOnly ? { ownSettingsOnly } : {}),
180
196
  ...(t3 ? { t3 } : {}),
181
197
  ...(granted ? { env: granted.env, scrub: granted.values } : {}),
182
198
  },
@@ -227,11 +243,16 @@ export function createRunWorker({
227
243
  // A stopped run's task is already closed, so nothing else frees the agent's next run.
228
244
  setImmediate(runBoard);
229
245
  if (extra?.usage) store.setRunUsage(task.id, extra.usage);
246
+ // Its changes are committed before it reports, so the audit of its report sees what was not.
247
+ commitRun(task);
230
248
  // A run that failed without reaching its agent's own report ended early: the runner says why.
231
249
  const reported = store.reportTask(task.id, agent, {
232
250
  status: kind,
233
251
  result: text || "",
234
- failure: extra?.failure ?? "exit",
252
+ // Stopped for the person's steer (threadRuns.mjs): the person ended it, not the agent or its provider.
253
+ failure: store.meta(`steered:${task.id}`)
254
+ ? "person"
255
+ : (extra?.failure ?? "exit"),
235
256
  });
236
257
  if (reported.ok) notifyBoard(reported.task);
237
258
  else
@@ -240,7 +261,6 @@ export function createRunWorker({
240
261
  );
241
262
  // A coding agent's finished turn settles once its receipt is read, so the coordinator's round that follows sees
242
263
  // what the run's own session shows (frames.mjs); the receipt is posted after the agent's own words.
243
- if (wake) commitWake(task);
244
264
  if (kind === "done" && RUNNERS.has(agent))
245
265
  void receiptFor(task.id, agent, { post: !wake }).then((line) => {
246
266
  if (wake) {
@@ -308,6 +328,9 @@ export function createRunWorker({
308
328
  test:
309
329
  result.tests.filter((test) => test.afterChange).at(-1)?.command ??
310
330
  null,
331
+ // Whether that last test passed, so a run that changed nothing still shows its tests passing (audit.mjs).
332
+ testOk:
333
+ result.tests.filter((test) => test.afterChange).at(-1)?.ok ?? null,
311
334
  repeatedFailures: result.repeatedFailures,
312
335
  at: new Date().toISOString(),
313
336
  })
@@ -319,6 +342,7 @@ export function createRunWorker({
319
342
  text: line,
320
343
  source: "receipts",
321
344
  });
345
+ onReceipt(taskId);
322
346
  localEvent("receipt", `${nameOf(agent)}'s run: ${result.verdict}`);
323
347
  void contextEngine.refresh();
324
348
  const forThread =
package/lib/runner.mjs CHANGED
@@ -1,14 +1,37 @@
1
1
  import fs from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
+ import os from "node:os";
3
4
  import path from "node:path";
4
5
  import { spawn } from "node:child_process";
6
+ import { randomBytes } from "node:crypto";
7
+ import { agentBinary } from "./agentBinaries.mjs";
5
8
  import { agentEnvironment } from "./agentnode.mjs";
6
9
  import { runtimeOf } from "./agentRuntimeConfig.mjs";
7
10
  import { runProtocolTask } from "./agentRuntimes.mjs";
8
11
  import { scrubValues } from "./vault.mjs";
12
+ import { paths } from "./paths.mjs";
9
13
 
10
14
  const running = new Set();
11
15
  const children = new Map();
16
+ // Each run this daemon starts carries its own capability in its environment (HARNESS_RUN_TOKEN). Its Harness MCP server
17
+ // and the CLI send it with every call on the daemon's socket, which takes such a call as that run's agent under that
18
+ // run's limits, whatever agent it names (runAuthority.mjs checkCaller). It ends with the run.
19
+ const capabilities = new Map();
20
+ const issueCapability = (task) => {
21
+ const token = randomBytes(32).toString("base64url");
22
+ capabilities.set(token, {
23
+ id: task.runId,
24
+ agent: task.agent,
25
+ restricted: task.restricted === true,
26
+ review: task.readOnly === true,
27
+ });
28
+ return token;
29
+ };
30
+
31
+ /** The run a capability belongs to while that run goes on: its id, agent, and whether it is restricted or a review. */
32
+ export function runCapability(token) {
33
+ return capabilities.get(String(token)) ?? null;
34
+ }
12
35
 
13
36
  /** Stops a run in progress (a goal's Stop); its close reports it failed. */
14
37
  export function stopAgentTask(runId) {
@@ -49,6 +72,13 @@ export function runningPids() {
49
72
  return [...children.values()].map((child) => child.pid).filter(Boolean);
50
73
  }
51
74
 
75
+ /** Each run in progress with its process, so a session one of them started is known as that run's. */
76
+ export function runningProcesses() {
77
+ return [...children]
78
+ .filter(([run, child]) => child.pid && !run.startsWith("helper:"))
79
+ .map(([run, child]) => ({ run, pid: child.pid }));
80
+ }
81
+
52
82
  export function resolveWorkingDirectory(requested) {
53
83
  if (!requested || !path.isAbsolute(requested))
54
84
  throw new Error("Delegated tasks require an absolute working directory.");
@@ -65,21 +95,95 @@ export function resolveWorkingDirectory(requested) {
65
95
  return requested;
66
96
  }
67
97
 
98
+ // Where the person keeps what a run held in must never read: other agents' and tools' credentials and keys, under the
99
+ // home folder. Harness's own home (its keys, the board, the vault) is added where it is (paths.home).
100
+ const SECRET_PLACES = [
101
+ ".harness",
102
+ ".claude",
103
+ ".claude.json",
104
+ ".codex",
105
+ ".pi",
106
+ ".config/opencode",
107
+ ".local/share/opencode",
108
+ ".t3",
109
+ ".ssh",
110
+ ".gnupg",
111
+ ".aws",
112
+ ".azure",
113
+ ".kube",
114
+ ".docker",
115
+ ".config/gh",
116
+ ".config/hub",
117
+ ".config/gcloud",
118
+ ".config/solana",
119
+ ".npmrc",
120
+ ".yarnrc.yml",
121
+ ".pypirc",
122
+ ".netrc",
123
+ ".git-credentials",
124
+ ".cargo/credentials.toml",
125
+ ".password-store",
126
+ "Library/Keychains",
127
+ ];
128
+ /** Every place a restricted or review run may not read, as absolute paths. */
129
+ export const secretPlaces = (home = os.homedir()) => [
130
+ ...new Set([
131
+ ...SECRET_PLACES.map((place) => path.join(home, place)),
132
+ paths.home,
133
+ ]),
134
+ ];
135
+ // Claude Code's own file tools are held by deny rules ("//" starts an absolute path). Harness's home holds the
136
+ // worktrees runs work in, so only its own files are named there, never a pattern that would cover a worktree.
137
+ const HARNESS_FILES = [
138
+ "*.json",
139
+ "*.db",
140
+ "*.db-*",
141
+ "*.lock",
142
+ "*.log",
143
+ "*.sock",
144
+ "vault*",
145
+ "*key*",
146
+ "runs/**",
147
+ "files/**",
148
+ "runtime/**",
149
+ "models/**",
150
+ "local/**",
151
+ "checks/**",
152
+ "native-host/**",
153
+ "editor/**",
154
+ ];
155
+ const readDenials = (home) =>
156
+ secretPlaces(home).flatMap((place) =>
157
+ place === paths.home
158
+ ? HARNESS_FILES.map((file) => `Read(/${path.join(place, file)})`)
159
+ : [`Read(/${place})`, `Read(/${place}/**)`]
160
+ );
161
+ // The sandbox holds shell commands to the same places. The run's own folder stays readable even inside Harness's home,
162
+ // where its worktree is, and so do the shell snapshots each agent's shell tool sources before every command.
163
+ const sandboxReads = (cwd, home) => ({
164
+ denyRead: secretPlaces(home),
165
+ allowRead: [
166
+ ...(cwd ? [cwd] : []),
167
+ path.join(home, ".claude", "shell-snapshots"),
168
+ ],
169
+ });
170
+
68
171
  // A run another agent started without the person's tap (docs/member-runs.md): anything that would ask is refused, file
69
- // edits only in its worktree, shell commands only inside the operating system's sandbox with no network, and no hooks or
70
- // settings from the repository. A review gets no edits at all.
71
- export const RESTRICTED_CLAUDE_SETTINGS = {
172
+ // edits only in its worktree, shell commands only inside the operating system's sandbox with no network, nothing read
173
+ // where the person keeps credentials, and no hooks or settings from the repository. A review gets no edits at all.
174
+ export const restrictedClaudeSettings = (cwd, home = os.homedir()) => ({
72
175
  disableAllHooks: true,
73
- permissions: { deny: ["WebFetch", "WebSearch"] },
176
+ permissions: { deny: ["WebFetch", "WebSearch", ...readDenials(home)] },
74
177
  sandbox: {
75
178
  enabled: true,
76
179
  autoAllowBashIfSandboxed: true,
77
180
  allowUnsandboxedCommands: false,
78
181
  failIfUnavailable: true,
79
182
  excludedCommands: [],
183
+ filesystem: sandboxReads(cwd, home),
80
184
  network: { allowedDomains: [], strictAllowlist: true },
81
185
  },
82
- };
186
+ });
83
187
  // Only the Harness board MCP, as Claude Code: none of the person's other MCP servers or claude.ai connectors load.
84
188
  export const restrictedMcpConfig = () => ({
85
189
  mcpServers: {
@@ -102,7 +206,10 @@ const restrictedClaude = (task) => [
102
206
  "--setting-sources",
103
207
  "user",
104
208
  "--settings",
105
- JSON.stringify(RESTRICTED_CLAUDE_SETTINGS),
209
+ JSON.stringify({
210
+ ...restrictedClaudeSettings(task.cwd),
211
+ ...modelWindow(task),
212
+ }),
106
213
  "--strict-mcp-config",
107
214
  "--mcp-config",
108
215
  JSON.stringify(restrictedMcpConfig()),
@@ -131,32 +238,83 @@ const modelFlags = ({ agent, model, effort }) => [
131
238
  ...(model ? (MODEL_FLAGS[agent]?.model(model) ?? []) : []),
132
239
  ...(effort ? (MODEL_FLAGS[agent]?.effort(effort) ?? []) : []),
133
240
  ];
241
+ // Claude Code knows no window for a model of Harness's AI (cloudAi.mjs tells it its default's); a run on one says
242
+ // that model's window and longest answer in its own settings, which outrank the user settings for this run.
243
+ const modelWindow = ({ limits }) =>
244
+ limits
245
+ ? {
246
+ env: {
247
+ CLAUDE_CODE_MAX_CONTEXT_TOKENS: String(limits.contextTokens),
248
+ CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(limits.maxOutputTokens),
249
+ },
250
+ }
251
+ : {};
134
252
 
135
253
  // A review or research turn reads and reports. Plan mode kept Claude Code from editing but also refused the Harness
136
254
  // tools it reads the thread and posts with (October 20, live run: "plan mode blocks the room tools", the findings left
137
255
  // in ~/.claude/plans). Instead: anything not allowed is refused, edits and writes are refused, Harness's tools and
138
256
  // reading are allowed, and shell commands run only inside the operating system's sandbox, which the deny rule keeps
139
257
  // from writing in the working folder (probed live October 20: Harness's tools answer, node and git run, a write in the
140
- // folder is refused; denying edits everywhere also broke Claude Code's own scratch files under /tmp).
141
- export const READ_ONLY_CLAUDE_SETTINGS = {
142
- permissions: { deny: ["Edit(./**)"] },
258
+ // folder is refused; denying edits everywhere also broke Claude Code's own scratch files under /tmp). It reads nothing
259
+ // where the person keeps credentials, loads no settings or hooks from the repository it reviews, and has no web: what
260
+ // it reviews is in the folder and the thread, and a fetch is a way out for what it read.
261
+ export const readOnlyClaudeSettings = (cwd, home = os.homedir()) => ({
262
+ permissions: {
263
+ deny: ["Edit(./**)", "WebFetch", "WebSearch", ...readDenials(home)],
264
+ },
143
265
  sandbox: {
144
266
  enabled: true,
145
267
  autoAllowBashIfSandboxed: true,
146
268
  allowUnsandboxedCommands: false,
269
+ filesystem: sandboxReads(cwd, home),
270
+ network: { allowedDomains: [], strictAllowlist: true },
147
271
  },
148
- };
149
- const readOnlyClaude = () => [
272
+ });
273
+ const readOnlyClaude = (task) => [
150
274
  "--permission-mode",
151
275
  "dontAsk",
152
276
  "--allowedTools",
153
- "Read Grep Glob WebSearch WebFetch mcp__harness",
277
+ "Read Grep Glob mcp__harness",
154
278
  "--disallowedTools",
155
- "Edit Write NotebookEdit",
279
+ "Edit Write NotebookEdit WebFetch WebSearch",
280
+ "--setting-sources",
281
+ "user",
156
282
  "--settings",
157
- JSON.stringify(READ_ONLY_CLAUDE_SETTINGS),
283
+ JSON.stringify({
284
+ ...readOnlyClaudeSettings(task.cwd),
285
+ ...modelWindow(task),
286
+ }),
158
287
  ];
159
288
 
289
+ // Codex's review: its read-only permission profile, with the same places denied to every command it runs (the run's
290
+ // own folder stays readable when it lies inside one) and no web search. Probed with `codex sandbox` 0.164: a denied
291
+ // file is "Operation not permitted", the folder reads, writes and the daemon's socket are refused.
292
+ const codexReview = (task, home = os.homedir()) => {
293
+ const places = Object.fromEntries(
294
+ secretPlaces(home).map((place) => [place, "deny"])
295
+ );
296
+ places[path.join(home, ".codex", "shell_snapshots")] = "read";
297
+ if (task.cwd) places[task.cwd] = "read";
298
+ const table = Object.entries(places)
299
+ .map(
300
+ ([place, access]) => `${JSON.stringify(place)}=${JSON.stringify(access)}`
301
+ )
302
+ .join(",");
303
+ return [
304
+ "-c",
305
+ 'default_permissions="harness-review"',
306
+ "-c",
307
+ 'permissions.harness-review.extends=":read-only"',
308
+ "-c",
309
+ `permissions.harness-review.filesystem={${table}}`,
310
+ "-c",
311
+ 'web_search="disabled"',
312
+ ];
313
+ };
314
+
315
+ /** The coding agents whose runs Harness can hold to read-only: only they review or audit. */
316
+ export const READ_ONLY_AGENTS = new Set(["claude-code", "codex"]);
317
+
160
318
  export function agentInvocation(task) {
161
319
  if (task.agent === "claude-code") {
162
320
  return {
@@ -170,8 +328,18 @@ export function agentInvocation(task) {
170
328
  ...(task.restricted
171
329
  ? restrictedClaude(task)
172
330
  : task.readOnly
173
- ? readOnlyClaude()
174
- : ["--dangerously-skip-permissions"]),
331
+ ? readOnlyClaude(task)
332
+ : [
333
+ "--dangerously-skip-permissions",
334
+ ...(task.limits
335
+ ? ["--settings", JSON.stringify(modelWindow(task))]
336
+ : []),
337
+ ]),
338
+ // Another person's ask: the person's own settings only, never the project's or its local ones (their hooks).
339
+ // Restricted and review runs already keep to the person's own settings.
340
+ ...(task.ownSettingsOnly && !task.restricted && !task.readOnly
341
+ ? ["--setting-sources", "user"]
342
+ : []),
175
343
  "--name",
176
344
  `Harness: ${task.title}`,
177
345
  ...modelFlags(task),
@@ -192,13 +360,12 @@ export function agentInvocation(task) {
192
360
  ...(task.resumeSession ? ["resume", task.resumeSession] : []),
193
361
  "--json",
194
362
  ...modelFlags(task),
195
- // A review still talks to the thread: with approvals off, Codex refused every Harness tool as unapproved, so
196
- // it could not read the room or post what it found (October 14, the chop keeper review). Harness's own tools
197
- // are approved for it; the files stay read-only.
363
+ // A review still talks to the thread: with approvals off, Codex refused every Harness tool as unapproved, so it
364
+ // could not read the room or post what it found. Harness's own tools are approved for it; the files stay
365
+ // read-only.
198
366
  ...(task.readOnly
199
367
  ? [
200
- "-c",
201
- 'sandbox_mode="read-only"',
368
+ ...codexReview(task),
202
369
  "-c",
203
370
  'approval_policy="never"',
204
371
  "-c",
@@ -211,15 +378,21 @@ export function agentInvocation(task) {
211
378
  stdin: task.brief,
212
379
  };
213
380
  }
381
+ // Neither has a read-only mode Harness can hold it to (their runs below are unrestricted), so neither reviews.
382
+ if (task.readOnly && !READ_ONLY_AGENTS.has(task.agent))
383
+ throw new Error(
384
+ `${task.agent} has no read-only mode, so it does not review; Claude Code or Codex can`
385
+ );
214
386
  // Pi has no permission prompts. --approve trusts project-local configuration for
215
- // this non-interactive run; its complete built-in tool set remains enabled.
387
+ // this non-interactive run; its complete built-in tool set remains enabled. Another
388
+ // person's ask ignores project-local files instead (--no-approve).
216
389
  if (task.agent === "pi")
217
390
  return {
218
391
  command: "pi",
219
392
  args: [
220
393
  "--mode",
221
394
  "json",
222
- "--approve",
395
+ task.ownSettingsOnly ? "--no-approve" : "--approve",
223
396
  ...modelFlags(task),
224
397
  "-p",
225
398
  task.brief,
@@ -240,6 +413,10 @@ export function agentInvocation(task) {
240
413
  "--",
241
414
  task.brief,
242
415
  ],
416
+ // Another person's ask: OpenCode reads no opencode.json or .opencode folder from the project.
417
+ ...(task.ownSettingsOnly
418
+ ? { env: { OPENCODE_DISABLE_PROJECT_CONFIG: "1" } }
419
+ : {}),
243
420
  };
244
421
  }
245
422
  throw new Error(`Unsupported agent: ${task.agent}`);
@@ -468,18 +645,21 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
468
645
  let cwd;
469
646
  let invocation;
470
647
  let environment;
648
+ let capability = null;
471
649
  try {
472
650
  cwd = resolveWorkingDirectory(task.cwd);
473
651
  if (runtimeOf(task.agent)) {
474
652
  const controller = new AbortController();
475
653
  running.add(slot);
476
654
  children.set(task.runId, { kill: () => controller.abort() });
655
+ const capability = issueCapability(task);
477
656
  let released = false;
478
657
  const release = () => {
479
658
  if (released) return;
480
659
  released = true;
481
660
  running.delete(slot);
482
661
  children.delete(task.runId);
662
+ capabilities.delete(capability);
483
663
  };
484
664
  let settled = false;
485
665
  const report = (kind, text, extra) => {
@@ -491,7 +671,12 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
491
671
  emit(kind, text, extra);
492
672
  };
493
673
  void runProtocolTask(
494
- { ...task, cwd },
674
+ {
675
+ ...task,
676
+ cwd,
677
+ capability,
678
+ env: { ...(task.env ?? {}), HARNESS_RUN_TOKEN: capability },
679
+ },
495
680
  { ...hooks, emit: report, observe, signal: controller.signal }
496
681
  )
497
682
  .catch((error) => report("failed", error.message, { failure: "exit" }))
@@ -499,17 +684,26 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
499
684
  return;
500
685
  }
501
686
  invocation = agentInvocation(task);
687
+ capability = issueCapability(task);
502
688
  // A Node agent runs on a Node it accepts, whichever Node Harness itself runs on.
503
689
  // The person's environment grants for this run (vault.mjs), over the daemon's own environment.
504
690
  // HARNESS_RUN_ID tells the agent's own Harness tools which run they serve (mcp-stdio.mjs), where its MCP servers
505
- // inherit the agent's environment.
691
+ // inherit the agent's environment; HARNESS_RUN_TOKEN is the run's capability (above).
506
692
  environment = agentEnvironment(invocation.command, {
507
693
  ...process.env,
508
694
  ...(task.env ?? {}),
695
+ ...(invocation.env ?? {}),
509
696
  HARNESS_RUN_ID: task.runId,
697
+ HARNESS_RUN_TOKEN: capability,
510
698
  });
511
699
  if (environment.error) throw new Error(environment.error);
700
+ // The program confirmed for this agent, not the first one on PATH (agentBinaries.mjs).
701
+ const program = agentBinary(task.agent, invocation.command);
702
+ if (!program)
703
+ throw new Error(`${task.agent} is not installed on this computer.`);
704
+ invocation = { ...invocation, command: program };
512
705
  } catch (error) {
706
+ if (capability) capabilities.delete(capability);
513
707
  emit("failed", error.message, { failure: "start" });
514
708
  return;
515
709
  }
@@ -525,6 +719,7 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
525
719
  child.stdin.end(invocation.stdin);
526
720
  } catch (error) {
527
721
  running.delete(slot);
722
+ capabilities.delete(capability);
528
723
  emit("failed", `Could not start ${task.agent}: ${error.message}`, {
529
724
  failure: "start",
530
725
  });
@@ -614,15 +809,13 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
614
809
  child.on("close", (code) => {
615
810
  running.delete(slot);
616
811
  children.delete(task.runId);
812
+ capabilities.delete(capability);
617
813
  if (code === 0 && modelError)
618
814
  emit(
619
815
  "failed",
620
816
  clean(
621
817
  `${task.agent} stopped on an error from its model: ${modelError}`
622
- ).slice(
623
- 0,
624
- 4_000
625
- ),
818
+ ).slice(0, 4_000),
626
819
  { usage: usage.result(), failure: "exit" }
627
820
  );
628
821
  else if (code === 0)
@@ -644,6 +837,7 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
644
837
  child.on("error", (error) => {
645
838
  running.delete(slot);
646
839
  children.delete(task.runId);
840
+ capabilities.delete(capability);
647
841
  emit("failed", `Could not start ${task.agent}: ${error.message}`, {
648
842
  failure: "start",
649
843
  });