pacework 1.6.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-ctl.mjs +14 -2
- package/bin/pacework-runner.mjs +30 -1
- package/lib/capabilities.mjs +58 -0
- package/lib/run-limits.mjs +43 -5
- package/lib/runner-control.mjs +6 -0
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ import os from "node:os"
|
|
|
13
13
|
import path from "node:path"
|
|
14
14
|
import process from "node:process"
|
|
15
15
|
import readline from "node:readline"
|
|
16
|
+
import { AVAILABILITY_MODES } from "../lib/runner-control.mjs"
|
|
16
17
|
import { spawn, execFileSync, execSync } from "node:child_process"
|
|
17
18
|
import { fileURLToPath } from "node:url"
|
|
18
19
|
import { agentSecretsFrom, detectSetupCommand } from "../lib/environment.mjs"
|
|
@@ -273,7 +274,7 @@ ${row("pacework logs [--lines N]", "Follow its log")}
|
|
|
273
274
|
${row("pacework connect", "Run it in this terminal instead")}
|
|
274
275
|
${row("pacework use <tool>", `Switch AI tool: ${d("claude_code, codex, gemini, cursor_agent, github_copilot")}`)}
|
|
275
276
|
${row("pacework settings", "Change the AI tool, model, folder, parallel jobs, triage, sandbox or name")}
|
|
276
|
-
${row("pacework config [key] [value]", `The same from scripts: ${d("max-parallel-runs, triage, sandbox, model, …")}`)}
|
|
277
|
+
${row("pacework config [key] [value]", `The same from scripts: ${d("max-parallel-runs, triage, sandbox, model, team, mode, …")}`)}
|
|
277
278
|
${row("pacework doctor", "Check this machine's setup")}
|
|
278
279
|
${row("pacework triage [--once]", "Only triage, in the foreground")}
|
|
279
280
|
${row("pacework up --token CODE", "One-step setup from the command in pacework's Runners page; asks for the runner's name and model")}
|
|
@@ -281,6 +282,7 @@ ${row("pacework down", "Remove the background service")}
|
|
|
281
282
|
|
|
282
283
|
\x1b[1mRunner flags\x1b[0m ${d("for start, connect and up")}
|
|
283
284
|
--repo-root PATH --executor TOOL --name NAME --model ID --max-parallel-runs N --sandbox --no-triage
|
|
285
|
+
--team KEY --mode only_mine|my_team|help_when_idle|anyone ${d("which work this runner takes; default: anyone")}
|
|
284
286
|
${d("--model: empty for the tool's latest default; Claude Code also takes opus, sonnet or haiku for the newest of each")}
|
|
285
287
|
`)
|
|
286
288
|
process.exit(0)
|
|
@@ -500,12 +502,15 @@ if (command === "config") {
|
|
|
500
502
|
"max-parallel-runs": "maxParallelRuns",
|
|
501
503
|
"triage": "triage",
|
|
502
504
|
"sandbox": "sandbox",
|
|
505
|
+
"team": "homeTeam",
|
|
506
|
+
"mode": "availabilityMode",
|
|
503
507
|
}
|
|
504
508
|
// Settings that are not plain text: how to read the typed value, or why it is wrong.
|
|
505
509
|
const PARSERS = {
|
|
506
510
|
maxParallelRuns: (raw) => (/^\d+$/.test(raw) && Number(raw) >= 1 && Number(raw) <= 20 ? Number(raw) : new Error("max-parallel-runs is a whole number from 1 to 20")),
|
|
507
511
|
triage: (raw) => (["on", "true", "yes", "1"].includes(raw) ? true : ["off", "false", "no", "0"].includes(raw) ? false : new Error("triage is on or off")),
|
|
508
512
|
sandbox: (raw) => (["on", "true", "yes", "1"].includes(raw) ? true : ["off", "false", "no", "0"].includes(raw) ? false : new Error("sandbox is on or off")),
|
|
513
|
+
availabilityMode: (raw) => (AVAILABILITY_MODES.includes(raw.replace(/-/g, "_")) ? raw.replace(/-/g, "_") : new Error(`mode is one of: ${AVAILABILITY_MODES.join(", ")}`)),
|
|
509
514
|
}
|
|
510
515
|
|
|
511
516
|
const config = readConfig()
|
|
@@ -523,6 +528,8 @@ if (command === "config") {
|
|
|
523
528
|
["max-parallel-runs", String(config.maxParallelRuns ?? 1)],
|
|
524
529
|
["triage", config.triage === false ? "off" : "on"],
|
|
525
530
|
["sandbox", config.sandbox === true ? "on" : "off"],
|
|
531
|
+
["team", config.homeTeam ?? "\x1b[2mmy teams\x1b[0m"],
|
|
532
|
+
["mode", config.availabilityMode ?? "\x1b[2manyone\x1b[0m"],
|
|
526
533
|
["app-url", config.appUrl ?? "https://pacework.io"],
|
|
527
534
|
["api-key", config.apiKey ? `\x1b[2m${config.apiKey.slice(0, 12)}…\x1b[0m` : "\x1b[2mnot set\x1b[0m"],
|
|
528
535
|
]
|
|
@@ -748,8 +755,13 @@ function buildRunnerArgs(extraArgs) {
|
|
|
748
755
|
if (sandbox) base.push("--sandbox", "true")
|
|
749
756
|
// Triage is on unless switched off here (pacework settings) or with --no-triage.
|
|
750
757
|
if (config.triage === false && parsedArgs["no-triage"] === undefined) base.push("--no-triage")
|
|
758
|
+
// Which work the runner takes (PWK-293); the server keeps what the web app set when neither is given.
|
|
759
|
+
const homeTeam = parsedArgs.team !== undefined && parsedArgs.team !== "true" ? String(parsedArgs.team) : config.homeTeam
|
|
760
|
+
if (homeTeam) base.push("--team", homeTeam)
|
|
761
|
+
const availabilityMode = parsedArgs.mode !== undefined && parsedArgs.mode !== "true" ? String(parsedArgs.mode) : config.availabilityMode
|
|
762
|
+
if (availabilityMode) base.push("--mode", availabilityMode)
|
|
751
763
|
|
|
752
|
-
const consumed = new Set(["app-url", "workspace-id", "workspace-api-key", "repo-root", "executor", "name", "model", "yes", "max-parallel-runs", "token", "sandbox"])
|
|
764
|
+
const consumed = new Set(["app-url", "workspace-id", "workspace-api-key", "repo-root", "executor", "name", "model", "yes", "max-parallel-runs", "token", "sandbox", "team", "mode"])
|
|
753
765
|
for (let i = 0; i < extraArgs.length; i++) {
|
|
754
766
|
const arg = extraArgs[i]
|
|
755
767
|
if (arg.startsWith("--")) {
|
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,
|
|
@@ -28,7 +29,7 @@ import { clearPendingPush, describeGitFailure, isTransientGitHubFailure, readPen
|
|
|
28
29
|
import { prepareRunEnvironment } from "../lib/environment.mjs"
|
|
29
30
|
import { installSkills, parseSkillsUsed, skillsPromptSection } from "../lib/skills.mjs"
|
|
30
31
|
import { isGitLockError, repoLockKey, retryGitLock, withRepoLock } from "../lib/git-lock.mjs"
|
|
31
|
-
import { describeRegistration, isRevokedError, registrationChanges, REVOKED_MESSAGE, runEndedOnServer } from "../lib/runner-control.mjs"
|
|
32
|
+
import { AVAILABILITY_MODES, describeRegistration, isRevokedError, registrationChanges, REVOKED_MESSAGE, runEndedOnServer } from "../lib/runner-control.mjs"
|
|
32
33
|
import { describeTriageJob, runTriageLoop, TRIAGE_EXECUTORS } from "../lib/triage-worker.mjs"
|
|
33
34
|
import { automationDenyRules, automationLimits } from "../lib/automation-limits.mjs"
|
|
34
35
|
import { truncateSummary } from "../lib/summary-text.mjs"
|
|
@@ -132,6 +133,13 @@ const labels = (args.labels || process.env.RUNNER_LABELS || "")
|
|
|
132
133
|
.split(",")
|
|
133
134
|
.map(value => value.trim())
|
|
134
135
|
.filter(Boolean)
|
|
136
|
+
// Which work this runner takes (PWK-293). Unset: the server keeps what it has.
|
|
137
|
+
const homeTeam = String(args.team || process.env.RUNNER_TEAM || "").trim() || null
|
|
138
|
+
const availabilityMode = String(args.mode || process.env.RUNNER_MODE || "").trim().replace(/-/g, "_") || null
|
|
139
|
+
if (availabilityMode && !AVAILABILITY_MODES.includes(availabilityMode)) {
|
|
140
|
+
console.error(`--mode must be one of: ${AVAILABILITY_MODES.join(", ")}`)
|
|
141
|
+
process.exit(1)
|
|
142
|
+
}
|
|
135
143
|
const runnerBaseLogger = createLogger({
|
|
136
144
|
service: "runner",
|
|
137
145
|
component: "local_agent_runner",
|
|
@@ -958,6 +966,9 @@ async function registerRunner() {
|
|
|
958
966
|
local_executor: defaultExecutor,
|
|
959
967
|
labels,
|
|
960
968
|
max_parallel_runs: maxParallelRuns,
|
|
969
|
+
...(homeTeam ? { home_team: homeTeam } : {}),
|
|
970
|
+
...(availabilityMode ? { availability_mode: availabilityMode } : {}),
|
|
971
|
+
capabilities: runnerCapabilities(),
|
|
961
972
|
}),
|
|
962
973
|
})
|
|
963
974
|
|
|
@@ -972,6 +983,9 @@ async function registerRunner() {
|
|
|
972
983
|
local_executor: payload.runner.local_executor,
|
|
973
984
|
max_parallel_runs: payload.runner.max_parallel_runs ?? maxParallelRuns,
|
|
974
985
|
labels: payload.runner.labels ?? [],
|
|
986
|
+
// What was asked for, so a later start with the same flags doesn't register again.
|
|
987
|
+
home_team: homeTeam,
|
|
988
|
+
availability_mode: payload.runner.availability_mode ?? availabilityMode,
|
|
975
989
|
registered_at: new Date().toISOString(),
|
|
976
990
|
}
|
|
977
991
|
saveState(state)
|
|
@@ -988,6 +1002,8 @@ async function ensureRegisteredRunner() {
|
|
|
988
1002
|
local_executor: defaultExecutor,
|
|
989
1003
|
max_parallel_runs: maxParallelRuns,
|
|
990
1004
|
labels,
|
|
1005
|
+
home_team: homeTeam,
|
|
1006
|
+
availability_mode: availabilityMode,
|
|
991
1007
|
})
|
|
992
1008
|
if (changes.length === 0) return state
|
|
993
1009
|
// Registering again updates this machine's entry in place (the server
|
|
@@ -1001,6 +1017,18 @@ async function ensureRegisteredRunner() {
|
|
|
1001
1017
|
return registerRunner()
|
|
1002
1018
|
}
|
|
1003
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
|
+
|
|
1004
1032
|
async function heartbeat(state, status = "online") {
|
|
1005
1033
|
return requestJson(`${appUrl}/api/agent-runners/heartbeat`, {
|
|
1006
1034
|
method: "POST",
|
|
@@ -1013,6 +1041,7 @@ async function heartbeat(state, status = "online") {
|
|
|
1013
1041
|
runner_id: state.runner_id,
|
|
1014
1042
|
status,
|
|
1015
1043
|
local_executors: installedExecutors,
|
|
1044
|
+
capabilities: runnerCapabilities(),
|
|
1016
1045
|
}),
|
|
1017
1046
|
})
|
|
1018
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" }
|
package/lib/runner-control.mjs
CHANGED
|
@@ -34,6 +34,9 @@ export function isRevokedError(error) {
|
|
|
34
34
|
* The registration settings that differ between what this runner registered
|
|
35
35
|
* with (its saved state) and what it was started with now.
|
|
36
36
|
*/
|
|
37
|
+
/** Which work a runner takes (PWK-293). Without one, the server keeps what it has (new runners: anyone). */
|
|
38
|
+
export const AVAILABILITY_MODES = ["only_mine", "my_team", "help_when_idle", "anyone"]
|
|
39
|
+
|
|
37
40
|
export function registrationChanges(saved, wanted) {
|
|
38
41
|
if (!saved) return []
|
|
39
42
|
const changes = []
|
|
@@ -45,6 +48,9 @@ export function registrationChanges(saved, wanted) {
|
|
|
45
48
|
if (Number(saved.max_parallel_runs ?? 1) !== Number(wanted.max_parallel_runs ?? 1)) changes.push("max parallel runs")
|
|
46
49
|
const labels = (list) => [...new Set((list ?? []).map(String))].sort().join("\n")
|
|
47
50
|
if (labels(saved.labels) !== labels(wanted.labels)) changes.push("labels")
|
|
51
|
+
// Only when asked for: a runner started without --team/--mode keeps what the web app set.
|
|
52
|
+
if (wanted.home_team && !same(saved.home_team, wanted.home_team)) changes.push("team")
|
|
53
|
+
if (wanted.availability_mode && !same(saved.availability_mode, wanted.availability_mode)) changes.push("mode")
|
|
48
54
|
return changes
|
|
49
55
|
}
|
|
50
56
|
|