@the-vibe-company/armada 0.2.45 → 0.2.47
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 +1034 -181
- package/package.json +1 -1
package/dist/armada.js
CHANGED
|
@@ -8,7 +8,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 dirname9, join as join9, resolve as resolve3 } from "node:path";
|
|
12
12
|
|
|
13
13
|
// ../core/src/types.ts
|
|
14
14
|
var LABEL_PHASES = [
|
|
@@ -613,6 +613,13 @@ function armadaApi(opts) {
|
|
|
613
613
|
throw new ArmadaApiError(`Armada (${host}) answered the revoked launch in a shape this CLI does not know`);
|
|
614
614
|
return { id: body.id, ticket: body.ticket };
|
|
615
615
|
},
|
|
616
|
+
async revokePendingLaunch(signIn, target) {
|
|
617
|
+
const { status, body } = await call("POST", "workers/revoke-pending", { signIn, body: target });
|
|
618
|
+
if (status !== 200)
|
|
619
|
+
throw refusal(status, body, "Armada did not revoke this pending launch");
|
|
620
|
+
if (body.id !== target.id || body.ticket !== target.ticket)
|
|
621
|
+
throw new ArmadaApiError(`Armada (${host}) answered a different revoked launch`);
|
|
622
|
+
},
|
|
616
623
|
async signOut(signIn) {
|
|
617
624
|
const { status, body } = await call("DELETE", "session", { signIn });
|
|
618
625
|
if (status !== 200)
|
|
@@ -1976,124 +1983,19 @@ var HAS_WELLFORMED = !!"".isWellFormed;
|
|
|
1976
1983
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1977
1984
|
*/
|
|
1978
1985
|
|
|
1979
|
-
// ../core/src/herdr-profile.ts
|
|
1980
|
-
var herdrHarnessKind = (harness) => harness === "deepseek" ? "opencode" : harness;
|
|
1981
|
-
var herdrHarnessLabel = (harness) => harness === "deepseek" ? "deepseek (OpenCode + DeepSeek model)" : harness;
|
|
1982
|
-
function herdrChoice(choice) {
|
|
1983
|
-
return {
|
|
1984
|
-
...choice,
|
|
1985
|
-
profile: {
|
|
1986
|
-
runtime: "herdr",
|
|
1987
|
-
agent: herdrHarnessLabel(choice.profile.harness),
|
|
1988
|
-
model: choice.profile.model,
|
|
1989
|
-
effort: choice.profile.effort,
|
|
1990
|
-
fastMode: false
|
|
1991
|
-
}
|
|
1992
|
-
};
|
|
1993
|
-
}
|
|
1994
|
-
var herdrClaimHandle = (handle) => JSON.stringify({ workspace: handle.workspace, pane: handle.pane, agent: handle.agent });
|
|
1995
|
-
function isDeepseekModel(model) {
|
|
1996
|
-
const [provider, ...parts] = model.split("/");
|
|
1997
|
-
return !!parts.length && (provider === "deepseek" || /(?:^|[/-])deepseek(?:$|[/-])/i.test(parts.join("/")));
|
|
1998
|
-
}
|
|
1999
|
-
function setHerdrModel(text, name, model) {
|
|
2000
|
-
const raw = parse(text);
|
|
2001
|
-
const profiles = raw.herdr?.profiles;
|
|
2002
|
-
if (!profiles?.[name])
|
|
2003
|
-
throw new Error("profile is no longer present");
|
|
2004
|
-
const lines = text.split(/(?<=\n)/);
|
|
2005
|
-
let section = -1;
|
|
2006
|
-
let end = lines.length;
|
|
2007
|
-
for (let i = 0;i < lines.length; i++) {
|
|
2008
|
-
const header = lines[i]?.match(/^\s*\[herdr\s*\.\s*profiles\s*\.\s*(.+?)\]\s*(?:#.*)?(?:\r?\n)?$/);
|
|
2009
|
-
if (header) {
|
|
2010
|
-
const key = header[1]?.trim();
|
|
2011
|
-
if (key && Object.hasOwn(parse(`[${key}]
|
|
2012
|
-
`), name)) {
|
|
2013
|
-
section = i;
|
|
2014
|
-
break;
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
if (section < 0)
|
|
2019
|
-
throw new Error("use an explicit [herdr.profiles.<name>] section to save the model");
|
|
2020
|
-
for (let i = section + 1;i < lines.length; i++) {
|
|
2021
|
-
if (/^\s*\[/.test(lines[i] ?? "")) {
|
|
2022
|
-
end = i;
|
|
2023
|
-
break;
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
let replaced = false;
|
|
2027
|
-
for (let i = section + 1;i < end; i++) {
|
|
2028
|
-
const match = lines[i]?.match(/^(\s*(?:model|"model"|'model')\s*=\s*)("(?:[^"\\]|\\.)*"|'[^']*')(.*?)(\r?\n)?$/);
|
|
2029
|
-
if (match) {
|
|
2030
|
-
const value = match[2]?.startsWith("'") && !model.includes("'") ? `'${model}'` : JSON.stringify(model);
|
|
2031
|
-
lines[i] = `${match[1]}${value}${match[3]}${match[4] ?? ""}`;
|
|
2032
|
-
replaced = true;
|
|
2033
|
-
break;
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
|
-
if (!replaced) {
|
|
2037
|
-
const newline = text.includes(`\r
|
|
2038
|
-
`) ? `\r
|
|
2039
|
-
` : `
|
|
2040
|
-
`;
|
|
2041
|
-
if (!(lines[section] ?? "").endsWith(`
|
|
2042
|
-
`))
|
|
2043
|
-
lines[section] += newline;
|
|
2044
|
-
lines.splice(section + 1, 0, `model = ${JSON.stringify(model)}${newline}`);
|
|
2045
|
-
}
|
|
2046
|
-
const next = lines.join("");
|
|
2047
|
-
profiles[name].model = model;
|
|
2048
|
-
if (JSON.stringify(parse(next)) !== JSON.stringify(raw)) {
|
|
2049
|
-
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);
|
|
2050
|
-
if (canonical(parse(next)) !== canonical(raw))
|
|
2051
|
-
throw new Error("could not safely edit the profile model");
|
|
2052
|
-
}
|
|
2053
|
-
return next;
|
|
2054
|
-
}
|
|
2055
|
-
|
|
2056
|
-
// ../core/src/npm.ts
|
|
2057
|
-
var ARMADA_PACKAGE = CLI_PACKAGE;
|
|
2058
|
-
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${ARMADA_PACKAGE.replace("/", "%2f")}`;
|
|
2059
|
-
var NPM_CHECK_MS = 3000;
|
|
2060
|
-
async function checkPublished(version, fetch2, timeoutMs = NPM_CHECK_MS) {
|
|
2061
|
-
try {
|
|
2062
|
-
const signal = AbortSignal.timeout(timeoutMs);
|
|
2063
|
-
const res = await fetch2(NPM_REGISTRY_URL, {
|
|
2064
|
-
headers: { accept: "application/vnd.npm.install-v1+json" },
|
|
2065
|
-
cache: "no-store",
|
|
2066
|
-
signal
|
|
2067
|
-
});
|
|
2068
|
-
if (!res.ok)
|
|
2069
|
-
return { state: "unknown", reason: `npm answered HTTP ${res.status}` };
|
|
2070
|
-
const body = await res.json();
|
|
2071
|
-
const versions = body?.versions;
|
|
2072
|
-
if (!versions || typeof versions !== "object" || Array.isArray(versions) || !Object.keys(versions).length)
|
|
2073
|
-
return { state: "unknown", reason: "npm listed no version" };
|
|
2074
|
-
const candidates = Object.keys(versions).filter((candidate) => /^\d+\.\d+\.\d+$/.test(candidate) && compareVersions(candidate, version) <= 0).sort((first, second) => compareVersions(second, first));
|
|
2075
|
-
for (const candidate of candidates) {
|
|
2076
|
-
const tarball = versions[candidate]?.dist?.tarball;
|
|
2077
|
-
if (typeof tarball !== "string" || !tarball)
|
|
2078
|
-
continue;
|
|
2079
|
-
const download = await fetch2(tarball, { method: "HEAD", cache: "no-store", signal });
|
|
2080
|
-
if (download.status === 200)
|
|
2081
|
-
return candidate === version ? { state: "published" } : { state: "missing", newest: candidate };
|
|
2082
|
-
if (download.status !== 404)
|
|
2083
|
-
return { state: "unknown", reason: `npm tarball answered HTTP ${download.status}` };
|
|
2084
|
-
}
|
|
2085
|
-
return { state: "missing", newest: null };
|
|
2086
|
-
} catch (err) {
|
|
2087
|
-
return { state: "unknown", reason: networkReason(err, timeoutMs) };
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
1986
|
// ../core/src/config.ts
|
|
2092
1987
|
var CONFIG_FILE = "armada.toml";
|
|
2093
1988
|
var PLAN_POLICIES = ["approve", "pre-approved"];
|
|
2094
1989
|
var routingLabelKey = (name) => name.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{M}\p{N}]/gu, "");
|
|
2095
1990
|
var PROFILE_RUNTIMES = ["conductor", "claude-code"];
|
|
2096
1991
|
var HERDR_HARNESSES = ["claude", "codex", "opencode", "deepseek"];
|
|
1992
|
+
var HERDR_PERMISSIONS = ["ask", "full"];
|
|
1993
|
+
var HERDR_FULL_PERMISSION_ARGS = {
|
|
1994
|
+
claude: "--dangerously-skip-permissions",
|
|
1995
|
+
codex: "--dangerously-bypass-approvals-and-sandbox",
|
|
1996
|
+
opencode: "--auto",
|
|
1997
|
+
deepseek: "--auto"
|
|
1998
|
+
};
|
|
2097
1999
|
var CONFIG_DEFAULTS = {
|
|
2098
2000
|
language: "en",
|
|
2099
2001
|
readyLabel: "ready-for-agent",
|
|
@@ -2316,7 +2218,7 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2316
2218
|
problems.push(`"${path}" is not a usable profile name`);
|
|
2317
2219
|
continue;
|
|
2318
2220
|
}
|
|
2319
|
-
known.push([path, p, ["harness", "model", "effort", "extra_args", "when"]]);
|
|
2221
|
+
known.push([path, p, ["harness", "model", "effort", "extra_args", "permissions", "when"]]);
|
|
2320
2222
|
let harness = "claude";
|
|
2321
2223
|
if (p.harness === undefined)
|
|
2322
2224
|
problems.push(`missing required key "${path}.harness"`);
|
|
@@ -2333,13 +2235,23 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2333
2235
|
}
|
|
2334
2236
|
if (harness === "deepseek" && extraArgs.some((arg) => /^(?:--model(?:=|$)|-m)/.test(arg.trim())))
|
|
2335
2237
|
problems.push(`"${path}.extra_args" must not override the DeepSeek model; use "${path}.model"`);
|
|
2238
|
+
let permissions;
|
|
2239
|
+
if (p.permissions !== undefined) {
|
|
2240
|
+
if (HERDR_PERMISSIONS.includes(p.permissions))
|
|
2241
|
+
permissions = p.permissions;
|
|
2242
|
+
else
|
|
2243
|
+
problems.push(`"${path}.permissions" must be "ask" or "full"`);
|
|
2244
|
+
}
|
|
2245
|
+
if (permissions === "ask" && extraArgs.some((arg) => arg.trim() === HERDR_FULL_PERMISSION_ARGS[harness]))
|
|
2246
|
+
problems.push(`"${path}.permissions" = "ask" cannot be combined with "${HERDR_FULL_PERMISSION_ARGS[harness]}" in "${path}.extra_args"`);
|
|
2336
2247
|
const model = (harness === "opencode" || harness === "deepseek") && (p.model === undefined || typeof p.model === "string" && !p.model.trim()) ? "" : str(p, path, "model");
|
|
2337
2248
|
herdrProfiles[name] = {
|
|
2338
2249
|
...p.when !== undefined ? { when: str(p, path, "when") } : {},
|
|
2339
2250
|
harness,
|
|
2340
2251
|
model,
|
|
2341
2252
|
effort: str(p, path, "effort"),
|
|
2342
|
-
extraArgs
|
|
2253
|
+
extraArgs,
|
|
2254
|
+
...permissions !== undefined ? { permissions } : {}
|
|
2343
2255
|
};
|
|
2344
2256
|
}
|
|
2345
2257
|
let herdrDefaultProfile = null;
|
|
@@ -2648,6 +2560,7 @@ profile = "debug"
|
|
|
2648
2560
|
# harness = "claude" # "claude", "codex", "opencode" or "deepseek" (OpenCode + DeepSeek model)
|
|
2649
2561
|
# model = "sonnet"
|
|
2650
2562
|
# effort = "high"
|
|
2563
|
+
# permissions = "ask" # normal harness approvals; use "full" for the native bypass/auto flag
|
|
2651
2564
|
# extra_args = ["--verbose"]
|
|
2652
2565
|
# when = "a ticket best handled by Claude"
|
|
2653
2566
|
|
|
@@ -2660,6 +2573,425 @@ function slugify(name) {
|
|
|
2660
2573
|
return name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "project";
|
|
2661
2574
|
}
|
|
2662
2575
|
|
|
2576
|
+
// ../core/src/herdr-profile.ts
|
|
2577
|
+
var herdrHarnessKind = (harness) => harness === "deepseek" ? "opencode" : harness;
|
|
2578
|
+
var herdrHarnessLabel = (harness) => harness === "deepseek" ? "deepseek (OpenCode + DeepSeek model)" : harness;
|
|
2579
|
+
function herdrChoice(choice) {
|
|
2580
|
+
return {
|
|
2581
|
+
...choice,
|
|
2582
|
+
profile: {
|
|
2583
|
+
runtime: "herdr",
|
|
2584
|
+
agent: herdrHarnessLabel(choice.profile.harness),
|
|
2585
|
+
model: choice.profile.model,
|
|
2586
|
+
effort: choice.profile.effort,
|
|
2587
|
+
fastMode: false
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
}
|
|
2591
|
+
var herdrClaimHandle = (handle) => JSON.stringify({ workspace: handle.workspace, pane: handle.pane, agent: handle.agent });
|
|
2592
|
+
function isDeepseekModel(model) {
|
|
2593
|
+
const [provider, ...parts] = model.split("/");
|
|
2594
|
+
return !!parts.length && (provider === "deepseek" || /(?:^|[/-])deepseek(?:$|[/-])/i.test(parts.join("/")));
|
|
2595
|
+
}
|
|
2596
|
+
function herdrPermissionArgs(profile) {
|
|
2597
|
+
const args = [...profile.extraArgs];
|
|
2598
|
+
if (profile.permissions !== "full")
|
|
2599
|
+
return args;
|
|
2600
|
+
const fullArg = HERDR_FULL_PERMISSION_ARGS[profile.harness];
|
|
2601
|
+
const firstMatching = args.findIndex((arg) => arg.trim() === fullArg);
|
|
2602
|
+
const withoutMatching = args.filter((arg) => arg.trim() !== fullArg);
|
|
2603
|
+
if (firstMatching < 0)
|
|
2604
|
+
return [...withoutMatching, fullArg];
|
|
2605
|
+
withoutMatching.splice(firstMatching, 0, fullArg);
|
|
2606
|
+
return withoutMatching;
|
|
2607
|
+
}
|
|
2608
|
+
var isTable2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2609
|
+
var canonicalToml = (value) => JSON.stringify(value, (_, nested) => typeof nested === "object" && nested !== null && !Array.isArray(nested) ? Object.fromEntries(Object.keys(nested).sort().map((key) => [key, nested[key]])) : nested);
|
|
2610
|
+
var linesOf = (text) => text.split(/(?<=\n)/);
|
|
2611
|
+
var lineWithoutEnding = (line) => line.replace(/\r?\n$/, "");
|
|
2612
|
+
var hasTomlHeader = (line) => /^\s*\[\[?[^\]]+\]\]?\s*(?:#.*)?(?:\r?\n)?$/.test(line);
|
|
2613
|
+
var profileHeaderName = (line) => {
|
|
2614
|
+
const source = lineWithoutEnding(line);
|
|
2615
|
+
if (!/^\s*\[(?!\[)/.test(source) || !/herdr\s*\.\s*profiles\s*\./.test(source))
|
|
2616
|
+
return null;
|
|
2617
|
+
try {
|
|
2618
|
+
const parsed = parse(`${source}
|
|
2619
|
+
`);
|
|
2620
|
+
const herdr = parsed.herdr;
|
|
2621
|
+
const profiles = isTable2(herdr) ? herdr.profiles : undefined;
|
|
2622
|
+
if (!isTable2(profiles))
|
|
2623
|
+
return null;
|
|
2624
|
+
const names = Object.keys(profiles);
|
|
2625
|
+
return names.length === 1 ? names[0] ?? null : null;
|
|
2626
|
+
} catch {
|
|
2627
|
+
return null;
|
|
2628
|
+
}
|
|
2629
|
+
};
|
|
2630
|
+
var keyAssignment = (line, key) => new RegExp(`^\\s*(?:${key}|"${key}"|'${key}')\\s*=`).test(lineWithoutEnding(line));
|
|
2631
|
+
var keyLine = (lines, key) => {
|
|
2632
|
+
for (let i = 1;i < lines.length; i++)
|
|
2633
|
+
if (keyAssignment(lines[i] ?? "", key))
|
|
2634
|
+
return i;
|
|
2635
|
+
return -1;
|
|
2636
|
+
};
|
|
2637
|
+
var quotedValueLine = (line, key) => lineWithoutEnding(line).match(new RegExp(`^(\\s*(?:${key}|"${key}"|'${key}')\\s*=\\s*)("(?:[^"\\\\]|\\\\.)*"|'[^']*')(.*)$`));
|
|
2638
|
+
var addLineBreak = (line, newline) => /\r?\n$/.test(line) ? line : `${line}${newline}`;
|
|
2639
|
+
var skipArrayTrivia = (source, start, close) => {
|
|
2640
|
+
let cursor = start;
|
|
2641
|
+
while (cursor < close) {
|
|
2642
|
+
if (/\s/.test(source[cursor] ?? "")) {
|
|
2643
|
+
cursor++;
|
|
2644
|
+
continue;
|
|
2645
|
+
}
|
|
2646
|
+
if (source[cursor] === "#") {
|
|
2647
|
+
const newline = source.indexOf(`
|
|
2648
|
+
`, cursor);
|
|
2649
|
+
cursor = newline < 0 || newline > close ? close : newline + 1;
|
|
2650
|
+
continue;
|
|
2651
|
+
}
|
|
2652
|
+
break;
|
|
2653
|
+
}
|
|
2654
|
+
return cursor;
|
|
2655
|
+
};
|
|
2656
|
+
var scanStringArray = (source, start) => {
|
|
2657
|
+
if (source[start] !== "[")
|
|
2658
|
+
throw new Error("could not safely edit extra_args: expected a string array");
|
|
2659
|
+
const close = (() => {
|
|
2660
|
+
let cursor = start + 1;
|
|
2661
|
+
let quote = null;
|
|
2662
|
+
while (cursor < source.length) {
|
|
2663
|
+
const char = source[cursor];
|
|
2664
|
+
if (quote === "'") {
|
|
2665
|
+
if (char === "'")
|
|
2666
|
+
quote = null;
|
|
2667
|
+
cursor++;
|
|
2668
|
+
continue;
|
|
2669
|
+
}
|
|
2670
|
+
if (quote === '"') {
|
|
2671
|
+
if (char === "\\") {
|
|
2672
|
+
cursor += 2;
|
|
2673
|
+
continue;
|
|
2674
|
+
}
|
|
2675
|
+
if (char === '"')
|
|
2676
|
+
quote = null;
|
|
2677
|
+
cursor++;
|
|
2678
|
+
continue;
|
|
2679
|
+
}
|
|
2680
|
+
if (char === "'") {
|
|
2681
|
+
if (source[cursor + 1] === "'")
|
|
2682
|
+
throw new Error("could not safely edit extra_args: multiline strings are unsupported");
|
|
2683
|
+
quote = "'";
|
|
2684
|
+
} else if (char === '"') {
|
|
2685
|
+
if (source[cursor + 1] === '"')
|
|
2686
|
+
throw new Error("could not safely edit extra_args: multiline strings are unsupported");
|
|
2687
|
+
quote = '"';
|
|
2688
|
+
} else if (char === "]") {
|
|
2689
|
+
return cursor;
|
|
2690
|
+
}
|
|
2691
|
+
cursor++;
|
|
2692
|
+
}
|
|
2693
|
+
throw new Error("could not safely edit extra_args: unterminated string array");
|
|
2694
|
+
})();
|
|
2695
|
+
const items = [];
|
|
2696
|
+
let cursor = skipArrayTrivia(source, start + 1, close);
|
|
2697
|
+
while (cursor < close) {
|
|
2698
|
+
const quote = source[cursor];
|
|
2699
|
+
if (quote !== "'" && quote !== '"')
|
|
2700
|
+
throw new Error("could not safely edit extra_args: expected string values");
|
|
2701
|
+
if (source[cursor + 1] === quote)
|
|
2702
|
+
throw new Error("could not safely edit extra_args: multiline strings are unsupported");
|
|
2703
|
+
const itemStart = cursor;
|
|
2704
|
+
cursor++;
|
|
2705
|
+
while (cursor < close) {
|
|
2706
|
+
if (quote === '"' && source[cursor] === "\\") {
|
|
2707
|
+
cursor += 2;
|
|
2708
|
+
continue;
|
|
2709
|
+
}
|
|
2710
|
+
if (source[cursor] === quote)
|
|
2711
|
+
break;
|
|
2712
|
+
cursor++;
|
|
2713
|
+
}
|
|
2714
|
+
if (source[cursor] !== quote)
|
|
2715
|
+
throw new Error("could not safely edit extra_args: unterminated string value");
|
|
2716
|
+
const itemEnd = cursor + 1;
|
|
2717
|
+
const literal = source.slice(itemStart, itemEnd);
|
|
2718
|
+
let decoded;
|
|
2719
|
+
try {
|
|
2720
|
+
decoded = parse(`value = ${literal}
|
|
2721
|
+
`).value;
|
|
2722
|
+
} catch {
|
|
2723
|
+
throw new Error("could not safely edit extra_args: invalid string value");
|
|
2724
|
+
}
|
|
2725
|
+
if (typeof decoded !== "string")
|
|
2726
|
+
throw new Error("could not safely edit extra_args: expected string values");
|
|
2727
|
+
cursor = skipArrayTrivia(source, itemEnd, close);
|
|
2728
|
+
const commaAfter = source[cursor] === "," ? cursor : null;
|
|
2729
|
+
items.push({ start: itemStart, end: itemEnd, commaAfter, value: decoded });
|
|
2730
|
+
if (commaAfter === null) {
|
|
2731
|
+
cursor = skipArrayTrivia(source, cursor, close);
|
|
2732
|
+
if (cursor < close)
|
|
2733
|
+
throw new Error("could not safely edit extra_args: expected a comma");
|
|
2734
|
+
break;
|
|
2735
|
+
}
|
|
2736
|
+
cursor = skipArrayTrivia(source, commaAfter + 1, close);
|
|
2737
|
+
}
|
|
2738
|
+
return { close, items };
|
|
2739
|
+
};
|
|
2740
|
+
var arrayAssignment = (source, key) => {
|
|
2741
|
+
const pattern = new RegExp(`(^|\\r?\\n)([ \\t]*(?:${key}|"${key}"|'${key}')\\s*=\\s*)`, "g");
|
|
2742
|
+
const match = pattern.exec(source);
|
|
2743
|
+
if (!match)
|
|
2744
|
+
return null;
|
|
2745
|
+
const assignmentStart = (match.index ?? 0) + (match[1]?.length ?? 0);
|
|
2746
|
+
let arrayStart = (match.index ?? 0) + match[0].length;
|
|
2747
|
+
while (/\s/.test(source[arrayStart] ?? ""))
|
|
2748
|
+
arrayStart++;
|
|
2749
|
+
if (source[arrayStart] !== "[")
|
|
2750
|
+
throw new Error(`could not safely edit ${key}: expected a string array`);
|
|
2751
|
+
return { start: assignmentStart, arrayStart, scan: scanStringArray(source, arrayStart) };
|
|
2752
|
+
};
|
|
2753
|
+
var removeArrayItems = (source, assignment, remove) => {
|
|
2754
|
+
if (!assignment)
|
|
2755
|
+
return source;
|
|
2756
|
+
const { items } = assignment.scan;
|
|
2757
|
+
if (!items.some((item) => remove(item.value)))
|
|
2758
|
+
return source;
|
|
2759
|
+
const edits = [];
|
|
2760
|
+
for (let start = 0;start < items.length; ) {
|
|
2761
|
+
if (!remove(items[start]?.value ?? "")) {
|
|
2762
|
+
start++;
|
|
2763
|
+
continue;
|
|
2764
|
+
}
|
|
2765
|
+
let end = start;
|
|
2766
|
+
while (end + 1 < items.length && remove(items[end + 1]?.value ?? ""))
|
|
2767
|
+
end++;
|
|
2768
|
+
let editStart = items[start]?.start ?? 0;
|
|
2769
|
+
let editEnd = items[end]?.end ?? editStart;
|
|
2770
|
+
if (end < items.length - 1) {
|
|
2771
|
+
const comma = items[end]?.commaAfter;
|
|
2772
|
+
if (comma === null || comma === undefined)
|
|
2773
|
+
throw new Error("could not safely edit extra_args: invalid separators");
|
|
2774
|
+
editEnd = comma + 1;
|
|
2775
|
+
while (source[editEnd] === " " || source[editEnd] === "\t")
|
|
2776
|
+
editEnd++;
|
|
2777
|
+
} else if (start > 0) {
|
|
2778
|
+
const previousComma = items[start - 1]?.commaAfter;
|
|
2779
|
+
if (previousComma === null || previousComma === undefined)
|
|
2780
|
+
throw new Error("could not safely edit extra_args: invalid separators");
|
|
2781
|
+
editStart = previousComma;
|
|
2782
|
+
const trailingComma = items[end]?.commaAfter;
|
|
2783
|
+
editEnd = trailingComma === null || trailingComma === undefined ? items[end]?.end ?? editEnd : trailingComma + 1;
|
|
2784
|
+
} else {
|
|
2785
|
+
const trailingComma = items[end]?.commaAfter;
|
|
2786
|
+
editEnd = trailingComma === null || trailingComma === undefined ? items[end]?.end ?? editEnd : trailingComma + 1;
|
|
2787
|
+
}
|
|
2788
|
+
edits.push({ start: editStart, end: editEnd });
|
|
2789
|
+
start = end + 1;
|
|
2790
|
+
}
|
|
2791
|
+
let next = source;
|
|
2792
|
+
for (const edit of edits.sort((a, b) => b.start - a.start))
|
|
2793
|
+
next = `${next.slice(0, edit.start)}${next.slice(edit.end)}`;
|
|
2794
|
+
return next;
|
|
2795
|
+
};
|
|
2796
|
+
var profileSections = (text) => {
|
|
2797
|
+
const lines = linesOf(text);
|
|
2798
|
+
const found = [];
|
|
2799
|
+
for (let i = 0;i < lines.length; i++) {
|
|
2800
|
+
const name = profileHeaderName(lines[i] ?? "");
|
|
2801
|
+
if (name)
|
|
2802
|
+
found.push({ name, start: i });
|
|
2803
|
+
}
|
|
2804
|
+
return new Map(found.map((entry, index) => {
|
|
2805
|
+
let end = lines.length;
|
|
2806
|
+
for (let i = entry.start + 1;i < lines.length; i++) {
|
|
2807
|
+
if (hasTomlHeader(lines[i] ?? "")) {
|
|
2808
|
+
end = i;
|
|
2809
|
+
break;
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
const next = found[index + 1];
|
|
2813
|
+
if (next && next.start < end)
|
|
2814
|
+
end = next.start;
|
|
2815
|
+
return [entry.name, { start: entry.start, end }];
|
|
2816
|
+
}));
|
|
2817
|
+
};
|
|
2818
|
+
function setHerdrPermissions(text, names, choice) {
|
|
2819
|
+
if (!HERDR_PERMISSIONS.includes(choice))
|
|
2820
|
+
throw new Error('permissions must be "ask" or "full"');
|
|
2821
|
+
const raw = parse(text);
|
|
2822
|
+
const requested = [...new Set(names)];
|
|
2823
|
+
if (!requested.length)
|
|
2824
|
+
return text;
|
|
2825
|
+
const herdr = raw.herdr;
|
|
2826
|
+
const profiles = isTable2(herdr) ? herdr.profiles : undefined;
|
|
2827
|
+
if (!isTable2(profiles))
|
|
2828
|
+
throw new Error("could not safely edit permissions: no [herdr.profiles] table");
|
|
2829
|
+
const sections = profileSections(text);
|
|
2830
|
+
const lines = linesOf(text);
|
|
2831
|
+
const expected = structuredClone(raw);
|
|
2832
|
+
const expectedHerdr = expected.herdr;
|
|
2833
|
+
const expectedProfiles = isTable2(expectedHerdr) ? expectedHerdr.profiles : undefined;
|
|
2834
|
+
if (!isTable2(expectedProfiles))
|
|
2835
|
+
throw new Error("could not safely edit permissions: no [herdr.profiles] table");
|
|
2836
|
+
const replacements = [];
|
|
2837
|
+
for (const name of requested) {
|
|
2838
|
+
if (!Object.hasOwn(profiles, name) || !isTable2(profiles[name]))
|
|
2839
|
+
throw new Error(`profile "${name}" is no longer present`);
|
|
2840
|
+
const section = sections.get(name);
|
|
2841
|
+
if (!section)
|
|
2842
|
+
throw new Error(`use an explicit [herdr.profiles.${name}] section to save permissions`);
|
|
2843
|
+
const profile = profiles[name];
|
|
2844
|
+
const harness = profile.harness;
|
|
2845
|
+
if (!(typeof harness === "string" && Object.hasOwn(HERDR_FULL_PERMISSION_ARGS, harness)))
|
|
2846
|
+
throw new Error(`could not safely edit permissions for profile "${name}": invalid harness`);
|
|
2847
|
+
const profileLines = lines.slice(section.start, section.end);
|
|
2848
|
+
const permissionLine = keyLine(profileLines, "permissions");
|
|
2849
|
+
if (permissionLine >= 0) {
|
|
2850
|
+
const match = quotedValueLine(profileLines[permissionLine] ?? "", "permissions");
|
|
2851
|
+
if (!match)
|
|
2852
|
+
throw new Error(`could not safely edit permissions for profile "${name}"`);
|
|
2853
|
+
const oldValue = match[2] ?? '"ask"';
|
|
2854
|
+
const quote = oldValue.startsWith("'") ? "'" : '"';
|
|
2855
|
+
const value = quote === "'" ? `'${choice}'` : JSON.stringify(choice);
|
|
2856
|
+
const ending = (profileLines[permissionLine] ?? "").match(/\r?\n$/)?.[0] ?? "";
|
|
2857
|
+
profileLines[permissionLine] = `${match[1]}${value}${match[3]}${ending}`;
|
|
2858
|
+
} else if (Object.hasOwn(profile, "permissions")) {
|
|
2859
|
+
throw new Error(`could not safely edit permissions for profile "${name}"`);
|
|
2860
|
+
} else {
|
|
2861
|
+
const newline = text.includes(`\r
|
|
2862
|
+
`) ? `\r
|
|
2863
|
+
` : `
|
|
2864
|
+
`;
|
|
2865
|
+
let insertAt = keyLine(profileLines, "effort");
|
|
2866
|
+
insertAt = insertAt < 0 ? keyLine(profileLines, "model") : insertAt;
|
|
2867
|
+
insertAt = insertAt < 0 ? 1 : insertAt + 1;
|
|
2868
|
+
if (insertAt > 0 && insertAt <= profileLines.length) {
|
|
2869
|
+
const previous = insertAt - 1;
|
|
2870
|
+
profileLines[previous] = addLineBreak(profileLines[previous] ?? "", newline);
|
|
2871
|
+
}
|
|
2872
|
+
const sourceLine = profileLines.find((line) => keyAssignment(line, "harness")) ?? "";
|
|
2873
|
+
const indent = sourceLine.match(/^\s*/)?.[0] ?? "";
|
|
2874
|
+
profileLines.splice(insertAt, 0, `${indent}permissions = ${JSON.stringify(choice)}${newline}`);
|
|
2875
|
+
}
|
|
2876
|
+
let profileSource = profileLines.join("");
|
|
2877
|
+
const existingArgs = profile.extra_args;
|
|
2878
|
+
if (choice === "ask" && existingArgs !== undefined) {
|
|
2879
|
+
if (!Array.isArray(existingArgs) || !existingArgs.every((arg) => typeof arg === "string"))
|
|
2880
|
+
throw new Error(`could not safely edit extra_args for profile "${name}"`);
|
|
2881
|
+
const assignment = arrayAssignment(profileSource, "extra_args");
|
|
2882
|
+
if (!assignment)
|
|
2883
|
+
throw new Error(`could not safely edit extra_args for profile "${name}"`);
|
|
2884
|
+
const scanned = assignment.scan.items.map((item) => item.value);
|
|
2885
|
+
if (canonicalToml(scanned) !== canonicalToml(existingArgs))
|
|
2886
|
+
throw new Error(`could not safely edit extra_args for profile "${name}"`);
|
|
2887
|
+
profileSource = removeArrayItems(profileSource, assignment, (arg) => arg.trim() === HERDR_FULL_PERMISSION_ARGS[harness]);
|
|
2888
|
+
const expectedProfile = expectedProfiles[name];
|
|
2889
|
+
expectedProfile.extra_args = existingArgs.filter((arg) => arg.trim() !== HERDR_FULL_PERMISSION_ARGS[harness]);
|
|
2890
|
+
}
|
|
2891
|
+
const updatedProfile = expectedProfiles[name];
|
|
2892
|
+
updatedProfile.permissions = choice;
|
|
2893
|
+
replacements.push({ start: section.start, end: section.end, source: profileSource });
|
|
2894
|
+
}
|
|
2895
|
+
const nextLines = [...lines];
|
|
2896
|
+
for (const replacement of replacements.sort((a, b) => b.start - a.start))
|
|
2897
|
+
nextLines.splice(replacement.start, replacement.end - replacement.start, ...linesOf(replacement.source));
|
|
2898
|
+
const next = nextLines.join("");
|
|
2899
|
+
if (canonicalToml(parse(next)) !== canonicalToml(expected))
|
|
2900
|
+
throw new Error("could not safely edit profile permissions");
|
|
2901
|
+
return next;
|
|
2902
|
+
}
|
|
2903
|
+
function setHerdrModel(text, name, model) {
|
|
2904
|
+
const raw = parse(text);
|
|
2905
|
+
const profiles = raw.herdr?.profiles;
|
|
2906
|
+
if (!profiles?.[name])
|
|
2907
|
+
throw new Error("profile is no longer present");
|
|
2908
|
+
const lines = text.split(/(?<=\n)/);
|
|
2909
|
+
let section = -1;
|
|
2910
|
+
let end = lines.length;
|
|
2911
|
+
for (let i = 0;i < lines.length; i++) {
|
|
2912
|
+
const header = lines[i]?.match(/^\s*\[herdr\s*\.\s*profiles\s*\.\s*(.+?)\]\s*(?:#.*)?(?:\r?\n)?$/);
|
|
2913
|
+
if (header) {
|
|
2914
|
+
const key = header[1]?.trim();
|
|
2915
|
+
if (key && Object.hasOwn(parse(`[${key}]
|
|
2916
|
+
`), name)) {
|
|
2917
|
+
section = i;
|
|
2918
|
+
break;
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
if (section < 0)
|
|
2923
|
+
throw new Error("use an explicit [herdr.profiles.<name>] section to save the model");
|
|
2924
|
+
for (let i = section + 1;i < lines.length; i++) {
|
|
2925
|
+
if (/^\s*\[/.test(lines[i] ?? "")) {
|
|
2926
|
+
end = i;
|
|
2927
|
+
break;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
let replaced = false;
|
|
2931
|
+
for (let i = section + 1;i < end; i++) {
|
|
2932
|
+
const match = lines[i]?.match(/^(\s*(?:model|"model"|'model')\s*=\s*)("(?:[^"\\]|\\.)*"|'[^']*')(.*?)(\r?\n)?$/);
|
|
2933
|
+
if (match) {
|
|
2934
|
+
const value = match[2]?.startsWith("'") && !model.includes("'") ? `'${model}'` : JSON.stringify(model);
|
|
2935
|
+
lines[i] = `${match[1]}${value}${match[3]}${match[4] ?? ""}`;
|
|
2936
|
+
replaced = true;
|
|
2937
|
+
break;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
if (!replaced) {
|
|
2941
|
+
const newline = text.includes(`\r
|
|
2942
|
+
`) ? `\r
|
|
2943
|
+
` : `
|
|
2944
|
+
`;
|
|
2945
|
+
if (!(lines[section] ?? "").endsWith(`
|
|
2946
|
+
`))
|
|
2947
|
+
lines[section] += newline;
|
|
2948
|
+
lines.splice(section + 1, 0, `model = ${JSON.stringify(model)}${newline}`);
|
|
2949
|
+
}
|
|
2950
|
+
const next = lines.join("");
|
|
2951
|
+
profiles[name].model = model;
|
|
2952
|
+
if (JSON.stringify(parse(next)) !== JSON.stringify(raw)) {
|
|
2953
|
+
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);
|
|
2954
|
+
if (canonical(parse(next)) !== canonical(raw))
|
|
2955
|
+
throw new Error("could not safely edit the profile model");
|
|
2956
|
+
}
|
|
2957
|
+
return next;
|
|
2958
|
+
}
|
|
2959
|
+
|
|
2960
|
+
// ../core/src/npm.ts
|
|
2961
|
+
var ARMADA_PACKAGE = CLI_PACKAGE;
|
|
2962
|
+
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${ARMADA_PACKAGE.replace("/", "%2f")}`;
|
|
2963
|
+
var NPM_CHECK_MS = 3000;
|
|
2964
|
+
async function checkPublished(version, fetch2, timeoutMs = NPM_CHECK_MS) {
|
|
2965
|
+
try {
|
|
2966
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
2967
|
+
const res = await fetch2(NPM_REGISTRY_URL, {
|
|
2968
|
+
headers: { accept: "application/vnd.npm.install-v1+json" },
|
|
2969
|
+
cache: "no-store",
|
|
2970
|
+
signal
|
|
2971
|
+
});
|
|
2972
|
+
if (!res.ok)
|
|
2973
|
+
return { state: "unknown", reason: `npm answered HTTP ${res.status}` };
|
|
2974
|
+
const body = await res.json();
|
|
2975
|
+
const versions = body?.versions;
|
|
2976
|
+
if (!versions || typeof versions !== "object" || Array.isArray(versions) || !Object.keys(versions).length)
|
|
2977
|
+
return { state: "unknown", reason: "npm listed no version" };
|
|
2978
|
+
const candidates = Object.keys(versions).filter((candidate) => /^\d+\.\d+\.\d+$/.test(candidate) && compareVersions(candidate, version) <= 0).sort((first, second) => compareVersions(second, first));
|
|
2979
|
+
for (const candidate of candidates) {
|
|
2980
|
+
const tarball = versions[candidate]?.dist?.tarball;
|
|
2981
|
+
if (typeof tarball !== "string" || !tarball)
|
|
2982
|
+
continue;
|
|
2983
|
+
const download = await fetch2(tarball, { method: "HEAD", cache: "no-store", signal });
|
|
2984
|
+
if (download.status === 200)
|
|
2985
|
+
return candidate === version ? { state: "published" } : { state: "missing", newest: candidate };
|
|
2986
|
+
if (download.status !== 404)
|
|
2987
|
+
return { state: "unknown", reason: `npm tarball answered HTTP ${download.status}` };
|
|
2988
|
+
}
|
|
2989
|
+
return { state: "missing", newest: null };
|
|
2990
|
+
} catch (err) {
|
|
2991
|
+
return { state: "unknown", reason: networkReason(err, timeoutMs) };
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2663
2995
|
// ../core/src/phases.ts
|
|
2664
2996
|
var TRANSITIONS = {
|
|
2665
2997
|
planning: ["awaiting-approval", "implementing", "awaiting-validation"],
|
|
@@ -4939,7 +5271,7 @@ var EMPTY_PERSONAL_CONFIG = {
|
|
|
4939
5271
|
dashboard: { url: null },
|
|
4940
5272
|
api: { url: null }
|
|
4941
5273
|
};
|
|
4942
|
-
var
|
|
5274
|
+
var isTable3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4943
5275
|
function parsePersonalConfig(text, source = "config.toml") {
|
|
4944
5276
|
let raw;
|
|
4945
5277
|
try {
|
|
@@ -4955,11 +5287,11 @@ function parsePersonalConfig(text, source = "config.toml") {
|
|
|
4955
5287
|
continue;
|
|
4956
5288
|
const keys = known[key];
|
|
4957
5289
|
if (!keys) {
|
|
4958
|
-
if (!
|
|
5290
|
+
if (!isTable3(v))
|
|
4959
5291
|
problems.push(`unknown key "${key}"`);
|
|
4960
5292
|
continue;
|
|
4961
5293
|
}
|
|
4962
|
-
if (!
|
|
5294
|
+
if (!isTable3(v)) {
|
|
4963
5295
|
problems.push(`"${key}" must be a table`);
|
|
4964
5296
|
continue;
|
|
4965
5297
|
}
|
|
@@ -4975,7 +5307,7 @@ function parsePersonalConfig(text, source = "config.toml") {
|
|
|
4975
5307
|
problems.push(`"${dotted}" must be a non-empty string`);
|
|
4976
5308
|
return null;
|
|
4977
5309
|
};
|
|
4978
|
-
const table = (key) =>
|
|
5310
|
+
const table = (key) => isTable3(raw[key]) ? raw[key] : {};
|
|
4979
5311
|
const config = {
|
|
4980
5312
|
language: str(raw.language, "language"),
|
|
4981
5313
|
dashboard: { url: str(table("dashboard").url, "dashboard.url") },
|
|
@@ -10159,7 +10491,7 @@ ${attachments.join(`
|
|
|
10159
10491
|
};
|
|
10160
10492
|
}
|
|
10161
10493
|
// package.json
|
|
10162
|
-
var version = "0.2.
|
|
10494
|
+
var version = "0.2.47";
|
|
10163
10495
|
|
|
10164
10496
|
// src/attach.ts
|
|
10165
10497
|
import { resolve } from "node:path";
|
|
@@ -10492,10 +10824,10 @@ async function authLogout(io) {
|
|
|
10492
10824
|
}
|
|
10493
10825
|
|
|
10494
10826
|
// src/brief.ts
|
|
10495
|
-
import { dirname as
|
|
10827
|
+
import { dirname as dirname4, join as join3 } from "node:path";
|
|
10496
10828
|
|
|
10497
10829
|
// src/watch.ts
|
|
10498
|
-
import { dirname as
|
|
10830
|
+
import { dirname as dirname3 } from "node:path";
|
|
10499
10831
|
|
|
10500
10832
|
// src/login.ts
|
|
10501
10833
|
var hostOf = (url) => {
|
|
@@ -10696,13 +11028,50 @@ async function logout(io) {
|
|
|
10696
11028
|
return 0;
|
|
10697
11029
|
}
|
|
10698
11030
|
|
|
10699
|
-
// src/
|
|
11031
|
+
// src/herdr.ts
|
|
11032
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
11033
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
11034
|
+
|
|
11035
|
+
// src/first-run.ts
|
|
10700
11036
|
import { stripVTControlCharacters } from "node:util";
|
|
10701
|
-
|
|
11037
|
+
function firstRunIssue(harness, raw) {
|
|
11038
|
+
const text = stripVTControlCharacters(raw).replace(/\s+/g, " ");
|
|
11039
|
+
const kind = herdrHarnessKind(harness);
|
|
11040
|
+
if (kind === "claude") {
|
|
11041
|
+
if (/Is this a project you created or one you trust\?|Yes, I trust this folder|Do you trust the files in this folder\?/i.test(text))
|
|
11042
|
+
return { kind: "trust", message: "Claude Code asks to trust this folder" };
|
|
11043
|
+
if (/\d+ new MCP servers? found in this project/i.test(text))
|
|
11044
|
+
return { kind: "mcp", message: "Claude Code asks about new project MCP servers" };
|
|
11045
|
+
if (/Select login method|Log in to use Claude|Sign in to Claude/i.test(text))
|
|
11046
|
+
return { kind: "sign-in", message: "Claude Code asks the owner to sign in" };
|
|
11047
|
+
}
|
|
11048
|
+
if (kind === "codex") {
|
|
11049
|
+
if (/not supported when using Codex with a ChatGPT account/i.test(text))
|
|
11050
|
+
return { kind: "model", message: "Codex reports the configured model is not supported by this ChatGPT account" };
|
|
11051
|
+
if (/Do you trust the contents of this directory\?/i.test(text))
|
|
11052
|
+
return { kind: "trust", message: "Codex asks to trust this repository" };
|
|
11053
|
+
if (/Update available!/i.test(text) && /Skip until next version/i.test(text))
|
|
11054
|
+
return { kind: "update", message: "Codex asks whether to update" };
|
|
11055
|
+
if (/Sign in with ChatGPT/i.test(text) && /(?:Use|Provide|Sign in with) an API key/i.test(text))
|
|
11056
|
+
return { kind: "sign-in", message: "Codex asks the owner to sign in" };
|
|
11057
|
+
}
|
|
11058
|
+
if (kind === "opencode" && /Select a provider to connect|Connect a provider/i.test(text))
|
|
11059
|
+
return { kind: "sign-in", message: "OpenCode asks the owner to connect a provider" };
|
|
11060
|
+
if (/model (?:is )?(?:not found|unavailable)|invalid model|unsupported model/i.test(text))
|
|
11061
|
+
return {
|
|
11062
|
+
kind: "model",
|
|
11063
|
+
message: `${kind === "claude" ? "Claude Code" : kind === "codex" ? "Codex" : "OpenCode"} reports a model problem`
|
|
11064
|
+
};
|
|
11065
|
+
return null;
|
|
11066
|
+
}
|
|
11067
|
+
|
|
11068
|
+
// src/opencode-model.ts
|
|
11069
|
+
import { stripVTControlCharacters as stripVTControlCharacters2 } from "node:util";
|
|
11070
|
+
var displayName = (value) => typeof value === "string" && !!value.trim() && !/[\r\n]/.test(value) && stripVTControlCharacters2(value) === value;
|
|
10702
11071
|
function providersFrom(raw, configuration) {
|
|
10703
11072
|
try {
|
|
10704
|
-
const catalog = JSON.parse(
|
|
10705
|
-
const config = JSON.parse(
|
|
11073
|
+
const catalog = JSON.parse(stripVTControlCharacters2(raw));
|
|
11074
|
+
const config = JSON.parse(stripVTControlCharacters2(configuration));
|
|
10706
11075
|
const providers = Array.isArray(catalog?.providers) ? catalog.providers.filter((provider) => provider && displayName(provider.id) && displayName(provider.name)) : [];
|
|
10707
11076
|
for (const [id, value] of Object.entries(config?.provider ?? {})) {
|
|
10708
11077
|
const name = value?.name;
|
|
@@ -10722,7 +11091,7 @@ function providersFrom(raw, configuration) {
|
|
|
10722
11091
|
}
|
|
10723
11092
|
function modelsFrom(raw, providers) {
|
|
10724
11093
|
const models = [];
|
|
10725
|
-
for (const match of
|
|
11094
|
+
for (const match of stripVTControlCharacters2(raw).matchAll(/^([^\s/#]+\/[^\s#]+)\r?\n(\{\r?\n[\s\S]*?^\})/gm)) {
|
|
10726
11095
|
try {
|
|
10727
11096
|
const metadata = JSON.parse(match[2] ?? "");
|
|
10728
11097
|
const id = match[1] ?? "";
|
|
@@ -10734,7 +11103,7 @@ function modelsFrom(raw, providers) {
|
|
|
10734
11103
|
return models;
|
|
10735
11104
|
}
|
|
10736
11105
|
function selectedModel(pane, models) {
|
|
10737
|
-
const lines =
|
|
11106
|
+
const lines = stripVTControlCharacters2(pane).split(`
|
|
10738
11107
|
`);
|
|
10739
11108
|
const footers = lines.flatMap((line, index) => {
|
|
10740
11109
|
const bordered = /^\s*╹/.test(lines[index + 1] ?? "");
|
|
@@ -10775,7 +11144,7 @@ async function verifyOpenCodeModel(io, pane, expected) {
|
|
|
10775
11144
|
}).catch(() => null);
|
|
10776
11145
|
if (reading?.code !== 0)
|
|
10777
11146
|
throw failure();
|
|
10778
|
-
const text =
|
|
11147
|
+
const text = stripVTControlCharacters2(reading.stdout);
|
|
10779
11148
|
if (/ProviderModelNotFoundError|Model not found:/i.test(text))
|
|
10780
11149
|
throw new UsageError(`OpenCode could not load profile model ${expected}; launch stopped`);
|
|
10781
11150
|
const selected = selectedModel(text, models);
|
|
@@ -10802,10 +11171,51 @@ var harnessArgs = (p) => [
|
|
|
10802
11171
|
"--model",
|
|
10803
11172
|
p.model,
|
|
10804
11173
|
...p.harness === "codex" ? ["-c", `model_reasoning_effort=${JSON.stringify(p.effort)}`] : p.harness === "claude" ? ["--effort", p.effort] : [],
|
|
10805
|
-
...p.extraArgs
|
|
11174
|
+
...p.harness === "codex" && !p.extraArgs.some((arg) => /^(?:check_for_update_on_startup\s*=|--config=check_for_update_on_startup=)/.test(arg)) ? ["-c", "check_for_update_on_startup=false"] : [],
|
|
11175
|
+
...herdrPermissionArgs(p)
|
|
10806
11176
|
];
|
|
10807
11177
|
var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : null;
|
|
10808
11178
|
var id = (v) => typeof v === "string" && /^[a-zA-Z0-9][a-zA-Z0-9:_-]{0,127}$/.test(v);
|
|
11179
|
+
function herdrWorktreesDirectory(env, configText) {
|
|
11180
|
+
const configured = configText ? worktreesDirectoryOf(configText) : null;
|
|
11181
|
+
const directory = configured ?? "~/.herdr/worktrees";
|
|
11182
|
+
const home = env.HOME;
|
|
11183
|
+
if (directory === "~")
|
|
11184
|
+
return home ?? directory;
|
|
11185
|
+
if (directory.startsWith("~/"))
|
|
11186
|
+
return home ? join2(home, directory.slice(2)) : directory;
|
|
11187
|
+
return directory;
|
|
11188
|
+
}
|
|
11189
|
+
function herdrWorktreePath(directory, repoName, branch) {
|
|
11190
|
+
return join2(directory, repoName, branch.replaceAll("/", "-"));
|
|
11191
|
+
}
|
|
11192
|
+
function worktreesDirectoryOf(text) {
|
|
11193
|
+
let inWorktrees = false;
|
|
11194
|
+
for (const raw of text.split(`
|
|
11195
|
+
`)) {
|
|
11196
|
+
const line = raw.trim();
|
|
11197
|
+
if (!line || line.startsWith("#"))
|
|
11198
|
+
continue;
|
|
11199
|
+
const table = line.match(/^\[([^\]]+)\]\s*(?:#.*)?$/);
|
|
11200
|
+
if (table) {
|
|
11201
|
+
inWorktrees = table[1]?.trim() === "worktrees";
|
|
11202
|
+
continue;
|
|
11203
|
+
}
|
|
11204
|
+
if (!inWorktrees)
|
|
11205
|
+
continue;
|
|
11206
|
+
const value = line.match(/^directory\s*=\s*("(?:[^"\\]|\\.)*"|'[^']*')\s*(?:#.*)?$/)?.[1];
|
|
11207
|
+
if (!value)
|
|
11208
|
+
continue;
|
|
11209
|
+
if (value.startsWith("'"))
|
|
11210
|
+
return value.slice(1, -1);
|
|
11211
|
+
try {
|
|
11212
|
+
return JSON.parse(value);
|
|
11213
|
+
} catch {
|
|
11214
|
+
return null;
|
|
11215
|
+
}
|
|
11216
|
+
}
|
|
11217
|
+
return null;
|
|
11218
|
+
}
|
|
10809
11219
|
function parseHerdrHandle(raw) {
|
|
10810
11220
|
let h = null;
|
|
10811
11221
|
try {
|
|
@@ -10853,6 +11263,7 @@ var credentialNames = (env, extra) => [
|
|
|
10853
11263
|
|
|
10854
11264
|
class Herdr {
|
|
10855
11265
|
io;
|
|
11266
|
+
setupShell = null;
|
|
10856
11267
|
constructor(io) {
|
|
10857
11268
|
this.io = io;
|
|
10858
11269
|
}
|
|
@@ -10865,7 +11276,7 @@ class Herdr {
|
|
|
10865
11276
|
throw new Error("no exec");
|
|
10866
11277
|
const out = await this.io.exec("herdr", args, { cwd: this.io.cwd, timeoutMs });
|
|
10867
11278
|
code = out.code;
|
|
10868
|
-
if (code === 0 && !out.stdout.trim() && !out.stderr.trim() && ["pane run", "pane report-agent"].includes(operation))
|
|
11279
|
+
if (code === 0 && !out.stdout.trim() && !out.stderr.trim() && ["pane run", "pane report-agent", "pane report-metadata"].includes(operation))
|
|
10869
11280
|
return {};
|
|
10870
11281
|
reply = object(JSON.parse(out.stdout || out.stderr));
|
|
10871
11282
|
} catch {
|
|
@@ -10920,7 +11331,8 @@ class Herdr {
|
|
|
10920
11331
|
input.branch,
|
|
10921
11332
|
"--base",
|
|
10922
11333
|
input.base,
|
|
10923
|
-
"--no-focus"
|
|
11334
|
+
"--no-focus",
|
|
11335
|
+
...input.label ? ["--label", input.label] : []
|
|
10924
11336
|
])).result);
|
|
10925
11337
|
const workspace = object(r?.workspace)?.workspace_id;
|
|
10926
11338
|
const rootPane = object(r?.root_pane)?.pane_id;
|
|
@@ -10945,7 +11357,113 @@ class Herdr {
|
|
|
10945
11357
|
await this.call(["pane", "close", rootPane]);
|
|
10946
11358
|
return { workspace, pane, agent, path };
|
|
10947
11359
|
}
|
|
10948
|
-
async
|
|
11360
|
+
async setupRoot(repo, slug, secrets) {
|
|
11361
|
+
const result = object((await this.call(["worktree", "list", "--cwd", repo])).result);
|
|
11362
|
+
const source = object(result?.source);
|
|
11363
|
+
if (source?.source_checkout_path !== repo || typeof source.repo_root !== "string" || !source.repo_root.startsWith("/") || !Array.isArray(result?.worktrees))
|
|
11364
|
+
throw new UsageError("invalid herdr worktree list response; inspect herdr worktree list before setup");
|
|
11365
|
+
const branch = `armada-local-setup-${slug}`;
|
|
11366
|
+
const label = `Armada local setup checkout: ${slug}`;
|
|
11367
|
+
const found = result.worktrees.map(object).find((tree) => tree?.branch === branch);
|
|
11368
|
+
let path;
|
|
11369
|
+
if (found) {
|
|
11370
|
+
if (found.is_linked_worktree !== true || typeof found.path !== "string" || !found.path.startsWith("/"))
|
|
11371
|
+
throw new UsageError(`the setup branch ${branch} already exists outside Armada setup; leave it untouched and choose another project slug`);
|
|
11372
|
+
path = found.path;
|
|
11373
|
+
} else {
|
|
11374
|
+
path = (await this.create({ repo, branch, base: "HEAD", ticket: "setup-local", secrets, label })).path;
|
|
11375
|
+
}
|
|
11376
|
+
const root = dirname2(path);
|
|
11377
|
+
if (root === "/" || [...root].some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127))
|
|
11378
|
+
throw new UsageError("invalid herdr worktree parent directory");
|
|
11379
|
+
return { root, repo: source.repo_root };
|
|
11380
|
+
}
|
|
11381
|
+
async setupWorkspace(root, secrets) {
|
|
11382
|
+
const label = `Armada local setup: ${root}`;
|
|
11383
|
+
const workspaces = object((await this.call(["workspace", "list"])).result)?.workspaces;
|
|
11384
|
+
if (!Array.isArray(workspaces))
|
|
11385
|
+
throw new UsageError("invalid herdr workspace list response");
|
|
11386
|
+
const matches = workspaces.map(object).filter((ws) => ws?.label === label);
|
|
11387
|
+
if (matches.length > 1)
|
|
11388
|
+
throw new UsageError("multiple local setup workspaces; inspect herdr workspace list before retrying");
|
|
11389
|
+
if (matches.length) {
|
|
11390
|
+
const workspace = matches[0]?.workspace_id;
|
|
11391
|
+
if (!id(workspace))
|
|
11392
|
+
throw new UsageError("invalid herdr setup workspace response");
|
|
11393
|
+
return workspace;
|
|
11394
|
+
}
|
|
11395
|
+
const result = object((await this.call([
|
|
11396
|
+
"workspace",
|
|
11397
|
+
"create",
|
|
11398
|
+
"--cwd",
|
|
11399
|
+
root,
|
|
11400
|
+
"--label",
|
|
11401
|
+
label,
|
|
11402
|
+
"--no-focus",
|
|
11403
|
+
...credentialNames(this.io.env, secrets).flatMap((name) => ["--env", `${name}=`]),
|
|
11404
|
+
"--env",
|
|
11405
|
+
"ARMADA_TICKET="
|
|
11406
|
+
])).result);
|
|
11407
|
+
const workspace = object(result?.workspace)?.workspace_id;
|
|
11408
|
+
const pane = object(result?.root_pane);
|
|
11409
|
+
if (!id(workspace) || !id(pane?.pane_id) || pane?.workspace_id !== workspace)
|
|
11410
|
+
throw new UsageError("invalid herdr setup workspace response");
|
|
11411
|
+
this.setupShell = { workspace, pane: String(pane?.pane_id) };
|
|
11412
|
+
return workspace;
|
|
11413
|
+
}
|
|
11414
|
+
async setupPane(workspace, root, profile, secrets) {
|
|
11415
|
+
const kind = herdrHarnessKind(profile.harness);
|
|
11416
|
+
const fingerprint = createHash3("sha256").update(JSON.stringify([kind, ...harnessArgs(profile)])).digest("hex").slice(0, 32);
|
|
11417
|
+
const name = `setup-${workspace}-${kind}`;
|
|
11418
|
+
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(name))
|
|
11419
|
+
throw new UsageError("cannot name the setup agent for this workspace");
|
|
11420
|
+
const agents = object((await this.call(["agent", "list"])).result)?.agents;
|
|
11421
|
+
if (!Array.isArray(agents))
|
|
11422
|
+
throw new UsageError("invalid herdr agent list response");
|
|
11423
|
+
const matches = agents.map(object).filter((agent) => agent?.name === name);
|
|
11424
|
+
if (matches.length > 1)
|
|
11425
|
+
throw new UsageError("multiple setup agents; inspect herdr agent list");
|
|
11426
|
+
if (matches.length) {
|
|
11427
|
+
const agent = matches[0];
|
|
11428
|
+
if (agent?.workspace_id !== workspace || !id(agent.pane_id) || agent.cwd !== root || agent.agent !== kind)
|
|
11429
|
+
throw new UsageError("setup agent identity or directory changed; inspect herdr agent list before retrying");
|
|
11430
|
+
if (object(agent.tokens)?.armadaSetup !== fingerprint)
|
|
11431
|
+
throw new UsageError(`the ${kind} setup session uses different launch settings; close its pane ${agent.pane_id} in herdr, then rerun armada setup local to check the current profile`);
|
|
11432
|
+
return { handle: { workspace, pane: agent.pane_id, agent: name, path: root }, existing: true };
|
|
11433
|
+
}
|
|
11434
|
+
const result = object((await this.call([
|
|
11435
|
+
"tab",
|
|
11436
|
+
"create",
|
|
11437
|
+
"--workspace",
|
|
11438
|
+
workspace,
|
|
11439
|
+
"--cwd",
|
|
11440
|
+
root,
|
|
11441
|
+
"--label",
|
|
11442
|
+
kind,
|
|
11443
|
+
"--no-focus",
|
|
11444
|
+
...credentialNames(this.io.env, secrets).flatMap((key) => ["--env", `${key}=`]),
|
|
11445
|
+
"--env",
|
|
11446
|
+
"ARMADA_TICKET="
|
|
11447
|
+
])).result);
|
|
11448
|
+
const pane = object(result?.root_pane);
|
|
11449
|
+
if (!id(pane?.pane_id) || pane?.workspace_id !== workspace)
|
|
11450
|
+
throw new UsageError("invalid herdr setup pane response");
|
|
11451
|
+
await this.call([
|
|
11452
|
+
"pane",
|
|
11453
|
+
"report-metadata",
|
|
11454
|
+
pane.pane_id,
|
|
11455
|
+
"--source",
|
|
11456
|
+
"armada-setup",
|
|
11457
|
+
"--token",
|
|
11458
|
+
`armadaSetup=${fingerprint}`
|
|
11459
|
+
]);
|
|
11460
|
+
if (this.setupShell?.workspace === workspace) {
|
|
11461
|
+
await this.call(["pane", "close", this.setupShell.pane]);
|
|
11462
|
+
this.setupShell = null;
|
|
11463
|
+
}
|
|
11464
|
+
return { handle: { workspace, pane: pane.pane_id, agent: name, path: root }, existing: false };
|
|
11465
|
+
}
|
|
11466
|
+
async start(handle, profile, timeoutMs = 30000, verifyModel = true) {
|
|
10949
11467
|
const r = await this.call([
|
|
10950
11468
|
"agent",
|
|
10951
11469
|
"start",
|
|
@@ -10955,12 +11473,12 @@ class Herdr {
|
|
|
10955
11473
|
"--pane",
|
|
10956
11474
|
handle.pane,
|
|
10957
11475
|
"--timeout",
|
|
10958
|
-
|
|
11476
|
+
String(timeoutMs),
|
|
10959
11477
|
"--",
|
|
10960
11478
|
...harnessArgs(profile)
|
|
10961
11479
|
]);
|
|
10962
11480
|
this.checkAgent(r, handle);
|
|
10963
|
-
if (herdrHarnessKind(profile.harness) === "opencode") {
|
|
11481
|
+
if (verifyModel && herdrHarnessKind(profile.harness) === "opencode") {
|
|
10964
11482
|
try {
|
|
10965
11483
|
await verifyOpenCodeModel(this.io, handle.pane, profile.model);
|
|
10966
11484
|
} catch (error) {
|
|
@@ -10973,11 +11491,121 @@ class Herdr {
|
|
|
10973
11491
|
}
|
|
10974
11492
|
}
|
|
10975
11493
|
}
|
|
11494
|
+
async inspect(handle, harness) {
|
|
11495
|
+
const agent = this.checkAgent(await this.call(["agent", "get", handle.pane], 5000), handle);
|
|
11496
|
+
if (agent.agent !== undefined && agent.agent !== null && agent.agent !== herdrHarnessKind(harness))
|
|
11497
|
+
throw new UsageError("herdr worker harness changed; inspect herdr agent list before retrying");
|
|
11498
|
+
const state = agent.agent_status;
|
|
11499
|
+
if (!["working", "blocked", "idle", "done", "unknown"].includes(String(state)))
|
|
11500
|
+
throw new UsageError("invalid herdr agent state");
|
|
11501
|
+
let text;
|
|
11502
|
+
try {
|
|
11503
|
+
if (!this.io.exec)
|
|
11504
|
+
throw new Error("no exec");
|
|
11505
|
+
const result = await this.io.exec("herdr", ["pane", "read", handle.pane, "--source", "visible", "--lines", "80"], {
|
|
11506
|
+
cwd: this.io.cwd,
|
|
11507
|
+
timeoutMs: 5000
|
|
11508
|
+
});
|
|
11509
|
+
if (result.code !== 0)
|
|
11510
|
+
throw new Error("read failed");
|
|
11511
|
+
text = result.stdout;
|
|
11512
|
+
} catch {
|
|
11513
|
+
throw new UsageError(`could not inspect the worker screen; run herdr agent attach ${handle.agent}`);
|
|
11514
|
+
}
|
|
11515
|
+
return {
|
|
11516
|
+
state,
|
|
11517
|
+
ready: (state === "idle" || state === "done") && agent.interactive_ready !== false && agent.launch_pending !== true,
|
|
11518
|
+
issue: firstRunIssue(harness, text)
|
|
11519
|
+
};
|
|
11520
|
+
}
|
|
11521
|
+
screenError(handle, issue, message = "The harness needs the owner's attention") {
|
|
11522
|
+
return new UsageError(`${issue?.message ?? message}: run armada setup local, or answer it with herdr agent attach ${handle.agent}`, `herdr agent attach ${handle.agent}`);
|
|
11523
|
+
}
|
|
11524
|
+
async checkProfileModel(handle, profile) {
|
|
11525
|
+
if (herdrHarnessKind(profile.harness) !== "opencode")
|
|
11526
|
+
return;
|
|
11527
|
+
try {
|
|
11528
|
+
await verifyOpenCodeModel(this.io, handle.pane, profile.model);
|
|
11529
|
+
} catch (error) {
|
|
11530
|
+
const screen = await this.inspect(handle, profile.harness);
|
|
11531
|
+
throw this.screenError(handle, screen.issue, error instanceof UsageError ? error.message : "Could not verify the OpenCode profile model");
|
|
11532
|
+
}
|
|
11533
|
+
}
|
|
11534
|
+
async startChecked(handle, profile) {
|
|
11535
|
+
try {
|
|
11536
|
+
await this.start(handle, profile, 3500, false);
|
|
11537
|
+
} catch (error) {
|
|
11538
|
+
if (!(error instanceof HerdrError) || !["agent_not_ready", "timeout"].includes(error.code ?? ""))
|
|
11539
|
+
throw error;
|
|
11540
|
+
}
|
|
11541
|
+
const now = this.io.now ?? (() => new Date);
|
|
11542
|
+
const deadline = now().getTime() + 30000;
|
|
11543
|
+
for (let attempt = 0;attempt < 120 && now().getTime() < deadline; attempt++) {
|
|
11544
|
+
const screen = await this.inspect(handle, profile.harness);
|
|
11545
|
+
if (screen.issue || screen.state === "blocked")
|
|
11546
|
+
throw this.screenError(handle, screen.issue);
|
|
11547
|
+
if (screen.ready) {
|
|
11548
|
+
await this.checkProfileModel(handle, profile);
|
|
11549
|
+
return;
|
|
11550
|
+
}
|
|
11551
|
+
await (this.io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))))(250);
|
|
11552
|
+
}
|
|
11553
|
+
throw this.screenError(handle, null, "The harness did not become ready");
|
|
11554
|
+
}
|
|
11555
|
+
async promptChecked(handle, profile, prompt) {
|
|
11556
|
+
const before = await this.inspect(handle, profile.harness);
|
|
11557
|
+
if (before.issue || !before.ready)
|
|
11558
|
+
throw this.screenError(handle, before.issue);
|
|
11559
|
+
await this.checkProfileModel(handle, profile);
|
|
11560
|
+
try {
|
|
11561
|
+
await this.prompt(handle, prompt);
|
|
11562
|
+
} catch (error) {
|
|
11563
|
+
const screen = await this.inspect(handle, profile.harness);
|
|
11564
|
+
if (screen.issue || screen.state === "blocked")
|
|
11565
|
+
throw this.screenError(handle, screen.issue);
|
|
11566
|
+
if (error instanceof HerdrError && ["agent_prompt_stalled", "timeout"].includes(error.code ?? ""))
|
|
11567
|
+
throw this.screenError(handle, null, "The harness did not accept the brief");
|
|
11568
|
+
throw error;
|
|
11569
|
+
}
|
|
11570
|
+
}
|
|
11571
|
+
async checkSetupModel(handle, profile) {
|
|
11572
|
+
const screen = await this.inspect(handle, profile.harness);
|
|
11573
|
+
if (screen.issue || !screen.ready)
|
|
11574
|
+
throw this.screenError(handle, screen.issue);
|
|
11575
|
+
await this.checkProfileModel(handle, profile);
|
|
11576
|
+
try {
|
|
11577
|
+
const agent = this.checkAgent(await this.call([
|
|
11578
|
+
"agent",
|
|
11579
|
+
"prompt",
|
|
11580
|
+
handle.pane,
|
|
11581
|
+
"Reply with OK only. Do not read files, run commands or modify anything.",
|
|
11582
|
+
"--wait",
|
|
11583
|
+
"--until",
|
|
11584
|
+
"idle",
|
|
11585
|
+
"--until",
|
|
11586
|
+
"done",
|
|
11587
|
+
"--timeout",
|
|
11588
|
+
"10000"
|
|
11589
|
+
], 12000), handle);
|
|
11590
|
+
const after = await this.inspect(handle, profile.harness);
|
|
11591
|
+
if (after.issue)
|
|
11592
|
+
throw this.screenError(handle, after.issue);
|
|
11593
|
+
if (!["idle", "done"].includes(String(agent.agent_status)) || !after.ready)
|
|
11594
|
+
throw this.screenError(handle, null, "The model did not finish the setup check");
|
|
11595
|
+
} catch (error) {
|
|
11596
|
+
const after = await this.inspect(handle, profile.harness);
|
|
11597
|
+
if (after.issue)
|
|
11598
|
+
throw this.screenError(handle, after.issue);
|
|
11599
|
+
if (error instanceof UsageError && !(error instanceof HerdrError))
|
|
11600
|
+
throw error;
|
|
11601
|
+
throw this.screenError(handle, null, "The model did not finish the setup check");
|
|
11602
|
+
}
|
|
11603
|
+
}
|
|
10976
11604
|
async prompt(handle, prompt) {
|
|
10977
11605
|
const r = await this.call([
|
|
10978
11606
|
"agent",
|
|
10979
11607
|
"prompt",
|
|
10980
|
-
handle.
|
|
11608
|
+
handle.pane,
|
|
10981
11609
|
prompt,
|
|
10982
11610
|
"--wait",
|
|
10983
11611
|
"--until",
|
|
@@ -11738,7 +12366,7 @@ async function watchUntil(io, config, credentials, json, configPath) {
|
|
|
11738
12366
|
if (!fleet)
|
|
11739
12367
|
throw new Refusal(`the inbox is on Armada, which cannot be reached: ${warning ?? "no answer"}`, "armada whoami");
|
|
11740
12368
|
const before = paths ? await readWatchState(paths, project) : null;
|
|
11741
|
-
await remember(io, project, { root:
|
|
12369
|
+
await remember(io, project, { root: dirname3(configPath), stopped: null });
|
|
11742
12370
|
const report = await watchInbox(observingFleet(watchingIo, fleet), {
|
|
11743
12371
|
project,
|
|
11744
12372
|
signal: controller.signal,
|
|
@@ -11812,7 +12440,7 @@ async function hookStop(io, rest, findConfig) {
|
|
|
11812
12440
|
const { path, text } = await findConfig({ ...io, cwd });
|
|
11813
12441
|
const project = parseConfig(text, path).project.slug;
|
|
11814
12442
|
const { state, running } = await watchOf(io, project);
|
|
11815
|
-
const d = stopHookDecision({ project, root:
|
|
12443
|
+
const d = stopHookDecision({ project, root: dirname3(path), state, watching: running, env: io.env });
|
|
11816
12444
|
if (d.block)
|
|
11817
12445
|
io.stdout(`${JSON.stringify({ decision: "block", reason: d.reason })}
|
|
11818
12446
|
`);
|
|
@@ -11941,7 +12569,7 @@ async function brief(io, config, credentials, a, version, configPath) {
|
|
|
11941
12569
|
if (!credentials.linearApiKey)
|
|
11942
12570
|
throw missingKey(LINEAR_KEY);
|
|
11943
12571
|
const extraPath = config.brief.extra;
|
|
11944
|
-
const conventions = extraPath ? { path: extraPath, text: await io.readFile(
|
|
12572
|
+
const conventions = extraPath ? { path: extraPath, text: await io.readFile(join3(dirname4(configPath), extraPath)).catch(() => null) } : null;
|
|
11945
12573
|
let b;
|
|
11946
12574
|
try {
|
|
11947
12575
|
b = await loadBrief(config, {
|
|
@@ -12009,10 +12637,10 @@ ${next.line}
|
|
|
12009
12637
|
}
|
|
12010
12638
|
|
|
12011
12639
|
// src/doctor.ts
|
|
12012
|
-
import { join as
|
|
12640
|
+
import { join as join5 } from "node:path";
|
|
12013
12641
|
|
|
12014
12642
|
// src/local-tools.ts
|
|
12015
|
-
import { stripVTControlCharacters as
|
|
12643
|
+
import { stripVTControlCharacters as stripVTControlCharacters3 } from "node:util";
|
|
12016
12644
|
var MINIMUM_HERDR_VERSION = "0.9.1";
|
|
12017
12645
|
var TOOLS = {
|
|
12018
12646
|
herdr: { command: "herdr", install: "curl -fsSL https://herdr.dev/install.sh | sh" },
|
|
@@ -12128,7 +12756,7 @@ async function openCodeModels(io) {
|
|
|
12128
12756
|
if (result?.code !== 0)
|
|
12129
12757
|
return null;
|
|
12130
12758
|
return [
|
|
12131
|
-
...new Set(
|
|
12759
|
+
...new Set(stripVTControlCharacters3(result.stdout).split(`
|
|
12132
12760
|
`).map((line) => line.trim()).filter((line) => /^[^\s/#]+\/[^\s#]+$/.test(line)))
|
|
12133
12761
|
];
|
|
12134
12762
|
}
|
|
@@ -12136,7 +12764,7 @@ async function claudeModels(io) {
|
|
|
12136
12764
|
const result = await probe(io, "claude", ["--help"], { timeoutMs: 5000, maxOutputBytes: 262144 });
|
|
12137
12765
|
if (result?.code !== 0)
|
|
12138
12766
|
return null;
|
|
12139
|
-
const help =
|
|
12767
|
+
const help = stripVTControlCharacters3(result.stdout);
|
|
12140
12768
|
const option = help.match(/(?:^|\n)\s+--model\s+<model>([\s\S]*?)(?=\n\s+--?[a-zA-Z]|$)/)?.[1];
|
|
12141
12769
|
if (!option)
|
|
12142
12770
|
return null;
|
|
@@ -12328,14 +12956,14 @@ async function ensureLocalProfile(io, configPath, name, profile) {
|
|
|
12328
12956
|
|
|
12329
12957
|
// src/repo.ts
|
|
12330
12958
|
import { lstat, mkdir as mkdir2, readdir, readFile as readFile2, readlink, rm as rm2, symlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
12331
|
-
import { dirname as
|
|
12959
|
+
import { dirname as dirname5, join as join4, relative, sep } from "node:path";
|
|
12332
12960
|
var absent = (err) => {
|
|
12333
12961
|
const code = err.code;
|
|
12334
12962
|
return code === "ENOENT" || code === "ENOTDIR" || code === "EISDIR";
|
|
12335
12963
|
};
|
|
12336
12964
|
async function collect(base, dir, out) {
|
|
12337
12965
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
12338
|
-
const full =
|
|
12966
|
+
const full = join4(dir, entry.name);
|
|
12339
12967
|
if (entry.isDirectory()) {
|
|
12340
12968
|
if (![".git", "node_modules", "__pycache__"].includes(entry.name))
|
|
12341
12969
|
await collect(base, full, out);
|
|
@@ -12345,12 +12973,12 @@ async function collect(base, dir, out) {
|
|
|
12345
12973
|
}
|
|
12346
12974
|
function fsRepoView(root) {
|
|
12347
12975
|
return {
|
|
12348
|
-
readFile: (path) => readFile2(
|
|
12976
|
+
readFile: (path) => readFile2(join4(root, path), "utf8").catch((err) => {
|
|
12349
12977
|
if (absent(err))
|
|
12350
12978
|
return null;
|
|
12351
12979
|
throw err;
|
|
12352
12980
|
}),
|
|
12353
|
-
readLink: (path) => readlink(
|
|
12981
|
+
readLink: (path) => readlink(join4(root, path)).catch((err) => {
|
|
12354
12982
|
if (absent(err) || err.code === "EINVAL")
|
|
12355
12983
|
return null;
|
|
12356
12984
|
throw err;
|
|
@@ -12358,7 +12986,7 @@ function fsRepoView(root) {
|
|
|
12358
12986
|
readFolder: async (path) => {
|
|
12359
12987
|
const out = [];
|
|
12360
12988
|
try {
|
|
12361
|
-
await collect(
|
|
12989
|
+
await collect(join4(root, path), join4(root, path), out);
|
|
12362
12990
|
} catch (err) {
|
|
12363
12991
|
if (absent(err))
|
|
12364
12992
|
return null;
|
|
@@ -12372,7 +13000,7 @@ async function assertNoLinkedParent(root, path) {
|
|
|
12372
13000
|
const parts = path.split("/").slice(0, -1);
|
|
12373
13001
|
for (let k = 1;k <= parts.length; k++) {
|
|
12374
13002
|
const parent = parts.slice(0, k).join("/");
|
|
12375
|
-
if ((await lstat(
|
|
13003
|
+
if ((await lstat(join4(root, parent)).catch(() => null))?.isSymbolicLink())
|
|
12376
13004
|
throw new CommandError(`${parent} is a link; Armada does not write through it. Replace it with a folder first.`);
|
|
12377
13005
|
}
|
|
12378
13006
|
}
|
|
@@ -12380,18 +13008,18 @@ async function applyPlan(root, plan) {
|
|
|
12380
13008
|
for (const path of [...plan.removes, ...plan.writes.map((w) => w.path), ...plan.links.map((l) => l.path)])
|
|
12381
13009
|
await assertNoLinkedParent(root, path);
|
|
12382
13010
|
for (const w of plan.writes)
|
|
12383
|
-
if ((await lstat(
|
|
13011
|
+
if ((await lstat(join4(root, w.path)).catch(() => null))?.isSymbolicLink())
|
|
12384
13012
|
throw new CommandError(`${w.path} is a link; Armada does not write through it. Replace it with a file first.`);
|
|
12385
13013
|
for (const path of plan.removes)
|
|
12386
|
-
await rm2(
|
|
13014
|
+
await rm2(join4(root, path), { force: true });
|
|
12387
13015
|
for (const w of plan.writes) {
|
|
12388
|
-
const full =
|
|
12389
|
-
await mkdir2(
|
|
13016
|
+
const full = join4(root, w.path);
|
|
13017
|
+
await mkdir2(dirname5(full), { recursive: true });
|
|
12390
13018
|
await writeFile2(full, w.content);
|
|
12391
13019
|
}
|
|
12392
13020
|
for (const l of plan.links) {
|
|
12393
|
-
const full =
|
|
12394
|
-
await mkdir2(
|
|
13021
|
+
const full = join4(root, l.path);
|
|
13022
|
+
await mkdir2(dirname5(full), { recursive: true });
|
|
12395
13023
|
if (await lstat(full).catch(() => null))
|
|
12396
13024
|
await rm2(full, { recursive: true, force: true });
|
|
12397
13025
|
await symlink(l.target, full);
|
|
@@ -12654,7 +13282,7 @@ async function localRuntimeChecks(io, config, options = { readOnly: true }) {
|
|
|
12654
13282
|
if (!harnesses.length)
|
|
12655
13283
|
return [];
|
|
12656
13284
|
const result = await offerLocalInstalls(io, await detectLocalTools(io, harnesses, config ? localModelProfiles(config) : []), options);
|
|
12657
|
-
const selected = await offerLocalModels(io, result, options.configPath ??
|
|
13285
|
+
const selected = await offerLocalModels(io, result, options.configPath ?? join5(io.cwd, CONFIG_FILE), options);
|
|
12658
13286
|
return [
|
|
12659
13287
|
...selected.checks,
|
|
12660
13288
|
...harnesses.some((harness) => harness === "opencode" || harness === "deepseek") ? [
|
|
@@ -12699,7 +13327,7 @@ async function buildDoctor(io, armadaVersion, options = { readOnly: true }) {
|
|
|
12699
13327
|
...keyFileChecks(machine, credentials),
|
|
12700
13328
|
...await labelChecks(io, config, credentials),
|
|
12701
13329
|
...await conductorChecks(io, config),
|
|
12702
|
-
...await localRuntimeChecks(io, config, { ...options, configPath:
|
|
13330
|
+
...await localRuntimeChecks(io, config, { ...options, configPath: join5(root, CONFIG_FILE) }),
|
|
12703
13331
|
...config ? await reviewRuntimeChecks(io, root) : [],
|
|
12704
13332
|
...await secretChecks(api, config, credentials)
|
|
12705
13333
|
];
|
|
@@ -12732,6 +13360,8 @@ function renderDoctor(r) {
|
|
|
12732
13360
|
const errors = r.checks.filter((c) => c.level === "error");
|
|
12733
13361
|
if (errors.length)
|
|
12734
13362
|
lines.push(errors.some((c) => c.fix?.includes("armada init")) ? "Next: armada init, which opens one pull request with the fixes it can make" : `Next: ${errors[0]?.fix}`);
|
|
13363
|
+
if (r.checks.some((c) => c.id === "local-herdr"))
|
|
13364
|
+
lines.push("Local first-run setup: armada setup local — the owner answers trust, updates, project MCP, sign-in and model questions in herdr; new worktrees may still ask once.");
|
|
12735
13365
|
return `${lines.join(`
|
|
12736
13366
|
`)}
|
|
12737
13367
|
`;
|
|
@@ -12744,7 +13374,7 @@ async function doctor(io, json, armadaVersion) {
|
|
|
12744
13374
|
}
|
|
12745
13375
|
|
|
12746
13376
|
// src/heartbeat.ts
|
|
12747
|
-
import { createHash as
|
|
13377
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
12748
13378
|
async function heartbeat(io, config, credentials, args) {
|
|
12749
13379
|
if (args.rest.length)
|
|
12750
13380
|
throw new UsageError("heartbeat takes no positional argument");
|
|
@@ -12812,7 +13442,7 @@ async function heartbeat(io, config, credentials, args) {
|
|
|
12812
13442
|
return result;
|
|
12813
13443
|
},
|
|
12814
13444
|
ready: async (session) => {
|
|
12815
|
-
const name = `${config.project.slug}-heartbeat-${ticket.toLowerCase()}-${
|
|
13445
|
+
const name = `${config.project.slug}-heartbeat-${ticket.toLowerCase()}-${createHash4("sha256").update(`${handle}/${session.claimedAt}`).digest("hex").slice(0, 12)}`;
|
|
12816
13446
|
const acquired = await takeWatchLock(paths, name, pid, io.processAlive ?? processAlive);
|
|
12817
13447
|
if (acquired.taken)
|
|
12818
13448
|
lock = name;
|
|
@@ -12838,7 +13468,7 @@ async function heartbeat(io, config, credentials, args) {
|
|
|
12838
13468
|
// src/init.ts
|
|
12839
13469
|
import { mkdtemp, realpath, rm as rm3 } from "node:fs/promises";
|
|
12840
13470
|
import { tmpdir } from "node:os";
|
|
12841
|
-
import { join as
|
|
13471
|
+
import { join as join6 } from "node:path";
|
|
12842
13472
|
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] ";
|
|
12843
13473
|
async function wantsStopHook(io, opts) {
|
|
12844
13474
|
if (opts.stopHook !== null)
|
|
@@ -12871,7 +13501,7 @@ async function resolveConfig(exec, root, checkout, opts) {
|
|
|
12871
13501
|
return { config: parse(onDefault, `${CONFIG_FILE} on the default branch`), text: null, source: "default branch" };
|
|
12872
13502
|
const local = await fsRepoView(root).readFile(CONFIG_FILE);
|
|
12873
13503
|
if (local !== null && !opts.programRoot)
|
|
12874
|
-
return { config: parse(local,
|
|
13504
|
+
return { config: parse(local, join6(root, CONFIG_FILE)), text: local, source: "working tree" };
|
|
12875
13505
|
const branch = initBranch(opts.armadaVersion);
|
|
12876
13506
|
if (!opts.programRoot && await sh(exec, root, "git", ["ls-remote", "origin", `refs/heads/${branch}`])) {
|
|
12877
13507
|
await sh(exec, root, "git", ["fetch", "--quiet", "origin", branch]);
|
|
@@ -12942,7 +13572,7 @@ async function init(io, opts) {
|
|
|
12942
13572
|
const base = await defaultBranch(exec, root);
|
|
12943
13573
|
await sh(exec, root, "git", ["fetch", "--quiet", "origin", base]);
|
|
12944
13574
|
const baseSha = await sh(exec, root, "git", ["rev-parse", "FETCH_HEAD"]);
|
|
12945
|
-
const checkout = await realpath(await mkdtemp(
|
|
13575
|
+
const checkout = await realpath(await mkdtemp(join6(tmpdir(), "armada-init-")));
|
|
12946
13576
|
try {
|
|
12947
13577
|
await sh(exec, root, "git", ["worktree", "add", "--quiet", "--detach", checkout, baseSha]);
|
|
12948
13578
|
const { config, text, source } = await resolveConfig(exec, root, checkout, opts);
|
|
@@ -13045,7 +13675,7 @@ async function init(io, opts) {
|
|
|
13045
13675
|
}
|
|
13046
13676
|
|
|
13047
13677
|
// src/launch.ts
|
|
13048
|
-
import { dirname as
|
|
13678
|
+
import { basename, dirname as dirname6, join as join7 } from "node:path";
|
|
13049
13679
|
async function launch(io, config, credentials, args, version, configPath) {
|
|
13050
13680
|
if (args.rest[0] !== "revoke")
|
|
13051
13681
|
return launchLocal(io, config, credentials, args, version, configPath);
|
|
@@ -13136,6 +13766,8 @@ async function launchLocal(io, config, credentials, args, version, configPath) {
|
|
|
13136
13766
|
throw new UsageError("local launch needs a [herdr.profiles.<name>] with harness, model and effort");
|
|
13137
13767
|
if (o.harness && o.harness !== choice.profile.harness)
|
|
13138
13768
|
throw new UsageError(`profile "${choice.name}" uses ${choice.profile.harness}; choose a matching --profile with --reason to change harness`);
|
|
13769
|
+
if (o["dry-run"] === "true")
|
|
13770
|
+
return await launchPlan(io, args.json, { ticketId, choice, branch, version });
|
|
13139
13771
|
const execute = io.exec;
|
|
13140
13772
|
const preflight = {
|
|
13141
13773
|
...io,
|
|
@@ -13162,7 +13794,7 @@ async function launchLocal(io, config, credentials, args, version, configPath) {
|
|
|
13162
13794
|
const base = remote.code === 0 ? remote.stdout.match(/^ref:\s+refs\/heads\/(\S+)\s+HEAD/m)?.[1] : null;
|
|
13163
13795
|
if (!base)
|
|
13164
13796
|
throw new UsageError("could not read the default branch of origin");
|
|
13165
|
-
const conventions = config.brief.extra ? { path: config.brief.extra, text: await io.readFile(
|
|
13797
|
+
const conventions = config.brief.extra ? { path: config.brief.extra, text: await io.readFile(join7(dirname6(configPath), config.brief.extra)) } : null;
|
|
13166
13798
|
const npm = await checkPublished(version, io.fetch ?? fetch);
|
|
13167
13799
|
if (npm.state === "missing")
|
|
13168
13800
|
throw new UsageError(`armada ${version} is not on npm yet; publish this version before launching local workers`);
|
|
@@ -13174,7 +13806,7 @@ async function launchLocal(io, config, credentials, args, version, configPath) {
|
|
|
13174
13806
|
await runtime.ensureServer();
|
|
13175
13807
|
handle = await runtime.create({ repo, branch, base, ticket: ticketId, secrets: config.secrets.names });
|
|
13176
13808
|
if (configSnapshot !== null && io.writeFile)
|
|
13177
|
-
await io.writeFile(
|
|
13809
|
+
await io.writeFile(join7(handle.path, CONFIG_FILE), configSnapshot);
|
|
13178
13810
|
const b = buildBrief({
|
|
13179
13811
|
config,
|
|
13180
13812
|
ticket,
|
|
@@ -13193,13 +13825,23 @@ async function launchLocal(io, config, credentials, args, version, configPath) {
|
|
|
13193
13825
|
},
|
|
13194
13826
|
herdr: { choice, handle: herdrClaimHandle(handle) }
|
|
13195
13827
|
});
|
|
13196
|
-
await runtime.
|
|
13197
|
-
await runtime.
|
|
13828
|
+
await runtime.startChecked(handle, choice.profile);
|
|
13829
|
+
await runtime.promptChecked(handle, choice.profile, b.prompt);
|
|
13198
13830
|
} catch (error) {
|
|
13199
13831
|
if (handle)
|
|
13200
13832
|
io.stderr(`armada: local workspace retained: ${herdrClaimHandle(handle)}
|
|
13201
13833
|
`);
|
|
13202
|
-
|
|
13834
|
+
let revoked = false;
|
|
13835
|
+
try {
|
|
13836
|
+
await api.revokePendingLaunch(signIn, { project: config.project.slug, ticket: ticketId, id: launch.worker.id });
|
|
13837
|
+
revoked = true;
|
|
13838
|
+
io.stderr(`armada: revoked the pending launch of ${ticketId}.
|
|
13839
|
+
`);
|
|
13840
|
+
} catch {
|
|
13841
|
+
io.stderr(`armada: could not revoke the pending launch; run armada launch revoke ${ticketId} before retrying (a claimed worker must release).
|
|
13842
|
+
`);
|
|
13843
|
+
}
|
|
13844
|
+
throw new UsageError(error instanceof UsageError || error instanceof BriefError ? error.message : "local worker launch failed", !revoked ? `armada launch revoke ${ticketId}` : handle ? `herdr agent attach ${handle.agent}` : "herdr agent list");
|
|
13203
13845
|
}
|
|
13204
13846
|
const known = (await watchOf(io, config.project.slug)).state?.inFlight ?? [];
|
|
13205
13847
|
const inFlightTickets = [...new Set([...known, ticketId])].sort();
|
|
@@ -13227,12 +13869,208 @@ ${watch.line}
|
|
|
13227
13869
|
`);
|
|
13228
13870
|
return 0;
|
|
13229
13871
|
}
|
|
13872
|
+
async function launchPlan(io, json, input) {
|
|
13873
|
+
const openCode = herdrHarnessKind(input.choice.profile.harness) === "opencode";
|
|
13874
|
+
const detected = await detectLocalTools(io, [input.choice.profile.harness], openCode ? [{ name: input.choice.name, harness: input.choice.profile.harness, model: input.choice.profile.model }] : []);
|
|
13875
|
+
const npm = await checkPublished(input.version, io.fetch ?? fetch);
|
|
13876
|
+
const describe = (checks) => checks.map((check) => `${check.message}${check.fix ? `: ${check.fix}` : ""}`);
|
|
13877
|
+
const gaps = describe(detected.checks.filter((check) => check.level === "error"));
|
|
13878
|
+
const warnings = describe(detected.checks.filter((check) => check.level === "warning"));
|
|
13879
|
+
if (npm.state === "missing")
|
|
13880
|
+
gaps.push(`armada ${input.version} is not on npm yet; publish this version before launching local workers`);
|
|
13881
|
+
let worktree = null;
|
|
13882
|
+
let base = null;
|
|
13883
|
+
try {
|
|
13884
|
+
const execute = io.exec;
|
|
13885
|
+
if (!execute)
|
|
13886
|
+
throw new UsageError("local launch needs process execution");
|
|
13887
|
+
const root = await execute("git", ["rev-parse", "--show-toplevel"], { cwd: io.cwd, timeoutMs: 1e4 });
|
|
13888
|
+
if (root.code !== 0 || !root.stdout.trim().startsWith("/"))
|
|
13889
|
+
throw new UsageError("local launch must run in a git repository");
|
|
13890
|
+
const repo = root.stdout.trim();
|
|
13891
|
+
const common = await execute("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], {
|
|
13892
|
+
cwd: repo,
|
|
13893
|
+
timeoutMs: 1e4
|
|
13894
|
+
});
|
|
13895
|
+
const mainRoot = common.code === 0 && common.stdout.trim().startsWith("/") ? dirname6(common.stdout.trim()) : repo;
|
|
13896
|
+
const remote = await execute("git", ["ls-remote", "--symref", "origin", "HEAD"], { cwd: repo, timeoutMs: 20000 });
|
|
13897
|
+
base = remote.code === 0 ? remote.stdout.match(/^ref:\s+refs\/heads\/(\S+)\s+HEAD/m)?.[1] ?? null : null;
|
|
13898
|
+
if (!base)
|
|
13899
|
+
throw new UsageError("could not read the default branch of origin");
|
|
13900
|
+
const configHome = io.env.XDG_CONFIG_HOME ?? (io.env.HOME ? join7(io.env.HOME, ".config") : null);
|
|
13901
|
+
const herdrConfigPath = io.env.HERDR_CONFIG_PATH ?? (configHome ? join7(configHome, "herdr", "config.toml") : null);
|
|
13902
|
+
const herdrConfig = herdrConfigPath ? await io.readFile(herdrConfigPath).catch(() => null) : null;
|
|
13903
|
+
worktree = herdrWorktreePath(herdrWorktreesDirectory(io.env, herdrConfig), basename(mainRoot), input.branch);
|
|
13904
|
+
} catch (error) {
|
|
13905
|
+
gaps.push(error instanceof UsageError ? error.message : "could not read the repository state");
|
|
13906
|
+
}
|
|
13907
|
+
const ready = gaps.length === 0;
|
|
13908
|
+
const plan = {
|
|
13909
|
+
ticket: input.ticketId,
|
|
13910
|
+
runtime: "herdr",
|
|
13911
|
+
dryRun: true,
|
|
13912
|
+
profile: input.choice.name,
|
|
13913
|
+
profileWhy: input.choice.why,
|
|
13914
|
+
routed: input.choice.routed,
|
|
13915
|
+
reason: input.choice.reason,
|
|
13916
|
+
harness: input.choice.profile.harness,
|
|
13917
|
+
actualHarness: herdrHarnessKind(input.choice.profile.harness),
|
|
13918
|
+
harnessDescription: herdrHarnessLabel(input.choice.profile.harness),
|
|
13919
|
+
model: input.choice.profile.model,
|
|
13920
|
+
effort: input.choice.profile.effort,
|
|
13921
|
+
branch: input.branch,
|
|
13922
|
+
worktree,
|
|
13923
|
+
base,
|
|
13924
|
+
preflight: { ready, gaps, warnings }
|
|
13925
|
+
};
|
|
13926
|
+
io.stdout(json ? `${JSON.stringify(plan, null, 2)}
|
|
13927
|
+
` : `Launch plan for ${input.ticketId} (dry run: nothing is created)
|
|
13928
|
+
|
|
13929
|
+
Profile ${input.choice.name} — ${input.choice.why}
|
|
13930
|
+
Harness ${plan.harnessDescription} (exact model: ${plan.model || "not set"}, effort ${plan.effort})
|
|
13931
|
+
Branch ${plan.branch}
|
|
13932
|
+
Worktree ${worktree ?? "unknown"}
|
|
13933
|
+
Base ${base ?? "unknown"}
|
|
13934
|
+
Preflight ${ready ? "ready" : "blocked"}
|
|
13935
|
+
`);
|
|
13936
|
+
for (const warning of warnings)
|
|
13937
|
+
io.stderr(`armada: warning: ${warning}
|
|
13938
|
+
`);
|
|
13939
|
+
for (const gap of gaps)
|
|
13940
|
+
io.stderr(`armada: ${gap}
|
|
13941
|
+
`);
|
|
13942
|
+
return ready ? 0 : 1;
|
|
13943
|
+
}
|
|
13944
|
+
|
|
13945
|
+
// src/local-setup.ts
|
|
13946
|
+
async function setupLocal(io, initial, configPath, args) {
|
|
13947
|
+
if (args.rest.length !== 1 || args.rest[0] !== "local")
|
|
13948
|
+
throw new UsageError("setup needs a command: armada setup local");
|
|
13949
|
+
if (args.json || !io.interactive || io.env.CI || !io.prompt) {
|
|
13950
|
+
const message = "Local setup needs the owner at an interactive terminal to choose permissions and answer harness questions";
|
|
13951
|
+
io.stdout(args.json ? `${JSON.stringify({ ready: false, message, next: "armada setup local at an interactive terminal" })}
|
|
13952
|
+
` : `${message}: run armada setup local at an interactive terminal.
|
|
13953
|
+
`);
|
|
13954
|
+
return 1;
|
|
13955
|
+
}
|
|
13956
|
+
let config = initial;
|
|
13957
|
+
const profiles = Object.entries(config.herdr.profiles);
|
|
13958
|
+
if (!profiles.length)
|
|
13959
|
+
throw new UsageError("local setup needs at least one [herdr.profiles.<name>] in armada.toml");
|
|
13960
|
+
const unset = profiles.filter(([, p]) => p.permissions === undefined).map(([name]) => name);
|
|
13961
|
+
if (unset.length) {
|
|
13962
|
+
if (!io.writeFile)
|
|
13963
|
+
throw new UsageError("local setup needs configuration writes to save the owner's permission choice");
|
|
13964
|
+
const before = await io.readFile(configPath);
|
|
13965
|
+
if (before === null || JSON.stringify(parseConfig(before, configPath)) !== JSON.stringify(initial))
|
|
13966
|
+
throw new UsageError("configuration changed before setup; retry with the current armada.toml");
|
|
13967
|
+
io.stdout(`Choose permissions for local profiles: ${unset.join(", ")}.
|
|
13968
|
+
Ask keeps each harness's normal approval policy. Full uses Claude --dangerously-skip-permissions, Codex --dangerously-bypass-approvals-and-sandbox (no command sandbox), and OpenCode --auto (explicit deny rules still apply).
|
|
13969
|
+
Trust, MCP, sign-in and model questions remain the owner's decisions.
|
|
13970
|
+
`);
|
|
13971
|
+
const answer = await io.prompt("Permissions [ask/full] (Enter for ask): ", { hidden: false });
|
|
13972
|
+
if (answer === null)
|
|
13973
|
+
return 1;
|
|
13974
|
+
const permissions = answer.trim().toLowerCase() || "ask";
|
|
13975
|
+
if (permissions !== "ask" && permissions !== "full") {
|
|
13976
|
+
io.stderr(`Choose ask or full; configuration unchanged.
|
|
13977
|
+
`);
|
|
13978
|
+
return 1;
|
|
13979
|
+
}
|
|
13980
|
+
if (await io.readFile(configPath) !== before) {
|
|
13981
|
+
io.stderr(`Configuration changed while you chose permissions; retry setup without overwriting that edit.
|
|
13982
|
+
`);
|
|
13983
|
+
return 1;
|
|
13984
|
+
}
|
|
13985
|
+
let next;
|
|
13986
|
+
try {
|
|
13987
|
+
next = setHerdrPermissions(before, unset, permissions);
|
|
13988
|
+
const parsed = parseConfig(next, configPath);
|
|
13989
|
+
await io.writeFile(configPath, next);
|
|
13990
|
+
config = parsed;
|
|
13991
|
+
} catch {
|
|
13992
|
+
throw new UsageError(`could not safely save permissions; set permissions = "${permissions}" in the named profiles yourself, removing any conflicting native bypass flag from extra_args`);
|
|
13993
|
+
}
|
|
13994
|
+
io.stdout(`Saved permissions = "${permissions}" for ${unset.join(", ")} in ${configPath}.
|
|
13995
|
+
`);
|
|
13996
|
+
}
|
|
13997
|
+
if (!io.exec)
|
|
13998
|
+
throw new UsageError("local setup needs process execution");
|
|
13999
|
+
const detected = await offerLocalInstalls(io, await detectLocalTools(io, localHarnesses(config), localModelProfiles(config)));
|
|
14000
|
+
if (detected.tools.some((tool) => tool.state !== "ready")) {
|
|
14001
|
+
for (const check of detected.checks.filter((c) => c.level === "error"))
|
|
14002
|
+
io.stderr(`${check.message}${check.fix ? `: ${check.fix}` : ""}
|
|
14003
|
+
`);
|
|
14004
|
+
return 1;
|
|
14005
|
+
}
|
|
14006
|
+
const git = await io.exec("git", ["rev-parse", "--show-toplevel"], { cwd: io.cwd, timeoutMs: 1e4 });
|
|
14007
|
+
const repo = git.stdout.trim();
|
|
14008
|
+
if (git.code !== 0 || !repo.startsWith("/") || [...repo].some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127))
|
|
14009
|
+
throw new UsageError("local setup must run in a git repository");
|
|
14010
|
+
const runtime = new Herdr(io);
|
|
14011
|
+
await runtime.ensureServer();
|
|
14012
|
+
const location = await runtime.setupRoot(repo, config.project.slug, config.secrets.names);
|
|
14013
|
+
const workspace = await runtime.setupWorkspace(location.root, config.secrets.names);
|
|
14014
|
+
io.stdout(`Local setup at ${location.root}.
|
|
14015
|
+
Answer each harness's folder trust, update, project MCP, sign-in and model questions yourself in its pane. Armada never answers these questions or edits harness settings.
|
|
14016
|
+
Claude Code: trusting this parent folder does not cover Git repositories beneath it. Current versions key linked-worktree trust on the main checkout (${location.repo}); approve that repository yourself, or answer each new worktree's question on versions that ask again. Project MCP questions can still appear per checkout.
|
|
14017
|
+
`);
|
|
14018
|
+
const selected = new Set;
|
|
14019
|
+
const sessions = [];
|
|
14020
|
+
for (const [name, profile] of Object.entries(config.herdr.profiles)) {
|
|
14021
|
+
const kind = herdrHarnessKind(profile.harness);
|
|
14022
|
+
if (selected.has(kind))
|
|
14023
|
+
continue;
|
|
14024
|
+
selected.add(kind);
|
|
14025
|
+
const pane = await runtime.setupPane(workspace, location.root, profile, config.secrets.names);
|
|
14026
|
+
const session = { handle: pane.handle, profile, name, error: null };
|
|
14027
|
+
sessions.push(session);
|
|
14028
|
+
io.stdout(`${kind} (profile ${name}): herdr agent attach ${pane.handle.agent}
|
|
14029
|
+
`);
|
|
14030
|
+
if (!pane.existing) {
|
|
14031
|
+
try {
|
|
14032
|
+
await runtime.startChecked(pane.handle, profile);
|
|
14033
|
+
} catch (error) {
|
|
14034
|
+
session.error = error instanceof UsageError ? error.message : `Could not start ${kind}; run herdr agent attach ${pane.handle.agent}`;
|
|
14035
|
+
io.stdout(`${session.error}
|
|
14036
|
+
`);
|
|
14037
|
+
}
|
|
14038
|
+
}
|
|
14039
|
+
}
|
|
14040
|
+
io.stdout(`Setup checks the selected profile for each native harness; other models remain subject to armada doctor's profile checks.
|
|
14041
|
+
`);
|
|
14042
|
+
const answer = await io.prompt("Answer the questions in those panes, then press Enter here to check (or Ctrl-C to leave them open): ", { hidden: false });
|
|
14043
|
+
if (answer === null)
|
|
14044
|
+
return 1;
|
|
14045
|
+
let ready = true;
|
|
14046
|
+
for (const session of sessions) {
|
|
14047
|
+
try {
|
|
14048
|
+
const screen = await runtime.inspect(session.handle, session.profile.harness);
|
|
14049
|
+
if (screen.issue || !screen.ready) {
|
|
14050
|
+
ready = false;
|
|
14051
|
+
io.stdout(`${screen.issue?.message ?? "The harness is not ready"}: herdr agent attach ${session.handle.agent}
|
|
14052
|
+
`);
|
|
14053
|
+
} else {
|
|
14054
|
+
await runtime.checkSetupModel(session.handle, session.profile);
|
|
14055
|
+
io.stdout(`${herdrHarnessKind(session.profile.harness)} (profile ${session.name}): ready; model answered the setup check.
|
|
14056
|
+
`);
|
|
14057
|
+
}
|
|
14058
|
+
} catch (error) {
|
|
14059
|
+
ready = false;
|
|
14060
|
+
io.stdout(`${error instanceof UsageError ? error.message : "Could not verify the harness"}; herdr agent attach ${session.handle.agent}
|
|
14061
|
+
`);
|
|
14062
|
+
}
|
|
14063
|
+
}
|
|
14064
|
+
io.stdout(`${ready ? "Local setup checked" : "Local setup still needs attention"}. The panes and setup checkout are kept; rerun armada setup local to check again.
|
|
14065
|
+
`);
|
|
14066
|
+
return ready ? 0 : 1;
|
|
14067
|
+
}
|
|
13230
14068
|
|
|
13231
14069
|
// src/merge.ts
|
|
13232
14070
|
import { randomUUID } from "node:crypto";
|
|
13233
14071
|
import { rm as rm4 } from "node:fs/promises";
|
|
13234
14072
|
import { hostname, tmpdir as tmpdir2 } from "node:os";
|
|
13235
|
-
import { dirname as
|
|
14073
|
+
import { dirname as dirname7, join as join8 } from "node:path";
|
|
13236
14074
|
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;
|
|
13237
14075
|
var tail = (text, lines = 30) => text.trimEnd().split(`
|
|
13238
14076
|
`).slice(-lines).join(`
|
|
@@ -13310,7 +14148,7 @@ function gitRepo(exec, cwd) {
|
|
|
13310
14148
|
},
|
|
13311
14149
|
async testMerge({ branch, base, head, number, commands }) {
|
|
13312
14150
|
await must(["fetch", "--quiet", "origin", branch, `refs/pull/${number}/head`]);
|
|
13313
|
-
const dir =
|
|
14151
|
+
const dir = join8(tmpdir2(), `armada-merge-${number}-${randomUUID().slice(0, 8)}`);
|
|
13314
14152
|
const remove = async () => {
|
|
13315
14153
|
await git(["worktree", "remove", "--force", dir]);
|
|
13316
14154
|
await git(["worktree", "prune"]);
|
|
@@ -13419,7 +14257,7 @@ async function merge(io, config, credentials, a, configPath) {
|
|
|
13419
14257
|
if (!exec)
|
|
13420
14258
|
throw new UsageError("armada merge needs to run git and gh");
|
|
13421
14259
|
const linearApiKey = credentials.linearApiKey;
|
|
13422
|
-
const repoDir =
|
|
14260
|
+
const repoDir = dirname7(configPath);
|
|
13423
14261
|
const fetchOpt = io.fetch ? { fetch: io.fetch } : {};
|
|
13424
14262
|
const gh = { token, repository: config.github.repository, ...fetchOpt };
|
|
13425
14263
|
const linearOpts = { apiKey: linearApiKey, labels: config.tracker.labels, ...fetchOpt };
|
|
@@ -13454,7 +14292,7 @@ async function merge(io, config, credentials, a, configPath) {
|
|
|
13454
14292
|
`),
|
|
13455
14293
|
installedSkill: async (name) => {
|
|
13456
14294
|
for (const dir of [AGENTS_SKILLS_DIR, CLAUDE_SKILLS_DIR])
|
|
13457
|
-
if (await io.readFile(
|
|
14295
|
+
if (await io.readFile(join8(repoDir, dir, name, "SKILL.md")) !== null)
|
|
13458
14296
|
return true;
|
|
13459
14297
|
return false;
|
|
13460
14298
|
}
|
|
@@ -13670,7 +14508,7 @@ ${"─".repeat(60)}
|
|
|
13670
14508
|
}
|
|
13671
14509
|
|
|
13672
14510
|
// src/secrets.ts
|
|
13673
|
-
import { dirname as
|
|
14511
|
+
import { dirname as dirname8, relative as relative3, resolve as resolve2 } from "node:path";
|
|
13674
14512
|
var NAME_HINT = "upper snake case, e.g. OPENAI_API_KEY";
|
|
13675
14513
|
var hhmm2 = (iso) => `${iso.slice(0, 16).replace("T", " ")} UTC`;
|
|
13676
14514
|
function signInOf(config, credentials) {
|
|
@@ -13750,7 +14588,7 @@ Next: armada secrets set <NAME> (an owner or admin), or the Keys page of Armada
|
|
|
13750
14588
|
async function exportRefusal(io, path) {
|
|
13751
14589
|
if (!io.exec)
|
|
13752
14590
|
return "git cannot be run here to check that the file is ignored";
|
|
13753
|
-
const cwd =
|
|
14591
|
+
const cwd = dirname8(path);
|
|
13754
14592
|
const tracked = await io.exec("git", ["ls-files", "--error-unmatch", "--", path], { cwd }).catch(() => null);
|
|
13755
14593
|
if (tracked?.code === 0)
|
|
13756
14594
|
return `git tracks ${path}: secrets written there would be committed`;
|
|
@@ -14009,11 +14847,16 @@ var COMMAND_HELP = {
|
|
|
14009
14847
|
`,
|
|
14010
14848
|
status: ` status Tickets in flight, tickets ready to start and pull requests waiting
|
|
14011
14849
|
status --all The same for every project registered by \`armada init\`
|
|
14850
|
+
`,
|
|
14851
|
+
setup: ` setup local Open local harness panes for the owner to answer first-run questions,
|
|
14852
|
+
choose ask/full permissions once, and check the selected models.
|
|
14853
|
+
Requires an interactive terminal; --json reports that requirement
|
|
14012
14854
|
`,
|
|
14013
14855
|
doctor: ` doctor What this repository lacks to be run by Armada, with the fix for each,
|
|
14014
14856
|
and whether this terminal is signed in to Armada. Local herdr profiles
|
|
14015
14857
|
check tools and harness sign-in; offers official installs with y/N.
|
|
14016
|
-
No terminal, CI and --json only print fixes and never install
|
|
14858
|
+
No terminal, CI and --json only print fixes and never install.
|
|
14859
|
+
For harness first-run questions, the owner runs armada setup local
|
|
14017
14860
|
`,
|
|
14018
14861
|
init: ` init [--program-root <ISSUE-ID>] [--name <name>] [--slug <slug>] [--no-stop-hook]
|
|
14019
14862
|
Open one pull request that installs or updates it all, create the
|
|
@@ -14121,6 +14964,11 @@ var COMMAND_HELP = {
|
|
|
14121
14964
|
[--profile <name> [--reason <why>]] [--validation <n|none>]
|
|
14122
14965
|
Create the ticket's worktree and start a persistent local worker
|
|
14123
14966
|
with its launch-token brief. Profiles follow [[herdr.routing]]
|
|
14967
|
+
launch <ticket> --runtime herdr --dry-run [--json]
|
|
14968
|
+
Print the launch plan (profile and why, harness and exact model,
|
|
14969
|
+
branch and worktree path, preflight) and create nothing: no
|
|
14970
|
+
worktree, token, pane or install. Exits 0 when the preflight
|
|
14971
|
+
passes, else non-zero, listing every gap
|
|
14124
14972
|
launch revoke <ticket>
|
|
14125
14973
|
Cancel the newest pending launch through Armada, including a worker
|
|
14126
14974
|
signed in but not claimed. A claimed launch needs armada release instead
|
|
@@ -14199,7 +15047,8 @@ var CONFIG_OPTION = new Set([
|
|
|
14199
15047
|
"stop",
|
|
14200
15048
|
"merge",
|
|
14201
15049
|
"brief",
|
|
14202
|
-
"launch"
|
|
15050
|
+
"launch",
|
|
15051
|
+
"setup"
|
|
14203
15052
|
]);
|
|
14204
15053
|
var JSON_OPTION = new Set([
|
|
14205
15054
|
"skills",
|
|
@@ -14324,7 +15173,7 @@ var COMMAND_OPTIONS = {
|
|
|
14324
15173
|
init: ["program-root", "name", "slug", "no-stop-hook"],
|
|
14325
15174
|
merge: ["ticket", "no-ticket", "dry-run", "no-lock", "wait", "timeout", "reason", "ask-owner"],
|
|
14326
15175
|
brief: ["profile", "reason", "prompt", "profile-line", "validation", "validation-reason"],
|
|
14327
|
-
launch: ["runtime", "harness", "profile", "reason", "validation", "validation-reason"],
|
|
15176
|
+
launch: ["runtime", "harness", "profile", "reason", "validation", "validation-reason", "dry-run"],
|
|
14328
15177
|
validate: ["ticket", "attach", "caption", "choices", "message", "message-file"],
|
|
14329
15178
|
"ask-owner": ["choices"],
|
|
14330
15179
|
login: ["api-key", "launch-token", "api-url"],
|
|
@@ -14390,12 +15239,12 @@ async function findConfig(io, explicit, command = "status") {
|
|
|
14390
15239
|
throw new UsageError(`${path} does not exist`, `armada ${command} --config <file>, with the path of an ${CONFIG_FILE}`);
|
|
14391
15240
|
return { path, text };
|
|
14392
15241
|
}
|
|
14393
|
-
for (let dir = resolve3(io.cwd);; dir =
|
|
14394
|
-
const path =
|
|
15242
|
+
for (let dir = resolve3(io.cwd);; dir = dirname9(dir)) {
|
|
15243
|
+
const path = join9(dir, CONFIG_FILE);
|
|
14395
15244
|
const text = await io.readFile(path);
|
|
14396
15245
|
if (text !== null)
|
|
14397
15246
|
return { path, text };
|
|
14398
|
-
if (
|
|
15247
|
+
if (dirname9(dir) === dir)
|
|
14399
15248
|
break;
|
|
14400
15249
|
}
|
|
14401
15250
|
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`);
|
|
@@ -14416,7 +15265,7 @@ async function status(io, args) {
|
|
|
14416
15265
|
...io.fetch ? { fetch: io.fetch } : {},
|
|
14417
15266
|
...io.now ? { now: io.now } : {}
|
|
14418
15267
|
});
|
|
14419
|
-
const behind = await skillsBehind(fsRepoView(
|
|
15268
|
+
const behind = await skillsBehind(fsRepoView(dirname9(path))).catch(() => null);
|
|
14420
15269
|
if (behind)
|
|
14421
15270
|
report.warnings.push(skillsBehindLine(behind, version));
|
|
14422
15271
|
io.stdout(args.json ? `${JSON.stringify(report, null, 2)}
|
|
@@ -14569,6 +15418,10 @@ async function dispatch(argv, io) {
|
|
|
14569
15418
|
await recordPresence(io, config, credentials);
|
|
14570
15419
|
return await brief(io, config, credentials, args, version, path);
|
|
14571
15420
|
}
|
|
15421
|
+
if (args.command === "setup") {
|
|
15422
|
+
const { path, text } = await findConfig(io, args.config, "setup");
|
|
15423
|
+
return await setupLocal(io, parseConfig(text, path), path, args);
|
|
15424
|
+
}
|
|
14572
15425
|
if (args.command === "launch") {
|
|
14573
15426
|
const { path, text } = await findConfig(io, args.config, "launch");
|
|
14574
15427
|
const config = parseConfig(text, path);
|