@the-vibe-company/armada 0.2.35 → 0.2.37
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 +809 -146
- package/package.json +1 -1
package/dist/armada.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { spawn as spawn2, spawnSync } from "node:child_process";
|
|
5
5
|
import { createReadStream } from "node:fs";
|
|
6
|
-
import { open as open2, readFile as readFile4 } from "node:fs/promises";
|
|
6
|
+
import { open as open2, readFile as readFile4, writeFile as writeFile3 } from "node:fs/promises";
|
|
7
7
|
import { hostname as hostname2 } from "node:os";
|
|
8
8
|
import { isatty } from "node:tty";
|
|
9
9
|
|
|
10
10
|
// src/cli.ts
|
|
11
|
-
import { dirname as
|
|
11
|
+
import { dirname as dirname8, join as join8, resolve as resolve3 } from "node:path";
|
|
12
12
|
|
|
13
13
|
// ../core/src/types.ts
|
|
14
14
|
var LABEL_PHASES = [
|
|
@@ -998,41 +998,6 @@ function waitingPullRequests(m, prs) {
|
|
|
998
998
|
return prs.filter((p) => p.state === "open").map((pr) => ({ pr, ticket: ticketOf.get(pr.url) ?? null })).sort((a, b) => a.pr.number - b.pr.number);
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
-
// ../core/src/npm.ts
|
|
1002
|
-
var ARMADA_PACKAGE = CLI_PACKAGE;
|
|
1003
|
-
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${ARMADA_PACKAGE.replace("/", "%2f")}`;
|
|
1004
|
-
var NPM_CHECK_MS = 3000;
|
|
1005
|
-
async function checkPublished(version, fetch2, timeoutMs = NPM_CHECK_MS) {
|
|
1006
|
-
try {
|
|
1007
|
-
const signal = AbortSignal.timeout(timeoutMs);
|
|
1008
|
-
const res = await fetch2(NPM_REGISTRY_URL, {
|
|
1009
|
-
headers: { accept: "application/vnd.npm.install-v1+json" },
|
|
1010
|
-
cache: "no-store",
|
|
1011
|
-
signal
|
|
1012
|
-
});
|
|
1013
|
-
if (!res.ok)
|
|
1014
|
-
return { state: "unknown", reason: `npm answered HTTP ${res.status}` };
|
|
1015
|
-
const body = await res.json();
|
|
1016
|
-
const versions = body?.versions;
|
|
1017
|
-
if (!versions || typeof versions !== "object" || Array.isArray(versions) || !Object.keys(versions).length)
|
|
1018
|
-
return { state: "unknown", reason: "npm listed no version" };
|
|
1019
|
-
const candidates = Object.keys(versions).filter((candidate) => /^\d+\.\d+\.\d+$/.test(candidate) && compareVersions(candidate, version) <= 0).sort((first, second) => compareVersions(second, first));
|
|
1020
|
-
for (const candidate of candidates) {
|
|
1021
|
-
const tarball = versions[candidate]?.dist?.tarball;
|
|
1022
|
-
if (typeof tarball !== "string" || !tarball)
|
|
1023
|
-
continue;
|
|
1024
|
-
const download = await fetch2(tarball, { method: "HEAD", cache: "no-store", signal });
|
|
1025
|
-
if (download.status === 200)
|
|
1026
|
-
return candidate === version ? { state: "published" } : { state: "missing", newest: candidate };
|
|
1027
|
-
if (download.status !== 404)
|
|
1028
|
-
return { state: "unknown", reason: `npm tarball answered HTTP ${download.status}` };
|
|
1029
|
-
}
|
|
1030
|
-
return { state: "missing", newest: null };
|
|
1031
|
-
} catch (err) {
|
|
1032
|
-
return { state: "unknown", reason: networkReason(err, timeoutMs) };
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
1001
|
// ../../node_modules/.bun/smol-toml@1.9.0/node_modules/smol-toml/dist/error.js
|
|
1037
1002
|
/*!
|
|
1038
1003
|
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
@@ -2001,17 +1966,130 @@ var HAS_WELLFORMED = !!"".isWellFormed;
|
|
|
2001
1966
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
2002
1967
|
*/
|
|
2003
1968
|
|
|
1969
|
+
// ../core/src/herdr-profile.ts
|
|
1970
|
+
var herdrHarnessKind = (harness) => harness === "deepseek" ? "opencode" : harness;
|
|
1971
|
+
var herdrHarnessLabel = (harness) => harness === "deepseek" ? "deepseek (OpenCode + DeepSeek model)" : harness;
|
|
1972
|
+
function herdrChoice(choice) {
|
|
1973
|
+
return {
|
|
1974
|
+
...choice,
|
|
1975
|
+
profile: {
|
|
1976
|
+
runtime: "herdr",
|
|
1977
|
+
agent: herdrHarnessLabel(choice.profile.harness),
|
|
1978
|
+
model: choice.profile.model,
|
|
1979
|
+
effort: choice.profile.effort,
|
|
1980
|
+
fastMode: false
|
|
1981
|
+
}
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
var herdrClaimHandle = (handle) => JSON.stringify({ workspace: handle.workspace, pane: handle.pane, agent: handle.agent });
|
|
1985
|
+
function isDeepseekModel(model) {
|
|
1986
|
+
const [provider, ...parts] = model.split("/");
|
|
1987
|
+
return !!parts.length && (provider === "deepseek" || /(?:^|[/-])deepseek(?:$|[/-])/i.test(parts.join("/")));
|
|
1988
|
+
}
|
|
1989
|
+
function setHerdrModel(text, name, model) {
|
|
1990
|
+
const raw = parse(text);
|
|
1991
|
+
const profiles = raw.herdr?.profiles;
|
|
1992
|
+
if (!profiles?.[name])
|
|
1993
|
+
throw new Error("profile is no longer present");
|
|
1994
|
+
const lines = text.split(/(?<=\n)/);
|
|
1995
|
+
let section = -1;
|
|
1996
|
+
let end = lines.length;
|
|
1997
|
+
for (let i = 0;i < lines.length; i++) {
|
|
1998
|
+
const header = lines[i]?.match(/^\s*\[herdr\s*\.\s*profiles\s*\.\s*(.+?)\]\s*(?:#.*)?(?:\r?\n)?$/);
|
|
1999
|
+
if (header) {
|
|
2000
|
+
const key = header[1]?.trim();
|
|
2001
|
+
if (key && Object.hasOwn(parse(`[${key}]
|
|
2002
|
+
`), name)) {
|
|
2003
|
+
section = i;
|
|
2004
|
+
break;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
if (section < 0)
|
|
2009
|
+
throw new Error("use an explicit [herdr.profiles.<name>] section to save the model");
|
|
2010
|
+
for (let i = section + 1;i < lines.length; i++) {
|
|
2011
|
+
if (/^\s*\[/.test(lines[i] ?? "")) {
|
|
2012
|
+
end = i;
|
|
2013
|
+
break;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
let replaced = false;
|
|
2017
|
+
for (let i = section + 1;i < end; i++) {
|
|
2018
|
+
const match = lines[i]?.match(/^(\s*(?:model|"model"|'model')\s*=\s*)("(?:[^"\\]|\\.)*"|'[^']*')(.*?)(\r?\n)?$/);
|
|
2019
|
+
if (match) {
|
|
2020
|
+
const value = match[2]?.startsWith("'") && !model.includes("'") ? `'${model}'` : JSON.stringify(model);
|
|
2021
|
+
lines[i] = `${match[1]}${value}${match[3]}${match[4] ?? ""}`;
|
|
2022
|
+
replaced = true;
|
|
2023
|
+
break;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
if (!replaced) {
|
|
2027
|
+
const newline = text.includes(`\r
|
|
2028
|
+
`) ? `\r
|
|
2029
|
+
` : `
|
|
2030
|
+
`;
|
|
2031
|
+
if (!(lines[section] ?? "").endsWith(`
|
|
2032
|
+
`))
|
|
2033
|
+
lines[section] += newline;
|
|
2034
|
+
lines.splice(section + 1, 0, `model = ${JSON.stringify(model)}${newline}`);
|
|
2035
|
+
}
|
|
2036
|
+
const next = lines.join("");
|
|
2037
|
+
profiles[name].model = model;
|
|
2038
|
+
if (JSON.stringify(parse(next)) !== JSON.stringify(raw)) {
|
|
2039
|
+
const canonical = (value) => JSON.stringify(value, (_, v) => typeof v === "object" && v !== null && !Array.isArray(v) ? Object.fromEntries(Object.keys(v).sort().map((key) => [key, v[key]])) : v);
|
|
2040
|
+
if (canonical(parse(next)) !== canonical(raw))
|
|
2041
|
+
throw new Error("could not safely edit the profile model");
|
|
2042
|
+
}
|
|
2043
|
+
return next;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
// ../core/src/npm.ts
|
|
2047
|
+
var ARMADA_PACKAGE = CLI_PACKAGE;
|
|
2048
|
+
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${ARMADA_PACKAGE.replace("/", "%2f")}`;
|
|
2049
|
+
var NPM_CHECK_MS = 3000;
|
|
2050
|
+
async function checkPublished(version, fetch2, timeoutMs = NPM_CHECK_MS) {
|
|
2051
|
+
try {
|
|
2052
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
2053
|
+
const res = await fetch2(NPM_REGISTRY_URL, {
|
|
2054
|
+
headers: { accept: "application/vnd.npm.install-v1+json" },
|
|
2055
|
+
cache: "no-store",
|
|
2056
|
+
signal
|
|
2057
|
+
});
|
|
2058
|
+
if (!res.ok)
|
|
2059
|
+
return { state: "unknown", reason: `npm answered HTTP ${res.status}` };
|
|
2060
|
+
const body = await res.json();
|
|
2061
|
+
const versions = body?.versions;
|
|
2062
|
+
if (!versions || typeof versions !== "object" || Array.isArray(versions) || !Object.keys(versions).length)
|
|
2063
|
+
return { state: "unknown", reason: "npm listed no version" };
|
|
2064
|
+
const candidates = Object.keys(versions).filter((candidate) => /^\d+\.\d+\.\d+$/.test(candidate) && compareVersions(candidate, version) <= 0).sort((first, second) => compareVersions(second, first));
|
|
2065
|
+
for (const candidate of candidates) {
|
|
2066
|
+
const tarball = versions[candidate]?.dist?.tarball;
|
|
2067
|
+
if (typeof tarball !== "string" || !tarball)
|
|
2068
|
+
continue;
|
|
2069
|
+
const download = await fetch2(tarball, { method: "HEAD", cache: "no-store", signal });
|
|
2070
|
+
if (download.status === 200)
|
|
2071
|
+
return candidate === version ? { state: "published" } : { state: "missing", newest: candidate };
|
|
2072
|
+
if (download.status !== 404)
|
|
2073
|
+
return { state: "unknown", reason: `npm tarball answered HTTP ${download.status}` };
|
|
2074
|
+
}
|
|
2075
|
+
return { state: "missing", newest: null };
|
|
2076
|
+
} catch (err) {
|
|
2077
|
+
return { state: "unknown", reason: networkReason(err, timeoutMs) };
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2004
2081
|
// ../core/src/config.ts
|
|
2005
2082
|
var CONFIG_FILE = "armada.toml";
|
|
2006
2083
|
var PLAN_POLICIES = ["approve", "pre-approved"];
|
|
2007
2084
|
var routingLabelKey = (name) => name.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{M}\p{N}]/gu, "");
|
|
2008
2085
|
var PROFILE_RUNTIMES = ["conductor", "claude-code"];
|
|
2086
|
+
var HERDR_HARNESSES = ["claude", "codex", "opencode", "deepseek"];
|
|
2009
2087
|
var CONFIG_DEFAULTS = {
|
|
2010
2088
|
language: "en",
|
|
2011
2089
|
readyLabel: "ready-for-agent",
|
|
2012
2090
|
phaseGroup: "Agent phase",
|
|
2013
2091
|
runtimeGroup: "Agent runtime",
|
|
2014
|
-
runtimes: ["Claude Code", "Codex", "Conductor"],
|
|
2092
|
+
runtimes: ["Claude Code", "Codex", "Conductor", "Herdr"],
|
|
2015
2093
|
silentAfterMinutes: 15,
|
|
2016
2094
|
quietAfterMinutes: 45,
|
|
2017
2095
|
coordinatorMinutes: 10,
|
|
@@ -2120,6 +2198,14 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2120
2198
|
if (!isTable(profilesRaw))
|
|
2121
2199
|
problems.push(`"conductor.profiles" must be a table of profiles`);
|
|
2122
2200
|
const profilesT = isTable(profilesRaw) ? profilesRaw : {};
|
|
2201
|
+
const herdr = raw.herdr === undefined ? {} : raw.herdr;
|
|
2202
|
+
if (!isTable(herdr))
|
|
2203
|
+
problems.push(`"herdr" must be a table`);
|
|
2204
|
+
const herdrT = isTable(herdr) ? herdr : {};
|
|
2205
|
+
const herdrProfilesRaw = herdrT.profiles === undefined ? {} : herdrT.profiles;
|
|
2206
|
+
if (!isTable(herdrProfilesRaw))
|
|
2207
|
+
problems.push(`"herdr.profiles" must be a table of profiles`);
|
|
2208
|
+
const herdrProfilesT = isTable(herdrProfilesRaw) ? herdrProfilesRaw : {};
|
|
2123
2209
|
const known = [
|
|
2124
2210
|
["project", project, ["name", "slug"]],
|
|
2125
2211
|
["tracker", tracker, ["program_root", "language", "ready_label", "labels"]],
|
|
@@ -2147,7 +2233,8 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2147
2233
|
],
|
|
2148
2234
|
["brief", briefT, ["extra"]],
|
|
2149
2235
|
["secrets", secretsT, ["names"]],
|
|
2150
|
-
["conductor", conductorT, ["default_profile", "profiles", "routing"]]
|
|
2236
|
+
["conductor", conductorT, ["default_profile", "profiles", "routing"]],
|
|
2237
|
+
["herdr", herdrT, ["default_profile", "profiles", "routing"]]
|
|
2151
2238
|
];
|
|
2152
2239
|
const profiles = {};
|
|
2153
2240
|
for (const [name, p] of Object.entries(profilesT)) {
|
|
@@ -2207,6 +2294,73 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2207
2294
|
}
|
|
2208
2295
|
if (Array.isArray(routingRaw) && routingRaw.length && conductorT.default_profile === undefined && !Object.values(profiles).some((profile) => profile.when))
|
|
2209
2296
|
problems.push(`"conductor.default_profile" is required with [[conductor.routing]], for tickets no rule matches`);
|
|
2297
|
+
const herdrProfiles = {};
|
|
2298
|
+
for (const [name, p] of Object.entries(herdrProfilesT)) {
|
|
2299
|
+
const path = `herdr.profiles.${name}`;
|
|
2300
|
+
if (!isTable(p)) {
|
|
2301
|
+
problems.push(`"${path}" must be a table`);
|
|
2302
|
+
continue;
|
|
2303
|
+
}
|
|
2304
|
+
if (name === "__proto__") {
|
|
2305
|
+
problems.push(`"${path}" is not a usable profile name`);
|
|
2306
|
+
continue;
|
|
2307
|
+
}
|
|
2308
|
+
known.push([path, p, ["harness", "model", "effort", "extra_args", "when"]]);
|
|
2309
|
+
let harness = "claude";
|
|
2310
|
+
if (p.harness === undefined)
|
|
2311
|
+
problems.push(`missing required key "${path}.harness"`);
|
|
2312
|
+
else if (HERDR_HARNESSES.includes(p.harness))
|
|
2313
|
+
harness = p.harness;
|
|
2314
|
+
else
|
|
2315
|
+
problems.push(`"${path}.harness" must be one of ${HERDR_HARNESSES.map((h) => `"${h}"`).join(", ")}`);
|
|
2316
|
+
let extraArgs = [];
|
|
2317
|
+
if (p.extra_args !== undefined) {
|
|
2318
|
+
if (Array.isArray(p.extra_args) && p.extra_args.every((arg) => typeof arg === "string" && arg.trim()))
|
|
2319
|
+
extraArgs = [...p.extra_args];
|
|
2320
|
+
else
|
|
2321
|
+
problems.push(`"${path}.extra_args" must be a list of non-empty argument strings`);
|
|
2322
|
+
}
|
|
2323
|
+
if (harness === "deepseek" && extraArgs.some((arg) => /^(?:--model(?:=|$)|-m)/.test(arg.trim())))
|
|
2324
|
+
problems.push(`"${path}.extra_args" must not override the DeepSeek model; use "${path}.model"`);
|
|
2325
|
+
const model = (harness === "opencode" || harness === "deepseek") && (p.model === undefined || typeof p.model === "string" && !p.model.trim()) ? "" : str(p, path, "model");
|
|
2326
|
+
herdrProfiles[name] = {
|
|
2327
|
+
...p.when !== undefined ? { when: str(p, path, "when") } : {},
|
|
2328
|
+
harness,
|
|
2329
|
+
model,
|
|
2330
|
+
effort: str(p, path, "effort"),
|
|
2331
|
+
extraArgs
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
let herdrDefaultProfile = null;
|
|
2335
|
+
if (herdrT.default_profile !== undefined) {
|
|
2336
|
+
herdrDefaultProfile = str(herdrT, "herdr", "default_profile") || null;
|
|
2337
|
+
if (herdrDefaultProfile && !Object.hasOwn(herdrProfiles, herdrDefaultProfile))
|
|
2338
|
+
problems.push(`"herdr.default_profile" is "${herdrDefaultProfile}", but there is no [herdr.profiles.${herdrDefaultProfile}]`);
|
|
2339
|
+
}
|
|
2340
|
+
const herdrRouting = [];
|
|
2341
|
+
const herdrRoutingRaw = herdrT.routing ?? [];
|
|
2342
|
+
if (!Array.isArray(herdrRoutingRaw))
|
|
2343
|
+
problems.push(`"herdr.routing" must be a list of [[herdr.routing]] rules`);
|
|
2344
|
+
else
|
|
2345
|
+
for (const [i, r] of herdrRoutingRaw.entries()) {
|
|
2346
|
+
const path = `herdr.routing[${i + 1}]`;
|
|
2347
|
+
if (!isTable(r)) {
|
|
2348
|
+
problems.push(`"${path}" must be a table`);
|
|
2349
|
+
continue;
|
|
2350
|
+
}
|
|
2351
|
+
known.push([path, r, ["labels", "profile"]]);
|
|
2352
|
+
const labels = r.labels;
|
|
2353
|
+
const ok = Array.isArray(labels) && labels.length && labels.every((l) => typeof l === "string" && routingLabelKey(l));
|
|
2354
|
+
if (!ok)
|
|
2355
|
+
problems.push(`"${path}.labels" must be a non-empty list of Linear label names, each with a letter or digit`);
|
|
2356
|
+
const profile = str(r, path, "profile");
|
|
2357
|
+
if (profile && !Object.hasOwn(herdrProfiles, profile))
|
|
2358
|
+
problems.push(`"${path}.profile" is "${profile}", but there is no [herdr.profiles.${profile}]`);
|
|
2359
|
+
if (ok && profile)
|
|
2360
|
+
herdrRouting.push({ labels: labels.map((l) => l.trim()), profile });
|
|
2361
|
+
}
|
|
2362
|
+
if (Array.isArray(herdrRoutingRaw) && herdrRoutingRaw.length && herdrT.default_profile === undefined && !Object.values(herdrProfiles).some((profile) => profile.when))
|
|
2363
|
+
problems.push(`"herdr.default_profile" is required with [[herdr.routing]], for tickets no rule matches`);
|
|
2210
2364
|
for (const [path, t, keys] of known)
|
|
2211
2365
|
for (const key of Object.keys(t))
|
|
2212
2366
|
if (!keys.includes(key))
|
|
@@ -2368,7 +2522,8 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2368
2522
|
},
|
|
2369
2523
|
brief: { extra },
|
|
2370
2524
|
secrets: { names: secretNames },
|
|
2371
|
-
conductor: { defaultProfile, profiles, routing }
|
|
2525
|
+
conductor: { defaultProfile, profiles, routing },
|
|
2526
|
+
herdr: { defaultProfile: herdrDefaultProfile, profiles: herdrProfiles, routing: herdrRouting }
|
|
2372
2527
|
};
|
|
2373
2528
|
if (problems.length)
|
|
2374
2529
|
throw new ConfigError(source, problems);
|
|
@@ -2392,7 +2547,7 @@ ready_label = "ready-for-agent"
|
|
|
2392
2547
|
[tracker.labels]
|
|
2393
2548
|
phase_group = "Agent phase"
|
|
2394
2549
|
runtime_group = "Agent runtime"
|
|
2395
|
-
runtimes = ["Claude Code", "Codex", "Conductor"]
|
|
2550
|
+
runtimes = ["Claude Code", "Codex", "Conductor", "Herdr"]
|
|
2396
2551
|
|
|
2397
2552
|
[github]
|
|
2398
2553
|
repository = ${q(p.repository)}
|
|
@@ -2469,6 +2624,23 @@ profile = "codex"
|
|
|
2469
2624
|
[[conductor.routing]]
|
|
2470
2625
|
labels = ["Bug"]
|
|
2471
2626
|
profile = "debug"
|
|
2627
|
+
|
|
2628
|
+
# Herdr profiles use one of its supported harnesses and are selected with the
|
|
2629
|
+
# same label and \`when\` rules as Conductor. Every extra argument is passed to
|
|
2630
|
+
# the selected harness exactly as written.
|
|
2631
|
+
# [herdr]
|
|
2632
|
+
# default_profile = "claude"
|
|
2633
|
+
|
|
2634
|
+
# [herdr.profiles.claude]
|
|
2635
|
+
# harness = "claude" # "claude", "codex", "opencode" or "deepseek" (OpenCode + DeepSeek model)
|
|
2636
|
+
# model = "sonnet"
|
|
2637
|
+
# effort = "high"
|
|
2638
|
+
# extra_args = ["--verbose"]
|
|
2639
|
+
# when = "a ticket best handled by Claude"
|
|
2640
|
+
|
|
2641
|
+
# [[herdr.routing]]
|
|
2642
|
+
# labels = ["herdr"]
|
|
2643
|
+
# profile = "claude"
|
|
2472
2644
|
`;
|
|
2473
2645
|
}
|
|
2474
2646
|
function slugify(name) {
|
|
@@ -2562,44 +2734,49 @@ var checkProblems = (checks, requiredChecks) => checkIssues(checks, requiredChec
|
|
|
2562
2734
|
class ProfileError extends Error {
|
|
2563
2735
|
name = "ProfileError";
|
|
2564
2736
|
}
|
|
2565
|
-
var
|
|
2566
|
-
var
|
|
2567
|
-
|
|
2568
|
-
|
|
2737
|
+
var profileSection = (config, runtime) => runtime === "herdr" ? config.herdr : config.conductor;
|
|
2738
|
+
var runtimeName = (runtime) => runtime === "herdr" ? "Herdr" : "Conductor";
|
|
2739
|
+
var hasProfileRules = (config, runtime = "conductor") => Object.values(profileSection(config, runtime).profiles).some((profile) => !!profile.when);
|
|
2740
|
+
var profileChoiceHint = (ticket, runtime = "conductor") => `Choose ${runtime === "herdr" ? "a Herdr profile" : "a profile"}: read the ticket and its parent, match the profiles' when rules, then run armada ${runtime === "herdr" ? "launch" : "brief"} ${ticket}${runtime === "herdr" ? " --runtime herdr" : ""} --profile <name> --reason "<why>"`;
|
|
2741
|
+
function routeProfile(config, labels, runtime = "conductor") {
|
|
2742
|
+
const { routing, defaultProfile, profiles } = profileSection(config, runtime);
|
|
2569
2743
|
for (const [i, rule] of routing.entries()) {
|
|
2570
2744
|
const keys = rule.labels.map(routingLabelKey);
|
|
2571
2745
|
const label = labels.find((l) => keys.includes(routingLabelKey(l)));
|
|
2572
2746
|
if (label !== undefined)
|
|
2573
2747
|
return { name: rule.profile, source: "rule", rule: { index: i + 1, labels: rule.labels, label } };
|
|
2574
2748
|
}
|
|
2575
|
-
if (hasProfileRules(config))
|
|
2749
|
+
if (hasProfileRules(config, runtime))
|
|
2576
2750
|
return null;
|
|
2577
2751
|
if (defaultProfile)
|
|
2578
2752
|
return { name: defaultProfile, source: "default", rule: null };
|
|
2579
2753
|
const names = Object.keys(profiles);
|
|
2580
2754
|
return names.length === 1 && names[0] ? { name: names[0], source: "only", rule: null } : null;
|
|
2581
2755
|
}
|
|
2582
|
-
function describeRoute(route, config) {
|
|
2756
|
+
function describeRoute(route, config, runtime = "conductor") {
|
|
2757
|
+
const section = profileSection(config, runtime);
|
|
2758
|
+
const sectionName = runtime === "herdr" ? "herdr" : "conductor";
|
|
2583
2759
|
if (route.rule)
|
|
2584
|
-
return `rule ${route.rule.index} of [[
|
|
2760
|
+
return `rule ${route.rule.index} of [[${sectionName}.routing]] (label "${route.rule.label}")`;
|
|
2585
2761
|
if (route.source === "default")
|
|
2586
|
-
return
|
|
2587
|
-
return "the only profile in armada.toml";
|
|
2762
|
+
return section.routing.length ? `${sectionName}.default_profile (no routing rule matched)` : `${sectionName}.default_profile`;
|
|
2763
|
+
return runtime === "herdr" ? "the only Herdr profile in armada.toml" : "the only profile in armada.toml";
|
|
2588
2764
|
}
|
|
2589
|
-
function checkRequestedProfile(config, requested) {
|
|
2590
|
-
|
|
2765
|
+
function checkRequestedProfile(config, requested, runtime = "conductor") {
|
|
2766
|
+
const { profiles } = profileSection(config, runtime);
|
|
2767
|
+
if (requested === null || Object.hasOwn(profiles, requested))
|
|
2591
2768
|
return;
|
|
2592
|
-
const names = Object.keys(
|
|
2593
|
-
throw new ProfileError(`no
|
|
2769
|
+
const names = Object.keys(profiles);
|
|
2770
|
+
throw new ProfileError(`no ${runtimeName(runtime)} profile "${requested}" (available: ${names.join(", ") || "none"})`);
|
|
2594
2771
|
}
|
|
2595
|
-
function chooseProfile(config, input) {
|
|
2596
|
-
checkRequestedProfile(config, input.requested);
|
|
2597
|
-
const { profiles } = config
|
|
2772
|
+
function chooseProfile(config, input, runtime = "conductor") {
|
|
2773
|
+
checkRequestedProfile(config, input.requested, runtime);
|
|
2774
|
+
const { profiles } = profileSection(config, runtime);
|
|
2598
2775
|
const reason = input.reason?.replace(/\s+/g, " ").trim() || null;
|
|
2599
|
-
const route = routeProfile(config, input.labels);
|
|
2600
|
-
const semantic = !route && hasProfileRules(config);
|
|
2776
|
+
const route = routeProfile(config, input.labels, runtime);
|
|
2777
|
+
const semantic = !route && hasProfileRules(config, runtime);
|
|
2601
2778
|
if (semantic && (input.requested === null || !reason))
|
|
2602
|
-
throw new ProfileError(profileChoiceHint(input.ticket));
|
|
2779
|
+
throw new ProfileError(profileChoiceHint(input.ticket, runtime));
|
|
2603
2780
|
if (input.requested === null) {
|
|
2604
2781
|
if (route && Object.hasOwn(profiles, route.name))
|
|
2605
2782
|
return {
|
|
@@ -2609,12 +2786,12 @@ function chooseProfile(config, input) {
|
|
|
2609
2786
|
rule: route.rule,
|
|
2610
2787
|
routed: route.name,
|
|
2611
2788
|
reason,
|
|
2612
|
-
why: describeRoute(route, config)
|
|
2789
|
+
why: describeRoute(route, config, runtime)
|
|
2613
2790
|
};
|
|
2614
2791
|
const names = Object.keys(profiles);
|
|
2615
2792
|
if (!names.length)
|
|
2616
2793
|
return null;
|
|
2617
|
-
throw new ProfileError(`several
|
|
2794
|
+
throw new ProfileError(`several ${runtimeName(runtime)} profiles and no ${runtime}.default_profile; pass --profile (${names.join(", ")})`);
|
|
2618
2795
|
}
|
|
2619
2796
|
const name = input.requested;
|
|
2620
2797
|
const profile = profiles[name];
|
|
@@ -2626,11 +2803,11 @@ function chooseProfile(config, input) {
|
|
|
2626
2803
|
rule: route.rule,
|
|
2627
2804
|
routed: name,
|
|
2628
2805
|
reason,
|
|
2629
|
-
why: describeRoute(route, config)
|
|
2806
|
+
why: describeRoute(route, config, runtime)
|
|
2630
2807
|
};
|
|
2631
|
-
if (route && !reason && config.
|
|
2632
|
-
throw new ProfileError(`${input.ticket} is routed to "${route.name}" by ${describeRoute(route, config)}; say why "${name}" instead with --reason "<why>"`);
|
|
2633
|
-
const why = semantic ? `Chosen by the coordinator: ${reason}` : `--profile${route ? `, instead of "${route.name}" from ${describeRoute(route, config)}` : ""}${reason ? `: ${reason}` : ""}`;
|
|
2808
|
+
if (route && !reason && profileSection(config, runtime).routing.length)
|
|
2809
|
+
throw new ProfileError(`${input.ticket} is routed to "${route.name}" by ${describeRoute(route, config, runtime)}; say why "${name}" instead with --reason "<why>"`);
|
|
2810
|
+
const why = semantic ? `Chosen by the coordinator: ${reason}` : `--profile${route ? `, instead of "${route.name}" from ${describeRoute(route, config, runtime)}` : ""}${reason ? `: ${reason}` : ""}`;
|
|
2634
2811
|
return { name, profile, source: "requested", rule: null, routed: route?.name ?? null, reason, why };
|
|
2635
2812
|
}
|
|
2636
2813
|
|
|
@@ -2869,12 +3046,15 @@ async function claimTicket(ctx, input) {
|
|
|
2869
3046
|
throw new Refusal(`${ticket.id} already carries the agent phase "${ticket.agentPhase}"`, another);
|
|
2870
3047
|
if (input.profile)
|
|
2871
3048
|
try {
|
|
2872
|
-
|
|
3049
|
+
const selection = {
|
|
2873
3050
|
ticket: ticket.id,
|
|
2874
3051
|
labels: ticket.labels.map((l) => l.name),
|
|
2875
3052
|
requested: input.profile,
|
|
2876
3053
|
reason: input.reason ?? null
|
|
2877
|
-
}
|
|
3054
|
+
};
|
|
3055
|
+
const local = input.runtime.toLowerCase() === "herdr";
|
|
3056
|
+
const choice = local ? chooseProfile(config, selection, "herdr") : null;
|
|
3057
|
+
profile = local ? choice ? herdrChoice(choice) : null : chooseProfile(config, selection);
|
|
2878
3058
|
} catch (err) {
|
|
2879
3059
|
if (err instanceof ProfileError)
|
|
2880
3060
|
throw new Refusal(err.message, `armada brief ${ticket.id}, which shows the profile the ticket routes to`);
|
|
@@ -2893,7 +3073,7 @@ ${validation}` : ""}`;
|
|
|
2893
3073
|
await linear.deleteComment(mine.id);
|
|
2894
3074
|
throw new Refusal(`${ticket.id} was claimed first by ${winner.claim?.runtime ?? "another worker"} · ${winner.claim?.session ?? "unknown session"}; your claim was withdrawn`, "armada status, to pick another ticket ready to start");
|
|
2895
3075
|
}
|
|
2896
|
-
lines.push(`Claimed ${ticket.id} for ${runtime.name} (${input.handle})${profile ? ` on profile ${profile.name}` : ""}.`);
|
|
3076
|
+
lines.push(`Claimed ${ticket.id} for ${runtime.name} (${input.handle})${profile ? ` on profile ${profile.name}${profile.profile.runtime === "herdr" ? ` (${profile.profile.agent})` : ""}` : ""}.`);
|
|
2897
3077
|
} else {
|
|
2898
3078
|
lines.push(`${ticket.id} is already claimed by this session (${input.handle}); labels and state repaired.`);
|
|
2899
3079
|
if (input.profile && (holder?.profile ?? null) !== input.profile)
|
|
@@ -3150,7 +3330,7 @@ function buildBrief(input) {
|
|
|
3150
3330
|
const warnings = [...new Set([...ticket.warnings, ...program.warnings])];
|
|
3151
3331
|
let choice;
|
|
3152
3332
|
try {
|
|
3153
|
-
choice = chooseProfile(config, {
|
|
3333
|
+
choice = input.herdr ? herdrChoice(input.herdr.choice) : chooseProfile(config, {
|
|
3154
3334
|
ticket: ticket.id,
|
|
3155
3335
|
labels: ticket.labels,
|
|
3156
3336
|
requested: input.profile,
|
|
@@ -3190,10 +3370,10 @@ function buildBrief(input) {
|
|
|
3190
3370
|
const pkg = `${ARMADA_PACKAGE}@${pinned}`;
|
|
3191
3371
|
const branch = ticket.branchName;
|
|
3192
3372
|
const runtime = choice?.profile.runtime ?? "conductor";
|
|
3193
|
-
const handle = runtime === "claude-code" ? subagentName(ticket.id) : CONDUCTOR_HANDLE;
|
|
3373
|
+
const handle = input.herdr ? shellWord(input.herdr.handle) : runtime === "claude-code" ? subagentName(ticket.id) : CONDUCTOR_HANDLE;
|
|
3194
3374
|
const claimCommand = [
|
|
3195
3375
|
`armada claim ${ticket.id} --runtime ${runtime} --handle ${handle}`,
|
|
3196
|
-
branch ? ` --branch ${branch}` : "",
|
|
3376
|
+
branch ? ` --branch ${shellWord(branch)}` : "",
|
|
3197
3377
|
choice ? ` --profile ${shellWord(choice.name)}` : "",
|
|
3198
3378
|
choice?.reason ? ` --reason ${shellWord(choice.reason)}` : "",
|
|
3199
3379
|
...input.validation?.rules.length ? [
|
|
@@ -3245,6 +3425,7 @@ function buildBrief(input) {
|
|
|
3245
3425
|
install: `npm install -g ${pkg}`,
|
|
3246
3426
|
fallback: `npm exec --yes --package=${pkg} -- armada`,
|
|
3247
3427
|
claimCommand,
|
|
3428
|
+
...input.herdr ? { handle: input.herdr.handle } : {},
|
|
3248
3429
|
launch: launch ? {
|
|
3249
3430
|
command: `armada login --launch-token ${shellWord(launch.token)}${launch.apiUrl ? ` --api-url ${shellWord(launch.apiUrl)}` : ""}`,
|
|
3250
3431
|
expiresAt: launch.expiresAt
|
|
@@ -3306,7 +3487,7 @@ function renderPrompt(b) {
|
|
|
3306
3487
|
b.install,
|
|
3307
3488
|
...b.launch ? [b.launch.command] : [],
|
|
3308
3489
|
b.claimCommand,
|
|
3309
|
-
`armada heartbeat --every 5m --ticket ${t.id} --handle ${subagent ? subagentName(t.id) : CONDUCTOR_HANDLE} --parent "$PPID"${subagent ? "" : " --background"}`,
|
|
3490
|
+
`armada heartbeat --every 5m --ticket ${t.id} --handle ${b.handle ? shellWord(b.handle) : subagent ? subagentName(t.id) : CONDUCTOR_HANDLE} --parent "$PPID"${subagent ? "" : " --background"}`,
|
|
3310
3491
|
"```",
|
|
3311
3492
|
"",
|
|
3312
3493
|
subagent ? "Keep this Bash heartbeat in the subagent's background: it dies with the subagent, which is intended. Do not detach it from the subagent. If background processes are unavailable, report manually at least every 15 minutes." : "The heartbeat detaches from the short-lived command shell (a new process group, like nohup + setsid), keeps a PID file under ~/.config/armada/watch/, and stays alive between turns and while waiting for messages. Its parent is the persistent agent PID ($PPID in the command shell), never the shell PID ($$). If startup fails or the runtime cannot keep a background process, report manually at least every 15 minutes instead.",
|
|
@@ -3321,13 +3502,19 @@ function renderPrompt(b) {
|
|
|
3321
3502
|
"",
|
|
3322
3503
|
"## Branch",
|
|
3323
3504
|
"",
|
|
3324
|
-
t.branch ? `Work on \`${t.branch}\`. Your ${subagent ? "worktree starts on a branch Claude Code" : "workspace starts on a branch Conductor"} named; rename it before your first commit: \`git branch -m ${t.branch}\`.` : "Linear suggests no branch name for this ticket; name yours after the ticket id.",
|
|
3505
|
+
b.runtime === "herdr" ? `Herdr already created your own worktree on \`${t.branch}\`. Work only there. Before editing, check \`git branch --show-current\` and \`git rev-parse --show-toplevel\`; do not rename the branch or switch the coordinator's checkout. Your runtime handle is \`${b.handle}\`.` : t.branch ? `Work on \`${t.branch}\`. Your ${subagent ? "worktree starts on a branch Claude Code" : "workspace starts on a branch Conductor"} named; rename it before your first commit: \`git branch -m ${t.branch}\`.` : "Linear suggests no branch name for this ticket; name yours after the ticket id.",
|
|
3325
3506
|
"",
|
|
3507
|
+
...b.runtime === "herdr" ? [
|
|
3508
|
+
`You share the coordinator's machine, but own only ${t.id}. Pass \`--ticket ${t.id}\` to every \`armada report\`, \`ask\`, \`release\` and \`validate\`; an inherited \`ARMADA_TICKET\` may name the coordinator's ticket. Herdr keeps your terminal alive when the coordinator disconnects.`,
|
|
3509
|
+
""
|
|
3510
|
+
] : [],
|
|
3326
3511
|
...subagent ? [
|
|
3327
3512
|
`You share the coordinator's machine and environment: its \`ARMADA_TICKET\`, if it has one, is not yours. Pass \`--ticket ${t.id}\` to every \`armada report\`, \`ask\` and \`release\`. You end when the coordinator's session ends: report at every step, so the ticket always says where you are.`,
|
|
3328
3513
|
""
|
|
3329
3514
|
] : []
|
|
3330
3515
|
];
|
|
3516
|
+
if (b.runtime === "herdr" && b.profile)
|
|
3517
|
+
out.push("## Harness", "", `Profile ${b.profile.name}: ${b.profile.agent}, model ${b.profile.model}, effort ${b.profile.effort}.`, "");
|
|
3331
3518
|
if (t.description)
|
|
3332
3519
|
out.push("## Ticket", "", quote(t.description), "");
|
|
3333
3520
|
if (b.parent)
|
|
@@ -9677,28 +9864,33 @@ function buildStatus({
|
|
|
9677
9864
|
},
|
|
9678
9865
|
silentAfterMinutes: config.policy.silentAfterMinutes,
|
|
9679
9866
|
coordinatorMinutes: config.policy.coordinatorMinutes,
|
|
9680
|
-
inFlight: lanes.map((l) =>
|
|
9681
|
-
|
|
9682
|
-
|
|
9683
|
-
|
|
9684
|
-
|
|
9685
|
-
|
|
9686
|
-
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9867
|
+
inFlight: lanes.map((l) => {
|
|
9868
|
+
const profileName = live?.handles?.[l.issue.id]?.profile ?? l.claim?.profile ?? null;
|
|
9869
|
+
const profile = profileName && l.runtime?.toLowerCase() === "herdr" ? config.herdr.profiles[profileName] : null;
|
|
9870
|
+
return {
|
|
9871
|
+
id: l.issue.id,
|
|
9872
|
+
title: l.issue.title,
|
|
9873
|
+
url: l.issue.url,
|
|
9874
|
+
spec: l.spec,
|
|
9875
|
+
phase: l.phase,
|
|
9876
|
+
phaseSource: l.phaseSource,
|
|
9877
|
+
runtime: l.runtime,
|
|
9878
|
+
handle: l.handle,
|
|
9879
|
+
profile: profileName,
|
|
9880
|
+
profileReason: l.claim?.profileReason ?? null,
|
|
9881
|
+
...profile ? { harness: herdrHarnessLabel(profile.harness) } : {},
|
|
9882
|
+
agent: l.agent,
|
|
9883
|
+
since: l.since,
|
|
9884
|
+
lastUpdate: l.lastUpdate,
|
|
9885
|
+
lastReport: l.lastReport,
|
|
9886
|
+
lastHeartbeat: l.lastHeartbeat,
|
|
9887
|
+
silent: l.flags.includes("silent"),
|
|
9888
|
+
statusLine: l.statusLine ? { summary: l.statusLine.summary, at: l.statusLine.at, url: l.statusLine.url, plan: l.statusLine.plan } : null,
|
|
9889
|
+
pr: l.pr ? prRef(l.pr) : null,
|
|
9890
|
+
openBlockers: l.openBlockers,
|
|
9891
|
+
flags: l.flags
|
|
9892
|
+
};
|
|
9893
|
+
}),
|
|
9702
9894
|
pendingLaunches: followedLaunches(launches, now),
|
|
9703
9895
|
notStarted: notStartedLaunches(launches, now, config.policy.notStartedMinutes).map((l) => {
|
|
9704
9896
|
const issue = issues.find((i) => i.id === l.ticket);
|
|
@@ -9901,7 +10093,7 @@ ${attachments.join(`
|
|
|
9901
10093
|
};
|
|
9902
10094
|
}
|
|
9903
10095
|
// package.json
|
|
9904
|
-
var version = "0.2.
|
|
10096
|
+
var version = "0.2.37";
|
|
9905
10097
|
|
|
9906
10098
|
// src/attach.ts
|
|
9907
10099
|
import { resolve } from "node:path";
|
|
@@ -10559,7 +10751,7 @@ async function claim(io, config, credentials, a) {
|
|
|
10559
10751
|
if (reason && !profile)
|
|
10560
10752
|
throw new UsageError("--reason goes with --profile: it says why the routed profile is not used");
|
|
10561
10753
|
try {
|
|
10562
|
-
checkRequestedProfile(config, profile);
|
|
10754
|
+
checkRequestedProfile(config, profile, a.options.runtime?.toLowerCase() === "herdr" ? "herdr" : "conductor");
|
|
10563
10755
|
} catch (err) {
|
|
10564
10756
|
if (err instanceof ProfileError)
|
|
10565
10757
|
throw new UsageError(err.message);
|
|
@@ -11230,6 +11422,9 @@ ${next.line}
|
|
|
11230
11422
|
return 0;
|
|
11231
11423
|
}
|
|
11232
11424
|
|
|
11425
|
+
// src/doctor.ts
|
|
11426
|
+
import { join as join4 } from "node:path";
|
|
11427
|
+
|
|
11233
11428
|
// src/local-tools.ts
|
|
11234
11429
|
import { stripVTControlCharacters } from "node:util";
|
|
11235
11430
|
var MINIMUM_HERDR_VERSION = "0.9.1";
|
|
@@ -11238,11 +11433,14 @@ var TOOLS = {
|
|
|
11238
11433
|
claude: { command: "claude", install: "curl -fsSL https://claude.ai/install.sh | bash" },
|
|
11239
11434
|
codex: { command: "codex", install: "npm i -g @openai/codex" },
|
|
11240
11435
|
opencode: { command: "opencode", install: "curl -fsSL https://opencode.ai/install | bash" },
|
|
11241
|
-
|
|
11436
|
+
dsh: { command: "dsh", install: "" }
|
|
11242
11437
|
};
|
|
11243
11438
|
function localHarnesses(config) {
|
|
11244
11439
|
return [...new Set(Object.values(config.herdr?.profiles ?? {}).map((profile) => profile.harness))];
|
|
11245
11440
|
}
|
|
11441
|
+
function localModelProfiles(config) {
|
|
11442
|
+
return Object.entries(config.herdr?.profiles ?? {}).flatMap(([name, profile]) => profile.harness === "opencode" || profile.harness === "deepseek" ? [{ name, harness: profile.harness, model: profile.model ?? "" }] : []);
|
|
11443
|
+
}
|
|
11246
11444
|
async function probe(io, command, args) {
|
|
11247
11445
|
if (!io.exec)
|
|
11248
11446
|
return null;
|
|
@@ -11323,7 +11521,7 @@ async function signInCheck(io, harness) {
|
|
|
11323
11521
|
}
|
|
11324
11522
|
} catch {}
|
|
11325
11523
|
}
|
|
11326
|
-
} else
|
|
11524
|
+
} else {
|
|
11327
11525
|
login = "codex login";
|
|
11328
11526
|
const result = await probe(io, command, ["login", "status"]);
|
|
11329
11527
|
if (result?.code === 0)
|
|
@@ -11331,38 +11529,121 @@ async function signInCheck(io, harness) {
|
|
|
11331
11529
|
else if (result?.code === 1 && /(?:^|\n)Not logged in\s*(?:\n|$)/i.test(`${result.stdout}
|
|
11332
11530
|
${result.stderr}`))
|
|
11333
11531
|
state = "missing";
|
|
11334
|
-
} else if (harness === "opencode") {
|
|
11335
|
-
login = "opencode auth login";
|
|
11336
|
-
const result = await probe(io, command, ["auth", "list"]);
|
|
11337
|
-
if (result?.code === 0) {
|
|
11338
|
-
const text = stripVTControlCharacters(`${result.stdout}
|
|
11339
|
-
${result.stderr}`);
|
|
11340
|
-
const count = text.match(/\b(\d+) credentials\b/);
|
|
11341
|
-
const environment = text.match(/\b(\d+) environment variables?\b/);
|
|
11342
|
-
if (count)
|
|
11343
|
-
state = Number(count[1]) > 0 || Number(environment?.[1] ?? 0) > 0 ? "ready" : "missing";
|
|
11344
|
-
}
|
|
11345
|
-
} else {
|
|
11346
|
-
login = "dsh web";
|
|
11347
11532
|
}
|
|
11348
11533
|
return {
|
|
11349
11534
|
id: `local-${command}-sign-in`,
|
|
11350
11535
|
level: state === "ready" ? "ok" : state === "missing" ? "error" : "warning",
|
|
11351
|
-
message: state === "ready" ? `${command} reports credentials are present
|
|
11352
|
-
fix: state === "ready" ? null : `the owner runs \`${login}
|
|
11536
|
+
message: state === "ready" ? `${command} reports credentials are present` : state === "missing" ? `${command} is not signed in` : `${command}: could not check sign-in`,
|
|
11537
|
+
fix: state === "ready" ? null : `the owner runs \`${login}\`; Armada never runs sign-in`
|
|
11538
|
+
};
|
|
11539
|
+
}
|
|
11540
|
+
async function openCodeModels(io) {
|
|
11541
|
+
const result = await probe(io, "opencode", ["models"]);
|
|
11542
|
+
if (result?.code !== 0)
|
|
11543
|
+
return null;
|
|
11544
|
+
return [
|
|
11545
|
+
...new Set(stripVTControlCharacters(result.stdout).split(`
|
|
11546
|
+
`).map((line) => line.trim()).filter((line) => /^[^\s/#]+\/[^\s#]+$/.test(line)))
|
|
11547
|
+
];
|
|
11548
|
+
}
|
|
11549
|
+
function modelCheck(profile, available) {
|
|
11550
|
+
const model = profile.model;
|
|
11551
|
+
const matching = available?.filter((id) => profile.harness !== "deepseek" || isDeepseekModel(id)) ?? [];
|
|
11552
|
+
const ready = !!model && matching.includes(model);
|
|
11553
|
+
const label = profile.harness === "deepseek" ? "deepseek (OpenCode + DeepSeek model)" : "opencode";
|
|
11554
|
+
return {
|
|
11555
|
+
id: `local-opencode-${profile.harness}:${profile.name || model}`,
|
|
11556
|
+
level: ready ? "ok" : "error",
|
|
11557
|
+
message: `${label}${profile.name ? ` profile ${profile.name}` : ""}: ${ready ? `OpenCode lists ${model}` : available === null ? "could not check opencode models" : `${model || "the profile's model"} is not listed by OpenCode`}
|
|
11558
|
+
${ready ? "" : `Available models: ${matching.length ? matching.map((id, i) => `${i + 1}. ${id} — model = ${JSON.stringify(id)}`).join("; ") : "none"}`}`.trimEnd(),
|
|
11559
|
+
fix: ready ? null : `the owner runs \`opencode\`, then \`/connect\`, or picks a model listed by \`opencode models\`; add \`model = "<exact model id>"\`${profile.name ? ` under [herdr.profiles.${profile.name}]` : ""}; Armada never handles the key`
|
|
11560
|
+
};
|
|
11561
|
+
}
|
|
11562
|
+
async function offerLocalModels(io, detected, configPath, options = {}) {
|
|
11563
|
+
if (detected.availableModels === null)
|
|
11564
|
+
return detected;
|
|
11565
|
+
let changed = false;
|
|
11566
|
+
for (const profile of detected.profiles) {
|
|
11567
|
+
if (modelCheck(profile, detected.availableModels).level === "ok")
|
|
11568
|
+
continue;
|
|
11569
|
+
const models = detected.availableModels.filter((id) => profile.harness !== "deepseek" || isDeepseekModel(id));
|
|
11570
|
+
if (!models.length || options.readOnly || !io.interactive || io.env.CI || !io.prompt || !io.writeFile || !configPath || !profile.name)
|
|
11571
|
+
continue;
|
|
11572
|
+
io.stderr(`Choose a model for [herdr.profiles.${profile.name}]:
|
|
11573
|
+
${models.map((id, i) => ` ${i + 1}. ${id}`).join(`
|
|
11574
|
+
`)}
|
|
11575
|
+
`);
|
|
11576
|
+
const before = await io.readFile(configPath);
|
|
11577
|
+
const answer = await io.prompt("Model number (Enter to leave unchanged): ", { hidden: false });
|
|
11578
|
+
if (answer === null)
|
|
11579
|
+
break;
|
|
11580
|
+
if (!answer.trim())
|
|
11581
|
+
continue;
|
|
11582
|
+
const selected = /^\d+$/.test(answer.trim()) ? models[Number(answer.trim()) - 1] : undefined;
|
|
11583
|
+
if (!selected) {
|
|
11584
|
+
io.stderr(`No model was selected; configuration unchanged.
|
|
11585
|
+
`);
|
|
11586
|
+
continue;
|
|
11587
|
+
}
|
|
11588
|
+
try {
|
|
11589
|
+
if (before === null)
|
|
11590
|
+
throw new Error("missing config");
|
|
11591
|
+
const after = setHerdrModel(before, profile.name, selected);
|
|
11592
|
+
if (await io.readFile(configPath) !== before)
|
|
11593
|
+
throw new Error("config changed");
|
|
11594
|
+
await io.writeFile(configPath, after);
|
|
11595
|
+
profile.model = selected;
|
|
11596
|
+
changed = true;
|
|
11597
|
+
io.stderr(`Wrote model = ${JSON.stringify(selected)} under [herdr.profiles.${profile.name}] in ${configPath}.
|
|
11598
|
+
`);
|
|
11599
|
+
} catch {
|
|
11600
|
+
io.stderr(`Could not safely save the model in ${configPath}; add model = ${JSON.stringify(selected)} under [herdr.profiles.${profile.name}] yourself.
|
|
11601
|
+
`);
|
|
11602
|
+
}
|
|
11603
|
+
}
|
|
11604
|
+
return changed ? detectLocalTools(io, detected.harnesses, detected.profiles) : detected;
|
|
11605
|
+
}
|
|
11606
|
+
async function dshInformation(io) {
|
|
11607
|
+
const tool = await detectTool(io, "dsh");
|
|
11608
|
+
const present = tool.state === "ready";
|
|
11609
|
+
return {
|
|
11610
|
+
id: "local-dsh",
|
|
11611
|
+
level: "ok",
|
|
11612
|
+
message: `${present ? `dsh ${tool.version} is on PATH` : tool.state === "missing" ? "dsh is not installed" : "dsh installation could not be checked"}; information only: deepseek (OpenCode + DeepSeek model) runs OpenCode. Inspected dsh 0.1.5-rc.2 is one-shot, with no follow-up input or --resume`,
|
|
11613
|
+
fix: null
|
|
11353
11614
|
};
|
|
11354
11615
|
}
|
|
11355
|
-
async function detectLocalTools(io, harnesses) {
|
|
11616
|
+
async function detectLocalTools(io, harnesses, configured = []) {
|
|
11617
|
+
const profiles = configured.map((profile) => typeof profile === "string" ? { name: "", harness: "deepseek", model: profile } : { ...profile });
|
|
11618
|
+
for (const harness of harnesses) {
|
|
11619
|
+
if ((harness === "opencode" || harness === "deepseek") && !profiles.some((profile) => profile.harness === harness))
|
|
11620
|
+
profiles.push({ name: "", harness, model: "" });
|
|
11621
|
+
}
|
|
11622
|
+
let availableModels = null;
|
|
11356
11623
|
const tools = [];
|
|
11357
11624
|
const checks = [];
|
|
11358
|
-
|
|
11625
|
+
const binaries = new Set(harnesses.map((harness) => harness === "deepseek" ? "opencode" : harness));
|
|
11626
|
+
for (const name of ["herdr", ...binaries]) {
|
|
11359
11627
|
const tool = await detectTool(io, name);
|
|
11360
11628
|
tools.push(tool);
|
|
11361
11629
|
checks.push(toolCheck(tool));
|
|
11362
|
-
if (name !== "herdr" && tool.state === "ready")
|
|
11363
|
-
|
|
11630
|
+
if (name !== "herdr" && tool.state === "ready") {
|
|
11631
|
+
if (name !== "opencode")
|
|
11632
|
+
checks.push(await signInCheck(io, name));
|
|
11633
|
+
else {
|
|
11634
|
+
availableModels = await openCodeModels(io);
|
|
11635
|
+
checks.push(...profiles.map((profile) => modelCheck(profile, availableModels)));
|
|
11636
|
+
}
|
|
11637
|
+
}
|
|
11364
11638
|
}
|
|
11365
|
-
return {
|
|
11639
|
+
return {
|
|
11640
|
+
tools,
|
|
11641
|
+
profiles,
|
|
11642
|
+
availableModels,
|
|
11643
|
+
harnesses: [...new Set(harnesses)],
|
|
11644
|
+
checks,
|
|
11645
|
+
ready: !checks.some((check) => check.level === "error")
|
|
11646
|
+
};
|
|
11366
11647
|
}
|
|
11367
11648
|
async function offerLocalInstalls(io, detected, options = {}) {
|
|
11368
11649
|
const platform = io.platform ?? process.platform;
|
|
@@ -11370,7 +11651,7 @@ async function offerLocalInstalls(io, detected, options = {}) {
|
|
|
11370
11651
|
return detected;
|
|
11371
11652
|
let attempted = false;
|
|
11372
11653
|
for (const tool of detected.tools) {
|
|
11373
|
-
if (tool.state === "ready" || tool.state === "unknown")
|
|
11654
|
+
if (tool.name === "dsh" || tool.state === "ready" || tool.state === "unknown")
|
|
11374
11655
|
continue;
|
|
11375
11656
|
const check = toolCheck(tool);
|
|
11376
11657
|
const answer = await io.prompt(`${check.message}: \`${tool.install}\` — install now? [y/N] `, { hidden: false });
|
|
@@ -11380,20 +11661,52 @@ async function offerLocalInstalls(io, detected, options = {}) {
|
|
|
11380
11661
|
continue;
|
|
11381
11662
|
attempted = true;
|
|
11382
11663
|
const definition = TOOLS[tool.name];
|
|
11383
|
-
const npm = tool.name === "codex"
|
|
11384
|
-
const code = await io.spawn(npm ? "npm" : "sh", npm ? ["i", "-g",
|
|
11664
|
+
const npm = tool.name === "codex";
|
|
11665
|
+
const code = await io.spawn(npm ? "npm" : "sh", npm ? ["i", "-g", "@openai/codex"] : ["-c", definition.install], {
|
|
11666
|
+
cwd: io.cwd,
|
|
11667
|
+
env: installerEnv(io.env)
|
|
11668
|
+
}).catch(() => null);
|
|
11385
11669
|
if (code !== 0)
|
|
11386
11670
|
io.stderr(`${tool.command} installation failed${code === null ? "" : ` (exit ${code})`}. Run \`${definition.install}\` yourself.
|
|
11387
11671
|
`);
|
|
11388
11672
|
}
|
|
11389
11673
|
if (!attempted)
|
|
11390
11674
|
return detected;
|
|
11391
|
-
const result = await detectLocalTools(io, detected.
|
|
11675
|
+
const result = await detectLocalTools(io, detected.harnesses, detected.profiles);
|
|
11392
11676
|
if (result.tools.some((tool) => tool.state !== "ready"))
|
|
11393
11677
|
io.stderr(`Some local tools still cannot run. Check PATH, open a new terminal if needed, and retry.
|
|
11394
11678
|
`);
|
|
11395
11679
|
return result;
|
|
11396
11680
|
}
|
|
11681
|
+
async function ensureLocalTools(io, harness, model) {
|
|
11682
|
+
const print = (detected) => {
|
|
11683
|
+
for (const check of detected.checks) {
|
|
11684
|
+
if (check.level === "ok")
|
|
11685
|
+
continue;
|
|
11686
|
+
io.stderr(`${check.message}${check.fix ? `: ${check.fix}` : ""}
|
|
11687
|
+
`);
|
|
11688
|
+
}
|
|
11689
|
+
};
|
|
11690
|
+
const detected = await detectLocalTools(io, [harness], harness === "deepseek" || harness === "opencode" ? [{ name: "", harness, model: model ?? "" }] : []);
|
|
11691
|
+
print(detected);
|
|
11692
|
+
const result = await offerLocalInstalls(io, detected);
|
|
11693
|
+
if (result !== detected)
|
|
11694
|
+
print(result);
|
|
11695
|
+
return result.ready;
|
|
11696
|
+
}
|
|
11697
|
+
async function ensureLocalProfile(io, configPath, name, profile) {
|
|
11698
|
+
if (profile.harness !== "opencode" && profile.harness !== "deepseek")
|
|
11699
|
+
return await ensureLocalTools(io, profile.harness, profile.model) ? profile.model : null;
|
|
11700
|
+
const detected = await detectLocalTools(io, [profile.harness], [{ name, harness: profile.harness, model: profile.model }]);
|
|
11701
|
+
const installed = await offerLocalInstalls(io, detected);
|
|
11702
|
+
const chosen = await offerLocalModels(io, installed, configPath);
|
|
11703
|
+
for (const check of chosen.checks) {
|
|
11704
|
+
if (check.level !== "ok")
|
|
11705
|
+
io.stderr(`${check.message}${check.fix ? `: ${check.fix}` : ""}
|
|
11706
|
+
`);
|
|
11707
|
+
}
|
|
11708
|
+
return chosen.ready ? chosen.profiles[0]?.model ?? null : null;
|
|
11709
|
+
}
|
|
11397
11710
|
|
|
11398
11711
|
// src/repo.ts
|
|
11399
11712
|
import { lstat, mkdir as mkdir2, readdir, readFile as readFile2, readlink, rm as rm2, symlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
@@ -11722,7 +12035,9 @@ async function localRuntimeChecks(io, config, options = { readOnly: true }) {
|
|
|
11722
12035
|
const harnesses = config ? localHarnesses(config) : [];
|
|
11723
12036
|
if (!harnesses.length)
|
|
11724
12037
|
return [];
|
|
11725
|
-
|
|
12038
|
+
const result = await offerLocalInstalls(io, await detectLocalTools(io, harnesses, config ? localModelProfiles(config) : []), options);
|
|
12039
|
+
const selected = await offerLocalModels(io, result, options.configPath ?? join4(io.cwd, CONFIG_FILE), options);
|
|
12040
|
+
return [...selected.checks, ...harnesses.includes("deepseek") ? [await dshInformation(io)] : []];
|
|
11726
12041
|
}
|
|
11727
12042
|
async function buildDoctor(io, armadaVersion, options = { readOnly: true }) {
|
|
11728
12043
|
const root = (io.exec ? await gitRoot(io.exec, io.cwd) : null) ?? io.cwd;
|
|
@@ -11755,7 +12070,7 @@ async function buildDoctor(io, armadaVersion, options = { readOnly: true }) {
|
|
|
11755
12070
|
...keyFileChecks(machine, credentials),
|
|
11756
12071
|
...await labelChecks(io, config, credentials),
|
|
11757
12072
|
...await conductorChecks(io, config),
|
|
11758
|
-
...await localRuntimeChecks(io, config, options),
|
|
12073
|
+
...await localRuntimeChecks(io, config, { ...options, configPath: join4(root, CONFIG_FILE) }),
|
|
11759
12074
|
...config ? await reviewRuntimeChecks(io, root) : [],
|
|
11760
12075
|
...await secretChecks(api, config, credentials)
|
|
11761
12076
|
];
|
|
@@ -11889,7 +12204,7 @@ async function heartbeat(io, config, credentials, args) {
|
|
|
11889
12204
|
// src/init.ts
|
|
11890
12205
|
import { mkdtemp, realpath, rm as rm3 } from "node:fs/promises";
|
|
11891
12206
|
import { tmpdir } from "node:os";
|
|
11892
|
-
import { join as
|
|
12207
|
+
import { join as join5 } from "node:path";
|
|
11893
12208
|
var STOP_HOOK_QUESTION = "Add the Claude Code stop hook to this repository's .claude/settings.json? A coordinator then cannot end its turn while workers are in flight and no armada watch runs; your user settings are not touched. [Y/n] ";
|
|
11894
12209
|
async function wantsStopHook(io, opts) {
|
|
11895
12210
|
if (opts.stopHook !== null)
|
|
@@ -11922,7 +12237,7 @@ async function resolveConfig(exec, root, checkout, opts) {
|
|
|
11922
12237
|
return { config: parse(onDefault, `${CONFIG_FILE} on the default branch`), text: null, source: "default branch" };
|
|
11923
12238
|
const local = await fsRepoView(root).readFile(CONFIG_FILE);
|
|
11924
12239
|
if (local !== null && !opts.programRoot)
|
|
11925
|
-
return { config: parse(local,
|
|
12240
|
+
return { config: parse(local, join5(root, CONFIG_FILE)), text: local, source: "working tree" };
|
|
11926
12241
|
const branch = initBranch(opts.armadaVersion);
|
|
11927
12242
|
if (!opts.programRoot && await sh(exec, root, "git", ["ls-remote", "origin", `refs/heads/${branch}`])) {
|
|
11928
12243
|
await sh(exec, root, "git", ["fetch", "--quiet", "origin", branch]);
|
|
@@ -11993,7 +12308,7 @@ async function init(io, opts) {
|
|
|
11993
12308
|
const base = await defaultBranch(exec, root);
|
|
11994
12309
|
await sh(exec, root, "git", ["fetch", "--quiet", "origin", base]);
|
|
11995
12310
|
const baseSha = await sh(exec, root, "git", ["rev-parse", "FETCH_HEAD"]);
|
|
11996
|
-
const checkout = await realpath(await mkdtemp(
|
|
12311
|
+
const checkout = await realpath(await mkdtemp(join5(tmpdir(), "armada-init-")));
|
|
11997
12312
|
try {
|
|
11998
12313
|
await sh(exec, root, "git", ["worktree", "add", "--quiet", "--detach", checkout, baseSha]);
|
|
11999
12314
|
const { config, text, source } = await resolveConfig(exec, root, checkout, opts);
|
|
@@ -12096,7 +12411,172 @@ async function init(io, opts) {
|
|
|
12096
12411
|
}
|
|
12097
12412
|
|
|
12098
12413
|
// src/launch.ts
|
|
12099
|
-
|
|
12414
|
+
import { dirname as dirname5, join as join6 } from "node:path";
|
|
12415
|
+
|
|
12416
|
+
// src/herdr.ts
|
|
12417
|
+
var harnessArgs = (p) => [
|
|
12418
|
+
"--model",
|
|
12419
|
+
herdrHarnessKind(p.harness) === "opencode" ? `${p.model.split("#")[0]}#${p.effort}` : p.model,
|
|
12420
|
+
...p.harness === "codex" ? ["-c", `model_reasoning_effort=${JSON.stringify(p.effort)}`] : p.harness === "claude" ? ["--effort", p.effort] : [],
|
|
12421
|
+
...p.extraArgs
|
|
12422
|
+
];
|
|
12423
|
+
var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : null;
|
|
12424
|
+
var id = (v) => typeof v === "string" && /^[a-zA-Z0-9:_-]{1,128}$/.test(v);
|
|
12425
|
+
var runtimeEnvironment = (env) => Object.fromEntries(Object.entries(env).filter(([name]) => /^(PATH|HOME|USER|LOGNAME|SHELL|TMPDIR|TMP|TEMP|LANG|TERM|LC_[A-Z_]+|XDG_(CONFIG_HOME|DATA_HOME|STATE_HOME|CACHE_HOME|RUNTIME_DIR)|HERDR_(SESSION|SOCKET_PATH|CONFIG_PATH))$/.test(name)));
|
|
12426
|
+
var credentialNames = (env, extra) => [
|
|
12427
|
+
...new Set([
|
|
12428
|
+
"LINEAR_API_KEY",
|
|
12429
|
+
"GITHUB_TOKEN",
|
|
12430
|
+
"GH_TOKEN",
|
|
12431
|
+
"ARMADA_API_KEY",
|
|
12432
|
+
"ARMADA_SESSION_TOKEN",
|
|
12433
|
+
"ARMADA_SIGNED_IN_TO",
|
|
12434
|
+
"ARMADA_API_URL",
|
|
12435
|
+
"OPENAI_API_KEY",
|
|
12436
|
+
"ANTHROPIC_API_KEY",
|
|
12437
|
+
...Object.keys(env).filter((name) => /^(ARMADA_|CONDUCTOR_)|(?:KEY|TOKEN|SECRET|PASSWORD)$/.test(name)),
|
|
12438
|
+
...extra
|
|
12439
|
+
])
|
|
12440
|
+
].filter((name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)).sort();
|
|
12441
|
+
|
|
12442
|
+
class Herdr {
|
|
12443
|
+
io;
|
|
12444
|
+
constructor(io) {
|
|
12445
|
+
this.io = io;
|
|
12446
|
+
}
|
|
12447
|
+
async call(args, timeoutMs = 40000) {
|
|
12448
|
+
const operation = args.slice(0, 2).join(" ");
|
|
12449
|
+
let reply;
|
|
12450
|
+
let code;
|
|
12451
|
+
try {
|
|
12452
|
+
if (!this.io.exec)
|
|
12453
|
+
throw new Error("no exec");
|
|
12454
|
+
const out = await this.io.exec("herdr", args, { cwd: this.io.cwd, timeoutMs });
|
|
12455
|
+
code = out.code;
|
|
12456
|
+
reply = object(JSON.parse(out.stdout || out.stderr));
|
|
12457
|
+
} catch {
|
|
12458
|
+
throw new UsageError(`herdr ${operation} failed; inspect the runtime with herdr agent list`);
|
|
12459
|
+
}
|
|
12460
|
+
const error = object(reply?.error);
|
|
12461
|
+
if (code !== 0 || error) {
|
|
12462
|
+
const reason = typeof error?.code === "string" && /^[a-z_]{1,64}$/.test(error.code) ? ` (${error.code})` : "";
|
|
12463
|
+
throw new UsageError(`herdr ${operation} failed${reason}; inspect the runtime with herdr agent list`);
|
|
12464
|
+
}
|
|
12465
|
+
if (!reply)
|
|
12466
|
+
throw new UsageError(`herdr ${operation} returned invalid JSON`);
|
|
12467
|
+
return reply;
|
|
12468
|
+
}
|
|
12469
|
+
async ensureServer() {
|
|
12470
|
+
const status = async (timeoutMs) => {
|
|
12471
|
+
const server = object((await this.call(["status", "--json"], timeoutMs)).server);
|
|
12472
|
+
if (!server || typeof server.running !== "boolean")
|
|
12473
|
+
throw new UsageError("invalid herdr server status response");
|
|
12474
|
+
if (server.running && (server.compatible === false || server.endpoint_compatible === false))
|
|
12475
|
+
throw new UsageError("the running herdr server is incompatible; update or restart it before launching");
|
|
12476
|
+
return server.running;
|
|
12477
|
+
};
|
|
12478
|
+
if (await status(5000))
|
|
12479
|
+
return;
|
|
12480
|
+
if (!this.io.detach || !await this.io.detach("herdr", ["server"], { cwd: this.io.cwd, env: runtimeEnvironment(this.io.env) }))
|
|
12481
|
+
throw new UsageError("could not start herdr server; start it headless with herdr server");
|
|
12482
|
+
const now = this.io.now ?? (() => new Date);
|
|
12483
|
+
const deadline = now().getTime() + 5000;
|
|
12484
|
+
for (let attempt = 0;attempt < 20; attempt++) {
|
|
12485
|
+
const remaining = deadline - now().getTime();
|
|
12486
|
+
if (remaining <= 0)
|
|
12487
|
+
break;
|
|
12488
|
+
if (await status(Math.min(1000, remaining)))
|
|
12489
|
+
return;
|
|
12490
|
+
const delay = Math.min(250, deadline - now().getTime());
|
|
12491
|
+
if (delay > 0)
|
|
12492
|
+
await (this.io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))))(delay);
|
|
12493
|
+
}
|
|
12494
|
+
throw new UsageError("herdr server did not become ready; inspect herdr status");
|
|
12495
|
+
}
|
|
12496
|
+
async create(input) {
|
|
12497
|
+
const agent = input.ticket.toLowerCase();
|
|
12498
|
+
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(agent))
|
|
12499
|
+
throw new UsageError("ticket cannot be used as a herdr agent name");
|
|
12500
|
+
const r = object((await this.call([
|
|
12501
|
+
"worktree",
|
|
12502
|
+
"create",
|
|
12503
|
+
"--cwd",
|
|
12504
|
+
input.repo,
|
|
12505
|
+
"--branch",
|
|
12506
|
+
input.branch,
|
|
12507
|
+
"--base",
|
|
12508
|
+
input.base,
|
|
12509
|
+
"--no-focus"
|
|
12510
|
+
])).result);
|
|
12511
|
+
const workspace = object(r?.workspace)?.workspace_id;
|
|
12512
|
+
const rootPane = object(r?.root_pane)?.pane_id;
|
|
12513
|
+
const path = object(r?.worktree)?.path;
|
|
12514
|
+
if (!id(workspace) || !id(rootPane) || typeof path !== "string" || !path.startsWith("/") || object(r?.root_pane)?.workspace_id !== workspace)
|
|
12515
|
+
throw new UsageError("invalid herdr worktree response; inspect herdr worktree list before retrying");
|
|
12516
|
+
const tab = object((await this.call([
|
|
12517
|
+
"tab",
|
|
12518
|
+
"create",
|
|
12519
|
+
"--workspace",
|
|
12520
|
+
workspace,
|
|
12521
|
+
"--cwd",
|
|
12522
|
+
path,
|
|
12523
|
+
"--no-focus",
|
|
12524
|
+
...credentialNames(this.io.env, input.secrets ?? []).flatMap((name) => ["--env", `${name}=`]),
|
|
12525
|
+
"--env",
|
|
12526
|
+
`ARMADA_TICKET=${input.ticket}`
|
|
12527
|
+
])).result);
|
|
12528
|
+
const pane = object(tab?.root_pane)?.pane_id;
|
|
12529
|
+
if (!id(pane) || pane === rootPane || object(tab?.root_pane)?.workspace_id !== workspace)
|
|
12530
|
+
throw new UsageError("invalid herdr worker pane response; inspect herdr pane list before retrying");
|
|
12531
|
+
await this.call(["pane", "close", rootPane]);
|
|
12532
|
+
return { workspace, pane, agent, path };
|
|
12533
|
+
}
|
|
12534
|
+
async start(handle, profile) {
|
|
12535
|
+
const r = await this.call([
|
|
12536
|
+
"agent",
|
|
12537
|
+
"start",
|
|
12538
|
+
handle.agent,
|
|
12539
|
+
"--kind",
|
|
12540
|
+
herdrHarnessKind(profile.harness),
|
|
12541
|
+
"--pane",
|
|
12542
|
+
handle.pane,
|
|
12543
|
+
"--timeout",
|
|
12544
|
+
"30000",
|
|
12545
|
+
"--",
|
|
12546
|
+
...harnessArgs(profile)
|
|
12547
|
+
]);
|
|
12548
|
+
this.checkAgent(r, handle);
|
|
12549
|
+
}
|
|
12550
|
+
async prompt(handle, prompt) {
|
|
12551
|
+
const r = await this.call([
|
|
12552
|
+
"agent",
|
|
12553
|
+
"prompt",
|
|
12554
|
+
handle.agent,
|
|
12555
|
+
prompt,
|
|
12556
|
+
"--wait",
|
|
12557
|
+
"--until",
|
|
12558
|
+
"working",
|
|
12559
|
+
"--timeout",
|
|
12560
|
+
"30000"
|
|
12561
|
+
]);
|
|
12562
|
+
const agent = this.checkAgent(r, handle);
|
|
12563
|
+
if (agent.agent_status !== "working")
|
|
12564
|
+
throw new UsageError("herdr did not confirm the worker is working");
|
|
12565
|
+
}
|
|
12566
|
+
checkAgent(reply, handle) {
|
|
12567
|
+
const agent = object(object(reply.result)?.agent);
|
|
12568
|
+
if (!agent || agent.name !== handle.agent || agent.pane_id !== handle.pane || agent.workspace_id !== handle.workspace)
|
|
12569
|
+
throw new UsageError("invalid herdr agent response; inspect herdr agent list before retrying");
|
|
12570
|
+
return agent;
|
|
12571
|
+
}
|
|
12572
|
+
}
|
|
12573
|
+
|
|
12574
|
+
// src/launch.ts
|
|
12575
|
+
async function launch(io, config, credentials, args, version, configPath) {
|
|
12576
|
+
if (args.rest[0] !== "revoke")
|
|
12577
|
+
return launchLocal(io, config, credentials, args, version, configPath);
|
|
12578
|
+
if (Object.keys(args.options).length)
|
|
12579
|
+
throw new UsageError("launch revoke does not take runtime or profile options");
|
|
12100
12580
|
const [operation, ticket, ...extra] = args.rest;
|
|
12101
12581
|
if (operation !== "revoke" || !ticket || extra.length || !/^[A-Za-z][A-Za-z0-9]{0,15}-\d{1,9}$/.test(ticket))
|
|
12102
12582
|
throw new UsageError("launch needs a ticket to revoke: armada launch revoke <ticket>");
|
|
@@ -12115,12 +12595,170 @@ ${watch.line}
|
|
|
12115
12595
|
`);
|
|
12116
12596
|
return 0;
|
|
12117
12597
|
}
|
|
12598
|
+
async function launchLocal(io, config, credentials, args, version, configPath) {
|
|
12599
|
+
const [input, ...extra] = args.rest;
|
|
12600
|
+
const o = args.options;
|
|
12601
|
+
if (!input || extra.length || !/^[A-Za-z][A-Za-z0-9]{0,15}-\d{1,9}$/.test(input) || o.runtime !== "herdr")
|
|
12602
|
+
throw new UsageError("launch needs a ticket and runtime: armada launch <ticket> --runtime herdr [--harness claude|codex|opencode|deepseek]");
|
|
12603
|
+
const requested = o.profile?.trim() || null;
|
|
12604
|
+
const reason = o.reason?.trim() || null;
|
|
12605
|
+
if (reason && !requested)
|
|
12606
|
+
throw new UsageError("--reason goes with --profile");
|
|
12607
|
+
if (o.harness && !HERDR_HARNESSES.includes(o.harness))
|
|
12608
|
+
throw new UsageError("--harness must be claude, codex, opencode or deepseek (OpenCode + DeepSeek model)");
|
|
12609
|
+
try {
|
|
12610
|
+
checkRequestedProfile(config, requested, "herdr");
|
|
12611
|
+
} catch (error) {
|
|
12612
|
+
if (error instanceof ProfileError)
|
|
12613
|
+
throw new UsageError(error.message);
|
|
12614
|
+
throw error;
|
|
12615
|
+
}
|
|
12616
|
+
const signIn = requireSignIn(credentials);
|
|
12617
|
+
if (!credentials.linearApiKey)
|
|
12618
|
+
throw missingKey(LINEAR_KEY);
|
|
12619
|
+
if (!io.exec)
|
|
12620
|
+
throw new UsageError("local launch needs process execution");
|
|
12621
|
+
const ticketId = input.toUpperCase();
|
|
12622
|
+
const now = io.now ?? (() => new Date);
|
|
12623
|
+
const linear = { apiKey: credentials.linearApiKey, fetch: io.fetch ?? fetch };
|
|
12624
|
+
const [ticket, program] = await Promise.all([
|
|
12625
|
+
fetchBriefTicket(linear, ticketId),
|
|
12626
|
+
fetchProgram({ ...linear, rootId: config.tracker.programRoot, labels: config.tracker.labels, now })
|
|
12627
|
+
]);
|
|
12628
|
+
if (!ticket)
|
|
12629
|
+
throw new UsageError(`ticket ${ticketId} not found in Linear`);
|
|
12630
|
+
if (ticket.statusType === "completed" || ticket.statusType === "canceled")
|
|
12631
|
+
throw new UsageError(`${ticketId} is ${ticket.status}; there is nothing to launch`);
|
|
12632
|
+
if (!program.issues.some((i) => i.id === ticketId))
|
|
12633
|
+
throw new UsageError(`${ticketId} is not under program root ${config.tracker.programRoot}`);
|
|
12634
|
+
if (ticket.blockers.some((b) => b.statusType !== "completed" && b.statusType !== "canceled"))
|
|
12635
|
+
throw new UsageError(`${ticketId} has open blockers; resolve them before launching`);
|
|
12636
|
+
if (inFlight(buildModel(program.issues, program.rootId), program.comments, {
|
|
12637
|
+
now: now().getTime(),
|
|
12638
|
+
silentAfterMinutes: config.policy.silentAfterMinutes
|
|
12639
|
+
}).some((lane) => lane.issue.id === ticketId))
|
|
12640
|
+
throw new UsageError(`${ticketId} is already in flight; inspect its worker before launching again`);
|
|
12641
|
+
const branch = ticket.branchName;
|
|
12642
|
+
if (!branch)
|
|
12643
|
+
throw new UsageError(`${ticketId} has no suggested branch in Linear`);
|
|
12644
|
+
let choice;
|
|
12645
|
+
let validation;
|
|
12646
|
+
try {
|
|
12647
|
+
choice = chooseProfile(config, { ticket: ticketId, labels: ticket.labels, requested, reason }, "herdr");
|
|
12648
|
+
validation = chooseValidations(config.policy.validations, {
|
|
12649
|
+
ticket: ticketId,
|
|
12650
|
+
requested: o.validation ?? null,
|
|
12651
|
+
reason: o["validation-reason"] ?? null,
|
|
12652
|
+
command: `armada launch ${ticketId} --runtime herdr`
|
|
12653
|
+
});
|
|
12654
|
+
} catch (error) {
|
|
12655
|
+
if (error instanceof ProfileError)
|
|
12656
|
+
throw new UsageError(error.message);
|
|
12657
|
+
if (error instanceof ValidationChoiceError)
|
|
12658
|
+
throw new UsageError(error.message, error.next);
|
|
12659
|
+
throw error;
|
|
12660
|
+
}
|
|
12661
|
+
if (!choice)
|
|
12662
|
+
throw new UsageError("local launch needs a [herdr.profiles.<name>] with harness, model and effort");
|
|
12663
|
+
if (o.harness && o.harness !== choice.profile.harness)
|
|
12664
|
+
throw new UsageError(`profile "${choice.name}" uses ${choice.profile.harness}; choose a matching --profile with --reason to change harness`);
|
|
12665
|
+
const execute = io.exec;
|
|
12666
|
+
const preflight = {
|
|
12667
|
+
...io,
|
|
12668
|
+
interactive: args.json ? false : io.interactive,
|
|
12669
|
+
exec: (command, argv, options) => execute(command, argv, { ...options, timeoutMs: options.timeoutMs ?? 1e4 })
|
|
12670
|
+
};
|
|
12671
|
+
const model = await ensureLocalProfile(preflight, configPath, choice.name, choice.profile);
|
|
12672
|
+
if (model === null)
|
|
12673
|
+
return 1;
|
|
12674
|
+
choice.profile.model = model;
|
|
12675
|
+
const openCode = herdrHarnessKind(choice.profile.harness) === "opencode";
|
|
12676
|
+
const configSnapshot = openCode ? await io.readFile(configPath) : null;
|
|
12677
|
+
if (openCode) {
|
|
12678
|
+
if (!io.writeFile || configSnapshot === null)
|
|
12679
|
+
throw new UsageError("local OpenCode launch needs the configuration copied into its worker worktree");
|
|
12680
|
+
if (JSON.stringify(parseConfig(configSnapshot, configPath)) !== JSON.stringify(config))
|
|
12681
|
+
throw new UsageError("configuration changed during preflight; retry launch with the saved model");
|
|
12682
|
+
}
|
|
12683
|
+
const root = await io.exec("git", ["rev-parse", "--show-toplevel"], { cwd: io.cwd, timeoutMs: 1e4 });
|
|
12684
|
+
if (root.code !== 0 || !root.stdout.trim().startsWith("/"))
|
|
12685
|
+
throw new UsageError("local launch must run in a git repository");
|
|
12686
|
+
const repo = root.stdout.trim();
|
|
12687
|
+
const remote = await io.exec("git", ["ls-remote", "--symref", "origin", "HEAD"], { cwd: repo, timeoutMs: 20000 });
|
|
12688
|
+
const base = remote.code === 0 ? remote.stdout.match(/^ref:\s+refs\/heads\/(\S+)\s+HEAD/m)?.[1] : null;
|
|
12689
|
+
if (!base)
|
|
12690
|
+
throw new UsageError("could not read the default branch of origin");
|
|
12691
|
+
const conventions = config.brief.extra ? { path: config.brief.extra, text: await io.readFile(join6(dirname5(configPath), config.brief.extra)) } : null;
|
|
12692
|
+
const npm = await checkPublished(version, io.fetch ?? fetch);
|
|
12693
|
+
if (npm.state === "missing")
|
|
12694
|
+
throw new UsageError(`armada ${version} is not on npm yet; publish this version before launching local workers`);
|
|
12695
|
+
const api = apiOf(io, credentials.armadaApi.url);
|
|
12696
|
+
const launch = await api.launchToken(signIn, { project: config.project.slug, ticket: ticketId });
|
|
12697
|
+
const runtime = new Herdr(io);
|
|
12698
|
+
let handle;
|
|
12699
|
+
try {
|
|
12700
|
+
await runtime.ensureServer();
|
|
12701
|
+
handle = await runtime.create({ repo, branch, base, ticket: ticketId, secrets: config.secrets.names });
|
|
12702
|
+
if (configSnapshot !== null && io.writeFile)
|
|
12703
|
+
await io.writeFile(join6(handle.path, CONFIG_FILE), configSnapshot);
|
|
12704
|
+
const b = buildBrief({
|
|
12705
|
+
config,
|
|
12706
|
+
ticket,
|
|
12707
|
+
program,
|
|
12708
|
+
profile: null,
|
|
12709
|
+
version,
|
|
12710
|
+
npm,
|
|
12711
|
+
env: io.env,
|
|
12712
|
+
now: now(),
|
|
12713
|
+
conventions,
|
|
12714
|
+
validation,
|
|
12715
|
+
launch: {
|
|
12716
|
+
token: launch.token,
|
|
12717
|
+
expiresAt: launch.expiresAt,
|
|
12718
|
+
apiUrl: armadaAddress(credentials.armadaApi.url) === armadaAddress(DEFAULT_ARMADA_API_URL) ? null : armadaAddress(credentials.armadaApi.url)
|
|
12719
|
+
},
|
|
12720
|
+
herdr: { choice, handle: herdrClaimHandle(handle) }
|
|
12721
|
+
});
|
|
12722
|
+
await runtime.start(handle, choice.profile);
|
|
12723
|
+
await runtime.prompt(handle, b.prompt);
|
|
12724
|
+
} catch (error) {
|
|
12725
|
+
if (handle)
|
|
12726
|
+
io.stderr(`armada: local workspace retained: ${herdrClaimHandle(handle)}
|
|
12727
|
+
`);
|
|
12728
|
+
throw new UsageError(error instanceof UsageError || error instanceof BriefError ? error.message : "local worker launch failed", `inspect herdr agent list; revoke the pending token with armada launch revoke ${ticketId} before retrying`);
|
|
12729
|
+
}
|
|
12730
|
+
const known = (await watchOf(io, config.project.slug)).state?.inFlight ?? [];
|
|
12731
|
+
const inFlightTickets = [...new Set([...known, ticketId])].sort();
|
|
12732
|
+
await remember(io, config.project.slug, { inFlight: inFlightTickets, readAt: now().toISOString() });
|
|
12733
|
+
const watch = await rearmFor(io, config.project.slug, { inFlight: inFlightTickets, open: null });
|
|
12734
|
+
const result = {
|
|
12735
|
+
ticket: ticketId,
|
|
12736
|
+
runtime: "herdr",
|
|
12737
|
+
profile: choice.name,
|
|
12738
|
+
harness: choice.profile.harness,
|
|
12739
|
+
actualHarness: herdrHarnessKind(choice.profile.harness),
|
|
12740
|
+
harnessDescription: herdrHarnessLabel(choice.profile.harness),
|
|
12741
|
+
branch,
|
|
12742
|
+
handle: herdrClaimHandle(handle),
|
|
12743
|
+
path: handle.path,
|
|
12744
|
+
state: "working",
|
|
12745
|
+
watch
|
|
12746
|
+
};
|
|
12747
|
+
io.stdout(args.json ? `${JSON.stringify(result, null, 2)}
|
|
12748
|
+
` : `Launched ${ticketId} with ${result.harnessDescription} on profile ${choice.name}.
|
|
12749
|
+
Worktree: ${handle.path}
|
|
12750
|
+
Handle: ${result.handle}
|
|
12751
|
+
The worker signs in and claims its ticket from the brief.
|
|
12752
|
+
${watch.line}
|
|
12753
|
+
`);
|
|
12754
|
+
return 0;
|
|
12755
|
+
}
|
|
12118
12756
|
|
|
12119
12757
|
// src/merge.ts
|
|
12120
12758
|
import { randomUUID } from "node:crypto";
|
|
12121
12759
|
import { rm as rm4 } from "node:fs/promises";
|
|
12122
12760
|
import { hostname, tmpdir as tmpdir2 } from "node:os";
|
|
12123
|
-
import { dirname as
|
|
12761
|
+
import { dirname as dirname6, join as join7 } from "node:path";
|
|
12124
12762
|
var TRANSIENT = /\bHTTP 5\d\d\b|\b5\d\d (?:Bad Gateway|Service Unavailable|Gateway Time-?out|Internal Server Error)\b|Bad Gateway|Service Unavailable|Gateway Time-?out|ECONNRESET|ETIMEDOUT|connection reset|i\/o timeout|TLS handshake timeout/i;
|
|
12125
12763
|
var tail = (text, lines = 30) => text.trimEnd().split(`
|
|
12126
12764
|
`).slice(-lines).join(`
|
|
@@ -12198,7 +12836,7 @@ function gitRepo(exec, cwd) {
|
|
|
12198
12836
|
},
|
|
12199
12837
|
async testMerge({ branch, base, head, number, commands }) {
|
|
12200
12838
|
await must(["fetch", "--quiet", "origin", branch, `refs/pull/${number}/head`]);
|
|
12201
|
-
const dir =
|
|
12839
|
+
const dir = join7(tmpdir2(), `armada-merge-${number}-${randomUUID().slice(0, 8)}`);
|
|
12202
12840
|
const remove = async () => {
|
|
12203
12841
|
await git(["worktree", "remove", "--force", dir]);
|
|
12204
12842
|
await git(["worktree", "prune"]);
|
|
@@ -12307,7 +12945,7 @@ async function merge(io, config, credentials, a, configPath) {
|
|
|
12307
12945
|
if (!exec)
|
|
12308
12946
|
throw new UsageError("armada merge needs to run git and gh");
|
|
12309
12947
|
const linearApiKey = credentials.linearApiKey;
|
|
12310
|
-
const repoDir =
|
|
12948
|
+
const repoDir = dirname6(configPath);
|
|
12311
12949
|
const fetchOpt = io.fetch ? { fetch: io.fetch } : {};
|
|
12312
12950
|
const gh = { token, repository: config.github.repository, ...fetchOpt };
|
|
12313
12951
|
const linearOpts = { apiKey: linearApiKey, labels: config.tracker.labels, ...fetchOpt };
|
|
@@ -12342,7 +12980,7 @@ async function merge(io, config, credentials, a, configPath) {
|
|
|
12342
12980
|
`),
|
|
12343
12981
|
installedSkill: async (name) => {
|
|
12344
12982
|
for (const dir of [AGENTS_SKILLS_DIR, CLAUDE_SKILLS_DIR])
|
|
12345
|
-
if (await io.readFile(
|
|
12983
|
+
if (await io.readFile(join7(repoDir, dir, name, "SKILL.md")) !== null)
|
|
12346
12984
|
return true;
|
|
12347
12985
|
return false;
|
|
12348
12986
|
}
|
|
@@ -12440,7 +13078,7 @@ function renderStatus(r) {
|
|
|
12440
13078
|
out.push(` ${pad(t.id, idWidth)} ${pad(phaseLabel(t), phaseWidth)} ${who} · ${t.lastReport ? `reported ${relative2(t.lastReport, now)}` : `updated ${relative2(t.lastUpdate, now)}`}`);
|
|
12441
13079
|
out.push(`${indent}${truncate(t.title, 90)}${t.spec ? ` [${t.spec}]` : ""}`);
|
|
12442
13080
|
if (t.profile)
|
|
12443
|
-
out.push(`${indent}Profile: ${t.profile}${t.profileReason ? ` — ${t.profileReason}` : ""}`);
|
|
13081
|
+
out.push(`${indent}Profile: ${t.profile}${t.harness ? ` · ${t.harness}` : ""}${t.profileReason ? ` — ${t.profileReason}` : ""}`);
|
|
12444
13082
|
if (t.statusLine?.summary)
|
|
12445
13083
|
out.push(`${indent}“${truncate(t.statusLine.summary, 100)}”`);
|
|
12446
13084
|
if (t.statusLine?.plan)
|
|
@@ -12558,7 +13196,7 @@ ${"─".repeat(60)}
|
|
|
12558
13196
|
}
|
|
12559
13197
|
|
|
12560
13198
|
// src/secrets.ts
|
|
12561
|
-
import { dirname as
|
|
13199
|
+
import { dirname as dirname7, relative as relative3, resolve as resolve2 } from "node:path";
|
|
12562
13200
|
var NAME_HINT = "upper snake case, e.g. OPENAI_API_KEY";
|
|
12563
13201
|
var hhmm2 = (iso) => `${iso.slice(0, 16).replace("T", " ")} UTC`;
|
|
12564
13202
|
function signInOf(config, credentials) {
|
|
@@ -12638,7 +13276,7 @@ Next: armada secrets set <NAME> (an owner or admin), or the Keys page of Armada
|
|
|
12638
13276
|
async function exportRefusal(io, path) {
|
|
12639
13277
|
if (!io.exec)
|
|
12640
13278
|
return "git cannot be run here to check that the file is ignored";
|
|
12641
|
-
const cwd =
|
|
13279
|
+
const cwd = dirname7(path);
|
|
12642
13280
|
const tracked = await io.exec("git", ["ls-files", "--error-unmatch", "--", path], { cwd }).catch(() => null);
|
|
12643
13281
|
if (tracked?.code === 0)
|
|
12644
13282
|
return `git tracks ${path}: secrets written there would be committed`;
|
|
@@ -13001,7 +13639,12 @@ var COMMAND_HELP = {
|
|
|
13001
13639
|
A pull request the owner was asked about merges only once they approved
|
|
13002
13640
|
that exact head (or it with only the base merged in).
|
|
13003
13641
|
`,
|
|
13004
|
-
launch: ` launch
|
|
13642
|
+
launch: ` launch <ticket> --runtime herdr [--harness claude|codex|opencode|deepseek]
|
|
13643
|
+
deepseek (OpenCode + DeepSeek model) runs a persistent session
|
|
13644
|
+
[--profile <name> [--reason <why>]] [--validation <n|none>]
|
|
13645
|
+
Create the ticket's worktree and start a persistent local worker
|
|
13646
|
+
with its launch-token brief. Profiles follow [[herdr.routing]]
|
|
13647
|
+
launch revoke <ticket>
|
|
13005
13648
|
Cancel the newest pending launch through Armada, including a worker
|
|
13006
13649
|
signed in but not claimed. A claimed launch needs armada release instead
|
|
13007
13650
|
`,
|
|
@@ -13144,6 +13787,7 @@ var VALUE_OPTIONS = [
|
|
|
13144
13787
|
"every",
|
|
13145
13788
|
"parent",
|
|
13146
13789
|
"runtime",
|
|
13790
|
+
"harness",
|
|
13147
13791
|
"handle",
|
|
13148
13792
|
"branch",
|
|
13149
13793
|
"ticket",
|
|
@@ -13202,6 +13846,7 @@ var COMMAND_OPTIONS = {
|
|
|
13202
13846
|
init: ["program-root", "name", "slug", "no-stop-hook"],
|
|
13203
13847
|
merge: ["ticket", "no-ticket", "dry-run", "no-lock", "wait", "timeout", "reason", "ask-owner"],
|
|
13204
13848
|
brief: ["profile", "reason", "prompt", "profile-line", "validation", "validation-reason"],
|
|
13849
|
+
launch: ["runtime", "harness", "profile", "reason", "validation", "validation-reason"],
|
|
13205
13850
|
validate: ["ticket", "attach", "caption", "choices", "message", "message-file"],
|
|
13206
13851
|
"ask-owner": ["choices"],
|
|
13207
13852
|
login: ["api-key", "launch-token", "api-url"],
|
|
@@ -13267,12 +13912,12 @@ async function findConfig(io, explicit, command = "status") {
|
|
|
13267
13912
|
throw new UsageError(`${path} does not exist`, `armada ${command} --config <file>, with the path of an ${CONFIG_FILE}`);
|
|
13268
13913
|
return { path, text };
|
|
13269
13914
|
}
|
|
13270
|
-
for (let dir = resolve3(io.cwd);; dir =
|
|
13271
|
-
const path =
|
|
13915
|
+
for (let dir = resolve3(io.cwd);; dir = dirname8(dir)) {
|
|
13916
|
+
const path = join8(dir, CONFIG_FILE);
|
|
13272
13917
|
const text = await io.readFile(path);
|
|
13273
13918
|
if (text !== null)
|
|
13274
13919
|
return { path, text };
|
|
13275
|
-
if (
|
|
13920
|
+
if (dirname8(dir) === dir)
|
|
13276
13921
|
break;
|
|
13277
13922
|
}
|
|
13278
13923
|
throw new UsageError(`no ${CONFIG_FILE} found in ${io.cwd} or any parent directory, so this is not a repository Armada runs`, `armada init to set this repository up, armada ${command} --config <file> to use another ${CONFIG_FILE}, or armada status --all to see the registered projects`);
|
|
@@ -13293,7 +13938,7 @@ async function status(io, args) {
|
|
|
13293
13938
|
...io.fetch ? { fetch: io.fetch } : {},
|
|
13294
13939
|
...io.now ? { now: io.now } : {}
|
|
13295
13940
|
});
|
|
13296
|
-
const behind = await skillsBehind(fsRepoView(
|
|
13941
|
+
const behind = await skillsBehind(fsRepoView(dirname8(path))).catch(() => null);
|
|
13297
13942
|
if (behind)
|
|
13298
13943
|
report.warnings.push(skillsBehindLine(behind, version));
|
|
13299
13944
|
io.stdout(args.json ? `${JSON.stringify(report, null, 2)}
|
|
@@ -13450,7 +14095,7 @@ async function dispatch(argv, io) {
|
|
|
13450
14095
|
const { path, text } = await findConfig(io, args.config, "launch");
|
|
13451
14096
|
const config = parseConfig(text, path);
|
|
13452
14097
|
const { credentials } = await loadCredentials(io, { project: config.project.slug });
|
|
13453
|
-
return await launch(io, config, credentials, args);
|
|
14098
|
+
return await launch(io, config, credentials, args, version, path);
|
|
13454
14099
|
}
|
|
13455
14100
|
if (args.command === "status") {
|
|
13456
14101
|
noExtra(args.rest);
|
|
@@ -13709,8 +14354,9 @@ function openUrl(url) {
|
|
|
13709
14354
|
return false;
|
|
13710
14355
|
}
|
|
13711
14356
|
}
|
|
13712
|
-
var exec = (command, args, { cwd }) => new Promise((done, fail) => {
|
|
14357
|
+
var exec = (command, args, { cwd, timeoutMs }) => new Promise((done, fail) => {
|
|
13713
14358
|
const child = spawn2(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
14359
|
+
const timer = timeoutMs ? setTimeout(() => child.kill("SIGKILL"), timeoutMs) : null;
|
|
13714
14360
|
let stdout = "";
|
|
13715
14361
|
let stderr = "";
|
|
13716
14362
|
child.stdout.setEncoding("utf8").on("data", (d) => {
|
|
@@ -13719,8 +14365,16 @@ var exec = (command, args, { cwd }) => new Promise((done, fail) => {
|
|
|
13719
14365
|
child.stderr.setEncoding("utf8").on("data", (d) => {
|
|
13720
14366
|
stderr += d;
|
|
13721
14367
|
});
|
|
13722
|
-
child.on("error",
|
|
13723
|
-
|
|
14368
|
+
child.on("error", (err) => {
|
|
14369
|
+
if (timer)
|
|
14370
|
+
clearTimeout(timer);
|
|
14371
|
+
fail(err);
|
|
14372
|
+
});
|
|
14373
|
+
child.on("close", (code) => {
|
|
14374
|
+
if (timer)
|
|
14375
|
+
clearTimeout(timer);
|
|
14376
|
+
done({ code: code ?? 1, stdout, stderr });
|
|
14377
|
+
});
|
|
13724
14378
|
});
|
|
13725
14379
|
var stopped = false;
|
|
13726
14380
|
if (process.argv.includes("heartbeat") && !process.argv.includes("--background"))
|
|
@@ -13739,6 +14393,7 @@ var code = await run(process.argv.slice(2), {
|
|
|
13739
14393
|
return null;
|
|
13740
14394
|
throw err;
|
|
13741
14395
|
}),
|
|
14396
|
+
writeFile: (path, text) => writeFile3(path, text, "utf8"),
|
|
13742
14397
|
stdout: (t) => process.stdout.write(t),
|
|
13743
14398
|
readBinaryFile: async (path, maxBytes) => {
|
|
13744
14399
|
const file = await open2(path, "r").catch((err) => {
|
|
@@ -13791,6 +14446,14 @@ var code = await run(process.argv.slice(2), {
|
|
|
13791
14446
|
gitBranch,
|
|
13792
14447
|
readStdin,
|
|
13793
14448
|
exec,
|
|
14449
|
+
detach: (command, args, { cwd, env }) => new Promise((resolve) => {
|
|
14450
|
+
const child = spawn2(command, args, { cwd, env, stdio: "ignore", detached: true });
|
|
14451
|
+
child.once("error", () => resolve(false));
|
|
14452
|
+
child.once("spawn", () => {
|
|
14453
|
+
child.unref();
|
|
14454
|
+
resolve(true);
|
|
14455
|
+
});
|
|
14456
|
+
}),
|
|
13794
14457
|
spawn: spawnInherited,
|
|
13795
14458
|
startBackground,
|
|
13796
14459
|
stopped: () => stopped,
|