@firstdraft.com/cli 0.2.0 → 0.2.2

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,84 +1,106 @@
1
1
  # First Draft CLI
2
2
 
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.
3
+ firstdraft is the command-line client shared by First Draft agents and automation. It manages local Foundation Plan
4
+ files, calls the versioned Service API, exposes reviewed analysis and GapSets, materializes verified Compilations,
5
+ and coordinates private GitHub publication.
6
6
 
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.
7
+ Trying First Draft as a tester? Start with the
8
+ [Drawing Board guide](https://github.com/firstdraft/drawing-board#build-an-app-with-first-draft), which installs a
9
+ compatible CLI and Skill together.
12
10
 
13
- ## Install
11
+ ## What this repository owns
14
12
 
15
- Running the CLI requires Node.js 22.0.0 or newer. Install the stable release selected by npm's `latest` dist-tag:
13
+ - local Plan initialization, UUIDs, application keys, and source hashing;
14
+ - conditional whole-document push and conflict reporting;
15
+ - analysis polling and complete GapSet output;
16
+ - direct Compile-and-materialize and private publish orchestration;
17
+ - retained Compilation inspection and artifact download;
18
+ - terminal output, exit status, and recovery contracts;
19
+ - the dependency-free npm package; and
20
+ - package provenance and release promotion.
16
21
 
17
- ```sh
18
- npm install --global @firstdraft.com/cli
19
- firstdraft --version
20
- ```
22
+ The Service owns Foundation Plan meaning and server-side lifecycle. Skills own the agent conversation. This
23
+ repository owns the exact command and transport behavior between them.
24
+
25
+ ## Start with the right document
26
+
27
+ | Task | Read first |
28
+ | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------- |
29
+ | Change the CLI | [Agent instructions](https://github.com/firstdraft/cli/blob/main/AGENTS.md), then [documentation map](docs/README.md) |
30
+ | Find a command or output contract | [Command reference](docs/commands.md) |
31
+ | Interpret an error or recover safely | [Errors and recovery](docs/errors.md) |
32
+ | Prepare or promote a package | [Release runbook](RELEASING.md) |
33
+ | Inspect dated package observations | [Release history](docs/release-history.md) |
34
+ | Report a vulnerability | [Security policy](SECURITY.md) |
21
35
 
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).
36
+ Run firstdraft --help or a command group's --help for concise terminal syntax.
26
37
 
27
- ## Shortest current journey
38
+ ## Repository layout
28
39
 
29
- From the project that the Foundation Plan describes:
40
+ | Path | Responsibility |
41
+ | -------- | ------------------------------------------------------------- |
42
+ | bin/ | Published executable entrypoint |
43
+ | src/ | Commands, API client, local Plan state, and output contracts |
44
+ | test/ | Command, protocol, recovery, and package tests |
45
+ | scripts/ | Test runner and package allowlist/smoke checks |
46
+ | docs/ | Command, error, release-history, and maintainer documentation |
47
+
48
+ ## Development
49
+
50
+ Development uses the Node.js and npm versions pinned in `.tool-versions`. Follow
51
+ [Work on the repository](docs/README.md#work-on-the-repository) for the complete install, audit, and check sequence.
30
52
 
31
53
  ```sh
32
- firstdraft plan init --name "Oscar Party"
54
+ npm run check
33
55
  ```
34
56
 
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:
57
+ The complete check runs type checking, ESLint, Prettier verification, tests, package allowlist validation, and a
58
+ smoke installation of the packed tarball. Use the narrower scripts while iterating:
37
59
 
38
60
  ```sh
39
- firstdraft generate uuid
61
+ npm run typecheck
62
+ npm run lint
63
+ npm test
64
+ npm run pack:check
65
+ npm run pack:smoke
40
66
  ```
41
67
 
42
- Provide an API token only through the environment, then submit, analyze, compile, and publish the exact current Plan:
68
+ To exercise the checkout directly:
43
69
 
44
70
  ```sh
45
- export FIRSTDRAFT_API_TOKEN="your-token"
46
- firstdraft plan compile
71
+ node bin/firstdraft.js --help
47
72
  ```
48
73
 
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.
54
-
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.
58
-
59
- ## Trust model
60
-
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.
68
- - CI exercises the exact minimum Node.js version separately from current development tooling.
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.
74
+ Remote commands read FIRSTDRAFT_API_TOKEN from the environment. See
75
+ [Push a Foundation Plan](docs/commands.md#push-a-foundation-plan) for FIRSTDRAFT_API_URL and origin pinning. Keep
76
+ tokens out of arguments, shell history, fixtures, snapshots, and logs.
77
+
78
+ ## Package contract
79
+
80
+ The published CLI supports Node.js 22 or newer. Direct automation callers can install the stable package with:
81
+
82
+ ```sh
83
+ npm install --global @firstdraft.com/cli
84
+ ```
85
+
86
+ Pin an exact compatible version when a repeatable installation matters; [RELEASING.md](RELEASING.md) owns channel
87
+ and promotion meaning.
88
+
89
+ The published package:
90
+
91
+ - installs the firstdraft executable;
92
+ - runs reviewed JavaScript source directly;
93
+ - has no runtime dependencies or install scripts;
94
+ - performs no telemetry, update check, or network request unless the caller invokes an API command;
95
+ - reads Bearer credentials only from the environment; and
96
+ - carries npm provenance linking registry bytes to its GitHub workflow and commit.
97
+
98
+ Inspect the packed file list whenever a source or documentation path moves. The public documentation graph,
99
+ including the release runbook and dated release history, ships with the package. `AGENTS.md` and the source-only
100
+ `release/compatibility.json` do not.
101
+
102
+ ## Release boundary
103
+
104
+ Merging source is not package publication. Publishing a candidate, moving npm dist-tags, coordinating the Skills
105
+ package, and promoting a stable release are distinct steps in [RELEASING.md](RELEASING.md). Verify the exact packed
106
+ digest and Service compatibility before any promotion.
package/docs/README.md CHANGED
@@ -3,18 +3,19 @@
3
3
  Use this page to find the narrowest authoritative document for a task. Runtime source and tests remain the final
4
4
  evidence for implemented behavior; if they contradict a document, surface the contradiction instead of guessing.
5
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) |
6
+ | If the task concerns... | Read first |
7
+ | -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
8
+ | Beginner tester journey | [Drawing Board guide](https://github.com/firstdraft/drawing-board#build-an-app-with-first-draft) |
9
+ | Direct CLI installation, repository orientation, or package contract | [Root README](../README.md) |
10
+ | Commands, options, environment variables, API behavior, output, or materialization | [Command reference](commands.md) |
11
+ | Stable errors, exit codes, retry safety, ambiguous outcomes, or local recovery | [Errors and recovery](errors.md) |
12
+ | Version policy, release preparation, publication, verification, rollback, or promotion | [Release policy and runbook](../RELEASING.md) |
13
+ | What was observed for an earlier tag, package, or dist-tag | [Release history](release-history.md) |
14
+ | Vulnerability reporting | [Security policy](../SECURITY.md) |
14
15
 
15
16
  ## Authority boundaries
16
17
 
17
- - [README.md](../README.md) owns public onboarding, the shortest supported journey, current trust claims, and routes.
18
+ - [README.md](../README.md) owns repository orientation, direct installation, package boundaries, and routes.
18
19
  - [commands.md](commands.md) owns detailed command semantics. Built-in `--help`, runtime source, and tests own exact
19
20
  executable syntax and behavior.
20
21
  - [errors.md](errors.md) owns handled-error interpretation and recovery guidance.
@@ -26,9 +27,7 @@ evidence for implemented behavior; if they contradict a document, surface the co
26
27
  ## Retrieval quality
27
28
 
28
29
  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.
30
+ authority boundary. Create another page only for a distinct audience, task, or authority.
32
31
 
33
32
  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
33
  below 4 KiB. They also require every public topic to remain reachable from this map or the root README and verify
package/docs/commands.md CHANGED
@@ -4,10 +4,10 @@ This page owns the detailed public semantics of the current command surface. Run
4
4
  group's `--help` for concise executable syntax. See [Errors and recovery](errors.md) before retrying a failed mutation.
5
5
 
6
6
  The current `0.2.x` source line contains the auditable command shell, local Foundation Plan initialization, local
7
- application-key and UUID generation, conditional whole-document push, whole-graph analysis status polling,
8
- compile-and-publish orchestration, and read-only retained-Compilation download. CLI `0.2.x` requires the service's
9
- `0.3.x` API contract. See the [release policy](../RELEASING.md) for versioning and channel semantics and
10
- [release history](release-history.md) for the transition from prereleases.
7
+ application-key and UUID generation, conditional whole-document push, whole-graph analysis status polling, direct
8
+ Compile-and-materialize and private publish orchestration, and retained-Compilation inspection. CLI `0.2.x`
9
+ requires the service's `0.3.x` API contract. See the [release policy](../RELEASING.md) for versioning and channel
10
+ semantics and [release history](release-history.md) for the transition from prereleases.
11
11
 
12
12
  ## Command map
13
13
 
@@ -18,7 +18,7 @@ compile-and-publish orchestration, and read-only retained-Compilation download.
18
18
  | `firstdraft generate uuid` | No | Generate one or more Foundation Plan subject identities |
19
19
  | `firstdraft plan push` | Yes | Conditionally submit the exact whole Plan |
20
20
  | `firstdraft plan status` | Yes | Read or wait for the current whole-graph analysis |
21
- | `firstdraft plan compile` | Yes | Push, analyze, compile, and publish the current Plan |
21
+ | `firstdraft plan compile` | Yes | Push and analyze, then materialize or publish |
22
22
  | `firstdraft compilation status` | Yes | Inspect a retained Compilation by ID |
23
23
  | `firstdraft compilation download` | Yes | Verify and materialize a successful retained Compilation |
24
24
 
@@ -131,34 +131,149 @@ repeats only validated `processing` responses and stops on its first failed read
131
131
  a bounded number of times because the command sends only `GET` requests. See
132
132
  [read-only failures](errors.md#read-only-status-failures) if the problem persists.
133
133
 
134
- ## Compile and publish the current Plan
134
+ ## Compile the current Plan
135
135
 
136
- When the candidate is ready, run:
136
+ To compile into a local application directory, run:
137
137
 
138
138
  ```sh
139
- firstdraft plan compile
139
+ firstdraft plan compile --output ./application
140
140
  ```
141
141
 
142
- `plan compile` is the single terminal action. It first pushes the exact current bytes in
142
+ Both `plan compile` modes first push the exact current bytes in
143
143
  `.firstdraft/foundation-plan.json`, even when those bytes are unchanged, and saves the accepted ETag using the same
144
144
  contract as `plan push`. It then waits up to two minutes for an analysis whose graph version and
145
145
  `head_source_sha256` exactly match that accepted push, polling past a terminal result retained for an older Head.
146
146
  Invalid JSON, schema diagnostics, semantic diagnostics, a failed analysis, a superseded analysis, or a recurring
147
147
  diagnostic stop the command with structured output; no Compilation or Publication is requested.
148
148
 
149
- Only a `valid` analysis proceeds to the internal GitHub Publication lifecycle. Invoking `plan compile` is the
150
- authorization to request that lifecycle. Immediately before its conditional mutation, the CLI re-reads the local
151
- Plan and requires its exact bytes to match the accepted Head, so bytes changed after analysis cannot be published.
152
- It extracts the accepted source SHA-256 from the saved ETag, hashes the current local bytes, and sends that complete
153
- ETag in `If-Match`.
149
+ Only a `valid` analysis proceeds to the selected completion mode. Immediately before either conditional mutation,
150
+ the CLI re-reads the local Plan and requires its exact bytes and saved state to match the accepted Head. It extracts
151
+ the accepted source SHA-256 from the saved ETag, hashes the current local bytes, and sends that complete ETag in
152
+ `If-Match`.
153
+
154
+ ### Materialize a direct Compilation
155
+
156
+ With `--output`, the CLI accepts either an explicit absent destination beneath an existing real directory or a path
157
+ that resolves to the physical current directory. It validates either destination before pushing the Plan. An absent
158
+ destination is checked again after analysis; root adoption instead holds its owned lock and performs the exact
159
+ pre-move identity recheck described below. Other existing destinations remain invalid, so
160
+ `--output ./application` retains its absent-directory contract.
161
+
162
+ `--output .` is the noninteractive root-adoption mode. `./`, an absolute spelling of the current directory, and
163
+ another spelling that resolves to that same physical directory select the same mode. It works at any real current
164
+ directory that meets the preconditions below and does not recognize Drawing Board or another repository layout
165
+ specially. This first root-adoption contract supports POSIX filesystems; Windows retains absent-directory output
166
+ and refuses root adoption as `root_platform_unsupported`. Before starting Compilation, the CLI requires:
167
+
168
+ - the current directory to be a real, writable, non-filesystem-root directory;
169
+ - no existing top-level path whose portable, case-insensitive name is `design` or the reserved
170
+ `.firstdraft-root-output` transaction path;
171
+ - every top-level entry other than `.git` to be a regular file or real directory on the current directory's
172
+ filesystem. Interior symlinks, dependency trees, sockets, and nested repositories move opaquely with their
173
+ top-level directory; the CLI neither follows nor repairs them; and
174
+ - when the current directory is the root of a Git worktree, a clean tracked worktree and index with no unmerged
175
+ entries, sparse checkout, or in-progress merge, rebase, cherry-pick, or revert. Untracked and ignored design
176
+ material may remain present. Submodules and tracked `.gitmodules` files are refused in this first root-adoption
177
+ contract rather than moved with broken Git wiring. A directory nested inside a higher Git worktree is refused
178
+ rather than treated as non-Git. A valid top-level `.git` file for a linked worktree is retained like a `.git`
179
+ directory.
180
+
181
+ Git-backed root adoption invokes the installed Git executable explicitly. Read-only discovery uses
182
+ `git --no-optional-locks` with stable NUL-delimited porcelain so it does not refresh the index. Before remote work,
183
+ the CLI verifies in a temporary preview that every currently ignored entry remains ignored after its path and
184
+ applicable worktree `.gitignore` files move beneath `design`; repository-local and configured global exclusions are
185
+ both honored. A refusal is `invalid_output_path` with a machine-readable `reason` and happens before Plan push.
186
+
187
+ The CLI creates `.firstdraft-root-output` with exclusive creation during the pre-push output check and holds it
188
+ through analysis, Compilation, and materialization. That directory is both the single-writer lock and the owned
189
+ transaction journal, so a concurrent root adoption is refused before either command sends a request. Immediately
190
+ after acquiring it, the CLI captures every other top-level entry's exact name, entry type, device, and inode. After
191
+ staging the artifact and any replacement Git index, it rechecks that set immediately before moving anything. Size,
192
+ modification time, and contents are deliberately not part of this identity: interior changes are not recursively
193
+ inventoried, and a top-level directory moves intact at the transaction boundary. A replaced, added, or removed
194
+ top-level entry stops materialization. The reserved-path precondition ignores only the transaction directory
195
+ created and still held by this invocation.
196
+
197
+ `compilation download --output .` acquires the same lock before its first status request and holds it through
198
+ artifact download and materialization. Either command removes its own transaction directory on every ordinary exit
199
+ before the journal records an irreversible move or index installation. Its signal handlers do the same when Node
200
+ dispatches the signal before that boundary. A journal whose phase records no irreversible operation is likewise
201
+ safe to remove; the manual reconciliation rule below applies only after `root_rollback_incomplete`.
202
+
203
+ The complete generated artifact is written and verified inside that in-root transaction directory before any
204
+ existing path moves. Staging inside the destination makes every later rename same-filesystem even when the current
205
+ directory itself is a container mount point. The artifact may not own a top-level path whose portable,
206
+ case-insensitive name is `design` or `.firstdraft-root-output`; artifact validation already excludes `.git` at any
207
+ depth.
208
+
209
+ The transaction creates `./design` with mode `0755` on POSIX, moves every preexisting non-Git top-level entry under
210
+ it, keeps an existing top-level `.git` file or directory at the root, and installs the artifact's top-level entries
211
+ at the root. Immediately before each artifact entry is installed, its root destination must still be absent; an
212
+ unexpected entry stops the transaction and is never overwritten. If the root contains no entry other than `.git`,
213
+ it does not retain an empty `design` directory. A
214
+ nested mount that cannot travel with its top-level directory may make its rename fail; that is a transactional
215
+ failure, not permission to copy or traverse the mount.
216
+
217
+ For a Git root, the CLI first prepares a replacement index that stages each formerly tracked path at
218
+ `design/<old-path>` and stages every exact generated artifact path at the root. This handles overlapping names such
219
+ as `README.md` and `.gitignore` without leaving the old design blob indexed at a generated path. Previously
220
+ untracked and ignored paths are never added to the index. Preparing that index writes the generated blobs into the
221
+ Git object database; a rollback may therefore leave unreachable blobs for ordinary Git garbage collection, while
222
+ `HEAD`, refs, configuration, and history remain unchanged. After the worktree renames finish, the CLI installs the
223
+ prepared index through Git's actual index lock path and atomic lock-file commit protocol, including in a linked
224
+ worktree whose index is outside the adopted root. The transaction journal retains whether an index existed plus an
225
+ exact private copy, mode, and digest of its prior bytes until final verification succeeds. The preflighted ignore
226
+ protection is rechecked after the move. The caller should inspect and commit this staged root-adoption change before
227
+ using destructive worktree or index restoration commands. A non-Git root remains non-Git and is not initialized.
228
+
229
+ The journal is a versioned private JSON record plus owned staging files. It records the physical root and original
230
+ top-level identity set, the transaction phase, completed design and artifact renames, and, for Git, the resolved
231
+ index path and original and prepared index digests. Each irreversible phase is recorded before the next one starts.
232
+ On any failure after a move, index installation, or post-install verification, the CLI first restores the exact
233
+ prior index through the same Git lock boundary, then reverses artifact and design renames in journal order. A fully
234
+ successful rollback removes only the owned transaction. If rollback itself cannot finish,
235
+ `materialization_failed` reports `reason: "root_rollback_incomplete"` and includes
236
+ `recovery_path: ".firstdraft-root-output"`; it leaves the journal and owned copies in place rather than guessing.
237
+ Do not delete that directory or run Git restoration commands. Inspect the versioned journal, restore the listed
238
+ index and paths to its recorded original identities, verify that snapshot, and only then remove the transaction
239
+ directory. Another root adoption reports `root_busy` until that state is reconciled; a foreign preexisting directory
240
+ with the same reserved name reports `root_reserved_path`.
241
+
242
+ After valid analysis, the CLI requests one Compilation for that exact reviewed Head and never starts GitHub
243
+ Publication. It validates that the `202` response identifies the same Project, graph version, Head, Analysis,
244
+ Compiler release, and target; polls only that retained Compilation for up to ten minutes; downloads its exact
245
+ artifact; and applies the same integrity and atomic materialization contract as `compilation download`. An ambiguous
246
+ Compilation start is not retried automatically. After a validated `202`, later status, artifact, authentication,
247
+ and materialization failures retain the last validated Compilation projection so the caller can recover by ID
248
+ without starting duplicate work. Follow the [direct Compilation recovery procedure](errors.md#direct-compilation-recovery).
249
+
250
+ Success writes one JSON object to stdout containing the validated Project, Compilation, and absolute output path.
251
+ Root adoption additionally reports `root_adoption.design_path` (or `null` when no design directory was needed), its
252
+ top-level moved-entry count, whether a Git repository was preserved, and whether its index was replaced.
253
+ After final verification succeeds, the CLI removes its owned `.firstdraft-root-output` transaction directory.
254
+ An absent output directory contains exactly the artifact files and modes. Root adoption additionally contains the
255
+ preserved `design` directory and an existing root `.git`, when present; every artifact-owned path remains exact. The
256
+ CLI does not add a Git repository, run a formatter, or repair generated source. When an absent output is nested
257
+ inside another Git worktree, initialize the application as its own repository before running generated checks that
258
+ inspect Git; otherwise Git resolves to the parent worktree. Progress on stderr reports analysis and Compilation
259
+ only.
260
+
261
+ ### Publish through GitHub
262
+
263
+ Without `--output`, the existing GitHub Publication journey remains unchanged:
154
264
 
155
- The command writes stable human-readable progress to stderr, with every line prefixed by `First Draft:`. It reports
156
- analysis, compilation completion or terminal failure or cancellation, the current GitHub phase, and an allowlisted
157
- reason, retry count, and exact UTC retry time when a GitHub preflight check is delayed. A retained retry with no next
158
- time is reported as paused and requiring operator recovery. Progress never includes IDs, hashes, repository names or
159
- URLs, raw server projections, local paths, or environment values. Success writes exactly the validated private
160
- GitHub repository URL plus a newline to stdout. If the command fails after progress has begun, its structured JSON
161
- error envelope is the final stderr document after the progress lines.
265
+ ```sh
266
+ firstdraft plan compile
267
+ ```
268
+
269
+ Invoking this form authorizes the internal GitHub Publication lifecycle. The command writes stable human-readable
270
+ progress to stderr, with every line prefixed by `First Draft:`. It reports analysis, Compilation completion or
271
+ terminal failure or cancellation, the current GitHub phase, and an allowlisted reason, retry count, and exact UTC
272
+ retry time when a GitHub preflight check is delayed. A retained retry with no next time is reported as paused and
273
+ requiring operator recovery. Progress never includes IDs, hashes, repository names or URLs, raw server projections,
274
+ local paths, or environment values. Success writes exactly the validated private GitHub repository URL plus a
275
+ newline to stdout. If the command fails after progress has begun, its structured JSON error envelope is the final
276
+ stderr document after the progress lines.
162
277
 
163
278
  The closed API `0.3.x` progress-reason allowlist is `github.configuration_missing`, `github.oauth_unavailable`,
164
279
  `github.api_unavailable`, `github.reauthorization_required`, `github.account_mismatch`,
@@ -177,14 +292,14 @@ identity, and repository identity. Do not run concurrent Compile commands; use t
177
292
  [publication recovery procedure](errors.md#publication-recovery) after an invocation exits.
178
293
 
179
294
  This release cannot repoint a Project's Publication to a later accepted Head. The public CLI therefore has no
180
- `plan publish` command and no local-start `plan compile --output` mode. It retains lower-level Compilation commands
181
- for operational callers that acquire an ID separately, but they are intentionally not a continuation of the
182
- URL-only `plan compile` journey.
295
+ `plan publish` command. Direct local Compilation and GitHub Publication are separate completion modes after the same
296
+ exact Plan push and valid Analysis.
183
297
 
184
298
  ## Inspect a retained Compilation
185
299
 
186
300
  These lower-level commands are for callers that already hold a retained Compilation ID from authenticated API
187
- metadata or operational tooling; `plan compile` prints only the final repository URL:
301
+ metadata or operational tooling. The no-output `plan compile` form prints only the final repository URL, while
302
+ `plan compile --output` waits for and downloads its own direct Compilation:
188
303
 
189
304
  ```sh
190
305
  firstdraft compilation status 01900000-0000-7000-8000-000000000001
@@ -204,6 +319,16 @@ Materialize an already successful Compilation into an absent path:
204
319
  firstdraft compilation download 01900000-0000-7000-8000-000000000001 --output ../movie-catalog
205
320
  ```
206
321
 
322
+ The same command accepts `--output .` and applies the root-adoption transaction above. This is the recovery path
323
+ when a retained direct Compilation succeeded but an earlier root materialization failed _and fully rolled back_; it
324
+ never starts replacement work. An incomplete rollback leaves `.firstdraft-root-output` and requires journal
325
+ reconciliation before this command can run again.
326
+
327
+ Successful root adoption is intentionally one-way. The original `.firstdraft` authoring state moves under
328
+ `design/.firstdraft`; run later Plan commands from `design`, not from the generated application root. Compiling a
329
+ later Plan revision does not overwrite an already adopted root: choose a new absent output and deliberately
330
+ reconcile it with application work.
331
+
207
332
  The command validates the UUID and output path before network access, makes one status `GET`, requires `succeeded`,
208
333
  and makes one artifact `GET`. It never starts work or polls. Historical artifact validation uses the retained
209
334
  `compilation.head_source_sha256`, not the current local Plan or ETag, to pin the artifact's exact
package/docs/errors.md CHANGED
@@ -16,12 +16,15 @@ remain human-readable text on standard error with exit 2. Unexpected programming
16
16
 
17
17
  ## Ambiguous mutations
18
18
 
19
- `plan compile` supplies `phase: "push" | "publication"` when `request_outcome_unknown` requires phase-specific
20
- recovery:
19
+ `plan compile` supplies `phase: "push" | "compilation" | "publication"` when `request_outcome_unknown` requires
20
+ phase-specific recovery:
21
21
 
22
22
  - `phase: "push"` means the Plan mutation may have been accepted. Stop and reconcile local Head state. Until First
23
23
  Draft has a Foundation Plan Head reconciliation endpoint, an accepted request whose response cannot be verified
24
24
  may require manual recovery. Do not construct an ETag from the Plan digest or trust an unverified response.
25
+ - `phase: "compilation"` means a direct `--output` Compilation may have started, but its retained identity is unknown.
26
+ The CLI never repeats that `POST`. Do not start another Compilation until the Project is reconciled through First
27
+ Draft or an operator can identify the retained work.
25
28
  - `phase: "publication"` means the singleton Publication mutation was not resolved. Do not run concurrent Compile
26
29
  commands. After the prior invocation exits, wait and rerun `plan compile` with unchanged Plan bytes to safely
27
30
  reconcile or resume the retained singleton.
@@ -39,9 +42,45 @@ A network failure from `plan status` is safe to retry a bounded number of times
39
42
  `invalid_server_response` instead means the response violated the CLI/server contract; retrying the unchanged read
40
43
  will not repair it.
41
44
 
42
- The lower-level `compilation status` command is also read-only. `compilation_status_unavailable` is safe to retry;
45
+ Only the lower-level `compilation status <compilation-id>` command is read-only. Its
46
+ `compilation_status_unavailable` result is safe to retry a bounded number of times;
43
47
  `invalid_compilation_status` requires contract reconciliation. A wait stops rather than following a changed
44
- analysis or Compilation identity.
48
+ analysis or Compilation identity. This read-only retry guidance does not apply to `plan compile --output`, which
49
+ starts a new Compilation after analysis.
50
+
51
+ ## Direct Compilation recovery
52
+
53
+ Do not blindly rerun `plan compile --output` after its Compilation start was accepted or may have been accepted.
54
+ That command creates new work; it is not a retained-Compilation reconciliation command.
55
+
56
+ If `request_outcome_unknown` reports `phase: "compilation"`, the start request did not yield a validated retained
57
+ ID. The CLI sent exactly one `POST` and did not retry it. Stop until First Draft or an operator can reconcile the
58
+ Project and identify whether work was retained.
59
+
60
+ Once the start response has yielded a validated retained Compilation, later status, artifact, authentication, and
61
+ materialization failure envelopes include that last validated projection as `current`. Preserve
62
+ `current.compilation.id` and recover without creating duplicate work:
63
+
64
+ - after `compilation_status_unavailable`, use
65
+ `firstdraft compilation status <current.compilation.id>`; this lower-level read is safe to retry boundedly;
66
+ - after `invalid_compilation_status` or `invalid_artifact`, preserve the retained ID and reconcile the CLI/Service
67
+ contract instead of retrying the unchanged invalid read;
68
+ - after `artifact_unavailable`, wait if appropriate and use
69
+ `firstdraft compilation download <current.compilation.id> --output <new-absent-path>`; and
70
+ - after `materialization_failed`, repair the destination condition, then use the same lower-level download command
71
+ with a new absent path. A root-output attempt whose transaction fully rolled back may instead retry that retained
72
+ download with `--output .`; `reason: "root_rollback_incomplete"` requires reconciliation of the retained
73
+ `.firstdraft-root-output` journal before another root attempt. Only that reason requires manual reconciliation:
74
+ do not delete its journal or run Git restoration commands; read its versioned record, restore the exact listed
75
+ index and path identities, verify its original snapshot, and then remove the transaction directory. A journal
76
+ whose phase records no irreversible operation is safe to remove. After `.firstdraft` has moved successfully under
77
+ `design`, run retained status and later Plan commands from `design`, not from the generated application root.
78
+
79
+ After `compilation_wait_timed_out`, retained work may still continue. Use
80
+ `firstdraft compilation status <current.compilation.id>` for one read-only status check; do not rerun
81
+ `plan compile --output`. `compilation_failed`, `compilation_cancelled`, and `compilation_changed` already carry the
82
+ validated `current` projection appropriate to their stopping boundary. Authentication recovery may refresh the
83
+ credential, but it must continue from the retained ID rather than starting another Compilation.
45
84
 
46
85
  ## Publication recovery
47
86
 
@@ -60,28 +99,38 @@ stopped without following the replacement.
60
99
 
61
100
  ## Error index
62
101
 
63
- | Commands | `error` | Exit | Meaning |
64
- | -------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---: | -------------------------------------------------------------------------------------------------------------- |
65
- | Any leaf command | `invalid_arguments` | 2 | Syntax was invalid; no request was made. |
66
- | `plan init` | `local_initialization_failed` | 1 | Initialization failed without overwriting an existing path. |
67
- | `plan push`, `plan compile` | `invalid_configuration` | 2 | API origin or saved Head state is incompatible. |
68
- | Network commands | `authentication_required` | 1 | The token is missing or First Draft returned a validated authentication problem. |
69
- | Plan commands, `compilation *` | `local_input_unreadable` | 1 | Required local Plan or private state could not be read. |
70
- | Status, Compile, Compilation commands | `project_not_pushed` | 1 | No API origin is pinned for the local Project. |
71
- | `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. |
72
- | `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`. |
73
- | `plan push`, `plan compile` | `server_rejected` | 1 | First Draft returned validated Plan diagnostics or rejected the request with a validated problem. |
74
- | `plan status` | `server_rejected` | 1 | First Draft rejected the analysis status request with a validated non-authentication problem. |
75
- | `plan status` | `status_unavailable`, `invalid_server_response` | 1 | The analysis read failed or violated its protocol. |
76
- | `plan compile` | `analysis_status_unavailable`, `invalid_analysis_status`, `analysis_status_rejected` | 1 | The bounded analysis read failed, was invalid, or was rejected. |
77
- | Analysis waits | `analysis_changed`, `wait_timed_out`, `analysis_wait_timed_out` | 1 | The pinned analysis changed or remained processing at the deadline. |
78
- | `plan compile` | `plan_not_valid` | 1 | Analysis completed without `valid`; `current` contains diagnostics and status. |
79
- | `plan compile` | `local_plan_changed` | 1 | Local bytes changed after acceptance or analysis, before Publication mutation. |
80
- | `plan compile` | `publication_start_rejected`, `publication_status_unavailable`, `invalid_publication_status` | 1 | Publication start or status failed its validated transport contract. |
81
- | `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. |
82
- | `compilation status`, `compilation download` | `compilation_status_unavailable`, `invalid_compilation_status` | 1 | The retained status could not be read or violated its exact contract. |
83
- | `compilation status --wait` | `compilation_changed`, `compilation_wait_timed_out` | 1 | Retained identity/provenance changed or the wait ended. |
84
- | `compilation download` | `compilation_not_succeeded` | 1 | Status was not `succeeded`; no artifact request was made. |
85
- | `compilation download` | `artifact_unavailable`, `invalid_artifact` | 1 | Artifact transport or integrity validation failed before materialization. |
86
- | `compilation download` | `invalid_output_path` | 2 | The destination was not an absent path beneath an existing real directory. |
87
- | `compilation download` | `materialization_failed` | 1 | The output raced or the verified tree could not be atomically installed. |
102
+ | Commands | `error` | Exit | Meaning |
103
+ | -------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---: | ------------------------------------------------------------------------------------------------------ |
104
+ | Any leaf command | `invalid_arguments` | 2 | Syntax was invalid; no request was made. |
105
+ | `plan init` | `local_initialization_failed` | 1 | Initialization failed without overwriting an existing path. |
106
+ | `plan push`, `plan compile` | `invalid_configuration` | 2 | API origin or saved Head state is incompatible. |
107
+ | Network commands | `authentication_required` | 1 | The token is missing or First Draft returned a validated authentication problem. |
108
+ | Plan commands, `compilation *` | `local_input_unreadable` | 1 | Required local Plan or private state could not be read. |
109
+ | Status, Compile, Compilation commands | `project_not_pushed` | 1 | No API origin is pinned for the local Project. |
110
+ | `plan push`, `plan compile` | `request_outcome_unknown` | 1 | A mutation or its response could not be verified; `plan compile` identifies its mutation phase. |
111
+ | `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`. |
112
+ | `plan push`, `plan compile` | `server_rejected` | 1 | First Draft returned validated Plan diagnostics or rejected the request with a validated problem. |
113
+ | `plan status` | `server_rejected` | 1 | First Draft rejected the analysis status request with a validated non-authentication problem. |
114
+ | `plan status` | `status_unavailable`, `invalid_server_response` | 1 | The analysis read failed or violated its protocol. |
115
+ | `plan compile` | `analysis_status_unavailable`, `invalid_analysis_status`, `analysis_status_rejected` | 1 | The bounded analysis read failed, was invalid, or was rejected. |
116
+ | Analysis waits | `analysis_changed`, `wait_timed_out`, `analysis_wait_timed_out` | 1 | The pinned analysis changed or remained processing at the deadline. |
117
+ | `plan compile` | `plan_not_valid` | 1 | Analysis completed without `valid`; `current` contains diagnostics and status. |
118
+ | `plan compile` | `local_plan_changed` | 1 | Local bytes or saved state changed after acceptance, before the selected mutation. |
119
+ | `plan compile --output` | `compilation_start_rejected`, `compilation_status_unavailable`, `invalid_compilation_status` | 1 | Direct start was rejected or retained status failed; post-start errors include `current`. |
120
+ | `plan compile --output` | `compilation_changed`, `compilation_wait_timed_out`, `compilation_failed`, `compilation_cancelled` | 1 | The pinned direct Compilation changed, timed out, failed, or was cancelled. |
121
+ | `plan compile` | `publication_start_rejected`, `publication_status_unavailable`, `invalid_publication_status` | 1 | Publication start or status failed its validated transport contract. |
122
+ | `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. |
123
+ | `compilation status`, `compilation download` | `compilation_status_unavailable`, `invalid_compilation_status` | 1 | The retained status could not be read or violated its exact contract. |
124
+ | `compilation status --wait` | `compilation_changed`, `compilation_wait_timed_out` | 1 | Retained identity/provenance changed or the wait ended. |
125
+ | `compilation download` | `compilation_not_succeeded` | 1 | Status was not `succeeded`; no artifact request was made. |
126
+ | Download commands | `artifact_unavailable`, `invalid_artifact` | 1 | Artifact transport or integrity validation failed; direct Compile post-start errors include `current`. |
127
+ | Download commands | `invalid_output_path` | 2 | The absent destination or root-adoption preconditions failed; `reason` identifies the stable refusal. |
128
+ | Download commands | `materialization_failed` | 1 | The output changed or its transaction failed; `reason` identifies incomplete rollback when applicable. |
129
+
130
+ Root-output `invalid_output_path.reason` values are `destination_exists`, `root_not_real`, `root_not_writable`,
131
+ `root_platform_unsupported`, `root_reserved_path`, `root_entry_unsupported`, `root_enclosing_worktree`,
132
+ `root_git_unavailable`, `root_git_unsupported`, `root_git_dirty`, `root_ignore_not_preserved`, and `root_busy`. Git
133
+ refusing discovery, including a `safe.directory` refusal, is `root_git_unavailable`; a discovered but unsupported
134
+ Git shape such as a submodule is `root_git_unsupported`. Root-output `materialization_failed.reason` values are
135
+ `output_changed`, `root_artifact_collision`, `root_ignore_changed`, `root_transaction_failed`, and
136
+ `root_rollback_incomplete`.