pacework 1.1.0 → 1.4.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 +91 -60
- package/bin/pacework-runner.mjs +628 -95
- package/lib/automation-limits.mjs +23 -0
- package/lib/git-lock.mjs +83 -0
- package/lib/home.mjs +63 -6
- package/lib/issues-cli.mjs +80 -0
- package/lib/mcp-cli.mjs +177 -0
- package/lib/mcp-connect.mjs +159 -0
- package/lib/pr-base-branch.mjs +84 -0
- package/lib/push-retry.mjs +108 -0
- package/lib/run-limits.mjs +302 -0
- package/lib/runner-control.mjs +55 -0
- package/lib/skills.mjs +130 -0
- package/lib/triage-worker.mjs +29 -4
- package/lib/ui.mjs +11 -1
- package/lib/usage-limit.mjs +23 -0
- package/lib/version.mjs +27 -0
- package/lib/workspace-api.mjs +47 -0
- package/package.json +1 -1
package/lib/triage-worker.mjs
CHANGED
|
@@ -79,7 +79,12 @@ function runExecutorPrompt(options, prompt) {
|
|
|
79
79
|
/**
|
|
80
80
|
* Polls until `shouldStop()` returns true (or after one job with `once`).
|
|
81
81
|
* `report(event, details)` receives: started, claimed, completed, failed,
|
|
82
|
-
* rejected, poll_error and
|
|
82
|
+
* rejected, poll_error, auth_failed and auth_recovered; callers turn those
|
|
83
|
+
* into log lines.
|
|
84
|
+
*
|
|
85
|
+
* A rejected key does not end the loop. It used to: triage stopped for good
|
|
86
|
+
* while the runner stayed online, so requests went untriaged with nothing
|
|
87
|
+
* looking wrong (PWK-113). Polling slows to `authRetryMs` until the key works.
|
|
83
88
|
*/
|
|
84
89
|
export async function runTriageLoop({
|
|
85
90
|
appUrl,
|
|
@@ -88,6 +93,7 @@ export async function runTriageLoop({
|
|
|
88
93
|
model = null,
|
|
89
94
|
runnerName = `${os.hostname()} triage`,
|
|
90
95
|
pollIntervalMs = 5000,
|
|
96
|
+
authRetryMs = 5 * 60_000,
|
|
91
97
|
timeoutMs = 240_000,
|
|
92
98
|
binaries = {},
|
|
93
99
|
once = false,
|
|
@@ -132,12 +138,23 @@ export async function runTriageLoop({
|
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
report("started", { runnerName, executor, model, pollIntervalMs })
|
|
141
|
+
/** Set while the server rejects the key; reported once per streak. */
|
|
142
|
+
let authFailedSince = null
|
|
135
143
|
while (!shouldStop()) {
|
|
136
144
|
try {
|
|
137
145
|
const claim = await api("/api/triage-runner/claim", { runner_name: runnerName })
|
|
138
146
|
if (claim.status === 401 || claim.status === 403) {
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
if (authFailedSince === null) {
|
|
148
|
+
authFailedSince = Date.now()
|
|
149
|
+
report("auth_failed", { status: claim.status, retryMs: authRetryMs })
|
|
150
|
+
}
|
|
151
|
+
if (once) return
|
|
152
|
+
await sleep(authRetryMs, shouldStop)
|
|
153
|
+
continue
|
|
154
|
+
}
|
|
155
|
+
if (authFailedSince !== null) {
|
|
156
|
+
report("auth_recovered", { downMs: Date.now() - authFailedSince })
|
|
157
|
+
authFailedSince = null
|
|
141
158
|
}
|
|
142
159
|
if (claim.status >= 400) {
|
|
143
160
|
report("poll_error", { message: `claim failed (${claim.status}): ${JSON.stringify(claim.payload)}` })
|
|
@@ -150,6 +167,14 @@ export async function runTriageLoop({
|
|
|
150
167
|
report("poll_error", { message: error instanceof Error ? error.message : String(error) })
|
|
151
168
|
}
|
|
152
169
|
if (once) return
|
|
153
|
-
await
|
|
170
|
+
await sleep(pollIntervalMs, shouldStop)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Waits up to `ms`, waking early once `shouldStop()` turns true. */
|
|
175
|
+
async function sleep(ms, shouldStop) {
|
|
176
|
+
const until = Date.now() + ms
|
|
177
|
+
while (Date.now() < until && !shouldStop()) {
|
|
178
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(1000, until - Date.now())))
|
|
154
179
|
}
|
|
155
180
|
}
|
package/lib/ui.mjs
CHANGED
|
@@ -19,9 +19,19 @@ export const style = {
|
|
|
19
19
|
inverse: paint(7, 27),
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/** The one-line wordmark
|
|
22
|
+
/** The one-line wordmark, for places too small for the banner. */
|
|
23
23
|
export const LOGO = style.bold(style.brand("pacework"))
|
|
24
24
|
|
|
25
|
+
/** The big PACEWORK banner (ANSI Shadow), 67 columns wide. */
|
|
26
|
+
export const BANNER_LINES = [
|
|
27
|
+
"██████╗ █████╗ ██████╗███████╗██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗",
|
|
28
|
+
"██╔══██╗██╔══██╗██╔════╝██╔════╝██║ ██║██╔═══██╗██╔══██╗██║ ██╔╝",
|
|
29
|
+
"██████╔╝███████║██║ █████╗ ██║ █╗ ██║██║ ██║██████╔╝█████╔╝ ",
|
|
30
|
+
"██╔═══╝ ██╔══██║██║ ██╔══╝ ██║███╗██║██║ ██║██╔══██╗██╔═██╗ ",
|
|
31
|
+
"██║ ██║ ██║╚██████╗███████╗╚███╔███╔╝╚██████╔╝██║ ██║██║ ██╗",
|
|
32
|
+
"╚═╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝",
|
|
33
|
+
]
|
|
34
|
+
|
|
25
35
|
export function visibleLength(text) {
|
|
26
36
|
return String(text).replace(/\x1b\[[0-9;]*m/g, "").length
|
|
27
37
|
}
|
package/lib/usage-limit.mjs
CHANGED
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
// out: an agent working on rate limiting says it all the time.
|
|
11
11
|
const LIMIT_PATTERN = /usage limit|hit your (?:usage )?limit|limit reached|quota exceeded|insufficient_quota|credit balance is too low|\b429\b[^\n]{0,40}rate.?limit|rate.?limit[^\n]{0,40}\b429\b/i
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* How a run stopped by a usage limit starts its error message. The server
|
|
15
|
+
* treats a failure as a usage limit only when it starts with this, so keep it
|
|
16
|
+
* in step with USAGE_LIMIT_MARKER in backend control-plane/runner-usage-limit.ts.
|
|
17
|
+
*/
|
|
18
|
+
export const USAGE_LIMIT_MARKER = "Usage limit reached on "
|
|
19
|
+
|
|
13
20
|
/** When the limit is not stated, wait this long before trying again. */
|
|
14
21
|
export const DEFAULT_LIMIT_WAIT_MS = 30 * 60_000
|
|
15
22
|
|
|
@@ -29,6 +36,22 @@ export function detectUsageLimit(text, now = new Date()) {
|
|
|
29
36
|
: { resetAt: new Date(now.getTime() + DEFAULT_LIMIT_WAIT_MS), stated: false }
|
|
30
37
|
}
|
|
31
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The usage limit that stopped a failed run, or null.
|
|
41
|
+
*
|
|
42
|
+
* Only the AI tool can hit a usage limit, so only a failure while it was
|
|
43
|
+
* running is looked at. A failure after it finished (the tripwire, a commit, a
|
|
44
|
+
* push or pull request on GitHub) is never one, whatever the tool's final
|
|
45
|
+
* words or the git error happen to say.
|
|
46
|
+
*
|
|
47
|
+
* @param {{ phase: "before" | "running" | "finished", canceled?: boolean, text: string }} failure
|
|
48
|
+
* `phase` is where the run was when it failed, relative to the AI tool.
|
|
49
|
+
*/
|
|
50
|
+
export function detectRunUsageLimit({ phase, canceled = false, text }, now = new Date()) {
|
|
51
|
+
if (canceled || phase !== "running") return null
|
|
52
|
+
return detectUsageLimit(text, now)
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
function parseResetTime(text, now) {
|
|
33
56
|
// Claude Code: "Claude AI usage limit reached|1761058800" (epoch seconds).
|
|
34
57
|
const epoch = text.match(/limit reached\|(\d{10})\b/i)
|
package/lib/version.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's own npm package. The update check and `pacework update` both use
|
|
3
|
+
* this name: they used to ask for "pacework-runner", a name nobody owns, so no
|
|
4
|
+
* one was told about updates and `pacework update` would have installed
|
|
5
|
+
* whatever someone published under that name.
|
|
6
|
+
*/
|
|
7
|
+
export const NPM_PACKAGE = "pacework"
|
|
8
|
+
|
|
9
|
+
/** True when version a is newer than b (plain x.y.z; anything else counts as not newer). */
|
|
10
|
+
export function isNewerVersion(a, b) {
|
|
11
|
+
const parse = (value) => /^\d+\.\d+\.\d+$/.test(String(value)) ? String(value).split(".").map(Number) : null
|
|
12
|
+
const left = parse(a)
|
|
13
|
+
const right = parse(b)
|
|
14
|
+
if (!left || !right) return false
|
|
15
|
+
for (let index = 0; index < 3; index++) {
|
|
16
|
+
if (left[index] !== right[index]) return left[index] > right[index]
|
|
17
|
+
}
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The latest published version, or null when the registry cannot be reached. */
|
|
22
|
+
export async function latestPublishedVersion(fetchImpl = fetch) {
|
|
23
|
+
const res = await fetchImpl(`https://registry.npmjs.org/${NPM_PACKAGE}/latest`, { signal: AbortSignal.timeout(4000) })
|
|
24
|
+
if (!res.ok) return null
|
|
25
|
+
const { version } = await res.json()
|
|
26
|
+
return typeof version === "string" ? version : null
|
|
27
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { readConfig } from "./control-state.mjs"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calls to the signed-in workspace with the CLI's workspace API key. Errors
|
|
5
|
+
* carry a message that says what to do next, so commands can print it as is.
|
|
6
|
+
*/
|
|
7
|
+
export class NotSignedInError extends Error {}
|
|
8
|
+
|
|
9
|
+
export function currentSession() {
|
|
10
|
+
const config = readConfig()
|
|
11
|
+
if (!config.apiKey || !config.workspaceId) throw new NotSignedInError("Not signed in. Run `pacework login`.")
|
|
12
|
+
return {
|
|
13
|
+
appUrl: String(config.appUrl || "https://pacework.io").replace(/\/$/, ""),
|
|
14
|
+
apiKey: config.apiKey,
|
|
15
|
+
workspaceId: config.workspaceId,
|
|
16
|
+
workspaceSlug: config.workspaceSlug ?? null,
|
|
17
|
+
userName: config.userName ?? null,
|
|
18
|
+
userEmail: config.userEmail ?? null,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function workspaceGet(route) {
|
|
23
|
+
const session = currentSession()
|
|
24
|
+
let res
|
|
25
|
+
try {
|
|
26
|
+
res = await fetch(`${session.appUrl}/api/workspaces/${session.workspaceId}${route}`, {
|
|
27
|
+
headers: { "x-workspace-api-key": session.apiKey },
|
|
28
|
+
})
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(`Could not reach ${session.appUrl} (${error instanceof Error ? error.message : error}).`)
|
|
31
|
+
}
|
|
32
|
+
if (res.status === 401) throw new NotSignedInError("Your sign-in is no longer valid. Run `pacework login`.")
|
|
33
|
+
const body = await res.json().catch(() => ({}))
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
const error = new Error(body.error || `${session.appUrl} answered ${res.status}.`)
|
|
36
|
+
error.status = res.status
|
|
37
|
+
throw error
|
|
38
|
+
}
|
|
39
|
+
return body
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Web address of the workspace, or of one issue in it. */
|
|
43
|
+
export function workspaceUrl(issueIdentifier) {
|
|
44
|
+
const session = currentSession()
|
|
45
|
+
const base = `${session.appUrl}/${session.workspaceSlug ?? session.workspaceId}`
|
|
46
|
+
return issueIdentifier ? `${base}/issue/${encodeURIComponent(issueIdentifier.toUpperCase())}` : base
|
|
47
|
+
}
|