pacework 1.4.3 → 1.6.0
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 +85 -12
- package/bin/pacework-runner.mjs +30 -8
- package/lib/control-state.mjs +3 -0
- package/lib/home.mjs +18 -12
- package/lib/models.mjs +36 -0
- package/lib/runner-settings.mjs +21 -0
- package/lib/setup.mjs +76 -0
- package/lib/summary-text.mjs +15 -0
- package/lib/triage-worker.mjs +12 -1
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ import readline from "node:readline"
|
|
|
16
16
|
import { spawn, execFileSync, execSync } from "node:child_process"
|
|
17
17
|
import { fileURLToPath } from "node:url"
|
|
18
18
|
import { agentSecretsFrom, detectSetupCommand } from "../lib/environment.mjs"
|
|
19
|
-
import { runTriageLoop } from "../lib/triage-worker.mjs"
|
|
19
|
+
import { describeTriageJob, runTriageLoop } from "../lib/triage-worker.mjs"
|
|
20
20
|
import { NPM_PACKAGE, isNewerVersion, latestPublishedVersion } from "../lib/version.mjs"
|
|
21
21
|
import { EXECUTORS, EXECUTOR_DEFAULT_NAMES, checkBinaryExists, executorLabel } from "../lib/executors.mjs"
|
|
22
22
|
import { BANNER_LINES } from "../lib/ui.mjs"
|
|
@@ -272,13 +272,16 @@ ${row("pacework status [--json]", "Is it running, and what is it doing")}
|
|
|
272
272
|
${row("pacework logs [--lines N]", "Follow its log")}
|
|
273
273
|
${row("pacework connect", "Run it in this terminal instead")}
|
|
274
274
|
${row("pacework use <tool>", `Switch AI tool: ${d("claude_code, codex, gemini, cursor_agent, github_copilot")}`)}
|
|
275
|
+
${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, …")}`)}
|
|
275
277
|
${row("pacework doctor", "Check this machine's setup")}
|
|
276
278
|
${row("pacework triage [--once]", "Only triage, in the foreground")}
|
|
277
|
-
${row("pacework up --token CODE", "One-step setup from the command in pacework's Runners page")}
|
|
279
|
+
${row("pacework up --token CODE", "One-step setup from the command in pacework's Runners page; asks for the runner's name and model")}
|
|
278
280
|
${row("pacework down", "Remove the background service")}
|
|
279
281
|
|
|
280
282
|
\x1b[1mRunner flags\x1b[0m ${d("for start, connect and up")}
|
|
281
|
-
--repo-root PATH --executor TOOL --name NAME --max-parallel-runs N --sandbox --no-triage
|
|
283
|
+
--repo-root PATH --executor TOOL --name NAME --model ID --max-parallel-runs N --sandbox --no-triage
|
|
284
|
+
${d("--model: empty for the tool's latest default; Claude Code also takes opus, sonnet or haiku for the newest of each")}
|
|
282
285
|
`)
|
|
283
286
|
process.exit(0)
|
|
284
287
|
}
|
|
@@ -489,10 +492,20 @@ if (command === "config") {
|
|
|
489
492
|
const KEY_ALIASES = {
|
|
490
493
|
"executor": "executor",
|
|
491
494
|
"name": "runnerName",
|
|
495
|
+
"model": "model",
|
|
492
496
|
"runner-name": "runnerName",
|
|
493
497
|
"repo-root": "repoRoot",
|
|
494
498
|
"app-url": "appUrl",
|
|
495
499
|
"workspace-id": "workspaceId",
|
|
500
|
+
"max-parallel-runs": "maxParallelRuns",
|
|
501
|
+
"triage": "triage",
|
|
502
|
+
"sandbox": "sandbox",
|
|
503
|
+
}
|
|
504
|
+
// Settings that are not plain text: how to read the typed value, or why it is wrong.
|
|
505
|
+
const PARSERS = {
|
|
506
|
+
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
|
+
triage: (raw) => (["on", "true", "yes", "1"].includes(raw) ? true : ["off", "false", "no", "0"].includes(raw) ? false : new Error("triage is on or off")),
|
|
508
|
+
sandbox: (raw) => (["on", "true", "yes", "1"].includes(raw) ? true : ["off", "false", "no", "0"].includes(raw) ? false : new Error("sandbox is on or off")),
|
|
496
509
|
}
|
|
497
510
|
|
|
498
511
|
const config = readConfig()
|
|
@@ -506,11 +519,15 @@ if (command === "config") {
|
|
|
506
519
|
["executor", config.executor ? `\x1b[1m${executorLabel(config.executor)}\x1b[0m (${config.executor})` : "\x1b[2mnot set\x1b[0m"],
|
|
507
520
|
["name", config.runnerName ?? "\x1b[2mnot set\x1b[0m"],
|
|
508
521
|
["repo-root", config.repoRoot ?? "\x1b[2mnot set\x1b[0m"],
|
|
522
|
+
["model", config.model || "\x1b[2mlatest\x1b[0m"],
|
|
523
|
+
["max-parallel-runs", String(config.maxParallelRuns ?? 1)],
|
|
524
|
+
["triage", config.triage === false ? "off" : "on"],
|
|
525
|
+
["sandbox", config.sandbox === true ? "on" : "off"],
|
|
509
526
|
["app-url", config.appUrl ?? "https://pacework.io"],
|
|
510
527
|
["api-key", config.apiKey ? `\x1b[2m${config.apiKey.slice(0, 12)}…\x1b[0m` : "\x1b[2mnot set\x1b[0m"],
|
|
511
528
|
]
|
|
512
|
-
rows.forEach(([k, v]) => console.log(` ${k.padEnd(
|
|
513
|
-
console.log(`\nTo set: \x1b[36mpacework
|
|
529
|
+
rows.forEach(([k, v]) => console.log(` ${k.padEnd(17)} ${v}`))
|
|
530
|
+
console.log(`\nTo set: \x1b[36mpacework config <key> <value>\x1b[0m`)
|
|
514
531
|
console.log(`Keys: ${Object.keys(KEY_ALIASES).join(", ")}`)
|
|
515
532
|
process.exit(0)
|
|
516
533
|
}
|
|
@@ -534,9 +551,16 @@ if (command === "config") {
|
|
|
534
551
|
process.exit(1)
|
|
535
552
|
}
|
|
536
553
|
|
|
537
|
-
|
|
554
|
+
const parsed = PARSERS[configKey] ? PARSERS[configKey](String(value).trim().toLowerCase()) : value
|
|
555
|
+
if (parsed instanceof Error) {
|
|
556
|
+
console.error(parsed.message)
|
|
557
|
+
process.exit(1)
|
|
558
|
+
}
|
|
559
|
+
config[configKey] = parsed
|
|
538
560
|
writeConfig(config)
|
|
539
|
-
|
|
561
|
+
const pidNow = readPid()
|
|
562
|
+
const restartHint = pidNow && isRunning(pidNow) ? ` \x1b[2mrestart the runner to use it: pacework stop && pacework start\x1b[0m` : ""
|
|
563
|
+
console.log(`\x1b[32m✓\x1b[0m ${key} = \x1b[1m${typeof parsed === "boolean" ? (parsed ? "on" : "off") : parsed}\x1b[0m${restartHint}`)
|
|
540
564
|
process.exit(0)
|
|
541
565
|
}
|
|
542
566
|
|
|
@@ -713,14 +737,19 @@ function buildRunnerArgs(extraArgs) {
|
|
|
713
737
|
"--executor", executor,
|
|
714
738
|
]
|
|
715
739
|
if (runnerName) base.push("--name", runnerName)
|
|
740
|
+
// The model chosen at `pacework up`; empty means the tool's own current default.
|
|
741
|
+
const model = parsedArgs["model"] !== undefined && parsedArgs["model"] !== "true" ? String(parsedArgs["model"]) : config.model
|
|
742
|
+
if (model) base.push("--model-preferences", model)
|
|
716
743
|
const maxParallelRuns = parsedArgs["max-parallel-runs"] || config.maxParallelRuns
|
|
717
744
|
if (maxParallelRuns) base.push("--max-parallel-runs", String(maxParallelRuns))
|
|
718
745
|
const sandbox = parsedArgs.sandbox !== undefined
|
|
719
746
|
? !["false", "0", "no"].includes(String(parsedArgs.sandbox))
|
|
720
747
|
: config.sandbox === true
|
|
721
748
|
if (sandbox) base.push("--sandbox", "true")
|
|
749
|
+
// Triage is on unless switched off here (pacework settings) or with --no-triage.
|
|
750
|
+
if (config.triage === false && parsedArgs["no-triage"] === undefined) base.push("--no-triage")
|
|
722
751
|
|
|
723
|
-
const consumed = new Set(["app-url", "workspace-id", "workspace-api-key", "repo-root", "executor", "name", "max-parallel-runs", "token", "sandbox"])
|
|
752
|
+
const consumed = new Set(["app-url", "workspace-id", "workspace-api-key", "repo-root", "executor", "name", "model", "yes", "max-parallel-runs", "token", "sandbox"])
|
|
724
753
|
for (let i = 0; i < extraArgs.length; i++) {
|
|
725
754
|
const arg = extraArgs[i]
|
|
726
755
|
if (arg.startsWith("--")) {
|
|
@@ -779,7 +808,7 @@ function formatLogLine(raw) {
|
|
|
779
808
|
|
|
780
809
|
if (event === "runner.ready") return `${prefix} ${green}●${reset} Runner ready ${dim}${entry.meta?.local_executor ?? ""} ${entry.meta?.machine_name ?? ""}${reset}`
|
|
781
810
|
if (event === "runner.job.start") return `${prefix} ${blue}▶${reset} ${bold}${entry.meta?.task_identifier ?? ""}${reset} ${entry.meta?.task_title ?? msg} ${dim}${entry.meta?.local_executor ?? ""}${reset}`
|
|
782
|
-
if (event === "runner.job.complete") return `${prefix} ${green}✓${reset} ${bold}${entry.meta?.task_identifier ?? ""}${reset} completed ${dim}${fmtDuration(entry.meta?.duration_ms)}${reset}`
|
|
811
|
+
if (event === "runner.job.complete") return `${prefix} ${green}✓${reset} ${bold}${entry.meta?.task_identifier ?? ""}${reset} ${entry.meta?.task_title ?? ""} ${entry.meta?.outcome ?? "completed"} ${dim}${fmtDuration(entry.meta?.duration_ms)}${reset}`
|
|
783
812
|
if (event === "runner.job.error") return `${prefix} ${red}✗${reset} ${bold}${entry.meta?.task_identifier ?? ""}${reset} ${red}${msg}${reset}`
|
|
784
813
|
if (event === "runner.job.cancel") return `${prefix} ${dim}■ ${entry.meta?.task_identifier ?? ""} canceled${reset}`
|
|
785
814
|
if (event === "runner.heartbeat") return null // skip noise
|
|
@@ -1165,8 +1194,8 @@ else if (command === "triage") {
|
|
|
1165
1194
|
shouldStop: () => stopping,
|
|
1166
1195
|
report: (event, details) => {
|
|
1167
1196
|
if (event === "started") log(`Triage runner "${details.runnerName}" polling ${appUrl} every ${details.pollIntervalMs / 1000}s (executor: ${details.executor})`)
|
|
1168
|
-
else if (event === "claimed") log(
|
|
1169
|
-
else if (event === "completed") log(`\x1b[
|
|
1197
|
+
else if (event === "claimed") log(`\x1b[1m${describeTriageJob(details.job).identifier}\x1b[0m ${describeTriageJob(details.job).title} \x1b[2mrunning ${executor}…\x1b[0m`)
|
|
1198
|
+
else if (event === "completed") log(`\x1b[32m✓\x1b[0m ${describeTriageJob(details.job).title} ${details.outcome ?? `confidence ${details.confidence ?? "n/a"}`} \x1b[2m${Math.round(details.durationMs / 1000)}s\x1b[0m`)
|
|
1170
1199
|
else if (event === "rejected") log(`\x1b[31mJob ${details.job.id}: server rejected completion (${details.status}): ${JSON.stringify(details.payload)}\x1b[0m`)
|
|
1171
1200
|
else if (event === "failed") log(`\x1b[31mJob ${details.job.id} failed: ${details.message}\x1b[0m`)
|
|
1172
1201
|
else if (event === "poll_error") log(`Poll error: ${details.message}`)
|
|
@@ -1185,6 +1214,20 @@ else if (command === "triage") {
|
|
|
1185
1214
|
// Question-driven UX: numbered choices instead of remembering commands/flags.
|
|
1186
1215
|
// Every action shells out to this same CLI, so menu and commands never drift.
|
|
1187
1216
|
|
|
1217
|
+
else if (command === "settings") {
|
|
1218
|
+
const { changeSettings } = await import("../lib/setup.mjs")
|
|
1219
|
+
const changed = await changeSettings()
|
|
1220
|
+
const pid = readPid()
|
|
1221
|
+
if (changed && pid && isRunning(pid)) {
|
|
1222
|
+
const ctlScript = fileURLToPath(import.meta.url)
|
|
1223
|
+
const run = (args) => new Promise((resolve) => spawn(process.execPath, [ctlScript, ...args], { stdio: "ignore" }).on("close", (code) => resolve(code === 0)))
|
|
1224
|
+
console.log("Restarting the runner with the new settings…")
|
|
1225
|
+
await run(["stop"])
|
|
1226
|
+
console.log(await run(["start"]) ? "\x1b[32m✓\x1b[0m Runner restarted." : "\x1b[31mThe runner did not start again; see pacework logs.\x1b[0m")
|
|
1227
|
+
}
|
|
1228
|
+
process.exit(0)
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1188
1231
|
else if (command === "menu") {
|
|
1189
1232
|
// `pacework` in a terminal: guided setup the first time, then the live home
|
|
1190
1233
|
// screen. Both load the prompt library lazily, so the background service,
|
|
@@ -3058,13 +3101,43 @@ else if (command === "up") {
|
|
|
3058
3101
|
|
|
3059
3102
|
config.executor = executor
|
|
3060
3103
|
config.repoRoot = repoRoot
|
|
3061
|
-
|
|
3104
|
+
const defaultName = config.runnerName || `${os.hostname().replace(/\.local$/, "")} · ${executorLabel(executor)}`
|
|
3105
|
+
const namedByFlag = parsedArgs.name && parsedArgs.name !== "true"
|
|
3106
|
+
const modelByFlag = parsedArgs.model !== undefined && parsedArgs.model !== "true"
|
|
3107
|
+
// In a terminal, ask for the name and the model; flags and pipes keep the defaults.
|
|
3108
|
+
if (process.stdin.isTTY && !parsedArgs.yes && (!namedByFlag || !modelByFlag)) {
|
|
3109
|
+
const prompt = await import("@clack/prompts")
|
|
3110
|
+
const { CUSTOM_MODEL, modelChoices } = await import("../lib/models.mjs")
|
|
3111
|
+
const answered = (value) => {
|
|
3112
|
+
if (prompt.isCancel(value)) { prompt.cancel("Nothing changed."); process.exit(0) }
|
|
3113
|
+
return value
|
|
3114
|
+
}
|
|
3115
|
+
if (!namedByFlag) {
|
|
3116
|
+
const typed = answered(await prompt.text({ message: "Name this runner", initialValue: defaultName, placeholder: defaultName }))
|
|
3117
|
+
config.runnerName = String(typed || "").trim() || defaultName
|
|
3118
|
+
}
|
|
3119
|
+
if (!modelByFlag) {
|
|
3120
|
+
const picked = answered(await prompt.select({
|
|
3121
|
+
message: `Which model should ${executorLabel(executor)} use?`,
|
|
3122
|
+
options: modelChoices(executor, config.model).map(({ value, label, hint }) => ({ value, label, hint })),
|
|
3123
|
+
initialValue: config.model ?? "",
|
|
3124
|
+
}))
|
|
3125
|
+
config.model = picked === CUSTOM_MODEL
|
|
3126
|
+
? String(answered(await prompt.text({ message: "Model id", placeholder: executor === "codex" ? "gpt-5.4" : "a model id the tool accepts" })) || "").trim()
|
|
3127
|
+
: picked
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
if (namedByFlag) config.runnerName = parsedArgs.name
|
|
3131
|
+
else if (!config.runnerName) config.runnerName = defaultName
|
|
3132
|
+
if (modelByFlag) config.model = String(parsedArgs.model).trim()
|
|
3062
3133
|
// Gemini and Cursor share one config file per machine, so one run at a time.
|
|
3063
3134
|
const singleRun = executor === "gemini" || executor === "cursor_agent"
|
|
3064
3135
|
config.maxParallelRuns = singleRun ? 1 : Number(parsedArgs["max-parallel-runs"]) || config.maxParallelRuns || 2
|
|
3065
3136
|
if (parsedArgs.sandbox !== undefined) config.sandbox = !["false", "0", "no"].includes(String(parsedArgs.sandbox))
|
|
3066
3137
|
writeConfig(config)
|
|
3067
3138
|
console.log(` runner \x1b[1m${config.runnerName}\x1b[0m (${config.maxParallelRuns} at a time${config.sandbox ? ", sandboxed" : ""})`)
|
|
3139
|
+
const { modelLabel } = await import("../lib/models.mjs")
|
|
3140
|
+
console.log(` model ${modelLabel(executor, config.model)}`)
|
|
3068
3141
|
|
|
3069
3142
|
// 4. Replace any runner already going on this machine.
|
|
3070
3143
|
if (isServiceInstalled()) stopService()
|
package/bin/pacework-runner.mjs
CHANGED
|
@@ -29,8 +29,9 @@ import { prepareRunEnvironment } from "../lib/environment.mjs"
|
|
|
29
29
|
import { installSkills, parseSkillsUsed, skillsPromptSection } from "../lib/skills.mjs"
|
|
30
30
|
import { isGitLockError, repoLockKey, retryGitLock, withRepoLock } from "../lib/git-lock.mjs"
|
|
31
31
|
import { describeRegistration, isRevokedError, registrationChanges, REVOKED_MESSAGE, runEndedOnServer } from "../lib/runner-control.mjs"
|
|
32
|
-
import { runTriageLoop, TRIAGE_EXECUTORS } from "../lib/triage-worker.mjs"
|
|
32
|
+
import { describeTriageJob, runTriageLoop, TRIAGE_EXECUTORS } from "../lib/triage-worker.mjs"
|
|
33
33
|
import { automationDenyRules, automationLimits } from "../lib/automation-limits.mjs"
|
|
34
|
+
import { truncateSummary } from "../lib/summary-text.mjs"
|
|
34
35
|
|
|
35
36
|
function parseArgs(argv) {
|
|
36
37
|
const args = {}
|
|
@@ -215,6 +216,11 @@ function getRunLogger(state, run) {
|
|
|
215
216
|
run_id: run?.id || undefined,
|
|
216
217
|
task_id: run?.task_id || undefined,
|
|
217
218
|
agent_id: run?.agent_id || run?.agent?.id || undefined,
|
|
219
|
+
// Every line of a run names its issue, so `pacework` can say what is being worked on.
|
|
220
|
+
meta: {
|
|
221
|
+
task_identifier: run?.task?.identifier || undefined,
|
|
222
|
+
task_title: run?.task?.title ? String(run.task.title).replace(/\s+/g, " ").trim() : undefined,
|
|
223
|
+
},
|
|
218
224
|
})
|
|
219
225
|
}
|
|
220
226
|
|
|
@@ -648,7 +654,7 @@ function parseReviewerDecisionSummary(summary) {
|
|
|
648
654
|
|
|
649
655
|
return {
|
|
650
656
|
decision,
|
|
651
|
-
summary:
|
|
657
|
+
summary: truncateSummary(review || "Reviewer decision submitted.", 6000),
|
|
652
658
|
}
|
|
653
659
|
}
|
|
654
660
|
|
|
@@ -1443,7 +1449,7 @@ function buildPullRequestBody(run, details = {}) {
|
|
|
1443
1449
|
const sections = [
|
|
1444
1450
|
"## Summary",
|
|
1445
1451
|
// An agent that ignored the headings still wrote a report; show it whole.
|
|
1446
|
-
summary ||
|
|
1452
|
+
summary || truncateSummary(report, 4000) || `Implements ${identifier}: ${run.task?.title || "see the linked issue"}.`,
|
|
1447
1453
|
"",
|
|
1448
1454
|
"## Why",
|
|
1449
1455
|
`pacework issue **${identifier}** — ${run.task?.title || "Untitled"}`,
|
|
@@ -3250,7 +3256,10 @@ async function runExecutor(run, state) {
|
|
|
3250
3256
|
}, RUN_TIMEOUT_MS)
|
|
3251
3257
|
})
|
|
3252
3258
|
|
|
3259
|
+
const jobStartedAt = Date.now()
|
|
3253
3260
|
try {
|
|
3261
|
+
// The job events the CLI's home screen, `jobs` and `logs` read.
|
|
3262
|
+
runLogger.info("runner.job.start", `Working on ${run.task?.identifier || "an issue"}`)
|
|
3254
3263
|
runLogger.info("runner.run.started", "Local runner execution started", {
|
|
3255
3264
|
meta: {
|
|
3256
3265
|
branch,
|
|
@@ -3770,7 +3779,7 @@ async function runExecutor(run, state) {
|
|
|
3770
3779
|
|
|
3771
3780
|
await completeRun(state, run.id, {
|
|
3772
3781
|
status: "completed",
|
|
3773
|
-
result_summary:
|
|
3782
|
+
result_summary: truncateSummary(summary, 4000),
|
|
3774
3783
|
// Which of its skills the agent says it used, from its report's last line.
|
|
3775
3784
|
skills_used: parseSkillsUsed(summary, skillInstall.installed),
|
|
3776
3785
|
usage: runUsage,
|
|
@@ -3780,7 +3789,7 @@ async function runExecutor(run, state) {
|
|
|
3780
3789
|
// This completion payload omitted the excerpt entirely, so the diff was
|
|
3781
3790
|
// captured and then dropped on the way to the server.
|
|
3782
3791
|
diff_excerpt: diffExcerpt,
|
|
3783
|
-
verification_summary:
|
|
3792
|
+
verification_summary: truncateSummary(verificationSummary, 4000),
|
|
3784
3793
|
worktree_path: worktreePath,
|
|
3785
3794
|
commit_sha: commitResult?.sha,
|
|
3786
3795
|
commit_message: commitResult?.subject,
|
|
@@ -3823,6 +3832,14 @@ async function runExecutor(run, state) {
|
|
|
3823
3832
|
},
|
|
3824
3833
|
})
|
|
3825
3834
|
|
|
3835
|
+
runLogger.info("runner.job.complete", "Done", {
|
|
3836
|
+
meta: {
|
|
3837
|
+
duration_ms: Date.now() - jobStartedAt,
|
|
3838
|
+
outcome: pushResult?.pr_url
|
|
3839
|
+
? `PR ${pushResult.pr_url.replace(/^.*\/pull\//, "#")} · ${changedFiles.length} file${changedFiles.length === 1 ? "" : "s"}`
|
|
3840
|
+
: changedFiles.length ? `${changedFiles.length} file${changedFiles.length === 1 ? "" : "s"} changed` : "no changes",
|
|
3841
|
+
},
|
|
3842
|
+
})
|
|
3826
3843
|
return { summary, branch, worktreePath, artifactsFile, reportFile, verificationSummary, commitResult, pushResult }
|
|
3827
3844
|
} catch (error) {
|
|
3828
3845
|
await flushRunnerLog().catch(() => {})
|
|
@@ -3903,6 +3920,8 @@ async function runExecutor(run, state) {
|
|
|
3903
3920
|
changed_files: stopped?.changedFiles ?? undefined,
|
|
3904
3921
|
}).catch(() => {})
|
|
3905
3922
|
|
|
3923
|
+
if (cancelRequested) runLogger.info("runner.job.cancel", "Canceled", { meta: { duration_ms: Date.now() - jobStartedAt } })
|
|
3924
|
+
else runLogger.error("runner.job.error", String(message).split("\n")[0].slice(0, 200), { meta: { duration_ms: Date.now() - jobStartedAt } })
|
|
3906
3925
|
runLogger.error("runner.run.failed", "Local runner execution failed", {
|
|
3907
3926
|
meta: {
|
|
3908
3927
|
branch,
|
|
@@ -4237,7 +4256,10 @@ async function main() {
|
|
|
4237
4256
|
if (!cloudState && triageEnabled && workspaceApiKey) {
|
|
4238
4257
|
const triageLogger = () => getRunnerLogger(state)
|
|
4239
4258
|
if (TRIAGE_EXECUTORS.includes(defaultExecutor)) {
|
|
4240
|
-
const jobMeta = (job, extra = {}) =>
|
|
4259
|
+
const jobMeta = (job, extra = {}) => {
|
|
4260
|
+
const { identifier, title } = describeTriageJob(job)
|
|
4261
|
+
return { meta: { run_id: job.id, task_identifier: identifier, task_title: title, request_id: job.request_id, ...extra } }
|
|
4262
|
+
}
|
|
4241
4263
|
runTriageLoop({
|
|
4242
4264
|
appUrl,
|
|
4243
4265
|
apiKey: workspaceApiKey,
|
|
@@ -4246,8 +4268,8 @@ async function main() {
|
|
|
4246
4268
|
shouldStop: () => shuttingDown,
|
|
4247
4269
|
report: (event, details) => {
|
|
4248
4270
|
if (event === "started") triageLogger().info("runner.triage.ready", "Taking triage jobs too")
|
|
4249
|
-
else if (event === "claimed") triageLogger().info("runner.job.start",
|
|
4250
|
-
else if (event === "completed") triageLogger().info("runner.job.complete", "Triage job completed", jobMeta(details.job, { duration_ms: details.durationMs, confidence: details.confidence }))
|
|
4271
|
+
else if (event === "claimed") triageLogger().info("runner.job.start", `Triaging: ${describeTriageJob(details.job).title}`, jobMeta(details.job))
|
|
4272
|
+
else if (event === "completed") triageLogger().info("runner.job.complete", details.outcome ? `Triaged: ${details.outcome}` : "Triage job completed", jobMeta(details.job, { duration_ms: details.durationMs, confidence: details.confidence, outcome: details.outcome }))
|
|
4251
4273
|
else if (event === "rejected") triageLogger().error("runner.job.error", `Triage result rejected (${details.status})`, jobMeta(details.job, { duration_ms: details.durationMs }))
|
|
4252
4274
|
else if (event === "failed") triageLogger().error("runner.job.error", details.message, jobMeta(details.job, { duration_ms: details.durationMs }))
|
|
4253
4275
|
else if (event === "auth_failed") triageLogger().error("runner.triage.auth_failed", `Triage is paused: the server rejected this runner's key (${details.status}). Retrying every ${Math.round(details.retryMs / 60000)} minutes; run \`npx pacework login\` if it keeps failing.`)
|
package/lib/control-state.mjs
CHANGED
|
@@ -101,6 +101,7 @@ function parseLogLine(raw) {
|
|
|
101
101
|
taskIdentifier: entry.meta?.task_identifier ?? null,
|
|
102
102
|
taskTitle: entry.meta?.task_title ?? null,
|
|
103
103
|
durationMs: entry.meta?.duration_ms ?? null,
|
|
104
|
+
outcome: entry.meta?.outcome ?? null,
|
|
104
105
|
}
|
|
105
106
|
} catch {
|
|
106
107
|
return { ts: null, level: "info", event: null, message: raw }
|
|
@@ -120,6 +121,7 @@ function summarizeJobs(entries) {
|
|
|
120
121
|
finishedAt: null,
|
|
121
122
|
durationMs: null,
|
|
122
123
|
message: null,
|
|
124
|
+
outcome: null,
|
|
123
125
|
}
|
|
124
126
|
if (entry.event === "runner.job.start") {
|
|
125
127
|
existing.status = "running"
|
|
@@ -128,6 +130,7 @@ function summarizeJobs(entries) {
|
|
|
128
130
|
existing.status = "completed"
|
|
129
131
|
existing.finishedAt = entry.ts
|
|
130
132
|
existing.durationMs = entry.durationMs
|
|
133
|
+
existing.outcome = entry.outcome
|
|
131
134
|
} else if (entry.event === "runner.job.error") {
|
|
132
135
|
existing.status = "error"
|
|
133
136
|
existing.finishedAt = entry.ts
|
package/lib/home.mjs
CHANGED
|
@@ -3,9 +3,10 @@ import { spawn } from "node:child_process"
|
|
|
3
3
|
import { readConfig, readRunnerSnapshot } from "./control-state.mjs"
|
|
4
4
|
import { executorLabel } from "./executors.mjs"
|
|
5
5
|
import { openInBrowser } from "./login.mjs"
|
|
6
|
-
import { changeExecutor, changeRepo, switchServer } from "./setup.mjs"
|
|
6
|
+
import { changeExecutor, changeRepo, changeSettings, switchServer } from "./setup.mjs"
|
|
7
|
+
import { runnerSettingRows } from "./runner-settings.mjs"
|
|
7
8
|
import { TRIAGE_EXECUTORS } from "./triage-worker.mjs"
|
|
8
|
-
import { BANNER_LINES, LOGO, formatDuration, hostOf, relativeTime, style, tildePath, truncate } from "./ui.mjs"
|
|
9
|
+
import { BANNER_LINES, LOGO, formatDuration, hostOf, relativeTime, style, tildePath, truncate, visibleLength } from "./ui.mjs"
|
|
9
10
|
import { formatIssueRows, listIssues } from "./issues-cli.mjs"
|
|
10
11
|
import { workspaceUrl } from "./workspace-api.mjs"
|
|
11
12
|
|
|
@@ -20,9 +21,8 @@ const KEYS = [
|
|
|
20
21
|
["i", "issues"],
|
|
21
22
|
["m", "MCP"],
|
|
22
23
|
["l", "logs"],
|
|
24
|
+
["c", "settings"],
|
|
23
25
|
["w", "switch"],
|
|
24
|
-
["r", "repo"],
|
|
25
|
-
["e", "agent AI"],
|
|
26
26
|
["o", "open"],
|
|
27
27
|
["d", "doctor"],
|
|
28
28
|
["?", "help"],
|
|
@@ -35,8 +35,7 @@ const HELP = [
|
|
|
35
35
|
["m", "Connect your AI tools to pacework over MCP, so they can read and update issues"],
|
|
36
36
|
["l", "Show the live runner log"],
|
|
37
37
|
["w", "Switch to another pacework server or workspace (signs in again)"],
|
|
38
|
-
["
|
|
39
|
-
["e", "Change the AI tool agents run on (Claude Code, Codex, …)"],
|
|
38
|
+
["c", "Runner settings: AI tool, model, folder, parallel jobs, triage, sandbox, name"],
|
|
40
39
|
["o", "Open this workspace in your browser"],
|
|
41
40
|
["d", "Run the health check"],
|
|
42
41
|
["q", "Quit this screen; the runner keeps working in the background"],
|
|
@@ -49,6 +48,7 @@ const PLAIN_COMMANDS = [
|
|
|
49
48
|
["pacework start | stop", "Start or stop the background runner"],
|
|
50
49
|
["pacework logs", "Follow the runner log"],
|
|
51
50
|
["pacework login | logout", "Sign in to a pacework, or sign out"],
|
|
51
|
+
["pacework settings", "Change runner settings"],
|
|
52
52
|
["pacework doctor", "Check this machine's setup"],
|
|
53
53
|
["pacework triage", "Run only triage, in the foreground"],
|
|
54
54
|
]
|
|
@@ -84,11 +84,13 @@ function jobLine(job, width) {
|
|
|
84
84
|
}
|
|
85
85
|
const mark = job.status === "completed" ? style.green("✓") : job.status === "error" ? style.red("✗") : style.gray("–")
|
|
86
86
|
const outcome = job.status === "completed"
|
|
87
|
-
? formatDuration(job.durationMs)
|
|
87
|
+
? [job.outcome, formatDuration(job.durationMs)].filter(Boolean).join(" · ")
|
|
88
88
|
: job.status === "error" ? `failed${job.message ? `: ${job.message}` : ""}` : job.status
|
|
89
89
|
const when = relativeTime(job.finishedAt)
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
// The result gets the room it needs (a triage verdict is longer than a duration); the title the rest.
|
|
91
|
+
const tail = truncate(`${outcome}${when ? ` · ${when}` : ""}`, Math.max(20, Math.floor(width * 0.45)))
|
|
92
|
+
const title = truncate(job.title ?? "", Math.max(10, width - 18 - visibleLength(tail)))
|
|
93
|
+
return ` ${mark} ${id} ${title} ${style.gray(tail)}`
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
export async function runHome({ ctlScript, version }) {
|
|
@@ -119,8 +121,11 @@ export async function runHome({ ctlScript, version }) {
|
|
|
119
121
|
lines.push(` ${style.gray(`${hostOf(snapshot.appUrl)} · ${snapshot.workspace ?? "no workspace"}`)}`)
|
|
120
122
|
const state = snapshot.running ? `${style.green("●")} running` : `${style.gray("○")} stopped`
|
|
121
123
|
const tool = executorLabel(snapshot.executor)
|
|
122
|
-
const
|
|
123
|
-
lines.push(` ${state} ${tildePath(snapshot.repoRoot) || style.yellow("no folder set")} ${style.gray("·")} ${tool} ${style.gray("·")} ${style.gray(
|
|
124
|
+
const triageOn = TRIAGE_EXECUTORS.includes(snapshot.executor) && config.triage !== false
|
|
125
|
+
lines.push(` ${state} ${tildePath(snapshot.repoRoot) || style.yellow("no folder set")} ${style.gray("·")} ${tool} ${style.gray("·")} ${style.gray(triageOn ? "development + triage" : "development")}`)
|
|
126
|
+
// The settings that change what it does, so nobody has to open the menu to check.
|
|
127
|
+
const setting = Object.fromEntries(runnerSettingRows(config).map((row) => [row.key, row.value]))
|
|
128
|
+
lines.push(` ${style.gray(`model ${setting.model} · ${setting.maxParallelRuns} at a time${config.sandbox ? " · sandboxed" : ""} · c to change`)}`)
|
|
124
129
|
lines.push("")
|
|
125
130
|
|
|
126
131
|
if (mode === "issues") {
|
|
@@ -307,7 +312,8 @@ export async function runHome({ ctlScript, version }) {
|
|
|
307
312
|
})
|
|
308
313
|
})
|
|
309
314
|
}
|
|
310
|
-
|
|
315
|
+
// r and e predate the settings menu (c) and still go straight to their setting.
|
|
316
|
+
const settings = { c: changeSettings, w: switchServer, r: changeRepo, e: changeExecutor }
|
|
311
317
|
if (settings[name]) {
|
|
312
318
|
const changed = await suspend(() => settings[name]())
|
|
313
319
|
if (changed) {
|
package/lib/models.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { executorLabel } from "./executors.mjs"
|
|
2
|
+
|
|
3
|
+
/** The answer meaning "type another model id". */
|
|
4
|
+
export const CUSTOM_MODEL = "__custom__"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Model choices offered when a runner starts. "" means the tool's own current
|
|
8
|
+
* default, which moves forward whenever the tool updates. Claude Code's family
|
|
9
|
+
* aliases always resolve to the newest model in that family, so they never go
|
|
10
|
+
* stale the way a pinned id does.
|
|
11
|
+
*/
|
|
12
|
+
export function modelChoices(executor, savedModel = "") {
|
|
13
|
+
const tool = executorLabel(executor)
|
|
14
|
+
const choices = [{ value: "", label: "Latest", hint: `whatever ${tool} uses by default; updates with ${tool}` }]
|
|
15
|
+
if (executor === "claude_code") {
|
|
16
|
+
choices.push(
|
|
17
|
+
{ value: "opus", label: "Opus", hint: "always the newest Opus" },
|
|
18
|
+
{ value: "sonnet", label: "Sonnet", hint: "always the newest Sonnet" },
|
|
19
|
+
{ value: "haiku", label: "Haiku", hint: "always the newest Haiku" },
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
const saved = String(savedModel || "").trim()
|
|
23
|
+
if (saved && !choices.some((choice) => choice.value === saved)) {
|
|
24
|
+
choices.push({ value: saved, label: saved, hint: "used before" })
|
|
25
|
+
}
|
|
26
|
+
choices.push({ value: CUSTOM_MODEL, label: "Another model…", hint: "type its id" })
|
|
27
|
+
return choices
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** How a saved model reads in the summary. */
|
|
31
|
+
export function modelLabel(executor, model) {
|
|
32
|
+
const value = String(model || "").trim()
|
|
33
|
+
if (!value) return `latest (${executorLabel(executor)} default)`
|
|
34
|
+
if (executor === "claude_code" && ["opus", "sonnet", "haiku"].includes(value)) return `newest ${value[0].toUpperCase()}${value.slice(1)}`
|
|
35
|
+
return value
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { executorLabel } from "./executors.mjs"
|
|
2
|
+
import { modelLabel } from "./models.mjs"
|
|
3
|
+
import { tildePath } from "./ui.mjs"
|
|
4
|
+
|
|
5
|
+
/** The runner settings `pacework settings` and the home screen show, read from the saved config. */
|
|
6
|
+
export const RUNNER_SETTING_DEFAULTS = { maxParallelRuns: 1, triage: true, sandbox: false }
|
|
7
|
+
|
|
8
|
+
export function runnerSettingRows(config) {
|
|
9
|
+
const executor = config.executor ?? "codex"
|
|
10
|
+
const on = (value) => (value ? "on" : "off")
|
|
11
|
+
return [
|
|
12
|
+
{ key: "executor", label: "AI tool", value: executorLabel(executor) },
|
|
13
|
+
{ key: "model", label: "Model", value: modelLabel(executor, config.model) },
|
|
14
|
+
{ key: "repoRoot", label: "Folder", value: tildePath(config.repoRoot) || "not set" },
|
|
15
|
+
{ key: "maxParallelRuns", label: "Parallel jobs", value: String(config.maxParallelRuns ?? RUNNER_SETTING_DEFAULTS.maxParallelRuns) },
|
|
16
|
+
{ key: "triage", label: "Triage requests", value: on(config.triage ?? RUNNER_SETTING_DEFAULTS.triage) },
|
|
17
|
+
{ key: "sandbox", label: "Sandbox", value: on(config.sandbox ?? RUNNER_SETTING_DEFAULTS.sandbox) },
|
|
18
|
+
{ key: "runnerName", label: "Name", value: config.runnerName || "not set" },
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
|
package/lib/setup.mjs
CHANGED
|
@@ -6,6 +6,8 @@ import { readConfig, writeConfig } from "./control-state.mjs"
|
|
|
6
6
|
import { EXECUTORS, EXECUTOR_DEFAULT_NAMES, checkBinaryExists, executorLabel } from "./executors.mjs"
|
|
7
7
|
import { openInBrowser, startLogin, waitForApproval } from "./login.mjs"
|
|
8
8
|
import { hostOf, normalizeAppUrl, style, tildePath } from "./ui.mjs"
|
|
9
|
+
import { CUSTOM_MODEL, modelChoices } from "./models.mjs"
|
|
10
|
+
import { RUNNER_SETTING_DEFAULTS, runnerSettingRows } from "./runner-settings.mjs"
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Guided setup for the interactive CLI: which pacework, sign in, which folder,
|
|
@@ -220,3 +222,77 @@ export async function changeExecutor() {
|
|
|
220
222
|
return true
|
|
221
223
|
}) ?? false
|
|
222
224
|
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Every runner setting in one menu (home screen key c, `pacework settings`):
|
|
228
|
+
* pick one, change it, come back to the list; Done or Esc leaves. Returns
|
|
229
|
+
* whether anything changed, so the caller can restart a running runner.
|
|
230
|
+
*/
|
|
231
|
+
const SETTING_HINTS = {
|
|
232
|
+
maxParallelRuns: "how many issues it works on at once",
|
|
233
|
+
triage: "also triage incoming requests with your AI tool",
|
|
234
|
+
sandbox: "run agents with restricted file and network access",
|
|
235
|
+
runnerName: "how this machine shows in pacework",
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function changeSetting(key) {
|
|
239
|
+
const config = readConfig()
|
|
240
|
+
if (key === "executor") {
|
|
241
|
+
const executor = await chooseExecutor(config.executor)
|
|
242
|
+
// A model id belongs to one tool; switching tools starts from its default.
|
|
243
|
+
updateConfig(executor === config.executor ? { executor } : { executor, model: "" })
|
|
244
|
+
} else if (key === "model") {
|
|
245
|
+
const executor = config.executor ?? "codex"
|
|
246
|
+
const picked = unlessCancelled(await prompt.select({
|
|
247
|
+
message: `Which model should ${executorLabel(executor)} use?`,
|
|
248
|
+
options: modelChoices(executor, config.model),
|
|
249
|
+
initialValue: config.model ?? "",
|
|
250
|
+
}))
|
|
251
|
+
const model = picked === CUSTOM_MODEL
|
|
252
|
+
? String(unlessCancelled(await prompt.text({ message: "Model id", validate: (value) => (String(value ?? "").trim() ? undefined : "Enter a model id") }))).trim()
|
|
253
|
+
: picked
|
|
254
|
+
updateConfig({ model })
|
|
255
|
+
} else if (key === "repoRoot") {
|
|
256
|
+
updateConfig({ repoRoot: await chooseRepo(config.repoRoot) })
|
|
257
|
+
} else if (key === "maxParallelRuns") {
|
|
258
|
+
const current = config.maxParallelRuns ?? RUNNER_SETTING_DEFAULTS.maxParallelRuns
|
|
259
|
+
const value = unlessCancelled(await prompt.text({
|
|
260
|
+
message: "How many issues at once? (1-20)",
|
|
261
|
+
initialValue: String(current),
|
|
262
|
+
validate: (input) => (/^\d+$/.test(String(input ?? "").trim()) && Number(input) >= 1 && Number(input) <= 20 ? undefined : "A whole number from 1 to 20"),
|
|
263
|
+
}))
|
|
264
|
+
updateConfig({ maxParallelRuns: Number(value) })
|
|
265
|
+
} else if (key === "triage" || key === "sandbox") {
|
|
266
|
+
const current = config[key] ?? RUNNER_SETTING_DEFAULTS[key]
|
|
267
|
+
const value = unlessCancelled(await prompt.confirm({ message: `${key === "triage" ? "Triage requests on this machine" : "Run agents in a sandbox"}?`, initialValue: current }))
|
|
268
|
+
updateConfig({ [key]: value })
|
|
269
|
+
} else if (key === "runnerName") {
|
|
270
|
+
const value = unlessCancelled(await prompt.text({
|
|
271
|
+
message: "Runner name",
|
|
272
|
+
initialValue: config.runnerName ?? "",
|
|
273
|
+
validate: (input) => (String(input ?? "").trim() ? undefined : "Enter a name"),
|
|
274
|
+
}))
|
|
275
|
+
updateConfig({ runnerName: String(value).trim() })
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export async function changeSettings() {
|
|
280
|
+
let changed = false
|
|
281
|
+
prompt.intro(`${style.inverse(" pacework ")} Runner settings`)
|
|
282
|
+
for (;;) {
|
|
283
|
+
const rows = runnerSettingRows(readConfig())
|
|
284
|
+
const width = Math.max(...rows.map((row) => row.label.length))
|
|
285
|
+
const choice = await prompt.select({
|
|
286
|
+
message: "Pick a setting to change",
|
|
287
|
+
options: [
|
|
288
|
+
...rows.map((row) => ({ value: row.key, label: `${row.label.padEnd(width)} ${row.value}`, hint: SETTING_HINTS[row.key] })),
|
|
289
|
+
{ value: "done", label: "Done" },
|
|
290
|
+
],
|
|
291
|
+
})
|
|
292
|
+
if (prompt.isCancel(choice) || choice === "done") break
|
|
293
|
+
const saved = await step(async () => { await changeSetting(choice); return true })
|
|
294
|
+
if (saved) changed = true
|
|
295
|
+
}
|
|
296
|
+
prompt.outro(changed ? "Saved. A running runner restarts to use them." : "Nothing changed.")
|
|
297
|
+
return changed
|
|
298
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shortens text a person will read (a run summary, a review, a PR body) by
|
|
3
|
+
* keeping its beginning. Cuts at the last line break before the limit so a
|
|
4
|
+
* code span or list item is not split, and says where the rest is.
|
|
5
|
+
* Logs keep their tail instead; see truncate() in bin/pacework-runner.mjs.
|
|
6
|
+
*/
|
|
7
|
+
export function truncateSummary(value, max = 4000, note = "…(shortened; the full text is in the run report)") {
|
|
8
|
+
const text = String(value ?? "").trim()
|
|
9
|
+
if (text.length <= max) return text
|
|
10
|
+
const room = Math.max(0, max - note.length - 2)
|
|
11
|
+
const head = text.slice(0, room)
|
|
12
|
+
const lineBreak = head.lastIndexOf("\n")
|
|
13
|
+
const cut = lineBreak > room * 0.5 ? head.slice(0, lineBreak) : head.replace(/\s+\S*$/, "")
|
|
14
|
+
return `${cut.trimEnd()}\n\n${note}`
|
|
15
|
+
}
|
package/lib/triage-worker.mjs
CHANGED
|
@@ -11,6 +11,17 @@ import { spawn } from "node:child_process"
|
|
|
11
11
|
*/
|
|
12
12
|
export const TRIAGE_EXECUTORS = ["claude_code", "codex", "gemini"]
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* How a job reads in the terminal: a short tag and what it is about. Triage
|
|
16
|
+
* jobs carry their request's title (servers before that send none); the other
|
|
17
|
+
* kind answers an AI feature such as the Slack agent.
|
|
18
|
+
*/
|
|
19
|
+
export function describeTriageJob(job) {
|
|
20
|
+
if (job?.kind === "completion") return { identifier: "AI reply", title: "Answering for the Slack agent" }
|
|
21
|
+
const title = typeof job?.title === "string" ? job.title.replace(/\s+/g, " ").trim() : ""
|
|
22
|
+
return { identifier: "Triage", title: title || "A request" }
|
|
23
|
+
}
|
|
24
|
+
|
|
14
25
|
function buildExecSpec({ executor, model, binaries }, prompt) {
|
|
15
26
|
if (executor === "codex") {
|
|
16
27
|
const outputFile = path.join(os.tmpdir(), `pacework-triage-${Date.now()}-${Math.random().toString(36).slice(2)}.txt`)
|
|
@@ -129,7 +140,7 @@ export async function runTriageLoop({
|
|
|
129
140
|
model: `${executor}${model ? `:${model}` : ""}`,
|
|
130
141
|
})
|
|
131
142
|
if (complete.status >= 400) report("rejected", { job, status: complete.status, payload: complete.payload, durationMs: Date.now() - startedAt })
|
|
132
|
-
else report("completed", { job, confidence: complete.payload?.confidence ?? null, durationMs: Date.now() - startedAt })
|
|
143
|
+
else report("completed", { job, confidence: complete.payload?.confidence ?? null, outcome: complete.payload?.outcome ?? null, durationMs: Date.now() - startedAt })
|
|
133
144
|
} catch (error) {
|
|
134
145
|
const message = error instanceof Error ? error.message : String(error)
|
|
135
146
|
report("failed", { job, message, durationMs: Date.now() - startedAt })
|