pacework 1.0.2 → 1.2.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 +156 -347
- package/bin/pacework-runner.mjs +31 -0
- package/lib/executors.mjs +29 -0
- package/lib/home.mjs +322 -0
- package/lib/issues-cli.mjs +80 -0
- package/lib/login.mjs +50 -0
- package/lib/mcp-cli.mjs +177 -0
- package/lib/mcp-connect.mjs +159 -0
- package/lib/service.mjs +32 -1
- package/lib/setup.mjs +222 -0
- package/lib/triage-worker.mjs +155 -0
- package/lib/ui.mjs +88 -0
- package/lib/workspace-api.mjs +47 -0
- package/package.json +11 -3
|
@@ -16,6 +16,9 @@ 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"
|
|
20
|
+
import { EXECUTORS, EXECUTOR_DEFAULT_NAMES, checkBinaryExists, executorLabel } from "../lib/executors.mjs"
|
|
21
|
+
import { BANNER_LINES } from "../lib/ui.mjs"
|
|
19
22
|
import {
|
|
20
23
|
PACEWORK_DIR,
|
|
21
24
|
STATE_DIR,
|
|
@@ -30,6 +33,7 @@ import {
|
|
|
30
33
|
clearPid,
|
|
31
34
|
readConfig,
|
|
32
35
|
writeConfig,
|
|
36
|
+
readRunnerSnapshot,
|
|
33
37
|
} from "../lib/control-state.mjs"
|
|
34
38
|
import {
|
|
35
39
|
installService,
|
|
@@ -70,12 +74,7 @@ async function checkForUpdate() {
|
|
|
70
74
|
|
|
71
75
|
// ── ascii banner ──────────────────────────────────────────────────────────────
|
|
72
76
|
|
|
73
|
-
const BANNER = `\x1b[38;5;39m
|
|
74
|
-
██╔══██╗██╔══██╗██╔════╝██╔════╝██║ ██║██╔═══██╗██╔══██╗██║ ██╔╝
|
|
75
|
-
██████╔╝███████║██║ █████╗ ██║ █╗ ██║██║ ██║██████╔╝█████╔╝
|
|
76
|
-
██╔═══╝ ██╔══██║██║ ██╔══╝ ██║███╗██║██║ ██║██╔══██╗██╔═██╗
|
|
77
|
-
██║ ██║ ██║╚██████╗███████╗╚███╔███╔╝╚██████╔╝██║ ██║██║ ██╗
|
|
78
|
-
╚═╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝\x1b[0m`
|
|
77
|
+
const BANNER = `\x1b[38;5;39m${BANNER_LINES.map((line) => ` ${line}`).join("\n")}\x1b[0m`
|
|
79
78
|
|
|
80
79
|
function printBanner(config) {
|
|
81
80
|
const cols = process.stdout.columns || 80
|
|
@@ -84,7 +83,9 @@ function printBanner(config) {
|
|
|
84
83
|
const kv = (label, val) => ` \x1b[2m${label}\x1b[0m \x1b[1m${val}\x1b[0m`
|
|
85
84
|
|
|
86
85
|
console.log("")
|
|
87
|
-
|
|
86
|
+
// The big banner greets a machine that is not signed in yet; after that a
|
|
87
|
+
// one-line logo is enough, so status output stays short.
|
|
88
|
+
console.log(readConfig().apiKey ? ` \x1b[1m\x1b[38;5;39mpacework\x1b[0m \x1b[38;5;240mv${LOCAL_VERSION ?? "?"}\x1b[0m` : BANNER)
|
|
88
89
|
console.log("")
|
|
89
90
|
|
|
90
91
|
if (!config) { console.log(""); return }
|
|
@@ -146,35 +147,6 @@ function fmtDuration(ms) {
|
|
|
146
147
|
return `${Math.floor(s / 60)}m${s % 60}s`
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
// ── executors ─────────────────────────────────────────────────────────────────
|
|
150
|
-
|
|
151
|
-
const EXECUTORS = [
|
|
152
|
-
{ id: "claude_code", label: "Claude Code", bin: "claude" },
|
|
153
|
-
{ id: "codex", label: "Codex (OpenAI)", bin: "codex" },
|
|
154
|
-
{ id: "gemini", label: "Gemini CLI", bin: "gemini" },
|
|
155
|
-
{ id: "cursor_agent", label: "Cursor Agent", bin: "cursor" },
|
|
156
|
-
{ id: "github_copilot", label: "GitHub Copilot", bin: "gh" },
|
|
157
|
-
]
|
|
158
|
-
|
|
159
|
-
const EXECUTOR_DEFAULT_NAMES = {
|
|
160
|
-
claude_code: "Claude Dev",
|
|
161
|
-
codex: "Codex Dev",
|
|
162
|
-
gemini: "Gemini Dev",
|
|
163
|
-
cursor_agent: "Cursor Dev",
|
|
164
|
-
github_copilot: "Copilot Dev",
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function checkBinaryExists(bin) {
|
|
168
|
-
try {
|
|
169
|
-
execFileSync(process.platform === "win32" ? "where" : "which", [bin], { stdio: "ignore" })
|
|
170
|
-
return true
|
|
171
|
-
} catch { return false }
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function executorLabel(id) {
|
|
175
|
-
return EXECUTORS.find(e => e.id === id)?.label ?? id
|
|
176
|
-
}
|
|
177
|
-
|
|
178
150
|
// ── login setup prompts ───────────────────────────────────────────────────────
|
|
179
151
|
|
|
180
152
|
async function promptExecutorSetup() {
|
|
@@ -268,53 +240,101 @@ const parsedArgs = parseCliArgs(restArgs)
|
|
|
268
240
|
|
|
269
241
|
// ── help ──────────────────────────────────────────────────────────────────────
|
|
270
242
|
|
|
271
|
-
if (!command || command === "--help" || command === "-h") {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
pacework start \x1b[2m# run as background daemon\x1b[0m
|
|
243
|
+
if (!command || command === "--help" || command === "-h" || command === "help") {
|
|
244
|
+
const c = (text) => `\x1b[36m${text}\x1b[0m`
|
|
245
|
+
const d = (text) => `\x1b[2m${text}\x1b[0m`
|
|
246
|
+
const row = (command, description) => ` ${c(command.padEnd(30))} ${description}`
|
|
247
|
+
console.log(`\n${BANNER}\n`)
|
|
248
|
+
console.log(` Connect this machine to pacework: agents work on your issues here, and
|
|
249
|
+
your AI tools can read and update pacework.
|
|
250
|
+
|
|
251
|
+
\x1b[1mStart here\x1b[0m
|
|
252
|
+
${row("pacework", "Guided setup the first time, then the live home screen")}
|
|
253
|
+
|
|
254
|
+
\x1b[1mAccount\x1b[0m
|
|
255
|
+
${row("pacework login", "Sign in to a pacework (asks which one)")}
|
|
256
|
+
${row("pacework logout", "Sign out and revoke this machine's key")}
|
|
257
|
+
${row("pacework whoami", "Who and where you are signed in")}
|
|
258
|
+
|
|
259
|
+
\x1b[1mConnect your AI tools\x1b[0m ${d("Claude Code, Codex, Gemini CLI, Cursor, VS Code")}
|
|
260
|
+
${row("pacework mcp add [tool…|--all]", "Give them pacework's tools; they sign in on first use")}
|
|
261
|
+
${row("pacework mcp status", "Which tools are connected")}
|
|
262
|
+
${row("pacework mcp remove [tool…]", "Disconnect tools")}
|
|
263
|
+
|
|
264
|
+
\x1b[1mIssues\x1b[0m
|
|
265
|
+
${row("pacework issues [--mine]", "List open issues, or the ones assigned to you")}
|
|
266
|
+
${row("pacework issues --status S", `Filter: ${d("open, todo, in_progress, in_review, done, …")}`)}
|
|
267
|
+
${row("pacework issue ENG-42", "Show one issue with its latest comments")}
|
|
268
|
+
${row("pacework open [ENG-42]", "Open the workspace or an issue in the browser")}
|
|
269
|
+
|
|
270
|
+
\x1b[1mRunner\x1b[0m ${d("takes development and triage jobs")}
|
|
271
|
+
${row("pacework start | stop", "Start or stop it in the background")}
|
|
272
|
+
${row("pacework status [--json]", "Is it running, and what is it doing")}
|
|
273
|
+
${row("pacework logs [--lines N]", "Follow its log")}
|
|
274
|
+
${row("pacework connect", "Run it in this terminal instead")}
|
|
275
|
+
${row("pacework use <tool>", `Switch AI tool: ${d("claude_code, codex, gemini, cursor_agent, github_copilot")}`)}
|
|
276
|
+
${row("pacework doctor", "Check this machine's setup")}
|
|
277
|
+
${row("pacework triage [--once]", "Only triage, in the foreground")}
|
|
278
|
+
${row("pacework up --token CODE", "One-step setup from the command in pacework's Runners page")}
|
|
279
|
+
${row("pacework down", "Remove the background service")}
|
|
280
|
+
|
|
281
|
+
\x1b[1mRunner flags\x1b[0m ${d("for start, connect and up")}
|
|
282
|
+
--repo-root PATH --executor TOOL --name NAME --max-parallel-runs N --sandbox --no-triage
|
|
312
283
|
`)
|
|
313
284
|
process.exit(0)
|
|
314
285
|
}
|
|
315
286
|
|
|
287
|
+
// ── account, AI tools, issues ─────────────────────────────────────────────────
|
|
288
|
+
|
|
289
|
+
if (["whoami", "issues", "issue", "open", "mcp"].includes(command)) {
|
|
290
|
+
try {
|
|
291
|
+
const api = await import("../lib/workspace-api.mjs")
|
|
292
|
+
if (command === "whoami") {
|
|
293
|
+
const session = api.currentSession()
|
|
294
|
+
await api.workspaceGet("/cli/issues?limit=1")
|
|
295
|
+
console.log(`\n ${session.userName ?? session.userEmail ?? "Signed in"}${session.userName && session.userEmail ? ` \x1b[2m${session.userEmail}\x1b[0m` : ""}`)
|
|
296
|
+
console.log(` workspace \x1b[1m${session.workspaceSlug ?? session.workspaceId}\x1b[0m`)
|
|
297
|
+
console.log(` server ${session.appUrl}`)
|
|
298
|
+
console.log(` key \x1b[2m${session.apiKey.slice(0, 12)}…\x1b[0m \x1b[32mvalid\x1b[0m\n`)
|
|
299
|
+
} else if (command === "issues") {
|
|
300
|
+
const { printIssues } = await import("../lib/issues-cli.mjs")
|
|
301
|
+
const status = parsedArgs.status && parsedArgs.status !== "true" ? parsedArgs.status : (restArgs.find((arg) => !arg.startsWith("--")) ?? "open")
|
|
302
|
+
await printIssues({ mine: Boolean(parsedArgs.mine), status, limit: Number(parsedArgs.limit) || 30 })
|
|
303
|
+
} else if (command === "issue") {
|
|
304
|
+
const identifier = restArgs.find((arg) => !arg.startsWith("--"))
|
|
305
|
+
if (!identifier) throw new Error("Which issue? For example: pacework issue ENG-42")
|
|
306
|
+
const { printIssue } = await import("../lib/issues-cli.mjs")
|
|
307
|
+
await printIssue(identifier)
|
|
308
|
+
} else if (command === "open") {
|
|
309
|
+
const { openInBrowser } = await import("../lib/login.mjs")
|
|
310
|
+
const url = api.workspaceUrl(restArgs.find((arg) => !arg.startsWith("--")))
|
|
311
|
+
console.log(openInBrowser(url) ? `Opened ${url}` : `Open ${url}`)
|
|
312
|
+
} else if (command === "mcp") {
|
|
313
|
+
const { runMcpCommand } = await import("../lib/mcp-cli.mjs")
|
|
314
|
+
const sub = restArgs[0] && !restArgs[0].startsWith("--") ? restArgs[0] : (process.stdin.isTTY ? "add" : "status")
|
|
315
|
+
process.exit(await runMcpCommand(sub, restArgs.slice(1).filter((arg) => !arg.startsWith("--")), parsedArgs))
|
|
316
|
+
}
|
|
317
|
+
process.exit(0)
|
|
318
|
+
} catch (error) {
|
|
319
|
+
console.error(`\x1b[31m${error instanceof Error ? error.message : error}\x1b[0m`)
|
|
320
|
+
process.exit(1)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
316
324
|
// ── login ─────────────────────────────────────────────────────────────────────
|
|
317
325
|
|
|
326
|
+
if (command === "login" && process.stdin.isTTY && !parsedArgs["app-url"] && !parsedArgs["workspace-id"]) {
|
|
327
|
+
// Interactive: pick the server with arrow keys, sign in, and only ask for
|
|
328
|
+
// the folder and AI tool if they were never set.
|
|
329
|
+
const setup = await import("../lib/setup.mjs")
|
|
330
|
+
const { LOGO } = await import("../lib/ui.mjs")
|
|
331
|
+
if (!await setup.switchServer()) process.exit(0)
|
|
332
|
+
if (!readConfig().repoRoot) await setup.changeRepo()
|
|
333
|
+
if (!readConfig().executor) await setup.changeExecutor()
|
|
334
|
+
console.log(`\n${LOGO} Signed in. Run \x1b[1mpacework\x1b[0m to see the runner, or \x1b[1mpacework start\x1b[0m to start it.`)
|
|
335
|
+
process.exit(0)
|
|
336
|
+
}
|
|
337
|
+
|
|
318
338
|
if (command === "login") {
|
|
319
339
|
printBanner()
|
|
320
340
|
const savedUrl = readConfig().appUrl
|
|
@@ -381,8 +401,8 @@ if (command === "login") {
|
|
|
381
401
|
Config : \x1b[2m${CONFIG_FILE}\x1b[0m
|
|
382
402
|
|
|
383
403
|
Start the runner:
|
|
384
|
-
\x1b[36mpacework
|
|
385
|
-
\x1b[36mpacework
|
|
404
|
+
\x1b[36mpacework start\x1b[0m \x1b[2m# in the background\x1b[0m
|
|
405
|
+
\x1b[36mpacework connect\x1b[0m \x1b[2m# in this terminal\x1b[0m
|
|
386
406
|
`)
|
|
387
407
|
process.exit(0)
|
|
388
408
|
}
|
|
@@ -460,7 +480,7 @@ if (command === "use") {
|
|
|
460
480
|
writeConfig(config)
|
|
461
481
|
|
|
462
482
|
console.log(`\x1b[32m✓ Executor switched:\x1b[0m ${executorLabel(prev)} → \x1b[1m${executorLabel(target)}\x1b[0m`)
|
|
463
|
-
console.log(` Restart the runner to apply: \x1b[36mpacework
|
|
483
|
+
console.log(` Restart the runner to apply: \x1b[36mpacework connect\x1b[0m`)
|
|
464
484
|
process.exit(0)
|
|
465
485
|
}
|
|
466
486
|
|
|
@@ -543,7 +563,7 @@ if (command === "doctor") {
|
|
|
543
563
|
// Config
|
|
544
564
|
const config = readConfig()
|
|
545
565
|
if (config.apiKey) ok(`Config found (${CONFIG_FILE})`)
|
|
546
|
-
else { err(`Not logged in — run \x1b[36mpacework
|
|
566
|
+
else { err(`Not logged in — run \x1b[36mpacework login\x1b[0m`); issues++ }
|
|
547
567
|
|
|
548
568
|
if (config.workspaceSlug || config.workspaceId) ok(`Workspace: ${config.workspaceSlug ?? config.workspaceId}`)
|
|
549
569
|
else { err("No workspace saved"); issues++ }
|
|
@@ -588,7 +608,7 @@ if (command === "doctor") {
|
|
|
588
608
|
signal: AbortSignal.timeout(4000),
|
|
589
609
|
})
|
|
590
610
|
if (res.ok) ok("API key valid")
|
|
591
|
-
else { err(`API key rejected (${res.status}) — run \x1b[36mpacework
|
|
611
|
+
else { err(`API key rejected (${res.status}) — run \x1b[36mpacework login\x1b[0m`); issues++ }
|
|
592
612
|
} catch { warn("Could not verify API key (server unreachable)") }
|
|
593
613
|
}
|
|
594
614
|
|
|
@@ -1039,6 +1059,12 @@ else if (command === "stop") {
|
|
|
1039
1059
|
// ── status ────────────────────────────────────────────────────────────────────
|
|
1040
1060
|
|
|
1041
1061
|
else if (command === "status") {
|
|
1062
|
+
if (parsedArgs.json) {
|
|
1063
|
+
// For scripts: the same facts as the home screen, without the raw log or the key.
|
|
1064
|
+
const { logs, ...snapshot } = readRunnerSnapshot({ logLines: 400 })
|
|
1065
|
+
console.log(JSON.stringify({ ...snapshot, signedIn: Boolean(readConfig().apiKey), serviceInstalled: isServiceInstalled(), version: LOCAL_VERSION ?? null }, null, 2))
|
|
1066
|
+
process.exit(0)
|
|
1067
|
+
}
|
|
1042
1068
|
const pid = readPid()
|
|
1043
1069
|
const config = readConfig()
|
|
1044
1070
|
|
|
@@ -1115,155 +1141,42 @@ else if (command === "triage") {
|
|
|
1115
1141
|
console.error("\x1b[31mNot logged in.\x1b[0m Run \x1b[36mpacework login\x1b[0m first (or pass --app-url and --api-key).")
|
|
1116
1142
|
process.exit(1)
|
|
1117
1143
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
const
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
// servers, allowing this interpreter process to execute mutations
|
|
1151
|
-
// itself (and potentially call a stale/remote pacework endpoint).
|
|
1152
|
-
const cliArgs = ["exec", "--ignore-user-config", "--ignore-rules", "--sandbox", "read-only"]
|
|
1153
|
-
if (claudeModel) cliArgs.push("-m", claudeModel)
|
|
1154
|
-
cliArgs.push(
|
|
1155
|
-
"--ephemeral",
|
|
1156
|
-
"--color", "never",
|
|
1157
|
-
"--skip-git-repo-check",
|
|
1158
|
-
"--output-last-message", outputFile,
|
|
1159
|
-
"-",
|
|
1160
|
-
)
|
|
1161
|
-
return { command: codexBinary, args: cliArgs, stdinPayload: prompt, outputFile }
|
|
1162
|
-
}
|
|
1163
|
-
if (triageExecutor === "gemini") {
|
|
1164
|
-
const cliArgs = ["-p", prompt, "--output-format", "text"]
|
|
1165
|
-
if (claudeModel) cliArgs.push("--model", claudeModel)
|
|
1166
|
-
return { command: geminiBinary, args: cliArgs, stdinPayload: null, outputFile: null }
|
|
1167
|
-
}
|
|
1168
|
-
// claude_code (default)
|
|
1169
|
-
// As above, give completion jobs no tools and an explicitly empty MCP
|
|
1170
|
-
// config. The outer pacework Slack agent owns all tool execution.
|
|
1171
|
-
const cliArgs = [
|
|
1172
|
-
"-p",
|
|
1173
|
-
"--output-format", "text",
|
|
1174
|
-
"--strict-mcp-config",
|
|
1175
|
-
"--mcp-config", '{"mcpServers":{}}',
|
|
1176
|
-
"--tools", "",
|
|
1177
|
-
]
|
|
1178
|
-
if (claudeModel) cliArgs.push("--model", claudeModel)
|
|
1179
|
-
return { command: claudeBinary, args: cliArgs, stdinPayload: prompt, outputFile: null }
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
const runExecutorPrompt = (prompt) => new Promise((resolve, reject) => {
|
|
1183
|
-
const spec = buildTriageExecSpec(prompt)
|
|
1184
|
-
const child = spawn(spec.command, spec.args, { stdio: ["pipe", "pipe", "pipe"], env: process.env })
|
|
1185
|
-
let stdout = ""
|
|
1186
|
-
let stderr = ""
|
|
1187
|
-
const timer = setTimeout(() => {
|
|
1188
|
-
child.kill("SIGKILL")
|
|
1189
|
-
reject(new Error(`${spec.command} timed out after ${Math.round(claudeTimeoutMs / 1000)}s`))
|
|
1190
|
-
}, claudeTimeoutMs)
|
|
1191
|
-
const readResult = () => {
|
|
1192
|
-
// Codex writes the final answer to a file; the others stream stdout.
|
|
1193
|
-
if (spec.outputFile) {
|
|
1194
|
-
try {
|
|
1195
|
-
const fileText = fs.readFileSync(spec.outputFile, "utf8").trim()
|
|
1196
|
-
fs.unlinkSync(spec.outputFile)
|
|
1197
|
-
return fileText
|
|
1198
|
-
} catch {
|
|
1199
|
-
return ""
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
return stdout.trim()
|
|
1203
|
-
}
|
|
1204
|
-
child.stdout.on("data", (chunk) => { stdout += chunk })
|
|
1205
|
-
child.stderr.on("data", (chunk) => { stderr += chunk })
|
|
1206
|
-
child.on("error", (error) => {
|
|
1207
|
-
clearTimeout(timer)
|
|
1208
|
-
reject(error.code === "ENOENT"
|
|
1209
|
-
? new Error(`Could not find the "${spec.command}" CLI for executor ${triageExecutor}. Install it or pass --claude-bin/--codex-bin/--gemini-bin.`)
|
|
1210
|
-
: error)
|
|
1211
|
-
})
|
|
1212
|
-
child.on("close", (code) => {
|
|
1213
|
-
clearTimeout(timer)
|
|
1214
|
-
const text = code === 0 ? readResult() : ""
|
|
1215
|
-
if (code === 0 && text) resolve(text)
|
|
1216
|
-
else reject(new Error(`${spec.command} exited with code ${code}: ${stderr.trim().slice(0, 400) || "no output"}`))
|
|
1217
|
-
})
|
|
1218
|
-
if (spec.stdinPayload !== null) child.stdin.write(spec.stdinPayload)
|
|
1219
|
-
child.stdin.end()
|
|
1220
|
-
})
|
|
1221
|
-
|
|
1222
|
-
const processTriageJob = async (job) => {
|
|
1223
|
-
triageLog(`Job ${job.id} claimed; running ${triageExecutor}${claudeModel ? ` (${claudeModel})` : ""}...`)
|
|
1224
|
-
try {
|
|
1225
|
-
const text = await runExecutorPrompt(job.prompt)
|
|
1226
|
-
const complete = await triageApi(`/api/triage-runner/jobs/${job.id}/complete`, {
|
|
1227
|
-
text,
|
|
1228
|
-
model: `${triageExecutor}${claudeModel ? `:${claudeModel}` : ""}`,
|
|
1229
|
-
})
|
|
1230
|
-
if (complete.status >= 400) {
|
|
1231
|
-
triageLog(`\x1b[31mJob ${job.id}: server rejected completion (${complete.status}): ${JSON.stringify(complete.payload)}\x1b[0m`)
|
|
1232
|
-
} else {
|
|
1233
|
-
triageLog(`\x1b[32mJob ${job.id} completed\x1b[0m (confidence: ${complete.payload?.confidence ?? "n/a"})`)
|
|
1234
|
-
}
|
|
1235
|
-
} catch (error) {
|
|
1236
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
1237
|
-
triageLog(`\x1b[31mJob ${job.id} failed: ${message}\x1b[0m`)
|
|
1238
|
-
await triageApi(`/api/triage-runner/jobs/${job.id}/fail`, { error: message }).catch(() => {})
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
triageLog(`Triage runner "${triageRunnerName}" polling ${appUrl} every ${pollIntervalMs / 1000}s (executor: ${triageExecutor})`)
|
|
1243
|
-
let triageStopping = false
|
|
1244
|
-
process.on("SIGINT", () => { triageStopping = true; triageLog("Stopping after current poll...") })
|
|
1245
|
-
process.on("SIGTERM", () => { triageStopping = true })
|
|
1246
|
-
|
|
1247
|
-
while (!triageStopping) {
|
|
1248
|
-
try {
|
|
1249
|
-
const claim = await triageApi("/api/triage-runner/claim", { runner_name: triageRunnerName })
|
|
1250
|
-
if (claim.status === 401 || claim.status === 403) {
|
|
1251
|
-
console.error(`\x1b[31mAuthentication failed (${claim.status}).\x1b[0m Run \x1b[36mpacework login\x1b[0m again.`)
|
|
1144
|
+
// The background runner already does triage alongside development work;
|
|
1145
|
+
// this runs triage on its own, in the foreground.
|
|
1146
|
+
const executor = (parsedArgs.executor || config.executor || "claude_code").trim()
|
|
1147
|
+
const log = (message) => console.log(`\x1b[2m[${new Date().toISOString()}]\x1b[0m ${message}`)
|
|
1148
|
+
let stopping = false
|
|
1149
|
+
process.on("SIGINT", () => { stopping = true; log("Stopping after current poll...") })
|
|
1150
|
+
process.on("SIGTERM", () => { stopping = true })
|
|
1151
|
+
|
|
1152
|
+
await runTriageLoop({
|
|
1153
|
+
appUrl,
|
|
1154
|
+
apiKey,
|
|
1155
|
+
executor,
|
|
1156
|
+
model: parsedArgs.model || process.env.TRIAGE_RUNNER_CLAUDE_MODEL || null,
|
|
1157
|
+
runnerName: parsedArgs.name || process.env.TRIAGE_RUNNER_NAME || `${os.hostname()} triage`,
|
|
1158
|
+
pollIntervalMs: Math.max(2000, Number(parsedArgs["poll-interval-ms"] || process.env.TRIAGE_RUNNER_POLL_INTERVAL_MS || 5000)),
|
|
1159
|
+
timeoutMs: Math.max(30_000, Number(parsedArgs["claude-timeout-ms"] || process.env.TRIAGE_RUNNER_CLAUDE_TIMEOUT_MS || 240_000)),
|
|
1160
|
+
binaries: {
|
|
1161
|
+
claude: parsedArgs["claude-bin"] || process.env.TRIAGE_RUNNER_CLAUDE_BIN,
|
|
1162
|
+
codex: parsedArgs["codex-bin"] || process.env.CODEX_BIN,
|
|
1163
|
+
gemini: parsedArgs["gemini-bin"] || process.env.GEMINI_BIN,
|
|
1164
|
+
},
|
|
1165
|
+
once: (parsedArgs.once || "").toLowerCase() === "true",
|
|
1166
|
+
shouldStop: () => stopping,
|
|
1167
|
+
report: (event, details) => {
|
|
1168
|
+
if (event === "started") log(`Triage runner "${details.runnerName}" polling ${appUrl} every ${details.pollIntervalMs / 1000}s (executor: ${details.executor})`)
|
|
1169
|
+
else if (event === "claimed") log(`Job ${details.job.id} claimed; running ${executor}...`)
|
|
1170
|
+
else if (event === "completed") log(`\x1b[32mJob ${details.job.id} completed\x1b[0m (confidence: ${details.confidence ?? "n/a"})`)
|
|
1171
|
+
else if (event === "rejected") log(`\x1b[31mJob ${details.job.id}: server rejected completion (${details.status}): ${JSON.stringify(details.payload)}\x1b[0m`)
|
|
1172
|
+
else if (event === "failed") log(`\x1b[31mJob ${details.job.id} failed: ${details.message}\x1b[0m`)
|
|
1173
|
+
else if (event === "poll_error") log(`Poll error: ${details.message}`)
|
|
1174
|
+
else if (event === "auth_failed") {
|
|
1175
|
+
console.error(`\x1b[31mAuthentication failed (${details.status}).\x1b[0m Run \x1b[36mpacework login\x1b[0m again.`)
|
|
1252
1176
|
process.exit(1)
|
|
1253
1177
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
} else if (claim.payload?.job) {
|
|
1257
|
-
await processTriageJob(claim.payload.job)
|
|
1258
|
-
if (runOnce) break
|
|
1259
|
-
continue
|
|
1260
|
-
}
|
|
1261
|
-
} catch (error) {
|
|
1262
|
-
triageLog(`Poll error: ${error instanceof Error ? error.message : String(error)}`)
|
|
1263
|
-
}
|
|
1264
|
-
if (runOnce) break
|
|
1265
|
-
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs))
|
|
1266
|
-
}
|
|
1178
|
+
},
|
|
1179
|
+
})
|
|
1267
1180
|
process.exit(0)
|
|
1268
1181
|
}
|
|
1269
1182
|
|
|
@@ -1274,125 +1187,21 @@ else if (command === "triage") {
|
|
|
1274
1187
|
// Every action shells out to this same CLI, so menu and commands never drift.
|
|
1275
1188
|
|
|
1276
1189
|
else if (command === "menu") {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1190
|
+
// `pacework` in a terminal: guided setup the first time, then the live home
|
|
1191
|
+
// screen. Both load the prompt library lazily, so the background service,
|
|
1192
|
+
// which never comes through here, does not depend on it.
|
|
1193
|
+
const { runSetup } = await import("../lib/setup.mjs")
|
|
1194
|
+
const { runHome } = await import("../lib/home.mjs")
|
|
1195
|
+
const ctlScript = fileURLToPath(import.meta.url)
|
|
1196
|
+
const startRunner = () => new Promise((resolve) => {
|
|
1197
|
+
const child = spawn(process.execPath, [ctlScript, "start"], { stdio: "ignore" })
|
|
1198
|
+
child.on("close", (code) => resolve(code === 0))
|
|
1199
|
+
child.on("error", () => resolve(false))
|
|
1281
1200
|
})
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
console.log("")
|
|
1285
|
-
options.forEach((option, index) => {
|
|
1286
|
-
const marker = index === defaultIndex ? "\x1b[36m" : ""
|
|
1287
|
-
console.log(` ${marker}${index + 1}. ${option}\x1b[0m`)
|
|
1288
|
-
})
|
|
1289
|
-
const answer = (await promptLine(`${question} (default ${defaultIndex + 1}, q to cancel): `)).trim()
|
|
1290
|
-
if (/^q(uit)?$/i.test(answer)) return -1
|
|
1291
|
-
const picked = answer ? Number(answer) - 1 : defaultIndex
|
|
1292
|
-
return Number.isInteger(picked) && picked >= 0 && picked < options.length ? picked : defaultIndex
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
const TRIAGE_MODELS = {
|
|
1296
|
-
claude_code: ["CLI default", "haiku", "sonnet", "opus"],
|
|
1297
|
-
codex: ["CLI default", "gpt-5.5", "gpt-5.5-pro"],
|
|
1298
|
-
gemini: ["CLI default", "gemini-2.5-flash", "gemini-2.5-pro"],
|
|
1201
|
+
if (!readConfig().apiKey) {
|
|
1202
|
+
if (!await runSetup({ startRunner })) process.exit(0)
|
|
1299
1203
|
}
|
|
1300
|
-
|
|
1301
|
-
const guidedTriage = async (config) => {
|
|
1302
|
-
const executors = ["claude_code", "codex", "gemini"]
|
|
1303
|
-
const executorLabels = {
|
|
1304
|
-
claude_code: "Claude Code (Claude subscription)",
|
|
1305
|
-
codex: "Codex (ChatGPT subscription)",
|
|
1306
|
-
gemini: "Gemini CLI",
|
|
1307
|
-
}
|
|
1308
|
-
const defaultExecutorIndex = Math.max(0, executors.indexOf(config.executor))
|
|
1309
|
-
const executorIndex = await choose(
|
|
1310
|
-
"Which AI runs triage jobs?",
|
|
1311
|
-
executors.map((name) => executorLabels[name]),
|
|
1312
|
-
defaultExecutorIndex,
|
|
1313
|
-
)
|
|
1314
|
-
if (executorIndex < 0) return
|
|
1315
|
-
const executor = executors[executorIndex]
|
|
1316
|
-
|
|
1317
|
-
const models = TRIAGE_MODELS[executor] ?? ["CLI default"]
|
|
1318
|
-
const modelIndex = await choose("Which model?", models, 0)
|
|
1319
|
-
if (modelIndex < 0) return
|
|
1320
|
-
const model = modelIndex === 0 ? null : models[modelIndex]
|
|
1321
|
-
|
|
1322
|
-
const modeIndex = await choose("How should it run?", [
|
|
1323
|
-
"Keep running (poll for jobs until Ctrl-C)",
|
|
1324
|
-
"Process one job, then exit",
|
|
1325
|
-
], 0)
|
|
1326
|
-
if (modeIndex < 0) return
|
|
1327
|
-
|
|
1328
|
-
const childArgs = ["triage", "--executor", executor]
|
|
1329
|
-
if (model) childArgs.push("--model", model)
|
|
1330
|
-
if (modeIndex === 1) childArgs.push("--once", "true")
|
|
1331
|
-
console.log(`\n\x1b[2m→ pacework triage ${childArgs.slice(1).join(" ")}\x1b[0m\n`)
|
|
1332
|
-
await runChild(childArgs)
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
const guidedAgentRunner = async () => {
|
|
1336
|
-
const modeIndex = await choose("How should the agent runner run?", [
|
|
1337
|
-
"Background daemon (keeps running after this menu closes)",
|
|
1338
|
-
"Foreground (watch output, Ctrl-C to stop)",
|
|
1339
|
-
], 0)
|
|
1340
|
-
if (modeIndex < 0) return
|
|
1341
|
-
await runChild([modeIndex === 0 ? "start" : "connect"])
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
let menuRunning = true
|
|
1345
|
-
while (menuRunning) {
|
|
1346
|
-
const config = readConfig()
|
|
1347
|
-
console.clear()
|
|
1348
|
-
printBanner(config)
|
|
1349
|
-
if (config.apiKey) {
|
|
1350
|
-
console.log(` Workspace: \x1b[1m${config.workspaceSlug ?? config.workspaceId ?? "?"}\x1b[0m Executor: \x1b[1m${executorLabel(config.executor) ?? config.executor ?? "not set"}\x1b[0m`)
|
|
1351
|
-
} else {
|
|
1352
|
-
console.log(" \x1b[33mNot logged in yet — pick “Log in” to get started.\x1b[0m")
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
const loggedIn = Boolean(config.apiKey)
|
|
1356
|
-
const entries = loggedIn
|
|
1357
|
-
? [
|
|
1358
|
-
{ label: "Run triage (pacework Intelligence on this machine)", action: () => guidedTriage(config) },
|
|
1359
|
-
{ label: "Run the agent runner (works on issues)", action: guidedAgentRunner },
|
|
1360
|
-
{ label: "Status", action: () => runChild(["status"]) },
|
|
1361
|
-
{ label: "Recent jobs", action: () => runChild(["jobs"]) },
|
|
1362
|
-
{ label: "Tail runner logs", action: () => runChild(["logs"]) },
|
|
1363
|
-
{ label: "Stop background runner", action: () => runChild(["stop"]) },
|
|
1364
|
-
{ label: "Health check (doctor)", action: () => runChild(["doctor"]) },
|
|
1365
|
-
{ label: "Switch executor", action: async () => {
|
|
1366
|
-
const executorIndex = await choose(
|
|
1367
|
-
"Which executor?",
|
|
1368
|
-
EXECUTORS.map((executor) => `${executor.label}${checkBinaryExists(executor.bin) ? "" : " (not installed)"}`),
|
|
1369
|
-
Math.max(0, EXECUTORS.findIndex((executor) => executor.id === config.executor)),
|
|
1370
|
-
)
|
|
1371
|
-
if (executorIndex < 0) return
|
|
1372
|
-
await runChild(["use", EXECUTORS[executorIndex].id])
|
|
1373
|
-
} },
|
|
1374
|
-
{ label: "Log in again / switch server or workspace", action: () => runChild(["login"]) },
|
|
1375
|
-
{ label: "Log out", action: () => runChild(["logout"]) },
|
|
1376
|
-
{ label: "Quit", action: null },
|
|
1377
|
-
]
|
|
1378
|
-
: [
|
|
1379
|
-
{ label: "Log in (opens your browser)", action: () => runChild(["login"]) },
|
|
1380
|
-
{ label: "Status", action: () => runChild(["status"]) },
|
|
1381
|
-
{ label: "Quit", action: null },
|
|
1382
|
-
]
|
|
1383
|
-
|
|
1384
|
-
const pickedIndex = await choose("What do you want to do?", entries.map((entry) => entry.label), 0)
|
|
1385
|
-
const picked = pickedIndex < 0 ? entries[entries.length - 1] : entries[pickedIndex]
|
|
1386
|
-
if (!picked.action) {
|
|
1387
|
-
menuRunning = false
|
|
1388
|
-
break
|
|
1389
|
-
}
|
|
1390
|
-
await picked.action()
|
|
1391
|
-
if (menuRunning) {
|
|
1392
|
-
await promptLine("\n\x1b[2mPress Enter to return to the menu…\x1b[0m")
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
process.exit(0)
|
|
1204
|
+
await runHome({ ctlScript, version: LOCAL_VERSION })
|
|
1396
1205
|
}
|
|
1397
1206
|
|
|
1398
1207
|
else if (command === "shell" || command === "sh") {
|
|
@@ -2675,7 +2484,7 @@ else if (command === "shell" || command === "sh") {
|
|
|
2675
2484
|
const slug = config.workspaceSlug ?? config.workspaceId ?? ""
|
|
2676
2485
|
const issueId = args[0]
|
|
2677
2486
|
const url = issueId
|
|
2678
|
-
? (slug ? `${base}/${slug}/
|
|
2487
|
+
? (slug ? `${base}/${slug}/issue/${issueId.toUpperCase()}` : base)
|
|
2679
2488
|
: (slug ? `${base}/${slug}` : base)
|
|
2680
2489
|
console.log(`Opening \x1b[36m${url}\x1b[0m`)
|
|
2681
2490
|
const opener = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open"
|