@mycompbox/compbox-cli 1.21.15 → 1.21.16
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/configure.d.ts.map +1 -1
- package/commands/configure.js +3 -3
- package/commands/configure.js.map +1 -1
- package/commands/doctor.d.ts +21 -3
- package/commands/doctor.d.ts.map +1 -1
- package/commands/doctor.js +93 -8
- package/commands/doctor.js.map +1 -1
- package/commands/run.d.ts.map +1 -1
- package/commands/run.js +4 -1
- package/commands/run.js.map +1 -1
- package/commands/service.d.ts +10 -19
- package/commands/service.d.ts.map +1 -1
- package/commands/service.js +107 -73
- package/commands/service.js.map +1 -1
- package/commands/workspace.d.ts +18 -1
- package/commands/workspace.d.ts.map +1 -1
- package/commands/workspace.js +122 -12
- package/commands/workspace.js.map +1 -1
- package/index.js +1427 -351
- package/package.json +1 -1
- package/utils/agent-invoker.d.ts +29 -2
- package/utils/agent-invoker.d.ts.map +1 -1
- package/utils/agent-invoker.js +97 -16
- package/utils/agent-invoker.js.map +1 -1
- package/utils/claude-runtime.d.ts +63 -7
- package/utils/claude-runtime.d.ts.map +1 -1
- package/utils/claude-runtime.js +203 -67
- package/utils/claude-runtime.js.map +1 -1
- package/utils/config-store.d.ts.map +1 -1
- package/utils/config-store.js +7 -4
- package/utils/config-store.js.map +1 -1
- package/utils/mcp-config-writer.d.ts +30 -4
- package/utils/mcp-config-writer.d.ts.map +1 -1
- package/utils/mcp-config-writer.js +33 -6
- package/utils/mcp-config-writer.js.map +1 -1
- package/utils/package-manager-shims.d.ts +20 -4
- package/utils/package-manager-shims.d.ts.map +1 -1
- package/utils/package-manager-shims.js +84 -13
- package/utils/package-manager-shims.js.map +1 -1
- package/utils/process-group.d.ts +9 -2
- package/utils/process-group.d.ts.map +1 -1
- package/utils/process-group.js +14 -4
- package/utils/process-group.js.map +1 -1
- package/utils/process-spawn.d.ts +68 -0
- package/utils/process-spawn.d.ts.map +1 -0
- package/utils/process-spawn.js +119 -0
- package/utils/process-spawn.js.map +1 -0
- package/utils/project-checks.d.ts +28 -0
- package/utils/project-checks.d.ts.map +1 -1
- package/utils/project-checks.js +58 -50
- package/utils/project-checks.js.map +1 -1
- package/utils/repo-setup.js +3 -3
- package/utils/repo-setup.js.map +1 -1
- package/utils/windows-runner.d.ts +136 -0
- package/utils/windows-runner.d.ts.map +1 -0
- package/utils/windows-runner.js +407 -0
- package/utils/windows-runner.js.map +1 -0
- package/utils/wrap-up.d.ts +81 -3
- package/utils/wrap-up.d.ts.map +1 -1
- package/utils/wrap-up.js +240 -8
- package/utils/wrap-up.js.map +1 -1
package/index.js
CHANGED
|
@@ -1831,6 +1831,7 @@ var SessionEventType;
|
|
|
1831
1831
|
})(SessionEventType || (SessionEventType = {}));
|
|
1832
1832
|
|
|
1833
1833
|
// ../shared/dist/types/mailbox.js
|
|
1834
|
+
var CHECK_MODES = ["every", "smart", "end"];
|
|
1834
1835
|
var START_EXECUTION_KINDS = ["plan", "orchestrate", "refine", "follow_up"];
|
|
1835
1836
|
function normalizeGitRemote(raw) {
|
|
1836
1837
|
const input = (raw ?? "").trim();
|
|
@@ -6605,6 +6606,22 @@ def handler(event, context):
|
|
|
6605
6606
|
// ../shared/dist/stack-cost.js
|
|
6606
6607
|
var MONTH_SECONDS = 30 * 24 * 60 * 60;
|
|
6607
6608
|
|
|
6609
|
+
// ../shared/dist/github-repo.js
|
|
6610
|
+
function canonicalRemoteKey(remote) {
|
|
6611
|
+
if (typeof remote !== "string")
|
|
6612
|
+
return null;
|
|
6613
|
+
const normalized = normalizeGitRemote(remote);
|
|
6614
|
+
if (normalized === "")
|
|
6615
|
+
return null;
|
|
6616
|
+
return normalized.toLowerCase();
|
|
6617
|
+
}
|
|
6618
|
+
function sameGitRemote(a, b) {
|
|
6619
|
+
const keyA = canonicalRemoteKey(a);
|
|
6620
|
+
if (keyA === null)
|
|
6621
|
+
return false;
|
|
6622
|
+
return keyA === canonicalRemoteKey(b);
|
|
6623
|
+
}
|
|
6624
|
+
|
|
6608
6625
|
// ../shared/dist/machineVersion.js
|
|
6609
6626
|
var MIN_MACHINE_VERSION = Object.freeze({
|
|
6610
6627
|
default: "0.0.0",
|
|
@@ -6932,7 +6949,7 @@ function resolveProjectDirForJob(projectRemote, opts) {
|
|
|
6932
6949
|
if (remote.length === 0) {
|
|
6933
6950
|
return { status: "no-remote" };
|
|
6934
6951
|
}
|
|
6935
|
-
const entry = (opts.config?.projectDirs ?? []).find((e) => e.remote
|
|
6952
|
+
const entry = (opts.config?.projectDirs ?? []).find((e) => sameGitRemote(e.remote, remote));
|
|
6936
6953
|
return entry ? { status: "registered", path: entry.path } : { status: "unregistered", remote };
|
|
6937
6954
|
}
|
|
6938
6955
|
function unusedLegacyProjectDir(config, env = process.env) {
|
|
@@ -6979,7 +6996,7 @@ function addProjectDir(path3, readOrigin = readOriginRemote) {
|
|
|
6979
6996
|
);
|
|
6980
6997
|
}
|
|
6981
6998
|
const entry = { remote, path: target };
|
|
6982
|
-
const next = listProjectDirs().filter((e) => e.remote
|
|
6999
|
+
const next = listProjectDirs().filter((e) => !sameGitRemote(e.remote, remote));
|
|
6983
7000
|
next.push(entry);
|
|
6984
7001
|
updateConfig({ projectDirs: next });
|
|
6985
7002
|
return entry;
|
|
@@ -6990,7 +7007,7 @@ function removeProjectDir(remoteOrPath) {
|
|
|
6990
7007
|
const normalizedNeedle = normalizeGitRemote(needle);
|
|
6991
7008
|
const current = listProjectDirs();
|
|
6992
7009
|
const next = current.filter(
|
|
6993
|
-
(e) => e.path !== needle && e.remote !== needle && e.remote !== normalizedNeedle
|
|
7010
|
+
(e) => e.path !== needle && e.remote !== needle && e.remote !== normalizedNeedle && !sameGitRemote(e.remote, needle)
|
|
6994
7011
|
);
|
|
6995
7012
|
if (next.length === current.length) {
|
|
6996
7013
|
return false;
|
|
@@ -7323,7 +7340,7 @@ var cached;
|
|
|
7323
7340
|
function resolveCliVersion() {
|
|
7324
7341
|
if (cached !== void 0) return cached;
|
|
7325
7342
|
if (true) {
|
|
7326
|
-
cached = "1.21.
|
|
7343
|
+
cached = "1.21.16";
|
|
7327
7344
|
return cached;
|
|
7328
7345
|
}
|
|
7329
7346
|
const require2 = createRequire(import.meta.url);
|
|
@@ -7820,7 +7837,7 @@ var MailboxClient = class {
|
|
|
7820
7837
|
|
|
7821
7838
|
// src/utils/mcp-config-writer.ts
|
|
7822
7839
|
import { existsSync as existsSync8, readFileSync as readFileSync4, writeFileSync as writeFileSync5, mkdirSync as mkdirSync4 } from "fs";
|
|
7823
|
-
import { basename, dirname as dirname3, join as join8 } from "path";
|
|
7840
|
+
import { basename, dirname as dirname3, join as join8, win32 } from "path";
|
|
7824
7841
|
var DEFAULT_MCP_CONFIG_FILENAME = ".mcp.json";
|
|
7825
7842
|
var DEFAULT_SERVER_KEY = "compbox";
|
|
7826
7843
|
var MCP_SERVER_PACKAGE = "@mycompbox/compbox-mcp";
|
|
@@ -7844,6 +7861,18 @@ function resolveInstalledMcpBundle(opts) {
|
|
|
7844
7861
|
}
|
|
7845
7862
|
return void 0;
|
|
7846
7863
|
}
|
|
7864
|
+
function isNodeCommand(command) {
|
|
7865
|
+
return /^node(\.exe)?$/i.test(win32.basename(command));
|
|
7866
|
+
}
|
|
7867
|
+
function isNpxLaunch(command, args) {
|
|
7868
|
+
const base = win32.basename(command).toLowerCase();
|
|
7869
|
+
if (base === "npx" || base === "npx.cmd") return true;
|
|
7870
|
+
if (base === "cmd" || base === "cmd.exe") {
|
|
7871
|
+
const a = (args ?? []).map((x) => x.toLowerCase());
|
|
7872
|
+
return a[0] === "/c" && (a[1] === "npx" || a[1] === "npx.cmd");
|
|
7873
|
+
}
|
|
7874
|
+
return false;
|
|
7875
|
+
}
|
|
7847
7876
|
function defaultMcpConfigPath(projectRoot = process.cwd()) {
|
|
7848
7877
|
return join8(projectRoot, DEFAULT_MCP_CONFIG_FILENAME);
|
|
7849
7878
|
}
|
|
@@ -7856,7 +7885,10 @@ function buildCompboxServerEntry(spec) {
|
|
|
7856
7885
|
if (!explicitLaunch) {
|
|
7857
7886
|
const bundlePath = (spec.resolveInstalledBundle ?? resolveInstalledMcpBundle)();
|
|
7858
7887
|
if (bundlePath !== void 0) {
|
|
7859
|
-
return { command:
|
|
7888
|
+
return { command: spec.execPath ?? process.execPath, args: [bundlePath], env };
|
|
7889
|
+
}
|
|
7890
|
+
if ((spec.platform ?? process.platform) === "win32") {
|
|
7891
|
+
return { command: "cmd", args: ["/c", "npx", "-y", MCP_SERVER_PACKAGE], env };
|
|
7860
7892
|
}
|
|
7861
7893
|
}
|
|
7862
7894
|
return {
|
|
@@ -8097,9 +8129,9 @@ Device already paired as "${config.machineName ?? config.machineId}".`));
|
|
|
8097
8129
|
console.log(chalk7.yellow(`
|
|
8098
8130
|
\u26A0 ${LOOPBACK_NOTICE}`));
|
|
8099
8131
|
}
|
|
8100
|
-
if (result.entry.command
|
|
8132
|
+
if (isNodeCommand(result.entry.command)) {
|
|
8101
8133
|
console.log(
|
|
8102
|
-
chalk7.green(`\u2714 MCP server:
|
|
8134
|
+
chalk7.green(`\u2714 MCP server: installed bundle at ${result.entry.args[0] ?? "(unknown)"}`)
|
|
8103
8135
|
);
|
|
8104
8136
|
console.log(chalk7.gray(" No download needed \u2014 the launch uses the locally installed bundle."));
|
|
8105
8137
|
} else {
|
|
@@ -8228,37 +8260,109 @@ import { spawn as spawn3 } from "node:child_process";
|
|
|
8228
8260
|
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
8229
8261
|
import { accessSync, constants as fsConstants, statSync as statSync2 } from "node:fs";
|
|
8230
8262
|
import { homedir as homedir5 } from "node:os";
|
|
8231
|
-
import {
|
|
8263
|
+
import { posix as posixPath, win32 as win32Path } from "node:path";
|
|
8264
|
+
function pathFor(platform) {
|
|
8265
|
+
return platform === "win32" ? win32Path : posixPath;
|
|
8266
|
+
}
|
|
8267
|
+
function readEnvPath(env, platform) {
|
|
8268
|
+
if (platform !== "win32") {
|
|
8269
|
+
return env.PATH;
|
|
8270
|
+
}
|
|
8271
|
+
if (env.PATH !== void 0) {
|
|
8272
|
+
return env.PATH;
|
|
8273
|
+
}
|
|
8274
|
+
const key = Object.keys(env).find((k) => k.toUpperCase() === "PATH");
|
|
8275
|
+
return key === void 0 ? void 0 : env[key];
|
|
8276
|
+
}
|
|
8277
|
+
var DEFAULT_PATHEXT = ".COM;.EXE;.BAT;.CMD";
|
|
8278
|
+
function pathExtensions(env) {
|
|
8279
|
+
const raw = env.PATHEXT ?? DEFAULT_PATHEXT;
|
|
8280
|
+
const exts = raw.split(";").map((e) => e.trim().toLowerCase()).filter((e) => e.length > 1 && e.startsWith("."));
|
|
8281
|
+
return exts.length > 0 ? exts : DEFAULT_PATHEXT.toLowerCase().split(";");
|
|
8282
|
+
}
|
|
8283
|
+
function claudeCandidateNames(platform = process.platform, env = process.env) {
|
|
8284
|
+
if (platform !== "win32") {
|
|
8285
|
+
return ["claude"];
|
|
8286
|
+
}
|
|
8287
|
+
const exts = pathExtensions(env);
|
|
8288
|
+
const ordered = [];
|
|
8289
|
+
for (const ext of [".exe", ".cmd", ...exts]) {
|
|
8290
|
+
if (exts.includes(ext) && !ordered.includes(ext)) {
|
|
8291
|
+
ordered.push(ext);
|
|
8292
|
+
}
|
|
8293
|
+
}
|
|
8294
|
+
return ordered.map((ext) => `claude${ext}`);
|
|
8295
|
+
}
|
|
8232
8296
|
var WELL_KNOWN_DIRS = buildWellKnownDirs();
|
|
8233
|
-
function buildWellKnownDirs() {
|
|
8234
|
-
const
|
|
8297
|
+
function buildWellKnownDirs(options = {}) {
|
|
8298
|
+
const platform = options.platform ?? process.platform;
|
|
8299
|
+
const env = options.env ?? process.env;
|
|
8300
|
+
if (platform === "win32") {
|
|
8301
|
+
return buildWin32WellKnownDirs(env, options.home);
|
|
8302
|
+
}
|
|
8303
|
+
const join19 = (...parts) => posixPath.join(...parts);
|
|
8304
|
+
const home = options.home ?? homedir5();
|
|
8235
8305
|
const dirs = [
|
|
8236
|
-
|
|
8306
|
+
join19(home, ".local", "bin"),
|
|
8237
8307
|
// default Claude Code install location
|
|
8238
8308
|
"/opt/homebrew/bin",
|
|
8239
8309
|
// Homebrew on Apple Silicon
|
|
8240
8310
|
"/usr/local/bin"
|
|
8241
8311
|
// Homebrew on Intel / common Unix prefix
|
|
8242
8312
|
];
|
|
8243
|
-
if (
|
|
8244
|
-
dirs.push(
|
|
8313
|
+
if (env.npm_config_prefix) {
|
|
8314
|
+
dirs.push(join19(env.npm_config_prefix, "bin"));
|
|
8245
8315
|
}
|
|
8246
|
-
dirs.push(
|
|
8247
|
-
if (
|
|
8248
|
-
dirs.push(
|
|
8316
|
+
dirs.push(join19(home, ".npm-global", "bin"));
|
|
8317
|
+
if (env.PNPM_HOME) {
|
|
8318
|
+
dirs.push(env.PNPM_HOME);
|
|
8249
8319
|
}
|
|
8250
|
-
dirs.push(
|
|
8251
|
-
dirs.push(
|
|
8320
|
+
dirs.push(join19(home, "Library", "pnpm"));
|
|
8321
|
+
dirs.push(join19(home, ".local", "share", "pnpm"));
|
|
8252
8322
|
return dirs;
|
|
8253
8323
|
}
|
|
8324
|
+
function buildWin32WellKnownDirs(env, homeOverride) {
|
|
8325
|
+
const join19 = (...parts) => win32Path.join(...parts);
|
|
8326
|
+
const dirs = [];
|
|
8327
|
+
const userProfile = env.USERPROFILE ?? homeOverride;
|
|
8328
|
+
if (userProfile) {
|
|
8329
|
+
dirs.push(join19(userProfile, ".local", "bin"));
|
|
8330
|
+
}
|
|
8331
|
+
if (env.APPDATA) {
|
|
8332
|
+
dirs.push(join19(env.APPDATA, "npm"));
|
|
8333
|
+
}
|
|
8334
|
+
if (env.LOCALAPPDATA) {
|
|
8335
|
+
dirs.push(join19(env.LOCALAPPDATA, "Programs", "claude"));
|
|
8336
|
+
dirs.push(join19(env.LOCALAPPDATA, "pnpm"));
|
|
8337
|
+
}
|
|
8338
|
+
if (env.npm_config_prefix) {
|
|
8339
|
+
dirs.push(env.npm_config_prefix);
|
|
8340
|
+
}
|
|
8341
|
+
if (env.PNPM_HOME) {
|
|
8342
|
+
dirs.push(env.PNPM_HOME);
|
|
8343
|
+
}
|
|
8344
|
+
return dirs;
|
|
8345
|
+
}
|
|
8346
|
+
function wellKnownDirsFor(platform, env) {
|
|
8347
|
+
if (platform === process.platform && env === process.env) {
|
|
8348
|
+
return WELL_KNOWN_DIRS;
|
|
8349
|
+
}
|
|
8350
|
+
return buildWellKnownDirs({ platform, env });
|
|
8351
|
+
}
|
|
8352
|
+
function dirKey(dir, platform) {
|
|
8353
|
+
return platform === "win32" ? dir.toLowerCase() : dir;
|
|
8354
|
+
}
|
|
8254
8355
|
var LOGIN_SHELL_PATH_TIMEOUT_MS = 2e3;
|
|
8255
8356
|
var cachedLoginShellPath = null;
|
|
8256
|
-
function getLoginShellPath(exec = defaultExecFileSync) {
|
|
8357
|
+
function getLoginShellPath(exec = defaultExecFileSync, platform = process.platform, env = process.env) {
|
|
8358
|
+
if (platform === "win32") {
|
|
8359
|
+
return readEnvPath(env, platform) ?? "";
|
|
8360
|
+
}
|
|
8257
8361
|
if (cachedLoginShellPath !== null) {
|
|
8258
8362
|
return cachedLoginShellPath;
|
|
8259
8363
|
}
|
|
8260
|
-
const shell =
|
|
8261
|
-
const fallback =
|
|
8364
|
+
const shell = env.SHELL;
|
|
8365
|
+
const fallback = env.PATH ?? "";
|
|
8262
8366
|
if (!shell) {
|
|
8263
8367
|
cachedLoginShellPath = fallback;
|
|
8264
8368
|
return cachedLoginShellPath;
|
|
@@ -8282,23 +8386,28 @@ function defaultExecFileSync(file, args, options) {
|
|
|
8282
8386
|
stdio: ["ignore", "pipe", "ignore"]
|
|
8283
8387
|
});
|
|
8284
8388
|
}
|
|
8285
|
-
function claudeSearchDirs(getPath =
|
|
8286
|
-
const
|
|
8389
|
+
function claudeSearchDirs(getPath, platform = process.platform, env = process.env) {
|
|
8390
|
+
const readPath = getPath ?? (() => getLoginShellPath(void 0, platform, env));
|
|
8391
|
+
const pathDirs = readPath().split(pathFor(platform).delimiter).map((d) => d.trim()).filter((d) => d.length > 0);
|
|
8287
8392
|
const seen = /* @__PURE__ */ new Set();
|
|
8288
8393
|
const out = [];
|
|
8289
|
-
for (const dir of [...pathDirs, ...
|
|
8290
|
-
|
|
8291
|
-
|
|
8394
|
+
for (const dir of [...pathDirs, ...wellKnownDirsFor(platform, env)]) {
|
|
8395
|
+
const key = dirKey(dir, platform);
|
|
8396
|
+
if (!seen.has(key)) {
|
|
8397
|
+
seen.add(key);
|
|
8292
8398
|
out.push(dir);
|
|
8293
8399
|
}
|
|
8294
8400
|
}
|
|
8295
8401
|
return out;
|
|
8296
8402
|
}
|
|
8297
|
-
function isExecutableFile(p) {
|
|
8403
|
+
function isExecutableFile(p, platform = process.platform, env = process.env) {
|
|
8298
8404
|
try {
|
|
8299
8405
|
if (!statSync2(p).isFile()) {
|
|
8300
8406
|
return false;
|
|
8301
8407
|
}
|
|
8408
|
+
if (platform === "win32") {
|
|
8409
|
+
return pathExtensions(env).includes(win32Path.extname(p).toLowerCase());
|
|
8410
|
+
}
|
|
8302
8411
|
accessSync(p, fsConstants.X_OK);
|
|
8303
8412
|
return true;
|
|
8304
8413
|
} catch {
|
|
@@ -8306,37 +8415,52 @@ function isExecutableFile(p) {
|
|
|
8306
8415
|
}
|
|
8307
8416
|
}
|
|
8308
8417
|
function resolveClaudeBinary(deps = {}) {
|
|
8309
|
-
const
|
|
8310
|
-
const
|
|
8418
|
+
const platform = deps.platform ?? process.platform;
|
|
8419
|
+
const env = deps.env ?? process.env;
|
|
8420
|
+
const dirs = deps.dirs ?? claudeSearchDirs(void 0, platform, env);
|
|
8421
|
+
const isExec = deps.isExecutableFile ?? ((p) => isExecutableFile(p, platform, env));
|
|
8422
|
+
const names = claudeCandidateNames(platform, env);
|
|
8423
|
+
const pathImpl = pathFor(platform);
|
|
8311
8424
|
const seen = /* @__PURE__ */ new Set();
|
|
8312
8425
|
for (const dir of dirs) {
|
|
8313
|
-
if (!dir
|
|
8426
|
+
if (!dir) {
|
|
8314
8427
|
continue;
|
|
8315
8428
|
}
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8429
|
+
const key = dirKey(dir, platform);
|
|
8430
|
+
if (seen.has(key)) {
|
|
8431
|
+
continue;
|
|
8432
|
+
}
|
|
8433
|
+
seen.add(key);
|
|
8434
|
+
for (const name of names) {
|
|
8435
|
+
const candidate = pathImpl.join(dir, name);
|
|
8436
|
+
if (isExec(candidate)) {
|
|
8437
|
+
return candidate;
|
|
8438
|
+
}
|
|
8320
8439
|
}
|
|
8321
8440
|
}
|
|
8322
8441
|
return null;
|
|
8323
8442
|
}
|
|
8324
|
-
function claudeChildEnvPath(currentPath =
|
|
8325
|
-
const
|
|
8443
|
+
function claudeChildEnvPath(currentPath, options = {}) {
|
|
8444
|
+
const platform = options.platform ?? process.platform;
|
|
8445
|
+
const env = options.env ?? process.env;
|
|
8446
|
+
const { delimiter: delimiter2 } = pathFor(platform);
|
|
8447
|
+
const existing = (currentPath ?? readEnvPath(env, platform) ?? "").split(delimiter2).map((d) => d.trim()).filter((d) => d.length > 0);
|
|
8326
8448
|
const seen = /* @__PURE__ */ new Set();
|
|
8327
8449
|
const merged = [];
|
|
8328
|
-
for (const dir of [...claudeSearchDirs(), ...existing]) {
|
|
8329
|
-
|
|
8330
|
-
|
|
8450
|
+
for (const dir of [...claudeSearchDirs(void 0, platform, env), ...existing]) {
|
|
8451
|
+
const key = dirKey(dir, platform);
|
|
8452
|
+
if (!seen.has(key)) {
|
|
8453
|
+
seen.add(key);
|
|
8331
8454
|
merged.push(dir);
|
|
8332
8455
|
}
|
|
8333
8456
|
}
|
|
8334
|
-
return merged.join(
|
|
8457
|
+
return merged.join(delimiter2);
|
|
8335
8458
|
}
|
|
8336
|
-
function claudeNotFoundMessage() {
|
|
8459
|
+
function claudeNotFoundMessage(platform = process.platform, env = process.env) {
|
|
8460
|
+
const pathLabel = platform === "win32" ? "PATH" : "login-shell PATH";
|
|
8337
8461
|
return [
|
|
8338
|
-
|
|
8339
|
-
...
|
|
8462
|
+
`The \`claude\` CLI could not be located. Searched every directory on the ${pathLabel}, plus these well-known install locations:`,
|
|
8463
|
+
...wellKnownDirsFor(platform, env).map((d) => ` - ${d}`),
|
|
8340
8464
|
"Install Claude Code to use subscription mode: https://code.claude.com"
|
|
8341
8465
|
].join("\n");
|
|
8342
8466
|
}
|
|
@@ -8409,6 +8533,340 @@ function probeAgentRuntime(deps = {}) {
|
|
|
8409
8533
|
});
|
|
8410
8534
|
}
|
|
8411
8535
|
|
|
8536
|
+
// src/utils/windows-runner.ts
|
|
8537
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
8538
|
+
import { mkdtempSync as mkdtempSync2, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
|
|
8539
|
+
import { homedir as homedir6, tmpdir as tmpdir2, userInfo } from "node:os";
|
|
8540
|
+
import { join as join9 } from "node:path";
|
|
8541
|
+
import { promisify as promisify2 } from "node:util";
|
|
8542
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
8543
|
+
var RUNNER_TASK_NAME = "CompBoxAgentRunner";
|
|
8544
|
+
var LEGACY_SERVICE_NAME = "CompBoxAgentRunner";
|
|
8545
|
+
var RUNNER_DISPLAY_NAME = "CompBox Agent Runner";
|
|
8546
|
+
var LEGACY_ELEVATED_COMMANDS = [
|
|
8547
|
+
`sc.exe stop ${LEGACY_SERVICE_NAME}`,
|
|
8548
|
+
`sc.exe delete ${LEGACY_SERVICE_NAME}`
|
|
8549
|
+
];
|
|
8550
|
+
var defaultExec = async (file, args) => {
|
|
8551
|
+
const r = await execFileAsync2(file, args, { windowsHide: true });
|
|
8552
|
+
return { stdout: r.stdout, stderr: r.stderr };
|
|
8553
|
+
};
|
|
8554
|
+
var defaultSleep = (ms) => new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
8555
|
+
function describeExecError(err) {
|
|
8556
|
+
const e = err ?? {};
|
|
8557
|
+
const code = typeof e.code === "number" || typeof e.code === "string" ? e.code : void 0;
|
|
8558
|
+
return {
|
|
8559
|
+
code,
|
|
8560
|
+
stdout: typeof e.stdout === "string" ? e.stdout : "",
|
|
8561
|
+
stderr: typeof e.stderr === "string" ? e.stderr : "",
|
|
8562
|
+
message: err instanceof Error ? err.message : String(err)
|
|
8563
|
+
};
|
|
8564
|
+
}
|
|
8565
|
+
function failureText(f) {
|
|
8566
|
+
return `${f.stdout}
|
|
8567
|
+
${f.stderr}
|
|
8568
|
+
${f.message}`;
|
|
8569
|
+
}
|
|
8570
|
+
function isAccessDenied(f) {
|
|
8571
|
+
return f.code === 5 || /FAILED 5\b|access is denied/i.test(failureText(f));
|
|
8572
|
+
}
|
|
8573
|
+
function failureSummary(f) {
|
|
8574
|
+
const text = (f.stderr.trim() || f.stdout.trim() || f.message).replace(/\s+/g, " ");
|
|
8575
|
+
return text.length > 300 ? `${text.slice(0, 300)}\u2026` : text;
|
|
8576
|
+
}
|
|
8577
|
+
function currentUserId(env = process.env) {
|
|
8578
|
+
let user = env.USERNAME;
|
|
8579
|
+
if (!user) {
|
|
8580
|
+
try {
|
|
8581
|
+
user = userInfo().username;
|
|
8582
|
+
} catch {
|
|
8583
|
+
user = "";
|
|
8584
|
+
}
|
|
8585
|
+
}
|
|
8586
|
+
const domain = env.USERDOMAIN;
|
|
8587
|
+
return domain ? `${domain}\\${user}` : user;
|
|
8588
|
+
}
|
|
8589
|
+
function sameUser(a, b) {
|
|
8590
|
+
const norm2 = (s) => s.trim().toLowerCase();
|
|
8591
|
+
const bare = (s) => norm2(s).split("\\").pop() ?? "";
|
|
8592
|
+
const x = norm2(a);
|
|
8593
|
+
const y = norm2(b);
|
|
8594
|
+
if (!x || !y) return false;
|
|
8595
|
+
if (x === y) return true;
|
|
8596
|
+
if (!x.includes("\\") || !y.includes("\\")) return bare(x) === bare(y);
|
|
8597
|
+
return false;
|
|
8598
|
+
}
|
|
8599
|
+
function xmlEscape2(s) {
|
|
8600
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
8601
|
+
}
|
|
8602
|
+
function defaultTaskSpec() {
|
|
8603
|
+
return {
|
|
8604
|
+
nodeExe: process.execPath,
|
|
8605
|
+
scriptPath: process.argv[1] ?? "",
|
|
8606
|
+
workingDirectory: join9(homedir6(), ".compbox"),
|
|
8607
|
+
userId: currentUserId()
|
|
8608
|
+
};
|
|
8609
|
+
}
|
|
8610
|
+
function buildTaskXml(spec) {
|
|
8611
|
+
const x = xmlEscape2;
|
|
8612
|
+
return [
|
|
8613
|
+
'<?xml version="1.0" encoding="UTF-16"?>',
|
|
8614
|
+
'<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">',
|
|
8615
|
+
" <RegistrationInfo>",
|
|
8616
|
+
` <Description>${RUNNER_DISPLAY_NAME}: runs compbox run for the signed-in user.</Description>`,
|
|
8617
|
+
" </RegistrationInfo>",
|
|
8618
|
+
" <Triggers>",
|
|
8619
|
+
" <LogonTrigger>",
|
|
8620
|
+
" <Enabled>true</Enabled>",
|
|
8621
|
+
` <UserId>${x(spec.userId)}</UserId>`,
|
|
8622
|
+
" </LogonTrigger>",
|
|
8623
|
+
" </Triggers>",
|
|
8624
|
+
" <Principals>",
|
|
8625
|
+
' <Principal id="Author">',
|
|
8626
|
+
` <UserId>${x(spec.userId)}</UserId>`,
|
|
8627
|
+
" <LogonType>InteractiveToken</LogonType>",
|
|
8628
|
+
" <RunLevel>LeastPrivilege</RunLevel>",
|
|
8629
|
+
" </Principal>",
|
|
8630
|
+
" </Principals>",
|
|
8631
|
+
" <Settings>",
|
|
8632
|
+
" <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>",
|
|
8633
|
+
" <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>",
|
|
8634
|
+
" <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>",
|
|
8635
|
+
" <AllowHardTerminate>true</AllowHardTerminate>",
|
|
8636
|
+
" <StartWhenAvailable>true</StartWhenAvailable>",
|
|
8637
|
+
" <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>",
|
|
8638
|
+
" <IdleSettings>",
|
|
8639
|
+
" <StopOnIdleEnd>false</StopOnIdleEnd>",
|
|
8640
|
+
" <RestartOnIdle>false</RestartOnIdle>",
|
|
8641
|
+
" </IdleSettings>",
|
|
8642
|
+
" <AllowStartOnDemand>true</AllowStartOnDemand>",
|
|
8643
|
+
" <Enabled>true</Enabled>",
|
|
8644
|
+
" <Hidden>false</Hidden>",
|
|
8645
|
+
" <RunOnlyIfIdle>false</RunOnlyIfIdle>",
|
|
8646
|
+
" <WakeToRun>false</WakeToRun>",
|
|
8647
|
+
" <ExecutionTimeLimit>PT0S</ExecutionTimeLimit>",
|
|
8648
|
+
" <Priority>7</Priority>",
|
|
8649
|
+
" <RestartOnFailure>",
|
|
8650
|
+
" <Interval>PT1M</Interval>",
|
|
8651
|
+
" <Count>99</Count>",
|
|
8652
|
+
" </RestartOnFailure>",
|
|
8653
|
+
" </Settings>",
|
|
8654
|
+
' <Actions Context="Author">',
|
|
8655
|
+
" <Exec>",
|
|
8656
|
+
` <Command>${x(spec.nodeExe)}</Command>`,
|
|
8657
|
+
` <Arguments>${x(`"${spec.scriptPath}" run`)}</Arguments>`,
|
|
8658
|
+
` <WorkingDirectory>${x(spec.workingDirectory)}</WorkingDirectory>`,
|
|
8659
|
+
" </Exec>",
|
|
8660
|
+
" </Actions>",
|
|
8661
|
+
"</Task>",
|
|
8662
|
+
""
|
|
8663
|
+
].join("\r\n");
|
|
8664
|
+
}
|
|
8665
|
+
function encodeTaskXml(xml) {
|
|
8666
|
+
return Buffer.concat([Buffer.from([255, 254]), Buffer.from(xml, "utf16le")]);
|
|
8667
|
+
}
|
|
8668
|
+
function writeTaskXmlFile(xml) {
|
|
8669
|
+
const dir = mkdtempSync2(join9(tmpdir2(), "compbox-task-"));
|
|
8670
|
+
const path3 = join9(dir, "runner-task.xml");
|
|
8671
|
+
writeFileSync6(path3, encodeTaskXml(xml));
|
|
8672
|
+
return {
|
|
8673
|
+
path: path3,
|
|
8674
|
+
cleanup: () => {
|
|
8675
|
+
rmSync3(dir, { recursive: true, force: true });
|
|
8676
|
+
}
|
|
8677
|
+
};
|
|
8678
|
+
}
|
|
8679
|
+
function parseCsv(text) {
|
|
8680
|
+
const rows = [];
|
|
8681
|
+
let row = [];
|
|
8682
|
+
let field = "";
|
|
8683
|
+
let inQuotes = false;
|
|
8684
|
+
const endRow = () => {
|
|
8685
|
+
row.push(field);
|
|
8686
|
+
field = "";
|
|
8687
|
+
if (row.some((f) => f !== "")) rows.push(row);
|
|
8688
|
+
row = [];
|
|
8689
|
+
};
|
|
8690
|
+
for (let i = 0; i < text.length; i++) {
|
|
8691
|
+
const c = text.charAt(i);
|
|
8692
|
+
if (inQuotes) {
|
|
8693
|
+
if (c === '"') {
|
|
8694
|
+
if (text.charAt(i + 1) === '"') {
|
|
8695
|
+
field += '"';
|
|
8696
|
+
i++;
|
|
8697
|
+
} else {
|
|
8698
|
+
inQuotes = false;
|
|
8699
|
+
}
|
|
8700
|
+
} else {
|
|
8701
|
+
field += c;
|
|
8702
|
+
}
|
|
8703
|
+
} else if (c === '"') {
|
|
8704
|
+
inQuotes = true;
|
|
8705
|
+
} else if (c === ",") {
|
|
8706
|
+
row.push(field);
|
|
8707
|
+
field = "";
|
|
8708
|
+
} else if (c === "\r" || c === "\n") {
|
|
8709
|
+
if (c === "\r" && text.charAt(i + 1) === "\n") i++;
|
|
8710
|
+
endRow();
|
|
8711
|
+
} else {
|
|
8712
|
+
field += c;
|
|
8713
|
+
}
|
|
8714
|
+
}
|
|
8715
|
+
endRow();
|
|
8716
|
+
return rows;
|
|
8717
|
+
}
|
|
8718
|
+
function parseTaskQueryCsv(stdout2) {
|
|
8719
|
+
const rows = parseCsv(stdout2);
|
|
8720
|
+
const header = rows[0];
|
|
8721
|
+
if (!header) return { exists: false };
|
|
8722
|
+
const data = rows.slice(1).find((r) => r.join("\0") !== header.join("\0"));
|
|
8723
|
+
if (!data) return { exists: false };
|
|
8724
|
+
const get = (name) => {
|
|
8725
|
+
const idx = header.findIndex((h) => h.trim().toLowerCase() === name.toLowerCase());
|
|
8726
|
+
if (idx < 0) return void 0;
|
|
8727
|
+
const v = data[idx]?.trim();
|
|
8728
|
+
return v === void 0 || v === "" ? void 0 : v;
|
|
8729
|
+
};
|
|
8730
|
+
return {
|
|
8731
|
+
exists: true,
|
|
8732
|
+
status: get("Status"),
|
|
8733
|
+
runAsUser: get("Run As User"),
|
|
8734
|
+
scheduledState: get("Scheduled Task State"),
|
|
8735
|
+
taskToRun: get("Task To Run")
|
|
8736
|
+
};
|
|
8737
|
+
}
|
|
8738
|
+
async function queryRunnerTask(exec = defaultExec) {
|
|
8739
|
+
try {
|
|
8740
|
+
const { stdout: stdout2 } = await exec("schtasks.exe", [
|
|
8741
|
+
"/Query",
|
|
8742
|
+
"/TN",
|
|
8743
|
+
RUNNER_TASK_NAME,
|
|
8744
|
+
"/FO",
|
|
8745
|
+
"CSV",
|
|
8746
|
+
"/V"
|
|
8747
|
+
]);
|
|
8748
|
+
return parseTaskQueryCsv(stdout2);
|
|
8749
|
+
} catch (err) {
|
|
8750
|
+
const f = describeExecError(err);
|
|
8751
|
+
if (/cannot find|does not exist/i.test(failureText(f))) return { exists: false };
|
|
8752
|
+
return { exists: false, error: failureSummary(f) };
|
|
8753
|
+
}
|
|
8754
|
+
}
|
|
8755
|
+
function parseScState(stdout2) {
|
|
8756
|
+
const m = /STATE\s*:\s*(\d+)/.exec(stdout2);
|
|
8757
|
+
if (!m) return "unknown";
|
|
8758
|
+
return m[1] === "1" ? "stopped" : "running";
|
|
8759
|
+
}
|
|
8760
|
+
async function queryLegacyService(exec = defaultExec) {
|
|
8761
|
+
try {
|
|
8762
|
+
const { stdout: stdout2 } = await exec("sc.exe", ["query", LEGACY_SERVICE_NAME]);
|
|
8763
|
+
return parseScState(stdout2);
|
|
8764
|
+
} catch (err) {
|
|
8765
|
+
const f = describeExecError(err);
|
|
8766
|
+
if (f.code === 1060 || /\b1060\b|does not exist/i.test(failureText(f))) return "absent";
|
|
8767
|
+
return "unknown";
|
|
8768
|
+
}
|
|
8769
|
+
}
|
|
8770
|
+
async function migrateLegacyService(deps = {}) {
|
|
8771
|
+
const exec = deps.exec ?? defaultExec;
|
|
8772
|
+
const sleep2 = deps.sleep ?? defaultSleep;
|
|
8773
|
+
const polls = deps.stopPolls ?? 15;
|
|
8774
|
+
const interval = deps.stopPollIntervalMs ?? 1e3;
|
|
8775
|
+
const state = await queryLegacyService(exec);
|
|
8776
|
+
if (state === "absent") return { outcome: "absent", stillRunning: false };
|
|
8777
|
+
if (state === "unknown") {
|
|
8778
|
+
return {
|
|
8779
|
+
outcome: "unknown",
|
|
8780
|
+
stillRunning: false,
|
|
8781
|
+
detail: `could not query the legacy "${LEGACY_SERVICE_NAME}" service with sc.exe`
|
|
8782
|
+
};
|
|
8783
|
+
}
|
|
8784
|
+
let running = state === "running";
|
|
8785
|
+
if (running) {
|
|
8786
|
+
try {
|
|
8787
|
+
await exec("sc.exe", ["stop", LEGACY_SERVICE_NAME]);
|
|
8788
|
+
} catch (err) {
|
|
8789
|
+
const f = describeExecError(err);
|
|
8790
|
+
if (isAccessDenied(f)) {
|
|
8791
|
+
return { outcome: "access-denied", stillRunning: true, detail: failureSummary(f) };
|
|
8792
|
+
}
|
|
8793
|
+
if (!(f.code === 1062 || /\b1062\b/.test(failureText(f)))) {
|
|
8794
|
+
return { outcome: "failed", stillRunning: true, detail: failureSummary(f) };
|
|
8795
|
+
}
|
|
8796
|
+
}
|
|
8797
|
+
for (let i = 0; i < polls; i++) {
|
|
8798
|
+
const now = await queryLegacyService(exec);
|
|
8799
|
+
if (now === "stopped" || now === "absent") {
|
|
8800
|
+
running = false;
|
|
8801
|
+
break;
|
|
8802
|
+
}
|
|
8803
|
+
await sleep2(interval);
|
|
8804
|
+
}
|
|
8805
|
+
if (running) {
|
|
8806
|
+
return {
|
|
8807
|
+
outcome: "failed",
|
|
8808
|
+
stillRunning: true,
|
|
8809
|
+
detail: `the legacy service did not stop within ${String(Math.round(polls * interval / 1e3))}s`
|
|
8810
|
+
};
|
|
8811
|
+
}
|
|
8812
|
+
}
|
|
8813
|
+
try {
|
|
8814
|
+
await exec("sc.exe", ["delete", LEGACY_SERVICE_NAME]);
|
|
8815
|
+
} catch (err) {
|
|
8816
|
+
const f = describeExecError(err);
|
|
8817
|
+
return {
|
|
8818
|
+
outcome: isAccessDenied(f) ? "access-denied" : "failed",
|
|
8819
|
+
stillRunning: false,
|
|
8820
|
+
detail: failureSummary(f)
|
|
8821
|
+
};
|
|
8822
|
+
}
|
|
8823
|
+
return { outcome: "removed", stillRunning: false };
|
|
8824
|
+
}
|
|
8825
|
+
async function installRunnerTask(deps = {}) {
|
|
8826
|
+
const exec = deps.exec ?? defaultExec;
|
|
8827
|
+
const migration = await migrateLegacyService({ ...deps, exec });
|
|
8828
|
+
const xml = buildTaskXml(deps.spec ?? defaultTaskSpec());
|
|
8829
|
+
const file = (deps.writeXml ?? writeTaskXmlFile)(xml);
|
|
8830
|
+
try {
|
|
8831
|
+
await exec("schtasks.exe", ["/Create", "/TN", RUNNER_TASK_NAME, "/XML", file.path, "/F"]);
|
|
8832
|
+
} finally {
|
|
8833
|
+
file.cleanup();
|
|
8834
|
+
}
|
|
8835
|
+
if (migration.stillRunning) {
|
|
8836
|
+
return { migration, started: false, notStartedReason: "legacy-running" };
|
|
8837
|
+
}
|
|
8838
|
+
try {
|
|
8839
|
+
await exec("schtasks.exe", ["/Run", "/TN", RUNNER_TASK_NAME]);
|
|
8840
|
+
return { migration, started: true };
|
|
8841
|
+
} catch (err) {
|
|
8842
|
+
return {
|
|
8843
|
+
migration,
|
|
8844
|
+
started: false,
|
|
8845
|
+
notStartedReason: "start-failed",
|
|
8846
|
+
startError: failureSummary(describeExecError(err))
|
|
8847
|
+
};
|
|
8848
|
+
}
|
|
8849
|
+
}
|
|
8850
|
+
async function startRunnerTask(exec = defaultExec) {
|
|
8851
|
+
if (await queryLegacyService(exec) === "running") {
|
|
8852
|
+
return { started: false, reason: "legacy-running" };
|
|
8853
|
+
}
|
|
8854
|
+
try {
|
|
8855
|
+
await exec("schtasks.exe", ["/Run", "/TN", RUNNER_TASK_NAME]);
|
|
8856
|
+
return { started: true };
|
|
8857
|
+
} catch (err) {
|
|
8858
|
+
return { started: false, reason: "failed", error: failureSummary(describeExecError(err)) };
|
|
8859
|
+
}
|
|
8860
|
+
}
|
|
8861
|
+
async function stopRunnerTask(exec = defaultExec) {
|
|
8862
|
+
await exec("schtasks.exe", ["/End", "/TN", RUNNER_TASK_NAME]);
|
|
8863
|
+
}
|
|
8864
|
+
async function uninstallRunnerTask(exec = defaultExec) {
|
|
8865
|
+
await exec("schtasks.exe", ["/End", "/TN", RUNNER_TASK_NAME]).catch(() => {
|
|
8866
|
+
});
|
|
8867
|
+
await exec("schtasks.exe", ["/Delete", "/TN", RUNNER_TASK_NAME, "/F"]);
|
|
8868
|
+
}
|
|
8869
|
+
|
|
8412
8870
|
// src/commands/doctor.ts
|
|
8413
8871
|
function printResult(result) {
|
|
8414
8872
|
const marker = result.warning ? chalk8.yellow("WARN") : result.skipped ? chalk8.yellow("SKIP") : result.passed ? chalk8.green("PASS") : chalk8.red("FAIL");
|
|
@@ -8527,14 +8985,22 @@ async function launchTargetCheck(mcpStatus, deps = {}) {
|
|
|
8527
8985
|
detail: mcpStatus.entryPresent ? "Skipped \u2014 MCP entry present but has no launch command. Re-run `compbox configure` to rewrite it." : "Skipped \u2014 no CompBox MCP entry to verify. Run `compbox configure` to write one."
|
|
8528
8986
|
};
|
|
8529
8987
|
}
|
|
8530
|
-
|
|
8988
|
+
const platform = deps.platform ?? process.platform;
|
|
8989
|
+
if (platform === "win32" && mcpStatus.command === "npx") {
|
|
8990
|
+
return {
|
|
8991
|
+
name,
|
|
8992
|
+
passed: false,
|
|
8993
|
+
detail: "Launch target is bare `npx`, which Claude Code cannot spawn on Windows (npx is a .cmd shim and MCP servers are launched without a shell). Run `compbox configure` to rewrite the entry."
|
|
8994
|
+
};
|
|
8995
|
+
}
|
|
8996
|
+
if (isNpxLaunch(mcpStatus.command, mcpStatus.args)) {
|
|
8531
8997
|
return {
|
|
8532
8998
|
name,
|
|
8533
8999
|
passed: true,
|
|
8534
9000
|
detail: `Launch target is \`npx\` \u2014 ${MCP_SERVER_PACKAGE} resolves from registry.npmjs.org on first use; nothing installed locally to verify.`
|
|
8535
9001
|
};
|
|
8536
9002
|
}
|
|
8537
|
-
if (mcpStatus.command
|
|
9003
|
+
if (!isNodeCommand(mcpStatus.command)) {
|
|
8538
9004
|
return {
|
|
8539
9005
|
name,
|
|
8540
9006
|
passed: true,
|
|
@@ -8547,7 +9013,7 @@ async function launchTargetCheck(mcpStatus, deps = {}) {
|
|
|
8547
9013
|
return {
|
|
8548
9014
|
name,
|
|
8549
9015
|
passed: false,
|
|
8550
|
-
detail: "Launch command is
|
|
9016
|
+
detail: "Launch command is Node but no bundle path is configured \u2014 re-run `compbox configure` to rewrite the entry."
|
|
8551
9017
|
};
|
|
8552
9018
|
}
|
|
8553
9019
|
if (!fileExists(bundlePath)) {
|
|
@@ -8557,7 +9023,7 @@ async function launchTargetCheck(mcpStatus, deps = {}) {
|
|
|
8557
9023
|
detail: `Configured MCP bundle not found at ${bundlePath} \u2014 run \`brew reinstall compbox\` (or re-run \`compbox configure\`) to restore it.`
|
|
8558
9024
|
};
|
|
8559
9025
|
}
|
|
8560
|
-
const probeResult = await probe(
|
|
9026
|
+
const probeResult = await probe(mcpStatus.command, [bundlePath]);
|
|
8561
9027
|
if (probeResult.status === "answered") {
|
|
8562
9028
|
return {
|
|
8563
9029
|
name,
|
|
@@ -8633,6 +9099,65 @@ function checkBrewService(deps = {}) {
|
|
|
8633
9099
|
detail: started ? "CompBox Agent Runner is running under `brew services`." : "CompBox service is registered but not running \u2014 run `brew services start compbox`."
|
|
8634
9100
|
};
|
|
8635
9101
|
}
|
|
9102
|
+
async function checkWindowsRunner(deps = {}) {
|
|
9103
|
+
const userId = deps.userId ?? currentUserId();
|
|
9104
|
+
const queryTask = deps.queryTask ?? queryRunnerTask;
|
|
9105
|
+
const queryLegacy = deps.queryLegacy ?? queryLegacyService;
|
|
9106
|
+
const [task, legacy] = await Promise.all([queryTask(deps.exec), queryLegacy(deps.exec)]);
|
|
9107
|
+
const elevated = LEGACY_ELEVATED_COMMANDS.join(" && ");
|
|
9108
|
+
const taskName = "Agent Runner task (Windows)";
|
|
9109
|
+
let taskResult;
|
|
9110
|
+
if (task.error) {
|
|
9111
|
+
taskResult = {
|
|
9112
|
+
name: taskName,
|
|
9113
|
+
passed: false,
|
|
9114
|
+
detail: `Could not query Scheduled Task "${RUNNER_TASK_NAME}" (${task.error}) \u2014 run \`compbox service status\` for details.`
|
|
9115
|
+
};
|
|
9116
|
+
} else if (!task.exists) {
|
|
9117
|
+
taskResult = {
|
|
9118
|
+
name: taskName,
|
|
9119
|
+
passed: false,
|
|
9120
|
+
detail: `Scheduled Task "${RUNNER_TASK_NAME}" is not registered \u2014 run \`compbox service install\`.`
|
|
9121
|
+
};
|
|
9122
|
+
} else if (task.runAsUser && !sameUser(task.runAsUser, userId)) {
|
|
9123
|
+
taskResult = {
|
|
9124
|
+
name: taskName,
|
|
9125
|
+
passed: false,
|
|
9126
|
+
detail: `Scheduled Task "${RUNNER_TASK_NAME}" runs as ${task.runAsUser}, not ${userId} \u2014 run \`compbox service install\` as ${userId} to re-register it.`
|
|
9127
|
+
};
|
|
9128
|
+
} else if (!task.status || !/^running$/i.test(task.status)) {
|
|
9129
|
+
taskResult = {
|
|
9130
|
+
name: taskName,
|
|
9131
|
+
passed: false,
|
|
9132
|
+
detail: `Scheduled Task "${RUNNER_TASK_NAME}" is registered but not running (status: ${task.status ?? "unknown"}) \u2014 run \`compbox service start\`.`
|
|
9133
|
+
};
|
|
9134
|
+
} else {
|
|
9135
|
+
taskResult = {
|
|
9136
|
+
name: taskName,
|
|
9137
|
+
passed: true,
|
|
9138
|
+
detail: `Agent Runner is running as ${task.runAsUser ?? userId} (Scheduled Task "${RUNNER_TASK_NAME}").`
|
|
9139
|
+
};
|
|
9140
|
+
}
|
|
9141
|
+
const legacyName = "Legacy LocalSystem service (Windows)";
|
|
9142
|
+
let legacyResult;
|
|
9143
|
+
if (legacy === "absent") {
|
|
9144
|
+
legacyResult = { name: legacyName, passed: true, detail: "No leftover LocalSystem service." };
|
|
9145
|
+
} else if (legacy === "unknown") {
|
|
9146
|
+
legacyResult = {
|
|
9147
|
+
name: legacyName,
|
|
9148
|
+
passed: true,
|
|
9149
|
+
warning: true,
|
|
9150
|
+
detail: `Could not query the legacy "${LEGACY_SERVICE_NAME}" service with sc.exe \u2014 check with \`sc.exe query ${LEGACY_SERVICE_NAME}\`.`
|
|
9151
|
+
};
|
|
9152
|
+
} else {
|
|
9153
|
+
legacyResult = {
|
|
9154
|
+
name: legacyName,
|
|
9155
|
+
passed: false,
|
|
9156
|
+
detail: `The old LocalSystem service "${LEGACY_SERVICE_NAME}" is still installed (${legacy}) \u2014 from an Administrator terminal run: ${elevated}`
|
|
9157
|
+
};
|
|
9158
|
+
}
|
|
9159
|
+
return [taskResult, legacyResult];
|
|
9160
|
+
}
|
|
8636
9161
|
async function checkPxpipe() {
|
|
8637
9162
|
if (!isPxpipeEnabled()) {
|
|
8638
9163
|
return {
|
|
@@ -8877,6 +9402,9 @@ var doctorCommand = new Command7("doctor").description("Diagnose config, connect
|
|
|
8877
9402
|
if (process.platform === "darwin") {
|
|
8878
9403
|
results.push(checkBrewService());
|
|
8879
9404
|
}
|
|
9405
|
+
if (process.platform === "win32") {
|
|
9406
|
+
results.push(...await checkWindowsRunner());
|
|
9407
|
+
}
|
|
8880
9408
|
results.push(await checkPxpipe());
|
|
8881
9409
|
results.forEach(printResult);
|
|
8882
9410
|
const failedCount = countFailures(results);
|
|
@@ -9208,16 +9736,168 @@ async function finishMergeApproval(approval, merge) {
|
|
|
9208
9736
|
|
|
9209
9737
|
// src/commands/run.ts
|
|
9210
9738
|
import { Command as Command8 } from "commander";
|
|
9211
|
-
import { delimiter
|
|
9739
|
+
import { delimiter } from "node:path";
|
|
9212
9740
|
import chalk9 from "chalk";
|
|
9213
9741
|
|
|
9214
9742
|
// src/utils/agent-invoker.ts
|
|
9215
9743
|
import Anthropic from "@anthropic-ai/sdk";
|
|
9216
|
-
import { execFile as
|
|
9744
|
+
import { execFile as execFile3, spawn as spawn6, spawnSync } from "node:child_process";
|
|
9745
|
+
|
|
9746
|
+
// src/utils/process-spawn.ts
|
|
9747
|
+
import { spawn as nodeSpawn2 } from "node:child_process";
|
|
9748
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
9749
|
+
import { win32 as win32Path2 } from "node:path";
|
|
9750
|
+
|
|
9751
|
+
// src/utils/process-group.ts
|
|
9752
|
+
import { spawn as nodeSpawn } from "node:child_process";
|
|
9753
|
+
var CANCEL_GRACE_MS = 1e4;
|
|
9754
|
+
function groupSpawnOptions(platform = process.platform) {
|
|
9755
|
+
return platform === "win32" ? {} : { detached: true };
|
|
9756
|
+
}
|
|
9757
|
+
function taskkillTree(pid, spawn9 = nodeSpawn) {
|
|
9758
|
+
try {
|
|
9759
|
+
const killer = spawn9("taskkill", ["/pid", String(pid), "/T", "/F"], {
|
|
9760
|
+
stdio: "ignore",
|
|
9761
|
+
windowsHide: true
|
|
9762
|
+
});
|
|
9763
|
+
killer.on("error", () => {
|
|
9764
|
+
});
|
|
9765
|
+
} catch {
|
|
9766
|
+
}
|
|
9767
|
+
}
|
|
9768
|
+
function windowsKillTree(pid, deps) {
|
|
9769
|
+
if (deps.killTree) deps.killTree(pid);
|
|
9770
|
+
else taskkillTree(pid, deps.spawn);
|
|
9771
|
+
}
|
|
9772
|
+
function signalGroup(child, signal, deps) {
|
|
9773
|
+
const pid = child.pid;
|
|
9774
|
+
if (pid === void 0) {
|
|
9775
|
+
try {
|
|
9776
|
+
child.kill(signal);
|
|
9777
|
+
} catch {
|
|
9778
|
+
}
|
|
9779
|
+
return;
|
|
9780
|
+
}
|
|
9781
|
+
const kill = deps.kill ?? ((p, s) => process.kill(p, s));
|
|
9782
|
+
try {
|
|
9783
|
+
kill(-pid, signal);
|
|
9784
|
+
} catch (error) {
|
|
9785
|
+
if (error.code === "ESRCH") return;
|
|
9786
|
+
try {
|
|
9787
|
+
child.kill(signal);
|
|
9788
|
+
} catch {
|
|
9789
|
+
}
|
|
9790
|
+
}
|
|
9791
|
+
}
|
|
9792
|
+
function terminateProcessGroup(child, deps = {}) {
|
|
9793
|
+
const platform = deps.platform ?? process.platform;
|
|
9794
|
+
if (platform === "win32") {
|
|
9795
|
+
if (child.pid !== void 0) windowsKillTree(child.pid, deps);
|
|
9796
|
+
else child.kill("SIGKILL");
|
|
9797
|
+
return () => void 0;
|
|
9798
|
+
}
|
|
9799
|
+
signalGroup(child, "SIGTERM", deps);
|
|
9800
|
+
const escalate = setTimeout(() => {
|
|
9801
|
+
signalGroup(child, "SIGKILL", deps);
|
|
9802
|
+
}, deps.graceMs ?? CANCEL_GRACE_MS);
|
|
9803
|
+
escalate.unref();
|
|
9804
|
+
return () => {
|
|
9805
|
+
clearTimeout(escalate);
|
|
9806
|
+
};
|
|
9807
|
+
}
|
|
9808
|
+
function killProcessGroupNow(child, deps = {}) {
|
|
9809
|
+
const platform = deps.platform ?? process.platform;
|
|
9810
|
+
if (platform === "win32") {
|
|
9811
|
+
if (child.pid !== void 0) windowsKillTree(child.pid, deps);
|
|
9812
|
+
else child.kill("SIGKILL");
|
|
9813
|
+
return;
|
|
9814
|
+
}
|
|
9815
|
+
signalGroup(child, "SIGKILL", deps);
|
|
9816
|
+
}
|
|
9817
|
+
function killGroupOnAbort(signal, child, onAbort, deps = {}) {
|
|
9818
|
+
if (!signal) return () => void 0;
|
|
9819
|
+
const handler = () => {
|
|
9820
|
+
onAbort();
|
|
9821
|
+
terminateProcessGroup(child, deps);
|
|
9822
|
+
};
|
|
9823
|
+
if (signal.aborted) {
|
|
9824
|
+
handler();
|
|
9825
|
+
} else {
|
|
9826
|
+
signal.addEventListener("abort", handler, { once: true });
|
|
9827
|
+
}
|
|
9828
|
+
return () => {
|
|
9829
|
+
signal.removeEventListener("abort", handler);
|
|
9830
|
+
};
|
|
9831
|
+
}
|
|
9832
|
+
function cancelledRunResult(what) {
|
|
9833
|
+
return {
|
|
9834
|
+
status: "failed",
|
|
9835
|
+
result: { cancelled: true, message: `Cancelled from the website; the ${what} was stopped.` }
|
|
9836
|
+
};
|
|
9837
|
+
}
|
|
9838
|
+
|
|
9839
|
+
// src/utils/process-spawn.ts
|
|
9840
|
+
var CMD_META_CHARS = /([()\][%!^"`<>&|;, *?])/g;
|
|
9841
|
+
function isBatchFile(command) {
|
|
9842
|
+
return /\.(cmd|bat)$/i.test(command.trim());
|
|
9843
|
+
}
|
|
9844
|
+
function escapeCmdMeta(value) {
|
|
9845
|
+
return value.replace(CMD_META_CHARS, "^$1");
|
|
9846
|
+
}
|
|
9847
|
+
function escapeArgument(arg, doubleEscape) {
|
|
9848
|
+
let quoted = arg.replace(/(\\*)"/g, '$1$1\\"');
|
|
9849
|
+
quoted = quoted.replace(/(\\*)$/, "$1$1");
|
|
9850
|
+
quoted = escapeCmdMeta(`"${quoted}"`);
|
|
9851
|
+
return doubleEscape ? escapeCmdMeta(quoted) : quoted;
|
|
9852
|
+
}
|
|
9853
|
+
function buildWindowsCmdLine(command, args) {
|
|
9854
|
+
const doubleEscape = isBatchFile(command);
|
|
9855
|
+
const escapedCommand = escapeCmdMeta(command.replace(/"/g, ""));
|
|
9856
|
+
return [escapedCommand, ...args.map((arg) => escapeArgument(arg, doubleEscape))].join(" ");
|
|
9857
|
+
}
|
|
9858
|
+
function envValue(env, name) {
|
|
9859
|
+
const upper = name.toUpperCase();
|
|
9860
|
+
const key = Object.keys(env).find((k) => k.toUpperCase() === upper);
|
|
9861
|
+
return key === void 0 ? void 0 : env[key];
|
|
9862
|
+
}
|
|
9863
|
+
function resolveWindowsCommand(command, env, exists = existsSync10) {
|
|
9864
|
+
if (/[\\/:]/.test(command) || win32Path2.extname(command) !== "") return command;
|
|
9865
|
+
const exts = (envValue(env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((ext) => ext !== "");
|
|
9866
|
+
const dirs = (envValue(env, "PATH") ?? "").split(";").filter((dir) => dir !== "");
|
|
9867
|
+
for (const dir of dirs) {
|
|
9868
|
+
for (const ext of exts) {
|
|
9869
|
+
const candidate = win32Path2.join(dir.replace(/"/g, ""), command + ext.toLowerCase());
|
|
9870
|
+
if (exists(candidate)) return candidate;
|
|
9871
|
+
}
|
|
9872
|
+
}
|
|
9873
|
+
return command;
|
|
9874
|
+
}
|
|
9875
|
+
function planCrossPlatformSpawn(command, args, options = {}, planEnv = {}) {
|
|
9876
|
+
const platform = planEnv.platform ?? process.platform;
|
|
9877
|
+
const { shell: _shell, ...rest } = options;
|
|
9878
|
+
if (platform !== "win32") return { command, args: [...args], options: rest };
|
|
9879
|
+
const env = options.env ?? planEnv.env ?? process.env;
|
|
9880
|
+
const resolved = resolveWindowsCommand(command, env, planEnv.exists);
|
|
9881
|
+
if (!isBatchFile(resolved)) return { command, args: [...args], options: rest };
|
|
9882
|
+
return {
|
|
9883
|
+
command: envValue(env, "ComSpec") ?? "cmd.exe",
|
|
9884
|
+
args: ["/d", "/s", "/c", `"${buildWindowsCmdLine(resolved, args)}"`],
|
|
9885
|
+
options: { ...rest, windowsVerbatimArguments: true, windowsHide: true }
|
|
9886
|
+
};
|
|
9887
|
+
}
|
|
9888
|
+
function spawnCrossPlatform(command, args = [], options = {}, deps = {}) {
|
|
9889
|
+
const plan = planCrossPlatformSpawn(command, args, options, deps);
|
|
9890
|
+
return (deps.spawn ?? nodeSpawn2)(plan.command, plan.args, plan.options);
|
|
9891
|
+
}
|
|
9892
|
+
function killProcessTree(child, deps = {}) {
|
|
9893
|
+
killProcessGroupNow(child, deps);
|
|
9894
|
+
}
|
|
9895
|
+
|
|
9896
|
+
// src/utils/agent-invoker.ts
|
|
9217
9897
|
import { randomUUID } from "node:crypto";
|
|
9218
|
-
import { mkdirSync as
|
|
9898
|
+
import { copyFileSync as copyFileSync3, existsSync as existsSync15, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync4 } from "node:fs";
|
|
9219
9899
|
import { mkdir as mkdir2, mkdtemp, realpath, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
9220
|
-
import { homedir as
|
|
9900
|
+
import { homedir as homedir8, tmpdir as tmpdir4 } from "node:os";
|
|
9221
9901
|
import { join as join16 } from "node:path";
|
|
9222
9902
|
|
|
9223
9903
|
// src/utils/run-timings.ts
|
|
@@ -9326,18 +10006,34 @@ import {
|
|
|
9326
10006
|
readdirSync,
|
|
9327
10007
|
renameSync,
|
|
9328
10008
|
statSync as statSync3,
|
|
9329
|
-
writeFileSync as
|
|
10009
|
+
writeFileSync as writeFileSync8
|
|
9330
10010
|
} from "node:fs";
|
|
9331
10011
|
import { isAbsolute as isAbsolute2, join as join11 } from "node:path";
|
|
9332
10012
|
|
|
9333
10013
|
// src/utils/package-manager-shims.ts
|
|
9334
|
-
import { accessSync as accessSync2, chmodSync as chmodSync3, constants, existsSync as
|
|
9335
|
-
import { homedir as
|
|
9336
|
-
import {
|
|
10014
|
+
import { accessSync as accessSync2, chmodSync as chmodSync3, constants, existsSync as existsSync11, mkdirSync as mkdirSync5, writeFileSync as writeFileSync7 } from "node:fs";
|
|
10015
|
+
import { homedir as homedir7 } from "node:os";
|
|
10016
|
+
import { dirname as dirname4, join as join10, posix as posixPath2, win32 as win32Path3 } from "node:path";
|
|
9337
10017
|
var STAND_INS = { pnpm: "pnpm@10", yarn: "yarn@1" };
|
|
9338
|
-
function
|
|
9339
|
-
|
|
10018
|
+
function delimiterFor(platform) {
|
|
10019
|
+
return platform === "win32" ? win32Path3.delimiter : posixPath2.delimiter;
|
|
10020
|
+
}
|
|
10021
|
+
function sameDir(a, b, platform) {
|
|
10022
|
+
if (platform !== "win32") return posixPath2.resolve(a) === posixPath2.resolve(b);
|
|
10023
|
+
const norm2 = (d) => d.replace(/[\\/]+$/, "").replace(/\//g, "\\").toLowerCase();
|
|
10024
|
+
return norm2(a) === norm2(b);
|
|
10025
|
+
}
|
|
10026
|
+
function pathWithout(path3, exclude, platform = process.platform) {
|
|
10027
|
+
const delim = delimiterFor(platform);
|
|
10028
|
+
return path3.split(delim).filter((d) => d && !sameDir(d, exclude, platform)).join(delim);
|
|
10029
|
+
}
|
|
10030
|
+
function isOnPath(command, path3, platform = process.platform, env = process.env) {
|
|
10031
|
+
for (const dir of path3.split(delimiterFor(platform))) {
|
|
9340
10032
|
if (!dir) continue;
|
|
10033
|
+
if (platform === "win32") {
|
|
10034
|
+
if (findWin32Executable(command, dir, env)) return true;
|
|
10035
|
+
continue;
|
|
10036
|
+
}
|
|
9341
10037
|
try {
|
|
9342
10038
|
accessSync2(join10(dir, command), constants.X_OK);
|
|
9343
10039
|
return true;
|
|
@@ -9346,6 +10042,18 @@ function isOnPath(command, path3) {
|
|
|
9346
10042
|
}
|
|
9347
10043
|
return false;
|
|
9348
10044
|
}
|
|
10045
|
+
function win32Extensions(env) {
|
|
10046
|
+
const raw = env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD";
|
|
10047
|
+
return raw.split(";").map((e) => e.trim().toLowerCase()).filter((e) => e.length > 1 && e.startsWith("."));
|
|
10048
|
+
}
|
|
10049
|
+
function findWin32Executable(command, dir, env) {
|
|
10050
|
+
const names = win32Path3.extname(command) ? [command] : win32Extensions(env).map((ext) => command + ext);
|
|
10051
|
+
for (const name of names) {
|
|
10052
|
+
const candidate = join10(dir, name);
|
|
10053
|
+
if (isExecutableFile(candidate, "win32", env)) return candidate;
|
|
10054
|
+
}
|
|
10055
|
+
return null;
|
|
10056
|
+
}
|
|
9349
10057
|
function shimScript(tool, nodeBinDir, npx) {
|
|
9350
10058
|
return [
|
|
9351
10059
|
"#!/bin/sh",
|
|
@@ -9357,19 +10065,42 @@ function shimScript(tool, nodeBinDir, npx) {
|
|
|
9357
10065
|
""
|
|
9358
10066
|
].join("\n");
|
|
9359
10067
|
}
|
|
10068
|
+
function shimCmdScript(tool, nodeBinDir, npx) {
|
|
10069
|
+
return [
|
|
10070
|
+
"@echo off",
|
|
10071
|
+
`rem Written by CompBox: ${tool} isn't installed on this computer, so it runs`,
|
|
10072
|
+
"rem through Node's npx. Installing it yourself makes CompBox use that instead.",
|
|
10073
|
+
`set "PATH=${nodeBinDir};%PATH%"`,
|
|
10074
|
+
`"${npx}" --yes ${STAND_INS[tool]} %*`,
|
|
10075
|
+
"exit /b %ERRORLEVEL%",
|
|
10076
|
+
""
|
|
10077
|
+
].join("\r\n");
|
|
10078
|
+
}
|
|
9360
10079
|
function ensurePackageManagerShims(opts = {}) {
|
|
9361
|
-
|
|
9362
|
-
const
|
|
9363
|
-
const
|
|
10080
|
+
const platform = opts.platform ?? process.platform;
|
|
10081
|
+
const env = opts.env ?? process.env;
|
|
10082
|
+
const dir = join10(opts.home ?? homedir7(), ".compbox", "shims");
|
|
10083
|
+
const searchPath = opts.searchPath ?? ((p) => claudeChildEnvPath(p, { platform, env }));
|
|
10084
|
+
const path3 = pathWithout(searchPath(opts.path ?? process.env.PATH), dir, platform);
|
|
10085
|
+
const missing = Object.keys(STAND_INS).filter((tool) => !isOnPath(tool, path3, platform, env));
|
|
9364
10086
|
if (missing.length === 0) return null;
|
|
9365
10087
|
const nodeBinDir = opts.nodeBinDir ?? dirname4(process.execPath);
|
|
9366
|
-
const
|
|
9367
|
-
|
|
10088
|
+
const win322 = platform === "win32";
|
|
10089
|
+
let npx;
|
|
10090
|
+
if (win322) {
|
|
10091
|
+
npx = findWin32Executable("npx", nodeBinDir, env) ?? "npx";
|
|
10092
|
+
} else {
|
|
10093
|
+
npx = existsSync11(join10(nodeBinDir, "npx")) ? join10(nodeBinDir, "npx") : "npx";
|
|
10094
|
+
}
|
|
9368
10095
|
try {
|
|
9369
10096
|
mkdirSync5(dir, { recursive: true });
|
|
9370
10097
|
for (const tool of missing) {
|
|
10098
|
+
if (win322) {
|
|
10099
|
+
writeFileSync7(join10(dir, `${tool}.cmd`), shimCmdScript(tool, nodeBinDir, npx));
|
|
10100
|
+
continue;
|
|
10101
|
+
}
|
|
9371
10102
|
const file = join10(dir, tool);
|
|
9372
|
-
|
|
10103
|
+
writeFileSync7(file, shimScript(tool, nodeBinDir, npx));
|
|
9373
10104
|
chmodSync3(file, 493);
|
|
9374
10105
|
}
|
|
9375
10106
|
} catch {
|
|
@@ -9450,7 +10181,7 @@ function ghShimCmd(realGhPath) {
|
|
|
9450
10181
|
}
|
|
9451
10182
|
function writeAtomic(file, content, mode) {
|
|
9452
10183
|
const tmp = `${file}.${String(process.pid)}.${String(Date.now())}.tmp`;
|
|
9453
|
-
|
|
10184
|
+
writeFileSync8(tmp, content);
|
|
9454
10185
|
chmodSync4(tmp, mode);
|
|
9455
10186
|
renameSync(tmp, file);
|
|
9456
10187
|
}
|
|
@@ -9627,90 +10358,6 @@ function parseClaudeJsonResult(stdout2, fallbackModel) {
|
|
|
9627
10358
|
return { text: typeof data.result === "string" ? data.result : "", usage };
|
|
9628
10359
|
}
|
|
9629
10360
|
|
|
9630
|
-
// src/utils/process-group.ts
|
|
9631
|
-
import { spawn as nodeSpawn } from "node:child_process";
|
|
9632
|
-
var CANCEL_GRACE_MS = 1e4;
|
|
9633
|
-
function groupSpawnOptions(platform = process.platform) {
|
|
9634
|
-
return platform === "win32" ? {} : { detached: true };
|
|
9635
|
-
}
|
|
9636
|
-
function defaultKillTree(pid) {
|
|
9637
|
-
try {
|
|
9638
|
-
const killer = nodeSpawn("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
9639
|
-
stdio: "ignore",
|
|
9640
|
-
windowsHide: true
|
|
9641
|
-
});
|
|
9642
|
-
killer.on("error", () => {
|
|
9643
|
-
});
|
|
9644
|
-
} catch {
|
|
9645
|
-
}
|
|
9646
|
-
}
|
|
9647
|
-
function signalGroup(child, signal, deps) {
|
|
9648
|
-
const pid = child.pid;
|
|
9649
|
-
if (pid === void 0) {
|
|
9650
|
-
try {
|
|
9651
|
-
child.kill(signal);
|
|
9652
|
-
} catch {
|
|
9653
|
-
}
|
|
9654
|
-
return;
|
|
9655
|
-
}
|
|
9656
|
-
const kill = deps.kill ?? ((p, s) => process.kill(p, s));
|
|
9657
|
-
try {
|
|
9658
|
-
kill(-pid, signal);
|
|
9659
|
-
} catch (error) {
|
|
9660
|
-
if (error.code === "ESRCH") return;
|
|
9661
|
-
try {
|
|
9662
|
-
child.kill(signal);
|
|
9663
|
-
} catch {
|
|
9664
|
-
}
|
|
9665
|
-
}
|
|
9666
|
-
}
|
|
9667
|
-
function terminateProcessGroup(child, deps = {}) {
|
|
9668
|
-
const platform = deps.platform ?? process.platform;
|
|
9669
|
-
if (platform === "win32") {
|
|
9670
|
-
if (child.pid !== void 0) (deps.killTree ?? defaultKillTree)(child.pid);
|
|
9671
|
-
else child.kill("SIGKILL");
|
|
9672
|
-
return () => void 0;
|
|
9673
|
-
}
|
|
9674
|
-
signalGroup(child, "SIGTERM", deps);
|
|
9675
|
-
const escalate = setTimeout(() => {
|
|
9676
|
-
signalGroup(child, "SIGKILL", deps);
|
|
9677
|
-
}, deps.graceMs ?? CANCEL_GRACE_MS);
|
|
9678
|
-
escalate.unref();
|
|
9679
|
-
return () => {
|
|
9680
|
-
clearTimeout(escalate);
|
|
9681
|
-
};
|
|
9682
|
-
}
|
|
9683
|
-
function killProcessGroupNow(child, deps = {}) {
|
|
9684
|
-
const platform = deps.platform ?? process.platform;
|
|
9685
|
-
if (platform === "win32") {
|
|
9686
|
-
if (child.pid !== void 0) (deps.killTree ?? defaultKillTree)(child.pid);
|
|
9687
|
-
else child.kill("SIGKILL");
|
|
9688
|
-
return;
|
|
9689
|
-
}
|
|
9690
|
-
signalGroup(child, "SIGKILL", deps);
|
|
9691
|
-
}
|
|
9692
|
-
function killGroupOnAbort(signal, child, onAbort, deps = {}) {
|
|
9693
|
-
if (!signal) return () => void 0;
|
|
9694
|
-
const handler = () => {
|
|
9695
|
-
onAbort();
|
|
9696
|
-
terminateProcessGroup(child, deps);
|
|
9697
|
-
};
|
|
9698
|
-
if (signal.aborted) {
|
|
9699
|
-
handler();
|
|
9700
|
-
} else {
|
|
9701
|
-
signal.addEventListener("abort", handler, { once: true });
|
|
9702
|
-
}
|
|
9703
|
-
return () => {
|
|
9704
|
-
signal.removeEventListener("abort", handler);
|
|
9705
|
-
};
|
|
9706
|
-
}
|
|
9707
|
-
function cancelledRunResult(what) {
|
|
9708
|
-
return {
|
|
9709
|
-
status: "failed",
|
|
9710
|
-
result: { cancelled: true, message: `Cancelled from the website; the ${what} was stopped.` }
|
|
9711
|
-
};
|
|
9712
|
-
}
|
|
9713
|
-
|
|
9714
10361
|
// src/utils/progress-watcher.ts
|
|
9715
10362
|
var PROGRESS_WATCHER_TICK_MS = 6e4;
|
|
9716
10363
|
async function readProbe(probe) {
|
|
@@ -10015,21 +10662,21 @@ function nextZonedOccurrence(now, hour, minute, zone) {
|
|
|
10015
10662
|
import { spawn as spawn5 } from "node:child_process";
|
|
10016
10663
|
import {
|
|
10017
10664
|
copyFileSync,
|
|
10018
|
-
existsSync as
|
|
10665
|
+
existsSync as existsSync12,
|
|
10019
10666
|
mkdirSync as mkdirSync8,
|
|
10020
10667
|
readdirSync as readdirSync2,
|
|
10021
10668
|
readFileSync as readFileSync6,
|
|
10022
10669
|
realpathSync as realpathSync3,
|
|
10023
|
-
rmSync as
|
|
10670
|
+
rmSync as rmSync4,
|
|
10024
10671
|
statSync as statSync4,
|
|
10025
10672
|
utimesSync,
|
|
10026
|
-
writeFileSync as
|
|
10673
|
+
writeFileSync as writeFileSync10
|
|
10027
10674
|
} from "node:fs";
|
|
10028
10675
|
import { basename as basename3, dirname as dirname5, join as join13 } from "node:path";
|
|
10029
10676
|
|
|
10030
10677
|
// src/utils/install-cache.ts
|
|
10031
10678
|
import { createHash } from "node:crypto";
|
|
10032
|
-
import { mkdirSync as mkdirSync7, readFileSync as readFileSync5, writeFileSync as
|
|
10679
|
+
import { mkdirSync as mkdirSync7, readFileSync as readFileSync5, writeFileSync as writeFileSync9 } from "node:fs";
|
|
10033
10680
|
import { basename as basename2, join as join12 } from "node:path";
|
|
10034
10681
|
var LOCKFILES = [
|
|
10035
10682
|
["pnpm-lock.yaml", "pnpm"],
|
|
@@ -10096,7 +10743,7 @@ function readInstallMarker(storeDir) {
|
|
|
10096
10743
|
}
|
|
10097
10744
|
function writeInstallMarker(storeDir, marker) {
|
|
10098
10745
|
mkdirSync7(storeDir, { recursive: true });
|
|
10099
|
-
|
|
10746
|
+
writeFileSync9(join12(storeDir, MARKER_FILE), `${JSON.stringify(marker, null, 2)}
|
|
10100
10747
|
`);
|
|
10101
10748
|
}
|
|
10102
10749
|
function markerMatches(marker, lockHash, pmVersion) {
|
|
@@ -10242,6 +10889,10 @@ function gitReason(text) {
|
|
|
10242
10889
|
);
|
|
10243
10890
|
return notProgress.at(-1) ?? lines.at(-1) ?? "";
|
|
10244
10891
|
}
|
|
10892
|
+
function installCommand2(dir, exists = existsSync12, opts = {}) {
|
|
10893
|
+
const found = detectLockfile(dir, exists);
|
|
10894
|
+
return found ? [found.pm, installArgs(found.pm, opts)] : null;
|
|
10895
|
+
}
|
|
10245
10896
|
function githubCompareUrl(remoteUrl, baseBranch, branch) {
|
|
10246
10897
|
const m = /^https?:\/\/(?:[^@/]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(remoteUrl.trim()) ?? /^(?:ssh:\/\/)?git@github\.com[:/]([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(remoteUrl.trim());
|
|
10247
10898
|
if (!m) return null;
|
|
@@ -10278,7 +10929,7 @@ var RunWorkspaceManager = class {
|
|
|
10278
10929
|
this.run = deps.run ?? defaultCommandRunner;
|
|
10279
10930
|
this.now = deps.now ?? (() => /* @__PURE__ */ new Date());
|
|
10280
10931
|
this.runsRoot = deps.runsRoot ?? join13(getConfigDir(), "runs");
|
|
10281
|
-
this.exists = deps.exists ??
|
|
10932
|
+
this.exists = deps.exists ?? existsSync12;
|
|
10282
10933
|
this.copyFile = deps.copyFile ?? ((from, to) => {
|
|
10283
10934
|
mkdirSync8(dirname5(to), { recursive: true });
|
|
10284
10935
|
copyFileSync(from, to);
|
|
@@ -10314,7 +10965,7 @@ var RunWorkspaceManager = class {
|
|
|
10314
10965
|
*/
|
|
10315
10966
|
markActive(dir) {
|
|
10316
10967
|
try {
|
|
10317
|
-
|
|
10968
|
+
writeFileSync10(
|
|
10318
10969
|
activeMarkerPath(dir),
|
|
10319
10970
|
formatActiveMarker({ pid: this.pid, startedAt: this.now().toISOString() })
|
|
10320
10971
|
);
|
|
@@ -10327,7 +10978,7 @@ var RunWorkspaceManager = class {
|
|
|
10327
10978
|
}
|
|
10328
10979
|
}
|
|
10329
10980
|
clearActive(dir) {
|
|
10330
|
-
|
|
10981
|
+
rmSync4(activeMarkerPath(dir), { force: true });
|
|
10331
10982
|
}
|
|
10332
10983
|
/** Whether a `.active` marker still protects this folder from pruning. */
|
|
10333
10984
|
activeByMarker(dir) {
|
|
@@ -10358,7 +11009,7 @@ var RunWorkspaceManager = class {
|
|
|
10358
11009
|
}
|
|
10359
11010
|
for (const name of orphanMarkers(entries)) {
|
|
10360
11011
|
try {
|
|
10361
|
-
|
|
11012
|
+
rmSync4(join13(this.runsRoot, name), { force: true });
|
|
10362
11013
|
} catch {
|
|
10363
11014
|
}
|
|
10364
11015
|
}
|
|
@@ -10486,7 +11137,7 @@ var RunWorkspaceManager = class {
|
|
|
10486
11137
|
if (removed.status === 0) {
|
|
10487
11138
|
pruned += 1;
|
|
10488
11139
|
this.clearActive(dir);
|
|
10489
|
-
|
|
11140
|
+
rmSync4(waitingMarkerPath(dir), { force: true });
|
|
10490
11141
|
}
|
|
10491
11142
|
}
|
|
10492
11143
|
return pruned;
|
|
@@ -10582,7 +11233,7 @@ var RunWorkspaceManager = class {
|
|
|
10582
11233
|
const result = await this.reopenLocked(input);
|
|
10583
11234
|
if (result.ok) {
|
|
10584
11235
|
this.markActive(result.workspace.dir);
|
|
10585
|
-
|
|
11236
|
+
rmSync4(waitingMarkerPath(result.workspace.dir), { force: true });
|
|
10586
11237
|
}
|
|
10587
11238
|
return result;
|
|
10588
11239
|
});
|
|
@@ -10848,7 +11499,7 @@ ${untracked.stdout}`.split("\n").map((p) => p.trim()).filter((p) => p && !p.ends
|
|
|
10848
11499
|
const result = await this.finishLocked(input);
|
|
10849
11500
|
if (input.waiting?.keepRunCopy && result.keptWorktree) {
|
|
10850
11501
|
try {
|
|
10851
|
-
|
|
11502
|
+
writeFileSync10(waitingMarkerPath(result.keptWorktree), `${input.jobId}
|
|
10852
11503
|
`);
|
|
10853
11504
|
} catch {
|
|
10854
11505
|
}
|
|
@@ -11241,12 +11892,12 @@ ${untracked.stdout}`.split("\n").map((p) => p.trim()).filter((p) => p && !p.ends
|
|
|
11241
11892
|
};
|
|
11242
11893
|
|
|
11243
11894
|
// src/utils/wrap-up.ts
|
|
11244
|
-
import { readFileSync as readFileSync8 } from "node:fs";
|
|
11245
|
-
import {
|
|
11895
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync14, mkdirSync as mkdirSync9, mkdtempSync as mkdtempSync3, readFileSync as readFileSync8, rmSync as rmSync5 } from "node:fs";
|
|
11896
|
+
import { tmpdir as tmpdir3 } from "node:os";
|
|
11897
|
+
import { dirname as dirname6, join as join15 } from "node:path";
|
|
11246
11898
|
|
|
11247
11899
|
// src/utils/project-checks.ts
|
|
11248
|
-
import {
|
|
11249
|
-
import { existsSync as existsSync12, readdirSync as readdirSync3, readFileSync as readFileSync7, statSync as statSync5 } from "node:fs";
|
|
11900
|
+
import { existsSync as existsSync13, readdirSync as readdirSync3, readFileSync as readFileSync7, statSync as statSync5 } from "node:fs";
|
|
11250
11901
|
import { join as join14, relative as relative2 } from "node:path";
|
|
11251
11902
|
var DEFAULT_CHECK_SCRIPTS = ["typecheck", "lint", "test"];
|
|
11252
11903
|
var CHECKS_CONFIG_FILE = join14(".compbox", "checks.json");
|
|
@@ -11260,8 +11911,8 @@ function isRecord(value) {
|
|
|
11260
11911
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11261
11912
|
}
|
|
11262
11913
|
function packageManagerFor(rootDir) {
|
|
11263
|
-
if (
|
|
11264
|
-
if (
|
|
11914
|
+
if (existsSync13(join14(rootDir, "pnpm-lock.yaml"))) return "pnpm";
|
|
11915
|
+
if (existsSync13(join14(rootDir, "yarn.lock"))) return "yarn";
|
|
11265
11916
|
return "npm";
|
|
11266
11917
|
}
|
|
11267
11918
|
function workspacePatterns(rootDir, rootPkg) {
|
|
@@ -11272,7 +11923,7 @@ function workspacePatterns(rootDir, rootPkg) {
|
|
|
11272
11923
|
patterns.push(...ws.packages.filter((p) => typeof p === "string"));
|
|
11273
11924
|
}
|
|
11274
11925
|
const pnpmFile = join14(rootDir, "pnpm-workspace.yaml");
|
|
11275
|
-
if (
|
|
11926
|
+
if (existsSync13(pnpmFile)) {
|
|
11276
11927
|
let inPackages = false;
|
|
11277
11928
|
for (const raw of readFileSync7(pnpmFile, "utf-8").split("\n")) {
|
|
11278
11929
|
const line = raw.replace(/#.*$/, "").trimEnd();
|
|
@@ -11296,16 +11947,16 @@ function expandPatterns(rootDir, patterns) {
|
|
|
11296
11947
|
const clean = pattern.replace(/\/+$/, "");
|
|
11297
11948
|
if (clean.endsWith("/*") || clean.endsWith("/**")) {
|
|
11298
11949
|
const parent = join14(rootDir, clean.replace(/\/\*\*?$/, ""));
|
|
11299
|
-
if (!
|
|
11950
|
+
if (!existsSync13(parent)) continue;
|
|
11300
11951
|
for (const entry of readdirSync3(parent).sort()) {
|
|
11301
11952
|
const dir = join14(parent, entry);
|
|
11302
|
-
if (entry !== "node_modules" && statSync5(dir).isDirectory() &&
|
|
11953
|
+
if (entry !== "node_modules" && statSync5(dir).isDirectory() && existsSync13(join14(dir, "package.json"))) {
|
|
11303
11954
|
dirs.add(dir);
|
|
11304
11955
|
}
|
|
11305
11956
|
}
|
|
11306
11957
|
} else if (!clean.includes("*")) {
|
|
11307
11958
|
const dir = join14(rootDir, clean);
|
|
11308
|
-
if (
|
|
11959
|
+
if (existsSync13(join14(dir, "package.json"))) dirs.add(dir);
|
|
11309
11960
|
}
|
|
11310
11961
|
}
|
|
11311
11962
|
return [...dirs];
|
|
@@ -11351,7 +12002,7 @@ function checksFromConfig(config, warnings) {
|
|
|
11351
12002
|
function resolveProjectChecks(rootDir) {
|
|
11352
12003
|
const warnings = [];
|
|
11353
12004
|
const configPath = join14(rootDir, CHECKS_CONFIG_FILE);
|
|
11354
|
-
if (
|
|
12005
|
+
if (existsSync13(configPath)) {
|
|
11355
12006
|
let config;
|
|
11356
12007
|
try {
|
|
11357
12008
|
config = readJson(configPath);
|
|
@@ -11363,7 +12014,7 @@ function resolveProjectChecks(rootDir) {
|
|
|
11363
12014
|
}
|
|
11364
12015
|
let rootPkg = null;
|
|
11365
12016
|
try {
|
|
11366
|
-
const value =
|
|
12017
|
+
const value = existsSync13(join14(rootDir, "package.json")) ? readJson(join14(rootDir, "package.json")) : null;
|
|
11367
12018
|
rootPkg = isRecord(value) ? value : null;
|
|
11368
12019
|
} catch {
|
|
11369
12020
|
rootPkg = null;
|
|
@@ -11398,50 +12049,59 @@ function outputTail(output, lines = OUTPUT_TAIL_LINES) {
|
|
|
11398
12049
|
const tail = output.trimEnd().split("\n").slice(-lines).join("\n");
|
|
11399
12050
|
return tail.length > OUTPUT_TAIL_CHARS ? tail.slice(-OUTPUT_TAIL_CHARS) : tail;
|
|
11400
12051
|
}
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11405
|
-
|
|
11406
|
-
settled =
|
|
11407
|
-
|
|
11408
|
-
|
|
11409
|
-
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
|
|
11413
|
-
|
|
11414
|
-
|
|
11415
|
-
|
|
11416
|
-
|
|
11417
|
-
|
|
11418
|
-
|
|
11419
|
-
|
|
11420
|
-
|
|
11421
|
-
|
|
11422
|
-
|
|
11423
|
-
|
|
11424
|
-
|
|
11425
|
-
|
|
11426
|
-
|
|
11427
|
-
|
|
11428
|
-
|
|
11429
|
-
|
|
11430
|
-
|
|
11431
|
-
|
|
11432
|
-
|
|
11433
|
-
|
|
11434
|
-
|
|
11435
|
-
|
|
11436
|
-
|
|
11437
|
-
|
|
11438
|
-
|
|
12052
|
+
function createCheckRunner(deps = {}) {
|
|
12053
|
+
const platform = deps.platform ?? process.platform;
|
|
12054
|
+
const killDeps = { ...deps.processGroup, platform };
|
|
12055
|
+
return (command, args, cwd, timeoutMs) => new Promise((resolve4) => {
|
|
12056
|
+
let output = "";
|
|
12057
|
+
let settled = false;
|
|
12058
|
+
const done = (result) => {
|
|
12059
|
+
if (settled) return;
|
|
12060
|
+
settled = true;
|
|
12061
|
+
clearTimeout(timer);
|
|
12062
|
+
resolve4(result);
|
|
12063
|
+
};
|
|
12064
|
+
const child = spawnCrossPlatform(
|
|
12065
|
+
command,
|
|
12066
|
+
args,
|
|
12067
|
+
{
|
|
12068
|
+
cwd,
|
|
12069
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
12070
|
+
// CI=1 keeps test runners out of watch mode and interactive prompts.
|
|
12071
|
+
env: {
|
|
12072
|
+
...process.env,
|
|
12073
|
+
PATH: claudeChildEnvPath(process.env.PATH),
|
|
12074
|
+
CI: "1",
|
|
12075
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
12076
|
+
},
|
|
12077
|
+
...groupSpawnOptions(platform)
|
|
12078
|
+
},
|
|
12079
|
+
{
|
|
12080
|
+
platform,
|
|
12081
|
+
...deps.spawn ? { spawn: deps.spawn } : {},
|
|
12082
|
+
...deps.exists ? { exists: deps.exists } : {}
|
|
12083
|
+
}
|
|
12084
|
+
);
|
|
12085
|
+
const append = (chunk) => {
|
|
12086
|
+
output += chunk.toString("utf-8");
|
|
12087
|
+
if (output.length > 2e5) output = output.slice(-1e5);
|
|
12088
|
+
};
|
|
12089
|
+
const timer = setTimeout(() => {
|
|
12090
|
+
killProcessTree(child, killDeps);
|
|
12091
|
+
done({ exitCode: 1, output, timedOut: true });
|
|
12092
|
+
}, timeoutMs);
|
|
12093
|
+
child.stdout?.on("data", append);
|
|
12094
|
+
child.stderr?.on("data", append);
|
|
12095
|
+
child.on("error", (error) => {
|
|
12096
|
+
done({ exitCode: 1, output: `${output}
|
|
11439
12097
|
${error.message}`, timedOut: false });
|
|
12098
|
+
});
|
|
12099
|
+
child.on("close", (code) => {
|
|
12100
|
+
done({ exitCode: code ?? 1, output, timedOut: false });
|
|
12101
|
+
});
|
|
11440
12102
|
});
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
});
|
|
11444
|
-
});
|
|
12103
|
+
}
|
|
12104
|
+
var defaultCheckRunner = createCheckRunner();
|
|
11445
12105
|
async function runProjectChecks(rootDir, checks, deps = {}) {
|
|
11446
12106
|
const runner = deps.runner ?? defaultCheckRunner;
|
|
11447
12107
|
const now = deps.now ?? Date.now;
|
|
@@ -11468,6 +12128,11 @@ Timed out after ${String(Math.round(check.timeoutMs / 1e3))}s.`.trim() : tail
|
|
|
11468
12128
|
var WRAP_UP_MAX_MIGRATION_SQL = 2e5;
|
|
11469
12129
|
var WRAP_UP_MAX_COMMENT = 5e4;
|
|
11470
12130
|
var MIGRATION_FILE = /prisma\/migrations[^/]*\/[^/]+\/migration\.sql$/;
|
|
12131
|
+
var BASE_COMPARE_BUDGET_MS = 15 * 60 * 1e3;
|
|
12132
|
+
function checkGroup(check) {
|
|
12133
|
+
if (check.passed) return "passed";
|
|
12134
|
+
return check.classification ?? "caused";
|
|
12135
|
+
}
|
|
11471
12136
|
function parseNameStatus(output) {
|
|
11472
12137
|
const files = [];
|
|
11473
12138
|
for (const line of output.split("\n")) {
|
|
@@ -11491,6 +12156,162 @@ function defaultRunChecks(dir) {
|
|
|
11491
12156
|
warnings: resolved.warnings
|
|
11492
12157
|
}));
|
|
11493
12158
|
}
|
|
12159
|
+
function defaultRetryChecks(dir, failed) {
|
|
12160
|
+
const names = new Set(failed.map((c) => c.name));
|
|
12161
|
+
return runProjectChecks(
|
|
12162
|
+
dir,
|
|
12163
|
+
resolveProjectChecks(dir).checks.filter((c) => names.has(c.name))
|
|
12164
|
+
);
|
|
12165
|
+
}
|
|
12166
|
+
function firstLine(text) {
|
|
12167
|
+
return text.trim().split("\n")[0]?.trim() ?? "";
|
|
12168
|
+
}
|
|
12169
|
+
async function compareWithBase(input, deps) {
|
|
12170
|
+
if (input.failed.length === 0) return { failingOnBase: /* @__PURE__ */ new Set() };
|
|
12171
|
+
const now = deps.now ?? Date.now;
|
|
12172
|
+
const budgetMs = deps.budgetMs ?? BASE_COMPARE_BUDGET_MS;
|
|
12173
|
+
const exists = deps.exists ?? existsSync14;
|
|
12174
|
+
const removeDir = deps.removeDir ?? ((path3) => {
|
|
12175
|
+
rmSync5(path3, { recursive: true, force: true });
|
|
12176
|
+
});
|
|
12177
|
+
const copyFile = deps.copyFile ?? ((from, to) => {
|
|
12178
|
+
mkdirSync9(dirname6(to), { recursive: true });
|
|
12179
|
+
copyFileSync2(from, to);
|
|
12180
|
+
});
|
|
12181
|
+
const resolveChecks = deps.resolveChecks ?? ((dir) => resolveProjectChecks(dir).checks);
|
|
12182
|
+
const started = now();
|
|
12183
|
+
const skipped = (why) => ({
|
|
12184
|
+
failingOnBase: null,
|
|
12185
|
+
note: `The failing checks weren't compared with \`${input.baseRef}\`: ${why}`
|
|
12186
|
+
});
|
|
12187
|
+
const mergeBase = await deps.run("git", ["merge-base", "HEAD", input.baseRef], input.dir);
|
|
12188
|
+
const sha = mergeBase.stdout.trim();
|
|
12189
|
+
if (mergeBase.status !== 0 || !sha) {
|
|
12190
|
+
return skipped(`git merge-base failed (${firstLine(mergeBase.stderr) || "no common commit"}).`);
|
|
12191
|
+
}
|
|
12192
|
+
let baseDir;
|
|
12193
|
+
try {
|
|
12194
|
+
baseDir = (deps.makeTempDir ?? (() => mkdtempSync3(join15(tmpdir3(), "compbox-base-"))))();
|
|
12195
|
+
} catch (error) {
|
|
12196
|
+
return skipped(`couldn't create a temporary folder (${errorText(error)}).`);
|
|
12197
|
+
}
|
|
12198
|
+
let added = false;
|
|
12199
|
+
try {
|
|
12200
|
+
const add = await deps.run("git", ["worktree", "add", "--detach", baseDir, sha], input.dir);
|
|
12201
|
+
if (add.status !== 0) {
|
|
12202
|
+
return skipped(`git worktree add failed (${firstLine(add.stderr) || "unknown error"}).`);
|
|
12203
|
+
}
|
|
12204
|
+
added = true;
|
|
12205
|
+
const ignored = await deps.run(
|
|
12206
|
+
"git",
|
|
12207
|
+
["ls-files", "--others", "--ignored", "--exclude-standard", "--directory"],
|
|
12208
|
+
input.dir
|
|
12209
|
+
);
|
|
12210
|
+
const untracked = await deps.run("git", ["ls-files", "--others", "--exclude-standard"], input.dir);
|
|
12211
|
+
const candidates = new Set(
|
|
12212
|
+
`${ignored.status === 0 ? ignored.stdout : ""}
|
|
12213
|
+
${untracked.status === 0 ? untracked.stdout : ""}`.split("\n").map((p) => p.trim()).filter((p) => p && !p.endsWith("/") && isLocalConfigFile(p))
|
|
12214
|
+
);
|
|
12215
|
+
for (const path3 of candidates) {
|
|
12216
|
+
try {
|
|
12217
|
+
copyFile(join15(input.dir, path3), join15(baseDir, path3));
|
|
12218
|
+
} catch {
|
|
12219
|
+
}
|
|
12220
|
+
}
|
|
12221
|
+
const install = installCommand2(baseDir, exists);
|
|
12222
|
+
if (install) {
|
|
12223
|
+
const res = await deps.run(install[0], install[1], baseDir);
|
|
12224
|
+
if (res.status !== 0) {
|
|
12225
|
+
return skipped(`installing dependencies failed (${firstLine(res.stderr) || "unknown error"}).`);
|
|
12226
|
+
}
|
|
12227
|
+
}
|
|
12228
|
+
const available = new Map(resolveChecks(baseDir).map((c) => [c.name, c]));
|
|
12229
|
+
const failingOnBase = /* @__PURE__ */ new Set();
|
|
12230
|
+
const notRun = [];
|
|
12231
|
+
for (const failed of input.failed) {
|
|
12232
|
+
const check = available.get(failed.name);
|
|
12233
|
+
const remaining = budgetMs - (now() - started);
|
|
12234
|
+
if (!check || remaining <= 0) {
|
|
12235
|
+
notRun.push(failed.name);
|
|
12236
|
+
continue;
|
|
12237
|
+
}
|
|
12238
|
+
const [result] = await runProjectChecks(
|
|
12239
|
+
baseDir,
|
|
12240
|
+
[{ ...check, timeoutMs: Math.min(check.timeoutMs, remaining) }],
|
|
12241
|
+
{ ...deps.checkRunner ? { runner: deps.checkRunner } : {}, now }
|
|
12242
|
+
);
|
|
12243
|
+
if (result && !result.passed && !result.timedOut) failingOnBase.add(failed.name);
|
|
12244
|
+
else if (result?.timedOut) notRun.push(failed.name);
|
|
12245
|
+
}
|
|
12246
|
+
return notRun.length > 0 ? {
|
|
12247
|
+
failingOnBase,
|
|
12248
|
+
note: `Couldn't tell whether ${notRun.map((n) => `\`${n}\``).join(", ")} also ${notRun.length === 1 ? "fails" : "fail"} on \`${input.baseRef}\` (missing there, or out of time), so ${notRun.length === 1 ? "it counts" : "they count"} as caused by this build.`
|
|
12249
|
+
} : { failingOnBase };
|
|
12250
|
+
} catch (error) {
|
|
12251
|
+
return skipped(`${errorText(error)}.`);
|
|
12252
|
+
} finally {
|
|
12253
|
+
let removed = false;
|
|
12254
|
+
if (added) {
|
|
12255
|
+
try {
|
|
12256
|
+
const res = await deps.run("git", ["worktree", "remove", "--force", baseDir], input.dir);
|
|
12257
|
+
removed = res.status === 0;
|
|
12258
|
+
} catch {
|
|
12259
|
+
removed = false;
|
|
12260
|
+
}
|
|
12261
|
+
}
|
|
12262
|
+
if (!removed) {
|
|
12263
|
+
try {
|
|
12264
|
+
removeDir(baseDir);
|
|
12265
|
+
} catch {
|
|
12266
|
+
}
|
|
12267
|
+
if (added) {
|
|
12268
|
+
try {
|
|
12269
|
+
await deps.run("git", ["worktree", "prune"], input.dir);
|
|
12270
|
+
} catch {
|
|
12271
|
+
}
|
|
12272
|
+
}
|
|
12273
|
+
}
|
|
12274
|
+
}
|
|
12275
|
+
}
|
|
12276
|
+
async function classifyChecks(input, deps) {
|
|
12277
|
+
const warnings = [];
|
|
12278
|
+
const retryable = input.checks.filter((c) => !c.passed && !c.timedOut);
|
|
12279
|
+
const retried = /* @__PURE__ */ new Map();
|
|
12280
|
+
if (deps.retryChecks && retryable.length > 0) {
|
|
12281
|
+
try {
|
|
12282
|
+
for (const result of await deps.retryChecks(input.dir, retryable)) retried.set(result.name, result);
|
|
12283
|
+
} catch (error) {
|
|
12284
|
+
warnings.push(`The failed checks couldn't be run again: ${errorText(error)}.`);
|
|
12285
|
+
}
|
|
12286
|
+
}
|
|
12287
|
+
let checks = input.checks.map((check) => {
|
|
12288
|
+
if (check.passed) return check;
|
|
12289
|
+
const again = retried.get(check.name);
|
|
12290
|
+
if (!again) return { ...check, classification: "caused" };
|
|
12291
|
+
if (again.passed) return { ...check, retried: true, classification: "flaky" };
|
|
12292
|
+
return { ...again, retried: true, classification: "caused" };
|
|
12293
|
+
});
|
|
12294
|
+
const stillFailing = checks.filter((c) => c.classification === "caused" && !c.timedOut);
|
|
12295
|
+
if (deps.compareWithBase && stillFailing.length > 0) {
|
|
12296
|
+
try {
|
|
12297
|
+
const comparison = await deps.compareWithBase({
|
|
12298
|
+
dir: input.dir,
|
|
12299
|
+
baseRef: input.baseRef,
|
|
12300
|
+
failed: stillFailing
|
|
12301
|
+
});
|
|
12302
|
+
const onBase = comparison.failingOnBase;
|
|
12303
|
+
if (onBase) {
|
|
12304
|
+
checks = checks.map(
|
|
12305
|
+
(c) => c.classification === "caused" && !c.timedOut && onBase.has(c.name) ? { ...c, classification: "base" } : c
|
|
12306
|
+
);
|
|
12307
|
+
}
|
|
12308
|
+
if (comparison.note) warnings.push(comparison.note);
|
|
12309
|
+
} catch (error) {
|
|
12310
|
+
warnings.push(`The failing checks couldn't be compared with \`${input.baseRef}\`: ${errorText(error)}.`);
|
|
12311
|
+
}
|
|
12312
|
+
}
|
|
12313
|
+
return { checks, warnings };
|
|
12314
|
+
}
|
|
11494
12315
|
function migrationLine(entry) {
|
|
11495
12316
|
if (typeof entry !== "object" || entry === null) return null;
|
|
11496
12317
|
const m = entry;
|
|
@@ -11500,7 +12321,8 @@ function migrationLine(entry) {
|
|
|
11500
12321
|
return `- \`${m.path}\` \u2014 ${safety}${reasons.length > 0 ? `: ${reasons.join("; ")}` : ""}`;
|
|
11501
12322
|
}
|
|
11502
12323
|
function buildReviewComment(input) {
|
|
11503
|
-
const
|
|
12324
|
+
const allPassed = input.checks.every((c) => c.passed);
|
|
12325
|
+
const heading = input.status === "ready" ? allPassed ? "\u2705 **Ready for you** \u2014 every check passed and no gaps were found." : "\u2705 **Ready for you** \u2014 no check failures were caused by this build and no gaps were found." : input.status === "needs_decision" ? "\u26A0\uFE0F **Needs a decision** \u2014 this pull request stays a draft." : "\u274C **Wrap-up failed** \u2014 this pull request stays a draft.";
|
|
11504
12326
|
const lines = ["## CompBox build wrap-up", "", heading];
|
|
11505
12327
|
if (input.reasons.length > 0) {
|
|
11506
12328
|
lines.push("", ...input.reasons.map((r) => `- ${r}`));
|
|
@@ -11518,13 +12340,38 @@ function buildReviewComment(input) {
|
|
|
11518
12340
|
else lines.push(merge.reason);
|
|
11519
12341
|
lines.push("", "### Checks");
|
|
11520
12342
|
if (input.checks.length === 0) lines.push("No checks were found to run.");
|
|
11521
|
-
|
|
11522
|
-
const mark = check.passed ? "\u2705" : check.timedOut ? "\u23F1\uFE0F" : "\u274C";
|
|
12343
|
+
const checkLine = (check) => {
|
|
12344
|
+
const mark = check.passed ? "\u2705" : check.timedOut ? "\u23F1\uFE0F" : checkGroup(check) === "flaky" ? "\u{1F501}" : "\u274C";
|
|
11523
12345
|
const where = check.cwd === "." ? "" : ` (${check.cwd})`;
|
|
11524
|
-
|
|
12346
|
+
return `- ${mark} \`${check.name}\`${where} \u2014 ${String(Math.round(check.durationMs / 1e3))}s`;
|
|
12347
|
+
};
|
|
12348
|
+
const group = (g) => input.checks.filter((c) => checkGroup(c) === g);
|
|
12349
|
+
const caused = group("caused");
|
|
12350
|
+
const onBase = group("base");
|
|
12351
|
+
const flaky = group("flaky");
|
|
12352
|
+
lines.push(...group("passed").map(checkLine));
|
|
12353
|
+
if (caused.length > 0) {
|
|
12354
|
+
lines.push("", "#### Caused by this build", ...caused.map(checkLine));
|
|
12355
|
+
}
|
|
12356
|
+
if (onBase.length > 0) {
|
|
12357
|
+
lines.push(
|
|
12358
|
+
"",
|
|
12359
|
+
`#### Already failing on \`${input.baseBranch}\``,
|
|
12360
|
+
"These fail on the base branch too, so they don't hold this pull request back.",
|
|
12361
|
+
...onBase.map(checkLine)
|
|
12362
|
+
);
|
|
11525
12363
|
}
|
|
12364
|
+
if (flaky.length > 0) {
|
|
12365
|
+
lines.push(
|
|
12366
|
+
"",
|
|
12367
|
+
"#### Flaky",
|
|
12368
|
+
"These failed, then passed when run again.",
|
|
12369
|
+
...flaky.map(checkLine)
|
|
12370
|
+
);
|
|
12371
|
+
}
|
|
12372
|
+
if (input.checkWarnings.length > 0) lines.push("");
|
|
11526
12373
|
for (const warning of input.checkWarnings) lines.push(`- \u26A0\uFE0F ${warning}`);
|
|
11527
|
-
for (const check of
|
|
12374
|
+
for (const check of [...caused, ...onBase, ...flaky].filter((c) => c.outputTail)) {
|
|
11528
12375
|
lines.push(
|
|
11529
12376
|
"",
|
|
11530
12377
|
`<details><summary>${check.name} output</summary>`,
|
|
@@ -11550,6 +12397,8 @@ function buildReviewComment(input) {
|
|
|
11550
12397
|
function createWrapUp(deps) {
|
|
11551
12398
|
const { client } = deps;
|
|
11552
12399
|
const runChecks = deps.runChecks ?? defaultRunChecks;
|
|
12400
|
+
const retryChecks = deps.retryChecks ?? (deps.runChecks ? void 0 : defaultRetryChecks);
|
|
12401
|
+
const compare = deps.compareWithBase ?? (deps.runChecks ? void 0 : (i) => compareWithBase(i, { run: deps.run }));
|
|
11553
12402
|
const readFile3 = deps.readFile ?? ((path3) => readFileSync8(path3, "utf-8"));
|
|
11554
12403
|
return async (input) => {
|
|
11555
12404
|
const reasons = [];
|
|
@@ -11581,7 +12430,15 @@ function createWrapUp(deps) {
|
|
|
11581
12430
|
} catch (error) {
|
|
11582
12431
|
failures.push(`The project checks couldn't be run: ${errorText(error)}.`);
|
|
11583
12432
|
}
|
|
11584
|
-
|
|
12433
|
+
if (checks.some((c) => !c.passed)) {
|
|
12434
|
+
const classified = await classifyChecks(
|
|
12435
|
+
{ dir: input.dir, baseRef: input.baseRef, checks },
|
|
12436
|
+
{ ...retryChecks ? { retryChecks } : {}, ...compare ? { compareWithBase: compare } : {} }
|
|
12437
|
+
);
|
|
12438
|
+
checks = classified.checks;
|
|
12439
|
+
checkWarnings = [...checkWarnings, ...classified.warnings];
|
|
12440
|
+
}
|
|
12441
|
+
for (const check of checks.filter((c) => checkGroup(c) === "caused")) {
|
|
11585
12442
|
failures.push(
|
|
11586
12443
|
check.timedOut ? `The \`${check.name}\` check took too long and was stopped.` : `The \`${check.name}\` check failed.`
|
|
11587
12444
|
);
|
|
@@ -11689,6 +12546,12 @@ function createWrapUp(deps) {
|
|
|
11689
12546
|
}
|
|
11690
12547
|
|
|
11691
12548
|
// src/utils/agent-invoker.ts
|
|
12549
|
+
function spawnPiped(spawnImpl, command, args, options, platform) {
|
|
12550
|
+
return spawnCrossPlatform(command, args, options, {
|
|
12551
|
+
spawn: spawnImpl,
|
|
12552
|
+
...platform ? { platform } : {}
|
|
12553
|
+
});
|
|
12554
|
+
}
|
|
11692
12555
|
var ANTHROPIC_MODEL = "claude-fable-5";
|
|
11693
12556
|
var CHAT_MODEL = "claude-haiku-5-5";
|
|
11694
12557
|
var SAVE_MODEL = ANTHROPIC_MODEL;
|
|
@@ -11716,6 +12579,34 @@ function anthropicClientOptions(apiKey, routing) {
|
|
|
11716
12579
|
function claudeSpawnEnv(base, routing) {
|
|
11717
12580
|
return routing.mode === "proxy" ? { ...base, ANTHROPIC_BASE_URL: routing.anthropicBaseUrl } : base;
|
|
11718
12581
|
}
|
|
12582
|
+
function withHooksDisabled(env, hooksDir) {
|
|
12583
|
+
const raw = env.GIT_CONFIG_COUNT?.trim();
|
|
12584
|
+
if (raw && !/^\d+$/.test(raw)) return env;
|
|
12585
|
+
const n = raw ? Number(raw) : 0;
|
|
12586
|
+
return {
|
|
12587
|
+
...env,
|
|
12588
|
+
GIT_CONFIG_COUNT: String(n + 1),
|
|
12589
|
+
[`GIT_CONFIG_KEY_${String(n)}`]: "core.hooksPath",
|
|
12590
|
+
[`GIT_CONFIG_VALUE_${String(n)}`]: hooksDir
|
|
12591
|
+
};
|
|
12592
|
+
}
|
|
12593
|
+
function makeAgentHooksDir(runDir) {
|
|
12594
|
+
try {
|
|
12595
|
+
const dir = mkdtempSync4(join16(tmpdir4(), "compbox-nohooks-"));
|
|
12596
|
+
if (runDir) {
|
|
12597
|
+
const res = spawnSync("git", ["rev-parse", "--path-format=absolute", "--git-dir"], {
|
|
12598
|
+
cwd: runDir,
|
|
12599
|
+
encoding: "utf-8"
|
|
12600
|
+
});
|
|
12601
|
+
const gitDir = res.status === 0 ? res.stdout.trim() : "";
|
|
12602
|
+
const guard = gitDir ? join16(gitDir, "compbox-hooks", "pre-push") : "";
|
|
12603
|
+
if (guard && existsSync15(guard)) copyFileSync3(guard, join16(dir, "pre-push"));
|
|
12604
|
+
}
|
|
12605
|
+
return dir;
|
|
12606
|
+
} catch {
|
|
12607
|
+
return void 0;
|
|
12608
|
+
}
|
|
12609
|
+
}
|
|
11719
12610
|
var SUPPORTED_IMAGE_MEDIA_TYPES = ["image/jpeg", "image/png", "image/gif", "image/webp"];
|
|
11720
12611
|
var MAX_IMAGE_BYTES_PER_TURN = 20 * 1024 * 1024;
|
|
11721
12612
|
var defaultWarn = (message) => {
|
|
@@ -11930,9 +12821,9 @@ async function submitAndScore(ctx, currentErId, draft) {
|
|
|
11930
12821
|
return { erId: created.id, compliance: created.compliance };
|
|
11931
12822
|
}
|
|
11932
12823
|
function claudeCliSessionCwd() {
|
|
11933
|
-
const dir = join16(
|
|
12824
|
+
const dir = join16(homedir8(), ".compbox", "claude-sessions");
|
|
11934
12825
|
try {
|
|
11935
|
-
|
|
12826
|
+
mkdirSync10(dir, { recursive: true });
|
|
11936
12827
|
} catch {
|
|
11937
12828
|
}
|
|
11938
12829
|
return dir;
|
|
@@ -11978,11 +12869,17 @@ function runClaudeCliTurn(prompt, opts) {
|
|
|
11978
12869
|
const command = resolveClaudeBinary() ?? "claude";
|
|
11979
12870
|
const pxpipeEnv = claudeSpawnEnv(process.env, opts.routing);
|
|
11980
12871
|
const attempt = (withPartial) => {
|
|
11981
|
-
const child =
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
|
|
12872
|
+
const child = spawnPiped(
|
|
12873
|
+
spawn6,
|
|
12874
|
+
command,
|
|
12875
|
+
buildArgs(withPartial),
|
|
12876
|
+
{
|
|
12877
|
+
cwd: claudeCliSessionCwd(),
|
|
12878
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
12879
|
+
env: { ...pxpipeEnv, PATH: claudeChildEnvPath(pxpipeEnv.PATH) }
|
|
12880
|
+
},
|
|
12881
|
+
void 0
|
|
12882
|
+
);
|
|
11986
12883
|
let stdout2 = "";
|
|
11987
12884
|
let stderr = "";
|
|
11988
12885
|
let settled = false;
|
|
@@ -12000,7 +12897,7 @@ function runClaudeCliTurn(prompt, opts) {
|
|
|
12000
12897
|
const timer = setTimeout(() => {
|
|
12001
12898
|
if (settled) return;
|
|
12002
12899
|
settled = true;
|
|
12003
|
-
child
|
|
12900
|
+
killProcessGroupNow(child);
|
|
12004
12901
|
reject(
|
|
12005
12902
|
new Error(`claude CLI timed out after ${String(CLAUDE_CLI_TURN_TIMEOUT_MS / 1e3)}s`)
|
|
12006
12903
|
);
|
|
@@ -12164,7 +13061,7 @@ async function takeConversationStep(job, ctx) {
|
|
|
12164
13061
|
const hasAttachments = job.turns.some(
|
|
12165
13062
|
(t) => t.role === "user" && (t.attachments?.length ?? 0) > 0
|
|
12166
13063
|
);
|
|
12167
|
-
const attachmentsDir = !anthropic && hasAttachments ? await realpath(await mkdtemp(join16(
|
|
13064
|
+
const attachmentsDir = !anthropic && hasAttachments ? await realpath(await mkdtemp(join16(tmpdir4(), "compbox-attachments-"))) : void 0;
|
|
12168
13065
|
try {
|
|
12169
13066
|
return await converseWithAttachments(job, ctx, {
|
|
12170
13067
|
routing,
|
|
@@ -12498,7 +13395,7 @@ function buildPlannerFinalTurn(outcome) {
|
|
|
12498
13395
|
}
|
|
12499
13396
|
async function invokeStartExecutionPlan(ctx, deps = {}) {
|
|
12500
13397
|
if (ctx.signal?.aborted) return cancelledRunResult("planner");
|
|
12501
|
-
const spawnImpl = deps.spawnImpl ??
|
|
13398
|
+
const spawnImpl = deps.spawnImpl ?? spawn6;
|
|
12502
13399
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
12503
13400
|
const isGitRepo = deps.isGitRepo ?? isGitRepoDir;
|
|
12504
13401
|
const resolveRoutingImpl = deps.resolveRoutingImpl ?? resolveRouting;
|
|
@@ -12535,13 +13432,19 @@ async function invokeStartExecutionPlan(ctx, deps = {}) {
|
|
|
12535
13432
|
let stdout2 = "";
|
|
12536
13433
|
let stderr = "";
|
|
12537
13434
|
let settled = false;
|
|
12538
|
-
const child =
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
|
|
12544
|
-
|
|
13435
|
+
const child = spawnPiped(
|
|
13436
|
+
spawnImpl,
|
|
13437
|
+
command,
|
|
13438
|
+
args,
|
|
13439
|
+
{
|
|
13440
|
+
cwd: ctx.projectDir,
|
|
13441
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
13442
|
+
env: childEnv,
|
|
13443
|
+
// ENG-300: lead its own process group so a cancel can stop everything it started.
|
|
13444
|
+
...groupSpawnOptions(deps.processGroup?.platform)
|
|
13445
|
+
},
|
|
13446
|
+
deps.processGroup?.platform
|
|
13447
|
+
);
|
|
12545
13448
|
let cancelled = false;
|
|
12546
13449
|
const disposeAbort = killGroupOnAbort(
|
|
12547
13450
|
ctx.signal,
|
|
@@ -12713,7 +13616,7 @@ function buildRefineFinalTurn(outcome) {
|
|
|
12713
13616
|
}
|
|
12714
13617
|
async function invokeStartExecutionRefine(ctx, deps = {}) {
|
|
12715
13618
|
if (ctx.signal?.aborted) return cancelledRunResult("planner");
|
|
12716
|
-
const spawnImpl = deps.spawnImpl ??
|
|
13619
|
+
const spawnImpl = deps.spawnImpl ?? spawn6;
|
|
12717
13620
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
12718
13621
|
const isGitRepo = deps.isGitRepo ?? isGitRepoDir;
|
|
12719
13622
|
const resolveRoutingImpl = deps.resolveRoutingImpl ?? resolveRouting;
|
|
@@ -12742,13 +13645,19 @@ async function invokeStartExecutionRefine(ctx, deps = {}) {
|
|
|
12742
13645
|
let stdout2 = "";
|
|
12743
13646
|
let stderr = "";
|
|
12744
13647
|
let settled = false;
|
|
12745
|
-
const child =
|
|
12746
|
-
|
|
12747
|
-
|
|
12748
|
-
|
|
12749
|
-
|
|
12750
|
-
|
|
12751
|
-
|
|
13648
|
+
const child = spawnPiped(
|
|
13649
|
+
spawnImpl,
|
|
13650
|
+
command,
|
|
13651
|
+
args,
|
|
13652
|
+
{
|
|
13653
|
+
cwd: ctx.projectDir,
|
|
13654
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
13655
|
+
env: childEnv,
|
|
13656
|
+
// ENG-300: lead its own process group so a cancel can stop everything it started.
|
|
13657
|
+
...groupSpawnOptions(deps.processGroup?.platform)
|
|
13658
|
+
},
|
|
13659
|
+
deps.processGroup?.platform
|
|
13660
|
+
);
|
|
12752
13661
|
let cancelled = false;
|
|
12753
13662
|
const disposeAbort = killGroupOnAbort(
|
|
12754
13663
|
ctx.signal,
|
|
@@ -12868,7 +13777,7 @@ ${stderr}`;
|
|
|
12868
13777
|
}
|
|
12869
13778
|
function gitHead(dir) {
|
|
12870
13779
|
return new Promise((resolve4, reject) => {
|
|
12871
|
-
|
|
13780
|
+
execFile3("git", ["rev-parse", "HEAD"], { cwd: dir, timeout: 15e3 }, (error, stdout2) => {
|
|
12872
13781
|
if (error) reject(new Error(`git rev-parse HEAD failed: ${error.message}`));
|
|
12873
13782
|
else resolve4(stdout2.trim());
|
|
12874
13783
|
});
|
|
@@ -12935,16 +13844,22 @@ function buildConflictResolveArgs(files, baseBranch) {
|
|
|
12935
13844
|
];
|
|
12936
13845
|
}
|
|
12937
13846
|
function createClaudeConflictResolver(opts) {
|
|
12938
|
-
const spawnImpl = opts.spawnImpl ??
|
|
13847
|
+
const spawnImpl = opts.spawnImpl ?? spawn6;
|
|
12939
13848
|
const timeoutMs = opts.timeoutMs ?? CONFLICT_RESOLVE_TIMEOUT_MS;
|
|
12940
13849
|
return ({ dir, files, baseBranch, signal }) => new Promise((resolve4) => {
|
|
12941
13850
|
let settled = false;
|
|
12942
|
-
const child =
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
|
|
12946
|
-
|
|
12947
|
-
|
|
13851
|
+
const child = spawnPiped(
|
|
13852
|
+
spawnImpl,
|
|
13853
|
+
opts.command,
|
|
13854
|
+
buildConflictResolveArgs(files, baseBranch),
|
|
13855
|
+
{
|
|
13856
|
+
cwd: dir,
|
|
13857
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
13858
|
+
env: opts.env,
|
|
13859
|
+
...groupSpawnOptions(opts.processGroup?.platform)
|
|
13860
|
+
},
|
|
13861
|
+
opts.processGroup?.platform
|
|
13862
|
+
);
|
|
12948
13863
|
let stderr = "";
|
|
12949
13864
|
child.stderr.on("data", (chunk) => {
|
|
12950
13865
|
stderr += chunk.toString("utf-8");
|
|
@@ -12998,7 +13913,9 @@ ${followUpContext(extra.followUp)}` : "") + (extra?.ownerNote ? `
|
|
|
12998
13913
|
|
|
12999
13914
|
${ownerNoteContext(extra.ownerNote)}` : "") + (extra?.deferred && extra.deferred.length > 0 ? `
|
|
13000
13915
|
|
|
13001
|
-
${deferredFeaturesText(extra.deferred)}` : "")
|
|
13916
|
+
${deferredFeaturesText(extra.deferred)}` : "") + (extra?.checkMode ? `
|
|
13917
|
+
|
|
13918
|
+
${checkModeText(extra.checkMode)}` : ""),
|
|
13002
13919
|
// A known session id lets the runner resume this same conversation when
|
|
13003
13920
|
// the agent ends its turn early (see buildOrchestratorContinueArgs).
|
|
13004
13921
|
...sessionId ? ["--session-id", sessionId] : [],
|
|
@@ -13016,14 +13933,18 @@ ${deferredFeaturesText(extra.deferred)}` : ""),
|
|
|
13016
13933
|
];
|
|
13017
13934
|
}
|
|
13018
13935
|
var MAX_ORCHESTRATOR_CONTINUES = 5;
|
|
13019
|
-
function orchestratorContinuePrompt(epicId, done, total, deferred = []) {
|
|
13936
|
+
function orchestratorContinuePrompt(epicId, done, total, deferred = [], checkMode) {
|
|
13020
13937
|
return [
|
|
13021
13938
|
`Continue executing epic ${epicId} in non-interactive mode. CompBox shows ${String(done)} of ${String(total)} features done.`,
|
|
13022
13939
|
"You ended your turn early, which stopped the run. Do not announce the next step: take it.",
|
|
13023
13940
|
"Keep going until every feature is done and recorded in CompBox, or a hard gate stops the run.",
|
|
13024
|
-
...deferred.length > 0 ? [deferredFeaturesText(deferred)] : []
|
|
13941
|
+
...deferred.length > 0 ? [deferredFeaturesText(deferred)] : [],
|
|
13942
|
+
...checkMode ? [checkModeText(checkMode)] : []
|
|
13025
13943
|
].join(" ");
|
|
13026
13944
|
}
|
|
13945
|
+
function checkModeText(checkMode) {
|
|
13946
|
+
return `Check mode: ${checkMode}`;
|
|
13947
|
+
}
|
|
13027
13948
|
function deferredFeaturesText(deferred) {
|
|
13028
13949
|
return `The owner deferred these features: skip them and don't ask about them: ${deferred.map((f) => `${f.identifier} (${f.title})`).join(", ")}.`;
|
|
13029
13950
|
}
|
|
@@ -13178,10 +14099,11 @@ function defaultWorktreeCapable(dir) {
|
|
|
13178
14099
|
function defaultToolchainPresent(_dir) {
|
|
13179
14100
|
for (const pm of ["pnpm", "npm"]) {
|
|
13180
14101
|
try {
|
|
13181
|
-
const
|
|
14102
|
+
const plan = planCrossPlatformSpawn(pm, ["--version"], {
|
|
13182
14103
|
stdio: "ignore",
|
|
13183
14104
|
env: { ...process.env, PATH: claudeChildEnvPath(process.env.PATH) }
|
|
13184
14105
|
});
|
|
14106
|
+
const res = spawnSync(plan.command, plan.args, plan.options);
|
|
13185
14107
|
if (res.status === 0) return true;
|
|
13186
14108
|
} catch {
|
|
13187
14109
|
}
|
|
@@ -13293,7 +14215,7 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
13293
14215
|
if (ctx.signal?.aborted) return cancelledRunResult("orchestrator");
|
|
13294
14216
|
const clockMs = deps.clockMs ?? Date.now;
|
|
13295
14217
|
const startedAtMs = clockMs();
|
|
13296
|
-
const spawnImpl = deps.spawnImpl ??
|
|
14218
|
+
const spawnImpl = deps.spawnImpl ?? spawn6;
|
|
13297
14219
|
const isGitRepo = deps.isGitRepo ?? isGitRepoDir;
|
|
13298
14220
|
const worktreeCapable = deps.worktreeCapable ?? defaultWorktreeCapable;
|
|
13299
14221
|
const toolchainPresent = deps.toolchainPresent ?? defaultToolchainPresent;
|
|
@@ -13376,7 +14298,7 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
13376
14298
|
if (replyAttachments.length > 0) {
|
|
13377
14299
|
try {
|
|
13378
14300
|
replyAttachmentsDir = await realpath(
|
|
13379
|
-
await mkdtemp(join16(
|
|
14301
|
+
await mkdtemp(join16(tmpdir4(), "compbox-reply-attachments-"))
|
|
13380
14302
|
);
|
|
13381
14303
|
const { files, failed } = await materializeAttachments(
|
|
13382
14304
|
replyAttachmentsDir,
|
|
@@ -13406,7 +14328,8 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
13406
14328
|
...ctx.ownerNote && { ownerNote: ctx.ownerNote },
|
|
13407
14329
|
...ctx.deferredFeatures && { deferred: ctx.deferredFeatures },
|
|
13408
14330
|
...ctx.followUp && { followUp: ctx.followUp },
|
|
13409
|
-
...attachmentsNote && { replyAttachmentsNote: attachmentsNote }
|
|
14331
|
+
...attachmentsNote && { replyAttachmentsNote: attachmentsNote },
|
|
14332
|
+
...ctx.checkMode && { checkMode: ctx.checkMode }
|
|
13410
14333
|
}
|
|
13411
14334
|
);
|
|
13412
14335
|
const args = ctx.keyRun ? keyRunArgs(runArgs) : runArgs;
|
|
@@ -13425,6 +14348,8 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
13425
14348
|
deps.mergeGuardDir === void 0 ? join16(getConfigDir(), "merge-guard") : deps.mergeGuardDir
|
|
13426
14349
|
)
|
|
13427
14350
|
};
|
|
14351
|
+
const agentHooksDir = makeAgentHooksDir(runDir);
|
|
14352
|
+
if (agentHooksDir) Object.assign(baseEnv, withHooksDisabled(baseEnv, agentHooksDir));
|
|
13428
14353
|
const childEnv = ctx.keyRun ? keyRunEnv(baseEnv, ctx.keyRun) : baseEnv;
|
|
13429
14354
|
try {
|
|
13430
14355
|
if (resume) {
|
|
@@ -13465,13 +14390,19 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
13465
14390
|
let stderr = "";
|
|
13466
14391
|
let outputBytes = 0;
|
|
13467
14392
|
let settled = false;
|
|
13468
|
-
const child =
|
|
13469
|
-
|
|
13470
|
-
|
|
13471
|
-
|
|
13472
|
-
|
|
13473
|
-
|
|
13474
|
-
|
|
14393
|
+
const child = spawnPiped(
|
|
14394
|
+
spawnImpl,
|
|
14395
|
+
command,
|
|
14396
|
+
runArgsNow,
|
|
14397
|
+
{
|
|
14398
|
+
cwd: runDir,
|
|
14399
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
14400
|
+
env: childEnv,
|
|
14401
|
+
// ENG-300: lead its own process group so a cancel can stop everything it started.
|
|
14402
|
+
...groupSpawnOptions(deps.processGroup?.platform)
|
|
14403
|
+
},
|
|
14404
|
+
deps.processGroup?.platform
|
|
14405
|
+
);
|
|
13475
14406
|
let cancelled = false;
|
|
13476
14407
|
const disposeAbort = killGroupOnAbort(
|
|
13477
14408
|
ctx.signal,
|
|
@@ -13711,7 +14642,8 @@ ${stderr}`;
|
|
|
13711
14642
|
ctx.epicId,
|
|
13712
14643
|
progress.completedFeatures,
|
|
13713
14644
|
progress.totalFeatures,
|
|
13714
|
-
ctx.deferredFeatures
|
|
14645
|
+
ctx.deferredFeatures,
|
|
14646
|
+
ctx.checkMode
|
|
13715
14647
|
),
|
|
13716
14648
|
workspace?.baseBranch,
|
|
13717
14649
|
ctx.fastMode
|
|
@@ -13827,6 +14759,7 @@ ${stderr}`;
|
|
|
13827
14759
|
if (workspace) deps.activeRunDirs?.delete(workspace.dir);
|
|
13828
14760
|
if (replyAttachmentsDir)
|
|
13829
14761
|
await rm(replyAttachmentsDir, { recursive: true, force: true }).catch(() => void 0);
|
|
14762
|
+
if (agentHooksDir) await rm(agentHooksDir, { recursive: true, force: true }).catch(() => void 0);
|
|
13830
14763
|
const timings = buildJobTimings({
|
|
13831
14764
|
install: workspace?.install,
|
|
13832
14765
|
runs: runDurations,
|
|
@@ -13936,14 +14869,14 @@ async function updatePersonalEpicRequest(apiBaseUrl, userApiToken, epicRequestId
|
|
|
13936
14869
|
}
|
|
13937
14870
|
|
|
13938
14871
|
// src/utils/repo-setup.ts
|
|
13939
|
-
import { spawn as
|
|
13940
|
-
import { existsSync as
|
|
13941
|
-
import { homedir as
|
|
13942
|
-
import { dirname as
|
|
14872
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
14873
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync11, readdirSync as readdirSync4 } from "node:fs";
|
|
14874
|
+
import { homedir as homedir9 } from "node:os";
|
|
14875
|
+
import { dirname as dirname7, isAbsolute as isAbsolute3, join as join17, resolve as resolve3 } from "node:path";
|
|
13943
14876
|
var CLONE_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
13944
14877
|
var defaultGitCloner = (url, target) => new Promise((done) => {
|
|
13945
14878
|
let stderr = "";
|
|
13946
|
-
const child =
|
|
14879
|
+
const child = spawn7("git", ["clone", "--quiet", url, target], {
|
|
13947
14880
|
stdio: ["ignore", "ignore", "pipe"],
|
|
13948
14881
|
// Never hang on a username/password prompt: fail and explain instead.
|
|
13949
14882
|
env: { ...process.env, PATH: claudeChildEnvPath(process.env.PATH), GIT_TERMINAL_PROMPT: "0" }
|
|
@@ -13992,13 +14925,13 @@ function parsePayload(payload) {
|
|
|
13992
14925
|
...typeof p.projectName === "string" ? { projectName: p.projectName } : {}
|
|
13993
14926
|
};
|
|
13994
14927
|
}
|
|
13995
|
-
function
|
|
14928
|
+
function firstLine2(text) {
|
|
13996
14929
|
return text.trim().split("\n").filter(Boolean).pop() ?? "";
|
|
13997
14930
|
}
|
|
13998
14931
|
async function invokeConnectRepo(payload, deps = {}) {
|
|
13999
14932
|
const clone = deps.clone ?? defaultGitCloner;
|
|
14000
|
-
const home = deps.home ??
|
|
14001
|
-
const exists = deps.exists ??
|
|
14933
|
+
const home = deps.home ?? homedir9();
|
|
14934
|
+
const exists = deps.exists ?? existsSync16;
|
|
14002
14935
|
const isEmptyDir = deps.isEmptyDir ?? ((path3) => {
|
|
14003
14936
|
try {
|
|
14004
14937
|
return readdirSync4(path3).length === 0;
|
|
@@ -14010,14 +14943,14 @@ async function invokeConnectRepo(payload, deps = {}) {
|
|
|
14010
14943
|
const readOrigin = deps.readOrigin ?? readOriginRemote;
|
|
14011
14944
|
const listDirs = deps.listDirs ?? listProjectDirs;
|
|
14012
14945
|
const addDir = deps.addDir ?? ((path3) => addProjectDir(path3));
|
|
14013
|
-
const mkdir3 = deps.mkdir ?? ((path3) => void
|
|
14946
|
+
const mkdir3 = deps.mkdir ?? ((path3) => void mkdirSync11(path3, { recursive: true }));
|
|
14014
14947
|
const p = parsePayload(payload);
|
|
14015
14948
|
if (!p) {
|
|
14016
14949
|
return { status: "failed", result: { error: "The job was missing the project repository. Try again from the project page." } };
|
|
14017
14950
|
}
|
|
14018
14951
|
const remote = normalizeGitRemote(p.projectRemote);
|
|
14019
14952
|
const name = p.projectName ?? repoFolderName(remote);
|
|
14020
|
-
const existing = listDirs().find((entry) => entry.remote
|
|
14953
|
+
const existing = listDirs().find((entry) => sameGitRemote(entry.remote, remote) && exists(entry.path));
|
|
14021
14954
|
if (existing) {
|
|
14022
14955
|
return {
|
|
14023
14956
|
status: "done",
|
|
@@ -14033,7 +14966,7 @@ async function invokeConnectRepo(payload, deps = {}) {
|
|
|
14033
14966
|
} catch {
|
|
14034
14967
|
origin = "";
|
|
14035
14968
|
}
|
|
14036
|
-
if (origin
|
|
14969
|
+
if (!sameGitRemote(origin, remote)) {
|
|
14037
14970
|
return {
|
|
14038
14971
|
status: "failed",
|
|
14039
14972
|
result: {
|
|
@@ -14047,7 +14980,7 @@ async function invokeConnectRepo(payload, deps = {}) {
|
|
|
14047
14980
|
result: { path: entry2.path, remote, outcome: "adopted", message: `Found an existing copy of ${name} at ${entry2.path} and set it up.` }
|
|
14048
14981
|
};
|
|
14049
14982
|
}
|
|
14050
|
-
mkdir3(
|
|
14983
|
+
mkdir3(dirname7(target));
|
|
14051
14984
|
const errors = [];
|
|
14052
14985
|
let cloned = false;
|
|
14053
14986
|
for (const url of cloneUrls(remote)) {
|
|
@@ -14056,7 +14989,7 @@ async function invokeConnectRepo(payload, deps = {}) {
|
|
|
14056
14989
|
cloned = true;
|
|
14057
14990
|
break;
|
|
14058
14991
|
}
|
|
14059
|
-
errors.push(
|
|
14992
|
+
errors.push(firstLine2(res.stderr));
|
|
14060
14993
|
}
|
|
14061
14994
|
if (!cloned) {
|
|
14062
14995
|
return {
|
|
@@ -14083,11 +15016,11 @@ async function invokeConnectRepo(payload, deps = {}) {
|
|
|
14083
15016
|
}
|
|
14084
15017
|
|
|
14085
15018
|
// src/utils/keep-awake.ts
|
|
14086
|
-
import { spawn as
|
|
15019
|
+
import { spawn as spawn8 } from "node:child_process";
|
|
14087
15020
|
function startKeepAwake(opts) {
|
|
14088
15021
|
const platform = opts.platform ?? process.platform;
|
|
14089
15022
|
if (opts.enabled === false || platform !== "darwin") return null;
|
|
14090
|
-
const spawnFn = opts.spawnFn ??
|
|
15023
|
+
const spawnFn = opts.spawnFn ?? spawn8;
|
|
14091
15024
|
try {
|
|
14092
15025
|
const child = spawnFn("/usr/bin/caffeinate", ["-i", "-s", "-w", String(opts.pid ?? process.pid)], {
|
|
14093
15026
|
stdio: "ignore"
|
|
@@ -14308,6 +15241,8 @@ function parseStartExecutionPayload(payload) {
|
|
|
14308
15241
|
...fix && { fix },
|
|
14309
15242
|
// ENG-350: fast mode only when explicitly true.
|
|
14310
15243
|
...p.fastMode === true && { fastMode: true },
|
|
15244
|
+
// ENG-395: check cadence; an absent/unknown value leaves the orchestrator's default.
|
|
15245
|
+
...CHECK_MODES.includes(p.checkMode) && { checkMode: p.checkMode },
|
|
14311
15246
|
// ER-130: the owner's note and deferred features from "All merged — continue" / "Restart".
|
|
14312
15247
|
...typeof p.ownerNote === "string" && p.ownerNote.trim().length > 0 && { ownerNote: p.ownerNote },
|
|
14313
15248
|
...parseDeferredFeatures(p.deferredFeatures).length > 0 && {
|
|
@@ -14483,6 +15418,7 @@ async function handleStartExecution(ctx, job) {
|
|
|
14483
15418
|
...keyRun && { keyRun },
|
|
14484
15419
|
...orch?.fix && { fix: orch.fix },
|
|
14485
15420
|
...orch?.fastMode === true && { fastMode: true },
|
|
15421
|
+
...orch?.checkMode && { checkMode: orch.checkMode },
|
|
14486
15422
|
...orch?.ownerNote && { ownerNote: orch.ownerNote },
|
|
14487
15423
|
...orch?.deferredFeatures && { deferredFeatures: orch.deferredFeatures },
|
|
14488
15424
|
...orch?.freshBranch === true && { freshBranch: true },
|
|
@@ -14686,7 +15622,7 @@ Couldn't register ${options.projectDir.trim()}: ${error instanceof Error ? error
|
|
|
14686
15622
|
const legacyDir = unusedLegacyProjectDir(config);
|
|
14687
15623
|
const shims = ensurePackageManagerShims();
|
|
14688
15624
|
if (shims) {
|
|
14689
|
-
process.env.PATH = [shims.dir, process.env.PATH ?? ""].filter(Boolean).join(
|
|
15625
|
+
process.env.PATH = [shims.dir, process.env.PATH ?? ""].filter(Boolean).join(delimiter);
|
|
14690
15626
|
console.log(chalk9.gray(` ${shims.tools.join(" and ")} not installed \u2014 builds will run ${shims.tools.length > 1 ? "them" : "it"} through npx.`));
|
|
14691
15627
|
}
|
|
14692
15628
|
if (startKeepAwake({ enabled: config.keepAwake })) {
|
|
@@ -14837,11 +15773,6 @@ Received ${signal}, shutting down...`));
|
|
|
14837
15773
|
// src/commands/service.ts
|
|
14838
15774
|
import { Command as Command9 } from "commander";
|
|
14839
15775
|
import chalk10 from "chalk";
|
|
14840
|
-
import { execFile as execFile3 } from "node:child_process";
|
|
14841
|
-
import { promisify as promisify2 } from "node:util";
|
|
14842
|
-
var execFileAsync2 = promisify2(execFile3);
|
|
14843
|
-
var SERVICE_NAME = "CompBoxAgentRunner";
|
|
14844
|
-
var SERVICE_DISPLAY_NAME = "CompBox Agent Runner";
|
|
14845
15776
|
function requireWindows() {
|
|
14846
15777
|
if (process.platform !== "win32") {
|
|
14847
15778
|
console.error(
|
|
@@ -14856,93 +15787,159 @@ function requireWindows() {
|
|
|
14856
15787
|
}
|
|
14857
15788
|
return true;
|
|
14858
15789
|
}
|
|
14859
|
-
|
|
14860
|
-
|
|
15790
|
+
function printElevatedCommands() {
|
|
15791
|
+
console.error(chalk10.yellow(" From an Administrator terminal, run:"));
|
|
15792
|
+
for (const cmd of LEGACY_ELEVATED_COMMANDS) console.error(chalk10.yellow(` ${cmd}`));
|
|
15793
|
+
}
|
|
15794
|
+
function reportMigration(m) {
|
|
15795
|
+
switch (m.outcome) {
|
|
15796
|
+
case "absent":
|
|
15797
|
+
return;
|
|
15798
|
+
case "removed":
|
|
15799
|
+
console.log(chalk10.green(`\u2714 Removed the old LocalSystem service "${LEGACY_SERVICE_NAME}".`));
|
|
15800
|
+
return;
|
|
15801
|
+
case "access-denied":
|
|
15802
|
+
console.error(
|
|
15803
|
+
chalk10.yellow(
|
|
15804
|
+
`
|
|
15805
|
+
\u26A0 The old LocalSystem service "${LEGACY_SERVICE_NAME}" is still installed and removing it needs Administrator rights.`
|
|
15806
|
+
)
|
|
15807
|
+
);
|
|
15808
|
+
printElevatedCommands();
|
|
15809
|
+
return;
|
|
15810
|
+
case "failed":
|
|
15811
|
+
console.error(
|
|
15812
|
+
chalk10.yellow(`
|
|
15813
|
+
\u26A0 Could not remove the old service "${LEGACY_SERVICE_NAME}": ${m.detail ?? "unknown error"}`)
|
|
15814
|
+
);
|
|
15815
|
+
printElevatedCommands();
|
|
15816
|
+
return;
|
|
15817
|
+
case "unknown":
|
|
15818
|
+
console.error(chalk10.yellow(`
|
|
15819
|
+
\u26A0 ${m.detail ?? "Could not check for the old service."}`));
|
|
15820
|
+
return;
|
|
15821
|
+
}
|
|
14861
15822
|
}
|
|
14862
15823
|
var serviceCommand = new Command9("service").description(
|
|
14863
|
-
"Manage the Agent Runner as a Windows
|
|
15824
|
+
"Manage the Agent Runner as a per-user Windows Scheduled Task (macOS/Linux: use `brew services` instead)"
|
|
14864
15825
|
);
|
|
14865
|
-
serviceCommand.command("install").description("Register the Agent Runner as
|
|
15826
|
+
serviceCommand.command("install").description("Register the Agent Runner to start at logon as the current user, and start it now").action(async () => {
|
|
14866
15827
|
if (!requireWindows()) {
|
|
14867
15828
|
process.exit(1);
|
|
14868
15829
|
return;
|
|
14869
15830
|
}
|
|
14870
|
-
const nodeExe = process.execPath;
|
|
14871
|
-
const scriptPath = process.argv[1] ?? "";
|
|
14872
|
-
const binPath = `"${nodeExe}" "${scriptPath}" run`;
|
|
14873
15831
|
try {
|
|
14874
|
-
await
|
|
14875
|
-
|
|
14876
|
-
|
|
14877
|
-
|
|
14878
|
-
|
|
14879
|
-
|
|
14880
|
-
|
|
14881
|
-
"
|
|
14882
|
-
|
|
14883
|
-
|
|
14884
|
-
|
|
14885
|
-
|
|
14886
|
-
|
|
15832
|
+
const result = await installRunnerTask();
|
|
15833
|
+
reportMigration(result.migration);
|
|
15834
|
+
console.log(
|
|
15835
|
+
chalk10.green(`
|
|
15836
|
+
\u2714 "${RUNNER_DISPLAY_NAME}" registered as Scheduled Task "${RUNNER_TASK_NAME}" (starts when you sign in).`)
|
|
15837
|
+
);
|
|
15838
|
+
if (result.started) {
|
|
15839
|
+
console.log(chalk10.green("\u2714 Agent Runner started."));
|
|
15840
|
+
} else if (result.notStartedReason === "legacy-running") {
|
|
15841
|
+
console.error(
|
|
15842
|
+
chalk10.yellow(
|
|
15843
|
+
" Not started: the old service is still running. Remove it with the commands above, then run: compbox service start"
|
|
15844
|
+
)
|
|
15845
|
+
);
|
|
15846
|
+
} else {
|
|
15847
|
+
console.error(chalk10.yellow(` Not started: ${result.startError ?? "schtasks /Run failed"}`));
|
|
15848
|
+
console.error(chalk10.gray(" Retry with: compbox service start"));
|
|
15849
|
+
}
|
|
14887
15850
|
} catch (error) {
|
|
14888
|
-
const
|
|
14889
|
-
const stderr = error.stderr?.trim();
|
|
15851
|
+
const f = describeExecError(error);
|
|
14890
15852
|
console.error(chalk10.red(`
|
|
14891
|
-
Failed to
|
|
14892
|
-
if (stderr) console.error(chalk10.red(` sc.exe: ${stderr}`));
|
|
14893
|
-
console.error(chalk10.gray(" If this is a permissions error, run the terminal as Administrator."));
|
|
15853
|
+
Failed to register the Scheduled Task: ${failureSummary(f)}`));
|
|
14894
15854
|
process.exit(1);
|
|
14895
15855
|
}
|
|
14896
15856
|
});
|
|
14897
|
-
serviceCommand.command("uninstall").description("Stop and remove the
|
|
15857
|
+
serviceCommand.command("uninstall").description("Stop and remove the Agent Runner Scheduled Task").action(async () => {
|
|
14898
15858
|
if (!requireWindows()) {
|
|
14899
15859
|
process.exit(1);
|
|
14900
15860
|
return;
|
|
14901
15861
|
}
|
|
14902
15862
|
try {
|
|
14903
|
-
await
|
|
14904
|
-
});
|
|
14905
|
-
await runSc(["delete", SERVICE_NAME]);
|
|
15863
|
+
await uninstallRunnerTask();
|
|
14906
15864
|
console.log(chalk10.green(`
|
|
14907
|
-
\u2714
|
|
15865
|
+
\u2714 Scheduled Task "${RUNNER_TASK_NAME}" removed.`));
|
|
14908
15866
|
} catch (error) {
|
|
14909
|
-
const message = error instanceof Error ? error.message : "sc.exe delete failed";
|
|
14910
15867
|
console.error(chalk10.red(`
|
|
14911
|
-
Failed to remove the
|
|
14912
|
-
console.error(chalk10.gray(" Try running this terminal as Administrator."));
|
|
15868
|
+
Failed to remove the Scheduled Task: ${failureSummary(describeExecError(error))}`));
|
|
14913
15869
|
process.exit(1);
|
|
14914
15870
|
}
|
|
15871
|
+
if (await queryLegacyService() !== "absent") {
|
|
15872
|
+
console.error(chalk10.yellow(`
|
|
15873
|
+
\u26A0 The old LocalSystem service "${LEGACY_SERVICE_NAME}" is still installed.`));
|
|
15874
|
+
printElevatedCommands();
|
|
15875
|
+
}
|
|
14915
15876
|
});
|
|
14916
|
-
serviceCommand.command("start").description("Start the
|
|
15877
|
+
serviceCommand.command("start").description("Start the Agent Runner Scheduled Task now").action(async () => {
|
|
14917
15878
|
if (!requireWindows()) {
|
|
14918
15879
|
process.exit(1);
|
|
14919
15880
|
return;
|
|
14920
15881
|
}
|
|
14921
|
-
|
|
14922
|
-
|
|
15882
|
+
const r = await startRunnerTask();
|
|
15883
|
+
if (r.started) {
|
|
14923
15884
|
console.log(chalk10.green(`
|
|
14924
|
-
\u2714
|
|
14925
|
-
|
|
14926
|
-
|
|
15885
|
+
\u2714 "${RUNNER_DISPLAY_NAME}" started.`));
|
|
15886
|
+
return;
|
|
15887
|
+
}
|
|
15888
|
+
if (r.reason === "legacy-running") {
|
|
15889
|
+
console.error(
|
|
15890
|
+
chalk10.red(`
|
|
15891
|
+
Not started: the old LocalSystem service "${LEGACY_SERVICE_NAME}" is running, and only one runner may run.`)
|
|
15892
|
+
);
|
|
15893
|
+
printElevatedCommands();
|
|
15894
|
+
} else {
|
|
14927
15895
|
console.error(chalk10.red(`
|
|
14928
|
-
Failed to start
|
|
14929
|
-
|
|
15896
|
+
Failed to start: ${r.error}`));
|
|
15897
|
+
console.error(chalk10.gray(" If the task is not registered yet, run: compbox service install"));
|
|
14930
15898
|
}
|
|
15899
|
+
process.exit(1);
|
|
14931
15900
|
});
|
|
14932
|
-
serviceCommand.command("stop").description("Stop the running
|
|
15901
|
+
serviceCommand.command("stop").description("Stop the running Agent Runner").action(async () => {
|
|
14933
15902
|
if (!requireWindows()) {
|
|
14934
15903
|
process.exit(1);
|
|
14935
15904
|
return;
|
|
14936
15905
|
}
|
|
14937
15906
|
try {
|
|
14938
|
-
await
|
|
15907
|
+
await stopRunnerTask();
|
|
14939
15908
|
console.log(chalk10.green(`
|
|
14940
|
-
\u2714
|
|
15909
|
+
\u2714 "${RUNNER_DISPLAY_NAME}" stopped.`));
|
|
14941
15910
|
} catch (error) {
|
|
14942
|
-
const message = error instanceof Error ? error.message : "sc.exe stop failed";
|
|
14943
15911
|
console.error(chalk10.red(`
|
|
14944
|
-
Failed to stop
|
|
15912
|
+
Failed to stop: ${failureSummary(describeExecError(error))}`));
|
|
15913
|
+
process.exit(1);
|
|
15914
|
+
}
|
|
15915
|
+
});
|
|
15916
|
+
serviceCommand.command("status").description("Show whether the Agent Runner task is registered and running").action(async () => {
|
|
15917
|
+
if (!requireWindows()) {
|
|
15918
|
+
process.exit(1);
|
|
15919
|
+
return;
|
|
15920
|
+
}
|
|
15921
|
+
const task = await queryRunnerTask();
|
|
15922
|
+
if (task.error) {
|
|
15923
|
+
console.error(chalk10.red(`
|
|
15924
|
+
Could not query the Scheduled Task: ${task.error}`));
|
|
14945
15925
|
process.exit(1);
|
|
15926
|
+
return;
|
|
15927
|
+
}
|
|
15928
|
+
if (!task.exists) {
|
|
15929
|
+
console.log(chalk10.yellow(`
|
|
15930
|
+
Scheduled Task "${RUNNER_TASK_NAME}" is not registered \u2014 run: compbox service install`));
|
|
15931
|
+
} else {
|
|
15932
|
+
console.log(`
|
|
15933
|
+
Scheduled Task "${RUNNER_TASK_NAME}"`);
|
|
15934
|
+
console.log(` Status: ${task.status ?? "unknown"}`);
|
|
15935
|
+
console.log(` Runs as: ${task.runAsUser ?? "unknown"}`);
|
|
15936
|
+
if (task.taskToRun) console.log(` Command: ${task.taskToRun}`);
|
|
15937
|
+
}
|
|
15938
|
+
const legacy = await queryLegacyService();
|
|
15939
|
+
if (legacy !== "absent") {
|
|
15940
|
+
console.log(chalk10.yellow(`
|
|
15941
|
+
\u26A0 Old LocalSystem service "${LEGACY_SERVICE_NAME}" is still installed (${legacy}).`));
|
|
15942
|
+
printElevatedCommands();
|
|
14946
15943
|
}
|
|
14947
15944
|
});
|
|
14948
15945
|
|
|
@@ -15208,8 +16205,8 @@ Setting up ${match.name} (${match.gitRemote})...`));
|
|
|
15208
16205
|
import { Command as Command13 } from "commander";
|
|
15209
16206
|
import chalk14 from "chalk";
|
|
15210
16207
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
15211
|
-
import { mkdirSync as
|
|
15212
|
-
import { homedir as
|
|
16208
|
+
import { mkdirSync as mkdirSync12, readdirSync as readdirSync5, readFileSync as readFileSync9, statSync as statSync6, writeFileSync as writeFileSync11 } from "node:fs";
|
|
16209
|
+
import { homedir as homedir10 } from "node:os";
|
|
15213
16210
|
import { join as join18 } from "node:path";
|
|
15214
16211
|
function readWorkspaceEnv(env = process.env) {
|
|
15215
16212
|
const apiUrl = env.COMPBOX_API_URL?.trim();
|
|
@@ -15218,15 +16215,15 @@ function readWorkspaceEnv(env = process.env) {
|
|
|
15218
16215
|
if (!apiUrl || !jobId || !token) return null;
|
|
15219
16216
|
return { apiUrl: apiUrl.replace(/\/+$/, ""), jobId, token };
|
|
15220
16217
|
}
|
|
15221
|
-
async function workspaceApi(env, path3, method, fetchFn) {
|
|
16218
|
+
async function workspaceApi(env, path3, method, fetchFn, body = {}) {
|
|
15222
16219
|
const res = await fetchFn(`${env.apiUrl}/api/v1/cloud-runs/workspace/${path3}`, {
|
|
15223
16220
|
method,
|
|
15224
16221
|
headers: { Authorization: `Bearer ${env.token}`, ...method === "POST" && { "Content-Type": "application/json" } },
|
|
15225
|
-
...method === "POST" && { body:
|
|
16222
|
+
...method === "POST" && { body: JSON.stringify(body) }
|
|
15226
16223
|
});
|
|
15227
16224
|
if (!res.ok) {
|
|
15228
|
-
const
|
|
15229
|
-
throw new Error(
|
|
16225
|
+
const body2 = await res.json().catch(() => null);
|
|
16226
|
+
throw new Error(body2?.error?.message ?? `CompBox returned ${String(res.status)} for ${path3}`);
|
|
15230
16227
|
}
|
|
15231
16228
|
return (await res.json()).data;
|
|
15232
16229
|
}
|
|
@@ -15254,7 +16251,7 @@ async function runWorkspace(deps = {}) {
|
|
|
15254
16251
|
}
|
|
15255
16252
|
const fetchFn = deps.fetchFn ?? fetch;
|
|
15256
16253
|
const run = deps.run ?? defaultRunner;
|
|
15257
|
-
const home = deps.home ??
|
|
16254
|
+
const home = deps.home ?? homedir10();
|
|
15258
16255
|
const agentsDir = deps.agentsDir ?? "/opt/compbox/.github/agents/claude";
|
|
15259
16256
|
const workDir = deps.workDir ?? "/workspace";
|
|
15260
16257
|
const client = deps.client ?? new MailboxClient(env.apiUrl);
|
|
@@ -15284,7 +16281,7 @@ async function runWorkspace(deps = {}) {
|
|
|
15284
16281
|
run("git", ["config", "--global", "credential.helper", "!compbox workspace git-credential"]);
|
|
15285
16282
|
run("git", ["config", "--global", "user.name", "CompBox"]);
|
|
15286
16283
|
run("git", ["config", "--global", "user.email", "bot@mycompbox.com"]);
|
|
15287
|
-
|
|
16284
|
+
mkdirSync12(workDir, { recursive: true });
|
|
15288
16285
|
run("git", ["clone", "--branch", git.defaultBranch, git.cloneUrl, repoDir]);
|
|
15289
16286
|
run("claude", [
|
|
15290
16287
|
"mcp",
|
|
@@ -15299,8 +16296,8 @@ async function runWorkspace(deps = {}) {
|
|
|
15299
16296
|
"--",
|
|
15300
16297
|
"compbox-mcp"
|
|
15301
16298
|
]);
|
|
15302
|
-
|
|
15303
|
-
|
|
16299
|
+
mkdirSync12(join18(home, ".claude"), { recursive: true });
|
|
16300
|
+
writeFileSync11(join18(home, ".claude", "CLAUDE.md"), agentRoutingInstructions(agentsDir));
|
|
15304
16301
|
} catch (error) {
|
|
15305
16302
|
return fail(`Setting up the cloud workspace failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
15306
16303
|
}
|
|
@@ -15377,17 +16374,96 @@ async function runWorkspace(deps = {}) {
|
|
|
15377
16374
|
}
|
|
15378
16375
|
if (cancelled()) return finishCancelled();
|
|
15379
16376
|
if (outcome.status === "waiting") {
|
|
15380
|
-
|
|
15381
|
-
await client.completeJob(env.token, job.id, "failed", {
|
|
15382
|
-
...outcome.result,
|
|
15383
|
-
error: `The AI usage limit was reached${resetAt}. Cloud runs can't wait for the reset \u2014 start the run again once the limit resets.`
|
|
15384
|
-
});
|
|
16377
|
+
return parkWorkspace({ env, jobId: job.id, outcome, home, run, fetchFn, client });
|
|
15385
16378
|
} else {
|
|
15386
16379
|
await client.completeJob(env.token, job.id, outcome.status, outcome.result);
|
|
15387
16380
|
}
|
|
15388
16381
|
console.log(outcome.status === "done" ? chalk14.green("Finished.") : chalk14.yellow(`Stopped: ${JSON.stringify(outcome.result)}`));
|
|
15389
16382
|
return outcome.status === "done" ? 0 : 1;
|
|
15390
16383
|
}
|
|
16384
|
+
var MAX_TRANSCRIPT_BYTES = 5 * 1024 * 1024;
|
|
16385
|
+
function findSessionTranscript(home) {
|
|
16386
|
+
const root = join18(home, ".claude", "projects");
|
|
16387
|
+
let newest = null;
|
|
16388
|
+
let folders;
|
|
16389
|
+
try {
|
|
16390
|
+
folders = readdirSync5(root);
|
|
16391
|
+
} catch {
|
|
16392
|
+
return null;
|
|
16393
|
+
}
|
|
16394
|
+
for (const folder of folders) {
|
|
16395
|
+
let files;
|
|
16396
|
+
try {
|
|
16397
|
+
files = readdirSync5(join18(root, folder));
|
|
16398
|
+
} catch {
|
|
16399
|
+
continue;
|
|
16400
|
+
}
|
|
16401
|
+
for (const file of files) {
|
|
16402
|
+
if (!file.endsWith(".jsonl")) continue;
|
|
16403
|
+
const path3 = join18(root, folder, file);
|
|
16404
|
+
const stat = statSync6(path3, { throwIfNoEntry: false });
|
|
16405
|
+
if (!stat?.isFile()) continue;
|
|
16406
|
+
if (!newest || stat.mtimeMs > newest.mtime) {
|
|
16407
|
+
newest = { path: path3, folder, sessionId: file.slice(0, -".jsonl".length), mtime: stat.mtimeMs, bytes: stat.size };
|
|
16408
|
+
}
|
|
16409
|
+
}
|
|
16410
|
+
}
|
|
16411
|
+
if (!newest) return null;
|
|
16412
|
+
return {
|
|
16413
|
+
sessionId: newest.sessionId,
|
|
16414
|
+
projectFolder: newest.folder,
|
|
16415
|
+
transcript: newest.bytes > MAX_TRANSCRIPT_BYTES ? "" : readFileSync9(newest.path, "utf-8"),
|
|
16416
|
+
bytes: newest.bytes
|
|
16417
|
+
};
|
|
16418
|
+
}
|
|
16419
|
+
async function parkWorkspace({ env, jobId, outcome, home, run, fetchFn, client }) {
|
|
16420
|
+
const result = outcome.result;
|
|
16421
|
+
const needsInput = result.stopReason === "needs_input";
|
|
16422
|
+
const failPark = async (why) => {
|
|
16423
|
+
const resetAt = outcome.resumeAt ? ` (it resets at ${outcome.resumeAt.toISOString()})` : "";
|
|
16424
|
+
const error = needsInput ? `The run stopped to ask you something, but it couldn't be paused: ${why}. Start the run again.` : `The AI usage limit was reached${resetAt}, but the run couldn't be paused: ${why}. Start the run again once the limit resets.`;
|
|
16425
|
+
console.error(chalk14.red(error));
|
|
16426
|
+
await client.completeJob(env.token, jobId, "failed", { ...result, error }).catch(() => void 0);
|
|
16427
|
+
return 1;
|
|
16428
|
+
};
|
|
16429
|
+
const branch = typeof result.branch === "string" ? result.branch : void 0;
|
|
16430
|
+
const commits = typeof result.commits === "number" ? result.commits : 0;
|
|
16431
|
+
const keptWorktree = typeof result.keptWorktree === "string" ? result.keptWorktree : void 0;
|
|
16432
|
+
let pushed = result.pushed === true;
|
|
16433
|
+
if (branch && commits > 0 && !pushed) {
|
|
16434
|
+
if (!keptWorktree) return failPark(`its branch ${branch} wasn't pushed`);
|
|
16435
|
+
try {
|
|
16436
|
+
run("git", ["push", "--set-upstream", "origin", `HEAD:refs/heads/${branch}`], keptWorktree);
|
|
16437
|
+
pushed = true;
|
|
16438
|
+
} catch (error) {
|
|
16439
|
+
return failPark(`pushing its branch ${branch} failed (${error instanceof Error ? error.message : String(error)})`);
|
|
16440
|
+
}
|
|
16441
|
+
}
|
|
16442
|
+
const session = findSessionTranscript(home);
|
|
16443
|
+
if (!session) return failPark("its Claude session couldn't be found");
|
|
16444
|
+
if (session.bytes > MAX_TRANSCRIPT_BYTES) {
|
|
16445
|
+
return failPark(`its Claude session is too large to keep (${String(Math.ceil(session.bytes / 1024 / 1024))} MB, the limit is 5 MB)`);
|
|
16446
|
+
}
|
|
16447
|
+
try {
|
|
16448
|
+
await workspaceApi(env, "park", "POST", fetchFn, {
|
|
16449
|
+
jobId,
|
|
16450
|
+
reason: needsInput ? "needs_input" : "usage_limit",
|
|
16451
|
+
result: { ...result, ...branch && { pushed } },
|
|
16452
|
+
...outcome.resumeAt && { resumeAt: outcome.resumeAt.toISOString() },
|
|
16453
|
+
sessionId: session.sessionId,
|
|
16454
|
+
projectFolder: session.projectFolder,
|
|
16455
|
+
transcript: session.transcript
|
|
16456
|
+
});
|
|
16457
|
+
} catch (error) {
|
|
16458
|
+
return failPark(error instanceof Error ? error.message : String(error));
|
|
16459
|
+
}
|
|
16460
|
+
console.log(
|
|
16461
|
+
chalk14.yellow(
|
|
16462
|
+
needsInput ? "Paused: waiting for your reply. The run picks up again when you answer." : `Paused: the AI usage limit was reached. The run picks up again${outcome.resumeAt ? ` at ${outcome.resumeAt.toISOString()}` : " once it resets"}.`
|
|
16463
|
+
)
|
|
16464
|
+
);
|
|
16465
|
+
return 0;
|
|
16466
|
+
}
|
|
15391
16467
|
async function gitCredential(action, deps = {}) {
|
|
15392
16468
|
if (action !== "get") return;
|
|
15393
16469
|
const env = readWorkspaceEnv(deps.env);
|