@the-vibe-company/armada 0.2.6 → 0.2.8
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 +20 -3
- package/dist/armada.js +449 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -176,7 +176,7 @@ Try it locally with synthetic data and no key:
|
|
|
176
176
|
|
|
177
177
|
```sh
|
|
178
178
|
cd packages/dashboard
|
|
179
|
-
bun run demo:seed # a local PGlite database (Postgres in the process) with
|
|
179
|
+
bun run demo:seed # a local PGlite database (Postgres in the process) with the mockup's Acme world (three projects, ten sessions)
|
|
180
180
|
ARMADA_DASHBOARD_PASSWORD=off ARMADA_DASHBOARD_DEMO=fleet ARMADA_DATABASE_URL=pglite:.demo/armada bun run dev # http://localhost:4822
|
|
181
181
|
```
|
|
182
182
|
|
|
@@ -220,10 +220,11 @@ ARMADA_AUTH_URL=http://localhost:4822 ARMADA_AUTH_OWNER_EMAILS=you@example.com b
|
|
|
220
220
|
| `ARMADA_SECRETS_KEY` | The vault's master key: 32 random bytes in base64 or hex, `openssl rand -base64 32`. It stays in the deployment's environment, never in a database. Changing it makes every stored key unreadable (the Keys page asks to enter them again) |
|
|
221
221
|
|
|
222
222
|
- The Keys page holds the Linear API key, and a GitHub token for the dashboard's own reads, needed only without the [GitHub App](#github-app). Each member may add their own Linear key: their terminals use it, so the comments they post carry their name.
|
|
223
|
-
-
|
|
223
|
+
- Each project can keep its own keys (pick it at the top of the Keys page): a Linear key, which wins for that project over the organization's and anyone's own (a project in another Linear workspace); the dashboard and every command run for that project (`status --all` and `doctor` included) read its Linear with it. And its secrets for workers (see [Secrets for workers](#secrets-for-workers)), next to the organization's, which every project gets; a project's own wins over the organization's of the same name.
|
|
224
|
+
- Values are write-only: once saved, a secret is never shown again, only who set it and when. Each value is sealed with AES-256-GCM under its own data key, itself sealed by the master key, and bound to its organization, project, person and name.
|
|
224
225
|
- A signed-in terminal (a session of `armada login`, an organization API key, or a worker session) calls `POST /api/cli/credentials`. It receives the Linear key (the person's own first), so workers and coordinators can search and edit Linear freely. Answers are never cached; a terminal asking more than 30 times a minute is refused for a minute.
|
|
225
226
|
- No terminal ever receives a database key. Every read and write of the fleet's live data (claims, reports, questions and plans, the inbox, answers, the merge lock, the project registry) goes through `POST /api/cli/fleet/<operation>` with the terminal's sign-in. Armada checks each one: the project must belong to the caller's organization (a project is registered for the first organization that names it), and a worker session only claims, reports, asks and releases its own ticket. Times are Armada's.
|
|
226
|
-
- Every change and every key handed out is in the audit list at the bottom of the Keys page (owners and admins): who, which key, when; never a value.
|
|
227
|
+
- Every change and every key handed out is in the audit list at the bottom of the Keys page (owners and admins): who, which key, when, for which project; never a value. A project picked at the top shows only its own.
|
|
227
228
|
- The dashboard reads each organization's fleet with that organization's Linear and GitHub keys from the vault. Only the deployment's first organization falls back to the environment's (and to `ARMADA_REPOSITORIES`): another organization could name any repository in the registry. Once the keys are on the Keys page, the environment shrinks to `ARMADA_DATABASE_URL`, the accounts variables, `ARMADA_SECRETS_KEY` and the GitHub App's. With the [GitHub App](#github-app), GitHub is read through it rather than with a stored token.
|
|
228
229
|
- Without `ARMADA_SECRETS_KEY` (or under the shared password), nothing changes: the Keys page says how to turn the vault on, the CLI's call answers 503 with that next step, and terminals keep their own keys.
|
|
229
230
|
|
|
@@ -346,6 +347,19 @@ url = "https://<your-armada-dashboard>"
|
|
|
346
347
|
url = "https://armada.example.com" # a self-hosted Armada for `armada login`; used when ARMADA_API_URL is not set
|
|
347
348
|
```
|
|
348
349
|
|
|
350
|
+
### Secrets for workers
|
|
351
|
+
|
|
352
|
+
What a project's workers need to build and test (an LLM provider key, a test database URL) is kept in Armada with the project, never in a worker's launch environment. Names are in upper snake case; the keys Armada itself uses (`LINEAR_API_KEY`, `GITHUB_TOKEN`, `GH_TOKEN`, `ARMADA_*`) are not secrets for workers.
|
|
353
|
+
|
|
354
|
+
- The coordinator sets them, signed in as an owner or admin (or with an organization API key whose creator still is one): `armada secrets set <NAME>` for the current project, `--org` for every project of the organization. The value is read from a hidden prompt, from standard input (`--value-stdin`), or from a variable of the coordinator's environment (`--from-env <VAR>`), so an agent can move a key without reading it. Never from the command line. `armada secrets unset <NAME> [--org]` removes one. Owners and admins can also do both on the Keys page.
|
|
355
|
+
- `armada secrets` lists the names, where each is set (project or organization), who set it and when. Never a value.
|
|
356
|
+
- A worker fetches them through Armada, with its worker session, for its own project only (another project's is refused, and the refusal is in the audit list), in this order:
|
|
357
|
+
- `armada run [--only A,B] -- <command>` runs the command with them in its environment: tests, builds, dev servers. Armada's value wins over a variable of the same name (stderr names it). Nothing is written to disk or printed; the exit code is the command's.
|
|
358
|
+
- `armada secrets export --file <path> [--only A,B]` writes a dotenv file with mode 0600, for a tool that reads one (`.env.local`). It refuses a path git tracks or does not ignore.
|
|
359
|
+
- `armada secrets get <NAME>` prints one value, for a person, with a warning on stderr that it is now visible. An agent never runs it: its command output is its transcript.
|
|
360
|
+
- Every fetch is one release in the audit list, naming the project and the secrets. Nothing is cached: an unset secret is no longer handed out, and a changed one takes effect on the next command.
|
|
361
|
+
- `[secrets] names` in `armada.toml` lists what the project expects; `armada doctor` names those Armada does not keep for it.
|
|
362
|
+
|
|
349
363
|
## Configure a project
|
|
350
364
|
|
|
351
365
|
Add an `armada.toml` at the root of the repository. One project is one repository plus one Linear program root. The file holds no secrets.
|
|
@@ -382,6 +396,9 @@ approval_label = "needs-plan-approval" # a ticket with this label waits for ap
|
|
|
382
396
|
[brief]
|
|
383
397
|
extra = "docs/worker-conventions.md" # every brief ends with this file under "Project conventions" (default: none)
|
|
384
398
|
|
|
399
|
+
[secrets]
|
|
400
|
+
names = ["OPENAI_API_KEY", "TEST_DATABASE_URL"] # what workers need from Armada; `armada doctor` names those not set (names only)
|
|
401
|
+
|
|
385
402
|
[conductor]
|
|
386
403
|
default_profile = "opus" # for tickets no routing rule matches (required with routing)
|
|
387
404
|
|
package/dist/armada.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
|
-
import { spawn, spawnSync } from "node:child_process";
|
|
4
|
+
import { spawn as spawn2, spawnSync } from "node:child_process";
|
|
5
5
|
import { createReadStream } from "node:fs";
|
|
6
6
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
7
7
|
import { isatty } from "node:tty";
|
|
8
8
|
|
|
9
9
|
// src/cli.ts
|
|
10
|
-
import { dirname as
|
|
10
|
+
import { dirname as dirname7, join as join6, resolve as resolve2 } from "node:path";
|
|
11
11
|
|
|
12
12
|
// ../core/src/types.ts
|
|
13
13
|
var LABEL_PHASES = [
|
|
@@ -469,10 +469,11 @@ function armadaApi(opts) {
|
|
|
469
469
|
if (!shaped)
|
|
470
470
|
throw new ArmadaApiError(`Armada (${host}) answered the keys in a shape this CLI does not know`);
|
|
471
471
|
const warnings = Array.isArray(body.warnings) ? body.warnings.filter((w) => typeof w === "string") : [];
|
|
472
|
+
const scope = linear?.scope === "own" || linear?.scope === "project" ? linear.scope : "organization";
|
|
472
473
|
return {
|
|
473
474
|
schemaVersion: 1,
|
|
474
475
|
organization: org,
|
|
475
|
-
linear: linear ? { apiKey: linear.apiKey, scope
|
|
476
|
+
linear: linear ? { apiKey: linear.apiKey, scope } : null,
|
|
476
477
|
warnings
|
|
477
478
|
};
|
|
478
479
|
},
|
|
@@ -482,7 +483,15 @@ function armadaApi(opts) {
|
|
|
482
483
|
throw refusal(status, body, status === 401 ? null : "Armada did not list the projects");
|
|
483
484
|
if (!Array.isArray(body.projects))
|
|
484
485
|
throw new ArmadaApiError(`Armada (${host}) answered the projects in a shape this CLI does not know`);
|
|
485
|
-
return body.projects.flatMap((p) => typeof p.slug === "string" && typeof p.name === "string" && typeof p.repository === "string" && typeof p.programRoot === "string" ? [
|
|
486
|
+
return body.projects.flatMap((p) => typeof p.slug === "string" && typeof p.name === "string" && typeof p.repository === "string" && typeof p.programRoot === "string" ? [
|
|
487
|
+
{
|
|
488
|
+
slug: p.slug,
|
|
489
|
+
name: p.name,
|
|
490
|
+
repository: p.repository,
|
|
491
|
+
programRoot: p.programRoot,
|
|
492
|
+
...p.ownLinearKey === true ? { ownLinearKey: true } : {}
|
|
493
|
+
}
|
|
494
|
+
] : []);
|
|
486
495
|
},
|
|
487
496
|
async fleet(signIn, op, body, timeoutMs) {
|
|
488
497
|
const { status, body: answer } = await call("POST", `fleet/${op}`, {
|
|
@@ -498,6 +507,52 @@ function armadaApi(opts) {
|
|
|
498
507
|
throw new ArmadaApiError(`Armada (${host}) answered fleet/${op} in a shape this CLI does not know`);
|
|
499
508
|
return answer.result;
|
|
500
509
|
},
|
|
510
|
+
async listSecrets(signIn, project) {
|
|
511
|
+
const { status, body } = await call("POST", "secrets/list", { signIn, body: { project } });
|
|
512
|
+
if (status !== 200)
|
|
513
|
+
throw refusal(status, body, status === 401 ? null : "Armada did not list the secrets");
|
|
514
|
+
if (!Array.isArray(body.secrets))
|
|
515
|
+
throw new ArmadaApiError(`Armada (${host}) answered the secrets in a shape this CLI does not know`);
|
|
516
|
+
return body.secrets.flatMap((s) => typeof s.name === "string" && typeof s.setBy === "string" && typeof s.setAt === "string" ? [
|
|
517
|
+
{
|
|
518
|
+
name: s.name,
|
|
519
|
+
scope: s.scope === "organization" ? "organization" : "project",
|
|
520
|
+
setBy: s.setBy,
|
|
521
|
+
setAt: s.setAt,
|
|
522
|
+
overridden: s.overridden === true
|
|
523
|
+
}
|
|
524
|
+
] : []);
|
|
525
|
+
},
|
|
526
|
+
async releaseSecrets(signIn, project, names = null) {
|
|
527
|
+
const { status, body } = await call("POST", "secrets/release", { signIn, body: { project, names } });
|
|
528
|
+
if (status !== 200)
|
|
529
|
+
throw refusal(status, body, status === 401 ? null : "Armada gave no secrets");
|
|
530
|
+
const secrets = Array.isArray(body.secrets) ? body.secrets : null;
|
|
531
|
+
if (!secrets?.every((s) => typeof s.name === "string" && typeof s.value === "string"))
|
|
532
|
+
throw new ArmadaApiError(`Armada (${host}) answered the secrets in a shape this CLI does not know`);
|
|
533
|
+
const strings = (v) => Array.isArray(v) ? v.filter((w) => typeof w === "string") : [];
|
|
534
|
+
return {
|
|
535
|
+
project: typeof body.project === "string" ? body.project : project.slug,
|
|
536
|
+
secrets: secrets.map((s) => ({
|
|
537
|
+
name: String(s.name),
|
|
538
|
+
value: String(s.value),
|
|
539
|
+
scope: s.scope === "organization" ? "organization" : "project"
|
|
540
|
+
})),
|
|
541
|
+
missing: strings(body.missing),
|
|
542
|
+
warnings: strings(body.warnings)
|
|
543
|
+
};
|
|
544
|
+
},
|
|
545
|
+
async setSecret(signIn, target) {
|
|
546
|
+
const { status, body } = await call("POST", "secrets/set", { signIn, body: target });
|
|
547
|
+
if (status !== 200)
|
|
548
|
+
throw refusal(status, body, status === 401 ? null : `Armada did not set ${target.name}`);
|
|
549
|
+
},
|
|
550
|
+
async unsetSecret(signIn, target) {
|
|
551
|
+
const { status, body } = await call("POST", "secrets/unset", { signIn, body: target });
|
|
552
|
+
if (status !== 200)
|
|
553
|
+
throw refusal(status, body, status === 401 ? null : `Armada did not unset ${target.name}`);
|
|
554
|
+
return body.deleted === true;
|
|
555
|
+
},
|
|
501
556
|
async launchToken(signIn, target) {
|
|
502
557
|
const { status, body } = await call("POST", "launch-tokens", { signIn, body: target });
|
|
503
558
|
if (status !== 200)
|
|
@@ -1864,6 +1919,15 @@ ${problems.map((p) => ` - ${p}`).join(`
|
|
|
1864
1919
|
}
|
|
1865
1920
|
var SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
1866
1921
|
var ISSUE_ID = /^[A-Za-z][A-Za-z0-9]*-\d+$/;
|
|
1922
|
+
var SECRET_NAME = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
1923
|
+
var RESERVED_SECRET_NAMES = ["LINEAR_API_KEY", "GITHUB_TOKEN", "GH_TOKEN"];
|
|
1924
|
+
function secretNameRefusal(name) {
|
|
1925
|
+
if (!SECRET_NAME.test(name))
|
|
1926
|
+
return "a secret name is in upper snake case, e.g. OPENAI_API_KEY";
|
|
1927
|
+
if (RESERVED_SECRET_NAMES.includes(name) || name.startsWith("ARMADA_"))
|
|
1928
|
+
return `${name} is a key Armada itself uses: it is set on the Keys page as such, not as a secret for workers`;
|
|
1929
|
+
return null;
|
|
1930
|
+
}
|
|
1867
1931
|
var REPOSITORY = /^[\w.-]+\/[\w.-]+$/;
|
|
1868
1932
|
var isTable = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1869
1933
|
function parseConfig(text, source = CONFIG_FILE) {
|
|
@@ -1925,6 +1989,10 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
1925
1989
|
if (!isTable(brief))
|
|
1926
1990
|
problems.push(`"brief" must be a table`);
|
|
1927
1991
|
const briefT = isTable(brief) ? brief : {};
|
|
1992
|
+
const secrets = raw.secrets === undefined ? {} : raw.secrets;
|
|
1993
|
+
if (!isTable(secrets))
|
|
1994
|
+
problems.push(`"secrets" must be a table`);
|
|
1995
|
+
const secretsT = isTable(secrets) ? secrets : {};
|
|
1928
1996
|
const conductor = raw.conductor === undefined ? {} : raw.conductor;
|
|
1929
1997
|
if (!isTable(conductor))
|
|
1930
1998
|
problems.push(`"conductor" must be a table`);
|
|
@@ -1952,6 +2020,7 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
1952
2020
|
]
|
|
1953
2021
|
],
|
|
1954
2022
|
["brief", briefT, ["extra"]],
|
|
2023
|
+
["secrets", secretsT, ["names"]],
|
|
1955
2024
|
["conductor", conductorT, ["default_profile", "profiles", "routing"]]
|
|
1956
2025
|
];
|
|
1957
2026
|
const profiles = {};
|
|
@@ -2062,6 +2131,14 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2062
2131
|
else if (v)
|
|
2063
2132
|
extra = v;
|
|
2064
2133
|
}
|
|
2134
|
+
let secretNames = [];
|
|
2135
|
+
if (secretsT.names !== undefined) {
|
|
2136
|
+
const v = secretsT.names;
|
|
2137
|
+
if (Array.isArray(v) && v.every((n) => typeof n === "string" && !secretNameRefusal(n.trim())))
|
|
2138
|
+
secretNames = [...new Set(v.map((n) => n.trim()))];
|
|
2139
|
+
else
|
|
2140
|
+
problems.push(`"secrets.names" must be a list of secret names in upper snake case, e.g. ["OPENAI_API_KEY"], none of Armada's own keys`);
|
|
2141
|
+
}
|
|
2065
2142
|
let requiredChecks = [];
|
|
2066
2143
|
if (gatesT.required_checks !== undefined) {
|
|
2067
2144
|
const v = gatesT.required_checks;
|
|
@@ -2102,6 +2179,7 @@ function parseConfig(text, source = CONFIG_FILE) {
|
|
|
2102
2179
|
gates: { requiredChecks, localCommands },
|
|
2103
2180
|
policy: { silentAfterMinutes, coordinatorMinutes, plans, preApprovedLabel, approvalLabel },
|
|
2104
2181
|
brief: { extra },
|
|
2182
|
+
secrets: { names: secretNames },
|
|
2105
2183
|
conductor: { defaultProfile, profiles, routing }
|
|
2106
2184
|
};
|
|
2107
2185
|
if (problems.length)
|
|
@@ -4005,6 +4083,9 @@ async function writePrivate(paths, path, text, mode) {
|
|
|
4005
4083
|
await chmod(paths.dir, 448);
|
|
4006
4084
|
if (dirname(path) !== paths.dir)
|
|
4007
4085
|
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
4086
|
+
await writePrivateFile(path, text, mode);
|
|
4087
|
+
}
|
|
4088
|
+
async function writePrivateFile(path, text, mode = 384) {
|
|
4008
4089
|
const tmp = `${path}.${randomBytes(6).toString("hex")}.tmp`;
|
|
4009
4090
|
const handle = await open(tmp, "wx", mode);
|
|
4010
4091
|
try {
|
|
@@ -4891,6 +4972,7 @@ The coordinator turns the owner's intent into merged pull requests. Each worker
|
|
|
4891
4972
|
A coordinator may start cold, on a laptop or in a fresh cloud session, with nothing but the repository and a sign-in to Armada. Everything it needs is in the tracker, GitHub and Armada; the Armada [runbook](https://github.com/The-Vibe-Company/armada/blob/main/docs/runbook.md) says how to start one.
|
|
4892
4973
|
|
|
4893
4974
|
1. **Sign in to Armada.** \`armada doctor\` (or \`armada whoami\`) says whether this terminal is signed in and to which organization. If not: a person runs \`armada login\` and approves the code in the browser; a headless coordinator (a cloud workspace, CI) sets \`ARMADA_API_KEY\` to an organization API key an owner created on the Organization page. Signed in, Armada gives your commands the organization's keys, and every brief carries a one-time launch token, so no worker needs a key in its environment. Keys set in the environment still win over Armada's: they are the override for CI and a self-hosted Armada without accounts.
|
|
4975
|
+
The secrets workers need to build and test (an LLM provider key, a test database URL) are kept per project in Armada: \`armada secrets set <NAME>\` (owner or admin; \`--org\` for every project) reads the value from a hidden prompt, \`--value-stdin\`, or \`--from-env <VAR>\`, which moves a variable you already have without you ever reading it. Never put a value on a command line or in a brief; \`armada secrets\` lists the names, and \`armada doctor\` names those \`[secrets] names\` in \`armada.toml\` expects and Armada lacks. Workers fetch them with \`armada run\`; a worker of another project never gets them.
|
|
4894
4976
|
2. **Find your coordination ticket.** When the owner gives the coordinator a ticket of its own (a run to carry out, for example "run this ticket end to end"), that ticket holds the run's history. Read its comments, newest first. A last comment \`Agent status: released — <text>\` is a hand-over: the previous coordinator stopped on purpose, \`<text>\` is the state it left (who runs, what was asked and answered, what remains), and the ticket is back without agent labels, waiting for you.
|
|
4895
4977
|
3. **Claim it with your own handle**, never the previous coordinator's: \`armada claim <ticket> --runtime <your runtime> --handle <your handle> --branch <default branch>\`. In a Conductor workspace the runtime is \`conductor\` and the handle \`"$CONDUCTOR_WORKSPACE_ID/$CONDUCTOR_SESSION_ID"\`; on a laptop, the runtime you run in (a value of the runtime label group, for example \`claude-code\`) and a handle that names your session. The claim is refused while the previous coordinator still holds the ticket: ask the owner whether it stopped before releasing it for them. Without a coordination ticket, skip this step.
|
|
4896
4978
|
4. **Read the fleet** (step 1 of the loop): \`armada status\` and \`armada inbox\` give each worker's handle, phase, question and hand-back. Trust them over the hand-over comment where they disagree: the comment is older. If a worker is in flight, start \`armada watch\` in the background now (see [Keep watching](#keep-watching)).
|
|
@@ -5065,6 +5147,7 @@ You are a worker. You own exactly one ticket, named in your launch brief. You tu
|
|
|
5065
5147
|
- **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.
|
|
5066
5148
|
- Work only in your own branch and worktree. Never touch another agent's checkout, and stop only the processes you started.
|
|
5067
5149
|
- Never print, commit or log a secret.
|
|
5150
|
+
- **The project's secrets** (an LLM provider key, a test database URL) come from Armada, never from your launch environment; \`armada secrets\` lists their names. Use them, in this order: \`armada run -- <command>\` for tests, builds and dev servers (they go in that command's environment only); \`armada secrets export --file <path>\` for a tool that reads a dotenv file, at a path git ignores (e.g. \`.env.local\`). Never run \`armada secrets get\`, and never echo, \`env\` or \`printenv\` a value: your command output is your transcript. A secret you need and do not have: ask the coordinator for it by name.
|
|
5068
5151
|
|
|
5069
5152
|
## Steps
|
|
5070
5153
|
|
|
@@ -5524,7 +5607,7 @@ async function loadStatus(config, opts) {
|
|
|
5524
5607
|
});
|
|
5525
5608
|
}
|
|
5526
5609
|
// package.json
|
|
5527
|
-
var version = "0.2.
|
|
5610
|
+
var version = "0.2.8";
|
|
5528
5611
|
|
|
5529
5612
|
// src/api.ts
|
|
5530
5613
|
var apiOf = (io, url, cliVersion = version) => armadaApi({ url, version: cliVersion, ...io.fetch ? { fetch: io.fetch } : {} });
|
|
@@ -5577,11 +5660,11 @@ async function fromArmada(io, credentials, purpose) {
|
|
|
5577
5660
|
return {
|
|
5578
5661
|
linearApiKey: answer.linear ? {
|
|
5579
5662
|
value: answer.linear.apiKey,
|
|
5580
|
-
detail: answer.linear.scope === "own" ? "your own key" : `the key of ${answer.organization.name}`
|
|
5663
|
+
detail: answer.linear.scope === "own" ? "your own key" : answer.linear.scope === "project" && purpose ? `the key of the project ${purpose.project}` : `the key of ${answer.organization.name}`
|
|
5581
5664
|
} : null
|
|
5582
5665
|
};
|
|
5583
5666
|
}
|
|
5584
|
-
async function loadCredentials(io, { armada = true, worker } = {}) {
|
|
5667
|
+
async function loadCredentials(io, { armada = true, worker, project } = {}) {
|
|
5585
5668
|
const machine = await loadMachine(io);
|
|
5586
5669
|
let ticket = null;
|
|
5587
5670
|
if (worker)
|
|
@@ -5604,7 +5687,8 @@ async function loadCredentials(io, { armada = true, worker } = {}) {
|
|
|
5604
5687
|
};
|
|
5605
5688
|
const local = resolveCredentials(sources);
|
|
5606
5689
|
const signIn = local.armadaSignIn;
|
|
5607
|
-
const
|
|
5690
|
+
const scoped = worker?.project ?? project;
|
|
5691
|
+
const purpose = worker && ticket ? { command: worker.command, project: worker.project, ticket } : scoped ? { project: scoped } : null;
|
|
5608
5692
|
if (signIn?.kind === "worker" && armada) {
|
|
5609
5693
|
if (signIn.project !== worker?.project)
|
|
5610
5694
|
throw new UsageError(`the worker session of ${signIn.ticket} is for the project ${signIn.project}, not ${worker?.project} (armada.toml): this repository is not its own`, `cd into the repository of ${signIn.project}`);
|
|
@@ -6781,13 +6865,36 @@ async function conductorChecks(io, config) {
|
|
|
6781
6865
|
}
|
|
6782
6866
|
];
|
|
6783
6867
|
}
|
|
6868
|
+
async function secretChecks(api, config, credentials) {
|
|
6869
|
+
const expected = config?.secrets.names ?? [];
|
|
6870
|
+
if (!config || !expected.length)
|
|
6871
|
+
return [];
|
|
6872
|
+
const signIn = credentials.armadaSignIn;
|
|
6873
|
+
const list = expected.join(", ");
|
|
6874
|
+
const warning = (message, fix) => [{ id: "secrets", level: "warning", message, fix }];
|
|
6875
|
+
if (!signIn)
|
|
6876
|
+
return warning(`the project expects the secrets ${list}; not checked: not signed in to Armada`, SIGN_IN_FIX);
|
|
6877
|
+
let set;
|
|
6878
|
+
try {
|
|
6879
|
+
set = (await api.listSecrets(signIn, projectOf(config))).map((s) => s.name);
|
|
6880
|
+
} catch (err) {
|
|
6881
|
+
if (!(err instanceof ArmadaApiError))
|
|
6882
|
+
throw err;
|
|
6883
|
+
return warning(`the project expects the secrets ${list}; not checked: ${err.message}`, err.next ?? "run doctor again once Armada answers");
|
|
6884
|
+
}
|
|
6885
|
+
const missing = expected.filter((n) => !set.includes(n));
|
|
6886
|
+
if (!missing.length)
|
|
6887
|
+
return [{ id: "secrets", level: "ok", message: `the secrets the project expects are set: ${list}`, fix: null }];
|
|
6888
|
+
return warning(`the project expects the secrets ${list}; not set in Armada: ${missing.join(", ")}`, "an owner or admin runs `armada secrets set <NAME>` for each (or sets it on the Keys page of Armada)");
|
|
6889
|
+
}
|
|
6784
6890
|
async function buildDoctor(io, armadaVersion) {
|
|
6785
6891
|
const root = (io.exec ? await gitRoot(io.exec, io.cwd) : null) ?? io.cwd;
|
|
6786
6892
|
const upgrade = (err) => err instanceof ArmadaApiError && err.upgrade ? err : null;
|
|
6787
6893
|
let outdated = null;
|
|
6788
6894
|
let loaded;
|
|
6895
|
+
const config = await projectConfig(root);
|
|
6789
6896
|
try {
|
|
6790
|
-
loaded = await loadCredentials(io);
|
|
6897
|
+
loaded = await loadCredentials(io, config ? { project: config.project.slug } : {});
|
|
6791
6898
|
} catch (err) {
|
|
6792
6899
|
outdated = upgrade(err);
|
|
6793
6900
|
if (!outdated)
|
|
@@ -6796,7 +6903,6 @@ async function buildDoctor(io, armadaVersion) {
|
|
|
6796
6903
|
}
|
|
6797
6904
|
const { machine, credentials } = loaded;
|
|
6798
6905
|
const api = apiOf(io, credentials.armadaApi.url, armadaVersion);
|
|
6799
|
-
const config = await projectConfig(root);
|
|
6800
6906
|
let signIn = [];
|
|
6801
6907
|
try {
|
|
6802
6908
|
signIn = await signInChecks(credentials, api);
|
|
@@ -6811,7 +6917,8 @@ async function buildDoctor(io, armadaVersion) {
|
|
|
6811
6917
|
...versionChecks(hostOf(credentials.armadaApi.url), api, armadaVersion, outdated),
|
|
6812
6918
|
...keyFileChecks(machine, credentials),
|
|
6813
6919
|
...await labelChecks(io, config, credentials),
|
|
6814
|
-
...await conductorChecks(io, config)
|
|
6920
|
+
...await conductorChecks(io, config),
|
|
6921
|
+
...await secretChecks(api, config, credentials)
|
|
6815
6922
|
];
|
|
6816
6923
|
return {
|
|
6817
6924
|
schemaVersion: 1,
|
|
@@ -7425,8 +7532,9 @@ async function statusAll(io, json) {
|
|
|
7425
7532
|
});
|
|
7426
7533
|
warning = read.warning;
|
|
7427
7534
|
const config = read.config;
|
|
7535
|
+
const own = p.ownLinearKey && !io.env.LINEAR_API_KEY?.trim() ? (await api.credentials(signIn, { project: p.slug })).linear?.apiKey : undefined;
|
|
7428
7536
|
const report = await loadStatus(config, {
|
|
7429
|
-
linearApiKey,
|
|
7537
|
+
linearApiKey: own ?? linearApiKey,
|
|
7430
7538
|
githubToken: credentials.githubToken,
|
|
7431
7539
|
...io.fetch ? { fetch: io.fetch } : {},
|
|
7432
7540
|
...io.now ? { now: io.now } : {}
|
|
@@ -7458,6 +7566,222 @@ ${"─".repeat(60)}
|
|
|
7458
7566
|
return projects.some((p) => p.error) ? 1 : 0;
|
|
7459
7567
|
}
|
|
7460
7568
|
|
|
7569
|
+
// src/secrets.ts
|
|
7570
|
+
import { dirname as dirname6, relative as relative3, resolve } from "node:path";
|
|
7571
|
+
var NAME_HINT = "upper snake case, e.g. OPENAI_API_KEY";
|
|
7572
|
+
var hhmm = (iso) => `${iso.slice(0, 16).replace("T", " ")} UTC`;
|
|
7573
|
+
function signInOf(config, credentials) {
|
|
7574
|
+
const signIn = credentials.armadaSignIn;
|
|
7575
|
+
if (!signIn)
|
|
7576
|
+
throw new UsageError("not signed in to Armada: a project's secrets are kept there", "armada login (a worker: the `armada login --launch-token` line of its launch message)");
|
|
7577
|
+
if (signIn.kind === "worker" && signIn.project !== config.project.slug)
|
|
7578
|
+
throw new UsageError(`the worker session of ${signIn.ticket} is for the project ${signIn.project}, not ${config.project.slug} (armada.toml): this repository is not its own`, `cd into the repository of ${signIn.project}`);
|
|
7579
|
+
return signIn;
|
|
7580
|
+
}
|
|
7581
|
+
function onlyOf(v) {
|
|
7582
|
+
if (v === undefined)
|
|
7583
|
+
return null;
|
|
7584
|
+
const names = v.split(",").map((n) => n.trim()).filter(Boolean);
|
|
7585
|
+
if (!names.length)
|
|
7586
|
+
throw new UsageError(`--only takes secret names separated by commas, ${NAME_HINT}`);
|
|
7587
|
+
const refusal = names.map(secretNameRefusal).find(Boolean);
|
|
7588
|
+
if (refusal)
|
|
7589
|
+
throw new UsageError(`--only: ${refusal}`);
|
|
7590
|
+
return [...new Set(names)];
|
|
7591
|
+
}
|
|
7592
|
+
function nameOf(rest, sub) {
|
|
7593
|
+
const [name, ...extra] = rest;
|
|
7594
|
+
if (extra.length)
|
|
7595
|
+
throw new UsageError(`secrets ${sub} takes one name: a value is never given on the command line, where it would stay in the shell history and in transcripts`, sub === "set" ? "armada secrets set <NAME>, then type the value at the hidden prompt" : null);
|
|
7596
|
+
if (!name)
|
|
7597
|
+
throw new UsageError(`secrets ${sub} needs a secret name, ${NAME_HINT}`);
|
|
7598
|
+
const refusal = secretNameRefusal(name);
|
|
7599
|
+
if (refusal)
|
|
7600
|
+
throw new UsageError(refusal);
|
|
7601
|
+
return name;
|
|
7602
|
+
}
|
|
7603
|
+
async function secretValue(io, name, options) {
|
|
7604
|
+
const variable = options["from-env"];
|
|
7605
|
+
const stdin = options["value-stdin"] === "true";
|
|
7606
|
+
if (variable !== undefined && stdin)
|
|
7607
|
+
throw new UsageError("--from-env and --value-stdin: one or the other");
|
|
7608
|
+
if (variable !== undefined) {
|
|
7609
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(variable))
|
|
7610
|
+
throw new UsageError("--from-env takes a variable name");
|
|
7611
|
+
const value = io.env[variable];
|
|
7612
|
+
if (!value)
|
|
7613
|
+
throw new UsageError(`${variable} is not set in this environment, so ${name} was not set`);
|
|
7614
|
+
return value;
|
|
7615
|
+
}
|
|
7616
|
+
if (stdin) {
|
|
7617
|
+
if (!io.readStdin)
|
|
7618
|
+
throw new UsageError("standard input cannot be read here");
|
|
7619
|
+
const value = (await io.readStdin()).replace(/\r?\n$/, "");
|
|
7620
|
+
if (!value)
|
|
7621
|
+
throw new UsageError(`standard input was empty, so ${name} was not set`);
|
|
7622
|
+
return value;
|
|
7623
|
+
}
|
|
7624
|
+
if (!io.interactive || !io.prompt)
|
|
7625
|
+
throw new UsageError(`no terminal to ask for the value of ${name}`, `--value-stdin to read it from standard input, or --from-env <VAR> to take it from a variable of this environment`);
|
|
7626
|
+
const value = await io.prompt(`${name} (hidden): `, { hidden: true });
|
|
7627
|
+
if (value === null)
|
|
7628
|
+
return null;
|
|
7629
|
+
if (!value)
|
|
7630
|
+
throw new UsageError(`no value given, so ${name} was not set`);
|
|
7631
|
+
return value;
|
|
7632
|
+
}
|
|
7633
|
+
function renderList(config, secrets) {
|
|
7634
|
+
const p = config.project.slug;
|
|
7635
|
+
if (!secrets.length)
|
|
7636
|
+
return `No secret for workers is set for ${p}.
|
|
7637
|
+
Next: armada secrets set <NAME> (an owner or admin), or the Keys page of Armada
|
|
7638
|
+
`;
|
|
7639
|
+
const width = Math.max(...secrets.map((s) => s.name.length));
|
|
7640
|
+
const lines = [`Secrets for workers of ${p} (names only; values stay in Armada)`];
|
|
7641
|
+
for (const s of secrets)
|
|
7642
|
+
lines.push(` ${s.name.padEnd(width)} ${s.scope.padEnd(12)} set by ${s.setBy}, ${hhmm(s.setAt)}${s.overridden ? " (the project's own wins)" : ""}`);
|
|
7643
|
+
return `${lines.join(`
|
|
7644
|
+
`)}
|
|
7645
|
+
`;
|
|
7646
|
+
}
|
|
7647
|
+
async function exportRefusal(io, path) {
|
|
7648
|
+
if (!io.exec)
|
|
7649
|
+
return "git cannot be run here to check that the file is ignored";
|
|
7650
|
+
const cwd = dirname6(path);
|
|
7651
|
+
const tracked = await io.exec("git", ["ls-files", "--error-unmatch", "--", path], { cwd }).catch(() => null);
|
|
7652
|
+
if (tracked?.code === 0)
|
|
7653
|
+
return `git tracks ${path}: secrets written there would be committed`;
|
|
7654
|
+
const ignored = await io.exec("git", ["check-ignore", "-q", "--", path], { cwd }).catch(() => null);
|
|
7655
|
+
if (ignored?.code === 0)
|
|
7656
|
+
return null;
|
|
7657
|
+
if (ignored?.code === 1)
|
|
7658
|
+
return `git does not ignore ${path}: secrets written there could be committed`;
|
|
7659
|
+
return `git cannot tell whether ${path} is ignored (is it in a git repository?)`;
|
|
7660
|
+
}
|
|
7661
|
+
async function secretsCommand(io, config, credentials, args) {
|
|
7662
|
+
const [sub = "list", ...rest] = args.rest;
|
|
7663
|
+
const signIn = signInOf(config, credentials);
|
|
7664
|
+
const api = apiOf(io, credentials.armadaApi.url);
|
|
7665
|
+
const project = projectOf(config);
|
|
7666
|
+
const p = config.project.slug;
|
|
7667
|
+
const allowed = {
|
|
7668
|
+
list: [],
|
|
7669
|
+
set: ["org", "value-stdin", "from-env"],
|
|
7670
|
+
unset: ["org"],
|
|
7671
|
+
get: [],
|
|
7672
|
+
export: ["file", "only"]
|
|
7673
|
+
};
|
|
7674
|
+
const options = allowed[sub];
|
|
7675
|
+
if (!options)
|
|
7676
|
+
throw new UsageError(`unknown secrets command "${sub}": list, set, unset, get or export`);
|
|
7677
|
+
for (const name of Object.keys(args.options))
|
|
7678
|
+
if (name !== "ticket" && !options.includes(name))
|
|
7679
|
+
throw new UsageError(`--${name} does not apply to secrets ${sub}`);
|
|
7680
|
+
if (args.json && sub !== "list")
|
|
7681
|
+
throw new UsageError(`--json does not apply to secrets ${sub}`);
|
|
7682
|
+
const scope = args.options.org === "true" ? "organization" : "project";
|
|
7683
|
+
const where = scope === "project" ? `the project ${p}` : "every project of the organization";
|
|
7684
|
+
if (sub === "list") {
|
|
7685
|
+
if (rest.length)
|
|
7686
|
+
throw new UsageError(`unexpected argument ${rest[0]}`);
|
|
7687
|
+
const secrets = await api.listSecrets(signIn, project);
|
|
7688
|
+
io.stdout(args.json ? `${JSON.stringify({ schemaVersion: 1, project: p, secrets }, null, 2)}
|
|
7689
|
+
` : renderList(config, secrets));
|
|
7690
|
+
return 0;
|
|
7691
|
+
}
|
|
7692
|
+
if (sub === "set") {
|
|
7693
|
+
const name = nameOf(rest, "set");
|
|
7694
|
+
const value = await secretValue(io, name, args.options);
|
|
7695
|
+
if (value === null) {
|
|
7696
|
+
io.stderr(`Cancelled. ${name} was not set.
|
|
7697
|
+
`);
|
|
7698
|
+
return 130;
|
|
7699
|
+
}
|
|
7700
|
+
await api.setSecret(signIn, { project, name, value, scope });
|
|
7701
|
+
io.stdout(`Set ${name} for ${where}. Workers get it on their next command.
|
|
7702
|
+
`);
|
|
7703
|
+
return 0;
|
|
7704
|
+
}
|
|
7705
|
+
if (sub === "unset") {
|
|
7706
|
+
const name = nameOf(rest, "unset");
|
|
7707
|
+
const deleted = await api.unsetSecret(signIn, { project, name, scope });
|
|
7708
|
+
io.stdout(deleted ? `Unset ${name} for ${where}.
|
|
7709
|
+
` : `${name} was not set for ${where}: nothing changed.
|
|
7710
|
+
`);
|
|
7711
|
+
return 0;
|
|
7712
|
+
}
|
|
7713
|
+
if (sub === "get") {
|
|
7714
|
+
const name = nameOf(rest, "get");
|
|
7715
|
+
const release = await api.releaseSecrets(signIn, project, [name]);
|
|
7716
|
+
for (const w of release.warnings)
|
|
7717
|
+
io.stderr(`! Armada: ${w}
|
|
7718
|
+
`);
|
|
7719
|
+
const found = release.secrets.find((s) => s.name === name);
|
|
7720
|
+
if (!found)
|
|
7721
|
+
throw new UsageError(`${name} is not set for ${p}`, "armada secrets, which lists the names set");
|
|
7722
|
+
io.stderr(`! The value of ${name} is now visible in this terminal, and in any transcript that reads this output. An agent never runs this: it uses \`armada run -- <command>\` or \`armada secrets export --file <path>\`.
|
|
7723
|
+
`);
|
|
7724
|
+
io.stdout(`${found.value}
|
|
7725
|
+
`);
|
|
7726
|
+
return 0;
|
|
7727
|
+
}
|
|
7728
|
+
if (rest.length)
|
|
7729
|
+
throw new UsageError(`unexpected argument ${rest[0]}`);
|
|
7730
|
+
const file = args.options.file;
|
|
7731
|
+
if (!file)
|
|
7732
|
+
throw new UsageError("secrets export needs --file <path>, a file git ignores (e.g. .env.local)");
|
|
7733
|
+
const path = resolve(io.cwd, file);
|
|
7734
|
+
const refusal = await exportRefusal(io, path);
|
|
7735
|
+
if (refusal)
|
|
7736
|
+
throw new UsageError(refusal, "a path git ignores, e.g. .env.local listed in .gitignore");
|
|
7737
|
+
const release = await api.releaseSecrets(signIn, project, onlyOf(args.options.only));
|
|
7738
|
+
for (const w of release.warnings)
|
|
7739
|
+
io.stderr(`! Armada: ${w}
|
|
7740
|
+
`);
|
|
7741
|
+
if (release.missing.length)
|
|
7742
|
+
io.stderr(`! Not set for ${p}: ${release.missing.join(", ")}
|
|
7743
|
+
`);
|
|
7744
|
+
const written = release.secrets.filter((s) => !/[\r\n\0]/.test(s.value));
|
|
7745
|
+
const skipped = release.secrets.filter((s) => !written.includes(s));
|
|
7746
|
+
if (skipped.length)
|
|
7747
|
+
io.stderr(`! Not written: ${skipped.map((s) => s.name).join(", ")}, whose value spans several lines; \`armada run -- <command>\` hands ${skipped.length === 1 ? "it" : "them"} over
|
|
7748
|
+
`);
|
|
7749
|
+
const lines = [
|
|
7750
|
+
`# The secrets for workers of ${p}, written by \`armada secrets export\`. Never commit this file.`,
|
|
7751
|
+
...written.map((s) => `${s.name}=${formatDotenvValue(s.name, s.value)}`)
|
|
7752
|
+
];
|
|
7753
|
+
await writePrivateFile(path, `${lines.join(`
|
|
7754
|
+
`)}
|
|
7755
|
+
`);
|
|
7756
|
+
const names = written.map((s) => s.name);
|
|
7757
|
+
io.stdout(`Wrote ${names.length} secret${names.length === 1 ? "" : "s"} of ${p} to ${relative3(io.cwd, path) || path} (mode 0600)${names.length ? `: ${names.join(", ")}` : ""}.
|
|
7758
|
+
`);
|
|
7759
|
+
return 0;
|
|
7760
|
+
}
|
|
7761
|
+
async function runCommand(io, config, credentials, args) {
|
|
7762
|
+
if (args.rest.length)
|
|
7763
|
+
throw new UsageError(`unexpected argument ${args.rest[0]}: the command goes after --`);
|
|
7764
|
+
const [command, ...commandArgs] = args.passthrough ?? [];
|
|
7765
|
+
if (!command)
|
|
7766
|
+
throw new UsageError("run needs a command after --, e.g. armada run -- bun test");
|
|
7767
|
+
if (!io.spawn)
|
|
7768
|
+
throw new UsageError("this terminal cannot run a command");
|
|
7769
|
+
const signIn = signInOf(config, credentials);
|
|
7770
|
+
const release = await apiOf(io, credentials.armadaApi.url).releaseSecrets(signIn, projectOf(config), onlyOf(args.options.only));
|
|
7771
|
+
for (const w of release.warnings)
|
|
7772
|
+
io.stderr(`! Armada: ${w}
|
|
7773
|
+
`);
|
|
7774
|
+
if (release.missing.length)
|
|
7775
|
+
io.stderr(`! Not set for ${config.project.slug}: ${release.missing.join(", ")}
|
|
7776
|
+
`);
|
|
7777
|
+
const values = Object.fromEntries(release.secrets.map((s) => [s.name, s.value]));
|
|
7778
|
+
const overridden = release.secrets.map((s) => s.name).filter((n) => io.env[n] !== undefined);
|
|
7779
|
+
if (overridden.length)
|
|
7780
|
+
io.stderr(`! armada run: the project's ${overridden.join(", ")} override${overridden.length === 1 ? "s" : ""} the variable${overridden.length === 1 ? "" : "s"} of the same name in this environment
|
|
7781
|
+
`);
|
|
7782
|
+
return io.spawn(command, commandArgs, { cwd: io.cwd, env: { ...io.env, ...values } });
|
|
7783
|
+
}
|
|
7784
|
+
|
|
7461
7785
|
// src/cli.ts
|
|
7462
7786
|
var COMMAND_HELP = {
|
|
7463
7787
|
status: ` status Tickets in flight, tickets ready to start and pull requests waiting
|
|
@@ -7539,6 +7863,26 @@ var COMMAND_HELP = {
|
|
|
7539
7863
|
default_profile; --profile overrides it, with --reason when it differs.
|
|
7540
7864
|
Signed in to Armada, the prompt starts with a one-time launch token, so
|
|
7541
7865
|
the worker needs no key. --prompt prints only the prompt, for \`--message-file -\`
|
|
7866
|
+
`,
|
|
7867
|
+
secrets: ` secrets The project's secrets for workers: names, project or organization,
|
|
7868
|
+
who set each and when; never a value. Needs a sign-in to Armada
|
|
7869
|
+
secrets set <NAME> [--org] [--value-stdin | --from-env <VAR>]
|
|
7870
|
+
Coordinator (owner or admin): set one for this project, or with --org
|
|
7871
|
+
for every project. The value comes from a hidden prompt, standard input
|
|
7872
|
+
or a variable of this environment, never from the command line
|
|
7873
|
+
secrets unset <NAME> [--org]
|
|
7874
|
+
Coordinator: unset one; workers no longer get it from their next command
|
|
7875
|
+
secrets export --file <path> [--only <A,B>]
|
|
7876
|
+
Write them to a dotenv file (mode 0600) for a tool that reads one;
|
|
7877
|
+
refused for a path git tracks or does not ignore
|
|
7878
|
+
secrets get <NAME>
|
|
7879
|
+
Print one value, for a person: it is then visible in any transcript.
|
|
7880
|
+
An agent uses \`armada run\` or \`secrets export\` instead
|
|
7881
|
+
`,
|
|
7882
|
+
run: ` run [--only <A,B>] -- <command> [args...]
|
|
7883
|
+
Run a command with the project's secrets in its environment (they win
|
|
7884
|
+
over variables of the same name, named on stderr): tests, builds, dev
|
|
7885
|
+
servers. Nothing is written to disk or printed. Exits with its code
|
|
7542
7886
|
`,
|
|
7543
7887
|
hook: ` hook stop Claude Code's Stop hook, installed by \`armada init\`: a coordinator
|
|
7544
7888
|
cannot end its turn while workers are in flight and no \`armada watch\`
|
|
@@ -7561,9 +7905,11 @@ var COMMAND_HELP = {
|
|
|
7561
7905
|
auth logout Remove Armada's keys from this machine
|
|
7562
7906
|
`
|
|
7563
7907
|
};
|
|
7564
|
-
var TICKET_OPTION = new Set(["report", "release", "ask", "merge"]);
|
|
7908
|
+
var TICKET_OPTION = new Set(["report", "release", "ask", "merge", "secrets", "run"]);
|
|
7565
7909
|
var CONFIG_OPTION = new Set([
|
|
7566
7910
|
"status",
|
|
7911
|
+
"secrets",
|
|
7912
|
+
"run",
|
|
7567
7913
|
"claim",
|
|
7568
7914
|
"report",
|
|
7569
7915
|
"release",
|
|
@@ -7574,7 +7920,7 @@ var CONFIG_OPTION = new Set([
|
|
|
7574
7920
|
"merge",
|
|
7575
7921
|
"brief"
|
|
7576
7922
|
]);
|
|
7577
|
-
var JSON_OPTION = new Set([...CONFIG_OPTION, "doctor", "auth", "whoami"]);
|
|
7923
|
+
var JSON_OPTION = new Set([...[...CONFIG_OPTION].filter((c) => c !== "run"), "doctor", "auth", "whoami"]);
|
|
7578
7924
|
var TICKET_HELP = ` --ticket <id> Ticket for report, release and ask (default ARMADA_TICKET, then the git
|
|
7579
7925
|
branch) and for merge (default: the ticket the PR branch names)
|
|
7580
7926
|
`;
|
|
@@ -7645,9 +7991,23 @@ var VALUE_OPTIONS = [
|
|
|
7645
7991
|
"options",
|
|
7646
7992
|
"timeout",
|
|
7647
7993
|
"launch-token",
|
|
7648
|
-
"api-url"
|
|
7994
|
+
"api-url",
|
|
7995
|
+
"only",
|
|
7996
|
+
"file",
|
|
7997
|
+
"from-env"
|
|
7998
|
+
];
|
|
7999
|
+
var FLAG_OPTIONS = [
|
|
8000
|
+
"dry-run",
|
|
8001
|
+
"no-lock",
|
|
8002
|
+
"no-ticket",
|
|
8003
|
+
"prompt",
|
|
8004
|
+
"wait",
|
|
8005
|
+
"note",
|
|
8006
|
+
"api-key",
|
|
8007
|
+
"no-stop-hook",
|
|
8008
|
+
"org",
|
|
8009
|
+
"value-stdin"
|
|
7649
8010
|
];
|
|
7650
|
-
var FLAG_OPTIONS = ["dry-run", "no-lock", "no-ticket", "prompt", "wait", "note", "api-key", "no-stop-hook"];
|
|
7651
8011
|
var COMMAND_OPTIONS = {
|
|
7652
8012
|
claim: ["runtime", "handle", "branch", "profile", "reason"],
|
|
7653
8013
|
report: ["ticket", "message", "message-file", "plan", "plan-file", "pr", "sha"],
|
|
@@ -7658,7 +8018,9 @@ var COMMAND_OPTIONS = {
|
|
|
7658
8018
|
init: ["program-root", "name", "slug", "no-stop-hook"],
|
|
7659
8019
|
merge: ["ticket", "no-ticket", "dry-run", "no-lock", "wait", "timeout"],
|
|
7660
8020
|
brief: ["profile", "reason", "prompt"],
|
|
7661
|
-
login: ["api-key", "launch-token", "api-url"]
|
|
8021
|
+
login: ["api-key", "launch-token", "api-url"],
|
|
8022
|
+
secrets: ["ticket", "org", "value-stdin", "from-env", "file", "only"],
|
|
8023
|
+
run: ["ticket", "only"]
|
|
7662
8024
|
};
|
|
7663
8025
|
var WORKER_COMMANDS = new Set(["claim", "report", "release", "ask"]);
|
|
7664
8026
|
function parseArgs(argv) {
|
|
@@ -7670,10 +8032,15 @@ function parseArgs(argv) {
|
|
|
7670
8032
|
config: null,
|
|
7671
8033
|
help: false,
|
|
7672
8034
|
version: false,
|
|
7673
|
-
options: {}
|
|
8035
|
+
options: {},
|
|
8036
|
+
passthrough: null
|
|
7674
8037
|
};
|
|
7675
8038
|
for (let k = 0;k < argv.length; k++) {
|
|
7676
8039
|
const a = argv[k];
|
|
8040
|
+
if (a === "--") {
|
|
8041
|
+
args.passthrough = argv.slice(k + 1);
|
|
8042
|
+
break;
|
|
8043
|
+
}
|
|
7677
8044
|
const named = a?.match(/^--([a-z-]+)(?:=([\s\S]*))?$/);
|
|
7678
8045
|
const name = named?.[1];
|
|
7679
8046
|
if (a === "--json")
|
|
@@ -7705,18 +8072,18 @@ function parseArgs(argv) {
|
|
|
7705
8072
|
}
|
|
7706
8073
|
async function findConfig(io, explicit, command = "status") {
|
|
7707
8074
|
if (explicit) {
|
|
7708
|
-
const path =
|
|
8075
|
+
const path = resolve2(io.cwd, explicit);
|
|
7709
8076
|
const text = await io.readFile(path);
|
|
7710
8077
|
if (text === null)
|
|
7711
8078
|
throw new UsageError(`${path} does not exist`, `armada ${command} --config <file>, with the path of an ${CONFIG_FILE}`);
|
|
7712
8079
|
return { path, text };
|
|
7713
8080
|
}
|
|
7714
|
-
for (let dir =
|
|
8081
|
+
for (let dir = resolve2(io.cwd);; dir = dirname7(dir)) {
|
|
7715
8082
|
const path = join6(dir, CONFIG_FILE);
|
|
7716
8083
|
const text = await io.readFile(path);
|
|
7717
8084
|
if (text !== null)
|
|
7718
8085
|
return { path, text };
|
|
7719
|
-
if (
|
|
8086
|
+
if (dirname7(dir) === dir)
|
|
7720
8087
|
break;
|
|
7721
8088
|
}
|
|
7722
8089
|
throw new UsageError(`no ${CONFIG_FILE} found in ${io.cwd} or any parent directory, so this is not a repository Armada runs`, `armada init to set this repository up, armada ${command} --config <file> to use another ${CONFIG_FILE}, or armada status --all to see the registered projects`);
|
|
@@ -7724,7 +8091,7 @@ async function findConfig(io, explicit, command = "status") {
|
|
|
7724
8091
|
async function status2(io, args) {
|
|
7725
8092
|
const { path, text } = await findConfig(io, args.config, "status");
|
|
7726
8093
|
const config = parseConfig(text, path);
|
|
7727
|
-
const { credentials } = await loadCredentials(io);
|
|
8094
|
+
const { credentials } = await loadCredentials(io, { project: config.project.slug });
|
|
7728
8095
|
const { linearApiKey, githubToken } = credentials;
|
|
7729
8096
|
if (!linearApiKey)
|
|
7730
8097
|
throw missingKey(LINEAR_KEY);
|
|
@@ -7794,6 +8161,24 @@ async function run(argv, io) {
|
|
|
7794
8161
|
throw new UsageError(`--${name} does not apply to ${args.command}`);
|
|
7795
8162
|
if (args.all && args.command !== "status")
|
|
7796
8163
|
throw new UsageError(`--all does not apply to ${args.command}`);
|
|
8164
|
+
if (args.passthrough && args.command !== "run")
|
|
8165
|
+
throw new UsageError(`-- does not apply to ${args.command}: only \`armada run\` runs a command`);
|
|
8166
|
+
if (args.command === "secrets" || args.command === "run") {
|
|
8167
|
+
const { path, text } = await findConfig(io, args.config, args.command);
|
|
8168
|
+
const config = parseConfig(text, path);
|
|
8169
|
+
const sets = args.command === "secrets" && ["set", "unset"].includes(args.rest[0] ?? "");
|
|
8170
|
+
const { credentials } = await loadCredentials(io, {
|
|
8171
|
+
armada: false,
|
|
8172
|
+
...sets ? {} : {
|
|
8173
|
+
worker: {
|
|
8174
|
+
command: args.command,
|
|
8175
|
+
project: config.project.slug,
|
|
8176
|
+
ticket: (stored) => currentTicket(io, config, args.options.ticket, stored)
|
|
8177
|
+
}
|
|
8178
|
+
}
|
|
8179
|
+
});
|
|
8180
|
+
return await (args.command === "run" ? runCommand : secretsCommand)(io, config, credentials, args);
|
|
8181
|
+
}
|
|
7797
8182
|
const worker = { claim, report, release, ask, inbox: inbox2, answer }[args.command];
|
|
7798
8183
|
if (worker) {
|
|
7799
8184
|
const { path, text } = await findConfig(io, args.config, args.command);
|
|
@@ -7804,25 +8189,28 @@ async function run(argv, io) {
|
|
|
7804
8189
|
project: config.project.slug,
|
|
7805
8190
|
ticket: (stored) => command === "claim" ? args.rest[0]?.toUpperCase() ?? null : currentTicket(io, config, args.options.ticket, stored)
|
|
7806
8191
|
} : undefined;
|
|
7807
|
-
const { credentials } = await loadCredentials(io, scope ? { worker: scope } : {});
|
|
8192
|
+
const { credentials } = await loadCredentials(io, scope ? { worker: scope } : { project: config.project.slug });
|
|
7808
8193
|
return await worker(io, config, credentials, args);
|
|
7809
8194
|
}
|
|
7810
8195
|
if (args.command === "watch") {
|
|
7811
8196
|
const { path, text } = await findConfig(io, args.config, "watch");
|
|
7812
|
-
const
|
|
7813
|
-
|
|
8197
|
+
const config = parseConfig(text, path);
|
|
8198
|
+
const { credentials } = await loadCredentials(io, { project: config.project.slug });
|
|
8199
|
+
return await watch2(io, config, credentials, args, path);
|
|
7814
8200
|
}
|
|
7815
8201
|
if (args.command === "hook")
|
|
7816
8202
|
return await hookStop(io, args.rest, (at) => findConfig(at, null, "hook"));
|
|
7817
8203
|
if (args.command === "merge") {
|
|
7818
8204
|
const { path, text } = await findConfig(io, args.config, "merge");
|
|
7819
|
-
const
|
|
7820
|
-
|
|
8205
|
+
const config = parseConfig(text, path);
|
|
8206
|
+
const { credentials } = await loadCredentials(io, { project: config.project.slug });
|
|
8207
|
+
return await merge2(io, config, credentials, args, path);
|
|
7821
8208
|
}
|
|
7822
8209
|
if (args.command === "brief") {
|
|
7823
8210
|
const { path, text } = await findConfig(io, args.config, "brief");
|
|
7824
|
-
const
|
|
7825
|
-
|
|
8211
|
+
const config = parseConfig(text, path);
|
|
8212
|
+
const { credentials } = await loadCredentials(io, { project: config.project.slug });
|
|
8213
|
+
return await brief2(io, config, credentials, args, version, path);
|
|
7826
8214
|
}
|
|
7827
8215
|
if (args.command === "status") {
|
|
7828
8216
|
noExtra(args.rest);
|
|
@@ -7908,6 +8296,35 @@ function echo(before, after) {
|
|
|
7908
8296
|
return "\b \b".repeat(before.length - common) + after.slice(common);
|
|
7909
8297
|
}
|
|
7910
8298
|
|
|
8299
|
+
// src/spawn.ts
|
|
8300
|
+
import { spawn } from "node:child_process";
|
|
8301
|
+
import { constants } from "node:os";
|
|
8302
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
8303
|
+
var spawnInherited = (command, args, { cwd, env }) => new Promise((done, fail) => {
|
|
8304
|
+
const child = spawn(command, args, { cwd, env, stdio: "inherit" });
|
|
8305
|
+
const fromTerminal = process.stdin.isTTY === true;
|
|
8306
|
+
const handlers = SIGNALS.map((signal) => {
|
|
8307
|
+
const handler = () => {
|
|
8308
|
+
if (signal !== "SIGINT" || !fromTerminal)
|
|
8309
|
+
child.kill(signal);
|
|
8310
|
+
};
|
|
8311
|
+
process.on(signal, handler);
|
|
8312
|
+
return [signal, handler];
|
|
8313
|
+
});
|
|
8314
|
+
const stop = () => {
|
|
8315
|
+
for (const [signal, handler] of handlers)
|
|
8316
|
+
process.off(signal, handler);
|
|
8317
|
+
};
|
|
8318
|
+
child.on("error", (err) => {
|
|
8319
|
+
stop();
|
|
8320
|
+
fail(err.code === "ENOENT" ? new Error(`${command}: command not found`) : err);
|
|
8321
|
+
});
|
|
8322
|
+
child.on("exit", (code, signal) => {
|
|
8323
|
+
stop();
|
|
8324
|
+
done(code ?? 128 + (signal ? constants.signals[signal] ?? 0 : 0));
|
|
8325
|
+
});
|
|
8326
|
+
});
|
|
8327
|
+
|
|
7911
8328
|
// src/main.ts
|
|
7912
8329
|
function gitBranch() {
|
|
7913
8330
|
try {
|
|
@@ -7965,7 +8382,7 @@ function openUrl(url) {
|
|
|
7965
8382
|
return false;
|
|
7966
8383
|
const [command, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : ["xdg-open", [url]];
|
|
7967
8384
|
try {
|
|
7968
|
-
const child =
|
|
8385
|
+
const child = spawn2(command, args, { stdio: "ignore", detached: true });
|
|
7969
8386
|
child.on("error", () => {});
|
|
7970
8387
|
child.unref();
|
|
7971
8388
|
return true;
|
|
@@ -7974,7 +8391,7 @@ function openUrl(url) {
|
|
|
7974
8391
|
}
|
|
7975
8392
|
}
|
|
7976
8393
|
var exec = (command, args, { cwd }) => new Promise((done, fail) => {
|
|
7977
|
-
const child =
|
|
8394
|
+
const child = spawn2(command, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
|
|
7978
8395
|
let stdout = "";
|
|
7979
8396
|
let stderr = "";
|
|
7980
8397
|
child.stdout.setEncoding("utf8").on("data", (d) => {
|
|
@@ -8002,6 +8419,7 @@ var code = await run(process.argv.slice(2), {
|
|
|
8002
8419
|
gitBranch,
|
|
8003
8420
|
readStdin,
|
|
8004
8421
|
exec,
|
|
8422
|
+
spawn: spawnInherited,
|
|
8005
8423
|
openUrl
|
|
8006
8424
|
});
|
|
8007
8425
|
process.exitCode = code;
|