@firstdraft.com/cli 0.10.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/README.md CHANGED
@@ -19,7 +19,7 @@ is the Codespaces fallback.
19
19
  - direct Compile-and-materialize;
20
20
  - retained Compilation inspection, cancellation, and artifact download;
21
21
  - terminal output, exit status, and recovery contracts;
22
- - the dependency-free npm package; and
22
+ - the npm package with local Chrome capture for Sketches; and
23
23
  - package provenance and publication.
24
24
 
25
25
  The Service owns Foundation Plan meaning and server-side lifecycle. Skills own the agent conversation. This
@@ -95,7 +95,7 @@ The published package:
95
95
 
96
96
  - installs the firstdraft executable;
97
97
  - runs reviewed JavaScript source directly;
98
- - has no runtime dependencies or install scripts;
98
+ - uses Playwright Core for local Sketches capture and has no install scripts;
99
99
  - sends nothing in the background or beyond the command the caller runs. [What the CLI sends](docs/commands.md#what-the-cli-sends)
100
100
  lists each command's requests and their `FirstDraft-Client` header: CLI and plugin versions, agent, and operating
101
101
  system. `report` and `note` read the account first and, only with reports on, print their exact body and then send it;
package/docs/commands.md CHANGED
@@ -3,43 +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.10.x` source line contains the auditable command shell, the agent's `start` check, browser and device
6
+ The current `0.11.x` source line contains the auditable command shell, the agent's `start` check, browser and device
7
7
  login in one command or in two steps that an agent runs, local Foundation Plan
8
- initialization, local application-key and UUID generation, conditional whole-document push, whole-graph analysis
8
+ initialization, hosted Project creation and Sketch review, local application-key and UUID generation, conditional whole-document push, whole-graph analysis
9
9
  status polling, direct Compile-and-materialize, retained-Compilation inspection and
10
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 the service's `0.9.x` API contract. The [changelog](https://github.com/firstdraft/cli/blob/main/CHANGELOG.md) describes each version.
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
12
  [What the CLI sends](#what-the-cli-sends) lists every request and what it carries.
13
13
 
14
14
  ## Command map
15
15
 
16
- | Command | Network | Purpose |
17
- | ------------------------------------- | ------- | ------------------------------------------------------------- |
18
- | `firstdraft start` | Yes | Check versions, login, and reports before other work |
19
- | `firstdraft plan init` | No | Create an empty local Foundation Plan and Project identity |
20
- | `firstdraft generate application-key` | No | Preview deterministic name-to-key derivation |
21
- | `firstdraft generate uuid` | No | Generate one or more Foundation Plan subject identities |
22
- | `firstdraft login` | Yes | Approve the CLI in a browser and save a token for an origin |
23
- | `firstdraft login --no-wait` | Yes | Start a device login for an agent and exit |
24
- | `firstdraft login --finish` | Yes | Finish that device login once the person approved |
25
- | `firstdraft logout` | Yes | Revoke and remove the saved token for an origin |
26
- | `firstdraft plan push` | Yes | Conditionally submit the exact whole Plan |
27
- | `firstdraft plan status` | Yes | Read or wait for the current whole-graph analysis |
28
- | `firstdraft plan compile` | Yes | Push and analyze, then materialize in the current folder |
29
- | `firstdraft compilation status` | Yes | Inspect a retained Compilation by ID |
30
- | `firstdraft compilation download` | Yes | Verify and materialize a successful retained Compilation |
31
- | `firstdraft compilation cancel` | Yes | Cancel a queued or running Compilation by ID |
32
- | `firstdraft account` | Yes | Show whether the account sends reports |
33
- | `firstdraft report progress` | Yes | Print, then send, how far a generated application has come |
34
- | `firstdraft report failure` | Yes | Print, then send, an unexpected failure in generated code |
35
- | `firstdraft note unstated_request` | Yes | Print, then send, a request the Plan could not state |
36
- | `firstdraft note unclear_guidance` | Yes | Print, then send, a Skill page or diagnostic that was unclear |
37
- | `firstdraft note wrong_output` | Yes | Print, then send, analysis or generated code that was wrong |
38
- | `firstdraft maintain` | Yes | List a deployed Environment's open items |
39
- | `firstdraft maintain show` | Yes | Read one item with its evidence |
40
- | `firstdraft maintain resolve` | Yes | Resolve one item with a reason |
41
- | `firstdraft maintain defer` | Yes | Set one item aside until a time |
42
- | `firstdraft maintain ask-owner` | Yes | Record a question for the owner about one item |
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.
43
89
 
44
90
  ## Select an environment and authenticate
45
91
 
@@ -224,19 +270,22 @@ CLI without the plugin's launcher, such as a direct npm installation, may set th
224
270
 
225
271
  Beyond the header, a command sends only what it needs:
226
272
 
227
- | Commands | Request content |
228
- | ----------------------------------------- | ----------------------------------------------------------------------------------- |
229
- | `login`, `logout` | OAuth parameters; `logout` sends the saved token to revoke it |
230
- | `start` | An account read, and nothing without a token |
231
- | `plan push`, `plan compile` | The exact local Plan bytes and the saved Head ETag |
232
- | `plan status`, `compilation *`, `account` | Only the IDs in the request path |
233
- | `report progress`, `report failure` | An account read; with reports on, the report printed just before |
234
- | `note <kind>` | An account read; with reports on, the note printed just before |
235
- | `maintain` | An account read; then the Project and Environment in the request path and `?page=N` |
236
- | `maintain show` | Only the Project, Environment, and item IDs in the request path |
237
- | `maintain resolve` | The reason, the cause, and any `--detail` text, whatever the reports choice |
238
- | `maintain defer` | The `--until` time |
239
- | `maintain ask-owner` | The `--question` text, whatever the reports choice |
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 |
240
289
 
241
290
  ### Update line and refusals
242
291
 
@@ -256,7 +305,7 @@ notice therefore comes from First Draft's answer to the command being run, not f
256
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`.
257
306
  Without a plugin version the line names `CLI <latest>` and `CLI <installed>`. `start` writes the same line on
258
307
  standard output, after its version line.
259
- - **Older than the minimum, or a contract other than API `0.9.x`:** the CLI finishes handling that response, so
308
+ - **Older than the minimum, or a contract outside the accepted range:** the CLI finishes handling that response, so
260
309
  local state stays in step with First Draft, and sends nothing more. When the command still had a request to send,
261
310
  it exits with `update_required` or `api_contract_unsupported` instead of its own result. When that response was the
262
311
  command's last, the command reports its own result, after one `First Draft: ` line on standard error that names
@@ -354,10 +403,9 @@ From the project that the Plan describes:
354
403
  firstdraft plan init --name "Oscar Party"
355
404
  ```
356
405
 
357
- This creates an empty `firstdraft.foundation-plan.sketch/0.23` Plan targeting `rails-sketch/2026-11` and a
358
- client-generated Project ID under `.firstdraft/`. A nested ignore file keeps that local scratch area out of Git
359
- without changing the project's own `.gitignore`. Initialization makes no network request and refuses to replace an
360
- 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.
361
409
 
362
410
  Provide either `--name`, `--application-key`, or both. Name-only initialization derives a lower-snake key. Key-only
363
411
  initialization derives a humanized display name. Supplying both preserves both values exactly after validating them
@@ -405,11 +453,11 @@ From the initialized project:
405
453
  firstdraft plan push
406
454
  ```
407
455
 
408
- The command sends the exact bytes in `.firstdraft/foundation-plan.json`. The first push conditionally creates the
409
- Project; later pushes replay the complete ETag saved in `.firstdraft/state.json` so a stale writer cannot replace a
410
- 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.
411
459
 
412
- 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
413
461
  [environment selection and authentication](#select-an-environment-and-authenticate) for production, staging, custom
414
462
  origins, and the credentials each requires.
415
463
 
@@ -460,7 +508,10 @@ directory. No GitHub connection, repository clone, or push is required. Compilat
460
508
  output and the application runtime are local. To put the application on GitHub, create and push a repository with
461
509
  `git` and `gh` after it is written.
462
510
 
463
- `plan compile` first pushes the exact current bytes in
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.
513
+
514
+ In a Plan-only workflow, `plan compile` first pushes the exact current bytes in
464
515
  `.firstdraft/foundation-plan.json`, even when those bytes are unchanged, and saves the accepted ETag using the same
465
516
  contract as `plan push`. It then waits up to two minutes for an analysis whose graph version and
466
517
  `head_source_sha256` exactly match that accepted push, polling past a terminal result retained for an older Head.
@@ -578,7 +629,8 @@ Success writes one JSON object to stdout containing the validated Project, Compi
578
629
  Root adoption additionally reports `root_adoption.design_path` (or `null` when no design directory was needed), its
579
630
  top-level moved-entry count, whether a Git repository was preserved, and whether its index was replaced.
580
631
  After final verification succeeds, the CLI removes its owned `.firstdraft-root-output` transaction directory.
581
- 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
582
634
  preserved `.firstdraft/design` archive and an existing root `.git`, when present. Verification skips only the
583
635
  archive and retained Git/transaction paths; it still checks every generated file, including
584
636
  `.firstdraft/submitted-foundation-plan.json` and `.firstdraft/gaps.json`, and rejects unexpected generated paths. The
@@ -957,6 +1009,8 @@ timeout. Each request takes its method and path from one
957
1009
 
958
1010
  | Method | Path | Purpose |
959
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 |
960
1014
  | `PUT` | `/v1/projects/{project_id}/foundation-plan` | Create or replace the Head |
961
1015
  | `GET` | `/v1/projects/{project_id}/analysis` | Read the Head's current analysis |
962
1016
  | `POST` | `/v1/projects/{project_id}/compilations` | Start a Compilation of the Head |
@@ -976,7 +1030,8 @@ timeout. Each request takes its method and path from one
976
1030
  | `POST` | `/oauth/device_authorization` | Start a device-flow login |
977
1031
  | `POST` | `/oauth/revoke` | Revoke a saved token |
978
1032
 
979
- `plan push` sends the Plan `PUT`, and `plan status` reads the analysis. `plan compile` does both. It then starts a
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
980
1035
  Compilation, polls it, and downloads its artifact.
981
1036
  `compilation status` reads one retained Compilation. `compilation download` reads it and downloads its artifact.
982
1037
  `compilation cancel` cancels it. `account` reads `/v1/account`, and `start` reads it when it has a token.
@@ -993,7 +1048,7 @@ The first push sends `If-None-Match: *`. Later pushes and the Compilation start
993
1048
  `If-Match`. The cancel `POST` sends no precondition header. The resolution, deferral, and owner-question `POST`s send
994
1049
  a JSON body and no precondition header.
995
1050
 
996
- The `/v1` routes belong to API contract `0.9.x`. `API_CONTRACT_RANGE` in `src/service-client.js` declares that range,
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,
997
1052
  `release/compatibility.json` declares it for the Service's release compatibility check, and
998
1053
  `test/release-compatibility.test.js` keeps the two equal. The CLI reads `FirstDraft-API-Contract` on every response
999
1054
  and stops at a Service outside the range, as [update line and refusals](#update-line-and-refusals) describes: with
@@ -1003,11 +1058,11 @@ repository.
1003
1058
 
1004
1059
  ### Head and its ETag
1005
1060
 
1006
- The Head is the exact Foundation Plan bytes that First Draft holds for a Project. The latest accepted
1007
- `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
1008
1063
  keeps the Plan's meaning still makes a new Head, although the Project's `graph_version` stays the same.
1009
1064
 
1010
- 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
1011
1066
  64-character lowercase SHA-256 of the Head bytes. The CLI saves the complete header value in `.firstdraft/state.json`
1012
1067
  and replays it in `If-Match`. `plan compile` also extracts `<hex>` to check that the local Plan still matches the
1013
1068
  Head before it starts a Compilation. A saved ETag in any other form stops that check with
package/docs/errors.md CHANGED
@@ -19,6 +19,56 @@ errors, or unvalidated response bodies. `local_state_not_saved` is the sole exce
19
19
  its `recovery_state` is required to repair the accepted ETag locally. Root-level and command-group usage failures
20
20
  remain human-readable text on standard error with exit 2. Unexpected programming defects remain loud.
21
21
 
22
+ ## Sketch review recovery
23
+
24
+ When a screen capture fails, the detail gives its screen ID and viewport dimensions. Correct the indicated Plan
25
+ binding, image, asset URL, or layout and publish again.
26
+
27
+ `sketch_review_failed` describes a Project-start, capture, publication or reviewed-source problem. Retry an interrupted
28
+ start from the same directory. A fresh publication refused with a client error other than an HTTP 408 clears its
29
+ pending request. Correct the rejected draft or login, or wait for the rate limit, then publish again.
30
+
31
+ After a timeout or another unknown outcome, the CLI retains the exact request privately. Run the same publish
32
+ command to settle that revision before sending edits. A refusal before the service can check the revision, such as
33
+ a 400 for an invalid ID, an access refusal, a size limit or a rate limit, retains the journal on replay. Restore
34
+ access or correct the service configuration and retry. A verified conflict, active Compilation, Project storage
35
+ quota, invalid review or Plan diagnostics after the revision check clears a refused replay. If local sources have
36
+ changed, a successful replay returns the recovered revision ID and a `next_step` to publish the current draft.
37
+
38
+ If replay keeps timing out or returning a server error, keep the planning folder and its pending request intact.
39
+ Reopen the Project URL to inspect the hosted board and continue the walkthrough using local HTML. To continue
40
+ publishing before the original submission can be resolved, start a separate Project with `project start` in a new
41
+ folder. Copy only the working Plan and `sketches/` there. Publish, share the new Project URL and obtain approval
42
+ for its new revision. The original Project and pending request remain available for recovery.
43
+
44
+ Hosted Plan pushes, Sketch publications and root adoption reserve the planning folder while they run. Wait for the
45
+ active command to finish and retry. After a killed hosted writer, check the PID in
46
+ `.firstdraft-root-output/hosted-writer.pid`. Once the process has exited, remove that file and the empty directory.
47
+ A stopped command can leave an empty reservation or an empty PID file. First ensure every writer, Compile and
48
+ download using this folder has stopped. If the directory is empty, remove it with `rmdir .firstdraft-root-output`.
49
+ If its only entry is an empty `hosted-writer.pid`, remove that file first. Preserve all journal or artifact files.
50
+ For a root-output journal, follow the root-adoption recovery instructions below.
51
+
52
+ The service problem appears in `response` when the CLI can verify its shape:
53
+
54
+ - `409 sketch_review_conflict` in `sketch_review_failed` means the submitted revision conflicts with the hosted
55
+ Project. Open the Project URL, inspect the current review and reconcile its changes locally. Then run
56
+ `firstdraft sketches publish --after <current-review-id> --head <current-head-sha256>` using the identities
57
+ returned in `response.current_review.id` and `response.head_sha256`. Use `none` for a missing review or Head.
58
+ An interrupted rebased publication accepts the same two options on replay.
59
+ - `412 sketch_review_changed` in `compilation_start_rejected` means the service declined to start Compile for the
60
+ requested review and Plan. Inspect the current revision and Head, reconcile and publish any changes, and obtain
61
+ approval for the revision before passing it to `plan compile --revision`. When graph versions differ, the Plan
62
+ passed through another generation even if its current bytes match an older review.
63
+ - `422 invalid_sketch_review` in `sketch_review_failed` means the service rejected the review bundle. Read
64
+ `response.detail`, correct the indicated board, capture or reference, and publish the corrected draft. A rejected Plan can instead return `response.diagnostics`; use those to fix the Plan.
65
+ - `413 sketch_quota_reached` in `sketch_review_failed` means the Project reached its stored review limit. A
66
+ smaller capture may fit if only the stored byte budget is limiting it. At the revision-count limit, continue
67
+ the walkthrough using local HTML.
68
+
69
+ Restore missing approved source from the planning folder or review a reconstruction. When an older service lacks
70
+ the hosted endpoint, use local HTML for the walkthrough until the service and CLI are matched.
71
+
22
72
  ## Environment and credential errors
23
73
 
24
74
  `invalid_configuration` stops before a request when `--staging` conflicts with `FIRSTDRAFT_API_URL` or a Project's
@@ -197,11 +247,13 @@ replaced. `plan compile` can also meet it at the Compilation start, as `compilat
197
247
  `response.detail` names the active Compilation's ID.
198
248
 
199
249
  1. Read that Compilation once with `firstdraft compilation status <id>`. One that has reached `succeeded`, `failed`,
200
- or `cancelled` no longer blocks; rerun `plan compile`.
250
+ or `cancelled` no longer blocks. Rerun the original Compile command, including its approved `--revision` and
251
+ `--output` options when present.
201
252
  2. If it is still `queued` or `running` well after a Compilation normally finishes, for example after a
202
253
  `plan compile` wait timed out, cancel it with `firstdraft compilation cancel <id>`. Cancelling throws away any
203
254
  work it is still doing.
204
- 3. After the cancel succeeds, rerun `plan compile`.
255
+ 3. After the cancel succeeds, rerun that same command. If the hosted revision has changed, obtain approval for
256
+ the new revision before starting another Compile.
205
257
 
206
258
  Cancel never changes a succeeded or failed Compilation, and repeating it is safe:
207
259
 
@@ -272,6 +324,7 @@ again. First Draft refuses to resolve an item that is still resolved, with `main
272
324
 
273
325
  | Commands | `error` | Exit | Meaning |
274
326
  | ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---: | ---------------------------------------------------------------------------------------------------------------------------- |
327
+ | Hosted Sketches commands and reviewed source handoff | `sketch_review_failed` | 1 | Repair the Project, capture, publication or source handoff ([recovery](#sketch-review-recovery)). |
275
328
  | Any leaf command | `invalid_arguments` | 2 | Syntax was invalid; no request was made. |
276
329
  | Network commands except `logout` | `update_required`, `api_contract_unsupported` | 1 | First Draft needs a newer plugin or CLI, or serves another API contract ([recovery](#update-and-limit-errors)). |
277
330
  | Network commands except `logout` | `rate_limited` | 1 | First Draft refused a request at a limit; `retry_at` says when to try again. |
@@ -283,7 +336,7 @@ again. First Draft refuses to resolve an item that is still resolved, with `main
283
336
  | `logout` | `logout_failed` | 1 | Check `phase` and `revoked`; revocation may have happened ([recovery](#login-and-logout-errors)). |
284
337
  | Network commands | `authentication_required` | 1 | No environment or saved token exists for the origin, or First Draft rejected it. |
285
338
  | Plan, `compilation *`, `report`, `note`, `maintain` | `local_input_unreadable` | 1 | Required local Plan or private state, the Compilation record, or an application's `.firstdraft/gaps.json` could not be read. |
286
- | Status, Compile, Compilation, `report`, `note`, `maintain` | `project_not_pushed` | 1 | No API origin is pinned for the local Project. |
339
+ | Status, Compile, Compilation, `report`, `note`, `maintain` | `project_not_pushed` | 1 | The local Project has no accepted Plan recorded. |
287
340
  | `plan push`, `plan compile` | `request_outcome_unknown` | 1 | A mutation or its response could not be verified; `plan compile` identifies its mutation phase. |
288
341
  | `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`. |
289
342
  | `plan push`, `plan compile` | `server_rejected` | 1 | First Draft returned validated Plan diagnostics or rejected the request with a validated problem. |
@@ -318,5 +371,5 @@ Root-output `invalid_output_path.reason` values are `destination_exists`, `root_
318
371
  `root_git_unavailable`, `root_git_unsupported`, `root_git_dirty`, `root_ignore_not_preserved`, and `root_busy`. Git
319
372
  refusing discovery, including a `safe.directory` refusal, is `root_git_unavailable`; a discovered but unsupported
320
373
  Git shape such as a submodule is `root_git_unsupported`. Root-output `materialization_failed.reason` values are
321
- `output_changed`, `root_artifact_collision`, `root_ignore_changed`, `root_transaction_failed`, and
374
+ `output_changed`, `reviewed_sources_changed`, `root_artifact_collision`, `root_ignore_changed`, `root_transaction_failed`, and
322
375
  `root_rollback_incomplete`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firstdraft.com/cli",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Command-line interface for First Draft",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -53,5 +53,8 @@
53
53
  },
54
54
  "overrides": {
55
55
  "minimatch": "^11.0.5"
56
+ },
57
+ "dependencies": {
58
+ "playwright-core": "1.65.1"
56
59
  }
57
60
  }
@@ -1,5 +1,5 @@
1
1
  import { ApiAuthenticationRequiredError } from "./api-authentication.js";
2
- import { PlanStateConfigurationError } from "./plan-state.js";
2
+ import { isUuidV7, PlanStateConfigurationError } from "./plan-state.js";
3
3
 
4
4
  const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
5
5
 
@@ -27,6 +27,11 @@ export class FirstDraftProtocolError extends Error {
27
27
  * has one row for each, and test/service-endpoints.test.js compares the two.
28
28
  */
29
29
  export const SERVICE_ROUTES = {
30
+ startProject: { method: "PUT", path: "/v1/projects/{project_id}" },
31
+ publishSketches: {
32
+ method: "PUT",
33
+ path: "/v1/projects/{project_id}/sketch-reviews/{revision_id}",
34
+ },
30
35
  pushPlan: {
31
36
  method: "PUT",
32
37
  path: "/v1/projects/{project_id}/foundation-plan",
@@ -192,6 +197,60 @@ export function isProblemBody(response, body) {
192
197
  );
193
198
  }
194
199
 
200
+ /** @param {Response} response @param {unknown} body */
201
+ export function reviewConflict(response, body) {
202
+ if (
203
+ responseMediaType(response) !== "application/problem+json" ||
204
+ !isRecord(body) ||
205
+ body.status !== response.status ||
206
+ typeof body.detail !== "string"
207
+ )
208
+ return null;
209
+ if (!(
210
+ (body.code === "sketch_review_changed" && body.status === 412) ||
211
+ (body.code === "sketch_review_conflict" && body.status === 409)
212
+ ))
213
+ return null;
214
+ const review = body.current_review;
215
+ const head = body.head_sha256;
216
+ if (
217
+ head !== null &&
218
+ (typeof head !== "string" || !/^[a-f0-9]{64}$/.test(head))
219
+ )
220
+ return null;
221
+ if (
222
+ review !== null &&
223
+ !(
224
+ isRecord(review) &&
225
+ isUuidV7(review.id) &&
226
+ typeof review.plan_sha256 === "string" &&
227
+ /^[a-f0-9]{64}$/.test(review.plan_sha256)
228
+ )
229
+ )
230
+ return null;
231
+ return {
232
+ ...(validGraphVersion(body.head_graph_version)
233
+ ? { head_graph_version: body.head_graph_version }
234
+ : {}),
235
+ code: body.code,
236
+ status: body.status,
237
+ detail: body.detail,
238
+ current_review: review && {
239
+ ...(validGraphVersion(review.graph_version)
240
+ ? { graph_version: review.graph_version }
241
+ : {}),
242
+ id: review.id,
243
+ plan_sha256: review.plan_sha256,
244
+ },
245
+ head_sha256: head,
246
+ };
247
+ }
248
+
249
+ /** @param {unknown} value @returns {value is number} */
250
+ function validGraphVersion(value) {
251
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
252
+ }
253
+
195
254
  /**
196
255
  * The fields of a problem that isProblemBody accepted, and nothing else.
197
256
  *