@the-vibe-company/armada 0.2.35 → 0.2.36
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 +523 -55
- 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 dirname8, join as join7, resolve as resolve3 } from "node:path";
|
|
12
12
|
|
|
13
13
|
// ../core/src/types.ts
|
|
14
14
|
var LABEL_PHASES = [
|
|
@@ -998,6 +998,21 @@ function waitingPullRequests(m, prs) {
|
|
|
998
998
|
return prs.filter((p) => p.state === "open").map((pr) => ({ pr, ticket: ticketOf.get(pr.url) ?? null })).sort((a, b) => a.pr.number - b.pr.number);
|
|
999
999
|
}
|
|
1000
1000
|
|
|
1001
|
+
// ../core/src/herdr-profile.ts
|
|
1002
|
+
function herdrChoice(choice) {
|
|
1003
|
+
return {
|
|
1004
|
+
...choice,
|
|
1005
|
+
profile: {
|
|
1006
|
+
runtime: "herdr",
|
|
1007
|
+
agent: choice.profile.harness,
|
|
1008
|
+
model: choice.profile.model,
|
|
1009
|
+
effort: choice.profile.effort,
|
|
1010
|
+
fastMode: false
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
var herdrClaimHandle = (handle) => JSON.stringify({ workspace: handle.workspace, pane: handle.pane, agent: handle.agent });
|
|
1015
|
+
|
|
1001
1016
|
// ../core/src/npm.ts
|
|
1002
1017
|
var ARMADA_PACKAGE = CLI_PACKAGE;
|
|
1003
1018
|
var NPM_REGISTRY_URL = `https://registry.npmjs.org/${ARMADA_PACKAGE.replace("/", "%2f")}`;
|
|
@@ -2006,12 +2021,13 @@ var CONFIG_FILE = "armada.toml";
|
|
|
2006
2021
|
var PLAN_POLICIES = ["approve", "pre-approved"];
|
|
2007
2022
|
var routingLabelKey = (name) => name.normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{M}\p{N}]/gu, "");
|
|
2008
2023
|
var PROFILE_RUNTIMES = ["conductor", "claude-code"];
|
|
2024
|
+
var HERDR_HARNESSES = ["claude", "codex", "opencode"];
|
|
2009
2025
|
var CONFIG_DEFAULTS = {
|
|
2010
2026
|
language: "en",
|
|
2011
2027
|
readyLabel: "ready-for-agent",
|
|
2012
2028
|
phaseGroup: "Agent phase",
|
|
2013
2029
|
runtimeGroup: "Agent runtime",
|
|
2014
|
-
runtimes: ["Claude Code", "Codex", "Conductor"],
|
|
2030
|
+
runtimes: ["Claude Code", "Codex", "Conductor", "Herdr"],
|
|
2015
2031
|
silentAfterMinutes: 15,
|
|
2016
2032
|
quietAfterMinutes: 45,
|
|
2017
2033
|
coordinatorMinutes: 10,
|
|
@@ -2120,6 +2136,14 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2120
2136
|
if (!isTable(profilesRaw))
|
|
2121
2137
|
problems.push(`"conductor.profiles" must be a table of profiles`);
|
|
2122
2138
|
const profilesT = isTable(profilesRaw) ? profilesRaw : {};
|
|
2139
|
+
const herdr = raw.herdr === undefined ? {} : raw.herdr;
|
|
2140
|
+
if (!isTable(herdr))
|
|
2141
|
+
problems.push(`"herdr" must be a table`);
|
|
2142
|
+
const herdrT = isTable(herdr) ? herdr : {};
|
|
2143
|
+
const herdrProfilesRaw = herdrT.profiles === undefined ? {} : herdrT.profiles;
|
|
2144
|
+
if (!isTable(herdrProfilesRaw))
|
|
2145
|
+
problems.push(`"herdr.profiles" must be a table of profiles`);
|
|
2146
|
+
const herdrProfilesT = isTable(herdrProfilesRaw) ? herdrProfilesRaw : {};
|
|
2123
2147
|
const known = [
|
|
2124
2148
|
["project", project, ["name", "slug"]],
|
|
2125
2149
|
["tracker", tracker, ["program_root", "language", "ready_label", "labels"]],
|
|
@@ -2147,7 +2171,8 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2147
2171
|
],
|
|
2148
2172
|
["brief", briefT, ["extra"]],
|
|
2149
2173
|
["secrets", secretsT, ["names"]],
|
|
2150
|
-
["conductor", conductorT, ["default_profile", "profiles", "routing"]]
|
|
2174
|
+
["conductor", conductorT, ["default_profile", "profiles", "routing"]],
|
|
2175
|
+
["herdr", herdrT, ["default_profile", "profiles", "routing"]]
|
|
2151
2176
|
];
|
|
2152
2177
|
const profiles = {};
|
|
2153
2178
|
for (const [name, p] of Object.entries(profilesT)) {
|
|
@@ -2207,6 +2232,70 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2207
2232
|
}
|
|
2208
2233
|
if (Array.isArray(routingRaw) && routingRaw.length && conductorT.default_profile === undefined && !Object.values(profiles).some((profile) => profile.when))
|
|
2209
2234
|
problems.push(`"conductor.default_profile" is required with [[conductor.routing]], for tickets no rule matches`);
|
|
2235
|
+
const herdrProfiles = {};
|
|
2236
|
+
for (const [name, p] of Object.entries(herdrProfilesT)) {
|
|
2237
|
+
const path = `herdr.profiles.${name}`;
|
|
2238
|
+
if (!isTable(p)) {
|
|
2239
|
+
problems.push(`"${path}" must be a table`);
|
|
2240
|
+
continue;
|
|
2241
|
+
}
|
|
2242
|
+
if (name === "__proto__") {
|
|
2243
|
+
problems.push(`"${path}" is not a usable profile name`);
|
|
2244
|
+
continue;
|
|
2245
|
+
}
|
|
2246
|
+
known.push([path, p, ["harness", "model", "effort", "extra_args", "when"]]);
|
|
2247
|
+
let harness = "claude";
|
|
2248
|
+
if (p.harness === undefined)
|
|
2249
|
+
problems.push(`missing required key "${path}.harness"`);
|
|
2250
|
+
else if (HERDR_HARNESSES.includes(p.harness))
|
|
2251
|
+
harness = p.harness;
|
|
2252
|
+
else
|
|
2253
|
+
problems.push(`"${path}.harness" must be one of ${HERDR_HARNESSES.map((h) => `"${h}"`).join(", ")}`);
|
|
2254
|
+
let extraArgs = [];
|
|
2255
|
+
if (p.extra_args !== undefined) {
|
|
2256
|
+
if (Array.isArray(p.extra_args) && p.extra_args.every((arg) => typeof arg === "string" && arg.trim()))
|
|
2257
|
+
extraArgs = [...p.extra_args];
|
|
2258
|
+
else
|
|
2259
|
+
problems.push(`"${path}.extra_args" must be a list of non-empty argument strings`);
|
|
2260
|
+
}
|
|
2261
|
+
herdrProfiles[name] = {
|
|
2262
|
+
...p.when !== undefined ? { when: str(p, path, "when") } : {},
|
|
2263
|
+
harness,
|
|
2264
|
+
model: str(p, path, "model"),
|
|
2265
|
+
effort: str(p, path, "effort"),
|
|
2266
|
+
extraArgs
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
let herdrDefaultProfile = null;
|
|
2270
|
+
if (herdrT.default_profile !== undefined) {
|
|
2271
|
+
herdrDefaultProfile = str(herdrT, "herdr", "default_profile") || null;
|
|
2272
|
+
if (herdrDefaultProfile && !Object.hasOwn(herdrProfiles, herdrDefaultProfile))
|
|
2273
|
+
problems.push(`"herdr.default_profile" is "${herdrDefaultProfile}", but there is no [herdr.profiles.${herdrDefaultProfile}]`);
|
|
2274
|
+
}
|
|
2275
|
+
const herdrRouting = [];
|
|
2276
|
+
const herdrRoutingRaw = herdrT.routing ?? [];
|
|
2277
|
+
if (!Array.isArray(herdrRoutingRaw))
|
|
2278
|
+
problems.push(`"herdr.routing" must be a list of [[herdr.routing]] rules`);
|
|
2279
|
+
else
|
|
2280
|
+
for (const [i, r] of herdrRoutingRaw.entries()) {
|
|
2281
|
+
const path = `herdr.routing[${i + 1}]`;
|
|
2282
|
+
if (!isTable(r)) {
|
|
2283
|
+
problems.push(`"${path}" must be a table`);
|
|
2284
|
+
continue;
|
|
2285
|
+
}
|
|
2286
|
+
known.push([path, r, ["labels", "profile"]]);
|
|
2287
|
+
const labels = r.labels;
|
|
2288
|
+
const ok = Array.isArray(labels) && labels.length && labels.every((l) => typeof l === "string" && routingLabelKey(l));
|
|
2289
|
+
if (!ok)
|
|
2290
|
+
problems.push(`"${path}.labels" must be a non-empty list of Linear label names, each with a letter or digit`);
|
|
2291
|
+
const profile = str(r, path, "profile");
|
|
2292
|
+
if (profile && !Object.hasOwn(herdrProfiles, profile))
|
|
2293
|
+
problems.push(`"${path}.profile" is "${profile}", but there is no [herdr.profiles.${profile}]`);
|
|
2294
|
+
if (ok && profile)
|
|
2295
|
+
herdrRouting.push({ labels: labels.map((l) => l.trim()), profile });
|
|
2296
|
+
}
|
|
2297
|
+
if (Array.isArray(herdrRoutingRaw) && herdrRoutingRaw.length && herdrT.default_profile === undefined && !Object.values(herdrProfiles).some((profile) => profile.when))
|
|
2298
|
+
problems.push(`"herdr.default_profile" is required with [[herdr.routing]], for tickets no rule matches`);
|
|
2210
2299
|
for (const [path, t, keys] of known)
|
|
2211
2300
|
for (const key of Object.keys(t))
|
|
2212
2301
|
if (!keys.includes(key))
|
|
@@ -2368,7 +2457,8 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2368
2457
|
},
|
|
2369
2458
|
brief: { extra },
|
|
2370
2459
|
secrets: { names: secretNames },
|
|
2371
|
-
conductor: { defaultProfile, profiles, routing }
|
|
2460
|
+
conductor: { defaultProfile, profiles, routing },
|
|
2461
|
+
herdr: { defaultProfile: herdrDefaultProfile, profiles: herdrProfiles, routing: herdrRouting }
|
|
2372
2462
|
};
|
|
2373
2463
|
if (problems.length)
|
|
2374
2464
|
throw new ConfigError(source, problems);
|
|
@@ -2392,7 +2482,7 @@ ready_label = "ready-for-agent"
|
|
|
2392
2482
|
[tracker.labels]
|
|
2393
2483
|
phase_group = "Agent phase"
|
|
2394
2484
|
runtime_group = "Agent runtime"
|
|
2395
|
-
runtimes = ["Claude Code", "Codex", "Conductor"]
|
|
2485
|
+
runtimes = ["Claude Code", "Codex", "Conductor", "Herdr"]
|
|
2396
2486
|
|
|
2397
2487
|
[github]
|
|
2398
2488
|
repository = ${q(p.repository)}
|
|
@@ -2469,6 +2559,23 @@ profile = "codex"
|
|
|
2469
2559
|
[[conductor.routing]]
|
|
2470
2560
|
labels = ["Bug"]
|
|
2471
2561
|
profile = "debug"
|
|
2562
|
+
|
|
2563
|
+
# Herdr profiles use one of its supported harnesses and are selected with the
|
|
2564
|
+
# same label and \`when\` rules as Conductor. Every extra argument is passed to
|
|
2565
|
+
# the selected harness exactly as written.
|
|
2566
|
+
# [herdr]
|
|
2567
|
+
# default_profile = "claude"
|
|
2568
|
+
|
|
2569
|
+
# [herdr.profiles.claude]
|
|
2570
|
+
# harness = "claude" # "claude", "codex" or "opencode"
|
|
2571
|
+
# model = "sonnet"
|
|
2572
|
+
# effort = "high"
|
|
2573
|
+
# extra_args = ["--verbose"]
|
|
2574
|
+
# when = "a ticket best handled by Claude"
|
|
2575
|
+
|
|
2576
|
+
# [[herdr.routing]]
|
|
2577
|
+
# labels = ["herdr"]
|
|
2578
|
+
# profile = "claude"
|
|
2472
2579
|
`;
|
|
2473
2580
|
}
|
|
2474
2581
|
function slugify(name) {
|
|
@@ -2562,44 +2669,49 @@ var checkProblems = (checks, requiredChecks) => checkIssues(checks, requiredChec
|
|
|
2562
2669
|
class ProfileError extends Error {
|
|
2563
2670
|
name = "ProfileError";
|
|
2564
2671
|
}
|
|
2565
|
-
var
|
|
2566
|
-
var
|
|
2567
|
-
|
|
2568
|
-
|
|
2672
|
+
var profileSection = (config, runtime) => runtime === "herdr" ? config.herdr : config.conductor;
|
|
2673
|
+
var runtimeName = (runtime) => runtime === "herdr" ? "Herdr" : "Conductor";
|
|
2674
|
+
var hasProfileRules = (config, runtime = "conductor") => Object.values(profileSection(config, runtime).profiles).some((profile) => !!profile.when);
|
|
2675
|
+
var profileChoiceHint = (ticket, runtime = "conductor") => `Choose ${runtime === "herdr" ? "a Herdr profile" : "a profile"}: read the ticket and its parent, match the profiles' when rules, then run armada ${runtime === "herdr" ? "launch" : "brief"} ${ticket}${runtime === "herdr" ? " --runtime herdr" : ""} --profile <name> --reason "<why>"`;
|
|
2676
|
+
function routeProfile(config, labels, runtime = "conductor") {
|
|
2677
|
+
const { routing, defaultProfile, profiles } = profileSection(config, runtime);
|
|
2569
2678
|
for (const [i, rule] of routing.entries()) {
|
|
2570
2679
|
const keys = rule.labels.map(routingLabelKey);
|
|
2571
2680
|
const label = labels.find((l) => keys.includes(routingLabelKey(l)));
|
|
2572
2681
|
if (label !== undefined)
|
|
2573
2682
|
return { name: rule.profile, source: "rule", rule: { index: i + 1, labels: rule.labels, label } };
|
|
2574
2683
|
}
|
|
2575
|
-
if (hasProfileRules(config))
|
|
2684
|
+
if (hasProfileRules(config, runtime))
|
|
2576
2685
|
return null;
|
|
2577
2686
|
if (defaultProfile)
|
|
2578
2687
|
return { name: defaultProfile, source: "default", rule: null };
|
|
2579
2688
|
const names = Object.keys(profiles);
|
|
2580
2689
|
return names.length === 1 && names[0] ? { name: names[0], source: "only", rule: null } : null;
|
|
2581
2690
|
}
|
|
2582
|
-
function describeRoute(route, config) {
|
|
2691
|
+
function describeRoute(route, config, runtime = "conductor") {
|
|
2692
|
+
const section = profileSection(config, runtime);
|
|
2693
|
+
const sectionName = runtime === "herdr" ? "herdr" : "conductor";
|
|
2583
2694
|
if (route.rule)
|
|
2584
|
-
return `rule ${route.rule.index} of [[
|
|
2695
|
+
return `rule ${route.rule.index} of [[${sectionName}.routing]] (label "${route.rule.label}")`;
|
|
2585
2696
|
if (route.source === "default")
|
|
2586
|
-
return
|
|
2587
|
-
return "the only profile in armada.toml";
|
|
2697
|
+
return section.routing.length ? `${sectionName}.default_profile (no routing rule matched)` : `${sectionName}.default_profile`;
|
|
2698
|
+
return runtime === "herdr" ? "the only Herdr profile in armada.toml" : "the only profile in armada.toml";
|
|
2588
2699
|
}
|
|
2589
|
-
function checkRequestedProfile(config, requested) {
|
|
2590
|
-
|
|
2700
|
+
function checkRequestedProfile(config, requested, runtime = "conductor") {
|
|
2701
|
+
const { profiles } = profileSection(config, runtime);
|
|
2702
|
+
if (requested === null || Object.hasOwn(profiles, requested))
|
|
2591
2703
|
return;
|
|
2592
|
-
const names = Object.keys(
|
|
2593
|
-
throw new ProfileError(`no
|
|
2704
|
+
const names = Object.keys(profiles);
|
|
2705
|
+
throw new ProfileError(`no ${runtimeName(runtime)} profile "${requested}" (available: ${names.join(", ") || "none"})`);
|
|
2594
2706
|
}
|
|
2595
|
-
function chooseProfile(config, input) {
|
|
2596
|
-
checkRequestedProfile(config, input.requested);
|
|
2597
|
-
const { profiles } = config
|
|
2707
|
+
function chooseProfile(config, input, runtime = "conductor") {
|
|
2708
|
+
checkRequestedProfile(config, input.requested, runtime);
|
|
2709
|
+
const { profiles } = profileSection(config, runtime);
|
|
2598
2710
|
const reason = input.reason?.replace(/\s+/g, " ").trim() || null;
|
|
2599
|
-
const route = routeProfile(config, input.labels);
|
|
2600
|
-
const semantic = !route && hasProfileRules(config);
|
|
2711
|
+
const route = routeProfile(config, input.labels, runtime);
|
|
2712
|
+
const semantic = !route && hasProfileRules(config, runtime);
|
|
2601
2713
|
if (semantic && (input.requested === null || !reason))
|
|
2602
|
-
throw new ProfileError(profileChoiceHint(input.ticket));
|
|
2714
|
+
throw new ProfileError(profileChoiceHint(input.ticket, runtime));
|
|
2603
2715
|
if (input.requested === null) {
|
|
2604
2716
|
if (route && Object.hasOwn(profiles, route.name))
|
|
2605
2717
|
return {
|
|
@@ -2609,12 +2721,12 @@ function chooseProfile(config, input) {
|
|
|
2609
2721
|
rule: route.rule,
|
|
2610
2722
|
routed: route.name,
|
|
2611
2723
|
reason,
|
|
2612
|
-
why: describeRoute(route, config)
|
|
2724
|
+
why: describeRoute(route, config, runtime)
|
|
2613
2725
|
};
|
|
2614
2726
|
const names = Object.keys(profiles);
|
|
2615
2727
|
if (!names.length)
|
|
2616
2728
|
return null;
|
|
2617
|
-
throw new ProfileError(`several
|
|
2729
|
+
throw new ProfileError(`several ${runtimeName(runtime)} profiles and no ${runtime}.default_profile; pass --profile (${names.join(", ")})`);
|
|
2618
2730
|
}
|
|
2619
2731
|
const name = input.requested;
|
|
2620
2732
|
const profile = profiles[name];
|
|
@@ -2626,11 +2738,11 @@ function chooseProfile(config, input) {
|
|
|
2626
2738
|
rule: route.rule,
|
|
2627
2739
|
routed: name,
|
|
2628
2740
|
reason,
|
|
2629
|
-
why: describeRoute(route, config)
|
|
2741
|
+
why: describeRoute(route, config, runtime)
|
|
2630
2742
|
};
|
|
2631
|
-
if (route && !reason && config.
|
|
2632
|
-
throw new ProfileError(`${input.ticket} is routed to "${route.name}" by ${describeRoute(route, config)}; say why "${name}" instead with --reason "<why>"`);
|
|
2633
|
-
const why = semantic ? `Chosen by the coordinator: ${reason}` : `--profile${route ? `, instead of "${route.name}" from ${describeRoute(route, config)}` : ""}${reason ? `: ${reason}` : ""}`;
|
|
2743
|
+
if (route && !reason && profileSection(config, runtime).routing.length)
|
|
2744
|
+
throw new ProfileError(`${input.ticket} is routed to "${route.name}" by ${describeRoute(route, config, runtime)}; say why "${name}" instead with --reason "<why>"`);
|
|
2745
|
+
const why = semantic ? `Chosen by the coordinator: ${reason}` : `--profile${route ? `, instead of "${route.name}" from ${describeRoute(route, config, runtime)}` : ""}${reason ? `: ${reason}` : ""}`;
|
|
2634
2746
|
return { name, profile, source: "requested", rule: null, routed: route?.name ?? null, reason, why };
|
|
2635
2747
|
}
|
|
2636
2748
|
|
|
@@ -2869,12 +2981,15 @@ async function claimTicket(ctx, input) {
|
|
|
2869
2981
|
throw new Refusal(`${ticket.id} already carries the agent phase "${ticket.agentPhase}"`, another);
|
|
2870
2982
|
if (input.profile)
|
|
2871
2983
|
try {
|
|
2872
|
-
|
|
2984
|
+
const selection = {
|
|
2873
2985
|
ticket: ticket.id,
|
|
2874
2986
|
labels: ticket.labels.map((l) => l.name),
|
|
2875
2987
|
requested: input.profile,
|
|
2876
2988
|
reason: input.reason ?? null
|
|
2877
|
-
}
|
|
2989
|
+
};
|
|
2990
|
+
const local = input.runtime.toLowerCase() === "herdr";
|
|
2991
|
+
const choice = local ? chooseProfile(config, selection, "herdr") : null;
|
|
2992
|
+
profile = local ? choice ? herdrChoice(choice) : null : chooseProfile(config, selection);
|
|
2878
2993
|
} catch (err) {
|
|
2879
2994
|
if (err instanceof ProfileError)
|
|
2880
2995
|
throw new Refusal(err.message, `armada brief ${ticket.id}, which shows the profile the ticket routes to`);
|
|
@@ -3150,7 +3265,7 @@ function buildBrief(input) {
|
|
|
3150
3265
|
const warnings = [...new Set([...ticket.warnings, ...program.warnings])];
|
|
3151
3266
|
let choice;
|
|
3152
3267
|
try {
|
|
3153
|
-
choice = chooseProfile(config, {
|
|
3268
|
+
choice = input.herdr ? herdrChoice(input.herdr.choice) : chooseProfile(config, {
|
|
3154
3269
|
ticket: ticket.id,
|
|
3155
3270
|
labels: ticket.labels,
|
|
3156
3271
|
requested: input.profile,
|
|
@@ -3190,10 +3305,10 @@ function buildBrief(input) {
|
|
|
3190
3305
|
const pkg = `${ARMADA_PACKAGE}@${pinned}`;
|
|
3191
3306
|
const branch = ticket.branchName;
|
|
3192
3307
|
const runtime = choice?.profile.runtime ?? "conductor";
|
|
3193
|
-
const handle = runtime === "claude-code" ? subagentName(ticket.id) : CONDUCTOR_HANDLE;
|
|
3308
|
+
const handle = input.herdr ? shellWord(input.herdr.handle) : runtime === "claude-code" ? subagentName(ticket.id) : CONDUCTOR_HANDLE;
|
|
3194
3309
|
const claimCommand = [
|
|
3195
3310
|
`armada claim ${ticket.id} --runtime ${runtime} --handle ${handle}`,
|
|
3196
|
-
branch ? ` --branch ${branch}` : "",
|
|
3311
|
+
branch ? ` --branch ${shellWord(branch)}` : "",
|
|
3197
3312
|
choice ? ` --profile ${shellWord(choice.name)}` : "",
|
|
3198
3313
|
choice?.reason ? ` --reason ${shellWord(choice.reason)}` : "",
|
|
3199
3314
|
...input.validation?.rules.length ? [
|
|
@@ -3245,6 +3360,7 @@ function buildBrief(input) {
|
|
|
3245
3360
|
install: `npm install -g ${pkg}`,
|
|
3246
3361
|
fallback: `npm exec --yes --package=${pkg} -- armada`,
|
|
3247
3362
|
claimCommand,
|
|
3363
|
+
...input.herdr ? { handle: input.herdr.handle } : {},
|
|
3248
3364
|
launch: launch ? {
|
|
3249
3365
|
command: `armada login --launch-token ${shellWord(launch.token)}${launch.apiUrl ? ` --api-url ${shellWord(launch.apiUrl)}` : ""}`,
|
|
3250
3366
|
expiresAt: launch.expiresAt
|
|
@@ -3306,7 +3422,7 @@ function renderPrompt(b) {
|
|
|
3306
3422
|
b.install,
|
|
3307
3423
|
...b.launch ? [b.launch.command] : [],
|
|
3308
3424
|
b.claimCommand,
|
|
3309
|
-
`armada heartbeat --every 5m --ticket ${t.id} --handle ${subagent ? subagentName(t.id) : CONDUCTOR_HANDLE} --parent "$PPID"${subagent ? "" : " --background"}`,
|
|
3425
|
+
`armada heartbeat --every 5m --ticket ${t.id} --handle ${b.handle ? shellWord(b.handle) : subagent ? subagentName(t.id) : CONDUCTOR_HANDLE} --parent "$PPID"${subagent ? "" : " --background"}`,
|
|
3310
3426
|
"```",
|
|
3311
3427
|
"",
|
|
3312
3428
|
subagent ? "Keep this Bash heartbeat in the subagent's background: it dies with the subagent, which is intended. Do not detach it from the subagent. If background processes are unavailable, report manually at least every 15 minutes." : "The heartbeat detaches from the short-lived command shell (a new process group, like nohup + setsid), keeps a PID file under ~/.config/armada/watch/, and stays alive between turns and while waiting for messages. Its parent is the persistent agent PID ($PPID in the command shell), never the shell PID ($$). If startup fails or the runtime cannot keep a background process, report manually at least every 15 minutes instead.",
|
|
@@ -3321,8 +3437,12 @@ function renderPrompt(b) {
|
|
|
3321
3437
|
"",
|
|
3322
3438
|
"## Branch",
|
|
3323
3439
|
"",
|
|
3324
|
-
t.branch ? `Work on \`${t.branch}\`. Your ${subagent ? "worktree starts on a branch Claude Code" : "workspace starts on a branch Conductor"} named; rename it before your first commit: \`git branch -m ${t.branch}\`.` : "Linear suggests no branch name for this ticket; name yours after the ticket id.",
|
|
3440
|
+
b.runtime === "herdr" ? `Herdr already created your own worktree on \`${t.branch}\`. Work only there. Before editing, check \`git branch --show-current\` and \`git rev-parse --show-toplevel\`; do not rename the branch or switch the coordinator's checkout. Your runtime handle is \`${b.handle}\`.` : t.branch ? `Work on \`${t.branch}\`. Your ${subagent ? "worktree starts on a branch Claude Code" : "workspace starts on a branch Conductor"} named; rename it before your first commit: \`git branch -m ${t.branch}\`.` : "Linear suggests no branch name for this ticket; name yours after the ticket id.",
|
|
3325
3441
|
"",
|
|
3442
|
+
...b.runtime === "herdr" ? [
|
|
3443
|
+
`You share the coordinator's machine, but own only ${t.id}. Pass \`--ticket ${t.id}\` to every \`armada report\`, \`ask\`, \`release\` and \`validate\`; an inherited \`ARMADA_TICKET\` may name the coordinator's ticket. Herdr keeps your terminal alive when the coordinator disconnects.`,
|
|
3444
|
+
""
|
|
3445
|
+
] : [],
|
|
3326
3446
|
...subagent ? [
|
|
3327
3447
|
`You share the coordinator's machine and environment: its \`ARMADA_TICKET\`, if it has one, is not yours. Pass \`--ticket ${t.id}\` to every \`armada report\`, \`ask\` and \`release\`. You end when the coordinator's session ends: report at every step, so the ticket always says where you are.`,
|
|
3328
3448
|
""
|
|
@@ -9901,7 +10021,7 @@ ${attachments.join(`
|
|
|
9901
10021
|
};
|
|
9902
10022
|
}
|
|
9903
10023
|
// package.json
|
|
9904
|
-
var version = "0.2.
|
|
10024
|
+
var version = "0.2.36";
|
|
9905
10025
|
|
|
9906
10026
|
// src/attach.ts
|
|
9907
10027
|
import { resolve } from "node:path";
|
|
@@ -10559,7 +10679,7 @@ async function claim(io, config, credentials, a) {
|
|
|
10559
10679
|
if (reason && !profile)
|
|
10560
10680
|
throw new UsageError("--reason goes with --profile: it says why the routed profile is not used");
|
|
10561
10681
|
try {
|
|
10562
|
-
checkRequestedProfile(config, profile);
|
|
10682
|
+
checkRequestedProfile(config, profile, a.options.runtime?.toLowerCase() === "herdr" ? "herdr" : "conductor");
|
|
10563
10683
|
} catch (err) {
|
|
10564
10684
|
if (err instanceof ProfileError)
|
|
10565
10685
|
throw new UsageError(err.message);
|
|
@@ -11394,6 +11514,22 @@ async function offerLocalInstalls(io, detected, options = {}) {
|
|
|
11394
11514
|
`);
|
|
11395
11515
|
return result;
|
|
11396
11516
|
}
|
|
11517
|
+
async function ensureLocalTools(io, harness) {
|
|
11518
|
+
const print = (detected) => {
|
|
11519
|
+
for (const check of detected.checks) {
|
|
11520
|
+
if (check.level === "ok")
|
|
11521
|
+
continue;
|
|
11522
|
+
io.stderr(`${check.message}${check.fix ? `: ${check.fix}` : ""}
|
|
11523
|
+
`);
|
|
11524
|
+
}
|
|
11525
|
+
};
|
|
11526
|
+
const detected = await detectLocalTools(io, [harness]);
|
|
11527
|
+
print(detected);
|
|
11528
|
+
const result = await offerLocalInstalls(io, detected);
|
|
11529
|
+
if (result !== detected)
|
|
11530
|
+
print(result);
|
|
11531
|
+
return result.ready;
|
|
11532
|
+
}
|
|
11397
11533
|
|
|
11398
11534
|
// src/repo.ts
|
|
11399
11535
|
import { lstat, mkdir as mkdir2, readdir, readFile as readFile2, readlink, rm as rm2, symlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
@@ -12096,7 +12232,172 @@ async function init(io, opts) {
|
|
|
12096
12232
|
}
|
|
12097
12233
|
|
|
12098
12234
|
// src/launch.ts
|
|
12099
|
-
|
|
12235
|
+
import { dirname as dirname5, join as join5 } from "node:path";
|
|
12236
|
+
|
|
12237
|
+
// src/herdr.ts
|
|
12238
|
+
var harnessArgs = (p) => [
|
|
12239
|
+
"--model",
|
|
12240
|
+
p.harness === "opencode" ? `${p.model.split("#")[0]}#${p.effort}` : p.model,
|
|
12241
|
+
...p.harness === "codex" ? ["-c", `model_reasoning_effort=${JSON.stringify(p.effort)}`] : p.harness === "claude" ? ["--effort", p.effort] : [],
|
|
12242
|
+
...p.extraArgs
|
|
12243
|
+
];
|
|
12244
|
+
var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : null;
|
|
12245
|
+
var id = (v) => typeof v === "string" && /^[a-zA-Z0-9:_-]{1,128}$/.test(v);
|
|
12246
|
+
var runtimeEnvironment = (env) => Object.fromEntries(Object.entries(env).filter(([name]) => /^(PATH|HOME|USER|LOGNAME|SHELL|TMPDIR|TMP|TEMP|LANG|TERM|LC_[A-Z_]+|XDG_(CONFIG_HOME|DATA_HOME|STATE_HOME|CACHE_HOME|RUNTIME_DIR)|HERDR_(SESSION|SOCKET_PATH|CONFIG_PATH))$/.test(name)));
|
|
12247
|
+
var credentialNames = (env, extra) => [
|
|
12248
|
+
...new Set([
|
|
12249
|
+
"LINEAR_API_KEY",
|
|
12250
|
+
"GITHUB_TOKEN",
|
|
12251
|
+
"GH_TOKEN",
|
|
12252
|
+
"ARMADA_API_KEY",
|
|
12253
|
+
"ARMADA_SESSION_TOKEN",
|
|
12254
|
+
"ARMADA_SIGNED_IN_TO",
|
|
12255
|
+
"ARMADA_API_URL",
|
|
12256
|
+
"OPENAI_API_KEY",
|
|
12257
|
+
"ANTHROPIC_API_KEY",
|
|
12258
|
+
...Object.keys(env).filter((name) => /^(ARMADA_|CONDUCTOR_)|(?:KEY|TOKEN|SECRET|PASSWORD)$/.test(name)),
|
|
12259
|
+
...extra
|
|
12260
|
+
])
|
|
12261
|
+
].filter((name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)).sort();
|
|
12262
|
+
|
|
12263
|
+
class Herdr {
|
|
12264
|
+
io;
|
|
12265
|
+
constructor(io) {
|
|
12266
|
+
this.io = io;
|
|
12267
|
+
}
|
|
12268
|
+
async call(args, timeoutMs = 40000) {
|
|
12269
|
+
const operation = args.slice(0, 2).join(" ");
|
|
12270
|
+
let reply;
|
|
12271
|
+
let code;
|
|
12272
|
+
try {
|
|
12273
|
+
if (!this.io.exec)
|
|
12274
|
+
throw new Error("no exec");
|
|
12275
|
+
const out = await this.io.exec("herdr", args, { cwd: this.io.cwd, timeoutMs });
|
|
12276
|
+
code = out.code;
|
|
12277
|
+
reply = object(JSON.parse(out.stdout || out.stderr));
|
|
12278
|
+
} catch {
|
|
12279
|
+
throw new UsageError(`herdr ${operation} failed; inspect the runtime with herdr agent list`);
|
|
12280
|
+
}
|
|
12281
|
+
const error = object(reply?.error);
|
|
12282
|
+
if (code !== 0 || error) {
|
|
12283
|
+
const reason = typeof error?.code === "string" && /^[a-z_]{1,64}$/.test(error.code) ? ` (${error.code})` : "";
|
|
12284
|
+
throw new UsageError(`herdr ${operation} failed${reason}; inspect the runtime with herdr agent list`);
|
|
12285
|
+
}
|
|
12286
|
+
if (!reply)
|
|
12287
|
+
throw new UsageError(`herdr ${operation} returned invalid JSON`);
|
|
12288
|
+
return reply;
|
|
12289
|
+
}
|
|
12290
|
+
async ensureServer() {
|
|
12291
|
+
const status = async (timeoutMs) => {
|
|
12292
|
+
const server = object((await this.call(["status", "--json"], timeoutMs)).server);
|
|
12293
|
+
if (!server || typeof server.running !== "boolean")
|
|
12294
|
+
throw new UsageError("invalid herdr server status response");
|
|
12295
|
+
if (server.running && (server.compatible === false || server.endpoint_compatible === false))
|
|
12296
|
+
throw new UsageError("the running herdr server is incompatible; update or restart it before launching");
|
|
12297
|
+
return server.running;
|
|
12298
|
+
};
|
|
12299
|
+
if (await status(5000))
|
|
12300
|
+
return;
|
|
12301
|
+
if (!this.io.detach || !await this.io.detach("herdr", ["server"], { cwd: this.io.cwd, env: runtimeEnvironment(this.io.env) }))
|
|
12302
|
+
throw new UsageError("could not start herdr server; start it headless with herdr server");
|
|
12303
|
+
const now = this.io.now ?? (() => new Date);
|
|
12304
|
+
const deadline = now().getTime() + 5000;
|
|
12305
|
+
for (let attempt = 0;attempt < 20; attempt++) {
|
|
12306
|
+
const remaining = deadline - now().getTime();
|
|
12307
|
+
if (remaining <= 0)
|
|
12308
|
+
break;
|
|
12309
|
+
if (await status(Math.min(1000, remaining)))
|
|
12310
|
+
return;
|
|
12311
|
+
const delay = Math.min(250, deadline - now().getTime());
|
|
12312
|
+
if (delay > 0)
|
|
12313
|
+
await (this.io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))))(delay);
|
|
12314
|
+
}
|
|
12315
|
+
throw new UsageError("herdr server did not become ready; inspect herdr status");
|
|
12316
|
+
}
|
|
12317
|
+
async create(input) {
|
|
12318
|
+
const agent = input.ticket.toLowerCase();
|
|
12319
|
+
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(agent))
|
|
12320
|
+
throw new UsageError("ticket cannot be used as a herdr agent name");
|
|
12321
|
+
const r = object((await this.call([
|
|
12322
|
+
"worktree",
|
|
12323
|
+
"create",
|
|
12324
|
+
"--cwd",
|
|
12325
|
+
input.repo,
|
|
12326
|
+
"--branch",
|
|
12327
|
+
input.branch,
|
|
12328
|
+
"--base",
|
|
12329
|
+
input.base,
|
|
12330
|
+
"--no-focus"
|
|
12331
|
+
])).result);
|
|
12332
|
+
const workspace = object(r?.workspace)?.workspace_id;
|
|
12333
|
+
const rootPane = object(r?.root_pane)?.pane_id;
|
|
12334
|
+
const path = object(r?.worktree)?.path;
|
|
12335
|
+
if (!id(workspace) || !id(rootPane) || typeof path !== "string" || !path.startsWith("/") || object(r?.root_pane)?.workspace_id !== workspace)
|
|
12336
|
+
throw new UsageError("invalid herdr worktree response; inspect herdr worktree list before retrying");
|
|
12337
|
+
const tab = object((await this.call([
|
|
12338
|
+
"tab",
|
|
12339
|
+
"create",
|
|
12340
|
+
"--workspace",
|
|
12341
|
+
workspace,
|
|
12342
|
+
"--cwd",
|
|
12343
|
+
path,
|
|
12344
|
+
"--no-focus",
|
|
12345
|
+
...credentialNames(this.io.env, input.secrets ?? []).flatMap((name) => ["--env", `${name}=`]),
|
|
12346
|
+
"--env",
|
|
12347
|
+
`ARMADA_TICKET=${input.ticket}`
|
|
12348
|
+
])).result);
|
|
12349
|
+
const pane = object(tab?.root_pane)?.pane_id;
|
|
12350
|
+
if (!id(pane) || pane === rootPane || object(tab?.root_pane)?.workspace_id !== workspace)
|
|
12351
|
+
throw new UsageError("invalid herdr worker pane response; inspect herdr pane list before retrying");
|
|
12352
|
+
await this.call(["pane", "close", rootPane]);
|
|
12353
|
+
return { workspace, pane, agent, path };
|
|
12354
|
+
}
|
|
12355
|
+
async start(handle, profile) {
|
|
12356
|
+
const r = await this.call([
|
|
12357
|
+
"agent",
|
|
12358
|
+
"start",
|
|
12359
|
+
handle.agent,
|
|
12360
|
+
"--kind",
|
|
12361
|
+
profile.harness,
|
|
12362
|
+
"--pane",
|
|
12363
|
+
handle.pane,
|
|
12364
|
+
"--timeout",
|
|
12365
|
+
"30000",
|
|
12366
|
+
"--",
|
|
12367
|
+
...harnessArgs(profile)
|
|
12368
|
+
]);
|
|
12369
|
+
this.checkAgent(r, handle);
|
|
12370
|
+
}
|
|
12371
|
+
async prompt(handle, prompt) {
|
|
12372
|
+
const r = await this.call([
|
|
12373
|
+
"agent",
|
|
12374
|
+
"prompt",
|
|
12375
|
+
handle.agent,
|
|
12376
|
+
prompt,
|
|
12377
|
+
"--wait",
|
|
12378
|
+
"--until",
|
|
12379
|
+
"working",
|
|
12380
|
+
"--timeout",
|
|
12381
|
+
"30000"
|
|
12382
|
+
]);
|
|
12383
|
+
const agent = this.checkAgent(r, handle);
|
|
12384
|
+
if (agent.agent_status !== "working")
|
|
12385
|
+
throw new UsageError("herdr did not confirm the worker is working");
|
|
12386
|
+
}
|
|
12387
|
+
checkAgent(reply, handle) {
|
|
12388
|
+
const agent = object(object(reply.result)?.agent);
|
|
12389
|
+
if (!agent || agent.name !== handle.agent || agent.pane_id !== handle.pane || agent.workspace_id !== handle.workspace)
|
|
12390
|
+
throw new UsageError("invalid herdr agent response; inspect herdr agent list before retrying");
|
|
12391
|
+
return agent;
|
|
12392
|
+
}
|
|
12393
|
+
}
|
|
12394
|
+
|
|
12395
|
+
// src/launch.ts
|
|
12396
|
+
async function launch(io, config, credentials, args, version, configPath) {
|
|
12397
|
+
if (args.rest[0] !== "revoke")
|
|
12398
|
+
return launchLocal(io, config, credentials, args, version, configPath);
|
|
12399
|
+
if (Object.keys(args.options).length)
|
|
12400
|
+
throw new UsageError("launch revoke does not take runtime or profile options");
|
|
12100
12401
|
const [operation, ticket, ...extra] = args.rest;
|
|
12101
12402
|
if (operation !== "revoke" || !ticket || extra.length || !/^[A-Za-z][A-Za-z0-9]{0,15}-\d{1,9}$/.test(ticket))
|
|
12102
12403
|
throw new UsageError("launch needs a ticket to revoke: armada launch revoke <ticket>");
|
|
@@ -12115,12 +12416,156 @@ ${watch.line}
|
|
|
12115
12416
|
`);
|
|
12116
12417
|
return 0;
|
|
12117
12418
|
}
|
|
12419
|
+
async function launchLocal(io, config, credentials, args, version, configPath) {
|
|
12420
|
+
const [input, ...extra] = args.rest;
|
|
12421
|
+
const o = args.options;
|
|
12422
|
+
if (!input || extra.length || !/^[A-Za-z][A-Za-z0-9]{0,15}-\d{1,9}$/.test(input) || o.runtime !== "herdr")
|
|
12423
|
+
throw new UsageError("launch needs a ticket and runtime: armada launch <ticket> --runtime herdr [--harness claude|codex|opencode]");
|
|
12424
|
+
const requested = o.profile?.trim() || null;
|
|
12425
|
+
const reason = o.reason?.trim() || null;
|
|
12426
|
+
if (reason && !requested)
|
|
12427
|
+
throw new UsageError("--reason goes with --profile");
|
|
12428
|
+
if (o.harness && !HERDR_HARNESSES.includes(o.harness))
|
|
12429
|
+
throw new UsageError("--harness must be claude, codex or opencode");
|
|
12430
|
+
try {
|
|
12431
|
+
checkRequestedProfile(config, requested, "herdr");
|
|
12432
|
+
} catch (error) {
|
|
12433
|
+
if (error instanceof ProfileError)
|
|
12434
|
+
throw new UsageError(error.message);
|
|
12435
|
+
throw error;
|
|
12436
|
+
}
|
|
12437
|
+
const signIn = requireSignIn(credentials);
|
|
12438
|
+
if (!credentials.linearApiKey)
|
|
12439
|
+
throw missingKey(LINEAR_KEY);
|
|
12440
|
+
if (!io.exec)
|
|
12441
|
+
throw new UsageError("local launch needs process execution");
|
|
12442
|
+
const ticketId = input.toUpperCase();
|
|
12443
|
+
const now = io.now ?? (() => new Date);
|
|
12444
|
+
const linear = { apiKey: credentials.linearApiKey, fetch: io.fetch ?? fetch };
|
|
12445
|
+
const [ticket, program] = await Promise.all([
|
|
12446
|
+
fetchBriefTicket(linear, ticketId),
|
|
12447
|
+
fetchProgram({ ...linear, rootId: config.tracker.programRoot, labels: config.tracker.labels, now })
|
|
12448
|
+
]);
|
|
12449
|
+
if (!ticket)
|
|
12450
|
+
throw new UsageError(`ticket ${ticketId} not found in Linear`);
|
|
12451
|
+
if (ticket.statusType === "completed" || ticket.statusType === "canceled")
|
|
12452
|
+
throw new UsageError(`${ticketId} is ${ticket.status}; there is nothing to launch`);
|
|
12453
|
+
if (!program.issues.some((i) => i.id === ticketId))
|
|
12454
|
+
throw new UsageError(`${ticketId} is not under program root ${config.tracker.programRoot}`);
|
|
12455
|
+
if (ticket.blockers.some((b) => b.statusType !== "completed" && b.statusType !== "canceled"))
|
|
12456
|
+
throw new UsageError(`${ticketId} has open blockers; resolve them before launching`);
|
|
12457
|
+
if (inFlight(buildModel(program.issues, program.rootId), program.comments, {
|
|
12458
|
+
now: now().getTime(),
|
|
12459
|
+
silentAfterMinutes: config.policy.silentAfterMinutes
|
|
12460
|
+
}).some((lane) => lane.issue.id === ticketId))
|
|
12461
|
+
throw new UsageError(`${ticketId} is already in flight; inspect its worker before launching again`);
|
|
12462
|
+
const branch = ticket.branchName;
|
|
12463
|
+
if (!branch)
|
|
12464
|
+
throw new UsageError(`${ticketId} has no suggested branch in Linear`);
|
|
12465
|
+
let choice;
|
|
12466
|
+
let validation;
|
|
12467
|
+
try {
|
|
12468
|
+
choice = chooseProfile(config, { ticket: ticketId, labels: ticket.labels, requested, reason }, "herdr");
|
|
12469
|
+
validation = chooseValidations(config.policy.validations, {
|
|
12470
|
+
ticket: ticketId,
|
|
12471
|
+
requested: o.validation ?? null,
|
|
12472
|
+
reason: o["validation-reason"] ?? null,
|
|
12473
|
+
command: `armada launch ${ticketId} --runtime herdr`
|
|
12474
|
+
});
|
|
12475
|
+
} catch (error) {
|
|
12476
|
+
if (error instanceof ProfileError)
|
|
12477
|
+
throw new UsageError(error.message);
|
|
12478
|
+
if (error instanceof ValidationChoiceError)
|
|
12479
|
+
throw new UsageError(error.message, error.next);
|
|
12480
|
+
throw error;
|
|
12481
|
+
}
|
|
12482
|
+
if (!choice)
|
|
12483
|
+
throw new UsageError("local launch needs a [herdr.profiles.<name>] with harness, model and effort");
|
|
12484
|
+
if (o.harness && o.harness !== choice.profile.harness)
|
|
12485
|
+
throw new UsageError(`profile "${choice.name}" uses ${choice.profile.harness}; choose a matching --profile with --reason to change harness`);
|
|
12486
|
+
const execute = io.exec;
|
|
12487
|
+
const preflight = {
|
|
12488
|
+
...io,
|
|
12489
|
+
interactive: args.json ? false : io.interactive,
|
|
12490
|
+
exec: (command, argv, options) => execute(command, argv, { ...options, timeoutMs: options.timeoutMs ?? 1e4 })
|
|
12491
|
+
};
|
|
12492
|
+
if (!await ensureLocalTools(preflight, choice.profile.harness))
|
|
12493
|
+
return 1;
|
|
12494
|
+
const root = await io.exec("git", ["rev-parse", "--show-toplevel"], { cwd: io.cwd, timeoutMs: 1e4 });
|
|
12495
|
+
if (root.code !== 0 || !root.stdout.trim().startsWith("/"))
|
|
12496
|
+
throw new UsageError("local launch must run in a git repository");
|
|
12497
|
+
const repo = root.stdout.trim();
|
|
12498
|
+
const remote = await io.exec("git", ["ls-remote", "--symref", "origin", "HEAD"], { cwd: repo, timeoutMs: 20000 });
|
|
12499
|
+
const base = remote.code === 0 ? remote.stdout.match(/^ref:\s+refs\/heads\/(\S+)\s+HEAD/m)?.[1] : null;
|
|
12500
|
+
if (!base)
|
|
12501
|
+
throw new UsageError("could not read the default branch of origin");
|
|
12502
|
+
const conventions = config.brief.extra ? { path: config.brief.extra, text: await io.readFile(join5(dirname5(configPath), config.brief.extra)) } : null;
|
|
12503
|
+
const npm = await checkPublished(version, io.fetch ?? fetch);
|
|
12504
|
+
if (npm.state === "missing")
|
|
12505
|
+
throw new UsageError(`armada ${version} is not on npm yet; publish this version before launching local workers`);
|
|
12506
|
+
const api = apiOf(io, credentials.armadaApi.url);
|
|
12507
|
+
const launch = await api.launchToken(signIn, { project: config.project.slug, ticket: ticketId });
|
|
12508
|
+
const runtime = new Herdr(io);
|
|
12509
|
+
let handle;
|
|
12510
|
+
try {
|
|
12511
|
+
await runtime.ensureServer();
|
|
12512
|
+
handle = await runtime.create({ repo, branch, base, ticket: ticketId, secrets: config.secrets.names });
|
|
12513
|
+
const b = buildBrief({
|
|
12514
|
+
config,
|
|
12515
|
+
ticket,
|
|
12516
|
+
program,
|
|
12517
|
+
profile: null,
|
|
12518
|
+
version,
|
|
12519
|
+
npm,
|
|
12520
|
+
env: io.env,
|
|
12521
|
+
now: now(),
|
|
12522
|
+
conventions,
|
|
12523
|
+
validation,
|
|
12524
|
+
launch: {
|
|
12525
|
+
token: launch.token,
|
|
12526
|
+
expiresAt: launch.expiresAt,
|
|
12527
|
+
apiUrl: armadaAddress(credentials.armadaApi.url) === armadaAddress(DEFAULT_ARMADA_API_URL) ? null : armadaAddress(credentials.armadaApi.url)
|
|
12528
|
+
},
|
|
12529
|
+
herdr: { choice, handle: herdrClaimHandle(handle) }
|
|
12530
|
+
});
|
|
12531
|
+
await runtime.start(handle, choice.profile);
|
|
12532
|
+
await runtime.prompt(handle, b.prompt);
|
|
12533
|
+
} catch (error) {
|
|
12534
|
+
if (handle)
|
|
12535
|
+
io.stderr(`armada: local workspace retained: ${herdrClaimHandle(handle)}
|
|
12536
|
+
`);
|
|
12537
|
+
throw new UsageError(error instanceof UsageError || error instanceof BriefError ? error.message : "local worker launch failed", `inspect herdr agent list; revoke the pending token with armada launch revoke ${ticketId} before retrying`);
|
|
12538
|
+
}
|
|
12539
|
+
const known = (await watchOf(io, config.project.slug)).state?.inFlight ?? [];
|
|
12540
|
+
const inFlightTickets = [...new Set([...known, ticketId])].sort();
|
|
12541
|
+
await remember(io, config.project.slug, { inFlight: inFlightTickets, readAt: now().toISOString() });
|
|
12542
|
+
const watch = await rearmFor(io, config.project.slug, { inFlight: inFlightTickets, open: null });
|
|
12543
|
+
const result = {
|
|
12544
|
+
ticket: ticketId,
|
|
12545
|
+
runtime: "herdr",
|
|
12546
|
+
profile: choice.name,
|
|
12547
|
+
harness: choice.profile.harness,
|
|
12548
|
+
branch,
|
|
12549
|
+
handle: herdrClaimHandle(handle),
|
|
12550
|
+
path: handle.path,
|
|
12551
|
+
state: "working",
|
|
12552
|
+
watch
|
|
12553
|
+
};
|
|
12554
|
+
io.stdout(args.json ? `${JSON.stringify(result, null, 2)}
|
|
12555
|
+
` : `Launched ${ticketId} with ${result.harness} on profile ${choice.name}.
|
|
12556
|
+
Worktree: ${handle.path}
|
|
12557
|
+
Handle: ${result.handle}
|
|
12558
|
+
The worker signs in and claims its ticket from the brief.
|
|
12559
|
+
${watch.line}
|
|
12560
|
+
`);
|
|
12561
|
+
return 0;
|
|
12562
|
+
}
|
|
12118
12563
|
|
|
12119
12564
|
// src/merge.ts
|
|
12120
12565
|
import { randomUUID } from "node:crypto";
|
|
12121
12566
|
import { rm as rm4 } from "node:fs/promises";
|
|
12122
12567
|
import { hostname, tmpdir as tmpdir2 } from "node:os";
|
|
12123
|
-
import { dirname as
|
|
12568
|
+
import { dirname as dirname6, join as join6 } from "node:path";
|
|
12124
12569
|
var TRANSIENT = /\bHTTP 5\d\d\b|\b5\d\d (?:Bad Gateway|Service Unavailable|Gateway Time-?out|Internal Server Error)\b|Bad Gateway|Service Unavailable|Gateway Time-?out|ECONNRESET|ETIMEDOUT|connection reset|i\/o timeout|TLS handshake timeout/i;
|
|
12125
12570
|
var tail = (text, lines = 30) => text.trimEnd().split(`
|
|
12126
12571
|
`).slice(-lines).join(`
|
|
@@ -12198,7 +12643,7 @@ function gitRepo(exec, cwd) {
|
|
|
12198
12643
|
},
|
|
12199
12644
|
async testMerge({ branch, base, head, number, commands }) {
|
|
12200
12645
|
await must(["fetch", "--quiet", "origin", branch, `refs/pull/${number}/head`]);
|
|
12201
|
-
const dir =
|
|
12646
|
+
const dir = join6(tmpdir2(), `armada-merge-${number}-${randomUUID().slice(0, 8)}`);
|
|
12202
12647
|
const remove = async () => {
|
|
12203
12648
|
await git(["worktree", "remove", "--force", dir]);
|
|
12204
12649
|
await git(["worktree", "prune"]);
|
|
@@ -12307,7 +12752,7 @@ async function merge(io, config, credentials, a, configPath) {
|
|
|
12307
12752
|
if (!exec)
|
|
12308
12753
|
throw new UsageError("armada merge needs to run git and gh");
|
|
12309
12754
|
const linearApiKey = credentials.linearApiKey;
|
|
12310
|
-
const repoDir =
|
|
12755
|
+
const repoDir = dirname6(configPath);
|
|
12311
12756
|
const fetchOpt = io.fetch ? { fetch: io.fetch } : {};
|
|
12312
12757
|
const gh = { token, repository: config.github.repository, ...fetchOpt };
|
|
12313
12758
|
const linearOpts = { apiKey: linearApiKey, labels: config.tracker.labels, ...fetchOpt };
|
|
@@ -12342,7 +12787,7 @@ async function merge(io, config, credentials, a, configPath) {
|
|
|
12342
12787
|
`),
|
|
12343
12788
|
installedSkill: async (name) => {
|
|
12344
12789
|
for (const dir of [AGENTS_SKILLS_DIR, CLAUDE_SKILLS_DIR])
|
|
12345
|
-
if (await io.readFile(
|
|
12790
|
+
if (await io.readFile(join6(repoDir, dir, name, "SKILL.md")) !== null)
|
|
12346
12791
|
return true;
|
|
12347
12792
|
return false;
|
|
12348
12793
|
}
|
|
@@ -12558,7 +13003,7 @@ ${"─".repeat(60)}
|
|
|
12558
13003
|
}
|
|
12559
13004
|
|
|
12560
13005
|
// src/secrets.ts
|
|
12561
|
-
import { dirname as
|
|
13006
|
+
import { dirname as dirname7, relative as relative3, resolve as resolve2 } from "node:path";
|
|
12562
13007
|
var NAME_HINT = "upper snake case, e.g. OPENAI_API_KEY";
|
|
12563
13008
|
var hhmm2 = (iso) => `${iso.slice(0, 16).replace("T", " ")} UTC`;
|
|
12564
13009
|
function signInOf(config, credentials) {
|
|
@@ -12638,7 +13083,7 @@ Next: armada secrets set <NAME> (an owner or admin), or the Keys page of Armada
|
|
|
12638
13083
|
async function exportRefusal(io, path) {
|
|
12639
13084
|
if (!io.exec)
|
|
12640
13085
|
return "git cannot be run here to check that the file is ignored";
|
|
12641
|
-
const cwd =
|
|
13086
|
+
const cwd = dirname7(path);
|
|
12642
13087
|
const tracked = await io.exec("git", ["ls-files", "--error-unmatch", "--", path], { cwd }).catch(() => null);
|
|
12643
13088
|
if (tracked?.code === 0)
|
|
12644
13089
|
return `git tracks ${path}: secrets written there would be committed`;
|
|
@@ -13001,7 +13446,11 @@ var COMMAND_HELP = {
|
|
|
13001
13446
|
A pull request the owner was asked about merges only once they approved
|
|
13002
13447
|
that exact head (or it with only the base merged in).
|
|
13003
13448
|
`,
|
|
13004
|
-
launch: ` launch
|
|
13449
|
+
launch: ` launch <ticket> --runtime herdr [--harness claude|codex|opencode]
|
|
13450
|
+
[--profile <name> [--reason <why>]] [--validation <n|none>]
|
|
13451
|
+
Create the ticket's worktree and start a persistent local worker
|
|
13452
|
+
with its launch-token brief. Profiles follow [[herdr.routing]]
|
|
13453
|
+
launch revoke <ticket>
|
|
13005
13454
|
Cancel the newest pending launch through Armada, including a worker
|
|
13006
13455
|
signed in but not claimed. A claimed launch needs armada release instead
|
|
13007
13456
|
`,
|
|
@@ -13144,6 +13593,7 @@ var VALUE_OPTIONS = [
|
|
|
13144
13593
|
"every",
|
|
13145
13594
|
"parent",
|
|
13146
13595
|
"runtime",
|
|
13596
|
+
"harness",
|
|
13147
13597
|
"handle",
|
|
13148
13598
|
"branch",
|
|
13149
13599
|
"ticket",
|
|
@@ -13202,6 +13652,7 @@ var COMMAND_OPTIONS = {
|
|
|
13202
13652
|
init: ["program-root", "name", "slug", "no-stop-hook"],
|
|
13203
13653
|
merge: ["ticket", "no-ticket", "dry-run", "no-lock", "wait", "timeout", "reason", "ask-owner"],
|
|
13204
13654
|
brief: ["profile", "reason", "prompt", "profile-line", "validation", "validation-reason"],
|
|
13655
|
+
launch: ["runtime", "harness", "profile", "reason", "validation", "validation-reason"],
|
|
13205
13656
|
validate: ["ticket", "attach", "caption", "choices", "message", "message-file"],
|
|
13206
13657
|
"ask-owner": ["choices"],
|
|
13207
13658
|
login: ["api-key", "launch-token", "api-url"],
|
|
@@ -13267,12 +13718,12 @@ async function findConfig(io, explicit, command = "status") {
|
|
|
13267
13718
|
throw new UsageError(`${path} does not exist`, `armada ${command} --config <file>, with the path of an ${CONFIG_FILE}`);
|
|
13268
13719
|
return { path, text };
|
|
13269
13720
|
}
|
|
13270
|
-
for (let dir = resolve3(io.cwd);; dir =
|
|
13271
|
-
const path =
|
|
13721
|
+
for (let dir = resolve3(io.cwd);; dir = dirname8(dir)) {
|
|
13722
|
+
const path = join7(dir, CONFIG_FILE);
|
|
13272
13723
|
const text = await io.readFile(path);
|
|
13273
13724
|
if (text !== null)
|
|
13274
13725
|
return { path, text };
|
|
13275
|
-
if (
|
|
13726
|
+
if (dirname8(dir) === dir)
|
|
13276
13727
|
break;
|
|
13277
13728
|
}
|
|
13278
13729
|
throw new UsageError(`no ${CONFIG_FILE} found in ${io.cwd} or any parent directory, so this is not a repository Armada runs`, `armada init to set this repository up, armada ${command} --config <file> to use another ${CONFIG_FILE}, or armada status --all to see the registered projects`);
|
|
@@ -13293,7 +13744,7 @@ async function status(io, args) {
|
|
|
13293
13744
|
...io.fetch ? { fetch: io.fetch } : {},
|
|
13294
13745
|
...io.now ? { now: io.now } : {}
|
|
13295
13746
|
});
|
|
13296
|
-
const behind = await skillsBehind(fsRepoView(
|
|
13747
|
+
const behind = await skillsBehind(fsRepoView(dirname8(path))).catch(() => null);
|
|
13297
13748
|
if (behind)
|
|
13298
13749
|
report.warnings.push(skillsBehindLine(behind, version));
|
|
13299
13750
|
io.stdout(args.json ? `${JSON.stringify(report, null, 2)}
|
|
@@ -13450,7 +13901,7 @@ async function dispatch(argv, io) {
|
|
|
13450
13901
|
const { path, text } = await findConfig(io, args.config, "launch");
|
|
13451
13902
|
const config = parseConfig(text, path);
|
|
13452
13903
|
const { credentials } = await loadCredentials(io, { project: config.project.slug });
|
|
13453
|
-
return await launch(io, config, credentials, args);
|
|
13904
|
+
return await launch(io, config, credentials, args, version, path);
|
|
13454
13905
|
}
|
|
13455
13906
|
if (args.command === "status") {
|
|
13456
13907
|
noExtra(args.rest);
|
|
@@ -13709,8 +14160,9 @@ function openUrl(url) {
|
|
|
13709
14160
|
return false;
|
|
13710
14161
|
}
|
|
13711
14162
|
}
|
|
13712
|
-
var exec = (command, args, { cwd }) => new Promise((done, fail) => {
|
|
14163
|
+
var exec = (command, args, { cwd, timeoutMs }) => new Promise((done, fail) => {
|
|
13713
14164
|
const child = spawn2(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
14165
|
+
const timer = timeoutMs ? setTimeout(() => child.kill("SIGKILL"), timeoutMs) : null;
|
|
13714
14166
|
let stdout = "";
|
|
13715
14167
|
let stderr = "";
|
|
13716
14168
|
child.stdout.setEncoding("utf8").on("data", (d) => {
|
|
@@ -13719,8 +14171,16 @@ var exec = (command, args, { cwd }) => new Promise((done, fail) => {
|
|
|
13719
14171
|
child.stderr.setEncoding("utf8").on("data", (d) => {
|
|
13720
14172
|
stderr += d;
|
|
13721
14173
|
});
|
|
13722
|
-
child.on("error",
|
|
13723
|
-
|
|
14174
|
+
child.on("error", (err) => {
|
|
14175
|
+
if (timer)
|
|
14176
|
+
clearTimeout(timer);
|
|
14177
|
+
fail(err);
|
|
14178
|
+
});
|
|
14179
|
+
child.on("close", (code) => {
|
|
14180
|
+
if (timer)
|
|
14181
|
+
clearTimeout(timer);
|
|
14182
|
+
done({ code: code ?? 1, stdout, stderr });
|
|
14183
|
+
});
|
|
13724
14184
|
});
|
|
13725
14185
|
var stopped = false;
|
|
13726
14186
|
if (process.argv.includes("heartbeat") && !process.argv.includes("--background"))
|
|
@@ -13791,6 +14251,14 @@ var code = await run(process.argv.slice(2), {
|
|
|
13791
14251
|
gitBranch,
|
|
13792
14252
|
readStdin,
|
|
13793
14253
|
exec,
|
|
14254
|
+
detach: (command, args, { cwd, env }) => new Promise((resolve) => {
|
|
14255
|
+
const child = spawn2(command, args, { cwd, env, stdio: "ignore", detached: true });
|
|
14256
|
+
child.once("error", () => resolve(false));
|
|
14257
|
+
child.once("spawn", () => {
|
|
14258
|
+
child.unref();
|
|
14259
|
+
resolve(true);
|
|
14260
|
+
});
|
|
14261
|
+
}),
|
|
13794
14262
|
spawn: spawnInherited,
|
|
13795
14263
|
startBackground,
|
|
13796
14264
|
stopped: () => stopped,
|