@firstdraft.com/cli 0.1.0-alpha.2 → 0.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 CHANGED
@@ -1,267 +1,84 @@
1
1
  # First Draft CLI
2
2
 
3
- `firstdraft` is the command-line client for [First Draft](https://github.com/firstdraft/firstdraft). It is being
4
- built for agents that author and review Foundation Plans with their users.
3
+ `firstdraft` is the command-line client for First Draft. It helps agents author and review
4
+ Foundation Plans with their users, then submit a valid Plan for the current bounded compilation and private GitHub
5
+ publication journey.
5
6
 
6
- Public alpha releases use npm's `next` tag. This release line contains the auditable command shell, local Foundation
7
- Plan initialization, local application-key and UUID generation, conditional whole-document push, whole-graph
8
- analysis status polling, compile-and-publish orchestration, and read-only retained-Compilation download.
9
- Interfaces may change between prereleases, and publishing the CLI does not make the wider First Draft service
10
- generally available.
7
+ The current `0.2.x` source line includes local Plan initialization, application-key and UUID generation, conditional
8
+ whole-document push, whole-graph analysis polling, compile-and-publish orchestration, and read-only retained
9
+ Compilation download. Analysis status exposes the complete reviewed GapSet before Compile. Remote commands require
10
+ a compatible First Draft service and are intended for coordinated trials; publishing this CLI does not make the
11
+ wider service generally available.
11
12
 
12
- ## Requirements
13
+ ## Install
13
14
 
14
- - Running the CLI: Node.js 22.0.0 or newer
15
- - Working on this repository: Node.js 24.18.0 (pinned in `.tool-versions`)
16
-
17
- ## Installation
18
-
19
- Once npm reports a public alpha, install the current prerelease explicitly:
15
+ Running the CLI requires Node.js 22.0.0 or newer. Install the stable release selected by npm's `latest` dist-tag:
20
16
 
21
17
  ```sh
22
- npm install --global @firstdraft.com/cli@next
18
+ npm install --global @firstdraft.com/cli
23
19
  firstdraft --version
24
20
  ```
25
21
 
26
- The npm package is `@firstdraft.com/cli`; it installs the `firstdraft` executable.
27
-
28
- There is intentionally no stable `latest` release yet. Pin an exact prerelease version instead of `next` when a
29
- repeatable installation matters. Remote Plan and Compilation commands require a
30
- compatible First Draft service and are currently intended for coordinated trials.
31
-
32
- ## Authenticate API commands
33
-
34
- Create an API token in First Draft and provide it only through the environment when running a network command:
35
-
36
- ```sh
37
- export FIRSTDRAFT_API_TOKEN="your-token"
38
- firstdraft plan push
39
- ```
22
+ The package installs the `firstdraft` executable. Pin an exact compatible version, such as
23
+ `@firstdraft.com/cli@0.1.0`, when a repeatable installation matters. Candidate publication under `next` is not stable
24
+ release completion and does not displace the supported `latest` release before promotion; see the
25
+ [release policy](RELEASING.md) and [dated release history](docs/release-history.md).
40
26
 
41
- `plan push`, `plan status`, `plan compile`, and `compilation` subcommands send the token as a Bearer credential on
42
- every API request. The CLI does not save it in `.firstdraft`, print it, or require it for local commands such as
43
- `plan init` and `generate`. Revoke the token in First Draft if it is exposed. A missing token, or First Draft's validated
44
- `401` problem response with the `authentication_required` code, produces that stable CLI error.
27
+ ## Shortest current journey
45
28
 
46
- ## Development
47
-
48
- ```sh
49
- npm ci
50
- npm run check
51
- npm run pack:check
52
- ```
53
-
54
- To reproduce the length-delimited SHA-256 used by external evidence to identify the packaged JavaScript runtime
55
- inputs (`package.json`, `bin/firstdraft.js`, and every `.js` file under `src/`), run from the repository root:
56
-
57
- ```sh
58
- node scripts/runtime-digest.js
59
- ```
60
-
61
- ## Start a Foundation Plan
62
-
63
- From the project that the Plan describes:
29
+ From the project that the Foundation Plan describes:
64
30
 
65
31
  ```sh
66
32
  firstdraft plan init --name "Oscar Party"
67
33
  ```
68
34
 
69
- This creates an empty `sketch/0.19` Plan and client-generated Project ID under `.firstdraft/`. A nested ignore file
70
- keeps that local scratch area out of Git without changing the project's own `.gitignore`. Initialization makes no
71
- network request and refuses to replace an existing `.firstdraft` path.
72
-
73
- Provide either `--name`, `--application-key`, or both. Name-only initialization derives a lower-snake key. Key-only
74
- initialization derives a humanized display name. Supplying both preserves both values exactly after
75
- validating them against the Foundation Plan schema. To inspect the name-to-key derivation without initializing a
76
- project, run:
77
-
78
- ```sh
79
- firstdraft generate application-key --name "Oscar Party"
80
- ```
81
-
82
- The generated key is deterministic, starts with a letter, contains only lowercase ASCII letters, digits, and
83
- underscores, and is at most 63 bytes so it can lower to the current iOS application identifier component. Names
84
- without a readable ASCII form receive a stable digest-based key. Longer readable names are shortened to a readable
85
- prefix plus a stable digest suffix. Explicit application keys retain the Foundation Plan's broader
86
- `^[a-z][a-z0-9_]*$` boundary and are left for target analysis rather than silently rewritten.
87
-
88
- ## Add Foundation Plan subjects
89
-
90
- Generate an identity before adding each new independently mutable authored subject:
35
+ Edit `.firstdraft/foundation-plan.json`, preserving each authored subject's UUID across renames and moves that do not
36
+ replace the concept. Generate new subject identities locally as needed:
91
37
 
92
38
  ```sh
93
39
  firstdraft generate uuid
94
40
  ```
95
41
 
96
- The command prints one UUIDv7 for the subject's `subject_uuid`. It does not read or modify the Plan, reserve the
97
- value, or make a network request. Preserve that UUID when renaming the subject or moving it to a different semantic
98
- owner without changing its kind. Use a new UUID for a replacement concept. Readable keys and paths may change and
99
- remain the document's links; the UUID preserves continuity between complete-document pushes.
100
-
101
- Use `--count <n>` to print several independently generated UUIDv7 values, one per line.
102
-
103
- ## Push a Foundation Plan
104
-
105
- From the initialized project:
106
-
107
- ```sh
108
- firstdraft plan push
109
- ```
110
-
111
- The command sends the exact bytes in `.firstdraft/foundation-plan.json`. The first push conditionally creates the
112
- Project; later pushes replay the complete ETag saved in `.firstdraft/state.json` so a stale writer cannot replace a
113
- newer Plan. Successful responses and server diagnostics are printed as JSON for an agent to inspect.
114
-
115
- The initial API origin defaults to `https://firstdraft.com`. Set `FIRSTDRAFT_API_URL` to use another HTTPS origin
116
- or a loopback HTTP development server. The first successful push pins the normalized origin in local state, and a
117
- later override must match it.
118
-
119
- If a failure happens after sending the request, the CLI reports that the outcome may be ambiguous and leaves local
120
- state unchanged. It never constructs an ETag from the Plan digest or trusts an ETag from a response it could not
121
- fully verify. Until First Draft has a Foundation Plan head reconciliation endpoint, an accepted request whose
122
- response cannot be verified may require manual recovery. If a verified response cannot replace local state,
123
- preserve the printed recovery state; an adjacent `.tmp` file may contain the same private recovery copy.
124
-
125
- ## Read analysis status
126
-
127
- After a successful push:
128
-
129
- ```sh
130
- firstdraft plan status
131
- firstdraft plan status --wait
132
- ```
133
-
134
- Without `--wait`, the command makes one `GET` and prints the current analysis as one JSON object. With `--wait`, it
135
- polls sequentially once per second for at most two minutes and stops at `valid`, `issues_found`, `analysis_failed`,
136
- or `superseded`. Every validated analysis status is a successful read with exit 0; agents should branch on the
137
- `analysis.status` value and inspect `analysis.diagnostics` rather than treating a completed analysis with issues as
138
- a transport failure.
139
-
140
- Status reads require the API origin pinned by a successful push. They never select an origin from the current
141
- environment, expose the private ETag, follow redirects, or modify local state. Each request has a bounded timeout,
142
- every response is byte-bounded and fully validated, and polling will not silently switch to a replacement analysis.
143
- The wait repeats only validated `processing` responses and stops on its first failed read. A network failure is safe
144
- to retry a bounded number of times because the command sends only `GET` requests. If `status_unavailable` persists,
145
- inspect the API origin pinned in `.firstdraft/state.json`; an invalid server response instead requires reconciling the
146
- CLI and server contract.
147
-
148
- ## Compile and publish the current Plan
149
-
150
- When the candidate is ready, run:
42
+ Provide an API token only through the environment, then submit, analyze, compile, and publish the exact current Plan:
151
43
 
152
44
  ```sh
45
+ export FIRSTDRAFT_API_TOKEN="your-token"
153
46
  firstdraft plan compile
154
47
  ```
155
48
 
156
- `plan compile` is the single terminal action. It first pushes the exact current bytes in
157
- `.firstdraft/foundation-plan.json`, even when those bytes are unchanged, and saves the accepted ETag using the same
158
- contract as `plan push`. It then waits up to two minutes for an analysis whose graph version exactly matches that
159
- accepted push, polling past a terminal result retained for an older Head. Invalid JSON, schema diagnostics,
160
- semantic diagnostics, a failed analysis, a superseded analysis, or a recurring diagnostic stop the command with
161
- structured output; no Compilation or Publication is requested.
162
-
163
- Only a `valid` analysis proceeds to the internal GitHub Publication lifecycle. Invoking `plan compile` is the
164
- authorization to request that lifecycle. Immediately before its conditional mutation, the CLI re-reads the local
165
- Plan and requires its exact bytes to match the accepted Head, so bytes changed after analysis cannot be published.
166
- It extracts the accepted source SHA-256 from the saved ETag, hashes the current local bytes, and then sends that
167
- complete ETag in `If-Match`.
168
- The command writes no progress output to stdout. Success is exactly one validated JSON object containing the
169
- retained `project`, `compilation`, and `publication`, including the private GitHub repository URL.
170
-
171
- The internal Publication is a Project singleton in this release. A repeat safely receives the same Publication
172
- instead of creating another. If the first conditional `PUT` has an ambiguous result, the CLI reconciles it with
173
- one read-only singleton `GET` and never automatically repeats the mutation. Rerunning `plan compile` safely
174
- replays the singleton request. Publication polling is sequential, bounded to ten minutes, and pinned to the
175
- retained Project Head, Compilation input, Publication identity, and repository identity.
176
-
177
- This release cannot repoint a Project's Publication to a later accepted Head. The public CLI therefore has no
178
- `plan publish` command and no local-start `plan compile --output` mode. Use the standalone retained-Compilation
179
- commands below when local generated source is useful.
180
-
181
- ## Inspect a retained Compilation
182
-
183
- Read one Compilation ID returned by `plan compile`:
184
-
185
- ```sh
186
- firstdraft compilation status 01900000-0000-7000-8000-000000000001
187
- firstdraft compilation status 01900000-0000-7000-8000-000000000001 --wait
188
- ```
189
-
190
- Without `--wait`, the command makes exactly one metadata-only `GET`. With `--wait`, it polls that same
191
- Compilation sequentially for at most ten minutes and rejects changes to its identity, Head provenance, target, or
192
- lifecycle progression. `failed` and `cancelled` are successfully read terminal states with exit 0; branch on
193
- `compilation.status` and inspect its validated `failure`.
194
-
195
- ## Download a retained Compilation
196
-
197
- Materialize an already successful Compilation into an absent path:
198
-
199
- ```sh
200
- firstdraft compilation download 01900000-0000-7000-8000-000000000001 --output ../movie-catalog
201
- ```
202
-
203
- The command validates the UUID and output path before network access, makes one status `GET`, requires
204
- `succeeded`, and makes one artifact `GET`. It never starts work or polls. Historical artifact validation uses
205
- the retained `compilation.head_source_sha256`, not the current local Plan or ETag, to pin the artifact's exact
206
- `head_source_sha256`. The artifact's canonical `foundation_plan.sha256` may differ because it identifies the
207
- normalized Compiler input. It is validated as a SHA-256 digest inside the exact artifact bytes authenticated by
208
- the status response's `artifact.sha256`; it is not equated to the submitted Head digest.
209
-
210
- Before materialization, the CLI verifies the artifact media type, declared and actual byte sizes, strong digest
211
- ETag, exact-byte SHA-256, canonical UTF-8 JSON envelope, provenance, metadata-only manifest digest, portable paths,
212
- strict Base64 contents, file digests, modes, owners, and source-subject UUIDs. It writes only into a uniquely
213
- created sibling directory, verifies the complete tree, and atomically renames it into the still-absent destination.
214
- On POSIX, directories use mode `0755` and files use artifact-declared `0644` or `0755`; Windows verifies
215
- structure, contents, and digests without claiming POSIX mode bits.
216
-
217
- ## Handled failures
49
+ Invoking `plan compile` authorizes the internal GitHub Publication lifecycle. It proceeds only after the accepted
50
+ Plan's analysis is valid, writes allowlisted progress to standard error, and on success writes only the validated
51
+ private GitHub repository URL to standard output. The current Publication is a Project singleton and cannot be
52
+ repointed to a later accepted Head. Read the [complete command contract](docs/commands.md#compile-and-publish-the-current-plan)
53
+ before using it and follow [phase-specific recovery](docs/errors.md#ambiguous-mutations) after an ambiguous mutation.
218
54
 
219
- Every handled subcommand failure writes exactly one JSON object to standard error. Branch on its stable `error`
220
- value rather than the human-readable `detail`; `plan compile` also supplies `phase: "push" | "publication"` when
221
- `request_outcome_unknown` requires phase-specific recovery:
222
-
223
- - `phase: "push"` means the Plan mutation may have been accepted; stop and reconcile local Head state.
224
- - `phase: "publication"` means the singleton Publication mutation was not resolved; rerunning `plan compile` is a
225
- safe replay.
226
-
227
- | Commands | `error` | Exit | Meaning |
228
- | -------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---: | -------------------------------------------------------------------------------------------------------------- |
229
- | Any leaf command | `invalid_arguments` | 2 | Syntax was invalid; no request was made. |
230
- | `plan init` | `local_initialization_failed` | 1 | Initialization failed without overwriting an existing path. |
231
- | `plan push`, `plan compile` | `invalid_configuration` | 2 | API origin or saved Head state is incompatible. |
232
- | Network commands | `authentication_required` | 1 | The token is missing or First Draft returned a validated authentication problem. |
233
- | Plan commands, `compilation *` | `local_input_unreadable` | 1 | Required local Plan or private state could not be read. |
234
- | Status, Compile, Compilation commands | `project_not_pushed` | 1 | No API origin is pinned for the local Project. |
235
- | `plan push`, `plan compile` | `request_outcome_unknown` | 1 | A mutation or its response could not be verified; `plan compile` identifies its `push` or `publication` phase. |
236
- | `plan push`, `plan compile` | `local_state_not_saved` | 1 | The Plan was accepted but the private ETag state could not be replaced; includes `recovery_state`. |
237
- | `plan push`, `plan compile` | `server_rejected` | 1 | First Draft returned validated Plan diagnostics or a validated problem. |
238
- | `plan status` | `status_unavailable`, `invalid_server_response` | 1 | The analysis read failed or violated its protocol. |
239
- | `plan compile` | `analysis_status_unavailable`, `invalid_analysis_status`, `analysis_status_rejected` | 1 | The bounded analysis read failed, was invalid, or was rejected. |
240
- | Analysis waits | `analysis_changed`, `wait_timed_out`, `analysis_wait_timed_out` | 1 | The pinned analysis changed or remained processing at the deadline. |
241
- | `plan compile` | `plan_not_valid` | 1 | Analysis completed without `valid`; `current` contains diagnostics and status. |
242
- | `plan compile` | `local_plan_changed` | 1 | Local bytes changed after acceptance or analysis, before Publication mutation. |
243
- | `plan compile` | `publication_start_rejected`, `publication_status_unavailable`, `invalid_publication_status` | 1 | Publication start or status failed its validated transport contract. |
244
- | `plan compile` | `publication_changed`, `publication_wait_timed_out`, `publication_failed`, `publication_cancelled` | 1 | The pinned Publication changed, timed out, or reached a non-success terminal state. |
245
- | `compilation status`, `compilation download` | `compilation_status_unavailable`, `invalid_compilation_status` | 1 | The retained status could not be read or violated its exact contract. |
246
- | `compilation status --wait` | `compilation_changed`, `compilation_wait_timed_out` | 1 | Retained identity/provenance changed or the wait ended. |
247
- | `compilation download` | `compilation_not_succeeded` | 1 | Status was not `succeeded`; no artifact request was made. |
248
- | `compilation download` | `artifact_unavailable`, `invalid_artifact` | 1 | Artifact transport or integrity validation failed before materialization. |
249
- | `compilation download` | `invalid_output_path` | 2 | The destination was not an absent path beneath an existing real directory. |
250
- | `compilation download` | `materialization_failed` | 1 | The output raced or the verified tree could not be atomically installed. |
251
-
252
- Handled output never includes command arguments, local Plan bytes, raw artifact bytes, raw filesystem or network
253
- errors, or unvalidated response bodies. `local_state_not_saved` is the sole exception to private-state redaction:
254
- its `recovery_state` is required to repair the accepted ETag locally. Root-level and command-group usage failures
255
- remain human-readable text on standard error with exit 2. Unexpected programming defects remain loud.
55
+ To review analysis before that terminal action, use `firstdraft plan push` followed by
56
+ `firstdraft plan status --wait`. See [Command reference](docs/commands.md) for all supported commands, flags, output
57
+ contracts, and retained-Compilation operations.
256
58
 
257
59
  ## Trust model
258
60
 
259
- - The published CLI will run the reviewed JavaScript source directly, without generated or bundled code.
260
- - The CLI has no runtime dependencies, install scripts, telemetry, update checks, or network activity except an
261
- explicitly invoked API command.
262
- - Package contents are allowlisted and checked before release.
61
+ - The published CLI runs the reviewed JavaScript source directly, without generated or bundled code.
62
+ - It has no runtime dependencies, install scripts, telemetry, update checks, or network activity except an explicitly
63
+ invoked API command.
64
+ - API tokens are read from `FIRSTDRAFT_API_TOKEN`, sent as Bearer credentials, and never saved in `.firstdraft` or
65
+ printed. Revoke an exposed token in First Draft.
66
+ - Package contents are allowlisted and checked before release. The public documentation graph is packaged with the
67
+ exact CLI version; agent instructions and source-only release metadata remain repository-only.
263
68
  - CI exercises the exact minimum Node.js version separately from current development tooling.
264
- - Public packages carry npm provenance linking their registry bytes to the reviewed GitHub workflow and commit.
265
-
266
- Security issues should follow the
267
- [private reporting instructions](https://github.com/firstdraft/cli/security/advisories/new).
69
+ - Public packages carry npm provenance linking registry bytes to the reviewed GitHub workflow and commit.
70
+
71
+ ## Find the right documentation
72
+
73
+ | Task | Read |
74
+ | ------------------------------------------------------- | ------------------------------------------ |
75
+ | Install and complete the shortest current journey | This README |
76
+ | Choose a command or inspect its exact behavior | [Command reference](docs/commands.md) |
77
+ | Interpret an error or recover safely | [Errors and recovery](docs/errors.md) |
78
+ | Contribute to this repository | [Documentation map](docs/README.md) |
79
+ | Prepare, publish, verify, recover, or promote a release | [Release policy and runbook](RELEASING.md) |
80
+ | Check dated package, tag, or channel observations | [Release history](docs/release-history.md) |
81
+ | Report a vulnerability | [Security policy](SECURITY.md) |
82
+
83
+ Run `firstdraft --help` or a command group's `--help` for concise terminal syntax. The documentation map explains
84
+ which source owns each longer-lived contract.
package/RELEASING.md ADDED
@@ -0,0 +1,210 @@
1
+ # Releasing First Draft CLI
2
+
3
+ This document owns living release policy and the operator runbook. Dated tag, package, qualification, and dist-tag
4
+ observations belong in [release history](docs/release-history.md) and must be rechecked before an operation.
5
+
6
+ Publishing is a separate, explicit action after a release-preparation pull request has merged. npm registry bytes
7
+ and package versions cannot be replaced, so do not create or push a release tag as a dry run.
8
+
9
+ Only a version that npm reports as published or a protected release tag that exists is immutable. Before either
10
+ exists, an unpublished candidate may be revised without changing its proposed version; its exact source SHA and
11
+ reviewed digests identify it. Reconcile the registry and remote tags before deciding that a version was consumed.
12
+
13
+ ## Pre-1.0 version and channel policy
14
+
15
+ Before `1.0.0`, First Draft CLI uses ordinary `0.MINOR.PATCH` versions. Increase `MINOR` for a breaking
16
+ compatibility-line change. Increase `PATCH` for a change that is otherwise backward-compatible within the current
17
+ minor line. Never reuse a published version to preserve compatibility; publish the next version required by this
18
+ policy. Do not add aliases or shims solely to make a breaking compatibility line look patch-compatible. The policy
19
+ applies to ordinary versions; historical prereleases do not establish an ordinary compatibility line.
20
+
21
+ Version semantics and npm distribution channels are independent. An approved candidate is published first under
22
+ the approval-gated `next` tag even when it has an ordinary version such as `0.1.0`. The release workflow does not
23
+ move `latest`. Moving `latest` requires a later, separate approval after the exact `next` candidate has completed
24
+ its explicitly named release-specific qualification. Candidate publication is not stable release completion. A
25
+ stable CLI release is complete only when that separately approved candidate is selected by npm's `latest` dist-tag.
26
+ Release-specific qualification means the exact gate named for that candidate; it does not imply unrelated or full
27
+ service qualification. Until promotion, `latest` remains the supported stable release; a distinct `next` candidate
28
+ is supported only for its named qualification. When both tags identify one version, that version fills both roles.
29
+
30
+ ## Coordinated candidate eligibility
31
+
32
+ `release/compatibility.json` declares this package's SemVer version, the First Draft API-contract range it accepts,
33
+ and the exact Foundation Plan formats it accepts. It is source-only release metadata and is intentionally absent from
34
+ the npm tarball. The normal test suite validates the manifest's shape, keeps its version equal to `package.json`, and
35
+ binds its Foundation Plan format to the implemented CLI constant.
36
+
37
+ The `script/release_compatibility_check` evaluator in `firstdraft/firstdraft` reads this declaration with the matching
38
+ declarations from exact, clean checkouts of `firstdraft/firstdraft` and `firstdraft/skills`. It implements SemVer 2.0
39
+ precedence. CLI `0.2.x` requires the service's `0.3.x` API contract because Analysis now returns the complete reviewed
40
+ GapSet and digest. The released CLI `0.1.0` accepts only API `0.2.x`, uses a generic 2 MiB response bound for Analysis,
41
+ and cannot safely consume every schema-valid API `0.3.x` result. CLI `0.2.x` retains that generic bound but gives
42
+ Analysis and Compilation artifacts dedicated 128 MiB bounds. Comparator arrays form one conjunction, while
43
+ `foundation_plan_formats` lists alternatives. A prerelease satisfies a comparator set only when a comparator
44
+ explicitly names a prerelease with the same major, minor, and patch numbers. Skills names the candidate CLI version
45
+ explicitly, so a stale comparator makes the three-repository candidate ineligible.
46
+ `firstdraft.release-compatibility/1` is intentionally closed. The evaluator in `firstdraft/firstdraft` rejects an
47
+ unrecognized format and unknown keys, so adding a key requires a coordinated compatibility-format bump rather than
48
+ silently changing version 1.
49
+
50
+ A compatible result establishes candidate eligibility, not authorization or runtime proof. Exact Git SHAs identify
51
+ the three-repository candidate. A merge to `main` is integration only: report the merged SHA and ask the user whether
52
+ to coordinate the three repositories and promote that candidate. If promotion is declined, record the SHA as
53
+ unpromoted.
54
+
55
+ Promotion is manual and approval-gated. One operator serializes mutations: qualify the exact candidate on staging,
56
+ obtain human approval, and only then promote the approved service revision to production or authorize the
57
+ corresponding npm and plugin releases. Do not publish npm, deploy either environment, or release the plugin merely
58
+ because the compatibility check passes.
59
+
60
+ ## Repository and registry controls
61
+
62
+ Before a release, a repository administrator must confirm:
63
+
64
+ 1. Confirm `firstdraft/cli` is public. The release workflow deliberately removes checkout credentials and re-fetches
65
+ the public release refs anonymously.
66
+ 2. Confirm `main` has pull-request and CI requirements and a `v*` tag ruleset restricts tag creation, update, and
67
+ deletion.
68
+ 3. Confirm the GitHub environment named `npm` is restricted to release tags, requires an explicit reviewer, disables
69
+ administrator bypass, and defines `NPM_RELEASE_ENABLED=true`. The workflow fails before publishing when this
70
+ variable is absent.
71
+ 4. Confirm that the `firstdraft.com` npm organization and `@firstdraft.com/cli` package still identify the intended
72
+ publisher and repository. The publisher account must have write-protecting 2FA enabled. Verify authenticated
73
+ identity, organization membership, package identity, and current tags:
74
+
75
+ ```sh
76
+ npm whoami
77
+ npm org ls firstdraft.com --json
78
+ npm view '@firstdraft.com/cli' name repository.url versions dist-tags --json
79
+ ```
80
+
81
+ 5. Before creating a `v<package-version>` tag, verify [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)
82
+ for the exact package, repository, workflow, protected environment, and allowed publish operation. No persistent
83
+ npm credential is permitted for a release workflow.
84
+
85
+ Use the repository-pinned Node.js 24.18.0 toolchain with npm 11.16.0 to verify the organization's durable read/write
86
+ access:
87
+
88
+ ```sh
89
+ npm --version
90
+ npm access list packages firstdraft.com:developers '@firstdraft.com/cli' --json
91
+ ```
92
+
93
+ Require the package to report `read-write` access for the `developers` team. If access is missing or changed, stop:
94
+ restoring it is a separate administrator and security mutation, not a routine release step.
95
+
96
+ For every release, inspect the existing trusted-publisher relationship read-only:
97
+
98
+ ```sh
99
+ npm trust list '@firstdraft.com/cli'
100
+ ```
101
+
102
+ Confirm `npm trust list` reports type `github`, repository `firstdraft/cli`, file `publish.yml`, environment `npm`,
103
+ and permission `createPackage`, which is npm's trust-list vocabulary for the allowed publish operation. npm does not
104
+ validate the saved relationship by attempting an exchange, so each case-sensitive value must be inspected. If the
105
+ relationship is missing or changed, stop: restoring it is a separate administrator and security mutation, not a
106
+ routine release step. The publish job must remain on a GitHub-hosted runner with `id-token: write` and must not read
107
+ `NODE_AUTH_TOKEN`, an npm token, or any GitHub Actions secret. Confirm the repository and `npm` environment secret
108
+ lists contain no npm automation secret. Trusted publishing's short-lived OIDC exchange is the sole workflow
109
+ publication credential; an authentication failure stops the release and must never fall back to a persistent token.
110
+
111
+ As optional defense-in-depth after trusted publication is operationally proven, an npm administrator may complete
112
+ the separate security-key ceremony and set package **Publishing access** to **Require two-factor authentication and
113
+ disallow tokens**. Do not report that setting as enabled until it is directly observed.
114
+
115
+ ## Prepare a release
116
+
117
+ 1. Update `package.json`, `package-lock.json`, and `release/compatibility.json` to the exact release version.
118
+ 2. When that version changes, coordinate the matching explicit CLI comparator in `firstdraft/skills` before
119
+ qualification; a stale comparator intentionally makes the three-repository candidate ineligible.
120
+ 3. Apply the pre-1.0 policy: use a minor increment for a breaking compatibility line and a patch increment for a
121
+ change that is otherwise backward-compatible. Keep the initial distribution under `next` independently of that
122
+ version choice. Do not move `latest` during release publication.
123
+ 4. Confirm neither the exact package version nor its `v<package-version>` tag already exists. If both remain absent,
124
+ the unpublished candidate may retain its proposed version while its exact SHA and digests are revised.
125
+ 5. Re-run `npm trust list '@firstdraft.com/cli'`, verify the exact `github`/repository/file/environment/`createPackage`
126
+ relationship described above, and confirm the workflow contains no persistent npm credential or GitHub Actions
127
+ secret.
128
+ 6. Update user-facing documentation and release notes for behavior changes.
129
+ 7. Run:
130
+
131
+ ```sh
132
+ npm ci --ignore-scripts
133
+ npm audit
134
+ npm run check
135
+ ```
136
+
137
+ 8. Merge the reviewed pull request only after local and hosted checks pass.
138
+
139
+ ## Publish
140
+
141
+ The manual boundary is creation of the version tag. From an up-to-date, clean `main`, verify the intended commit and
142
+ confirm that both the intended package version and `v<package-version>` tag are absent. If either identity is already
143
+ consumed, prepare the next version required by the pre-1.0 policy rather than moving or reusing it. Otherwise create
144
+ and push the tag. Push one release tag at a time; the workflow serializes publication, but GitHub retains at most one
145
+ pending run in a concurrency group.
146
+
147
+ The workflow rejects accidental or stale inputs unless they use a protected `v*` tag in `firstdraft/cli`, the tag
148
+ equals `v` plus the version in `package.json`, the remote tag still identifies the triggering commit, and that commit
149
+ appears in the first-parent history of `origin/main`. First-parent membership allows an older reviewed `main` state
150
+ after another change lands while rejecting intermediate commits from a merged side branch. The workflow reruns the
151
+ complete check, waits for approval in the `npm` environment, reverifies the remote refs, and publishes to the public
152
+ registry with provenance under `next`. It authenticates only through the exact npm trusted-publisher relationship and
153
+ the job's short-lived GitHub OIDC token; it reads no persistent npm credential or GitHub Actions secret.
154
+
155
+ The tag ruleset and `npm` environment approval are the external trust boundary because a tag-push run loads its
156
+ workflow from the tagged commit. Before approving the `npm` deployment, the reviewer must confirm:
157
+
158
+ - The tag, package version, and commit SHA are the intended release.
159
+ - The commit is a known reviewed state in protected `main` history and its required checks passed.
160
+ - `.github/workflows/publish.yml` at that commit is the reviewed workflow, still selects the `npm` environment, and
161
+ publishes the public `@firstdraft.com/cli` package only under `next` with provenance.
162
+ - npm lists the exact `github`/`firstdraft/cli`/`publish.yml`/`npm`/`createPackage` trusted-publisher relationship,
163
+ and the GitHub repository and `npm` environment contain no npm automation secret.
164
+ - The unprivileged verification job passed for that exact commit.
165
+
166
+ Do not move or reuse a release tag. If the tagged commit is not a first-parent state of `main`, merge the intended
167
+ change and prepare a new version rather than moving an already shared tag.
168
+
169
+ ## Verify and recover
170
+
171
+ After publication, inspect the registry before retrying any reported failure; the package may already exist. From
172
+ the tagged checkout, verify the exact version, `next` dist-tag, unchanged `latest` dist-tag, integrity metadata, and
173
+ provenance metadata:
174
+
175
+ ```sh
176
+ FD_CLI_RELEASE_VERSION="$(node -p "require('./package.json').version")"
177
+ npm view "@firstdraft.com/cli@$FD_CLI_RELEASE_VERSION" \
178
+ version dist.integrity dist.shasum repository.url engines bin --json
179
+ npm dist-tag ls '@firstdraft.com/cli'
180
+ ```
181
+
182
+ Install that exact version into a fresh temporary prefix, confirm `firstdraft --version`, compare the
183
+ packed file list with the release workflow, and run `npm audit signatures` after an exact installation.
184
+
185
+ If OIDC authentication fails, reconcile both the registry version and protected remote tag first. If only npm's
186
+ listed relationship is wrong, correct it on npm and rerun the existing workflow's failed jobs without changing the
187
+ tagged source. If the workflow filename, environment, permissions, or other identity at the tagged commit is wrong,
188
+ the protected tag is immutable: prepare the next version rather than moving the tag. Never add a token fallback.
189
+
190
+ A published version cannot be overwritten or reused. For a bad release, move `next` only to a known-good compatible
191
+ version if one exists; otherwise deprecate the bad version and publish a corrected higher version. Treat
192
+ unpublishing as an exceptional incident response, not a routine rollback.
193
+
194
+ ## Promote the release-specific qualified candidate
195
+
196
+ Publishing under `next` is not promotion to the default install channel. After the exact `next` version completes
197
+ its named release-specific qualification and a human separately approves promotion, one operator may move `latest`
198
+ to that exact version from the tagged checkout:
199
+
200
+ ```sh
201
+ FD_CLI_RELEASE_VERSION="$(node -p "require('./package.json').version")"
202
+ npm dist-tag add "@firstdraft.com/cli@$FD_CLI_RELEASE_VERSION" latest
203
+ npm dist-tag ls '@firstdraft.com/cli'
204
+ ```
205
+
206
+ Verify both tags after the mutation, then append the exact dated observation and qualification boundary to
207
+ [release history](docs/release-history.md). The stable CLI release is complete only after `next` and `latest` both
208
+ name the exact release-specific qualified version. Do not call a candidate fully promoted before that equality is
209
+ observed. Do not move `latest` merely because a release merged, published successfully, or passed candidate
210
+ compatibility checks, and do not use a dist-tag change to repair or disguise a bad immutable version.
package/SECURITY.md ADDED
@@ -0,0 +1,18 @@
1
+ # Security
2
+
3
+ Please report suspected vulnerabilities through a
4
+ [private GitHub security advisory](https://github.com/firstdraft/cli/security/advisories/new). Do not include
5
+ sensitive details in a public Issue.
6
+
7
+ ## Supported versions
8
+
9
+ During coordinated trials, the stable release currently identified by npm's `latest` tag receives security fixes. A
10
+ different version under the approval-gated `next` tag is supported only for its explicitly named release-specific
11
+ qualification; it does not displace the stable release before separate promotion approval. When `next` and `latest`
12
+ identify the same version, that release fills both roles.
13
+
14
+ Distribution channels are independent of version syntax. Before `1.0.0`, increasing the minor version starts a
15
+ breaking compatibility line; increasing the patch version is otherwise backward-compatible within that line. All
16
+ other older ordinary versions, historical prereleases, and unreleased source snapshots are not supported unless a
17
+ separate support policy says otherwise. Historical prereleases remain outside the ordinary version compatibility
18
+ guarantee.
package/docs/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # First Draft CLI documentation
2
+
3
+ Use this page to find the narrowest authoritative document for a task. Runtime source and tests remain the final
4
+ evidence for implemented behavior; if they contradict a document, surface the contradiction instead of guessing.
5
+
6
+ | If the task concerns... | Read first |
7
+ | -------------------------------------------------------------------------------------- | --------------------------------------------- |
8
+ | Public installation, trust, or the shortest current journey | [Root README](../README.md) |
9
+ | Commands, options, environment variables, API behavior, output, or materialization | [Command reference](commands.md) |
10
+ | Stable errors, exit codes, retry safety, ambiguous outcomes, or local recovery | [Errors and recovery](errors.md) |
11
+ | Version policy, release preparation, publication, verification, rollback, or promotion | [Release policy and runbook](../RELEASING.md) |
12
+ | What was observed for an earlier tag, package, or dist-tag | [Release history](release-history.md) |
13
+ | Vulnerability reporting | [Security policy](../SECURITY.md) |
14
+
15
+ ## Authority boundaries
16
+
17
+ - [README.md](../README.md) owns public onboarding, the shortest supported journey, current trust claims, and routes.
18
+ - [commands.md](commands.md) owns detailed command semantics. Built-in `--help`, runtime source, and tests own exact
19
+ executable syntax and behavior.
20
+ - [errors.md](errors.md) owns handled-error interpretation and recovery guidance.
21
+ - [RELEASING.md](../RELEASING.md) owns living release policy and the operator runbook.
22
+ - [release-history.md](release-history.md) preserves dated release observations. Recheck live tags, package versions,
23
+ dist-tags, access, and trusted-publisher state before relying on them operationally.
24
+ - The source repository's `AGENTS.md` routes agent work; it should stay compact rather than duplicate these documents.
25
+
26
+ ## Retrieval quality
27
+
28
+ Start here, then load the one owning document for the task. Follow a cross-link only when the task crosses an
29
+ authority boundary, such as moving from successful command behavior to failure recovery. Prefer descriptive
30
+ headings, short paragraphs, command maps, and checklists; create another page only when it has a distinct audience,
31
+ task, or authority.
32
+
33
+ The documentation tests keep `AGENTS.md` at or below 2 KiB, the root README at or below 6 KiB, and this map at or
34
+ below 4 KiB. They also require every public topic to remain reachable from this map or the root README and verify
35
+ repository-local links and fragments. The package check separately verifies that every relative link in the
36
+ packaged Markdown resolves inside that exact package.
37
+
38
+ ## Work on the repository
39
+
40
+ Development uses Node.js 24.18.0 and npm 11.16.0, pinned in `.tool-versions`. From a fresh checkout:
41
+
42
+ ```sh
43
+ npm ci --ignore-scripts
44
+ npm audit
45
+ npm run check
46
+ ```
47
+
48
+ `npm run check` runs type checking, linting, formatting, tests, the exact package allowlist check, and a packed-package
49
+ smoke test. To inspect the package manifest without writing a tarball:
50
+
51
+ ```sh
52
+ npm pack --dry-run --json --ignore-scripts
53
+ ```
54
+
55
+ To reproduce the length-delimited SHA-256 used by external evidence to identify packaged JavaScript runtime inputs
56
+ (`package.json`, `bin/firstdraft.js`, and every `.js` file under `src/`), run:
57
+
58
+ ```sh
59
+ node scripts/runtime-digest.js
60
+ ```