@the-vibe-company/armada 0.2.44 → 0.2.46
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 +903 -166
- 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 join8, 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)
|
|
@@ -852,6 +859,9 @@ function activeClaims(comments) {
|
|
|
852
859
|
return claims;
|
|
853
860
|
}
|
|
854
861
|
var latest = (...xs) => xs.filter((x) => !!x).reduce((a, b) => b > a ? b : a, "");
|
|
862
|
+
function workerLivenessAt(worker) {
|
|
863
|
+
return latest(worker.lastHeartbeat, worker.lastReport) || worker.lastUpdate;
|
|
864
|
+
}
|
|
855
865
|
function inferPhase(pr, comments) {
|
|
856
866
|
if (pr?.state === "open")
|
|
857
867
|
return pr.ci === "success" && pr.mergeable !== "CONFLICTING" ? "ready-to-merge" : "shipping";
|
|
@@ -908,7 +918,7 @@ function buildLane(m, allComments, issue, opts) {
|
|
|
908
918
|
const flags = [];
|
|
909
919
|
const waitingOnHuman = NEEDS_HUMAN.includes(phase) || phase === "merged";
|
|
910
920
|
const lastHeartbeat = opts.heartbeats?.[issue.id] ?? opts.live?.handles?.[issue.id]?.lastHeartbeatAt ?? null;
|
|
911
|
-
const alive = lastHeartbeat
|
|
921
|
+
const alive = workerLivenessAt({ lastHeartbeat, lastReport, lastUpdate });
|
|
912
922
|
if (!waitingOnHuman && opts.now - Date.parse(alive) > opts.silentAfterMinutes * MIN)
|
|
913
923
|
flags.push("silent");
|
|
914
924
|
if (pr?.state === "open" && pr.ci === "failure")
|
|
@@ -1973,124 +1983,19 @@ var HAS_WELLFORMED = !!"".isWellFormed;
|
|
|
1973
1983
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1974
1984
|
*/
|
|
1975
1985
|
|
|
1976
|
-
// ../core/src/herdr-profile.ts
|
|
1977
|
-
var herdrHarnessKind = (harness) => harness === "deepseek" ? "opencode" : harness;
|
|
1978
|
-
var herdrHarnessLabel = (harness) => harness === "deepseek" ? "deepseek (OpenCode + DeepSeek model)" : harness;
|
|
1979
|
-
function herdrChoice(choice) {
|
|
1980
|
-
return {
|
|
1981
|
-
...choice,
|
|
1982
|
-
profile: {
|
|
1983
|
-
runtime: "herdr",
|
|
1984
|
-
agent: herdrHarnessLabel(choice.profile.harness),
|
|
1985
|
-
model: choice.profile.model,
|
|
1986
|
-
effort: choice.profile.effort,
|
|
1987
|
-
fastMode: false
|
|
1988
|
-
}
|
|
1989
|
-
};
|
|
1990
|
-
}
|
|
1991
|
-
var herdrClaimHandle = (handle) => JSON.stringify({ workspace: handle.workspace, pane: handle.pane, agent: handle.agent });
|
|
1992
|
-
function isDeepseekModel(model) {
|
|
1993
|
-
const [provider, ...parts] = model.split("/");
|
|
1994
|
-
return !!parts.length && (provider === "deepseek" || /(?:^|[/-])deepseek(?:$|[/-])/i.test(parts.join("/")));
|
|
1995
|
-
}
|
|
1996
|
-
function setHerdrModel(text, name, model) {
|
|
1997
|
-
const raw = parse(text);
|
|
1998
|
-
const profiles = raw.herdr?.profiles;
|
|
1999
|
-
if (!profiles?.[name])
|
|
2000
|
-
throw new Error("profile is no longer present");
|
|
2001
|
-
const lines = text.split(/(?<=\n)/);
|
|
2002
|
-
let section = -1;
|
|
2003
|
-
let end = lines.length;
|
|
2004
|
-
for (let i = 0;i < lines.length; i++) {
|
|
2005
|
-
const header = lines[i]?.match(/^\s*\[herdr\s*\.\s*profiles\s*\.\s*(.+?)\]\s*(?:#.*)?(?:\r?\n)?$/);
|
|
2006
|
-
if (header) {
|
|
2007
|
-
const key = header[1]?.trim();
|
|
2008
|
-
if (key && Object.hasOwn(parse(`[${key}]
|
|
2009
|
-
`), name)) {
|
|
2010
|
-
section = i;
|
|
2011
|
-
break;
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
if (section < 0)
|
|
2016
|
-
throw new Error("use an explicit [herdr.profiles.<name>] section to save the model");
|
|
2017
|
-
for (let i = section + 1;i < lines.length; i++) {
|
|
2018
|
-
if (/^\s*\[/.test(lines[i] ?? "")) {
|
|
2019
|
-
end = i;
|
|
2020
|
-
break;
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
let replaced = false;
|
|
2024
|
-
for (let i = section + 1;i < end; i++) {
|
|
2025
|
-
const match = lines[i]?.match(/^(\s*(?:model|"model"|'model')\s*=\s*)("(?:[^"\\]|\\.)*"|'[^']*')(.*?)(\r?\n)?$/);
|
|
2026
|
-
if (match) {
|
|
2027
|
-
const value = match[2]?.startsWith("'") && !model.includes("'") ? `'${model}'` : JSON.stringify(model);
|
|
2028
|
-
lines[i] = `${match[1]}${value}${match[3]}${match[4] ?? ""}`;
|
|
2029
|
-
replaced = true;
|
|
2030
|
-
break;
|
|
2031
|
-
}
|
|
2032
|
-
}
|
|
2033
|
-
if (!replaced) {
|
|
2034
|
-
const newline = text.includes(`\r
|
|
2035
|
-
`) ? `\r
|
|
2036
|
-
` : `
|
|
2037
|
-
`;
|
|
2038
|
-
if (!(lines[section] ?? "").endsWith(`
|
|
2039
|
-
`))
|
|
2040
|
-
lines[section] += newline;
|
|
2041
|
-
lines.splice(section + 1, 0, `model = ${JSON.stringify(model)}${newline}`);
|
|
2042
|
-
}
|
|
2043
|
-
const next = lines.join("");
|
|
2044
|
-
profiles[name].model = model;
|
|
2045
|
-
if (JSON.stringify(parse(next)) !== JSON.stringify(raw)) {
|
|
2046
|
-
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);
|
|
2047
|
-
if (canonical(parse(next)) !== canonical(raw))
|
|
2048
|
-
throw new Error("could not safely edit the profile model");
|
|
2049
|
-
}
|
|
2050
|
-
return next;
|
|
2051
|
-
}
|
|
2052
|
-
|
|
2053
|
-
// ../core/src/npm.ts
|
|
2054
|
-
var ARMADA_PACKAGE = CLI_PACKAGE;
|
|
2055
|
-
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${ARMADA_PACKAGE.replace("/", "%2f")}`;
|
|
2056
|
-
var NPM_CHECK_MS = 3000;
|
|
2057
|
-
async function checkPublished(version, fetch2, timeoutMs = NPM_CHECK_MS) {
|
|
2058
|
-
try {
|
|
2059
|
-
const signal = AbortSignal.timeout(timeoutMs);
|
|
2060
|
-
const res = await fetch2(NPM_REGISTRY_URL, {
|
|
2061
|
-
headers: { accept: "application/vnd.npm.install-v1+json" },
|
|
2062
|
-
cache: "no-store",
|
|
2063
|
-
signal
|
|
2064
|
-
});
|
|
2065
|
-
if (!res.ok)
|
|
2066
|
-
return { state: "unknown", reason: `npm answered HTTP ${res.status}` };
|
|
2067
|
-
const body = await res.json();
|
|
2068
|
-
const versions = body?.versions;
|
|
2069
|
-
if (!versions || typeof versions !== "object" || Array.isArray(versions) || !Object.keys(versions).length)
|
|
2070
|
-
return { state: "unknown", reason: "npm listed no version" };
|
|
2071
|
-
const candidates = Object.keys(versions).filter((candidate) => /^\d+\.\d+\.\d+$/.test(candidate) && compareVersions(candidate, version) <= 0).sort((first, second) => compareVersions(second, first));
|
|
2072
|
-
for (const candidate of candidates) {
|
|
2073
|
-
const tarball = versions[candidate]?.dist?.tarball;
|
|
2074
|
-
if (typeof tarball !== "string" || !tarball)
|
|
2075
|
-
continue;
|
|
2076
|
-
const download = await fetch2(tarball, { method: "HEAD", cache: "no-store", signal });
|
|
2077
|
-
if (download.status === 200)
|
|
2078
|
-
return candidate === version ? { state: "published" } : { state: "missing", newest: candidate };
|
|
2079
|
-
if (download.status !== 404)
|
|
2080
|
-
return { state: "unknown", reason: `npm tarball answered HTTP ${download.status}` };
|
|
2081
|
-
}
|
|
2082
|
-
return { state: "missing", newest: null };
|
|
2083
|
-
} catch (err) {
|
|
2084
|
-
return { state: "unknown", reason: networkReason(err, timeoutMs) };
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
1986
|
// ../core/src/config.ts
|
|
2089
1987
|
var CONFIG_FILE = "armada.toml";
|
|
2090
1988
|
var PLAN_POLICIES = ["approve", "pre-approved"];
|
|
2091
1989
|
var routingLabelKey = (name) => name.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{M}\p{N}]/gu, "");
|
|
2092
1990
|
var PROFILE_RUNTIMES = ["conductor", "claude-code"];
|
|
2093
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
|
+
};
|
|
2094
1999
|
var CONFIG_DEFAULTS = {
|
|
2095
2000
|
language: "en",
|
|
2096
2001
|
readyLabel: "ready-for-agent",
|
|
@@ -2313,7 +2218,7 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2313
2218
|
problems.push(`"${path}" is not a usable profile name`);
|
|
2314
2219
|
continue;
|
|
2315
2220
|
}
|
|
2316
|
-
known.push([path, p, ["harness", "model", "effort", "extra_args", "when"]]);
|
|
2221
|
+
known.push([path, p, ["harness", "model", "effort", "extra_args", "permissions", "when"]]);
|
|
2317
2222
|
let harness = "claude";
|
|
2318
2223
|
if (p.harness === undefined)
|
|
2319
2224
|
problems.push(`missing required key "${path}.harness"`);
|
|
@@ -2330,13 +2235,23 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2330
2235
|
}
|
|
2331
2236
|
if (harness === "deepseek" && extraArgs.some((arg) => /^(?:--model(?:=|$)|-m)/.test(arg.trim())))
|
|
2332
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"`);
|
|
2333
2247
|
const model = (harness === "opencode" || harness === "deepseek") && (p.model === undefined || typeof p.model === "string" && !p.model.trim()) ? "" : str(p, path, "model");
|
|
2334
2248
|
herdrProfiles[name] = {
|
|
2335
2249
|
...p.when !== undefined ? { when: str(p, path, "when") } : {},
|
|
2336
2250
|
harness,
|
|
2337
2251
|
model,
|
|
2338
2252
|
effort: str(p, path, "effort"),
|
|
2339
|
-
extraArgs
|
|
2253
|
+
extraArgs,
|
|
2254
|
+
...permissions !== undefined ? { permissions } : {}
|
|
2340
2255
|
};
|
|
2341
2256
|
}
|
|
2342
2257
|
let herdrDefaultProfile = null;
|
|
@@ -2645,6 +2560,7 @@ profile = "debug"
|
|
|
2645
2560
|
# harness = "claude" # "claude", "codex", "opencode" or "deepseek" (OpenCode + DeepSeek model)
|
|
2646
2561
|
# model = "sonnet"
|
|
2647
2562
|
# effort = "high"
|
|
2563
|
+
# permissions = "ask" # normal harness approvals; use "full" for the native bypass/auto flag
|
|
2648
2564
|
# extra_args = ["--verbose"]
|
|
2649
2565
|
# when = "a ticket best handled by Claude"
|
|
2650
2566
|
|
|
@@ -2657,6 +2573,425 @@ function slugify(name) {
|
|
|
2657
2573
|
return name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "project";
|
|
2658
2574
|
}
|
|
2659
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
|
+
|
|
2660
2995
|
// ../core/src/phases.ts
|
|
2661
2996
|
var TRANSITIONS = {
|
|
2662
2997
|
planning: ["awaiting-approval", "implementing", "awaiting-validation"],
|
|
@@ -3500,7 +3835,7 @@ function renderPrompt(b) {
|
|
|
3500
3835
|
`armada heartbeat --every 5m --ticket ${t.id} --handle ${b.handle ? shellWord(b.handle) : subagent ? subagentName(t.id) : CONDUCTOR_HANDLE} --parent "$PPID"${subagent ? "" : " --background"}`,
|
|
3501
3836
|
"```",
|
|
3502
3837
|
"",
|
|
3503
|
-
subagent ? "Keep this Bash heartbeat in the subagent's background: it dies with the subagent, which is intended. Do not detach it from the subagent. If background processes are unavailable, report manually at least every 15 minutes." : "The heartbeat detaches from the short-lived command shell (a new process group, like nohup + setsid)
|
|
3838
|
+
subagent ? "Keep this Bash heartbeat in the subagent's background: it dies with the subagent, which is intended. Do not detach it from the subagent. If background processes are unavailable, report manually at least every 15 minutes." : "The heartbeat detaches from the short-lived command shell (a new process group, like nohup + setsid) and keeps a PID file under ~/.config/armada/watch/. Its monitored parent is the agent PID ($PPID in the command shell), never the shell PID ($$); it stops if that agent exits between turns. No heartbeat or manual report is required while awaiting-approval, blocked or awaiting-validation until someone answers. On resume, report the working phase and run the heartbeat line again with the current $PPID; an existing heartbeat for the same claim is kept. A newer answer or report starts a fresh silence window even when the old heartbeat is stale. If startup fails or the runtime cannot keep a background process, report manually at least every 15 minutes during active work instead.",
|
|
3504
3839
|
"",
|
|
3505
3840
|
`${b.armadaVersion.pinned === b.armadaVersion.coordinator ? "This installs the coordinator's Armada version." : `This installs Armada ${b.armadaVersion.pinned}, the newest on npm (the coordinator runs ${b.armadaVersion.coordinator}, not published yet).`} If the global install is refused, use \`${b.fallback}\` wherever this brief or the skill says \`armada\`.`,
|
|
3506
3841
|
...b.launch ? [
|
|
@@ -4936,7 +5271,7 @@ var EMPTY_PERSONAL_CONFIG = {
|
|
|
4936
5271
|
dashboard: { url: null },
|
|
4937
5272
|
api: { url: null }
|
|
4938
5273
|
};
|
|
4939
|
-
var
|
|
5274
|
+
var isTable3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4940
5275
|
function parsePersonalConfig(text, source = "config.toml") {
|
|
4941
5276
|
let raw;
|
|
4942
5277
|
try {
|
|
@@ -4952,11 +5287,11 @@ function parsePersonalConfig(text, source = "config.toml") {
|
|
|
4952
5287
|
continue;
|
|
4953
5288
|
const keys = known[key];
|
|
4954
5289
|
if (!keys) {
|
|
4955
|
-
if (!
|
|
5290
|
+
if (!isTable3(v))
|
|
4956
5291
|
problems.push(`unknown key "${key}"`);
|
|
4957
5292
|
continue;
|
|
4958
5293
|
}
|
|
4959
|
-
if (!
|
|
5294
|
+
if (!isTable3(v)) {
|
|
4960
5295
|
problems.push(`"${key}" must be a table`);
|
|
4961
5296
|
continue;
|
|
4962
5297
|
}
|
|
@@ -4972,7 +5307,7 @@ function parsePersonalConfig(text, source = "config.toml") {
|
|
|
4972
5307
|
problems.push(`"${dotted}" must be a non-empty string`);
|
|
4973
5308
|
return null;
|
|
4974
5309
|
};
|
|
4975
|
-
const table = (key) =>
|
|
5310
|
+
const table = (key) => isTable3(raw[key]) ? raw[key] : {};
|
|
4976
5311
|
const config = {
|
|
4977
5312
|
language: str(raw.language, "language"),
|
|
4978
5313
|
dashboard: { url: str(table("dashboard").url, "dashboard.url") },
|
|
@@ -6171,7 +6506,7 @@ A subagent launched without \`isolation: "worktree"\` runs in your checkout. The
|
|
|
6171
6506
|
files: [
|
|
6172
6507
|
{
|
|
6173
6508
|
path: "SKILL.md",
|
|
6174
|
-
content: "---\nname: armada-runtime-conductor\ndescription: Runtime guide for running Armada workers on Conductor Cloud. Use when an Armada coordinator must launch a worker on a ticket, send it a message, check whether a silent worker is still alive, or stop and archive it. Four fixed sections, each with the exact conductor command and how to read its output.\n---\n\nArmada records Conductor and Claude Code runtime actions separately; persistent herdr workers use integrated commands. This guide tells the coordinator how to launch, message, check and stop a worker with the `conductor` command line tool, and what to record in Armada afterwards. It was checked against `conductor` 0.89.x (the desktop app's CLI, macOS) and 0.1.x (the CLI inside a Conductor Cloud workspace, Linux); every command below works in both. `conductor --version` prints yours; if a flag is refused, compare with `conductor <command> --help`.\n\n- On a Mac, the app ships the CLI at `/Applications/Conductor.app/Contents/Resources/bin/conductor`, which is not on PATH. `armada doctor` looks for it and prints the fix: a link from a directory already on PATH (`ln -s \"/Applications/Conductor.app/Contents/Resources/bin/conductor\" ~/.local/bin/conductor`), or a PATH line for your shell profile.\n- Always pass `--json` and read fields with `jq`. Exit codes: 0 ok, 1 runtime error, 2 usage error, 3 authentication, 4 server error.\n- On exit code 3, `conductor auth whoami` checks the token the CLI uses (it exits 0 when the token works). Do not rely on `conductor auth status`: it only looks for a macOS Keychain entry and fails on Linux (\"Keychain storage is only supported on macOS\"). In a Conductor Cloud workspace the CLI reads `CONDUCTOR_API_KEY` from the environment and needs no login; on a Mac, `conductor auth login` stores a token in the Keychain.\n- A worker is one workspace with one session. Its Armada handle is `<workspaceId>/<sessionId>`; the worker's claim comment carries it, so `armada status` and the ticket always lead back to the session.\n- A worker needs no key in its workspace: the prompt of `armada brief` carries a one-time launch token, and the worker's first command exchanges it for a session limited to its ticket, through which Armada gives each command its keys. The token works once, within the hour, so a copy left in a transcript is useless once used.\n- Never type a secret value into a command, a file or a message: name the variable and let your shell expand it. The expanded value is still in the `conductor` process's arguments while it runs, so launch from a machine only you use.\n\n## Launch\n\nThe brief starts `armada heartbeat --every 5m --parent \"$PPID\" --background` immediately after claim. It creates a detached process group (like `nohup` + `setsid`) with closed terminal streams and a PID file under `~/.config/armada/watch/`. Plain `&` and `nohup` alone can be killed by command-tool cleanup on Cloud; detached startup survives between turns and while waiting for a message. `$PPID` in the agent's command shell must be the persistent agent process, never `$$` (the shell). The heartbeat stops with that parent or when Armada ends the current session (release, merge, revoke). If startup fails or the runtime cannot retain any background process, fall back to manual reports at least every 15 minutes and record that fallback on the ticket. Reports remain progress dots, not liveness.\n\n1. Pick a ready ticket from `armada status` that does not collide with work in flight.\n2. Read the ticket and parent, then choose its profile. A matching label rule wins; otherwise match the profiles' `when` rules by most files/work. Mixed front-end/back-end work: choose the larger part and say why with `--profile <name> --reason \"<why>\"`. An optional `armada brief ABC-12` or `--json` preview helps resolve the choice and warnings, but is read-only: neither creates a launch token nor marks a worker in flight. If the choice is still needed, `--prompt` refuses before minting anything.\n3. **Make one brief call for the launch:** `--prompt --profile-line` writes only the worker prompt to stdout and the selected profile (agent, model, effort, fast mode, runtime and reason) to stderr. Read that line to configure Conductor; no second brief is needed for the profile. Keep any `--profile` and `--reason` flags on this call. Resolve warnings before launching. Never cut a launch message from the human view or `--json`: they carry no token. Write the prompt to a file only you can read, then add what only you know (the boundary with a parallel worker, a decision not yet on the ticket). The token works once, within the hour; if you cancel or the runtime launch fails, use `armada launch revoke ABC-12`. Generate a fresh prompt if its token has expired.\n\n```sh\n(umask 077; armada brief ABC-12 --prompt --profile-line > /tmp/abc-12-brief.md)\n```\n\n4. Create the workspace with every value from the profile. Never leave the agent, model or effort to Conductor's defaults. Add `--fast-mode` when the profile says fast mode. Run the whole block as one command: shell state does not carry over between separate calls.\n\n```sh\nconductor --json workspace create \\\n --repo-url https://github.com/<owner>/<name> \\\n --branch main \\\n --name \"ABC-12 <short title>\" \\\n --agent claude --model opus-5-5-1m --effort high \\\n --message-file - \\\n --env ARMADA_TICKET=ABC-12 \\\n < /tmp/abc-12-brief.md > /tmp/abc-12-launch.json\nrm -f /tmp/abc-12-brief.md\njq -r '\"\\(.workspaceId)/\\(.sessionId)\"' /tmp/abc-12-launch.json\n```\n\nIf the prompt has no launch token, its stderr warning says why. Not signed in: `armada login` (a headless coordinator sets `ARMADA_API_KEY`), then generate a new prompt; `armada doctor` checks the sign-in. Only on an Armada that keeps no keys yet (no accounts or no vault), pass the keys the read-only brief's environment table marks `required`, from your shell or from Armada's credentials file (`in credentials file`: the `set -a` line loads it without printing it; drop it when every variable is set in your shell). The subshell keeps the keys out of the rest of your session. Without a launch token the worker is not signed in to Armada: its claims and reports reach Linear only, with a warning. When Conductor's organization environment still holds the keys, every workspace already has them: use the first block.\n\n```sh\n(\n set -a; . \"${XDG_CONFIG_HOME:-$HOME/.config}/armada/credentials\"; set +a\n [ -n \"$LINEAR_API_KEY\" ] || { echo \"LINEAR_API_KEY is missing\" >&2; exit 1; }\n conductor --json workspace create \\\n --repo-url https://github.com/<owner>/<name> \\\n --branch main \\\n --name \"ABC-12 <short title>\" \\\n --agent claude --model opus-5-5-1m --effort high \\\n --message-file - \\\n --env ARMADA_TICKET=ABC-12 \\\n --env LINEAR_API_KEY=\"$LINEAR_API_KEY\" \\\n < /tmp/abc-12-brief.md > /tmp/abc-12-launch.json\n)\nrm -f /tmp/abc-12-brief.md\n```\n\n- `--branch` is the base branch (the default branch). Conductor creates a branch named `conductor/<slug of --name>`; the brief tells the worker to rename it to the ticket's branch.\n- The output has `workspaceId`, `sessionId`, `deepLink` and `initialMessage` (`messageId`, `state: \"queued\"`). Keep the handle the `jq` line prints, and give the owner the `deepLink` when they want to watch.\n- Conductor sets `CONDUCTOR_WORKSPACE_ID` and `CONDUCTOR_SESSION_ID` inside the workspace, and signs `gh` in for the worker's pushes. The brief's first commands install your Armada version (`npm install -g`), sign in with the launch token (`armada login --launch-token`) and claim the ticket. `--env` values are not shown back by `workspace get`.\n- Keys in Conductor's organization environment reach every workspace, workers included: once Armada keeps the organization's keys, they belong on Armada's Keys page, not there.\n- An unknown agent, model or effort fails the command. Check the ids with `conductor model` (each agent's models, efforts and defaults) and fix the profile in `armada.toml`.\n\n5. **Check the claim.** Within a few minutes, `armada status` lists the ticket in flight, phase `planning`, runtime `Conductor`, and the ticket's claim comment reads `session: <workspaceId>/<sessionId>` and `profile: <name>`. No claim after `[policy] not_started_minutes` (ten by default): `armada watch` and `armada inbox` show a `not-started` entry; status lists it under \"Pending launches\" with `armada launch revoke ABC-12`. It says whether the worker never used its launch token (it never reached its login line) or signed in and stopped before its claim. An unused token expired more than an hour ago produces one `not started (token expired)` inbox notice, then clears. Exchanged launches without a claim stop being followed after 24 hours and remain revocable. Read the transcript (Status section). A worker whose launch token was refused (already used, or more than an hour old) needs a new one: `armada brief ABC-12 --prompt --profile-line` again, and message it only the `armada login --launch-token …` line of the new `--prompt` output (Message section). A worker cut off from Armada was revoked (Organization > Workers says by whom) or left idle for three days: ask the owner before you give a revoked worker a new token. If the worker cannot claim for another reason, fix the cause and message it; as a last resort record the handle yourself with `armada claim ABC-12 --runtime conductor --handle <workspaceId>/<sessionId> --profile <name>`, adding the brief's `--reason` for an override.\n\n## Message\n\n```sh\nprintf '%s\\n' \"Plan approved. Go on.\" | conductor --json message create --session <sessionId> --message-file -\nconductor --json message create --session <sessionId> --message-file - < /tmp/abc-12-answer.md\n```\n\nThe output is `{\"messageId\": …, \"state\": \"sent\"}`. Exit code 0 means Conductor accepted the message, not that the worker read it: check that the session turns `working`, then read its reply in the transcript. Use it to deliver an answer, a plan approval, or a heads-up that the default branch moved. Then record it in Armada: `armada answer <item> \"<answer>\"` for a question from `armada inbox`, `armada answer --note ABC-12 \"<message>\"` for a message the worker did not ask for.\n\n## Status\n\n```sh\nconductor --json session status <sessionId>\n```\n\nThe output is `{\"workspaceId\", \"sessionId\", \"status\", \"updatedAt\"}`. For a worker:\n\n- `working`: a turn is running. A silent worker that is `working` is busy (a long build or test run): leave it, and read the transcript if it stays silent past twice `policy.silence_minutes`.\n- `idle`: no turn is running. The worker finished its turn: it handed back, it waits for an answer, or it stopped without finishing. If `armada status` does not show it `ready-to-merge`, `awaiting-approval` or `blocked`, it has stopped: read its last reply, then message it to go on, or release and relaunch the ticket.\n- `error`: the last turn failed (agent or provider failure). Read the transcript and message it to resume; if it fails again, cancel, archive, release and relaunch.\n- Right after launch the session is `idle` for a few seconds while the workspace is initializing and the first message is queued; it turns `working` when the agent starts.\n\nThe workspace itself: `conductor --json workspace status <workspaceId>` gives `status` `initializing`, `ready` or `archived`.\n\n**Read the transcript** to see what a worker did or said. Events come oldest first, 100 per page; `hasMore` tells when to fetch the next page with `--after` the last event id. Keep the last id you read and poll from it.\n\n```sh\nconductor --json session message <sessionId> --limit 100 > /tmp/abc-12-events.json\njq -r '.hasMore, .data[-1].id' /tmp/abc-12-events.json\nconductor --json session message <sessionId> --after <lastEventId> --limit 100\n```\n\nThe second line prints whether more pages exist and the id to continue from. `.content.rawPayload` is the agent's own event format, so the filters depend on the worker's agent (the `agent` of its profile in `armada.toml`).\n\nA `claude` worker: each turn's final reply, then the commands and tools it ran.\n\n```sh\njq -r '.data[] | select(.content.rawPayload.type == \"result\") | .content.rawPayload | \"error=\\(.is_error)\\n\\(.result)\"' /tmp/abc-12-events.json\njq -r '.data[] | select(.content.rawPayload.type == \"assistant\") | .content.rawPayload.message.content[] | select(.type == \"tool_use\") | .input.command // .name' /tmp/abc-12-events.json\n```\n\nA `codex` worker: its events are `.content.rawPayload.event`, each item once as `item.started` and once as `item.completed`; read the completed ones. Its messages (`phase` is `commentary` along the way, `final_answer` at the end of a turn), then each command with its exit code, and its tool calls (Linear and other MCP servers).\n\n```sh\njq -r '.data[] | .content.rawPayload.event | select(.type == \"item.completed\") | .item | select(.type == \"agentMessage\") | \"[\\(.phase)] \\(.text)\"' /tmp/abc-12-events.json\njq -r '.data[] | .content.rawPayload.event | select(.type == \"item.completed\") | .item | select(.type == \"commandExecution\") | \"exit=\\(.exitCode) \\(.command)\"' /tmp/abc-12-events.json\njq -r '.data[] | .content.rawPayload.event | select(.type == \"item.completed\") | .item | select(.type == \"mcpToolCall\") | \"\\(.server) \\(.tool)\"' /tmp/abc-12-events.json\n```\n\nAnother agent, or a filter that prints nothing: count the event types, look at one event of the type you need, and adapt the filter.\n\n```sh\njq -r '.data[].content.rawPayload | .type // .event.type // \"(no payload)\"' /tmp/abc-12-events.json | sort | uniq -c\n```\n\n## Stop and archive\n\n```sh\nconductor --json session cancel <sessionId>\nconductor --json workspace archive <workspaceId>\n```\n\n- `session cancel` stops the running turn: `{\"status\", \"canceledQueuedMessages\"}`, and the session is `idle` within seconds. The workspace stays; a message starts a new turn. Use it on a worker that runs the wrong thing.\n- `workspace archive` answers `{\"status\": \"archived\"}`. Archive a worker's workspace after its pull request is merged, or after `armada release --ticket ABC-12 --reason \"<why>\"` for a worker that stops without handing back. The branch and the pull request stay on GitHub.\n- **Wait for `idle` before archiving.** A hand-back often arrives while the worker's session is still `working`: `armada report ready-to-merge` runs inside its last turn, which then writes its final reply. Archive only once `session status` answers `idle`. Poll it every 15 seconds; if it is still `working` after 10 minutes, cancel the turn and archive (the transcript keeps what it was doing). Run the whole block as one command; it can take up to 10 minutes, so run it in the background or give it a longer command timeout:\n\n```sh\nfor i in $(seq 40); do\n [ \"$(conductor --json session status <sessionId> | jq -r .status)\" = working ] || break\n sleep 15\ndone\n[ \"$(conductor --json session status <sessionId> | jq -r .status)\" = working ] && conductor --json session cancel <sessionId>\nconductor --json workspace archive <workspaceId>\n```\n- After an archive, `session status` still answers `idle`; `workspace status` says `archived`.\n"
|
|
6509
|
+
content: "---\nname: armada-runtime-conductor\ndescription: Runtime guide for running Armada workers on Conductor Cloud. Use when an Armada coordinator must launch a worker on a ticket, send it a message, check whether a silent worker is still alive, or stop and archive it. Four fixed sections, each with the exact conductor command and how to read its output.\n---\n\nArmada records Conductor and Claude Code runtime actions separately; persistent herdr workers use integrated commands. This guide tells the coordinator how to launch, message, check and stop a worker with the `conductor` command line tool, and what to record in Armada afterwards. It was checked against `conductor` 0.89.x (the desktop app's CLI, macOS) and 0.1.x (the CLI inside a Conductor Cloud workspace, Linux); every command below works in both. `conductor --version` prints yours; if a flag is refused, compare with `conductor <command> --help`.\n\n- On a Mac, the app ships the CLI at `/Applications/Conductor.app/Contents/Resources/bin/conductor`, which is not on PATH. `armada doctor` looks for it and prints the fix: a link from a directory already on PATH (`ln -s \"/Applications/Conductor.app/Contents/Resources/bin/conductor\" ~/.local/bin/conductor`), or a PATH line for your shell profile.\n- Always pass `--json` and read fields with `jq`. Exit codes: 0 ok, 1 runtime error, 2 usage error, 3 authentication, 4 server error.\n- On exit code 3, `conductor auth whoami` checks the token the CLI uses (it exits 0 when the token works). Do not rely on `conductor auth status`: it only looks for a macOS Keychain entry and fails on Linux (\"Keychain storage is only supported on macOS\"). In a Conductor Cloud workspace the CLI reads `CONDUCTOR_API_KEY` from the environment and needs no login; on a Mac, `conductor auth login` stores a token in the Keychain.\n- A worker is one workspace with one session. Its Armada handle is `<workspaceId>/<sessionId>`; the worker's claim comment carries it, so `armada status` and the ticket always lead back to the session.\n- A worker needs no key in its workspace: the prompt of `armada brief` carries a one-time launch token, and the worker's first command exchanges it for a session limited to its ticket, through which Armada gives each command its keys. The token works once, within the hour, so a copy left in a transcript is useless once used.\n- Never type a secret value into a command, a file or a message: name the variable and let your shell expand it. The expanded value is still in the `conductor` process's arguments while it runs, so launch from a machine only you use.\n\n## Launch\n\nThe brief starts `armada heartbeat --every 5m --parent \"$PPID\" --background` immediately after claim. It creates a detached process group (like `nohup` + `setsid`) with closed terminal streams and a PID file under `~/.config/armada/watch/`. Plain `&` and `nohup` alone can be killed by command-tool cleanup on Cloud. Detachment does not extend the monitored agent's lifetime: `$PPID` in the agent's command shell is the agent process, never `$$` (the shell), and a runtime may replace that process between turns. The heartbeat stops with that parent or when Armada ends the current session (release, merge, revoke).\n\nWorkers in `awaiting-approval`, `blocked` or `awaiting-validation` end their turn and need no heartbeat or manual report while the decision is pending. After delivering and recording an answer, let the worker resume: it reports its working phase and runs the brief's heartbeat line again with the current `$PPID`. An existing heartbeat for the same claim is kept. Armada counts silence from the newest heartbeat, report or answer, so a heartbeat left over from a previous turn cannot make a newly resumed worker immediately silent. An answered worker that never resumes still becomes silent after `policy.silence_minutes`. If startup fails or the runtime cannot retain any background process, fall back to manual reports at least every 15 minutes during active work and record that fallback on the ticket. Reports remain meaningful progress updates; `policy.quiet_minutes` counts time without a report while heartbeats arrive.\n\n1. Pick a ready ticket from `armada status` that does not collide with work in flight.\n2. Read the ticket and parent, then choose its profile. A matching label rule wins; otherwise match the profiles' `when` rules by most files/work. Mixed front-end/back-end work: choose the larger part and say why with `--profile <name> --reason \"<why>\"`. An optional `armada brief ABC-12` or `--json` preview helps resolve the choice and warnings, but is read-only: neither creates a launch token nor marks a worker in flight. If the choice is still needed, `--prompt` refuses before minting anything.\n3. **Make one brief call for the launch:** `--prompt --profile-line` writes only the worker prompt to stdout and the selected profile (agent, model, effort, fast mode, runtime and reason) to stderr. Read that line to configure Conductor; no second brief is needed for the profile. Keep any `--profile` and `--reason` flags on this call. Resolve warnings before launching. Never cut a launch message from the human view or `--json`: they carry no token. Write the prompt to a file only you can read, then add what only you know (the boundary with a parallel worker, a decision not yet on the ticket). The token works once, within the hour; if you cancel or the runtime launch fails, use `armada launch revoke ABC-12`. Generate a fresh prompt if its token has expired.\n\n```sh\n(umask 077; armada brief ABC-12 --prompt --profile-line > /tmp/abc-12-brief.md)\n```\n\n4. Create the workspace with every value from the profile. Never leave the agent, model or effort to Conductor's defaults. Add `--fast-mode` when the profile says fast mode. Run the whole block as one command: shell state does not carry over between separate calls.\n\n```sh\nconductor --json workspace create \\\n --repo-url https://github.com/<owner>/<name> \\\n --branch main \\\n --name \"ABC-12 <short title>\" \\\n --agent claude --model opus-5-5-1m --effort high \\\n --message-file - \\\n --env ARMADA_TICKET=ABC-12 \\\n < /tmp/abc-12-brief.md > /tmp/abc-12-launch.json\nrm -f /tmp/abc-12-brief.md\njq -r '\"\\(.workspaceId)/\\(.sessionId)\"' /tmp/abc-12-launch.json\n```\n\nIf the prompt has no launch token, its stderr warning says why. Not signed in: `armada login` (a headless coordinator sets `ARMADA_API_KEY`), then generate a new prompt; `armada doctor` checks the sign-in. Only on an Armada that keeps no keys yet (no accounts or no vault), pass the keys the read-only brief's environment table marks `required`, from your shell or from Armada's credentials file (`in credentials file`: the `set -a` line loads it without printing it; drop it when every variable is set in your shell). The subshell keeps the keys out of the rest of your session. Without a launch token the worker is not signed in to Armada: its claims and reports reach Linear only, with a warning. When Conductor's organization environment still holds the keys, every workspace already has them: use the first block.\n\n```sh\n(\n set -a; . \"${XDG_CONFIG_HOME:-$HOME/.config}/armada/credentials\"; set +a\n [ -n \"$LINEAR_API_KEY\" ] || { echo \"LINEAR_API_KEY is missing\" >&2; exit 1; }\n conductor --json workspace create \\\n --repo-url https://github.com/<owner>/<name> \\\n --branch main \\\n --name \"ABC-12 <short title>\" \\\n --agent claude --model opus-5-5-1m --effort high \\\n --message-file - \\\n --env ARMADA_TICKET=ABC-12 \\\n --env LINEAR_API_KEY=\"$LINEAR_API_KEY\" \\\n < /tmp/abc-12-brief.md > /tmp/abc-12-launch.json\n)\nrm -f /tmp/abc-12-brief.md\n```\n\n- `--branch` is the base branch (the default branch). Conductor creates a branch named `conductor/<slug of --name>`; the brief tells the worker to rename it to the ticket's branch.\n- The output has `workspaceId`, `sessionId`, `deepLink` and `initialMessage` (`messageId`, `state: \"queued\"`). Keep the handle the `jq` line prints, and give the owner the `deepLink` when they want to watch.\n- Conductor sets `CONDUCTOR_WORKSPACE_ID` and `CONDUCTOR_SESSION_ID` inside the workspace, and signs `gh` in for the worker's pushes. The brief's first commands install your Armada version (`npm install -g`), sign in with the launch token (`armada login --launch-token`) and claim the ticket. `--env` values are not shown back by `workspace get`.\n- Keys in Conductor's organization environment reach every workspace, workers included: once Armada keeps the organization's keys, they belong on Armada's Keys page, not there.\n- An unknown agent, model or effort fails the command. Check the ids with `conductor model` (each agent's models, efforts and defaults) and fix the profile in `armada.toml`.\n\n5. **Check the claim.** Within a few minutes, `armada status` lists the ticket in flight, phase `planning`, runtime `Conductor`, and the ticket's claim comment reads `session: <workspaceId>/<sessionId>` and `profile: <name>`. No claim after `[policy] not_started_minutes` (ten by default): `armada watch` and `armada inbox` show a `not-started` entry; status lists it under \"Pending launches\" with `armada launch revoke ABC-12`. It says whether the worker never used its launch token (it never reached its login line) or signed in and stopped before its claim. An unused token expired more than an hour ago produces one `not started (token expired)` inbox notice, then clears. Exchanged launches without a claim stop being followed after 24 hours and remain revocable. Read the transcript (Status section). A worker whose launch token was refused (already used, or more than an hour old) needs a new one: `armada brief ABC-12 --prompt --profile-line` again, and message it only the `armada login --launch-token …` line of the new `--prompt` output (Message section). A worker cut off from Armada was revoked (Organization > Workers says by whom) or left idle for three days: ask the owner before you give a revoked worker a new token. If the worker cannot claim for another reason, fix the cause and message it; as a last resort record the handle yourself with `armada claim ABC-12 --runtime conductor --handle <workspaceId>/<sessionId> --profile <name>`, adding the brief's `--reason` for an override.\n\n## Message\n\n```sh\nprintf '%s\\n' \"Plan approved. Go on.\" | conductor --json message create --session <sessionId> --message-file -\nconductor --json message create --session <sessionId> --message-file - < /tmp/abc-12-answer.md\n```\n\nThe output is `{\"messageId\": …, \"state\": \"sent\"}`. Exit code 0 means Conductor accepted the message, not that the worker read it: check that the session turns `working`, then read its reply in the transcript. Use it to deliver an answer, a plan approval, or a heads-up that the default branch moved. Then record it in Armada: `armada answer <item> \"<answer>\"` for a question from `armada inbox`, `armada answer --note ABC-12 \"<message>\"` for a message the worker did not ask for.\n\n## Status\n\n```sh\nconductor --json session status <sessionId>\n```\n\nThe output is `{\"workspaceId\", \"sessionId\", \"status\", \"updatedAt\"}`. For a worker:\n\n- `working`: a turn is running. A silent worker that is `working` is busy (a long build or test run): leave it, and read the transcript if it stays silent past twice `policy.silence_minutes`.\n- `idle`: no turn is running. The worker finished its turn: it handed back, it waits for an answer, or it stopped without finishing. If `armada status` does not show it `ready-to-merge`, `awaiting-approval`, `awaiting-validation` or `blocked`, it has stopped: read its last reply, then message it to go on, or release and relaunch the ticket.\n- `error`: the last turn failed (agent or provider failure). Read the transcript and message it to resume; if it fails again, cancel, archive, release and relaunch.\n- Right after launch the session is `idle` for a few seconds while the workspace is initializing and the first message is queued; it turns `working` when the agent starts.\n\nThe workspace itself: `conductor --json workspace status <workspaceId>` gives `status` `initializing`, `ready` or `archived`.\n\n**Read the transcript** to see what a worker did or said. Events come oldest first, 100 per page; `hasMore` tells when to fetch the next page with `--after` the last event id. Keep the last id you read and poll from it.\n\n```sh\nconductor --json session message <sessionId> --limit 100 > /tmp/abc-12-events.json\njq -r '.hasMore, .data[-1].id' /tmp/abc-12-events.json\nconductor --json session message <sessionId> --after <lastEventId> --limit 100\n```\n\nThe second line prints whether more pages exist and the id to continue from. `.content.rawPayload` is the agent's own event format, so the filters depend on the worker's agent (the `agent` of its profile in `armada.toml`).\n\nA `claude` worker: each turn's final reply, then the commands and tools it ran.\n\n```sh\njq -r '.data[] | select(.content.rawPayload.type == \"result\") | .content.rawPayload | \"error=\\(.is_error)\\n\\(.result)\"' /tmp/abc-12-events.json\njq -r '.data[] | select(.content.rawPayload.type == \"assistant\") | .content.rawPayload.message.content[] | select(.type == \"tool_use\") | .input.command // .name' /tmp/abc-12-events.json\n```\n\nA `codex` worker: its events are `.content.rawPayload.event`, each item once as `item.started` and once as `item.completed`; read the completed ones. Its messages (`phase` is `commentary` along the way, `final_answer` at the end of a turn), then each command with its exit code, and its tool calls (Linear and other MCP servers).\n\n```sh\njq -r '.data[] | .content.rawPayload.event | select(.type == \"item.completed\") | .item | select(.type == \"agentMessage\") | \"[\\(.phase)] \\(.text)\"' /tmp/abc-12-events.json\njq -r '.data[] | .content.rawPayload.event | select(.type == \"item.completed\") | .item | select(.type == \"commandExecution\") | \"exit=\\(.exitCode) \\(.command)\"' /tmp/abc-12-events.json\njq -r '.data[] | .content.rawPayload.event | select(.type == \"item.completed\") | .item | select(.type == \"mcpToolCall\") | \"\\(.server) \\(.tool)\"' /tmp/abc-12-events.json\n```\n\nAnother agent, or a filter that prints nothing: count the event types, look at one event of the type you need, and adapt the filter.\n\n```sh\njq -r '.data[].content.rawPayload | .type // .event.type // \"(no payload)\"' /tmp/abc-12-events.json | sort | uniq -c\n```\n\n## Stop and archive\n\n```sh\nconductor --json session cancel <sessionId>\nconductor --json workspace archive <workspaceId>\n```\n\n- `session cancel` stops the running turn: `{\"status\", \"canceledQueuedMessages\"}`, and the session is `idle` within seconds. The workspace stays; a message starts a new turn. Use it on a worker that runs the wrong thing.\n- `workspace archive` answers `{\"status\": \"archived\"}`. Archive a worker's workspace after its pull request is merged, or after `armada release --ticket ABC-12 --reason \"<why>\"` for a worker that stops without handing back. The branch and the pull request stay on GitHub.\n- **Wait for `idle` before archiving.** A hand-back often arrives while the worker's session is still `working`: `armada report ready-to-merge` runs inside its last turn, which then writes its final reply. Archive only once `session status` answers `idle`. Poll it every 15 seconds; if it is still `working` after 10 minutes, cancel the turn and archive (the transcript keeps what it was doing). Run the whole block as one command; it can take up to 10 minutes, so run it in the background or give it a longer command timeout:\n\n```sh\nfor i in $(seq 40); do\n [ \"$(conductor --json session status <sessionId> | jq -r .status)\" = working ] || break\n sleep 15\ndone\n[ \"$(conductor --json session status <sessionId> | jq -r .status)\" = working ] && conductor --json session cancel <sessionId>\nconductor --json workspace archive <workspaceId>\n```\n- After an archive, `session status` still answers `idle`; `workspace status` says `archived`.\n"
|
|
6175
6510
|
}
|
|
6176
6511
|
]
|
|
6177
6512
|
},
|
|
@@ -6199,8 +6534,8 @@ You are a worker. You own exactly one ticket, named in your launch brief. You tu
|
|
|
6199
6534
|
## Rules
|
|
6200
6535
|
|
|
6201
6536
|
- **Never merge**, never enable auto-merge, never approve your own plan. The coordinator merges.
|
|
6202
|
-
- **Start the heartbeat right after claim**, using the line in your brief. It pings Armada only, never Linear. Conductor's \`--background\` detaches it and keeps a PID file
|
|
6203
|
-
- **Report at each real step** with \`armada report <phase> --message "<what changed, what is next>"\`: the plan, meaningful implementation progress, blockers, tests, shipping and hand-back. The same phase is allowed. Reports
|
|
6537
|
+
- **Start the heartbeat right after claim**, using the line in your brief. It pings Armada only, never Linear. Conductor's \`--background\` detaches it from the command shell and keeps a PID file. Pass the agent PID, \`$PPID\` in its command shell, not the short-lived shell \`$$\`. The heartbeat stops when that agent process exits; a runtime may replace it between turns. While the phase is \`awaiting-approval\`, \`blocked\` or \`awaiting-validation\`, end your turn as instructed: no heartbeat or manual liveness report is required until someone answers. On resume, report the working phase and run the brief's heartbeat line again with the current \`$PPID\` (an existing heartbeat for the same claim is kept). A newer answer or report starts a fresh \`policy.silence_minutes\` window, even if the previous heartbeat is stale. On Claude Code use the subagent's background Bash without \`--background\`: it dies with the subagent, as intended. If startup fails or the runtime cannot retain any background process, fall back to manual reports at least every 15 minutes during active work and say so on the ticket. Older CLIs keep that manual rule too.
|
|
6538
|
+
- **Report at each real step** with \`armada report <phase> --message "<what changed, what is next>"\`: the plan, meaningful implementation progress, blockers, tests, shipping and hand-back. The same phase is allowed. Reports describe progress: \`policy.silence_minutes\` measures time since the newest heartbeat, report or answer (15 by default); unanswered waiting phases are exempt; \`policy.quiet_minutes\` is a coordinator-only reminder for a live worker without a report (45 by default). Never post empty reports just to look alive.
|
|
6204
6539
|
- **Keep going on setup choices.** When setup needs a choice (an install fallback, a retry, a missing tool), pick the safe option, say which in your next report, and keep going: never stop to ask about it. Ask only for product decisions.
|
|
6205
6540
|
- **Ask instead of guessing** when a choice changes the ticket's outcome: \`armada ask "<question and your recommendation>" --options "<a> | <b>"\`. Your phase becomes \`blocked\` and the question reaches the coordinator's inbox. Then **stop and end your turn**: the answer arrives as a message in this session, not in a command's output. When it arrives, report the phase you resume, for example \`armada report implementing --message "resumed: <the decision>"\`. Decide reversible technical choices yourself and record each one, with its reason, on the ticket and in the pull request.
|
|
6206
6541
|
- **Show the owner when your brief says so.** A brief with an "Owner validation" block names what the owner must see before the work goes on (a design ticket: the mockup itself). Produce it, then \`armada validate "<what to check>" --attach <files|https-urls>... [--caption "<text>"]\`: the attachments and the question go to the owner's Validations page on Armada, your phase becomes \`awaiting-validation\`, and the command prints the approval link. Then **stop and end your turn**: the coordinator relays the owner's decision in this session. On "Request changes", revise and run \`armada validate\` again (it replaces the open one); on approval, report the phase you resume, or, for a design ticket, stop: the coordinator closes it and building it is another ticket. Never merge or build what the owner has not approved.
|
|
@@ -10156,7 +10491,7 @@ ${attachments.join(`
|
|
|
10156
10491
|
};
|
|
10157
10492
|
}
|
|
10158
10493
|
// package.json
|
|
10159
|
-
var version = "0.2.
|
|
10494
|
+
var version = "0.2.46";
|
|
10160
10495
|
|
|
10161
10496
|
// src/attach.ts
|
|
10162
10497
|
import { resolve } from "node:path";
|
|
@@ -10489,10 +10824,10 @@ async function authLogout(io) {
|
|
|
10489
10824
|
}
|
|
10490
10825
|
|
|
10491
10826
|
// src/brief.ts
|
|
10492
|
-
import { dirname as
|
|
10827
|
+
import { dirname as dirname4, join as join2 } from "node:path";
|
|
10493
10828
|
|
|
10494
10829
|
// src/watch.ts
|
|
10495
|
-
import { dirname as
|
|
10830
|
+
import { dirname as dirname3 } from "node:path";
|
|
10496
10831
|
|
|
10497
10832
|
// src/login.ts
|
|
10498
10833
|
var hostOf = (url) => {
|
|
@@ -10693,13 +11028,50 @@ async function logout(io) {
|
|
|
10693
11028
|
return 0;
|
|
10694
11029
|
}
|
|
10695
11030
|
|
|
10696
|
-
// src/
|
|
11031
|
+
// src/herdr.ts
|
|
11032
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
11033
|
+
import { dirname as dirname2 } from "node:path";
|
|
11034
|
+
|
|
11035
|
+
// src/first-run.ts
|
|
10697
11036
|
import { stripVTControlCharacters } from "node:util";
|
|
10698
|
-
|
|
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;
|
|
10699
11071
|
function providersFrom(raw, configuration) {
|
|
10700
11072
|
try {
|
|
10701
|
-
const catalog = JSON.parse(
|
|
10702
|
-
const config = JSON.parse(
|
|
11073
|
+
const catalog = JSON.parse(stripVTControlCharacters2(raw));
|
|
11074
|
+
const config = JSON.parse(stripVTControlCharacters2(configuration));
|
|
10703
11075
|
const providers = Array.isArray(catalog?.providers) ? catalog.providers.filter((provider) => provider && displayName(provider.id) && displayName(provider.name)) : [];
|
|
10704
11076
|
for (const [id, value] of Object.entries(config?.provider ?? {})) {
|
|
10705
11077
|
const name = value?.name;
|
|
@@ -10719,7 +11091,7 @@ function providersFrom(raw, configuration) {
|
|
|
10719
11091
|
}
|
|
10720
11092
|
function modelsFrom(raw, providers) {
|
|
10721
11093
|
const models = [];
|
|
10722
|
-
for (const match of
|
|
11094
|
+
for (const match of stripVTControlCharacters2(raw).matchAll(/^([^\s/#]+\/[^\s#]+)\r?\n(\{\r?\n[\s\S]*?^\})/gm)) {
|
|
10723
11095
|
try {
|
|
10724
11096
|
const metadata = JSON.parse(match[2] ?? "");
|
|
10725
11097
|
const id = match[1] ?? "";
|
|
@@ -10731,7 +11103,7 @@ function modelsFrom(raw, providers) {
|
|
|
10731
11103
|
return models;
|
|
10732
11104
|
}
|
|
10733
11105
|
function selectedModel(pane, models) {
|
|
10734
|
-
const lines =
|
|
11106
|
+
const lines = stripVTControlCharacters2(pane).split(`
|
|
10735
11107
|
`);
|
|
10736
11108
|
const footers = lines.flatMap((line, index) => {
|
|
10737
11109
|
const bordered = /^\s*╹/.test(lines[index + 1] ?? "");
|
|
@@ -10772,7 +11144,7 @@ async function verifyOpenCodeModel(io, pane, expected) {
|
|
|
10772
11144
|
}).catch(() => null);
|
|
10773
11145
|
if (reading?.code !== 0)
|
|
10774
11146
|
throw failure();
|
|
10775
|
-
const text =
|
|
11147
|
+
const text = stripVTControlCharacters2(reading.stdout);
|
|
10776
11148
|
if (/ProviderModelNotFoundError|Model not found:/i.test(text))
|
|
10777
11149
|
throw new UsageError(`OpenCode could not load profile model ${expected}; launch stopped`);
|
|
10778
11150
|
const selected = selectedModel(text, models);
|
|
@@ -10799,7 +11171,8 @@ var harnessArgs = (p) => [
|
|
|
10799
11171
|
"--model",
|
|
10800
11172
|
p.model,
|
|
10801
11173
|
...p.harness === "codex" ? ["-c", `model_reasoning_effort=${JSON.stringify(p.effort)}`] : p.harness === "claude" ? ["--effort", p.effort] : [],
|
|
10802
|
-
...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)
|
|
10803
11176
|
];
|
|
10804
11177
|
var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : null;
|
|
10805
11178
|
var id = (v) => typeof v === "string" && /^[a-zA-Z0-9][a-zA-Z0-9:_-]{0,127}$/.test(v);
|
|
@@ -10850,6 +11223,7 @@ var credentialNames = (env, extra) => [
|
|
|
10850
11223
|
|
|
10851
11224
|
class Herdr {
|
|
10852
11225
|
io;
|
|
11226
|
+
setupShell = null;
|
|
10853
11227
|
constructor(io) {
|
|
10854
11228
|
this.io = io;
|
|
10855
11229
|
}
|
|
@@ -10862,7 +11236,7 @@ class Herdr {
|
|
|
10862
11236
|
throw new Error("no exec");
|
|
10863
11237
|
const out = await this.io.exec("herdr", args, { cwd: this.io.cwd, timeoutMs });
|
|
10864
11238
|
code = out.code;
|
|
10865
|
-
if (code === 0 && !out.stdout.trim() && !out.stderr.trim() && ["pane run", "pane report-agent"].includes(operation))
|
|
11239
|
+
if (code === 0 && !out.stdout.trim() && !out.stderr.trim() && ["pane run", "pane report-agent", "pane report-metadata"].includes(operation))
|
|
10866
11240
|
return {};
|
|
10867
11241
|
reply = object(JSON.parse(out.stdout || out.stderr));
|
|
10868
11242
|
} catch {
|
|
@@ -10917,7 +11291,8 @@ class Herdr {
|
|
|
10917
11291
|
input.branch,
|
|
10918
11292
|
"--base",
|
|
10919
11293
|
input.base,
|
|
10920
|
-
"--no-focus"
|
|
11294
|
+
"--no-focus",
|
|
11295
|
+
...input.label ? ["--label", input.label] : []
|
|
10921
11296
|
])).result);
|
|
10922
11297
|
const workspace = object(r?.workspace)?.workspace_id;
|
|
10923
11298
|
const rootPane = object(r?.root_pane)?.pane_id;
|
|
@@ -10942,7 +11317,113 @@ class Herdr {
|
|
|
10942
11317
|
await this.call(["pane", "close", rootPane]);
|
|
10943
11318
|
return { workspace, pane, agent, path };
|
|
10944
11319
|
}
|
|
10945
|
-
async
|
|
11320
|
+
async setupRoot(repo, slug, secrets) {
|
|
11321
|
+
const result = object((await this.call(["worktree", "list", "--cwd", repo])).result);
|
|
11322
|
+
const source = object(result?.source);
|
|
11323
|
+
if (source?.source_checkout_path !== repo || typeof source.repo_root !== "string" || !source.repo_root.startsWith("/") || !Array.isArray(result?.worktrees))
|
|
11324
|
+
throw new UsageError("invalid herdr worktree list response; inspect herdr worktree list before setup");
|
|
11325
|
+
const branch = `armada-local-setup-${slug}`;
|
|
11326
|
+
const label = `Armada local setup checkout: ${slug}`;
|
|
11327
|
+
const found = result.worktrees.map(object).find((tree) => tree?.branch === branch);
|
|
11328
|
+
let path;
|
|
11329
|
+
if (found) {
|
|
11330
|
+
if (found.is_linked_worktree !== true || typeof found.path !== "string" || !found.path.startsWith("/"))
|
|
11331
|
+
throw new UsageError(`the setup branch ${branch} already exists outside Armada setup; leave it untouched and choose another project slug`);
|
|
11332
|
+
path = found.path;
|
|
11333
|
+
} else {
|
|
11334
|
+
path = (await this.create({ repo, branch, base: "HEAD", ticket: "setup-local", secrets, label })).path;
|
|
11335
|
+
}
|
|
11336
|
+
const root = dirname2(path);
|
|
11337
|
+
if (root === "/" || [...root].some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127))
|
|
11338
|
+
throw new UsageError("invalid herdr worktree parent directory");
|
|
11339
|
+
return { root, repo: source.repo_root };
|
|
11340
|
+
}
|
|
11341
|
+
async setupWorkspace(root, secrets) {
|
|
11342
|
+
const label = `Armada local setup: ${root}`;
|
|
11343
|
+
const workspaces = object((await this.call(["workspace", "list"])).result)?.workspaces;
|
|
11344
|
+
if (!Array.isArray(workspaces))
|
|
11345
|
+
throw new UsageError("invalid herdr workspace list response");
|
|
11346
|
+
const matches = workspaces.map(object).filter((ws) => ws?.label === label);
|
|
11347
|
+
if (matches.length > 1)
|
|
11348
|
+
throw new UsageError("multiple local setup workspaces; inspect herdr workspace list before retrying");
|
|
11349
|
+
if (matches.length) {
|
|
11350
|
+
const workspace = matches[0]?.workspace_id;
|
|
11351
|
+
if (!id(workspace))
|
|
11352
|
+
throw new UsageError("invalid herdr setup workspace response");
|
|
11353
|
+
return workspace;
|
|
11354
|
+
}
|
|
11355
|
+
const result = object((await this.call([
|
|
11356
|
+
"workspace",
|
|
11357
|
+
"create",
|
|
11358
|
+
"--cwd",
|
|
11359
|
+
root,
|
|
11360
|
+
"--label",
|
|
11361
|
+
label,
|
|
11362
|
+
"--no-focus",
|
|
11363
|
+
...credentialNames(this.io.env, secrets).flatMap((name) => ["--env", `${name}=`]),
|
|
11364
|
+
"--env",
|
|
11365
|
+
"ARMADA_TICKET="
|
|
11366
|
+
])).result);
|
|
11367
|
+
const workspace = object(result?.workspace)?.workspace_id;
|
|
11368
|
+
const pane = object(result?.root_pane);
|
|
11369
|
+
if (!id(workspace) || !id(pane?.pane_id) || pane?.workspace_id !== workspace)
|
|
11370
|
+
throw new UsageError("invalid herdr setup workspace response");
|
|
11371
|
+
this.setupShell = { workspace, pane: String(pane?.pane_id) };
|
|
11372
|
+
return workspace;
|
|
11373
|
+
}
|
|
11374
|
+
async setupPane(workspace, root, profile, secrets) {
|
|
11375
|
+
const kind = herdrHarnessKind(profile.harness);
|
|
11376
|
+
const fingerprint = createHash3("sha256").update(JSON.stringify([kind, ...harnessArgs(profile)])).digest("hex").slice(0, 32);
|
|
11377
|
+
const name = `setup-${workspace}-${kind}`;
|
|
11378
|
+
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(name))
|
|
11379
|
+
throw new UsageError("cannot name the setup agent for this workspace");
|
|
11380
|
+
const agents = object((await this.call(["agent", "list"])).result)?.agents;
|
|
11381
|
+
if (!Array.isArray(agents))
|
|
11382
|
+
throw new UsageError("invalid herdr agent list response");
|
|
11383
|
+
const matches = agents.map(object).filter((agent) => agent?.name === name);
|
|
11384
|
+
if (matches.length > 1)
|
|
11385
|
+
throw new UsageError("multiple setup agents; inspect herdr agent list");
|
|
11386
|
+
if (matches.length) {
|
|
11387
|
+
const agent = matches[0];
|
|
11388
|
+
if (agent?.workspace_id !== workspace || !id(agent.pane_id) || agent.cwd !== root || agent.agent !== kind)
|
|
11389
|
+
throw new UsageError("setup agent identity or directory changed; inspect herdr agent list before retrying");
|
|
11390
|
+
if (object(agent.tokens)?.armadaSetup !== fingerprint)
|
|
11391
|
+
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`);
|
|
11392
|
+
return { handle: { workspace, pane: agent.pane_id, agent: name, path: root }, existing: true };
|
|
11393
|
+
}
|
|
11394
|
+
const result = object((await this.call([
|
|
11395
|
+
"tab",
|
|
11396
|
+
"create",
|
|
11397
|
+
"--workspace",
|
|
11398
|
+
workspace,
|
|
11399
|
+
"--cwd",
|
|
11400
|
+
root,
|
|
11401
|
+
"--label",
|
|
11402
|
+
kind,
|
|
11403
|
+
"--no-focus",
|
|
11404
|
+
...credentialNames(this.io.env, secrets).flatMap((key) => ["--env", `${key}=`]),
|
|
11405
|
+
"--env",
|
|
11406
|
+
"ARMADA_TICKET="
|
|
11407
|
+
])).result);
|
|
11408
|
+
const pane = object(result?.root_pane);
|
|
11409
|
+
if (!id(pane?.pane_id) || pane?.workspace_id !== workspace)
|
|
11410
|
+
throw new UsageError("invalid herdr setup pane response");
|
|
11411
|
+
await this.call([
|
|
11412
|
+
"pane",
|
|
11413
|
+
"report-metadata",
|
|
11414
|
+
pane.pane_id,
|
|
11415
|
+
"--source",
|
|
11416
|
+
"armada-setup",
|
|
11417
|
+
"--token",
|
|
11418
|
+
`armadaSetup=${fingerprint}`
|
|
11419
|
+
]);
|
|
11420
|
+
if (this.setupShell?.workspace === workspace) {
|
|
11421
|
+
await this.call(["pane", "close", this.setupShell.pane]);
|
|
11422
|
+
this.setupShell = null;
|
|
11423
|
+
}
|
|
11424
|
+
return { handle: { workspace, pane: pane.pane_id, agent: name, path: root }, existing: false };
|
|
11425
|
+
}
|
|
11426
|
+
async start(handle, profile, timeoutMs = 30000, verifyModel = true) {
|
|
10946
11427
|
const r = await this.call([
|
|
10947
11428
|
"agent",
|
|
10948
11429
|
"start",
|
|
@@ -10952,12 +11433,12 @@ class Herdr {
|
|
|
10952
11433
|
"--pane",
|
|
10953
11434
|
handle.pane,
|
|
10954
11435
|
"--timeout",
|
|
10955
|
-
|
|
11436
|
+
String(timeoutMs),
|
|
10956
11437
|
"--",
|
|
10957
11438
|
...harnessArgs(profile)
|
|
10958
11439
|
]);
|
|
10959
11440
|
this.checkAgent(r, handle);
|
|
10960
|
-
if (herdrHarnessKind(profile.harness) === "opencode") {
|
|
11441
|
+
if (verifyModel && herdrHarnessKind(profile.harness) === "opencode") {
|
|
10961
11442
|
try {
|
|
10962
11443
|
await verifyOpenCodeModel(this.io, handle.pane, profile.model);
|
|
10963
11444
|
} catch (error) {
|
|
@@ -10970,11 +11451,121 @@ class Herdr {
|
|
|
10970
11451
|
}
|
|
10971
11452
|
}
|
|
10972
11453
|
}
|
|
11454
|
+
async inspect(handle, harness) {
|
|
11455
|
+
const agent = this.checkAgent(await this.call(["agent", "get", handle.pane], 5000), handle);
|
|
11456
|
+
if (agent.agent !== undefined && agent.agent !== null && agent.agent !== herdrHarnessKind(harness))
|
|
11457
|
+
throw new UsageError("herdr worker harness changed; inspect herdr agent list before retrying");
|
|
11458
|
+
const state = agent.agent_status;
|
|
11459
|
+
if (!["working", "blocked", "idle", "done", "unknown"].includes(String(state)))
|
|
11460
|
+
throw new UsageError("invalid herdr agent state");
|
|
11461
|
+
let text;
|
|
11462
|
+
try {
|
|
11463
|
+
if (!this.io.exec)
|
|
11464
|
+
throw new Error("no exec");
|
|
11465
|
+
const result = await this.io.exec("herdr", ["pane", "read", handle.pane, "--source", "visible", "--lines", "80"], {
|
|
11466
|
+
cwd: this.io.cwd,
|
|
11467
|
+
timeoutMs: 5000
|
|
11468
|
+
});
|
|
11469
|
+
if (result.code !== 0)
|
|
11470
|
+
throw new Error("read failed");
|
|
11471
|
+
text = result.stdout;
|
|
11472
|
+
} catch {
|
|
11473
|
+
throw new UsageError(`could not inspect the worker screen; run herdr agent attach ${handle.agent}`);
|
|
11474
|
+
}
|
|
11475
|
+
return {
|
|
11476
|
+
state,
|
|
11477
|
+
ready: (state === "idle" || state === "done") && agent.interactive_ready !== false && agent.launch_pending !== true,
|
|
11478
|
+
issue: firstRunIssue(harness, text)
|
|
11479
|
+
};
|
|
11480
|
+
}
|
|
11481
|
+
screenError(handle, issue, message = "The harness needs the owner's attention") {
|
|
11482
|
+
return new UsageError(`${issue?.message ?? message}: run armada setup local, or answer it with herdr agent attach ${handle.agent}`, `herdr agent attach ${handle.agent}`);
|
|
11483
|
+
}
|
|
11484
|
+
async checkProfileModel(handle, profile) {
|
|
11485
|
+
if (herdrHarnessKind(profile.harness) !== "opencode")
|
|
11486
|
+
return;
|
|
11487
|
+
try {
|
|
11488
|
+
await verifyOpenCodeModel(this.io, handle.pane, profile.model);
|
|
11489
|
+
} catch (error) {
|
|
11490
|
+
const screen = await this.inspect(handle, profile.harness);
|
|
11491
|
+
throw this.screenError(handle, screen.issue, error instanceof UsageError ? error.message : "Could not verify the OpenCode profile model");
|
|
11492
|
+
}
|
|
11493
|
+
}
|
|
11494
|
+
async startChecked(handle, profile) {
|
|
11495
|
+
try {
|
|
11496
|
+
await this.start(handle, profile, 3500, false);
|
|
11497
|
+
} catch (error) {
|
|
11498
|
+
if (!(error instanceof HerdrError) || !["agent_not_ready", "timeout"].includes(error.code ?? ""))
|
|
11499
|
+
throw error;
|
|
11500
|
+
}
|
|
11501
|
+
const now = this.io.now ?? (() => new Date);
|
|
11502
|
+
const deadline = now().getTime() + 30000;
|
|
11503
|
+
for (let attempt = 0;attempt < 120 && now().getTime() < deadline; attempt++) {
|
|
11504
|
+
const screen = await this.inspect(handle, profile.harness);
|
|
11505
|
+
if (screen.issue || screen.state === "blocked")
|
|
11506
|
+
throw this.screenError(handle, screen.issue);
|
|
11507
|
+
if (screen.ready) {
|
|
11508
|
+
await this.checkProfileModel(handle, profile);
|
|
11509
|
+
return;
|
|
11510
|
+
}
|
|
11511
|
+
await (this.io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))))(250);
|
|
11512
|
+
}
|
|
11513
|
+
throw this.screenError(handle, null, "The harness did not become ready");
|
|
11514
|
+
}
|
|
11515
|
+
async promptChecked(handle, profile, prompt) {
|
|
11516
|
+
const before = await this.inspect(handle, profile.harness);
|
|
11517
|
+
if (before.issue || !before.ready)
|
|
11518
|
+
throw this.screenError(handle, before.issue);
|
|
11519
|
+
await this.checkProfileModel(handle, profile);
|
|
11520
|
+
try {
|
|
11521
|
+
await this.prompt(handle, prompt);
|
|
11522
|
+
} catch (error) {
|
|
11523
|
+
const screen = await this.inspect(handle, profile.harness);
|
|
11524
|
+
if (screen.issue || screen.state === "blocked")
|
|
11525
|
+
throw this.screenError(handle, screen.issue);
|
|
11526
|
+
if (error instanceof HerdrError && ["agent_prompt_stalled", "timeout"].includes(error.code ?? ""))
|
|
11527
|
+
throw this.screenError(handle, null, "The harness did not accept the brief");
|
|
11528
|
+
throw error;
|
|
11529
|
+
}
|
|
11530
|
+
}
|
|
11531
|
+
async checkSetupModel(handle, profile) {
|
|
11532
|
+
const screen = await this.inspect(handle, profile.harness);
|
|
11533
|
+
if (screen.issue || !screen.ready)
|
|
11534
|
+
throw this.screenError(handle, screen.issue);
|
|
11535
|
+
await this.checkProfileModel(handle, profile);
|
|
11536
|
+
try {
|
|
11537
|
+
const agent = this.checkAgent(await this.call([
|
|
11538
|
+
"agent",
|
|
11539
|
+
"prompt",
|
|
11540
|
+
handle.pane,
|
|
11541
|
+
"Reply with OK only. Do not read files, run commands or modify anything.",
|
|
11542
|
+
"--wait",
|
|
11543
|
+
"--until",
|
|
11544
|
+
"idle",
|
|
11545
|
+
"--until",
|
|
11546
|
+
"done",
|
|
11547
|
+
"--timeout",
|
|
11548
|
+
"10000"
|
|
11549
|
+
], 12000), handle);
|
|
11550
|
+
const after = await this.inspect(handle, profile.harness);
|
|
11551
|
+
if (after.issue)
|
|
11552
|
+
throw this.screenError(handle, after.issue);
|
|
11553
|
+
if (!["idle", "done"].includes(String(agent.agent_status)) || !after.ready)
|
|
11554
|
+
throw this.screenError(handle, null, "The model did not finish the setup check");
|
|
11555
|
+
} catch (error) {
|
|
11556
|
+
const after = await this.inspect(handle, profile.harness);
|
|
11557
|
+
if (after.issue)
|
|
11558
|
+
throw this.screenError(handle, after.issue);
|
|
11559
|
+
if (error instanceof UsageError && !(error instanceof HerdrError))
|
|
11560
|
+
throw error;
|
|
11561
|
+
throw this.screenError(handle, null, "The model did not finish the setup check");
|
|
11562
|
+
}
|
|
11563
|
+
}
|
|
10973
11564
|
async prompt(handle, prompt) {
|
|
10974
11565
|
const r = await this.call([
|
|
10975
11566
|
"agent",
|
|
10976
11567
|
"prompt",
|
|
10977
|
-
handle.
|
|
11568
|
+
handle.pane,
|
|
10978
11569
|
prompt,
|
|
10979
11570
|
"--wait",
|
|
10980
11571
|
"--until",
|
|
@@ -11735,7 +12326,7 @@ async function watchUntil(io, config, credentials, json, configPath) {
|
|
|
11735
12326
|
if (!fleet)
|
|
11736
12327
|
throw new Refusal(`the inbox is on Armada, which cannot be reached: ${warning ?? "no answer"}`, "armada whoami");
|
|
11737
12328
|
const before = paths ? await readWatchState(paths, project) : null;
|
|
11738
|
-
await remember(io, project, { root:
|
|
12329
|
+
await remember(io, project, { root: dirname3(configPath), stopped: null });
|
|
11739
12330
|
const report = await watchInbox(observingFleet(watchingIo, fleet), {
|
|
11740
12331
|
project,
|
|
11741
12332
|
signal: controller.signal,
|
|
@@ -11809,7 +12400,7 @@ async function hookStop(io, rest, findConfig) {
|
|
|
11809
12400
|
const { path, text } = await findConfig({ ...io, cwd });
|
|
11810
12401
|
const project = parseConfig(text, path).project.slug;
|
|
11811
12402
|
const { state, running } = await watchOf(io, project);
|
|
11812
|
-
const d = stopHookDecision({ project, root:
|
|
12403
|
+
const d = stopHookDecision({ project, root: dirname3(path), state, watching: running, env: io.env });
|
|
11813
12404
|
if (d.block)
|
|
11814
12405
|
io.stdout(`${JSON.stringify({ decision: "block", reason: d.reason })}
|
|
11815
12406
|
`);
|
|
@@ -11938,7 +12529,7 @@ async function brief(io, config, credentials, a, version, configPath) {
|
|
|
11938
12529
|
if (!credentials.linearApiKey)
|
|
11939
12530
|
throw missingKey(LINEAR_KEY);
|
|
11940
12531
|
const extraPath = config.brief.extra;
|
|
11941
|
-
const conventions = extraPath ? { path: extraPath, text: await io.readFile(join2(
|
|
12532
|
+
const conventions = extraPath ? { path: extraPath, text: await io.readFile(join2(dirname4(configPath), extraPath)).catch(() => null) } : null;
|
|
11942
12533
|
let b;
|
|
11943
12534
|
try {
|
|
11944
12535
|
b = await loadBrief(config, {
|
|
@@ -12009,7 +12600,7 @@ ${next.line}
|
|
|
12009
12600
|
import { join as join4 } from "node:path";
|
|
12010
12601
|
|
|
12011
12602
|
// src/local-tools.ts
|
|
12012
|
-
import { stripVTControlCharacters as
|
|
12603
|
+
import { stripVTControlCharacters as stripVTControlCharacters3 } from "node:util";
|
|
12013
12604
|
var MINIMUM_HERDR_VERSION = "0.9.1";
|
|
12014
12605
|
var TOOLS = {
|
|
12015
12606
|
herdr: { command: "herdr", install: "curl -fsSL https://herdr.dev/install.sh | sh" },
|
|
@@ -12125,7 +12716,7 @@ async function openCodeModels(io) {
|
|
|
12125
12716
|
if (result?.code !== 0)
|
|
12126
12717
|
return null;
|
|
12127
12718
|
return [
|
|
12128
|
-
...new Set(
|
|
12719
|
+
...new Set(stripVTControlCharacters3(result.stdout).split(`
|
|
12129
12720
|
`).map((line) => line.trim()).filter((line) => /^[^\s/#]+\/[^\s#]+$/.test(line)))
|
|
12130
12721
|
];
|
|
12131
12722
|
}
|
|
@@ -12133,7 +12724,7 @@ async function claudeModels(io) {
|
|
|
12133
12724
|
const result = await probe(io, "claude", ["--help"], { timeoutMs: 5000, maxOutputBytes: 262144 });
|
|
12134
12725
|
if (result?.code !== 0)
|
|
12135
12726
|
return null;
|
|
12136
|
-
const help =
|
|
12727
|
+
const help = stripVTControlCharacters3(result.stdout);
|
|
12137
12728
|
const option = help.match(/(?:^|\n)\s+--model\s+<model>([\s\S]*?)(?=\n\s+--?[a-zA-Z]|$)/)?.[1];
|
|
12138
12729
|
if (!option)
|
|
12139
12730
|
return null;
|
|
@@ -12325,7 +12916,7 @@ async function ensureLocalProfile(io, configPath, name, profile) {
|
|
|
12325
12916
|
|
|
12326
12917
|
// src/repo.ts
|
|
12327
12918
|
import { lstat, mkdir as mkdir2, readdir, readFile as readFile2, readlink, rm as rm2, symlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
12328
|
-
import { dirname as
|
|
12919
|
+
import { dirname as dirname5, join as join3, relative, sep } from "node:path";
|
|
12329
12920
|
var absent = (err) => {
|
|
12330
12921
|
const code = err.code;
|
|
12331
12922
|
return code === "ENOENT" || code === "ENOTDIR" || code === "EISDIR";
|
|
@@ -12383,12 +12974,12 @@ async function applyPlan(root, plan) {
|
|
|
12383
12974
|
await rm2(join3(root, path), { force: true });
|
|
12384
12975
|
for (const w of plan.writes) {
|
|
12385
12976
|
const full = join3(root, w.path);
|
|
12386
|
-
await mkdir2(
|
|
12977
|
+
await mkdir2(dirname5(full), { recursive: true });
|
|
12387
12978
|
await writeFile2(full, w.content);
|
|
12388
12979
|
}
|
|
12389
12980
|
for (const l of plan.links) {
|
|
12390
12981
|
const full = join3(root, l.path);
|
|
12391
|
-
await mkdir2(
|
|
12982
|
+
await mkdir2(dirname5(full), { recursive: true });
|
|
12392
12983
|
if (await lstat(full).catch(() => null))
|
|
12393
12984
|
await rm2(full, { recursive: true, force: true });
|
|
12394
12985
|
await symlink(l.target, full);
|
|
@@ -12729,6 +13320,8 @@ function renderDoctor(r) {
|
|
|
12729
13320
|
const errors = r.checks.filter((c) => c.level === "error");
|
|
12730
13321
|
if (errors.length)
|
|
12731
13322
|
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}`);
|
|
13323
|
+
if (r.checks.some((c) => c.id === "local-herdr"))
|
|
13324
|
+
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.");
|
|
12732
13325
|
return `${lines.join(`
|
|
12733
13326
|
`)}
|
|
12734
13327
|
`;
|
|
@@ -12741,7 +13334,7 @@ async function doctor(io, json, armadaVersion) {
|
|
|
12741
13334
|
}
|
|
12742
13335
|
|
|
12743
13336
|
// src/heartbeat.ts
|
|
12744
|
-
import { createHash as
|
|
13337
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
12745
13338
|
async function heartbeat(io, config, credentials, args) {
|
|
12746
13339
|
if (args.rest.length)
|
|
12747
13340
|
throw new UsageError("heartbeat takes no positional argument");
|
|
@@ -12809,7 +13402,7 @@ async function heartbeat(io, config, credentials, args) {
|
|
|
12809
13402
|
return result;
|
|
12810
13403
|
},
|
|
12811
13404
|
ready: async (session) => {
|
|
12812
|
-
const name = `${config.project.slug}-heartbeat-${ticket.toLowerCase()}-${
|
|
13405
|
+
const name = `${config.project.slug}-heartbeat-${ticket.toLowerCase()}-${createHash4("sha256").update(`${handle}/${session.claimedAt}`).digest("hex").slice(0, 12)}`;
|
|
12813
13406
|
const acquired = await takeWatchLock(paths, name, pid, io.processAlive ?? processAlive);
|
|
12814
13407
|
if (acquired.taken)
|
|
12815
13408
|
lock = name;
|
|
@@ -13042,7 +13635,7 @@ async function init(io, opts) {
|
|
|
13042
13635
|
}
|
|
13043
13636
|
|
|
13044
13637
|
// src/launch.ts
|
|
13045
|
-
import { dirname as
|
|
13638
|
+
import { dirname as dirname6, join as join6 } from "node:path";
|
|
13046
13639
|
async function launch(io, config, credentials, args, version, configPath) {
|
|
13047
13640
|
if (args.rest[0] !== "revoke")
|
|
13048
13641
|
return launchLocal(io, config, credentials, args, version, configPath);
|
|
@@ -13159,7 +13752,7 @@ async function launchLocal(io, config, credentials, args, version, configPath) {
|
|
|
13159
13752
|
const base = remote.code === 0 ? remote.stdout.match(/^ref:\s+refs\/heads\/(\S+)\s+HEAD/m)?.[1] : null;
|
|
13160
13753
|
if (!base)
|
|
13161
13754
|
throw new UsageError("could not read the default branch of origin");
|
|
13162
|
-
const conventions = config.brief.extra ? { path: config.brief.extra, text: await io.readFile(join6(
|
|
13755
|
+
const conventions = config.brief.extra ? { path: config.brief.extra, text: await io.readFile(join6(dirname6(configPath), config.brief.extra)) } : null;
|
|
13163
13756
|
const npm = await checkPublished(version, io.fetch ?? fetch);
|
|
13164
13757
|
if (npm.state === "missing")
|
|
13165
13758
|
throw new UsageError(`armada ${version} is not on npm yet; publish this version before launching local workers`);
|
|
@@ -13190,13 +13783,23 @@ async function launchLocal(io, config, credentials, args, version, configPath) {
|
|
|
13190
13783
|
},
|
|
13191
13784
|
herdr: { choice, handle: herdrClaimHandle(handle) }
|
|
13192
13785
|
});
|
|
13193
|
-
await runtime.
|
|
13194
|
-
await runtime.
|
|
13786
|
+
await runtime.startChecked(handle, choice.profile);
|
|
13787
|
+
await runtime.promptChecked(handle, choice.profile, b.prompt);
|
|
13195
13788
|
} catch (error) {
|
|
13196
13789
|
if (handle)
|
|
13197
13790
|
io.stderr(`armada: local workspace retained: ${herdrClaimHandle(handle)}
|
|
13198
13791
|
`);
|
|
13199
|
-
|
|
13792
|
+
let revoked = false;
|
|
13793
|
+
try {
|
|
13794
|
+
await api.revokePendingLaunch(signIn, { project: config.project.slug, ticket: ticketId, id: launch.worker.id });
|
|
13795
|
+
revoked = true;
|
|
13796
|
+
io.stderr(`armada: revoked the pending launch of ${ticketId}.
|
|
13797
|
+
`);
|
|
13798
|
+
} catch {
|
|
13799
|
+
io.stderr(`armada: could not revoke the pending launch; run armada launch revoke ${ticketId} before retrying (a claimed worker must release).
|
|
13800
|
+
`);
|
|
13801
|
+
}
|
|
13802
|
+
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");
|
|
13200
13803
|
}
|
|
13201
13804
|
const known = (await watchOf(io, config.project.slug)).state?.inFlight ?? [];
|
|
13202
13805
|
const inFlightTickets = [...new Set([...known, ticketId])].sort();
|
|
@@ -13225,11 +13828,135 @@ ${watch.line}
|
|
|
13225
13828
|
return 0;
|
|
13226
13829
|
}
|
|
13227
13830
|
|
|
13831
|
+
// src/local-setup.ts
|
|
13832
|
+
async function setupLocal(io, initial, configPath, args) {
|
|
13833
|
+
if (args.rest.length !== 1 || args.rest[0] !== "local")
|
|
13834
|
+
throw new UsageError("setup needs a command: armada setup local");
|
|
13835
|
+
if (args.json || !io.interactive || io.env.CI || !io.prompt) {
|
|
13836
|
+
const message = "Local setup needs the owner at an interactive terminal to choose permissions and answer harness questions";
|
|
13837
|
+
io.stdout(args.json ? `${JSON.stringify({ ready: false, message, next: "armada setup local at an interactive terminal" })}
|
|
13838
|
+
` : `${message}: run armada setup local at an interactive terminal.
|
|
13839
|
+
`);
|
|
13840
|
+
return 1;
|
|
13841
|
+
}
|
|
13842
|
+
let config = initial;
|
|
13843
|
+
const profiles = Object.entries(config.herdr.profiles);
|
|
13844
|
+
if (!profiles.length)
|
|
13845
|
+
throw new UsageError("local setup needs at least one [herdr.profiles.<name>] in armada.toml");
|
|
13846
|
+
const unset = profiles.filter(([, p]) => p.permissions === undefined).map(([name]) => name);
|
|
13847
|
+
if (unset.length) {
|
|
13848
|
+
if (!io.writeFile)
|
|
13849
|
+
throw new UsageError("local setup needs configuration writes to save the owner's permission choice");
|
|
13850
|
+
const before = await io.readFile(configPath);
|
|
13851
|
+
if (before === null || JSON.stringify(parseConfig(before, configPath)) !== JSON.stringify(initial))
|
|
13852
|
+
throw new UsageError("configuration changed before setup; retry with the current armada.toml");
|
|
13853
|
+
io.stdout(`Choose permissions for local profiles: ${unset.join(", ")}.
|
|
13854
|
+
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).
|
|
13855
|
+
Trust, MCP, sign-in and model questions remain the owner's decisions.
|
|
13856
|
+
`);
|
|
13857
|
+
const answer = await io.prompt("Permissions [ask/full] (Enter for ask): ", { hidden: false });
|
|
13858
|
+
if (answer === null)
|
|
13859
|
+
return 1;
|
|
13860
|
+
const permissions = answer.trim().toLowerCase() || "ask";
|
|
13861
|
+
if (permissions !== "ask" && permissions !== "full") {
|
|
13862
|
+
io.stderr(`Choose ask or full; configuration unchanged.
|
|
13863
|
+
`);
|
|
13864
|
+
return 1;
|
|
13865
|
+
}
|
|
13866
|
+
if (await io.readFile(configPath) !== before) {
|
|
13867
|
+
io.stderr(`Configuration changed while you chose permissions; retry setup without overwriting that edit.
|
|
13868
|
+
`);
|
|
13869
|
+
return 1;
|
|
13870
|
+
}
|
|
13871
|
+
let next;
|
|
13872
|
+
try {
|
|
13873
|
+
next = setHerdrPermissions(before, unset, permissions);
|
|
13874
|
+
const parsed = parseConfig(next, configPath);
|
|
13875
|
+
await io.writeFile(configPath, next);
|
|
13876
|
+
config = parsed;
|
|
13877
|
+
} catch {
|
|
13878
|
+
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`);
|
|
13879
|
+
}
|
|
13880
|
+
io.stdout(`Saved permissions = "${permissions}" for ${unset.join(", ")} in ${configPath}.
|
|
13881
|
+
`);
|
|
13882
|
+
}
|
|
13883
|
+
if (!io.exec)
|
|
13884
|
+
throw new UsageError("local setup needs process execution");
|
|
13885
|
+
const detected = await offerLocalInstalls(io, await detectLocalTools(io, localHarnesses(config), localModelProfiles(config)));
|
|
13886
|
+
if (detected.tools.some((tool) => tool.state !== "ready")) {
|
|
13887
|
+
for (const check of detected.checks.filter((c) => c.level === "error"))
|
|
13888
|
+
io.stderr(`${check.message}${check.fix ? `: ${check.fix}` : ""}
|
|
13889
|
+
`);
|
|
13890
|
+
return 1;
|
|
13891
|
+
}
|
|
13892
|
+
const git = await io.exec("git", ["rev-parse", "--show-toplevel"], { cwd: io.cwd, timeoutMs: 1e4 });
|
|
13893
|
+
const repo = git.stdout.trim();
|
|
13894
|
+
if (git.code !== 0 || !repo.startsWith("/") || [...repo].some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127))
|
|
13895
|
+
throw new UsageError("local setup must run in a git repository");
|
|
13896
|
+
const runtime = new Herdr(io);
|
|
13897
|
+
await runtime.ensureServer();
|
|
13898
|
+
const location = await runtime.setupRoot(repo, config.project.slug, config.secrets.names);
|
|
13899
|
+
const workspace = await runtime.setupWorkspace(location.root, config.secrets.names);
|
|
13900
|
+
io.stdout(`Local setup at ${location.root}.
|
|
13901
|
+
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.
|
|
13902
|
+
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.
|
|
13903
|
+
`);
|
|
13904
|
+
const selected = new Set;
|
|
13905
|
+
const sessions = [];
|
|
13906
|
+
for (const [name, profile] of Object.entries(config.herdr.profiles)) {
|
|
13907
|
+
const kind = herdrHarnessKind(profile.harness);
|
|
13908
|
+
if (selected.has(kind))
|
|
13909
|
+
continue;
|
|
13910
|
+
selected.add(kind);
|
|
13911
|
+
const pane = await runtime.setupPane(workspace, location.root, profile, config.secrets.names);
|
|
13912
|
+
const session = { handle: pane.handle, profile, name, error: null };
|
|
13913
|
+
sessions.push(session);
|
|
13914
|
+
io.stdout(`${kind} (profile ${name}): herdr agent attach ${pane.handle.agent}
|
|
13915
|
+
`);
|
|
13916
|
+
if (!pane.existing) {
|
|
13917
|
+
try {
|
|
13918
|
+
await runtime.startChecked(pane.handle, profile);
|
|
13919
|
+
} catch (error) {
|
|
13920
|
+
session.error = error instanceof UsageError ? error.message : `Could not start ${kind}; run herdr agent attach ${pane.handle.agent}`;
|
|
13921
|
+
io.stdout(`${session.error}
|
|
13922
|
+
`);
|
|
13923
|
+
}
|
|
13924
|
+
}
|
|
13925
|
+
}
|
|
13926
|
+
io.stdout(`Setup checks the selected profile for each native harness; other models remain subject to armada doctor's profile checks.
|
|
13927
|
+
`);
|
|
13928
|
+
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 });
|
|
13929
|
+
if (answer === null)
|
|
13930
|
+
return 1;
|
|
13931
|
+
let ready = true;
|
|
13932
|
+
for (const session of sessions) {
|
|
13933
|
+
try {
|
|
13934
|
+
const screen = await runtime.inspect(session.handle, session.profile.harness);
|
|
13935
|
+
if (screen.issue || !screen.ready) {
|
|
13936
|
+
ready = false;
|
|
13937
|
+
io.stdout(`${screen.issue?.message ?? "The harness is not ready"}: herdr agent attach ${session.handle.agent}
|
|
13938
|
+
`);
|
|
13939
|
+
} else {
|
|
13940
|
+
await runtime.checkSetupModel(session.handle, session.profile);
|
|
13941
|
+
io.stdout(`${herdrHarnessKind(session.profile.harness)} (profile ${session.name}): ready; model answered the setup check.
|
|
13942
|
+
`);
|
|
13943
|
+
}
|
|
13944
|
+
} catch (error) {
|
|
13945
|
+
ready = false;
|
|
13946
|
+
io.stdout(`${error instanceof UsageError ? error.message : "Could not verify the harness"}; herdr agent attach ${session.handle.agent}
|
|
13947
|
+
`);
|
|
13948
|
+
}
|
|
13949
|
+
}
|
|
13950
|
+
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.
|
|
13951
|
+
`);
|
|
13952
|
+
return ready ? 0 : 1;
|
|
13953
|
+
}
|
|
13954
|
+
|
|
13228
13955
|
// src/merge.ts
|
|
13229
13956
|
import { randomUUID } from "node:crypto";
|
|
13230
13957
|
import { rm as rm4 } from "node:fs/promises";
|
|
13231
13958
|
import { hostname, tmpdir as tmpdir2 } from "node:os";
|
|
13232
|
-
import { dirname as
|
|
13959
|
+
import { dirname as dirname7, join as join7 } from "node:path";
|
|
13233
13960
|
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;
|
|
13234
13961
|
var tail = (text, lines = 30) => text.trimEnd().split(`
|
|
13235
13962
|
`).slice(-lines).join(`
|
|
@@ -13416,7 +14143,7 @@ async function merge(io, config, credentials, a, configPath) {
|
|
|
13416
14143
|
if (!exec)
|
|
13417
14144
|
throw new UsageError("armada merge needs to run git and gh");
|
|
13418
14145
|
const linearApiKey = credentials.linearApiKey;
|
|
13419
|
-
const repoDir =
|
|
14146
|
+
const repoDir = dirname7(configPath);
|
|
13420
14147
|
const fetchOpt = io.fetch ? { fetch: io.fetch } : {};
|
|
13421
14148
|
const gh = { token, repository: config.github.repository, ...fetchOpt };
|
|
13422
14149
|
const linearOpts = { apiKey: linearApiKey, labels: config.tracker.labels, ...fetchOpt };
|
|
@@ -13667,7 +14394,7 @@ ${"─".repeat(60)}
|
|
|
13667
14394
|
}
|
|
13668
14395
|
|
|
13669
14396
|
// src/secrets.ts
|
|
13670
|
-
import { dirname as
|
|
14397
|
+
import { dirname as dirname8, relative as relative3, resolve as resolve2 } from "node:path";
|
|
13671
14398
|
var NAME_HINT = "upper snake case, e.g. OPENAI_API_KEY";
|
|
13672
14399
|
var hhmm2 = (iso) => `${iso.slice(0, 16).replace("T", " ")} UTC`;
|
|
13673
14400
|
function signInOf(config, credentials) {
|
|
@@ -13747,7 +14474,7 @@ Next: armada secrets set <NAME> (an owner or admin), or the Keys page of Armada
|
|
|
13747
14474
|
async function exportRefusal(io, path) {
|
|
13748
14475
|
if (!io.exec)
|
|
13749
14476
|
return "git cannot be run here to check that the file is ignored";
|
|
13750
|
-
const cwd =
|
|
14477
|
+
const cwd = dirname8(path);
|
|
13751
14478
|
const tracked = await io.exec("git", ["ls-files", "--error-unmatch", "--", path], { cwd }).catch(() => null);
|
|
13752
14479
|
if (tracked?.code === 0)
|
|
13753
14480
|
return `git tracks ${path}: secrets written there would be committed`;
|
|
@@ -14006,11 +14733,16 @@ var COMMAND_HELP = {
|
|
|
14006
14733
|
`,
|
|
14007
14734
|
status: ` status Tickets in flight, tickets ready to start and pull requests waiting
|
|
14008
14735
|
status --all The same for every project registered by \`armada init\`
|
|
14736
|
+
`,
|
|
14737
|
+
setup: ` setup local Open local harness panes for the owner to answer first-run questions,
|
|
14738
|
+
choose ask/full permissions once, and check the selected models.
|
|
14739
|
+
Requires an interactive terminal; --json reports that requirement
|
|
14009
14740
|
`,
|
|
14010
14741
|
doctor: ` doctor What this repository lacks to be run by Armada, with the fix for each,
|
|
14011
14742
|
and whether this terminal is signed in to Armada. Local herdr profiles
|
|
14012
14743
|
check tools and harness sign-in; offers official installs with y/N.
|
|
14013
|
-
No terminal, CI and --json only print fixes and never install
|
|
14744
|
+
No terminal, CI and --json only print fixes and never install.
|
|
14745
|
+
For harness first-run questions, the owner runs armada setup local
|
|
14014
14746
|
`,
|
|
14015
14747
|
init: ` init [--program-root <ISSUE-ID>] [--name <name>] [--slug <slug>] [--no-stop-hook]
|
|
14016
14748
|
Open one pull request that installs or updates it all, create the
|
|
@@ -14196,7 +14928,8 @@ var CONFIG_OPTION = new Set([
|
|
|
14196
14928
|
"stop",
|
|
14197
14929
|
"merge",
|
|
14198
14930
|
"brief",
|
|
14199
|
-
"launch"
|
|
14931
|
+
"launch",
|
|
14932
|
+
"setup"
|
|
14200
14933
|
]);
|
|
14201
14934
|
var JSON_OPTION = new Set([
|
|
14202
14935
|
"skills",
|
|
@@ -14387,12 +15120,12 @@ async function findConfig(io, explicit, command = "status") {
|
|
|
14387
15120
|
throw new UsageError(`${path} does not exist`, `armada ${command} --config <file>, with the path of an ${CONFIG_FILE}`);
|
|
14388
15121
|
return { path, text };
|
|
14389
15122
|
}
|
|
14390
|
-
for (let dir = resolve3(io.cwd);; dir =
|
|
15123
|
+
for (let dir = resolve3(io.cwd);; dir = dirname9(dir)) {
|
|
14391
15124
|
const path = join8(dir, CONFIG_FILE);
|
|
14392
15125
|
const text = await io.readFile(path);
|
|
14393
15126
|
if (text !== null)
|
|
14394
15127
|
return { path, text };
|
|
14395
|
-
if (
|
|
15128
|
+
if (dirname9(dir) === dir)
|
|
14396
15129
|
break;
|
|
14397
15130
|
}
|
|
14398
15131
|
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`);
|
|
@@ -14413,7 +15146,7 @@ async function status(io, args) {
|
|
|
14413
15146
|
...io.fetch ? { fetch: io.fetch } : {},
|
|
14414
15147
|
...io.now ? { now: io.now } : {}
|
|
14415
15148
|
});
|
|
14416
|
-
const behind = await skillsBehind(fsRepoView(
|
|
15149
|
+
const behind = await skillsBehind(fsRepoView(dirname9(path))).catch(() => null);
|
|
14417
15150
|
if (behind)
|
|
14418
15151
|
report.warnings.push(skillsBehindLine(behind, version));
|
|
14419
15152
|
io.stdout(args.json ? `${JSON.stringify(report, null, 2)}
|
|
@@ -14566,6 +15299,10 @@ async function dispatch(argv, io) {
|
|
|
14566
15299
|
await recordPresence(io, config, credentials);
|
|
14567
15300
|
return await brief(io, config, credentials, args, version, path);
|
|
14568
15301
|
}
|
|
15302
|
+
if (args.command === "setup") {
|
|
15303
|
+
const { path, text } = await findConfig(io, args.config, "setup");
|
|
15304
|
+
return await setupLocal(io, parseConfig(text, path), path, args);
|
|
15305
|
+
}
|
|
14569
15306
|
if (args.command === "launch") {
|
|
14570
15307
|
const { path, text } = await findConfig(io, args.config, "launch");
|
|
14571
15308
|
const config = parseConfig(text, path);
|