@mycompbox/compbox-cli 1.21.6 → 1.21.8
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/.tsbuildinfo +1 -1
- package/commands/run.d.ts +39 -0
- package/commands/run.d.ts.map +1 -1
- package/commands/run.js +121 -12
- package/commands/run.js.map +1 -1
- package/commands/workspace.d.ts.map +1 -1
- package/commands/workspace.js +35 -1
- package/commands/workspace.js.map +1 -1
- package/index.js +447 -48
- package/package.json +1 -1
- package/utils/agent-invoker.d.ts +20 -0
- package/utils/agent-invoker.d.ts.map +1 -1
- package/utils/agent-invoker.js +112 -8
- package/utils/agent-invoker.js.map +1 -1
- package/utils/mailbox-client.d.ts +27 -1
- package/utils/mailbox-client.d.ts.map +1 -1
- package/utils/mailbox-client.js +28 -3
- package/utils/mailbox-client.js.map +1 -1
- package/utils/package-manager-shims.d.ts +38 -0
- package/utils/package-manager-shims.d.ts.map +1 -0
- package/utils/package-manager-shims.js +76 -0
- package/utils/package-manager-shims.js.map +1 -0
- package/utils/process-group.d.ts +42 -0
- package/utils/process-group.d.ts.map +1 -0
- package/utils/process-group.js +127 -0
- package/utils/process-group.js.map +1 -0
- package/utils/run-workspace.d.ts +10 -0
- package/utils/run-workspace.d.ts.map +1 -1
- package/utils/run-workspace.js +28 -2
- package/utils/run-workspace.js.map +1 -1
package/index.js
CHANGED
|
@@ -5467,6 +5467,13 @@ async function resolveRouting(opts = {}) {
|
|
|
5467
5467
|
}
|
|
5468
5468
|
|
|
5469
5469
|
// ../shared/dist/interview-definition.js
|
|
5470
|
+
var DATABASE_CHOICE_VALUES = ["free_hosted", "cloud_paid", "existing", "none"];
|
|
5471
|
+
function normalizeDatabaseChoice(raw) {
|
|
5472
|
+
if (typeof raw !== "string")
|
|
5473
|
+
return void 0;
|
|
5474
|
+
const candidate = raw.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
5475
|
+
return DATABASE_CHOICE_VALUES.includes(candidate) ? candidate : void 0;
|
|
5476
|
+
}
|
|
5470
5477
|
var INTERVIEW_DEFINITION = [
|
|
5471
5478
|
{
|
|
5472
5479
|
key: "problemStatement",
|
|
@@ -5553,6 +5560,17 @@ var INTERVIEW_DEFINITION = [
|
|
|
5553
5560
|
"Why were those alternatives not chosen?"
|
|
5554
5561
|
],
|
|
5555
5562
|
fields: ["alternatives"]
|
|
5563
|
+
},
|
|
5564
|
+
{
|
|
5565
|
+
key: "database",
|
|
5566
|
+
title: "Database",
|
|
5567
|
+
purpose: "Record what kind of database the work should use, as databaseChoice set to exactly one of: free_hosted, cloud_paid, existing, none. Put any extra detail the employee gives in databaseNote. Never ask for, suggest, or record credentials, connection strings, or a specific vendor.",
|
|
5568
|
+
required: false,
|
|
5569
|
+
followUps: [
|
|
5570
|
+
"Will this need a database: a free hosted one, a paid cloud one, an existing one your team already has, or none?"
|
|
5571
|
+
],
|
|
5572
|
+
fields: ["databaseChoice", "databaseNote"],
|
|
5573
|
+
askOnlyWhen: "the idea involves storing or persisting data. Ask this at most once, and skip it entirely for ideas that store nothing"
|
|
5556
5574
|
}
|
|
5557
5575
|
];
|
|
5558
5576
|
function interviewFieldKeys() {
|
|
@@ -5596,7 +5614,8 @@ var OPTIONAL_DRAFT_KEYS = [
|
|
|
5596
5614
|
"targetAudience",
|
|
5597
5615
|
"alternatives",
|
|
5598
5616
|
"dependencies",
|
|
5599
|
-
"estimatedEffort"
|
|
5617
|
+
"estimatedEffort",
|
|
5618
|
+
"databaseNote"
|
|
5600
5619
|
];
|
|
5601
5620
|
function isEpicRequestDraft(value) {
|
|
5602
5621
|
if (typeof value !== "object" || value === null)
|
|
@@ -5671,6 +5690,9 @@ function toDraft(parsed) {
|
|
|
5671
5690
|
draft[key] = raw;
|
|
5672
5691
|
}
|
|
5673
5692
|
}
|
|
5693
|
+
const databaseChoice = normalizeDatabaseChoice(parsed.databaseChoice);
|
|
5694
|
+
if (databaseChoice)
|
|
5695
|
+
draft.databaseChoice = databaseChoice;
|
|
5674
5696
|
return draft;
|
|
5675
5697
|
}
|
|
5676
5698
|
function extractCompletionJson(text) {
|
|
@@ -6470,6 +6492,12 @@ function errorFromResponse(res, fallback) {
|
|
|
6470
6492
|
const message = extractServerMessage(res.data) ?? fallback;
|
|
6471
6493
|
return new MailboxClientError(message, res.status);
|
|
6472
6494
|
}
|
|
6495
|
+
function parseCancelJobIds(body) {
|
|
6496
|
+
if (typeof body !== "object" || body === null) return [];
|
|
6497
|
+
const raw = body.cancelJobIds;
|
|
6498
|
+
if (!Array.isArray(raw)) return [];
|
|
6499
|
+
return raw.filter((id) => typeof id === "string" && id.length > 0);
|
|
6500
|
+
}
|
|
6473
6501
|
var MailboxClient = class {
|
|
6474
6502
|
http;
|
|
6475
6503
|
baseUrl;
|
|
@@ -6594,6 +6622,14 @@ var MailboxClient = class {
|
|
|
6594
6622
|
* new work instead of resuming one of them.
|
|
6595
6623
|
*/
|
|
6596
6624
|
async nextJob(machineToken, waitMs = 0, runningIds = []) {
|
|
6625
|
+
return (await this.pollNextJob(machineToken, waitMs, runningIds)).job;
|
|
6626
|
+
}
|
|
6627
|
+
/**
|
|
6628
|
+
* Same as {@link nextJob}, but also returns `cancelJobIds` (ENG-299): the ids
|
|
6629
|
+
* of this machine's jobs someone asked to cancel. A 204 means no job and no
|
|
6630
|
+
* cancels; a 200 may carry `{ data: null, cancelJobIds }` (cancels only).
|
|
6631
|
+
*/
|
|
6632
|
+
async pollNextJob(machineToken, waitMs = 0, runningIds = []) {
|
|
6597
6633
|
let res;
|
|
6598
6634
|
try {
|
|
6599
6635
|
res = await this.http.get("/api/v1/machines/next-job", {
|
|
@@ -6606,13 +6642,13 @@ var MailboxClient = class {
|
|
|
6606
6642
|
throw toMailboxError(error, "next-job request failed");
|
|
6607
6643
|
}
|
|
6608
6644
|
if (res.status === 204) {
|
|
6609
|
-
return null;
|
|
6645
|
+
return { job: null, cancelJobIds: [] };
|
|
6610
6646
|
}
|
|
6611
6647
|
if (res.status < 200 || res.status >= 300) {
|
|
6612
6648
|
throw errorFromResponse(res, "next-job failed");
|
|
6613
6649
|
}
|
|
6614
|
-
const
|
|
6615
|
-
return data
|
|
6650
|
+
const body = res.data;
|
|
6651
|
+
return { job: body?.data ?? null, cancelJobIds: parseCancelJobIds(body) };
|
|
6616
6652
|
}
|
|
6617
6653
|
/**
|
|
6618
6654
|
* Explicit heartbeat ping (idle-period keepalive; next-job itself also
|
|
@@ -6630,6 +6666,8 @@ var MailboxClient = class {
|
|
|
6630
6666
|
* Both extras are independent and optional: calling `heartbeat(token)` with
|
|
6631
6667
|
* neither is backward-compatible and sends `{}`; passing only `runtime`
|
|
6632
6668
|
* preserves the exact ENG-136 wire shape (no `servicedRemotes` key).
|
|
6669
|
+
*
|
|
6670
|
+
* Resolves with the response's `cancelJobIds` (ENG-299) — `[]` when absent.
|
|
6633
6671
|
*/
|
|
6634
6672
|
async heartbeat(machineToken, runtime, servicedRemotes) {
|
|
6635
6673
|
const body = {};
|
|
@@ -6654,6 +6692,7 @@ var MailboxClient = class {
|
|
|
6654
6692
|
if (res.status < 200 || res.status >= 300) {
|
|
6655
6693
|
throw errorFromResponse(res, "Heartbeat failed");
|
|
6656
6694
|
}
|
|
6695
|
+
return { cancelJobIds: parseCancelJobIds(res.data) };
|
|
6657
6696
|
}
|
|
6658
6697
|
/** Posts an agent turn (a question/status update) to a job's interview log. */
|
|
6659
6698
|
async postTurn(machineToken, jobId, content) {
|
|
@@ -7975,6 +8014,7 @@ var doctorCommand = new Command7("doctor").description("Diagnose config, connect
|
|
|
7975
8014
|
|
|
7976
8015
|
// src/commands/run.ts
|
|
7977
8016
|
import { Command as Command8 } from "commander";
|
|
8017
|
+
import { delimiter as delimiter3 } from "node:path";
|
|
7978
8018
|
import chalk9 from "chalk";
|
|
7979
8019
|
|
|
7980
8020
|
// src/utils/agent-invoker.ts
|
|
@@ -8038,6 +8078,90 @@ function parseClaudeJsonResult(stdout2, fallbackModel) {
|
|
|
8038
8078
|
return { text: typeof data.result === "string" ? data.result : "", usage };
|
|
8039
8079
|
}
|
|
8040
8080
|
|
|
8081
|
+
// src/utils/process-group.ts
|
|
8082
|
+
import { spawn as nodeSpawn } from "node:child_process";
|
|
8083
|
+
var CANCEL_GRACE_MS = 1e4;
|
|
8084
|
+
function groupSpawnOptions(platform = process.platform) {
|
|
8085
|
+
return platform === "win32" ? {} : { detached: true };
|
|
8086
|
+
}
|
|
8087
|
+
function defaultKillTree(pid) {
|
|
8088
|
+
try {
|
|
8089
|
+
const killer = nodeSpawn("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
8090
|
+
stdio: "ignore",
|
|
8091
|
+
windowsHide: true
|
|
8092
|
+
});
|
|
8093
|
+
killer.on("error", () => {
|
|
8094
|
+
});
|
|
8095
|
+
} catch {
|
|
8096
|
+
}
|
|
8097
|
+
}
|
|
8098
|
+
function signalGroup(child, signal, deps) {
|
|
8099
|
+
const pid = child.pid;
|
|
8100
|
+
if (pid === void 0) {
|
|
8101
|
+
try {
|
|
8102
|
+
child.kill(signal);
|
|
8103
|
+
} catch {
|
|
8104
|
+
}
|
|
8105
|
+
return;
|
|
8106
|
+
}
|
|
8107
|
+
const kill = deps.kill ?? ((p, s) => process.kill(p, s));
|
|
8108
|
+
try {
|
|
8109
|
+
kill(-pid, signal);
|
|
8110
|
+
} catch (error) {
|
|
8111
|
+
if (error.code === "ESRCH") return;
|
|
8112
|
+
try {
|
|
8113
|
+
child.kill(signal);
|
|
8114
|
+
} catch {
|
|
8115
|
+
}
|
|
8116
|
+
}
|
|
8117
|
+
}
|
|
8118
|
+
function terminateProcessGroup(child, deps = {}) {
|
|
8119
|
+
const platform = deps.platform ?? process.platform;
|
|
8120
|
+
if (platform === "win32") {
|
|
8121
|
+
if (child.pid !== void 0) (deps.killTree ?? defaultKillTree)(child.pid);
|
|
8122
|
+
else child.kill("SIGKILL");
|
|
8123
|
+
return () => void 0;
|
|
8124
|
+
}
|
|
8125
|
+
signalGroup(child, "SIGTERM", deps);
|
|
8126
|
+
const escalate = setTimeout(() => {
|
|
8127
|
+
signalGroup(child, "SIGKILL", deps);
|
|
8128
|
+
}, deps.graceMs ?? CANCEL_GRACE_MS);
|
|
8129
|
+
escalate.unref();
|
|
8130
|
+
return () => {
|
|
8131
|
+
clearTimeout(escalate);
|
|
8132
|
+
};
|
|
8133
|
+
}
|
|
8134
|
+
function killProcessGroupNow(child, deps = {}) {
|
|
8135
|
+
const platform = deps.platform ?? process.platform;
|
|
8136
|
+
if (platform === "win32") {
|
|
8137
|
+
if (child.pid !== void 0) (deps.killTree ?? defaultKillTree)(child.pid);
|
|
8138
|
+
else child.kill("SIGKILL");
|
|
8139
|
+
return;
|
|
8140
|
+
}
|
|
8141
|
+
signalGroup(child, "SIGKILL", deps);
|
|
8142
|
+
}
|
|
8143
|
+
function killGroupOnAbort(signal, child, onAbort, deps = {}) {
|
|
8144
|
+
if (!signal) return () => void 0;
|
|
8145
|
+
const handler = () => {
|
|
8146
|
+
onAbort();
|
|
8147
|
+
terminateProcessGroup(child, deps);
|
|
8148
|
+
};
|
|
8149
|
+
if (signal.aborted) {
|
|
8150
|
+
handler();
|
|
8151
|
+
} else {
|
|
8152
|
+
signal.addEventListener("abort", handler, { once: true });
|
|
8153
|
+
}
|
|
8154
|
+
return () => {
|
|
8155
|
+
signal.removeEventListener("abort", handler);
|
|
8156
|
+
};
|
|
8157
|
+
}
|
|
8158
|
+
function cancelledRunResult(what) {
|
|
8159
|
+
return {
|
|
8160
|
+
status: "failed",
|
|
8161
|
+
result: { cancelled: true, message: `Cancelled from the website; the ${what} was stopped.` }
|
|
8162
|
+
};
|
|
8163
|
+
}
|
|
8164
|
+
|
|
8041
8165
|
// src/utils/agent-invoker.ts
|
|
8042
8166
|
var ANTHROPIC_MODEL = "claude-fable-5";
|
|
8043
8167
|
var CLAUDE_CLI_TURN_TIMEOUT_MS = 4 * 60 * 1e3;
|
|
@@ -8243,17 +8367,32 @@ async function takeConversationStep(job, ctx) {
|
|
|
8243
8367
|
{
|
|
8244
8368
|
reply: async (system, messages) => {
|
|
8245
8369
|
if (anthropic) {
|
|
8246
|
-
const response = await anthropic.messages.create({
|
|
8370
|
+
const response = await anthropic.messages.create({
|
|
8371
|
+
model: ANTHROPIC_MODEL,
|
|
8372
|
+
max_tokens: 4096,
|
|
8373
|
+
system,
|
|
8374
|
+
messages
|
|
8375
|
+
});
|
|
8247
8376
|
const text = response.content.find((b) => b.type === "text");
|
|
8248
8377
|
return text?.type === "text" ? text.text : "";
|
|
8249
8378
|
}
|
|
8250
8379
|
const prompt = renderConversationPrompt(messages);
|
|
8251
8380
|
try {
|
|
8252
|
-
return (await runClaudeCliTurn(prompt, {
|
|
8381
|
+
return (await runClaudeCliTurn(prompt, {
|
|
8382
|
+
systemPrompt: system,
|
|
8383
|
+
resumeSessionId: void 0,
|
|
8384
|
+
routing,
|
|
8385
|
+
model: cliModel
|
|
8386
|
+
})).text;
|
|
8253
8387
|
} catch (error) {
|
|
8254
8388
|
if (cliModel === null || !needsDefaultModel(error)) throw error;
|
|
8255
8389
|
cliModel = null;
|
|
8256
|
-
return (await runClaudeCliTurn(prompt, {
|
|
8390
|
+
return (await runClaudeCliTurn(prompt, {
|
|
8391
|
+
systemPrompt: system,
|
|
8392
|
+
resumeSessionId: void 0,
|
|
8393
|
+
routing,
|
|
8394
|
+
model: null
|
|
8395
|
+
})).text;
|
|
8257
8396
|
}
|
|
8258
8397
|
},
|
|
8259
8398
|
save: async (existingId, draft) => {
|
|
@@ -8450,6 +8589,7 @@ function buildPlannerFinalTurn(outcome) {
|
|
|
8450
8589
|
return `Planner run ended: ${JSON.stringify(r).slice(0, PLANNER_FINAL_TURN_MAX_CHARS)}`;
|
|
8451
8590
|
}
|
|
8452
8591
|
async function invokeStartExecutionPlan(ctx, deps = {}) {
|
|
8592
|
+
if (ctx.signal?.aborted) return cancelledRunResult("planner");
|
|
8453
8593
|
const spawnImpl = deps.spawnImpl ?? spawn3;
|
|
8454
8594
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
8455
8595
|
const isGitRepo = deps.isGitRepo ?? isGitRepoDir;
|
|
@@ -8490,8 +8630,22 @@ async function invokeStartExecutionPlan(ctx, deps = {}) {
|
|
|
8490
8630
|
const child = spawnImpl(command, args, {
|
|
8491
8631
|
cwd: ctx.projectDir,
|
|
8492
8632
|
stdio: ["ignore", "pipe", "pipe"],
|
|
8493
|
-
env: childEnv
|
|
8494
|
-
|
|
8633
|
+
env: childEnv,
|
|
8634
|
+
// ENG-300: lead its own process group so a cancel can stop everything it started.
|
|
8635
|
+
...groupSpawnOptions(deps.processGroup?.platform)
|
|
8636
|
+
});
|
|
8637
|
+
let cancelled = false;
|
|
8638
|
+
const disposeAbort = killGroupOnAbort(
|
|
8639
|
+
ctx.signal,
|
|
8640
|
+
child,
|
|
8641
|
+
() => {
|
|
8642
|
+
cancelled = true;
|
|
8643
|
+
setTimeout(() => {
|
|
8644
|
+
finish(cancelledRunResult("planner"));
|
|
8645
|
+
}, (deps.processGroup?.graceMs ?? CANCEL_GRACE_MS) + 5e3).unref();
|
|
8646
|
+
},
|
|
8647
|
+
deps.processGroup
|
|
8648
|
+
);
|
|
8495
8649
|
const heartbeatTimer = deps.heartbeat ? setInterval(() => {
|
|
8496
8650
|
void Promise.resolve(deps.heartbeat?.()).catch(() => {
|
|
8497
8651
|
});
|
|
@@ -8501,10 +8655,11 @@ async function invokeStartExecutionPlan(ctx, deps = {}) {
|
|
|
8501
8655
|
settled = true;
|
|
8502
8656
|
if (heartbeatTimer) clearInterval(heartbeatTimer);
|
|
8503
8657
|
clearTimeout(timer);
|
|
8658
|
+
disposeAbort();
|
|
8504
8659
|
resolve3(result);
|
|
8505
8660
|
};
|
|
8506
8661
|
const timer = setTimeout(() => {
|
|
8507
|
-
child.
|
|
8662
|
+
killProcessGroupNow(child, deps.processGroup);
|
|
8508
8663
|
finish({
|
|
8509
8664
|
status: "failed",
|
|
8510
8665
|
result: {
|
|
@@ -8519,6 +8674,10 @@ async function invokeStartExecutionPlan(ctx, deps = {}) {
|
|
|
8519
8674
|
stderr += chunk.toString("utf-8");
|
|
8520
8675
|
});
|
|
8521
8676
|
child.on("error", (error) => {
|
|
8677
|
+
if (cancelled) {
|
|
8678
|
+
finish(cancelledRunResult("planner"));
|
|
8679
|
+
return;
|
|
8680
|
+
}
|
|
8522
8681
|
finish({
|
|
8523
8682
|
status: "failed",
|
|
8524
8683
|
result: {
|
|
@@ -8529,6 +8688,10 @@ async function invokeStartExecutionPlan(ctx, deps = {}) {
|
|
|
8529
8688
|
child.on("close", (code) => {
|
|
8530
8689
|
void (async () => {
|
|
8531
8690
|
if (ctx.keyRun) stdout2 = await settleKeyRun(ctx, ctx.keyRun, stdout2);
|
|
8691
|
+
if (cancelled) {
|
|
8692
|
+
finish(cancelledRunResult("planner"));
|
|
8693
|
+
return;
|
|
8694
|
+
}
|
|
8532
8695
|
const combined = `${stdout2}
|
|
8533
8696
|
${stderr}`;
|
|
8534
8697
|
const review = detectNeedsHumanReview(combined);
|
|
@@ -8632,6 +8795,7 @@ function buildRefineFinalTurn(outcome) {
|
|
|
8632
8795
|
return `Refine run ended: ${text(r.error) ?? JSON.stringify(r)}`.slice(0, PLANNER_FINAL_TURN_MAX_CHARS);
|
|
8633
8796
|
}
|
|
8634
8797
|
async function invokeStartExecutionRefine(ctx, deps = {}) {
|
|
8798
|
+
if (ctx.signal?.aborted) return cancelledRunResult("planner");
|
|
8635
8799
|
const spawnImpl = deps.spawnImpl ?? spawn3;
|
|
8636
8800
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
8637
8801
|
const isGitRepo = deps.isGitRepo ?? isGitRepoDir;
|
|
@@ -8664,8 +8828,22 @@ async function invokeStartExecutionRefine(ctx, deps = {}) {
|
|
|
8664
8828
|
const child = spawnImpl(command, args, {
|
|
8665
8829
|
cwd: ctx.projectDir,
|
|
8666
8830
|
stdio: ["ignore", "pipe", "pipe"],
|
|
8667
|
-
env: childEnv
|
|
8668
|
-
|
|
8831
|
+
env: childEnv,
|
|
8832
|
+
// ENG-300: lead its own process group so a cancel can stop everything it started.
|
|
8833
|
+
...groupSpawnOptions(deps.processGroup?.platform)
|
|
8834
|
+
});
|
|
8835
|
+
let cancelled = false;
|
|
8836
|
+
const disposeAbort = killGroupOnAbort(
|
|
8837
|
+
ctx.signal,
|
|
8838
|
+
child,
|
|
8839
|
+
() => {
|
|
8840
|
+
cancelled = true;
|
|
8841
|
+
setTimeout(() => {
|
|
8842
|
+
finish(cancelledRunResult("planner"));
|
|
8843
|
+
}, (deps.processGroup?.graceMs ?? CANCEL_GRACE_MS) + 5e3).unref();
|
|
8844
|
+
},
|
|
8845
|
+
deps.processGroup
|
|
8846
|
+
);
|
|
8669
8847
|
const heartbeatTimer = deps.heartbeat ? setInterval(() => {
|
|
8670
8848
|
void Promise.resolve(deps.heartbeat?.()).catch(() => {
|
|
8671
8849
|
});
|
|
@@ -8675,10 +8853,11 @@ async function invokeStartExecutionRefine(ctx, deps = {}) {
|
|
|
8675
8853
|
settled = true;
|
|
8676
8854
|
if (heartbeatTimer) clearInterval(heartbeatTimer);
|
|
8677
8855
|
clearTimeout(timer);
|
|
8856
|
+
disposeAbort();
|
|
8678
8857
|
resolve3(result);
|
|
8679
8858
|
};
|
|
8680
8859
|
const timer = setTimeout(() => {
|
|
8681
|
-
child.
|
|
8860
|
+
killProcessGroupNow(child, deps.processGroup);
|
|
8682
8861
|
finish({
|
|
8683
8862
|
status: "failed",
|
|
8684
8863
|
result: {
|
|
@@ -8693,6 +8872,10 @@ async function invokeStartExecutionRefine(ctx, deps = {}) {
|
|
|
8693
8872
|
stderr += chunk.toString("utf-8");
|
|
8694
8873
|
});
|
|
8695
8874
|
child.on("error", (error) => {
|
|
8875
|
+
if (cancelled) {
|
|
8876
|
+
finish(cancelledRunResult("planner"));
|
|
8877
|
+
return;
|
|
8878
|
+
}
|
|
8696
8879
|
finish({
|
|
8697
8880
|
status: "failed",
|
|
8698
8881
|
result: {
|
|
@@ -8703,6 +8886,10 @@ async function invokeStartExecutionRefine(ctx, deps = {}) {
|
|
|
8703
8886
|
child.on("close", (code) => {
|
|
8704
8887
|
void (async () => {
|
|
8705
8888
|
if (ctx.keyRun) stdout2 = await settleKeyRun(ctx, ctx.keyRun, stdout2);
|
|
8889
|
+
if (cancelled) {
|
|
8890
|
+
finish(cancelledRunResult("planner"));
|
|
8891
|
+
return;
|
|
8892
|
+
}
|
|
8706
8893
|
const combined = `${stdout2}
|
|
8707
8894
|
${stderr}`;
|
|
8708
8895
|
const review = detectNeedsHumanReview(combined);
|
|
@@ -8852,6 +9039,9 @@ function buildIncompleteRunResult(epicId, progress) {
|
|
|
8852
9039
|
};
|
|
8853
9040
|
}
|
|
8854
9041
|
function describeRunBranch(finish) {
|
|
9042
|
+
if (finish.cancelled) {
|
|
9043
|
+
return `Cancelled: nothing was pushed. The work is kept in ${finish.keptWorktree ?? "its run folder"} on branch ${finish.branch}.`;
|
|
9044
|
+
}
|
|
8855
9045
|
if (finish.needsAttention) {
|
|
8856
9046
|
return `Needs attention: the run's work was kept in ${finish.keptWorktree ?? "its run folder"} (branch ${finish.branch}) because it couldn't all be committed.`;
|
|
8857
9047
|
}
|
|
@@ -8882,6 +9072,7 @@ function buildOrchestrateNeedsReviewResult(epicId, marker) {
|
|
|
8882
9072
|
};
|
|
8883
9073
|
}
|
|
8884
9074
|
async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
9075
|
+
if (ctx.signal?.aborted) return cancelledRunResult("orchestrator");
|
|
8885
9076
|
const spawnImpl = deps.spawnImpl ?? spawn3;
|
|
8886
9077
|
const isGitRepo = deps.isGitRepo ?? isGitRepoDir;
|
|
8887
9078
|
const worktreeCapable = deps.worktreeCapable ?? defaultWorktreeCapable;
|
|
@@ -8942,8 +9133,22 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
8942
9133
|
const child = spawnImpl(command, args, {
|
|
8943
9134
|
cwd: runDir,
|
|
8944
9135
|
stdio: ["ignore", "pipe", "pipe"],
|
|
8945
|
-
env: childEnv
|
|
8946
|
-
|
|
9136
|
+
env: childEnv,
|
|
9137
|
+
// ENG-300: lead its own process group so a cancel can stop everything it started.
|
|
9138
|
+
...groupSpawnOptions(deps.processGroup?.platform)
|
|
9139
|
+
});
|
|
9140
|
+
let cancelled = false;
|
|
9141
|
+
const disposeAbort = killGroupOnAbort(
|
|
9142
|
+
ctx.signal,
|
|
9143
|
+
child,
|
|
9144
|
+
() => {
|
|
9145
|
+
cancelled = true;
|
|
9146
|
+
setTimeout(() => {
|
|
9147
|
+
finish(cancelledRunResult("orchestrator"));
|
|
9148
|
+
}, (deps.processGroup?.graceMs ?? CANCEL_GRACE_MS) + 5e3).unref();
|
|
9149
|
+
},
|
|
9150
|
+
deps.processGroup
|
|
9151
|
+
);
|
|
8947
9152
|
const heartbeatTimer = deps.heartbeat ? setInterval(() => {
|
|
8948
9153
|
void Promise.resolve(deps.heartbeat?.()).catch(() => {
|
|
8949
9154
|
});
|
|
@@ -8953,10 +9158,11 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
8953
9158
|
settled = true;
|
|
8954
9159
|
if (heartbeatTimer) clearInterval(heartbeatTimer);
|
|
8955
9160
|
clearTimeout(timer);
|
|
9161
|
+
disposeAbort();
|
|
8956
9162
|
resolve3(result);
|
|
8957
9163
|
};
|
|
8958
9164
|
const timer = setTimeout(() => {
|
|
8959
|
-
child.
|
|
9165
|
+
killProcessGroupNow(child, deps.processGroup);
|
|
8960
9166
|
finish({
|
|
8961
9167
|
status: "failed",
|
|
8962
9168
|
result: {
|
|
@@ -8971,6 +9177,10 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
8971
9177
|
stderr += chunk.toString("utf-8");
|
|
8972
9178
|
});
|
|
8973
9179
|
child.on("error", (error) => {
|
|
9180
|
+
if (cancelled) {
|
|
9181
|
+
finish(cancelledRunResult("orchestrator"));
|
|
9182
|
+
return;
|
|
9183
|
+
}
|
|
8974
9184
|
finish({
|
|
8975
9185
|
status: "failed",
|
|
8976
9186
|
result: {
|
|
@@ -8980,6 +9190,10 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
8980
9190
|
});
|
|
8981
9191
|
child.on("close", (code) => {
|
|
8982
9192
|
if (ctx.keyRun) stdout2 = takeKeyRunResult(ctx, ctx.keyRun, stdout2).text;
|
|
9193
|
+
if (cancelled) {
|
|
9194
|
+
finish(cancelledRunResult("orchestrator"));
|
|
9195
|
+
return;
|
|
9196
|
+
}
|
|
8983
9197
|
const combined = `${stdout2}
|
|
8984
9198
|
${stderr}`;
|
|
8985
9199
|
const review = detectNeedsHumanReview(combined);
|
|
@@ -9001,7 +9215,12 @@ ${stderr}`;
|
|
|
9001
9215
|
}
|
|
9002
9216
|
finish({
|
|
9003
9217
|
status: "done",
|
|
9004
|
-
result: ctx.fix ? {
|
|
9218
|
+
result: ctx.fix ? {
|
|
9219
|
+
epicId: ctx.epicId,
|
|
9220
|
+
fix: true,
|
|
9221
|
+
branch: ctx.fix.branch,
|
|
9222
|
+
...ctx.fix.pullRequestUrl && { prUrl: ctx.fix.pullRequestUrl }
|
|
9223
|
+
} : { epicId: ctx.epicId }
|
|
9005
9224
|
});
|
|
9006
9225
|
});
|
|
9007
9226
|
});
|
|
@@ -9033,7 +9252,9 @@ ${stderr}`;
|
|
|
9033
9252
|
epicId: ctx.epicId,
|
|
9034
9253
|
jobId: ctx.jobId,
|
|
9035
9254
|
completed: outcome.status === "done",
|
|
9036
|
-
...stopReason ? { stopReason } : {}
|
|
9255
|
+
...stopReason ? { stopReason } : {},
|
|
9256
|
+
// ENG-300: a cancelled run keeps its branch and worktree locally — no push, no PR.
|
|
9257
|
+
...ctx.signal ? { signal: ctx.signal } : {}
|
|
9037
9258
|
});
|
|
9038
9259
|
branchLine = describeRunBranch(finished);
|
|
9039
9260
|
outcome.result = {
|
|
@@ -9046,7 +9267,11 @@ ${stderr}`;
|
|
|
9046
9267
|
...finished.notes.length > 0 ? { branchNotes: finished.notes } : {},
|
|
9047
9268
|
...finished.keptWorktree ? { keptWorktree: finished.keptWorktree } : {}
|
|
9048
9269
|
};
|
|
9049
|
-
if (finished.
|
|
9270
|
+
if (finished.cancelled) {
|
|
9271
|
+
outcome.status = "failed";
|
|
9272
|
+
outcome.result = { ...outcome.result, cancelled: true };
|
|
9273
|
+
}
|
|
9274
|
+
if (finished.needsAttention && !finished.cancelled) {
|
|
9050
9275
|
outcome.status = "failed";
|
|
9051
9276
|
outcome.result = {
|
|
9052
9277
|
...outcome.result,
|
|
@@ -9100,7 +9325,9 @@ async function createPersonalEpicRequest(apiBaseUrl, userApiToken, draft) {
|
|
|
9100
9325
|
...draft.targetAudience ? { targetAudience: draft.targetAudience } : {},
|
|
9101
9326
|
...draft.alternatives ? { alternatives: draft.alternatives } : {},
|
|
9102
9327
|
...draft.dependencies ? { dependencies: draft.dependencies } : {},
|
|
9103
|
-
...draft.estimatedEffort ? { estimatedEffort: draft.estimatedEffort } : {}
|
|
9328
|
+
...draft.estimatedEffort ? { estimatedEffort: draft.estimatedEffort } : {},
|
|
9329
|
+
...draft.databaseChoice ? { databaseChoice: draft.databaseChoice } : {},
|
|
9330
|
+
...draft.databaseNote ? { databaseNote: draft.databaseNote } : {}
|
|
9104
9331
|
}
|
|
9105
9332
|
})
|
|
9106
9333
|
});
|
|
@@ -9131,7 +9358,9 @@ async function updatePersonalEpicRequest(apiBaseUrl, userApiToken, epicRequestId
|
|
|
9131
9358
|
...draft.targetAudience ? { targetAudience: draft.targetAudience } : {},
|
|
9132
9359
|
...draft.alternatives ? { alternatives: draft.alternatives } : {},
|
|
9133
9360
|
...draft.dependencies ? { dependencies: draft.dependencies } : {},
|
|
9134
|
-
...draft.estimatedEffort ? { estimatedEffort: draft.estimatedEffort } : {}
|
|
9361
|
+
...draft.estimatedEffort ? { estimatedEffort: draft.estimatedEffort } : {},
|
|
9362
|
+
...draft.databaseChoice ? { databaseChoice: draft.databaseChoice } : {},
|
|
9363
|
+
...draft.databaseNote ? { databaseNote: draft.databaseNote } : {}
|
|
9135
9364
|
}
|
|
9136
9365
|
})
|
|
9137
9366
|
}
|
|
@@ -9309,7 +9538,11 @@ var RunWorkspaceManager = class {
|
|
|
9309
9538
|
const ref = await this.git(["update-ref", "refs/heads/main", sha, ""], projectDir);
|
|
9310
9539
|
if (ref.status !== 0) return fail("create the main branch", ref);
|
|
9311
9540
|
await this.git(["symbolic-ref", "HEAD", "refs/heads/main"], projectDir);
|
|
9312
|
-
if (!remote)
|
|
9541
|
+
if (!remote)
|
|
9542
|
+
return {
|
|
9543
|
+
ok: true,
|
|
9544
|
+
note: "The repository had no commits, so CompBox started main with an empty first commit."
|
|
9545
|
+
};
|
|
9313
9546
|
const push = await this.git(["push", remote, "main"], projectDir);
|
|
9314
9547
|
if (push.status !== 0) return fail(`push its first commit to ${remote}`, push);
|
|
9315
9548
|
return { ok: true, note: `The repository had no commits, so CompBox started main with an empty first commit and pushed it to ${remote}.` };
|
|
@@ -9404,7 +9637,11 @@ ${untracked.stdout}`.split("\n").map((p) => p.trim()).filter((p) => p && !p.ends
|
|
|
9404
9637
|
notes.push(`Couldn't copy ${path3} into the run workspace.`);
|
|
9405
9638
|
}
|
|
9406
9639
|
}
|
|
9407
|
-
return {
|
|
9640
|
+
return {
|
|
9641
|
+
ok: true,
|
|
9642
|
+
workspace: { dir, projectDir, branch, baseRef, baseBranch, remote, continued },
|
|
9643
|
+
notes
|
|
9644
|
+
};
|
|
9408
9645
|
}
|
|
9409
9646
|
/** The newest pushed run branch for this epic that isn't merged into the base yet, if any. */
|
|
9410
9647
|
async unfinishedBranch(remote, epicSlug, baseRef, projectDir) {
|
|
@@ -9417,6 +9654,19 @@ ${untracked.stdout}`.split("\n").map((p) => p.trim()).filter((p) => p && !p.ends
|
|
|
9417
9654
|
if ((await this.git(["merge-base", "--is-ancestor", latest, baseRef], projectDir)).status === 0) return null;
|
|
9418
9655
|
return latest.slice(remote.length + 1);
|
|
9419
9656
|
}
|
|
9657
|
+
/** A cancelled run's result: the branch and worktree are kept locally, untouched. */
|
|
9658
|
+
async keepCancelled(ws, notes, commits) {
|
|
9659
|
+
const count = commits ?? (Number.parseInt((await this.git(["rev-list", "--count", `${ws.baseRef}..HEAD`], ws.dir)).stdout.trim(), 10) || 0);
|
|
9660
|
+
notes.push(`The run was cancelled, so nothing was pushed. Its work is kept in ${ws.dir} on branch ${ws.branch}.`);
|
|
9661
|
+
return {
|
|
9662
|
+
branch: ws.branch,
|
|
9663
|
+
commits: count,
|
|
9664
|
+
pushed: false,
|
|
9665
|
+
keptWorktree: ws.dir,
|
|
9666
|
+
cancelled: true,
|
|
9667
|
+
notes
|
|
9668
|
+
};
|
|
9669
|
+
}
|
|
9420
9670
|
/** Commits, pushes and opens the pull request; then cleans up the worktree. */
|
|
9421
9671
|
finish(input) {
|
|
9422
9672
|
return withRepoLock(input.workspace.projectDir, () => this.finishLocked(input));
|
|
@@ -9424,6 +9674,7 @@ ${untracked.stdout}`.split("\n").map((p) => p.trim()).filter((p) => p && !p.ends
|
|
|
9424
9674
|
async finishLocked(input) {
|
|
9425
9675
|
const { workspace: ws } = input;
|
|
9426
9676
|
const notes = [];
|
|
9677
|
+
if (input.signal?.aborted) return this.keepCancelled(ws, notes);
|
|
9427
9678
|
const dirtyBefore = await this.isDirty(ws.dir);
|
|
9428
9679
|
let commitFailed = false;
|
|
9429
9680
|
if (dirtyBefore) {
|
|
@@ -9465,6 +9716,7 @@ ${untracked.stdout}`.split("\n").map((p) => p.trim()).filter((p) => p && !p.ends
|
|
|
9465
9716
|
);
|
|
9466
9717
|
return base;
|
|
9467
9718
|
}
|
|
9719
|
+
if (input.signal?.aborted) return this.keepCancelled(ws, notes, commits);
|
|
9468
9720
|
const push = await this.git(["push", "--set-upstream", ws.remote, ws.branch], ws.dir);
|
|
9469
9721
|
if (push.status !== 0) {
|
|
9470
9722
|
notes.push(
|
|
@@ -9701,6 +9953,54 @@ function startKeepAwake(opts) {
|
|
|
9701
9953
|
}
|
|
9702
9954
|
}
|
|
9703
9955
|
|
|
9956
|
+
// src/utils/package-manager-shims.ts
|
|
9957
|
+
import { accessSync as accessSync2, chmodSync as chmodSync3, constants, existsSync as existsSync11, mkdirSync as mkdirSync8, writeFileSync as writeFileSync5 } from "node:fs";
|
|
9958
|
+
import { homedir as homedir7 } from "node:os";
|
|
9959
|
+
import { delimiter as delimiter2, dirname as dirname6, join as join12 } from "node:path";
|
|
9960
|
+
var STAND_INS = { pnpm: "pnpm@10", yarn: "yarn@1" };
|
|
9961
|
+
function isOnPath(command, path3) {
|
|
9962
|
+
for (const dir of path3.split(delimiter2)) {
|
|
9963
|
+
if (!dir) continue;
|
|
9964
|
+
try {
|
|
9965
|
+
accessSync2(join12(dir, command), constants.X_OK);
|
|
9966
|
+
return true;
|
|
9967
|
+
} catch {
|
|
9968
|
+
}
|
|
9969
|
+
}
|
|
9970
|
+
return false;
|
|
9971
|
+
}
|
|
9972
|
+
function shimScript(tool, nodeBinDir, npx) {
|
|
9973
|
+
return [
|
|
9974
|
+
"#!/bin/sh",
|
|
9975
|
+
`# Written by CompBox: ${tool} isn't installed on this computer, so it runs`,
|
|
9976
|
+
"# through Node's npx. Installing it yourself makes CompBox use that instead.",
|
|
9977
|
+
`PATH="${nodeBinDir}:$PATH"`,
|
|
9978
|
+
"export PATH",
|
|
9979
|
+
`exec "${npx}" --yes ${STAND_INS[tool]} "$@"`,
|
|
9980
|
+
""
|
|
9981
|
+
].join("\n");
|
|
9982
|
+
}
|
|
9983
|
+
function ensurePackageManagerShims(opts = {}) {
|
|
9984
|
+
if ((opts.platform ?? process.platform) === "win32") return null;
|
|
9985
|
+
const path3 = claudeChildEnvPath(opts.path ?? process.env.PATH);
|
|
9986
|
+
const missing = Object.keys(STAND_INS).filter((tool) => !isOnPath(tool, path3));
|
|
9987
|
+
if (missing.length === 0) return null;
|
|
9988
|
+
const nodeBinDir = opts.nodeBinDir ?? dirname6(process.execPath);
|
|
9989
|
+
const npx = existsSync11(join12(nodeBinDir, "npx")) ? join12(nodeBinDir, "npx") : "npx";
|
|
9990
|
+
const dir = join12(opts.home ?? homedir7(), ".compbox", "shims");
|
|
9991
|
+
try {
|
|
9992
|
+
mkdirSync8(dir, { recursive: true });
|
|
9993
|
+
for (const tool of missing) {
|
|
9994
|
+
const file = join12(dir, tool);
|
|
9995
|
+
writeFileSync5(file, shimScript(tool, nodeBinDir, npx));
|
|
9996
|
+
chmodSync3(file, 493);
|
|
9997
|
+
}
|
|
9998
|
+
} catch {
|
|
9999
|
+
return null;
|
|
10000
|
+
}
|
|
10001
|
+
return { dir, tools: missing };
|
|
10002
|
+
}
|
|
10003
|
+
|
|
9704
10004
|
// src/commands/run.ts
|
|
9705
10005
|
var POLL_WAIT_MS = 0;
|
|
9706
10006
|
var IDLE_POLL_INTERVAL_MS = 15e3;
|
|
@@ -9746,16 +10046,69 @@ async function safeProbeAgentRuntime(probe, previous, log = (m) => {
|
|
|
9746
10046
|
}
|
|
9747
10047
|
async function runHeartbeatCycle(deps) {
|
|
9748
10048
|
const runtime = await safeProbeAgentRuntime(deps.probe, deps.previous, deps.log);
|
|
10049
|
+
let result;
|
|
9749
10050
|
try {
|
|
9750
10051
|
if (deps.servicedRemotes !== void 0) {
|
|
9751
|
-
await deps.client.heartbeat(deps.machineToken, runtime, deps.servicedRemotes);
|
|
10052
|
+
result = await deps.client.heartbeat(deps.machineToken, runtime, deps.servicedRemotes);
|
|
9752
10053
|
} else {
|
|
9753
|
-
await deps.client.heartbeat(deps.machineToken, runtime);
|
|
10054
|
+
result = await deps.client.heartbeat(deps.machineToken, runtime);
|
|
9754
10055
|
}
|
|
9755
|
-
return { runtime, sent: true };
|
|
9756
10056
|
} catch {
|
|
9757
10057
|
return { runtime, sent: false };
|
|
9758
10058
|
}
|
|
10059
|
+
deps.onCancelJobIds?.(cancelIdsOf(result));
|
|
10060
|
+
return { runtime, sent: true };
|
|
10061
|
+
}
|
|
10062
|
+
function cancelIdsOf(result) {
|
|
10063
|
+
return parseCancelJobIds(result);
|
|
10064
|
+
}
|
|
10065
|
+
var CancelRegistry = class {
|
|
10066
|
+
constructor(log = (m) => {
|
|
10067
|
+
console.log(m);
|
|
10068
|
+
}) {
|
|
10069
|
+
this.log = log;
|
|
10070
|
+
}
|
|
10071
|
+
controllers = /* @__PURE__ */ new Map();
|
|
10072
|
+
/** Starts tracking a job; returns the signal its work should honor. */
|
|
10073
|
+
register(jobId) {
|
|
10074
|
+
const controller = new AbortController();
|
|
10075
|
+
this.controllers.set(jobId, controller);
|
|
10076
|
+
return controller.signal;
|
|
10077
|
+
}
|
|
10078
|
+
/** Stops tracking a job (call from a `finally` so entries never leak). */
|
|
10079
|
+
release(jobId) {
|
|
10080
|
+
this.controllers.delete(jobId);
|
|
10081
|
+
}
|
|
10082
|
+
/** Whether a job is currently tracked. */
|
|
10083
|
+
has(jobId) {
|
|
10084
|
+
return this.controllers.has(jobId);
|
|
10085
|
+
}
|
|
10086
|
+
/** Number of tracked jobs. */
|
|
10087
|
+
get size() {
|
|
10088
|
+
return this.controllers.size;
|
|
10089
|
+
}
|
|
10090
|
+
/**
|
|
10091
|
+
* Aborts every tracked job listed in `ids`. Returns the ids aborted by THIS
|
|
10092
|
+
* call (already-aborted and unknown ids are skipped).
|
|
10093
|
+
*/
|
|
10094
|
+
handleCancelIds(ids) {
|
|
10095
|
+
const aborted = [];
|
|
10096
|
+
for (const id of ids) {
|
|
10097
|
+
const controller = this.controllers.get(id);
|
|
10098
|
+
if (!controller || controller.signal.aborted) continue;
|
|
10099
|
+
controller.abort(new Error("Job cancelled"));
|
|
10100
|
+
aborted.push(id);
|
|
10101
|
+
this.log(chalk9.yellow(` Job ${id}: cancel requested \u2014 stopping it.`));
|
|
10102
|
+
}
|
|
10103
|
+
return aborted;
|
|
10104
|
+
}
|
|
10105
|
+
};
|
|
10106
|
+
async function jobHeartbeat(ctx, servicedRemotes) {
|
|
10107
|
+
try {
|
|
10108
|
+
const result = servicedRemotes !== void 0 ? await ctx.client.heartbeat(ctx.machineToken, void 0, servicedRemotes) : await ctx.client.heartbeat(ctx.machineToken);
|
|
10109
|
+
ctx.onCancelJobIds?.(cancelIdsOf(result));
|
|
10110
|
+
} catch {
|
|
10111
|
+
}
|
|
9759
10112
|
}
|
|
9760
10113
|
function gatherServicedRemotes() {
|
|
9761
10114
|
return listProjectDirs().map((dir) => dir.remote);
|
|
@@ -9786,7 +10139,12 @@ function parseStartExecutionPayload(payload) {
|
|
|
9786
10139
|
const projectRemote = typeof p.projectRemote === "string" && p.projectRemote.length > 0 ? p.projectRemote : void 0;
|
|
9787
10140
|
const useAiKey = p.useAiKey === true;
|
|
9788
10141
|
if (p.kind === "plan" && typeof p.epicRequestId === "string" && p.epicRequestId.length > 0) {
|
|
9789
|
-
return {
|
|
10142
|
+
return {
|
|
10143
|
+
kind: "plan",
|
|
10144
|
+
epicRequestId: p.epicRequestId,
|
|
10145
|
+
...projectRemote && { projectRemote },
|
|
10146
|
+
...useAiKey && { useAiKey }
|
|
10147
|
+
};
|
|
9790
10148
|
}
|
|
9791
10149
|
if (p.kind === "orchestrate" && typeof p.epicId === "string" && p.epicId.length > 0) {
|
|
9792
10150
|
const fix = parseFix(p.fix);
|
|
@@ -9862,6 +10220,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
9862
10220
|
mailboxClient: ctx.client,
|
|
9863
10221
|
machineToken: ctx.machineToken,
|
|
9864
10222
|
jobId: job.id,
|
|
10223
|
+
...ctx.signal && { signal: ctx.signal },
|
|
9865
10224
|
apiBaseUrl: ctx.apiBaseUrl,
|
|
9866
10225
|
userApiToken: userApiToken2,
|
|
9867
10226
|
epicRequestId: payload.epicRequestId,
|
|
@@ -9871,7 +10230,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
9871
10230
|
{
|
|
9872
10231
|
// H4: keep this machine online during the long planner run — the poll
|
|
9873
10232
|
// loop (its own heartbeat) is blocked for the whole job.
|
|
9874
|
-
heartbeat: () =>
|
|
10233
|
+
heartbeat: () => jobHeartbeat(ctx)
|
|
9875
10234
|
}
|
|
9876
10235
|
)
|
|
9877
10236
|
);
|
|
@@ -9896,6 +10255,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
9896
10255
|
mailboxClient: ctx.client,
|
|
9897
10256
|
machineToken: ctx.machineToken,
|
|
9898
10257
|
jobId: job.id,
|
|
10258
|
+
...ctx.signal && { signal: ctx.signal },
|
|
9899
10259
|
apiBaseUrl: ctx.apiBaseUrl,
|
|
9900
10260
|
userApiToken: userApiToken2,
|
|
9901
10261
|
epicId: payload.epicId,
|
|
@@ -9904,7 +10264,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
9904
10264
|
...keyRun && { keyRun }
|
|
9905
10265
|
},
|
|
9906
10266
|
{
|
|
9907
|
-
heartbeat: () =>
|
|
10267
|
+
heartbeat: () => jobHeartbeat(ctx)
|
|
9908
10268
|
}
|
|
9909
10269
|
)
|
|
9910
10270
|
);
|
|
@@ -9928,6 +10288,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
9928
10288
|
mailboxClient: ctx.client,
|
|
9929
10289
|
machineToken: ctx.machineToken,
|
|
9930
10290
|
jobId: job.id,
|
|
10291
|
+
...ctx.signal && { signal: ctx.signal },
|
|
9931
10292
|
epicId: payload.epicId,
|
|
9932
10293
|
projectDir: jobProjectDir,
|
|
9933
10294
|
...keyRun && { keyRun },
|
|
@@ -9936,7 +10297,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
9936
10297
|
{
|
|
9937
10298
|
// H4: keep this machine online during the long orchestrator run — the
|
|
9938
10299
|
// poll loop (its own heartbeat) is blocked for the whole job.
|
|
9939
|
-
heartbeat: () =>
|
|
10300
|
+
heartbeat: () => jobHeartbeat(ctx),
|
|
9940
10301
|
// Own branch + worktree per run, finishing with a pull request (opened
|
|
9941
10302
|
// through CompBox's GitHub app when the project is connected to it).
|
|
9942
10303
|
workspace: new RunWorkspaceManager({
|
|
@@ -10003,7 +10364,7 @@ async function handleJob(ctx, job) {
|
|
|
10003
10364
|
await runInvokerAndComplete(ctx, job, async () => {
|
|
10004
10365
|
const outcome = await invokeConnectRepo(job.payload);
|
|
10005
10366
|
if (outcome.status === "done") {
|
|
10006
|
-
await
|
|
10367
|
+
await jobHeartbeat(ctx, gatherServicedRemotes());
|
|
10007
10368
|
}
|
|
10008
10369
|
return outcome;
|
|
10009
10370
|
});
|
|
@@ -10075,15 +10436,25 @@ Couldn't register ${options.projectDir.trim()}: ${error instanceof Error ? error
|
|
|
10075
10436
|
}
|
|
10076
10437
|
const waitMs = options.waitMs ? Number.parseInt(options.waitMs, 10) : POLL_WAIT_MS;
|
|
10077
10438
|
const client = new MailboxClient(config.apiBaseUrl);
|
|
10439
|
+
const cancels = new CancelRegistry();
|
|
10440
|
+
const handleCancelIds = (ids) => {
|
|
10441
|
+
cancels.handleCancelIds(ids);
|
|
10442
|
+
};
|
|
10078
10443
|
const jobContext = {
|
|
10079
10444
|
client,
|
|
10080
10445
|
machineToken,
|
|
10081
10446
|
apiBaseUrl: config.apiBaseUrl,
|
|
10082
10447
|
aiMode: config.aiMode,
|
|
10083
|
-
userApiToken: config.apiToken
|
|
10448
|
+
userApiToken: config.apiToken,
|
|
10449
|
+
onCancelJobIds: handleCancelIds
|
|
10084
10450
|
};
|
|
10085
10451
|
const folders = config.projectDirs ?? [];
|
|
10086
10452
|
const legacyDir = unusedLegacyProjectDir(config);
|
|
10453
|
+
const shims = ensurePackageManagerShims();
|
|
10454
|
+
if (shims) {
|
|
10455
|
+
process.env.PATH = [shims.dir, process.env.PATH ?? ""].filter(Boolean).join(delimiter3);
|
|
10456
|
+
console.log(chalk9.gray(` ${shims.tools.join(" and ")} not installed \u2014 builds will run ${shims.tools.length > 1 ? "them" : "it"} through npx.`));
|
|
10457
|
+
}
|
|
10087
10458
|
if (startKeepAwake({ enabled: config.keepAwake })) {
|
|
10088
10459
|
console.log(chalk9.gray(' Keeping this Mac awake while the runner is on (set "keepAwake": false in ~/.compbox/config.json to stop).'));
|
|
10089
10460
|
}
|
|
@@ -10119,8 +10490,9 @@ Couldn't register ${options.projectDir.trim()}: ${error instanceof Error ? error
|
|
|
10119
10490
|
let lastRuntimeSentAt = 0;
|
|
10120
10491
|
if (agentRuntime) {
|
|
10121
10492
|
try {
|
|
10122
|
-
await client.heartbeat(machineToken, agentRuntime, gatherServicedRemotes());
|
|
10493
|
+
const result = await client.heartbeat(machineToken, agentRuntime, gatherServicedRemotes());
|
|
10123
10494
|
lastRuntimeSentAt = Date.now();
|
|
10495
|
+
handleCancelIds(cancelIdsOf(result));
|
|
10124
10496
|
} catch {
|
|
10125
10497
|
}
|
|
10126
10498
|
}
|
|
@@ -10144,9 +10516,12 @@ Received ${signal}, shutting down...`));
|
|
|
10144
10516
|
const inFlight = /* @__PURE__ */ new Map();
|
|
10145
10517
|
do {
|
|
10146
10518
|
let job = null;
|
|
10519
|
+
let pollCancelIds = [];
|
|
10147
10520
|
try {
|
|
10148
10521
|
if (inFlight.size < maxJobs) {
|
|
10149
|
-
|
|
10522
|
+
const polled = await client.pollNextJob(machineToken, waitMs, [...inFlight.keys()]);
|
|
10523
|
+
job = polled.job;
|
|
10524
|
+
pollCancelIds = polled.cancelJobIds;
|
|
10150
10525
|
}
|
|
10151
10526
|
consecutiveErrors = 0;
|
|
10152
10527
|
} catch (error) {
|
|
@@ -10168,15 +10543,18 @@ Received ${signal}, shutting down...`));
|
|
|
10168
10543
|
if (job) {
|
|
10169
10544
|
const jobId = job.id;
|
|
10170
10545
|
const isConversation = job.type === "epic_request";
|
|
10171
|
-
const
|
|
10546
|
+
const signal = cancels.register(jobId);
|
|
10547
|
+
const work = handleJob({ ...jobContext, signal }, job).catch((error) => {
|
|
10172
10548
|
console.error(chalk9.red(` Job ${jobId} stopped unexpectedly: ${error instanceof Error ? error.message : String(error)}`));
|
|
10173
10549
|
}).finally(() => {
|
|
10174
10550
|
inFlight.delete(jobId);
|
|
10551
|
+
cancels.release(jobId);
|
|
10175
10552
|
lastJobAt = Date.now();
|
|
10176
10553
|
if (isConversation) lastConversationAt = lastJobAt;
|
|
10177
10554
|
});
|
|
10178
10555
|
inFlight.set(jobId, work);
|
|
10179
10556
|
}
|
|
10557
|
+
handleCancelIds(pollCancelIds);
|
|
10180
10558
|
if (runtimeHeartbeatDue(Date.now(), lastRuntimeSentAt)) {
|
|
10181
10559
|
const cycle = await runHeartbeatCycle({
|
|
10182
10560
|
client,
|
|
@@ -10185,7 +10563,8 @@ Received ${signal}, shutting down...`));
|
|
|
10185
10563
|
previous: agentRuntime,
|
|
10186
10564
|
// Re-read the allowlist each cycle so `machines dirs` edits between
|
|
10187
10565
|
// polls are reflected without a daemon restart (ENG-177).
|
|
10188
|
-
servicedRemotes: gatherServicedRemotes()
|
|
10566
|
+
servicedRemotes: gatherServicedRemotes(),
|
|
10567
|
+
onCancelJobIds: handleCancelIds
|
|
10189
10568
|
});
|
|
10190
10569
|
agentRuntime = cycle.runtime;
|
|
10191
10570
|
if (cycle.sent) {
|
|
@@ -10526,9 +10905,9 @@ Setting up ${match.name} (${match.gitRemote})...`));
|
|
|
10526
10905
|
import { Command as Command13 } from "commander";
|
|
10527
10906
|
import chalk14 from "chalk";
|
|
10528
10907
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
10529
|
-
import { mkdirSync as
|
|
10530
|
-
import { homedir as
|
|
10531
|
-
import { join as
|
|
10908
|
+
import { mkdirSync as mkdirSync9, writeFileSync as writeFileSync6 } from "node:fs";
|
|
10909
|
+
import { homedir as homedir8 } from "node:os";
|
|
10910
|
+
import { join as join13 } from "node:path";
|
|
10532
10911
|
function readWorkspaceEnv(env = process.env) {
|
|
10533
10912
|
const apiUrl = env.COMPBOX_API_URL?.trim();
|
|
10534
10913
|
const jobId = env.COMPBOX_JOB_ID?.trim();
|
|
@@ -10572,7 +10951,7 @@ async function runWorkspace(deps = {}) {
|
|
|
10572
10951
|
}
|
|
10573
10952
|
const fetchFn = deps.fetchFn ?? fetch;
|
|
10574
10953
|
const run = deps.run ?? defaultRunner;
|
|
10575
|
-
const home = deps.home ??
|
|
10954
|
+
const home = deps.home ?? homedir8();
|
|
10576
10955
|
const agentsDir = deps.agentsDir ?? "/opt/compbox/.github/agents/claude";
|
|
10577
10956
|
const workDir = deps.workDir ?? "/workspace";
|
|
10578
10957
|
const client = deps.client ?? new MailboxClient(env.apiUrl);
|
|
@@ -10591,7 +10970,7 @@ async function runWorkspace(deps = {}) {
|
|
|
10591
10970
|
if (payload.fix !== void 0 && !fix) {
|
|
10592
10971
|
return fail("This fix job's pull request details couldn't be read, so nothing was run.");
|
|
10593
10972
|
}
|
|
10594
|
-
const repoDir =
|
|
10973
|
+
const repoDir = join13(workDir, "repo");
|
|
10595
10974
|
let userApiToken;
|
|
10596
10975
|
let keyRun;
|
|
10597
10976
|
try {
|
|
@@ -10602,7 +10981,7 @@ async function runWorkspace(deps = {}) {
|
|
|
10602
10981
|
run("git", ["config", "--global", "credential.helper", "!compbox workspace git-credential"]);
|
|
10603
10982
|
run("git", ["config", "--global", "user.name", "CompBox"]);
|
|
10604
10983
|
run("git", ["config", "--global", "user.email", "bot@mycompbox.com"]);
|
|
10605
|
-
|
|
10984
|
+
mkdirSync9(workDir, { recursive: true });
|
|
10606
10985
|
run("git", ["clone", "--branch", git.defaultBranch, git.cloneUrl, repoDir]);
|
|
10607
10986
|
run("claude", [
|
|
10608
10987
|
"mcp",
|
|
@@ -10617,12 +10996,28 @@ async function runWorkspace(deps = {}) {
|
|
|
10617
10996
|
"--",
|
|
10618
10997
|
"compbox-mcp"
|
|
10619
10998
|
]);
|
|
10620
|
-
|
|
10621
|
-
|
|
10999
|
+
mkdirSync9(join13(home, ".claude"), { recursive: true });
|
|
11000
|
+
writeFileSync6(join13(home, ".claude", "CLAUDE.md"), agentRoutingInstructions(agentsDir));
|
|
10622
11001
|
} catch (error) {
|
|
10623
11002
|
return fail(`Setting up the cloud workspace failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
10624
11003
|
}
|
|
10625
|
-
const
|
|
11004
|
+
const controller = new AbortController();
|
|
11005
|
+
const heartbeat = () => client.heartbeat(env.token).then((res) => {
|
|
11006
|
+
const ids = res?.cancelJobIds;
|
|
11007
|
+
if (Array.isArray(ids) && ids.includes(job.id) && !controller.signal.aborted) {
|
|
11008
|
+
controller.abort(new Error("Job cancelled"));
|
|
11009
|
+
}
|
|
11010
|
+
}).catch(() => void 0);
|
|
11011
|
+
const cancelled = () => controller.signal.aborted;
|
|
11012
|
+
const finishCancelled = async () => {
|
|
11013
|
+
const { result } = cancelledRunResult("workspace");
|
|
11014
|
+
await client.completeJob(env.token, job.id, "failed", result).catch(() => void 0);
|
|
11015
|
+
console.log(chalk14.yellow("Cancelled."));
|
|
11016
|
+
return 1;
|
|
11017
|
+
};
|
|
11018
|
+
await heartbeat();
|
|
11019
|
+
if (cancelled()) return finishCancelled();
|
|
11020
|
+
const signal = controller.signal;
|
|
10626
11021
|
let outcome;
|
|
10627
11022
|
if (payload.kind === "plan" && payload.epicRequestId) {
|
|
10628
11023
|
outcome = await (deps.plan ?? invokeStartExecutionPlan)(
|
|
@@ -10634,7 +11029,8 @@ async function runWorkspace(deps = {}) {
|
|
|
10634
11029
|
userApiToken,
|
|
10635
11030
|
epicRequestId: payload.epicRequestId,
|
|
10636
11031
|
projectDir: repoDir,
|
|
10637
|
-
keyRun
|
|
11032
|
+
keyRun,
|
|
11033
|
+
signal
|
|
10638
11034
|
},
|
|
10639
11035
|
{ heartbeat }
|
|
10640
11036
|
);
|
|
@@ -10647,6 +11043,7 @@ async function runWorkspace(deps = {}) {
|
|
|
10647
11043
|
epicId: payload.epicId,
|
|
10648
11044
|
projectDir: repoDir,
|
|
10649
11045
|
keyRun,
|
|
11046
|
+
signal,
|
|
10650
11047
|
...fix && { fix }
|
|
10651
11048
|
},
|
|
10652
11049
|
{
|
|
@@ -10667,13 +11064,15 @@ async function runWorkspace(deps = {}) {
|
|
|
10667
11064
|
epicId: payload.epicId,
|
|
10668
11065
|
notes: typeof payload.notes === "string" ? payload.notes : void 0,
|
|
10669
11066
|
projectDir: repoDir,
|
|
10670
|
-
keyRun
|
|
11067
|
+
keyRun,
|
|
11068
|
+
signal
|
|
10671
11069
|
},
|
|
10672
11070
|
{ heartbeat }
|
|
10673
11071
|
);
|
|
10674
11072
|
} else {
|
|
10675
11073
|
return fail("The job is missing what to plan or build.");
|
|
10676
11074
|
}
|
|
11075
|
+
if (cancelled()) return finishCancelled();
|
|
10677
11076
|
await client.completeJob(env.token, job.id, outcome.status, outcome.result);
|
|
10678
11077
|
console.log(outcome.status === "done" ? chalk14.green("Finished.") : chalk14.yellow(`Stopped: ${JSON.stringify(outcome.result)}`));
|
|
10679
11078
|
return outcome.status === "done" ? 0 : 1;
|
|
@@ -10780,7 +11179,7 @@ ${error instanceof Error ? error.message : String(error)}`));
|
|
|
10780
11179
|
// src/index.ts
|
|
10781
11180
|
function resolveCliVersion() {
|
|
10782
11181
|
if (true) {
|
|
10783
|
-
return "1.21.
|
|
11182
|
+
return "1.21.8";
|
|
10784
11183
|
}
|
|
10785
11184
|
const require2 = createRequire(import.meta.url);
|
|
10786
11185
|
const pkg = require2("../package.json");
|