pacework 1.7.0 → 1.7.1
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/bin/pacework-runner.mjs +15 -0
- package/lib/capabilities.mjs +58 -0
- package/lib/run-limits.mjs +43 -5
- package/package.json +1 -1
package/bin/pacework-runner.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import process from "node:process"
|
|
|
9
9
|
import { spawn, execFileSync } from "node:child_process"
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks"
|
|
11
11
|
import { createLogger } from "../lib/logger.mjs"
|
|
12
|
+
import { detectCapabilities, detectPower } from "../lib/capabilities.mjs"
|
|
12
13
|
import { detectRunUsageLimit, USAGE_LIMIT_MARKER } from "../lib/usage-limit.mjs"
|
|
13
14
|
import {
|
|
14
15
|
buildImpactReport,
|
|
@@ -967,6 +968,7 @@ async function registerRunner() {
|
|
|
967
968
|
max_parallel_runs: maxParallelRuns,
|
|
968
969
|
...(homeTeam ? { home_team: homeTeam } : {}),
|
|
969
970
|
...(availabilityMode ? { availability_mode: availabilityMode } : {}),
|
|
971
|
+
capabilities: runnerCapabilities(),
|
|
970
972
|
}),
|
|
971
973
|
})
|
|
972
974
|
|
|
@@ -1015,6 +1017,18 @@ async function ensureRegisteredRunner() {
|
|
|
1015
1017
|
return registerRunner()
|
|
1016
1018
|
}
|
|
1017
1019
|
|
|
1020
|
+
// Which repositories and tools this machine has (PWK-297). Re-checked every few
|
|
1021
|
+
// minutes, so a newly added remote or a started Docker shows up without a restart.
|
|
1022
|
+
let capabilitiesCache = null
|
|
1023
|
+
function runnerCapabilities() {
|
|
1024
|
+
if (!capabilitiesCache || Date.now() - capabilitiesCache.at > 5 * 60_000) {
|
|
1025
|
+
capabilitiesCache = { at: Date.now(), value: detectCapabilities({ repoRoot, executors: installedExecutors }) }
|
|
1026
|
+
}
|
|
1027
|
+
// Power changes often (unplugging a laptop); it's cheap to read every heartbeat.
|
|
1028
|
+
const power = detectPower()
|
|
1029
|
+
return power ? { ...capabilitiesCache.value, power } : capabilitiesCache.value
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1018
1032
|
async function heartbeat(state, status = "online") {
|
|
1019
1033
|
return requestJson(`${appUrl}/api/agent-runners/heartbeat`, {
|
|
1020
1034
|
method: "POST",
|
|
@@ -1027,6 +1041,7 @@ async function heartbeat(state, status = "online") {
|
|
|
1027
1041
|
runner_id: state.runner_id,
|
|
1028
1042
|
status,
|
|
1029
1043
|
local_executors: installedExecutors,
|
|
1044
|
+
capabilities: runnerCapabilities(),
|
|
1030
1045
|
}),
|
|
1031
1046
|
})
|
|
1032
1047
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What this machine can work on (PWK-297), reported when the runner registers and
|
|
5
|
+
* on every heartbeat. The server only gives it issues for repositories it has.
|
|
6
|
+
* Anything not detected is left out, which the server reads as "unknown, eligible".
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** "owner/name" (lower case) from a GitHub remote URL, or null for anything else. */
|
|
10
|
+
export function repoFromRemoteUrl(url) {
|
|
11
|
+
const match = String(url ?? "").trim().match(/github\.com[:/]+([^/\s]+)\/([^/\s]+?)(?:\.git)?\/?$/i)
|
|
12
|
+
return match ? `${match[1]}/${match[2]}`.toLowerCase() : null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function run(command, args, options = {}) {
|
|
16
|
+
try {
|
|
17
|
+
return execFileSync(command, args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 4000, ...options }).trim()
|
|
18
|
+
} catch {
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** "ac" or "battery" on macOS (pmset); null where it can't tell. For "help only on power" (PWK-300). */
|
|
24
|
+
export function detectPower(exec = run) {
|
|
25
|
+
const out = exec("pmset", ["-g", "batt"])
|
|
26
|
+
if (!out) return null
|
|
27
|
+
if (/AC Power/i.test(out)) return "ac"
|
|
28
|
+
if (/Battery Power/i.test(out)) return "battery"
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Whether this machine can run an agent inside its AI tool's own OS sandbox
|
|
34
|
+
* (Seatbelt on macOS, bubblewrap on Linux; Claude Code and Codex). Teams that
|
|
35
|
+
* require sandboxed helpers only get such runners (PWK-295). No Docker needed,
|
|
36
|
+
* and the tool keeps using the machine's own login.
|
|
37
|
+
*/
|
|
38
|
+
export function canSandbox({ platform = process.platform, executors = [], exec = run } = {}) {
|
|
39
|
+
if (!executors.some((executor) => executor === "claude_code" || executor === "codex")) return false
|
|
40
|
+
if (platform === "darwin") return true
|
|
41
|
+
if (platform === "linux") return Boolean(exec("bwrap", ["--version"]))
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function detectCapabilities({ repoRoot, executors = [], exec = run, platform = process.platform } = {}) {
|
|
46
|
+
const capabilities = {}
|
|
47
|
+
const remotes = (exec("git", ["-C", repoRoot, "remote", "-v"]) ?? "")
|
|
48
|
+
.split("\n")
|
|
49
|
+
.map((line) => repoFromRemoteUrl(line.split(/\s+/)[1]))
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
// Only when a GitHub repo was found: an empty list would mean "can't do any repo".
|
|
52
|
+
if (remotes.length) capabilities.repos = [...new Set(remotes)]
|
|
53
|
+
const tools = []
|
|
54
|
+
if (exec("docker", ["version", "--format", "{{.Server.Version}}"])) tools.push("docker")
|
|
55
|
+
if (canSandbox({ platform, executors, exec })) tools.push("sandbox")
|
|
56
|
+
capabilities.tools = tools
|
|
57
|
+
return capabilities
|
|
58
|
+
}
|
package/lib/run-limits.mjs
CHANGED
|
@@ -142,6 +142,44 @@ export function tripwireHeadline(stop) {
|
|
|
142
142
|
return `${TRIPWIRE_MARKER}: the run was stopped at its ${what} limit because ${stop.reason}.`
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Folders that hold installed dependencies, package stores and build caches.
|
|
147
|
+
* An install inside the checkout (a pnpm store when the home folder is on
|
|
148
|
+
* another volume, a Python virtualenv, a node_modules a repo forgot to ignore)
|
|
149
|
+
* writes tens of thousands of files that are not the agent's work. They do not
|
|
150
|
+
* count toward the file limit and are never committed as a stopped run's work.
|
|
151
|
+
*/
|
|
152
|
+
export const DEPENDENCY_DIRS = Object.freeze([
|
|
153
|
+
"node_modules",
|
|
154
|
+
".pnpm-store",
|
|
155
|
+
".npm",
|
|
156
|
+
".bun",
|
|
157
|
+
".venv",
|
|
158
|
+
"venv",
|
|
159
|
+
"__pycache__",
|
|
160
|
+
".gradle",
|
|
161
|
+
".m2",
|
|
162
|
+
".cargo",
|
|
163
|
+
".turbo",
|
|
164
|
+
".next",
|
|
165
|
+
".cache",
|
|
166
|
+
])
|
|
167
|
+
|
|
168
|
+
const DEPENDENCY_DIR_SET = new Set(DEPENDENCY_DIRS)
|
|
169
|
+
|
|
170
|
+
/** Whether a repo-relative path lies inside one of DEPENDENCY_DIRS. */
|
|
171
|
+
export function isDependencyPath(file) {
|
|
172
|
+
const parts = String(file || "").split("/")
|
|
173
|
+
// The last part is the file itself; only its folders matter.
|
|
174
|
+
return parts.slice(0, -1).some((part) => DEPENDENCY_DIR_SET.has(part))
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Pathspecs that keep git from listing or adding anything in DEPENDENCY_DIRS. */
|
|
178
|
+
export const DEPENDENCY_PATHSPEC_EXCLUDES = Object.freeze([
|
|
179
|
+
".",
|
|
180
|
+
...DEPENDENCY_DIRS.map((dir) => `:(exclude,glob)**/${dir}/**`),
|
|
181
|
+
])
|
|
182
|
+
|
|
145
183
|
/**
|
|
146
184
|
* The files a run has changed, from `git status --porcelain --untracked-files=all`
|
|
147
185
|
* and `git diff --name-only` against where the run started. Counting from the
|
|
@@ -160,7 +198,7 @@ export function parseChangedFiles(porcelain, diffNames = "") {
|
|
|
160
198
|
if (line.trim()) files.add(line.trim())
|
|
161
199
|
}
|
|
162
200
|
files.delete("")
|
|
163
|
-
return [...files].sort()
|
|
201
|
+
return [...files].filter((file) => !isDependencyPath(file)).sort()
|
|
164
202
|
}
|
|
165
203
|
|
|
166
204
|
const REPORT_FILE_LIST_MAX = 30
|
|
@@ -259,8 +297,8 @@ function git(cwd, args, onError) {
|
|
|
259
297
|
|
|
260
298
|
/** The files a run changed since `startSha`, committed or not, untracked included. */
|
|
261
299
|
export async function listRunChangedFiles(worktreePath, startSha) {
|
|
262
|
-
const status = await git(worktreePath, ["status", "--porcelain", "--untracked-files=all"])
|
|
263
|
-
const diff = startSha ? await git(worktreePath, ["diff", "--name-only", startSha]) : null
|
|
300
|
+
const status = await git(worktreePath, ["status", "--porcelain", "--untracked-files=all", "--", ...DEPENDENCY_PATHSPEC_EXCLUDES])
|
|
301
|
+
const diff = startSha ? await git(worktreePath, ["diff", "--name-only", startSha, "--", ...DEPENDENCY_PATHSPEC_EXCLUDES]) : null
|
|
264
302
|
return parseChangedFiles(status, diff)
|
|
265
303
|
}
|
|
266
304
|
|
|
@@ -272,11 +310,11 @@ export async function listRunChangedFiles(worktreePath, startSha) {
|
|
|
272
310
|
* `committed` is false with no error when there was nothing to commit.
|
|
273
311
|
*/
|
|
274
312
|
export async function commitStoppedWork(worktreePath, { subject, body }) {
|
|
275
|
-
const dirty = (await git(worktreePath, ["status", "--porcelain"]))?.trim()
|
|
313
|
+
const dirty = (await git(worktreePath, ["status", "--porcelain", "--", ...DEPENDENCY_PATHSPEC_EXCLUDES]))?.trim()
|
|
276
314
|
if (!dirty) return { committed: false, sha: null, error: null }
|
|
277
315
|
let error = null
|
|
278
316
|
const onError = (message) => { error = message.replace(/\s+/g, " ").slice(0, 200) }
|
|
279
|
-
const added = await git(worktreePath, ["add", "-A"], onError)
|
|
317
|
+
const added = await git(worktreePath, ["add", "-A", "--", ...DEPENDENCY_PATHSPEC_EXCLUDES], onError)
|
|
280
318
|
const done = added !== null
|
|
281
319
|
&& await git(worktreePath, ["commit", "--no-verify", "-m", subject, "-m", body, "-m", STOPPED_BY_TRIPWIRE_TRAILER], onError) !== null
|
|
282
320
|
if (!done) return { committed: false, sha: null, error: error || "git commit failed" }
|