tryharness 0.7.83 → 0.7.86
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 +21 -19
- package/assets/dsh-plugin.mjs +75 -4
- package/assets/herdr-mod/harness/main.js +367 -0
- package/assets/herdr-mod/harness/mod.json +6 -0
- package/assets/opencode-plugin.js +87 -22
- package/assets/pi-extension.ts +81 -2
- package/cli.mjs +544 -208
- package/lib/adapters.mjs +62 -27
- package/lib/agentBinaries.mjs +6 -8
- package/lib/agentClaims.mjs +168 -0
- package/lib/agentReadTools.json +415 -0
- package/lib/agentSignIn.mjs +17 -18
- package/lib/agentWiring.mjs +114 -0
- package/lib/archetypes.js +10 -11
- package/lib/attention.mjs +100 -0
- package/lib/audit.mjs +1 -1
- package/lib/backupSetup.mjs +6 -28
- package/lib/bankrApprovals.mjs +86 -0
- package/lib/boardAccess.mjs +40 -66
- package/lib/boardBackup.mjs +86 -85
- package/lib/boardCommands.mjs +28 -0
- package/lib/boardFileCommands.mjs +29 -36
- package/lib/boardFiles.mjs +83 -15
- package/lib/boardMirror.mjs +78 -11
- package/lib/boardProtocol.json +191 -123
- package/lib/boardThreads.mjs +19 -37
- package/lib/boardTools.mjs +22 -15
- package/lib/boardWatches.mjs +43 -15
- package/lib/bridge.mjs +7 -3
- package/lib/browserAgentTools.mjs +59 -0
- package/lib/browserWake.mjs +0 -6
- package/lib/cards.mjs +52 -0
- package/lib/circling.mjs +189 -0
- package/lib/cleanup.mjs +234 -0
- package/lib/cloudBoot.mjs +21 -4
- package/lib/cloudSave.mjs +46 -5
- package/lib/compaction.mjs +8 -1
- package/lib/completion.mjs +358 -0
- package/lib/computerDevices.mjs +853 -0
- package/lib/connectionStatus.mjs +34 -0
- package/lib/connectors.mjs +139 -1
- package/lib/coordinator.mjs +108 -14
- package/lib/coreModels.mjs +36 -12
- package/lib/daemon.mjs +2426 -338
- package/lib/daemonLock.mjs +103 -0
- package/lib/deviceDoor.mjs +308 -0
- package/lib/deviceIdentity.mjs +114 -0
- package/lib/deviceList.mjs +172 -0
- package/lib/deviceSeal.mjs +74 -0
- package/lib/dispatcher.mjs +497 -26
- package/lib/dispatches.mjs +3 -3
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +67 -41
- package/lib/events.mjs +318 -0
- package/lib/facts.mjs +170 -0
- package/lib/fileSource.mjs +540 -0
- package/lib/files.mjs +47 -2
- package/lib/gitHost.mjs +39 -1
- package/lib/goalCommands.mjs +12 -80
- package/lib/handover.mjs +21 -16
- package/lib/harnessOffers.mjs +140 -15
- package/lib/herdr.mjs +100 -15
- package/lib/herdrAppCall.mjs +19 -0
- package/lib/herdrCore.mjs +59 -0
- package/lib/herdrRuns.mjs +1126 -0
- package/lib/hookDialects.mjs +235 -50
- package/lib/identityLink.mjs +81 -0
- package/lib/inference.mjs +31 -2
- package/lib/jamAccess.mjs +82 -0
- package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
- package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
- package/lib/jamKey.mjs +274 -0
- package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
- package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
- package/lib/jamStore.mjs +973 -0
- package/lib/jamUpgrade.mjs +112 -0
- package/lib/jams.mjs +3079 -0
- package/lib/kanban.mjs +13 -7
- package/lib/landed.mjs +5 -1
- package/lib/library.mjs +41 -22
- package/lib/limits.mjs +91 -0
- package/lib/lineDiff.mjs +97 -0
- package/lib/lineup.mjs +18 -13
- package/lib/link.mjs +584 -0
- package/lib/localStack.mjs +75 -16
- package/lib/localmodels.mjs +58 -78
- package/lib/loopBackstop.mjs +2 -1
- package/lib/machine.mjs +544 -0
- package/lib/machineLink.mjs +446 -0
- package/lib/machineRoutes.mjs +68 -19
- package/lib/machineRuns.mjs +85 -4
- package/lib/machineSeal.mjs +6 -31
- package/lib/manager.mjs +134 -12
- package/lib/mcp-stdio.mjs +492 -215
- package/lib/mcpRelay.mjs +34 -35
- package/lib/members.json +1 -1
- package/lib/modelRoute.mjs +162 -0
- package/lib/nativeHost.mjs +81 -90
- package/lib/nativeSenses.mjs +258 -0
- package/lib/nerves.mjs +523 -0
- package/lib/network.mjs +117 -278
- package/lib/networkPlaces.mjs +578 -0
- package/lib/nextStep.mjs +95 -0
- package/lib/notify.mjs +2 -2
- package/lib/nudge.mjs +116 -10
- package/lib/originals.mjs +216 -0
- package/lib/outsideEvents.mjs +383 -0
- package/lib/outsideRuns.mjs +230 -0
- package/lib/ownMachines.mjs +674 -256
- package/lib/pain.mjs +215 -0
- package/lib/pairing.mjs +91 -11
- package/lib/paths.mjs +42 -3
- package/lib/peerProcess.mjs +21 -7
- package/lib/peopleLink.mjs +268 -0
- package/lib/personNotices.mjs +3 -2
- package/lib/phones.mjs +252 -542
- package/lib/placeCards.mjs +282 -0
- package/lib/placeChecks.mjs +95 -0
- package/lib/placeCommands.mjs +8 -17
- package/lib/placeRequests.mjs +152 -0
- package/lib/placeStore.mjs +295 -0
- package/lib/placeTool.d.ts +12 -0
- package/lib/placeTool.js +40 -0
- package/lib/places.mjs +63 -14
- package/lib/plans.mjs +53 -8
- package/lib/presence.mjs +270 -0
- package/lib/privateNetwork.d.ts +2 -0
- package/lib/privateNetwork.js +93 -0
- package/lib/proposals.mjs +300 -0
- package/lib/publicFetch.d.ts +32 -0
- package/lib/publicFetch.js +248 -0
- package/lib/reach.mjs +128 -0
- package/lib/rebuildable.mjs +72 -0
- package/lib/recall.mjs +216 -0
- package/lib/record.mjs +13 -0
- package/lib/reflexes.mjs +392 -0
- package/lib/relayLimits.mjs +31 -2
- package/lib/releaseNotice.mjs +198 -0
- package/lib/removeHarness.mjs +15 -4
- package/lib/repoLinks.mjs +204 -35
- package/lib/runAuthority.mjs +102 -39
- package/lib/runBrief.mjs +93 -40
- package/lib/runRequests.mjs +52 -14
- package/lib/runUsage.mjs +31 -0
- package/lib/runWorker.mjs +74 -25
- package/lib/runner.mjs +289 -45
- package/lib/runtime-install.mjs +37 -8
- package/lib/schedules.mjs +171 -47
- package/lib/screenWatches.mjs +221 -0
- package/lib/sealed.mjs +12 -30
- package/lib/sealedThreads.mjs +198 -392
- package/lib/secretStore.mjs +178 -0
- package/lib/secrets.mjs +11 -0
- package/lib/seen.mjs +3 -9
- package/lib/selfUpdate.mjs +51 -15
- package/lib/senseCall.mjs +1514 -0
- package/lib/senseHook.mjs +114 -0
- package/lib/senseTools.mjs +1298 -0
- package/lib/sessionBriefs.mjs +87 -0
- package/lib/sessionControl.mjs +63 -13
- package/lib/sessionFiles.mjs +85 -0
- package/lib/setupChoices.mjs +12 -3
- package/lib/setupMode.mjs +70 -25
- package/lib/sharedKeys.mjs +166 -0
- package/lib/sleep.mjs +396 -0
- package/lib/sources.mjs +306 -0
- package/lib/speech.mjs +166 -411
- package/lib/spoken.mjs +210 -0
- package/lib/steerHook.mjs +3 -1
- package/lib/steerQueue.mjs +40 -11
- package/lib/store.mjs +323 -130
- package/lib/stuck.mjs +85 -7
- package/lib/swarm.mjs +157 -49
- package/lib/swarmDevices.mjs +25 -85
- package/lib/swarmMemory.mjs +93 -9
- package/lib/t3.mjs +73 -3
- package/lib/taskCommands.mjs +51 -60
- package/lib/taskRooms.mjs +30 -4
- package/lib/taskRules.json +29 -0
- package/lib/taskRules.mjs +21 -0
- package/lib/taskRuns.mjs +74 -11
- package/lib/team.mjs +2 -1
- package/lib/threadActions.mjs +37 -9
- package/lib/threadAuthority.mjs +4 -4
- package/lib/threadBriefs.mjs +173 -43
- package/lib/threadNotes.mjs +320 -0
- package/lib/threadRecord.mjs +491 -0
- package/lib/threadRuns.mjs +216 -108
- package/lib/threadView.mjs +27 -30
- package/lib/threadWatches.mjs +1962 -0
- package/lib/timeSense.mjs +839 -0
- package/lib/tripwires.mjs +454 -0
- package/lib/ui.mjs +1 -1
- package/lib/vault.mjs +560 -45
- package/lib/vaultCommands.mjs +5 -3
- package/lib/vaultPeers.mjs +165 -0
- package/lib/vaultTools.d.ts +4 -1
- package/lib/vaultTools.js +22 -1
- package/lib/verdicts.mjs +12 -26
- package/lib/versions.mjs +117 -0
- package/lib/waitTool.mjs +278 -0
- package/lib/wakePicture.mjs +268 -0
- package/lib/wakeQueue.mjs +108 -0
- package/lib/watchResponses.mjs +533 -0
- package/lib/watches.mjs +290 -145
- package/lib/windowAsks.mjs +80 -17
- package/lib/worktrees.mjs +159 -9
- package/npm-shrinkwrap.json +138 -631
- package/package.json +7 -6
- package/release.json +211 -129
- package/lib/callSessions.mjs +0 -51
- package/lib/directLink.mjs +0 -349
- package/lib/peopleBoard.mjs +0 -131
- package/lib/projects.mjs +0 -2917
- package/lib/roomChannels.mjs +0 -667
package/lib/runner.mjs
CHANGED
|
@@ -2,14 +2,17 @@ import fs from "node:fs";
|
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
6
|
-
import { randomBytes } from "node:crypto";
|
|
5
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
6
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
7
7
|
import { agentBinary } from "./agentBinaries.mjs";
|
|
8
8
|
import { agentEnvironment } from "./agentnode.mjs";
|
|
9
9
|
import { runtimeOf } from "./agentRuntimeConfig.mjs";
|
|
10
10
|
import { runProtocolTask } from "./agentRuntimes.mjs";
|
|
11
11
|
import { scrubValues } from "./vault.mjs";
|
|
12
12
|
import { harnessNode, historyRoots, paths } from "./paths.mjs";
|
|
13
|
+
import { writeJsonAtomic } from "./files.mjs";
|
|
14
|
+
import { processStart } from "./peerProcess.mjs";
|
|
15
|
+
import { cutKeepingNextStep } from "./nextStep.mjs";
|
|
13
16
|
|
|
14
17
|
const running = new Set();
|
|
15
18
|
const children = new Map();
|
|
@@ -28,6 +31,8 @@ const issueCapability = (task) => {
|
|
|
28
31
|
// none of the person's private things beyond that folder (runAuthority.mjs privateReach).
|
|
29
32
|
forAnotherPerson: task.ownSettingsOnly === true,
|
|
30
33
|
cwd: task.cwd ? path.resolve(task.cwd) : null,
|
|
34
|
+
// The jam's room a run in a jam reaches, and nothing else of the person's threads.
|
|
35
|
+
thread: typeof task.jamThread === "string" ? task.jamThread : null,
|
|
31
36
|
});
|
|
32
37
|
return token;
|
|
33
38
|
};
|
|
@@ -40,22 +45,109 @@ export function runCapability(token) {
|
|
|
40
45
|
return capabilities.get(String(token)) ?? null;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* The capability of the run whose agent process is `pid`, or null: what a call from inside that run is held to when
|
|
50
|
+
* the capability itself did not reach the program that made it (Codex starts its MCP servers with only a few of its
|
|
51
|
+
* environment's variables).
|
|
52
|
+
*/
|
|
53
|
+
export function runCapabilityOfPid(pid) {
|
|
54
|
+
const run = [...children].find(
|
|
55
|
+
([id, child]) => child.pid === pid && !id.startsWith("helper:")
|
|
56
|
+
)?.[0];
|
|
57
|
+
if (!run) return null;
|
|
58
|
+
return [...capabilities.values()].find((entry) => entry.id === run) ?? null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// A run's agent and everything it starts (its shells, test servers, its own subagents) are a process group of their own
|
|
62
|
+
// (a session, on macOS and Linux), so stopping the run stops all of them: signalled to the agent alone, what it started
|
|
63
|
+
// went on working in the folder. Each is asked to end, then made to once the agent has gone or this long has passed.
|
|
64
|
+
const STOP_GRACE_MS = 5_000;
|
|
65
|
+
// The runs going now, kept on disk with when each started: a daemon that stopped without stopping them (killed, or a
|
|
66
|
+
// crash) stops what is left of them when it starts again (stopLeftRuns).
|
|
67
|
+
const runningFile = () => path.join(paths.home, "runs", "running.json");
|
|
68
|
+
const keepRunning = () => {
|
|
69
|
+
const going = [...children]
|
|
70
|
+
.filter(([, child]) => child.ownGroup)
|
|
71
|
+
.map(([runId, child]) => ({
|
|
72
|
+
runId,
|
|
73
|
+
pid: child.pid,
|
|
74
|
+
started: child.started ?? "",
|
|
75
|
+
}));
|
|
76
|
+
try {
|
|
77
|
+
writeJsonAtomic(runningFile(), going);
|
|
78
|
+
} catch {}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const signalGroup = (pid, signal) => {
|
|
82
|
+
if (process.platform === "win32") {
|
|
83
|
+
// No process groups: the whole tree under the agent, forced (Windows has no asking to end).
|
|
84
|
+
spawnSync("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
85
|
+
stdio: "ignore",
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
process.kill(-pid, signal);
|
|
91
|
+
} catch {}
|
|
92
|
+
};
|
|
93
|
+
/** Stops a run's whole process group (one it started as its own: ownGroup); resolves once it was made to end. */
|
|
94
|
+
const stopGroup = (child) =>
|
|
95
|
+
new Promise((resolve) => {
|
|
96
|
+
const force = () => {
|
|
97
|
+
clearTimeout(timer);
|
|
98
|
+
signalGroup(child.pid, "SIGKILL");
|
|
99
|
+
resolve();
|
|
100
|
+
};
|
|
101
|
+
const timer = setTimeout(force, STOP_GRACE_MS);
|
|
102
|
+
if (child.exitCode !== null || child.signalCode !== null) force();
|
|
103
|
+
else child.once("exit", force);
|
|
104
|
+
signalGroup(child.pid, "SIGTERM");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
/** Stops a run in progress (a goal's Stop), and everything it started; its close reports it failed. */
|
|
44
108
|
export function stopAgentTask(runId) {
|
|
45
109
|
const child = children.get(runId);
|
|
46
110
|
if (!child) return false;
|
|
47
|
-
child.
|
|
111
|
+
if (child.ownGroup) void stopGroup(child);
|
|
112
|
+
else child.kill("SIGTERM");
|
|
48
113
|
return true;
|
|
49
114
|
}
|
|
50
115
|
|
|
51
116
|
/**
|
|
52
|
-
* Stops every agent process the relay started, as the daemon shuts down. Without the daemon
|
|
53
|
-
* or reports their end, and they would keep running (and holding memory) with no one waiting
|
|
54
|
-
* treats their turns as interrupted. Runs another app carries out are that app's to end.
|
|
117
|
+
* Stops every agent process the relay started, and what each started, as the daemon shuts down. Without the daemon
|
|
118
|
+
* nothing reads their output or reports their end, and they would keep running (and holding memory) with no one waiting
|
|
119
|
+
* on them; the next daemon treats their turns as interrupted. Runs another app carries out are that app's to end.
|
|
55
120
|
*/
|
|
56
121
|
export function stopAllRuns() {
|
|
57
|
-
|
|
58
|
-
|
|
122
|
+
return Promise.all(
|
|
123
|
+
[...children.values()]
|
|
124
|
+
.filter((child) => !child.external)
|
|
125
|
+
.map((child) =>
|
|
126
|
+
child.ownGroup ? stopGroup(child) : child.kill("SIGTERM")
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* As the daemon starts: what is left of the runs a daemon before it had going and never stopped (it was killed, or
|
|
133
|
+
* crashed). Each is still in its folder, so a new run there would work beside it. A process now under one of their
|
|
134
|
+
* numbers that started at another time is not one of them, and is left alone; on Windows, where that cannot be told,
|
|
135
|
+
* nothing is stopped. Returns the run ids it stopped.
|
|
136
|
+
*/
|
|
137
|
+
export function stopLeftRuns() {
|
|
138
|
+
let left = [];
|
|
139
|
+
try {
|
|
140
|
+
left = JSON.parse(fs.readFileSync(runningFile(), "utf8"));
|
|
141
|
+
} catch {}
|
|
142
|
+
const stopped = [];
|
|
143
|
+
for (const { runId, pid, started } of Array.isArray(left) ? left : []) {
|
|
144
|
+
if (!Number.isInteger(pid) || !started) continue;
|
|
145
|
+
if (processStart(pid) !== started) continue;
|
|
146
|
+
signalGroup(pid, "SIGKILL");
|
|
147
|
+
stopped.push(runId);
|
|
148
|
+
}
|
|
149
|
+
keepRunning();
|
|
150
|
+
return stopped;
|
|
59
151
|
}
|
|
60
152
|
|
|
61
153
|
/** A run another app carries out (T3 Code, t3.mjs): Stop reaches it through `stop`. Returns its release. */
|
|
@@ -165,6 +257,32 @@ const readDenials = (home) =>
|
|
|
165
257
|
? HARNESS_FILES.map((file) => `Read(/${path.join(place, file)})`)
|
|
166
258
|
: [`Read(/${place})`, `Read(/${place}/**)`]
|
|
167
259
|
);
|
|
260
|
+
// One of HARNESS_FILES as a test of a path below Harness's home ("/"-separated): "*" stays within a folder, "**" does not.
|
|
261
|
+
const harnessFilePattern = (glob) => {
|
|
262
|
+
const literal = (text) => text.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
263
|
+
const inFolder = (part) => part.split("*").map(literal).join("[^/]*");
|
|
264
|
+
return new RegExp(`^${glob.split("**").map(inFolder).join(".*")}$`);
|
|
265
|
+
};
|
|
266
|
+
const HARNESS_FILE_PATTERNS = HARNESS_FILES.map(harnessFilePattern);
|
|
267
|
+
const realOrSame = (place) => {
|
|
268
|
+
try {
|
|
269
|
+
return fs.realpathSync(place);
|
|
270
|
+
} catch {
|
|
271
|
+
return path.resolve(place);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* Whether a file is one a run's own sandbox keeps it from reading (the places readDenials names), so a run cannot get
|
|
276
|
+
* the daemon to read it instead. `file` is a real path: symlinks resolved, so a link in the run's folder is no way in.
|
|
277
|
+
*/
|
|
278
|
+
export const deniedToRuns = (file, home = os.homedir()) =>
|
|
279
|
+
secretPlaces(home).some((place) => {
|
|
280
|
+
const below = path.relative(realOrSame(place), file);
|
|
281
|
+
if (below.startsWith("..") || path.isAbsolute(below)) return false;
|
|
282
|
+
if (place !== paths.home) return true;
|
|
283
|
+
const relative = below.split(path.sep).join("/");
|
|
284
|
+
return HARNESS_FILE_PATTERNS.some((pattern) => pattern.test(relative));
|
|
285
|
+
});
|
|
168
286
|
// A run nobody pressed Start on reads only its own folder (owner, October 31: "nothing outside that without the consent
|
|
169
287
|
// of the user"). Denied: every home folder and the drives and shares mounted from outside, where people keep their
|
|
170
288
|
// files. Still readable: the operating system's own folders, the programs a run builds and tests with, git's settings,
|
|
@@ -285,6 +403,20 @@ const confinedDenials = (cwd, home, confined) =>
|
|
|
285
403
|
])
|
|
286
404
|
: [];
|
|
287
405
|
|
|
406
|
+
// A run held to its folder names every entry beside the path to it, and one folder with thousands of entries made the
|
|
407
|
+
// settings too long to start the run at all (spawn E2BIG; Linux allows one argument 128 KB). Claude Code takes a file too.
|
|
408
|
+
const LONGEST_SETTINGS_ON_THE_LINE = 64 * 1024;
|
|
409
|
+
const settingsArgument = (settings) => {
|
|
410
|
+
const text = JSON.stringify(settings);
|
|
411
|
+
if (text.length <= LONGEST_SETTINGS_ON_THE_LINE) return text;
|
|
412
|
+
const folder = path.join(paths.home, "run-settings");
|
|
413
|
+
fs.mkdirSync(folder, { recursive: true, mode: 0o700 });
|
|
414
|
+
const name = createHash("sha256").update(text).digest("hex");
|
|
415
|
+
const file = path.join(folder, `${name}.json`);
|
|
416
|
+
fs.writeFileSync(file, text, { mode: 0o600 });
|
|
417
|
+
return file;
|
|
418
|
+
};
|
|
419
|
+
|
|
288
420
|
// A run another agent started without the person's tap (docs/member-runs.md): anything that would ask is refused, file
|
|
289
421
|
// edits only in its worktree, shell commands only inside the operating system's sandbox with no network, nothing read
|
|
290
422
|
// where the person keeps credentials, and no hooks or settings from the repository. A review gets no edits at all.
|
|
@@ -330,7 +462,7 @@ const restrictedClaude = (task) => [
|
|
|
330
462
|
"--setting-sources",
|
|
331
463
|
"user",
|
|
332
464
|
"--settings",
|
|
333
|
-
|
|
465
|
+
settingsArgument({
|
|
334
466
|
...restrictedClaudeSettings(task.cwd),
|
|
335
467
|
...modelWindow(task),
|
|
336
468
|
}),
|
|
@@ -361,7 +493,7 @@ const MODEL_FLAGS = {
|
|
|
361
493
|
// Pi keeps each session in `<sessions>/<project>/<time>_<id>.jsonl`. Given only an id, Pi asks on the terminal whether
|
|
362
494
|
// to fork a session from another folder, and a non-interactive run cannot answer; given the file, it opens it. With
|
|
363
495
|
// no file, the run starts a new session: an id Pi can't find ends the run.
|
|
364
|
-
const piSessionFile = (sessionId) => {
|
|
496
|
+
export const piSessionFile = (sessionId) => {
|
|
365
497
|
const name = `_${sessionId}.jsonl`;
|
|
366
498
|
for (const root of historyRoots("pi")) {
|
|
367
499
|
let projects = [];
|
|
@@ -442,12 +574,41 @@ const readOnlyClaude = (task) => [
|
|
|
442
574
|
"--setting-sources",
|
|
443
575
|
"user",
|
|
444
576
|
"--settings",
|
|
445
|
-
|
|
577
|
+
settingsArgument({
|
|
446
578
|
...readOnlyClaudeSettings(task.cwd, os.homedir(), task.restricted === true),
|
|
447
579
|
...modelWindow(task),
|
|
448
580
|
}),
|
|
449
581
|
];
|
|
450
582
|
|
|
583
|
+
// On Linux, Codex's sandbox (bubblewrap) mounts an empty folder nothing can enter over a denied folder (Codex 0.164,
|
|
584
|
+
// linux-sandbox/src/bwrap.rs), so nothing allowed beneath it can be reached, and it cannot mount over a link. Codex's
|
|
585
|
+
// helper is a link in ~/.codex/tmp/arg0-linux to Codex itself, which a standalone install keeps in ~/.codex too, so
|
|
586
|
+
// denying that whole folder stopped every session before it started. Each entry beside what stays open is denied
|
|
587
|
+
// instead, and a link as what it points to.
|
|
588
|
+
const denyBeside = (place, opened, root = place) => {
|
|
589
|
+
const found = fs.lstatSync(place, { throwIfNoEntry: false });
|
|
590
|
+
if (!found) return [place];
|
|
591
|
+
if (found.isSymbolicLink()) {
|
|
592
|
+
const target = fs.existsSync(place) ? fs.realpathSync(place) : null;
|
|
593
|
+
return target && !within(target, root)
|
|
594
|
+
? denyBeside(target, opened, target)
|
|
595
|
+
: [];
|
|
596
|
+
}
|
|
597
|
+
if (opened.some((open) => within(place, open))) return [];
|
|
598
|
+
if (!opened.some((open) => within(open, place))) return [place];
|
|
599
|
+
return fs
|
|
600
|
+
.readdirSync(place)
|
|
601
|
+
.flatMap((entry) => denyBeside(path.join(place, entry), opened, root));
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
// A place inside a denied one is denied already, and bubblewrap cannot mount inside that empty folder: a link in the home
|
|
605
|
+
// folder to a file in another denied folder (~/.steampid, Steam's) stopped every restricted run on the owner's Linux.
|
|
606
|
+
const outermost = (places) =>
|
|
607
|
+
[...new Set(places)].filter(
|
|
608
|
+
(place, _, all) =>
|
|
609
|
+
!all.some((other) => other !== place && within(place, other))
|
|
610
|
+
);
|
|
611
|
+
|
|
451
612
|
// Codex's review: its read-only permission profile, with the same places denied to every command it runs (the run's
|
|
452
613
|
// own folder stays readable when it lies inside one) and no web search. Probed with `codex sandbox` 0.164: a denied
|
|
453
614
|
// file is "Operation not permitted", the folder reads, writes and the daemon's socket are refused. A restricted run
|
|
@@ -457,19 +618,27 @@ const readOnlyClaude = (task) => [
|
|
|
457
618
|
// under a denied home stay readable.
|
|
458
619
|
const codexReview = (task, executable, home = os.homedir(), write = false) => {
|
|
459
620
|
const confined = write || task.restricted === true;
|
|
460
|
-
const
|
|
461
|
-
(confined ?
|
|
462
|
-
|
|
463
|
-
)
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
621
|
+
const reads = [
|
|
622
|
+
...(confined ? confinedReads(task.cwd, home, "codex") : []),
|
|
623
|
+
path.join(home, ".codex", "shell_snapshots"),
|
|
624
|
+
...(task.cwd ? [task.cwd] : []),
|
|
625
|
+
// Standalone Codex lives inside its denied credential home and reexecutes
|
|
626
|
+
// itself to load AGENTS.md. Only its confirmed, resolved file needs access.
|
|
627
|
+
...(executable ? [executable] : []),
|
|
628
|
+
...(process.platform === "linux"
|
|
629
|
+
? [path.join(home, ".codex", "tmp", "arg0-linux")]
|
|
630
|
+
: []),
|
|
631
|
+
];
|
|
632
|
+
const denied = confined
|
|
633
|
+
? fencedPlaces(task.cwd, home, "codex")
|
|
634
|
+
: secretPlaces(home);
|
|
635
|
+
const denials =
|
|
636
|
+
process.platform === "linux"
|
|
637
|
+
? outermost(denied.flatMap((place) => denyBeside(place, reads)))
|
|
638
|
+
: denied;
|
|
639
|
+
const places = Object.fromEntries(denials.map((place) => [place, "deny"]));
|
|
640
|
+
for (const place of reads) places[place] = "read";
|
|
469
641
|
if (task.cwd) places[task.cwd] = write ? "write" : "read";
|
|
470
|
-
// Standalone Codex lives inside its denied credential home and reexecutes
|
|
471
|
-
// itself to load AGENTS.md. Only its confirmed, resolved file needs access.
|
|
472
|
-
if (executable) places[executable] = "read";
|
|
473
642
|
const table = Object.entries(places)
|
|
474
643
|
.map(
|
|
475
644
|
([place, access]) => `${JSON.stringify(place)}=${JSON.stringify(access)}`
|
|
@@ -636,9 +805,10 @@ export function usageCollector() {
|
|
|
636
805
|
};
|
|
637
806
|
return {
|
|
638
807
|
read(event) {
|
|
639
|
-
// Claude Code: one result event carries the run's
|
|
808
|
+
// Claude Code: one result event carries the run's tokens and its session's dollars so far (runUsage.mjs).
|
|
640
809
|
if (event.type === "result" && event.usage) {
|
|
641
810
|
const u = event.usage;
|
|
811
|
+
const cost = Number(event.total_cost_usd);
|
|
642
812
|
add(
|
|
643
813
|
{
|
|
644
814
|
input: u.input_tokens,
|
|
@@ -646,22 +816,26 @@ export function usageCollector() {
|
|
|
646
816
|
cacheRead: u.cache_read_input_tokens,
|
|
647
817
|
cacheWrite: u.cache_creation_input_tokens,
|
|
648
818
|
},
|
|
649
|
-
|
|
819
|
+
cost
|
|
650
820
|
);
|
|
821
|
+
if (Number.isFinite(cost)) usage.session_totals = { cost_usd: cost };
|
|
651
822
|
return;
|
|
652
823
|
}
|
|
653
|
-
// Codex:
|
|
824
|
+
// Codex: a completed turn carries its session's tokens so far (runUsage.mjs), its input with the cached tokens
|
|
825
|
+
// inside it. Input here means tokens not served from the cache, as every other agent reports it.
|
|
654
826
|
if (event.type === "turn.completed" && event.usage) {
|
|
655
827
|
const u = event.usage;
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
828
|
+
const cached = Number(u.cached_input_tokens) || 0;
|
|
829
|
+
const totals = {
|
|
830
|
+
input_tokens: (Number(u.input_tokens) || 0) - cached,
|
|
831
|
+
output_tokens: Number(u.output_tokens) || 0,
|
|
832
|
+
cache_read_tokens: cached,
|
|
833
|
+
cache_write_tokens: Number(u.cache_write_input_tokens) || 0,
|
|
834
|
+
};
|
|
835
|
+
Object.assign(usage, totals, {
|
|
836
|
+
reported: true,
|
|
837
|
+
session_totals: totals,
|
|
838
|
+
});
|
|
665
839
|
return;
|
|
666
840
|
}
|
|
667
841
|
// Pi: each finished assistant message carries its usage and price.
|
|
@@ -796,6 +970,56 @@ export function stepsOf(event) {
|
|
|
796
970
|
return [];
|
|
797
971
|
}
|
|
798
972
|
|
|
973
|
+
// What going in circles is read from (circling.mjs), apart from the steps the person reads: the shell command a tool
|
|
974
|
+
// call runs, or the file an edit tool changes. Claude Code, Pi and OpenCode name their tools this way; Codex says each
|
|
975
|
+
// in an item of its own.
|
|
976
|
+
const SHELL_TOOLS = new Set(["bash", "shell"]);
|
|
977
|
+
const EDIT_TOOLS = new Set(["edit", "write", "multiedit", "notebookedit"]);
|
|
978
|
+
const actOf = (name, input) => {
|
|
979
|
+
if (!input || typeof input !== "object") return [];
|
|
980
|
+
const tool = String(name ?? "").toLowerCase();
|
|
981
|
+
if (SHELL_TOOLS.has(tool) && typeof input.command === "string")
|
|
982
|
+
return [{ command: input.command }];
|
|
983
|
+
const file =
|
|
984
|
+
input.file_path ?? input.filePath ?? input.notebook_path ?? input.path;
|
|
985
|
+
return EDIT_TOOLS.has(tool) && typeof file === "string"
|
|
986
|
+
? [{ files: [file] }]
|
|
987
|
+
: [];
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
/** The commands one event of an agent's JSON stream ran and the files it changed: `{ command }` or `{ files }`. */
|
|
991
|
+
export function actsOf(event) {
|
|
992
|
+
if (!event || typeof event !== "object") return [];
|
|
993
|
+
if (event.type === "assistant" && Array.isArray(event.message?.content))
|
|
994
|
+
return event.message.content.flatMap((block) =>
|
|
995
|
+
block.type === "tool_use" ? actOf(block.name, block.input) : []
|
|
996
|
+
);
|
|
997
|
+
if (event.type === "item.completed" && event.item) {
|
|
998
|
+
const item = event.item;
|
|
999
|
+
if (item.type === "command_execution" && item.command)
|
|
1000
|
+
return [{ command: String(item.command) }];
|
|
1001
|
+
if (item.type === "file_change") {
|
|
1002
|
+
const files = (item.changes ?? [])
|
|
1003
|
+
.map((change) => change?.path)
|
|
1004
|
+
.filter((file) => typeof file === "string" && file);
|
|
1005
|
+
return files.length ? [{ files }] : [];
|
|
1006
|
+
}
|
|
1007
|
+
return [];
|
|
1008
|
+
}
|
|
1009
|
+
if (
|
|
1010
|
+
event.type === "message_end" &&
|
|
1011
|
+
event.message?.role === "assistant" &&
|
|
1012
|
+
Array.isArray(event.message.content)
|
|
1013
|
+
)
|
|
1014
|
+
return event.message.content.flatMap((block) =>
|
|
1015
|
+
block.type === "toolCall" ? actOf(block.name, block.arguments) : []
|
|
1016
|
+
);
|
|
1017
|
+
const part = event.part;
|
|
1018
|
+
if (part?.type === "tool" && part.state?.status === "completed")
|
|
1019
|
+
return actOf(part.tool, part.state.input);
|
|
1020
|
+
return [];
|
|
1021
|
+
}
|
|
1022
|
+
|
|
799
1023
|
/** The steps of a run from its log, oldest first; at most `limit`, the latest kept. */
|
|
800
1024
|
export function readRunSteps(file, limit = 200) {
|
|
801
1025
|
let raw = "";
|
|
@@ -822,7 +1046,7 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
822
1046
|
// One run per agent per folder: an agent's session there is one; other agents work beside it, as the person runs them
|
|
823
1047
|
// (runWorker.mjs slotOf). A read-only review edits nothing, so it goes beside whoever writes there.
|
|
824
1048
|
const slot = task.readOnly
|
|
825
|
-
? `review:${task.agent}:${task.
|
|
1049
|
+
? `review:${task.agent}:${task.runId}`
|
|
826
1050
|
: task.cwd
|
|
827
1051
|
? `${path.resolve(task.cwd)}:${task.agent}`
|
|
828
1052
|
: task.agent;
|
|
@@ -896,7 +1120,7 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
896
1120
|
// Seatbelt checks symlink traversal too: invoke the same exact file granted
|
|
897
1121
|
// to the review helper, without exposing its installation directory.
|
|
898
1122
|
invocation =
|
|
899
|
-
task.agent === "codex" && task.readOnly
|
|
1123
|
+
task.agent === "codex" && (task.readOnly || task.restricted)
|
|
900
1124
|
? agentInvocation(task, { executable: fs.realpathSync(program) })
|
|
901
1125
|
: { ...invocation, command: program };
|
|
902
1126
|
} catch (error) {
|
|
@@ -910,6 +1134,8 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
910
1134
|
child = spawn(invocation.command, invocation.args, {
|
|
911
1135
|
cwd,
|
|
912
1136
|
env: environment.env,
|
|
1137
|
+
// Its own process group, so a stop reaches everything it starts (stopGroup).
|
|
1138
|
+
detached: process.platform !== "win32",
|
|
913
1139
|
});
|
|
914
1140
|
// An agent that exits before reading its brief breaks the pipe; its exit says how the run went.
|
|
915
1141
|
child.stdin.on("error", () => {});
|
|
@@ -924,6 +1150,9 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
924
1150
|
}
|
|
925
1151
|
running.add(slot);
|
|
926
1152
|
children.set(task.runId, child);
|
|
1153
|
+
child.ownGroup = Boolean(child.pid);
|
|
1154
|
+
child.started = child.pid ? processStart(child.pid) : "";
|
|
1155
|
+
keepRunning();
|
|
927
1156
|
|
|
928
1157
|
let resultText = "";
|
|
929
1158
|
// A run with secrets in its environment (vault.mjs): its words are cleaned of them before anything is cut short, so
|
|
@@ -997,6 +1226,10 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
997
1226
|
emit("progress", clean(step.text).slice(0, 200), {
|
|
998
1227
|
step: { ...step, text: clean(step.text) },
|
|
999
1228
|
});
|
|
1229
|
+
for (const act of actsOf(event))
|
|
1230
|
+
hooks.acted?.(
|
|
1231
|
+
act.command ? { command: clean(act.command).slice(0, 2_000) } : act
|
|
1232
|
+
);
|
|
1000
1233
|
}
|
|
1001
1234
|
});
|
|
1002
1235
|
child.stderr?.on("data", (chunk) => {
|
|
@@ -1004,9 +1237,14 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
1004
1237
|
observe("stderr", raw);
|
|
1005
1238
|
tail = clean(tail + "\n" + raw).slice(-4_000);
|
|
1006
1239
|
});
|
|
1240
|
+
// A program that cannot start emits "error" and then "close": one run ends once.
|
|
1241
|
+
let ended = false;
|
|
1007
1242
|
child.on("close", (code) => {
|
|
1243
|
+
if (ended) return;
|
|
1244
|
+
ended = true;
|
|
1008
1245
|
running.delete(slot);
|
|
1009
1246
|
children.delete(task.runId);
|
|
1247
|
+
keepRunning();
|
|
1010
1248
|
capabilities.delete(capability);
|
|
1011
1249
|
if (code === 0 && modelError)
|
|
1012
1250
|
emit(
|
|
@@ -1016,16 +1254,19 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
1016
1254
|
).slice(0, 4_000),
|
|
1017
1255
|
{ usage: usage.result(), failure: "exit" }
|
|
1018
1256
|
);
|
|
1019
|
-
else if (code === 0)
|
|
1257
|
+
else if (code === 0) {
|
|
1258
|
+
const said = clean(resultText);
|
|
1020
1259
|
emit(
|
|
1021
1260
|
"done",
|
|
1022
|
-
(
|
|
1023
|
-
|
|
1024
|
-
"The run finished; check the repository for its changes."
|
|
1025
|
-
|
|
1026
|
-
|
|
1261
|
+
// Cut from the end, but its closing "Next:" line stays: it is what the agent means to do next (nextStep.mjs).
|
|
1262
|
+
cutKeepingNextStep(
|
|
1263
|
+
said || "The run finished; check the repository for its changes.",
|
|
1264
|
+
20_000
|
|
1265
|
+
),
|
|
1266
|
+
// With nothing written, a turn that ended to wait says so instead (runWorker.mjs).
|
|
1267
|
+
{ usage: usage.result(), ...(said ? {} : { nothingSaid: true }) }
|
|
1027
1268
|
);
|
|
1028
|
-
else
|
|
1269
|
+
} else
|
|
1029
1270
|
emit(
|
|
1030
1271
|
"failed",
|
|
1031
1272
|
`${task.agent} exited with code ${code}.\n${tail}`.slice(0, 4_000),
|
|
@@ -1033,8 +1274,11 @@ export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
|
|
|
1033
1274
|
);
|
|
1034
1275
|
});
|
|
1035
1276
|
child.on("error", (error) => {
|
|
1277
|
+
if (ended) return;
|
|
1278
|
+
ended = true;
|
|
1036
1279
|
running.delete(slot);
|
|
1037
1280
|
children.delete(task.runId);
|
|
1281
|
+
keepRunning();
|
|
1038
1282
|
capabilities.delete(capability);
|
|
1039
1283
|
emit("failed", `Could not start ${task.agent}: ${error.message}`, {
|
|
1040
1284
|
failure: "start",
|
package/lib/runtime-install.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
|
|
7
|
-
import { harnessNode, paths } from "./paths.mjs";
|
|
7
|
+
import { currentRuntimeLink, harnessNode, paths } from "./paths.mjs";
|
|
8
8
|
import {
|
|
9
9
|
RELEASE_ENTRIES,
|
|
10
10
|
RELEASE_FILE,
|
|
@@ -156,14 +156,25 @@ export function installRuntime({ sourceRoot, version, allowUnsigned = false }) {
|
|
|
156
156
|
throw refuse(version, reason);
|
|
157
157
|
}
|
|
158
158
|
if (allowUnsigned) fs.writeFileSync(path.join(staging, LOCAL_BUILD), "");
|
|
159
|
-
// Everything the package depends on, so a dependency added there cannot be left out here
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
// Everything the package depends on, so a dependency added there cannot be left out here; and the Linux senses
|
|
160
|
+
// program npm installed for this chip (an optional dependency, there only where its os and cpu match).
|
|
161
|
+
const manifest = readJson(path.join(sourceRoot, "package.json"), {});
|
|
162
|
+
const fromSource = createRequire(path.join(sourceRoot, "package.json"));
|
|
163
|
+
const senses = Object.keys(manifest.optionalDependencies || {}).filter(
|
|
164
|
+
(name) => {
|
|
165
|
+
if (!name.startsWith("tryharness-senses-")) return false;
|
|
166
|
+
try {
|
|
167
|
+
fromSource.resolve(`${name}/package.json`);
|
|
168
|
+
return true;
|
|
169
|
+
} catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
166
173
|
);
|
|
174
|
+
copyDependencyClosure(sourceRoot, staging, [
|
|
175
|
+
...Object.keys(manifest.dependencies || {}),
|
|
176
|
+
...senses,
|
|
177
|
+
]);
|
|
167
178
|
fs.writeFileSync(path.join(staging, ".ready"), version + "\n", {
|
|
168
179
|
mode: 0o600,
|
|
169
180
|
});
|
|
@@ -175,10 +186,28 @@ export function installRuntime({ sourceRoot, version, allowUnsigned = false }) {
|
|
|
175
186
|
version,
|
|
176
187
|
path: release,
|
|
177
188
|
});
|
|
189
|
+
linkCurrent(release);
|
|
178
190
|
writeLauncher(release);
|
|
179
191
|
return release;
|
|
180
192
|
}
|
|
181
193
|
|
|
194
|
+
// The installed release under one name that stays the same across updates: what an agent's hooks run (paths.mjs
|
|
195
|
+
// stableRuntimeRoot). Codex asks the person to approve a hook again whenever its command changes, so a command naming
|
|
196
|
+
// the version would be asked about after every update (owner, November 13: "yes 100% shouodl do this"). Replaced in one
|
|
197
|
+
// rename, so a hook never finds it missing. Not on Windows, where a link needs rights a person may not have.
|
|
198
|
+
function linkCurrent(release) {
|
|
199
|
+
if (process.platform === "win32") return;
|
|
200
|
+
const link = currentRuntimeLink();
|
|
201
|
+
const aside = `${link}.${process.pid}`;
|
|
202
|
+
try {
|
|
203
|
+
fs.rmSync(aside, { force: true });
|
|
204
|
+
fs.symlinkSync(release, aside, "dir");
|
|
205
|
+
fs.renameSync(aside, link);
|
|
206
|
+
} catch {
|
|
207
|
+
fs.rmSync(aside, { force: true });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
182
211
|
export function currentRuntime() {
|
|
183
212
|
const current = readJson(path.join(paths.runtime, "current.json"), {});
|
|
184
213
|
return typeof current.path === "string" && fs.existsSync(current.path)
|