@bugb-technologies/bravos 1.0.3 → 1.2.0
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 +7 -4
- package/dist/account.js +41 -5
- package/dist/artifacts.js +23 -10
- package/dist/ci.js +14 -1
- package/dist/cli.js +123 -13
- package/dist/device.js +124 -0
- package/dist/doctor.js +3 -0
- package/dist/guide.js +3 -3
- package/dist/help.js +17 -6
- package/dist/licence.js +6 -3
- package/dist/palette.js +100 -0
- package/dist/plugin-release.js +63 -13
- package/dist/setup.js +1 -1
- package/dist/start/answers.js +82 -0
- package/dist/start/index.js +442 -0
- package/dist/start/repos.js +78 -0
- package/dist/start/ui.js +219 -0
- package/dist/watch-frame.js +28 -16
- package/dist/watch.js +40 -1
- package/docs/GUIDE.md +6 -2
- package/hooks/lib/autopilot.mjs +3 -22
- package/hooks/lib/briefing.mjs +18 -15
- package/hooks/lib/palette.mjs +115 -0
- package/hooks/lib/pre-pr.mjs +1 -1
- package/hooks/lib/proving.mjs +25 -0
- package/hooks/lib/refresh.mjs +203 -0
- package/hooks/session-start.mjs +4 -1
- package/package.json +3 -1
- package/templates/omp/bravos.js +5 -0
package/README.md
CHANGED
|
@@ -10,7 +10,9 @@ npm install -g @bugb-technologies/bravos
|
|
|
10
10
|
|
|
11
11
|
The command it installs is `bravos`.
|
|
12
12
|
|
|
13
|
-
Then
|
|
13
|
+
Then run **`bravos start`**: a guided setup that asks one question at a time (terminal colours, licence, tools, which repository, which AI tools, pull-request checks, a daily or weekly scheduled run in GitHub Actions, and how testing is allowed), shows every change and the equivalent `bravos init` command, and writes nothing until you choose Apply. It ends by telling you the one thing to type in your agent (`/bravos-context`, then `/bravos-annotate`); Bravos never starts an agent itself. `bravos start --again` re-asks with your previous answers selected; `bravos start --yes --preset pr <dir>` takes every default in a script (it never records a testing permission on your behalf).
|
|
14
|
+
|
|
15
|
+
By hand instead, in order: `bravos account activate` signs you in once in the browser and writes the licence (a 30-day Team trial when the account has no plan; skip this to stay on Free), `bravos init` in a repository writes the skills, hooks and MCP wiring, and `bravos setup` puts the analyzer and the code graph on the machine (Team plan). Node 20 or newer; guardlink and cxg are installed by `bravos setup --tools -y` or by hand.
|
|
14
16
|
|
|
15
17
|
**Used the Python `bravos` before?** Its `bravos` command usually sits in `~/.local/bin`, which most shells search before npm's folder, so it would still answer when you type `bravos`. Keep it under another name, and this CLI keeps using its code graph and analyzer until `bravos setup` installs its own:
|
|
16
18
|
|
|
@@ -22,7 +24,8 @@ Or remove it (`pipx uninstall bravos` or `uv tool uninstall bravos`). `which -a
|
|
|
22
24
|
|
|
23
25
|
## Commands
|
|
24
26
|
|
|
25
|
-
- `bravos
|
|
27
|
+
- `bravos start [dir]`: the guided first run described above. `--again`, `--yes`, `--preset annotate|pr|everything`.
|
|
28
|
+
- `bravos init`: write skills, MCP wiring and the session-start hook into the current repo. `--agent claude,codex` picks the harnesses instead of detecting them. `--pre-pr-hook` also registers the PreToolUse gate on `gh pr create` / `gh pr ready` and lists it under `pre_pr` in `.guardlink/config.json`, so guardlink's agent block names it after `guardlink sync`; `--ci` also writes the GitHub Actions workflows (`--workflows pr-gate,nightly-claude,nightly-codex` picks which, `--schedule weekday|daily|weekly` sets how often the nightly runs; either implies `--ci`); `--scope` writes the loopback-only cxg scope starter to `.guardlink/scope.yaml` when no scope file exists (never overwritten). A repo with a `.cursor/` folder also gets `.cursor/rules/bravos.mdc`, a pointer to the skills.
|
|
26
29
|
- `bravos sync`: refresh the installed skills and wiring to match this version of bravos; it also adds the cxg and codegraph MCP servers once they are installed (bravos's own committed MCP config carries guardlink only). The codegraph server is registered by its full path with the graph store as `BRAVOS_CODEGRAPH_DIR`, so the MCP tools read the graphs `bravos graph build` writes; after a `bravos setup` that stages a new bundle, `sync` refreshes that one entry, and keeps every other existing entry as it is.
|
|
27
30
|
- `bravos setup`: puts the binaries bravos drives on this machine. The analyzer (`bravos-cli`, SAST) and the code graph (`codegraph-build`, `codegraph-mcp`) are signed bundles fetched through the account portal on the Team plan — the portal verifies the licence, the CLI verifies each file's Ed25519 signature before it unpacks, and nothing under `$BRAVOS_HOME` changes until every check has passed; `--tools -y` also installs guardlink (npm) and cxg (cargo). `--check` reports, `--dry-run` says what would happen.
|
|
28
31
|
- `bravos graph`: `graph build [DIR]` indexes a repository (`--scip no-exec` by default, so no repository code runs); `graph <question> [args] --json` asks it — the same answers as the `codegraph_` MCP tools, through a one-call MCP session on stdio; `graph --json` lists every question this machine's binary answers.
|
|
@@ -161,7 +164,7 @@ How new exposures get proven is the team's call, not a fixed rule. The first tim
|
|
|
161
164
|
|
|
162
165
|
It redraws within a couple of seconds of a file change (`fs.watch`, debounced; one snapshot at a time), re-reads boundaries, the model's size and PRs every `--interval` seconds (default 60), and asks the code graph again every `--graph-interval` seconds (default 300). Read-only and free: no model, nothing written to the repo. Autopilot logs each nudge to `.bravos/watch/events.jsonl`, a local log with its own `.gitignore`, capped at 500 lines.
|
|
163
166
|
|
|
164
|
-
Three columns from 150 wide, two from 110, one column from 80 (a split pane), a compact list below that (`--compact` forces it); the panels scroll when the terminal is shorter than they are. Keys: `n` copies the next command, `r` opens the intent review page, `d` writes guardlink's dashboard to a temp file and opens it, `g` asks the code graph a question (`bravos graph <q>`), `t` shows test-next and stale claims in full, `i` shows the recorded intent (`.guardlink/intent.md`, with who answered the review), `u` refreshes everything now, `j`/`k` (or the arrows, space, `G`) scroll, `?` the guide, `q` quits. Overlays (`t`, `i`, `?`, a graph answer) wrap to the terminal and scroll with the same keys; any other key closes them. `--once` prints one frame (and is what happens when stdout is not a terminal), `--json` one snapshot (`bravos.watch/v1`). `NO_COLOR` or `BRAVOS_WATCH_COLOR=off` prints it plain.
|
|
167
|
+
Three columns from 150 wide, two from 110, one column from 80 (a split pane), a compact list below that (`--compact` forces it); the panels scroll when the terminal is shorter than they are. Keys: `n` copies the next command, `r` opens the intent review page, `d` writes guardlink's dashboard to a temp file and opens it, `g` asks the code graph a question (`bravos graph <q>`), `t` shows test-next and stale claims in full, `i` shows the recorded intent (`.guardlink/intent.md`, with who answered the review), `u` refreshes everything now, `j`/`k` (or the arrows, space, `G`) scroll, `?` the guide, `q` quits. Overlays (`t`, `i`, `?`, a graph answer) wrap to the terminal and scroll with the same keys; any other key closes them. `--once` prints one frame (and is what happens when stdout is not a terminal), `--json` one snapshot (`bravos.watch/v1`). `c` switches the colours between dark, light and neutral. `NO_COLOR` or `BRAVOS_WATCH_COLOR=off` prints it plain; on a live terminal bravos asks it for its background colour and picks the light or dark palette (see `BRAVOS_THEME` below).
|
|
165
168
|
|
|
166
169
|
## Getting started: `bravos next`
|
|
167
170
|
|
|
@@ -173,7 +176,7 @@ Three columns from 150 wide, two from 110, one column from 80 (a split pane), a
|
|
|
173
176
|
|
|
174
177
|
## Session start: a briefing for the model, a banner for you
|
|
175
178
|
|
|
176
|
-
The session-start hook prints one JSON object. Its `additionalContext` is the briefing: open exposures by severity, coverage, confirmed findings, what to test next, stale claims, tickets, work in flight and the intent state, sent to the model on every start, resume, clear and compact. On a fresh start only (`source: startup`, or a manual run), its `systemMessage` carries a banner for the human, which the model does not see: the bravos logo, repo and branch, the counts, the top three threats (or the confirmed findings to fix now) beside a three-step quick start chosen from the repo's state, and a short introduction to bravos while `.guardlink/intent.md` is missing. It is plain text within 80 columns. The registered command carries `--harness claude` or `--harness codex` so the quick start prints `/bravos-…` or `$bravos-…`; `bravos sync` replaces the older entry without the flag, and Codex asks you to trust the changed hook once in `/hooks`. Set `BRAVOS_BANNER=off` to hide the banner; the briefing is unchanged. The banner is drawn in bravos's brand colours; `NO_COLOR` or `BRAVOS_BANNER_COLOR=off` prints it plain. Codex lists a hook's message as a warning (behind F2), so Codex gets a two-line summary instead of the art. opencode finds the skills through its skill tool but lists only its own `/commands` and runs no hooks, so when opencode is in use (`.opencode/`, `opencode.json`, or `opencode` on PATH) bravos also writes one `.opencode/commands/<skill>.md` per skill (so `/bravos`, `/bravos-ship` and the rest appear), `.opencode/plugins/bravos.js` (an opencode 2.x plugin that adds the briefing to the system prompt of each request), and guardlink under `mcp` in `opencode.json`. Antigravity (`agy`) reads `.agents/hooks.json`; bravos adds a `bravos` SessionStart group there that hands the briefing to the model, since Antigravity documents no way for a hook to show text to you.
|
|
179
|
+
The session-start hook prints one JSON object. Its `additionalContext` is the briefing: open exposures by severity, coverage, confirmed findings, what to test next, stale claims, tickets, work in flight and the intent state, sent to the model on every start, resume, clear and compact. On a fresh start only (`source: startup`, or a manual run), its `systemMessage` carries a banner for the human, which the model does not see: the bravos logo, repo and branch, the counts, the top three threats (or the confirmed findings to fix now) beside a three-step quick start chosen from the repo's state, and a short introduction to bravos while `.guardlink/intent.md` is missing. It is plain text within 80 columns. The registered command carries `--harness claude` or `--harness codex` so the quick start prints `/bravos-…` or `$bravos-…`; `bravos sync` replaces the older entry without the flag, and Codex asks you to trust the changed hook once in `/hooks`. Set `BRAVOS_BANNER=off` to hide the banner; the briefing is unchanged. The banner is drawn in bravos's brand colours; `NO_COLOR` or `BRAVOS_BANNER_COLOR=off` prints it plain. Colours follow the terminal's background: `BRAVOS_THEME=light|dark|neutral` picks them, otherwise `COLORFGBG`, the choice saved by `bravos start`, then `neutral`, whose colours read on light and dark backgrounds alike (`bravos doctor` says which and why). Codex lists a hook's message as a warning (behind F2), so Codex gets a two-line summary instead of the art. opencode finds the skills through its skill tool but lists only its own `/commands` and runs no hooks, so when opencode is in use (`.opencode/`, `opencode.json`, or `opencode` on PATH) bravos also writes one `.opencode/commands/<skill>.md` per skill (so `/bravos`, `/bravos-ship` and the rest appear), `.opencode/plugins/bravos.js` (an opencode 2.x plugin that adds the briefing to the system prompt of each request), and guardlink under `mcp` in `opencode.json`. Antigravity (`agy`) reads `.agents/hooks.json`; bravos adds a `bravos` SessionStart group there that hands the briefing to the model, since Antigravity documents no way for a hook to show text to you.
|
|
177
180
|
|
|
178
181
|
omp runs neither Claude Code's nor Codex's hooks, so when omp is in use (a `.omp/` folder, or `omp` on PATH) `bravos init` and `sync` also write `.omp/extensions/bravos.js`, which omp loads by itself: it shows the same banner above the editor at session start and hands the briefing to the model, hidden, with the first prompt. In none of these harnesses do you need to type a command for the briefing; `/bravos` is for deciding the next step. Anywhere else, the bravos skill runs `node .bravos/hooks/session-start.mjs --briefing`, which prints the briefing as plain text.
|
|
179
182
|
|
package/dist/account.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// @comment -- "bravos account: how a licence gets onto this machine. `activate` is the device-code pairing with the account portal (one POST to start, the browser to approve, polling until the portal hands back a signed token); `import` takes a downloaded file. Either way the token is verified by the same offline verifier before it is written, so a token the portal signed with a key this build does not trust is refused here, not at the first gated command. The origin is fixed (BRAVOS_ACCOUNT_ORIGIN overrides it for a local portal), no proxy is read from the environment, and the token is written 0600."
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
|
-
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { chmodSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { hostname } from 'node:os';
|
|
4
5
|
import { join } from 'node:path';
|
|
6
|
+
import { refreshLib, userAgent } from './device.js';
|
|
5
7
|
import { licenceLib, licenceLines } from './licence.js';
|
|
6
8
|
import { BravosError } from './types.js';
|
|
7
9
|
export const ACTIVATION_PATH = '/api/v1/cli/activation';
|
|
@@ -60,7 +62,9 @@ export async function importLicence(path, io) {
|
|
|
60
62
|
const L = await licenceLib();
|
|
61
63
|
return [`Licence written to ${file}`, ...licenceLines(L, status)];
|
|
62
64
|
}
|
|
63
|
-
|
|
65
|
+
/** What this machine calls itself in the portal's device list: the host name, printable ASCII only, at most 64 characters. */
|
|
66
|
+
export const deviceName = (raw = hostname()) => raw.replace(/[^\x20-\x7e]/g, '').trim().slice(0, 64) || 'unnamed machine';
|
|
67
|
+
// @comment -- "The device-code flow: POST /api/v1/cli/activation (body: this machine's name and refresh: true, which asks the portal for a short-lived per-machine token this build keeps current), show the code and open the verification URL, then poll /api/v1/cli/activation/poll with the device code as a bearer until the portal answers 200 {license} (428 pending, 429 slow down, 410 expired or consumed, 402 trial ended, 403 no licence assigned to this person or the machine limit reached). The device code never goes anywhere but that origin, and the token it yields is verified before it is written. When the token is a device token (a `did` claim), the device code becomes this machine's refresh secret and is kept in device.json (0600) beside the licence."
|
|
64
68
|
export async function activate(io) {
|
|
65
69
|
const L = await licenceLib();
|
|
66
70
|
const origin = accountOrigin(io.env, L);
|
|
@@ -68,10 +72,10 @@ export async function activate(io) {
|
|
|
68
72
|
const sleep = io.sleep ?? ((s) => new Promise((r) => setTimeout(r, s * 1000)));
|
|
69
73
|
const now = io.now ?? (() => Date.now() / 1000);
|
|
70
74
|
const open = io.open ?? defaultOpen;
|
|
71
|
-
const ua = { 'User-Agent':
|
|
75
|
+
const ua = { 'User-Agent': userAgent(), Accept: 'application/json' };
|
|
72
76
|
let start;
|
|
73
77
|
try {
|
|
74
|
-
const r = await f(`${origin}${ACTIVATION_PATH}`, { method: 'POST', headers: { ...ua, 'Content-Type': 'application/json' }, body:
|
|
78
|
+
const r = await f(`${origin}${ACTIVATION_PATH}`, { method: 'POST', headers: { ...ua, 'Content-Type': 'application/json' }, body: JSON.stringify({ device_name: deviceName(), refresh: true }) });
|
|
75
79
|
if (r.status === 404 || r.status === 405)
|
|
76
80
|
throw new BravosError(`${origin} does not offer CLI sign-in yet; download the licence from ${L.ACCOUNT_LICENCES} and run bravos account import <file>`);
|
|
77
81
|
if (!r.ok)
|
|
@@ -129,12 +133,44 @@ export async function activate(io) {
|
|
|
129
133
|
}
|
|
130
134
|
throw new BravosError(`this account's Team trial has ended and it has no plan, so no licence was written; this machine stays on Free (the research loop keeps working). Choose a plan at ${upgrade}, then run bravos account activate again`);
|
|
131
135
|
}
|
|
136
|
+
// 403: the person was signed in but the portal will not license this machine for them. Nothing is written.
|
|
137
|
+
if (r.status === 403) {
|
|
138
|
+
let error = null;
|
|
139
|
+
let manage = `${origin}/dashboard/license`;
|
|
140
|
+
try {
|
|
141
|
+
const b = (await r.json());
|
|
142
|
+
error = b?.error;
|
|
143
|
+
if (typeof b?.manage === 'string' && b.manage.startsWith(origin + '/'))
|
|
144
|
+
manage = b.manage;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
/* the default page */
|
|
148
|
+
}
|
|
149
|
+
if (error === 'device_limit')
|
|
150
|
+
throw new BravosError(`you already have the most machines your account allows, so no licence was written; remove one at ${manage} (or run bravos account devices / bravos account revoke <id> on a machine that is signed in), then run bravos account activate again`);
|
|
151
|
+
if (error === 'licence_not_assigned')
|
|
152
|
+
throw new BravosError(`you do not hold a licence on your team's account yet, so no licence was written; this machine stays on Free. Ask an owner or admin to assign you one, or request it at ${manage}, then run bravos account activate again`);
|
|
153
|
+
throw new BravosError(`${origin} refused to license this machine (HTTP 403${typeof error === 'string' ? `: ${error}` : ''}); see ${manage}`);
|
|
154
|
+
}
|
|
132
155
|
if (!r.ok)
|
|
133
156
|
throw new BravosError(`${origin} answered HTTP ${r.status} while waiting; run bravos account activate again`);
|
|
134
157
|
const body = (await r.json());
|
|
135
158
|
if (typeof body?.license !== 'string')
|
|
136
159
|
throw new BravosError(`${origin} approved the code but sent no licence; download it from ${L.ACCOUNT_LICENCES} and run bravos account import <file>`);
|
|
137
160
|
const { file, status } = await installToken(body.license, io.env, origin);
|
|
138
|
-
|
|
161
|
+
const lines = [`Licence written to ${file}`, ...licenceLines(L, status)];
|
|
162
|
+
const R = await refreshLib();
|
|
163
|
+
const did = R.claimsOf(body.license.trim())?.did;
|
|
164
|
+
if (typeof did === 'string' && R.isDeviceSecret(start.device_code)) {
|
|
165
|
+
R.writeDevice(io.env, { origin, device_id: R.isDeviceId(did) ? did : null, device_secret: start.device_code });
|
|
166
|
+
lines.push(`This machine is signed in to ${origin}; bravos renews its licence automatically. bravos account devices lists your machines, bravos account logout signs this one out.`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// A licence that is not a device token (a trial, or an older portal) is not renewed; a stale device record would point at the wrong licence.
|
|
170
|
+
const stale = R.devicePath(io.env);
|
|
171
|
+
if (stale)
|
|
172
|
+
rmSync(stale, { force: true });
|
|
173
|
+
}
|
|
174
|
+
return lines;
|
|
139
175
|
}
|
|
140
176
|
}
|
package/dist/artifacts.js
CHANGED
|
@@ -4,6 +4,7 @@ import { chmodSync, closeSync, existsSync, lstatSync, mkdirSync, openSync, readd
|
|
|
4
4
|
import { arch, platform } from 'node:os';
|
|
5
5
|
import { dirname, join } from 'node:path';
|
|
6
6
|
import { gunzipSync } from 'node:zlib';
|
|
7
|
+
import { refresh, userAgent } from './device.js';
|
|
7
8
|
import { licenceLib } from './licence.js';
|
|
8
9
|
import { BravosError } from './types.js';
|
|
9
10
|
import { ANALYZER_VERSION, CODEGRAPH_VERSION } from './versions.js';
|
|
@@ -330,7 +331,7 @@ async function get(f, url, limit, what, headers = {}) {
|
|
|
330
331
|
throw new BravosError(`the ${what} is ${buf.length} bytes, past the ${limit}-byte ceiling (${url.split('?')[0]})`);
|
|
331
332
|
return buf;
|
|
332
333
|
}
|
|
333
|
-
// @comment -- "Where the files come from. With BRAVOS_ARTIFACT_BASE_URL, a plain layout <base>/<kind>/<version>/<file> (tests, mirrors). Otherwise the account portal: GET /api/v1/cli/artifacts/<kind>/<version>/<triple> with the licence as the bearer; the portal verifies it, counts the pull, and answers presigned URLs into the private bucket. The licence token goes to the portal origin and nowhere else; the presigned URLs carry their own authorization."
|
|
334
|
+
// @comment -- "Where the files come from. With BRAVOS_ARTIFACT_BASE_URL, a plain layout <base>/<kind>/<version>/<file> (tests, mirrors). Otherwise the account portal: GET /api/v1/cli/artifacts/<kind>/<version>/<triple> with the licence as the bearer; the portal verifies it (and, for a device or CI licence, that it has not been revoked), counts the pull, and answers presigned URLs into the private bucket. On 401 or 403 a device licence is renewed once and the request repeated once. The licence token goes to the portal origin and nowhere else; the presigned URLs carry their own authorization."
|
|
334
335
|
async function urlsFor(kind, version, target, io) {
|
|
335
336
|
const f = io.fetch ?? fetch;
|
|
336
337
|
const base = (io.env[BASE_URL_ENV] || '').trim();
|
|
@@ -339,19 +340,31 @@ async function urlsFor(kind, version, target, io) {
|
|
|
339
340
|
return { manifest: `${root}/manifest.json`, manifestSig: `${root}/manifest.json.sig`, artifact: (file) => `${root}/${file}`, artifactSig: (file) => `${root}/${file}.sig` };
|
|
340
341
|
}
|
|
341
342
|
const L = await licenceLib();
|
|
342
|
-
const found = L.find(io.env);
|
|
343
|
-
if (!found.token)
|
|
344
|
-
throw new BravosError(`no licence at ${found.source}: the ${kind} download is licensed — bravos account activate (30-day Team trial, no card)`);
|
|
345
343
|
const originRaw = (io.env.BRAVOS_ACCOUNT_ORIGIN || '').trim();
|
|
346
344
|
const origin = originRaw || L.ACCOUNT_ORIGIN;
|
|
347
345
|
const url = `${origin}/api/v1/cli/artifacts/${kind}/${version}/${target}`;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
346
|
+
const ask = async () => {
|
|
347
|
+
const found = L.find(io.env);
|
|
348
|
+
if (!found.token)
|
|
349
|
+
throw new BravosError(`no licence at ${found.source}: the ${kind} download is licensed — bravos account activate (30-day Team trial, no card)`);
|
|
350
|
+
try {
|
|
351
|
+
return { found, r: await f(url, { headers: { 'User-Agent': userAgent(), Accept: 'application/json', Authorization: `Bearer ${found.token}` } }) };
|
|
352
|
+
}
|
|
353
|
+
catch (e) {
|
|
354
|
+
throw new BravosError(`could not reach ${origin} for the ${kind} download: ${e.message}`);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
let { r, found } = await ask();
|
|
358
|
+
// A device licence the portal refuses may only be stale (rotated on another process) or revoked: renew once, and ask once more only when a new token was written.
|
|
359
|
+
if (r.status === 401 || r.status === 403) {
|
|
360
|
+
const renewed = await refresh({ env: io.env, fetch: f }, true);
|
|
361
|
+
if (renewed.outcome === 'refreshed')
|
|
362
|
+
({ r, found } = await ask());
|
|
363
|
+
else if (renewed.outcome === 'revoked' || renewed.outcome === 'lapsed')
|
|
364
|
+
throw new BravosError(`${origin} refused the ${kind} download. ${renewed.note}`);
|
|
354
365
|
}
|
|
366
|
+
if (r.status === 403)
|
|
367
|
+
throw new BravosError(`${origin} refused the ${kind} download: the licence from ${found.source} has been revoked or you no longer hold one (${L.ACCOUNT_LICENCES})`);
|
|
355
368
|
if (r.status === 402)
|
|
356
369
|
throw new BravosError(`${origin} refused the ${kind} download: the licence from ${found.source} does not cover it (${L.ACCOUNT_UPGRADE})`);
|
|
357
370
|
if (r.status === 401)
|
package/dist/ci.js
CHANGED
|
@@ -4,7 +4,17 @@ import { readLock, sha256, writeLock } from './lock.js';
|
|
|
4
4
|
import { templatesDir } from './paths.js';
|
|
5
5
|
// @comment -- "Token every bravos workflow carries in its first line, so an unlocked workflow can still be recognised as bravos-managed."
|
|
6
6
|
export const WORKFLOW_MARKER = 'bravos:generated';
|
|
7
|
+
export const CADENCES = ['weekday', 'daily', 'weekly'];
|
|
8
|
+
// 03:17 UTC, off the hour so it does not land with everyone else's cron.
|
|
9
|
+
export const CRON = { weekday: '17 3 * * 1-5', daily: '17 3 * * *', weekly: '17 3 * * 0' };
|
|
10
|
+
/** The workflow files, by the name bravos init --workflows takes. */
|
|
11
|
+
export const WORKFLOW_NAMES = ['pr-gate', 'nightly-claude', 'nightly-codex'];
|
|
12
|
+
/** The template with its schedule line set to the cadence; any other file is unchanged. */
|
|
13
|
+
export function withCadence(content, cadence) {
|
|
14
|
+
return content.replace(/^(\s*- cron: )'[^']*'/m, `$1'${CRON[cadence]}'`);
|
|
15
|
+
}
|
|
7
16
|
// @comment -- "Copies each bundled templates/workflows/*.yml into .github/workflows/; an existing workflow is replaced only if bravos wrote it (lock hash or marker) unless --force, and the lock records each file written."
|
|
17
|
+
// @comment -- "Only the workflows named in `only` (all when absent) are written; `cadence` rewrites the nightly's cron line before the file is hashed and locked, so a re-sync with the same cadence finds it unchanged"
|
|
8
18
|
export function writeWorkflows(root, opts = {}) {
|
|
9
19
|
const src = join(opts.templates ?? templatesDir(), 'workflows');
|
|
10
20
|
const report = { written: [], updated: [], unchanged: [], skipped: [] };
|
|
@@ -13,9 +23,12 @@ export function writeWorkflows(root, opts = {}) {
|
|
|
13
23
|
const lock = readLock(root);
|
|
14
24
|
const record = {};
|
|
15
25
|
for (const name of readdirSync(src).filter((n) => n.endsWith('.yml')).sort()) {
|
|
26
|
+
if (opts.only && !opts.only.some((w) => name === `bravos-${w}.yml`))
|
|
27
|
+
continue;
|
|
16
28
|
const path = `.github/workflows/${name}`;
|
|
17
29
|
const abs = join(root, path);
|
|
18
|
-
const
|
|
30
|
+
const raw = readFileSync(join(src, name), 'utf8');
|
|
31
|
+
const content = Buffer.from(opts.cadence && name.startsWith('bravos-nightly-') ? withCadence(raw, opts.cadence) : raw);
|
|
19
32
|
const hash = sha256(content);
|
|
20
33
|
let status = 'written';
|
|
21
34
|
if (existsSync(abs)) {
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { resolve, join } from 'node:path';
|
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
6
|
import { DOCTOR_HELP, INIT_HELP, PROGRAM_HELP, SYNC_HELP } from './help.js';
|
|
7
7
|
import { Command, CommanderError, InvalidArgumentError, Option } from 'commander';
|
|
8
|
-
import { writeWorkflows } from './ci.js';
|
|
8
|
+
import { CADENCES, CRON, WORKFLOW_NAMES, writeWorkflows } from './ci.js';
|
|
9
9
|
import { writeCursorPointer } from './cursor.js';
|
|
10
10
|
import { writeOmpExtension } from './omp.js';
|
|
11
11
|
import { homeOf, installGlobal } from './global.js';
|
|
@@ -21,6 +21,7 @@ import { formatDoctor, runDoctor, withLicence } from './doctor.js';
|
|
|
21
21
|
import { ensureGuardlink, registerPrePr, whichBin, writeScope } from './guardlink.js';
|
|
22
22
|
import { installHook } from './hooks.js';
|
|
23
23
|
import { activate, importLicence } from './account.js';
|
|
24
|
+
import { listDevices, logout, refresh as refreshDevice, revokeDevice } from './device.js';
|
|
24
25
|
import * as graph from './codegraph.js';
|
|
25
26
|
import { askGraph } from './watch.js';
|
|
26
27
|
import { plan as setupPlan, runSast, runSetup } from './setup.js';
|
|
@@ -32,6 +33,17 @@ import { readLock, sha256, writeLock } from './lock.js';
|
|
|
32
33
|
import { mergeCodexConfig, mergeMcpJson, selectServers } from './mcp.js';
|
|
33
34
|
import { hooksDir, skillsDir as bundledSkillsDir, version } from './paths.js';
|
|
34
35
|
import { BravosError } from './types.js';
|
|
36
|
+
// @comment -- "Parses --workflows pr-gate,nightly-claude,nightly-codex; anything else is a usage error"
|
|
37
|
+
function parseWorkflows(value) {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const raw of value.split(',').map((x) => x.trim()).filter(Boolean)) {
|
|
40
|
+
if (!WORKFLOW_NAMES.includes(raw))
|
|
41
|
+
throw new InvalidArgumentError(`unknown workflow '${raw}' (expected ${WORKFLOW_NAMES.join(', ')})`);
|
|
42
|
+
if (!out.includes(raw))
|
|
43
|
+
out.push(raw);
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
35
47
|
const GUARDLINK_HINT = 'guardlink: not found on PATH — npm install -g guardlink';
|
|
36
48
|
// Antigravity reads the shared .agents/ root; opencode and omp get their own files on top of a skills root.
|
|
37
49
|
const AGENT_MAP = { claude: 'claude', codex: 'agents', agy: 'agents', opencode: 'opencode', omp: 'omp' };
|
|
@@ -229,8 +241,10 @@ function pipeline(root, io, opts, withGuardlink, lines) {
|
|
|
229
241
|
lines.push(`MCP deferred: ${d} — ${tools.find((t) => t.name === bin[d])?.hint ?? ''}`);
|
|
230
242
|
}
|
|
231
243
|
let workflowWritten = [];
|
|
232
|
-
if (opts.ci) {
|
|
233
|
-
const wf = writeWorkflows(root, { force: opts.force, dryRun });
|
|
244
|
+
if (opts.ci || opts.workflows || opts.schedule) {
|
|
245
|
+
const wf = writeWorkflows(root, { force: opts.force, dryRun, only: opts.workflows, cadence: opts.schedule });
|
|
246
|
+
if (opts.schedule)
|
|
247
|
+
lines.push(`Nightly schedule: ${opts.schedule} (cron ${CRON[opts.schedule]}, UTC)`);
|
|
234
248
|
lines.push(`Workflows: ${wf.written.length} written, ${wf.updated.length} updated, ${wf.unchanged.length} unchanged, ${wf.skipped.length} skipped`);
|
|
235
249
|
for (const s of wf.skipped)
|
|
236
250
|
lines.push(` skipped ${s.path} — ${s.reason}`);
|
|
@@ -319,7 +333,7 @@ export function buildProgram(io, result) {
|
|
|
319
333
|
const flags = [
|
|
320
334
|
[opts.autopilot, 'pre-pr', `bravos ${cmd} --autopilot`],
|
|
321
335
|
[opts.prePrHook, 'pre-pr', `bravos ${cmd} --pre-pr-hook`],
|
|
322
|
-
[opts.ci, 'ci', `bravos ${cmd} --ci`],
|
|
336
|
+
[opts.ci || !!opts.workflows || !!opts.schedule, 'ci', `bravos ${cmd} --ci`],
|
|
323
337
|
];
|
|
324
338
|
for (const [on, feature, what] of flags)
|
|
325
339
|
if (on)
|
|
@@ -352,6 +366,8 @@ export function buildProgram(io, result) {
|
|
|
352
366
|
.option('--force', 'overwrite edited or authored skill files')
|
|
353
367
|
.option('--pre-pr-hook', 'also register the PreToolUse gate that checks gh pr create / gh pr ready')
|
|
354
368
|
.option('--ci', 'also write the PR gate and nightly GitHub Actions workflows into .github/workflows/')
|
|
369
|
+
.option('--workflows <list>', `which workflows --ci writes: ${WORKFLOW_NAMES.join(',')} (implies --ci)`, parseWorkflows)
|
|
370
|
+
.addOption(new Option('--schedule <cadence>', 'how often the nightly workflow runs (implies --ci)').choices(CADENCES))
|
|
355
371
|
.option('--scope', 'also write the loopback-only cxg scope starter to .guardlink/scope.yaml when absent')
|
|
356
372
|
.option('--link-skills', 'make .agents/skills a link to .claude/skills so each skill exists once')
|
|
357
373
|
.option('--global', 'install for your user (home folder) instead of a repository')
|
|
@@ -372,6 +388,8 @@ export function buildProgram(io, result) {
|
|
|
372
388
|
.option('--force', 'overwrite edited or authored skill files')
|
|
373
389
|
.option('--pre-pr-hook', 'also register the PreToolUse gate that checks gh pr create / gh pr ready')
|
|
374
390
|
.option('--ci', 'also write the PR gate and nightly GitHub Actions workflows into .github/workflows/')
|
|
391
|
+
.option('--workflows <list>', `which workflows --ci writes: ${WORKFLOW_NAMES.join(',')} (implies --ci)`, parseWorkflows)
|
|
392
|
+
.addOption(new Option('--schedule <cadence>', 'how often the nightly workflow runs (implies --ci)').choices(CADENCES))
|
|
375
393
|
.option('--scope', 'also write the loopback-only cxg scope starter to .guardlink/scope.yaml when absent')
|
|
376
394
|
.option('--link-skills', 'make .agents/skills a link to .claude/skills so each skill exists once')
|
|
377
395
|
.option('--global', 'install for your user (home folder) instead of a repository')
|
|
@@ -398,22 +416,45 @@ export function buildProgram(io, result) {
|
|
|
398
416
|
lines.push(...licenceLines(L, v));
|
|
399
417
|
}));
|
|
400
418
|
program
|
|
401
|
-
.command('account <action> [
|
|
402
|
-
.description('activate: sign in once in the browser and get this machine its licence (a 30-day Team trial when the account has no plan); import FILE: install a downloaded licence; status: same as bravos licence.')
|
|
403
|
-
.action((action,
|
|
419
|
+
.command('account <action> [arg]')
|
|
420
|
+
.description('activate: sign in once in the browser and get this machine its licence (a 30-day Team trial when the account has no plan); import FILE: install a downloaded licence; status: same as bravos licence; refresh: renew this machine\'s licence now; devices: list your signed-in machines; revoke ID: sign one of them out; logout: sign this machine out and remove its licence.')
|
|
421
|
+
.action((action, arg) => guardedAsync(async (lines) => {
|
|
422
|
+
const accountIo = { env: io.env, stdout: io.stdout };
|
|
404
423
|
if (action === 'activate')
|
|
405
|
-
lines.push(...(await activate(
|
|
424
|
+
lines.push(...(await activate(accountIo)));
|
|
406
425
|
else if (action === 'import') {
|
|
407
|
-
if (!
|
|
426
|
+
if (!arg)
|
|
408
427
|
throw new BravosError('usage: bravos account import <licence file>');
|
|
409
|
-
lines.push(...(await importLicence(resolve(
|
|
428
|
+
lines.push(...(await importLicence(resolve(arg), accountIo)));
|
|
410
429
|
}
|
|
411
430
|
else if (action === 'status') {
|
|
412
431
|
const L = await licenceLib();
|
|
413
432
|
lines.push(...licenceLines(L, L.status(io.env)));
|
|
414
433
|
}
|
|
434
|
+
else if (action === 'refresh') {
|
|
435
|
+
const L = await licenceLib();
|
|
436
|
+
const r = await refreshDevice({ env: io.env }, true);
|
|
437
|
+
if (r.outcome === 'refreshed')
|
|
438
|
+
lines.push('Licence renewed.');
|
|
439
|
+
else if (r.outcome === 'revoked' || r.outcome === 'lapsed')
|
|
440
|
+
lines.push(r.note);
|
|
441
|
+
else if (r.outcome === 'skipped')
|
|
442
|
+
lines.push(r.reason === 'environment' ? 'The licence comes from BRAVOS_LICENCE, which is never renewed here.' : 'This machine has no device licence to renew (bravos account activate signs it in).');
|
|
443
|
+
else
|
|
444
|
+
lines.push('Could not renew the licence just now; the current one keeps working until it expires.');
|
|
445
|
+
lines.push(...licenceLines(L, L.status(io.env)));
|
|
446
|
+
}
|
|
447
|
+
else if (action === 'devices')
|
|
448
|
+
lines.push(...(await listDevices({ env: io.env })));
|
|
449
|
+
else if (action === 'revoke') {
|
|
450
|
+
if (!arg)
|
|
451
|
+
throw new BravosError('usage: bravos account revoke <device id> (bravos account devices lists them)');
|
|
452
|
+
lines.push(...(await revokeDevice({ env: io.env }, arg)));
|
|
453
|
+
}
|
|
454
|
+
else if (action === 'logout')
|
|
455
|
+
lines.push(...(await logout({ env: io.env })));
|
|
415
456
|
else
|
|
416
|
-
throw new BravosError(`unknown account action ${JSON.stringify(action)}: activate, import <file> or
|
|
457
|
+
throw new BravosError(`unknown account action ${JSON.stringify(action)}: activate, import <file>, status, refresh, devices, revoke <id> or logout`);
|
|
417
458
|
}));
|
|
418
459
|
program
|
|
419
460
|
.command('setup')
|
|
@@ -502,6 +543,67 @@ export function buildProgram(io, result) {
|
|
|
502
543
|
io.stderr(r.stderr.replace(/\n$/, ''));
|
|
503
544
|
result.code = r.status ?? 1;
|
|
504
545
|
}));
|
|
546
|
+
// @comment -- "bravos start: the guided first run (src/start). Interactive in a terminal; --yes takes every default and never invents what a person must answer. It installs through these same commands, run in-process."
|
|
547
|
+
program
|
|
548
|
+
.command('start [dir]')
|
|
549
|
+
.description('Guided first-run setup: licence, tools, repository, agents, PR checks, schedule and testing permission, one question at a time. Nothing changes until you confirm.')
|
|
550
|
+
.option('--again', 'ask again, with your previous answers selected')
|
|
551
|
+
.option('-y, --yes', 'no questions: take every default (testing permission stays unrecorded)')
|
|
552
|
+
.addOption(new Option('--preset <name>', 'starting point').choices(['annotate', 'pr', 'everything']))
|
|
553
|
+
.action((dir, opts) => guardedAsync(async () => {
|
|
554
|
+
const { runStart } = await import('./start/index.js');
|
|
555
|
+
const ui = await import('./start/ui.js');
|
|
556
|
+
const { plan: startPlan } = await import('./setup.js');
|
|
557
|
+
const { licenceStatus } = await import('./licence.js');
|
|
558
|
+
const { bravosHome } = await import('./palette.js');
|
|
559
|
+
const interactive = !opts.yes && !!process.stdout.isTTY && !!process.stdin.isTTY;
|
|
560
|
+
if (!opts.yes && !interactive)
|
|
561
|
+
throw new BravosError('bravos start asks questions, so it needs a terminal. In a script use: bravos start --yes --preset pr <dir>');
|
|
562
|
+
const prompter = interactive ? ui.terminalPrompter() : ui.scriptedPrompter({}, io.stdout);
|
|
563
|
+
const capture = async (argv) => {
|
|
564
|
+
const out = [];
|
|
565
|
+
const err = [];
|
|
566
|
+
const code = await run(argv, { ...io, stdout: (x) => out.push(x), stderr: (x) => err.push(x) });
|
|
567
|
+
return { code, out, err };
|
|
568
|
+
};
|
|
569
|
+
result.code = await runStart({ dir, again: opts.again, yes: opts.yes, preset: opts.preset }, {
|
|
570
|
+
prompter,
|
|
571
|
+
env: io.env,
|
|
572
|
+
cwd: process.cwd(),
|
|
573
|
+
version: version(),
|
|
574
|
+
home: bravosHome(io.env),
|
|
575
|
+
bravos: capture,
|
|
576
|
+
exec: (cmd, args, o = {}) => {
|
|
577
|
+
const r = spawnSync(cmd, args, { cwd: o.cwd, env: io.env, input: o.input, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 60000 });
|
|
578
|
+
return { code: r.status ?? 1, out: String(r.stdout ?? '') };
|
|
579
|
+
},
|
|
580
|
+
// @comment -- "A bravos command run as a child of this same node and cli.js, no shell, output captured: the code graph build runs this way so the spinner keeps moving while it works"
|
|
581
|
+
bravosChild: (argv) => new Promise((done) => {
|
|
582
|
+
const child = spawnChild(process.execPath, [fileURLToPath(import.meta.url), ...argv], { env: io.env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
583
|
+
let out = '';
|
|
584
|
+
let err = '';
|
|
585
|
+
child.stdout.on('data', (b) => (out += b));
|
|
586
|
+
child.stderr.on('data', (b) => (err += b));
|
|
587
|
+
child.on('error', (e) => done({ code: 1, out, err: err || e.message }));
|
|
588
|
+
child.on('close', (code) => done({ code: code ?? 1, out, err }));
|
|
589
|
+
}),
|
|
590
|
+
which: (bin) => whichBin(bin, io.env),
|
|
591
|
+
licence: () => licenceStatus(io.env),
|
|
592
|
+
setupPlan: () => startPlan(io.env),
|
|
593
|
+
activate: () => activate({ env: io.env, stdout: io.stdout }),
|
|
594
|
+
clipboard: (text) => {
|
|
595
|
+
const tools = process.platform === 'darwin' ? [['pbcopy', []]] : [['wl-copy', []], ['xclip', ['-selection', 'clipboard']], ['xsel', ['--clipboard', '--input']]];
|
|
596
|
+
for (const [bin, args] of tools) {
|
|
597
|
+
if (!whichBin(bin, io.env))
|
|
598
|
+
continue;
|
|
599
|
+
if (spawnSync(bin, args, { input: text, stdio: ['pipe', 'ignore', 'ignore'] }).status === 0)
|
|
600
|
+
return true;
|
|
601
|
+
}
|
|
602
|
+
return false;
|
|
603
|
+
},
|
|
604
|
+
today: () => new Date().toISOString().slice(0, 10),
|
|
605
|
+
});
|
|
606
|
+
}));
|
|
505
607
|
program
|
|
506
608
|
.command('doctor [dir]')
|
|
507
609
|
.description('Read-only check of the tools, licence, skills and hooks bravos relies on.')
|
|
@@ -617,8 +719,13 @@ export function buildProgram(io, result) {
|
|
|
617
719
|
const watch = await import('./watch.js');
|
|
618
720
|
const color = !io.env.NO_COLOR && io.env.BRAVOS_WATCH_COLOR !== 'off';
|
|
619
721
|
const live = !opts.once && !opts.json && process.stdout.isTTY && process.stdin.isTTY;
|
|
722
|
+
const { resolveTheme } = await import('./palette.js');
|
|
620
723
|
if (live) {
|
|
621
|
-
|
|
724
|
+
// Ask the terminal for its background only when nothing stronger has decided the theme.
|
|
725
|
+
const first = resolveTheme(io.env);
|
|
726
|
+
const detected = color && first.source.startsWith('default') ? await watch.queryBackground() : null;
|
|
727
|
+
const { theme } = resolveTheme(io.env, detected);
|
|
728
|
+
await watch.runWatch(root, io.env, { intervalSec: opts.interval, graphIntervalSec: opts.graphInterval, color, compact: !!opts.compact, theme });
|
|
622
729
|
return;
|
|
623
730
|
}
|
|
624
731
|
const sn = await watch.snapshot(root, io.env, { refreshGraph: true, refreshSlow: true });
|
|
@@ -628,7 +735,7 @@ export function buildProgram(io, result) {
|
|
|
628
735
|
}
|
|
629
736
|
const width = Number(io.env.COLUMNS) || process.stdout.columns || 100;
|
|
630
737
|
const events = watch.readAutopilotEvents(root).slice(-8);
|
|
631
|
-
lines.push(watch.buildFrame(sn, events, { width, color: color && !!process.stdout.isTTY, status: 'once', compact: !!opts.compact }));
|
|
738
|
+
lines.push(watch.buildFrame(sn, events, { width, color: color && !!process.stdout.isTTY, theme: resolveTheme(io.env).theme, status: 'once', compact: !!opts.compact }));
|
|
632
739
|
}));
|
|
633
740
|
program
|
|
634
741
|
.command('workspace <action> [args...]')
|
|
@@ -953,6 +1060,9 @@ export async function run(argv, io = {}) {
|
|
|
953
1060
|
...io,
|
|
954
1061
|
};
|
|
955
1062
|
const result = { code: 0 };
|
|
1063
|
+
// @comment -- "Bare bravos in a repository bravos has not set up yet points at the guided setup first"
|
|
1064
|
+
if (argv.length === 0 && !existsSync(join(process.cwd(), '.bravos')))
|
|
1065
|
+
full.stdout('New here? Run bravos start: a guided setup, one question at a time.\n');
|
|
956
1066
|
try {
|
|
957
1067
|
await buildProgram(full, result).parseAsync(argv, { from: 'user' });
|
|
958
1068
|
}
|
package/dist/device.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// @comment -- "The CLI's side of per-machine licences: a typed wrapper over hooks/lib/refresh.mjs (the one refresh implementation, shared with the session hook), and the three account commands that act on this machine's device record — refresh (force a new token), devices (the person's machines, as the portal lists them) and logout / revoke (end one machine's licence at the portal). Every request goes to the origin stored in device.json at activation, with the device secret as the bearer, and nowhere else."
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { hooksDir, version } from './paths.js';
|
|
5
|
+
import { BravosError } from './types.js';
|
|
6
|
+
let cached = null;
|
|
7
|
+
export const refreshLib = () => (cached ??= import(pathToFileURL(join(hooksDir(), 'lib', 'refresh.mjs')).href));
|
|
8
|
+
export const userAgent = () => `bravos-cli/${version()}`;
|
|
9
|
+
// @comment -- "Refreshes this machine's device licence when it is due (or always, with force). Never throws; the outcome says what happened, and a revocation or a lapsed plan carries the sentence to show."
|
|
10
|
+
export async function refresh(io, force = false) {
|
|
11
|
+
const R = await refreshLib();
|
|
12
|
+
return R.refreshIfDue(io.env, { fetch: io.fetch, now: io.now, force, userAgent: userAgent() });
|
|
13
|
+
}
|
|
14
|
+
const requireDevice = async (env) => {
|
|
15
|
+
const R = await refreshLib();
|
|
16
|
+
const device = R.readDevice(env);
|
|
17
|
+
if (!device)
|
|
18
|
+
throw new BravosError('this machine has no device licence (bravos account activate signs it in); a licence imported from a file or set in BRAVOS_LICENCE has no device record');
|
|
19
|
+
return { R, device };
|
|
20
|
+
};
|
|
21
|
+
const call = async (io, device, path, init) => {
|
|
22
|
+
const f = io.fetch ?? fetch;
|
|
23
|
+
let r;
|
|
24
|
+
try {
|
|
25
|
+
r = await f(`${device.origin}${path}`, {
|
|
26
|
+
...init,
|
|
27
|
+
headers: { 'User-Agent': userAgent(), Accept: 'application/json', Authorization: `Bearer ${device.device_secret}`, ...(init.body ? { 'Content-Type': 'application/json' } : {}) },
|
|
28
|
+
signal: AbortSignal.timeout(10_000),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw new BravosError(`could not reach ${device.origin}: ${e.message}`);
|
|
33
|
+
}
|
|
34
|
+
let body = null;
|
|
35
|
+
try {
|
|
36
|
+
body = (await r.json());
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
body = null;
|
|
40
|
+
}
|
|
41
|
+
return { status: r.status, body };
|
|
42
|
+
};
|
|
43
|
+
const refusedLine = (R, status, body) => {
|
|
44
|
+
const error = typeof body?.error === 'string' ? body.error : null;
|
|
45
|
+
if (status === 401)
|
|
46
|
+
return R.revokedNote('invalid_device');
|
|
47
|
+
if (status === 403 && error)
|
|
48
|
+
return R.revokedNote(error);
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
const day = (iso) => (typeof iso === 'string' && !Number.isNaN(Date.parse(iso)) ? new Date(iso).toISOString().slice(0, 10) : '—');
|
|
52
|
+
// @comment -- "bravos account devices: GET /api/v1/cli/devices with this machine's device secret, printed as a table (name, added, last seen, which one is this machine) with the per-person limit. A refusal that means this machine is no longer licensed is reported, and the local files removed, exactly as a refresh would."
|
|
53
|
+
export async function listDevices(io) {
|
|
54
|
+
const { R, device } = await requireDevice(io.env);
|
|
55
|
+
const { status, body } = await call(io, device, R.DEVICES_PATH, { method: 'GET' });
|
|
56
|
+
const refused = refusedLine(R, status, body);
|
|
57
|
+
if (refused) {
|
|
58
|
+
R.forgetDevice(io.env);
|
|
59
|
+
throw new BravosError(refused);
|
|
60
|
+
}
|
|
61
|
+
if (status !== 200 || !Array.isArray(body?.devices))
|
|
62
|
+
throw new BravosError(`${device.origin} answered HTTP ${status} for the device list`);
|
|
63
|
+
const rows = body.devices.map((d) => ({
|
|
64
|
+
name: typeof d.name === 'string' && d.name ? d.name.slice(0, 64) : '(unnamed)',
|
|
65
|
+
added: day(d.created_at),
|
|
66
|
+
seen: day(d.last_seen_at),
|
|
67
|
+
id: typeof d.id === 'string' ? d.id : '',
|
|
68
|
+
current: d.current === true || (typeof d.id === 'string' && d.id === device.device_id),
|
|
69
|
+
}));
|
|
70
|
+
const limit = typeof body.limit === 'number' ? body.limit : null;
|
|
71
|
+
const lines = [`Your machines (${rows.length}${limit !== null ? ` of ${limit}` : ''}):`];
|
|
72
|
+
const width = Math.max(4, ...rows.map((r) => r.name.length));
|
|
73
|
+
lines.push(` ${'NAME'.padEnd(width)} ADDED LAST SEEN ID`);
|
|
74
|
+
for (const r of rows)
|
|
75
|
+
lines.push(` ${r.name.padEnd(width)} ${r.added.padEnd(10)} ${r.seen.padEnd(10)} ${r.id}${r.current ? ' (this machine)' : ''}`);
|
|
76
|
+
if (rows.length === 0)
|
|
77
|
+
lines.push(' none');
|
|
78
|
+
lines.push('Remove one with bravos account revoke <id>, or this machine with bravos account logout.');
|
|
79
|
+
return lines;
|
|
80
|
+
}
|
|
81
|
+
// @comment -- "bravos account revoke <id>: ends one of the person's other machines at the portal (POST /api/v1/cli/devices/revoke with {device_id}). The id is checked to be a uuid before it is sent; the portal decides whether it is the caller's own."
|
|
82
|
+
export async function revokeDevice(io, deviceId) {
|
|
83
|
+
const { R, device } = await requireDevice(io.env);
|
|
84
|
+
if (!R.isDeviceId(deviceId))
|
|
85
|
+
throw new BravosError(`${JSON.stringify(deviceId)} is not a device id; bravos account devices lists them`);
|
|
86
|
+
if (deviceId === device.device_id)
|
|
87
|
+
return logout(io);
|
|
88
|
+
const { status, body } = await call(io, device, R.REVOKE_PATH, { method: 'POST', body: JSON.stringify({ device_id: deviceId }) });
|
|
89
|
+
if (status === 404)
|
|
90
|
+
throw new BravosError(`${deviceId} is not one of your machines; bravos account devices lists them`);
|
|
91
|
+
const refused = refusedLine(R, status, body);
|
|
92
|
+
if (refused) {
|
|
93
|
+
R.forgetDevice(io.env);
|
|
94
|
+
throw new BravosError(refused);
|
|
95
|
+
}
|
|
96
|
+
if (status !== 200)
|
|
97
|
+
throw new BravosError(`${device.origin} answered HTTP ${status}; nothing was revoked`);
|
|
98
|
+
return [`Revoked ${deviceId}: that machine's licence stops working at its next check with the portal.`];
|
|
99
|
+
}
|
|
100
|
+
// @comment -- "bravos account logout: revokes this machine at the portal (POST /api/v1/cli/devices/revoke, no body = this device), then removes licence.jwt and device.json — always, even when the portal cannot be reached, and the output says which of the two happened. A machine without a device record only has its local licence file removed."
|
|
101
|
+
export async function logout(io) {
|
|
102
|
+
const R = await refreshLib();
|
|
103
|
+
const device = R.readDevice(io.env);
|
|
104
|
+
const lines = [];
|
|
105
|
+
if (device) {
|
|
106
|
+
try {
|
|
107
|
+
const { status } = await call(io, device, R.REVOKE_PATH, { method: 'POST' });
|
|
108
|
+
if (status === 200 || status === 401 || status === 403 || status === 404)
|
|
109
|
+
lines.push(`Signed this machine out of ${device.origin}; its licence no longer works there.`);
|
|
110
|
+
else
|
|
111
|
+
lines.push(`${device.origin} answered HTTP ${status}, so the portal may still list this machine — remove it at ${device.origin}/dashboard/license.`);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
lines.push(`Could not reach ${device.origin}, so the portal still lists this machine — remove it at ${device.origin}/dashboard/license. The local licence is removed anyway.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else
|
|
118
|
+
lines.push('This machine has no device record; only the local licence file is removed.');
|
|
119
|
+
const removed = R.forgetDevice(io.env);
|
|
120
|
+
lines.push(removed.length ? `Removed ${removed.join(' and ')}. This machine is on Free.` : 'No local licence to remove. This machine is on Free.');
|
|
121
|
+
if (io.env.BRAVOS_LICENCE || io.env.BRAVOS_LICENSE)
|
|
122
|
+
lines.push('BRAVOS_LICENCE is still set in this environment and still applies; unset it to stop using it.');
|
|
123
|
+
return lines;
|
|
124
|
+
}
|
package/dist/doctor.js
CHANGED
|
@@ -6,6 +6,7 @@ import { graphBin } from './codegraph.js';
|
|
|
6
6
|
import { findAnalyzer, findLicence } from './graphbin.js';
|
|
7
7
|
import { AUTOPILOT_COMMAND, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, PRE_PR_COMMAND } from './hooks.js';
|
|
8
8
|
import { skillsRoot } from './skills.js';
|
|
9
|
+
import { resolveTheme } from './palette.js';
|
|
9
10
|
const TOOLS = [
|
|
10
11
|
{ name: 'guardlink', hint: 'npm install -g guardlink' },
|
|
11
12
|
{ name: 'cxg', hint: 'cargo install cert-x-gen (or: brew tap bugb-technologies/cxg && brew install cxg)' },
|
|
@@ -76,6 +77,7 @@ export function runDoctor(root, env = process.env) {
|
|
|
76
77
|
claude: hookRegistered(join(root, '.claude', 'settings.json'), 'PreToolUse', [PRE_PR_COMMAND]),
|
|
77
78
|
codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'PreToolUse', [PRE_PR_COMMAND]),
|
|
78
79
|
},
|
|
80
|
+
theme: resolveTheme(env),
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
// @comment -- "Renders a DoctorReport as one line per check, with an install hint for each missing tool and guardlink's playbook skills named per root."
|
|
@@ -95,5 +97,6 @@ export function formatDoctor(r) {
|
|
|
95
97
|
`hooks claude: ${yn(r.hooks.claude)} codex: ${yn(r.hooks.codex)}`,
|
|
96
98
|
`pre-pr claude: ${yn(r.pre_pr.claude)} codex: ${yn(r.pre_pr.codex)}${r.pre_pr.claude || r.pre_pr.codex ? '' : ' (opt-in: bravos init --pre-pr-hook)'}`,
|
|
97
99
|
`autopilot claude: ${yn(r.autopilot.claude)} codex: ${yn(r.autopilot.codex)}${r.autopilot.claude || r.autopilot.codex ? '' : ' (opt-in: bravos init --autopilot)'}`,
|
|
100
|
+
...(r.theme ? [`colours ${r.theme.theme} (${r.theme.source})${r.theme.source.startsWith('default') ? ' — pick yours: BRAVOS_THEME=light or dark, or bravos start' : ''}`] : []),
|
|
98
101
|
].join('\n');
|
|
99
102
|
}
|