@the-vibe-company/armada 0.1.1 → 0.1.2
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 +32 -4
- package/dist/armada.js +1019 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Armada runs a fleet of coding agents on one project and keeps every piece of wor
|
|
|
4
4
|
|
|
5
5
|
It imposes one method: grill the decisions, write a spec, cut it into tickets, let one worker agent ship each ticket as a green pull request, and let a coordinator agent merge. The tracker is the source of truth for progress; Armada adds live telemetry, contention rules and a fleet dashboard on top.
|
|
6
6
|
|
|
7
|
-
**Status:** early. `armada status`, `armada auth`, `armada claim`, `armada report` and `armada release` work; the other commands are being built.
|
|
7
|
+
**Status:** early. `armada status`, `armada auth`, `armada doctor`, `armada init`, `armada claim`, `armada report` and `armada release` work; the other commands are being built.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -32,6 +32,33 @@ armada status # or: armada status --json
|
|
|
32
32
|
|
|
33
33
|
GitHub is read with `GITHUB_TOKEN`, `GH_TOKEN` or the GitHub CLI login (`gh auth token`). Without any of them the tickets are still shown.
|
|
34
34
|
|
|
35
|
+
## Set up a repository
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
armada doctor # what this repository lacks, with the fix for each
|
|
39
|
+
armada init --program-root ABC-1 # one pull request that adds it all
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`armada doctor` checks, in the repository you are in:
|
|
43
|
+
|
|
44
|
+
- `armada.toml` exists and is valid;
|
|
45
|
+
- the Armada skills (`armada-coordinator`, `armada-worker`, `armada-runtime-conductor`) 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;
|
|
46
|
+
- `.conductor/settings.toml` has a `[scripts] setup` command;
|
|
47
|
+
- `.gitignore` ignores `plans/ship-pr-dev/`;
|
|
48
|
+
- the Linear label groups `Agent phase` and `Agent runtime` exist with every value (needs `LINEAR_API_KEY`).
|
|
49
|
+
|
|
50
|
+
Each problem is an error or a warning, with its fix. A missing skill is an error: workers cannot run without it. A skill that differs from this Armada version, or a missing ignore line, is a warning. Doctor exits 1 when there is an error. `--json` prints the same report as JSON.
|
|
51
|
+
|
|
52
|
+
`armada init` fixes everything doctor reports in one go:
|
|
53
|
+
|
|
54
|
+
1. It creates the missing Linear labels (a missing group goes in the team of the program root).
|
|
55
|
+
2. It builds the missing or outdated files on a fresh checkout of the default branch, commits them on the branch `armada/init-<version>` and opens a pull request with `gh`. Your own checkout is not touched. Running it again rebuilds that branch and updates the same pull request. When the default branch already has everything, no pull request is opened.
|
|
56
|
+
3. It registers the project (slug, name, repository, program root) in the Turso database, so `armada status --all` and the dashboard list it.
|
|
57
|
+
|
|
58
|
+
On a repository without `armada.toml`, pass `--program-root <ISSUE-ID>`; the name comes from the GitHub repository unless you pass `--name`, and the slug from the name unless you pass `--slug`. An existing `armada.toml` is never replaced. `init` needs `git`, the GitHub CLI logged in (`gh auth login`), `LINEAR_API_KEY` and `ARMADA_TURSO_URL`; on a terminal it asks for missing keys first.
|
|
59
|
+
|
|
60
|
+
`armada status --all` prints the status of every registered project, each read with the `armada.toml` on its repository's default branch. A project that cannot be read shows its error without hiding the others.
|
|
61
|
+
|
|
35
62
|
## Work on a ticket (workers)
|
|
36
63
|
|
|
37
64
|
A worker writes to the tracker only through three commands. They set the labels and write the comments in the protocol format, and record each event in Turso.
|
|
@@ -60,8 +87,8 @@ Armada needs a few keys. Set them up once per machine with `armada auth login`,
|
|
|
60
87
|
| Variable | What | Needed by |
|
|
61
88
|
| --- | --- | --- |
|
|
62
89
|
| `LINEAR_API_KEY` | Linear personal API key (Linear > Settings > Security & access > Personal API keys) | `armada status` |
|
|
63
|
-
| `ARMADA_TURSO_URL` | Turso database URL, `libsql://...` (`file:/path/armada.db` for a local database) | live activity: events, runtime handles, inbox (optional) |
|
|
64
|
-
| `ARMADA_TURSO_TOKEN` | Turso database token |
|
|
90
|
+
| `ARMADA_TURSO_URL` | Turso database URL, `libsql://...` (`file:/path/armada.db` for a local database) | `armada init` and `armada status --all` (project registry); live activity: events, runtime handles, inbox (optional) |
|
|
91
|
+
| `ARMADA_TURSO_TOKEN` | Turso database token | the same (optional for a `file:` database) |
|
|
65
92
|
| `GITHUB_TOKEN` or `GH_TOKEN` | GitHub token; otherwise `gh auth token` is used | pull requests and CI |
|
|
66
93
|
|
|
67
94
|
- `armada auth login` asks only for the keys that are missing, with hidden input for tokens, and stores them in `~/.config/armada/credentials` (or `$XDG_CONFIG_HOME/armada/credentials`), mode 0600 in a 0700 directory. Without a terminal it asks nothing and lists the variables to set instead.
|
|
@@ -99,6 +126,7 @@ ready_label = "ready-for-agent" # marks a ticket an agent may take (default)
|
|
|
99
126
|
[tracker.labels]
|
|
100
127
|
phase_group = "Agent phase" # single-select label group for the agent phase (default)
|
|
101
128
|
runtime_group = "Agent runtime" # single-select label group for the agent runtime (default)
|
|
129
|
+
runtimes = ["Claude Code", "Codex", "Conductor"] # values of the runtime group (default)
|
|
102
130
|
|
|
103
131
|
[github]
|
|
104
132
|
repository = "acme/widgets" # owner/name (required)
|
|
@@ -129,7 +157,7 @@ See [AGENTS.md](https://github.com/The-Vibe-Company/armada/blob/main/AGENTS.md)
|
|
|
129
157
|
## What it is made of
|
|
130
158
|
|
|
131
159
|
- **`armada` CLI** (TypeScript). The coordinator and the workers call it to claim tickets, report progress, ask and answer questions, launch workers and merge.
|
|
132
|
-
- **Skills** vendored into the managed repository
|
|
160
|
+
- **Skills** vendored into the managed repository by `armada init`: the coordinator loop, the worker protocol and one runtime guide per runtime. They live in [`skills/`](skills).
|
|
133
161
|
- **Linear** holds the plan: specs, tickets, dependencies and agent phases.
|
|
134
162
|
- **Turso** (libSQL) holds live telemetry: events, heartbeats, pending questions and locks. Losing it loses live detail, never progress.
|
|
135
163
|
- **Conductor Cloud** runs the workers in the first version. Other runtimes come later without changing the worker contract.
|
package/dist/armada.js
CHANGED
|
@@ -19,11 +19,11 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
19
19
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
20
|
|
|
21
21
|
// src/main.ts
|
|
22
|
-
import { spawnSync } from "node:child_process";
|
|
23
|
-
import { readFile as
|
|
22
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
23
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
24
24
|
|
|
25
25
|
// src/cli.ts
|
|
26
|
-
import { dirname, join as
|
|
26
|
+
import { dirname as dirname2, join as join4, resolve } from "node:path";
|
|
27
27
|
|
|
28
28
|
// ../../node_modules/.bun/smol-toml@1.9.0/node_modules/smol-toml/dist/error.js
|
|
29
29
|
/*!
|
|
@@ -1000,6 +1000,7 @@ var CONFIG_DEFAULTS = {
|
|
|
1000
1000
|
readyLabel: "ready-for-agent",
|
|
1001
1001
|
phaseGroup: "Agent phase",
|
|
1002
1002
|
runtimeGroup: "Agent runtime",
|
|
1003
|
+
runtimes: ["Claude Code", "Codex", "Conductor"],
|
|
1003
1004
|
silentAfterMinutes: 15
|
|
1004
1005
|
};
|
|
1005
1006
|
|
|
@@ -1077,7 +1078,7 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
1077
1078
|
const known = [
|
|
1078
1079
|
["project", project, ["name", "slug"]],
|
|
1079
1080
|
["tracker", tracker, ["program_root", "language", "ready_label", "labels"]],
|
|
1080
|
-
["tracker.labels", labelsT, ["phase_group", "runtime_group"]],
|
|
1081
|
+
["tracker.labels", labelsT, ["phase_group", "runtime_group", "runtimes"]],
|
|
1081
1082
|
["github", github, ["repository"]],
|
|
1082
1083
|
["gates", gatesT, ["required_checks"]],
|
|
1083
1084
|
["policy", policyT, ["silence_minutes", "silent_after_minutes"]]
|
|
@@ -1086,6 +1087,14 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
1086
1087
|
for (const key of Object.keys(t))
|
|
1087
1088
|
if (!keys.includes(key))
|
|
1088
1089
|
problems.push(`unknown key "${path}.${key}"`);
|
|
1090
|
+
let runtimes = [...CONFIG_DEFAULTS.runtimes];
|
|
1091
|
+
if (labelsT.runtimes !== undefined) {
|
|
1092
|
+
const v = labelsT.runtimes;
|
|
1093
|
+
if (Array.isArray(v) && v.length && v.every((x) => typeof x === "string" && x.trim()))
|
|
1094
|
+
runtimes = [...new Set(v.map((x) => x.trim()))];
|
|
1095
|
+
else
|
|
1096
|
+
problems.push(`"tracker.labels.runtimes" must be a non-empty list of names`);
|
|
1097
|
+
}
|
|
1089
1098
|
const silenceKey = policyT.silence_minutes !== undefined ? "silence_minutes" : "silent_after_minutes";
|
|
1090
1099
|
if (policyT.silence_minutes !== undefined && policyT.silent_after_minutes !== undefined)
|
|
1091
1100
|
problems.push(`"policy.silent_after_minutes" is the old name of "policy.silence_minutes"; keep only one`);
|
|
@@ -1119,7 +1128,8 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
1119
1128
|
readyLabel: str(tracker, "tracker", "ready_label", { default: CONFIG_DEFAULTS.readyLabel }),
|
|
1120
1129
|
labels: {
|
|
1121
1130
|
phaseGroup: str(labelsT, "tracker.labels", "phase_group", { default: CONFIG_DEFAULTS.phaseGroup }),
|
|
1122
|
-
runtimeGroup: str(labelsT, "tracker.labels", "runtime_group", { default: CONFIG_DEFAULTS.runtimeGroup })
|
|
1131
|
+
runtimeGroup: str(labelsT, "tracker.labels", "runtime_group", { default: CONFIG_DEFAULTS.runtimeGroup }),
|
|
1132
|
+
runtimes
|
|
1123
1133
|
}
|
|
1124
1134
|
},
|
|
1125
1135
|
github: {
|
|
@@ -1133,6 +1143,38 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
1133
1143
|
config.tracker.programRoot = config.tracker.programRoot.toUpperCase();
|
|
1134
1144
|
return config;
|
|
1135
1145
|
}
|
|
1146
|
+
function configTemplate(p) {
|
|
1147
|
+
const q = JSON.stringify;
|
|
1148
|
+
return `# Armada configuration: one project = one repository + one tracker program root.
|
|
1149
|
+
# No secrets here: keys come from the environment or \`armada auth login\`.
|
|
1150
|
+
|
|
1151
|
+
[project]
|
|
1152
|
+
name = ${q(p.name)}
|
|
1153
|
+
slug = ${q(p.slug)} # stable id: lowercase letters, digits and dashes
|
|
1154
|
+
|
|
1155
|
+
[tracker]
|
|
1156
|
+
program_root = ${q(p.programRoot)} # Linear issue at the root of the program
|
|
1157
|
+
language = "en" # language of owner-facing output
|
|
1158
|
+
ready_label = "ready-for-agent"
|
|
1159
|
+
|
|
1160
|
+
[tracker.labels]
|
|
1161
|
+
phase_group = "Agent phase"
|
|
1162
|
+
runtime_group = "Agent runtime"
|
|
1163
|
+
runtimes = ["Claude Code", "Codex", "Conductor"]
|
|
1164
|
+
|
|
1165
|
+
[github]
|
|
1166
|
+
repository = ${q(p.repository)}
|
|
1167
|
+
|
|
1168
|
+
[gates]
|
|
1169
|
+
# required_checks = ["test"] # CI checks that must be green before a hand-back (default: every check)
|
|
1170
|
+
|
|
1171
|
+
[policy]
|
|
1172
|
+
silence_minutes = 15 # a worker with no report for longer than this shows as silent
|
|
1173
|
+
`;
|
|
1174
|
+
}
|
|
1175
|
+
function slugify(name) {
|
|
1176
|
+
return name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "project";
|
|
1177
|
+
}
|
|
1136
1178
|
// ../core/src/credentials.ts
|
|
1137
1179
|
var LINEAR_KEY = {
|
|
1138
1180
|
name: "linearApiKey",
|
|
@@ -1974,6 +2016,120 @@ function attachPullRequests(program, forge) {
|
|
|
1974
2016
|
return { ...issue, prs: prs.sort((a, b) => a.number - b.number) };
|
|
1975
2017
|
});
|
|
1976
2018
|
}
|
|
2019
|
+
var FILE_QUERY = `
|
|
2020
|
+
query ArmadaConfig($owner: String!, $name: String!, $expression: String!) {
|
|
2021
|
+
repository(owner: $owner, name: $name) { object(expression: $expression) { ... on Blob { text } } }
|
|
2022
|
+
}`;
|
|
2023
|
+
async function fetchDefaultBranchFile(opts) {
|
|
2024
|
+
const [owner, name] = opts.repository.split("/");
|
|
2025
|
+
const doFetch = opts.fetch ?? fetch;
|
|
2026
|
+
const timeoutMs = opts.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
2027
|
+
const res = await doFetch(GITHUB_GRAPHQL, {
|
|
2028
|
+
method: "POST",
|
|
2029
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${opts.token}` },
|
|
2030
|
+
body: JSON.stringify({ query: FILE_QUERY, variables: { owner, name, expression: `HEAD:${opts.path}` } }),
|
|
2031
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
2032
|
+
}).catch((err) => {
|
|
2033
|
+
throw new GithubError(`GitHub API unreachable: ${networkReason(err, timeoutMs)}`);
|
|
2034
|
+
});
|
|
2035
|
+
if (!res.ok)
|
|
2036
|
+
throw new GithubError(`GitHub API HTTP ${res.status}`);
|
|
2037
|
+
const json = await res.json();
|
|
2038
|
+
if (json.errors?.length)
|
|
2039
|
+
throw new GithubError(`GitHub API: ${json.errors.map((e) => e.message).join("; ")}`);
|
|
2040
|
+
if (!json.data?.repository)
|
|
2041
|
+
throw new GithubError(`GitHub: repository ${opts.repository} not found`);
|
|
2042
|
+
return json.data.repository.object?.text ?? null;
|
|
2043
|
+
}
|
|
2044
|
+
// ../core/src/labels.ts
|
|
2045
|
+
function requiredLabels(config) {
|
|
2046
|
+
return [
|
|
2047
|
+
{ name: config.tracker.labels.phaseGroup, values: [...LABEL_PHASES] },
|
|
2048
|
+
{ name: config.tracker.labels.runtimeGroup, values: config.tracker.labels.runtimes }
|
|
2049
|
+
];
|
|
2050
|
+
}
|
|
2051
|
+
var LABELS_QUERY = `
|
|
2052
|
+
query Labels($root: String!, $filter: IssueLabelFilter) {
|
|
2053
|
+
issue(id: $root) { team { id key } }
|
|
2054
|
+
issueLabels(first: 50, filter: $filter) {
|
|
2055
|
+
nodes { id name isGroup team { id } children(first: 100) { nodes { name } } }
|
|
2056
|
+
}
|
|
2057
|
+
}`;
|
|
2058
|
+
async function readLabels(config, opts) {
|
|
2059
|
+
const wanted = requiredLabels(config);
|
|
2060
|
+
const data = await gql(opts, LABELS_QUERY, {
|
|
2061
|
+
root: config.tracker.programRoot,
|
|
2062
|
+
filter: { or: wanted.map((g) => ({ name: { eqIgnoreCase: g.name } })) }
|
|
2063
|
+
});
|
|
2064
|
+
if (!data.issue)
|
|
2065
|
+
throw new LinearError(`Linear: program root ${config.tracker.programRoot} not found`);
|
|
2066
|
+
const team = data.issue.team;
|
|
2067
|
+
const groups = wanted.map((w) => {
|
|
2068
|
+
const candidates = data.issueLabels.nodes.filter((n) => n.isGroup && n.name.toLowerCase() === w.name.toLowerCase());
|
|
2069
|
+
const group = candidates.find((n) => n.team?.id === team.id) ?? candidates.find((n) => n.team === null);
|
|
2070
|
+
const have = new Set(group?.children.nodes.map((c) => c.name.toLowerCase()) ?? []);
|
|
2071
|
+
return {
|
|
2072
|
+
name: w.name,
|
|
2073
|
+
id: group?.id ?? null,
|
|
2074
|
+
scope: group ? group.team ? "team" : "workspace" : null,
|
|
2075
|
+
missing: w.values.filter((v) => !have.has(v.toLowerCase()))
|
|
2076
|
+
};
|
|
2077
|
+
});
|
|
2078
|
+
return { team, groups };
|
|
2079
|
+
}
|
|
2080
|
+
function checkLabels(state) {
|
|
2081
|
+
return state.groups.map((g) => {
|
|
2082
|
+
const id = `labels:${g.name}`;
|
|
2083
|
+
if (!g.id)
|
|
2084
|
+
return {
|
|
2085
|
+
id,
|
|
2086
|
+
level: "error",
|
|
2087
|
+
message: `label group "${g.name}" does not exist in Linear team ${state.team.key}`,
|
|
2088
|
+
fix: "run `armada init` to create it with every value"
|
|
2089
|
+
};
|
|
2090
|
+
if (g.missing.length)
|
|
2091
|
+
return {
|
|
2092
|
+
id,
|
|
2093
|
+
level: "error",
|
|
2094
|
+
message: `label group "${g.name}" lacks ${g.missing.map((v) => `"${v}"`).join(", ")}`,
|
|
2095
|
+
fix: "run `armada init` to add the missing values"
|
|
2096
|
+
};
|
|
2097
|
+
return { id, level: "ok", message: `label group "${g.name}" has every value`, fix: null };
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
var CREATE_LABEL = `
|
|
2101
|
+
mutation CreateLabel($input: IssueLabelCreateInput!) {
|
|
2102
|
+
issueLabelCreate(input: $input) { success issueLabel { id } }
|
|
2103
|
+
}`;
|
|
2104
|
+
async function createLabel(opts, input) {
|
|
2105
|
+
const data = await gql(opts, CREATE_LABEL, { input });
|
|
2106
|
+
const created = data.issueLabelCreate.issueLabel;
|
|
2107
|
+
if (!data.issueLabelCreate.success || !created)
|
|
2108
|
+
throw new LinearError(`Linear refused to create label ${input.name}`);
|
|
2109
|
+
return created.id;
|
|
2110
|
+
}
|
|
2111
|
+
async function createMissingLabels(state, opts) {
|
|
2112
|
+
const created = [];
|
|
2113
|
+
for (const g of state.groups) {
|
|
2114
|
+
let groupId = g.id;
|
|
2115
|
+
let teamId = g.scope === "workspace" ? null : state.team.id;
|
|
2116
|
+
if (!groupId) {
|
|
2117
|
+
groupId = await createLabel(opts, {
|
|
2118
|
+
name: g.name,
|
|
2119
|
+
teamId: state.team.id,
|
|
2120
|
+
isGroup: true,
|
|
2121
|
+
groupType: "singleSelect"
|
|
2122
|
+
});
|
|
2123
|
+
teamId = state.team.id;
|
|
2124
|
+
created.push(g.name);
|
|
2125
|
+
}
|
|
2126
|
+
for (const value of g.missing) {
|
|
2127
|
+
await createLabel(opts, { name: value, parentId: groupId, ...teamId ? { teamId } : {} });
|
|
2128
|
+
created.push(`${g.name} / ${value}`);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
return created;
|
|
2132
|
+
}
|
|
1977
2133
|
// ../core/src/linear-write.ts
|
|
1978
2134
|
var MAX_COMMENTS2 = 100;
|
|
1979
2135
|
var TICKET_QUERY = `
|
|
@@ -2293,6 +2449,331 @@ function handBackProblems({ pr, repository, sha, requiredChecks }) {
|
|
|
2293
2449
|
}
|
|
2294
2450
|
return problems;
|
|
2295
2451
|
}
|
|
2452
|
+
// ../core/src/skills.ts
|
|
2453
|
+
import { createHash } from "node:crypto";
|
|
2454
|
+
|
|
2455
|
+
// ../../skills/armada-coordinator/MERGE.md
|
|
2456
|
+
var MERGE_default = "# Merging a pull request\n\n`armada merge <pr>` runs this checklist, merges and closes the ticket. When you merge by hand, follow the same steps.\n\n## Before\n\n1. The worker has handed back: `Agent phase` is `ready-to-merge` and you have the full 40-character head SHA it reported.\n2. `gh pr view <n> --json headRefOid,mergeStateStatus,isDraft,title` shows that SHA, `CLEAN`, not a draft, and a Commitizen title.\n3. `gh pr checks <n>` shows every required check passing.\n4. The head contains the current default branch: `git merge-base --is-ancestor origin/<default> <sha>`. If not, ask the worker to rebase.\n5. Semantic check: search the default branch for callers of anything the pull request deletes or renames.\n\n## Merge\n\n```sh\ngh pr merge <n> --squash --match-head-commit <full-sha>\n```\n\n- One merge at a time.\n- Leave out `--delete-branch`: it deletes local worktrees that have the branch checked out, including other agents'. Delete the branch once its worktree is gone.\n- If GitHub answers with a 5xx, check `gh pr view <n> --json state` before retrying.\n\n## After\n\n1. The ticket is Done, its `Agent phase` and `Agent runtime` labels removed, the pull request linked.\n2. Tell every in-flight worker what the merge changes for them: a shared file, a migration, a new check, code they must now reuse or delete.\n3. Launch the tickets this merge unblocked.\n";
|
|
2457
|
+
|
|
2458
|
+
// ../../skills/armada-coordinator/SKILL.md
|
|
2459
|
+
var SKILL_default = `---
|
|
2460
|
+
name: armada-coordinator
|
|
2461
|
+
description: Coordinating an Armada fleet of coding agents on one project. Use when designated coordinator, or asked to launch workers on ready tickets, answer their questions, merge their green pull requests, or resume a fleet in a new local or cloud session. Reads the fleet with armada status and armada inbox and drives workers through the runtime guide skill.
|
|
2462
|
+
---
|
|
2463
|
+
|
|
2464
|
+
The coordinator turns the owner's intent into merged pull requests. Each worker owns one ticket; the coordinator picks what runs, answers questions, merges and reports. There is one coordinator per project. \`armada.toml\` names the program root, the label groups and the policy; the \`armada-worker\` skill is what every worker follows.
|
|
2465
|
+
|
|
2466
|
+
**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.
|
|
2467
|
+
|
|
2468
|
+
**Armada never drives a runtime.** Launching, messaging, checking and stopping a worker go through the runtime guide skill for the worker's runtime (for example \`armada-runtime-conductor\`). Armada records what happened.
|
|
2469
|
+
|
|
2470
|
+
## Loop
|
|
2471
|
+
|
|
2472
|
+
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 or request.
|
|
2473
|
+
2. **Answer what waits for you first.** For each question: decide, deliver the answer in the worker's session with the runtime guide's *message* section, then \`armada answer <item> --message "<decision and reason>"\`. 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.
|
|
2474
|
+
3. **Check silent workers** with the runtime guide's *status* section. A worker that is still working gets a nudge to report; a worker that died is relaunched or its ticket released.
|
|
2475
|
+
4. **Launch ready tickets** that do not collide with work in flight: \`armada brief <ticket>\` gives the launch prompt and the environment the runtime must pass; launch with the runtime guide's *launch* section, then record the handle with \`armada claim\` if the worker did not. Add to the brief what only you know: merged blockers and their hand-back notes, decisions already made, and which parallel workers touch neighbouring code. Done when every launched ticket is In Progress with a claim.
|
|
2476
|
+
5. **Merge handed-back pull requests** one at a time with \`armada merge <pr>\`, following [MERGE.md](MERGE.md). Done when the pull request is merged, the ticket is Done with its agent labels removed, and every in-flight worker affected by what landed has been told.
|
|
2477
|
+
6. **Turn findings into tickets.** A gap a worker reports or a bug you see becomes a ticket under the right spec, with blocked-by relations, and is launched when ready. No finding lives only in a transcript.
|
|
2478
|
+
7. **Report to the owner** in their language (\`tracker.language\` in \`armada.toml\`, or the owner's personal setting): what merged, what runs, what you decided for them, and the one thing they must do, with its exact place (a URL, a setting). Outcomes and numbers, no process narration.
|
|
2479
|
+
|
|
2480
|
+
Repeat from step 1; \`armada inbox --wait\` blocks until something needs you.
|
|
2481
|
+
|
|
2482
|
+
## Rules of thumb
|
|
2483
|
+
|
|
2484
|
+
- Merge only after the worker's hand-back; a green pull request can still get one more rebased push.
|
|
2485
|
+
- Parallel workers in one area collide: stagger them, or give each a disjoint area and tell them the boundary.
|
|
2486
|
+
- Everything that must survive your session goes to the tracker or the repository. The next coordinator may be a fresh cloud session with none of your context: it resumes from \`armada status\` and \`armada inbox\`.
|
|
2487
|
+
- When a command named here is missing from your Armada version (\`armada --help\`), do the step by hand with the same protocol and say so in your report.
|
|
2488
|
+
`;
|
|
2489
|
+
|
|
2490
|
+
// ../../skills/armada-runtime-conductor/SKILL.md
|
|
2491
|
+
var SKILL_default2 = "---\nname: armada-runtime-conductor\ndescription: Runtime guide for running Armada workers on Conductor. Use when an Armada coordinator must launch a worker, send it a message, check whether it is alive, or stop and archive it on Conductor. Four fixed sections, each with the conductor command and how to read its output.\n---\n\nArmada never calls a runtime itself. This guide tells the coordinator how to do the four runtime actions with the `conductor` command line tool, and what to record in Armada afterwards. Check the exact flags with `conductor --help` and `conductor <command> --help`: this first version gives the commands to use, and a later Armada release completes the options and sample outputs.\n\n## Launch\n\n```sh\nconductor workspace create --repo <owner/name> --branch <ticket branch>\n```\n\nPass the prompt from `armada brief <ticket>` as the first message, and the environment variables it lists. Read the workspace id and the session id from the output; they form the handle `<workspace>/<session>`. Record it with `armada claim <ticket> --runtime conductor --handle <workspace>/<session>` unless the worker claims it itself.\n\n## Message\n\n```sh\nconductor message create --workspace <workspace> --session <session> --message \"<text>\"\n```\n\nUse it to deliver an answer, an approval or a heads-up that the default branch moved. A zero exit code means Conductor accepted the message; it does not mean the worker read it. After delivering an answer, record it with `armada answer`.\n\n## Status\n\n```sh\nconductor session status --workspace <workspace> --session <session>\n```\n\nTells whether the session is running, idle or ended. A silent worker whose session is running is busy: nudge it to report. An idle or ended session with the ticket not handed back needs a message or a relaunch.\n\n## Stop and archive\n\n```sh\nconductor workspace archive --workspace <workspace>\n```\n\nArchive a worker's workspace after its pull request is merged, or when its ticket is released. Archiving stops the session and frees the workspace; the branch and the pull request stay on GitHub.\n";
|
|
2492
|
+
|
|
2493
|
+
// ../../skills/armada-worker/SKILL.md
|
|
2494
|
+
var SKILL_default3 = `---
|
|
2495
|
+
name: armada-worker
|
|
2496
|
+
description: Working one ticket as an Armada worker agent. Use when you were launched on a ticket by an Armada coordinator, or asked to claim, plan, implement and ship one ticket of a project that has an armada.toml. Covers the claim, the phase reports every 15 minutes, questions to the coordinator, the green pull request and the hand-back. A worker never merges.
|
|
2497
|
+
---
|
|
2498
|
+
|
|
2499
|
+
You are a worker. You own exactly one ticket, named in your launch brief. You turn it into one green pull request and hand it back to the coordinator, who merges. \`armada.toml\` at the repository root names the tracker program, the label groups and the policy; \`AGENTS.md\` (or \`CLAUDE.md\`) holds the repository's own rules, and they win over this skill where they are stricter.
|
|
2500
|
+
|
|
2501
|
+
## Rules
|
|
2502
|
+
|
|
2503
|
+
- **Never merge**, never enable auto-merge, never approve your own plan. The coordinator merges.
|
|
2504
|
+
- **Report at least every 15 minutes** of work with \`armada report <phase> --message "<what you are doing>"\`. The same phase is allowed: it is your heartbeat. A worker silent for longer than \`policy.silence_minutes\` shows as silent, and the coordinator comes to check on you.
|
|
2505
|
+
- **Ask instead of guessing** when a choice changes the ticket's outcome: \`armada ask "<question, the options, your recommendation>"\`. Your phase becomes \`blocked\` until the coordinator answers in your session. Decide reversible technical choices yourself and record each one, with its reason, on the ticket and in the pull request.
|
|
2506
|
+
- **The ticket is the source of truth.** Read it, its parent spec and the hand-back comments of its merged blockers in full before planning.
|
|
2507
|
+
- Work only in your own branch and worktree. Never touch another agent's checkout, and stop only the processes you started.
|
|
2508
|
+
- Never print, commit or log a secret.
|
|
2509
|
+
|
|
2510
|
+
## Steps
|
|
2511
|
+
|
|
2512
|
+
1. **Claim.** \`armada claim <ticket> --runtime <runtime> --handle <workspace>/<session>\`. It assigns the ticket, moves it to In Progress, sets \`Agent phase = planning\` and your \`Agent runtime\`, and posts the \`Agent claim\` comment. If it refuses because another claim exists, stop: the older claim wins.
|
|
2513
|
+
2. **Branch.** Use the branch named after the ticket (the tracker suggests one, for example \`feature/abc-12-short-title\`), created from the latest default branch.
|
|
2514
|
+
3. **Plan.** Write the plan: what changes, how it is tested, and the checks a person could observe when it is done. If your brief says plans are pre-approved, post it with \`armada report implementing --message "<plan>"\` and go on. Otherwise post it with \`armada report awaiting-approval --message "<plan>"\`, push your branch, and wait for the coordinator's answer in your session.
|
|
2515
|
+
4. **Implement** test-first. A material change to the approved plan needs a new approval.
|
|
2516
|
+
5. **Ship.** \`armada report shipping --pr <number>\`. Use the \`ship-pr-dev\` skill when the repository has it; otherwise run the repository's local checks, open the pull request with a Commitizen title (\`feat(scope): …\`), link it on the ticket, and fix CI until every required check is green.
|
|
2517
|
+
6. **Rebase** on the latest default branch right before hand-back, and get CI green on that final head.
|
|
2518
|
+
7. **Hand back.** \`armada report ready-to-merge --pr <number> --sha <full 40-character head SHA>\`. Armada refuses a short SHA, a SHA that is not the pull request head, or a red check. Then report to the coordinator: pull request URL, full SHA, CI state, the decisions you made, and what the next tickets need to know.
|
|
2519
|
+
|
|
2520
|
+
If you stop without finishing, run \`armada release --reason "<why>"\` so the ticket is free again.
|
|
2521
|
+
|
|
2522
|
+
## When a command is missing
|
|
2523
|
+
|
|
2524
|
+
This skill is versioned with Armada; an older CLI may lack a command (\`armada --help\` lists them). Do the same step by hand in the tracker, keeping the protocol: exactly one label from the phase group (\`planning\`, \`awaiting-approval\`, \`implementing\`, \`shipping\`, \`blocked\`, \`ready-to-merge\`) and one from the runtime group; a first comment \`Agent claim — runtime: <runtime> · session: <id> · branch: <branch> · started: <ISO date>\`; and every comment starting with \`Agent status: <phase> — <one-line summary>\`.
|
|
2525
|
+
`;
|
|
2526
|
+
|
|
2527
|
+
// ../core/src/skills.ts
|
|
2528
|
+
var SKILLS_SOURCE = "The-Vibe-Company/armada";
|
|
2529
|
+
var BUNDLED_SKILLS = [
|
|
2530
|
+
{
|
|
2531
|
+
name: "armada-coordinator",
|
|
2532
|
+
files: [
|
|
2533
|
+
{ path: "MERGE.md", content: MERGE_default },
|
|
2534
|
+
{ path: "SKILL.md", content: SKILL_default }
|
|
2535
|
+
]
|
|
2536
|
+
},
|
|
2537
|
+
{ name: "armada-runtime-conductor", files: [{ path: "SKILL.md", content: SKILL_default2 }] },
|
|
2538
|
+
{ name: "armada-worker", files: [{ path: "SKILL.md", content: SKILL_default3 }] }
|
|
2539
|
+
];
|
|
2540
|
+
function skillFolderHash(files) {
|
|
2541
|
+
const hash = createHash("sha256");
|
|
2542
|
+
for (const f of [...files].sort((a, b) => a.path.localeCompare(b.path))) {
|
|
2543
|
+
hash.update(f.path);
|
|
2544
|
+
hash.update(f.content);
|
|
2545
|
+
}
|
|
2546
|
+
return hash.digest("hex");
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
// ../core/src/setup.ts
|
|
2550
|
+
var AGENTS_SKILLS_DIR = ".agents/skills";
|
|
2551
|
+
var CLAUDE_SKILLS_DIR = ".claude/skills";
|
|
2552
|
+
var SKILLS_LOCK_FILE = "skills-lock.json";
|
|
2553
|
+
var CONDUCTOR_SETTINGS = ".conductor/settings.toml";
|
|
2554
|
+
var GITIGNORE = ".gitignore";
|
|
2555
|
+
var SHIP_ARTIFACTS = "plans/ship-pr-dev/";
|
|
2556
|
+
var ok = (id, message) => ({ id, level: "ok", message, fix: null });
|
|
2557
|
+
var bad = (id, level, message, fix) => ({
|
|
2558
|
+
id,
|
|
2559
|
+
level,
|
|
2560
|
+
message,
|
|
2561
|
+
fix
|
|
2562
|
+
});
|
|
2563
|
+
var skillDir = (name) => `${AGENTS_SKILLS_DIR}/${name}`;
|
|
2564
|
+
var linkPath = (name) => `${CLAUDE_SKILLS_DIR}/${name}`;
|
|
2565
|
+
var skillLinkTarget = (name) => `../../${AGENTS_SKILLS_DIR}/${name}`;
|
|
2566
|
+
var bundledHash = (s) => skillFolderHash(s.files);
|
|
2567
|
+
var WHOLE_DIR_LINKS = new Set(["../.agents/skills", "../.agents/skills/"]);
|
|
2568
|
+
var linksWholeDir = async (view) => WHOLE_DIR_LINKS.has(await view.readLink(CLAUDE_SKILLS_DIR) ?? "");
|
|
2569
|
+
|
|
2570
|
+
class SetupError extends Error {
|
|
2571
|
+
name = "SetupError";
|
|
2572
|
+
}
|
|
2573
|
+
function parseSkillsLock(text) {
|
|
2574
|
+
if (text === null)
|
|
2575
|
+
return null;
|
|
2576
|
+
let raw;
|
|
2577
|
+
try {
|
|
2578
|
+
raw = JSON.parse(text);
|
|
2579
|
+
} catch {
|
|
2580
|
+
throw new SetupError(`${SKILLS_LOCK_FILE} is not valid JSON`);
|
|
2581
|
+
}
|
|
2582
|
+
const lock = raw;
|
|
2583
|
+
if (typeof lock?.version !== "number" || typeof lock.skills !== "object" || lock.skills === null)
|
|
2584
|
+
throw new SetupError(`${SKILLS_LOCK_FILE} has no "version" number and "skills" object`);
|
|
2585
|
+
return lock;
|
|
2586
|
+
}
|
|
2587
|
+
function conductorSetup(text) {
|
|
2588
|
+
let raw;
|
|
2589
|
+
try {
|
|
2590
|
+
raw = parse(text);
|
|
2591
|
+
} catch (err) {
|
|
2592
|
+
const where = err instanceof TomlError ? ` (line ${err.line}, column ${err.column})` : "";
|
|
2593
|
+
throw new SetupError(`${CONDUCTOR_SETTINGS} is not valid TOML${where}`);
|
|
2594
|
+
}
|
|
2595
|
+
const scripts = raw.scripts;
|
|
2596
|
+
const setup = scripts?.setup;
|
|
2597
|
+
return typeof setup === "string" ? setup.trim() : "";
|
|
2598
|
+
}
|
|
2599
|
+
var IGNORES_SHIP = new Set(["plans/ship-pr-dev/", "plans/ship-pr-dev", "plans/", "plans", "plans/*"]);
|
|
2600
|
+
var ignoresShipArtifacts = (gitignore) => (gitignore ?? "").split(/\r?\n/).some((l) => IGNORES_SHIP.has(l.trim().replace(/^\//, "")));
|
|
2601
|
+
async function checkRepository(view, armadaVersion) {
|
|
2602
|
+
const checks = [];
|
|
2603
|
+
const configText = await view.readFile(CONFIG_FILE);
|
|
2604
|
+
if (configText === null)
|
|
2605
|
+
checks.push(bad("config", "error", `${CONFIG_FILE} is missing`, "run `armada init --program-root <ISSUE-ID>` to open a pull request that adds it"));
|
|
2606
|
+
else
|
|
2607
|
+
try {
|
|
2608
|
+
const config = parseConfig(configText, CONFIG_FILE);
|
|
2609
|
+
checks.push(ok("config", `${CONFIG_FILE} is valid (project ${config.project.slug})`));
|
|
2610
|
+
} catch (err) {
|
|
2611
|
+
if (!(err instanceof ConfigError))
|
|
2612
|
+
throw err;
|
|
2613
|
+
checks.push(bad("config", "error", err.message, `fix the keys listed above in ${CONFIG_FILE}`));
|
|
2614
|
+
}
|
|
2615
|
+
let lock = null;
|
|
2616
|
+
let lockError = null;
|
|
2617
|
+
try {
|
|
2618
|
+
lock = parseSkillsLock(await view.readFile(SKILLS_LOCK_FILE));
|
|
2619
|
+
} catch (err) {
|
|
2620
|
+
if (!(err instanceof SetupError))
|
|
2621
|
+
throw err;
|
|
2622
|
+
lockError = err.message;
|
|
2623
|
+
}
|
|
2624
|
+
if (lockError)
|
|
2625
|
+
checks.push(bad("skills-lock", "error", lockError, `repair or delete ${SKILLS_LOCK_FILE}`));
|
|
2626
|
+
const wholeDir = await linksWholeDir(view);
|
|
2627
|
+
for (const skill of BUNDLED_SKILLS) {
|
|
2628
|
+
const folder = await view.readFolder(skillDir(skill.name));
|
|
2629
|
+
const installed = folder?.some((f) => f.path === "SKILL.md") ? skillFolderHash(folder) : null;
|
|
2630
|
+
const id = `skill:${skill.name}`;
|
|
2631
|
+
if (installed === null) {
|
|
2632
|
+
checks.push(bad(id, "error", `skill ${skill.name} is missing from ${AGENTS_SKILLS_DIR}`, "run `armada init`"));
|
|
2633
|
+
continue;
|
|
2634
|
+
}
|
|
2635
|
+
if (installed !== bundledHash(skill))
|
|
2636
|
+
checks.push(bad(id, "warning", `skill ${skill.name} differs from the version in Armada ${armadaVersion}`, "run `armada init` to open a pull request that updates it"));
|
|
2637
|
+
else
|
|
2638
|
+
checks.push(ok(id, `skill ${skill.name} is up to date`));
|
|
2639
|
+
const target = await view.readLink(linkPath(skill.name));
|
|
2640
|
+
const linkId = `skill-link:${skill.name}`;
|
|
2641
|
+
if (wholeDir)
|
|
2642
|
+
checks.push(ok(linkId, `${CLAUDE_SKILLS_DIR} links to ${AGENTS_SKILLS_DIR}`));
|
|
2643
|
+
else if (target === skillLinkTarget(skill.name))
|
|
2644
|
+
checks.push(ok(linkId, `${linkPath(skill.name)} links to ${skillDir(skill.name)}`));
|
|
2645
|
+
else
|
|
2646
|
+
checks.push(bad(linkId, "error", target === null ? `${linkPath(skill.name)} is not a link to ${skillDir(skill.name)}, so Claude Code does not see the skill` : `${linkPath(skill.name)} links to ${target} instead of ${skillLinkTarget(skill.name)}`, "run `armada init`"));
|
|
2647
|
+
if (lockError)
|
|
2648
|
+
continue;
|
|
2649
|
+
const entry = lock?.skills[skill.name];
|
|
2650
|
+
const lockId = `skill-lock:${skill.name}`;
|
|
2651
|
+
if (!entry)
|
|
2652
|
+
checks.push(bad(lockId, "error", `${SKILLS_LOCK_FILE} does not record ${skill.name}`, "run `armada init`"));
|
|
2653
|
+
else if (installed !== null && entry.computedHash !== installed)
|
|
2654
|
+
checks.push(bad(lockId, "warning", `${SKILLS_LOCK_FILE} records a different content for ${skill.name} than ${skillDir(skill.name)}`, "run `armada init`"));
|
|
2655
|
+
else
|
|
2656
|
+
checks.push(ok(lockId, `${SKILLS_LOCK_FILE} records ${skill.name}`));
|
|
2657
|
+
}
|
|
2658
|
+
const settings = await view.readFile(CONDUCTOR_SETTINGS);
|
|
2659
|
+
if (settings === null)
|
|
2660
|
+
checks.push(bad("conductor", "error", `${CONDUCTOR_SETTINGS} is missing`, "run `armada init` to add it with a setup script"));
|
|
2661
|
+
else
|
|
2662
|
+
try {
|
|
2663
|
+
checks.push(conductorSetup(settings) ? ok("conductor", `${CONDUCTOR_SETTINGS} has a setup script`) : bad("conductor", "error", `${CONDUCTOR_SETTINGS} has no [scripts] setup`, "run `armada init`, or add a setup command under [scripts]"));
|
|
2664
|
+
} catch (err) {
|
|
2665
|
+
if (!(err instanceof SetupError))
|
|
2666
|
+
throw err;
|
|
2667
|
+
checks.push(bad("conductor", "error", err.message, `fix ${CONDUCTOR_SETTINGS}`));
|
|
2668
|
+
}
|
|
2669
|
+
checks.push(ignoresShipArtifacts(await view.readFile(GITIGNORE)) ? ok("gitignore", `${GITIGNORE} ignores ${SHIP_ARTIFACTS}`) : bad("gitignore", "warning", `${GITIGNORE} does not ignore ${SHIP_ARTIFACTS}, so the ship-pr-dev skill refuses to start`, "run `armada init`"));
|
|
2670
|
+
return checks;
|
|
2671
|
+
}
|
|
2672
|
+
async function guessSetupCommand(view) {
|
|
2673
|
+
const has = async (p) => await view.readFile(p) !== null;
|
|
2674
|
+
if (await has("bun.lock") || await has("bun.lockb"))
|
|
2675
|
+
return "bun install --frozen-lockfile";
|
|
2676
|
+
if (await has("pnpm-lock.yaml"))
|
|
2677
|
+
return "pnpm install --frozen-lockfile";
|
|
2678
|
+
if (await has("yarn.lock"))
|
|
2679
|
+
return "yarn install --frozen-lockfile";
|
|
2680
|
+
if (await has("package-lock.json"))
|
|
2681
|
+
return "npm ci";
|
|
2682
|
+
return null;
|
|
2683
|
+
}
|
|
2684
|
+
var SETUP_COMMENT = "# Commands a fresh workspace runs once: install dependencies, copy env files.";
|
|
2685
|
+
function conductorSettings(setup) {
|
|
2686
|
+
return `"$schema" = "https://conductor.build/schemas/settings.repo.schema.json"
|
|
2687
|
+
|
|
2688
|
+
[scripts]
|
|
2689
|
+
${SETUP_COMMENT}
|
|
2690
|
+
setup = ${JSON.stringify(setup ?? "true")}
|
|
2691
|
+
`;
|
|
2692
|
+
}
|
|
2693
|
+
function withSetup(text, setup) {
|
|
2694
|
+
const command = setup ?? "true";
|
|
2695
|
+
const line = `${SETUP_COMMENT}
|
|
2696
|
+
setup = ${JSON.stringify(command)}`;
|
|
2697
|
+
const lines = text.split(`
|
|
2698
|
+
`);
|
|
2699
|
+
const at = lines.findIndex((l) => /^\s*\[scripts\]\s*(#.*)?$/.test(l));
|
|
2700
|
+
let edited;
|
|
2701
|
+
if (at >= 0) {
|
|
2702
|
+
lines.splice(at + 1, 0, line);
|
|
2703
|
+
edited = lines.join(`
|
|
2704
|
+
`);
|
|
2705
|
+
} else
|
|
2706
|
+
edited = `${text.replace(/\n*$/, `
|
|
2707
|
+
`)}
|
|
2708
|
+
[scripts]
|
|
2709
|
+
${line}
|
|
2710
|
+
`;
|
|
2711
|
+
let result = "";
|
|
2712
|
+
try {
|
|
2713
|
+
result = conductorSetup(edited);
|
|
2714
|
+
} catch {}
|
|
2715
|
+
if (result !== command)
|
|
2716
|
+
throw new SetupError(`${CONDUCTOR_SETTINGS} has a [scripts] table Armada cannot add a setup command to safely; set \`setup\` under [scripts] by hand`);
|
|
2717
|
+
return edited;
|
|
2718
|
+
}
|
|
2719
|
+
function lockText(lock, armadaVersion) {
|
|
2720
|
+
const skills = { ...lock?.skills ?? {} };
|
|
2721
|
+
for (const s of BUNDLED_SKILLS)
|
|
2722
|
+
skills[s.name] = {
|
|
2723
|
+
source: SKILLS_SOURCE,
|
|
2724
|
+
sourceType: "github",
|
|
2725
|
+
skillPath: `skills/${s.name}/SKILL.md`,
|
|
2726
|
+
...armadaVersion === "0.0.0" ? {} : { ref: `v${armadaVersion}` },
|
|
2727
|
+
computedHash: bundledHash(s)
|
|
2728
|
+
};
|
|
2729
|
+
const sorted = Object.fromEntries(Object.keys(skills).sort().map((k) => [k, skills[k]]));
|
|
2730
|
+
return `${JSON.stringify({ version: lock?.version ?? 1, skills: sorted }, null, 2)}
|
|
2731
|
+
`;
|
|
2732
|
+
}
|
|
2733
|
+
async function planSetup(view, opts) {
|
|
2734
|
+
const plan = { writes: [], removes: [], links: [], installed: [], updated: [] };
|
|
2735
|
+
if (opts.configText !== null && await view.readFile(CONFIG_FILE) === null)
|
|
2736
|
+
plan.writes.push({ path: CONFIG_FILE, content: opts.configText });
|
|
2737
|
+
const wholeDir = await linksWholeDir(view);
|
|
2738
|
+
for (const skill of BUNDLED_SKILLS) {
|
|
2739
|
+
const folder = await view.readFolder(skillDir(skill.name));
|
|
2740
|
+
const current = folder?.length ? skillFolderHash(folder) === bundledHash(skill) : false;
|
|
2741
|
+
if (!current) {
|
|
2742
|
+
((folder?.length) ? plan.updated : plan.installed).push(skill.name);
|
|
2743
|
+
for (const f of skill.files)
|
|
2744
|
+
plan.writes.push({ path: `${skillDir(skill.name)}/${f.path}`, content: f.content });
|
|
2745
|
+
const keep = new Set(skill.files.map((f) => f.path));
|
|
2746
|
+
for (const f of folder ?? [])
|
|
2747
|
+
if (!keep.has(f.path))
|
|
2748
|
+
plan.removes.push(`${skillDir(skill.name)}/${f.path}`);
|
|
2749
|
+
}
|
|
2750
|
+
if (!wholeDir && await view.readLink(linkPath(skill.name)) !== skillLinkTarget(skill.name))
|
|
2751
|
+
plan.links.push({ path: linkPath(skill.name), target: skillLinkTarget(skill.name) });
|
|
2752
|
+
}
|
|
2753
|
+
const lockBefore = await view.readFile(SKILLS_LOCK_FILE);
|
|
2754
|
+
const lockAfter = lockText(parseSkillsLock(lockBefore), opts.armadaVersion);
|
|
2755
|
+
if (lockAfter !== lockBefore)
|
|
2756
|
+
plan.writes.push({ path: SKILLS_LOCK_FILE, content: lockAfter });
|
|
2757
|
+
const settings = await view.readFile(CONDUCTOR_SETTINGS);
|
|
2758
|
+
if (settings === null)
|
|
2759
|
+
plan.writes.push({ path: CONDUCTOR_SETTINGS, content: conductorSettings(await guessSetupCommand(view)) });
|
|
2760
|
+
else if (!conductorSetup(settings))
|
|
2761
|
+
plan.writes.push({ path: CONDUCTOR_SETTINGS, content: withSetup(settings, await guessSetupCommand(view)) });
|
|
2762
|
+
const gitignore = await view.readFile(GITIGNORE);
|
|
2763
|
+
if (!ignoresShipArtifacts(gitignore)) {
|
|
2764
|
+
const base = gitignore === null || gitignore === "" ? "" : `${gitignore.replace(/\n*$/, `
|
|
2765
|
+
`)}
|
|
2766
|
+
`;
|
|
2767
|
+
plan.writes.push({
|
|
2768
|
+
path: GITIGNORE,
|
|
2769
|
+
content: `${base}# Local agent run artifacts (ship-pr-dev)
|
|
2770
|
+
${SHIP_ARTIFACTS}
|
|
2771
|
+
`
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2774
|
+
return plan;
|
|
2775
|
+
}
|
|
2776
|
+
var planIsEmpty = (p) => !p.writes.length && !p.removes.length && !p.links.length;
|
|
2296
2777
|
// ../core/src/status.ts
|
|
2297
2778
|
var STATUS_SCHEMA_VERSION = 1;
|
|
2298
2779
|
function buildStatus({
|
|
@@ -2501,6 +2982,19 @@ async function migrate(db) {
|
|
|
2501
2982
|
}
|
|
2502
2983
|
return Math.max(current, SCHEMA_VERSION);
|
|
2503
2984
|
}
|
|
2985
|
+
async function upsertProject(db, p, now = new Date) {
|
|
2986
|
+
const at = now.toISOString();
|
|
2987
|
+
await db.execute({
|
|
2988
|
+
sql: `INSERT INTO projects (slug, name, repository, program_root, created_at, updated_at)
|
|
2989
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
2990
|
+
ON CONFLICT (slug) DO UPDATE SET
|
|
2991
|
+
name = excluded.name, repository = excluded.repository,
|
|
2992
|
+
program_root = excluded.program_root, updated_at = excluded.updated_at
|
|
2993
|
+
WHERE name IS NOT excluded.name OR repository IS NOT excluded.repository
|
|
2994
|
+
OR program_root IS NOT excluded.program_root`,
|
|
2995
|
+
args: [p.slug, p.name, p.repository, p.programRoot, at, at]
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2504
2998
|
async function ensureProject(db, p, now = new Date) {
|
|
2505
2999
|
const at = now.toISOString();
|
|
2506
3000
|
await db.execute({
|
|
@@ -2509,6 +3003,17 @@ async function ensureProject(db, p, now = new Date) {
|
|
|
2509
3003
|
args: [p.slug, p.name, p.repository, p.programRoot, at, at]
|
|
2510
3004
|
});
|
|
2511
3005
|
}
|
|
3006
|
+
async function listProjects(db) {
|
|
3007
|
+
const rs = await db.execute("SELECT slug, name, repository, program_root, created_at, updated_at FROM projects ORDER BY slug");
|
|
3008
|
+
return rs.rows.map((r) => ({
|
|
3009
|
+
slug: String(r.slug),
|
|
3010
|
+
name: String(r.name),
|
|
3011
|
+
repository: String(r.repository),
|
|
3012
|
+
programRoot: String(r.program_root),
|
|
3013
|
+
createdAt: String(r.created_at),
|
|
3014
|
+
updatedAt: String(r.updated_at)
|
|
3015
|
+
}));
|
|
3016
|
+
}
|
|
2512
3017
|
async function recordEvent(db, e) {
|
|
2513
3018
|
await db.execute({
|
|
2514
3019
|
sql: `INSERT INTO events (project, ticket, kind, phase, message, runtime, handle, pr_url, head_sha, created_at)
|
|
@@ -2864,7 +3369,7 @@ async function releaseTicket(ctx, input) {
|
|
|
2864
3369
|
return { ticket: ticket.id, url: ticket.url, lines, warnings, inbox: null };
|
|
2865
3370
|
}
|
|
2866
3371
|
// package.json
|
|
2867
|
-
var version = "0.1.
|
|
3372
|
+
var version = "0.1.2";
|
|
2868
3373
|
|
|
2869
3374
|
// src/io.ts
|
|
2870
3375
|
class UsageError extends Error {
|
|
@@ -3035,9 +3540,369 @@ async function authLogout(io) {
|
|
|
3035
3540
|
return 0;
|
|
3036
3541
|
}
|
|
3037
3542
|
|
|
3543
|
+
// src/repo.ts
|
|
3544
|
+
import { lstat, mkdir as mkdir2, readdir, readFile as readFile2, readlink, rm as rm2, symlink, writeFile } from "node:fs/promises";
|
|
3545
|
+
import { dirname, join as join2, relative, sep } from "node:path";
|
|
3546
|
+
var absent = (err) => {
|
|
3547
|
+
const code = err.code;
|
|
3548
|
+
return code === "ENOENT" || code === "ENOTDIR" || code === "EISDIR";
|
|
3549
|
+
};
|
|
3550
|
+
async function collect(base, dir, out) {
|
|
3551
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
3552
|
+
const full = join2(dir, entry.name);
|
|
3553
|
+
if (entry.isDirectory()) {
|
|
3554
|
+
if (entry.name !== ".git" && entry.name !== "node_modules")
|
|
3555
|
+
await collect(base, full, out);
|
|
3556
|
+
} else if (entry.isFile())
|
|
3557
|
+
out.push({ path: relative(base, full).split(sep).join("/"), content: await readFile2(full) });
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
function fsRepoView(root) {
|
|
3561
|
+
return {
|
|
3562
|
+
readFile: (path) => readFile2(join2(root, path), "utf8").catch((err) => {
|
|
3563
|
+
if (absent(err))
|
|
3564
|
+
return null;
|
|
3565
|
+
throw err;
|
|
3566
|
+
}),
|
|
3567
|
+
readLink: (path) => readlink(join2(root, path)).catch((err) => {
|
|
3568
|
+
if (absent(err) || err.code === "EINVAL")
|
|
3569
|
+
return null;
|
|
3570
|
+
throw err;
|
|
3571
|
+
}),
|
|
3572
|
+
readFolder: async (path) => {
|
|
3573
|
+
const out = [];
|
|
3574
|
+
try {
|
|
3575
|
+
await collect(join2(root, path), join2(root, path), out);
|
|
3576
|
+
} catch (err) {
|
|
3577
|
+
if (absent(err))
|
|
3578
|
+
return null;
|
|
3579
|
+
throw err;
|
|
3580
|
+
}
|
|
3581
|
+
return out;
|
|
3582
|
+
}
|
|
3583
|
+
};
|
|
3584
|
+
}
|
|
3585
|
+
async function assertNoLinkedParent(root, path) {
|
|
3586
|
+
const parts = path.split("/").slice(0, -1);
|
|
3587
|
+
for (let k = 1;k <= parts.length; k++) {
|
|
3588
|
+
const parent = parts.slice(0, k).join("/");
|
|
3589
|
+
if ((await lstat(join2(root, parent)).catch(() => null))?.isSymbolicLink())
|
|
3590
|
+
throw new CommandError(`${parent} is a link; Armada does not write through it. Replace it with a folder first.`);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
async function applyPlan(root, plan) {
|
|
3594
|
+
for (const path of [...plan.removes, ...plan.writes.map((w) => w.path), ...plan.links.map((l) => l.path)])
|
|
3595
|
+
await assertNoLinkedParent(root, path);
|
|
3596
|
+
for (const path of plan.removes)
|
|
3597
|
+
await rm2(join2(root, path), { force: true });
|
|
3598
|
+
for (const w of plan.writes) {
|
|
3599
|
+
const full = join2(root, w.path);
|
|
3600
|
+
await mkdir2(dirname(full), { recursive: true });
|
|
3601
|
+
await writeFile(full, w.content);
|
|
3602
|
+
}
|
|
3603
|
+
for (const l of plan.links) {
|
|
3604
|
+
const full = join2(root, l.path);
|
|
3605
|
+
await mkdir2(dirname(full), { recursive: true });
|
|
3606
|
+
if (await lstat(full).catch(() => null))
|
|
3607
|
+
await rm2(full, { recursive: true, force: true });
|
|
3608
|
+
await symlink(l.target, full);
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
|
|
3612
|
+
class CommandError extends Error {
|
|
3613
|
+
name = "CommandError";
|
|
3614
|
+
}
|
|
3615
|
+
function requireExec(io) {
|
|
3616
|
+
if (!io.exec)
|
|
3617
|
+
throw new CommandError("this command needs git and gh, which this environment cannot run");
|
|
3618
|
+
return io.exec;
|
|
3619
|
+
}
|
|
3620
|
+
async function sh(exec, cwd, command, args) {
|
|
3621
|
+
const r = await exec(command, args, { cwd }).catch((err) => {
|
|
3622
|
+
throw new CommandError(`could not run ${command}: ${err instanceof Error ? err.message : String(err)}. Is ${command} installed?`);
|
|
3623
|
+
});
|
|
3624
|
+
if (r.code !== 0)
|
|
3625
|
+
throw new CommandError(`${command} ${args[0] ?? ""} failed: ${(r.stderr || r.stdout).trim() || `exit ${r.code}`}`);
|
|
3626
|
+
return r.stdout.trim();
|
|
3627
|
+
}
|
|
3628
|
+
async function gitRoot(exec, cwd) {
|
|
3629
|
+
const r = await exec("git", ["rev-parse", "--show-toplevel"], { cwd }).catch(() => null);
|
|
3630
|
+
return r && r.code === 0 ? r.stdout.trim() : null;
|
|
3631
|
+
}
|
|
3632
|
+
|
|
3633
|
+
// src/doctor.ts
|
|
3634
|
+
async function labelChecks(io, root) {
|
|
3635
|
+
const text = await fsRepoView(root).readFile(CONFIG_FILE);
|
|
3636
|
+
if (text === null)
|
|
3637
|
+
return [];
|
|
3638
|
+
let config2;
|
|
3639
|
+
try {
|
|
3640
|
+
config2 = parseConfig(text, CONFIG_FILE);
|
|
3641
|
+
} catch (err) {
|
|
3642
|
+
if (err instanceof ConfigError)
|
|
3643
|
+
return [];
|
|
3644
|
+
throw err;
|
|
3645
|
+
}
|
|
3646
|
+
const { linearApiKey } = (await loadCredentials(io)).credentials;
|
|
3647
|
+
if (!linearApiKey)
|
|
3648
|
+
return [
|
|
3649
|
+
{
|
|
3650
|
+
id: "labels",
|
|
3651
|
+
level: "warning",
|
|
3652
|
+
message: `Linear labels not checked: ${LINEAR_KEY.variable} is not set`,
|
|
3653
|
+
fix: `set ${LINEAR_KEY.variable} or run \`armada auth login\`, then run doctor again`
|
|
3654
|
+
}
|
|
3655
|
+
];
|
|
3656
|
+
try {
|
|
3657
|
+
const state = await readLabels(config2, { apiKey: linearApiKey, ...io.fetch ? { fetch: io.fetch } : {} });
|
|
3658
|
+
return checkLabels(state);
|
|
3659
|
+
} catch (err) {
|
|
3660
|
+
return [
|
|
3661
|
+
{
|
|
3662
|
+
id: "labels",
|
|
3663
|
+
level: "warning",
|
|
3664
|
+
message: `Linear labels not checked: ${err instanceof Error ? err.message : String(err)}`,
|
|
3665
|
+
fix: "run doctor again once Linear answers"
|
|
3666
|
+
}
|
|
3667
|
+
];
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
async function buildDoctor(io, armadaVersion) {
|
|
3671
|
+
const root = (io.exec ? await gitRoot(io.exec, io.cwd) : null) ?? io.cwd;
|
|
3672
|
+
const checks = [...await checkRepository(fsRepoView(root), armadaVersion), ...await labelChecks(io, root)];
|
|
3673
|
+
return {
|
|
3674
|
+
schemaVersion: 1,
|
|
3675
|
+
root,
|
|
3676
|
+
armadaVersion,
|
|
3677
|
+
checks,
|
|
3678
|
+
errors: checks.filter((c) => c.level === "error").length,
|
|
3679
|
+
warnings: checks.filter((c) => c.level === "warning").length
|
|
3680
|
+
};
|
|
3681
|
+
}
|
|
3682
|
+
var plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
3683
|
+
function renderDoctor(r) {
|
|
3684
|
+
const lines = [`Armada ${r.armadaVersion} doctor · ${r.root}`, ""];
|
|
3685
|
+
for (const c of r.checks) {
|
|
3686
|
+
const [first, ...more] = c.message.split(`
|
|
3687
|
+
`);
|
|
3688
|
+
lines.push(` ${c.level.padEnd(8)} ${first}`);
|
|
3689
|
+
for (const m of more)
|
|
3690
|
+
lines.push(` ${m}`);
|
|
3691
|
+
if (c.fix)
|
|
3692
|
+
lines.push(` fix: ${c.fix}`);
|
|
3693
|
+
}
|
|
3694
|
+
lines.push("");
|
|
3695
|
+
if (!r.errors && !r.warnings)
|
|
3696
|
+
lines.push("Everything Armada needs is in place.");
|
|
3697
|
+
else
|
|
3698
|
+
lines.push(`${plural(r.errors, "error")}, ${plural(r.warnings, "warning")}.${r.errors ? " Workers cannot be launched until the errors are fixed." : ""}`);
|
|
3699
|
+
return `${lines.join(`
|
|
3700
|
+
`)}
|
|
3701
|
+
`;
|
|
3702
|
+
}
|
|
3703
|
+
async function doctor(io, json, armadaVersion) {
|
|
3704
|
+
const report = await buildDoctor(io, armadaVersion);
|
|
3705
|
+
io.stdout(json ? `${JSON.stringify(report, null, 2)}
|
|
3706
|
+
` : renderDoctor(report));
|
|
3707
|
+
return report.errors ? 1 : 0;
|
|
3708
|
+
}
|
|
3709
|
+
|
|
3710
|
+
// src/init.ts
|
|
3711
|
+
import { mkdtemp, realpath, rm as rm3 } from "node:fs/promises";
|
|
3712
|
+
import { tmpdir } from "node:os";
|
|
3713
|
+
import { join as join3 } from "node:path";
|
|
3714
|
+
var initBranch = (version2) => `armada/init-${version2}`;
|
|
3715
|
+
async function defaultBranch(exec, root) {
|
|
3716
|
+
const out = await sh(exec, root, "git", ["ls-remote", "--symref", "origin", "HEAD"]);
|
|
3717
|
+
const m = out.match(/^ref:\s+refs\/heads\/(\S+)\s+HEAD/m);
|
|
3718
|
+
if (!m?.[1])
|
|
3719
|
+
throw new CommandError("could not read the default branch of origin");
|
|
3720
|
+
return m[1];
|
|
3721
|
+
}
|
|
3722
|
+
async function resolveConfig(exec, root, checkout, opts) {
|
|
3723
|
+
const parse2 = (text2, where) => {
|
|
3724
|
+
try {
|
|
3725
|
+
return parseConfig(text2, where);
|
|
3726
|
+
} catch (err) {
|
|
3727
|
+
if (err instanceof ConfigError)
|
|
3728
|
+
throw new UsageError(`${err.message}
|
|
3729
|
+
Fix it, then run armada init again.`);
|
|
3730
|
+
throw err;
|
|
3731
|
+
}
|
|
3732
|
+
};
|
|
3733
|
+
const onDefault = await fsRepoView(checkout).readFile(CONFIG_FILE);
|
|
3734
|
+
if (onDefault !== null)
|
|
3735
|
+
return { config: parse2(onDefault, `${CONFIG_FILE} on the default branch`), text: null, source: "default branch" };
|
|
3736
|
+
const local = await fsRepoView(root).readFile(CONFIG_FILE);
|
|
3737
|
+
if (local !== null && !opts.programRoot)
|
|
3738
|
+
return { config: parse2(local, join3(root, CONFIG_FILE)), text: local, source: "working tree" };
|
|
3739
|
+
const branch = initBranch(opts.armadaVersion);
|
|
3740
|
+
if (!opts.programRoot && await sh(exec, root, "git", ["ls-remote", "origin", `refs/heads/${branch}`])) {
|
|
3741
|
+
await sh(exec, root, "git", ["fetch", "--quiet", "origin", branch]);
|
|
3742
|
+
const shown = await exec("git", ["show", `FETCH_HEAD:${CONFIG_FILE}`], { cwd: root });
|
|
3743
|
+
if (shown.code === 0)
|
|
3744
|
+
return { config: parse2(shown.stdout, `${CONFIG_FILE} on ${branch}`), text: shown.stdout, source: branch };
|
|
3745
|
+
}
|
|
3746
|
+
if (!opts.programRoot)
|
|
3747
|
+
throw new UsageError(`${CONFIG_FILE} is missing. Run armada init --program-root <ISSUE-ID> with the Linear issue at the root of the program, or add ${CONFIG_FILE} (see README).`);
|
|
3748
|
+
const repo = JSON.parse(await sh(exec, root, "gh", ["repo", "view", "--json", "name,nameWithOwner"]));
|
|
3749
|
+
const name = opts.name ?? repo.name;
|
|
3750
|
+
const text = configTemplate({
|
|
3751
|
+
name,
|
|
3752
|
+
slug: opts.slug ?? slugify(name),
|
|
3753
|
+
programRoot: opts.programRoot,
|
|
3754
|
+
repository: repo.nameWithOwner
|
|
3755
|
+
});
|
|
3756
|
+
return { config: parse2(text, `the new ${CONFIG_FILE}`), text, source: "new" };
|
|
3757
|
+
}
|
|
3758
|
+
async function branchIsCurrent(exec, checkout, branch, baseSha) {
|
|
3759
|
+
if (!await sh(exec, checkout, "git", ["ls-remote", "origin", `refs/heads/${branch}`]))
|
|
3760
|
+
return false;
|
|
3761
|
+
await sh(exec, checkout, "git", ["fetch", "--quiet", "origin", branch]);
|
|
3762
|
+
const [remoteTree, remoteParent, tree] = await Promise.all([
|
|
3763
|
+
sh(exec, checkout, "git", ["rev-parse", "FETCH_HEAD^{tree}"]),
|
|
3764
|
+
sh(exec, checkout, "git", ["rev-parse", "FETCH_HEAD^"]),
|
|
3765
|
+
sh(exec, checkout, "git", ["rev-parse", "HEAD^{tree}"])
|
|
3766
|
+
]);
|
|
3767
|
+
return remoteTree === tree && remoteParent === baseSha;
|
|
3768
|
+
}
|
|
3769
|
+
function prText(plan, version2) {
|
|
3770
|
+
const title = plan.installed.length ? `chore(armada): set up Armada ${version2}` : `chore(armada): update the Armada setup to ${version2}`;
|
|
3771
|
+
const lines = [
|
|
3772
|
+
`Adds what \`armada doctor\` checks, so Armada ${version2} can run agents on this repository.`,
|
|
3773
|
+
"",
|
|
3774
|
+
...plan.writes.map((w) => `- write \`${w.path}\``),
|
|
3775
|
+
...plan.links.map((l) => `- link \`${l.path}\` → \`${l.target}\``),
|
|
3776
|
+
...plan.removes.map((p) => `- remove \`${p}\``),
|
|
3777
|
+
"",
|
|
3778
|
+
"Once merged, `armada doctor` passes on the default branch.",
|
|
3779
|
+
"",
|
|
3780
|
+
"Opened by `armada init`. Running it again rebuilds this branch from the default branch and updates this pull request, so commits pushed here by hand are replaced."
|
|
3781
|
+
];
|
|
3782
|
+
return { title, body: lines.join(`
|
|
3783
|
+
`) };
|
|
3784
|
+
}
|
|
3785
|
+
async function init(io, opts) {
|
|
3786
|
+
const exec = requireExec(io);
|
|
3787
|
+
const tursoKey = STORED_KEYS.find((k) => k.name === "tursoUrl") ?? LINEAR_KEY;
|
|
3788
|
+
const required = (c) => [c.linearApiKey ? null : LINEAR_KEY, c.tursoUrl ? null : tursoKey];
|
|
3789
|
+
if (io.interactive || required((await loadCredentials(io)).credentials).some(Boolean)) {
|
|
3790
|
+
const login = await authLogin(io);
|
|
3791
|
+
if (login !== 0)
|
|
3792
|
+
return login;
|
|
3793
|
+
}
|
|
3794
|
+
const { credentials: credentials2 } = await loadCredentials(io);
|
|
3795
|
+
const missing2 = required(credentials2).find(Boolean);
|
|
3796
|
+
if (missing2)
|
|
3797
|
+
throw new UsageError(missingKeyMessage(missing2));
|
|
3798
|
+
const linearApiKey = credentials2.linearApiKey ?? "";
|
|
3799
|
+
const tursoUrl = credentials2.tursoUrl ?? "";
|
|
3800
|
+
const root = await gitRoot(exec, io.cwd);
|
|
3801
|
+
if (!root)
|
|
3802
|
+
throw new UsageError(`${io.cwd} is not inside a git repository`);
|
|
3803
|
+
const base = await defaultBranch(exec, root);
|
|
3804
|
+
await sh(exec, root, "git", ["fetch", "--quiet", "origin", base]);
|
|
3805
|
+
const baseSha = await sh(exec, root, "git", ["rev-parse", "FETCH_HEAD"]);
|
|
3806
|
+
const checkout = await realpath(await mkdtemp(join3(tmpdir(), "armada-init-")));
|
|
3807
|
+
try {
|
|
3808
|
+
await sh(exec, root, "git", ["worktree", "add", "--quiet", "--detach", checkout, baseSha]);
|
|
3809
|
+
const { config: config2, text, source } = await resolveConfig(exec, root, checkout, opts);
|
|
3810
|
+
const view = fsRepoView(checkout);
|
|
3811
|
+
const plan = await planSetup(view, { armadaVersion: opts.armadaVersion, configText: text });
|
|
3812
|
+
const log = (line) => io.stdout(`${line}
|
|
3813
|
+
`);
|
|
3814
|
+
log(`Armada ${opts.armadaVersion} · ${config2.github.repository} · ${config2.tracker.programRoot}`);
|
|
3815
|
+
if (source !== "default branch" && source !== "new")
|
|
3816
|
+
log(`Using ${CONFIG_FILE} from ${source === "working tree" ? "the working tree" : source}; the pull request adds it.`);
|
|
3817
|
+
const linear2 = { apiKey: linearApiKey, ...io.fetch ? { fetch: io.fetch } : {} };
|
|
3818
|
+
const created = await createMissingLabels(await readLabels(config2, linear2), linear2);
|
|
3819
|
+
log(created.length ? `Created Linear labels: ${created.join(", ")}` : "Linear labels: all present");
|
|
3820
|
+
if (planIsEmpty(plan))
|
|
3821
|
+
log(`${base} already has everything Armada needs; no pull request to open.`);
|
|
3822
|
+
else {
|
|
3823
|
+
const branch = initBranch(opts.armadaVersion);
|
|
3824
|
+
await applyPlan(checkout, plan);
|
|
3825
|
+
const paths = [...plan.writes.map((w) => w.path), ...plan.links.map((l) => l.path), ...plan.removes];
|
|
3826
|
+
await sh(exec, checkout, "git", ["add", "--all", "--force", "--", ...paths]);
|
|
3827
|
+
const { title, body } = prText(plan, opts.armadaVersion);
|
|
3828
|
+
await sh(exec, checkout, "git", ["commit", "--quiet", "--no-verify", "--message", title]);
|
|
3829
|
+
if (await branchIsCurrent(exec, checkout, branch, baseSha))
|
|
3830
|
+
log(`${branch} is already up to date.`);
|
|
3831
|
+
else
|
|
3832
|
+
await sh(exec, checkout, "git", ["push", "--quiet", "--force", "origin", `HEAD:refs/heads/${branch}`]);
|
|
3833
|
+
const repo = config2.github.repository;
|
|
3834
|
+
const open2 = JSON.parse(await sh(exec, root, "gh", [
|
|
3835
|
+
"pr",
|
|
3836
|
+
"list",
|
|
3837
|
+
"--repo",
|
|
3838
|
+
repo,
|
|
3839
|
+
"--head",
|
|
3840
|
+
branch,
|
|
3841
|
+
"--state",
|
|
3842
|
+
"open",
|
|
3843
|
+
"--json",
|
|
3844
|
+
"number,url"
|
|
3845
|
+
]) || "[]");
|
|
3846
|
+
const existing = open2[0];
|
|
3847
|
+
if (existing) {
|
|
3848
|
+
await sh(exec, root, "gh", [
|
|
3849
|
+
"pr",
|
|
3850
|
+
"edit",
|
|
3851
|
+
String(existing.number),
|
|
3852
|
+
"--repo",
|
|
3853
|
+
repo,
|
|
3854
|
+
"--title",
|
|
3855
|
+
title,
|
|
3856
|
+
"--body",
|
|
3857
|
+
body
|
|
3858
|
+
]);
|
|
3859
|
+
log(`Updated pull request ${existing.url}`);
|
|
3860
|
+
} else {
|
|
3861
|
+
const url = await sh(exec, root, "gh", [
|
|
3862
|
+
"pr",
|
|
3863
|
+
"create",
|
|
3864
|
+
"--repo",
|
|
3865
|
+
repo,
|
|
3866
|
+
"--base",
|
|
3867
|
+
base,
|
|
3868
|
+
"--head",
|
|
3869
|
+
branch,
|
|
3870
|
+
"--title",
|
|
3871
|
+
title,
|
|
3872
|
+
"--body",
|
|
3873
|
+
body
|
|
3874
|
+
]);
|
|
3875
|
+
log(`Opened pull request ${url.split(`
|
|
3876
|
+
`).pop()}`);
|
|
3877
|
+
}
|
|
3878
|
+
if (plan.installed.length)
|
|
3879
|
+
log(`Installs: ${plan.installed.join(", ")}`);
|
|
3880
|
+
if (plan.updated.length)
|
|
3881
|
+
log(`Updates: ${plan.updated.join(", ")}`);
|
|
3882
|
+
}
|
|
3883
|
+
const db = await openTurso({ url: tursoUrl, token: credentials2.tursoToken });
|
|
3884
|
+
try {
|
|
3885
|
+
const project2 = {
|
|
3886
|
+
slug: config2.project.slug,
|
|
3887
|
+
name: config2.project.name,
|
|
3888
|
+
repository: config2.github.repository,
|
|
3889
|
+
programRoot: config2.tracker.programRoot
|
|
3890
|
+
};
|
|
3891
|
+
await upsertProject(db, project2, io.now?.() ?? new Date);
|
|
3892
|
+
} finally {
|
|
3893
|
+
db.close();
|
|
3894
|
+
}
|
|
3895
|
+
log(`Registered project ${config2.project.slug}; armada status --all lists it.`);
|
|
3896
|
+
return 0;
|
|
3897
|
+
} finally {
|
|
3898
|
+
await exec("git", ["worktree", "remove", "--force", checkout], { cwd: root }).catch(() => null);
|
|
3899
|
+
await rm3(checkout, { recursive: true, force: true });
|
|
3900
|
+
}
|
|
3901
|
+
}
|
|
3902
|
+
|
|
3038
3903
|
// src/render.ts
|
|
3039
3904
|
var MIN2 = 60000;
|
|
3040
|
-
function
|
|
3905
|
+
function relative2(iso, now) {
|
|
3041
3906
|
const diff = now - Date.parse(iso);
|
|
3042
3907
|
const m = Math.round(Math.abs(diff) / MIN2);
|
|
3043
3908
|
const suffix = diff >= 0 ? "ago" : "from now";
|
|
@@ -3079,7 +3944,7 @@ function renderStatus(r) {
|
|
|
3079
3944
|
out.push(" nobody is working");
|
|
3080
3945
|
for (const t of r.inFlight) {
|
|
3081
3946
|
const who = [t.runtime, t.agent].filter(Boolean).join(" · ") || "unassigned";
|
|
3082
|
-
out.push(` ${pad(t.id, idWidth)} ${pad(phaseLabel(t), phaseWidth)} ${who} · ${t.lastReport ? `reported ${
|
|
3947
|
+
out.push(` ${pad(t.id, idWidth)} ${pad(phaseLabel(t), phaseWidth)} ${who} · ${t.lastReport ? `reported ${relative2(t.lastReport, now)}` : `updated ${relative2(t.lastUpdate, now)}`}`);
|
|
3083
3948
|
out.push(`${indent}${truncate(t.title, 90)}${t.spec ? ` [${t.spec}]` : ""}`);
|
|
3084
3949
|
if (t.statusLine?.summary)
|
|
3085
3950
|
out.push(`${indent}“${truncate(t.statusLine.summary, 100)}”`);
|
|
@@ -3128,6 +3993,84 @@ function renderStatus(r) {
|
|
|
3128
3993
|
`;
|
|
3129
3994
|
}
|
|
3130
3995
|
|
|
3996
|
+
// src/projects.ts
|
|
3997
|
+
var message = (err) => err instanceof Error ? err.message : String(err);
|
|
3998
|
+
async function projectConfig(p, githubToken, io) {
|
|
3999
|
+
const fallback = (why) => ({
|
|
4000
|
+
config: parseConfig(configTemplate(p), `registry record ${p.slug}`),
|
|
4001
|
+
warning: `${CONFIG_FILE} not read (${why}); using the registry record with default labels and policy`
|
|
4002
|
+
});
|
|
4003
|
+
if (!githubToken)
|
|
4004
|
+
return fallback("no GitHub token");
|
|
4005
|
+
try {
|
|
4006
|
+
const text = await fetchDefaultBranchFile({
|
|
4007
|
+
token: githubToken,
|
|
4008
|
+
repository: p.repository,
|
|
4009
|
+
path: CONFIG_FILE,
|
|
4010
|
+
...io.fetch ? { fetch: io.fetch } : {}
|
|
4011
|
+
});
|
|
4012
|
+
if (text === null)
|
|
4013
|
+
return fallback(`not on the default branch of ${p.repository}`);
|
|
4014
|
+
return { config: parseConfig(text, `${p.repository}:${CONFIG_FILE}`), warning: null };
|
|
4015
|
+
} catch (err) {
|
|
4016
|
+
return fallback(message(err));
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
async function statusAll(io, json) {
|
|
4020
|
+
const { credentials: credentials2 } = await loadCredentials(io);
|
|
4021
|
+
const linearApiKey = credentials2.linearApiKey;
|
|
4022
|
+
if (!linearApiKey)
|
|
4023
|
+
throw new UsageError(missingKeyMessage(LINEAR_KEY));
|
|
4024
|
+
const tursoKey = STORED_KEYS.find((k) => k.name === "tursoUrl");
|
|
4025
|
+
if (!credentials2.tursoUrl && tursoKey)
|
|
4026
|
+
throw new UsageError(missingKeyMessage(tursoKey));
|
|
4027
|
+
const db = await openTurso({ url: credentials2.tursoUrl ?? "", token: credentials2.tursoToken });
|
|
4028
|
+
let records;
|
|
4029
|
+
try {
|
|
4030
|
+
records = await listProjects(db);
|
|
4031
|
+
} finally {
|
|
4032
|
+
db.close();
|
|
4033
|
+
}
|
|
4034
|
+
const projects = await Promise.all(records.map(async (p) => {
|
|
4035
|
+
const base = { slug: p.slug, name: p.name, repository: p.repository };
|
|
4036
|
+
let warning = null;
|
|
4037
|
+
try {
|
|
4038
|
+
const read = await projectConfig(p, credentials2.githubToken, io);
|
|
4039
|
+
warning = read.warning;
|
|
4040
|
+
const config2 = read.config;
|
|
4041
|
+
const report = await loadStatus(config2, {
|
|
4042
|
+
linearApiKey,
|
|
4043
|
+
githubToken: credentials2.githubToken,
|
|
4044
|
+
...io.fetch ? { fetch: io.fetch } : {},
|
|
4045
|
+
...io.now ? { now: io.now } : {}
|
|
4046
|
+
});
|
|
4047
|
+
return { ...base, report, error: null, configWarning: warning };
|
|
4048
|
+
} catch (err) {
|
|
4049
|
+
return { ...base, report: null, error: message(err), configWarning: warning };
|
|
4050
|
+
}
|
|
4051
|
+
}));
|
|
4052
|
+
const all = { schemaVersion: 1, projects };
|
|
4053
|
+
if (json)
|
|
4054
|
+
io.stdout(`${JSON.stringify(all, null, 2)}
|
|
4055
|
+
`);
|
|
4056
|
+
else if (!projects.length)
|
|
4057
|
+
io.stdout("No project is registered yet. Run `armada init` in a repository to register it.\n");
|
|
4058
|
+
else
|
|
4059
|
+
io.stdout(projects.map((p) => {
|
|
4060
|
+
if (!p.report)
|
|
4061
|
+
return `${p.name} (${p.slug}) · ${p.repository}
|
|
4062
|
+
! not read: ${p.error}
|
|
4063
|
+
${p.configWarning ? ` ! ${p.configWarning}
|
|
4064
|
+
` : ""}`;
|
|
4065
|
+
return `${renderStatus(p.report)}${p.configWarning ? ` ! ${p.configWarning}
|
|
4066
|
+
` : ""}`;
|
|
4067
|
+
}).join(`
|
|
4068
|
+
${"─".repeat(60)}
|
|
4069
|
+
|
|
4070
|
+
`));
|
|
4071
|
+
return projects.some((p) => p.error) ? 1 : 0;
|
|
4072
|
+
}
|
|
4073
|
+
|
|
3131
4074
|
// src/worker.ts
|
|
3132
4075
|
var TURSO_OPEN_TIMEOUT_MS = 1e4;
|
|
3133
4076
|
async function openLive(credentials2) {
|
|
@@ -3273,20 +4216,20 @@ async function report(io, config2, credentials2, a) {
|
|
|
3273
4216
|
throw new UsageError(`unexpected argument ${extra[0]}`);
|
|
3274
4217
|
if (a.options.message !== undefined && a.options["message-file"] !== undefined)
|
|
3275
4218
|
throw new UsageError("pass --message or --message-file, not both");
|
|
3276
|
-
let
|
|
4219
|
+
let message2 = a.options.message ?? null;
|
|
3277
4220
|
const file = a.options["message-file"];
|
|
3278
4221
|
if (file !== undefined) {
|
|
3279
|
-
|
|
3280
|
-
if (
|
|
4222
|
+
message2 = file === "-" ? await io.readStdin?.() ?? null : await io.readFile(file);
|
|
4223
|
+
if (message2 === null)
|
|
3281
4224
|
throw new UsageError(`cannot read the message from ${file}`);
|
|
3282
4225
|
}
|
|
3283
|
-
if (!
|
|
4226
|
+
if (!message2?.trim() && phase !== "ready-to-merge")
|
|
3284
4227
|
throw new UsageError("--message is required: what you did or what you are doing (first line = summary)");
|
|
3285
4228
|
const ticket = currentTicket(io, config2, a.options.ticket);
|
|
3286
4229
|
return withContext(io, config2, credentials2, a.json, (ctx) => reportPhase(ctx, {
|
|
3287
4230
|
ticket,
|
|
3288
4231
|
phase,
|
|
3289
|
-
message,
|
|
4232
|
+
message: message2,
|
|
3290
4233
|
pr: a.options.pr ?? null,
|
|
3291
4234
|
sha: a.options.sha ?? null
|
|
3292
4235
|
}));
|
|
@@ -3306,6 +4249,12 @@ var USAGE = `Usage: armada <command> [options]
|
|
|
3306
4249
|
|
|
3307
4250
|
Commands:
|
|
3308
4251
|
status Tickets in flight, tickets ready to start and pull requests waiting
|
|
4252
|
+
status --all The same for every project registered by \`armada init\`
|
|
4253
|
+
doctor What this repository lacks to be run by Armada, with the fix for each
|
|
4254
|
+
init [--program-root <ISSUE-ID>] [--name <name>] [--slug <slug>]
|
|
4255
|
+
Open one pull request that installs or updates it all, create the
|
|
4256
|
+
missing Linear labels and register the project. The options are for
|
|
4257
|
+
a repository without armada.toml (Linear issue at the program root)
|
|
3309
4258
|
claim <ticket> --runtime <name> --handle <id> [--branch <name>]
|
|
3310
4259
|
Claim a ticket for this worker: In Progress, phase planning, runtime
|
|
3311
4260
|
label and an Agent claim comment; refused if another worker holds it
|
|
@@ -3328,8 +4277,9 @@ Options:
|
|
|
3328
4277
|
-v, --version Print the version
|
|
3329
4278
|
|
|
3330
4279
|
Keys (the environment always wins over the file):
|
|
3331
|
-
LINEAR_API_KEY Linear API key (required by status, claim, report, release)
|
|
3332
|
-
ARMADA_TURSO_URL Turso database URL (
|
|
4280
|
+
LINEAR_API_KEY Linear API key (required by status, init, claim, report, release)
|
|
4281
|
+
ARMADA_TURSO_URL Turso database URL (required by init and status --all; optional
|
|
4282
|
+
elsewhere; a file: URL works locally)
|
|
3333
4283
|
ARMADA_TURSO_TOKEN Turso database token
|
|
3334
4284
|
GITHUB_TOKEN GitHub token; falls back to GH_TOKEN, then \`gh auth token\`
|
|
3335
4285
|
|
|
@@ -3338,17 +4288,32 @@ Files:
|
|
|
3338
4288
|
credentials KEY=value lines, mode 0600, written by \`armada auth login\`
|
|
3339
4289
|
config.toml personal defaults: language, [turso] url, [dashboard] url
|
|
3340
4290
|
`;
|
|
3341
|
-
var VALUE_OPTIONS = [
|
|
4291
|
+
var VALUE_OPTIONS = [
|
|
4292
|
+
"runtime",
|
|
4293
|
+
"handle",
|
|
4294
|
+
"branch",
|
|
4295
|
+
"ticket",
|
|
4296
|
+
"message",
|
|
4297
|
+
"message-file",
|
|
4298
|
+
"pr",
|
|
4299
|
+
"sha",
|
|
4300
|
+
"reason",
|
|
4301
|
+
"program-root",
|
|
4302
|
+
"name",
|
|
4303
|
+
"slug"
|
|
4304
|
+
];
|
|
3342
4305
|
var COMMAND_OPTIONS = {
|
|
3343
4306
|
claim: ["runtime", "handle", "branch"],
|
|
3344
4307
|
report: ["ticket", "message", "message-file", "pr", "sha"],
|
|
3345
|
-
release: ["ticket", "reason"]
|
|
4308
|
+
release: ["ticket", "reason"],
|
|
4309
|
+
init: ["program-root", "name", "slug"]
|
|
3346
4310
|
};
|
|
3347
4311
|
function parseArgs(argv) {
|
|
3348
4312
|
const args = {
|
|
3349
4313
|
command: null,
|
|
3350
4314
|
rest: [],
|
|
3351
4315
|
json: false,
|
|
4316
|
+
all: false,
|
|
3352
4317
|
config: null,
|
|
3353
4318
|
help: false,
|
|
3354
4319
|
version: false,
|
|
@@ -3360,6 +4325,8 @@ function parseArgs(argv) {
|
|
|
3360
4325
|
const name = named?.[1];
|
|
3361
4326
|
if (a === "--json")
|
|
3362
4327
|
args.json = true;
|
|
4328
|
+
else if (a === "--all")
|
|
4329
|
+
args.all = true;
|
|
3363
4330
|
else if (a === "-h" || a === "--help")
|
|
3364
4331
|
args.help = true;
|
|
3365
4332
|
else if (a === "-v" || a === "--version")
|
|
@@ -3389,12 +4356,12 @@ async function findConfig(io, explicit) {
|
|
|
3389
4356
|
throw new UsageError(`${path} does not exist`);
|
|
3390
4357
|
return { path, text };
|
|
3391
4358
|
}
|
|
3392
|
-
for (let dir = resolve(io.cwd);; dir =
|
|
3393
|
-
const path =
|
|
4359
|
+
for (let dir = resolve(io.cwd);; dir = dirname2(dir)) {
|
|
4360
|
+
const path = join4(dir, CONFIG_FILE);
|
|
3394
4361
|
const text = await io.readFile(path);
|
|
3395
4362
|
if (text !== null)
|
|
3396
4363
|
return { path, text };
|
|
3397
|
-
if (
|
|
4364
|
+
if (dirname2(dir) === dir)
|
|
3398
4365
|
break;
|
|
3399
4366
|
}
|
|
3400
4367
|
throw new UsageError(`no ${CONFIG_FILE} found in ${io.cwd} or any parent directory. Add one at the repository root (see README).`);
|
|
@@ -3438,6 +4405,8 @@ async function run(argv, io) {
|
|
|
3438
4405
|
for (const name of Object.keys(args.options))
|
|
3439
4406
|
if (!allowed.includes(name))
|
|
3440
4407
|
throw new UsageError(`--${name} does not apply to ${args.command}`);
|
|
4408
|
+
if (args.all && args.command !== "status")
|
|
4409
|
+
throw new UsageError(`--all does not apply to ${args.command}`);
|
|
3441
4410
|
const worker2 = { claim, report, release }[args.command];
|
|
3442
4411
|
if (worker2) {
|
|
3443
4412
|
const { path, text } = await findConfig(io, args.config);
|
|
@@ -3447,7 +4416,20 @@ async function run(argv, io) {
|
|
|
3447
4416
|
}
|
|
3448
4417
|
if (args.command === "status") {
|
|
3449
4418
|
noExtra(args.rest);
|
|
3450
|
-
return await status2(io, args);
|
|
4419
|
+
return await (args.all ? statusAll(io, args.json) : status2(io, args));
|
|
4420
|
+
}
|
|
4421
|
+
if (args.command === "doctor") {
|
|
4422
|
+
noExtra(args.rest);
|
|
4423
|
+
return await doctor(io, args.json, version);
|
|
4424
|
+
}
|
|
4425
|
+
if (args.command === "init") {
|
|
4426
|
+
noExtra(args.rest);
|
|
4427
|
+
return await init(io, {
|
|
4428
|
+
armadaVersion: version,
|
|
4429
|
+
programRoot: args.options["program-root"] ?? null,
|
|
4430
|
+
name: args.options.name ?? null,
|
|
4431
|
+
slug: args.options.slug ?? null
|
|
4432
|
+
});
|
|
3451
4433
|
}
|
|
3452
4434
|
if (args.command === "auth") {
|
|
3453
4435
|
const [sub, ...extra] = args.rest;
|
|
@@ -3554,10 +4536,23 @@ function prompt(question, { hidden }) {
|
|
|
3554
4536
|
stdin.resume();
|
|
3555
4537
|
});
|
|
3556
4538
|
}
|
|
4539
|
+
var exec = (command, args, { cwd }) => new Promise((done, fail) => {
|
|
4540
|
+
const child = spawn(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
4541
|
+
let stdout = "";
|
|
4542
|
+
let stderr = "";
|
|
4543
|
+
child.stdout.setEncoding("utf8").on("data", (d) => {
|
|
4544
|
+
stdout += d;
|
|
4545
|
+
});
|
|
4546
|
+
child.stderr.setEncoding("utf8").on("data", (d) => {
|
|
4547
|
+
stderr += d;
|
|
4548
|
+
});
|
|
4549
|
+
child.on("error", fail);
|
|
4550
|
+
child.on("close", (code) => done({ code: code ?? 1, stdout, stderr }));
|
|
4551
|
+
});
|
|
3557
4552
|
var code = await run(process.argv.slice(2), {
|
|
3558
4553
|
cwd: process.cwd(),
|
|
3559
4554
|
env: process.env,
|
|
3560
|
-
readFile: (path) =>
|
|
4555
|
+
readFile: (path) => readFile3(path, "utf8").catch((err) => {
|
|
3561
4556
|
if (err.code === "ENOENT" || err.code === "ENOTDIR")
|
|
3562
4557
|
return null;
|
|
3563
4558
|
throw err;
|
|
@@ -3568,6 +4563,7 @@ var code = await run(process.argv.slice(2), {
|
|
|
3568
4563
|
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
3569
4564
|
prompt,
|
|
3570
4565
|
gitBranch,
|
|
3571
|
-
readStdin
|
|
4566
|
+
readStdin,
|
|
4567
|
+
exec
|
|
3572
4568
|
});
|
|
3573
4569
|
process.stdout.write("", () => process.exit(code));
|