@firstdraft.com/cli 0.9.0 → 0.11.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/docs/commands.md CHANGED
@@ -3,28 +3,89 @@
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.9.x` source line contains the auditable command shell, browser and device login, local Foundation Plan initialization, local
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 and cancellation.
9
- CLI `0.9.x` requires the service's `0.8.x` API contract. The
10
- [changelog](https://github.com/firstdraft/cli/blob/main/CHANGELOG.md) describes each version.
6
+ The current `0.11.x` source line contains the auditable command shell, the agent's `start` check, browser and device
7
+ login in one command or in two steps that an agent runs, local Foundation Plan
8
+ initialization, hosted Project creation and Sketch review, local application-key and UUID generation, conditional whole-document push, whole-graph analysis
9
+ status polling, direct Compile-and-materialize, retained-Compilation inspection and
10
+ cancellation, the account's report setting, progress and failure reports, notes, and maintenance-item listing,
11
+ inspection, resolution, deferral, and owner questions. It requires API contract `0.9.1` or a later patch on the same minor line. The [changelog](https://github.com/firstdraft/cli/blob/main/CHANGELOG.md) describes each version.
12
+ [What the CLI sends](#what-the-cli-sends) lists every request and what it carries.
11
13
 
12
14
  ## Command map
13
15
 
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 |
27
- | `firstdraft compilation cancel` | Yes | Cancel a queued or running Compilation by ID |
16
+ | Command | Network | Purpose |
17
+ | ------------------------------------- | ------- | ------------------------------------------------------------------------- |
18
+ | `firstdraft start` | Yes | Check versions, login, and reports before other work |
19
+ | `firstdraft project start` | Yes | Create or reopen the owner’s Project before a Plan |
20
+ | `firstdraft sketches publish` | Yes | Capture the selected local screens and publish them with the working Plan |
21
+ | `firstdraft plan init` | No | Create an empty local Foundation Plan and Project identity |
22
+ | `firstdraft generate application-key` | No | Preview deterministic name-to-key derivation |
23
+ | `firstdraft generate uuid` | No | Generate one or more Foundation Plan subject identities |
24
+ | `firstdraft login` | Yes | Approve the CLI in a browser and save a token for an origin |
25
+ | `firstdraft login --no-wait` | Yes | Start a device login for an agent and exit |
26
+ | `firstdraft login --finish` | Yes | Finish that device login once the person approved |
27
+ | `firstdraft logout` | Yes | Revoke and remove the saved token for an origin |
28
+ | `firstdraft plan push` | Yes | Conditionally submit the exact whole Plan |
29
+ | `firstdraft plan status` | Yes | Read or wait for the current whole-graph analysis |
30
+ | `firstdraft plan compile` | Yes | Compile the Plan or approved review into the current folder |
31
+ | `firstdraft compilation status` | Yes | Inspect a retained Compilation by ID |
32
+ | `firstdraft compilation download` | Yes | Verify and materialize a successful retained Compilation |
33
+ | `firstdraft compilation cancel` | Yes | Cancel a queued or running Compilation by ID |
34
+ | `firstdraft account` | Yes | Show whether the account sends reports |
35
+ | `firstdraft report progress` | Yes | Print, then send, how far a generated application has come |
36
+ | `firstdraft report failure` | Yes | Print, then send, an unexpected failure in generated code |
37
+ | `firstdraft note unstated_request` | Yes | Print, then send, a request the Plan could not state |
38
+ | `firstdraft note unclear_guidance` | Yes | Print, then send, a Skill page or diagnostic that was unclear |
39
+ | `firstdraft note wrong_output` | Yes | Print, then send, analysis or generated code that was wrong |
40
+ | `firstdraft maintain` | Yes | List a deployed Environment's open items |
41
+ | `firstdraft maintain show` | Yes | Read one item with its evidence |
42
+ | `firstdraft maintain resolve` | Yes | Resolve one item with a reason |
43
+ | `firstdraft maintain defer` | Yes | Set one item aside until a time |
44
+ | `firstdraft maintain ask-owner` | Yes | Record a question for the owner about one item |
45
+
46
+ ## Hosted Sketches
47
+
48
+ After the readiness check, run `firstdraft project start` in the app's planning folder. Give the owner the returned
49
+ Project URL. Its private local UUID and origin are written before the request, so another start opens the same
50
+ Project after a lost response. Run `firstdraft plan init --name "Awards Pool"` there to initialize the reserved
51
+ Project's Plan. A Project opened this way requires a published and approved Sketch revision for Compile. To start a
52
+ Plan-only interview, begin with `plan init` in a fresh folder.
53
+
54
+ Write the ordered screen list to `sketches/board.json`. Paths are relative to `sketches/`. For example:
55
+
56
+ ```json
57
+ {
58
+ "assets": ["theme.css"],
59
+ "screens": [
60
+ {
61
+ "id": "guest-ballot",
62
+ "name": "Guest ballot",
63
+ "source": "guest-ballot.html",
64
+ "sample_keys": [],
65
+ "plan_subjects": []
66
+ }
67
+ ]
68
+ }
69
+ ```
70
+
71
+ List the Plan development-record UUIDs shown on a screen in `sample_keys` and related Plan subject UUIDs in
72
+ `plan_subjects`. Both lists default to empty. Use `data-plan-pointer` with an RFC 6901 JSON Pointer to put a scalar value from the exact
73
+ working Plan into an element's text during capture. Keep readable fallback text for directly opening the HTML.
74
+ Mark selectable elements with stable `data-sketch-key` values and name them using visible text, `aria-label` or
75
+ `data-sketch-label`. Keys of 1–80 ASCII letters, digits, underscores and hyphens must start with a letter or digit. Keep them stable across layout and copy changes.
76
+
77
+ Run `firstdraft sketches publish` with Google Chrome installed (or set `FIRSTDRAFT_CHROME_PATH` to its executable).
78
+ The CLI serves the declared local assets to a private browser context, captures each screen at 1280 × 800 and
79
+ 390 × 844 CSS pixels, and sends the exact Plan text with PNGs, thumbnails, element labels and bounds. Use suitable
80
+ examples in the Plan and screens before publishing. Captures support up to 32 screens, 8192 pixels of scroll height
81
+ per viewport, and 24 MiB for the request. Capture loads offscreen images, settles CSS animations and clips selectable elements to their visible area. Browser policy violations or undeclared assets stop capture. Supply eligible local assets in the manifest and use static markup for any scripted rendering. The capture context uses a light color scheme, en-US locale and UTC. Editable HTML, CSS, fonts and images stay local. If Chrome or hosting
82
+ is unavailable, open the local HTML screens to continue the conversation.
83
+
84
+ Record the returned review ID with the owner's feedback. After separate Compile approval, run
85
+ `firstdraft plan compile --revision <approved-id>`, optionally with `--output <absent-directory>`. The CLI
86
+ checks the exact local Plan and every selected source before starting. The service checks the requested revision
87
+ and Plan ETag together. Find the editable sources under `.firstdraft/design/sketches/` in either output. A retained download of a sketch-linked Compilation uses its per-revision local receipt and requires restoration of that revision’s Plan and source files. Complete
88
+ the Rails integration and exercise the selected flows as part of the app's own implementation.
28
89
 
29
90
  ## Select an environment and authenticate
30
91
 
@@ -63,12 +124,71 @@ firstdraft login --interactive # also -i or --device
63
124
 
64
125
  The CLI prints a verification URL, a short user code, and a URL that already includes the code. Open either URL on
65
126
  any device, confirm the code, and approve. The CLI polls at the server's interval, adds five seconds when asked to
66
- slow down, and stops when the code expires.
127
+ slow down, and stops when the code expires. An agent cannot hold that wait open, so it runs the same flow in
128
+ [two steps](#log-in-from-an-agent).
129
+
130
+ Neither flow sends this computer's hostname. Their requests carry `FirstDraft-Client` like every other request
131
+ ([What the CLI sends](#what-the-cli-sends)). A denied approval exits with `authorization_denied`. A login that is not approved in time exits with
132
+ `authorization_expired`. A First Draft limit ends it with `rate_limited`. A required update or an unsupported API
133
+ contract replaces its result with `update_required` or `api_contract_unsupported` only when it stops a request the
134
+ login still had to send, as [update line and refusals](#update-line-and-refusals) describes. Other failures exit with
135
+ `login_failed`. No credential is saved unless the login succeeds. See
136
+ [Errors and recovery](errors.md#login-and-logout-errors).
137
+
138
+ ### Log in from an agent
139
+
140
+ The agent may start the login. It runs the device flow as two short commands, which
141
+ [`firstdraft start`](#check-readiness-before-work) names, and shows the person the link and the code:
142
+
143
+ ```sh
144
+ firstdraft login --no-wait
145
+ firstdraft login --finish
146
+ ```
147
+
148
+ `--no-wait` asks First Draft for a device grant, saves it, prints these lines on standard output, and exits 0:
67
149
 
68
- Both flows send this machine's hostname as the device name shown on the approval page and in the token's name on
69
- `/api-tokens`. A denied approval exits with `authorization_denied`. A login that is not approved in time exits with
70
- `authorization_expired`. Other failures exit with `login_failed`. No credential is saved unless the login succeeds.
71
- See [Errors and recovery](errors.md#login-and-logout-errors).
150
+ ```text
151
+ To log in to <origin>, ask the person to open this link in a browser, check that the page shows the code <code>, and approve:
152
+ <link that includes the code>
153
+ The link and the code expire in <n> minutes, at <UTC time>.
154
+ When the person says they approved, run 'firstdraft login --finish'.
155
+ ```
156
+
157
+ When First Draft sends no link that includes the code, the first line asks the person to enter the code instead, and
158
+ the second is the plain verification link. On staging, each command the CLI prints for the agent ends in `--staging`.
159
+ The person approves on that page, where First Draft also asks the reports question until it has an answer.
160
+
161
+ The device code is a credential, so the CLI never prints it; only the link and the user code appear. `--no-wait` saves
162
+ the waiting login, device code included, as `device-login.json` beside `credentials.json`, with mode `0600`; the
163
+ directory is created with mode `0700` when it does not exist. The file holds one waiting login, and another `--no-wait` replaces it. As with `login`, an unusable
164
+ credentials file stops it before any request.
165
+
166
+ `--finish` reads that file for the selected origin and polls First Draft at the grant's interval for at most 15
167
+ seconds from its start, each request included. It waits first when the previous poll was less than an interval ago, and a `slow_down` answer lengthens the
168
+ interval by five seconds; the file keeps both for the next `--finish`. It then says on standard output which of these
169
+ happened, and every outcome but the first also ends with its handled error on standard error:
170
+
171
+ - **Logged in** (exit 0): it removes the file, saves the token as `login` does, and prints
172
+ `Logged in: this computer is now logged in to <origin>.` and `Run 'firstdraft start' again.` If the file cannot be
173
+ removed, a note on standard error names it; it then holds only a spent device code.
174
+ - **Still waiting** (`authorization_pending`): `Still waiting: First Draft has not confirmed that the person approved the login.`, the link
175
+ lines again, and
176
+ `The link and the code expire at <UTC time>. When the person says they approved, run 'firstdraft login --finish' again.`
177
+ The file stays.
178
+ - **Expired** (`authorization_expired`):
179
+ `Expired: the link and the code expired before this computer finished the login, so no new login was saved for <origin>.`
180
+ and `To try again, run 'firstdraft login --no-wait'.`
181
+ - **Refused** (`authorization_denied`):
182
+ `Refused: the person denied this login, so no new login was saved for <origin>.` and
183
+ `Ask the person before you start another login with 'firstdraft login --no-wait'.`
184
+ - **No waiting login** (`login_not_started`), when none was started for this origin or it already ended:
185
+ `No login is waiting: this computer has no device login for <origin> that has not ended.` and
186
+ `Run 'firstdraft start' to see whether this computer is logged in.`
187
+
188
+ An expired, refused, or spent grant (`invalid_grant`) removes the file. A network failure or server error keeps it, so
189
+ `--finish` can run again. `--no-wait` and `--finish` select the origin as `login` does, may be given with
190
+ `--interactive` or `--device`, and cannot be given together. `firstdraft login --interactive` still waits in one
191
+ process for a person in their own terminal.
72
192
 
73
193
  ### Saved credentials
74
194
 
@@ -97,7 +217,7 @@ Tokens from the environment still work and take precedence over a saved login. C
97
217
  [First Draft](https://firstdraft.com/api-tokens) and provide it through `FIRSTDRAFT_API_TOKEN`. For staging, create a
98
218
  separate token at [First Draft staging](https://staging.firstdraft.com/api-tokens) and provide it through
99
219
  `FIRSTDRAFT_STAGING_API_TOKEN`. Keep token values out of shell history and command arguments. `login` and `logout`
100
- note on standard error when an environment token will override the saved login.
220
+ note on standard error when an environment token will override the saved login, and `start` says so among its lines.
101
221
 
102
222
  ### Origins and projects
103
223
 
@@ -131,6 +251,150 @@ print it, or require it for local commands. Revoke a token in the environment th
131
251
  missing token, or First Draft's validated `401` problem response with the `authentication_required` code, produces
132
252
  that stable CLI error.
133
253
 
254
+ ## What the CLI sends
255
+
256
+ The CLI sends nothing on its own: no telemetry, no background request, and no separate update check. A command sends
257
+ only its own requests, listed under [Service endpoints](#service-endpoints); `plan init`, `generate`, and `--help`
258
+ make none. Each request carries the selected token (except the OAuth requests of `login` and `logout`) and this
259
+ header:
260
+
261
+ ```text
262
+ FirstDraft-Client: cli/<version>; plugin/<version>; agent/<name>; os/<platform>
263
+ ```
264
+
265
+ `cli` is this package's version. `plugin` and `agent` come from `FIRSTDRAFT_PLUGIN_VERSION` and `FIRSTDRAFT_AGENT`,
266
+ which the First Draft plugin's launcher sets to its own version and to the agent's name, such as `claude-code` or
267
+ `codex`. `os` is Node.js's `process.platform`, such as `darwin`, `linux`, or `win32`. A part that is unset, or is not a
268
+ plain version or name, is left out. The header carries no hostname, user name, path, or token. A setup that runs the
269
+ CLI without the plugin's launcher, such as a direct npm installation, may set the two variables itself.
270
+
271
+ Beyond the header, a command sends only what it needs:
272
+
273
+ | Commands | Request content |
274
+ | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
275
+ | `login`, `logout` | OAuth parameters; `logout` sends the saved token to revoke it |
276
+ | `start` | An account read, and nothing without a token |
277
+ | `project start` | The reserved Project ID in the request path |
278
+ | `sketches publish` | Project and revision IDs, previous revision and Head preconditions, exact Plan text and digest, screen names and order, source fingerprints, referenced Plan and sample IDs, viewport PNGs and thumbnails, and element IDs, labels and bounds |
279
+ | `plan push`, Plan-only `plan compile` | The exact local Plan bytes and the saved Head ETag |
280
+ | `plan compile --revision` | The approved revision ID and Plan ETag in request headers, with Project, analysis and Compilation reads. The Plan bytes are already hosted. |
281
+ | `plan status`, `compilation *`, `account` | Only the IDs in the request path |
282
+ | `report progress`, `report failure` | An account read; with reports on, the report printed just before |
283
+ | `note <kind>` | An account read; with reports on, the note printed just before |
284
+ | `maintain` | An account read; then the Project and Environment in the request path and `?page=N` |
285
+ | `maintain show` | Only the Project, Environment, and item IDs in the request path |
286
+ | `maintain resolve` | The reason, the cause, and any `--detail` text, whatever the reports choice |
287
+ | `maintain defer` | The `--until` time |
288
+ | `maintain ask-owner` | The `--question` text, whatever the reports choice |
289
+
290
+ ### Update line and refusals
291
+
292
+ First Draft answers each routed `/v1` request with `FirstDraft-API-Contract` and two pairs of versions:
293
+ `FirstDraft-Latest-Plugin` and `FirstDraft-Minimum-Plugin` for the plugin, and `FirstDraft-Latest-CLI` and
294
+ `FirstDraft-Minimum-CLI` for this package, which is numbered separately. The CLI checks every response it receives;
295
+ an OAuth answer or a missing route may carry none of them, so it then checks nothing. With
296
+ `FIRSTDRAFT_PLUGIN_VERSION` set, the CLI compares that plugin version with the plugin pair. Without it, it compares
297
+ its own version with the CLI pair. A pair is compared only when both of its versions are readable, so a Service that
298
+ sends no CLI pair, or half of one, produces no line and no refusal. A `FIRSTDRAFT_PLUGIN_VERSION` that is set but is
299
+ not a version, even blank, compares neither pair; the command's one line then says the CLI could not tell whether the
300
+ setup is current. The update
301
+ notice therefore comes from First Draft's answer to the command being run, not from a request of its own.
302
+
303
+ - **Older than the latest:** the CLI writes one line on standard error, once per command and just before the
304
+ command's own result, whether or not a terminal is attached, so an agent sees it and can pass it on:
305
+ `First Draft: an update is available (plugin <latest>; this setup has plugin <installed>). Tell the person the update steps are at https://firstdraft.com/update`.
306
+ Without a plugin version the line names `CLI <latest>` and `CLI <installed>`. `start` writes the same line on
307
+ standard output, after its version line.
308
+ - **Older than the minimum, or a contract outside the accepted range:** the CLI finishes handling that response, so
309
+ local state stays in step with First Draft, and sends nothing more. When the command still had a request to send,
310
+ it exits with `update_required` or `api_contract_unsupported` instead of its own result. When that response was the
311
+ command's last, the command reports its own result, after one `First Draft: ` line on standard error that names
312
+ the stop and says the command finished; `start` is the exception and always exits with the error, because such a
313
+ setup is not ready. For an older contract, or a prerelease of a release inside the accepted range, it says to use the CLI that origin supports instead of updating; a prerelease of a newer release counts as newer. Either replaces the update line above.
314
+ - **A `429` answer**, which First Draft sends when a limit is reached, such as an account's Compilations for the day
315
+ or its reports for the hour, usually with `Retry-After`: the request did nothing, and whatever else the response
316
+ says, the command exits with `rate_limited` and the time to try again.
317
+
318
+ A header value that is not a version is ignored, and a prerelease contract counts as outside the range. `logout`
319
+ always finishes removing the local token, so neither the stop line nor a refusal replaces its result.
320
+ [Errors and recovery](errors.md#update-and-limit-errors) explains each error.
321
+
322
+ ## Check readiness before work
323
+
324
+ An agent runs `firstdraft start` once, before other First Draft work; the Skill runs it first. It selects the origin as
325
+ `login` does, with `--staging` or `FIRSTDRAFT_API_URL`:
326
+
327
+ ```sh
328
+ firstdraft start
329
+ ```
330
+
331
+ It prints plain text for the agent on standard output, one fact per line. The sentences are fixed. The update line is
332
+ the one every command prints, and the rest ship in `src/agent-sentences.js`, where `login --no-wait` and
333
+ `login --finish` take theirs. First Draft's answer only chooses among them: the only values they carry are the origin,
334
+ versions, and the name of a token variable. It prints no token and no account fact other than whether reports are on,
335
+ and its handled errors leave out the problem text First Draft sent.
336
+
337
+ With a token for the origin, from the environment or a saved login, `start` makes one request, `GET /v1/account`, and
338
+ reads the version headers on that answer as every command does. Without one, it makes no request. It exits 0 only when
339
+ First Draft accepted the token, and every other outcome ends with its handled error on standard error.
340
+
341
+ The first line names the versions: `First Draft CLI <version>.`, or `First Draft CLI <version> with plugin <version>.`
342
+ when `FIRSTDRAFT_PLUGIN_VERSION` holds a version. When First Draft names a newer version, the
343
+ [update line](#update-line-and-refusals) comes second. Then, by outcome:
344
+
345
+ - **Ready, reports off** (exit 0). Nothing is said about reports:
346
+
347
+ ```text
348
+ This computer has a saved login for <origin>.
349
+ Ready: First Draft accepted this computer's login.
350
+ ```
351
+
352
+ - **Ready, reports on** (exit 0). The same two lines, then the sentences that say when to send reports and notes and
353
+ with which command. One yes covers both, so the agent of a person who said no hears about neither:
354
+
355
+ ```text
356
+ Reports are on: this person agreed that you send First Draft progress and failure reports about the code it generates, and notes about problems with First Draft itself.
357
+ Progress: run 'firstdraft report progress --step <step>' when bin/setup finishes (setup), when the first spec run finishes (specs_first_run), when every item under the README's Behavior to write is written (behavior_written), when the specs pass (specs_passing), and when the preview starts (preview_started). Add the counts you have; 'firstdraft report progress --help' lists them.
358
+ Failure: when generated code fails in a way the README does not list, run 'firstdraft report failure --kind <kind>' once you have fixed it or stopped trying, where <kind> is setup_failure, spec_failure, boot_error, or lint_failure; 'firstdraft report failure --help' lists the other fields.
359
+ Each report names the Compilation that the CLI last recorded for this Project when 'firstdraft plan compile' or 'firstdraft compilation download' wrote its code; to name a different one, put its compilation.id right after 'report progress' or 'report failure'.
360
+ Run each report and note command from the generated application's root, or from the Project's directory before the code is written or after --output. Each prints what it sends: pass only text that may leave this computer, never secrets or the person's data.
361
+ Notes: send a note only when a problem with First Draft cost you a real detour and is likely to happen again, never for routine debugging, and only after the Plan has been pushed once with 'firstdraft plan push' or 'firstdraft plan compile'.
362
+ Unstated request: when the person asked for something the Plan could not state, run 'firstdraft note unstated_request --request <text>', adding --workaround <text> for what you wrote in the Plan instead or left for later.
363
+ Unclear guidance: when a Skill page or a diagnostic was unclear, run 'firstdraft note unclear_guidance --page <page> --unclear <text>', where <page> is the page's path inside the Skill, such as SKILL.md or references/plan/policies.md; for a diagnostic code or a CLI error value, give --code <code> in place of or beside --page, and add --workaround <text> for what you did instead.
364
+ Wrong output: when analysis or generated code was wrong, run 'firstdraft note wrong_output --source <source> --expected <text> --actual <text>', where <source> is analysis or generated_code; a note about generated code names the recorded Compilation as a report does, and 'firstdraft note wrong_output --help' lists --code, --file, and --workaround.
365
+ Write each note in your own plain words, at most 300 characters a field: never secrets, credentials, personal data, or code from the person's project.
366
+ ```
367
+
368
+ The first five are `REPORTS_ON_LINES` and the rest `NOTES_ON_LINES` in `src/agent-sentences.js`.
369
+
370
+ - **An environment token** (exit 0 when accepted). The login lines say which token is used:
371
+
372
+ ```text
373
+ This computer has no saved login for <origin>.
374
+ FIRSTDRAFT_API_TOKEN is set, so the CLI uses that token in place of any saved login for <origin>, and no login is needed.
375
+ Ready: First Draft accepted FIRSTDRAFT_API_TOKEN.
376
+ ```
377
+
378
+ The first line says `a saved login` when one exists, and staging names `FIRSTDRAFT_STAGING_API_TOKEN`.
379
+
380
+ - **Not logged in** (`authentication_required`, exit 1, no request). The next step is the
381
+ [agent's login](#log-in-from-an-agent):
382
+
383
+ ```text
384
+ This computer has no saved login for <origin>.
385
+ To log in, run 'firstdraft login --no-wait'. It prints a link and a code: show both to the person and ask them to approve the login in their browser.
386
+ When the person says they approved, run 'firstdraft login --finish', then run 'firstdraft start' again.
387
+ ```
388
+
389
+ - **Login not accepted** (`authentication_required`, exit 1). After the login lines, a saved login First Draft
390
+ rejected gets `Not logged in: First Draft did not accept the saved login for <origin>.` and the two login steps
391
+ above. A rejected environment token gets
392
+ `Not logged in: First Draft did not accept FIRSTDRAFT_API_TOKEN. Ask the person to replace it or unset it; while it is set, the CLI uses no saved login.`
393
+ - **Below the minimum, or another API contract** (`update_required` or `api_contract_unsupported`, exit 1). The
394
+ login lines, then the [refusal](errors.md#update-and-limit-errors) instead of `Ready`.
395
+ - **Account not read** (`account_unavailable`, `invalid_server_response`, or `rate_limited`, exit 1). The login lines,
396
+ then the error. `account_unavailable` is safe to retry.
397
+
134
398
  ## Start a Foundation Plan
135
399
 
136
400
  From the project that the Plan describes:
@@ -139,10 +403,9 @@ From the project that the Plan describes:
139
403
  firstdraft plan init --name "Oscar Party"
140
404
  ```
141
405
 
142
- This creates an empty `firstdraft.foundation-plan.sketch/0.23` Plan targeting `rails-sketch/2026-10` and a
143
- client-generated Project ID under `.firstdraft/`. A nested ignore file keeps that local scratch area out of Git
144
- without changing the project's own `.gitignore`. Initialization makes no network request and refuses to replace an
145
- existing `.firstdraft` path.
406
+ This creates an empty `firstdraft.foundation-plan.sketch/0.23` Plan targeting `rails-sketch/2026-11`. In a fresh
407
+ folder it creates the Project ID and an ignored `.firstdraft/` directory. In a folder reserved by `project start`,
408
+ it writes the Plan for the existing Project ID and origin. Initialization runs locally and preserves any existing Plan.
146
409
 
147
410
  Provide either `--name`, `--application-key`, or both. Name-only initialization derives a lower-snake key. Key-only
148
411
  initialization derives a humanized display name. Supplying both preserves both values exactly after validating them
@@ -190,11 +453,11 @@ From the initialized project:
190
453
  firstdraft plan push
191
454
  ```
192
455
 
193
- The command sends the exact bytes in `.firstdraft/foundation-plan.json`. The first push conditionally creates the
194
- Project; later pushes replay the complete ETag saved in `.firstdraft/state.json` so a stale writer cannot replace a
195
- newer Plan. Successful responses and server diagnostics are printed as JSON for an agent to inspect.
456
+ The command sends the exact bytes in `.firstdraft/foundation-plan.json`. In a Plan-only workflow the first push conditionally creates the
457
+ Project. After `project start`, a push requires the reserved Project to exist. Later pushes replay the complete ETag
458
+ saved in `.firstdraft/state.json` so a stale writer cannot replace a newer Plan. Successful responses and server diagnostics are printed as JSON for an agent to inspect.
196
459
 
197
- The first successful push pins the normalized API origin in local state. See
460
+ The first successful Plan-only push pins the normalized API origin in local state. A hosted Project already has its origin from `project start`. See
198
461
  [environment selection and authentication](#select-an-environment-and-authenticate) for production, staging, custom
199
462
  origins, and the credentials each requires.
200
463
 
@@ -241,25 +504,28 @@ firstdraft plan compile
241
504
  ```
242
505
 
243
506
  This is equivalent to `firstdraft plan compile --output .`. Use `--output ./application` for another absent
244
- directory, or `--github` to publish to a private GitHub repository. `--github` and `--output` are mutually exclusive.
245
- No GitHub connection, repository clone, or push is required for local compilation. Compilation runs on the First
246
- Draft service; output and the application runtime are local.
507
+ directory. No GitHub connection, repository clone, or push is required. Compilation runs on the First Draft service;
508
+ output and the application runtime are local. To put the application on GitHub, create and push a repository with
509
+ `git` and `gh` after it is written.
510
+
511
+ For a Project with published Sketches, run `firstdraft plan compile --revision <approved-id>` as described in
512
+ [Hosted Sketches](#hosted-sketches). It uses the published Plan and checks that the local Plan and sources match the review.
247
513
 
248
- Both `plan compile` modes first push the exact current bytes in
249
- `.firstdraft/foundation-plan.json`, even when those bytes are unchanged, and save the accepted ETag using the same
514
+ In a Plan-only workflow, `plan compile` first pushes the exact current bytes in
515
+ `.firstdraft/foundation-plan.json`, even when those bytes are unchanged, and saves the accepted ETag using the same
250
516
  contract as `plan push`. It then waits up to two minutes for an analysis whose graph version and
251
517
  `head_source_sha256` exactly match that accepted push, polling past a terminal result retained for an older Head.
252
518
  Invalid JSON, schema diagnostics, semantic diagnostics, a failed analysis, a superseded analysis, or a recurring
253
- diagnostic stop the command with structured output; no Compilation or Publication is requested.
519
+ diagnostic stop the command with structured output; no Compilation is requested.
254
520
 
255
- Only a `valid` analysis proceeds to the selected completion mode. Immediately before either conditional mutation,
256
- the CLI re-reads the local Plan and requires its exact bytes and saved state to match the accepted Head. It extracts
521
+ Only a `valid` analysis proceeds to Compilation. Immediately before the conditional Compilation start, the CLI
522
+ re-reads the local Plan and requires its exact bytes and saved state to match the accepted Head. It extracts
257
523
  the accepted source SHA-256 from the saved ETag, hashes the current local bytes, and sends that complete ETag in
258
524
  `If-Match`.
259
525
 
260
526
  ### Materialize a direct Compilation
261
527
 
262
- Without `--github`, the CLI accepts either an explicit absent destination beneath an existing real directory or a path
528
+ The CLI accepts either an explicit absent destination beneath an existing real directory or a path
263
529
  that resolves to the physical current directory. It validates either destination before pushing the Plan. An absent
264
530
  destination is checked again after analysis; root adoption instead holds its owned lock and performs the exact
265
531
  pre-move identity recheck described below. Other existing destinations remain invalid, so
@@ -352,8 +618,7 @@ path identities, and verify its original snapshot before removing the transactio
352
618
  reports `root_busy` until that state is reconciled; a foreign preexisting directory with the same reserved name
353
619
  reports `root_reserved_path`.
354
620
 
355
- After valid analysis, the CLI requests one Compilation for that exact reviewed Head and never starts GitHub
356
- Publication. It validates that the `202` response identifies the same Project, graph version, Head, Analysis,
621
+ After valid analysis, the CLI requests one Compilation for that exact reviewed Head. It validates that the `202` response identifies the same Project, graph version, Head, Analysis,
357
622
  Compiler release, and target; polls only that retained Compilation for up to ten minutes; downloads its exact
358
623
  artifact; and applies the same integrity and atomic materialization contract as `compilation download`. An ambiguous
359
624
  Compilation start is not retried automatically. After a validated `202`, later status, artifact, authentication,
@@ -364,57 +629,48 @@ Success writes one JSON object to stdout containing the validated Project, Compi
364
629
  Root adoption additionally reports `root_adoption.design_path` (or `null` when no design directory was needed), its
365
630
  top-level moved-entry count, whether a Git repository was preserved, and whether its index was replaced.
366
631
  After final verification succeeds, the CLI removes its owned `.firstdraft-root-output` transaction directory.
367
- An absent output directory contains exactly the artifact files and modes. Root adoption additionally contains the
632
+ An absent output directory contains the verified artifact files and modes. For a Sketch-linked Compilation, both
633
+ output modes also receive the local sources under `.firstdraft/design/sketches/`. Root adoption contains the
368
634
  preserved `.firstdraft/design` archive and an existing root `.git`, when present. Verification skips only the
369
635
  archive and retained Git/transaction paths; it still checks every generated file, including
370
636
  `.firstdraft/submitted-foundation-plan.json` and `.firstdraft/gaps.json`, and rejects unexpected generated paths. The
371
637
  CLI does not add a Git repository, run a formatter, or repair generated source. When an absent output is nested
372
638
  inside another Git worktree, initialize the application as its own repository before running generated checks that
373
- inspect Git; otherwise Git resolves to the parent worktree. Progress on stderr reports analysis and Compilation
374
- only.
375
-
376
- ### Publish through GitHub
377
-
378
- Use the explicit GitHub option for the Publication journey:
379
-
380
- ```sh
381
- firstdraft plan compile --github
639
+ inspect Git; otherwise Git resolves to the parent worktree.
640
+
641
+ Progress lines go to stderr, each prefixed by `First Draft:`. They report analysis and Compilation only and never
642
+ include IDs, hashes, raw server projections, local paths, or environment values. One
643
+ [update line](#update-line-and-refusals) can follow them on stderr, before the result or the error envelope; that
644
+ section says what it names. If the command fails after progress has begun, its structured JSON error envelope is the
645
+ final stderr document.
646
+
647
+ ### Record the Compilation whose code was written
648
+
649
+ After `plan compile` or `compilation download` writes and verifies a Compilation's code, the CLI records that
650
+ Compilation's ID in `compilation.json` beside the Project's `state.json`, so a later session's
651
+ [report](#send-progress-and-failure-reports) or [note](#send-notes) about generated code names it without being told.
652
+ When the command writes to an absent `--output`, that is `.firstdraft/compilation.json` in the directory the command
653
+ ran from. After root adoption, it is `.firstdraft/design/.firstdraft/compilation.json`, beside the archived state, where commands
654
+ run from the application root find it. The file is a new one rather than a change to the `firstdraft.cli-state/1`
655
+ format of `state.json`, and it sits in the same planning folder, whose ignore file keeps it out of Git:
656
+
657
+ ```json
658
+ {
659
+ "format": "firstdraft.cli-compilation/1",
660
+ "compilation_id": "<compilation-id>"
661
+ }
382
662
  ```
383
663
 
384
- Invoking this form authorizes the internal GitHub Publication lifecycle. The command writes stable human-readable
385
- progress to stderr, with every line prefixed by `First Draft:`. It reports analysis, Compilation completion or
386
- terminal failure or cancellation, the current GitHub phase, and an allowlisted reason, retry count, and exact UTC
387
- retry time when a GitHub preflight check is delayed. A retained retry with no next time is reported as paused and
388
- requiring operator recovery. Progress never includes IDs, hashes, repository names or URLs, raw server projections,
389
- local paths, or environment values. Success writes exactly the validated private GitHub repository URL plus a
390
- newline to stdout. If the command fails after progress has begun, its structured JSON error envelope is the final
391
- stderr document after the progress lines.
392
-
393
- The closed API `0.8.x` progress-reason allowlist is `github.configuration_missing`, `github.oauth_unavailable`,
394
- `github.api_unavailable`, `github.reauthorization_required`, `github.account_mismatch`,
395
- `github.installation_unavailable`, `github.installation_not_ready`, `github.preflight_unavailable`, the legacy-only
396
- `github.preflight_unclassified`, and these stage-specific fallbacks: `github.preflight_unavailable.configuration`,
397
- `github.preflight_unavailable.authorization`, `github.preflight_unavailable.repository_client`,
398
- `github.preflight_unavailable.artifact_preparation`, `github.preflight_unavailable.installation_token`,
399
- `github.preflight_unavailable.publication_preparation`, and `github.preflight_unavailable.repository_ref_client`.
400
- Other values make the response invalid rather than becoming terminal output.
401
-
402
- The internal Publication is a Project singleton in this release. A repeat safely receives the same Publication
403
- instead of creating another. If the first conditional `PUT` has an ambiguous result, the CLI reconciles it with one
404
- read-only singleton `GET` and never automatically repeats the mutation within that invocation. Publication polling
405
- is sequential, bounded to ten minutes, and pinned to the retained Project Head, Compilation input, Publication
406
- identity, and repository identity. Do not run concurrent Compile commands; use the
407
- [publication recovery procedure](errors.md#publication-recovery) after an invocation exits.
408
-
409
- This release cannot repoint a Project's Publication to a later accepted Head. The public CLI therefore has no
410
- `plan publish` command. Direct local Compilation and GitHub Publication are separate completion modes after the same
411
- exact Plan push and valid Analysis.
664
+ The CLI writes it with mode `0600` through a temporary file and a rename, replacing the previous record, so it names
665
+ the Compilation whose code the CLI wrote last for the Project, wherever that code went. If the record cannot be written, the command keeps its result, any earlier
666
+ record stays as it was, and one `First Draft:` line on standard error names the Compilation to pass to later reports
667
+ and notes. Only a report, or a note about generated code, that names no Compilation reads the record; one that is not
668
+ exactly this shape stops it with `local_input_unreadable`.
412
669
 
413
670
  ## Inspect a retained Compilation
414
671
 
415
672
  These lower-level commands are for callers that already hold a retained Compilation ID from authenticated API
416
- metadata or operational tooling. `plan compile --github` prints only the final repository URL, while the default
417
- `plan compile` form waits for and downloads its own direct Compilation:
673
+ metadata or operational tooling. `plan compile` waits for and downloads its own direct Compilation:
418
674
 
419
675
  ```sh
420
676
  firstdraft compilation status 01900000-0000-7000-8000-000000000001
@@ -440,12 +696,14 @@ never starts replacement work. An incomplete rollback leaves `.firstdraft-root-o
440
696
  reconciliation before this command can run again.
441
697
 
442
698
  Artifact validation accepts only Plan format `firstdraft.foundation-plan.sketch/0.23` and target profile
443
- `rails-sketch/2026-10`, in addition to matching the retained Compilation's provenance and verifying file integrity.
699
+ `rails-sketch/2026-11`, in addition to matching the retained Compilation's provenance and verifying file integrity.
444
700
  An earlier format or profile is rejected before materialization, even when the retained status names that profile.
445
701
 
446
702
  Successful root adoption is intentionally one-way. The original `.firstdraft` authoring state moves under
447
- `.firstdraft/design/.firstdraft`; run later First Draft commands from `.firstdraft/design`. Run ordinary Rails
448
- setup, preview, and tests from the generated application root. Retain the archive when further First Draft
703
+ `.firstdraft/design/.firstdraft`; run later Plan and Compilation commands from `.firstdraft/design`. Run ordinary
704
+ Rails setup, preview, and tests, and `report` and `note`, from the generated application root, where
705
+ the CLI finds the archived Project and failure frames are relative to the application. A successful download
706
+ [records](#record-the-compilation-whose-code-was-written) the Compilation it wrote, as `plan compile` does. Retain the archive when further First Draft
449
707
  authoring is useful. The CLI does not run or qualify the generated application's setup, preview, or test commands.
450
708
  Compiling a later Plan revision does not overwrite an already adopted root: choose a new absent output and
451
709
  deliberately reconcile it with application work.
@@ -493,59 +751,321 @@ Compilation. First Draft never changes a succeeded or failed Compilation: it ans
493
751
  safe, an outcome the CLI cannot confirm is `compilation_cancel_unavailable` rather than `request_outcome_unknown`.
494
752
  See [stuck Compilation recovery](errors.md#stuck-compilation-recovery).
495
753
 
496
- If the Compilation was started by `plan compile --github`, Cancel also cancels the Project's Publication. The
497
- Publication is a Project singleton in this release, so `plan compile --github` cannot start another one for that
498
- Project.
754
+ ## Read the account
755
+
756
+ ```sh
757
+ firstdraft account
758
+ ```
759
+
760
+ The command makes one `GET` and prints `{"reports": "on"}` or `{"reports": "off"}`. Reports are off until the person
761
+ says yes, when approving `firstdraft login` or later on their First Draft account page, where they can also turn
762
+ reports off again; an agent cannot turn them on. The command is not tied to a
763
+ Project: like `login`, it uses production, `--staging`, or `FIRSTDRAFT_API_URL`, with that origin's token. It prints
764
+ no other account fact.
765
+
766
+ ## Send progress and failure reports
767
+
768
+ When reports are on, an agent tells First Draft how far a generated application has come, and about an unexpected
769
+ failure in generated code. Run these from the generated application's root after root adoption, where the CLI finds
770
+ the Project's state archived at `.firstdraft/design`, or from the Project's directory:
771
+
772
+ ```sh
773
+ firstdraft report progress --step specs_first_run --examples 120 --failures 14 \
774
+ --behavior-to-write-failures 12 --items-remaining 9
775
+ firstdraft report failure --kind spec_failure \
776
+ --rerun "bin/rspec ./spec/models/movie_spec.rb:42" --error-class NoMethodError \
777
+ --message "undefined method 'stars' for nil" --frame "app/models/movie.rb:12:in 'Movie#average'" \
778
+ --fix-summary "Guarded a nil rating in Movie#average"
779
+ ```
780
+
781
+ The full forms are `firstdraft report progress [<compilation-id>] --step <step> [counts]` and
782
+ `firstdraft report failure [<compilation-id>] --kind <kind> [options]`. A report names one Compilation: the
783
+ `<compilation-id>` given, which is `compilation.id` from `plan compile`, or else the one the CLI
784
+ [last recorded](#record-the-compilation-whose-code-was-written) for the Project when it wrote a Compilation's code.
785
+ So an agent can report in a later session, after another Compile, or during maintenance without carrying the ID. With
786
+ none given and none recorded, the command sends nothing and ends with `compilation_not_recorded`. `--step` is `setup`, `specs_first_run`,
787
+ `behavior_written`, `specs_passing`, or `preview_started`. The counts are optional whole numbers of at most 1000000:
788
+ examples in the spec
789
+ run, failing examples, failing examples that the README's Behavior to write names, and Behavior to write items still
790
+ to write. The report carries the given counts under `counts`.
791
+
792
+ A failure report needs only `--kind` (`spec_failure`, `setup_failure`, `boot_error`, `lint_failure`, or
793
+ `deployed_error`). A `deployed_error` is an error in a deployed copy of the application that
794
+ [`firstdraft maintain`](#maintain-a-deployed-application) resolved with `--cause generated_code`; an uptime or
795
+ heartbeat check, a GitHub item, a Core update, or a host report is not one, whatever its cause. It also needs
796
+ `--item <item-id>`, sent as `maintenance_item_id`, and takes no `--message`, because the item's evidence can hold end
797
+ users' text. Another kind with `--item`, or a `deployed_error` without a lowercase item ID or with `--message`, is
798
+ `invalid_arguments`, and nothing is read or sent. A `deployed_error` finds its Project as
799
+ [`firstdraft maintain`](#maintain-a-deployed-application) does, from the application's `.firstdraft/gaps.json` too.
800
+ Those files record no Compilation. The command reads the account first: with reports off it exits 0 as usual, and
801
+ with reports on, without a Compilation given right after `report failure`, it ends with `compilation_not_recorded` and
802
+ sends nothing. Each other field is sent only in its shape, and left out otherwise:
803
+
804
+ | Option | Field | What it may contain |
805
+ | ----------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
806
+ | `--rerun` | `rerun` | An RSpec run of the application's specs: an optional `bundle exec ` or `bin/`, `rspec`, then one or more paths under `spec/` whose parts are letters, digits, `_`, `.`, and `-` separated by single slashes, each with optional `:LINE` parts. Leading environment assignments, with or without `env`, are dropped first, and a trailing slash after a spec directory is removed. |
807
+ | `--error-class` | `error_class` | A Ruby constant path, such as `ActiveRecord::RecordInvalid`. |
808
+ | `--frame` | `frames` | Up to 20 frames in the application's files: a relative path under `app/`, `lib/`, `config/`, `db/`, or `spec/` made of the same characters, with a line number, sent as `path:LINE`. A path inside the current directory may be absolute. |
809
+ | `--message` | `message` | Plain words: the first line, at most 300 characters. |
810
+ | `--fix-summary` | `fix_summary` | Plain words: the first line, at most 200 characters. |
811
+ | `--ruby-version`, `--rails-version` | `versions` | Version numbers, such as `3.4.7`, `8.1.4.1`, or `8.2.0.beta1`. |
812
+
813
+ Free text keeps plain words only: the CLI takes the first line, replaces everything from the word that holds the first
814
+ quote character (`'`, `"`, or a backtick, including an apostrophe inside a word) to the end of the line with one `[…]`,
815
+ replaces each earlier word that contains `=`, `/`, `\`, or `@` or is longer than 24 characters with `[…]`, and keeps the
816
+ words that fit the length limit. A `lint_failure` therefore sends no rule name, and a rerun command that is not an
817
+ RSpec run is left out. Besides the Project's state and the Compilation record, or, for a `deployed_error` without
818
+ planning state, the application's `.firstdraft/gaps.json`, of which it uses only the Project ID, the CLI reads no file
819
+ for a failure report and attaches no diff or environment variable, but
820
+ the plain words of a message or fix summary it is given can still quote code, so pass only text that may be sent.
821
+
822
+ Each command first reads the account with a `GET` of `/v1/account` at the origin pinned by a successful push, or,
823
+ for a `deployed_error` without planning state, the origin `login` selects. Unless
824
+ First Draft answers `{"reports": "on"}`, no report is sent. With reports off, the command writes a line that says so
825
+ and exits 0, so the agent's work continues; it reads no Compilation record first. When the account read fails, no report is sent either. The command then
826
+ ends with `account_unavailable`, with `invalid_server_response` when the answer breaks the account's contract, or with
827
+ an error that any request can give: [`authentication_required`](errors.md#environment-and-credential-errors), or
828
+ `rate_limited` or an update refusal ([update and limit errors](errors.md#update-and-limit-errors)).
829
+
830
+ With reports on, the command writes `Sending this <progress or failure> report for Compilation <id> to <origin>:`, the
831
+ exact JSON body, and, when a field did not fit its shape, a `Left out:` line naming it, on standard output. It then
832
+ sends that body once in a `POST` to the same origin, and writes `Sent.` once First Draft acknowledges the stored report
833
+ with `201` and names the same Compilation; any other success is `report_unavailable`. If the person turns reports off between the two requests, First
834
+ Draft answers `403 reports_off` and keeps nothing, and the command writes the same line and exits 0. Neither command
835
+ retries.
836
+
837
+ ## Send notes
838
+
839
+ When reports are on, an agent also sends First Draft a note about a problem with First Draft itself: a request the Plan
840
+ could not state, guidance that was unclear, or output that was wrong. One yes covers reports and notes. A note belongs to
841
+ the Project, so the agent can send one during the interview, before any Compile, once the Plan's first push has pinned
842
+ the Project; before that push the command ends with `project_not_pushed`. Run it from the Project's directory, or from
843
+ the generated application's root after root adoption, as a report:
844
+
845
+ ```sh
846
+ firstdraft note unstated_request --request "A weekly digest email of new movies" \
847
+ --workaround "Left it for later"
848
+ firstdraft note unclear_guidance --page references/plan/policies.md#roles \
849
+ --unclear "It never says whether a role can be empty"
850
+ firstdraft note wrong_output --source analysis --code foundation_plan.identity.reserved_constant_collision \
851
+ --expected "The Plan is valid" --actual "Analysis refused it"
852
+ firstdraft note wrong_output --source generated_code --file app/policies/movie_policy.rb:12 \
853
+ --expected "Only the owner edits a movie" --actual "Any member can edit it"
854
+ ```
855
+
856
+ Each kind is a command, and its options are named after its fields:
857
+
858
+ | Kind | Option | Field | Needed | What it may contain |
859
+ | ------------------ | ------------------ | ---------------- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
860
+ | `unstated_request` | `--request` | `request` | Yes | Plain words: what the person asked for. |
861
+ | | `--workaround` | `workaround` | No | Plain words: what the agent wrote in the Plan instead, or left for later. |
862
+ | `unclear_guidance` | `--page` | `page` | `--page`, `--code`, or both | A Skill page: `SKILL.md` or a path inside the Skill ending in `.md`, such as `references/plan/policies.md`, with an optional `#anchor`. At most 200 characters. |
863
+ | | `--code` | `code` | See `--page` | A diagnostic code or CLI error value, such as `invalid_output_path`. At most 120 characters. |
864
+ | | `--unclear` | `unclear` | Yes | Plain words: what it says or leaves out, and what the agent needed. |
865
+ | | `--workaround` | `workaround` | No | Plain words: what the agent did instead. |
866
+ | `wrong_output` | `--source` | `source` | Yes | `analysis` or `generated_code`. |
867
+ | | `--code` | `code` | No; `analysis` only | A diagnostic code, as above. |
868
+ | | `--compilation-id` | `compilation_id` | `generated_code` only; the recorded one when not given | A lowercase UUIDv7: the Compilation the code came from. |
869
+ | | `--file` | `file` | No; `generated_code` only | A file in the generated application: a relative path with an optional `:LINE`, such as `app/models/movie.rb:12`. At most 300 characters. |
870
+ | | `--expected` | `expected` | Yes | Plain words: what the Plan or the page says should happen. |
871
+ | | `--actual` | `actual` | Yes | Plain words: what happened. |
872
+ | | `--workaround` | `workaround` | No | Plain words: what the agent changed. |
873
+
874
+ Plain words follow the [failure report's rule](#send-progress-and-failure-reports), at most 300 characters each. A page
875
+ is made of letters, digits, `_`, `.`, and `-` in parts separated by single slashes, and its anchor of letters, digits,
876
+ `_`, and `-`. A code is lowercase letters, digits, and `_`, in parts separated by single dots. A file is made of the
877
+ same characters as a page, without an anchor. Neither a page nor a file may have a `..` part. An option the kind does
878
+ not have, a needed option left out, a source other than the two, an option the source does not take, or a Compilation
879
+ that is not a lowercase UUIDv7 is `invalid_arguments`, and nothing is read or sent.
880
+
881
+ Like a report, each note command first reads the account at the pinned origin, and with reports off it writes the same
882
+ line and exits 0, having checked nothing else. With reports on:
883
+
884
+ 1. A note about generated code takes its Compilation from `--compilation-id`, or else from the
885
+ [record](#record-the-compilation-whose-code-was-written); with neither, the command sends nothing and ends with
886
+ `compilation_not_recorded`. Other notes name no Compilation.
887
+ 2. It shapes each field. A field that does not fit its shape is left out. When a field the note needs is left with
888
+ nothing, such as a request whose first line is blank, or guidance with neither a page nor a code left, the command
889
+ sends nothing and ends with `note_incomplete`, which names each such field.
890
+ 3. It writes `Sending this <kind> note to <origin>:`, with ` for Compilation <id>` before ` to` for a note about
891
+ generated code, then the exact JSON body, `{"note": {...}}` with `kind` first, and a `Left out:` line when a field was
892
+ left out.
893
+ 4. It sends that body once in a `POST` to `/v1/projects/{project_id}/notes` at the same origin, and writes `Sent.` once
894
+ First Draft acknowledges the stored note with `201` and names the same Compilation, or none. Any other success is
895
+ `note_unavailable`.
896
+
897
+ First Draft answers `403 reports_off` when the person turned reports off after the account read, and the command writes
898
+ the reports-off line and exits 0. A refusal, such as `invalid_note`, `compilation_not_found`, or
899
+ `compilation_not_succeeded`, is `note_rejected`; a network failure or server error is `note_unavailable`; and an
900
+ account's limit of 30 notes an hour is `rate_limited`. The command never retries. It reads the Project's state, and the
901
+ Compilation record only for a note about generated code without `--compilation-id`; it reads no file of the
902
+ application and no conversation. A note holds only what its options give, plus that recorded ID, so pass only text
903
+ that may be sent, and never code from the person's project.
904
+
905
+ ## Maintain a deployed application
906
+
907
+ First Draft records what needs attention in a deployed copy of the application, such as a production error group,
908
+ as items on that copy's Environment. From the Project's directory:
909
+
910
+ ```sh
911
+ firstdraft maintain
912
+ firstdraft maintain show 3f2c9a4e-8d1b-4c7a-9e5f-0a1b2c3d4e5f
913
+ firstdraft maintain resolve 3f2c9a4e-8d1b-4c7a-9e5f-0a1b2c3d4e5f --reason pull_request \
914
+ --cause generated_code --detail https://github.com/acme/app/pull/7
915
+ firstdraft maintain ask-owner 7b0e1d2c-3a4f-4e5d-8c6b-9a0f1e2d3c4b \
916
+ --question "Keep the free plan, whose app sleeps when idle, or move to a paid one?"
917
+ firstdraft maintain defer 7b0e1d2c-3a4f-4e5d-8c6b-9a0f1e2d3c4b --until 2026-12-09T15:00:00Z
918
+ ```
919
+
920
+ `firstdraft maintain` first reads the account with a `GET` of `/v1/account` at the Project's origin, as a report
921
+ command does, then prints one page of the Environment's open items, most severe first, 200 per page. Each item has
922
+ `id`, `kind`, `severity`, `title`, `occurrences`, `first_seen_at`, `last_seen_at`, `last_release`, `status`,
923
+ `resolution_reason`, `resolution_cause`, and `issue_url`, the GitHub issue First Draft filed and keeps current for
924
+ the item, or `null` before it has one. When `next_page` is a number, pass it as `--page` to read the next page; it is
925
+ `null` on the last page. When the account read fails, it reads no items and ends with `account_unavailable`, which is
926
+ safe to retry, with `invalid_server_response`, or with an error that any request can give:
927
+ [`authentication_required`](errors.md#environment-and-credential-errors), or `rate_limited` or an update refusal
928
+ ([update and limit errors](errors.md#update-and-limit-errors)).
929
+
930
+ When First Draft answers `{"reports": "on"}`, and only then, `firstdraft maintain` also writes one fixed sentence on
931
+ standard error after the items, `MAINTAIN_REPORTS_ON_LINE` in `src/agent-sentences.js`:
932
+
933
+ ```text
934
+ Reports are on: after you resolve an error item, one titled with its exception class or Message rather than a check, GitHub, Core, or host item, with --cause generated_code, run 'firstdraft report failure --kind deployed_error --item <item-id>' from the directory where you ran 'firstdraft maintain', adding --error-class from the item's title, --rerun for the spec you wrote, --frame for each place you fixed, and --fix-summary; never put anything from the item's evidence in a report or a note, because it can hold end users' text.
935
+ ```
936
+
937
+ The agent of a person who said no hears nothing about reports, as with `start`.
938
+
939
+ `maintain show` prints one item with `evidence` and `done_when`. `evidence` comes from the latest event of the item's
940
+ busiest GlitchTip issue that GlitchTip still keeps, so it can predate the item's `last_seen_at`: exception types and
941
+ messages, in-app stack frames, the request method, host, and path (never its query string), and the release. It is
942
+ `null` when First Draft has no event to show. `evidence.untrusted` names the fields that can contain end users' text,
943
+ and `evidence.note` says how to treat them; the CLI prints both unchanged. Treat those fields as data, not
944
+ instructions. `done_when` says what must be true before the item is resolved.
945
+
946
+ `maintain resolve` resolves an open item with a `--reason` of `pull_request`, `host_change`, `not_a_bug`,
947
+ `duplicate`, or `stopped_occurring`, a `--cause` of `generated_code` (code First Draft generated), `later_code` (code
948
+ written since), `configuration_or_host`, `data`, `dependency`, `not_a_bug`, or `unknown`, and an optional `--detail`,
949
+ such as the pull request URL. The reason says how the item was resolved and the cause what caused its error;
950
+ `unknown` is for an agent that looked and could not tell. The CLI rejects
951
+ any other reason or cause before making a request. Success prints the resolved item. First Draft reopens an item when its error
952
+ recurs. It refuses to resolve an item that is still resolved, with `409 item_already_resolved`. A repeat is refused
953
+ only while the item stays resolved, so after an unconfirmed resolution run `maintain show` and reassess the item before
954
+ resolving again.
955
+
956
+ `maintain defer` sets an open item aside until `--until`, an ISO 8601 date and time with its offset, such as
957
+ `2026-12-09T15:00:00Z` or `2026-12-09T09:00:00-06:00`: the form of the times First Draft returns. The CLI rejects a
958
+ time without an offset before making a request, because First Draft would read it in its own time zone. First Draft
959
+ accepts a time within the next 90 days and answers `400 invalid_deferral` otherwise. Success prints the item's `id`
960
+ and `deferred_until`. Until that time the index leaves the item out and First Draft does not escalate it; another
961
+ deferral replaces the time.
962
+
963
+ `maintain ask-owner` records `--question` on an open item for its owner and prints the item's `id` and
964
+ `owner_asked_at`. First Draft takes 1 to 500 characters once surrounding whitespace is trimmed and answers
965
+ `400 invalid_owner_question` otherwise; the CLI rejects an empty or blank question before making a request. A new
966
+ question replaces the last one. The item stays in the index unless it is deferred, and the index does not show the
967
+ question. First Draft stores the
968
+ question and sends it nowhere for now: no email, GitHub issue, or request log carries it, because it can quote end
969
+ users. Write only what the owner needs to decide, in your own words, and never a secret.
970
+
971
+ Both refuse a resolved item with `409 item_already_resolved`.
972
+
973
+ Each command takes `--environment`, which defaults to `production`: a lowercase name of letters, digits, and hyphens
974
+ that starts with a letter. Item IDs are lowercase UUIDs. Run the commands in the application's folder or in the
975
+ Project's directory. They find the Project in this order:
976
+
977
+ 1. The Project's `.firstdraft/state.json` in the current directory, or its archive at `.firstdraft/design` after root
978
+ adoption, as the report commands do. It pins both the Project ID and the API origin.
979
+ 2. Without that state, as in a fresh clone of the application or one compiled with `--output`, the Project ID in the
980
+ application's own `.firstdraft/gaps.json`, which every Compilation writes and which keeps the same Project ID
981
+ across recompiles. That file holds no origin, so the commands use the one `login` would select: `--staging`,
982
+ `FIRSTDRAFT_API_URL`, or `https://firstdraft.com`. They need a login for that origin on this computer, and after a
983
+ successful response they write this line on standard error, after any update line and before the reports
984
+ sentence:
985
+
986
+ ```text
987
+ No First Draft planning folder is here, so the CLI read the Project from .firstdraft/gaps.json and used <origin>: if the Project is on another First Draft origin, add --staging or set FIRSTDRAFT_API_URL.
988
+ ```
989
+
990
+ It is `applicationProjectLine` in `src/agent-sentences.js`. A Project on another origin answers
991
+ `environment_not_found`.
992
+
993
+ Without either, or with a `gaps.json` that names no Project, the command ends with `local_input_unreadable`. `show`,
994
+ `resolve`, `defer`, and `ask-owner` make one request each, and the index two. Each request has a
995
+ bounded timeout and refuses redirects; the commands change no local state, and print only a response that matches the
996
+ contract exactly, including its Project ID, Environment name, and item ID. See
997
+ [maintenance recovery](errors.md#maintenance-recovery).
499
998
 
500
999
  ## Service endpoints
501
1000
 
502
- The CLI calls these Service API routes. The `/v1` routes go to the origin pinned for the Project and send the
503
- selected token as a Bearer credential. The `/oauth` routes go to the origin selected for `login` or `logout` and
504
- send form-encoded OAuth parameters without a Bearer credential. Every request refuses redirects and has a bounded
1001
+ The CLI calls these Service API routes. The `/v1` routes send the selected token as a Bearer credential;
1002
+ `account` and `start` read `/v1/account` at the origin selected as for `login`; the report and note commands and the `maintain` index read it, and every other
1003
+ `/v1` request goes, to the origin pinned for the Project, or, for a maintain command or a `deployed_error` without
1004
+ planning state, the origin selected as for `login`. The `/oauth` routes go to the origin selected for `login` or `logout` and send form-encoded OAuth parameters
1005
+ without a Bearer credential. Every request refuses redirects and has a bounded
505
1006
  timeout. Each request takes its method and path from one
506
1007
  `SERVICE_ROUTES` entry in `src/api-response.js`. `test/service-endpoints.test.js` fails when this table and
507
1008
  `SERVICE_ROUTES` differ, or when no file in `src/` uses a declared route.
508
1009
 
509
- | Method | Path | Purpose |
510
- | ------ | ------------------------------------------------------------------ | ------------------------------------ |
511
- | `PUT` | `/v1/projects/{project_id}/foundation-plan` | Create or replace the Head |
512
- | `GET` | `/v1/projects/{project_id}/analysis` | Read the Head's current analysis |
513
- | `POST` | `/v1/projects/{project_id}/compilations` | Start a Compilation of the Head |
514
- | `GET` | `/v1/projects/{project_id}/compilations/{compilation_id}` | Read one retained Compilation |
515
- | `POST` | `/v1/projects/{project_id}/compilations/{compilation_id}/cancel` | Cancel that Compilation |
516
- | `GET` | `/v1/projects/{project_id}/compilations/{compilation_id}/artifact` | Download that Compilation's artifact |
517
- | `PUT` | `/v1/projects/{project_id}/github-publication` | Start or rejoin the Publication |
518
- | `GET` | `/v1/projects/{project_id}/github-publication` | Poll or reconcile the Publication |
519
- | `POST` | `/oauth/token` | Exchange a login grant for a token |
520
- | `POST` | `/oauth/device_authorization` | Start a device-flow login |
521
- | `POST` | `/oauth/revoke` | Revoke a saved token |
522
-
523
- `plan push` sends the Plan `PUT`, and `plan status` reads the analysis. `plan compile` does both. It then starts a
524
- Compilation, polls it, and downloads its artifact. With `--github`, it starts and polls the Publication instead.
1010
+ | Method | Path | Purpose |
1011
+ | ------ | ------------------------------------------------------------------------------------------ | ------------------------------------ |
1012
+ | `PUT` | `/v1/projects/{project_id}` | Start or reopen an owned Project |
1013
+ | `PUT` | `/v1/projects/{project_id}/sketch-reviews/{revision_id}` | Publish a board and working Plan |
1014
+ | `PUT` | `/v1/projects/{project_id}/foundation-plan` | Create or replace the Head |
1015
+ | `GET` | `/v1/projects/{project_id}/analysis` | Read the Head's current analysis |
1016
+ | `POST` | `/v1/projects/{project_id}/compilations` | Start a Compilation of the Head |
1017
+ | `GET` | `/v1/projects/{project_id}/compilations/{compilation_id}` | Read one retained Compilation |
1018
+ | `POST` | `/v1/projects/{project_id}/compilations/{compilation_id}/cancel` | Cancel that Compilation |
1019
+ | `GET` | `/v1/projects/{project_id}/compilations/{compilation_id}/artifact` | Download that Compilation's artifact |
1020
+ | `GET` | `/v1/account` | Read whether the account reports |
1021
+ | `POST` | `/v1/projects/{project_id}/compilations/{compilation_id}/progress-reports` | Send a progress report |
1022
+ | `POST` | `/v1/projects/{project_id}/compilations/{compilation_id}/failure-reports` | Send a failure report |
1023
+ | `POST` | `/v1/projects/{project_id}/notes` | Send a note |
1024
+ | `GET` | `/v1/projects/{project_id}/environments/{environment_name}/items` | List an Environment's open items |
1025
+ | `GET` | `/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}` | Read one item with its evidence |
1026
+ | `POST` | `/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/resolution` | Resolve that item |
1027
+ | `POST` | `/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/deferral` | Defer that item until a time |
1028
+ | `POST` | `/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/owner-question` | Record a question for its owner |
1029
+ | `POST` | `/oauth/token` | Exchange a login grant for a token |
1030
+ | `POST` | `/oauth/device_authorization` | Start a device-flow login |
1031
+ | `POST` | `/oauth/revoke` | Revoke a saved token |
1032
+
1033
+ `project start` reserves or reopens the Project. `sketches publish` sends its review and working Plan together.
1034
+ `plan push` sends the Plan `PUT`, and `plan status` reads the analysis. Plan-only `plan compile` does both, while `--revision` reads analysis for the published Plan. Compile then starts a
1035
+ Compilation, polls it, and downloads its artifact.
525
1036
  `compilation status` reads one retained Compilation. `compilation download` reads it and downloads its artifact.
526
- `compilation cancel` cancels it.
1037
+ `compilation cancel` cancels it. `account` reads `/v1/account`, and `start` reads it when it has a token.
1038
+ `report progress` and `report failure` read it and, with reports on, post their report. Each `note` command reads it
1039
+ and, with reports on, posts its note.
1040
+ `maintain` reads the account and then lists an Environment's open items, `maintain show` reads one item,
1041
+ `maintain resolve` resolves it, `maintain defer` defers it, and `maintain ask-owner` records a question about it.
527
1042
  `login` exchanges its authorization code at `/oauth/token`. With `--interactive`, it starts at
528
- `/oauth/device_authorization` and then polls `/oauth/token`. `logout` calls `/oauth/revoke`. The browser, not the
1043
+ `/oauth/device_authorization` and then polls `/oauth/token`. `login --no-wait` makes only the first request, and
1044
+ `login --finish` only the polls. `logout` calls `/oauth/revoke`. The browser, not the
529
1045
  CLI, opens `/oauth/authorize` and `/device`, so they have no rows.
530
1046
 
531
- The first push sends `If-None-Match: *`. Later pushes, the Compilation start `POST`, and the Publication `PUT` send
532
- the saved Head ETag in `If-Match`. The cancel `POST` sends no precondition header.
1047
+ The first push sends `If-None-Match: *`. Later pushes and the Compilation start `POST` send the saved Head ETag in
1048
+ `If-Match`. The cancel `POST` sends no precondition header. The resolution, deferral, and owner-question `POST`s send
1049
+ a JSON body and no precondition header.
533
1050
 
534
- The `/v1` routes belong to the API-contract range that `release/compatibility.json` accepts. The CLI does not read the
535
- Service's `FirstDraft-API-Contract` response header. Instead, the Service's release compatibility check compares the
536
- declared ranges before a release. The Service documents the routes in its Foundation Plan machine reference,
537
- `docs/architecture/reference/README.md` in the private `firstdraft/firstdraft` repository.
1051
+ The `/v1` routes require API contract `0.9.1` or a later patch on the same minor line. `API_CONTRACT_RANGE` in `src/service-client.js` declares that range,
1052
+ `release/compatibility.json` declares it for the Service's release compatibility check, and
1053
+ `test/release-compatibility.test.js` keeps the two equal. The CLI reads `FirstDraft-API-Contract` on every response
1054
+ and stops at a Service outside the range, as [update line and refusals](#update-line-and-refusals) describes: with
1055
+ `api_contract_unsupported` when the command had a request still to send. The Service documents the routes in its
1056
+ Foundation Plan machine reference, `docs/architecture/reference/README.md` in the private `firstdraft/firstdraft`
1057
+ repository.
538
1058
 
539
1059
  ### Head and its ETag
540
1060
 
541
- The Head is the exact Foundation Plan bytes that First Draft holds for a Project. The latest accepted
542
- `PUT /v1/projects/{project_id}/foundation-plan` sets it. The Service stores those bytes unchanged. A byte change that
1061
+ The Head is the exact Foundation Plan bytes that First Draft holds for a Project. A successful Plan push or new Sketch
1062
+ publication sets the Head to its submitted Plan. The Service stores those bytes unchanged. A byte change that
543
1063
  keeps the Plan's meaning still makes a new Head, although the Project's `graph_version` stays the same.
544
1064
 
545
- A successful Plan `PUT` returns a strong `ETag` of the form `"sha256:<hex>"`, quotes included. `<hex>` is the
1065
+ A successful Plan push or Sketch publication returns a strong `ETag` of the form `"sha256:<hex>"`, quotes included. `<hex>` is the
546
1066
  64-character lowercase SHA-256 of the Head bytes. The CLI saves the complete header value in `.firstdraft/state.json`
547
1067
  and replays it in `If-Match`. `plan compile` also extracts `<hex>` to check that the local Plan still matches the
548
- Head before it starts a Compilation or Publication. A saved ETag in any other form stops that check with
1068
+ Head before it starts a Compilation. A saved ETag in any other form stops that check with
549
1069
  `invalid_configuration`.
550
1070
 
551
1071
  The same digest appears as `head_source_sha256` in analysis and Compilation responses. To tell whether the local Plan
@@ -565,19 +1085,26 @@ Use this checklist when a change adds a command or subcommand. Each step names t
565
1085
  request with `serviceEndpoint` and a route declared in `SERVICE_ROUTES` in `src/api-response.js`.
566
1086
  2. **Dispatch it in `src/cli.js`.**
567
1087
  - Add a `<GROUP>_<NAME>_HELP` string, and list the command in its group's help: `PLAN_HELP`,
568
- `COMPILATION_HELP`, or `GENERATE_HELP`. A new group also needs a line in `ROOT_HELP` and a branch in `run`.
569
- - Add the branch in `runPlan`, `runCompilation`, or `runGenerate`, and a `run<Group><Name>` function.
1088
+ `COMPILATION_HELP`, `GENERATE_HELP`, or `MAINTAIN_HELP`. A new group also needs a line in `ROOT_HELP` and a
1089
+ branch in `run`.
1090
+ - Add the branch in `runPlan`, `runCompilation`, `runGenerate`, or `runMaintain`, and a `run<Group><Name>`
1091
+ function.
570
1092
  - Parse arguments with strict `parseArgs`. Invalid syntax writes `invalid_arguments` and exits 2.
571
- - A command that calls the Service also accepts `--staging` and calls `authenticateApiCommand`. It maps each
572
- error class to one `writeJson(stderr, …)` envelope and its exit status.
1093
+ - A command that calls the Service also accepts `--staging` and calls `authenticateApiCommand` with
1094
+ `service.fetch(fetchFunction)`, and awaits its module through `service.settle(…)` so that
1095
+ [refusals](#update-line-and-refusals) replace its result. It maps each error class to one
1096
+ `writeJson(stderr, …)` envelope and its exit status.
573
1097
  3. **Test it.**
574
1098
  - Add `test/<group>-<name>.test.js`. Cover the help text, invalid arguments, the success output, and every
575
1099
  handled `error` value.
576
1100
  - Update the exact group help in the tests: `HELP` in `test/cli.test.js`, `PLAN_HELP` in `test/plan-init.test.js`,
577
- or `GENERATE_HELP` in `test/generate-uuid.test.js`. No test asserts the whole `compilation` group help.
578
- - Append a command that calls the Service to `REMOTE_COMMANDS` in `test/api-environments.test.js`. Some tests
579
- there select entries by index, so add it at the end. The command's first request must reach the pinned origin
580
- with that origin's token, and one `401` must produce `authentication_required`.
1101
+ `GENERATE_HELP` in `test/generate-uuid.test.js`, or `MAINTAIN_HELP` in `test/maintain.test.js`. No test asserts
1102
+ the whole `compilation` group help.
1103
+ - Add a command that calls the Service to `REMOTE_COMMANDS` in `test/api-environments.test.js`. Tests there
1104
+ pick entries by group or with `remoteCommand(group, command)`, never by index. The command's first request
1105
+ must reach the pinned origin with that origin's token, and one `401` must produce `authentication_required`. A
1106
+ command not tied to a Project, such as `account`, selects its origin as `login` does; test that in its own file
1107
+ instead.
581
1108
  - Add packed-package cases to `scripts/smoke-package.js`, including at least an invalid-arguments case.
582
1109
  4. **Package it.** Add each new `src/` file to the exact list in `scripts/check-pack.js`. `firstdraft/skills` keeps
583
1110
  a copy of that list as `packedFileAllowlist` in `script/cli-contract/config.mjs`. The copy must change when
@@ -596,6 +1123,6 @@ Use this checklist when a change adds a command or subcommand. Each step names t
596
1123
  [version rule](https://github.com/firstdraft/cli/blob/main/RELEASING.md#versions), and apply it with the
597
1124
  [version pull request](https://github.com/firstdraft/cli/blob/main/RELEASING.md#prepare-the-version-pull-request)
598
1125
  steps. If the command needs a route or response that the accepted API range lacks, the Service ships it first
599
- under a new API-contract version. Then raise `requires.api_contract` in `release/compatibility.json`, and align
600
- the Skills CLI requirement. Because the CLI does not read the contract header, an older Service rejects the new
601
- route as not found.
1126
+ under a new API-contract version. Then raise `requires.api_contract` in `release/compatibility.json` and
1127
+ `API_CONTRACT_RANGE` in `src/service-client.js`, and align the Skills CLI requirement. The CLI then stops at a
1128
+ Service outside the new range, as [update line and refusals](#update-line-and-refusals) describes.