From 678734480fa65cd9783929ec31347840b55b20ea Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Fri, 27 Nov 2026 18:44:25 -0600 Subject: [PATCH 1/4] Read setup from the reviewed Foundation Plan Participants need the same instructions in conversation and on the Project page. Return that page with the steps for the selected review. Use its saved origin or the Project ID in a compiled application. Move the CLI to Plan 0.24 and API 0.10 for the workshop. Refresh the synthetic release pair and check the empty GapSet digest against the service serializer. A retained Familygram Project republished and compiled 453 files. A separate Plan kept both custom provider requirements in its submitted bytes. --- CHANGELOG.md | 8 ++ docs/commands.md | 33 +++++-- docs/errors.md | 1 + package-lock.json | 4 +- package.json | 2 +- release/compatibility.json | 6 +- scripts/check-pack.js | 1 + scripts/smoke-package.js | 15 +++- src/api-response.js | 4 + src/cli.js | 126 ++++++++++++++++++++++++++ src/commands/plan-setup.js | 107 +++++++++++++++++++++++ src/compilation-artifact.js | 2 +- src/service-client.js | 2 +- test/api-environments.test.js | 1 + test/compilation-artifact.test.js | 6 +- test/compilation.test.js | 7 +- test/plan-compile.test.js | 8 +- test/plan-init.test.js | 1 + test/plan-push.test.js | 2 +- test/plan-setup.test.js | 141 ++++++++++++++++++++++++++++++ test/plan-status.test.js | 6 +- test/service-client.test.js | 34 +++---- test/start.test.js | 6 +- 23 files changed, 472 insertions(+), 51 deletions(-) create mode 100644 src/commands/plan-setup.js create mode 100644 test/plan-setup.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 74d5094..fc05730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ carry no release status. The `v` tag and npm show whether a version is Entries start with the first version prepared after this file was added, and earlier versions have none. The repository's [tags](https://github.com/firstdraft/cli/tags) identify the source of each published version. +## 0.12.0 + +- Run `firstdraft plan setup` after publishing the Plan to read its setup steps and get the corresponding Project + link. Use `--revision ` for a particular Sketches review. Workshop participants can add `--workshop` for + the Revyl iPhone preview. +- This CLI creates Plans and accepts Compilations in format `firstdraft.foundation-plan.sketch/0.24`. It requires + service API contract 0.10.0 or a later patch on that minor line. CLI 0.11.0 remains the release for API 0.9.1. + ## 0.11.0 - Run `firstdraft project start` to get a hosted Project URL before writing the Plan. The command reserves the local diff --git a/docs/commands.md b/docs/commands.md index cce7a65..2fdd832 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -3,12 +3,12 @@ This page owns the detailed public semantics of the current command surface. Run `firstdraft --help` or a command group's `--help` for concise executable syntax. See [Errors and recovery](errors.md) before retrying a failed mutation. -The current `0.11.x` source line contains the auditable command shell, the agent's `start` check, browser and device +The current `0.12.x` source line contains the auditable command shell, the agent's `start` check, browser and device login in one command or in two steps that an agent runs, local Foundation Plan initialization, hosted Project creation and Sketch review, local application-key and UUID generation, conditional whole-document push, whole-graph analysis status polling, direct Compile-and-materialize, retained-Compilation inspection and cancellation, the account's report setting, progress and failure reports, notes, and maintenance-item listing, -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. +inspection, resolution, deferral, and owner questions. It requires API contract `0.10.0` or a later patch on the same minor line. The [changelog](https://github.com/firstdraft/cli/blob/main/CHANGELOG.md) describes each version. [What the CLI sends](#what-the-cli-sends) lists every request and what it carries. ## Command map @@ -27,6 +27,7 @@ inspection, resolution, deferral, and owner questions. It requires API contract | `firstdraft logout` | Yes | Revoke and remove the saved token for an origin | | `firstdraft plan push` | Yes | Conditionally submit the exact whole Plan | | `firstdraft plan status` | Yes | Read or wait for the current whole-graph analysis | +| `firstdraft plan setup` | Yes | Read the reviewed Plan’s setup steps and their Project link | | `firstdraft plan compile` | Yes | Compile the Plan or approved review into the current folder | | `firstdraft compilation status` | Yes | Inspect a retained Compilation by ID | | `firstdraft compilation download` | Yes | Verify and materialize a successful retained Compilation | @@ -278,6 +279,7 @@ Beyond the header, a command sends only what it needs: | `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 | | `plan push`, Plan-only `plan compile` | The exact local Plan bytes and the saved Head ETag | | `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. | +| `plan setup` | The Project ID and, when supplied, the review ID and workshop context | | `plan status`, `compilation *`, `account` | Only the IDs in the request path | | `report progress`, `report failure` | An account read; with reports on, the report printed just before | | `note ` | An account read; with reports on, the note printed just before | @@ -403,7 +405,7 @@ From the project that the Plan describes: firstdraft plan init --name "Oscar Party" ``` -This creates an empty `firstdraft.foundation-plan.sketch/0.23` Plan targeting `rails-sketch/2026-11`. In a fresh +This creates an empty `firstdraft.foundation-plan.sketch/0.24` Plan targeting `rails-sketch/2026-11`. In a fresh folder it creates the Project ID and an ignored `.firstdraft/` directory. In a folder reserved by `project start`, it writes the Plan for the existing Project ID and origin. Initialization runs locally and preserves any existing Plan. @@ -411,7 +413,7 @@ Provide either `--name`, `--application-key`, or both. Name-only initialization initialization derives a humanized display name. Supplying both preserves both values exactly after validating them against the Foundation Plan schema. -Plan `0.23` has no `application.pwa` option. The Rails target includes ordinary icons and bookmark metadata for +The Plan has no `application.pwa` option. The Rails target includes ordinary icons and bookmark metadata for the application owner to edit. The CLI sends authored bytes unchanged; the Service diagnoses unsupported Plan fields rather than the CLI removing them. These assets do not establish offline support or a complete PWA, and the CLI does not qualify browser or device installation. @@ -465,6 +467,24 @@ If a failure happens after sending the request, the CLI leaves local state uncha from the Plan digest or trusts an ETag from a response it could not fully verify. Follow [ambiguous-mutation recovery](errors.md#ambiguous-mutations) rather than blindly retrying. +## Read the reviewed Plan's setup steps + +After publishing, ask First Draft for the list the owner can reopen on the Project page. + +```sh +firstdraft plan setup +firstdraft plan setup --revision --workshop +``` + +The response includes the Project URL, the Plan digest, the review ID if the Project has Sketches, and the ordered +steps. Pass the review ID from `sketches publish` to read that version even after another review is published. +With no revision, the service selects the latest published Sketches review or the current Head of a Plan-only +Project. Use `--workshop` for the workshop’s Revyl iPhone preview. A fresh clone of a compiled application can +also identify the Project from `.firstdraft/gaps.json`, as it can for `maintain`. + +The list includes setup implied by the Plan and external requirements agreed during the interview. It describes +where a participant enters a credential. Credential values stay in the provider or application environment. + ## Read analysis status After a successful push: @@ -695,7 +715,7 @@ when a retained direct Compilation succeeded but an earlier root materialization never starts replacement work. An incomplete rollback leaves `.firstdraft-root-output` and requires journal reconciliation before this command can run again. -Artifact validation accepts only Plan format `firstdraft.foundation-plan.sketch/0.23` and target profile +Artifact validation accepts only Plan format `firstdraft.foundation-plan.sketch/0.24` and target profile `rails-sketch/2026-11`, in addition to matching the retained Compilation's provenance and verifying file integrity. An earlier format or profile is rejected before materialization, even when the retained status names that profile. @@ -1013,6 +1033,7 @@ timeout. Each request takes its method and path from one | `PUT` | `/v1/projects/{project_id}/sketch-reviews/{revision_id}` | Publish a board and working Plan | | `PUT` | `/v1/projects/{project_id}/foundation-plan` | Create or replace the Head | | `GET` | `/v1/projects/{project_id}/analysis` | Read the Head's current analysis | +| `GET` | `/v1/projects/{project_id}/setup` | Read the reviewed Plan's setup steps | | `POST` | `/v1/projects/{project_id}/compilations` | Start a Compilation of the Head | | `GET` | `/v1/projects/{project_id}/compilations/{compilation_id}` | Read one retained Compilation | | `POST` | `/v1/projects/{project_id}/compilations/{compilation_id}/cancel` | Cancel that Compilation | @@ -1048,7 +1069,7 @@ The first push sends `If-None-Match: *`. Later pushes and the Compilation start `If-Match`. The cancel `POST` sends no precondition header. The resolution, deferral, and owner-question `POST`s send a JSON body and no precondition header. -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, +The `/v1` routes require API contract `0.10.0` or a later patch on the same minor line. `API_CONTRACT_RANGE` in `src/service-client.js` declares that range, `release/compatibility.json` declares it for the Service's release compatibility check, and `test/release-compatibility.test.js` keeps the two equal. The CLI reads `FirstDraft-API-Contract` on every response and stops at a Service outside the range, as [update line and refusals](#update-line-and-refusals) describes: with diff --git a/docs/errors.md b/docs/errors.md index a3481ed..3b5fa9f 100644 --- a/docs/errors.md +++ b/docs/errors.md @@ -341,6 +341,7 @@ again. First Draft refuses to resolve an item that is still resolved, with `main | `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`. | | `plan push`, `plan compile` | `server_rejected` | 1 | First Draft returned validated Plan diagnostics or rejected the request with a validated problem. | | `plan status` | `server_rejected` | 1 | First Draft rejected the analysis status request with a validated non-authentication problem. | +| `plan setup` | `plan_setup_unavailable` | 1 | First Draft could not return the requested setup list. Confirm the review and retry the read. | | `plan status` | `status_unavailable`, `invalid_server_response` | 1 | The analysis read failed or violated its protocol. | | `plan compile` | `analysis_status_unavailable`, `invalid_analysis_status`, `analysis_status_rejected` | 1 | The bounded analysis read failed, was invalid, or was rejected. | | Analysis waits | `analysis_changed`, `wait_timed_out`, `analysis_wait_timed_out` | 1 | The pinned analysis changed or remained processing at the deadline. | diff --git a/package-lock.json b/package-lock.json index 1235583..5441673 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@firstdraft.com/cli", - "version": "0.11.0", + "version": "0.12.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@firstdraft.com/cli", - "version": "0.11.0", + "version": "0.12.0", "license": "MIT", "dependencies": { "playwright-core": "1.65.1" diff --git a/package.json b/package.json index af82857..1dcfb91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@firstdraft.com/cli", - "version": "0.11.0", + "version": "0.12.0", "description": "Command-line interface for First Draft", "license": "MIT", "type": "module", diff --git a/release/compatibility.json b/release/compatibility.json index 54e2166..f731fc5 100644 --- a/release/compatibility.json +++ b/release/compatibility.json @@ -1,9 +1,9 @@ { "format": "firstdraft.release-compatibility/1", "component": "cli", - "version": "0.11.0", + "version": "0.12.0", "requires": { - "api_contract": [">= 0.9.1", "< 0.10.0"], - "foundation_plan_formats": ["firstdraft.foundation-plan.sketch/0.23"] + "api_contract": [">= 0.10.0", "< 0.11.0"], + "foundation_plan_formats": ["firstdraft.foundation-plan.sketch/0.24"] } } diff --git a/scripts/check-pack.js b/scripts/check-pack.js index 79165a9..f36d378 100644 --- a/scripts/check-pack.js +++ b/scripts/check-pack.js @@ -50,6 +50,7 @@ if (result.status !== 0) { "src/commands/plan-compile.js", "src/commands/plan-init.js", "src/commands/plan-push.js", + "src/commands/plan-setup.js", "src/commands/plan-status.js", "src/commands/report.js", "src/commands/sketches.js", diff --git a/scripts/smoke-package.js b/scripts/smoke-package.js index aaee983..9214f59 100644 --- a/scripts/smoke-package.js +++ b/scripts/smoke-package.js @@ -251,6 +251,15 @@ try { detail: "Invalid arguments. Run 'firstdraft plan status --help' for usage.", }); + const invalidSetup = spawnPackedCli( + ["plan", "setup", "--revision", "invalid"], + installationDirectory, + ); + assertHandledFailure(invalidSetup, 2, { + error: "invalid_arguments", + detail: "Invalid arguments. Run 'firstdraft plan setup --help' for usage.", + }); + const localStatus = spawnPackedCli(["plan", "status"], installationDirectory); assertHandledFailure(localStatus, 1, { error: "local_input_unreadable", @@ -596,9 +605,9 @@ async function exercisePackedCompilation(projectDirectory) { const statusPath = `/v1/projects/${projectId}/compilations/${compilationId}`; const artifactPath = `${statusPath}/artifact`; const analyzerRelease = - "foundation-plan-rails/application-2026-09-27-bookmark-assets"; + "foundation-plan-rails/application-2026-11-25-application-mail"; const compilerRelease = - "foundation-plan-rails/compiler-application-2026-09-27-bookmark-assets"; + "foundation-plan-rails/compiler-application-2026-11-27-project-setup"; const target = { id: "rails", profile: RAILS_TARGET_PROFILE }; const gapSet = { format: "firstdraft.foundation-gaps/2", @@ -660,7 +669,7 @@ async function exercisePackedCompilation(projectDirectory) { analysis: { id: analysisId, release: - "foundation-plan-rails/application-2026-09-27-bookmark-assets", + "foundation-plan-rails/application-2026-11-25-application-mail", }, compiler_release: compilerRelease, target, diff --git a/src/api-response.js b/src/api-response.js index 688d955..298fde3 100644 --- a/src/api-response.js +++ b/src/api-response.js @@ -40,6 +40,10 @@ export const SERVICE_ROUTES = { method: "GET", path: "/v1/projects/{project_id}/analysis", }, + readPlanSetup: { + method: "GET", + path: "/v1/projects/{project_id}/setup", + }, startCompilation: { method: "POST", path: "/v1/projects/{project_id}/compilations", diff --git a/src/cli.js b/src/cli.js index 7f52b59..80b6bbc 100644 --- a/src/cli.js +++ b/src/cli.js @@ -100,6 +100,10 @@ import { SketchError, } from "./commands/sketches.js"; import { initializePlan } from "./commands/plan-init.js"; +import { + PlanSetupUnavailableError, + readPlanSetup, +} from "./commands/plan-setup.js"; import { PlanPushConfigurationError, PlanPushLocalError, @@ -406,6 +410,7 @@ Commands: init Create a local empty Foundation Plan push Send the local Foundation Plan to First Draft status Read the current whole-graph analysis status + setup Read the setup steps for a reviewed Foundation Plan compile Compile the current Foundation Plan Options: @@ -487,6 +492,17 @@ The command uses only the API origin pinned by a successful plan push. Without --wait, it makes exactly one status request. `; +const PLAN_SETUP_HELP = `First Draft CLI + +Usage: + firstdraft plan setup [--revision ] [--workshop] [--staging] + +Read the Project's setup steps and print the link to the same list in First Draft. +Use --revision to reopen a specific Sketches review. Without it, First Draft +selects the latest published review or the current Plan for a Plan-only Project. +Use --workshop when the participant will preview their iPhone app in Revyl. +`; + const PLAN_COMPILE_HELP = `First Draft CLI Usage: @@ -1389,6 +1405,24 @@ async function runPlan({ }); } + if (argv[0] === "setup") { + return runPlanSetup({ + argv: argv.slice(1), + stdout, + stderr, + cwd, + getCwd, + fetchFunction, + createRequestSignal, + apiUrl, + apiToken, + stagingApiToken, + staging, + credentials, + service, + }); + } + if (argv[0] === "compile") { return runPlanCompile({ argv: argv.slice(1), @@ -3154,6 +3188,98 @@ async function runPlanPush({ return 0; } +/** @param {ServiceCommandOptions} options */ +async function runPlanSetup(options) { + const { argv, stdout, stderr, service } = options; + const parsed = parseArguments(() => + parseArgs({ + args: [...argv], + options: { + revision: { type: "string" }, + workshop: { type: "boolean" }, + staging: { type: "boolean" }, + help: { type: "boolean", short: "h" }, + }, + allowPositionals: false, + strict: true, + tokens: true, + }), + ); + if ( + !parsed || + repeatedValueOption(parsed.tokens) || + (parsed.values.revision !== undefined && !isUuidV7(parsed.values.revision)) + ) { + writeInvalidArguments( + stderr, + "Invalid arguments. Run 'firstdraft plan setup --help' for usage.", + ); + return 2; + } + if (parsed.values.help) { + stdout.write(PLAN_SETUP_HELP); + return 0; + } + try { + const project = authenticatePinnedProject( + { ...options, staging: options.staging || parsed.values.staging }, + { fromApplication: true }, + ); + if (!project) { + writeAuthenticationRequired(stderr); + return 1; + } + const context = parsed.values.workshop ? "workshop" : "general"; + const setup = await service.settle( + readPlanSetup({ + apiUrl: project.apiUrl, + projectId: project.projectId, + revision: parsed.values.revision, + context, + fetchFunction: project.fetchFunction, + createRequestSignal: options.createRequestSignal, + }), + ); + const url = new URL("/projects/" + project.projectId, project.apiUrl); + url.searchParams.set("document", "setup"); + if (setup.review.id) url.searchParams.set("review", setup.review.id); + if (context === "workshop") url.searchParams.set("context", context); + writeJson(stdout, { + project: { id: project.projectId, url: url.href }, + ...setup, + }); + return 0; + } catch (error) { + const status = writePinnedProjectError(stderr, error); + if (status !== null) return status; + if (error instanceof PlanSetupUnavailableError) { + if (isAuthenticationProblem(error.status, error.problem)) { + writeAuthenticationRequired(stderr, error.status, error.problem); + return 1; + } + writeJson(stderr, { + error: "plan_setup_unavailable", + detail: error.message, + status: error.status, + response: error.problem, + }); + return 1; + } + if ( + error instanceof PlanPushNetworkError || + error instanceof PlanPushProtocolError + ) { + writeJson(stderr, { + error: "plan_setup_unavailable", + detail: error.message, + status: error.status, + }); + return 1; + } + throw error; + } +} + /** * @param {Pick} options */ diff --git a/src/commands/plan-setup.js b/src/commands/plan-setup.js new file mode 100644 index 0000000..6f1eedd --- /dev/null +++ b/src/commands/plan-setup.js @@ -0,0 +1,107 @@ +import { + FirstDraftProtocolError, + SERVICE_ROUTES, + isProblemBody, + problemProjection, + readResponseBody, + responseMediaType, + sendRequest, + serviceEndpoint, +} from "../api-response.js"; +import { isUuidV7 } from "../plan-state.js"; + +const STEP_TEXT_FIELDS = [ + "provider", + "title", + "purpose", + "needed", + "timing", + "destination", + "action", +]; +const STEP_FIELDS = new Set([ + "source", + ...STEP_TEXT_FIELDS, + "environment_variable", +]); + +export class PlanSetupUnavailableError extends Error { + /** + * @param {number} status + * @param {Record | null} problem + */ + constructor(status, problem) { + super("First Draft could not return this Project's setup steps."); + this.status = status; + this.problem = problem; + } +} + +/** + * @param {{apiUrl: string, projectId: string, revision?: string, + * context: "general" | "workshop", fetchFunction: typeof globalThis.fetch, + * createRequestSignal?: (timeoutMs: number) => AbortSignal}} options + */ +export async function readPlanSetup({ + apiUrl, + projectId, + revision, + context, + fetchFunction, + createRequestSignal = (timeoutMs) => AbortSignal.timeout(timeoutMs), +}) { + const endpoint = serviceEndpoint(SERVICE_ROUTES.readPlanSetup, apiUrl, { + project_id: projectId, + }); + if (revision) endpoint.url.searchParams.set("review", revision); + if (context === "workshop") endpoint.url.searchParams.set("context", context); + + const response = await sendRequest(fetchFunction, endpoint, { + headers: { Accept: "application/json, application/problem+json" }, + redirect: "error", + signal: createRequestSignal(30_000), + }); + const body = await readResponseBody(response); + if (!response.ok) { + throw new PlanSetupUnavailableError( + response.status, + isProblemBody(response, body) ? problemProjection(body) : null, + ); + } + if ( + response.status !== 200 || + responseMediaType(response) !== "application/json" || + body?.context !== context || + !body.review || + !(body.review.id === null || isUuidV7(body.review.id)) || + (revision && body.review.id !== revision) || + typeof body.review.plan_sha256 !== "string" || + !/^[0-9a-f]{64}$/.test(body.review.plan_sha256) || + !Array.isArray(body.steps) || + !body.steps.every(isSetupStep) + ) { + throw new FirstDraftProtocolError( + "First Draft returned an invalid setup list for this review.", + { status: response.status }, + ); + } + return { + review: { id: body.review.id, plan_sha256: body.review.plan_sha256 }, + context, + steps: body.steps, + }; +} + +/** @param {Record | null} step */ +function isSetupStep(step) { + return ( + step !== null && + typeof step === "object" && + (step.source === "plan" || step.source === "interview") && + Object.keys(step).every((key) => STEP_FIELDS.has(key)) && + STEP_TEXT_FIELDS.every((key) => typeof step[key] === "string") && + (step.environment_variable === undefined || + (typeof step.environment_variable === "string" && + /^[A-Z][A-Z0-9_]*$/.test(step.environment_variable))) + ); +} diff --git a/src/compilation-artifact.js b/src/compilation-artifact.js index b945d02..5c2812d 100644 --- a/src/compilation-artifact.js +++ b/src/compilation-artifact.js @@ -27,7 +27,7 @@ import { export const ARTIFACT_MEDIA_TYPE = "application/vnd.firstdraft.compilation-artifact+json"; export const ARTIFACT_FORMAT = "firstdraft.compilation-artifact/1"; -export const FOUNDATION_PLAN_FORMAT = "firstdraft.foundation-plan.sketch/0.23"; +export const FOUNDATION_PLAN_FORMAT = "firstdraft.foundation-plan.sketch/0.24"; // The one place the CLI names the Rails target profile: plan init writes it, // artifact validation accepts only it, and the documentation test requires // the docs to name only it. The value is the profile of this release. diff --git a/src/service-client.js b/src/service-client.js index 0e67c68..fb38bb4 100644 --- a/src/service-client.js +++ b/src/service-client.js @@ -15,7 +15,7 @@ export const UPDATE_URL = "https://firstdraft.com/update"; * declares the same range for the release check, and * test/release-compatibility.test.js keeps the two equal. */ -export const API_CONTRACT_RANGE = Object.freeze([">= 0.9.1", "< 0.10.0"]); +export const API_CONTRACT_RANGE = Object.freeze([">= 0.10.0", "< 0.11.0"]); /** Set by the plugin's launcher; docs/commands.md names them for wrappers. */ export const PLUGIN_VERSION_VARIABLE = "FIRSTDRAFT_PLUGIN_VERSION"; diff --git a/test/api-environments.test.js b/test/api-environments.test.js index 7cfa234..3582c6b 100644 --- a/test/api-environments.test.js +++ b/test/api-environments.test.js @@ -22,6 +22,7 @@ const REMOTE_COMMANDS = [ ["sketches", "publish"], ["plan", "push"], ["plan", "status"], + ["plan", "setup"], ["plan", "compile", "--output", "application"], ["compilation", "status", COMPILATION_ID], ["compilation", "download", COMPILATION_ID, "--output", "application"], diff --git a/test/compilation-artifact.test.js b/test/compilation-artifact.test.js index 16fd731..bd6b1d4 100644 --- a/test/compilation-artifact.test.js +++ b/test/compilation-artifact.test.js @@ -37,7 +37,7 @@ const SUBJECT_ID = "01900000-0000-7000-8000-000000000804"; const HEAD_SHA256 = "1".repeat(64); const FOUNDATION_PLAN_SHA256 = "5".repeat(64); const COMPILER_RELEASE = - "foundation-plan-rails/compiler-application-2026-09-27-bookmark-assets"; + "foundation-plan-rails/compiler-application-2026-11-27-project-setup"; const TARGET = { id: "rails", profile: RAILS_TARGET_PROFILE }; const EXPECTED = { projectId: PROJECT_ID, @@ -281,7 +281,7 @@ test("pins external provenance identities and validates nested metadata", () => analysis: { id: "01900000-0000-7000-8000-000000000899", release: - "foundation-plan-rails/application-2026-09-27-bookmark-assets", + "foundation-plan-rails/application-2026-11-25-application-mail", }, }, }), @@ -487,7 +487,7 @@ function artifactFixture(changes = {}) { }, analysis: { id: ANALYSIS_ID, - release: "foundation-plan-rails/application-2026-09-27-bookmark-assets", + release: "foundation-plan-rails/application-2026-11-25-application-mail", }, compiler_release: COMPILER_RELEASE, target: TARGET, diff --git a/test/compilation.test.js b/test/compilation.test.js index 1f79f96..8e0c2db 100644 --- a/test/compilation.test.js +++ b/test/compilation.test.js @@ -34,14 +34,14 @@ const CREATED_AT = "2026-08-04T12:00:00.000000Z"; const STARTED_AT = "2026-08-04T12:00:01.000000Z"; const COMPLETED_AT = "2026-08-04T12:00:02.000000Z"; const COMPILER_RELEASE = - "foundation-plan-rails/compiler-application-2026-09-27-bookmark-assets"; + "foundation-plan-rails/compiler-application-2026-11-27-project-setup"; const TARGET = { id: "rails", profile: RAILS_TARGET_PROFILE }; const STATUS_PATH = `/v1/projects/${PROJECT_ID}/compilations/${COMPILATION_ID}`; const ARTIFACT_PATH = `${STATUS_PATH}/artifact`; test("direct Compilation pins the reviewed Plan and materializes one retained artifact", async (context) => { const planSource = Buffer.from( - '{"format":"firstdraft.foundation-plan.sketch/0.23"}\n', + '{"format":"firstdraft.foundation-plan.sketch/0.24"}\n', ); const headSourceSha256 = sha256(planSource); const etag = `"sha256:${headSourceSha256}"`; @@ -734,7 +734,8 @@ function artifactFixture(changes = {}) { }, analysis: { id: ANALYSIS_ID, - release: "foundation-plan-rails/application-2026-09-27-bookmark-assets", + release: + "foundation-plan-rails/application-2026-11-25-application-mail", }, compiler_release: COMPILER_RELEASE, target: TARGET, diff --git a/test/plan-compile.test.js b/test/plan-compile.test.js index 3692332..55a544a 100644 --- a/test/plan-compile.test.js +++ b/test/plan-compile.test.js @@ -29,16 +29,16 @@ const STALE_ANALYSIS_ID = "01900000-0000-7000-8000-000000002005"; const COMPILATION_ID = "01900000-0000-7000-8000-000000002003"; const API_TOKEN = `fd_${"a".repeat(43)}`; const PLAN_SOURCE = Buffer.from( - '{"format":"firstdraft.foundation-plan.sketch/0.23","application":{"key":"movie_catalog","name":"Movie Catalog"}}\n', + '{"format":"firstdraft.foundation-plan.sketch/0.24","application":{"key":"movie_catalog","name":"Movie Catalog"}}\n', ); const HEAD_SHA256 = sha256(PLAN_SOURCE); const ETAG = `"sha256:${HEAD_SHA256}"`; const STARTED_AT = "2026-08-04T12:00:01.000Z"; const COMPLETED_AT = "2026-08-04T12:00:02.000Z"; const ANALYZER_RELEASE = - "foundation-plan-rails/application-2026-09-27-bookmark-assets"; + "foundation-plan-rails/application-2026-11-25-application-mail"; const COMPILER_RELEASE = - "foundation-plan-rails/compiler-application-2026-09-27-bookmark-assets"; + "foundation-plan-rails/compiler-application-2026-11-27-project-setup"; const TARGET = { id: "rails", profile: RAILS_TARGET_PROFILE }; const PLAN_COMPILE_HELP = `First Draft CLI @@ -1118,7 +1118,7 @@ function acceptedPlanBody(graphVersion = 1) { return { project: { id: PROJECT_ID, graph_version: graphVersion }, foundation_plan: { - format: "firstdraft.foundation-plan.sketch/0.23", + format: "firstdraft.foundation-plan.sketch/0.24", source_sha256: HEAD_SHA256, }, diagnostics: [], diff --git a/test/plan-init.test.js b/test/plan-init.test.js index 874b4b6..5422c54 100644 --- a/test/plan-init.test.js +++ b/test/plan-init.test.js @@ -30,6 +30,7 @@ Commands: init Create a local empty Foundation Plan push Send the local Foundation Plan to First Draft status Read the current whole-graph analysis status + setup Read the setup steps for a reviewed Foundation Plan compile Compile the current Foundation Plan Options: diff --git a/test/plan-push.test.js b/test/plan-push.test.js index 3aaa617..60b494d 100644 --- a/test/plan-push.test.js +++ b/test/plan-push.test.js @@ -1302,7 +1302,7 @@ function acceptedBody(source, diagnostics = []) { return { project: { id: PROJECT_ID, graph_version: 1 }, foundation_plan: { - format: "firstdraft.foundation-plan.sketch/0.23", + format: "firstdraft.foundation-plan.sketch/0.24", source_sha256: sha256(source), }, diagnostics, diff --git a/test/plan-setup.test.js b/test/plan-setup.test.js new file mode 100644 index 0000000..c93298a --- /dev/null +++ b/test/plan-setup.test.js @@ -0,0 +1,141 @@ +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import test from "node:test"; + +import { run } from "../src/cli.js"; + +const projectId = "01900000-0000-7000-8000-000000009501"; +const revision = "01900000-0000-7000-8000-000000009502"; +const digest = "7".repeat(64); +const origin = "https://firstdraft.example"; +const integration = { + source: "interview", + provider: "Anthropic", + title: "Set up the model provider", + purpose: "Read the shelf labels", + needed: "before_feature_test", + timing: "Before testing this feature", + destination: "Application environment", + action: "Set the environment variable for the app.", + environment_variable: "ANTHROPIC_API_KEY", +}; + +/** @param {import("node:test").TestContext} t */ +function application(t) { + const cwd = mkdtempSync(path.join(tmpdir(), "firstdraft-plan-setup-")); + t.after(() => rmSync(cwd, { recursive: true, force: true })); + mkdirSync(path.join(cwd, ".firstdraft")); + writeFileSync( + path.join(cwd, ".firstdraft/gaps.json"), + JSON.stringify({ + format: "firstdraft.foundation-gaps/2", + project: { id: projectId }, + }), + ); + return cwd; +} + +/** @param {string} cwd @param {string[]} flags @param {typeof globalThis.fetch} fetchFunction */ +async function invoke(cwd, flags, fetchFunction) { + let stdout = ""; + let stderr = ""; + const status = await run({ + cwd, + argv: ["plan", "setup", ...flags], + apiUrl: origin, + apiToken: "test-token", + env: {}, + fetchFunction, + stdout: { write: (data) => (stdout += data) }, + stderr: { write: (data) => (stderr += data) }, + }); + return { stdout, stderr, status }; +} + +test("a fresh clone reads the exact workshop review and returns its browser link", async (t) => { + const cwd = application(t); + const result = await invoke( + cwd, + ["--revision", revision, "--workshop"], + async (input, init) => { + const url = new URL(String(input)); + assert.equal(url.origin, origin); + assert.equal(url.pathname, "/v1/projects/" + projectId + "/setup"); + assert.equal(url.searchParams.get("review"), revision); + assert.equal(url.searchParams.get("context"), "workshop"); + assert.equal(init?.method, "GET"); + assert.equal( + new Headers(init?.headers).get("authorization"), + "Bearer test-token", + ); + return Response.json({ + review: { id: revision, plan_sha256: digest }, + context: "workshop", + steps: [integration], + }); + }, + ); + assert.equal(result.status, 0, result.stderr); + const body = JSON.parse(result.stdout); + assert.deepEqual(body.steps, [integration]); + assert.deepEqual(body.review, { id: revision, plan_sha256: digest }); + assert.equal( + body.project.url, + origin + + "/projects/" + + projectId + + "?document=setup&review=" + + revision + + "&context=workshop", + ); +}); + +test("a Plan-only Project links to its current head without a workshop or revision parameter", async (t) => { + const result = await invoke(application(t), [], async (input) => { + assert.equal(new URL(String(input)).search, ""); + return Response.json({ + review: { id: null, plan_sha256: digest }, + context: "general", + steps: [], + }); + }); + assert.equal(result.status, 0, result.stderr); + assert.equal( + JSON.parse(result.stdout).project.url, + origin + "/projects/" + projectId + "?document=setup", + ); +}); + +test("a mismatched review or an unexpected step field cannot reach the walkthrough", async (t) => { + const cwd = application(t); + for (const [id, steps] of [ + [projectId, [integration]], + [revision, [{ ...integration, value: "test-secret-unexpected" }]], + ]) { + const result = await invoke(cwd, ["--revision", revision], async () => + Response.json({ + review: { id, plan_sha256: digest }, + context: "general", + steps, + }), + ); + assert.equal(result.status, 1); + assert.equal(result.stdout, ""); + assert.equal(JSON.parse(result.stderr).error, "plan_setup_unavailable"); + assert.doesNotMatch(result.stderr, /test-secret-unexpected/); + } +}); + +test("help and invalid flags work before opening a Project or sending a request", async (t) => { + const cwd = application(t); + const noRequest = () => + assert.fail("help and invalid invocations do not call the service"); + const help = await invoke(cwd, ["--help"], noRequest); + assert.equal(help.status, 0); + assert.match(help.stdout, /--workshop/); + const invalid = await invoke(cwd, ["--revision", "not-a-review"], noRequest); + assert.equal(invalid.status, 2); + assert.equal(JSON.parse(invalid.stderr).error, "invalid_arguments"); +}); diff --git a/test/plan-status.test.js b/test/plan-status.test.js index 90ebc36..4ccee0f 100644 --- a/test/plan-status.test.js +++ b/test/plan-status.test.js @@ -36,9 +36,9 @@ const HEAD_SOURCE_SHA256 = "1".repeat(64); // The pinned Service gap-set digest covers these three values. Change them only // together with a digest that the Service computed. const ANALYZER_RELEASE = - "foundation-plan-rails/application-2026-09-27-bookmark-assets"; + "foundation-plan-rails/application-2026-11-25-application-mail"; const COMPILER_RELEASE = - "foundation-plan-rails/compiler-application-2026-09-27-bookmark-assets"; + "foundation-plan-rails/compiler-application-2026-11-27-project-setup"; const TARGET = { id: "rails", profile: RAILS_TARGET_PROFILE }; const PLAN_STATUS_HELP = `First Draft CLI @@ -250,7 +250,7 @@ test("plan status accepts the pinned Service zero-gap canonical digest", async ( const body = analysisBody("valid"); body.analysis.gap_set.gaps = []; body.analysis.gap_set_sha256 = - "c9599e35f30761180fc0cb1d57e33fd0106b4a8d8ff93df056b322e6fdfcfe58"; + "55217013405b40fefdd6737225458646cb377c38f502fb471343fb6603a68113"; const result = await invoke(["plan", "status"], { cwd, fetchFunction: recordingFetch([jsonResponse(body)], []), diff --git a/test/service-client.test.js b/test/service-client.test.js index 23e2ea0..d174b59 100644 --- a/test/service-client.test.js +++ b/test/service-client.test.js @@ -293,13 +293,13 @@ test("a stop that did not cut the command short keeps its result and names the s }); test("the CLI accepts only its declared API contract range", async () => { - assert.deepEqual(API_CONTRACT_RANGE, [">= 0.9.1", "< 0.10.0"]); + assert.deepEqual(API_CONTRACT_RANGE, [">= 0.10.0", "< 0.11.0"]); for (const contract of [ - "0.9.1", - "0.9.7", - " 0.9.1 ", - "0.9.2+build.7", + "0.10.0", + "0.10.7", + " 0.10.0 ", + "0.10.2+build.7", "unknown", "0.10", ]) { @@ -315,15 +315,15 @@ test("the CLI accepts only its declared API contract range", async () => { } for (const [contract, kind] of /** @type {[string, string][]} */ ([ - ["0.10.0", "newer"], - ["0.10.0+build.7", "newer"], - ["0.10.0-rc.1", "newer"], + ["0.11.0", "newer"], + ["0.11.0+build.7", "newer"], + ["0.11.0-rc.1", "newer"], ["1.0.0", "newer"], ["0.8.1", "older"], ["0.9.0-rc.1", "older"], - ["0.9.0", "older"], - ["0.9.1-rc.1", "older"], - ["0.9.2-rc.1", "prerelease"], + ["0.9.1", "older"], + ["0.10.0-rc.1", "older"], + ["0.10.2-rc.1", "prerelease"], ])) { const session = createServiceSession({ env: {}, notify: () => undefined }); const request = session.fetch(async () => versionedResponse({ contract })); @@ -433,7 +433,7 @@ test("a 429 reports the limit even when the response also requires an update", a test("the stop line for an older or prerelease contract does not advise updating", async () => { for (const [contract, sentence] of /** @type {[string, string][]} */ ([ ["0.8.7", "serves API contract 0.8.7, which is older than"], - ["0.9.2-rc.1", "serves prerelease API contract 0.9.2-rc.1, which"], + ["0.10.2-rc.1", "serves prerelease API contract 0.10.2-rc.1, which"], ])) { /** @type {string[]} */ const lines = []; @@ -650,15 +650,15 @@ test("a Service outside the API contract range is refused with both versions", a const cwd = await initializedProject(context); const result = await invoke(["plan", "compile", "--output", "application"], { cwd, - fetchFunction: async () => acceptedPush(cwd, { contract: "0.10.0" }), + fetchFunction: async () => acceptedPush(cwd, { contract: "0.11.0" }), }); assert.equal(result.status, 1); assert.deepEqual(errorEnvelope(result.stderr), { error: "api_contract_unsupported", - detail: `First Draft at ${ORIGIN} serves API contract 0.10.0, which is newer than CLI ${VERSION} accepts. The CLI stopped before the command finished and sent nothing more. Tell the person to update with the steps at ${UPDATE_URL}, then run the same command again, with the same options.`, - api_contract: "0.10.0", - accepted_api_contract: [">= 0.9.1", "< 0.10.0"], + detail: `First Draft at ${ORIGIN} serves API contract 0.11.0, which is newer than CLI ${VERSION} accepts. The CLI stopped before the command finished and sent nothing more. Tell the person to update with the steps at ${UPDATE_URL}, then run the same command again, with the same options.`, + api_contract: "0.11.0", + accepted_api_contract: [">= 0.10.0", "< 0.11.0"], cli_version: VERSION, update_url: UPDATE_URL, }); @@ -765,7 +765,7 @@ function acceptedPush(cwd, versions) { JSON.stringify({ project: { id: PROJECT_ID, graph_version: 1 }, foundation_plan: { - format: "firstdraft.foundation-plan.sketch/0.23", + format: "firstdraft.foundation-plan.sketch/0.24", source_sha256: createHash("sha256").update(source).digest("hex"), }, diagnostics: [], diff --git a/test/start.test.js b/test/start.test.js index 1ce938a..ddb88c0 100644 --- a/test/start.test.js +++ b/test/start.test.js @@ -296,7 +296,7 @@ test("below the minimum, start gives the handled refusal instead of ready", asyn }); test("an API contract outside the accepted range is not ready", async (context) => { - for (const contract of ["0.8.0", "0.10.0"]) { + for (const contract of ["0.9.1", "0.11.0"]) { const result = await invoke(context, ["start"], { saved: { [PRODUCTION]: SAVED_TOKEN }, fetchFunction: async () => @@ -433,7 +433,7 @@ test("a version refusal wins over a failed account read", async (context) => { status: 200, headers: { "Content-Type": "application/json", - "FirstDraft-API-Contract": "0.10.0", + "FirstDraft-API-Contract": "0.11.0", }, }), "api_contract_unsupported", @@ -516,7 +516,7 @@ function account(reports, headers = {}) { status: 200, headers: { "Content-Type": "application/json", - "FirstDraft-API-Contract": "0.9.1", + "FirstDraft-API-Contract": "0.10.0", ...headers, }, }, From 9a610299ebdf930d0a32ab79e2bce8cb4e1e7294 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Fri, 27 Nov 2026 18:59:57 -0600 Subject: [PATCH 2/4] Distinguish invalid setup replies from outages A missing review can be located again. Retrying a response for a different review cannot repair it. Keep those outcomes distinct and explain when the analyzed provider list is ready to use. --- CHANGELOG.md | 6 +++--- docs/commands.md | 14 +++++++++----- docs/errors.md | 13 ++++++++++++- src/cli.js | 5 ++++- test/plan-setup.test.js | 25 ++++++++++++++++++++++++- 5 files changed, 52 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc05730..1c1535f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,9 +11,9 @@ repository's [tags](https://github.com/firstdraft/cli/tags) identify the source ## 0.12.0 -- Run `firstdraft plan setup` after publishing the Plan to read its setup steps and get the corresponding Project - link. Use `--revision ` for a particular Sketches review. Workshop participants can add `--workshop` for - the Revyl iPhone preview. +- Run `firstdraft plan setup` after the published Plan's analysis completes to read its setup steps and get the + corresponding Project link. Use `--revision ` for a particular Sketches review. Workshop participants + can add `--workshop` for the Revyl iPhone preview. - This CLI creates Plans and accepts Compilations in format `firstdraft.foundation-plan.sketch/0.24`. It requires service API contract 0.10.0 or a later patch on that minor line. CLI 0.11.0 remains the release for API 0.9.1. diff --git a/docs/commands.md b/docs/commands.md index 2fdd832..728494b 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -469,7 +469,10 @@ from the Plan digest or trusts an ETag from a response it could not fully verify ## Read the reviewed Plan's setup steps -After publishing, ask First Draft for the list the owner can reopen on the Project page. +After publishing, use `firstdraft plan status --wait` to check the new Plan's analysis and digest. Once its +analysis is valid, ask First Draft for the list the owner can reopen on the Project page. An earlier read shows +the needs declared in the Plan. The completed analysis can remove a provider step or identify an iPhone client +that needs a Plan change before Compile. ```sh firstdraft plan setup @@ -1018,10 +1021,11 @@ contract exactly, including its Project ID, Environment name, and item ID. See ## Service endpoints -The CLI calls these Service API routes. The `/v1` routes send the selected token as a Bearer credential; -`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 -`/v1` request goes, to the origin pinned for the Project, or, for a maintain command or a `deployed_error` without -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 +The CLI calls these Service API routes. The `/v1` routes send the selected token as a Bearer credential. +`account` and `start` read `/v1/account` at the origin selected as for `login`. The report and note commands, +the `maintain` index and other Project requests use the Project's pinned origin. In an application clone without +planning state, `plan setup`, maintenance commands and `deployed_error` use the origin selected as for `login`. +The `/oauth` routes go to the origin selected for `login` or `logout` and send form-encoded OAuth parameters without a Bearer credential. Every request refuses redirects and has a bounded timeout. Each request takes its method and path from one `SERVICE_ROUTES` entry in `src/api-response.js`. `test/service-endpoints.test.js` fails when this table and diff --git a/docs/errors.md b/docs/errors.md index 3b5fa9f..704e112 100644 --- a/docs/errors.md +++ b/docs/errors.md @@ -69,6 +69,17 @@ The service problem appears in `response` when the CLI can verify its shape: Restore missing approved source from the planning folder or review a reconstruction. When an older service lacks the hosted endpoint, use local HTML for the walkthrough until the service and CLI are matched. +## Project setup recovery + +`plan_setup_unavailable` means the read failed. Retry after a network interruption or a temporary service error. +For `404 setup_not_found`, confirm the revision ID from this Project's `sketches publish` receipt. A new Sketches +Project needs its first publication. In a Plan-only Project, push the Plan and read Setup without `--revision`. +If a fresh application clone returns `404 project_not_found`, check the origin selected for login and use +`--staging` when the app belongs to staging. + +`invalid_server_response` means a success response could not identify the requested review, context and steps. +Stop the walkthrough and report the mismatch. Retrying the unchanged response cannot repair it. + ## Environment and credential errors `invalid_configuration` stops before a request when `--staging` conflicts with `FIRSTDRAFT_API_URL` or a Project's @@ -341,7 +352,7 @@ again. First Draft refuses to resolve an item that is still resolved, with `main | `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`. | | `plan push`, `plan compile` | `server_rejected` | 1 | First Draft returned validated Plan diagnostics or rejected the request with a validated problem. | | `plan status` | `server_rejected` | 1 | First Draft rejected the analysis status request with a validated non-authentication problem. | -| `plan setup` | `plan_setup_unavailable` | 1 | First Draft could not return the requested setup list. Confirm the review and retry the read. | +| `plan setup` | `plan_setup_unavailable`, `invalid_server_response` | 1 | Check the selected review and origin or report an invalid response. See [Project setup recovery](#project-setup-recovery). | | `plan status` | `status_unavailable`, `invalid_server_response` | 1 | The analysis read failed or violated its protocol. | | `plan compile` | `analysis_status_unavailable`, `invalid_analysis_status`, `analysis_status_rejected` | 1 | The bounded analysis read failed, was invalid, or was rejected. | | Analysis waits | `analysis_changed`, `wait_timed_out`, `analysis_wait_timed_out` | 1 | The pinned analysis changed or remained processing at the deadline. | diff --git a/src/cli.js b/src/cli.js index 80b6bbc..51f5874 100644 --- a/src/cli.js +++ b/src/cli.js @@ -3270,7 +3270,10 @@ async function runPlanSetup(options) { error instanceof PlanPushProtocolError ) { writeJson(stderr, { - error: "plan_setup_unavailable", + error: + error instanceof PlanPushProtocolError + ? "invalid_server_response" + : "plan_setup_unavailable", detail: error.message, status: error.status, }); diff --git a/test/plan-setup.test.js b/test/plan-setup.test.js index c93298a..f5bb7bf 100644 --- a/test/plan-setup.test.js +++ b/test/plan-setup.test.js @@ -123,11 +123,34 @@ test("a mismatched review or an unexpected step field cannot reach the walkthrou ); assert.equal(result.status, 1); assert.equal(result.stdout, ""); - assert.equal(JSON.parse(result.stderr).error, "plan_setup_unavailable"); + assert.equal(JSON.parse(result.stderr).error, "invalid_server_response"); assert.doesNotMatch(result.stderr, /test-secret-unexpected/); } }); +test("a missing review reports the service problem so the owner can recover that review", async (t) => { + const problem = { + title: "Not Found", + status: 404, + code: "setup_not_found", + detail: "This Project has no Plan at the requested review.", + }; + const result = await invoke( + application(t), + ["--revision", revision], + async () => + Response.json(problem, { + status: 404, + headers: { "Content-Type": "application/problem+json" }, + }), + ); + assert.equal(result.status, 1); + assert.equal(result.stdout, ""); + const failure = JSON.parse(result.stderr); + assert.equal(failure.error, "plan_setup_unavailable"); + assert.equal(failure.response.code, "setup_not_found"); +}); + test("help and invalid flags work before opening a Project or sending a request", async (t) => { const cwd = application(t); const noRequest = () => From 9ae42ec4013fa13b4e746ec592ea3008ccf54c4e Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Fri, 27 Nov 2026 19:03:00 -0600 Subject: [PATCH 3/4] Explain recovery for a retained Plan format The new Compiler can read the old review but needs a newly published Plan to start a Compilation. Keep the recovery on the same Project and use its new review when approving the build. --- CHANGELOG.md | 2 +- docs/errors.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c1535f..4d74981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ repository's [tags](https://github.com/firstdraft/cli/tags) identify the source ## 0.12.0 -- Run `firstdraft plan setup` after the published Plan's analysis completes to read its setup steps and get the +- Run `firstdraft plan setup` once the published Plan's analysis is valid to read its setup steps and get the corresponding Project link. Use `--revision ` for a particular Sketches review. Workshop participants can add `--workshop` for the Revyl iPhone preview. - This CLI creates Plans and accepts Compilations in format `firstdraft.foundation-plan.sketch/0.24`. It requires diff --git a/docs/errors.md b/docs/errors.md index 704e112..f2cf0e1 100644 --- a/docs/errors.md +++ b/docs/errors.md @@ -252,6 +252,11 @@ credential, but it must continue from the retained ID rather than starting anoth ## Stuck Compilation recovery +A `422 unsupported_plan_format` in `compilation_start_rejected` means the Project's Head uses an older Plan +format. Update the local Plan to the format named in `response.detail`. Republish it in the same Project, +check the new analysis and obtain approval for the updated Plan before compiling. For Sketches, use the new +revision ID. A previously published sketch review still opens with its original Plan. + A Project allows one active Compilation. While one is queued or running, `plan push` and `plan compile` report `server_rejected` with First Draft's `409 compilation_active` problem in `response`, because the Plan cannot be replaced. `plan compile` can also meet it at the Compilation start, as `compilation_start_rejected`. Either problem's From a90e9103155423b753c1b2764e34884c98e25c55 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Fri, 27 Nov 2026 19:13:36 -0600 Subject: [PATCH 4/4] Expose whether reviewed setup is ready to use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A freshly cloned app can reopen its Project without the planning state used to poll Analysis. Carry the service’s readiness signal so its owner can wait for verified provider steps. --- CHANGELOG.md | 5 +++-- docs/commands.md | 8 ++++++-- docs/errors.md | 3 ++- src/commands/plan-setup.js | 2 ++ test/plan-setup.test.js | 15 +++++++++++---- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d74981..7f8310d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,9 @@ repository's [tags](https://github.com/firstdraft/cli/tags) identify the source ## 0.12.0 - Run `firstdraft plan setup` once the published Plan's analysis is valid to read its setup steps and get the - corresponding Project link. Use `--revision ` for a particular Sketches review. Workshop participants - can add `--workshop` for the Revyl iPhone preview. + corresponding Project link. The response marks a list `preliminary` until it uses a valid analysis for that + Plan. Use `--revision ` for a particular Sketches review. Workshop participants can add `--workshop` for + the Revyl iPhone preview. - This CLI creates Plans and accepts Compilations in format `firstdraft.foundation-plan.sketch/0.24`. It requires service API contract 0.10.0 or a later patch on that minor line. CLI 0.11.0 remains the release for API 0.9.1. diff --git a/docs/commands.md b/docs/commands.md index 728494b..dd6a628 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -479,8 +479,12 @@ firstdraft plan setup firstdraft plan setup --revision --workshop ``` -The response includes the Project URL, the Plan digest, the review ID if the Project has Sketches, and the ordered -steps. Pass the review ID from `sketches publish` to read that version even after another review is published. +The response includes the Project URL, the Plan digest, the review ID if the Project has Sketches, the analysis +state and the ordered steps. `analysis` is `valid` when the list uses a valid analysis of this exact Plan. +`preliminary` means the service has no matching valid result for this revision. Return to the pinned Project +to check its analysis before obtaining provider credentials. An older revision can remain preliminary. + +Pass the review ID from `sketches publish` to read that version even after another review is published. With no revision, the service selects the latest published Sketches review or the current Head of a Plan-only Project. Use `--workshop` for the workshop’s Revyl iPhone preview. A fresh clone of a compiled application can also identify the Project from `.firstdraft/gaps.json`, as it can for `maintain`. diff --git a/docs/errors.md b/docs/errors.md index f2cf0e1..32566f0 100644 --- a/docs/errors.md +++ b/docs/errors.md @@ -77,7 +77,8 @@ Project needs its first publication. In a Plan-only Project, push the Plan and r If a fresh application clone returns `404 project_not_found`, check the origin selected for login and use `--staging` when the app belongs to staging. -`invalid_server_response` means a success response could not identify the requested review, context and steps. +`invalid_server_response` means a success response could not identify the requested review, context, analysis +state and steps. Stop the walkthrough and report the mismatch. Retrying the unchanged response cannot repair it. ## Environment and credential errors diff --git a/src/commands/plan-setup.js b/src/commands/plan-setup.js index 6f1eedd..18638d8 100644 --- a/src/commands/plan-setup.js +++ b/src/commands/plan-setup.js @@ -72,6 +72,7 @@ export async function readPlanSetup({ response.status !== 200 || responseMediaType(response) !== "application/json" || body?.context !== context || + !(body.analysis === "valid" || body.analysis === "preliminary") || !body.review || !(body.review.id === null || isUuidV7(body.review.id)) || (revision && body.review.id !== revision) || @@ -88,6 +89,7 @@ export async function readPlanSetup({ return { review: { id: body.review.id, plan_sha256: body.review.plan_sha256 }, context, + analysis: body.analysis, steps: body.steps, }; } diff --git a/test/plan-setup.test.js b/test/plan-setup.test.js index f5bb7bf..95c4bbf 100644 --- a/test/plan-setup.test.js +++ b/test/plan-setup.test.js @@ -73,6 +73,7 @@ test("a fresh clone reads the exact workshop review and returns its browser link return Response.json({ review: { id: revision, plan_sha256: digest }, context: "workshop", + analysis: "valid", steps: [integration], }); }, @@ -81,6 +82,7 @@ test("a fresh clone reads the exact workshop review and returns its browser link const body = JSON.parse(result.stdout); assert.deepEqual(body.steps, [integration]); assert.deepEqual(body.review, { id: revision, plan_sha256: digest }); + assert.equal(body.analysis, "valid"); assert.equal( body.project.url, origin + @@ -98,26 +100,31 @@ test("a Plan-only Project links to its current head without a workshop or revisi return Response.json({ review: { id: null, plan_sha256: digest }, context: "general", + analysis: "preliminary", steps: [], }); }); assert.equal(result.status, 0, result.stderr); + assert.equal(JSON.parse(result.stdout).analysis, "preliminary"); assert.equal( JSON.parse(result.stdout).project.url, origin + "/projects/" + projectId + "?document=setup", ); }); -test("a mismatched review or an unexpected step field cannot reach the walkthrough", async (t) => { +test("a mismatched review, unknown analysis state or unexpected field cannot reach the walkthrough", async (t) => { const cwd = application(t); - for (const [id, steps] of [ - [projectId, [integration]], - [revision, [{ ...integration, value: "test-secret-unexpected" }]], + for (const [id, analysis, steps] of [ + [projectId, "valid", [integration]], + [revision, undefined, [integration]], + [revision, "unknown", [integration]], + [revision, "valid", [{ ...integration, value: "test-secret-unexpected" }]], ]) { const result = await invoke(cwd, ["--revision", revision], async () => Response.json({ review: { id, plan_sha256: digest }, context: "general", + analysis, steps, }), );