@the-vibe-company/armada 0.2.41 → 0.2.43
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/dist/armada.js +263 -29
- package/package.json +1 -1
package/dist/armada.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
|
-
import { spawn as
|
|
4
|
+
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
5
5
|
import { createReadStream } from "node:fs";
|
|
6
6
|
import { open as open2, readFile as readFile4, writeFile as writeFile3 } from "node:fs/promises";
|
|
7
7
|
import { hostname as hostname2 } from "node:os";
|
|
@@ -10156,7 +10156,7 @@ ${attachments.join(`
|
|
|
10156
10156
|
};
|
|
10157
10157
|
}
|
|
10158
10158
|
// package.json
|
|
10159
|
-
var version = "0.2.
|
|
10159
|
+
var version = "0.2.43";
|
|
10160
10160
|
|
|
10161
10161
|
// src/attach.ts
|
|
10162
10162
|
import { resolve } from "node:path";
|
|
@@ -10693,6 +10693,68 @@ async function logout(io) {
|
|
|
10693
10693
|
return 0;
|
|
10694
10694
|
}
|
|
10695
10695
|
|
|
10696
|
+
// src/opencode-model.ts
|
|
10697
|
+
import { stripVTControlCharacters } from "node:util";
|
|
10698
|
+
function modelsFrom(raw) {
|
|
10699
|
+
const models = [];
|
|
10700
|
+
for (const match of stripVTControlCharacters(raw).matchAll(/^([^\s/#]+\/[^\s#]+)\r?\n(\{\r?\n[\s\S]*?^\})/gm)) {
|
|
10701
|
+
try {
|
|
10702
|
+
const metadata = JSON.parse(match[2] ?? "");
|
|
10703
|
+
const id = match[1] ?? "";
|
|
10704
|
+
if (metadata && `${metadata.providerID}/${metadata.id}` === id && typeof metadata.name === "string" && metadata.name.trim() && !/[\r\n]/.test(metadata.name) && stripVTControlCharacters(metadata.name) === metadata.name)
|
|
10705
|
+
models.push({ id, name: metadata.name });
|
|
10706
|
+
} catch {}
|
|
10707
|
+
}
|
|
10708
|
+
return models;
|
|
10709
|
+
}
|
|
10710
|
+
function selectedModel(pane, models) {
|
|
10711
|
+
const lines = stripVTControlCharacters(pane).split(`
|
|
10712
|
+
`);
|
|
10713
|
+
const footers = lines.flatMap((line, index) => {
|
|
10714
|
+
if (!/^\s*╹/.test(lines[index + 1] ?? ""))
|
|
10715
|
+
return [];
|
|
10716
|
+
const match = line.trim().match(/^(?:[┃│]\s*)?[A-Z][\w-]*(?:\s+auto)?(?:\s+·)?\s+(.+)$/);
|
|
10717
|
+
return match?.[1] ? [match[1]] : [];
|
|
10718
|
+
});
|
|
10719
|
+
const candidates = models.filter((model) => footers.some((footer) => footer.startsWith(`${model.name} `) || footer.startsWith(`${model.id} `)));
|
|
10720
|
+
const ids = [...new Set(candidates.map((model) => model.id))];
|
|
10721
|
+
return ids.length === 1 ? ids[0] ?? null : null;
|
|
10722
|
+
}
|
|
10723
|
+
async function verifyOpenCodeModel(io, pane, expected) {
|
|
10724
|
+
const failure = () => new UsageError(`could not verify OpenCode model ${expected} from its pane; launch stopped`);
|
|
10725
|
+
if (!io.exec)
|
|
10726
|
+
throw failure();
|
|
10727
|
+
const metadata = await io.exec("opencode", ["models", "--verbose"], { cwd: io.cwd, timeoutMs: 5000 }).catch(() => null);
|
|
10728
|
+
const models = metadata?.code === 0 ? modelsFrom(metadata.stdout) : [];
|
|
10729
|
+
if (!models.some((model) => model.id === expected))
|
|
10730
|
+
throw failure();
|
|
10731
|
+
const now = io.now ?? (() => new Date);
|
|
10732
|
+
const deadline = now().getTime() + 5000;
|
|
10733
|
+
for (let attempt = 0;attempt < 20; attempt++) {
|
|
10734
|
+
const remaining = deadline - now().getTime();
|
|
10735
|
+
if (remaining <= 0)
|
|
10736
|
+
break;
|
|
10737
|
+
const reading = await io.exec("herdr", ["pane", "read", pane, "--source", "visible"], {
|
|
10738
|
+
cwd: io.cwd,
|
|
10739
|
+
timeoutMs: Math.min(1000, remaining)
|
|
10740
|
+
}).catch(() => null);
|
|
10741
|
+
if (reading?.code !== 0)
|
|
10742
|
+
throw failure();
|
|
10743
|
+
const text = stripVTControlCharacters(reading.stdout);
|
|
10744
|
+
if (/ProviderModelNotFoundError|Model not found:/i.test(text))
|
|
10745
|
+
throw new UsageError(`OpenCode could not load profile model ${expected}; launch stopped`);
|
|
10746
|
+
const selected = selectedModel(text, models);
|
|
10747
|
+
if (selected === expected)
|
|
10748
|
+
return;
|
|
10749
|
+
if (selected)
|
|
10750
|
+
throw new UsageError(`OpenCode model differs from profile ${expected}; launch stopped`);
|
|
10751
|
+
const delay = Math.min(250, deadline - now().getTime());
|
|
10752
|
+
if (delay > 0)
|
|
10753
|
+
await (io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))))(delay);
|
|
10754
|
+
}
|
|
10755
|
+
throw failure();
|
|
10756
|
+
}
|
|
10757
|
+
|
|
10696
10758
|
// src/herdr.ts
|
|
10697
10759
|
class HerdrError extends UsageError {
|
|
10698
10760
|
code;
|
|
@@ -10703,7 +10765,7 @@ class HerdrError extends UsageError {
|
|
|
10703
10765
|
}
|
|
10704
10766
|
var harnessArgs = (p) => [
|
|
10705
10767
|
"--model",
|
|
10706
|
-
|
|
10768
|
+
p.model,
|
|
10707
10769
|
...p.harness === "codex" ? ["-c", `model_reasoning_effort=${JSON.stringify(p.effort)}`] : p.harness === "claude" ? ["--effort", p.effort] : [],
|
|
10708
10770
|
...p.extraArgs
|
|
10709
10771
|
];
|
|
@@ -10863,6 +10925,18 @@ class Herdr {
|
|
|
10863
10925
|
...harnessArgs(profile)
|
|
10864
10926
|
]);
|
|
10865
10927
|
this.checkAgent(r, handle);
|
|
10928
|
+
if (herdrHarnessKind(profile.harness) === "opencode") {
|
|
10929
|
+
try {
|
|
10930
|
+
await verifyOpenCodeModel(this.io, handle.pane, profile.model);
|
|
10931
|
+
} catch (error) {
|
|
10932
|
+
let closed = false;
|
|
10933
|
+
try {
|
|
10934
|
+
await this.call(["pane", "close", handle.pane]);
|
|
10935
|
+
closed = true;
|
|
10936
|
+
} catch {}
|
|
10937
|
+
throw new UsageError(`${error instanceof UsageError ? error.message : "could not verify OpenCode model"}; ${closed ? "worker pane closed" : "could not close worker pane; close it with herdr pane close"}. No worker brief was sent.`);
|
|
10938
|
+
}
|
|
10939
|
+
}
|
|
10866
10940
|
}
|
|
10867
10941
|
async prompt(handle, prompt) {
|
|
10868
10942
|
const r = await this.call([
|
|
@@ -11903,7 +11977,7 @@ ${next.line}
|
|
|
11903
11977
|
import { join as join4 } from "node:path";
|
|
11904
11978
|
|
|
11905
11979
|
// src/local-tools.ts
|
|
11906
|
-
import { stripVTControlCharacters } from "node:util";
|
|
11980
|
+
import { stripVTControlCharacters as stripVTControlCharacters2 } from "node:util";
|
|
11907
11981
|
var MINIMUM_HERDR_VERSION = "0.9.1";
|
|
11908
11982
|
var TOOLS = {
|
|
11909
11983
|
herdr: { command: "herdr", install: "curl -fsSL https://herdr.dev/install.sh | sh" },
|
|
@@ -11916,12 +11990,12 @@ function localHarnesses(config) {
|
|
|
11916
11990
|
return [...new Set(Object.values(config.herdr?.profiles ?? {}).map((profile) => profile.harness))];
|
|
11917
11991
|
}
|
|
11918
11992
|
function localModelProfiles(config) {
|
|
11919
|
-
return Object.entries(config.herdr?.profiles ?? {}).flatMap(([name, profile]) => profile.harness === "opencode" || profile.harness === "deepseek" ? [{ name, harness: profile.harness, model: profile.model ?? "" }] : []);
|
|
11993
|
+
return Object.entries(config.herdr?.profiles ?? {}).flatMap(([name, profile]) => profile.model || profile.harness === "opencode" || profile.harness === "deepseek" ? [{ name, harness: profile.harness, model: profile.model ?? "" }] : []);
|
|
11920
11994
|
}
|
|
11921
|
-
async function probe(io, command, args) {
|
|
11995
|
+
async function probe(io, command, args, limits = {}) {
|
|
11922
11996
|
if (!io.exec)
|
|
11923
11997
|
return null;
|
|
11924
|
-
return io.exec(command, args, { cwd: io.cwd }).catch(() => null);
|
|
11998
|
+
return io.exec(command, args, { cwd: io.cwd, ...limits }).catch(() => null);
|
|
11925
11999
|
}
|
|
11926
12000
|
function versionOf(result) {
|
|
11927
12001
|
if (result.code !== 0)
|
|
@@ -12019,12 +12093,41 @@ async function openCodeModels(io) {
|
|
|
12019
12093
|
if (result?.code !== 0)
|
|
12020
12094
|
return null;
|
|
12021
12095
|
return [
|
|
12022
|
-
...new Set(
|
|
12096
|
+
...new Set(stripVTControlCharacters2(result.stdout).split(`
|
|
12023
12097
|
`).map((line) => line.trim()).filter((line) => /^[^\s/#]+\/[^\s#]+$/.test(line)))
|
|
12024
12098
|
];
|
|
12025
12099
|
}
|
|
12100
|
+
async function claudeModels(io) {
|
|
12101
|
+
const result = await probe(io, "claude", ["--help"], { timeoutMs: 5000, maxOutputBytes: 262144 });
|
|
12102
|
+
if (result?.code !== 0)
|
|
12103
|
+
return null;
|
|
12104
|
+
const help = stripVTControlCharacters2(result.stdout);
|
|
12105
|
+
const option = help.match(/(?:^|\n)\s+--model\s+<model>([\s\S]*?)(?=\n\s+--?[a-zA-Z]|$)/)?.[1];
|
|
12106
|
+
if (!option)
|
|
12107
|
+
return null;
|
|
12108
|
+
return [
|
|
12109
|
+
...new Set([...option.matchAll(/['"]([a-z][a-z0-9.[\]-]*)['"]/g)].flatMap((match) => match[1] ? [match[1]] : []))
|
|
12110
|
+
];
|
|
12111
|
+
}
|
|
12112
|
+
function modelsFor(detected, profile) {
|
|
12113
|
+
return detected.availableModels[profile.harness === "deepseek" ? "opencode" : profile.harness] ?? null;
|
|
12114
|
+
}
|
|
12026
12115
|
function modelCheck(profile, available) {
|
|
12027
12116
|
const model = profile.model;
|
|
12117
|
+
if (profile.harness === "claude" || profile.harness === "codex") {
|
|
12118
|
+
const claude = profile.harness === "claude";
|
|
12119
|
+
const ready = !!model && !!available?.includes(model);
|
|
12120
|
+
const section = profile.name ? ` under [herdr.profiles.${profile.name}]` : "";
|
|
12121
|
+
const suggested = claude ? available?.find((id) => id === "opus") ?? available?.[0] : available?.[0];
|
|
12122
|
+
const line = `model = ${JSON.stringify(suggested ?? "<exact model id>")}${section}`;
|
|
12123
|
+
return {
|
|
12124
|
+
id: `local-${profile.harness}-model:${profile.name || model}`,
|
|
12125
|
+
level: ready ? "ok" : "error",
|
|
12126
|
+
message: `${profile.harness}${profile.name ? ` profile ${profile.name}` : ""}: ${ready ? claude ? `the installed CLI advertises ${model} in --help` : `model/list lists ${model} for this sign-in (catalog check only)` : claude ? `could not verify ${model} with the installed CLI; --help is not a complete model catalog` : available === null ? "could not read the installed CLI's model/list catalog for this sign-in" : `${model} is not listed by the installed CLI for this sign-in`}${!claude && !ready && available?.length ? `
|
|
12127
|
+
Available models: ${available.map((id, i) => `${i + 1}. ${id} — model = ${JSON.stringify(id)}`).join("; ")}` : ""}`,
|
|
12128
|
+
fix: ready ? null : claude ? `add ${line}${suggested ? " (an advertised alias or model)" : "; choose an alias from `claude --help` or the owner's `/model` picker"}; or run \`claude update\` and retry doctor` : `pick a listed model and add ${line}; or update with \`npm i -g @openai/codex\`; if the model requires API access, the owner signs in using \`codex login --with-api-key\` and retries doctor; Armada never runs sign-in`
|
|
12129
|
+
};
|
|
12130
|
+
}
|
|
12028
12131
|
const matching = available?.filter((id) => profile.harness !== "deepseek" || isDeepseekModel(id)) ?? [];
|
|
12029
12132
|
const ready = !!model && matching.includes(model);
|
|
12030
12133
|
const label = profile.harness === "deepseek" ? "deepseek (OpenCode + DeepSeek model)" : "opencode";
|
|
@@ -12037,13 +12140,14 @@ ${ready ? "" : `Available models: ${matching.length ? matching.map((id, i) => `$
|
|
|
12037
12140
|
};
|
|
12038
12141
|
}
|
|
12039
12142
|
async function offerLocalModels(io, detected, configPath, options = {}) {
|
|
12040
|
-
if (detected.availableModels === null)
|
|
12041
|
-
return detected;
|
|
12042
12143
|
let changed = false;
|
|
12043
12144
|
for (const profile of detected.profiles) {
|
|
12044
|
-
if (
|
|
12145
|
+
if (profile.harness === "claude")
|
|
12045
12146
|
continue;
|
|
12046
|
-
const
|
|
12147
|
+
const available = modelsFor(detected, profile);
|
|
12148
|
+
if (!available || modelCheck(profile, available).level === "ok")
|
|
12149
|
+
continue;
|
|
12150
|
+
const models = available.filter((id) => profile.harness !== "deepseek" || isDeepseekModel(id));
|
|
12047
12151
|
if (!models.length || options.readOnly || !io.interactive || io.env.CI || !io.prompt || !io.writeFile || !configPath || !profile.name)
|
|
12048
12152
|
continue;
|
|
12049
12153
|
io.stderr(`Choose a model for [herdr.profiles.${profile.name}]:
|
|
@@ -12096,7 +12200,7 @@ async function detectLocalTools(io, harnesses, configured = []) {
|
|
|
12096
12200
|
if ((harness === "opencode" || harness === "deepseek") && !profiles.some((profile) => profile.harness === harness))
|
|
12097
12201
|
profiles.push({ name: "", harness, model: "" });
|
|
12098
12202
|
}
|
|
12099
|
-
|
|
12203
|
+
const availableModels = {};
|
|
12100
12204
|
const tools = [];
|
|
12101
12205
|
const checks = [];
|
|
12102
12206
|
const binaries = new Set(harnesses.map((harness) => harness === "deepseek" ? "opencode" : harness));
|
|
@@ -12105,11 +12209,13 @@ async function detectLocalTools(io, harnesses, configured = []) {
|
|
|
12105
12209
|
tools.push(tool);
|
|
12106
12210
|
checks.push(toolCheck(tool));
|
|
12107
12211
|
if (name !== "herdr" && tool.state === "ready") {
|
|
12108
|
-
|
|
12109
|
-
|
|
12110
|
-
|
|
12111
|
-
|
|
12112
|
-
|
|
12212
|
+
const signIn = name !== "opencode" ? await signInCheck(io, name) : null;
|
|
12213
|
+
if (signIn)
|
|
12214
|
+
checks.push(signIn);
|
|
12215
|
+
const selected = profiles.filter((profile) => (profile.harness === "deepseek" ? "opencode" : profile.harness) === name);
|
|
12216
|
+
if (selected.length) {
|
|
12217
|
+
availableModels[name] = name === "opencode" ? await openCodeModels(io) : name === "claude" ? await claudeModels(io) : signIn?.level === "error" ? null : await io.codexModels?.(io.cwd).catch(() => null) ?? null;
|
|
12218
|
+
checks.push(...selected.map((profile) => modelCheck(profile, availableModels[name] ?? null)));
|
|
12113
12219
|
}
|
|
12114
12220
|
}
|
|
12115
12221
|
}
|
|
@@ -12514,7 +12620,18 @@ async function localRuntimeChecks(io, config, options = { readOnly: true }) {
|
|
|
12514
12620
|
return [];
|
|
12515
12621
|
const result = await offerLocalInstalls(io, await detectLocalTools(io, harnesses, config ? localModelProfiles(config) : []), options);
|
|
12516
12622
|
const selected = await offerLocalModels(io, result, options.configPath ?? join4(io.cwd, CONFIG_FILE), options);
|
|
12517
|
-
return [
|
|
12623
|
+
return [
|
|
12624
|
+
...selected.checks,
|
|
12625
|
+
...harnesses.some((harness) => harness === "opencode" || harness === "deepseek") ? [
|
|
12626
|
+
{
|
|
12627
|
+
id: "local-opencode-effort",
|
|
12628
|
+
level: "warning",
|
|
12629
|
+
message: "effort is not applied for OpenCode (including DeepSeek); the interactive UI uses its default variant",
|
|
12630
|
+
fix: null
|
|
12631
|
+
}
|
|
12632
|
+
] : [],
|
|
12633
|
+
...harnesses.includes("deepseek") ? [await dshInformation(io)] : []
|
|
12634
|
+
];
|
|
12518
12635
|
}
|
|
12519
12636
|
async function buildDoctor(io, armadaVersion, options = { readOnly: true }) {
|
|
12520
12637
|
const root = (io.exec ? await gitRoot(io.exec, io.cwd) : null) ?? io.cwd;
|
|
@@ -14481,6 +14598,109 @@ ${next ? `Next: ${next}
|
|
|
14481
14598
|
}
|
|
14482
14599
|
}
|
|
14483
14600
|
|
|
14601
|
+
// src/codex-models.ts
|
|
14602
|
+
import { spawn } from "node:child_process";
|
|
14603
|
+
var system = {
|
|
14604
|
+
start: (cwd) => spawn("codex", ["app-server"], { cwd, stdio: ["pipe", "pipe", "ignore"] }),
|
|
14605
|
+
deadline: (expire) => {
|
|
14606
|
+
const timer = setTimeout(expire, 1e4);
|
|
14607
|
+
return () => clearTimeout(timer);
|
|
14608
|
+
}
|
|
14609
|
+
};
|
|
14610
|
+
function readCodexModels(cwd, io = system) {
|
|
14611
|
+
return new Promise((resolve) => {
|
|
14612
|
+
let child;
|
|
14613
|
+
try {
|
|
14614
|
+
child = io.start(cwd);
|
|
14615
|
+
} catch {
|
|
14616
|
+
resolve(null);
|
|
14617
|
+
return;
|
|
14618
|
+
}
|
|
14619
|
+
let settled = false;
|
|
14620
|
+
let cancel = () => {};
|
|
14621
|
+
const finish = (models) => {
|
|
14622
|
+
if (settled)
|
|
14623
|
+
return;
|
|
14624
|
+
settled = true;
|
|
14625
|
+
cancel();
|
|
14626
|
+
child.stdin.destroy();
|
|
14627
|
+
child.kill("SIGKILL");
|
|
14628
|
+
resolve(models);
|
|
14629
|
+
};
|
|
14630
|
+
cancel = io.deadline(() => finish(null));
|
|
14631
|
+
let buffer = "";
|
|
14632
|
+
let bytes = 0;
|
|
14633
|
+
let requestId = 0;
|
|
14634
|
+
const models = new Set;
|
|
14635
|
+
const cursors = new Set;
|
|
14636
|
+
const send = (message) => {
|
|
14637
|
+
if (!settled)
|
|
14638
|
+
child.stdin.write(`${JSON.stringify(message)}
|
|
14639
|
+
`);
|
|
14640
|
+
};
|
|
14641
|
+
const list = (cursor) => {
|
|
14642
|
+
requestId++;
|
|
14643
|
+
send({ id: requestId, method: "model/list", params: { limit: 100, includeHidden: true, cursor } });
|
|
14644
|
+
};
|
|
14645
|
+
child.on("error", () => finish(null));
|
|
14646
|
+
child.on("close", () => finish(null));
|
|
14647
|
+
child.stdin.on("error", () => finish(null));
|
|
14648
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => {
|
|
14649
|
+
if (settled)
|
|
14650
|
+
return;
|
|
14651
|
+
bytes += Buffer.byteLength(chunk);
|
|
14652
|
+
if (bytes > 1048576)
|
|
14653
|
+
return finish(null);
|
|
14654
|
+
buffer += chunk;
|
|
14655
|
+
while (!settled) {
|
|
14656
|
+
const newline = buffer.indexOf(`
|
|
14657
|
+
`);
|
|
14658
|
+
if (newline === -1)
|
|
14659
|
+
break;
|
|
14660
|
+
const line = buffer.slice(0, newline);
|
|
14661
|
+
buffer = buffer.slice(newline + 1);
|
|
14662
|
+
if (!line.trim())
|
|
14663
|
+
continue;
|
|
14664
|
+
try {
|
|
14665
|
+
const message = JSON.parse(line);
|
|
14666
|
+
if (!message || typeof message !== "object")
|
|
14667
|
+
return finish(null);
|
|
14668
|
+
if (message.id !== requestId)
|
|
14669
|
+
continue;
|
|
14670
|
+
if (message.error || !message.result || typeof message.result !== "object")
|
|
14671
|
+
return finish(null);
|
|
14672
|
+
if (requestId === 0) {
|
|
14673
|
+
send({ method: "initialized", params: {} });
|
|
14674
|
+
list(null);
|
|
14675
|
+
continue;
|
|
14676
|
+
}
|
|
14677
|
+
const { data, nextCursor } = message.result;
|
|
14678
|
+
if (!Array.isArray(data) || nextCursor != null && typeof nextCursor !== "string")
|
|
14679
|
+
return finish(null);
|
|
14680
|
+
for (const entry of data) {
|
|
14681
|
+
if (!entry || typeof entry.model !== "string" || !entry.model.trim() || entry.model.length > 4096 || /\p{Cc}/u.test(entry.model))
|
|
14682
|
+
return finish(null);
|
|
14683
|
+
models.add(entry.model);
|
|
14684
|
+
}
|
|
14685
|
+
if (nextCursor == null)
|
|
14686
|
+
return finish([...models]);
|
|
14687
|
+
if (!nextCursor || cursors.has(nextCursor) || cursors.size >= 100)
|
|
14688
|
+
return finish(null);
|
|
14689
|
+
cursors.add(nextCursor);
|
|
14690
|
+
list(nextCursor);
|
|
14691
|
+
} catch {
|
|
14692
|
+
return finish(null);
|
|
14693
|
+
}
|
|
14694
|
+
}
|
|
14695
|
+
});
|
|
14696
|
+
send({
|
|
14697
|
+
id: 0,
|
|
14698
|
+
method: "initialize",
|
|
14699
|
+
params: { clientInfo: { name: "armada_doctor", version: "1" }, capabilities: { explicitGatewayOAuth: true } }
|
|
14700
|
+
});
|
|
14701
|
+
});
|
|
14702
|
+
}
|
|
14703
|
+
|
|
14484
14704
|
// src/line.ts
|
|
14485
14705
|
var emptyLine = () => ({ answer: "", sequence: "none" });
|
|
14486
14706
|
function feedLine(line, chunk) {
|
|
@@ -14560,11 +14780,11 @@ async function inspectProcess(exec, pid, system = {
|
|
|
14560
14780
|
}
|
|
14561
14781
|
|
|
14562
14782
|
// src/spawn.ts
|
|
14563
|
-
import { spawn } from "node:child_process";
|
|
14783
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
14564
14784
|
import { constants } from "node:os";
|
|
14565
14785
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
14566
14786
|
var spawnInherited = (command, args, { cwd, env }) => new Promise((done, fail) => {
|
|
14567
|
-
const child =
|
|
14787
|
+
const child = spawn2(command, args, { cwd, env, stdio: "inherit" });
|
|
14568
14788
|
const fromTerminal = process.stdin.isTTY === true;
|
|
14569
14789
|
const handlers = SIGNALS.map((signal) => {
|
|
14570
14790
|
const handler = () => {
|
|
@@ -14590,7 +14810,7 @@ var spawnInherited = (command, args, { cwd, env }) => new Promise((done, fail) =
|
|
|
14590
14810
|
var startBackground = (args) => new Promise((resolve) => {
|
|
14591
14811
|
if (process.platform === "win32")
|
|
14592
14812
|
return resolve(false);
|
|
14593
|
-
const child =
|
|
14813
|
+
const child = spawn2(process.execPath, [...process.execArgv, process.argv[1], ...args], {
|
|
14594
14814
|
cwd: process.cwd(),
|
|
14595
14815
|
env: process.env,
|
|
14596
14816
|
detached: true,
|
|
@@ -14672,7 +14892,7 @@ function openUrl(url) {
|
|
|
14672
14892
|
return false;
|
|
14673
14893
|
const [command, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : ["xdg-open", [url]];
|
|
14674
14894
|
try {
|
|
14675
|
-
const child =
|
|
14895
|
+
const child = spawn3(command, args, { stdio: "ignore", detached: true });
|
|
14676
14896
|
child.on("error", () => {});
|
|
14677
14897
|
child.unref();
|
|
14678
14898
|
return true;
|
|
@@ -14680,16 +14900,29 @@ function openUrl(url) {
|
|
|
14680
14900
|
return false;
|
|
14681
14901
|
}
|
|
14682
14902
|
}
|
|
14683
|
-
var exec = (command, args, { cwd, timeoutMs }) => new Promise((done, fail) => {
|
|
14684
|
-
const child =
|
|
14903
|
+
var exec = (command, args, { cwd, timeoutMs, maxOutputBytes }) => new Promise((done, fail) => {
|
|
14904
|
+
const child = spawn3(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
14685
14905
|
const timer = timeoutMs ? setTimeout(() => child.kill("SIGKILL"), timeoutMs) : null;
|
|
14686
14906
|
let stdout = "";
|
|
14687
14907
|
let stderr = "";
|
|
14908
|
+
let bytes = 0;
|
|
14909
|
+
let oversized = false;
|
|
14910
|
+
const accept = (text) => {
|
|
14911
|
+
bytes += Buffer.byteLength(text);
|
|
14912
|
+
if (maxOutputBytes !== undefined && bytes > maxOutputBytes) {
|
|
14913
|
+
oversized = true;
|
|
14914
|
+
stdout = stderr = "";
|
|
14915
|
+
child.kill("SIGKILL");
|
|
14916
|
+
}
|
|
14917
|
+
return !oversized;
|
|
14918
|
+
};
|
|
14688
14919
|
child.stdout.setEncoding("utf8").on("data", (d) => {
|
|
14689
|
-
|
|
14920
|
+
if (accept(d))
|
|
14921
|
+
stdout += d;
|
|
14690
14922
|
});
|
|
14691
14923
|
child.stderr.setEncoding("utf8").on("data", (d) => {
|
|
14692
|
-
|
|
14924
|
+
if (accept(d))
|
|
14925
|
+
stderr += d;
|
|
14693
14926
|
});
|
|
14694
14927
|
child.on("error", (err) => {
|
|
14695
14928
|
if (timer)
|
|
@@ -14699,7 +14932,7 @@ var exec = (command, args, { cwd, timeoutMs }) => new Promise((done, fail) => {
|
|
|
14699
14932
|
child.on("close", (code) => {
|
|
14700
14933
|
if (timer)
|
|
14701
14934
|
clearTimeout(timer);
|
|
14702
|
-
done({ code: code ?? 1, stdout, stderr });
|
|
14935
|
+
done({ code: oversized ? 1 : code ?? 1, stdout, stderr });
|
|
14703
14936
|
});
|
|
14704
14937
|
});
|
|
14705
14938
|
var stopped = false;
|
|
@@ -14709,6 +14942,7 @@ if (process.argv.includes("heartbeat") && !process.argv.includes("--background")
|
|
|
14709
14942
|
stopped = true;
|
|
14710
14943
|
});
|
|
14711
14944
|
var code = await run(process.argv.slice(2), {
|
|
14945
|
+
codexModels: readCodexModels,
|
|
14712
14946
|
platform: process.platform,
|
|
14713
14947
|
machineName: hostname2(),
|
|
14714
14948
|
ttyName: process.stdin.isTTY ? spawnSync("tty", [], { encoding: "utf8", stdio: ["inherit", "pipe", "ignore"] }).stdout?.trim() || null : null,
|
|
@@ -14773,7 +15007,7 @@ var code = await run(process.argv.slice(2), {
|
|
|
14773
15007
|
readStdin,
|
|
14774
15008
|
exec,
|
|
14775
15009
|
detach: (command, args, { cwd, env }) => new Promise((resolve) => {
|
|
14776
|
-
const child =
|
|
15010
|
+
const child = spawn3(command, args, { cwd, env, stdio: "ignore", detached: true });
|
|
14777
15011
|
child.once("error", () => resolve(false));
|
|
14778
15012
|
child.once("spawn", () => {
|
|
14779
15013
|
child.unref();
|