@the-vibe-company/armada 0.2.37 → 0.2.38
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/README.md +5 -3
- package/dist/armada.js +503 -185
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ armada skills update # update bundled skills locally on your cu
|
|
|
52
52
|
`armada doctor` checks, in the repository you are in:
|
|
53
53
|
|
|
54
54
|
- `armada.toml` exists and is valid;
|
|
55
|
-
- the Armada skills (`armada-coordinator`, `armada-worker`, `armada-runtime-conductor`, `armada-runtime-claude-code`, `ship-pr-dev`, `review-code-dev`, `capture-learning-tools`) are in `.agents/skills`, linked from `.claude/skills`, recorded in `skills-lock.json` (the [`npx skills`](https://github.com/vercel-labs/skills) format), and match this version of Armada;
|
|
55
|
+
- the Armada skills (`armada-coordinator`, `armada-worker`, `armada-runtime-conductor`, `armada-runtime-claude-code`, `armada-runtime-herdr`, `ship-pr-dev`, `review-code-dev`, `capture-learning-tools`) are in `.agents/skills`, linked from `.claude/skills`, recorded in `skills-lock.json` (the [`npx skills`](https://github.com/vercel-labs/skills) format), and match this version of Armada;
|
|
56
56
|
- `.conductor/settings.toml` has a `[scripts] setup` command;
|
|
57
57
|
- `.gitignore` ignores `plans/ship-pr-dev/`;
|
|
58
58
|
- this terminal is signed in to Armada, and to which organization: without a sign-in, `armada brief` gives workers no launch token, so each would need the keys in its environment;
|
|
@@ -91,7 +91,7 @@ On a repository without `armada.toml`, pass `--program-root <ISSUE-ID>`; the nam
|
|
|
91
91
|
|
|
92
92
|
## Launch a worker (coordinators)
|
|
93
93
|
|
|
94
|
-
Armada
|
|
94
|
+
Armada starts persistent local workers through herdr; Conductor and Claude Code subagents follow their runtime guides. The `armada-runtime-conductor` skill gives the exact Conductor Cloud commands; the `armada-runtime-claude-code` skill launches a worker as a background subagent of a coordinator running in Claude Code, in its own git worktree (it dies with the coordinator's session, so long runs go to Conductor). [`docs/runbook.md`](docs/runbook.md) says how to start a coordinator on a laptop or in Conductor Cloud, what the owner sets up once, and how one coordinator hands over to the next.
|
|
95
95
|
|
|
96
96
|
```sh
|
|
97
97
|
armada brief ABC-12 # read-only settings and prompt preview; no launch
|
|
@@ -161,7 +161,7 @@ armada answer --note ABC-12 "main moved: bring it in before you ship" # an unso
|
|
|
161
161
|
- `armada hook stop` is the Claude Code Stop hook `armada init` adds to `.claude/settings.json` (it asks; `--no-stop-hook` leaves it out; `armada doctor` shows it). It reads only armada.toml and the watch state, so it answers at once without the network. It refuses to end the turn, and tells the agent to start `armada watch` in the background, only in the checkout where `armada watch` ran (never a worker's), while the last read had workers in flight and no watch runs. A watch that ended on a refusal lets the turn end, and `ARMADA_STOP_HOOK=off` turns the hook off.
|
|
162
162
|
- On the dashboard, an item open in the coordinator's inbox for longer than `policy.coordinator_minutes` (default 10) shows "waiting for the coordinator for N min" in "Waiting for you".
|
|
163
163
|
- A coordinator's own claim is never listed as silent in its inbox: only an exact, nonempty handle match is excluded, not its questions, requests or hand-backs. `inbox` takes the reading coordinator's handle from `ARMADA_COORDINATOR_HANDLE` first, otherwise from both `CONDUCTOR_WORKSPACE_ID` and `CONDUCTOR_SESSION_ID` joined as `workspace/session`. Blank values are ignored; with no complete identity, silence detection is unchanged. Local coordinators should set `ARMADA_COORDINATOR_HANDLE` to the handle used for their claim. The same identity is used for every `--wait` poll and the dashboard presence record; the fleet-wide `status` and dashboard silence rules are unchanged.
|
|
164
|
-
- `answer`
|
|
164
|
+
- `answer` delivers herdr answers into the verified pane before recording them; for other runtimes, deliver first with the runtime guide's message section. A live herdr approval or question can be answered by ticket even before a worker reports. It posts `Agent status: <current phase> — answer: …` on the ticket and resolves the item. An item id needs Armada; a ticket id answers that ticket's open questions and plans and also works without it. `--note` records a delivered note as `Agent status: <phase> — note: …`; it accepts a ticket or plan item id and resolves open plans, not questions. These two are the coordinator's records: Armada never reads them as the worker's phase, hand-back or sign of life. Questions, plans and requests can be answered; `merge` resolves hand-backs, and `release` and `merge` resolve the ticket's open questions. For older clients without heartbeats, no report within `policy.silence_minutes` of an answer shows as silent. With heartbeats, the report reminder uses `policy.quiet_minutes` instead.
|
|
165
165
|
- The dashboard adds two kinds of request, signed by the person who made them. In "Waiting for you", **Approve** opens an editable approval (`approved` by default); sending it creates an `answer-request`, just like answering a question. Deliver its text, then `armada answer <request id> "<answer>"`, which resolves the request and its question or plan and names the requester on the ticket (answering the item itself also closes a waiting request). A `launch-request` asks to launch a ready ticket on a profile: launch it as usual; the worker's `armada claim` resolves it and posts who asked. To decline one, `armada answer <request id> "<why>"`: it is closed with the reason and nothing is posted on the ticket.
|
|
166
166
|
|
|
167
167
|
## What the owner validates
|
|
@@ -533,3 +533,5 @@ the worker's declaration, not an independent CLI verification of review artifact
|
|
|
533
533
|
|
|
534
534
|
MIT. The bundled Alibaba review workflow retains Apache-2.0; each shipping skill
|
|
535
535
|
includes its license and attribution notices.
|
|
536
|
+
|
|
537
|
+
Persistent local workers: `armada status`, `inbox` and `watch` publish herdr state for the dashboard. `armada stop <ticket>` archives only a clean worktree whose commits are on its verified remote upstream, retaining its branch. See [`armada-runtime-herdr`](skills/armada-runtime-herdr/SKILL.md) for all four runtime operations.
|
package/dist/armada.js
CHANGED
|
@@ -954,7 +954,14 @@ function buildLane(m, allComments, issue, opts) {
|
|
|
954
954
|
function inFlight(m, comments, opts) {
|
|
955
955
|
const held = (i) => {
|
|
956
956
|
const fresh = freshEvent(i.id, opts);
|
|
957
|
-
|
|
957
|
+
const handle = opts.live?.handles?.[i.id];
|
|
958
|
+
const open = !!handle && !handle.releasedAt;
|
|
959
|
+
if (fresh) {
|
|
960
|
+
if (!ENDS_WORK.includes(fresh.kind))
|
|
961
|
+
return true;
|
|
962
|
+
return open && !!handle.claimedAt && handle.claimedAt > fresh.at;
|
|
963
|
+
}
|
|
964
|
+
return open || !!i.agentPhase || isStarted(i);
|
|
958
965
|
};
|
|
959
966
|
return m.program.filter((i) => m.isLeaf(i) && !isClosed(i) && held(i)).map((i) => buildLane(m, comments, i, opts)).sort((a, b) => PHASE_RANK[a.phase] - PHASE_RANK[b.phase] || a.issue.id.localeCompare(b.issue.id, "en", { numeric: true }));
|
|
960
967
|
}
|
|
@@ -3889,6 +3896,12 @@ function notStartedBody(l, now) {
|
|
|
3889
3896
|
return `launched ${minutes} min ago and never claimed; ${why}${l.handle ? ` (session ${l.handle})` : ""}. Check its session with the runtime guide's status section; launch it again with armada brief ${l.ticket} --prompt, or revoke it with armada launch revoke ${l.ticket}`;
|
|
3890
3897
|
}
|
|
3891
3898
|
var notStartedLaunches = (launches, now, minutes) => followedLaunches(launches, now).filter((l) => now.getTime() - Date.parse(l.launchedAt) > minutes * MIN2);
|
|
3899
|
+
function freshRuntimeState(observation, now, minutes, claimedAt) {
|
|
3900
|
+
if (!observation || claimedAt && (observation.at < claimedAt || (observation.since ?? observation.at) < claimedAt))
|
|
3901
|
+
return null;
|
|
3902
|
+
const age = now.getTime() - Date.parse(observation.at);
|
|
3903
|
+
return observation.state !== "unknown" && Number.isFinite(age) && age >= 0 && age <= minutes * MIN2 ? observation.state : null;
|
|
3904
|
+
}
|
|
3892
3905
|
|
|
3893
3906
|
// ../core/src/fleet-api.ts
|
|
3894
3907
|
var WORKER_FLEET_OPS = ["claim", "report", "ask", "release", "heartbeat", "validate"];
|
|
@@ -3899,6 +3912,10 @@ var FLEET_OPS = [
|
|
|
3899
3912
|
"request",
|
|
3900
3913
|
"events/latest",
|
|
3901
3914
|
"heartbeats/latest",
|
|
3915
|
+
"runtime/handles",
|
|
3916
|
+
"runtime/handle",
|
|
3917
|
+
"runtime/observe",
|
|
3918
|
+
"runtime/stop",
|
|
3902
3919
|
"launches",
|
|
3903
3920
|
"inbox",
|
|
3904
3921
|
"inbox/item",
|
|
@@ -3928,6 +3945,10 @@ function fleetClient(o) {
|
|
|
3928
3945
|
lastEventTimes: () => call("events/latest", {}),
|
|
3929
3946
|
heartbeatTimes: () => call("heartbeats/latest", {}),
|
|
3930
3947
|
heartbeat: (input) => call("heartbeat", input),
|
|
3948
|
+
runtimeHandles: () => call("runtime/handles", {}),
|
|
3949
|
+
runtimeHandle: (ticket) => call("runtime/handle", { ticket }),
|
|
3950
|
+
observeRuntime: (input) => call("runtime/observe", input),
|
|
3951
|
+
stopRuntime: (input) => call("runtime/stop", input),
|
|
3931
3952
|
pendingLaunches: () => call("launches", {}),
|
|
3932
3953
|
claim: (c) => call("claim", c),
|
|
3933
3954
|
report: (r) => call("report", r),
|
|
@@ -4390,7 +4411,10 @@ async function answerItem(ctx, input) {
|
|
|
4390
4411
|
ticketId = input.target.trim().toUpperCase();
|
|
4391
4412
|
if (!input.note) {
|
|
4392
4413
|
const open = await live(ctx, warnings, `read the open questions of ${ticketId}`, (fleet) => fleet.ticketItems(ticketId ?? ""));
|
|
4393
|
-
|
|
4414
|
+
const handle = open && !open.some((i) => i.kind === "question" || i.kind === "plan") ? await live(ctx, warnings, `read the runtime of ${ticketId}`, (fleet) => fleet.runtimeHandle(ticketId ?? "")) : null;
|
|
4415
|
+
const observation = handle?.runtimeState;
|
|
4416
|
+
const runtimeBlocked = ctx.deliverAnswer && handle?.runtime.toLowerCase() === "herdr" && !handle.releasedAt && observation?.state === "blocked" && Date.parse(observation.at) <= ctx.now().getTime() && ctx.now().getTime() - Date.parse(observation.at) <= config.policy.silentAfterMinutes * 60000;
|
|
4417
|
+
if (open && !open.some((i) => i.kind === "question" || i.kind === "plan") && !runtimeBlocked)
|
|
4394
4418
|
throw new Refusal(`${ticketId} has no open question or plan in the inbox`, `armada answer --note ${ticketId} "<message>", for an unsolicited message`);
|
|
4395
4419
|
}
|
|
4396
4420
|
}
|
|
@@ -4403,6 +4427,11 @@ async function answerItem(ctx, input) {
|
|
|
4403
4427
|
const question = item?.kind === "answer-request" ? item.request?.question ?? null : null;
|
|
4404
4428
|
const answered = question === null ? item : await live(ctx, warnings, `read the item answered by #${item?.id}`, (fleet) => fleet.inboxItem(question));
|
|
4405
4429
|
const answerKind = answered?.kind === "plan" ? "plan" : "question";
|
|
4430
|
+
const claim = ticketId && ctx.deliverAnswer ? await live(ctx, warnings, `read the claim of ${ticketId}`, (fleet) => fleet.runtimeHandle(ticketId)) : null;
|
|
4431
|
+
if (claim?.runtime.toLowerCase() === "herdr" && claim.releasedAt)
|
|
4432
|
+
throw new Refusal("the herdr worker has ended; no answer was delivered", "armada inbox");
|
|
4433
|
+
if (claim?.runtime.toLowerCase() === "herdr" && answered && answered.createdAt < claim.claimedAt)
|
|
4434
|
+
throw new Refusal("the question belongs to an earlier worker claim; no answer was delivered", "armada inbox");
|
|
4406
4435
|
let url = "";
|
|
4407
4436
|
if (ticketId) {
|
|
4408
4437
|
const ticket = await linear.readTicket(ticketId);
|
|
@@ -4410,14 +4439,20 @@ async function answerItem(ctx, input) {
|
|
|
4410
4439
|
throw new Refusal(`ticket ${ticketId} not found in Linear`, "armada inbox");
|
|
4411
4440
|
url = ticket.url;
|
|
4412
4441
|
warnings.push(...ticket.warnings);
|
|
4413
|
-
|
|
4442
|
+
const herdrClaim = claim?.runtime.toLowerCase() === "herdr" && !claim.releasedAt;
|
|
4443
|
+
if (!ticket.agentPhase && !herdrClaim) {
|
|
4414
4444
|
if (input.note)
|
|
4415
4445
|
throw new Refusal(`${ticket.id} has no agent phase: no worker holds it, so there is no one to tell`, "armada status, to see which tickets are in flight");
|
|
4416
4446
|
warnings.push(`${ticket.id} has no agent phase (no worker holds it); the answer was not posted on the ticket`);
|
|
4417
4447
|
} else {
|
|
4418
4448
|
const ref = item?.kind === "answer-request" ? `Answers ${question === null ? "the open question or plan" : `${answerKind} #${question}`}, as ${item.author ?? "the owner"} asked from the dashboard (request #${item.id}).` : itemId === null ? null : `Answers ${answerKind} #${itemId}.`;
|
|
4419
|
-
await
|
|
4420
|
-
|
|
4449
|
+
if (ctx.deliverAnswer && await ctx.deliverAnswer(ticket.id, text, claim?.runtime ?? ticket.agentRuntime, claim))
|
|
4450
|
+
lines.push(`Delivered to ${ticket.id}'s herdr pane.`);
|
|
4451
|
+
if (ticket.agentPhase) {
|
|
4452
|
+
await linear.comment(ticket.uuid, statusComment(ticket.agentPhase, input.note ? "note" : "answer", text, ref));
|
|
4453
|
+
lines.push(`${input.note ? "Note" : "Answer"} posted on ${ticket.id} (${ticket.agentPhase}).`);
|
|
4454
|
+
} else
|
|
4455
|
+
warnings.push(`${ticket.id} has no tracker phase; the delivered answer is recorded in Armada`);
|
|
4421
4456
|
}
|
|
4422
4457
|
}
|
|
4423
4458
|
const recorded = await live(ctx, warnings, `record the ${input.note ? "note" : "answer"}`, (fleet) => fleet.answer({ text, note: !!input.note, ticket: ticketId, item: itemId }));
|
|
@@ -5947,7 +5982,7 @@ The coordinator turns the owner's intent into merged pull requests. Each worker
|
|
|
5947
5982
|
|
|
5948
5983
|
**Standing authority.** Unless the owner said otherwise, they delegate reversible technical decisions, plan approval and merging to you: act, then report. Escalate only product decisions, irreversible or outward-facing actions, and anything that spends money.
|
|
5949
5984
|
|
|
5950
|
-
**
|
|
5985
|
+
**Use the worker's runtime guide.** Launching, messaging, checking and stopping a worker go through the runtime guide skill for the worker's runtime: \`armada-runtime-conductor\` for a Conductor workspace, \`armada-runtime-claude-code\` for a subagent of your own Claude Code session (the \`Runtime:\` line of \`armada brief\` names it). For persistent local workers, \`armada-runtime-herdr\` uses Armada's integrated launch, state, answer and safe stop commands. Other runtimes are delivered separately and Armada records what happened.
|
|
5951
5986
|
|
|
5952
5987
|
## Take over a run
|
|
5953
5988
|
|
|
@@ -5964,7 +5999,7 @@ A coordinator may start cold, on a laptop or in a fresh cloud session, with noth
|
|
|
5964
5999
|
## Loop
|
|
5965
6000
|
|
|
5966
6001
|
1. **Read the fleet** with \`armada status\` and \`armada inbox\`, never from memory. Done when you can name every ticket in flight and its phase, every ready ticket, every pull request waiting, every silent worker and every pending question, plan or request.
|
|
5967
|
-
2. **Answer what waits for you first.** For each question in \`armada inbox\`: decide it, or escalate it to the owner when it is a product decision: \`armada ask-owner <ticket> "<question>" --choices "<a> | <b>"\` puts it on the owner's Validations page and prints the link to send them; their pick arrives as a \`decision\` item. For each \`plan\` item: read the full plan, approve it or give concrete amendments. Deliver the decision in the worker's session with the runtime guide's *message* section, then record it with \`armada answer <item> "approved"\` or \`armada answer <item> "<amendments and reason>"\`. The worker resumes with \`implementing\` on approval, or returns to \`planning\` and submits a revised plan. \`armada answer\`
|
|
6002
|
+
2. **Answer what waits for you first.** For each question in \`armada inbox\`: decide it, or escalate it to the owner when it is a product decision: \`armada ask-owner <ticket> "<question>" --choices "<a> | <b>"\` puts it on the owner's Validations page and prints the link to send them; their pick arrives as a \`decision\` item. For each \`plan\` item: read the full plan, approve it or give concrete amendments. Deliver the decision in the worker's session with the runtime guide's *message* section, then record it with \`armada answer <item> "approved"\` or \`armada answer <item> "<amendments and reason>"\`. The worker resumes with \`implementing\` on approval, or returns to \`planning\` and submits a revised plan. \`armada answer\` delivers herdr answers automatically; omit the separate delivery step for herdr. Decide reversible choices yourself and prefer the option that keeps behaviour observable. When two workers need the same shared resource (a migration slot, a generated file, a version number), set the rule once and tell both. A message the worker did not ask for (main moved, bring it in) takes the same path: deliver it with the runtime guide, then \`armada answer --note <ticket> "<message>"\`. A live herdr \`runtime-blocked\` entry has no item id: read the pane and answer by ticket. Done when the inbox shows no open question or plan.
|
|
5968
6003
|
3. **Carry out the owner's dashboard requests.** They are the owner's word, signed with their name; they never reached a worker.
|
|
5969
6004
|
- \`answer-request\` (it names the question or plan it answers, \`answers #<id>\`): deliver its text in the worker's session with the runtime guide's *message* section, as the owner's answer or plan approval, then \`armada answer <request id> "<the text you delivered>"\`. That resolves the request and its question or plan, and the ticket names who answered. If the item is gone (the worker was released or changed phase), \`armada answer <request id> "<why>"\` closes it.
|
|
5970
6005
|
- \`launch-request\`: launch the ticket as in step 5. A request may name a label-routed profile or one the owner chose; otherwise choose from the profiles' \`when\` rules. Pass \`--profile\` and \`--reason\` when a choice or override is needed. The worker's \`armada claim\` resolves the request and posts who asked. If the ticket must not start (it collides with work in flight, or its plan changed), decline it: \`armada answer <request id> "<why>"\`, and tell the owner in your report.
|
|
@@ -6019,7 +6054,7 @@ name: armada-runtime-claude-code
|
|
|
6019
6054
|
description: Runtime guide for running Armada workers as local subagents of a Claude Code coordinator. Use when an Armada coordinator running in Claude Code must launch a worker on a ticket with the Agent tool, send it a message, check whether a silent worker is still alive, or stop it and clean up its worktree. Four fixed sections, each with the exact tool call and how to read its result.
|
|
6020
6055
|
---
|
|
6021
6056
|
|
|
6022
|
-
Armada
|
|
6057
|
+
Armada records Conductor and Claude Code runtime actions separately; persistent herdr workers use integrated commands. This guide tells a coordinator running inside Claude Code how to launch, message, check and stop a worker as one of its own subagents (the Agent tool), and what to record in Armada afterwards. It was checked against Claude Code's Agent, SendMessage, TaskStop and EnterWorktree tools as of October 2026; if a parameter below is refused, read the tool's own description and adapt.
|
|
6023
6058
|
|
|
6024
6059
|
- **A subagent lives inside your session.** It dies when your session ends: closing the terminal, a crash or the end of a cloud machine stops every worker you launched this way, mid-turn. Use this runtime for short tickets you will see through in one sitting. Long runs, and anything that must survive you, go to Conductor (the \`armada-runtime-conductor\` skill).
|
|
6025
6060
|
- **Always in its own worktree.** A subagent launched without \`isolation: "worktree"\` works in your own checkout: it edits your files and switches your branch under you, and two such workers overwrite each other. Never launch one without it.
|
|
@@ -6131,7 +6166,16 @@ A subagent launched without \`isolation: "worktree"\` runs in your checkout. The
|
|
|
6131
6166
|
files: [
|
|
6132
6167
|
{
|
|
6133
6168
|
path: "SKILL.md",
|
|
6134
|
-
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 never calls a runtime. 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"
|
|
6169
|
+
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"
|
|
6170
|
+
}
|
|
6171
|
+
]
|
|
6172
|
+
},
|
|
6173
|
+
{
|
|
6174
|
+
name: "armada-runtime-herdr",
|
|
6175
|
+
files: [
|
|
6176
|
+
{
|
|
6177
|
+
path: "SKILL.md",
|
|
6178
|
+
content: '---\nname: armada-runtime-herdr\ndescription: Runtime guide for persistent Armada workers on this machine through herdr. Four sections cover launch, message, status, and stop with safe worktree archival.\n---\n\nHerdr keeps each worker in its own worktree and terminal across coordinator restarts. Run these commands on the machine that launched the worker, against the same herdr server/session. The claim stores JSON `{workspace,pane,agent}`: recover it from `armada status --json` or the ticket\'s claim comment instead of relying on your old coordinator session. Requires herdr 0.9.1+, a supported harness already signed in, and an Armada coordinator sign-in. Never handle harness keys or sign-ins.\n\n## Launch\n\n```sh\narmada launch ABC-12 --runtime herdr --profile backend --reason "back end work" --json\n```\n\nThe profile in `[herdr.profiles]` selects the harness, model and effort. Label routing wins; use a reason for semantic selection or an override. An optional `--harness claude|codex|opencode|deepseek` checks the selected profile. DeepSeek profiles run OpenCode with the exact configured DeepSeek model; Armada reports their runtime agent as `opencode` while preserving the DeepSeek profile label. Launch checks tools first, creates a worktree, starts the harness, and sends the scoped worker brief. Its JSON gives the `handle` and worktree path, without the token. The worker signs in with its one-time launch token, claims the stored handle and starts its heartbeat. No claim after the configured timeout: read the pane, fix the cause, or revoke the unused launch with `armada launch revoke ABC-12`. Failed launch retains the worktree for inspection.\n\n## Message\n\n```sh\narmada answer <inbox-id> "Plan approved. Go on."\narmada answer ABC-12 "<answer to a live harness approval or question>"\narmada answer --note ABC-12 --message-file /tmp/abc-12-message.md\n```\n\nFor herdr, Armada verifies the saved pane, delivers literal text plus Enter and then records the answer on the ticket and in the inbox. Read an approval UI before deciding what input it expects; the answer may be a short choice such as `y`. Delivery errors leave the question open and write no successful answer. Inspect the pane before retrying after a timeout: the terminal may already have received the input. There is no separate delivery step. Successful delivery confirms submission, not that the worker has completed a turn. For other runtimes, follow their guide and deliver before recording with Armada.\n\n## Status\n\n```sh\narmada status --json\narmada inbox\nherdr agent get <pane>\nherdr agent read <pane> --source recent-unwrapped --lines 120\nherdr agent wait <pane> --until idle --until done --until blocked --timeout 30000\n```\n\n`status`, `inbox` and each `watch` poll discover workers from persisted claims and publish local observations to Armada. The dashboard shows that stored live state beside the last report; it never probes a local runtime. Observations expire after `policy.silence_minutes`.\n\nHerdr\'s `.result.agent` carries `workspace_id`, `pane_id`, `name` and `agent_status`. Verify all three IDs against the claim. `working` is a running turn, `blocked` is an approval or question UI, and `idle`/`done` are ready for input. A live `runtime-blocked` inbox entry can appear before a worker report; read its pane and answer by ticket. It clears after an answer until the next blocked transition. Herdr\'s state-change counter preserves approvals that arrive between polls, even when both readings are blocked. `unknown` falls back to Armada reports; it is not proof of completion. DeepSeek and other harnesses also report their phase to herdr via `pane report-agent --source armada` on report, ask and heartbeat. Reporting failures warn and do not fail the worker command.\n\nTerminal reads print text directly, not JSON. Do not paste credentials or complete transcripts into tickets. A coordinator restart changes no worker handle: read `armada status` and continue from those claims.\n\n## Stop and archive\n\n```sh\n# For unfinished work, release the ticket with its reason first.\narmada release --ticket ABC-12 --reason "<why the worker is being stopped>"\narmada stop ABC-12\n```\n\nAfter merge, run `armada stop ABC-12` directly; the released claim is still discoverable for cleanup. Stop verifies the linked worktree belongs to this repository and the claim\'s branch. It refuses uncommitted files (including untracked files), a missing remote upstream, an unreachable upstream, or commits not on that upstream, and explains what remains. Push or preserve that work before retrying; never force removal. It fetches the configured upstream, interrupts an active turn and waits up to five seconds for idle or done, then rechecks the checkout before `herdr worktree remove --workspace <workspace>` without `--force`. Herdr ends the workspace terminals and removes the checkout; the branch remains. The exact saved claim is marked ended. If the worker does not settle, the checkout stays intact; inspect the pane and retry. Failed removal leaves the claim and checkout for inspection; inspect `herdr worktree list` before retrying a timeout.\n'
|
|
6135
6179
|
}
|
|
6136
6180
|
]
|
|
6137
6181
|
},
|
|
@@ -9884,6 +9928,7 @@ function buildStatus({
|
|
|
9884
9928
|
lastUpdate: l.lastUpdate,
|
|
9885
9929
|
lastReport: l.lastReport,
|
|
9886
9930
|
lastHeartbeat: l.lastHeartbeat,
|
|
9931
|
+
runtimeState: freshRuntimeState(live?.handles?.[l.issue.id]?.runtimeState, now, config.policy.silentAfterMinutes, live?.handles?.[l.issue.id]?.claimedAt),
|
|
9887
9932
|
silent: l.flags.includes("silent"),
|
|
9888
9933
|
statusLine: l.statusLine ? { summary: l.statusLine.summary, at: l.statusLine.at, url: l.statusLine.url, plan: l.statusLine.plan } : null,
|
|
9889
9934
|
pr: l.pr ? prRef(l.pr) : null,
|
|
@@ -9948,12 +9993,15 @@ async function loadStatus(config, opts) {
|
|
|
9948
9993
|
const launchesP = opts.launches ? opts.launches().then((launches) => ({ launches }), (err) => ({
|
|
9949
9994
|
warning: `Armada's launches could not be read (${err instanceof Error ? err.message : String(err)}); workers launched that never started are not listed`
|
|
9950
9995
|
})) : Promise.resolve({});
|
|
9951
|
-
const [{ program, forge, forgeError }, events, launches, heartbeats] = await Promise.all([
|
|
9996
|
+
const [{ program, forge, forgeError }, events, launches, heartbeats, runtimeHandles] = await Promise.all([
|
|
9952
9997
|
readStatusSources(config, opts),
|
|
9953
9998
|
eventsP,
|
|
9954
9999
|
launchesP,
|
|
9955
10000
|
opts.heartbeats?.().catch(() => {
|
|
9956
10001
|
return;
|
|
10002
|
+
}),
|
|
10003
|
+
opts.runtimeHandles?.().catch(() => {
|
|
10004
|
+
return;
|
|
9957
10005
|
})
|
|
9958
10006
|
]);
|
|
9959
10007
|
return buildStatus({
|
|
@@ -9963,6 +10011,13 @@ async function loadStatus(config, opts) {
|
|
|
9963
10011
|
forgeError,
|
|
9964
10012
|
...events.events ? { lastEvents: events.events } : {},
|
|
9965
10013
|
...heartbeats ? { heartbeats } : {},
|
|
10014
|
+
...runtimeHandles ? {
|
|
10015
|
+
live: {
|
|
10016
|
+
after: program.fetchedAt,
|
|
10017
|
+
events: {},
|
|
10018
|
+
handles: Object.fromEntries(runtimeHandles.map((h) => [h.ticket, h]))
|
|
10019
|
+
}
|
|
10020
|
+
} : {},
|
|
9966
10021
|
...launches.launches ? { launches: launches.launches } : {},
|
|
9967
10022
|
extraWarnings: [events.warning, launches.warning].filter((w) => !!w),
|
|
9968
10023
|
now: now()
|
|
@@ -10093,7 +10148,7 @@ ${attachments.join(`
|
|
|
10093
10148
|
};
|
|
10094
10149
|
}
|
|
10095
10150
|
// package.json
|
|
10096
|
-
var version = "0.2.
|
|
10151
|
+
var version = "0.2.38";
|
|
10097
10152
|
|
|
10098
10153
|
// src/attach.ts
|
|
10099
10154
|
import { resolve } from "node:path";
|
|
@@ -10630,6 +10685,395 @@ async function logout(io) {
|
|
|
10630
10685
|
return 0;
|
|
10631
10686
|
}
|
|
10632
10687
|
|
|
10688
|
+
// src/herdr.ts
|
|
10689
|
+
class HerdrError extends UsageError {
|
|
10690
|
+
code;
|
|
10691
|
+
constructor(message, code) {
|
|
10692
|
+
super(message);
|
|
10693
|
+
this.code = code;
|
|
10694
|
+
}
|
|
10695
|
+
}
|
|
10696
|
+
var harnessArgs = (p) => [
|
|
10697
|
+
"--model",
|
|
10698
|
+
herdrHarnessKind(p.harness) === "opencode" ? `${p.model.split("#")[0]}#${p.effort}` : p.model,
|
|
10699
|
+
...p.harness === "codex" ? ["-c", `model_reasoning_effort=${JSON.stringify(p.effort)}`] : p.harness === "claude" ? ["--effort", p.effort] : [],
|
|
10700
|
+
...p.extraArgs
|
|
10701
|
+
];
|
|
10702
|
+
var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : null;
|
|
10703
|
+
var id = (v) => typeof v === "string" && /^[a-zA-Z0-9][a-zA-Z0-9:_-]{0,127}$/.test(v);
|
|
10704
|
+
function parseHerdrHandle(raw) {
|
|
10705
|
+
let h = null;
|
|
10706
|
+
try {
|
|
10707
|
+
h = object(JSON.parse(raw));
|
|
10708
|
+
} catch {}
|
|
10709
|
+
if (!h || !id(h.workspace) || !id(h.pane) || !id(h.agent) || !/^[a-z][a-z0-9_-]{0,31}$/.test(h.agent))
|
|
10710
|
+
throw new UsageError("invalid herdr claim handle; expected JSON with workspace, pane and agent");
|
|
10711
|
+
return { workspace: h.workspace, pane: h.pane, agent: h.agent };
|
|
10712
|
+
}
|
|
10713
|
+
function herdrPhase(phase) {
|
|
10714
|
+
if (phase === "blocked" || phase === "awaiting-approval" || phase === "awaiting-validation")
|
|
10715
|
+
return "blocked";
|
|
10716
|
+
if (phase === "ready-to-merge")
|
|
10717
|
+
return "idle";
|
|
10718
|
+
return phase && ["planning", "implementing", "shipping"].includes(phase) ? "working" : "unknown";
|
|
10719
|
+
}
|
|
10720
|
+
async function reportHerdr(io, phase, agent, heartbeat = false) {
|
|
10721
|
+
if (io.env.HERDR_ENV !== "1" || !io.env.HERDR_PANE_ID)
|
|
10722
|
+
return;
|
|
10723
|
+
try {
|
|
10724
|
+
if (!id(io.env.HERDR_PANE_ID))
|
|
10725
|
+
throw new Error("invalid pane");
|
|
10726
|
+
await new Herdr(io).report(io.env.HERDR_PANE_ID, agent, herdrPhase(phase), heartbeat);
|
|
10727
|
+
} catch {
|
|
10728
|
+
io.stderr(`armada: warning: could not report worker state to herdr; Armada reporting continues.
|
|
10729
|
+
`);
|
|
10730
|
+
}
|
|
10731
|
+
}
|
|
10732
|
+
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)));
|
|
10733
|
+
var credentialNames = (env, extra) => [
|
|
10734
|
+
...new Set([
|
|
10735
|
+
"LINEAR_API_KEY",
|
|
10736
|
+
"GITHUB_TOKEN",
|
|
10737
|
+
"GH_TOKEN",
|
|
10738
|
+
"ARMADA_API_KEY",
|
|
10739
|
+
"ARMADA_SESSION_TOKEN",
|
|
10740
|
+
"ARMADA_SIGNED_IN_TO",
|
|
10741
|
+
"ARMADA_API_URL",
|
|
10742
|
+
"OPENAI_API_KEY",
|
|
10743
|
+
"ANTHROPIC_API_KEY",
|
|
10744
|
+
...Object.keys(env).filter((name) => /^(ARMADA_|CONDUCTOR_)|(?:KEY|TOKEN|SECRET|PASSWORD)$/.test(name)),
|
|
10745
|
+
...extra
|
|
10746
|
+
])
|
|
10747
|
+
].filter((name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)).sort();
|
|
10748
|
+
|
|
10749
|
+
class Herdr {
|
|
10750
|
+
io;
|
|
10751
|
+
constructor(io) {
|
|
10752
|
+
this.io = io;
|
|
10753
|
+
}
|
|
10754
|
+
async call(args, timeoutMs = 40000) {
|
|
10755
|
+
const operation = args.slice(0, 2).join(" ");
|
|
10756
|
+
let reply;
|
|
10757
|
+
let code;
|
|
10758
|
+
try {
|
|
10759
|
+
if (!this.io.exec)
|
|
10760
|
+
throw new Error("no exec");
|
|
10761
|
+
const out = await this.io.exec("herdr", args, { cwd: this.io.cwd, timeoutMs });
|
|
10762
|
+
code = out.code;
|
|
10763
|
+
if (code === 0 && !out.stdout.trim() && !out.stderr.trim() && ["pane run", "pane report-agent"].includes(operation))
|
|
10764
|
+
return {};
|
|
10765
|
+
reply = object(JSON.parse(out.stdout || out.stderr));
|
|
10766
|
+
} catch {
|
|
10767
|
+
throw new UsageError(`herdr ${operation} failed; inspect the runtime with herdr agent list`);
|
|
10768
|
+
}
|
|
10769
|
+
const error = object(reply?.error);
|
|
10770
|
+
if (code !== 0 || error) {
|
|
10771
|
+
const reason = typeof error?.code === "string" && /^[a-z_]{1,64}$/.test(error.code) ? ` (${error.code})` : "";
|
|
10772
|
+
throw new HerdrError(`herdr ${operation} failed${reason}; inspect the runtime with herdr agent list`, reason ? String(error?.code) : null);
|
|
10773
|
+
}
|
|
10774
|
+
if (!reply)
|
|
10775
|
+
throw new UsageError(`herdr ${operation} returned invalid JSON`);
|
|
10776
|
+
return reply;
|
|
10777
|
+
}
|
|
10778
|
+
async ensureServer() {
|
|
10779
|
+
const status = async (timeoutMs) => {
|
|
10780
|
+
const server = object((await this.call(["status", "--json"], timeoutMs)).server);
|
|
10781
|
+
if (!server || typeof server.running !== "boolean")
|
|
10782
|
+
throw new UsageError("invalid herdr server status response");
|
|
10783
|
+
if (server.running && (server.compatible === false || server.endpoint_compatible === false))
|
|
10784
|
+
throw new UsageError("the running herdr server is incompatible; update or restart it before launching");
|
|
10785
|
+
return server.running;
|
|
10786
|
+
};
|
|
10787
|
+
if (await status(5000))
|
|
10788
|
+
return;
|
|
10789
|
+
if (!this.io.detach || !await this.io.detach("herdr", ["server"], { cwd: this.io.cwd, env: runtimeEnvironment(this.io.env) }))
|
|
10790
|
+
throw new UsageError("could not start herdr server; start it headless with herdr server");
|
|
10791
|
+
const now = this.io.now ?? (() => new Date);
|
|
10792
|
+
const deadline = now().getTime() + 5000;
|
|
10793
|
+
for (let attempt = 0;attempt < 20; attempt++) {
|
|
10794
|
+
const remaining = deadline - now().getTime();
|
|
10795
|
+
if (remaining <= 0)
|
|
10796
|
+
break;
|
|
10797
|
+
if (await status(Math.min(1000, remaining)))
|
|
10798
|
+
return;
|
|
10799
|
+
const delay = Math.min(250, deadline - now().getTime());
|
|
10800
|
+
if (delay > 0)
|
|
10801
|
+
await (this.io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))))(delay);
|
|
10802
|
+
}
|
|
10803
|
+
throw new UsageError("herdr server did not become ready; inspect herdr status");
|
|
10804
|
+
}
|
|
10805
|
+
async create(input) {
|
|
10806
|
+
const agent = input.ticket.toLowerCase();
|
|
10807
|
+
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(agent))
|
|
10808
|
+
throw new UsageError("ticket cannot be used as a herdr agent name");
|
|
10809
|
+
const r = object((await this.call([
|
|
10810
|
+
"worktree",
|
|
10811
|
+
"create",
|
|
10812
|
+
"--cwd",
|
|
10813
|
+
input.repo,
|
|
10814
|
+
"--branch",
|
|
10815
|
+
input.branch,
|
|
10816
|
+
"--base",
|
|
10817
|
+
input.base,
|
|
10818
|
+
"--no-focus"
|
|
10819
|
+
])).result);
|
|
10820
|
+
const workspace = object(r?.workspace)?.workspace_id;
|
|
10821
|
+
const rootPane = object(r?.root_pane)?.pane_id;
|
|
10822
|
+
const path = object(r?.worktree)?.path;
|
|
10823
|
+
if (!id(workspace) || !id(rootPane) || typeof path !== "string" || !path.startsWith("/") || object(r?.root_pane)?.workspace_id !== workspace)
|
|
10824
|
+
throw new UsageError("invalid herdr worktree response; inspect herdr worktree list before retrying");
|
|
10825
|
+
const tab = object((await this.call([
|
|
10826
|
+
"tab",
|
|
10827
|
+
"create",
|
|
10828
|
+
"--workspace",
|
|
10829
|
+
workspace,
|
|
10830
|
+
"--cwd",
|
|
10831
|
+
path,
|
|
10832
|
+
"--no-focus",
|
|
10833
|
+
...credentialNames(this.io.env, input.secrets ?? []).flatMap((name) => ["--env", `${name}=`]),
|
|
10834
|
+
"--env",
|
|
10835
|
+
`ARMADA_TICKET=${input.ticket}`
|
|
10836
|
+
])).result);
|
|
10837
|
+
const pane = object(tab?.root_pane)?.pane_id;
|
|
10838
|
+
if (!id(pane) || pane === rootPane || object(tab?.root_pane)?.workspace_id !== workspace)
|
|
10839
|
+
throw new UsageError("invalid herdr worker pane response; inspect herdr pane list before retrying");
|
|
10840
|
+
await this.call(["pane", "close", rootPane]);
|
|
10841
|
+
return { workspace, pane, agent, path };
|
|
10842
|
+
}
|
|
10843
|
+
async start(handle, profile) {
|
|
10844
|
+
const r = await this.call([
|
|
10845
|
+
"agent",
|
|
10846
|
+
"start",
|
|
10847
|
+
handle.agent,
|
|
10848
|
+
"--kind",
|
|
10849
|
+
herdrHarnessKind(profile.harness),
|
|
10850
|
+
"--pane",
|
|
10851
|
+
handle.pane,
|
|
10852
|
+
"--timeout",
|
|
10853
|
+
"30000",
|
|
10854
|
+
"--",
|
|
10855
|
+
...harnessArgs(profile)
|
|
10856
|
+
]);
|
|
10857
|
+
this.checkAgent(r, handle);
|
|
10858
|
+
}
|
|
10859
|
+
async prompt(handle, prompt) {
|
|
10860
|
+
const r = await this.call([
|
|
10861
|
+
"agent",
|
|
10862
|
+
"prompt",
|
|
10863
|
+
handle.agent,
|
|
10864
|
+
prompt,
|
|
10865
|
+
"--wait",
|
|
10866
|
+
"--until",
|
|
10867
|
+
"working",
|
|
10868
|
+
"--timeout",
|
|
10869
|
+
"30000"
|
|
10870
|
+
]);
|
|
10871
|
+
const agent = this.checkAgent(r, handle);
|
|
10872
|
+
if (agent.agent_status !== "working")
|
|
10873
|
+
throw new UsageError("herdr did not confirm the worker is working");
|
|
10874
|
+
}
|
|
10875
|
+
async state(handle) {
|
|
10876
|
+
return (await this.reading(handle)).state;
|
|
10877
|
+
}
|
|
10878
|
+
async reading(handle) {
|
|
10879
|
+
const agent = this.checkAgent(await this.call(["agent", "get", handle.pane], 5000), handle);
|
|
10880
|
+
const state = agent.agent_status;
|
|
10881
|
+
if (!["working", "blocked", "idle", "done", "unknown"].includes(String(state)))
|
|
10882
|
+
throw new UsageError("invalid herdr agent state");
|
|
10883
|
+
const sequence = agent.state_change_seq;
|
|
10884
|
+
if (sequence !== undefined && (!Number.isSafeInteger(sequence) || Number(sequence) < 0))
|
|
10885
|
+
throw new UsageError("invalid herdr state-change sequence");
|
|
10886
|
+
return { state, ...sequence === undefined ? {} : { sequence: Number(sequence) } };
|
|
10887
|
+
}
|
|
10888
|
+
async message(handle, text) {
|
|
10889
|
+
const state = await this.state(handle);
|
|
10890
|
+
if (state === "blocked")
|
|
10891
|
+
await this.call(["pane", "run", handle.pane, text]);
|
|
10892
|
+
else
|
|
10893
|
+
this.checkAgent(await this.call(["agent", "prompt", handle.pane, text]), handle);
|
|
10894
|
+
}
|
|
10895
|
+
async quiesce(handle) {
|
|
10896
|
+
const state = await this.state(handle);
|
|
10897
|
+
if (state === "idle" || state === "done")
|
|
10898
|
+
return;
|
|
10899
|
+
if (state === "unknown")
|
|
10900
|
+
throw new UsageError("cannot stop an unverified active turn; wait for herdr idle state");
|
|
10901
|
+
await this.call(["agent", "send-keys", handle.pane, "ctrl+c"], 5000);
|
|
10902
|
+
const agent = this.checkAgent(await this.call(["agent", "wait", handle.pane, "--until", "idle", "--until", "done", "--timeout", "5000"], 7000), handle);
|
|
10903
|
+
if (agent.agent_status !== "idle" && agent.agent_status !== "done")
|
|
10904
|
+
throw new UsageError("worker is still active; its worktree was retained");
|
|
10905
|
+
}
|
|
10906
|
+
async report(pane, agent, state, heartbeat = false) {
|
|
10907
|
+
if (agent === "armada" || heartbeat) {
|
|
10908
|
+
const current = object(object((await this.call(["pane", "get", pane], 5000)).result)?.pane);
|
|
10909
|
+
if (current?.pane_id !== pane)
|
|
10910
|
+
throw new UsageError("invalid herdr pane response");
|
|
10911
|
+
if (agent === "armada" && typeof current.agent === "string" && current.agent)
|
|
10912
|
+
agent = current.agent;
|
|
10913
|
+
if (heartbeat && state === "working" && current.agent_status === "blocked")
|
|
10914
|
+
state = "blocked";
|
|
10915
|
+
}
|
|
10916
|
+
if (agent === "deepseek" || agent === herdrHarnessLabel("deepseek"))
|
|
10917
|
+
agent = herdrHarnessKind("deepseek");
|
|
10918
|
+
await this.call(["pane", "report-agent", pane, "--source", "armada", "--agent", agent, "--state", state], 5000);
|
|
10919
|
+
}
|
|
10920
|
+
async worktree(handle) {
|
|
10921
|
+
const ws = object(object((await this.call(["workspace", "get", handle.workspace], 5000)).result)?.workspace);
|
|
10922
|
+
const tree = object(ws?.worktree);
|
|
10923
|
+
if (ws?.workspace_id !== handle.workspace || tree?.is_linked_worktree !== true || typeof tree.repo_root !== "string" || !tree.repo_root.startsWith("/") || typeof tree.checkout_path !== "string" || !tree.checkout_path.startsWith("/") || tree.repo_root === tree.checkout_path)
|
|
10924
|
+
throw new UsageError("herdr workspace is not a verified linked worktree; left it untouched");
|
|
10925
|
+
return { repo: tree.repo_root, path: tree.checkout_path };
|
|
10926
|
+
}
|
|
10927
|
+
async remove(handle, path) {
|
|
10928
|
+
const result = object((await this.call(["worktree", "remove", "--workspace", handle.workspace])).result);
|
|
10929
|
+
if (result?.workspace_id !== handle.workspace || result?.path !== path || result?.forced !== false)
|
|
10930
|
+
throw new UsageError("invalid herdr worktree removal response; inspect herdr worktree list before retrying");
|
|
10931
|
+
}
|
|
10932
|
+
checkAgent(reply, handle) {
|
|
10933
|
+
const agent = object(object(reply.result)?.agent);
|
|
10934
|
+
if (!agent || agent.name !== handle.agent || agent.pane_id !== handle.pane || agent.workspace_id !== handle.workspace)
|
|
10935
|
+
throw new UsageError("invalid herdr agent response; inspect herdr agent list before retrying");
|
|
10936
|
+
return agent;
|
|
10937
|
+
}
|
|
10938
|
+
}
|
|
10939
|
+
|
|
10940
|
+
// src/runtime.ts
|
|
10941
|
+
var isHerdr = (runtime) => runtime.toLowerCase() === "herdr";
|
|
10942
|
+
async function observeHerdr(io, fleet) {
|
|
10943
|
+
const handles = await fleet.runtimeHandles();
|
|
10944
|
+
const local = handles.filter((h) => isHerdr(h.runtime));
|
|
10945
|
+
if (!local.length)
|
|
10946
|
+
return handles;
|
|
10947
|
+
await Promise.all(local.map(async (h) => {
|
|
10948
|
+
try {
|
|
10949
|
+
await verifyProvenance(io, h);
|
|
10950
|
+
const reading = await new Herdr(io).reading(parseHerdrHandle(h.handle));
|
|
10951
|
+
await fleet.observeRuntime({ ticket: h.ticket, handle: h.handle, claimedAt: h.claimedAt, ...reading });
|
|
10952
|
+
} catch {}
|
|
10953
|
+
}));
|
|
10954
|
+
return fleet.runtimeHandles();
|
|
10955
|
+
}
|
|
10956
|
+
function observingFleet(io, fleet) {
|
|
10957
|
+
return {
|
|
10958
|
+
...fleet,
|
|
10959
|
+
inbox: async (query) => {
|
|
10960
|
+
try {
|
|
10961
|
+
await observeHerdr(io, fleet);
|
|
10962
|
+
} catch {}
|
|
10963
|
+
return fleet.inbox(query);
|
|
10964
|
+
}
|
|
10965
|
+
};
|
|
10966
|
+
}
|
|
10967
|
+
async function deliverHerdr(io, fleet, ticket, text, expected) {
|
|
10968
|
+
const h = await fleet.runtimeHandle(ticket);
|
|
10969
|
+
if (!h || !isHerdr(h.runtime))
|
|
10970
|
+
return false;
|
|
10971
|
+
if (!expected || h.handle !== expected.handle || h.claimedAt !== expected.claimedAt)
|
|
10972
|
+
throw new Refusal(`${ticket}'s claim changed before delivery; no answer was delivered`, "armada inbox");
|
|
10973
|
+
if (h.releasedAt)
|
|
10974
|
+
throw new Refusal(`${ticket}'s herdr worker has ended; no answer was delivered`, "armada status");
|
|
10975
|
+
await verifyProvenance(io, h);
|
|
10976
|
+
const current = await fleet.runtimeHandle(ticket);
|
|
10977
|
+
if (!current || current.handle !== h.handle || current.claimedAt !== h.claimedAt || current.releasedAt)
|
|
10978
|
+
throw new Refusal(`${ticket}'s claim changed before delivery; no answer was delivered`, "armada inbox");
|
|
10979
|
+
await new Herdr(io).message(parseHerdrHandle(h.handle), text);
|
|
10980
|
+
return true;
|
|
10981
|
+
}
|
|
10982
|
+
async function verifyProvenance(io, h) {
|
|
10983
|
+
const tree = await new Herdr(io).worktree(parseHerdrHandle(h.handle));
|
|
10984
|
+
const git = async (cwd, args) => {
|
|
10985
|
+
const result = await io.exec?.("git", args, { cwd, timeoutMs: 5000 });
|
|
10986
|
+
if (result?.code !== 0)
|
|
10987
|
+
throw new Refusal("could not verify the herdr claim repository", "armada status");
|
|
10988
|
+
return result.stdout.trim();
|
|
10989
|
+
};
|
|
10990
|
+
const commonArgs = ["rev-parse", "--path-format=absolute", "--git-common-dir"];
|
|
10991
|
+
const local = await git(io.cwd, commonArgs);
|
|
10992
|
+
const worker = await git(tree.path, commonArgs);
|
|
10993
|
+
if (!local || local !== worker || !h.branch || await git(tree.path, ["branch", "--show-current"]) !== h.branch)
|
|
10994
|
+
throw new Refusal("herdr workspace does not match the claimed repository and branch", "armada status");
|
|
10995
|
+
}
|
|
10996
|
+
async function stop(io, config, credentials, args) {
|
|
10997
|
+
const [raw, ...extra] = args.rest;
|
|
10998
|
+
if (!raw || extra.length)
|
|
10999
|
+
throw new Refusal("stop needs one ticket: armada stop <ticket>", "armada stop --help");
|
|
11000
|
+
requireSignIn(credentials);
|
|
11001
|
+
const { fleet } = liveFleet(io, config, credentials);
|
|
11002
|
+
if (!fleet)
|
|
11003
|
+
throw new Refusal("stop needs Armada's stored claim", "armada whoami");
|
|
11004
|
+
const ticket = raw.toUpperCase();
|
|
11005
|
+
const h = await fleet.runtimeHandle(ticket);
|
|
11006
|
+
if (!h || !isHerdr(h.runtime))
|
|
11007
|
+
throw new Refusal(`${ticket} has no herdr claim to stop`, "armada status");
|
|
11008
|
+
const handle = parseHerdrHandle(h.handle);
|
|
11009
|
+
const runtime = new Herdr(io);
|
|
11010
|
+
let tree;
|
|
11011
|
+
try {
|
|
11012
|
+
tree = await runtime.worktree(handle);
|
|
11013
|
+
} catch (error) {
|
|
11014
|
+
if (!(error instanceof HerdrError) || error.code !== "workspace_not_found")
|
|
11015
|
+
throw error;
|
|
11016
|
+
if (!await fleet.stopRuntime({ ticket, handle: h.handle, claimedAt: h.claimedAt }))
|
|
11017
|
+
throw new Refusal("claim changed during archive recovery", "armada status");
|
|
11018
|
+
io.stdout(args.json ? `${JSON.stringify({ ticket, stopped: true, alreadyAbsent: true })}
|
|
11019
|
+
` : `${ticket}'s herdr workspace is already absent; its claim is ended.
|
|
11020
|
+
`);
|
|
11021
|
+
return 0;
|
|
11022
|
+
}
|
|
11023
|
+
const git = async (cwd, argv) => {
|
|
11024
|
+
const r = await io.exec?.("git", argv, { cwd, timeoutMs: 30000 });
|
|
11025
|
+
if (r?.code !== 0)
|
|
11026
|
+
throw new Refusal("could not verify the worker's Git state; left its worktree untouched", `git -C ${tree.path} status`);
|
|
11027
|
+
return r.stdout.trim();
|
|
11028
|
+
};
|
|
11029
|
+
const localCommon = await git(io.cwd, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
11030
|
+
const treeCommon = await git(tree.path, ["rev-parse", "--path-format=absolute", "--git-common-dir"]);
|
|
11031
|
+
const branch = await git(tree.path, ["branch", "--show-current"]);
|
|
11032
|
+
if (localCommon !== treeCommon || !h.branch || branch !== h.branch)
|
|
11033
|
+
throw new Refusal("herdr worktree does not match this repository and claim branch; left it untouched", "herdr worktree list");
|
|
11034
|
+
const dirty = await git(tree.path, ["status", "--porcelain=v1", "--untracked-files=all"]);
|
|
11035
|
+
if (dirty)
|
|
11036
|
+
throw new Refusal(`cannot stop ${ticket}: uncommitted work remains:
|
|
11037
|
+
${dirty}`, `git -C ${tree.path} status`);
|
|
11038
|
+
const upstream = await git(tree.path, [
|
|
11039
|
+
"for-each-ref",
|
|
11040
|
+
"--format=%(upstream:remotename)%00%(upstream:remoteref)",
|
|
11041
|
+
`refs/heads/${branch}`
|
|
11042
|
+
]);
|
|
11043
|
+
const [remote, ref] = upstream.split("\x00");
|
|
11044
|
+
if (!remote || remote === "." || remote.startsWith("-") || !ref?.startsWith("refs/heads/"))
|
|
11045
|
+
throw new Refusal(`cannot stop ${ticket}: the branch has no verified remote upstream`, `git -C ${tree.path} push -u origin ${branch}`);
|
|
11046
|
+
const advertised = await git(tree.path, ["ls-remote", "--exit-code", "--heads", "--", remote, ref]);
|
|
11047
|
+
const [remoteHead, remoteRef] = advertised.split("\t");
|
|
11048
|
+
if (!/^[a-f0-9]{40,64}$/.test(remoteHead ?? "") || remoteRef !== ref)
|
|
11049
|
+
throw new Refusal(`cannot stop ${ticket}: could not verify the upstream head`, `git -C ${tree.path} fetch`);
|
|
11050
|
+
await git(tree.path, ["fetch", "--no-tags", "--no-write-fetch-head", "--", remote, ref]);
|
|
11051
|
+
const localHead = await git(tree.path, ["rev-parse", "HEAD"]);
|
|
11052
|
+
const left = await git(tree.path, ["log", "--format=%h %s", `${remoteHead}..${localHead}`]);
|
|
11053
|
+
if (left)
|
|
11054
|
+
throw new Refusal(`cannot stop ${ticket}: unpushed commits remain:
|
|
11055
|
+
${left}`, `git -C ${tree.path} push`);
|
|
11056
|
+
await runtime.quiesce(handle);
|
|
11057
|
+
if (await git(tree.path, ["status", "--porcelain=v1", "--untracked-files=all"]))
|
|
11058
|
+
throw new Refusal(`cannot stop ${ticket}: the worktree changed during verification`, `git -C ${tree.path} status`);
|
|
11059
|
+
const current = await fleet.runtimeHandle(ticket);
|
|
11060
|
+
if (!current || current.handle !== h.handle || current.claimedAt !== h.claimedAt)
|
|
11061
|
+
throw new Refusal(`${ticket}'s claim changed; left the runtime untouched`, "armada status");
|
|
11062
|
+
const state = await runtime.state(handle);
|
|
11063
|
+
if (state !== "idle" && state !== "done")
|
|
11064
|
+
throw new Refusal("worker resumed during stop; left its worktree untouched", "armada status");
|
|
11065
|
+
if (await git(tree.path, ["rev-parse", "HEAD"]) !== localHead)
|
|
11066
|
+
throw new Refusal(`cannot stop ${ticket}: new commits appeared during verification`, `git -C ${tree.path} status`);
|
|
11067
|
+
await runtime.remove(handle, tree.path);
|
|
11068
|
+
if (!await fleet.stopRuntime({ ticket, handle: h.handle, claimedAt: h.claimedAt }))
|
|
11069
|
+
throw new Refusal("worktree removed, but claim changed during cleanup; inspect the new claim", "armada status");
|
|
11070
|
+
const result = { ticket, path: tree.path, stopped: true };
|
|
11071
|
+
io.stdout(args.json ? `${JSON.stringify(result, null, 2)}
|
|
11072
|
+
` : `Stopped ${ticket} and removed ${tree.path}; its branch is retained.
|
|
11073
|
+
`);
|
|
11074
|
+
return 0;
|
|
11075
|
+
}
|
|
11076
|
+
|
|
10633
11077
|
// src/worker.ts
|
|
10634
11078
|
function liveFleet(io, config, credentials) {
|
|
10635
11079
|
const signIn = credentials.armadaSignIn;
|
|
@@ -10653,7 +11097,8 @@ function statusLive(io, config, credentials) {
|
|
|
10653
11097
|
return fleet ? {
|
|
10654
11098
|
lastEvents: () => fleet.lastEventTimes(),
|
|
10655
11099
|
heartbeats: () => fleet.heartbeatTimes(),
|
|
10656
|
-
launches: () => fleet.pendingLaunches()
|
|
11100
|
+
launches: () => fleet.pendingLaunches(),
|
|
11101
|
+
runtimeHandles: () => observeHerdr(io, fleet)
|
|
10657
11102
|
} : undefined;
|
|
10658
11103
|
}
|
|
10659
11104
|
function currentTicket(io, config, explicit, workers = []) {
|
|
@@ -10733,7 +11178,13 @@ async function readMessage(io, options, name = "message") {
|
|
|
10733
11178
|
return text;
|
|
10734
11179
|
}
|
|
10735
11180
|
async function withContext(io, config, credentials, json, act) {
|
|
10736
|
-
|
|
11181
|
+
const outcome = await act(context(io, config, credentials));
|
|
11182
|
+
if (outcome.state?.phase) {
|
|
11183
|
+
const profile = outcome.state.profile;
|
|
11184
|
+
const agent = profile ? config.herdr.profiles[profile]?.harness : null;
|
|
11185
|
+
await reportHerdr(io, outcome.state.phase, agent ?? "armada");
|
|
11186
|
+
}
|
|
11187
|
+
print(io, outcome, json);
|
|
10737
11188
|
return 0;
|
|
10738
11189
|
}
|
|
10739
11190
|
async function claim(io, config, credentials, a) {
|
|
@@ -10896,7 +11347,23 @@ async function answer(io, config, credentials, a) {
|
|
|
10896
11347
|
const text = positional ?? fromOption;
|
|
10897
11348
|
if (!text?.trim())
|
|
10898
11349
|
throw new UsageError(`answer needs the text: ${usage}`);
|
|
10899
|
-
return withContext(io, config, credentials, a.json, (ctx) => answerItem(
|
|
11350
|
+
return withContext(io, config, credentials, a.json, (ctx) => answerItem({
|
|
11351
|
+
...ctx,
|
|
11352
|
+
deliverAnswer: async (ticket, message, runtime, claim) => {
|
|
11353
|
+
if (runtime && runtime.toLowerCase() !== "herdr")
|
|
11354
|
+
return false;
|
|
11355
|
+
const { fleet } = liveFleet(io, config, credentials);
|
|
11356
|
+
if (!fleet) {
|
|
11357
|
+
if (runtime?.toLowerCase() === "herdr")
|
|
11358
|
+
throw new Refusal("cannot read the herdr claim before delivery", "armada whoami");
|
|
11359
|
+
return false;
|
|
11360
|
+
}
|
|
11361
|
+
const delivered = await deliverHerdr(io, fleet, ticket, message, claim);
|
|
11362
|
+
if (!delivered && runtime?.toLowerCase() === "herdr")
|
|
11363
|
+
throw new Refusal("the herdr claim is missing or changed; no answer was delivered", "armada status");
|
|
11364
|
+
return delivered;
|
|
11365
|
+
}
|
|
11366
|
+
}, { target, text, note }));
|
|
10900
11367
|
}
|
|
10901
11368
|
function waitSeconds(raw) {
|
|
10902
11369
|
if (raw === undefined)
|
|
@@ -10925,10 +11392,12 @@ function renderEntries(project, items) {
|
|
|
10925
11392
|
if (e.kind === "hand-back" && !/shipped with (?:ship-pr-dev|the fallback:)|shipping path unreported/.test(e.body))
|
|
10926
11393
|
out.push(" shipping path unreported");
|
|
10927
11394
|
}
|
|
11395
|
+
if (items.some((e) => e.kind === "runtime-blocked"))
|
|
11396
|
+
out.push('Read the blocked herdr pane with its runtime guide, then answer: armada answer <ticket> "<answer>".');
|
|
10928
11397
|
if (items.some((e) => e.kind === "question" || e.kind === "plan"))
|
|
10929
|
-
out.push(`Deliver each answer in the worker's session with the runtime guide, then record it: armada answer <id> "<answer>".`);
|
|
11398
|
+
out.push(`For herdr, armada answer delivers automatically. Deliver each other answer in the worker's session with the runtime guide, then record it: armada answer <id> "<answer>".`);
|
|
10930
11399
|
if (items.some((e) => ["answer-request", "launch-request", "merge-request", "release-request", "plan-changes"].includes(e.kind)))
|
|
10931
|
-
out.push('Dashboard requests:
|
|
11400
|
+
out.push('Dashboard requests: armada answer <id> "<answer>" delivers herdr answer-requests automatically; deliver answers for other runtimes first; launch a launch-request (its claim resolves it), or decline it with armada answer <id> "<why>". Handle or decline merge-request, release-request and plan-changes, then resolve them with armada answer <id> "<result>". Plan changes are not an approval.');
|
|
10932
11401
|
return out;
|
|
10933
11402
|
}
|
|
10934
11403
|
function renderInbox(r, next) {
|
|
@@ -10953,7 +11422,7 @@ async function inbox(io, config, credentials, a) {
|
|
|
10953
11422
|
const { fleet, warning } = liveFleet(io, config, credentials);
|
|
10954
11423
|
if (!fleet)
|
|
10955
11424
|
throw new Refusal(`the inbox is on Armada, which cannot be reached: ${warning ?? "no answer"}`, "armada whoami");
|
|
10956
|
-
const report = await checkInbox(fleet, {
|
|
11425
|
+
const report = await checkInbox(observingFleet(io, fleet), {
|
|
10957
11426
|
project: config.project.slug,
|
|
10958
11427
|
coordinator: coordinatorHandle(io),
|
|
10959
11428
|
facts: detectCoordinator(io),
|
|
@@ -11153,7 +11622,7 @@ async function watchUntil(io, config, credentials, json, configPath) {
|
|
|
11153
11622
|
throw new Refusal(`the inbox is on Armada, which cannot be reached: ${warning ?? "no answer"}`, "armada whoami");
|
|
11154
11623
|
const before = paths ? await readWatchState(paths, project) : null;
|
|
11155
11624
|
await remember(io, project, { root: dirname2(configPath), stopped: null });
|
|
11156
|
-
const report = await watchInbox(fleet, {
|
|
11625
|
+
const report = await watchInbox(observingFleet(watchingIo, fleet), {
|
|
11157
11626
|
project,
|
|
11158
11627
|
signal: controller.signal,
|
|
11159
11628
|
coordinator: coordinatorHandle(io),
|
|
@@ -12176,7 +12645,12 @@ async function heartbeat(io, config, credentials, args) {
|
|
|
12176
12645
|
now: io.now ?? (() => new Date),
|
|
12177
12646
|
sleep: io.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))),
|
|
12178
12647
|
parentAlive: alive,
|
|
12179
|
-
ping: (input) =>
|
|
12648
|
+
ping: async (input) => {
|
|
12649
|
+
const result = await fleet.heartbeat(input);
|
|
12650
|
+
if (result.active)
|
|
12651
|
+
await reportHerdr(io, result.phase, result.agent ?? "armada", true);
|
|
12652
|
+
return result;
|
|
12653
|
+
},
|
|
12180
12654
|
ready: async (session) => {
|
|
12181
12655
|
const name = `${config.project.slug}-heartbeat-${ticket.toLowerCase()}-${createHash3("sha256").update(`${handle}/${session.claimedAt}`).digest("hex").slice(0, 12)}`;
|
|
12182
12656
|
const acquired = await takeWatchLock(paths, name, pid, io.processAlive ?? processAlive);
|
|
@@ -12412,166 +12886,6 @@ async function init(io, opts) {
|
|
|
12412
12886
|
|
|
12413
12887
|
// src/launch.ts
|
|
12414
12888
|
import { dirname as dirname5, join as join6 } from "node:path";
|
|
12415
|
-
|
|
12416
|
-
// src/herdr.ts
|
|
12417
|
-
var harnessArgs = (p) => [
|
|
12418
|
-
"--model",
|
|
12419
|
-
herdrHarnessKind(p.harness) === "opencode" ? `${p.model.split("#")[0]}#${p.effort}` : p.model,
|
|
12420
|
-
...p.harness === "codex" ? ["-c", `model_reasoning_effort=${JSON.stringify(p.effort)}`] : p.harness === "claude" ? ["--effort", p.effort] : [],
|
|
12421
|
-
...p.extraArgs
|
|
12422
|
-
];
|
|
12423
|
-
var object = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : null;
|
|
12424
|
-
var id = (v) => typeof v === "string" && /^[a-zA-Z0-9:_-]{1,128}$/.test(v);
|
|
12425
|
-
var runtimeEnvironment = (env) => Object.fromEntries(Object.entries(env).filter(([name]) => /^(PATH|HOME|USER|LOGNAME|SHELL|TMPDIR|TMP|TEMP|LANG|TERM|LC_[A-Z_]+|XDG_(CONFIG_HOME|DATA_HOME|STATE_HOME|CACHE_HOME|RUNTIME_DIR)|HERDR_(SESSION|SOCKET_PATH|CONFIG_PATH))$/.test(name)));
|
|
12426
|
-
var credentialNames = (env, extra) => [
|
|
12427
|
-
...new Set([
|
|
12428
|
-
"LINEAR_API_KEY",
|
|
12429
|
-
"GITHUB_TOKEN",
|
|
12430
|
-
"GH_TOKEN",
|
|
12431
|
-
"ARMADA_API_KEY",
|
|
12432
|
-
"ARMADA_SESSION_TOKEN",
|
|
12433
|
-
"ARMADA_SIGNED_IN_TO",
|
|
12434
|
-
"ARMADA_API_URL",
|
|
12435
|
-
"OPENAI_API_KEY",
|
|
12436
|
-
"ANTHROPIC_API_KEY",
|
|
12437
|
-
...Object.keys(env).filter((name) => /^(ARMADA_|CONDUCTOR_)|(?:KEY|TOKEN|SECRET|PASSWORD)$/.test(name)),
|
|
12438
|
-
...extra
|
|
12439
|
-
])
|
|
12440
|
-
].filter((name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)).sort();
|
|
12441
|
-
|
|
12442
|
-
class Herdr {
|
|
12443
|
-
io;
|
|
12444
|
-
constructor(io) {
|
|
12445
|
-
this.io = io;
|
|
12446
|
-
}
|
|
12447
|
-
async call(args, timeoutMs = 40000) {
|
|
12448
|
-
const operation = args.slice(0, 2).join(" ");
|
|
12449
|
-
let reply;
|
|
12450
|
-
let code;
|
|
12451
|
-
try {
|
|
12452
|
-
if (!this.io.exec)
|
|
12453
|
-
throw new Error("no exec");
|
|
12454
|
-
const out = await this.io.exec("herdr", args, { cwd: this.io.cwd, timeoutMs });
|
|
12455
|
-
code = out.code;
|
|
12456
|
-
reply = object(JSON.parse(out.stdout || out.stderr));
|
|
12457
|
-
} catch {
|
|
12458
|
-
throw new UsageError(`herdr ${operation} failed; inspect the runtime with herdr agent list`);
|
|
12459
|
-
}
|
|
12460
|
-
const error = object(reply?.error);
|
|
12461
|
-
if (code !== 0 || error) {
|
|
12462
|
-
const reason = typeof error?.code === "string" && /^[a-z_]{1,64}$/.test(error.code) ? ` (${error.code})` : "";
|
|
12463
|
-
throw new UsageError(`herdr ${operation} failed${reason}; inspect the runtime with herdr agent list`);
|
|
12464
|
-
}
|
|
12465
|
-
if (!reply)
|
|
12466
|
-
throw new UsageError(`herdr ${operation} returned invalid JSON`);
|
|
12467
|
-
return reply;
|
|
12468
|
-
}
|
|
12469
|
-
async ensureServer() {
|
|
12470
|
-
const status = async (timeoutMs) => {
|
|
12471
|
-
const server = object((await this.call(["status", "--json"], timeoutMs)).server);
|
|
12472
|
-
if (!server || typeof server.running !== "boolean")
|
|
12473
|
-
throw new UsageError("invalid herdr server status response");
|
|
12474
|
-
if (server.running && (server.compatible === false || server.endpoint_compatible === false))
|
|
12475
|
-
throw new UsageError("the running herdr server is incompatible; update or restart it before launching");
|
|
12476
|
-
return server.running;
|
|
12477
|
-
};
|
|
12478
|
-
if (await status(5000))
|
|
12479
|
-
return;
|
|
12480
|
-
if (!this.io.detach || !await this.io.detach("herdr", ["server"], { cwd: this.io.cwd, env: runtimeEnvironment(this.io.env) }))
|
|
12481
|
-
throw new UsageError("could not start herdr server; start it headless with herdr server");
|
|
12482
|
-
const now = this.io.now ?? (() => new Date);
|
|
12483
|
-
const deadline = now().getTime() + 5000;
|
|
12484
|
-
for (let attempt = 0;attempt < 20; attempt++) {
|
|
12485
|
-
const remaining = deadline - now().getTime();
|
|
12486
|
-
if (remaining <= 0)
|
|
12487
|
-
break;
|
|
12488
|
-
if (await status(Math.min(1000, remaining)))
|
|
12489
|
-
return;
|
|
12490
|
-
const delay = Math.min(250, deadline - now().getTime());
|
|
12491
|
-
if (delay > 0)
|
|
12492
|
-
await (this.io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))))(delay);
|
|
12493
|
-
}
|
|
12494
|
-
throw new UsageError("herdr server did not become ready; inspect herdr status");
|
|
12495
|
-
}
|
|
12496
|
-
async create(input) {
|
|
12497
|
-
const agent = input.ticket.toLowerCase();
|
|
12498
|
-
if (!/^[a-z][a-z0-9_-]{0,31}$/.test(agent))
|
|
12499
|
-
throw new UsageError("ticket cannot be used as a herdr agent name");
|
|
12500
|
-
const r = object((await this.call([
|
|
12501
|
-
"worktree",
|
|
12502
|
-
"create",
|
|
12503
|
-
"--cwd",
|
|
12504
|
-
input.repo,
|
|
12505
|
-
"--branch",
|
|
12506
|
-
input.branch,
|
|
12507
|
-
"--base",
|
|
12508
|
-
input.base,
|
|
12509
|
-
"--no-focus"
|
|
12510
|
-
])).result);
|
|
12511
|
-
const workspace = object(r?.workspace)?.workspace_id;
|
|
12512
|
-
const rootPane = object(r?.root_pane)?.pane_id;
|
|
12513
|
-
const path = object(r?.worktree)?.path;
|
|
12514
|
-
if (!id(workspace) || !id(rootPane) || typeof path !== "string" || !path.startsWith("/") || object(r?.root_pane)?.workspace_id !== workspace)
|
|
12515
|
-
throw new UsageError("invalid herdr worktree response; inspect herdr worktree list before retrying");
|
|
12516
|
-
const tab = object((await this.call([
|
|
12517
|
-
"tab",
|
|
12518
|
-
"create",
|
|
12519
|
-
"--workspace",
|
|
12520
|
-
workspace,
|
|
12521
|
-
"--cwd",
|
|
12522
|
-
path,
|
|
12523
|
-
"--no-focus",
|
|
12524
|
-
...credentialNames(this.io.env, input.secrets ?? []).flatMap((name) => ["--env", `${name}=`]),
|
|
12525
|
-
"--env",
|
|
12526
|
-
`ARMADA_TICKET=${input.ticket}`
|
|
12527
|
-
])).result);
|
|
12528
|
-
const pane = object(tab?.root_pane)?.pane_id;
|
|
12529
|
-
if (!id(pane) || pane === rootPane || object(tab?.root_pane)?.workspace_id !== workspace)
|
|
12530
|
-
throw new UsageError("invalid herdr worker pane response; inspect herdr pane list before retrying");
|
|
12531
|
-
await this.call(["pane", "close", rootPane]);
|
|
12532
|
-
return { workspace, pane, agent, path };
|
|
12533
|
-
}
|
|
12534
|
-
async start(handle, profile) {
|
|
12535
|
-
const r = await this.call([
|
|
12536
|
-
"agent",
|
|
12537
|
-
"start",
|
|
12538
|
-
handle.agent,
|
|
12539
|
-
"--kind",
|
|
12540
|
-
herdrHarnessKind(profile.harness),
|
|
12541
|
-
"--pane",
|
|
12542
|
-
handle.pane,
|
|
12543
|
-
"--timeout",
|
|
12544
|
-
"30000",
|
|
12545
|
-
"--",
|
|
12546
|
-
...harnessArgs(profile)
|
|
12547
|
-
]);
|
|
12548
|
-
this.checkAgent(r, handle);
|
|
12549
|
-
}
|
|
12550
|
-
async prompt(handle, prompt) {
|
|
12551
|
-
const r = await this.call([
|
|
12552
|
-
"agent",
|
|
12553
|
-
"prompt",
|
|
12554
|
-
handle.agent,
|
|
12555
|
-
prompt,
|
|
12556
|
-
"--wait",
|
|
12557
|
-
"--until",
|
|
12558
|
-
"working",
|
|
12559
|
-
"--timeout",
|
|
12560
|
-
"30000"
|
|
12561
|
-
]);
|
|
12562
|
-
const agent = this.checkAgent(r, handle);
|
|
12563
|
-
if (agent.agent_status !== "working")
|
|
12564
|
-
throw new UsageError("herdr did not confirm the worker is working");
|
|
12565
|
-
}
|
|
12566
|
-
checkAgent(reply, handle) {
|
|
12567
|
-
const agent = object(object(reply.result)?.agent);
|
|
12568
|
-
if (!agent || agent.name !== handle.agent || agent.pane_id !== handle.pane || agent.workspace_id !== handle.workspace)
|
|
12569
|
-
throw new UsageError("invalid herdr agent response; inspect herdr agent list before retrying");
|
|
12570
|
-
return agent;
|
|
12571
|
-
}
|
|
12572
|
-
}
|
|
12573
|
-
|
|
12574
|
-
// src/launch.ts
|
|
12575
12889
|
async function launch(io, config, credentials, args, version, configPath) {
|
|
12576
12890
|
if (args.rest[0] !== "revoke")
|
|
12577
12891
|
return launchLocal(io, config, credentials, args, version, configPath);
|
|
@@ -13074,7 +13388,7 @@ function renderStatus(r) {
|
|
|
13074
13388
|
if (!r.inFlight.length)
|
|
13075
13389
|
out.push(" nobody is working");
|
|
13076
13390
|
for (const t of r.inFlight) {
|
|
13077
|
-
const who = [t.runtime, t.agent].filter(Boolean).join(" · ") || "unassigned";
|
|
13391
|
+
const who = [t.runtime, t.runtimeState && `live ${t.runtimeState}`, t.agent].filter(Boolean).join(" · ") || "unassigned";
|
|
13078
13392
|
out.push(` ${pad(t.id, idWidth)} ${pad(phaseLabel(t), phaseWidth)} ${who} · ${t.lastReport ? `reported ${relative2(t.lastReport, now)}` : `updated ${relative2(t.lastUpdate, now)}`}`);
|
|
13079
13393
|
out.push(`${indent}${truncate(t.title, 90)}${t.spec ? ` [${t.spec}]` : ""}`);
|
|
13080
13394
|
if (t.profile)
|
|
@@ -13610,12 +13924,15 @@ var COMMAND_HELP = {
|
|
|
13610
13924
|
this machine. Needs a sign-in to Armada
|
|
13611
13925
|
watch --stop Stop only this project's verified watch and release its lock. Local,
|
|
13612
13926
|
no sign-in needed. Never stop a watch just to read inbox or status
|
|
13927
|
+
`,
|
|
13928
|
+
stop: ` stop <ticket>
|
|
13929
|
+
Stop a herdr worker and archive its worktree only when clean and fully pushed
|
|
13613
13930
|
`,
|
|
13614
13931
|
answer: ` answer <item|ticket> "<answer>"
|
|
13615
|
-
Coordinator:
|
|
13616
|
-
|
|
13617
|
-
the ticket. A ticket id answers
|
|
13618
|
-
clear a merged/closed PR or a Done/Canceled ticket
|
|
13932
|
+
Coordinator: deliver to a herdr worker and record the answer. For other
|
|
13933
|
+
runtimes, deliver with the runtime guide first. Resolves the question or
|
|
13934
|
+
plan and posts it on the ticket. A ticket id also answers a live herdr block.
|
|
13935
|
+
A hand-back id can clear a merged/closed PR or a Done/Canceled ticket
|
|
13619
13936
|
answer --note <ticket|plan item> "<message>"
|
|
13620
13937
|
Coordinator: record a delivered note; an open plan is resolved
|
|
13621
13938
|
`,
|
|
@@ -13719,6 +14036,7 @@ var CONFIG_OPTION = new Set([
|
|
|
13719
14036
|
"inbox",
|
|
13720
14037
|
"watch",
|
|
13721
14038
|
"answer",
|
|
14039
|
+
"stop",
|
|
13722
14040
|
"merge",
|
|
13723
14041
|
"brief",
|
|
13724
14042
|
"launch"
|
|
@@ -14046,7 +14364,7 @@ async function dispatch(argv, io) {
|
|
|
14046
14364
|
});
|
|
14047
14365
|
return await heartbeat(io, config, credentials, args);
|
|
14048
14366
|
}
|
|
14049
|
-
const worker = { claim, report, release, ask, inbox, answer, validate, "ask-owner": askOwner, done }[args.command];
|
|
14367
|
+
const worker = { claim, report, release, ask, inbox, answer, stop, validate, "ask-owner": askOwner, done }[args.command];
|
|
14050
14368
|
if (worker) {
|
|
14051
14369
|
const { path, text } = await findConfig(io, args.config, args.command);
|
|
14052
14370
|
const config = parseConfig(text, path);
|