@firstdraft.com/cli 0.8.0 → 0.8.1
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 +22 -25
- package/docs/README.md +15 -13
- package/docs/commands.md +202 -42
- package/docs/errors.md +42 -6
- package/package.json +6 -4
- package/src/api-authentication.js +55 -13
- package/src/api-response.js +73 -3
- package/src/cli.js +395 -6
- package/src/commands/compilation.js +21 -9
- package/src/commands/login.js +314 -0
- package/src/commands/logout.js +107 -0
- package/src/commands/plan-publish.js +16 -13
- package/src/commands/plan-push.js +5 -5
- package/src/commands/plan-status.js +5 -5
- package/src/credentials.js +343 -0
- package/src/oauth.js +565 -0
- package/RELEASING.md +0 -118
- package/docs/release-history.md +0 -77
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@ firstdraft is the command-line client shared by First Draft agents and automatio
|
|
|
4
4
|
files, calls the versioned Service API, exposes reviewed analysis and GapSets, materializes verified Compilations,
|
|
5
5
|
and coordinates private GitHub publication.
|
|
6
6
|
|
|
7
|
-
Start with the [local development guide](https://
|
|
7
|
+
Start with the [local development guide](https://firstdraft.github.io/firstdraft/docs/guides/local-app.html):
|
|
8
8
|
install the CLI and Skill, then compile into your current folder with `firstdraft plan compile --output .`. No Drawing Board
|
|
9
9
|
clone or GitHub push is required. The [Drawing Board guide](https://github.com/firstdraft/drawing-board#build-an-app-with-first-draft)
|
|
10
10
|
is the Codespaces fallback.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
`--output .` is also the default, so `firstdraft plan compile` alone writes to the current folder. GitHub publication
|
|
13
|
+
requires `--github`.
|
|
14
14
|
|
|
15
15
|
## What this repository owns
|
|
16
16
|
|
|
@@ -33,21 +33,22 @@ repository owns the exact command and transport behavior between them.
|
|
|
33
33
|
| Change the CLI | [Agent instructions](https://github.com/firstdraft/cli/blob/main/AGENTS.md), then [documentation map](docs/README.md) |
|
|
34
34
|
| Find a command or output contract | [Command reference](docs/commands.md) |
|
|
35
35
|
| Interpret an error or recover safely | [Errors and recovery](docs/errors.md) |
|
|
36
|
-
|
|
|
37
|
-
|
|
|
36
|
+
| Commit, review, or land a change | [Contributing guide](https://github.com/firstdraft/cli/blob/main/CONTRIBUTING.md) |
|
|
37
|
+
| Prepare or publish a package | [Release runbook](https://github.com/firstdraft/cli/blob/main/RELEASING.md) |
|
|
38
|
+
| See what changed in a version | [Changelog](https://github.com/firstdraft/cli/blob/main/CHANGELOG.md) |
|
|
38
39
|
| Report a vulnerability | [Security policy](SECURITY.md) |
|
|
39
40
|
|
|
40
41
|
Run firstdraft --help or a command group's --help for concise terminal syntax.
|
|
41
42
|
|
|
42
43
|
## Repository layout
|
|
43
44
|
|
|
44
|
-
| Path | Responsibility
|
|
45
|
-
| -------- |
|
|
46
|
-
| bin/ | Published executable entrypoint
|
|
47
|
-
| src/ | Commands, API client, local Plan state, and output contracts
|
|
48
|
-
| test/ | Command, protocol, recovery, and package tests
|
|
49
|
-
| scripts/ | Test runner and
|
|
50
|
-
| docs/ |
|
|
45
|
+
| Path | Responsibility |
|
|
46
|
+
| -------- | --------------------------------------------------------------------------- |
|
|
47
|
+
| bin/ | Published executable entrypoint |
|
|
48
|
+
| src/ | Commands, API client, local Plan state, and output contracts |
|
|
49
|
+
| test/ | Command, protocol, recovery, and package tests |
|
|
50
|
+
| scripts/ | Test runner, package checks, and version sync |
|
|
51
|
+
| docs/ | Documentation map, command and error references, and frozen release history |
|
|
51
52
|
|
|
52
53
|
## Development
|
|
53
54
|
|
|
@@ -75,8 +76,8 @@ To exercise the checkout directly:
|
|
|
75
76
|
node bin/firstdraft.js --help
|
|
76
77
|
```
|
|
77
78
|
|
|
78
|
-
Remote commands default to production
|
|
79
|
-
|
|
79
|
+
Remote commands default to production. Run `firstdraft login` (or `firstdraft --staging login`) once, or set
|
|
80
|
+
`FIRSTDRAFT_API_TOKEN` / `FIRSTDRAFT_STAGING_API_TOKEN`. Existing Projects retain their saved origin. See
|
|
80
81
|
[environment selection](docs/commands.md#select-an-environment-and-authenticate) for custom URLs and credential
|
|
81
82
|
isolation. Keep tokens out of arguments, shell history, fixtures, snapshots, and logs.
|
|
82
83
|
|
|
@@ -88,8 +89,8 @@ The published CLI supports Node.js 22 or newer. Direct automation callers can in
|
|
|
88
89
|
npm install --global @firstdraft.com/cli
|
|
89
90
|
```
|
|
90
91
|
|
|
91
|
-
Pin an exact compatible version when a repeatable installation matters
|
|
92
|
-
|
|
92
|
+
Pin an exact compatible version when a repeatable installation matters. The
|
|
93
|
+
[changelog](https://github.com/firstdraft/cli/blob/main/CHANGELOG.md) describes each version.
|
|
93
94
|
|
|
94
95
|
The published package:
|
|
95
96
|
|
|
@@ -97,14 +98,10 @@ The published package:
|
|
|
97
98
|
- runs reviewed JavaScript source directly;
|
|
98
99
|
- has no runtime dependencies or install scripts;
|
|
99
100
|
- performs no telemetry, update check, or network request unless the caller invokes an API command;
|
|
100
|
-
- reads Bearer credentials
|
|
101
|
+
- reads Bearer credentials from the environment or its private `firstdraft login` credentials file; and
|
|
101
102
|
- carries npm provenance linking registry bytes to its GitHub workflow and commit.
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
`release/compatibility.json
|
|
106
|
-
|
|
107
|
-
## Release boundary
|
|
108
|
-
|
|
109
|
-
Merging source is not package publication. An approved coordinated release publishes directly to `latest`, reusing
|
|
110
|
-
successful CI for the exact source. [RELEASING.md](RELEASING.md) owns the short release and recovery procedure.
|
|
104
|
+
The package includes this README, the documentation map, the command and error references, and the security
|
|
105
|
+
policy. Repository files for maintainers stay out of it: `AGENTS.md`, the release runbook, the changelog, the
|
|
106
|
+
release history, and the source-only `release/compatibility.json`. Inspect the packed file list whenever a source or
|
|
107
|
+
documentation path moves.
|
package/docs/README.md
CHANGED
|
@@ -5,35 +5,37 @@ evidence for implemented behavior; if they contradict a document, surface the co
|
|
|
5
5
|
|
|
6
6
|
| Task | Read first |
|
|
7
7
|
| -------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
8
|
-
| Local app development | [Local guide](https://
|
|
8
|
+
| Local app development | [Local guide](https://firstdraft.github.io/firstdraft/docs/guides/local-app.html) |
|
|
9
9
|
| Codespaces fallback | [Drawing Board guide](https://github.com/firstdraft/drawing-board#build-an-app-with-first-draft) |
|
|
10
10
|
| Installation or package contract | [Root README](../README.md) |
|
|
11
|
-
| Commands, API, or output
|
|
11
|
+
| Commands, Service API, or output | [Command reference](commands.md); [add a command](commands.md#add-a-command) |
|
|
12
12
|
| Errors and recovery | [Errors and recovery](errors.md) |
|
|
13
|
-
| Versioning and publication | [Release
|
|
14
|
-
|
|
|
13
|
+
| Versioning and publication | [Release runbook](https://github.com/firstdraft/cli/blob/main/RELEASING.md) |
|
|
14
|
+
| Changes by version | [Changelog](https://github.com/firstdraft/cli/blob/main/CHANGELOG.md) |
|
|
15
15
|
| Vulnerability reporting | [Security policy](../SECURITY.md) |
|
|
16
16
|
|
|
17
17
|
## Authority boundaries
|
|
18
18
|
|
|
19
19
|
- [README.md](../README.md) owns repository orientation, direct installation, package boundaries, and routes.
|
|
20
|
-
- [commands.md](commands.md) owns detailed command semantics
|
|
21
|
-
executable syntax and behavior.
|
|
20
|
+
- [commands.md](commands.md) owns detailed command semantics, Service endpoints, and the add-a-command checklist.
|
|
21
|
+
Built-in `--help`, runtime source, and tests own exact executable syntax and behavior.
|
|
22
22
|
- [errors.md](errors.md) owns handled-error interpretation and recovery guidance.
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
and dist-tags before relying on them operationally; publisher configuration is checked when it changes or fails.
|
|
23
|
+
- `RELEASING.md` owns publication mechanics. The service repository owns release policy.
|
|
24
|
+
- `CHANGELOG.md` gets each new version's entry in the pull request that sets the version.
|
|
26
25
|
- The source repository's `AGENTS.md` routes agent work; it should stay compact rather than duplicate these documents.
|
|
26
|
+
Its `CLAUDE.md` only imports `AGENTS.md`, so Claude Code and Codex read the same instructions.
|
|
27
27
|
|
|
28
28
|
## Retrieval quality
|
|
29
29
|
|
|
30
30
|
Start here, then load the one owning document for the task. Follow a cross-link only when the task crosses an
|
|
31
31
|
authority boundary. Create another page only for a distinct audience, task, or authority.
|
|
32
32
|
|
|
33
|
-
The documentation tests
|
|
34
|
-
|
|
35
|
-
repository
|
|
36
|
-
|
|
33
|
+
The documentation tests cap `AGENTS.md` at 2 KiB, the root README at 6 KiB, and this map at 4 KiB. They also
|
|
34
|
+
require every public topic to be reachable from this map or the root README. They check relative links, links to
|
|
35
|
+
this repository's `main` on GitHub, and their fragments. Outside the changelog and release history, they reject
|
|
36
|
+
retired version identities and release-status labels on the current version. They also reject status labels in
|
|
37
|
+
changelog headings. The package check verifies that relative links in packaged Markdown resolve inside the package;
|
|
38
|
+
packaged pages link other files on GitHub.
|
|
37
39
|
|
|
38
40
|
## Work on the repository
|
|
39
41
|
|
package/docs/commands.md
CHANGED
|
@@ -3,64 +3,127 @@
|
|
|
3
3
|
This page owns the detailed public semantics of the current command surface. Run `firstdraft --help` or a command
|
|
4
4
|
group's `--help` for concise executable syntax. See [Errors and recovery](errors.md) before retrying a failed mutation.
|
|
5
5
|
|
|
6
|
-
The current `0.8.x` source line contains the auditable command shell, local Foundation Plan initialization, local
|
|
6
|
+
The current `0.8.x` source line contains the auditable command shell, browser and device login, local Foundation Plan initialization, local
|
|
7
7
|
application-key and UUID generation, conditional whole-document push, whole-graph analysis status polling, direct
|
|
8
8
|
Compile-and-materialize and private publish orchestration, and retained-Compilation inspection. CLI `0.8.x`
|
|
9
|
-
requires the service's `0.7.x` API contract.
|
|
10
|
-
|
|
9
|
+
requires the service's `0.7.x` API contract. The
|
|
10
|
+
[changelog](https://github.com/firstdraft/cli/blob/main/CHANGELOG.md) describes each version.
|
|
11
11
|
|
|
12
12
|
## Command map
|
|
13
13
|
|
|
14
|
-
| Command | Network | Purpose
|
|
15
|
-
| ------------------------------------- | ------- |
|
|
16
|
-
| `firstdraft plan init` | No | Create an empty local Foundation Plan and Project identity
|
|
17
|
-
| `firstdraft generate application-key` | No | Preview deterministic name-to-key derivation
|
|
18
|
-
| `firstdraft generate uuid` | No | Generate one or more Foundation Plan subject identities
|
|
19
|
-
| `firstdraft
|
|
20
|
-
| `firstdraft
|
|
21
|
-
| `firstdraft plan
|
|
22
|
-
| `firstdraft plan
|
|
23
|
-
| `firstdraft
|
|
24
|
-
| `firstdraft
|
|
14
|
+
| Command | Network | Purpose |
|
|
15
|
+
| ------------------------------------- | ------- | ----------------------------------------------------------- |
|
|
16
|
+
| `firstdraft plan init` | No | Create an empty local Foundation Plan and Project identity |
|
|
17
|
+
| `firstdraft generate application-key` | No | Preview deterministic name-to-key derivation |
|
|
18
|
+
| `firstdraft generate uuid` | No | Generate one or more Foundation Plan subject identities |
|
|
19
|
+
| `firstdraft login` | Yes | Approve the CLI in a browser and save a token for an origin |
|
|
20
|
+
| `firstdraft logout` | Yes | Revoke and remove the saved token for an origin |
|
|
21
|
+
| `firstdraft plan push` | Yes | Conditionally submit the exact whole Plan |
|
|
22
|
+
| `firstdraft plan status` | Yes | Read or wait for the current whole-graph analysis |
|
|
23
|
+
| `firstdraft plan compile` | Yes | Push and analyze, then materialize in the current folder |
|
|
24
|
+
| `firstdraft plan compile --github` | Yes | Push and analyze, then publish to private GitHub |
|
|
25
|
+
| `firstdraft compilation status` | Yes | Inspect a retained Compilation by ID |
|
|
26
|
+
| `firstdraft compilation download` | Yes | Verify and materialize a successful retained Compilation |
|
|
25
27
|
|
|
26
28
|
## Select an environment and authenticate
|
|
27
29
|
|
|
28
|
-
Production at `https://firstdraft.com` is the default.
|
|
29
|
-
[First Draft](https://firstdraft.com/api-tokens) and provide it through `FIRSTDRAFT_API_TOKEN` when running a network
|
|
30
|
-
command. Keep token values out of shell history and command arguments.
|
|
30
|
+
Production at `https://firstdraft.com` is the default. Log in once per environment:
|
|
31
31
|
|
|
32
32
|
```sh
|
|
33
|
-
firstdraft
|
|
33
|
+
firstdraft login
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
The command prints an authorization URL on standard error. Open it in a browser on the same machine, sign in, and
|
|
37
|
+
approve **First Draft CLI**. The CLI then saves a token and prints `Logged in to <origin>` on standard output.
|
|
38
|
+
|
|
39
|
+
For staging, select it on the login and on the first remote command:
|
|
38
40
|
|
|
39
41
|
```sh
|
|
42
|
+
firstdraft --staging login
|
|
40
43
|
firstdraft --staging plan push
|
|
41
44
|
firstdraft plan compile --staging
|
|
42
45
|
```
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
### How login works
|
|
48
|
+
|
|
49
|
+
The default login uses the OAuth 2.0 authorization code flow with PKCE (`S256`) and a loopback redirect
|
|
50
|
+
(RFC 8252). The CLI listens on `127.0.0.1` at an ephemeral port for one `GET /callback`, sends a random `state`
|
|
51
|
+
and code challenge, and waits up to five minutes. Only a callback with the exact `state` is accepted. Requests
|
|
52
|
+
for other paths, with a missing or different `state`, or with another `Host` get an error page and do not end
|
|
53
|
+
the wait, so a stray local request can neither inject a code nor cancel the login. The first matching callback
|
|
54
|
+
closes the listener and shows a page that says you can close the tab. The CLI then exchanges the single-use code
|
|
55
|
+
and its PKCE verifier at `POST /oauth/token`. The token never appears in a URL.
|
|
56
|
+
|
|
57
|
+
On a machine without a browser, such as an SSH session or a container, use the device flow (RFC 8628):
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
firstdraft login --interactive # also -i or --device
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The CLI prints a verification URL, a short user code, and a URL that already includes the code. Open either URL on
|
|
64
|
+
any device, confirm the code, and approve. The CLI polls at the server's interval, adds five seconds when asked to
|
|
65
|
+
slow down, and stops when the code expires.
|
|
66
|
+
|
|
67
|
+
Both flows send this machine's hostname as the device name shown on the approval page and in the token's name on
|
|
68
|
+
`/api-tokens`. A denied approval exits with `authorization_denied`. A login that is not approved in time exits with
|
|
69
|
+
`authorization_expired`. Other failures exit with `login_failed`. No credential is saved unless the login succeeds.
|
|
70
|
+
See [Errors and recovery](errors.md#login-and-logout-errors).
|
|
71
|
+
|
|
72
|
+
### Saved credentials
|
|
73
|
+
|
|
74
|
+
The token is saved in `$XDG_CONFIG_HOME/firstdraft/credentials.json`, or `~/.config/firstdraft/credentials.json`
|
|
75
|
+
when `XDG_CONFIG_HOME` is unset or not absolute. The directory is created with mode `0700`. The file is written
|
|
76
|
+
with mode `0600` through a temporary file and an atomic rename. Each update holds `credentials.json.lock` in the
|
|
77
|
+
same directory from its read to its rename, so concurrent commands cannot drop each other's entries. An update
|
|
78
|
+
waits up to 10 seconds for another command's lock, then fails with reason `credentials_locked`. The CLI never removes
|
|
79
|
+
a lock by itself: if no other `firstdraft` command is running, the lock was left by one that exited mid-update, and
|
|
80
|
+
you can delete it. The file stores one entry per exact origin, so production, staging, and local development logins
|
|
81
|
+
can exist side by side. Logging in again to the same origin replaces its
|
|
82
|
+
entry. Run `firstdraft logout` first if the old token should also be revoked. The CLI never prints a saved token or
|
|
83
|
+
writes it to `.firstdraft`.
|
|
84
|
+
|
|
85
|
+
`firstdraft logout` (or `firstdraft --staging logout`) asks First Draft to revoke the saved token for the selected
|
|
86
|
+
origin through `POST /oauth/revoke`. It then removes the local entry even when revocation cannot be confirmed; in
|
|
87
|
+
that case it says so on standard error, and you can revoke the token on `/api-tokens`. With nothing saved, it
|
|
88
|
+
reports that and exits 0. If a newer login saved a different token for the origin while revocation was pending,
|
|
89
|
+
logout keeps that token and says so on standard error. If the local update fails after revocation, logout exits with `logout_failed` and reports
|
|
90
|
+
whether revocation was confirmed; see [Errors and recovery](errors.md#login-and-logout-errors). Logout never changes
|
|
91
|
+
token environment variables.
|
|
92
|
+
|
|
93
|
+
### Environment tokens
|
|
94
|
+
|
|
95
|
+
Tokens from the environment still work and take precedence over a saved login. Create one on
|
|
96
|
+
[First Draft](https://firstdraft.com/api-tokens) and provide it through `FIRSTDRAFT_API_TOKEN`. For staging, create a
|
|
97
|
+
separate token at [First Draft staging](https://staging.firstdraft.com/api-tokens) and provide it through
|
|
98
|
+
`FIRSTDRAFT_STAGING_API_TOKEN`. Keep token values out of shell history and command arguments. `login` and `logout`
|
|
99
|
+
note on standard error when an environment token will override the saved login.
|
|
100
|
+
|
|
101
|
+
### Origins and projects
|
|
102
|
+
|
|
103
|
+
`--staging` may precede the command group or appear among a remote command's options, including `login` and
|
|
104
|
+
`logout`. It selects `https://staging.firstdraft.com`. `plan init` and `generate` remain local; a global flag on a
|
|
105
|
+
local command does not save an environment selection. The first successful push, including the push within
|
|
106
|
+
`plan compile`, pins the API origin in `.firstdraft/state.json`.
|
|
48
107
|
|
|
49
108
|
Existing Projects keep their pinned origin with or without the flag. A CLI upgrade does not migrate a Project or its
|
|
50
109
|
credentials. A staging flag that disagrees with a Project's pin stops before any request.
|
|
51
110
|
To work with another environment, initialize a separate project directory and submit the Plan there; do not edit
|
|
52
111
|
the existing Project's private state to redirect it.
|
|
53
112
|
|
|
54
|
-
`FIRSTDRAFT_API_URL` remains available for an initial custom HTTPS origin or loopback HTTP development server
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
`
|
|
113
|
+
`FIRSTDRAFT_API_URL` remains available for an initial custom HTTPS origin or loopback HTTP development server, and
|
|
114
|
+
it also selects the origin for `login` and `logout`, for example `FIRSTDRAFT_API_URL=http://127.0.0.1:3000
|
|
115
|
+
firstdraft login`. `--staging` together with a different URL is an error; the equivalent normalized staging URL is
|
|
116
|
+
allowed. Later pushes and compilation reject an override that differs from the pin. Read-only status and retained
|
|
117
|
+
download commands use the pin and ignore `FIRSTDRAFT_API_URL` unless checking its conflict with an explicit
|
|
118
|
+
`--staging`.
|
|
119
|
+
|
|
120
|
+
Every remote command selects credentials from its effective origin. First it uses the environment: the exact
|
|
121
|
+
`https://staging.firstdraft.com` origin uses `FIRSTDRAFT_STAGING_API_TOKEN`; production and custom origins use
|
|
122
|
+
`FIRSTDRAFT_API_TOKEN`. When that variable is unset or empty, it uses the token saved by `firstdraft login` for that
|
|
123
|
+
exact origin. No token is a fallback for a different origin: neither environment variable substitutes for the other,
|
|
124
|
+
and a saved login for one origin never authenticates another. This includes existing staging Projects and retained
|
|
125
|
+
status or artifact reads, even when no flag is supplied. An unreadable or malformed credentials file counts as no
|
|
126
|
+
saved login.
|
|
64
127
|
|
|
65
128
|
The CLI sends the selected token as a Bearer credential on every API request. It does not save it in `.firstdraft`,
|
|
66
129
|
print it, or require it for local commands. Revoke a token in the environment that issued it if it is exposed. A
|
|
@@ -153,8 +216,8 @@ or `superseded`. Every validated analysis status is a successful read with exit
|
|
|
153
216
|
`analysis.status` value and inspect `analysis.diagnostics` rather than treating a completed analysis with issues as
|
|
154
217
|
a transport failure.
|
|
155
218
|
|
|
156
|
-
The projection includes the exact Head digest, Analyzer and Compiler releases, selected target,
|
|
157
|
-
`analysis.gap_set` plus `analysis.gap_set_sha256`. A `valid` run always returns the complete parsed canonical
|
|
219
|
+
The projection includes the exact [Head](#head-and-its-etag) digest, Analyzer and Compiler releases, selected target,
|
|
220
|
+
and `analysis.gap_set` plus `analysis.gap_set_sha256`. A `valid` run always returns the complete parsed canonical
|
|
158
221
|
`firstdraft.foundation-gaps/2` object, including every ordered gap record and an empty `gaps` array when nothing is
|
|
159
222
|
missing. Both GapSet fields are `null` for every other status. The CLI validates the GapSet's Head, Project,
|
|
160
223
|
generation, releases, target, canonical digest, and complete record shapes, then prints the records without
|
|
@@ -179,8 +242,7 @@ firstdraft plan compile
|
|
|
179
242
|
This is equivalent to `firstdraft plan compile --output .`. Use `--output ./application` for another absent
|
|
180
243
|
directory, or `--github` to publish to a private GitHub repository. `--github` and `--output` are mutually exclusive.
|
|
181
244
|
No GitHub connection, repository clone, or push is required for local compilation. Compilation runs on the First
|
|
182
|
-
Draft service; output and the application runtime are local.
|
|
183
|
-
scripts that require that behavior must add `--github` when upgrading to `0.4.x` or later.
|
|
245
|
+
Draft service; output and the application runtime are local.
|
|
184
246
|
|
|
185
247
|
Both `plan compile` modes first push the exact current bytes in
|
|
186
248
|
`.firstdraft/foundation-plan.json`, even when those bytes are unchanged, and save the accepted ETag using the same
|
|
@@ -202,10 +264,6 @@ destination is checked again after analysis; root adoption instead holds its own
|
|
|
202
264
|
pre-move identity recheck described below. Other existing destinations remain invalid, so
|
|
203
265
|
`--output ./application` retains its absent-directory contract.
|
|
204
266
|
|
|
205
|
-
The nested archive layout below is shared by CLI `0.3.x` and later.
|
|
206
|
-
[Published CLI `0.2.2`](release-history.md#022-publication-and-registry-observation) archives at top-level `design/`;
|
|
207
|
-
existing applications are not migrated automatically.
|
|
208
|
-
|
|
209
267
|
The default `--output .` is the noninteractive root-adoption mode. `./`, an absolute spelling of the current directory, and
|
|
210
268
|
another spelling that resolves to that same physical directory select the same mode. It works at any real current
|
|
211
269
|
directory that meets the preconditions below and does not recognize Drawing Board or another repository layout
|
|
@@ -405,3 +463,105 @@ sibling directory, verifies the complete tree, and atomically renames it into th
|
|
|
405
463
|
POSIX, directories use mode `0755` and files use artifact-declared `0644` or `0755`; Windows verifies structure,
|
|
406
464
|
contents, and digests without claiming POSIX mode bits. The declared and streamed artifact envelope is bounded at
|
|
407
465
|
128 MiB.
|
|
466
|
+
|
|
467
|
+
## Service endpoints
|
|
468
|
+
|
|
469
|
+
The CLI calls these Service API routes. The `/v1` routes go to the origin pinned for the Project and send the
|
|
470
|
+
selected token as a Bearer credential. The `/oauth` routes go to the origin selected for `login` or `logout` and
|
|
471
|
+
send form-encoded OAuth parameters without a Bearer credential. Every request refuses redirects and has a bounded
|
|
472
|
+
timeout. Each request takes its method and path from one
|
|
473
|
+
`SERVICE_ROUTES` entry in `src/api-response.js`. `test/service-endpoints.test.js` fails when this table and
|
|
474
|
+
`SERVICE_ROUTES` differ, or when no file in `src/` uses a declared route.
|
|
475
|
+
|
|
476
|
+
| Method | Path | Purpose |
|
|
477
|
+
| ------ | ------------------------------------------------------------------ | ------------------------------------ |
|
|
478
|
+
| `PUT` | `/v1/projects/{project_id}/foundation-plan` | Create or replace the Head |
|
|
479
|
+
| `GET` | `/v1/projects/{project_id}/analysis` | Read the Head's current analysis |
|
|
480
|
+
| `POST` | `/v1/projects/{project_id}/compilations` | Start a Compilation of the Head |
|
|
481
|
+
| `GET` | `/v1/projects/{project_id}/compilations/{compilation_id}` | Read one retained Compilation |
|
|
482
|
+
| `GET` | `/v1/projects/{project_id}/compilations/{compilation_id}/artifact` | Download that Compilation's artifact |
|
|
483
|
+
| `PUT` | `/v1/projects/{project_id}/github-publication` | Start or rejoin the Publication |
|
|
484
|
+
| `GET` | `/v1/projects/{project_id}/github-publication` | Poll or reconcile the Publication |
|
|
485
|
+
| `POST` | `/oauth/token` | Exchange a login grant for a token |
|
|
486
|
+
| `POST` | `/oauth/device_authorization` | Start a device-flow login |
|
|
487
|
+
| `POST` | `/oauth/revoke` | Revoke a saved token |
|
|
488
|
+
|
|
489
|
+
`plan push` sends the Plan `PUT`, and `plan status` reads the analysis. `plan compile` does both. It then starts a
|
|
490
|
+
Compilation, polls it, and downloads its artifact. With `--github`, it starts and polls the Publication instead.
|
|
491
|
+
`compilation status` reads one retained Compilation. `compilation download` reads it and downloads its artifact.
|
|
492
|
+
`login` exchanges its authorization code at `/oauth/token`. With `--interactive`, it starts at
|
|
493
|
+
`/oauth/device_authorization` and then polls `/oauth/token`. `logout` calls `/oauth/revoke`. The browser, not the
|
|
494
|
+
CLI, opens `/oauth/authorize` and `/device`, so they have no rows.
|
|
495
|
+
|
|
496
|
+
The first push sends `If-None-Match: *`. Later pushes, the Compilation `POST`, and the Publication `PUT` send the
|
|
497
|
+
saved Head ETag in `If-Match`. The Service also has a Compilation cancel route, which the CLI does not call.
|
|
498
|
+
|
|
499
|
+
The `/v1` routes belong to the API-contract range that `release/compatibility.json` accepts. The CLI does not read the
|
|
500
|
+
Service's `FirstDraft-API-Contract` response header. Instead, the Service's release compatibility check compares the
|
|
501
|
+
declared ranges before a release. The Service documents the routes in its Foundation Plan machine reference,
|
|
502
|
+
`docs/architecture/reference/README.md` in the private `firstdraft/firstdraft` repository.
|
|
503
|
+
|
|
504
|
+
### Head and its ETag
|
|
505
|
+
|
|
506
|
+
The Head is the exact Foundation Plan bytes that First Draft holds for a Project. The latest accepted
|
|
507
|
+
`PUT /v1/projects/{project_id}/foundation-plan` sets it. The Service stores those bytes unchanged. A byte change that
|
|
508
|
+
keeps the Plan's meaning still makes a new Head, although the Project's `graph_version` stays the same.
|
|
509
|
+
|
|
510
|
+
A successful Plan `PUT` returns a strong `ETag` of the form `"sha256:<hex>"`, quotes included. `<hex>` is the
|
|
511
|
+
64-character lowercase SHA-256 of the Head bytes. The CLI saves the complete header value in `.firstdraft/state.json`
|
|
512
|
+
and replays it in `If-Match`. `plan compile` also extracts `<hex>` to check that the local Plan still matches the
|
|
513
|
+
Head before it starts a Compilation or Publication. A saved ETag in any other form stops that check with
|
|
514
|
+
`invalid_configuration`.
|
|
515
|
+
|
|
516
|
+
The same digest appears as `head_source_sha256` in analysis and Compilation responses. To tell whether the local Plan
|
|
517
|
+
is the Head, compare the SHA-256 of `.firstdraft/foundation-plan.json` with `analysis.head_source_sha256` from
|
|
518
|
+
`plan status`. The artifact download expects an ETag of the same form over the artifact bytes.
|
|
519
|
+
|
|
520
|
+
The Service reference asks clients to replay the Plan ETag without interpreting it. This CLI parses it anyway. A
|
|
521
|
+
Service ETag in another form would make every `plan compile` stop with `invalid_configuration`.
|
|
522
|
+
|
|
523
|
+
## Add a command
|
|
524
|
+
|
|
525
|
+
Use this checklist when a change adds a command or subcommand. Each step names the file to change.
|
|
526
|
+
|
|
527
|
+
1. **Implement it.** Put the command's logic in a module under `src/commands/`, usually `<group>-<name>.js`. Accept
|
|
528
|
+
`fetchFunction`, file system functions, clocks, and request signals as options, as the existing commands do, so
|
|
529
|
+
tests can replace them. Throw a named error class for each failure the command handles. Build each Service
|
|
530
|
+
request with `serviceEndpoint` and a route declared in `SERVICE_ROUTES` in `src/api-response.js`.
|
|
531
|
+
2. **Dispatch it in `src/cli.js`.**
|
|
532
|
+
- Add a `<GROUP>_<NAME>_HELP` string, and list the command in its group's help: `PLAN_HELP`,
|
|
533
|
+
`COMPILATION_HELP`, or `GENERATE_HELP`. A new group also needs a line in `ROOT_HELP` and a branch in `run`.
|
|
534
|
+
- Add the branch in `runPlan`, `runCompilation`, or `runGenerate`, and a `run<Group><Name>` function.
|
|
535
|
+
- Parse arguments with strict `parseArgs`. Invalid syntax writes `invalid_arguments` and exits 2.
|
|
536
|
+
- A command that calls the Service also accepts `--staging` and calls `authenticateApiCommand`. It maps each
|
|
537
|
+
error class to one `writeJson(stderr, …)` envelope and its exit status.
|
|
538
|
+
3. **Test it.**
|
|
539
|
+
- Add `test/<group>-<name>.test.js`. Cover the help text, invalid arguments, the success output, and every
|
|
540
|
+
handled `error` value.
|
|
541
|
+
- Update the exact group help in the tests: `HELP` in `test/cli.test.js`, `PLAN_HELP` in `test/plan-init.test.js`,
|
|
542
|
+
or `GENERATE_HELP` in `test/generate-uuid.test.js`. No test asserts the whole `compilation` group help.
|
|
543
|
+
- Append a command that calls the Service to `REMOTE_COMMANDS` in `test/api-environments.test.js`. Some tests
|
|
544
|
+
there select entries by index, so add it at the end. The command's first request must reach the pinned origin
|
|
545
|
+
with that origin's token, and one `401` must produce `authentication_required`.
|
|
546
|
+
- Add packed-package cases to `scripts/smoke-package.js`, including at least an invalid-arguments case.
|
|
547
|
+
4. **Package it.** Add each new `src/` file to the exact list in `scripts/check-pack.js`. `firstdraft/skills` keeps
|
|
548
|
+
a copy of that list as `packedFileAllowlist` in `script/cli-contract/config.mjs`. The copy must change when
|
|
549
|
+
Skills bundles this CLI version.
|
|
550
|
+
5. **Document it.**
|
|
551
|
+
- In this page, add a row to the [command map](#command-map) and a section for the command. Add a row to
|
|
552
|
+
[Service endpoints](#service-endpoints) for each new route, and name the command in the paragraph below the
|
|
553
|
+
table. If the command calls a route that section says the CLI does not call, such as Compilation cancel,
|
|
554
|
+
rewrite that sentence.
|
|
555
|
+
- In [errors.md](errors.md#error-index), add an Error index row for each new `error` value. Add recovery guidance
|
|
556
|
+
when retrying the command is safe in a different way than for the existing commands.
|
|
557
|
+
- When the Skill will call the command, update the Skill's CLI references and contract checks in
|
|
558
|
+
`firstdraft/skills` with its CLI pin.
|
|
559
|
+
6. **Review it.** New command names, flags, `error` values, and exit statuses need the independent review named in
|
|
560
|
+
`AGENTS.md`.
|
|
561
|
+
7. **Version it.** Choose the next version with the
|
|
562
|
+
[version rule](https://github.com/firstdraft/cli/blob/main/RELEASING.md#versions), and apply it with the
|
|
563
|
+
[version pull request](https://github.com/firstdraft/cli/blob/main/RELEASING.md#prepare-the-version-pull-request)
|
|
564
|
+
steps. If the command needs a route or response that the accepted API range lacks, the Service ships it first
|
|
565
|
+
under a new API-contract version. Then raise `requires.api_contract` in `release/compatibility.json`, and align
|
|
566
|
+
the Skills CLI requirement. Because the CLI does not read the contract header, an older Service rejects the new
|
|
567
|
+
route as not found.
|
package/docs/errors.md
CHANGED
|
@@ -7,7 +7,8 @@ This page owns handled-error interpretation, retry safety, and recovery guidance
|
|
|
7
7
|
|
|
8
8
|
Every handled subcommand failure ends with exactly one JSON object on standard error. `plan compile` may first write
|
|
9
9
|
progress lines; machine consumers can remove only lines beginning with the exact `First Draft: ` prefix and parse the
|
|
10
|
-
remaining JSON document.
|
|
10
|
+
remaining JSON document. `login` may first write its human-readable authorization instructions; its JSON object
|
|
11
|
+
starts on the line after them. Branch on the stable `error` value rather than the human-readable `detail`.
|
|
11
12
|
|
|
12
13
|
Handled output never includes command arguments, local Plan bytes, raw artifact bytes, raw filesystem or network
|
|
13
14
|
errors, or unvalidated response bodies. `local_state_not_saved` is the sole exception to private-state redaction:
|
|
@@ -21,10 +22,42 @@ saved origin. Push and Compile also reject any URL override that differs from th
|
|
|
21
22
|
override or use a separate initialized project directory for the other environment; do not redirect existing
|
|
22
23
|
private Project state. Status and retained download commands continue using their pin.
|
|
23
24
|
|
|
24
|
-
`authentication_required` means the selected environment's token is missing or rejected. Staging
|
|
25
|
-
`FIRSTDRAFT_STAGING_API_TOKEN`, including old staging Projects with no flag. Production and custom origins
|
|
26
|
-
`FIRSTDRAFT_API_TOKEN`.
|
|
27
|
-
|
|
25
|
+
`authentication_required` means the selected environment's token is missing or rejected. Staging uses
|
|
26
|
+
`FIRSTDRAFT_STAGING_API_TOKEN`, including old staging Projects with no flag. Production and custom origins use
|
|
27
|
+
`FIRSTDRAFT_API_TOKEN`. When that variable is unset, the token saved by `firstdraft login` for the exact origin is
|
|
28
|
+
used. The CLI never substitutes one environment's credential for another's. Run `firstdraft login` for the same
|
|
29
|
+
environment (with `--staging` or the same `FIRSTDRAFT_API_URL`), or refresh the environment token, then follow the
|
|
30
|
+
command's recovery instructions below. If a saved login is rejected, run `firstdraft login` again.
|
|
31
|
+
|
|
32
|
+
## Login and logout errors
|
|
33
|
+
|
|
34
|
+
`login` and `logout` never print a token. A local credential failure can occur after the server has issued or revoked a token.
|
|
35
|
+
|
|
36
|
+
- `authorization_denied`: the approval was denied in the browser. Run `firstdraft login` again to retry.
|
|
37
|
+
- `authorization_expired`: no loopback callback arrived within five minutes, or the device code expired before
|
|
38
|
+
approval. Run `firstdraft login` again. Use `--interactive` if no browser on this machine can reach the printed URL.
|
|
39
|
+
- `login_failed`: the login could not be completed. `reason`, when present, is the server's OAuth error code (for
|
|
40
|
+
example `invalid_grant` for a used, expired, or mismatched code), `loopback_unavailable` when the local listener
|
|
41
|
+
could not start, `credentials_invalid` / `credentials_unavailable` when the credentials file could not be read or
|
|
42
|
+
written, or `credentials_locked` when another command held its lock for 10 seconds. `status` is the HTTP status
|
|
43
|
+
when one was received. Credentials failures include `credentials_path` and `phase`. With `phase: "read"`, no
|
|
44
|
+
request was made; repair or remove the file and retry. With `phase: "write"`, First Draft issued a token but the
|
|
45
|
+
CLI could not save it. Revoke that new token on the selected origin's `/api-tokens` page, then repair the
|
|
46
|
+
credentials file and retry login. Any previously saved token remains unchanged when the replacement fails.
|
|
47
|
+
- `logout_failed`: the credentials file could not be read or updated. It carries `reason`, `credentials_path`,
|
|
48
|
+
and `phase`. With `phase: "read"`, no token was revoked or removed; repair or remove the file and retry. With
|
|
49
|
+
`phase: "write"`, local removal failed after the revocation attempt. `revoked: true` means First Draft confirmed
|
|
50
|
+
revocation; repair the file and retry logout to remove the stale entry. `revoked: false` means revocation was not
|
|
51
|
+
confirmed, so the token may still be active; revoke it on the selected origin's `/api-tokens` page, then repair
|
|
52
|
+
the file and retry logout. Preserve entries for other origins when repairing the file.
|
|
53
|
+
- With reason `credentials_locked`, from either command: wait for any other `firstdraft` command to finish and
|
|
54
|
+
retry. If none is running, the lock was left by a command that exited mid-update; delete `credentials.json.lock`
|
|
55
|
+
next to `credentials_path` instead of repairing the file, and retry. The CLI never removes the lock itself,
|
|
56
|
+
because it cannot tell an abandoned lock from one another command has just taken.
|
|
57
|
+
|
|
58
|
+
`invalid_configuration` from `login` or `logout` means `--staging` conflicts with `FIRSTDRAFT_API_URL`, or the URL is
|
|
59
|
+
invalid. A logout whose server revocation is not confirmed still succeeds after removing the local entry. It
|
|
60
|
+
writes a note on standard error; revoke the token on `/api-tokens` if it may still be active.
|
|
28
61
|
|
|
29
62
|
## Ambiguous mutations
|
|
30
63
|
|
|
@@ -123,7 +156,10 @@ stopped without following the replacement.
|
|
|
123
156
|
| Any leaf command | `invalid_arguments` | 2 | Syntax was invalid; no request was made. |
|
|
124
157
|
| `plan init` | `local_initialization_failed` | 1 | Initialization failed without overwriting an existing path. |
|
|
125
158
|
| Network commands | `invalid_configuration` | 2 | API origin or saved Head state is incompatible. |
|
|
126
|
-
|
|
|
159
|
+
| `login` | `authorization_denied`, `authorization_expired` | 1 | The approval was denied, or not granted before the callback wait or device code expired. |
|
|
160
|
+
| `login` | `login_failed` | 1 | Nothing was saved; `phase: "write"` means a token was issued ([recovery](#login-and-logout-errors)). |
|
|
161
|
+
| `logout` | `logout_failed` | 1 | Check `phase` and `revoked`; revocation may have happened ([recovery](#login-and-logout-errors)). |
|
|
162
|
+
| Network commands | `authentication_required` | 1 | No environment or saved token exists for the origin, or First Draft rejected it. |
|
|
127
163
|
| Plan commands, `compilation *` | `local_input_unreadable` | 1 | Required local Plan or private state could not be read. |
|
|
128
164
|
| Status, Compile, Compilation commands | `project_not_pushed` | 1 | No API origin is pinned for the local Project. |
|
|
129
165
|
| `plan push`, `plan compile` | `request_outcome_unknown` | 1 | A mutation or its response could not be verified; `plan compile` identifies its mutation phase. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstdraft.com/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Command-line interface for First Draft",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"bin",
|
|
12
|
-
"docs",
|
|
12
|
+
"docs/README.md",
|
|
13
|
+
"docs/commands.md",
|
|
14
|
+
"docs/errors.md",
|
|
13
15
|
"src",
|
|
14
|
-
"RELEASING.md",
|
|
15
16
|
"SECURITY.md"
|
|
16
17
|
],
|
|
17
18
|
"engines": {
|
|
@@ -39,7 +40,8 @@
|
|
|
39
40
|
"pack:check": "node scripts/check-pack.js",
|
|
40
41
|
"pack:smoke": "node scripts/smoke-package.js",
|
|
41
42
|
"test": "node scripts/run-tests.js",
|
|
42
|
-
"typecheck": "tsc --project jsconfig.json"
|
|
43
|
+
"typecheck": "tsc --project jsconfig.json",
|
|
44
|
+
"version": "node scripts/sync-version.js --apply"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@eslint/js": "10.0.1",
|