@mycompbox/compbox-cli 1.21.9 → 1.21.11

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.
Files changed (85) hide show
  1. package/.tsbuildinfo +1 -1
  2. package/commands/list.js +1 -1
  3. package/commands/list.js.map +1 -1
  4. package/commands/machines.d.ts +4 -0
  5. package/commands/machines.d.ts.map +1 -1
  6. package/commands/machines.js +61 -2
  7. package/commands/machines.js.map +1 -1
  8. package/commands/run.d.ts +27 -1
  9. package/commands/run.d.ts.map +1 -1
  10. package/commands/run.js +182 -36
  11. package/commands/run.js.map +1 -1
  12. package/commands/update.d.ts +19 -0
  13. package/commands/update.d.ts.map +1 -1
  14. package/commands/update.js +124 -7
  15. package/commands/update.js.map +1 -1
  16. package/commands/workspace.d.ts.map +1 -1
  17. package/commands/workspace.js +13 -1
  18. package/commands/workspace.js.map +1 -1
  19. package/index.js +4983 -1505
  20. package/index.js.map +1 -1
  21. package/package.json +1 -1
  22. package/utils/agent-invoker.d.ts +264 -31
  23. package/utils/agent-invoker.d.ts.map +1 -1
  24. package/utils/agent-invoker.js +1013 -372
  25. package/utils/agent-invoker.js.map +1 -1
  26. package/utils/brew.d.ts +10 -0
  27. package/utils/brew.d.ts.map +1 -1
  28. package/utils/brew.js +14 -0
  29. package/utils/brew.js.map +1 -1
  30. package/utils/cli-version.d.ts +3 -0
  31. package/utils/cli-version.d.ts.map +1 -0
  32. package/utils/cli-version.js +18 -0
  33. package/utils/cli-version.js.map +1 -0
  34. package/utils/cloud-preflight.d.ts +68 -0
  35. package/utils/cloud-preflight.d.ts.map +1 -0
  36. package/utils/cloud-preflight.js +287 -0
  37. package/utils/cloud-preflight.js.map +1 -0
  38. package/utils/config-store.d.ts +29 -0
  39. package/utils/config-store.d.ts.map +1 -1
  40. package/utils/config-store.js +30 -0
  41. package/utils/config-store.js.map +1 -1
  42. package/utils/install-cache.d.ts +105 -0
  43. package/utils/install-cache.d.ts.map +1 -0
  44. package/utils/install-cache.js +184 -0
  45. package/utils/install-cache.js.map +1 -0
  46. package/utils/mailbox-client.d.ts +130 -3
  47. package/utils/mailbox-client.d.ts.map +1 -1
  48. package/utils/mailbox-client.js +140 -6
  49. package/utils/mailbox-client.js.map +1 -1
  50. package/utils/merge-guard.d.ts +66 -0
  51. package/utils/merge-guard.d.ts.map +1 -0
  52. package/utils/merge-guard.js +271 -0
  53. package/utils/merge-guard.js.map +1 -0
  54. package/utils/merge-policy.d.ts +68 -0
  55. package/utils/merge-policy.d.ts.map +1 -0
  56. package/utils/merge-policy.js +129 -0
  57. package/utils/merge-policy.js.map +1 -0
  58. package/utils/progress-watcher.d.ts +53 -0
  59. package/utils/progress-watcher.d.ts.map +1 -0
  60. package/utils/progress-watcher.js +109 -0
  61. package/utils/progress-watcher.js.map +1 -0
  62. package/utils/project-checks.d.ts +72 -0
  63. package/utils/project-checks.d.ts.map +1 -0
  64. package/utils/project-checks.js +276 -0
  65. package/utils/project-checks.js.map +1 -0
  66. package/utils/run-timings.d.ts +59 -0
  67. package/utils/run-timings.d.ts.map +1 -0
  68. package/utils/run-timings.js +130 -0
  69. package/utils/run-timings.js.map +1 -0
  70. package/utils/run-workspace.d.ts +200 -2
  71. package/utils/run-workspace.d.ts.map +1 -1
  72. package/utils/run-workspace.js +898 -136
  73. package/utils/run-workspace.js.map +1 -1
  74. package/utils/self-update.d.ts +104 -0
  75. package/utils/self-update.d.ts.map +1 -0
  76. package/utils/self-update.js +391 -0
  77. package/utils/self-update.js.map +1 -0
  78. package/utils/usage-limit.d.ts +30 -0
  79. package/utils/usage-limit.d.ts.map +1 -0
  80. package/utils/usage-limit.js +186 -0
  81. package/utils/usage-limit.js.map +1 -0
  82. package/utils/wrap-up.d.ts +109 -0
  83. package/utils/wrap-up.d.ts.map +1 -0
  84. package/utils/wrap-up.js +260 -0
  85. package/utils/wrap-up.js.map +1 -0
@@ -0,0 +1,184 @@
1
+ /**
2
+ * ENG-349: reuse installed packages between runs.
3
+ *
4
+ * Every run gets a fresh worktree, so without a shared package store each run
5
+ * downloads its dependencies again. This module holds the pure pieces:
6
+ *
7
+ * - which lockfile/package manager a folder uses,
8
+ * - the per-project store folder (`<configDir>/stores/<projectKey>`),
9
+ * - the install marker (`install.json`: lockfile hash + package-manager
10
+ * version) that says "this store already has everything this lockfile
11
+ * needs", so the next run can install offline from it,
12
+ * - which kept run folders are stale enough to prune.
13
+ *
14
+ * Side effects (running installs, removing worktrees) stay in run-workspace.ts.
15
+ */
16
+ import { createHash } from "node:crypto";
17
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
18
+ import { basename, join } from "node:path";
19
+ /** The lockfile each package manager is picked by, in priority order. */
20
+ export const LOCKFILES = [
21
+ ["pnpm-lock.yaml", "pnpm"],
22
+ ["package-lock.json", "npm"],
23
+ ["yarn.lock", "yarn"],
24
+ ];
25
+ /** The lockfile in `dir` and its package manager, or null when there is none. */
26
+ export function detectLockfile(dir, exists) {
27
+ for (const [file, pm] of LOCKFILES) {
28
+ const path = join(dir, file);
29
+ if (exists(path))
30
+ return { lockfile: path, pm };
31
+ }
32
+ return null;
33
+ }
34
+ /** True for Yarn classic (1.x) version strings. Pure. */
35
+ export function isYarnClassic(pmVersion) {
36
+ return /^v?1\./.test((pmVersion ?? "").trim());
37
+ }
38
+ /** The install argv for a package manager. Pure. */
39
+ export function installArgs(pm, opts = {}) {
40
+ const { storeDir, offline, pmVersion } = opts;
41
+ switch (pm) {
42
+ case "pnpm":
43
+ return [
44
+ "install",
45
+ ...(offline ? ["--offline"] : []),
46
+ "--frozen-lockfile",
47
+ ...(offline ? [] : ["--prefer-offline"]),
48
+ ...(storeDir ? ["--store-dir", storeDir] : []),
49
+ ];
50
+ case "npm":
51
+ return [
52
+ "ci",
53
+ offline ? "--offline" : "--prefer-offline",
54
+ ...(storeDir ? ["--cache", storeDir] : []),
55
+ ];
56
+ case "yarn":
57
+ if (!isYarnClassic(pmVersion))
58
+ return ["install", "--frozen-lockfile"];
59
+ return [
60
+ "install",
61
+ "--frozen-lockfile",
62
+ ...(offline ? ["--offline"] : []),
63
+ ...(storeDir ? ["--cache-folder", storeDir] : []),
64
+ ];
65
+ }
66
+ }
67
+ /** A short, folder-safe key for a project checkout: its name plus a hash of its path. */
68
+ export function projectKey(projectDir) {
69
+ const name = basename(projectDir.replace(/\/+$/, "")).replace(/[^A-Za-z0-9._-]+/g, "-") || "project";
70
+ const hash = createHash("sha256").update(projectDir).digest("hex").slice(0, 10);
71
+ return `${name}-${hash}`;
72
+ }
73
+ export function storeDirFor(storesRoot, projectDir) {
74
+ return join(storesRoot, projectKey(projectDir));
75
+ }
76
+ export const MARKER_FILE = "install.json";
77
+ export function hashLockfile(contents) {
78
+ return createHash("sha256").update(contents).digest("hex");
79
+ }
80
+ export function readInstallMarker(storeDir) {
81
+ try {
82
+ const parsed = JSON.parse(readFileSync(join(storeDir, MARKER_FILE), "utf-8"));
83
+ if (typeof parsed.lockHash !== "string" || typeof parsed.pmVersion !== "string")
84
+ return null;
85
+ return { lockHash: parsed.lockHash, pmVersion: parsed.pmVersion, at: parsed.at ?? "" };
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ }
91
+ export function writeInstallMarker(storeDir, marker) {
92
+ mkdirSync(storeDir, { recursive: true });
93
+ writeFileSync(join(storeDir, MARKER_FILE), `${JSON.stringify(marker, null, 2)}\n`);
94
+ }
95
+ /** True when the store already holds exactly what this lockfile needs. */
96
+ export function markerMatches(marker, lockHash, pmVersion) {
97
+ return marker !== null && marker.lockHash === lockHash && marker.pmVersion === pmVersion && pmVersion !== "";
98
+ }
99
+ /**
100
+ * Which candidates are old enough and unused enough to prune. Cleanliness and
101
+ * unpushed commits are checked afterwards with git. Pure.
102
+ */
103
+ export function selectStaleRuns(candidates, nowMs, retentionMs) {
104
+ return candidates
105
+ .filter((c) => !c.active && !c.waiting && c.mtimeMs !== null && nowMs - c.mtimeMs > retentionMs)
106
+ .map((c) => c.dir);
107
+ }
108
+ /** Worktree paths from `git worktree list --porcelain`. */
109
+ export function parseWorktreeList(porcelain) {
110
+ return porcelain
111
+ .split("\n")
112
+ .filter((line) => line.startsWith("worktree "))
113
+ .map((line) => line.slice("worktree ".length).trim())
114
+ .filter(Boolean);
115
+ }
116
+ /** Sibling marker that a run folder is kept for a waiting job's reply (ENG-E63). */
117
+ export function waitingMarkerPath(runDir) {
118
+ return `${runDir.replace(/\/+$/, "")}.waiting`;
119
+ }
120
+ /** Sibling marker that a run folder is in use by a running job (pid + startedAt). */
121
+ export function activeMarkerPath(runDir) {
122
+ return `${runDir.replace(/\/+$/, "")}.active`;
123
+ }
124
+ export function formatActiveMarker(marker) {
125
+ return `${JSON.stringify(marker)}\n`;
126
+ }
127
+ /** Parses a `.active` marker; null when unreadable. Pure. */
128
+ export function parseActiveMarker(text) {
129
+ if (text === null)
130
+ return null;
131
+ try {
132
+ const parsed = JSON.parse(text);
133
+ if (typeof parsed.pid !== "number" || !Number.isInteger(parsed.pid))
134
+ return null;
135
+ return { pid: parsed.pid, startedAt: typeof parsed.startedAt === "string" ? parsed.startedAt : "" };
136
+ }
137
+ catch {
138
+ return null;
139
+ }
140
+ }
141
+ /** How long a `.active` marker protects its folder even when its process is gone. */
142
+ export const ACTIVE_MARKER_GRACE_MS = 24 * 3_600_000;
143
+ /** True when a process with this pid exists (signal 0 only checks). */
144
+ export function pidAlive(pid) {
145
+ if (!Number.isInteger(pid) || pid <= 0)
146
+ return false;
147
+ try {
148
+ process.kill(pid, 0);
149
+ return true;
150
+ }
151
+ catch (err) {
152
+ // EPERM: it exists but belongs to someone else.
153
+ return err.code === "EPERM";
154
+ }
155
+ }
156
+ /**
157
+ * Whether a `.active` marker still protects its folder: its process is alive,
158
+ * or the marker (or folder) was touched within the grace window. A marker
159
+ * that exists but can't be parsed protects the folder too (fail safe). Pure
160
+ * apart from `isAlive`.
161
+ */
162
+ export function activeMarkerProtects(input) {
163
+ if (!input.exists)
164
+ return false;
165
+ if (!input.marker)
166
+ return true;
167
+ if (input.isAlive(input.marker.pid))
168
+ return true;
169
+ const started = Date.parse(input.marker.startedAt);
170
+ const touched = Math.max(Number.isNaN(started) ? 0 : started, input.markerMtimeMs ?? 0);
171
+ return input.nowMs - touched < ACTIVE_MARKER_GRACE_MS;
172
+ }
173
+ /**
174
+ * `.active`/`.waiting` marker files in the runs folder whose run folder no
175
+ * longer exists. Pure: `entries` are the runs folder's entry names.
176
+ */
177
+ export function orphanMarkers(entries) {
178
+ const names = new Set(entries);
179
+ return entries.filter((name) => {
180
+ const m = /^(.+)\.(active|waiting)$/.exec(name);
181
+ return m !== null && !names.has(m[1] ?? "");
182
+ });
183
+ }
184
+ //# sourceMappingURL=install-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-cache.js","sourceRoot":"","sources":["../../src/utils/install-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAI3C,yEAAyE;AACzE,MAAM,CAAC,MAAM,SAAS,GAAmD;IACvE,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAC1B,CAAC,mBAAmB,EAAE,KAAK,CAAC;IAC5B,CAAC,WAAW,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAC5B,GAAW,EACX,MAAiC;IAEjC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,MAAM,CAAC,IAAI,CAAC;YAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAClD,CAAC;IACD,OAAO,IAAI,CAAC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O,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -57,6 +57,11 @@ export interface MachineSummary {
57
57
  * value still parses.
58
58
  */
59
59
  readiness: 'ready' | 'runtime-not-found' | 'offline' | (string & {});
60
+ /**
61
+ * ENG-334: whether stalled orchestrate runs auto-continue on this machine.
62
+ * Optional so an older server that doesn't send it still parses (shown as the server default, on).
63
+ */
64
+ autoContinue?: boolean;
60
65
  createdAt: string;
61
66
  updatedAt: string;
62
67
  }
@@ -99,13 +104,60 @@ export interface MailboxJob {
99
104
  totalTasks: number;
100
105
  completedTasks: number;
101
106
  } | null;
107
+ /**
108
+ * ER-130: open pull requests from the epic's other runs that its owner
109
+ * still has to merge, in merge order. The runner stops and asks for them
110
+ * instead of continuing on top of unmerged work. Older servers omit it.
111
+ */
112
+ waitingPullRequests?: {
113
+ number: number;
114
+ htmlUrl: string;
115
+ title: string | null;
116
+ }[];
117
+ /**
118
+ * ENG-339 (machine-only): present on the claim of a job its owner replied
119
+ * to — resume the paused session in the kept run copy with the reply. Read
120
+ * through `parseReplyResume`; older servers never send it.
121
+ */
122
+ resume?: {
123
+ sessionId: string | null;
124
+ runDir: string | null;
125
+ reply: string;
126
+ needsInput?: unknown;
127
+ minCliForReplyResume?: string;
128
+ } | null;
129
+ /**
130
+ * ENG-345 (machine-only): on the claim of a start_execution job, the
131
+ * project's Google Cloud keyless-deploy facts plus projectId, region and
132
+ * serviceAccountEmail; null when the project has no Google Cloud. Read
133
+ * through `parseCloudFacts`; older servers never send it (no preflight).
134
+ */
135
+ cloud?: unknown;
136
+ /**
137
+ * ENG-343 (machine-only): on the claim of a start_execution job, the
138
+ * project's merge policy ("never" | "ask" | "auto"). Read through
139
+ * `parseMergePolicy`; older servers never send it ("never").
140
+ */
141
+ mergePolicy?: unknown;
102
142
  }
103
143
  /** Normalized error for mailbox request failures with a stable HTTP-ish status. */
104
144
  export declare class MailboxClientError extends Error {
105
145
  /** HTTP status when the server responded; 0 for network-level failures. */
106
146
  readonly status: number;
107
- constructor(message: string, status: number);
147
+ /** Server error code (e.g. `MACHINE_OUTDATED`), when the body carried one. */
148
+ readonly code?: string;
149
+ /** For MACHINE_OUTDATED (ENG-320): the minimum CLI version the server needs. */
150
+ readonly requiredVersion?: string;
151
+ /** For MACHINE_OUTDATED (ENG-320): the command that updates this machine. */
152
+ readonly updateCommand?: string;
153
+ constructor(message: string, status: number, extra?: {
154
+ code?: string;
155
+ requiredVersion?: string;
156
+ updateCommand?: string;
157
+ });
108
158
  }
159
+ /** The server error code a 409 carries when this machine's CLI is too old (ENG-319/320). */
160
+ export declare const MACHINE_OUTDATED = "MACHINE_OUTDATED";
109
161
  /**
110
162
  * Reads the `cancelJobIds` field (ENG-299) the server attaches to next-job and
111
163
  * heartbeat responses: the ids of this machine's jobs someone asked to cancel.
@@ -127,6 +179,13 @@ export interface HeartbeatResult {
127
179
  export declare class MailboxClient {
128
180
  private readonly http;
129
181
  readonly baseUrl: string;
182
+ /**
183
+ * ER-130: the jobs this daemon is running right now, sent on every
184
+ * heartbeat (`runningJobIds`) so the server can tell a build that is really
185
+ * running from one whose run ended without reporting. Set by the poll loop;
186
+ * unset (one-off commands), the field is left out and nothing is checked.
187
+ */
188
+ runningJobIds: (() => string[]) | undefined;
130
189
  constructor(baseUrl: string);
131
190
  /** Register this device with central using the user's API token, returning its machine token (once). */
132
191
  pairMachine(userToken: string, name: string): Promise<PairedMachine>;
@@ -134,6 +193,14 @@ export declare class MailboxClient {
134
193
  listMachines(userToken: string): Promise<MachineSummary[]>;
135
194
  /** Renames a machine the caller owns; returns the updated machine. */
136
195
  renameMachine(userToken: string, id: string, name: string): Promise<MachineSummary>;
196
+ /**
197
+ * Updates editable settings (name and/or autoContinue, ENG-334) of a
198
+ * machine the caller owns. Fields left undefined are not sent.
199
+ */
200
+ updateMachine(userToken: string, id: string, changes: {
201
+ name?: string;
202
+ autoContinue?: boolean;
203
+ }): Promise<MachineSummary>;
137
204
  /**
138
205
  * Soft-revokes (removes) a machine the caller owns. Server-side this cuts off
139
206
  * the daemon token and fails the machine's non-terminal jobs. Idempotent.
@@ -182,8 +249,15 @@ export declare class MailboxClient {
182
249
  heartbeat(machineToken: string, runtime?: AgentRuntimeProbe, servicedRemotes?: string[]): Promise<HeartbeatResult>;
183
250
  /** Posts an agent turn (a question/status update) to a job's interview log. */
184
251
  postTurn(machineToken: string, jobId: string, content: string): Promise<MailboxJob>;
185
- /** Marks a claimed job done or failed, with an optional structured result. */
186
- completeJob(machineToken: string, jobId: string, status: 'done' | 'failed', result?: Record<string, unknown>): Promise<MailboxJob>;
252
+ /**
253
+ * Marks a claimed job done or failed, with an optional structured result.
254
+ * `waiting` (ENG-333) parks a usage-limited job to resume later: `resumeAt`
255
+ * is sent only with `waiting` (the server rejects it otherwise), and when it
256
+ * is absent the server applies its own backoff. A run waiting for its
257
+ * owner's reply (ENG-337) is also `waiting`, with `result.stopReason`
258
+ * `needs_input`; the caller handles a 400 from an older server.
259
+ */
260
+ completeJob(machineToken: string, jobId: string, status: 'done' | 'failed' | 'waiting', result?: Record<string, unknown>, resumeAt?: Date): Promise<MailboxJob>;
187
261
  /**
188
262
  * The person's saved API key for one job sent with "Run with: My API key".
189
263
  * Kept in memory and passed to Claude Code's environment only — never
@@ -214,6 +288,41 @@ export declare class MailboxClient {
214
288
  url: string;
215
289
  number: number;
216
290
  }>;
291
+ /**
292
+ * Posts (or updates, by marker) the wrap-up review comment on the run's pull
293
+ * request and sets it ready or draft (ENG-327).
294
+ */
295
+ reviewPullRequest(machineToken: string, jobId: string, input: {
296
+ number: number;
297
+ ready: boolean;
298
+ comment: string;
299
+ }): Promise<{
300
+ commentId: number;
301
+ draft: boolean;
302
+ }>;
303
+ /**
304
+ * Merges the job's own pull request through CompBox (ENG-347): "auto" under
305
+ * the project's auto merge policy, "approved" after the owner approved it.
306
+ * CompBox only ever merges the PR this job opened.
307
+ */
308
+ mergePullRequest(machineToken: string, jobId: string, input: {
309
+ reason: 'auto' | 'approved';
310
+ number: number;
311
+ }): Promise<{
312
+ merged: boolean;
313
+ sha: string;
314
+ }>;
315
+ /** Starts the epic's next wrap-up attempt and returns its number (ENG-327). */
316
+ startWrapUp(machineToken: string, epicId: string): Promise<{
317
+ attempt: number;
318
+ }>;
319
+ /** Writes one wrap-up attempt's results (ENG-323/327). */
320
+ updateWrapUp(machineToken: string, epicId: string, attempt: number, body: WrapUpUpdate): Promise<{
321
+ migrations?: unknown[];
322
+ } | undefined>;
323
+ /** Asks CompBox which epic features look one-sided for the changed files (ENG-324). */
324
+ checkCompleteness(machineToken: string, epicId: string, changedFiles: string[]): Promise<CompletenessCheck>;
325
+ private send;
217
326
  /** Reports what a run on the person's API key spent. */
218
327
  reportAiUsage(machineToken: string, jobId: string, usage: KeyRunUsage): Promise<void>;
219
328
  }
@@ -226,4 +335,22 @@ export interface KeyRunUsage {
226
335
  cacheWriteTokens: number;
227
336
  costUsd: number | null;
228
337
  }
338
+ /** Fields a runner writes for one wrap-up attempt (mirrors the API's upsert schema). */
339
+ export interface WrapUpUpdate {
340
+ status?: 'running' | 'ready' | 'needs_decision' | 'failed';
341
+ checks?: unknown[];
342
+ findings?: unknown[];
343
+ migrationFiles?: {
344
+ path: string;
345
+ status: string;
346
+ sql: string | null;
347
+ truncated?: boolean;
348
+ }[];
349
+ reviewComment?: string | null;
350
+ }
351
+ /** The API's completeness verdict for an epic's changed files (ENG-324). */
352
+ export interface CompletenessCheck {
353
+ status: 'pass' | 'needs_decision';
354
+ findings: string[];
355
+ }
229
356
  //# sourceMappingURL=mailbox-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mailbox-client.d.ts","sourceRoot":"","sources":["../../src/utils/mailbox-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,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MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAC7F,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAClC,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB"}
@@ -13,16 +13,31 @@
13
13
  * separate: distinct concerns, distinct auth contexts.
14
14
  */
15
15
  import axios, { isAxiosError } from 'axios';
16
+ import { resolveCliVersion } from './cli-version.js';
16
17
  /** Normalized error for mailbox request failures with a stable HTTP-ish status. */
17
18
  export class MailboxClientError extends Error {
18
19
  /** HTTP status when the server responded; 0 for network-level failures. */
19
20
  status;
20
- constructor(message, status) {
21
+ /** Server error code (e.g. `MACHINE_OUTDATED`), when the body carried one. */
22
+ code;
23
+ /** For MACHINE_OUTDATED (ENG-320): the minimum CLI version the server needs. */
24
+ requiredVersion;
25
+ /** For MACHINE_OUTDATED (ENG-320): the command that updates this machine. */
26
+ updateCommand;
27
+ constructor(message, status, extra = {}) {
21
28
  super(message);
22
29
  this.name = 'MailboxClientError';
23
30
  this.status = status;
31
+ if (extra.code !== undefined)
32
+ this.code = extra.code;
33
+ if (extra.requiredVersion !== undefined)
34
+ this.requiredVersion = extra.requiredVersion;
35
+ if (extra.updateCommand !== undefined)
36
+ this.updateCommand = extra.updateCommand;
24
37
  }
25
38
  }
39
+ /** The server error code a 409 carries when this machine's CLI is too old (ENG-319/320). */
40
+ export const MACHINE_OUTDATED = 'MACHINE_OUTDATED';
26
41
  /** Extracts a server-provided error message from a JSON error body, if present. */
27
42
  function extractServerMessage(data) {
28
43
  if (typeof data !== 'object' || data === null)
@@ -35,7 +50,7 @@ function toMailboxError(error, fallback) {
35
50
  if (isAxiosError(error)) {
36
51
  const status = error.response?.status ?? 0;
37
52
  const message = extractServerMessage(error.response?.data) ?? error.message;
38
- return new MailboxClientError(message, status);
53
+ return new MailboxClientError(message, status, extractServerErrorFields(error.response?.data));
39
54
  }
40
55
  if (error instanceof Error) {
41
56
  return new MailboxClientError(error.message, 0);
@@ -50,7 +65,31 @@ function toMailboxError(error, fallback) {
50
65
  */
51
66
  function errorFromResponse(res, fallback) {
52
67
  const message = extractServerMessage(res.data) ?? fallback;
53
- return new MailboxClientError(message, res.status);
68
+ return new MailboxClientError(message, res.status, extractServerErrorFields(res.data));
69
+ }
70
+ /**
71
+ * Pulls `error.code` and the MACHINE_OUTDATED details (`requiredVersion`,
72
+ * `updateCommand`) out of a JSON error body. Defensive: the body may not be
73
+ * JSON or may lack any of these, in which case the field is simply omitted.
74
+ */
75
+ function extractServerErrorFields(data) {
76
+ if (typeof data !== 'object' || data === null)
77
+ return {};
78
+ const err = data.error;
79
+ if (typeof err !== 'object' || err === null)
80
+ return {};
81
+ const shaped = err;
82
+ const out = {};
83
+ if (typeof shaped.code === 'string')
84
+ out.code = shaped.code;
85
+ if (typeof shaped.details === 'object' && shaped.details !== null) {
86
+ const details = shaped.details;
87
+ if (typeof details.requiredVersion === 'string')
88
+ out.requiredVersion = details.requiredVersion;
89
+ if (typeof details.updateCommand === 'string')
90
+ out.updateCommand = details.updateCommand;
91
+ }
92
+ return out;
54
93
  }
55
94
  /**
56
95
  * Reads the `cancelJobIds` field (ENG-299) the server attaches to next-job and
@@ -69,6 +108,13 @@ export function parseCancelJobIds(body) {
69
108
  export class MailboxClient {
70
109
  http;
71
110
  baseUrl;
111
+ /**
112
+ * ER-130: the jobs this daemon is running right now, sent on every
113
+ * heartbeat (`runningJobIds`) so the server can tell a build that is really
114
+ * running from one whose run ended without reporting. Set by the poll loop;
115
+ * unset (one-off commands), the field is left out and nothing is checked.
116
+ */
117
+ runningJobIds;
72
118
  constructor(baseUrl) {
73
119
  this.baseUrl = baseUrl.replace(/\/+$/, '');
74
120
  this.http = axios.create({
@@ -89,6 +135,10 @@ export class MailboxClient {
89
135
  // 'application/json'"), breaking `compbox machines rm`. Regression:
90
136
  // mailbox-client.http.test.ts.
91
137
  validateStatus: () => true,
138
+ // Every request reports this CLI's version (ENG-320) so the server can
139
+ // refuse work this machine is too old to run (409 MACHINE_OUTDATED).
140
+ // Read from package.json via resolveCliVersion, never hardcoded.
141
+ headers: { 'X-CompBox-Version': resolveCliVersion() },
92
142
  });
93
143
  }
94
144
  // ---------------------------------------------------------------------
@@ -148,6 +198,29 @@ export class MailboxClient {
148
198
  const data = res.data;
149
199
  return data.data;
150
200
  }
201
+ /**
202
+ * Updates editable settings (name and/or autoContinue, ENG-334) of a
203
+ * machine the caller owns. Fields left undefined are not sent.
204
+ */
205
+ async updateMachine(userToken, id, changes) {
206
+ const body = {};
207
+ if (changes.name !== undefined)
208
+ body.name = changes.name;
209
+ if (changes.autoContinue !== undefined)
210
+ body.autoContinue = changes.autoContinue;
211
+ let res;
212
+ try {
213
+ res = await this.http.patch(`/api/v1/machines/${encodeURIComponent(id)}`, body, { headers: { Authorization: `Bearer ${userToken}` } });
214
+ }
215
+ catch (error) {
216
+ throw toMailboxError(error, 'Update machine request failed');
217
+ }
218
+ if (res.status < 200 || res.status >= 300) {
219
+ throw errorFromResponse(res, 'Failed to update machine');
220
+ }
221
+ const data = res.data;
222
+ return data.data;
223
+ }
151
224
  /**
152
225
  * Soft-revokes (removes) a machine the caller owns. Server-side this cuts off
153
226
  * the daemon token and fails the machine's non-terminal jobs. Idempotent.
@@ -248,6 +321,9 @@ export class MailboxClient {
248
321
  if (servicedRemotes !== undefined) {
249
322
  body.servicedRemotes = servicedRemotes;
250
323
  }
324
+ if (this.runningJobIds) {
325
+ body.runningJobIds = this.runningJobIds();
326
+ }
251
327
  let res;
252
328
  try {
253
329
  res = await this.http.post('/api/v1/machines/heartbeat', body, {
@@ -277,11 +353,22 @@ export class MailboxClient {
277
353
  const data = res.data;
278
354
  return data.data;
279
355
  }
280
- /** Marks a claimed job done or failed, with an optional structured result. */
281
- async completeJob(machineToken, jobId, status, result) {
356
+ /**
357
+ * Marks a claimed job done or failed, with an optional structured result.
358
+ * `waiting` (ENG-333) parks a usage-limited job to resume later: `resumeAt`
359
+ * is sent only with `waiting` (the server rejects it otherwise), and when it
360
+ * is absent the server applies its own backoff. A run waiting for its
361
+ * owner's reply (ENG-337) is also `waiting`, with `result.stopReason`
362
+ * `needs_input`; the caller handles a 400 from an older server.
363
+ */
364
+ async completeJob(machineToken, jobId, status, result, resumeAt) {
282
365
  let res;
283
366
  try {
284
- res = await this.http.post(`/api/v1/jobs/${jobId}/complete`, { status, ...(result !== undefined && { result }) }, { headers: { Authorization: `Bearer ${machineToken}` } });
367
+ res = await this.http.post(`/api/v1/jobs/${jobId}/complete`, {
368
+ status,
369
+ ...(result !== undefined && { result }),
370
+ ...(status === 'waiting' && resumeAt !== undefined && { resumeAt: resumeAt.toISOString() }),
371
+ }, { headers: { Authorization: `Bearer ${machineToken}` } });
285
372
  }
286
373
  catch (error) {
287
374
  throw toMailboxError(error, 'complete-job request failed');
@@ -349,6 +436,53 @@ export class MailboxClient {
349
436
  }
350
437
  return res.data.data;
351
438
  }
439
+ /**
440
+ * Posts (or updates, by marker) the wrap-up review comment on the run's pull
441
+ * request and sets it ready or draft (ENG-327).
442
+ */
443
+ async reviewPullRequest(machineToken, jobId, input) {
444
+ const res = await this.send('post', `/api/v1/jobs/${jobId}/pull-request/review`, machineToken, input, 'pull-request review');
445
+ return res.data;
446
+ }
447
+ /**
448
+ * Merges the job's own pull request through CompBox (ENG-347): "auto" under
449
+ * the project's auto merge policy, "approved" after the owner approved it.
450
+ * CompBox only ever merges the PR this job opened.
451
+ */
452
+ async mergePullRequest(machineToken, jobId, input) {
453
+ const res = await this.send('post', `/api/v1/jobs/${jobId}/pull-request/merge`, machineToken, input, 'pull-request merge');
454
+ return res.data;
455
+ }
456
+ /** Starts the epic's next wrap-up attempt and returns its number (ENG-327). */
457
+ async startWrapUp(machineToken, epicId) {
458
+ const res = await this.send('post', `/api/v1/epics/${epicId}/wrap-ups`, machineToken, {}, 'wrap-up start');
459
+ return res.data;
460
+ }
461
+ /** Writes one wrap-up attempt's results (ENG-323/327). */
462
+ async updateWrapUp(machineToken, epicId, attempt, body) {
463
+ const res = await this.send('put', `/api/v1/epics/${epicId}/wrap-ups/${String(attempt)}`, machineToken, body, 'wrap-up update');
464
+ return res?.data;
465
+ }
466
+ /** Asks CompBox which epic features look one-sided for the changed files (ENG-324). */
467
+ async checkCompleteness(machineToken, epicId, changedFiles) {
468
+ const res = await this.send('post', `/api/v1/epics/${epicId}/completeness`, machineToken, { changedFiles }, 'completeness');
469
+ return res.data;
470
+ }
471
+ async send(method, path, machineToken, body, what) {
472
+ let res;
473
+ try {
474
+ res = await this.http[method](path, body, {
475
+ headers: { Authorization: `Bearer ${machineToken}` },
476
+ });
477
+ }
478
+ catch (error) {
479
+ throw toMailboxError(error, `${what} request failed`);
480
+ }
481
+ if (res.status < 200 || res.status >= 300) {
482
+ throw errorFromResponse(res, `${what} failed`);
483
+ }
484
+ return res.data;
485
+ }
352
486
  /** Reports what a run on the person's API key spent. */
353
487
  async reportAiUsage(machineToken, jobId, usage) {
354
488
  let res;