@the-vibe-company/armada 0.1.11 → 0.1.13
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 +39 -6
- package/dist/armada.js +239 -245
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,12 +129,12 @@ armada merge 34 # or the pull request URL; --ticket ABC-12 when the
|
|
|
129
129
|
|
|
130
130
|
## Watch the fleet (dashboard)
|
|
131
131
|
|
|
132
|
-
`packages/dashboard` is a Next.js app
|
|
132
|
+
`packages/dashboard` is a Next.js app whose main page is the Fleet of the projects registered in Turso. With accounts, each person sees the projects of their organization; under the shared password, every project.
|
|
133
133
|
|
|
134
134
|
- **Waiting for you** comes first, across projects. It lists questions, blocked workers, plans to approve, hand-backs and silent workers, the most urgent first.
|
|
135
135
|
- **At work** has one row per ticket in flight. A row shows the project, the runtime and session, the six-step phase pipeline, time in phase, the last report, the pull request with its CI, and the flags (red CI, conflict, double claim).
|
|
136
136
|
- A filter shows one project. Each project shows whether its coordinator is active, from its last inbox read.
|
|
137
|
-
- **Answer** a question from its line in Waiting for you (an option of the question fills the answer in). **Ready to launch** lists the frontier with a Launch button and a profile picker, the routed profile preselected. Neither reaches a worker: each becomes a request in that project's coordinator inbox, signed with the name the viewer gives (remembered in a cookie
|
|
137
|
+
- **Answer** a question from its line in Waiting for you (an option of the question fills the answer in). **Ready to launch** lists the frontier with a Launch button and a profile picker, the routed profile preselected. Neither reaches a worker: each becomes a request in that project's coordinator inbox, signed with the signed-in person's name and address (with accounts) or with the name the viewer gives (under the shared password; remembered in a cookie, default `ARMADA_DASHBOARD_AUTHOR`), and shows as pending until the coordinator carries it out. The dashboard holds no runtime credential.
|
|
138
138
|
- It stays live without a reload. Linear and GitHub are read at most once a minute per project. Turso is read on every 5-second poll, so a worker's `armada report` shows within seconds.
|
|
139
139
|
- When Turso is unreachable, a banner says so and the view falls back to Linear and GitHub.
|
|
140
140
|
- The interface is in English or French (`ARMADA_DASHBOARD_LANGUAGE`, or the EN/FR switch).
|
|
@@ -148,18 +148,50 @@ ARMADA_DASHBOARD_PASSWORD=off ARMADA_DASHBOARD_DEMO=fleet ARMADA_TURSO_URL=file:
|
|
|
148
148
|
bun run demo:report WID-12 shipping "Opened the pull request" # watch the row change
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
+
The same with accounts (email and password work in development only; confirmation links are printed in the server log):
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
ARMADA_DASHBOARD_DEMO=fleet ARMADA_TURSO_URL=file:.demo/armada.db \
|
|
155
|
+
ARMADA_AUTH_DATABASE_URL=file:.demo/auth.db ARMADA_AUTH_SECRET="$(openssl rand -base64 32)" \
|
|
156
|
+
ARMADA_AUTH_URL=http://localhost:4822 ARMADA_AUTH_OWNER_EMAILS=you@example.com bun run dev
|
|
157
|
+
```
|
|
158
|
+
|
|
151
159
|
**Deploy on Vercel.** Create a project from this repository and set these options:
|
|
152
160
|
|
|
153
161
|
- Root Directory: `packages/dashboard`, with files outside the root directory included (the default). The framework preset is Next.js, and Bun installs the workspace from `bun.lock`.
|
|
154
|
-
- Environment variables: `ARMADA_DASHBOARD_PASSWORD
|
|
162
|
+
- Environment variables: the accounts variables below (or, until they are set, `ARMADA_DASHBOARD_PASSWORD`), `LINEAR_API_KEY`, `GITHUB_TOKEN`, `ARMADA_TURSO_URL` and `ARMADA_TURSO_TOKEN`. Optional: `ARMADA_REPOSITORIES` (the `owner/name` list shown while Turso is unreachable on a fresh server), `ARMADA_DASHBOARD_LANGUAGE` (`en` or `fr`), `ARMADA_DASHBOARD_SNAPSHOT_SECONDS` (Linear and GitHub read period, default 60) and `ARMADA_DASHBOARD_AUTHOR` (the name requests are signed with until a viewer gives theirs). Never add a runtime token (Conductor or other): the coordinator carries out every request.
|
|
155
163
|
- The keys stay on the server; the browser only receives the fleet reading.
|
|
156
164
|
|
|
157
|
-
**
|
|
165
|
+
**Accounts.** People sign in with GitHub (or email and password where enabled) and belong to organizations, with the roles owner, admin and member. Accounts, sessions, organizations and invitations live in a libSQL database of their own, separate from the fleet's Turso database; its schema is applied on first use. Accounts turn on only when every required variable below is set. With none of them set, the shared password applies, unchanged; with some but not all, the dashboard fails closed (503, naming the missing ones) rather than fall back to a password that shows every organization's projects.
|
|
166
|
+
|
|
167
|
+
| Variable | What |
|
|
168
|
+
| --- | --- |
|
|
169
|
+
| `ARMADA_AUTH_DATABASE_URL` | The accounts database, `libsql://...` (a new Turso database, not the fleet's), or `file:` locally |
|
|
170
|
+
| `ARMADA_AUTH_DATABASE_TOKEN` | Its token (not needed for `file:`) |
|
|
171
|
+
| `ARMADA_AUTH_SECRET` | Signs sessions: 32 characters at least, for example `openssl rand -base64 32`. Changing it signs everyone out |
|
|
172
|
+
| `ARMADA_AUTH_URL` | The dashboard's public address, for example `https://armada.example.com`: GitHub's callback and the links in emails |
|
|
173
|
+
| `ARMADA_AUTH_GITHUB_CLIENT_ID`, `ARMADA_AUTH_GITHUB_CLIENT_SECRET` | A GitHub OAuth app (GitHub > Settings > Developer settings > OAuth Apps) whose callback URL is `<ARMADA_AUTH_URL>/api/auth/callback/github` |
|
|
174
|
+
| `ARMADA_AUTH_OWNER_EMAILS` | Comma-separated addresses that may create an account without an invitation and create organizations |
|
|
175
|
+
| `ARMADA_AUTH_EMAIL_PASSWORD` | Optional, `on` or `off`: email and password sign-in, with address confirmation. Development only for now (default on): production ignores it until an email provider is plugged in, since confirmation links would sit in the server log |
|
|
176
|
+
|
|
177
|
+
- Accounts are by invitation: an account is created only for an owner address or an address with a pending invitation. The first owner to sign in creates the organization; the projects already registered, and those the CLI registers until it signs in, join the deployment's first organization. Organizations cannot be deleted.
|
|
178
|
+
- An owner or admin invites by email from the Organization page (the name in the top bar). No email provider is plugged in yet: messages (invitations, address confirmations) go to the server log, and the Organization page shows each pending invitation's link to copy and send. The invited person signs in with that address and accepts.
|
|
179
|
+
- Sessions are HttpOnly, SameSite=Lax cookies (Secure over https) valid 30 days; a revoked session can last up to five minutes (signed cookie cache). Without its accounts database the dashboard fails closed (503).
|
|
180
|
+
|
|
181
|
+
**Switch from the shared password to accounts** (a deployment that runs on `ARMADA_DASHBOARD_PASSWORD` keeps working until the redeploy of step 4; set every variable before it, since a partial set locks the dashboard):
|
|
182
|
+
|
|
183
|
+
1. Create the accounts database (`turso db create armada-accounts`, then `turso db show armada-accounts --url` and `turso db tokens create armada-accounts`) and set `ARMADA_AUTH_DATABASE_URL` and `ARMADA_AUTH_DATABASE_TOKEN`.
|
|
184
|
+
2. Create a GitHub OAuth app with the callback URL `https://<your dashboard>/api/auth/callback/github`, and set `ARMADA_AUTH_GITHUB_CLIENT_ID` and `ARMADA_AUTH_GITHUB_CLIENT_SECRET`.
|
|
185
|
+
3. Set `ARMADA_AUTH_SECRET`, `ARMADA_AUTH_URL` and `ARMADA_AUTH_OWNER_EMAILS` (at least the address of your GitHub account), for Production and Preview.
|
|
186
|
+
4. Redeploy. The dashboard now asks for an account; sign in with GitHub, create the organization (the registered projects join it) and invite the others.
|
|
187
|
+
5. Remove `ARMADA_DASHBOARD_PASSWORD` and `ARMADA_DASHBOARD_AUTHOR`: with accounts they are no longer read.
|
|
188
|
+
|
|
189
|
+
**Password (until accounts are configured).** The dashboard asks for `ARMADA_DASHBOARD_PASSWORD` before it shows anything, on every host, a custom domain included. Every page, the polling route and every server action answer 401 or send the viewer to the login page until then; only the build's static files are public.
|
|
158
190
|
|
|
159
191
|
- Use a long random value, for example `openssl rand -base64 24`, and set it for the Production and Preview environments. It stays on the server: never prefix it with `NEXT_PUBLIC_`.
|
|
160
192
|
- A correct password sets a signed session cookie (HttpOnly, Secure, SameSite=Lax) for 30 days. The signature is derived from the password, so changing it and redeploying logs every browser out. "Log out" in the top bar ends one session.
|
|
161
193
|
- Five wrong passwords from one address block it for 15 minutes, counted per server instance.
|
|
162
|
-
- Without the variable, the dashboard fails closed: every route answers 503 and names the variable. `ARMADA_DASHBOARD_PASSWORD=off` turns the password off for local development only; a production server refuses it the same way.
|
|
194
|
+
- Without the variable and without accounts, the dashboard fails closed: every route answers 503 and names the variable. `ARMADA_DASHBOARD_PASSWORD=off` turns the password off for local development only; a production server refuses it the same way.
|
|
163
195
|
- Vercel Authentication (Settings > Deployment Protection) is a useful second layer, but its standard protection leaves the production custom domain open (covering it takes a paid option), so it cannot replace the password.
|
|
164
196
|
|
|
165
197
|
One deployment covers one Linear workspace and one GitHub organization: its keys must read every registered project.
|
|
@@ -260,7 +292,8 @@ The program follows one convention: specs are direct children of the root titled
|
|
|
260
292
|
|
|
261
293
|
## Develop
|
|
262
294
|
|
|
263
|
-
|
|
295
|
+
Use the [Bun](https://bun.sh) version pinned in `package.json`'s `packageManager`
|
|
296
|
+
(currently 1.4.2). CI and release builds read the same pin.
|
|
264
297
|
|
|
265
298
|
```sh
|
|
266
299
|
bun install
|
package/dist/armada.js
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
-
for (let key of __getOwnPropNames(mod))
|
|
12
|
-
if (!__hasOwnProp.call(to, key))
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: () => mod[key],
|
|
15
|
-
enumerable: true
|
|
16
|
-
});
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
2
|
|
|
21
3
|
// src/main.ts
|
|
22
4
|
import { spawn, spawnSync } from "node:child_process";
|
|
@@ -1135,8 +1117,8 @@ function parseDate(ctx, c, endChr) {
|
|
|
1135
1117
|
if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
|
|
1136
1118
|
TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
|
|
1137
1119
|
if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) {
|
|
1138
|
-
let
|
|
1139
|
-
return readDate(ctx,
|
|
1120
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
1121
|
+
return readDate(ctx, t, 3, false, startPtr);
|
|
1140
1122
|
}
|
|
1141
1123
|
if (ctx.s.charCodeAt(ctx.p += 3) !== 58)
|
|
1142
1124
|
TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
|
|
@@ -1147,12 +1129,12 @@ function parseDate(ctx, c, endChr) {
|
|
|
1147
1129
|
;
|
|
1148
1130
|
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
1149
1131
|
if (c === 90 || c === 122) {
|
|
1150
|
-
let
|
|
1151
|
-
return readDate(ctx,
|
|
1132
|
+
let t = ctx.s.slice(startPtr, ++ctx.p);
|
|
1133
|
+
return readDate(ctx, t, 1, unsafeSeparator, startPtr, "[+00:00]");
|
|
1152
1134
|
}
|
|
1153
1135
|
if (c === 43 || c === 45) {
|
|
1154
|
-
let
|
|
1155
|
-
return readDate(ctx,
|
|
1136
|
+
let t = ctx.s.slice(startPtr, ctx.p += 6);
|
|
1137
|
+
return readDate(ctx, t, 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
|
|
1156
1138
|
}
|
|
1157
1139
|
}
|
|
1158
1140
|
let t = ctx.s.slice(startPtr, ctx.p);
|
|
@@ -1735,15 +1717,15 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
1735
1717
|
continue;
|
|
1736
1718
|
}
|
|
1737
1719
|
known.push([path, r, ["labels", "profile"]]);
|
|
1738
|
-
const
|
|
1739
|
-
const ok = Array.isArray(
|
|
1720
|
+
const labels = r.labels;
|
|
1721
|
+
const ok = Array.isArray(labels) && labels.length && labels.every((l) => typeof l === "string" && routingLabelKey(l));
|
|
1740
1722
|
if (!ok)
|
|
1741
1723
|
problems.push(`"${path}.labels" must be a non-empty list of Linear label names, each with a letter or digit`);
|
|
1742
1724
|
const profile = str(r, path, "profile");
|
|
1743
1725
|
if (profile && !Object.hasOwn(profiles, profile))
|
|
1744
1726
|
problems.push(`"${path}.profile" is "${profile}", but there is no [conductor.profiles.${profile}]`);
|
|
1745
1727
|
if (ok && profile)
|
|
1746
|
-
routing.push({ labels:
|
|
1728
|
+
routing.push({ labels: labels.map((l) => l.trim()), profile });
|
|
1747
1729
|
}
|
|
1748
1730
|
if (Array.isArray(routingRaw) && routingRaw.length && conductorT.default_profile === undefined)
|
|
1749
1731
|
problems.push(`"conductor.default_profile" is required with [[conductor.routing]], for tickets no rule matches`);
|
|
@@ -2114,6 +2096,16 @@ var MIGRATIONS = [
|
|
|
2114
2096
|
)`,
|
|
2115
2097
|
"CREATE INDEX IF NOT EXISTS inbox_requests_by_question ON inbox_requests (project, question)"
|
|
2116
2098
|
]
|
|
2099
|
+
},
|
|
2100
|
+
{
|
|
2101
|
+
version: 5,
|
|
2102
|
+
statements: [
|
|
2103
|
+
`CREATE TABLE IF NOT EXISTS project_organizations (
|
|
2104
|
+
project TEXT PRIMARY KEY,
|
|
2105
|
+
organization TEXT NOT NULL,
|
|
2106
|
+
assigned_at TEXT NOT NULL
|
|
2107
|
+
)`
|
|
2108
|
+
]
|
|
2117
2109
|
}
|
|
2118
2110
|
];
|
|
2119
2111
|
var SCHEMA_VERSION = MIGRATIONS.at(-1)?.version ?? 0;
|
|
@@ -2182,12 +2174,14 @@ async function ensureProject(db, p, now = new Date) {
|
|
|
2182
2174
|
});
|
|
2183
2175
|
}
|
|
2184
2176
|
async function listProjects(db) {
|
|
2185
|
-
const rs = await db.execute(
|
|
2177
|
+
const rs = await db.execute(`SELECT p.slug, p.name, p.repository, p.program_root, o.organization, p.created_at, p.updated_at
|
|
2178
|
+
FROM projects p LEFT JOIN project_organizations o ON o.project = p.slug ORDER BY p.slug`);
|
|
2186
2179
|
return rs.rows.map((r) => ({
|
|
2187
2180
|
slug: String(r.slug),
|
|
2188
2181
|
name: String(r.name),
|
|
2189
2182
|
repository: String(r.repository),
|
|
2190
2183
|
programRoot: String(r.program_root),
|
|
2184
|
+
organization: r.organization === null ? null : String(r.organization),
|
|
2191
2185
|
createdAt: String(r.created_at),
|
|
2192
2186
|
updatedAt: String(r.updated_at)
|
|
2193
2187
|
}));
|
|
@@ -3413,8 +3407,8 @@ function attachPullRequests(program, forge) {
|
|
|
3413
3407
|
}
|
|
3414
3408
|
return program.issues.map((issue) => {
|
|
3415
3409
|
const prs = issue.prs.map((p) => {
|
|
3416
|
-
const
|
|
3417
|
-
return
|
|
3410
|
+
const live = byUrl.get(p.url);
|
|
3411
|
+
return live ? { ...p, ...live, title: live.title || p.title } : p;
|
|
3418
3412
|
});
|
|
3419
3413
|
for (const p of byTicket.get(issue.id) ?? [])
|
|
3420
3414
|
if (!prs.some((x) => x.url === p.url))
|
|
@@ -4713,11 +4707,11 @@ var SKILLS_LOCK_FILE = "skills-lock.json";
|
|
|
4713
4707
|
var CONDUCTOR_SETTINGS = ".conductor/settings.toml";
|
|
4714
4708
|
var GITIGNORE = ".gitignore";
|
|
4715
4709
|
var SHIP_ARTIFACTS = "plans/ship-pr-dev/";
|
|
4716
|
-
var ok = (id,
|
|
4717
|
-
var bad = (id, level,
|
|
4710
|
+
var ok = (id, message) => ({ id, level: "ok", message, fix: null });
|
|
4711
|
+
var bad = (id, level, message, fix) => ({
|
|
4718
4712
|
id,
|
|
4719
4713
|
level,
|
|
4720
|
-
message
|
|
4714
|
+
message,
|
|
4721
4715
|
fix
|
|
4722
4716
|
});
|
|
4723
4717
|
var skillDir = (name) => `${AGENTS_SKILLS_DIR}/${name}`;
|
|
@@ -4946,7 +4940,7 @@ function buildStatus({
|
|
|
4946
4940
|
forge,
|
|
4947
4941
|
forgeError = null,
|
|
4948
4942
|
lastEvents,
|
|
4949
|
-
live
|
|
4943
|
+
live,
|
|
4950
4944
|
extraWarnings = [],
|
|
4951
4945
|
now
|
|
4952
4946
|
}) {
|
|
@@ -4956,7 +4950,7 @@ function buildStatus({
|
|
|
4956
4950
|
now: now.getTime(),
|
|
4957
4951
|
silentAfterMinutes: config.policy.silentAfterMinutes,
|
|
4958
4952
|
...lastEvents ? { lastEvents } : {},
|
|
4959
|
-
...
|
|
4953
|
+
...live ? { live } : {}
|
|
4960
4954
|
});
|
|
4961
4955
|
const phaseOf = new Map(lanes.map((l) => [l.issue.id, l.phase]));
|
|
4962
4956
|
const prRef = (p) => ({
|
|
@@ -4986,7 +4980,7 @@ function buildStatus({
|
|
|
4986
4980
|
phaseSource: l.phaseSource,
|
|
4987
4981
|
runtime: l.runtime,
|
|
4988
4982
|
handle: l.handle,
|
|
4989
|
-
profile:
|
|
4983
|
+
profile: live?.handles?.[l.issue.id]?.profile ?? l.claim?.profile ?? null,
|
|
4990
4984
|
agent: l.agent,
|
|
4991
4985
|
since: l.since,
|
|
4992
4986
|
lastUpdate: l.lastUpdate,
|
|
@@ -5031,13 +5025,13 @@ async function readStatusSources(config, opts) {
|
|
|
5031
5025
|
repository: config.github.repository,
|
|
5032
5026
|
...opts.fetch ? { fetch: opts.fetch } : {},
|
|
5033
5027
|
now
|
|
5034
|
-
}).then((
|
|
5028
|
+
}).then((forge) => ({ forge, forgeError: null }), (err) => ({ forge: null, forgeError: err instanceof Error ? err.message : String(err) })) : Promise.resolve({ forge: null, forgeError: "no GitHub token (set GITHUB_TOKEN or run gh auth login)" });
|
|
5035
5029
|
const [program, forge] = await Promise.all([programP, forgeP]);
|
|
5036
5030
|
return { program, ...forge };
|
|
5037
5031
|
}
|
|
5038
5032
|
async function loadStatus(config, opts) {
|
|
5039
5033
|
const now = opts.now ?? (() => new Date);
|
|
5040
|
-
const eventsP = opts.lastEvents ? opts.lastEvents().then((
|
|
5034
|
+
const eventsP = opts.lastEvents ? opts.lastEvents().then((events) => ({ events }), (err) => ({
|
|
5041
5035
|
warning: `Turso could not be read (${err instanceof Error ? err.message : String(err)}); silence is measured from Linear only`
|
|
5042
5036
|
})) : Promise.resolve({});
|
|
5043
5037
|
const [{ program, forge, forgeError }, events] = await Promise.all([readStatusSources(config, opts), eventsP]);
|
|
@@ -5052,13 +5046,13 @@ async function loadStatus(config, opts) {
|
|
|
5052
5046
|
});
|
|
5053
5047
|
}
|
|
5054
5048
|
// package.json
|
|
5055
|
-
var version = "0.1.
|
|
5049
|
+
var version = "0.1.13";
|
|
5056
5050
|
|
|
5057
5051
|
// src/io.ts
|
|
5058
5052
|
class UsageError extends Error {
|
|
5059
5053
|
next;
|
|
5060
|
-
constructor(
|
|
5061
|
-
super(
|
|
5054
|
+
constructor(message, next = null) {
|
|
5055
|
+
super(message);
|
|
5062
5056
|
this.next = next;
|
|
5063
5057
|
}
|
|
5064
5058
|
}
|
|
@@ -5076,14 +5070,14 @@ async function loadMachine(io) {
|
|
|
5076
5070
|
return { paths, store, personal };
|
|
5077
5071
|
}
|
|
5078
5072
|
async function loadCredentials(io) {
|
|
5079
|
-
const
|
|
5080
|
-
const
|
|
5073
|
+
const machine = await loadMachine(io);
|
|
5074
|
+
const credentials = resolveCredentials({
|
|
5081
5075
|
env: io.env,
|
|
5082
5076
|
ghToken: io.ghToken,
|
|
5083
|
-
...
|
|
5084
|
-
...
|
|
5077
|
+
...machine.store ? { store: machine.store.values } : {},
|
|
5078
|
+
...machine.personal ? { personal: machine.personal.config } : {}
|
|
5085
5079
|
});
|
|
5086
|
-
return { machine
|
|
5080
|
+
return { machine, credentials };
|
|
5087
5081
|
}
|
|
5088
5082
|
var describeSource = (s) => {
|
|
5089
5083
|
switch (s.kind) {
|
|
@@ -5103,8 +5097,8 @@ function requirePaths(paths) {
|
|
|
5103
5097
|
return paths;
|
|
5104
5098
|
throw new UsageError(`neither HOME nor XDG_CONFIG_HOME is set, so there is no place to store keys on this machine. Set ${STORED_KEYS.map((k) => k.variable).join(", ")} in the environment instead.`);
|
|
5105
5099
|
}
|
|
5106
|
-
function storeWarnings(
|
|
5107
|
-
const store =
|
|
5100
|
+
function storeWarnings(machine) {
|
|
5101
|
+
const store = machine.store;
|
|
5108
5102
|
if (!store?.exists)
|
|
5109
5103
|
return [];
|
|
5110
5104
|
const warnings = [];
|
|
@@ -5115,17 +5109,17 @@ function storeWarnings(machine2) {
|
|
|
5115
5109
|
return warnings;
|
|
5116
5110
|
}
|
|
5117
5111
|
async function authLogin(io) {
|
|
5118
|
-
const { machine
|
|
5119
|
-
const
|
|
5120
|
-
if (!
|
|
5112
|
+
const { machine, credentials } = await loadCredentials(io);
|
|
5113
|
+
const missing = missingKeys(credentials);
|
|
5114
|
+
if (!missing.length) {
|
|
5121
5115
|
io.stdout("Every Armada key is already set. Run `armada auth status` to see where each comes from.\n");
|
|
5122
5116
|
return 0;
|
|
5123
5117
|
}
|
|
5124
|
-
const paths = requirePaths(
|
|
5118
|
+
const paths = requirePaths(machine.paths);
|
|
5125
5119
|
if (!io.interactive || !io.prompt) {
|
|
5126
|
-
const width = Math.max(...
|
|
5120
|
+
const width = Math.max(...missing.map((k) => k.variable.length));
|
|
5127
5121
|
io.stderr(`armada: auth login needs an interactive terminal. Set these environment variables instead:
|
|
5128
|
-
${
|
|
5122
|
+
${missing.map((k) => ` ${k.variable.padEnd(width)} ${k.label}: ${k.hint}`).join(`
|
|
5129
5123
|
`)}
|
|
5130
5124
|
or add them as KEY=value lines to ${paths.credentials} (mode 0600).
|
|
5131
5125
|
`);
|
|
@@ -5135,7 +5129,7 @@ or add them as KEY=value lines to ${paths.credentials} (mode 0600).
|
|
|
5135
5129
|
Leave an answer empty to skip it.
|
|
5136
5130
|
`);
|
|
5137
5131
|
const updates = {};
|
|
5138
|
-
for (const key of
|
|
5132
|
+
for (const key of missing) {
|
|
5139
5133
|
io.stderr(`
|
|
5140
5134
|
${key.label}: ${key.hint}
|
|
5141
5135
|
`);
|
|
@@ -5162,52 +5156,52 @@ Saved ${saved.join(", ")} in ${paths.credentials}.
|
|
|
5162
5156
|
io.stdout(`
|
|
5163
5157
|
Nothing saved.
|
|
5164
5158
|
`);
|
|
5165
|
-
const skipped =
|
|
5159
|
+
const skipped = missing.filter((k) => !saved.includes(k.variable)).map((k) => k.variable);
|
|
5166
5160
|
if (skipped.length)
|
|
5167
5161
|
io.stdout(`Still missing: ${skipped.join(", ")}. Run \`armada auth login\` again to add them.
|
|
5168
5162
|
`);
|
|
5169
5163
|
return 0;
|
|
5170
5164
|
}
|
|
5171
|
-
function buildAuthStatus(
|
|
5165
|
+
function buildAuthStatus(machine, credentials) {
|
|
5172
5166
|
const keys = [
|
|
5173
|
-
...STORED_KEYS.map((k) => ({ variable: k.variable, label: k.label, source:
|
|
5174
|
-
{ variable: "GITHUB_TOKEN", label: "GitHub token", source:
|
|
5167
|
+
...STORED_KEYS.map((k) => ({ variable: k.variable, label: k.label, source: credentials.sources[k.name] })),
|
|
5168
|
+
{ variable: "GITHUB_TOKEN", label: "GitHub token", source: credentials.sources.githubToken }
|
|
5175
5169
|
].map((k) => ({ ...k, present: k.source !== null }));
|
|
5176
5170
|
return {
|
|
5177
5171
|
schemaVersion: 1,
|
|
5178
5172
|
keys,
|
|
5179
|
-
credentialsFile:
|
|
5180
|
-
path:
|
|
5181
|
-
exists:
|
|
5182
|
-
mode:
|
|
5173
|
+
credentialsFile: machine.store ? {
|
|
5174
|
+
path: machine.store.path,
|
|
5175
|
+
exists: machine.store.exists,
|
|
5176
|
+
mode: machine.store.mode === null ? null : octal(machine.store.mode)
|
|
5183
5177
|
} : null,
|
|
5184
|
-
personalConfig:
|
|
5185
|
-
warnings: storeWarnings(
|
|
5178
|
+
personalConfig: machine.paths && machine.personal ? { path: machine.paths.config, exists: machine.personal.exists } : null,
|
|
5179
|
+
warnings: storeWarnings(machine)
|
|
5186
5180
|
};
|
|
5187
5181
|
}
|
|
5188
|
-
function renderAuthStatus(
|
|
5189
|
-
const width = Math.max(...
|
|
5182
|
+
function renderAuthStatus(status) {
|
|
5183
|
+
const width = Math.max(...status.keys.map((k) => k.variable.length));
|
|
5190
5184
|
const lines = ["Armada keys"];
|
|
5191
|
-
for (const k of
|
|
5185
|
+
for (const k of status.keys) {
|
|
5192
5186
|
const where = k.source ? describeSource(k.source) : k.variable === "GITHUB_TOKEN" ? "set GITHUB_TOKEN or run `gh auth login`" : `set ${k.variable} or run \`armada auth login\``;
|
|
5193
5187
|
lines.push(` ${k.variable.padEnd(width)} ${(k.present ? "set" : "missing").padEnd(7)} ${where}`);
|
|
5194
5188
|
}
|
|
5195
5189
|
lines.push("");
|
|
5196
|
-
const file =
|
|
5190
|
+
const file = status.credentialsFile;
|
|
5197
5191
|
lines.push(file ? `Credentials file ${file.path}${file.exists ? ` (mode ${file.mode})` : " (not created yet)"}` : "Credentials file none: neither HOME nor XDG_CONFIG_HOME is set");
|
|
5198
|
-
if (
|
|
5199
|
-
lines.push(`Personal config ${
|
|
5200
|
-
for (const w of
|
|
5192
|
+
if (status.personalConfig)
|
|
5193
|
+
lines.push(`Personal config ${status.personalConfig.path}${status.personalConfig.exists ? "" : " (not created yet)"}`);
|
|
5194
|
+
for (const w of status.warnings)
|
|
5201
5195
|
lines.push(`! ${w}`);
|
|
5202
5196
|
return `${lines.join(`
|
|
5203
5197
|
`)}
|
|
5204
5198
|
`;
|
|
5205
5199
|
}
|
|
5206
5200
|
async function authStatus(io, json) {
|
|
5207
|
-
const { machine
|
|
5208
|
-
const
|
|
5209
|
-
io.stdout(json ? `${JSON.stringify(
|
|
5210
|
-
` : renderAuthStatus(
|
|
5201
|
+
const { machine, credentials } = await loadCredentials(io);
|
|
5202
|
+
const status = buildAuthStatus(machine, credentials);
|
|
5203
|
+
io.stdout(json ? `${JSON.stringify(status, null, 2)}
|
|
5204
|
+
` : renderAuthStatus(status));
|
|
5211
5205
|
return 0;
|
|
5212
5206
|
}
|
|
5213
5207
|
async function authLogout(io) {
|
|
@@ -5222,9 +5216,9 @@ async function authLogout(io) {
|
|
|
5222
5216
|
io.stdout(`Removed ${stored.map((k) => k.variable).join(", ")} from ${paths.credentials}.
|
|
5223
5217
|
`);
|
|
5224
5218
|
}
|
|
5225
|
-
const
|
|
5226
|
-
if (
|
|
5227
|
-
io.stdout(`Still set in the environment, and still used: ${
|
|
5219
|
+
const fromEnv = STORED_KEYS.filter((k) => io.env[k.variable]?.trim()).map((k) => k.variable);
|
|
5220
|
+
if (fromEnv.length)
|
|
5221
|
+
io.stdout(`Still set in the environment, and still used: ${fromEnv.join(", ")}. Unset them to stop using them.
|
|
5228
5222
|
`);
|
|
5229
5223
|
return 0;
|
|
5230
5224
|
}
|
|
@@ -5256,7 +5250,7 @@ function renderBrief(b) {
|
|
|
5256
5250
|
return out.join(`
|
|
5257
5251
|
`);
|
|
5258
5252
|
}
|
|
5259
|
-
async function brief2(io,
|
|
5253
|
+
async function brief2(io, config, credentials, a, version) {
|
|
5260
5254
|
const [ticket, ...extra] = a.rest;
|
|
5261
5255
|
if (!ticket)
|
|
5262
5256
|
throw new UsageError('brief needs a ticket: armada brief <ticket> [--profile <name> [--reason "<why>"]]');
|
|
@@ -5270,24 +5264,24 @@ async function brief2(io, config2, credentials2, a, version2) {
|
|
|
5270
5264
|
if (reason && !profile)
|
|
5271
5265
|
throw new UsageError("--reason goes with --profile: it says why the routed profile is not used");
|
|
5272
5266
|
try {
|
|
5273
|
-
checkRequestedProfile(
|
|
5267
|
+
checkRequestedProfile(config, profile);
|
|
5274
5268
|
} catch (err) {
|
|
5275
5269
|
if (err instanceof ProfileError)
|
|
5276
5270
|
throw new UsageError(err.message);
|
|
5277
5271
|
throw err;
|
|
5278
5272
|
}
|
|
5279
|
-
if (!
|
|
5273
|
+
if (!credentials.linearApiKey)
|
|
5280
5274
|
throw missingKey(LINEAR_KEY);
|
|
5281
5275
|
let b;
|
|
5282
5276
|
try {
|
|
5283
|
-
b = await loadBrief(
|
|
5284
|
-
linearApiKey:
|
|
5277
|
+
b = await loadBrief(config, {
|
|
5278
|
+
linearApiKey: credentials.linearApiKey,
|
|
5285
5279
|
ticket: ticket.toUpperCase(),
|
|
5286
5280
|
profile,
|
|
5287
5281
|
reason,
|
|
5288
|
-
version
|
|
5282
|
+
version,
|
|
5289
5283
|
env: io.env,
|
|
5290
|
-
stored: STORED_KEYS.filter((k) =>
|
|
5284
|
+
stored: STORED_KEYS.filter((k) => credentials.sources[k.name]?.kind === "store").map((k) => k.variable),
|
|
5291
5285
|
...io.fetch ? { fetch: io.fetch } : {},
|
|
5292
5286
|
...io.now ? { now: io.now } : {}
|
|
5293
5287
|
});
|
|
@@ -5404,9 +5398,9 @@ async function labelChecks(io, root) {
|
|
|
5404
5398
|
const text = await fsRepoView(root).readFile(CONFIG_FILE);
|
|
5405
5399
|
if (text === null)
|
|
5406
5400
|
return [];
|
|
5407
|
-
let
|
|
5401
|
+
let config;
|
|
5408
5402
|
try {
|
|
5409
|
-
|
|
5403
|
+
config = parseConfig(text, CONFIG_FILE);
|
|
5410
5404
|
} catch (err) {
|
|
5411
5405
|
if (err instanceof ConfigError)
|
|
5412
5406
|
return [];
|
|
@@ -5423,7 +5417,7 @@ async function labelChecks(io, root) {
|
|
|
5423
5417
|
}
|
|
5424
5418
|
];
|
|
5425
5419
|
try {
|
|
5426
|
-
const state = await readLabels(
|
|
5420
|
+
const state = await readLabels(config, { apiKey: linearApiKey, ...io.fetch ? { fetch: io.fetch } : {} });
|
|
5427
5421
|
return checkLabels(state);
|
|
5428
5422
|
} catch (err) {
|
|
5429
5423
|
return [
|
|
@@ -5481,11 +5475,11 @@ async function doctor(io, json, armadaVersion) {
|
|
|
5481
5475
|
|
|
5482
5476
|
// src/worker.ts
|
|
5483
5477
|
var TURSO_OPEN_TIMEOUT_MS = 1e4;
|
|
5484
|
-
async function openLive(
|
|
5485
|
-
if (!
|
|
5478
|
+
async function openLive(credentials) {
|
|
5479
|
+
if (!credentials.tursoUrl)
|
|
5486
5480
|
return { db: null, warning: "Turso is not configured (ARMADA_TURSO_URL); live activity is not recorded" };
|
|
5487
5481
|
let timer;
|
|
5488
|
-
const opening = openTurso({ url:
|
|
5482
|
+
const opening = openTurso({ url: credentials.tursoUrl, token: credentials.tursoToken });
|
|
5489
5483
|
try {
|
|
5490
5484
|
const db = await Promise.race([
|
|
5491
5485
|
opening,
|
|
@@ -5502,79 +5496,79 @@ async function openLive(credentials2) {
|
|
|
5502
5496
|
clearTimeout(timer);
|
|
5503
5497
|
}
|
|
5504
5498
|
}
|
|
5505
|
-
function statusEvents(
|
|
5506
|
-
if (!
|
|
5499
|
+
function statusEvents(config, credentials) {
|
|
5500
|
+
if (!credentials.tursoUrl)
|
|
5507
5501
|
return;
|
|
5508
5502
|
return async () => {
|
|
5509
|
-
const { db, warning } = await openLive(
|
|
5503
|
+
const { db, warning } = await openLive(credentials);
|
|
5510
5504
|
if (!db)
|
|
5511
5505
|
throw new Error(warning ?? "Turso unavailable");
|
|
5512
5506
|
try {
|
|
5513
|
-
return await lastEventTimes(db,
|
|
5507
|
+
return await lastEventTimes(db, config.project.slug);
|
|
5514
5508
|
} finally {
|
|
5515
5509
|
db.close();
|
|
5516
5510
|
}
|
|
5517
5511
|
};
|
|
5518
5512
|
}
|
|
5519
|
-
function currentTicket(io,
|
|
5520
|
-
const
|
|
5521
|
-
const id = explicit?.trim() ||
|
|
5513
|
+
function currentTicket(io, config, explicit) {
|
|
5514
|
+
const fromEnv = io.env.ARMADA_TICKET?.trim();
|
|
5515
|
+
const id = explicit?.trim() || fromEnv || (() => {
|
|
5522
5516
|
const branch = io.gitBranch?.();
|
|
5523
|
-
return branch ? ticketFromBranch(branch,
|
|
5517
|
+
return branch ? ticketFromBranch(branch, config.tracker.programRoot) : null;
|
|
5524
5518
|
})();
|
|
5525
5519
|
if (!id)
|
|
5526
5520
|
throw new UsageError("which ticket? pass --ticket <id>, set ARMADA_TICKET, or run on the ticket's branch");
|
|
5527
5521
|
return id.toUpperCase();
|
|
5528
5522
|
}
|
|
5529
|
-
async function context(io,
|
|
5530
|
-
if (!
|
|
5523
|
+
async function context(io, config, credentials) {
|
|
5524
|
+
if (!credentials.linearApiKey)
|
|
5531
5525
|
throw missingKey(LINEAR_KEY);
|
|
5532
5526
|
const linearOpts = {
|
|
5533
|
-
apiKey:
|
|
5534
|
-
labels:
|
|
5527
|
+
apiKey: credentials.linearApiKey,
|
|
5528
|
+
labels: config.tracker.labels,
|
|
5535
5529
|
...io.fetch ? { fetch: io.fetch } : {}
|
|
5536
5530
|
};
|
|
5537
|
-
const
|
|
5538
|
-
let
|
|
5539
|
-
const token =
|
|
5531
|
+
const linear = io.linearWriter ? io.linearWriter(linearOpts) : createLinearWriter(linearOpts);
|
|
5532
|
+
let live = null;
|
|
5533
|
+
const token = credentials.githubToken;
|
|
5540
5534
|
const ctx = {
|
|
5541
|
-
config
|
|
5542
|
-
linear
|
|
5535
|
+
config,
|
|
5536
|
+
linear,
|
|
5543
5537
|
turso: () => {
|
|
5544
|
-
|
|
5545
|
-
return
|
|
5538
|
+
live ??= openLive(credentials);
|
|
5539
|
+
return live;
|
|
5546
5540
|
},
|
|
5547
5541
|
readPull: token ? (number) => fetchPullRequest({
|
|
5548
5542
|
token,
|
|
5549
|
-
repository:
|
|
5543
|
+
repository: config.github.repository,
|
|
5550
5544
|
number,
|
|
5551
5545
|
...io.fetch ? { fetch: io.fetch } : {}
|
|
5552
5546
|
}) : null,
|
|
5553
5547
|
now: io.now ?? (() => new Date)
|
|
5554
5548
|
};
|
|
5555
5549
|
const close = async () => {
|
|
5556
|
-
const opened = await
|
|
5550
|
+
const opened = await live;
|
|
5557
5551
|
opened?.db?.close();
|
|
5558
5552
|
};
|
|
5559
5553
|
return { ctx, close };
|
|
5560
5554
|
}
|
|
5561
|
-
function print(io,
|
|
5555
|
+
function print(io, outcome, json) {
|
|
5562
5556
|
if (json) {
|
|
5563
|
-
io.stdout(`${JSON.stringify(
|
|
5557
|
+
io.stdout(`${JSON.stringify(outcome, null, 2)}
|
|
5564
5558
|
`);
|
|
5565
5559
|
return;
|
|
5566
5560
|
}
|
|
5567
|
-
const out = [...
|
|
5568
|
-
const s =
|
|
5561
|
+
const out = [...outcome.lines];
|
|
5562
|
+
const s = outcome.state;
|
|
5569
5563
|
if (s)
|
|
5570
5564
|
out.push(`Now: ${s.status} · phase ${s.phase ?? "none"} · runtime ${s.runtime ?? "none"} · profile ${s.profile ?? "none"}`);
|
|
5571
|
-
out.push(
|
|
5572
|
-
if (
|
|
5573
|
-
if (!
|
|
5565
|
+
out.push(outcome.url);
|
|
5566
|
+
if (outcome.inbox) {
|
|
5567
|
+
if (!outcome.inbox.length)
|
|
5574
5568
|
out.push("Inbox: nothing waiting for you.");
|
|
5575
5569
|
else {
|
|
5576
|
-
out.push(`Inbox (${
|
|
5577
|
-
for (const item of
|
|
5570
|
+
out.push(`Inbox (${outcome.inbox.length}) — read and act on these:`);
|
|
5571
|
+
for (const item of outcome.inbox)
|
|
5578
5572
|
out.push(` #${item.id} ${item.kind}${item.author ? ` from ${item.author}` : ""} · ${item.createdAt}`, ...item.body.split(`
|
|
5579
5573
|
`).map((l) => ` ${l}`));
|
|
5580
5574
|
}
|
|
@@ -5582,7 +5576,7 @@ function print(io, outcome2, json) {
|
|
|
5582
5576
|
io.stdout(`${out.join(`
|
|
5583
5577
|
`)}
|
|
5584
5578
|
`);
|
|
5585
|
-
for (const w of
|
|
5579
|
+
for (const w of outcome.warnings)
|
|
5586
5580
|
io.stderr(`armada: warning: ${w}
|
|
5587
5581
|
`);
|
|
5588
5582
|
}
|
|
@@ -5599,8 +5593,8 @@ async function readMessage(io, options) {
|
|
|
5599
5593
|
throw new UsageError(`${file === "-" ? "standard input" : `message file ${file}`} is empty or whitespace-only`, 'pass --message "<text>" or pipe a non-empty message into --message-file -');
|
|
5600
5594
|
return text;
|
|
5601
5595
|
}
|
|
5602
|
-
async function withContext(io,
|
|
5603
|
-
const { ctx, close } = await context(io,
|
|
5596
|
+
async function withContext(io, config, credentials, json, act) {
|
|
5597
|
+
const { ctx, close } = await context(io, config, credentials);
|
|
5604
5598
|
try {
|
|
5605
5599
|
print(io, await act(ctx), json);
|
|
5606
5600
|
return 0;
|
|
@@ -5608,7 +5602,7 @@ async function withContext(io, config2, credentials2, json, act) {
|
|
|
5608
5602
|
await close();
|
|
5609
5603
|
}
|
|
5610
5604
|
}
|
|
5611
|
-
async function claim(io,
|
|
5605
|
+
async function claim(io, config, credentials, a) {
|
|
5612
5606
|
const [ticket, ...extra] = a.rest;
|
|
5613
5607
|
if (!ticket)
|
|
5614
5608
|
throw new UsageError("claim needs a ticket: armada claim <ticket> --runtime <name> --handle <id>");
|
|
@@ -5623,7 +5617,7 @@ async function claim(io, config2, credentials2, a) {
|
|
|
5623
5617
|
if (reason && !profile)
|
|
5624
5618
|
throw new UsageError("--reason goes with --profile: it says why the routed profile is not used");
|
|
5625
5619
|
try {
|
|
5626
|
-
checkRequestedProfile(
|
|
5620
|
+
checkRequestedProfile(config, profile);
|
|
5627
5621
|
} catch (err) {
|
|
5628
5622
|
if (err instanceof ProfileError)
|
|
5629
5623
|
throw new UsageError(err.message);
|
|
@@ -5631,7 +5625,7 @@ async function claim(io, config2, credentials2, a) {
|
|
|
5631
5625
|
}
|
|
5632
5626
|
if (!handle)
|
|
5633
5627
|
throw new UsageError("--handle is required: the runtime's id for this session, e.g. <workspace>/<session>");
|
|
5634
|
-
return withContext(io,
|
|
5628
|
+
return withContext(io, config, credentials, a.json, (ctx) => claimTicket(ctx, {
|
|
5635
5629
|
ticket: ticket.toUpperCase(),
|
|
5636
5630
|
runtime,
|
|
5637
5631
|
handle,
|
|
@@ -5640,37 +5634,37 @@ async function claim(io, config2, credentials2, a) {
|
|
|
5640
5634
|
reason
|
|
5641
5635
|
}));
|
|
5642
5636
|
}
|
|
5643
|
-
async function report(io,
|
|
5637
|
+
async function report(io, config, credentials, a) {
|
|
5644
5638
|
const [phase, ...extra] = a.rest;
|
|
5645
5639
|
if (!phase || !isLabelPhase(phase))
|
|
5646
5640
|
throw new UsageError(`report needs a phase: ${LABEL_PHASES.join(", ")}${phase ? ` (got "${phase}")` : ""}`);
|
|
5647
5641
|
if (extra.length)
|
|
5648
5642
|
throw new UsageError(`unexpected argument ${extra[0]}`);
|
|
5649
|
-
const
|
|
5650
|
-
if (!
|
|
5643
|
+
const message = await readMessage(io, a.options);
|
|
5644
|
+
if (!message?.trim() && phase !== "ready-to-merge")
|
|
5651
5645
|
throw new UsageError("--message is required: what you did or what you are doing (first line = summary)");
|
|
5652
|
-
const ticket = currentTicket(io,
|
|
5653
|
-
return withContext(io,
|
|
5646
|
+
const ticket = currentTicket(io, config, a.options.ticket);
|
|
5647
|
+
return withContext(io, config, credentials, a.json, (ctx) => reportPhase(ctx, {
|
|
5654
5648
|
ticket,
|
|
5655
5649
|
phase,
|
|
5656
|
-
message
|
|
5650
|
+
message,
|
|
5657
5651
|
pr: a.options.pr ?? null,
|
|
5658
5652
|
sha: a.options.sha ?? null
|
|
5659
5653
|
}));
|
|
5660
5654
|
}
|
|
5661
|
-
async function release(io,
|
|
5655
|
+
async function release(io, config, credentials, a) {
|
|
5662
5656
|
if (a.rest.length)
|
|
5663
5657
|
throw new UsageError(`unexpected argument ${a.rest[0]}`);
|
|
5664
5658
|
const reason = a.options.reason?.trim();
|
|
5665
5659
|
if (!reason)
|
|
5666
5660
|
throw new UsageError("--reason is required: why the ticket is given back");
|
|
5667
|
-
const ticket = currentTicket(io,
|
|
5668
|
-
return withContext(io,
|
|
5661
|
+
const ticket = currentTicket(io, config, a.options.ticket);
|
|
5662
|
+
return withContext(io, config, credentials, a.json, (ctx) => releaseTicket(ctx, { ticket, reason }));
|
|
5669
5663
|
}
|
|
5670
5664
|
|
|
5671
5665
|
// src/inbox.ts
|
|
5672
5666
|
var DEFAULT_WAIT_SECONDS = 300;
|
|
5673
|
-
async function ask(io,
|
|
5667
|
+
async function ask(io, config, credentials, a) {
|
|
5674
5668
|
const [positional, ...extra] = a.rest;
|
|
5675
5669
|
if (extra.length)
|
|
5676
5670
|
throw new UsageError(`unexpected argument ${extra[0]}; quote the question`);
|
|
@@ -5681,10 +5675,10 @@ async function ask(io, config2, credentials2, a) {
|
|
|
5681
5675
|
if (!question?.trim())
|
|
5682
5676
|
throw new UsageError('ask needs a question: armada ask "<question, the options, your recommendation>"');
|
|
5683
5677
|
const options = (a.options.options ?? "").split("|").map((o) => o.trim()).filter(Boolean);
|
|
5684
|
-
const ticket = currentTicket(io,
|
|
5685
|
-
return withContext(io,
|
|
5678
|
+
const ticket = currentTicket(io, config, a.options.ticket);
|
|
5679
|
+
return withContext(io, config, credentials, a.json, (ctx) => askCoordinator(ctx, { ticket, question, options }));
|
|
5686
5680
|
}
|
|
5687
|
-
async function answer(io,
|
|
5681
|
+
async function answer(io, config, credentials, a) {
|
|
5688
5682
|
const note = a.options.note === "true";
|
|
5689
5683
|
const [target, positional, ...extra] = a.rest;
|
|
5690
5684
|
const usage = note ? 'armada answer --note <ticket> "<message>"' : 'armada answer <item or ticket> "<answer>"';
|
|
@@ -5698,7 +5692,7 @@ async function answer(io, config2, credentials2, a) {
|
|
|
5698
5692
|
const text = positional ?? fromOption;
|
|
5699
5693
|
if (!text?.trim())
|
|
5700
5694
|
throw new UsageError(`answer needs the text: ${usage}`);
|
|
5701
|
-
return withContext(io,
|
|
5695
|
+
return withContext(io, config, credentials, a.json, (ctx) => answerItem(ctx, { target, text, note }));
|
|
5702
5696
|
}
|
|
5703
5697
|
function waitSeconds(raw) {
|
|
5704
5698
|
if (raw === undefined)
|
|
@@ -5739,28 +5733,28 @@ function renderInbox(r) {
|
|
|
5739
5733
|
`)}
|
|
5740
5734
|
`;
|
|
5741
5735
|
}
|
|
5742
|
-
async function inbox2(io,
|
|
5736
|
+
async function inbox2(io, config, credentials, a) {
|
|
5743
5737
|
if (a.rest.length)
|
|
5744
5738
|
throw new UsageError(`unexpected argument ${a.rest[0]}`);
|
|
5745
5739
|
const wait = a.options.wait === "true";
|
|
5746
5740
|
if (!wait && a.options.timeout !== undefined)
|
|
5747
5741
|
throw new UsageError("--timeout applies to --wait");
|
|
5748
5742
|
const timeoutMs = waitSeconds(a.options.timeout) * 1000;
|
|
5749
|
-
if (!
|
|
5743
|
+
if (!credentials.tursoUrl)
|
|
5750
5744
|
throw new UsageError("the inbox lives in Turso: set ARMADA_TURSO_URL", "armada auth login");
|
|
5751
|
-
const { db, warning } = await openLive(
|
|
5745
|
+
const { db, warning } = await openLive(credentials);
|
|
5752
5746
|
if (!db)
|
|
5753
5747
|
throw new Refusal(`the inbox lives in Turso, which is unavailable: ${warning ?? "no answer"}`, "armada inbox again once Turso answers (armada auth status shows the URL in use)");
|
|
5754
5748
|
try {
|
|
5755
|
-
const
|
|
5756
|
-
project:
|
|
5757
|
-
silentAfterMinutes:
|
|
5749
|
+
const report = await checkInbox(db, {
|
|
5750
|
+
project: config.project.slug,
|
|
5751
|
+
silentAfterMinutes: config.policy.silentAfterMinutes,
|
|
5758
5752
|
now: io.now ?? (() => new Date),
|
|
5759
5753
|
...wait ? { wait: { timeoutMs, sleep: io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))) } } : {}
|
|
5760
5754
|
});
|
|
5761
|
-
io.stdout(a.json ? `${JSON.stringify(
|
|
5762
|
-
` : renderInbox(
|
|
5763
|
-
for (const w of
|
|
5755
|
+
io.stdout(a.json ? `${JSON.stringify(report, null, 2)}
|
|
5756
|
+
` : renderInbox(report));
|
|
5757
|
+
for (const w of report.warnings)
|
|
5764
5758
|
io.stderr(`armada: warning: ${w}
|
|
5765
5759
|
`);
|
|
5766
5760
|
return 0;
|
|
@@ -5773,7 +5767,7 @@ async function inbox2(io, config2, credentials2, a) {
|
|
|
5773
5767
|
import { mkdtemp, realpath, rm as rm3 } from "node:fs/promises";
|
|
5774
5768
|
import { tmpdir } from "node:os";
|
|
5775
5769
|
import { join as join3 } from "node:path";
|
|
5776
|
-
var initBranch = (
|
|
5770
|
+
var initBranch = (version) => `armada/init-${version}`;
|
|
5777
5771
|
async function defaultBranch(exec, root) {
|
|
5778
5772
|
const out = await sh(exec, root, "git", ["ls-remote", "--symref", "origin", "HEAD"]);
|
|
5779
5773
|
const m = out.match(/^ref:\s+refs\/heads\/(\S+)\s+HEAD/m);
|
|
@@ -5782,9 +5776,9 @@ async function defaultBranch(exec, root) {
|
|
|
5782
5776
|
return m[1];
|
|
5783
5777
|
}
|
|
5784
5778
|
async function resolveConfig(exec, root, checkout, opts) {
|
|
5785
|
-
const
|
|
5779
|
+
const parse = (text, where) => {
|
|
5786
5780
|
try {
|
|
5787
|
-
return parseConfig(
|
|
5781
|
+
return parseConfig(text, where);
|
|
5788
5782
|
} catch (err) {
|
|
5789
5783
|
if (err instanceof ConfigError)
|
|
5790
5784
|
throw new UsageError(err.message, "armada init again once the file is fixed");
|
|
@@ -5793,16 +5787,16 @@ async function resolveConfig(exec, root, checkout, opts) {
|
|
|
5793
5787
|
};
|
|
5794
5788
|
const onDefault = await fsRepoView(checkout).readFile(CONFIG_FILE);
|
|
5795
5789
|
if (onDefault !== null)
|
|
5796
|
-
return { config:
|
|
5790
|
+
return { config: parse(onDefault, `${CONFIG_FILE} on the default branch`), text: null, source: "default branch" };
|
|
5797
5791
|
const local = await fsRepoView(root).readFile(CONFIG_FILE);
|
|
5798
5792
|
if (local !== null && !opts.programRoot)
|
|
5799
|
-
return { config:
|
|
5793
|
+
return { config: parse(local, join3(root, CONFIG_FILE)), text: local, source: "working tree" };
|
|
5800
5794
|
const branch = initBranch(opts.armadaVersion);
|
|
5801
5795
|
if (!opts.programRoot && await sh(exec, root, "git", ["ls-remote", "origin", `refs/heads/${branch}`])) {
|
|
5802
5796
|
await sh(exec, root, "git", ["fetch", "--quiet", "origin", branch]);
|
|
5803
5797
|
const shown = await exec("git", ["show", `FETCH_HEAD:${CONFIG_FILE}`], { cwd: root });
|
|
5804
5798
|
if (shown.code === 0)
|
|
5805
|
-
return { config:
|
|
5799
|
+
return { config: parse(shown.stdout, `${CONFIG_FILE} on ${branch}`), text: shown.stdout, source: branch };
|
|
5806
5800
|
}
|
|
5807
5801
|
if (!opts.programRoot)
|
|
5808
5802
|
throw new UsageError(`${CONFIG_FILE} is missing, and armada init needs the Linear issue at the root of the program to write one`, "armada init --program-root <ISSUE-ID>");
|
|
@@ -5814,7 +5808,7 @@ async function resolveConfig(exec, root, checkout, opts) {
|
|
|
5814
5808
|
programRoot: opts.programRoot,
|
|
5815
5809
|
repository: repo.nameWithOwner
|
|
5816
5810
|
});
|
|
5817
|
-
return { config:
|
|
5811
|
+
return { config: parse(text, `the new ${CONFIG_FILE}`), text, source: "new" };
|
|
5818
5812
|
}
|
|
5819
5813
|
async function branchIsCurrent(exec, checkout, branch, baseSha) {
|
|
5820
5814
|
if (!await sh(exec, checkout, "git", ["ls-remote", "origin", `refs/heads/${branch}`]))
|
|
@@ -5827,10 +5821,10 @@ async function branchIsCurrent(exec, checkout, branch, baseSha) {
|
|
|
5827
5821
|
]);
|
|
5828
5822
|
return remoteTree === tree && remoteParent === baseSha;
|
|
5829
5823
|
}
|
|
5830
|
-
function prText(plan,
|
|
5831
|
-
const title = plan.installed.length ? `chore(armada): set up Armada ${
|
|
5824
|
+
function prText(plan, version) {
|
|
5825
|
+
const title = plan.installed.length ? `chore(armada): set up Armada ${version}` : `chore(armada): update the Armada setup to ${version}`;
|
|
5832
5826
|
const lines = [
|
|
5833
|
-
`Adds what \`armada doctor\` checks, so Armada ${
|
|
5827
|
+
`Adds what \`armada doctor\` checks, so Armada ${version} can run agents on this repository.`,
|
|
5834
5828
|
"",
|
|
5835
5829
|
...plan.writes.map((w) => `- write \`${w.path}\``),
|
|
5836
5830
|
...plan.links.map((l) => `- link \`${l.path}\` → \`${l.target}\``),
|
|
@@ -5852,12 +5846,12 @@ async function init(io, opts) {
|
|
|
5852
5846
|
if (login !== 0)
|
|
5853
5847
|
return login;
|
|
5854
5848
|
}
|
|
5855
|
-
const { credentials
|
|
5856
|
-
const
|
|
5857
|
-
if (
|
|
5858
|
-
throw missingKey(
|
|
5859
|
-
const linearApiKey =
|
|
5860
|
-
const tursoUrl =
|
|
5849
|
+
const { credentials } = await loadCredentials(io);
|
|
5850
|
+
const missing = required(credentials).find(Boolean);
|
|
5851
|
+
if (missing)
|
|
5852
|
+
throw missingKey(missing);
|
|
5853
|
+
const linearApiKey = credentials.linearApiKey ?? "";
|
|
5854
|
+
const tursoUrl = credentials.tursoUrl ?? "";
|
|
5861
5855
|
const root = await gitRoot(exec, io.cwd);
|
|
5862
5856
|
if (!root)
|
|
5863
5857
|
throw new UsageError(`${io.cwd} is not inside a git repository`, "armada init again from the checkout of the repository to set up");
|
|
@@ -5867,16 +5861,16 @@ async function init(io, opts) {
|
|
|
5867
5861
|
const checkout = await realpath(await mkdtemp(join3(tmpdir(), "armada-init-")));
|
|
5868
5862
|
try {
|
|
5869
5863
|
await sh(exec, root, "git", ["worktree", "add", "--quiet", "--detach", checkout, baseSha]);
|
|
5870
|
-
const { config
|
|
5864
|
+
const { config, text, source } = await resolveConfig(exec, root, checkout, opts);
|
|
5871
5865
|
const view = fsRepoView(checkout);
|
|
5872
5866
|
const plan = await planSetup(view, { armadaVersion: opts.armadaVersion, configText: text });
|
|
5873
5867
|
const log = (line) => io.stdout(`${line}
|
|
5874
5868
|
`);
|
|
5875
|
-
log(`Armada ${opts.armadaVersion} · ${
|
|
5869
|
+
log(`Armada ${opts.armadaVersion} · ${config.github.repository} · ${config.tracker.programRoot}`);
|
|
5876
5870
|
if (source !== "default branch" && source !== "new")
|
|
5877
5871
|
log(`Using ${CONFIG_FILE} from ${source === "working tree" ? "the working tree" : source}; the pull request adds it.`);
|
|
5878
|
-
const
|
|
5879
|
-
const created = await createMissingLabels(await readLabels(
|
|
5872
|
+
const linear = { apiKey: linearApiKey, ...io.fetch ? { fetch: io.fetch } : {} };
|
|
5873
|
+
const created = await createMissingLabels(await readLabels(config, linear), linear);
|
|
5880
5874
|
log(created.length ? `Created Linear labels: ${created.join(", ")}` : "Linear labels: all present");
|
|
5881
5875
|
if (planIsEmpty(plan))
|
|
5882
5876
|
log(`${base} already has everything Armada needs; no pull request to open.`);
|
|
@@ -5891,8 +5885,8 @@ async function init(io, opts) {
|
|
|
5891
5885
|
log(`${branch} is already up to date.`);
|
|
5892
5886
|
else
|
|
5893
5887
|
await sh(exec, checkout, "git", ["push", "--quiet", "--force", "origin", `HEAD:refs/heads/${branch}`]);
|
|
5894
|
-
const repo =
|
|
5895
|
-
const
|
|
5888
|
+
const repo = config.github.repository;
|
|
5889
|
+
const open = JSON.parse(await sh(exec, root, "gh", [
|
|
5896
5890
|
"pr",
|
|
5897
5891
|
"list",
|
|
5898
5892
|
"--repo",
|
|
@@ -5904,7 +5898,7 @@ async function init(io, opts) {
|
|
|
5904
5898
|
"--json",
|
|
5905
5899
|
"number,url"
|
|
5906
5900
|
]) || "[]");
|
|
5907
|
-
const existing =
|
|
5901
|
+
const existing = open[0];
|
|
5908
5902
|
if (existing) {
|
|
5909
5903
|
await sh(exec, root, "gh", [
|
|
5910
5904
|
"pr",
|
|
@@ -5941,19 +5935,19 @@ async function init(io, opts) {
|
|
|
5941
5935
|
if (plan.updated.length)
|
|
5942
5936
|
log(`Updates: ${plan.updated.join(", ")}`);
|
|
5943
5937
|
}
|
|
5944
|
-
const db = await openTurso({ url: tursoUrl, token:
|
|
5938
|
+
const db = await openTurso({ url: tursoUrl, token: credentials.tursoToken });
|
|
5945
5939
|
try {
|
|
5946
5940
|
const project = {
|
|
5947
|
-
slug:
|
|
5948
|
-
name:
|
|
5949
|
-
repository:
|
|
5950
|
-
programRoot:
|
|
5941
|
+
slug: config.project.slug,
|
|
5942
|
+
name: config.project.name,
|
|
5943
|
+
repository: config.github.repository,
|
|
5944
|
+
programRoot: config.tracker.programRoot
|
|
5951
5945
|
};
|
|
5952
5946
|
await upsertProject(db, project, io.now?.() ?? new Date);
|
|
5953
5947
|
} finally {
|
|
5954
5948
|
db.close();
|
|
5955
5949
|
}
|
|
5956
|
-
log(`Registered project ${
|
|
5950
|
+
log(`Registered project ${config.project.slug}; armada status --all lists it.`);
|
|
5957
5951
|
return 0;
|
|
5958
5952
|
} finally {
|
|
5959
5953
|
await exec("git", ["worktree", "remove", "--force", checkout], { cwd: root }).catch(() => null);
|
|
@@ -5975,9 +5969,9 @@ function ghMerge(exec, cwd, repository) {
|
|
|
5975
5969
|
const args = ["pr", "merge", String(number), "--repo", repository, "--squash", "--match-head-commit", sha];
|
|
5976
5970
|
try {
|
|
5977
5971
|
const r = await exec("gh", args, { cwd });
|
|
5978
|
-
const
|
|
5972
|
+
const message = tail(`${r.stderr}
|
|
5979
5973
|
${r.stdout}`.trim(), 5) || `gh exited with ${r.code}`;
|
|
5980
|
-
return { ok: r.code === 0, message
|
|
5974
|
+
return { ok: r.code === 0, message, transient: r.code !== 0 && TRANSIENT.test(message) };
|
|
5981
5975
|
} catch (err) {
|
|
5982
5976
|
return {
|
|
5983
5977
|
ok: false,
|
|
@@ -6098,42 +6092,42 @@ function render(o) {
|
|
|
6098
6092
|
`)}
|
|
6099
6093
|
`;
|
|
6100
6094
|
}
|
|
6101
|
-
async function merge2(io,
|
|
6095
|
+
async function merge2(io, config, credentials, a, configPath) {
|
|
6102
6096
|
const [arg, ...extra] = a.rest;
|
|
6103
6097
|
if (extra.length)
|
|
6104
6098
|
throw new UsageError(`unexpected argument ${extra[0]}`);
|
|
6105
|
-
const number = prNumber(arg,
|
|
6106
|
-
if (!
|
|
6099
|
+
const number = prNumber(arg, config.github.repository);
|
|
6100
|
+
if (!credentials.linearApiKey)
|
|
6107
6101
|
throw missingKey(LINEAR_KEY);
|
|
6108
|
-
const token =
|
|
6102
|
+
const token = credentials.githubToken;
|
|
6109
6103
|
if (!token)
|
|
6110
6104
|
throw new UsageError("armada merge reads GitHub: set GITHUB_TOKEN", "gh auth login");
|
|
6111
6105
|
const exec = io.exec;
|
|
6112
6106
|
if (!exec)
|
|
6113
6107
|
throw new UsageError("armada merge needs to run git and gh");
|
|
6114
|
-
const linearApiKey =
|
|
6108
|
+
const linearApiKey = credentials.linearApiKey;
|
|
6115
6109
|
const repoDir = dirname2(configPath);
|
|
6116
6110
|
const fetchOpt = io.fetch ? { fetch: io.fetch } : {};
|
|
6117
|
-
const gh = { token, repository:
|
|
6118
|
-
const linearOpts = { apiKey: linearApiKey, labels:
|
|
6111
|
+
const gh = { token, repository: config.github.repository, ...fetchOpt };
|
|
6112
|
+
const linearOpts = { apiKey: linearApiKey, labels: config.tracker.labels, ...fetchOpt };
|
|
6119
6113
|
const now = io.now ?? (() => new Date);
|
|
6120
|
-
const
|
|
6114
|
+
const turso = { live: null };
|
|
6121
6115
|
const ctx = {
|
|
6122
|
-
config
|
|
6116
|
+
config,
|
|
6123
6117
|
linear: io.linearWriter ? io.linearWriter(linearOpts) : createLinearWriter(linearOpts),
|
|
6124
6118
|
forge: {
|
|
6125
6119
|
readPull: (n) => fetchMergePull({ ...gh, number: n }),
|
|
6126
6120
|
compare: (base, head) => fetchComparison({ ...gh, base, head }),
|
|
6127
6121
|
diff: (n) => fetchPullDiff({ ...gh, number: n }),
|
|
6128
|
-
merge: ghMerge(exec, repoDir,
|
|
6122
|
+
merge: ghMerge(exec, repoDir, config.github.repository)
|
|
6129
6123
|
},
|
|
6130
6124
|
repo: gitRepo(exec, repoDir),
|
|
6131
|
-
tursoConfigured: !!
|
|
6125
|
+
tursoConfigured: !!credentials.tursoUrl,
|
|
6132
6126
|
turso: () => {
|
|
6133
|
-
|
|
6134
|
-
return
|
|
6127
|
+
turso.live ??= openLive(credentials);
|
|
6128
|
+
return turso.live;
|
|
6135
6129
|
},
|
|
6136
|
-
inFlight: async () => (await loadStatus(
|
|
6130
|
+
inFlight: async () => (await loadStatus(config, { linearApiKey, githubToken: null, ...fetchOpt, now })).inFlight.map((t) => ({
|
|
6137
6131
|
id: t.id,
|
|
6138
6132
|
title: t.title,
|
|
6139
6133
|
phase: t.phase,
|
|
@@ -6165,7 +6159,7 @@ async function merge2(io, config2, credentials2, a, configPath) {
|
|
|
6165
6159
|
`);
|
|
6166
6160
|
return 0;
|
|
6167
6161
|
} finally {
|
|
6168
|
-
(await
|
|
6162
|
+
(await turso.live)?.db?.close();
|
|
6169
6163
|
}
|
|
6170
6164
|
}
|
|
6171
6165
|
|
|
@@ -6203,7 +6197,7 @@ function renderStatus(r) {
|
|
|
6203
6197
|
const now = Date.parse(r.generatedAt);
|
|
6204
6198
|
const out = [];
|
|
6205
6199
|
const idWidth = Math.max(6, ...r.inFlight.map((t) => t.id.length), ...r.frontier.map((t) => t.id.length), ...(r.pullRequests ?? []).map((p) => `#${p.number}`.length));
|
|
6206
|
-
const
|
|
6200
|
+
const indent = " ".repeat(idWidth + 4);
|
|
6207
6201
|
const phaseWidth = Math.max(0, ...r.inFlight.map((t) => phaseLabel(t).length));
|
|
6208
6202
|
out.push(`${r.project.name} · ${r.programRoot.id} ${r.programRoot.title}`);
|
|
6209
6203
|
const gh = r.sources.github.error ? `GitHub not read: ${r.sources.github.error}` : `GitHub ${r.project.repository}`;
|
|
@@ -6214,13 +6208,13 @@ function renderStatus(r) {
|
|
|
6214
6208
|
for (const t of r.inFlight) {
|
|
6215
6209
|
const who = [t.runtime, t.agent].filter(Boolean).join(" · ") || "unassigned";
|
|
6216
6210
|
out.push(` ${pad(t.id, idWidth)} ${pad(phaseLabel(t), phaseWidth)} ${who} · ${t.lastReport ? `reported ${relative2(t.lastReport, now)}` : `updated ${relative2(t.lastUpdate, now)}`}`);
|
|
6217
|
-
out.push(`${
|
|
6211
|
+
out.push(`${indent}${truncate(t.title, 90)}${t.spec ? ` [${t.spec}]` : ""}`);
|
|
6218
6212
|
if (t.statusLine?.summary)
|
|
6219
|
-
out.push(`${
|
|
6213
|
+
out.push(`${indent}“${truncate(t.statusLine.summary, 100)}”`);
|
|
6220
6214
|
if (t.pr)
|
|
6221
|
-
out.push(`${
|
|
6215
|
+
out.push(`${indent}${[`PR #${t.pr.number}`, prState(t.pr)].filter(Boolean).join(" · ")}`);
|
|
6222
6216
|
if (t.flags.length)
|
|
6223
|
-
out.push(`${
|
|
6217
|
+
out.push(`${indent}! ${t.flags.join(", ")}`);
|
|
6224
6218
|
}
|
|
6225
6219
|
const ready = r.frontier.filter((t) => t.readyForAgent);
|
|
6226
6220
|
const untriaged = r.frontier.filter((t) => !t.readyForAgent);
|
|
@@ -6248,9 +6242,9 @@ function renderStatus(r) {
|
|
|
6248
6242
|
for (const p of r.pullRequests ?? []) {
|
|
6249
6243
|
const ticket = p.ticket ? `${p.ticket.id}${p.ticket.phase ? ` ${p.ticket.phase}` : ""}` : "no ticket";
|
|
6250
6244
|
out.push(` ${pad(`#${p.number}`, idWidth)} ${[ticket, prState(p)].filter(Boolean).join(" · ")}`);
|
|
6251
|
-
out.push(`${
|
|
6245
|
+
out.push(`${indent}${truncate(p.title, 90)}`);
|
|
6252
6246
|
if (p.failingChecks.length)
|
|
6253
|
-
out.push(`${
|
|
6247
|
+
out.push(`${indent}! failing: ${p.failingChecks.join(", ")}`);
|
|
6254
6248
|
}
|
|
6255
6249
|
if (r.warnings.length) {
|
|
6256
6250
|
out.push("", `Warnings (${r.warnings.length})`);
|
|
@@ -6265,49 +6259,49 @@ function renderStatus(r) {
|
|
|
6265
6259
|
// src/projects.ts
|
|
6266
6260
|
var message2 = (err) => err instanceof Error ? err.message : String(err);
|
|
6267
6261
|
async function statusAll(io, json) {
|
|
6268
|
-
const { credentials
|
|
6269
|
-
const linearApiKey =
|
|
6262
|
+
const { credentials } = await loadCredentials(io);
|
|
6263
|
+
const linearApiKey = credentials.linearApiKey;
|
|
6270
6264
|
if (!linearApiKey)
|
|
6271
6265
|
throw missingKey(LINEAR_KEY);
|
|
6272
6266
|
const tursoKey = STORED_KEYS.find((k) => k.name === "tursoUrl");
|
|
6273
|
-
if (!
|
|
6267
|
+
if (!credentials.tursoUrl && tursoKey)
|
|
6274
6268
|
throw missingKey(tursoKey);
|
|
6275
|
-
const db = await openTurso({ url:
|
|
6269
|
+
const db = await openTurso({ url: credentials.tursoUrl ?? "", token: credentials.tursoToken });
|
|
6276
6270
|
let records;
|
|
6277
6271
|
try {
|
|
6278
6272
|
records = await listProjects(db);
|
|
6279
6273
|
} finally {
|
|
6280
6274
|
db.close();
|
|
6281
6275
|
}
|
|
6282
|
-
const
|
|
6276
|
+
const projects = await Promise.all(records.map(async (p) => {
|
|
6283
6277
|
const base = { slug: p.slug, name: p.name, repository: p.repository };
|
|
6284
6278
|
let warning = null;
|
|
6285
6279
|
try {
|
|
6286
6280
|
const read = await readProjectConfig(p, {
|
|
6287
|
-
githubToken:
|
|
6281
|
+
githubToken: credentials.githubToken,
|
|
6288
6282
|
...io.fetch ? { fetch: io.fetch } : {}
|
|
6289
6283
|
});
|
|
6290
6284
|
warning = read.warning;
|
|
6291
|
-
const
|
|
6292
|
-
const
|
|
6285
|
+
const config = read.config;
|
|
6286
|
+
const report = await loadStatus(config, {
|
|
6293
6287
|
linearApiKey,
|
|
6294
|
-
githubToken:
|
|
6288
|
+
githubToken: credentials.githubToken,
|
|
6295
6289
|
...io.fetch ? { fetch: io.fetch } : {},
|
|
6296
6290
|
...io.now ? { now: io.now } : {}
|
|
6297
6291
|
});
|
|
6298
|
-
return { ...base, report
|
|
6292
|
+
return { ...base, report, error: null, configWarning: warning };
|
|
6299
6293
|
} catch (err) {
|
|
6300
6294
|
return { ...base, report: null, error: message2(err), configWarning: warning };
|
|
6301
6295
|
}
|
|
6302
6296
|
}));
|
|
6303
|
-
const all = { schemaVersion: 1, projects
|
|
6297
|
+
const all = { schemaVersion: 1, projects };
|
|
6304
6298
|
if (json)
|
|
6305
6299
|
io.stdout(`${JSON.stringify(all, null, 2)}
|
|
6306
6300
|
`);
|
|
6307
|
-
else if (!
|
|
6301
|
+
else if (!projects.length)
|
|
6308
6302
|
io.stdout("No project is registered yet. Run `armada init` in a repository to register it.\n");
|
|
6309
6303
|
else
|
|
6310
|
-
io.stdout(
|
|
6304
|
+
io.stdout(projects.map((p) => {
|
|
6311
6305
|
if (!p.report)
|
|
6312
6306
|
return `${p.name} (${p.slug}) · ${p.repository}
|
|
6313
6307
|
! not read: ${p.error}
|
|
@@ -6319,7 +6313,7 @@ ${p.configWarning ? ` ! ${p.configWarning}
|
|
|
6319
6313
|
${"─".repeat(60)}
|
|
6320
6314
|
|
|
6321
6315
|
`));
|
|
6322
|
-
return
|
|
6316
|
+
return projects.some((p) => p.error) ? 1 : 0;
|
|
6323
6317
|
}
|
|
6324
6318
|
|
|
6325
6319
|
// src/cli.ts
|
|
@@ -6526,21 +6520,21 @@ async function findConfig(io, explicit, command = "status") {
|
|
|
6526
6520
|
}
|
|
6527
6521
|
async function status2(io, args) {
|
|
6528
6522
|
const { path, text } = await findConfig(io, args.config, "status");
|
|
6529
|
-
const
|
|
6530
|
-
const { credentials
|
|
6531
|
-
const { linearApiKey, githubToken } =
|
|
6523
|
+
const config = parseConfig(text, path);
|
|
6524
|
+
const { credentials } = await loadCredentials(io);
|
|
6525
|
+
const { linearApiKey, githubToken } = credentials;
|
|
6532
6526
|
if (!linearApiKey)
|
|
6533
6527
|
throw missingKey(LINEAR_KEY);
|
|
6534
|
-
const events = statusEvents(
|
|
6535
|
-
const
|
|
6528
|
+
const events = statusEvents(config, credentials);
|
|
6529
|
+
const report = await loadStatus(config, {
|
|
6536
6530
|
linearApiKey,
|
|
6537
6531
|
githubToken,
|
|
6538
6532
|
...events ? { lastEvents: events } : {},
|
|
6539
6533
|
...io.fetch ? { fetch: io.fetch } : {},
|
|
6540
6534
|
...io.now ? { now: io.now } : {}
|
|
6541
6535
|
});
|
|
6542
|
-
io.stdout(args.json ? `${JSON.stringify(
|
|
6543
|
-
` : renderStatus(
|
|
6536
|
+
io.stdout(args.json ? `${JSON.stringify(report, null, 2)}
|
|
6537
|
+
` : renderStatus(report));
|
|
6544
6538
|
return 0;
|
|
6545
6539
|
}
|
|
6546
6540
|
function noExtra(rest) {
|
|
@@ -6595,22 +6589,22 @@ async function run(argv, io) {
|
|
|
6595
6589
|
throw new UsageError(`--${name} does not apply to ${args.command}`);
|
|
6596
6590
|
if (args.all && args.command !== "status")
|
|
6597
6591
|
throw new UsageError(`--all does not apply to ${args.command}`);
|
|
6598
|
-
const
|
|
6599
|
-
if (
|
|
6592
|
+
const worker = { claim, report, release, ask, inbox: inbox2, answer }[args.command];
|
|
6593
|
+
if (worker) {
|
|
6600
6594
|
const { path, text } = await findConfig(io, args.config, args.command);
|
|
6601
|
-
const
|
|
6602
|
-
const { credentials
|
|
6603
|
-
return await
|
|
6595
|
+
const config = parseConfig(text, path);
|
|
6596
|
+
const { credentials } = await loadCredentials(io);
|
|
6597
|
+
return await worker(io, config, credentials, args);
|
|
6604
6598
|
}
|
|
6605
6599
|
if (args.command === "merge") {
|
|
6606
6600
|
const { path, text } = await findConfig(io, args.config, "merge");
|
|
6607
|
-
const { credentials
|
|
6608
|
-
return await merge2(io, parseConfig(text, path),
|
|
6601
|
+
const { credentials } = await loadCredentials(io);
|
|
6602
|
+
return await merge2(io, parseConfig(text, path), credentials, args, path);
|
|
6609
6603
|
}
|
|
6610
6604
|
if (args.command === "brief") {
|
|
6611
6605
|
const { path, text } = await findConfig(io, args.config, "brief");
|
|
6612
|
-
const { credentials
|
|
6613
|
-
return await brief2(io, parseConfig(text, path),
|
|
6606
|
+
const { credentials } = await loadCredentials(io);
|
|
6607
|
+
return await brief2(io, parseConfig(text, path), credentials, args, version);
|
|
6614
6608
|
}
|
|
6615
6609
|
if (args.command === "status") {
|
|
6616
6610
|
noExtra(args.rest);
|
|
@@ -6654,7 +6648,7 @@ ${next ? `Next: ${next}
|
|
|
6654
6648
|
// src/line.ts
|
|
6655
6649
|
var emptyLine = () => ({ answer: "", sequence: "none" });
|
|
6656
6650
|
function feedLine(line, chunk) {
|
|
6657
|
-
let { answer
|
|
6651
|
+
let { answer, sequence } = line;
|
|
6658
6652
|
for (const c of chunk) {
|
|
6659
6653
|
if (sequence === "start")
|
|
6660
6654
|
sequence = c === "[" ? "csi" : "none";
|
|
@@ -6665,21 +6659,21 @@ function feedLine(line, chunk) {
|
|
|
6665
6659
|
sequence = "start";
|
|
6666
6660
|
else if (c === "\r" || c === `
|
|
6667
6661
|
`)
|
|
6668
|
-
return { answer
|
|
6669
|
-
else if (c === "\x03" || c === "\x04" && !
|
|
6670
|
-
return { answer
|
|
6662
|
+
return { answer, sequence, result: answer };
|
|
6663
|
+
else if (c === "\x03" || c === "\x04" && !answer)
|
|
6664
|
+
return { answer, sequence, result: null };
|
|
6671
6665
|
else if (c === "" || c === "\b")
|
|
6672
|
-
|
|
6666
|
+
answer = answer.slice(0, -1);
|
|
6673
6667
|
else if (c >= " ")
|
|
6674
|
-
|
|
6668
|
+
answer += c;
|
|
6675
6669
|
}
|
|
6676
|
-
return { answer
|
|
6670
|
+
return { answer, sequence };
|
|
6677
6671
|
}
|
|
6678
|
-
function echo(before,
|
|
6672
|
+
function echo(before, after) {
|
|
6679
6673
|
let common = 0;
|
|
6680
|
-
while (common < before.length && common <
|
|
6674
|
+
while (common < before.length && common < after.length && before[common] === after[common])
|
|
6681
6675
|
common++;
|
|
6682
|
-
return "\b \b".repeat(before.length - common) +
|
|
6676
|
+
return "\b \b".repeat(before.length - common) + after.slice(common);
|
|
6683
6677
|
}
|
|
6684
6678
|
|
|
6685
6679
|
// src/main.ts
|
|
@@ -6762,4 +6756,4 @@ var code = await run(process.argv.slice(2), {
|
|
|
6762
6756
|
readStdin,
|
|
6763
6757
|
exec
|
|
6764
6758
|
});
|
|
6765
|
-
process.
|
|
6759
|
+
process.exitCode = code;
|