@firstdraft.com/cli 0.9.0 → 0.10.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/errors.md CHANGED
@@ -5,10 +5,14 @@ This page owns handled-error interpretation, retry safety, and recovery guidance
5
5
 
6
6
  ## Handled output contract
7
7
 
8
- Every handled subcommand failure ends with exactly one JSON object on standard error. `plan compile` may first write
9
- progress lines; machine consumers can remove only lines beginning with the exact `First Draft: ` prefix and parse the
8
+ Every handled subcommand failure ends with exactly one JSON object on standard error. Any network command may first
9
+ write one [update or stop line](commands.md#update-line-and-refusals), and `plan compile` may first write progress lines;
10
+ both begin with the exact `First Draft: ` prefix, so machine consumers can remove only those lines and parse the
10
11
  remaining JSON document. `login` may first write its human-readable authorization instructions; its JSON object
11
- starts on the line after them. Branch on the stable `error` value rather than the human-readable `detail`.
12
+ starts on the line after them. `report` and `note` print what they send on standard output before sending it, so
13
+ standard output may hold that preview when they fail. `start`, `login --no-wait`, and `login --finish` print their plain
14
+ sentences for the agent on standard output, which holds them when the command fails. Branch on the stable `error`
15
+ value rather than the human-readable `detail`.
12
16
 
13
17
  Handled output never includes command arguments, local Plan bytes, raw artifact bytes, raw filesystem or network
14
18
  errors, or unvalidated response bodies. `local_state_not_saved` is the sole exception to private-state redaction:
@@ -29,13 +33,25 @@ used. The CLI never substitutes one environment's credential for another's. Run
29
33
  environment (with `--staging` or the same `FIRSTDRAFT_API_URL`), or refresh the environment token, then follow the
30
34
  command's recovery instructions below. If a saved login is rejected, run `firstdraft login` again.
31
35
 
36
+ From `start`, `authentication_required` means it is not ready: no token exists for the origin, so it made no
37
+ request, or First Draft rejected the token it sent. Its standard output says which and names the next step: the
38
+ [agent's two login steps](commands.md#log-in-from-an-agent), or, for a rejected environment token, asking the person
39
+ to replace or unset it. No handled error from `start` carries `response`, so none repeats text First Draft wrote.
40
+
32
41
  ## Login and logout errors
33
42
 
34
43
  `login` and `logout` never print a token. A local credential failure can occur after the server has issued or revoked a token.
35
44
 
36
- - `authorization_denied`: the approval was denied in the browser. Run `firstdraft login` again to retry.
37
- - `authorization_expired`: no loopback callback arrived within five minutes, or the device code expired before
38
- approval. Run `firstdraft login` again. Use `--interactive` if no browser on this machine can reach the printed URL.
45
+ - `authorization_denied`: the approval was denied in the browser. Run `firstdraft login` again to retry. After
46
+ `login --finish`, the person refused: ask them before starting another login with `login --no-wait`.
47
+ - `authorization_expired`: no loopback callback arrived within five minutes, or the device code expired before the
48
+ CLI received a token. Run `firstdraft login` again. Use `--interactive` if no browser on this machine can reach the printed URL.
49
+ After `login --finish`, start again with `login --no-wait`, which prints a new link and code.
50
+ - `authorization_pending`, from `login --finish`: First Draft has not confirmed an approval yet, and the CLI stopped after its
51
+ short wait. The link and the code still work until the time it prints; when the person says they approved, run
52
+ `login --finish` again.
53
+ - `login_not_started`, from `login --finish`: no waiting login started with `login --no-wait` exists for the
54
+ selected origin, or it already ended. Run `firstdraft start` to see whether this computer is logged in.
39
55
  - `login_failed`: the login could not be completed. `reason`, when present, is the server's OAuth error code (for
40
56
  example `invalid_grant` for a used, expired, or mismatched code), `loopback_unavailable` when the local listener
41
57
  could not start, `credentials_invalid` / `credentials_unavailable` when the credentials file could not be read or
@@ -44,6 +60,11 @@ command's recovery instructions below. If a saved login is rejected, run `firstd
44
60
  request was made; repair or remove the file and retry. With `phase: "write"`, First Draft issued a token but the
45
61
  CLI could not save it. Revoke that new token on the selected origin's `/api-tokens` page, then repair the
46
62
  credentials file and retry login. Any previously saved token remains unchanged when the replacement fails.
63
+ `device_login_invalid` or `device_login_unavailable` means the waiting device login, `device-login.json` at
64
+ `credentials_path`, was malformed or could not be read, written, or removed; it carries no `phase`. Remove that
65
+ file, then run `firstdraft start` to see whether this computer is logged in. From `login --finish`, `reason`
66
+ `invalid_grant` means the grant is spent and its file was removed: start again with `login --no-wait`. Any other
67
+ poll failure, such as a network failure or a server error, keeps the file, so `login --finish` can run again.
47
68
  - `logout_failed`: the credentials file could not be read or updated. It carries `reason`, `credentials_path`,
48
69
  and `phase`. With `phase: "read"`, no token was revoked or removed; repair or remove the file and retry. With
49
70
  `phase: "write"`, local removal failed after the revocation attempt. `revoked: true` means First Draft confirmed
@@ -59,23 +80,56 @@ command's recovery instructions below. If a saved login is rejected, run `firstd
59
80
  invalid. A logout whose server revocation is not confirmed still succeeds after removing the local entry. It
60
81
  writes a note on standard error; revoke the token on `/api-tokens` if it may still be active.
61
82
 
83
+ ## Update and limit errors
84
+
85
+ These errors replace a command's result when a First Draft response told the CLI to stop before the command
86
+ finished. The CLI finishes handling that response, so a push it accepted still saves its ETag, and then sends
87
+ nothing more. When the stopping response was the command's last, the command reports its own result instead, after
88
+ one `First Draft: ` line that names the required update ([update line and refusals](commands.md#update-line-and-refusals)).
89
+ `start` always reports the error, because a setup that must update is not ready.
90
+
91
+ - `update_required`: First Draft's `FirstDraft-Minimum-Plugin` is newer than this setup's plugin, or, when no plugin
92
+ version is set, its `FirstDraft-Minimum-CLI` is newer than this CLI. `plugin_version` and `minimum_plugin_version`,
93
+ or `minimum_cli_version`, name the versions, beside `cli_version`. Tell the person to update with the steps at `update_url` (`https://firstdraft.com/update`), then run the
94
+ same command again with the same options; the CLI saved the ETag of any push that First Draft accepted. When
95
+ `current` is present, a Compilation had already started: follow `current.compilation.id` with
96
+ `compilation status` instead of compiling again.
97
+ - `api_contract_unsupported`: First Draft serves an API contract outside `accepted_api_contract`. When `api_contract`
98
+ is newer, update and continue as above. When it is older, the CLI is newer than that origin's Service; use the CLI
99
+ that the origin supports.
100
+ - `rate_limited`: First Draft answered `429` because a limit was reached. The refused request did nothing.
101
+ `response.code`, when present, names the limit: `compilation_limit_reached` or `project_limit_reached` for the Compilations or
102
+ new Projects an account may start in a day, and `reports_rate_limited` for its reports in an hour.
103
+ `response.detail` says when the next one can start, and `retry_at`, when present, is that UTC time from
104
+ `Retry-After`. Wait until then and run the command again; without either, the detail says to wait a minute. `login --interactive` meets
105
+ a limit shared by every CLI that starts a device login at once. When `current` is present, follow that Compilation
106
+ as above instead.
107
+
108
+ A local failure while handling the stopping response, such as `local_state_not_saved` or `materialization_failed`,
109
+ is reported as itself, with its recovery data, after the stop line.
110
+
62
111
  ## Ambiguous mutations
63
112
 
64
- `plan compile` supplies `phase: "push" | "compilation" | "publication"` when `request_outcome_unknown` requires
113
+ `plan compile` supplies `phase: "push" | "compilation"` when `request_outcome_unknown` requires
65
114
  phase-specific recovery:
66
115
 
67
- - `phase: "push"` means the Plan mutation may have been accepted. Stop and reconcile local Head state. Until First
68
- Draft has a Foundation Plan Head reconciliation endpoint, an accepted request whose response cannot be verified
69
- may require manual recovery. Do not construct an ETag from the Plan digest or trust an unverified response.
70
- - `phase: "compilation"` means a local Compilation (the default mode, with optional `--output`) may have started, but its retained identity is unknown.
71
- The CLI never repeats that `POST`. Do not start another Compilation until the Project is reconciled through First
72
- Draft or an operator can identify the retained work.
73
- - `phase: "publication"` means the singleton Publication mutation was not resolved. Do not run concurrent Compile
74
- commands. After the prior invocation exits, wait and rerun `plan compile --github` with unchanged Plan bytes to safely
75
- reconcile or resume the retained singleton.
76
-
77
- `plan push` also reports `request_outcome_unknown` if a failure happens after sending its request. Local state remains
78
- unchanged. Stop and reconcile rather than assuming the request failed and repeating the mutation.
116
+ - `phase: "push"`, and `request_outcome_unknown` from `plan push`, mean the Plan may have been accepted, but the
117
+ response could not be verified, so local state was not changed. Run the same command once more, with the same
118
+ options and environment; a first push without a pinned origin otherwise goes to production. If First Draft accepts
119
+ it, carry on. If it answers `server_rejected` with status `412` (`precondition_failed`), its Plan is no longer the
120
+ one this folder last pushed: the first push may have landed, or another copy of the Project pushed. If another
121
+ copy holds newer work, continue from that copy. Otherwise start a new Project, which forks this one: run
122
+ `firstdraft plan init --name <name>` in a new folder, copy `.firstdraft/foundation-plan.json` from the old folder
123
+ over the new one, and push or compile from there with the same options and the old folder's origin: the `api_url`
124
+ in its `.firstdraft/state.json`, or, when a first push never saved one, the origin that push used. Select it with
125
+ `--staging` for staging, or the same `FIRSTDRAFT_API_URL` for a custom origin. A new folder has no pinned origin,
126
+ so without one the push goes to production. Never construct an ETag from the Plan
127
+ digest or edit `.firstdraft/state.json`.
128
+ - `phase: "compilation"` means the Compilation may have started, but its identity is unknown. The CLI never repeats that
129
+ `POST` itself. Run the same `plan compile` command, with the same options and environment, once more. If a Compilation
130
+ is still active, First Draft refuses with `compilation_active` and names it; follow
131
+ [stuck Compilation recovery](#stuck-compilation-recovery). Otherwise the rerun starts a new Compilation; one that the
132
+ first attempt may have started costs only service time and one of the day's Compilations.
79
133
 
80
134
  If a verified Plan response cannot replace local state, preserve the printed `recovery_state`; an adjacent `.tmp`
81
135
  file may contain the same private recovery copy. Do not push again until the accepted ETag state is repaired.
@@ -95,12 +149,12 @@ starts a new Compilation after analysis.
95
149
 
96
150
  ## Direct Compilation recovery
97
151
 
98
- Do not blindly rerun `plan compile` after its Compilation start was accepted or may have been accepted.
99
- That command creates new work; it is not a retained-Compilation reconciliation command.
152
+ Do not rerun `plan compile` after its Compilation start was accepted: that command creates new work; it is not a
153
+ retained-Compilation reconciliation command.
100
154
 
101
155
  If `request_outcome_unknown` reports `phase: "compilation"`, the start request did not yield a validated retained
102
- ID. The CLI sent exactly one `POST` and did not retry it. Stop until First Draft or an operator can reconcile the
103
- Project and identify whether work was retained.
156
+ ID. The CLI sent exactly one `POST` and did not retry it. Rerun `plan compile` once, as
157
+ [ambiguous mutations](#ambiguous-mutations) describes.
104
158
 
105
159
  Once the start response has yielded a validated retained Compilation, later status, artifact, authentication, and
106
160
  materialization failure envelopes include that last validated projection as `current`. Preserve
@@ -161,56 +215,103 @@ Cancel never changes a succeeded or failed Compilation, and repeating it is safe
161
215
  - `invalid_compilation_status` means the response violated the Compilation contract, so the cancellation may or may
162
216
  not have happened. Check with `compilation status` rather than repeating the unchanged request.
163
217
 
164
- ## Publication recovery
165
-
166
- The Publication is a Project singleton. If its initial conditional `PUT` is ambiguous, the CLI attempts one
167
- read-only singleton `GET` and never automatically repeats the mutation in that invocation.
168
-
169
- After `publication_status_unavailable` or `publication_wait_timed_out`, retained work may still continue. Do not run
170
- concurrent Compile commands. Wait, then rerun `plan compile --github` with unchanged Plan bytes; the conditional request
171
- safely reconciles or resumes the same retained singleton without creating another Compilation, repository, or push.
172
- The same recovery applies when an invocation exits after an unresolved Publication start.
173
-
174
- A GitHub preflight retry with no `retry_at` is paused and requires operator recovery. `publication_failed` and
175
- `publication_cancelled` are terminal; inspect the validated phase and failure information rather than blindly
176
- retrying. `publication_changed` means the pinned Publication identity or provenance changed, so the CLI deliberately
177
- stopped without following the replacement.
218
+ ## Report and note errors
219
+
220
+ `report progress`, `report failure`, and the `note` commands never stop an agent's work. Each reads the account first
221
+ and sends nothing unless it has reports on. With reports off, the command exits 0 with a line that says so; that is not
222
+ an error.
223
+
224
+ - `report_rejected`, `note_rejected`: First Draft refused the report or note and kept nothing. `response.code` says
225
+ why, for example `compilation_not_found` when the Compilation is not in this Project, `compilation_not_succeeded`
226
+ when it produced no code, or `invalid_report` or `invalid_note` when a field breaks its shape. Continue without it.
227
+ - `report_unavailable`, `note_unavailable`: a network failure, timeout, server error, or a success without First
228
+ Draft's `201` acknowledgment left the outcome unconfirmed, and First Draft may hold the report or note. Continue
229
+ without it rather than sending it again.
230
+ - `compilation_not_recorded`: a report, or a note about generated code, named no Compilation, and the CLI has none
231
+ [recorded](commands.md#record-the-compilation-whose-code-was-written) for this Project, so nothing was sent. Name the
232
+ Compilation the code came from: put `compilation.id` from `plan compile` right after `report progress` or
233
+ `report failure`, or pass it to a note with `--compilation-id`.
234
+ - `note_incomplete` (exit 2): a field the note needs had nothing left after shaping, so nothing was sent. `detail` names
235
+ each such field and why. Write the field again in plain words, or give a page or code in its shape.
236
+ - `account_unavailable`: `account` could not read the account. This read-only request is safe to retry.
237
+ `invalid_server_response` from `account` means the response broke its contract. From a report or note command,
238
+ either error means the account read failed, so nothing was sent; continue without it.
239
+
240
+ ## Maintenance recovery
241
+
242
+ The index and `show` only read, so they are safe to retry a bounded number of times. A deferral, a question, and a
243
+ resolution are not. After an unconfirmed deferral or question, run `maintain` and reassess the item before sending it
244
+ again: a deferred item is left out of the index, and an item that reopened since is back without its deferral or
245
+ question. When a resolution's result is unconfirmed, it may have succeeded, and a newer error may since have reopened
246
+ the item; repeating it would dismiss that recurrence. Run `maintain show` and reassess the item before resolving
247
+ again. First Draft refuses to resolve an item that is still resolved, with `maintain_rejected` and
248
+ `409 item_already_resolved`.
249
+
250
+ - `maintain_rejected` means First Draft refused and nothing changed; `response.code` says why.
251
+ `404 environment_not_found` means this account has no Environment of that name in the Project: check
252
+ `--environment`, the directory, and that the environment and login match the Project's. `404 item_not_found` means
253
+ the Environment has no such item; take IDs from the index. `400 invalid_resolution_reason` names an unaccepted
254
+ reason, `400 invalid_resolution_cause` an unaccepted cause, and `400 invalid_resolution_detail` a detail over
255
+ 1,000 characters. `400 invalid_deferral` means the `--until` time is past or more than 90 days ahead, and
256
+ `400 invalid_owner_question` a question over 500 characters. `409 item_already_resolved` from `defer` or
257
+ `ask-owner` means the item is resolved; read the index again.
258
+ - `maintain_unavailable` means a network failure, timeout, server error, or error response without a problem body
259
+ left the result unconfirmed. Retry a read. After a deferral or a question, run `maintain` and reassess the item
260
+ before sending it again. After a resolution, check the item with `maintain show` and reassess it before resolving
261
+ again. A `404` with no `response` usually means the Service at the origin the command used has no maintenance
262
+ routes: the pinned origin, or in a fresh clone the one `login` would select. Retrying will not help until that
263
+ Service is upgraded.
264
+ - `invalid_maintain_response` means a success response violated the contract; retrying the unchanged request will
265
+ not repair it. After a deferral or a question, check the index with `maintain`; after a resolution, check the
266
+ item with `maintain show`.
267
+ - The index reads the account first. When that read fails, it reads no items and ends with `account_unavailable`,
268
+ which is safe to retry, `invalid_server_response`, which retrying will not repair, or an error any request can give:
269
+ `authentication_required`, `rate_limited`, or an update refusal.
178
270
 
179
271
  ## Error index
180
272
 
181
- | Commands | `error` | Exit | Meaning |
182
- | -------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---: | ------------------------------------------------------------------------------------------------------ |
183
- | Any leaf command | `invalid_arguments` | 2 | Syntax was invalid; no request was made. |
184
- | `plan init` | `local_initialization_failed` | 1 | Initialization failed without overwriting an existing path. |
185
- | Network commands | `invalid_configuration` | 2 | API origin or saved Head state is incompatible. |
186
- | `login` | `authorization_denied`, `authorization_expired` | 1 | The approval was denied, or not granted before the callback wait or device code expired. |
187
- | `login` | `login_failed` | 1 | Nothing was saved; `phase: "write"` means a token was issued ([recovery](#login-and-logout-errors)). |
188
- | `logout` | `logout_failed` | 1 | Check `phase` and `revoked`; revocation may have happened ([recovery](#login-and-logout-errors)). |
189
- | Network commands | `authentication_required` | 1 | No environment or saved token exists for the origin, or First Draft rejected it. |
190
- | Plan commands, `compilation *` | `local_input_unreadable` | 1 | Required local Plan or private state could not be read. |
191
- | Status, Compile, Compilation commands | `project_not_pushed` | 1 | No API origin is pinned for the local Project. |
192
- | `plan push`, `plan compile` | `request_outcome_unknown` | 1 | A mutation or its response could not be verified; `plan compile` identifies its mutation phase. |
193
- | `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`. |
194
- | `plan push`, `plan compile` | `server_rejected` | 1 | First Draft returned validated Plan diagnostics or rejected the request with a validated problem. |
195
- | `plan status` | `server_rejected` | 1 | First Draft rejected the analysis status request with a validated non-authentication problem. |
196
- | `plan status` | `status_unavailable`, `invalid_server_response` | 1 | The analysis read failed or violated its protocol. |
197
- | `plan compile` | `analysis_status_unavailable`, `invalid_analysis_status`, `analysis_status_rejected` | 1 | The bounded analysis read failed, was invalid, or was rejected. |
198
- | Analysis waits | `analysis_changed`, `wait_timed_out`, `analysis_wait_timed_out` | 1 | The pinned analysis changed or remained processing at the deadline. |
199
- | `plan compile` | `plan_not_valid` | 1 | Analysis completed without `valid`; `current` contains diagnostics and status. |
200
- | `plan compile` | `local_plan_changed` | 1 | Local bytes or saved state changed after acceptance, before the selected mutation. |
201
- | `plan compile` | `compilation_start_rejected`, `compilation_status_unavailable`, `invalid_compilation_status` | 1 | Direct start was rejected or retained status failed; post-start errors include `current`. |
202
- | `plan compile` | `compilation_changed`, `compilation_wait_timed_out`, `compilation_failed`, `compilation_cancelled` | 1 | The pinned direct Compilation changed, timed out, failed, or was cancelled. |
203
- | `plan compile --github` | `publication_start_rejected`, `publication_status_unavailable`, `invalid_publication_status` | 1 | Publication start or status failed its validated transport contract. |
204
- | `plan compile --github` | `publication_changed`, `publication_wait_timed_out`, `publication_failed`, `publication_cancelled` | 1 | The pinned Publication changed, timed out, or reached a non-success terminal state. |
205
- | `compilation status`, `compilation download` | `compilation_status_unavailable`, `invalid_compilation_status` | 1 | The retained status could not be read or violated its exact contract. |
206
- | `compilation status --wait` | `compilation_changed`, `compilation_wait_timed_out` | 1 | Retained identity/provenance changed or the wait ended. |
207
- | `compilation download` | `compilation_not_succeeded` | 1 | Status was not `succeeded`; no artifact request was made. |
208
- | `compilation cancel` | `compilation_cancel_rejected` | 1 | Nothing was cancelled; `response.code` says why ([recovery](#stuck-compilation-recovery)). |
209
- | `compilation cancel` | `compilation_cancel_unavailable` | 1 | The cancellation could not be confirmed; repeating it is safe. |
210
- | `compilation cancel` | `invalid_compilation_status` | 1 | The response violated the Compilation contract; check status before repeating. |
211
- | Download commands | `artifact_unavailable`, `invalid_artifact` | 1 | Artifact transport or integrity validation failed; direct Compile post-start errors include `current`. |
212
- | Download commands | `invalid_output_path` | 2 | The absent destination or root-adoption preconditions failed; `reason` identifies the stable refusal. |
213
- | Download commands | `materialization_failed` | 1 | The output changed or its transaction failed; `reason` identifies incomplete rollback when applicable. |
273
+ | Commands | `error` | Exit | Meaning |
274
+ | ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | ---: | ---------------------------------------------------------------------------------------------------------------------------- |
275
+ | Any leaf command | `invalid_arguments` | 2 | Syntax was invalid; no request was made. |
276
+ | 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
+ | Network commands except `logout` | `rate_limited` | 1 | First Draft refused a request at a limit; `retry_at` says when to try again. |
278
+ | `plan init` | `local_initialization_failed` | 1 | Initialization failed without overwriting an existing path. |
279
+ | Network commands | `invalid_configuration` | 2 | API origin or saved Head state is incompatible. |
280
+ | `login` | `authorization_denied`, `authorization_expired` | 1 | The approval was denied, or the callback wait or device code ended before the CLI received a token. |
281
+ | `login --finish` | `authorization_pending`, `login_not_started` | 1 | First Draft has not confirmed an approval yet, or no device login is waiting for the origin. |
282
+ | `login` | `login_failed` | 1 | Nothing was saved; `phase: "write"` means a token was issued ([recovery](#login-and-logout-errors)). |
283
+ | `logout` | `logout_failed` | 1 | Check `phase` and `revoked`; revocation may have happened ([recovery](#login-and-logout-errors)). |
284
+ | Network commands | `authentication_required` | 1 | No environment or saved token exists for the origin, or First Draft rejected it. |
285
+ | 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. |
287
+ | `plan push`, `plan compile` | `request_outcome_unknown` | 1 | A mutation or its response could not be verified; `plan compile` identifies its mutation phase. |
288
+ | `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
+ | `plan push`, `plan compile` | `server_rejected` | 1 | First Draft returned validated Plan diagnostics or rejected the request with a validated problem. |
290
+ | `plan status` | `server_rejected` | 1 | First Draft rejected the analysis status request with a validated non-authentication problem. |
291
+ | `plan status` | `status_unavailable`, `invalid_server_response` | 1 | The analysis read failed or violated its protocol. |
292
+ | `plan compile` | `analysis_status_unavailable`, `invalid_analysis_status`, `analysis_status_rejected` | 1 | The bounded analysis read failed, was invalid, or was rejected. |
293
+ | Analysis waits | `analysis_changed`, `wait_timed_out`, `analysis_wait_timed_out` | 1 | The pinned analysis changed or remained processing at the deadline. |
294
+ | `plan compile` | `plan_not_valid` | 1 | Analysis completed without `valid`; `current` contains diagnostics and status. |
295
+ | `plan compile` | `local_plan_changed` | 1 | Local bytes or saved state changed after acceptance, before the selected mutation. |
296
+ | `plan compile` | `compilation_start_rejected`, `compilation_status_unavailable`, `invalid_compilation_status` | 1 | Direct start was rejected or retained status failed; post-start errors include `current`. |
297
+ | `plan compile` | `compilation_changed`, `compilation_wait_timed_out`, `compilation_failed`, `compilation_cancelled` | 1 | The pinned direct Compilation changed, timed out, failed, or was cancelled. |
298
+ | `compilation status`, `compilation download` | `compilation_status_unavailable`, `invalid_compilation_status` | 1 | The retained status could not be read or violated its exact contract. |
299
+ | `compilation status --wait` | `compilation_changed`, `compilation_wait_timed_out` | 1 | Retained identity/provenance changed or the wait ended. |
300
+ | `compilation download` | `compilation_not_succeeded` | 1 | Status was not `succeeded`; no artifact request was made. |
301
+ | `compilation cancel` | `compilation_cancel_rejected` | 1 | Nothing was cancelled; `response.code` says why ([recovery](#stuck-compilation-recovery)). |
302
+ | `compilation cancel` | `compilation_cancel_unavailable` | 1 | The cancellation could not be confirmed; repeating it is safe. |
303
+ | `compilation cancel` | `invalid_compilation_status` | 1 | The response violated the Compilation contract; check status before repeating. |
304
+ | Download commands | `artifact_unavailable`, `invalid_artifact` | 1 | Artifact transport or integrity validation failed; direct Compile post-start errors include `current`. |
305
+ | Download commands | `invalid_output_path` | 2 | The absent destination or root-adoption preconditions failed; `reason` identifies the stable refusal. |
306
+ | Download commands | `materialization_failed` | 1 | The output changed or its transaction failed; `reason` identifies incomplete rollback when applicable. |
307
+ | `account`, `start`, `maintain` | `account_unavailable`, `invalid_server_response` | 1 | The account read failed or violated its contract. |
308
+ | `report progress`, `report failure` | `report_rejected`, `report_unavailable`, `account_unavailable`, `invalid_server_response` | 1 | The report was refused or its outcome is unconfirmed, or the account read failed; continue without it. |
309
+ | `note <kind>` | `note_rejected`, `note_unavailable`, `account_unavailable`, `invalid_server_response` | 1 | The note was refused or its outcome is unconfirmed, or the account read failed; continue without it. |
310
+ | `report`, `note wrong_output` | `compilation_not_recorded` | 1 | No Compilation was given or recorded; nothing was sent ([recovery](#report-and-note-errors)). |
311
+ | `note <kind>` | `note_incomplete` | 2 | A field the note needs had nothing left after shaping; nothing was sent. |
312
+ | `maintain` commands | `maintain_rejected` | 1 | Refused with a validated problem; `response.code` says why ([recovery](#maintenance-recovery)). |
313
+ | `maintain` commands | `maintain_unavailable` | 1 | The request failed or its result is unconfirmed; retry a read, and reassess the item before any write again. |
314
+ | `maintain` commands | `invalid_maintain_response` | 1 | A success response violated the contract; retrying unchanged will not repair it. |
214
315
 
215
316
  Root-output `invalid_output_path.reason` values are `destination_exists`, `root_not_real`, `root_not_writable`,
216
317
  `root_platform_unsupported`, `root_reserved_path`, `root_entry_unsupported`, `root_enclosing_worktree`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firstdraft.com/cli",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Command-line interface for First Draft",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -50,5 +50,8 @@
50
50
  "globals": "17.8.0",
51
51
  "prettier": "3.9.6",
52
52
  "typescript": "7.0.2"
53
+ },
54
+ "overrides": {
55
+ "minimatch": "^11.0.5"
53
56
  }
54
57
  }
@@ -0,0 +1,210 @@
1
+ import { STAGING_API_URL } from "./api-authentication.js";
2
+
3
+ // The plain sentences the CLI prints for an agent, kept here so they are
4
+ // written once. `firstdraft start` and the two steps of the agent's device
5
+ // login print only these, besides the update line every command shares
6
+ // (src/service-client.js), and `firstdraft maintain` prints one of them
7
+ // beside its JSON. A First Draft answer only chooses among them, and
8
+ // the only values they carry are an origin, versions, a token variable's
9
+ // name, and a device login's validated link, user code, and expiry.
10
+ // docs/commands.md quotes them and the Skill copies them, so a change here is
11
+ // a change to both.
12
+
13
+ /**
14
+ * A command the agent can run as printed. A staging origin adds the flag that
15
+ * selects it; a custom origin keeps coming from FIRSTDRAFT_API_URL.
16
+ *
17
+ * @param {string} origin
18
+ * @param {string} command
19
+ */
20
+ export function commandLine(origin, command) {
21
+ return `'firstdraft ${command}${origin === STAGING_API_URL ? " --staging" : ""}'`;
22
+ }
23
+
24
+ /** @param {{cli: string, plugin: string | null}} versions */
25
+ export function versionLine({ cli, plugin }) {
26
+ return plugin === null
27
+ ? `First Draft CLI ${cli}.`
28
+ : `First Draft CLI ${cli} with plugin ${plugin}.`;
29
+ }
30
+
31
+ /**
32
+ * Whether a token for `origin` is saved on this computer or set in the
33
+ * environment, which takes precedence.
34
+ *
35
+ * @param {{origin: string, saved: boolean, environmentVariable: string | null}} login
36
+ */
37
+ export function loginLines({ origin, saved, environmentVariable }) {
38
+ return [
39
+ saved
40
+ ? `This computer has a saved login for ${origin}.`
41
+ : `This computer has no saved login for ${origin}.`,
42
+ ...(environmentVariable === null
43
+ ? []
44
+ : [
45
+ `${environmentVariable} is set, so the CLI uses that token in place of any saved login for ${origin}, and no login is needed.`,
46
+ ]),
47
+ ];
48
+ }
49
+
50
+ /** @param {string} origin */
51
+ export function loginSteps(origin) {
52
+ return [
53
+ `To log in, run ${commandLine(origin, "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.`,
54
+ `When the person says they approved, run ${commandLine(origin, "login --finish")}, then run ${commandLine(origin, "start")} again.`,
55
+ ];
56
+ }
57
+
58
+ /** @param {string | null} environmentVariable */
59
+ export function readyLine(environmentVariable) {
60
+ return environmentVariable === null
61
+ ? "Ready: First Draft accepted this computer's login."
62
+ : `Ready: First Draft accepted ${environmentVariable}.`;
63
+ }
64
+
65
+ /**
66
+ * @param {string} origin
67
+ * @param {string | null} environmentVariable
68
+ */
69
+ export function rejectedLoginLines(origin, environmentVariable) {
70
+ return environmentVariable === null
71
+ ? [
72
+ `Not logged in: First Draft did not accept the saved login for ${origin}.`,
73
+ ...loginSteps(origin),
74
+ ]
75
+ : [
76
+ `Not logged in: First Draft did not accept ${environmentVariable}. Ask the person to replace it or unset it; while it is set, the CLI uses no saved login.`,
77
+ ];
78
+ }
79
+
80
+ /**
81
+ * Printed when the person said yes to reports, and only then: the agent of a
82
+ * person who said no hears nothing about reports or notes. One yes covers
83
+ * both, so any command that tells the agent about reports prints these same
84
+ * sentences, followed by NOTES_ON_LINES.
85
+ */
86
+ export const REPORTS_ON_LINES = Object.freeze([
87
+ "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.",
88
+ "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.",
89
+ "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.",
90
+ "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'.",
91
+ "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.",
92
+ ]);
93
+
94
+ /** The notes half of what REPORTS_ON_LINES introduces, printed right after it. */
95
+ export const NOTES_ON_LINES = Object.freeze([
96
+ "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'.",
97
+ "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.",
98
+ "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.",
99
+ "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.",
100
+ "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.",
101
+ ]);
102
+
103
+ /**
104
+ * What `firstdraft maintain` prints on standard error when the person said
105
+ * yes to reports, and only then. An item's evidence can hold end users' text,
106
+ * so the report carries none of it.
107
+ */
108
+ export const MAINTAIN_REPORTS_ON_LINE =
109
+ "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.";
110
+
111
+ /**
112
+ * What a maintain command prints on standard error when it found no Project
113
+ * state and read the Project from the
114
+ * application's .firstdraft/gaps.json, as in a fresh clone. That file holds
115
+ * no origin, so the line says which origin it used. It says nothing about
116
+ * reports, which the agent of a person who said no never hears about.
117
+ *
118
+ * @param {string} origin
119
+ */
120
+ export function applicationProjectLine(origin) {
121
+ return `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.`;
122
+ }
123
+
124
+ /**
125
+ * @typedef {object} DeviceLoginLink
126
+ * @property {string} origin
127
+ * @property {string} userCode
128
+ * @property {string} verificationUri
129
+ * @property {string | undefined} verificationUriComplete
130
+ * @property {number} expiresAt epoch milliseconds
131
+ */
132
+
133
+ /**
134
+ * What `login --no-wait` prints. The device code is a credential and never
135
+ * appears; the link and the user code are for the person.
136
+ *
137
+ * @param {DeviceLoginLink & {expiresIn: number}} login
138
+ */
139
+ export function deviceLoginStartedLines(login) {
140
+ const minutes = Math.max(1, Math.floor(login.expiresIn / 60));
141
+ return [
142
+ ...linkLines(login),
143
+ `The link and the code expire in ${minutes} ${minutes === 1 ? "minute" : "minutes"}, at ${utcTime(login.expiresAt)}.`,
144
+ `When the person says they approved, run ${commandLine(login.origin, "login --finish")}.`,
145
+ ];
146
+ }
147
+
148
+ /** @param {string} origin */
149
+ export function deviceLoginFinishedLines(origin) {
150
+ return [
151
+ `Logged in: this computer is now logged in to ${origin}.`,
152
+ `Run ${commandLine(origin, "start")} again.`,
153
+ ];
154
+ }
155
+
156
+ /** @param {DeviceLoginLink} login */
157
+ export function deviceLoginPendingLines(login) {
158
+ return [
159
+ "Still waiting: First Draft has not confirmed that the person approved the login.",
160
+ ...linkLines(login),
161
+ `The link and the code expire at ${utcTime(login.expiresAt)}. When the person says they approved, run ${commandLine(login.origin, "login --finish")} again.`,
162
+ ];
163
+ }
164
+
165
+ /** @param {string} origin */
166
+ export function deviceLoginExpiredLines(origin) {
167
+ return [
168
+ `Expired: the link and the code expired before this computer finished the login, so no new login was saved for ${origin}.`,
169
+ `To try again, run ${commandLine(origin, "login --no-wait")}.`,
170
+ ];
171
+ }
172
+
173
+ /** @param {string} origin */
174
+ export function deviceLoginRefusedLines(origin) {
175
+ return [
176
+ `Refused: the person denied this login, so no new login was saved for ${origin}.`,
177
+ `Ask the person before you start another login with ${commandLine(origin, "login --no-wait")}.`,
178
+ ];
179
+ }
180
+
181
+ /** @param {string} origin */
182
+ export function deviceLoginNotStartedLines(origin) {
183
+ return [
184
+ `No login is waiting: this computer has no device login for ${origin} that has not ended.`,
185
+ `Run ${commandLine(origin, "start")} to see whether this computer is logged in.`,
186
+ ];
187
+ }
188
+
189
+ /** @param {DeviceLoginLink} login */
190
+ function linkLines({
191
+ origin,
192
+ userCode,
193
+ verificationUri,
194
+ verificationUriComplete,
195
+ }) {
196
+ return verificationUriComplete === undefined
197
+ ? [
198
+ `To log in to ${origin}, ask the person to open this link in a browser, enter the code ${userCode}, and approve:`,
199
+ verificationUri,
200
+ ]
201
+ : [
202
+ `To log in to ${origin}, ask the person to open this link in a browser, check that the page shows the code ${userCode}, and approve:`,
203
+ verificationUriComplete,
204
+ ];
205
+ }
206
+
207
+ /** @param {number} milliseconds */
208
+ function utcTime(milliseconds) {
209
+ return new Date(milliseconds).toISOString().replace(/\.\d{3}Z$/, "Z");
210
+ }