@the-vibe-company/armada 0.1.14 → 0.1.16

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.
Files changed (3) hide show
  1. package/README.md +21 -5
  2. package/dist/armada.js +156 -28
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -93,7 +93,7 @@ armada release --reason "wrong ticket"
93
93
  - `report`, `ask` and `answer` accept `--message-file -` to read standard input to EOF, including a pipe or a shell heredoc. For example: `printf 'line one\nline two' | bun run armada report implementing --ticket ABC-12 --message-file -`. An explicitly empty or whitespace-only message file or stdin exits 2 before any tracker or database write, with a retry naming `--message` or a non-empty pipe. A `ready-to-merge` report may still omit the message option.
94
94
  - `claim` and `report` read the ticket back and print where it stands, for example `Now: In Progress · phase implementing · runtime Conductor · profile none`, so a worker can check it without opening Linear. `--json` carries the same as `state`.
95
95
  - `ready-to-merge` is refused unless the pull request is open in the project repository, `--sha` is the full 40-character SHA of its head, and every check in `[gates] required_checks` is green on that head (with none declared: at least one check, all green). It needs a GitHub token.
96
- - `release` removes the phase and runtime labels, moves the ticket back to the team's first unstarted state and posts `Agent status: released — <reason>`.
96
+ - `release` removes the phase and runtime labels, keeps the configured ready label so the ticket can be taken again, moves the ticket back to the team's first unstarted state and posts `Agent status: released — <reason>`.
97
97
  - `report` and `release` find the ticket from `--ticket`, then `ARMADA_TICKET`, then the current git branch (`feature/abc-12-…`).
98
98
  - Turso is optional. When it is not configured or not reachable, the commands still write Linear and print a warning.
99
99
 
@@ -109,6 +109,7 @@ armada answer --note ABC-12 "main moved: rebase before you ship" # an unsolicit
109
109
 
110
110
  - `ask` reports the `blocked` phase with `Agent status: blocked — question: <first line>` (the rest and the numbered options below it) and adds a `question` item to the coordinator's inbox in Turso. The worker then stops and waits for the answer in its session, and reports the phase it resumes. It finds the ticket like `report`.
111
111
  - `inbox` lists the coordinator's open items (questions, requests, hand-backs) and silent workers, oldest first. A worker is silent when it holds a ticket, its newest Turso event is older than `policy.silence_minutes`, and its phase does not wait on someone else. It reads Turso only (no Linear key) and records that the coordinator is at work, for the dashboard. `--wait` polls every 5 s and marks the items that were not there before with `*`; loop on it.
112
+ - A coordinator's own claim is never listed as silent in its inbox: only an exact, nonempty handle match is excluded, not its questions, requests or hand-backs. `inbox` takes the reading coordinator's handle from `ARMADA_COORDINATOR_HANDLE` first, otherwise from both `CONDUCTOR_WORKSPACE_ID` and `CONDUCTOR_SESSION_ID` joined as `workspace/session`. Blank values are ignored; with no complete identity, silence detection is unchanged. Local coordinators should set `ARMADA_COORDINATOR_HANDLE` to the handle used for their claim. The same identity is used for every `--wait` poll and the dashboard presence record; the fleet-wide `status` and dashboard silence rules are unchanged.
112
113
  - `answer` never calls a runtime: deliver the answer first with the runtime guide's message section. It posts `Agent status: <current phase> — answer: …` on the ticket and resolves the item. An item id needs Turso; a ticket id answers that ticket's open questions and also works without Turso. `--note` records a message the worker did not ask for as `Agent status: <phase> — note: …`. These two are the coordinator's records: Armada never reads them as the worker's phase, hand-back or sign of life. Only questions and requests can be answered; `merge` resolves hand-backs, and `release` and `merge` resolve the ticket's open questions. A worker that does not report within `policy.silence_minutes` of an answer shows as silent.
113
114
  - The dashboard adds two kinds of request, signed by the person who made them. An `answer-request` carries the owner's answer to an open question: deliver it, then `armada answer <request id> "<answer>"`, which resolves the request and its question and names the requester on the ticket (answering the question itself also closes a waiting request). A `launch-request` asks to launch a ready ticket on a profile: launch it as usual; the worker's `armada claim` resolves it and posts who asked. To decline one, `armada answer <request id> "<why>"`: it is closed with the reason and nothing is posted on the ticket.
114
115
 
@@ -124,7 +125,7 @@ armada merge 34 # or the pull request URL; --ticket ABC-12 when the
124
125
  - Hints, never blocking: top-level functions, classes, types and constants the pull request removes or renames that the base branch still uses in files the pull request does not touch.
125
126
  - One merge at a time per project: a `merge` lease in Turso (20 minutes, renewed before the merge) makes a second coordinator wait. When Turso is configured but unreachable the merge is refused; `--no-lock` forces it, with a warning and "merged without lock" in the ticket's merged comment. Without Turso configured at all (one coordinator) the merge runs unlocked with a warning.
126
127
  - The merge is `gh pr merge <n> --squash --match-head-commit <sha>`, never `--delete-branch` (it removes local worktrees that have the branch checked out). A GitHub 5xx is retried with backoff, each time after checking that the pull request is still open at the same head. Success is reported only once GitHub shows the pull request as merged at that head.
127
- - Then the ticket moves to Done with its agent labels removed, the pull request is linked, `Agent status: merged — …` is posted, the Turso hand-back is resolved and the runtime handle released. The output lists the workers in flight to tell and the worker session to archive with its runtime guide, when one is installed for that runtime in `.agents/skills` or `.claude/skills`; otherwise it says there is none, since a local session or subagent has nothing to archive.
128
+ - Then the ticket moves to Done with its agent labels and `[tracker] ready_label` removed (unrelated labels stay), the pull request is linked, `Agent status: merged — …` is posted, the Turso hand-back is resolved and the runtime handle released. The output lists the workers in flight to tell and the worker session to archive with its runtime guide, when one is installed for that runtime in `.agents/skills` or `.claude/skills`; otherwise it says there is none, since a local session or subagent has nothing to archive.
128
129
  - It runs `gh` and `git` in the repository checkout and needs `LINEAR_API_KEY` and a GitHub token.
129
130
 
130
131
  ## Watch the fleet (dashboard)
@@ -159,7 +160,7 @@ ARMADA_AUTH_URL=http://localhost:4822 ARMADA_AUTH_OWNER_EMAILS=you@example.com b
159
160
  **Deploy on Vercel.** Create a project from this repository and set these options:
160
161
 
161
162
  - 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`.
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.
163
+ - 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`. With accounts and the vault (`ARMADA_SECRETS_KEY`, see [Keys kept in Armada](#keys-kept-in-armada)), the last four move to the Keys page and are only a fallback here. 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.
163
164
  - The keys stay on the server; the browser only receives the fleet reading.
164
165
 
165
166
  **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.
@@ -179,6 +180,19 @@ ARMADA_AUTH_URL=http://localhost:4822 ARMADA_AUTH_OWNER_EMAILS=you@example.com b
179
180
  - 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
  - Terminals sign in too (see [Sign in from a terminal](#sign-in-from-a-terminal)): `armada login` shows a code that the person confirms on the dashboard's `/device` page, and owners create API keys for headless coordinators on the Organization page. A key is shown once, belongs to the organization, and revoking it signs out whatever uses it. The CLI calls only `/api/cli/*`; without accounts those routes refuse with the next step.
181
182
 
183
+ **Keys kept in Armada.** With accounts, the organization's keys can live in Armada instead of on every machine: an owner or admin enters them once on the Keys page (Organization > Keys), and every signed-in terminal receives what it needs (see [Keys](#keys)). It turns on with one more variable:
184
+
185
+ | Variable | What |
186
+ | --- | --- |
187
+ | `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) |
188
+
189
+ - The Keys page holds the Linear API key; the Turso access: a Platform API token (`turso auth api-tokens mint armada`) with the Turso organization and database names, or, without one, the database URL and a database token; and a GitHub token for the dashboard's own reads. Each member may add their own Linear key: their terminals use it, so the comments they post carry their name.
190
+ - 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, person and name.
191
+ - A signed-in terminal (a session of `armada login` or an organization API key) calls `POST /api/cli/credentials`. It receives the Linear key (the person's own first) and a Turso database token made for it through the Turso Platform API, which expires after 4 hours and is renewed without asking. Without a Platform token, the stored database token is handed out as is, and the audit list says so. Answers are never cached; a terminal asking more than 30 times a minute is refused for a minute.
192
+ - 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.
193
+ - The dashboard reads each organization's fleet with that organization's keys from the vault, each missing one from its environment variables; once they are all on the Keys page, its environment shrinks to the accounts variables and `ARMADA_SECRETS_KEY`. A Turso database given on the Keys page is the organization's own: the projects registered in it belong to that organization, and, unless it is the deployment's first organization, it is read with none of the environment's keys (nor `ARMADA_REPOSITORIES`), since its registry could name any repository.
194
+ - 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.
195
+
182
196
  **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):
183
197
 
184
198
  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`.
@@ -215,7 +229,9 @@ armada logout # revokes this terminal's session and removes it from the machi
215
229
 
216
230
  ## Keys
217
231
 
218
- Armada needs a few keys. Set them up once per machine with `armada auth login`, or pass them as environment variables, which always win over the stored ones (the way to go in CI and cloud sandboxes).
232
+ Armada needs a few keys. A terminal signed in to an Armada that keeps its organization's keys ([Keys kept in Armada](#keys-kept-in-armada)) needs none on the machine: `armada login`, then `armada status`. Otherwise set them up once per machine with `armada auth login`, or pass them as environment variables (the way to go in CI and cloud sandboxes).
233
+
234
+ Each key comes from the environment first, then from Armada when signed in, then from the credentials file. Armada is asked only for what the environment does not set, on each command that needs keys, so a key replaced on the Keys page takes effect on the next command. The Linear key it gives stays in memory; the Turso token it makes for the terminal is kept in the credentials file (`ARMADA_TURSO_LEASE`, with its expiry) and renewed when less than an hour is left. When Armada cannot be reached, the command warns and goes on with the machine's keys (and the Turso token kept earlier, until it expires). `armada logout` and `armada auth logout` remove the kept token.
219
235
 
220
236
  | Variable | What | Needed by |
221
237
  | --- | --- | --- |
@@ -225,7 +241,7 @@ Armada needs a few keys. Set them up once per machine with `armada auth login`,
225
241
  | `GITHUB_TOKEN` or `GH_TOKEN` | GitHub token; otherwise `gh auth token` is used | pull requests and CI |
226
242
 
227
243
  - `armada auth login` asks only for the keys that are missing, with hidden input for tokens, and stores them in `~/.config/armada/credentials` (or `$XDG_CONFIG_HOME/armada/credentials`), mode 0600 in a 0700 directory. Without a terminal it asks nothing and lists the variables to set instead.
228
- - `armada auth status [--json]` shows which keys are set and where each comes from. It never prints a value.
244
+ - `armada auth status [--json]` shows which keys are set and where each comes from (for example `Armada: your own key`). It never prints a value.
229
245
  - `armada auth logout` removes Armada's keys from the file.
230
246
 
231
247
  The credentials file is a plain dotenv file (`KEY=value` lines, `#` comments) that a shell can also `source`. You may edit it by hand; Armada keeps your other lines and comments when it updates it. GitHub tokens are not stored there: use the environment or `gh auth login`.
package/dist/armada.js CHANGED
@@ -310,10 +310,12 @@ var displayCode = (code) => code.length === 8 ? `${code.slice(0, 4)}-${code.slic
310
310
  class ArmadaApiError extends Error {
311
311
  next;
312
312
  signedOut;
313
- constructor(message, next = null, signedOut = false) {
313
+ status;
314
+ constructor(message, next = null, signedOut = false, status = null) {
314
315
  super(message);
315
316
  this.next = next;
316
317
  this.signedOut = signedOut;
318
+ this.status = status;
317
319
  }
318
320
  }
319
321
  var LOGIN_NEXT = "armada login";
@@ -364,7 +366,7 @@ function armadaApi(opts) {
364
366
  const refusal = (status, body, what) => {
365
367
  const error = typeof body.error === "string" ? body.error : `HTTP ${status}`;
366
368
  const next = typeof body.next === "string" ? body.next : status === 401 ? LOGIN_NEXT : null;
367
- return new ArmadaApiError(what ? `${what}: ${error}` : error, next, status === 401);
369
+ return new ArmadaApiError(what ? `${what}: ${error}` : error, next, status === 401, status);
368
370
  };
369
371
  return {
370
372
  async startDeviceLogin() {
@@ -407,6 +409,20 @@ function armadaApi(opts) {
407
409
  throw refusal(status, body, status === 401 ? null : "Armada could not say who is signed in");
408
410
  return body;
409
411
  },
412
+ async credentials(signIn, held) {
413
+ const { status, body } = await call("POST", "credentials", { signIn, body: { turso: held } });
414
+ if (status !== 200)
415
+ throw refusal(status, body, status === 401 ? null : "Armada gave no keys");
416
+ const str = (v) => typeof v === "string" && v.length > 0;
417
+ const org = body.organization;
418
+ const linear = body.linear;
419
+ const turso = body.turso;
420
+ const shaped = body.schemaVersion === 1 && str(org?.id) && (linear === null || str(linear?.apiKey)) && (turso === null || turso?.kind === "kept" && str(turso.revision) && str(turso.expiresAt) || (turso?.kind === "minted" || turso?.kind === "stored") && str(turso.url) && str(turso.token));
421
+ if (!shaped)
422
+ throw new ArmadaApiError(`Armada (${host}) answered the keys in a shape this CLI does not know`);
423
+ const warnings = Array.isArray(body.warnings) ? body.warnings.filter((w) => typeof w === "string") : [];
424
+ return { ...body, warnings };
425
+ },
410
426
  async signOut(signIn) {
411
427
  const { status, body } = await call("DELETE", "session", { signIn });
412
428
  if (status !== 200)
@@ -3243,6 +3259,23 @@ var SESSION_TOKEN_VARIABLE = "ARMADA_SESSION_TOKEN";
3243
3259
  var API_KEY_VARIABLE = "ARMADA_API_KEY";
3244
3260
  var API_URL_VARIABLE = "ARMADA_API_URL";
3245
3261
  var SIGNED_IN_TO_VARIABLE = "ARMADA_SIGNED_IN_TO";
3262
+ var TURSO_LEASE_VARIABLE = "ARMADA_TURSO_LEASE";
3263
+ var formatLease = (lease) => Buffer.from(JSON.stringify(lease), "utf8").toString("base64url");
3264
+ function parseLease(value) {
3265
+ if (!value?.trim())
3266
+ return null;
3267
+ try {
3268
+ const l = JSON.parse(Buffer.from(value.trim(), "base64url").toString("utf8"));
3269
+ const keys = ["api", "organization", "url", "token", "expiresAt", "revision"];
3270
+ if (!keys.every((k) => typeof l[k] === "string" && l[k]))
3271
+ return null;
3272
+ if (Number.isNaN(Date.parse(String(l.expiresAt))))
3273
+ return null;
3274
+ return Object.fromEntries(keys.map((k) => [k, String(l[k])]));
3275
+ } catch {
3276
+ return null;
3277
+ }
3278
+ }
3246
3279
  function armadaAddress(url) {
3247
3280
  try {
3248
3281
  const u = new URL(url.trim());
@@ -3280,7 +3313,7 @@ var fromEnv = (env, variable) => {
3280
3313
  const value = clean(env[variable]);
3281
3314
  return value ? { value, source: { kind: "env", variable } } : null;
3282
3315
  };
3283
- function resolveCredentials({ env, store = {}, personal, ghToken }) {
3316
+ function resolveCredentials({ env, store = {}, personal, ghToken, armada }) {
3284
3317
  const fromStore = (variable) => {
3285
3318
  const value = clean(store[variable]);
3286
3319
  return value ? { value, source: { kind: "store" } } : null;
@@ -3301,10 +3334,12 @@ function resolveCredentials({ env, store = {}, personal, ghToken }) {
3301
3334
  const storedKey = fromStore(API_KEY_VARIABLE);
3302
3335
  const armadaSignInElsewhere = !here && (session || storedKey) ? signedInTo : null;
3303
3336
  const armadaSignIn = envKey ? { kind: "api-key", key: envKey.value, source: envKey.source } : session && here ? { kind: "session", token: session.value, source: session.source } : storedKey && here ? { kind: "api-key", key: storedKey.value, source: storedKey.source } : null;
3337
+ const fromArmada = (value, detail) => value && detail ? { value, source: { kind: "armada", detail } } : null;
3338
+ const tursoPair = armada?.turso && !fromEnv(env, "ARMADA_TURSO_URL") && !fromEnv(env, "ARMADA_TURSO_TOKEN") ? armada.turso : null;
3304
3339
  const found = {
3305
- linearApiKey: stored("LINEAR_API_KEY"),
3306
- tursoUrl: stored("ARMADA_TURSO_URL") ?? (tursoUrlConfig ? { value: tursoUrlConfig, source: { kind: "config", key: "turso.url" } } : null),
3307
- tursoToken: stored("ARMADA_TURSO_TOKEN"),
3340
+ linearApiKey: fromEnv(env, "LINEAR_API_KEY") ?? fromArmada(armada?.linearApiKey?.value, armada?.linearApiKey?.detail) ?? fromStore("LINEAR_API_KEY"),
3341
+ tursoUrl: fromArmada(tursoPair?.url, tursoPair?.detail) ?? stored("ARMADA_TURSO_URL") ?? (tursoUrlConfig ? { value: tursoUrlConfig, source: { kind: "config", key: "turso.url" } } : null),
3342
+ tursoToken: fromArmada(tursoPair?.token, tursoPair?.detail) ?? stored("ARMADA_TURSO_TOKEN"),
3308
3343
  githubToken: fromEnv(env, "GITHUB_TOKEN") ?? fromEnv(env, "GH_TOKEN") ?? fromGh()
3309
3344
  };
3310
3345
  return {
@@ -3325,7 +3360,7 @@ function resolveCredentials({ env, store = {}, personal, ghToken }) {
3325
3360
  }
3326
3361
  var missingKeys = (credentials) => STORED_KEYS.filter((k) => credentials[k.name] === null);
3327
3362
  function missingKeyMessage(key) {
3328
- return `${key.variable} is not set. Set it in the environment, or run \`armada auth login\` to store it on this machine (${key.hint}).`;
3363
+ return `${key.variable} is not set. Set it in the environment, run \`armada auth login\` to store it on this machine (${key.hint}), or sign in with \`armada login\` to an Armada that keeps your organization's keys.`;
3329
3364
  }
3330
3365
  // ../core/src/dotenv.ts
3331
3366
  var ASSIGNMENT = /^\s*(export\s+)?([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;
@@ -3726,6 +3761,8 @@ async function readInbox(db, o) {
3726
3761
  }));
3727
3762
  const asking = new Set(items.filter((i) => i.kind === "question").map((i) => i.ticket));
3728
3763
  for (const h of handles) {
3764
+ if (o.coordinator && h.handle === o.coordinator)
3765
+ continue;
3729
3766
  const e = events[h.ticket];
3730
3767
  if (e && (e.kind === "release" || e.kind === "merge"))
3731
3768
  continue;
@@ -4605,13 +4642,17 @@ async function closeTicket(ctx, ticket, merged, unlocked) {
4605
4642
  const done = ticket.statusType === "completed" ? null : firstState(ticket.states, "completed");
4606
4643
  await ctx.linear.updateTicket(ticket.uuid, {
4607
4644
  ...done ? { stateId: done.id } : {},
4608
- removeLabelIds: [...others(ticket, groups.phaseGroup, null), ...others(ticket, groups.runtimeGroup, null)]
4645
+ removeLabelIds: [
4646
+ ...others(ticket, groups.phaseGroup, null),
4647
+ ...others(ticket, groups.runtimeGroup, null),
4648
+ ...ticket.labels.filter((label) => label.name === ctx.config.tracker.readyLabel).map((label) => label.id)
4649
+ ]
4609
4650
  });
4610
4651
  if (!ticket.prs.some((p) => p.url === merged.url))
4611
4652
  await ctx.linear.linkUrl(ticket.uuid, merged.url, merged.title || `Pull request #${merged.number}`);
4612
4653
  await ctx.linear.comment(ticket.uuid, `Agent status: merged — PR #${merged.number} squash-merged into ${merged.baseRef} as ${merged.mergeCommit ?? "unknown"}, head ${merged.headSha}${unlocked ? ", merged without lock (--no-lock)" : ""}`);
4613
4654
  return [
4614
- `${ticket.id}: ${done ? `moved to ${done.name}` : "state unchanged"}, agent labels removed, merged status posted.`
4655
+ `${ticket.id}: ${done ? `moved to ${done.name}` : "state unchanged"}, agent and ready labels removed, merged status posted.`
4615
4656
  ];
4616
4657
  }
4617
4658
  async function mergePullRequest(ctx, input) {
@@ -4637,7 +4678,7 @@ async function mergePullRequest(ctx, input) {
4637
4678
  try {
4638
4679
  lines.push(...await closeTicket(ctx, c.ticket, merged, !!input.noLock));
4639
4680
  } catch (err) {
4640
- throw new Error(`#${merged.number} is merged, but Linear could not be updated (${err instanceof Error ? err.message : String(err)}); close ${c.ticket.id} by hand: Done, agent labels removed, pull request linked`);
4681
+ throw new Error(`#${merged.number} is merged, but Linear could not be updated (${err instanceof Error ? err.message : String(err)}); close ${c.ticket.id} by hand: Done, agent and ready labels removed, pull request linked`);
4641
4682
  }
4642
4683
  return after(ctx, c, merged, lines);
4643
4684
  };
@@ -5229,7 +5270,7 @@ async function loadStatus(config, opts) {
5229
5270
  });
5230
5271
  }
5231
5272
  // package.json
5232
- var version = "0.1.14";
5273
+ var version = "0.1.16";
5233
5274
 
5234
5275
  // src/io.ts
5235
5276
  class UsageError extends Error {
@@ -5252,15 +5293,91 @@ async function loadMachine(io) {
5252
5293
  ]);
5253
5294
  return { paths, store, personal };
5254
5295
  }
5255
- async function loadCredentials(io) {
5296
+ var hhmm = (iso) => `${iso.slice(0, 16).replace("T", " ")} UTC`;
5297
+ var wantsArmada = (env) => !env.LINEAR_API_KEY?.trim() || !env.ARMADA_TURSO_URL?.trim() && !env.ARMADA_TURSO_TOKEN?.trim();
5298
+ var fromLease = (lease) => ({
5299
+ url: lease.url,
5300
+ token: lease.token,
5301
+ detail: `a token made for this terminal, expires ${hhmm(lease.expiresAt)}`
5302
+ });
5303
+ async function fromArmada(io, machine, credentials) {
5304
+ const signIn = credentials.armadaSignIn;
5305
+ if (!signIn)
5306
+ return null;
5307
+ const now = (io.now ?? (() => new Date))();
5308
+ const address = armadaAddress(credentials.armadaApi.url);
5309
+ const stored = parseLease(machine.store?.values[TURSO_LEASE_VARIABLE]);
5310
+ const lease = stored && stored.api === address && Date.parse(stored.expiresAt) > now.getTime() ? stored : null;
5311
+ const keep = async (next) => {
5312
+ if (!machine.paths || next === null && !machine.store?.assigned.includes(TURSO_LEASE_VARIABLE))
5313
+ return;
5314
+ await updateCredentialStore(machine.paths, { [TURSO_LEASE_VARIABLE]: next ? formatLease(next) : null }).catch((err) => io.stderr(`! the Turso token from Armada could not be kept in ${machine.paths?.credentials} (${err.code ?? "error"}); it is asked again next time
5315
+ `));
5316
+ };
5317
+ let answer;
5318
+ try {
5319
+ answer = await armadaApi({ url: credentials.armadaApi.url, ...io.fetch ? { fetch: io.fetch } : {} }).credentials(signIn, lease ? { revision: lease.revision, expiresAt: lease.expiresAt } : null);
5320
+ } catch (err) {
5321
+ if (!(err instanceof ArmadaApiError))
5322
+ throw err;
5323
+ if (err.signedOut || err.status === 403) {
5324
+ await keep(null);
5325
+ io.stderr(`! Armada gave no keys (${err.message}); using this machine's${err.next ? `. Next: ${err.next}` : ""}
5326
+ `);
5327
+ return null;
5328
+ }
5329
+ if (err.status === 503 && !lease)
5330
+ return null;
5331
+ io.stderr(`! Armada gave no keys (${err.message}); using this machine's${lease ? " and the Turso token it made earlier" : ""}${err.next ? `. Next: ${err.next}` : ""}
5332
+ `);
5333
+ return lease ? { linearApiKey: null, turso: fromLease(lease) } : null;
5334
+ }
5335
+ for (const w of answer.warnings)
5336
+ io.stderr(`! Armada: ${w}
5337
+ `);
5338
+ const linearApiKey = answer.linear ? {
5339
+ value: answer.linear.apiKey,
5340
+ detail: answer.linear.scope === "own" ? "your own key" : `the key of ${answer.organization.name}`
5341
+ } : null;
5342
+ const t = answer.turso;
5343
+ if (t?.kind === "minted") {
5344
+ const next = {
5345
+ api: address,
5346
+ organization: answer.organization.id,
5347
+ url: t.url,
5348
+ token: t.token,
5349
+ expiresAt: t.expiresAt,
5350
+ revision: t.revision
5351
+ };
5352
+ await keep(next);
5353
+ return { linearApiKey, turso: fromLease(next) };
5354
+ }
5355
+ if (t?.kind === "kept" && lease)
5356
+ return { linearApiKey, turso: fromLease(lease) };
5357
+ await keep(null);
5358
+ return {
5359
+ linearApiKey,
5360
+ turso: t?.kind === "stored" ? { url: t.url, token: t.token, detail: `the stored Turso access of ${answer.organization.name}` } : null
5361
+ };
5362
+ }
5363
+ async function loadCredentials(io, { armada = true } = {}) {
5256
5364
  const machine = await loadMachine(io);
5257
- const credentials = resolveCredentials({
5365
+ let gh;
5366
+ const sources = {
5258
5367
  env: io.env,
5259
- ghToken: io.ghToken,
5368
+ ghToken: () => {
5369
+ if (gh === undefined)
5370
+ gh = io.ghToken();
5371
+ return gh;
5372
+ },
5260
5373
  ...machine.store ? { store: machine.store.values } : {},
5261
5374
  ...machine.personal ? { personal: machine.personal.config } : {}
5262
- });
5263
- return { machine, credentials };
5375
+ };
5376
+ const local = resolveCredentials(sources);
5377
+ if (!armada || !local.armadaSignIn || !wantsArmada(io.env))
5378
+ return { machine, credentials: local };
5379
+ const keys = await fromArmada(io, machine, local);
5380
+ return { machine, credentials: keys ? resolveCredentials({ ...sources, armada: keys }) : local };
5264
5381
  }
5265
5382
  var describeSource = (s) => {
5266
5383
  switch (s.kind) {
@@ -5268,6 +5385,8 @@ var describeSource = (s) => {
5268
5385
  return `environment (${s.variable})`;
5269
5386
  case "store":
5270
5387
  return "credentials file";
5388
+ case "armada":
5389
+ return `Armada: ${s.detail}`;
5271
5390
  case "config":
5272
5391
  return `personal config (${s.key})`;
5273
5392
  case "gh":
@@ -5399,13 +5518,14 @@ async function authStatus(io, json) {
5399
5518
  async function authLogout(io) {
5400
5519
  const paths = requirePaths(machinePaths(io.env));
5401
5520
  const store = await readCredentialStore(paths.credentials);
5402
- const stored = STORED_KEYS.filter((k) => store.assigned.includes(k.variable));
5521
+ const variables = [...STORED_KEYS.map((k) => k.variable), TURSO_LEASE_VARIABLE];
5522
+ const stored = variables.filter((v) => store.assigned.includes(v));
5403
5523
  if (!stored.length) {
5404
5524
  io.stdout(`No Armada key is stored in ${paths.credentials}.
5405
5525
  `);
5406
5526
  } else {
5407
- await updateCredentialStore(paths, Object.fromEntries(STORED_KEYS.map((k) => [k.variable, null])));
5408
- io.stdout(`Removed ${stored.map((k) => k.variable).join(", ")} from ${paths.credentials}.
5527
+ await updateCredentialStore(paths, Object.fromEntries(variables.map((v) => [v, null])));
5528
+ io.stdout(`Removed ${stored.join(", ")} from ${paths.credentials}.
5409
5529
  `);
5410
5530
  }
5411
5531
  const fromEnv = STORED_KEYS.filter((k) => io.env[k.variable]?.trim()).map((k) => k.variable);
@@ -5938,8 +6058,12 @@ async function inbox2(io, config, credentials, a) {
5938
6058
  if (!db)
5939
6059
  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)");
5940
6060
  try {
6061
+ const workspace = io.env.CONDUCTOR_WORKSPACE_ID?.trim();
6062
+ const session = io.env.CONDUCTOR_SESSION_ID?.trim();
6063
+ const coordinator = io.env.ARMADA_COORDINATOR_HANDLE?.trim() || (workspace && session ? `${workspace}/${session}` : null);
5941
6064
  const report = await checkInbox(db, {
5942
6065
  project: config.project.slug,
6066
+ coordinator,
5943
6067
  silentAfterMinutes: config.policy.silentAfterMinutes,
5944
6068
  now: io.now ?? (() => new Date),
5945
6069
  ...wait ? { wait: { timeoutMs, sleep: io.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms))) } } : {}
@@ -6204,7 +6328,8 @@ async function loginWithApiKey(io, credentials) {
6204
6328
  await updateCredentialStore(p, {
6205
6329
  [API_KEY_VARIABLE]: key,
6206
6330
  [SESSION_TOKEN_VARIABLE]: null,
6207
- [SIGNED_IN_TO_VARIABLE]: armadaAddress(url)
6331
+ [SIGNED_IN_TO_VARIABLE]: armadaAddress(url),
6332
+ [TURSO_LEASE_VARIABLE]: null
6208
6333
  });
6209
6334
  io.stdout(`Signed in to ${hostOf(credentials.armadaApi.url)} as ${describeIdentity(identity)}.
6210
6335
  The key is stored in ${p.credentials}.
@@ -6212,7 +6337,7 @@ The key is stored in ${p.credentials}.
6212
6337
  return 0;
6213
6338
  }
6214
6339
  async function login(io, apiKey) {
6215
- const { machine, credentials } = await loadCredentials(io);
6340
+ const { machine, credentials } = await loadCredentials(io, { armada: false });
6216
6341
  const host = hostOf(credentials.armadaApi.url);
6217
6342
  if (credentials.armadaSignIn?.source.kind === "env")
6218
6343
  io.stderr(`! ${API_KEY_VARIABLE} is set in the environment: it wins over what \`armada login\` stores.
@@ -6237,7 +6362,8 @@ Then confirm it at ${code.verificationUriComplete}
6237
6362
  await updateCredentialStore(p, {
6238
6363
  [SESSION_TOKEN_VARIABLE]: token,
6239
6364
  [API_KEY_VARIABLE]: null,
6240
- [SIGNED_IN_TO_VARIABLE]: armadaAddress(url)
6365
+ [SIGNED_IN_TO_VARIABLE]: armadaAddress(url),
6366
+ [TURSO_LEASE_VARIABLE]: null
6241
6367
  });
6242
6368
  if (previous && previous !== token)
6243
6369
  await apiOf(io, storedAt(machine)).signOut({ kind: "session", token: previous }).catch(() => {});
@@ -6249,7 +6375,7 @@ Then confirm it at ${code.verificationUriComplete}
6249
6375
  return 0;
6250
6376
  }
6251
6377
  async function whoami(io, json) {
6252
- const { credentials } = await loadCredentials(io);
6378
+ const { credentials } = await loadCredentials(io, { armada: false });
6253
6379
  const signIn = requireSignIn(credentials);
6254
6380
  const identity = await apiOf(io, credentials.armadaApi.url).whoami(signIn);
6255
6381
  if (json) {
@@ -6263,10 +6389,10 @@ async function whoami(io, json) {
6263
6389
  return 0;
6264
6390
  }
6265
6391
  async function logout(io) {
6266
- const { machine } = await loadCredentials(io);
6392
+ const { machine } = await loadCredentials(io, { armada: false });
6267
6393
  const p = paths(io);
6268
6394
  const at = storedAt(machine);
6269
- const stored = [SESSION_TOKEN_VARIABLE, API_KEY_VARIABLE].filter((k) => machine.store?.assigned.includes(k));
6395
+ const stored = [SESSION_TOKEN_VARIABLE, API_KEY_VARIABLE, TURSO_LEASE_VARIABLE].filter((k) => machine.store?.assigned.includes(k));
6270
6396
  const session = machine.store?.values[SESSION_TOKEN_VARIABLE]?.trim();
6271
6397
  if (session) {
6272
6398
  await apiOf(io, at).signOut({ kind: "session", token: session }).catch((err) => io.stderr(`! the session could not be revoked on Armada (${err instanceof Error ? err.message : String(err)}); it expires on its own
@@ -6276,7 +6402,8 @@ async function logout(io) {
6276
6402
  await updateCredentialStore(p, {
6277
6403
  [SESSION_TOKEN_VARIABLE]: null,
6278
6404
  [API_KEY_VARIABLE]: null,
6279
- [SIGNED_IN_TO_VARIABLE]: null
6405
+ [SIGNED_IN_TO_VARIABLE]: null,
6406
+ [TURSO_LEASE_VARIABLE]: null
6280
6407
  });
6281
6408
  io.stdout(`Signed out of ${hostOf(at)}: removed the sign-in from ${p.credentials}.
6282
6409
  `);
@@ -6739,7 +6866,7 @@ Options:
6739
6866
  ${TICKET_HELP} -h, --help Show this help; \`armada <command> --help\` shows one command
6740
6867
  -v, --version Print the version
6741
6868
 
6742
- Keys (the environment always wins over the file):
6869
+ Keys (the environment first, then Armada when signed in, then the file):
6743
6870
  LINEAR_API_KEY Linear API key (required by status, init, brief, claim, report,
6744
6871
  release, ask and answer)
6745
6872
  ARMADA_TURSO_URL Turso database URL (required by init, inbox and status --all;
@@ -6753,7 +6880,8 @@ Keys (the environment always wins over the file):
6753
6880
  Files:
6754
6881
  $XDG_CONFIG_HOME/armada (default ~/.config/armada)
6755
6882
  credentials KEY=value lines, mode 0600, written by \`armada auth login\` and
6756
- \`armada login\` (the sign-in: ARMADA_SESSION_TOKEN or ARMADA_API_KEY)
6883
+ \`armada login\` (the sign-in: ARMADA_SESSION_TOKEN or ARMADA_API_KEY; the
6884
+ Turso token Armada made for this terminal: ARMADA_TURSO_LEASE)
6757
6885
  config.toml personal defaults: language, [turso] url, [dashboard] url, [api] url
6758
6886
  `;
6759
6887
  function commandHelp(command) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-vibe-company/armada",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "type": "module",
5
5
  "description": "Run a fleet of coding agents on one project: the armada command line.",
6
6
  "license": "MIT",