tryharness 0.7.70 → 0.7.72

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.
@@ -4,7 +4,12 @@ import os from "node:os";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import { PS } from "./nudge.mjs";
6
6
  import { paths } from "./paths.mjs";
7
- import { MACHINE_RUNNERS, MEMBERS, nameOf } from "./members.mjs";
7
+ import {
8
+ MACHINE_RUNNERS,
9
+ PROPOSERS,
10
+ nameOf,
11
+ speaksThroughHarness,
12
+ } from "./members.mjs";
8
13
  import { runCapability, runningPids } from "./runner.mjs";
9
14
  import {
10
15
  descendsFrom,
@@ -20,6 +25,10 @@ import {
20
25
  export const HOSTED_CALLER = Symbol("a board call Harness's server made");
21
26
  /** The run Harness started that made a socket call, set by checkCaller; no JSON a caller writes can set it. */
22
27
  export const RUN_CALLER = Symbol("the run that called");
28
+ // Work the person's agents hand on to each other starts without a Start (owner, October 31), so a run that posts work
29
+ // for an agent whose run posts work again could go on forever. Past this many hand-offs in a row with no word from the
30
+ // person, the next one waits for their Start. In place of a daily limit the person never set.
31
+ export const MAX_HANDOFFS = 10;
23
32
  /** How the run that made a call was held in, so what it asks for is held in too: "review", "restricted" or null. */
24
33
  export const callerLimit = (request) => {
25
34
  const run = request?.[RUN_CALLER];
@@ -65,14 +74,63 @@ const PERSON_READS = new Set([
65
74
  "board.swarm.list",
66
75
  "board.swarm.read",
67
76
  ]);
68
- /**
69
- * The person's own agents that run elsewhere and can be handed work (Grok Bot, Muse): the only agents whose asks a coding
70
- * agent's standing permission may take, and only when the person named them on it (board.standing.set proposers).
71
- * Harness's server, another person's agents and any other name never qualify.
72
- */
73
- export const PROPOSERS = MEMBERS.filter(
74
- (entry) => entry.road === "hosted" && entry.runs === "self" && entry.target
75
- ).map((entry) => entry.id);
77
+ export { PROPOSERS };
78
+
79
+ // What stays the person's when a run works for someone else (another person's agent asked for it) or is held in: their
80
+ // screen, what they heard and watched, their memory and past conversations, their file and code library, their money
81
+ // and their secrets. Such a run has the board, its own thread and its own folder (owner, October 31: collaborators are
82
+ // trusted to work, "especially ones that deal with secrets sensitive info or money" stay guarded).
83
+ const PRIVATE_COMMANDS = new Set([
84
+ "board.audio.listen",
85
+ "board.code.search",
86
+ "board.desk.book",
87
+ "board.desk.contract",
88
+ "board.desk.write",
89
+ "board.files.search",
90
+ "board.media.search",
91
+ "board.screen.search",
92
+ "board.screens.compare",
93
+ "board.swarm.memory",
94
+ "board.wallet",
95
+ "board.watch.add",
96
+ "mcp.download",
97
+ ]);
98
+ // Harness's own tools such a run may call through the relay: none that read the person's screen, memory or
99
+ // conversations, spend their credits or hold their secrets.
100
+ const OPEN_HARNESS_TOOLS = new Set(["archetype"]);
101
+ const PRIVATE_REFUSAL =
102
+ "Work done for someone else does not reach the person's screen, memory, conversations, files, money or secrets: only this thread and its folder.";
103
+ /** Why a run working for someone else (or held in) may not make this call, or null. `within(file, folder)`. */
104
+ export const privateReach = (command, request, run, within) => {
105
+ if (PRIVATE_COMMANDS.has(command)) return PRIVATE_REFUSAL;
106
+ if (command === "board.swarm.search" && !request.thread)
107
+ return PRIVATE_REFUSAL;
108
+ if (
109
+ command === "board.file.add" &&
110
+ request.path != null &&
111
+ !(
112
+ run.cwd &&
113
+ path.isAbsolute(String(request.path)) &&
114
+ within(String(request.path), run.cwd)
115
+ )
116
+ )
117
+ return "Work done for someone else attaches files from its own folder only.";
118
+ if (
119
+ command === "mcp.call" &&
120
+ request.rpc?.method === "tools/call" &&
121
+ !OPEN_HARNESS_TOOLS.has(String(request.rpc?.params?.name ?? ""))
122
+ )
123
+ return PRIVATE_REFUSAL;
124
+ if (
125
+ command === "mcp.call" &&
126
+ !["initialize", "tools/list", "tools/call"].includes(
127
+ String(request.rpc?.method)
128
+ ) &&
129
+ !String(request.rpc?.method ?? "").startsWith("notifications/")
130
+ )
131
+ return PRIVATE_REFUSAL;
132
+ return null;
133
+ };
76
134
 
77
135
  const runMayAsk = (command) =>
78
136
  command.startsWith("board.") ||
@@ -125,13 +183,21 @@ export function createRunAuthority({ store, installedAgents }) {
125
183
  const aboveHome = (dir) => within(os.homedir(), dir);
126
184
  // A coding agent's own scratch folder, for the person's tasks that name none: nothing of theirs is in it.
127
185
  const scratchFolder = (agent) => path.join(paths.home, "work", agent);
186
+ // The only limits on where and how often the person's agents start are the ones the person set: folders and a daily
187
+ // limit they named (mode 'named'). By default an agent runs in any folder below home, as the person would, and as
188
+ // often as asked (owner, October 31: "i never authorized any of that"); a thread's wake limit still stops a loop.
189
+ // Harness's own folders for the work: an agent's and a thread's scratch folders, and a thread's copy of a folder.
190
+ const harnessWork = (dir) =>
191
+ ["work", "worktrees"].some((place) =>
192
+ within(dir, path.join(paths.home, place))
193
+ );
128
194
  const covers = (rule, dir) =>
129
195
  realDir(dir) === realDir(scratchFolder(rule.agent)) ||
130
- rule.workspaces.some((root) =>
131
- rule.mode === "default" && aboveHome(root)
132
- ? realDir(root) === realDir(dir)
133
- : within(dir, root)
134
- );
196
+ (rule.mode === "named"
197
+ ? rule.workspaces.some((root) => within(dir, root))
198
+ : harnessWork(dir) || (within(dir, os.homedir()) && !aboveHome(dir)));
199
+ const pastLimit = (rule) =>
200
+ rule.mode === "named" && rule.runs_today >= rule.daily_cap;
135
201
  const standingRules = () => store.standing(runners(), startOfToday());
136
202
  // null when the run may start now; otherwise why it waits for the person.
137
203
  const standingVerdict = ({ trust, target, workspace, capacity = true }) => {
@@ -143,11 +209,11 @@ export function createRunAuthority({ store, installedAgents }) {
143
209
  if (rule.mode === "off")
144
210
  return `${target} is set to wait for the person's Start.`;
145
211
  if (!covers(rule, workspace))
146
- return rule.mode === "default"
147
- ? `${target} has not worked in ${workspace} before, so its first run there waits for the person.`
148
- : `${workspace} is outside the folders ${target} may run in without asking (${rule.workspaces.join(", ")}).`;
149
- if (capacity && rule.runs_today >= rule.daily_cap)
150
- return `${target} already started ${rule.runs_today} runs today without asking, its daily limit.`;
212
+ return rule.mode === "named"
213
+ ? `${workspace} is outside the folders ${target} may run in without asking (${rule.workspaces.join(", ")}).`
214
+ : `${workspace} is not a folder below the home folder, where agents run without the person.`;
215
+ if (capacity && pastLimit(rule))
216
+ return `${target} already started ${rule.runs_today} runs today without asking, the daily limit the person set.`;
151
217
  return null;
152
218
  };
153
219
  const applyStanding = (task) => {
@@ -169,25 +235,38 @@ export function createRunAuthority({ store, installedAgents }) {
169
235
  const proposedWhy = (why, { target, proposer, folder }) =>
170
236
  ({
171
237
  off: "its standing permission is off.",
172
- "not-proposer": `it starts on ${nameOf(proposer)}'s asks only if you let it: npx tryharness board standing ${target} --from ${proposer}`,
173
- outside: `${folder} is outside the folders it may run in without asking.`,
174
- cap: "it already started its runs for today without asking, its daily limit.",
238
+ "not-proposer": `you took ${nameOf(proposer)}'s asks off its standing permission. Let it again: npx tryharness board standing ${target} --from ${proposer}`,
239
+ outside: `${folder} is outside the folders you let it run in without asking.`,
240
+ cap: "it already started today's runs up to the daily limit you set.",
175
241
  gone: "its turn could not be authorized.",
176
242
  })[why];
177
243
 
178
- // Why an ask from one of the person's own agents elsewhere cannot use a standing permission at all, or null.
179
- // `hosted`: it came from Harness's server itself (HOSTED_CALLER), never a local process or another computer.
244
+ // Why an ask from one of the person's own agents cannot use a standing permission at all, or null. `hosted`: it came
245
+ // from Harness's server itself (HOSTED_CALLER), never a local process or another computer; `here`: from a process on
246
+ // this computer, claiming no Harness origin. Each agent's ask must come the one way that agent speaks. The guard's flag
247
+ // is a label for readers (it cannot tell the person's agents coordinating from planted orders); words it reads as
248
+ // orders aimed at the person's agents wait for the person, as do words through Harness's server it could not read
249
+ // (security audit S4): that is where planted instructions would reach for their secrets. An agent on this computer
250
+ // needs no reading, as in a thread (threadAuthority.mjs personsGo).
180
251
  const askRefusal = (ask) => {
181
252
  const proposer = String(ask?.proposer ?? "");
182
253
  return !PROPOSERS.includes(proposer)
183
254
  ? `${nameOf(proposer)} is not one of your own agents that may start it.`
184
- : ask.hosted !== true || ask.window
255
+ : speaksThroughHarness(proposer) && (ask.hosted !== true || ask.window)
185
256
  ? `${nameOf(proposer)}'s ask did not come through Harness as its asks do.`
186
- : ask.limited
187
- ? `${nameOf(proposer)} asked from a held-in run.`
188
- : ask.guard?.verdict !== "clean" || ask.guard.unavailable
189
- ? `the guard on this computer did not read ${nameOf(proposer)}'s words as clean.`
190
- : null;
257
+ : !speaksThroughHarness(proposer) &&
258
+ (ask.hosted === true || ask.here !== true || ask.window)
259
+ ? `${nameOf(proposer)}'s ask did not come from this computer as its asks do.`
260
+ : ask.limited
261
+ ? `${nameOf(proposer)} asked from a held-in run.`
262
+ : speaksThroughHarness(proposer) &&
263
+ (!ask.guard || ask.guard.unavailable)
264
+ ? `the guard on this computer could not read ${nameOf(proposer)}'s words.`
265
+ : ask.guard.verdict === "hold"
266
+ ? `the guard on this computer read ${nameOf(proposer)}'s words as orders aimed at your agents.`
267
+ : (ask.handoffs ?? 0) > MAX_HANDOFFS
268
+ ? `your agents have handed this work on ${MAX_HANDOFFS} times in a row without you, so a loop cannot run on its own.`
269
+ : null;
191
270
  };
192
271
  // Authorized on the rule in one transaction (store.mjs authorizeProposed), its receipt naming the folder checked
193
272
  // and the computer it is for, which proposedHold checks again before it starts.
@@ -197,6 +276,7 @@ export function createRunAuthority({ store, installedAgents }) {
197
276
  proposer,
198
277
  since: startOfToday(),
199
278
  covered: (rule) => !folder || covers(rule, folder),
279
+ pastLimit,
200
280
  folder,
201
281
  scratch,
202
282
  });
@@ -215,12 +295,13 @@ export function createRunAuthority({ store, installedAgents }) {
215
295
  /**
216
296
  * One of the person's own agents elsewhere (PROPOSERS) asked a coding agent here for a turn in a thread whose own work
217
297
  * does not run on the person's go (threadAuthority.mjs threadMayRun: another agent wrote it). The turn starts only
218
- * on the coding agent's standing permission, where the person named that asker on it: its words reached here through
219
- * Harness's server and the guard on this computer read them clean, from no restricted run, review or linked window.
220
- * It counts against the agent's daily limit like any standing run and keeps the agent-written label; the thread's
221
- * own folder is the one checked (null: a fresh scratch folder of the thread's, which holds nothing of the person's).
298
+ * on the coding agent's standing permission unless the person took that asker off it: its words reached here the way
299
+ * that agent speaks and the guard on this computer did not read them as orders (a flag is only a label), from no
300
+ * restricted run, review or linked window.
301
+ * It counts as one of the agent's standing runs and keeps the agent-written label; the thread's own folder is the one
302
+ * checked (null: a fresh scratch folder of the thread's, which holds nothing of the person's).
222
303
  *
223
- * `ask`: { proposer, hosted, guard, limited, window }, as the thread heard it. Returns { started } or { started:
304
+ * `ask`: { proposer, hosted, here, guard, limited, window, handoffs }, as the thread heard it. Returns { started } or { started:
224
305
  * false, reason }, the reason ending "<agent> waits for your Start: ".
225
306
  */
226
307
  const admitProposed = (wake, ask, folder) => {
@@ -273,7 +354,7 @@ export function createRunAuthority({ store, installedAgents }) {
273
354
  ? `you took ${nameOf(proposal.proposer)}'s asks off ${nameOf(task.target_agent)}'s standing permission.`
274
355
  : proposal.folder && !covers(rule, proposal.folder)
275
356
  ? `${proposal.folder} is no longer among the folders it may run in without asking.`
276
- : changed && rule.runs_today > rule.daily_cap
357
+ : changed && rule.mode === "named" && rule.runs_today > rule.daily_cap
277
358
  ? "you lowered its daily limit below the runs it already started today."
278
359
  : (Object.hasOwn(proposal, "machine") &&
279
360
  (task.target_machine ?? null) !== proposal.machine) ||
@@ -334,6 +415,8 @@ export function createRunAuthority({ store, installedAgents }) {
334
415
  return "This run has only its scoped workspace and dispatch tools.";
335
416
  if (run.restricted && command.startsWith("mcp."))
336
417
  return "A restricted run reaches this computer's board, not the person's Harness.";
418
+ if (run.restricted || run.forAnotherPerson)
419
+ return privateReach(command, request, run, within);
337
420
  return null;
338
421
  }
339
422
  if (request.agent !== "user" && runMayAsk(command)) return null;
package/lib/runWorker.mjs CHANGED
@@ -50,22 +50,42 @@ export function createRunWorker({
50
50
  const defaults = standingRules().filter((rule) => rule.mode === "default");
51
51
  if (defaults.length && !store.meta("standing_announced")) {
52
52
  const one = defaults.length === 1;
53
- const text = `${defaults.map((rule) => nameOf(rule.agent)).join(", ")} now ${one ? "starts" : "start"} the tasks you ask for in folders ${one ? "it has" : "they have"} worked in, up to ${defaults[0].daily_cap} a day${one ? "" : " each"}, without a Start.`;
53
+ const text = `${defaults.map((rule) => nameOf(rule.agent)).join(", ")} now ${one ? "starts" : "start"} the tasks you and your agents ask for, in any folder below your home, without a Start.`;
54
54
  log(text);
55
55
  notifyDesktop(text);
56
56
  store.meta("standing_announced", new Date().toISOString());
57
57
  }
58
- // Where a run works, one at a time: its folder, or for a turn T3 Code carries out, its thread (T3 keeps the checkout).
59
- // A review changes nothing (runner.mjs runs it read-only), so it goes beside whoever writes there: one review per
60
- // agent per thread, as its session is one (reviews once waited 168 min behind other agents' turns in 3 days).
58
+ // Where a run works, one at a time for each agent: its folder, or for a turn T3 Code carries out, its thread (T3 keeps
59
+ // the checkout). Different agents work in one folder side by side, as the person runs them (owner, October 31: Claude
60
+ // Code and OpenCode once waited 2 h 44 min behind Codex in one folder; "making me babysit my agents"); an agent keeps
61
+ // one turn at a time there, as its session is one. A review changes nothing (runner.mjs runs it read-only), so it
62
+ // goes beside whoever writes there: one review per agent per thread.
61
63
  const slotOf = (task) =>
62
64
  store.meta(`review:${task.id}`) === "1"
63
65
  ? `review:${task.target_agent}:${task.parent_id}`
64
66
  : store.meta(`t3-run:${task.id}`) === "1"
65
67
  ? `t3:${task.parent_id}`
66
68
  : task.run_workspace
67
- ? path.resolve(task.run_workspace)
69
+ ? `${path.resolve(task.run_workspace)}:${task.target_agent}`
68
70
  : task.target_agent;
71
+ // Who asked for a run: the agent whose post woke it in a thread, or that posted the task.
72
+ const askerOf = (task) => {
73
+ if (task.kind !== "wake") return task.origin_agent;
74
+ try {
75
+ return JSON.parse(store.meta(`wake-reason:${task.id}`) || "null")?.asker;
76
+ } catch {
77
+ return null;
78
+ }
79
+ };
80
+ // A hand-off waits for the turn of the agent that asked for it in the same folder, so it starts from that agent's
81
+ // finished work (a handoff posted while it waited reaches its brief); independent work there goes side by side.
82
+ const askerHolds = (task) => {
83
+ if (!task.run_workspace) return null;
84
+ const asker = askerOf(task);
85
+ return asker && asker !== task.target_agent
86
+ ? (activeRuns.get(`${path.resolve(task.run_workspace)}:${asker}`) ?? null)
87
+ : null;
88
+ };
69
89
  const runsInThread = (agent, threadId) =>
70
90
  [...activeRuns.values()].some(
71
91
  (held) =>
@@ -90,9 +110,13 @@ export function createRunWorker({
90
110
  if (refusal) return refusal;
91
111
  if (runsHeld)
92
112
  return `${who} starts when your Mac is no longer running with its lid closed.`;
93
- const holder = activeRuns.get(slotOf({ ...run, parent_id: goalId }));
94
- if (!holder) return null;
95
- return `${who} starts when ${nameOf(holder.agent)}'s turn ends: they work in the same folder, one at a time.`;
113
+ const own = activeRuns.get(slotOf({ ...run, parent_id: goalId }));
114
+ if (own)
115
+ return `${who} starts when its turn there now ends: an agent takes one turn at a time in a folder.`;
116
+ const asker = askerHolds(run);
117
+ return asker
118
+ ? `${who} starts when ${nameOf(asker.agent)}'s turn ends: they work in the same folder, one at a time.`
119
+ : null;
96
120
  };
97
121
  // A thread hears once why its agent did not start right away. Work an agent asked for while its own turn holds the
98
122
  // folder is not said: the asker was told when it asked, and the wait ends as it stops (the thread's waits still show it).
@@ -113,7 +137,7 @@ export function createRunWorker({
113
137
  };
114
138
  const runBoard = () => {
115
139
  if (runsHeld || !holdsBoard()) return;
116
- // One run per folder at a time: each thread's worktree is its own folder, so threads run side by side.
140
+ // One run per agent per folder at a time: other agents and other threads' worktrees run side by side.
117
141
  for (const task of store.runnableTasks(installedAgents, machineId(), {
118
142
  only: onlyItsOwn(),
119
143
  })) {
@@ -131,11 +155,14 @@ export function createRunWorker({
131
155
  noteWaiting(task, activeRuns.get(slot));
132
156
  continue;
133
157
  }
134
- // A task T3 carries out still waits for a run working in its folder, such as the turn of the agent that handed it
135
- // on: two runs never work one checkout at once.
158
+ if (!slot.startsWith("review:") && askerHolds(task)) {
159
+ noteWaiting(task, askerHolds(task));
160
+ continue;
161
+ }
162
+ // A task T3 carries out still waits for the same agent's run in its folder: one session there at a time.
136
163
  const folder =
137
164
  task.kind === "task" && slot.startsWith("t3:") && task.run_workspace
138
- ? path.resolve(task.run_workspace)
165
+ ? `${path.resolve(task.run_workspace)}:${agent}`
139
166
  : null;
140
167
  if (folder && activeRuns.has(folder)) continue;
141
168
  // An agent resumes one session per thread: its review waits while its own turn there runs.
@@ -168,13 +195,15 @@ export function createRunWorker({
168
195
  const startBoardRun = async (task, agent) => {
169
196
  const wake = task.kind === "wake";
170
197
  const room = !wake && task.parent_id ? store.getTask(task.parent_id) : null;
198
+ // Taken before the brief reads the thread: words posted while it is prepared, after it read them, are later than
199
+ // the start, so settleWake wakes the agent again for them instead of dropping them as already read.
200
+ const startedAt = new Date().toISOString();
171
201
  const {
172
202
  prompt,
173
203
  resumeSession,
174
204
  again,
175
205
  t3: inT3,
176
206
  } = dispatches?.briefFor(task) ?? (await briefs.prepare(task, agent));
177
- const startedAt = new Date().toISOString();
178
207
  const stoppedFor = Boolean(again);
179
208
  // The session it resumes is the run's from its first moment, so Open never resumes it beside the run before the
180
209
  // agent says which session it is in (OpenCode once said so only minutes into its turn).
@@ -204,8 +233,9 @@ export function createRunWorker({
204
233
  // The person's environment grants (vault.mjs), never for a run they did not authorize: the values are in this
205
234
  // run's environment, and what it says is scrubbed of them.
206
235
  // Nor for a turn another of the person's agents asked for on standing permission: that grants a start, no secrets.
236
+ // Nor for work another person asked for, whoever started it: the person's secrets stay theirs.
207
237
  const secrets =
208
- restricted || store.standingProposal(task.id)
238
+ restricted || ownSettingsOnly || store.standingProposal(task.id)
209
239
  ? null
210
240
  : vaultEnv(task, agent);
211
241
  const granted = secrets && Object.keys(secrets.env).length ? secrets : null;
package/lib/runner.mjs CHANGED
@@ -25,11 +25,18 @@ const issueCapability = (task) => {
25
25
  restricted: task.restricted === true || Boolean(task.dispatchScope),
26
26
  review: task.readOnly === true,
27
27
  dispatchScope: task.dispatchScope ?? null,
28
+ // Work another person asked for (runWorker.mjs ownSettingsOnly), and the folder it works in: such a run reaches
29
+ // none of the person's private things beyond that folder (runAuthority.mjs privateReach).
30
+ forAnotherPerson: task.ownSettingsOnly === true,
31
+ cwd: task.cwd ? path.resolve(task.cwd) : null,
28
32
  });
29
33
  return token;
30
34
  };
31
35
 
32
- /** The run a capability belongs to while that run goes on: its id, agent, and whether it is restricted or a review. */
36
+ /**
37
+ * The run a capability belongs to while that run goes on: its id, agent, whether it is restricted or a review, whether
38
+ * it works for another person, and its folder.
39
+ */
33
40
  export function runCapability(token) {
34
41
  return capabilities.get(String(token)) ?? null;
35
42
  }
@@ -159,29 +166,146 @@ const readDenials = (home) =>
159
166
  ? HARNESS_FILES.map((file) => `Read(/${path.join(place, file)})`)
160
167
  : [`Read(/${place})`, `Read(/${place}/**)`]
161
168
  );
169
+ // A run nobody pressed Start on reads only its own folder (owner, October 31: "nothing outside that without the consent
170
+ // of the user"). Denied: every home folder and the drives and shares mounted from outside, where people keep their
171
+ // files. Still readable: the operating system's own folders, the programs a run builds and tests with, git's settings,
172
+ // and the repository a worktree belongs to, whose history git reads.
173
+ const PERSONAL_ROOTS = ["/Volumes", "/media", "/mnt", "/run/media"];
174
+ const PROGRAM_PLACES = [
175
+ ".nvm",
176
+ ".volta",
177
+ ".bun",
178
+ ".deno",
179
+ ".cargo/bin",
180
+ ".rustup",
181
+ ".pyenv",
182
+ ".asdf",
183
+ ".local/bin",
184
+ ".local/share/mise",
185
+ "go/bin",
186
+ // Without its settings git refuses to run at all, and a commit has no author.
187
+ ".gitconfig",
188
+ ".config/git",
189
+ ];
190
+ // The shell snapshot each agent's shell tool sources before every command, kept in that agent's own folder.
191
+ const SHELL_SNAPSHOTS = {
192
+ "claude-code": ".claude/shell-snapshots",
193
+ codex: ".codex/shell_snapshots",
194
+ };
195
+ const personalRoots = (home) => [
196
+ ...new Set([path.dirname(home), ...PERSONAL_ROOTS]),
197
+ ];
198
+ // A worktree's `.git` is a file naming its git folder inside the checkout it came from; git reads both.
199
+ const gitFolders = (cwd) => {
200
+ let pointer = "";
201
+ try {
202
+ pointer = fs.readFileSync(path.join(cwd, ".git"), "utf8");
203
+ } catch {
204
+ return [];
205
+ }
206
+ const own = pointer.match(/^gitdir: (.+)$/m)?.[1]?.trim();
207
+ if (!own) return [];
208
+ const gitDir = path.resolve(cwd, own);
209
+ let common = gitDir;
210
+ try {
211
+ common = path.resolve(
212
+ gitDir,
213
+ fs.readFileSync(path.join(gitDir, "commondir"), "utf8").trim()
214
+ );
215
+ } catch {}
216
+ return [...new Set([gitDir, common])];
217
+ };
218
+ /** What `agent`'s run held to its folder still reads beneath the places it may not: its folder, git's, programs. */
219
+ export const confinedReads = (
220
+ cwd,
221
+ home = os.homedir(),
222
+ agent = "claude-code"
223
+ ) => [
224
+ ...(cwd ? [cwd, ...gitFolders(cwd)] : []),
225
+ ...[...PROGRAM_PLACES, SHELL_SNAPSHOTS[agent]].map((place) =>
226
+ path.join(home, place)
227
+ ),
228
+ ];
229
+ const within = (place, root) => {
230
+ const relative = path.relative(root, place);
231
+ return (
232
+ relative === "" ||
233
+ (!relative.startsWith("..") && !path.isAbsolute(relative))
234
+ );
235
+ };
236
+ /**
237
+ * Every place a run held to its folder may not read, as absolute paths. Not a whole home folder with the run's own let
238
+ * back in: git walks up the folders above its own and stops at one it cannot look at, and Claude Code's file tools
239
+ * take no exception inside a deny. So each entry beside the path down to a place it may read is named, as the run
240
+ * starts; the folders on that path show their entries' names and nothing in them. A secret place is denied even where
241
+ * it lies beside an open one.
242
+ */
243
+ export const fencedPlaces = (
244
+ cwd,
245
+ home = os.homedir(),
246
+ agent = "claude-code"
247
+ ) => {
248
+ const open = confinedReads(cwd, home, agent);
249
+ const fenced = [];
250
+ const fence = (place, secret = false) => {
251
+ if (!secret && open.some((root) => within(place, root))) return;
252
+ if (!open.some((root) => root !== place && within(root, place))) {
253
+ fenced.push(place);
254
+ return;
255
+ }
256
+ let entries = [];
257
+ try {
258
+ entries = fs.readdirSync(place);
259
+ } catch {
260
+ return;
261
+ }
262
+ for (const entry of entries) fence(path.join(place, entry));
263
+ };
264
+ for (const root of personalRoots(home)) if (fs.existsSync(root)) fence(root);
265
+ for (const place of secretPlaces(home)) fence(place, true);
266
+ return [...new Set(fenced)];
267
+ };
162
268
  // The sandbox holds shell commands to the same places. The run's own folder stays readable even inside Harness's home,
163
- // where its worktree is, and so do the shell snapshots each agent's shell tool sources before every command.
164
- const sandboxReads = (cwd, home) => ({
165
- denyRead: secretPlaces(home),
166
- allowRead: [
167
- ...(cwd ? [cwd] : []),
168
- path.join(home, ".claude", "shell-snapshots"),
169
- ],
170
- });
269
+ // where its worktree is, and so do the shell snapshots each agent's shell tool sources before every command. A run
270
+ // held to its folder (`confined`) reads nothing else of the person's.
271
+ const sandboxReads = (cwd, home, confined = false) =>
272
+ confined
273
+ ? { denyRead: fencedPlaces(cwd, home), allowRead: confinedReads(cwd, home) }
274
+ : {
275
+ denyRead: secretPlaces(home),
276
+ allowRead: [
277
+ ...(cwd ? [cwd] : []),
278
+ path.join(home, ".claude", "shell-snapshots"),
279
+ ],
280
+ };
281
+ const confinedDenials = (cwd, home, confined) =>
282
+ confined
283
+ ? fencedPlaces(cwd, home).flatMap((place) => [
284
+ `Read(/${place})`,
285
+ `Read(/${place}/**)`,
286
+ ])
287
+ : [];
171
288
 
172
289
  // A run another agent started without the person's tap (docs/member-runs.md): anything that would ask is refused, file
173
290
  // edits only in its worktree, shell commands only inside the operating system's sandbox with no network, nothing read
174
291
  // where the person keeps credentials, and no hooks or settings from the repository. A review gets no edits at all.
175
292
  export const restrictedClaudeSettings = (cwd, home = os.homedir()) => ({
176
293
  disableAllHooks: true,
177
- permissions: { deny: ["WebFetch", "WebSearch", ...readDenials(home)] },
294
+ permissions: {
295
+ deny: [
296
+ "WebFetch",
297
+ "WebSearch",
298
+ ...readDenials(home),
299
+ ...confinedDenials(cwd, home, true),
300
+ ],
301
+ },
178
302
  sandbox: {
179
303
  enabled: true,
180
304
  autoAllowBashIfSandboxed: true,
181
305
  allowUnsandboxedCommands: false,
182
306
  failIfUnavailable: true,
183
307
  excludedCommands: [],
184
- filesystem: sandboxReads(cwd, home),
308
+ filesystem: sandboxReads(cwd, home, true),
185
309
  network: { allowedDomains: [], strictAllowlist: true },
186
310
  },
187
311
  });
@@ -286,15 +410,26 @@ const modelWindow = ({ limits }) =>
286
410
  // folder is refused; denying edits everywhere also broke Claude Code's own scratch files under /tmp). It reads nothing
287
411
  // where the person keeps credentials, loads no settings or hooks from the repository it reviews, and has no web: what
288
412
  // it reviews is in the folder and the thread, and a fetch is a way out for what it read.
289
- export const readOnlyClaudeSettings = (cwd, home = os.homedir()) => ({
413
+ // A review nobody pressed Start on (`confined`) reads only its folder, as a restricted run does.
414
+ export const readOnlyClaudeSettings = (
415
+ cwd,
416
+ home = os.homedir(),
417
+ confined = false
418
+ ) => ({
290
419
  permissions: {
291
- deny: ["Edit(./**)", "WebFetch", "WebSearch", ...readDenials(home)],
420
+ deny: [
421
+ "Edit(./**)",
422
+ "WebFetch",
423
+ "WebSearch",
424
+ ...readDenials(home),
425
+ ...confinedDenials(cwd, home, confined),
426
+ ],
292
427
  },
293
428
  sandbox: {
294
429
  enabled: true,
295
430
  autoAllowBashIfSandboxed: true,
296
431
  allowUnsandboxedCommands: false,
297
- filesystem: sandboxReads(cwd, home),
432
+ filesystem: sandboxReads(cwd, home, confined),
298
433
  network: { allowedDomains: [], strictAllowlist: true },
299
434
  },
300
435
  });
@@ -309,20 +444,30 @@ const readOnlyClaude = (task) => [
309
444
  "user",
310
445
  "--settings",
311
446
  JSON.stringify({
312
- ...readOnlyClaudeSettings(task.cwd),
447
+ ...readOnlyClaudeSettings(task.cwd, os.homedir(), task.restricted === true),
313
448
  ...modelWindow(task),
314
449
  }),
315
450
  ];
316
451
 
317
452
  // Codex's review: its read-only permission profile, with the same places denied to every command it runs (the run's
318
453
  // own folder stays readable when it lies inside one) and no web search. Probed with `codex sandbox` 0.164: a denied
319
- // file is "Operation not permitted", the folder reads, writes and the daemon's socket are refused.
320
- const codexReview = (task, executable, home = os.homedir()) => {
454
+ // file is "Operation not permitted", the folder reads, writes and the daemon's socket are refused. A restricted run
455
+ // (`write`) has the same profile with its own folder writable: probed with `codex sandbox` 0.166, it writes there,
456
+ // ~/.ssh is denied and the network is refused, as for Claude Code's restricted run. A restricted run, or a review
457
+ // nobody pressed Start on, reads only its folder: the more specific place wins, so the folder, git's and the programs
458
+ // under a denied home stay readable.
459
+ const codexReview = (task, executable, home = os.homedir(), write = false) => {
460
+ const confined = write || task.restricted === true;
321
461
  const places = Object.fromEntries(
322
- secretPlaces(home).map((place) => [place, "deny"])
462
+ (confined ? fencedPlaces(task.cwd, home, "codex") : secretPlaces(home)).map(
463
+ (place) => [place, "deny"]
464
+ )
323
465
  );
466
+ if (confined)
467
+ for (const place of confinedReads(task.cwd, home, "codex"))
468
+ places[place] = "read";
324
469
  places[path.join(home, ".codex", "shell_snapshots")] = "read";
325
- if (task.cwd) places[task.cwd] = "read";
470
+ if (task.cwd) places[task.cwd] = write ? "write" : "read";
326
471
  // Standalone Codex lives inside its denied credential home and reexecutes
327
472
  // itself to load AGENTS.md. Only its confirmed, resolved file needs access.
328
473
  if (executable) places[executable] = "read";
@@ -425,8 +570,9 @@ export function agentInvocation(task, { executable = null } = {}) {
425
570
  ],
426
571
  };
427
572
  }
428
- // Only Claude Code has a restricted mode; any other agent's restricted run is refused here, whatever let it start.
429
- if (task.restricted)
573
+ // Only Claude Code and Codex have a restricted mode; any other agent's restricted run is refused here, whatever let it
574
+ // start.
575
+ if (task.restricted && task.agent !== "codex")
430
576
  throw new Error(
431
577
  `${task.agent} has no restricted mode; it runs only after the person's Start`
432
578
  );
@@ -449,7 +595,18 @@ export function agentInvocation(task, { executable = null } = {}) {
449
595
  "-c",
450
596
  'mcp_servers.harness.default_tools_approval_mode="approve"',
451
597
  ]
452
- : ["--dangerously-bypass-approvals-and-sandbox"]),
598
+ : task.restricted
599
+ ? [
600
+ ...codexReview(task, executable, os.homedir(), true),
601
+ "-c",
602
+ 'approval_policy="never"',
603
+ // Only Harness's board, as for restricted Claude Code: none of the person's other MCP servers.
604
+ "-c",
605
+ `mcp_servers={harness={command=${JSON.stringify(process.execPath)},args=${JSON.stringify([fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)), "--agent", "codex", "--restricted"])}}}`,
606
+ "-c",
607
+ 'mcp_servers.harness.default_tools_approval_mode="approve"',
608
+ ]
609
+ : ["--dangerously-bypass-approvals-and-sandbox"]),
453
610
  "--skip-git-repo-check",
454
611
  "-",
455
612
  ],
@@ -710,17 +867,17 @@ export function readRunSteps(file, limit = 200) {
710
867
  }
711
868
 
712
869
  export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
713
- // One run per folder: two agents in one checkout would trip over each other; a thread's worktree is its own folder.
714
- // A read-only review edits nothing, so it goes beside whoever writes there (runWorker.mjs keeps one per agent).
870
+ // One run per agent per folder: an agent's session there is one; other agents work beside it, as the person runs them
871
+ // (runWorker.mjs slotOf). A read-only review edits nothing, so it goes beside whoever writes there.
715
872
  const slot = task.readOnly
716
873
  ? `review:${task.agent}:${task.cwd || ""}`
717
874
  : task.cwd
718
- ? path.resolve(task.cwd)
875
+ ? `${path.resolve(task.cwd)}:${task.agent}`
719
876
  : task.agent;
720
877
  if (running.has(slot)) {
721
878
  emit(
722
879
  "failed",
723
- `Another run is already working in ${task.cwd || "that folder"}.`,
880
+ `${task.agent} is already working in ${task.cwd || "that folder"}.`,
724
881
  { failure: "start" }
725
882
  );
726
883
  return;