@plume-press/cli 0.7.0 → 0.8.1

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.
Files changed (3) hide show
  1. package/README.md +4 -2
  2. package/dist/cli.mjs +448 -239
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Use Node.js 22.13 or newer. Install the scoped package in your website project before using its plume command. These examples use npm; keep your project's chosen package manager.
4
4
 
5
5
  ```sh
6
- npm install --save-dev @plume-press/cli@0.7.0
6
+ npm install --save-dev @plume-press/cli@0.8.1
7
7
  npx plume init --check
8
8
  npx plume --help
9
9
  ```
@@ -29,7 +29,9 @@ A successful connection saves nonsecret Site/editor URL facts in Git-ignored .pl
29
29
 
30
30
  ## Check a connected build
31
31
 
32
- Use plume build -- <your existing framework build command> in the build script. The wrapper checks the committed plume.lock and matching plume.schema.ts against the sealed content version, writes .plume/binding.json, then runs the framework. It performs no publication. PLUME_ENDPOINT defaults to https://app.plume.press; build validation needs no token. The same fixed binding can build a prepared host preview or production artifact. Schema files execute locally as trusted framework configuration does.
32
+ Use plume build --delivery auto -- <your existing framework build command> when the host builds both the live branch and preview branches: it builds a selected preview only when HEAD is Plume's prepared publication commit and production SSR otherwise, with no host setting. The explicit modes are --delivery production-ssr for public request-time content, --delivery selected-preview for an immutable publication candidate, or --delivery static (the default) for a pinned build. The wrapper validates clean exact Git HEAD, plume.lock and matching plume.schema.ts once, writes .plume/binding.json and .plume/delivery.json, then runs the framework. Selected-preview HEAD trailers must identify an existing immutable native reservation and agree with the lock. Compilation records operation ID, actual SHA and environment; later host evidence must match the final prepared target. There is no build UUID or preparation wait. It performs no publication. PLUME_ENDPOINT defaults to https://app.plume.press; validation needs no token. Schema files execute locally as trusted framework configuration does.
33
+
34
+ Production SSR resolves createLatestPlume once per render and shares the reader across page queries; selected preview/static use createPlume with the compiled binding. Emit same-reader render evidence with the compiled descriptor. Static or cached pages need a rebuild or real invalidation for freshness; runtime environment variables must not switch an immutable preview to latest.
33
35
 
34
36
  ## Export a Site
35
37
 
package/dist/cli.mjs CHANGED
@@ -35540,7 +35540,7 @@ var init_src = __esm({
35540
35540
  });
35541
35541
 
35542
35542
  // packages/sdk/src/protocol.ts
35543
- var MAX_CONTENT_DATA_BYTES, MAX_CONTENT_RESPONSE_BYTES, MAX_MEDIA_BYTES, contentBindingSchema, latestPublicationSchema, name, depth, contentQuerySchema, mediaPath, mediaQuerySchema, mediaRequestSchema, contentRequestSchema, timestamp, contentRecordSchema, contentAssetSchema, contentResponseSchema;
35543
+ var MAX_CONTENT_DATA_BYTES, MAX_CONTENT_RESPONSE_BYTES, MAX_MEDIA_BYTES, contentBindingSchema, publicPublicationSchema, latestPublicationSchema, previewCandidateSchema, deliveryArtifactSchema, deliveryDescriptorSchema, renderEvidenceSchema, name, depth, contentQuerySchema, mediaPath, mediaQuerySchema, mediaRequestSchema, contentRequestSchema, timestamp, contentRecordSchema, contentAssetSchema, contentResponseSchema;
35544
35544
  var init_protocol = __esm({
35545
35545
  "packages/sdk/src/protocol.ts"() {
35546
35546
  "use strict";
@@ -35553,12 +35553,50 @@ var init_protocol = __esm({
35553
35553
  contentVersionId: external_exports.uuidv7(),
35554
35554
  schemaHash: external_exports.string().regex(/^sha256:[a-f0-9]{64}$/)
35555
35555
  }).strict();
35556
+ publicPublicationSchema = external_exports.object({
35557
+ operationId: external_exports.uuidv7(),
35558
+ sequence: external_exports.number().int().positive().max(Number.MAX_SAFE_INTEGER),
35559
+ commitSha: external_exports.string().regex(/^[a-f0-9]{40}$/),
35560
+ branch: external_exports.string().min(1).max(256),
35561
+ acceptedAt: external_exports.iso.datetime({ offset: false, precision: 3 })
35562
+ }).strict();
35556
35563
  latestPublicationSchema = external_exports.object({
35557
35564
  binding: contentBindingSchema,
35558
35565
  commitSha: external_exports.string().min(1).max(64),
35559
35566
  branch: external_exports.string().min(1).max(256),
35560
- acceptedAt: external_exports.iso.datetime({ offset: false, precision: 3 })
35561
- });
35567
+ acceptedAt: external_exports.iso.datetime({ offset: false, precision: 3 }),
35568
+ /** Null on a legacy channel without an exact native receipt. */
35569
+ publication: publicPublicationSchema.nullable().default(null)
35570
+ }).refine(
35571
+ (value) => !value.publication || value.publication.commitSha === value.commitSha && value.publication.branch === value.branch && value.publication.acceptedAt === value.acceptedAt
35572
+ );
35573
+ previewCandidateSchema = external_exports.object({
35574
+ operationId: external_exports.uuidv7(),
35575
+ commitSha: external_exports.string().regex(/^[a-f0-9]{40}$/)
35576
+ }).strict();
35577
+ deliveryArtifactSchema = external_exports.object({
35578
+ commitSha: external_exports.string().regex(/^[a-f0-9]{40}$/),
35579
+ environment: external_exports.enum(["production", "preview"])
35580
+ }).strict();
35581
+ deliveryDescriptorSchema = external_exports.object({
35582
+ version: external_exports.literal(1),
35583
+ mode: external_exports.enum(["production-ssr", "selected-preview", "static"]),
35584
+ artifact: deliveryArtifactSchema,
35585
+ binding: contentBindingSchema,
35586
+ candidate: previewCandidateSchema.nullable()
35587
+ }).strict().refine(
35588
+ (value) => value.mode !== "production-ssr" || value.artifact.environment === "production"
35589
+ ).refine(
35590
+ (value) => value.mode !== "selected-preview" || value.artifact.environment === "preview" && value.candidate?.commitSha === value.artifact.commitSha
35591
+ );
35592
+ renderEvidenceSchema = external_exports.object({
35593
+ version: external_exports.literal(1),
35594
+ mode: external_exports.enum(["production-ssr", "selected-preview", "static"]),
35595
+ artifact: deliveryArtifactSchema,
35596
+ binding: contentBindingSchema,
35597
+ candidate: previewCandidateSchema.nullable(),
35598
+ publication: publicPublicationSchema.nullable()
35599
+ }).strict();
35562
35600
  name = external_exports.string().regex(/^[a-zA-Z][a-zA-Z0-9_-]*$/).max(100);
35563
35601
  depth = external_exports.union([external_exports.literal(0), external_exports.literal(1)]).optional();
35564
35602
  contentQuerySchema = external_exports.discriminatedUnion("kind", [
@@ -35900,56 +35938,56 @@ async function runLocalPrepare(options2) {
35900
35938
  "The local plume.schema.ts does not match this Update's registered schema. Register it before preparing."
35901
35939
  );
35902
35940
  await verifyCheckout(resolve(options2.cwd), inspect2, input2);
35903
- if (inspect2.state === "prepared") {
35904
- if (!inspect2.binding || !inspect2.preparedHeadSha || inspect2.headSha !== inspect2.preparedHeadSha || inspect2.binding.siteId !== input2.siteId || inspect2.binding.contentVersionId !== input2.expectedVersionId || inspect2.binding.schemaHash !== inspect2.schemaHash)
35905
- throw new PlumeToolError(
35906
- "INVALID_RESPONSE",
35907
- "Plume returned an inconsistent prepared Update. No preparation was requested."
35908
- );
35909
- return {
35910
- preparedHeadSha: inspect2.preparedHeadSha,
35911
- binding: inspect2.binding,
35912
- next: `git pull --ff-only origin ${inspect2.branch}`
35913
- };
35914
- }
35915
35941
  if (!input2.sessionId || !input2.token)
35916
35942
  throw new PlumeToolError(
35917
35943
  "INVALID_INPUT",
35918
- "An active preparation requires the writer sessionId and token."
35919
- );
35920
- const expectedHeadSha = inspect2.state === "preparing" ? inspect2.preparationBaseSha : inspect2.headSha;
35921
- if (!expectedHeadSha)
35922
- throw new PlumeToolError(
35923
- "INVALID_RESPONSE",
35924
- "Plume did not provide the preparation starting commit."
35944
+ "Preparation requires the writer sessionId and token."
35925
35945
  );
35926
- let prepared;
35927
- try {
35928
- prepared = preparedResult.parse(
35929
- (await runDeveloperTool({
35930
- action: "update.prepare",
35931
- input: { ...input2, expectedHeadSha },
35932
- endpoint: options2.endpoint,
35933
- token: options2.token
35934
- })).result
35935
- );
35936
- } catch (error62) {
35937
- if (error62 instanceof PlumeToolError) throw error62;
35938
- throw new PlumeToolError(
35939
- "INVALID_RESPONSE",
35940
- "Preparation may have completed, but Plume returned an invalid receipt. Inspect the Update before retrying."
35941
- );
35942
- }
35943
- if (prepared.update.id !== input2.updateId || prepared.update.branch !== inspect2.branch || prepared.update.preparationId !== input2.preparationId || prepared.update.preparationBaseSha !== expectedHeadSha || prepared.binding.siteId !== input2.siteId || prepared.binding.contentVersionId !== input2.expectedVersionId || prepared.binding.schemaHash !== inspect2.schemaHash)
35944
- throw new PlumeToolError(
35945
- "INVALID_RESPONSE",
35946
- "Preparation may have completed, but its receipt did not match the requested Update. Inspect before retrying."
35947
- );
35948
- return {
35949
- preparedHeadSha: prepared.update.preparedHeadSha,
35950
- binding: prepared.binding,
35951
- next: `git pull --ff-only origin ${inspect2.branch}`
35952
- };
35946
+ const plan = external_exports.object({
35947
+ fingerprint: external_exports.string(),
35948
+ operationId: id.nullable(),
35949
+ content: external_exports.object({ present: external_exports.boolean() }),
35950
+ website: external_exports.object({ present: external_exports.boolean() })
35951
+ }).parse(
35952
+ (await runDeveloperTool({
35953
+ action: "publication.plan",
35954
+ input: { siteId: input2.siteId, updateId: input2.updateId },
35955
+ endpoint: options2.endpoint,
35956
+ token: options2.token
35957
+ })).result
35958
+ );
35959
+ if (plan.operationId) {
35960
+ if (plan.operationId !== input2.preparationId)
35961
+ throw new PlumeToolError(
35962
+ "UPDATE_CONFLICT",
35963
+ "Another saved publication owns this Update. Inspect it before retrying."
35964
+ );
35965
+ return (await runDeveloperTool({
35966
+ action: "publication.status",
35967
+ input: {
35968
+ siteId: input2.siteId,
35969
+ updateId: input2.updateId,
35970
+ operationId: plan.operationId
35971
+ },
35972
+ endpoint: options2.endpoint,
35973
+ token: options2.token
35974
+ })).result;
35975
+ }
35976
+ return (await runDeveloperTool({
35977
+ action: "publication.start",
35978
+ input: {
35979
+ siteId: input2.siteId,
35980
+ updateId: input2.updateId,
35981
+ operationId: input2.preparationId,
35982
+ sessionId: input2.sessionId,
35983
+ token: input2.token,
35984
+ planFingerprint: plan.fingerprint,
35985
+ scope: plan.content.present && plan.website.present ? "both" : plan.content.present ? "content" : "website",
35986
+ purpose: "preview"
35987
+ },
35988
+ endpoint: options2.endpoint,
35989
+ token: options2.token
35990
+ })).result;
35953
35991
  }
35954
35992
  async function readInput() {
35955
35993
  let size = 0;
@@ -36074,7 +36112,7 @@ async function developerMain(args, env2 = process.env) {
36074
36112
  return 1;
36075
36113
  }
36076
36114
  }
36077
- var execFileAsync, MAX_INPUT_BYTES, MAX_RESPONSE_BYTES, MAX_SCHEMA_BYTES, MAX_SCHEMA_SOURCE_BYTES, schemaIssues, remoteText, detailShapes, id, context, writer, revision, record2, sha, operation, prepareInput, inspectResult, preparedResult, schemas, developerActions, PlumeToolError, developerHelp;
36115
+ var execFileAsync, MAX_INPUT_BYTES, MAX_RESPONSE_BYTES, MAX_SCHEMA_BYTES, MAX_SCHEMA_SOURCE_BYTES, schemaIssues, remoteText, detailShapes, id, context, writer, revision, record2, sha, operation, prepareInput, inspectResult, schemas, developerActions, PlumeToolError, developerHelp;
36078
36116
  var init_developer = __esm({
36079
36117
  "packages/cli/src/developer.ts"() {
36080
36118
  "use strict";
@@ -36166,22 +36204,28 @@ var init_developer = __esm({
36166
36204
  schemaHash: external_exports.string().regex(/^sha256:[a-f0-9]{64}$/),
36167
36205
  binding: contentBindingSchema.nullable()
36168
36206
  });
36169
- preparedResult = external_exports.object({
36170
- update: external_exports.object({
36171
- id,
36172
- branch: external_exports.string(),
36173
- state: external_exports.literal("prepared"),
36174
- preparationId: id,
36175
- preparationBaseSha: sha,
36176
- preparedHeadSha: sha
36177
- }),
36178
- binding: contentBindingSchema
36179
- });
36180
36207
  schemas = {
36181
36208
  // Needs no IDs: answers with the credential's own Site and Update.
36182
36209
  status: external_exports.object({ sessionId: id.optional() }).strict(),
36183
36210
  context: external_exports.object(context).strict(),
36184
36211
  "update.inspect": external_exports.object(context).strict(),
36212
+ "publication.plan": external_exports.object(context).strict(),
36213
+ "publication.start": external_exports.object({
36214
+ ...context,
36215
+ ...writer,
36216
+ operationId: id,
36217
+ scope: external_exports.enum(["content", "website", "both"]),
36218
+ purpose: external_exports.enum(["publish", "preview"]),
36219
+ planFingerprint: external_exports.string().regex(/^sha256:[a-f0-9]{64}$/)
36220
+ }).strict(),
36221
+ "publication.status": external_exports.object({ ...context, operationId: id }).strict(),
36222
+ "publication.recover": external_exports.object({ ...context, operationId: id }).strict(),
36223
+ "publication.cancel": external_exports.object({ ...context, operationId: id }).strict(),
36224
+ "publication.publishPrepared": external_exports.object({
36225
+ ...context,
36226
+ operationId: id,
36227
+ preparedFingerprint: external_exports.string().regex(/^sha256:[a-f0-9]{64}$/)
36228
+ }).strict(),
36185
36229
  "update.prepare": prepareInput.extend({
36186
36230
  sessionId: id,
36187
36231
  token: id,
@@ -36245,7 +36289,7 @@ Usage: plume tool <action> < request.json
36245
36289
 
36246
36290
  Actions: ${developerActions.join(", ")}
36247
36291
  Use PLUME_ENDPOINT and a separate PLUME_DEVELOPER_TOKEN. Send siteId and updateId explicitly on stdin (status needs neither and returns them). The action belongs in the command, not the JSON. schema.register without a schema field loads the named schema export from plume.schema.ts.
36248
- Mutations require an explicit Update, expected version/revision, and writer lease. Acquire with writer.acquire, retain its sessionId/token for writes, and release with writer.release. A busy Site answers WRITER_BUSY with details.holder (name, since); writer.takeover takes control explicitly, never automatically. record.replace requires fullReplacement: true and replaces the whole record. update.discard takes a free lease for sessionId when token is omitted. plume prepare requires a clean checkout at the connected GitHub origin and exact Update branch/commit. It commits plume.lock through Plume and returns a prepared commit; then run the printed git pull --ff-only command. Publish with plume publish.
36292
+ Mutations require an explicit Update, expected version/revision, and writer lease. Acquire with writer.acquire, retain its sessionId/token for writes, and release with writer.release. A busy Site answers WRITER_BUSY with details.holder (name, since); writer.takeover takes control explicitly, never automatically. record.replace requires fullReplacement: true and replaces the whole record. update.discard takes a free lease for sessionId when token is omitted. plume prepare requires a clean checkout at the connected GitHub origin and exact Update branch/commit. It admits one scoped preview operation and returns durable status; poll publication.status. Publishing the prepared candidate requires publication.publishPrepared with its exact preparedFingerprint. Publish with plume publish.
36249
36293
  Exit codes: 0 success, 1 refused or failed, 2 wrong usage.`;
36250
36294
  }
36251
36295
  });
@@ -36634,7 +36678,7 @@ For an unconnected local project, plume local schema applies safe additions; plu
36634
36678
 
36635
36679
  Hosted schemas arrive through an ordinary Update: add plume.schema.ts and page wiring on its branch, register the schema with plume schema apply using developer access for that Update, then prepare/publish through the existing Plume workflow when requested. To transfer local records once, the publication branch first needs a published schema-only Update and plume.lock, no hosted content, no open Updates and no active writer. plume connect performs browser approval, an explicit transfer choice and confirmation; its setup credential is not ongoing developer access. Resume interrupted transfers with plume connect; never silently merge them into an open Update. Transfer supports at most 100 records/1 MiB and rejects media.
36636
36680
 
36637
- Use only implemented commands in npx plume --help. There is no plume push, doctor, automatic deploy-hook configuration or universal website-check command. Prepare writes plume.lock remotely; deliberately run the printed git pull --ff-only on the correct branch before building. Never claim a local change is published or deployed.
36681
+ Use only implemented commands in npx plume --help. There is no plume push, doctor, automatic deploy-hook configuration or universal website-check command. Preparation returns one durable scoped operation; observe publication.status and deliberately check out its exact candidate before a selected host-preview build. Never claim a local change is published or deployed.
36638
36682
 
36639
36683
  ## One server-only reader, explicit content modes
36640
36684
 
@@ -36643,13 +36687,17 @@ Create or adapt one reader factory beside the site's existing server data helper
36643
36687
  Choose the mode explicitly in application/server configuration:
36644
36688
 
36645
36689
  - **Plume session preview:** when PLUME_PREVIEW is exactly true, require the session-provided PLUME_ENDPOINT and use createPlume({ schema, binding, endpoint, mode: "preview" }). Read the session's generated .plume/binding.json; fail if it is absent or malformed. Local loopback preview URLs can carry a path capability: keep the complete URL server-only. Do not replace it with the public CMS origin.
36646
- - **Prepared host preview or deliberately static build:** run plume build -- <existing framework build command>, then use createPlume with that generated .plume/binding.json and mode: "published". Public SDK reads default to https://cms.plume.press. The build's committed plume.lock is its authority; a missing/mismatched binding must fail rather than switch to latest.
36647
- - **Public SSR:** only for an explicitly selected public production SSR mode on a host that supports it, await createLatestPlume({ schema, siteId }) once per request/render. Derive siteId from the committed Site binding, and pass the reader to all page/metadata queries. Use a request-scoped promise/cache, never a module-global reader or promise. A public URL or matching schema does not by itself select latest. A prepared host preview must keep its fixed candidate even if public latest advances.
36690
+ - **Immutable host preview:** run plume build --delivery selected-preview -- <existing framework build command> from its clean exact Git candidate. The build reads its committed Plume operation trailers and validates the exact sealed binding against the native immutable reservation, then writes .plume/delivery.json with operationId and compiled code SHA. Final native preparation must match that operation, SHA and binding before Plume confirms the host preview. Use createPlume with the generated .plume/binding.json and mode: "published". Never resolve latest for this mode.
36691
+ - **Deliberately static build:** plume build --delivery static -- <existing framework build command> compiles an immutable selection. Content changes require a real rebuild or supported invalidation; a latest probe cannot certify an old page.
36692
+ - **Public SSR:** compile the explicit descriptor with plume build --delivery production-ssr -- <existing framework build command>. Only for an explicitly selected public production SSR mode on a host that supports it, await createLatestPlume({ schema, siteId }) once per request/render. Derive siteId from the committed Site binding, and pass the reader to all page/metadata queries. Use a request-scoped promise/cache, never a module-global reader or promise. A public URL or matching schema does not by itself select latest. A prepared host preview must keep its fixed candidate even if public latest advances.
36693
+ - **One build script for live and preview branches:** plume build --delivery auto -- <existing framework build command> builds as selected-preview only when HEAD is Plume's prepared publication commit (same trailer and reservation checks; a failed check stops the build) and as production-ssr otherwise, so the host needs no setting. .plume/delivery.json records the resolved mode; choose the reader from that compiled mode, never from runtime variables.
36648
36694
 
36649
36695
  Next.js: keep the helper server-only (import "server-only"). In App Router, use the existing server components and request-scoped React cache to share the async reader across a render/metadata pass; opt affected public SSR routes into the framework's dynamic behavior and avoid persistent caching of the latest binding. Preserve Pages Router if the site uses it: resolve once inside getServerSideProps and pass rendered data. Keep getStaticProps/static routes pinned when intentional.
36650
36696
 
36651
36697
  Astro: resolve once in page frontmatter or the existing request context and pass the reader/data into layouts and components. Public latest needs a configured SSR adapter and on-demand rendering (export const prerender = false for the affected routes); preserve deliberate static output and its fixed build binding. Do not add an arbitrary host adapter without checking the actual deployment.
36652
36698
 
36699
+ Emit cooperative publication evidence from the exact reader used for actual page queries: createRenderEvidence(reader, compiledDescriptor), serialized with serializeRenderEvidence. In Astro set X-Plume-Render on the actual HTML response; in Next App Router render one inert script type="application/json" data-plume-render="1" with that escaped JSON. Do not make a separate latest lookup or add a redundant probe endpoint. Intentional static routes emit mode static. Local/working preview dev configuration must select an explicit private module with no compiled descriptor and emit no publication evidence. Runtime flags cannot switch the compiled host-preview mode. Configure the host connection's Content page path to that real route. These are cooperative integration facts, not cryptographic attestation or a completed provider build receipt.
36700
+
36653
36701
  ## Admin entry and visitor metadata
36654
36702
 
36655
36703
  If /admin is free, add a framework-native server redirect to the verified editorUrl in .plume/site.json. In Next App Router this can be an app/admin route/page; in Astro use its existing redirects configuration or a server route as appropriate. Carry the nonsecret URL into reviewed application configuration that exists at deployment; .plume/site.json is Git-ignored. If /admin already has a purpose, preserve it and resolve the entry route in the integration diff. The destination's sign-in return and Site membership checks remain the authority: embed no shared secret, developer token or auth capability.
@@ -37141,7 +37189,7 @@ var init_package = __esm({
37141
37189
  "packages/sdk/package.json"() {
37142
37190
  package_default = {
37143
37191
  name: "@plume-press/sdk",
37144
- version: "0.3.0",
37192
+ version: "0.4.0",
37145
37193
  private: true,
37146
37194
  license: "MIT",
37147
37195
  type: "module",
@@ -37168,7 +37216,7 @@ var init_package2 = __esm({
37168
37216
  "packages/cli/package.json"() {
37169
37217
  package_default2 = {
37170
37218
  name: "@plume-press/cli",
37171
- version: "0.7.0",
37219
+ version: "0.8.1",
37172
37220
  private: true,
37173
37221
  license: "MIT",
37174
37222
  type: "module",
@@ -37663,9 +37711,10 @@ var sessionShape = external_exports.object({
37663
37711
  sessionId: uuid3,
37664
37712
  token: uuid3.optional(),
37665
37713
  publish: external_exports.object({
37666
- publishId: uuid3,
37667
- expectedVersionId: uuid3,
37668
- expectedRevision: external_exports.number().int().nonnegative()
37714
+ operationId: uuid3,
37715
+ scope: external_exports.enum(["content", "website", "both"]),
37716
+ purpose: external_exports.enum(["publish", "preview"]),
37717
+ planFingerprint: external_exports.string().regex(/^sha256:[a-f0-9]{64}$/)
37669
37718
  }).optional()
37670
37719
  });
37671
37720
  async function checkoutRoot(cwd) {
@@ -38393,164 +38442,221 @@ async function schema2(ctx, args) {
38393
38442
  }
38394
38443
  return exitCodes.done;
38395
38444
  }
38396
- var stepLabels = {
38397
- checking: "Checking for newer published changes\u2026",
38398
- updating: "Bringing in newer published changes\u2026",
38399
- freezing: "Freezing content\u2026",
38400
- publishing: "Publishing\u2026"
38401
- };
38402
- var notMerged = {
38403
- needs_approval: "In review: waiting for an Admin to approve.",
38404
- check_failed: "In review: the Plume check failed. See the check on the pull request.",
38405
- target_moved: "In review: something changed while publishing. Run plume publish again to check it afresh.",
38406
- merge_refused: "In review: GitHub couldn\u2019t publish it (conflicting changes or repository rules). Fix that on the Update\u2019s branch, then run plume publish again.",
38407
- changed: "In review: this Update changed while publishing. Run plume publish again."
38408
- };
38409
- var publishedShape = external_exports.object({
38410
- outcome: external_exports.enum(["merged", "awaiting_review"]),
38411
- reason: external_exports.string().optional(),
38412
- pullRequest: external_exports.object({ number: external_exports.number().int(), url: external_exports.string().optional() }).nullable().optional(),
38413
- mergeVerification: external_exports.object({ verified: external_exports.boolean() }).nullable().optional()
38445
+ var publicationStatusShape = external_exports.object({
38446
+ operationId: uuid3,
38447
+ sourceUpdateId: uuid3,
38448
+ scope: external_exports.enum(["content", "website", "both"]),
38449
+ purpose: external_exports.enum(["publish", "preview"]),
38450
+ publicationRequested: external_exports.boolean(),
38451
+ state: external_exports.enum([
38452
+ "preparing",
38453
+ "prepared",
38454
+ "needs_approval",
38455
+ "publishing",
38456
+ "recovery_required",
38457
+ "accepted",
38458
+ "cancelling",
38459
+ "cancelled",
38460
+ "blocked"
38461
+ ]),
38462
+ progress: external_exports.string().nullable(),
38463
+ reason: external_exports.string().nullable(),
38464
+ allowedActions: external_exports.array(external_exports.enum(["publish_prepared", "recover", "cancel"])),
38465
+ candidate: external_exports.object({ preparedFingerprint: external_exports.string().nullable() }).passthrough().nullable(),
38466
+ result: external_exports.object({
38467
+ receipt: external_exports.object({ operationId: uuid3, sequence: external_exports.number().int().positive() }).passthrough(),
38468
+ sourceUpdateId: uuid3,
38469
+ continuationUpdateId: uuid3.nullable()
38470
+ }).passthrough().nullable()
38471
+ }).passthrough().refine(
38472
+ (value) => value.state === "accepted" ? value.result?.receipt.operationId === value.operationId : value.result === null
38473
+ );
38474
+ var scopePlanShape = external_exports.object({
38475
+ present: external_exports.boolean(),
38476
+ permission: external_exports.enum(["allowed", "approval", "locked"]),
38477
+ disabledReason: external_exports.string().nullable()
38478
+ });
38479
+ var publicationPlanShape = external_exports.object({
38480
+ operationId: uuid3.nullable(),
38481
+ fingerprint: external_exports.string(),
38482
+ content: scopePlanShape,
38483
+ website: scopePlanShape,
38484
+ schemaPartialBlocked: external_exports.boolean()
38414
38485
  });
38415
- async function press(ctx, input2, onStep) {
38416
- const response = await postDeveloperTool({
38417
- body: JSON.stringify({ action: "update.publish", ...input2 }),
38418
- endpoint: ctx.endpoint,
38419
- token: ctx.token,
38420
- timeoutMs: PUBLISH_TIMEOUT_MS,
38421
- ...ctx.io.fetch ? { fetch: ctx.io.fetch } : {}
38422
- });
38423
- const reader = response.body?.getReader();
38424
- if (!reader) return null;
38425
- const decoder = new TextDecoder("utf-8", { fatal: true });
38426
- let buffer = "";
38427
- let size = 0;
38428
- try {
38429
- while (true) {
38430
- const { done, value } = await reader.read();
38431
- if (done) break;
38432
- size += value.byteLength;
38433
- if (size > 4 * 1024 * 1024) throw new Error();
38434
- buffer += decoder.decode(value, { stream: true });
38435
- let newline = buffer.indexOf("\n");
38436
- while (newline >= 0) {
38437
- const line = JSON.parse(buffer.slice(0, newline));
38438
- buffer = buffer.slice(newline + 1);
38439
- newline = buffer.indexOf("\n");
38440
- if (typeof line.step === "string") onStep(line.step);
38441
- else if ("error" in line) throw remoteError(409, line);
38442
- else if ("result" in line) {
38443
- const parsed = publishedShape.safeParse(line.result);
38444
- if (!parsed.success) return null;
38445
- return parsed.data;
38446
- }
38447
- }
38448
- }
38449
- } catch (error62) {
38450
- if (error62 instanceof PlumeToolError) throw error62;
38451
- return null;
38452
- } finally {
38453
- reader.releaseLock();
38454
- }
38455
- return null;
38456
- }
38457
38486
  async function publish(ctx, args) {
38458
- const options2 = parse6(args);
38487
+ const options2 = parse6(
38488
+ args,
38489
+ ["--preview", "--status", "--recover", "--cancel", "--publish-prepared"],
38490
+ ["--scope"]
38491
+ );
38459
38492
  if (options2.positional.length)
38460
- throw new UsageError("plume publish takes no arguments.");
38493
+ throw new UsageError("plume publish takes no positional arguments.");
38494
+ const actionFlags = [
38495
+ "--status",
38496
+ "--recover",
38497
+ "--cancel",
38498
+ "--publish-prepared"
38499
+ ].filter((flag) => options2.flags.has(flag));
38500
+ if (actionFlags.length > 1)
38501
+ throw new UsageError("Choose one publication action.");
38502
+ const requestedScope = options2.values.get("--scope");
38503
+ if (requestedScope && !["content", "website", "both"].includes(requestedScope))
38504
+ throw new UsageError("--scope takes content, website or both.");
38461
38505
  let { session } = await scope(ctx);
38462
- const current = await context2(ctx, session);
38463
- const editable = !!current.update && ["editing", "preparing"].includes(current.update.state);
38464
- const lease = editable ? await control(ctx, session) : null;
38465
- if (lease) session = await readSession(ctx) ?? session;
38466
- const stop = lease ? keepControl(ctx, session, lease) : () => {
38506
+ let pending = session.publish;
38507
+ let status2;
38508
+ let stop = () => {
38467
38509
  };
38468
- const steps = [];
38469
- const onStep = (step) => {
38470
- steps.push(step);
38471
- if (!ctx.json) ctx.io.out(`${stepLabels[step] ?? step}
38472
- `);
38473
- };
38474
- const fresh = () => ({
38475
- publishId: uuidv72(),
38476
- expectedVersionId: current.versionId,
38477
- expectedRevision: current.revision
38478
- });
38479
- let pending = session.publish ?? fresh();
38480
- let resuming = !!session.publish;
38481
- await writeSession(ctx, { ...session, publish: pending });
38482
- const forget = () => writeSession(ctx, { ...session, publish: void 0 });
38483
38510
  try {
38484
- let result = null;
38485
- for (let attempt = 0; attempt < 3 && !result; attempt++) {
38486
- if (attempt) await delay(attempt * 2e3);
38511
+ if (pending) {
38512
+ if (requestedScope && requestedScope !== pending.scope || options2.flags.has("--preview") && pending.purpose !== "preview")
38513
+ throw new UsageError(
38514
+ "This checkout has a saved publication. Inspect or cancel it before choosing a different scope."
38515
+ );
38487
38516
  try {
38488
- result = await press(
38517
+ status2 = await call(
38518
+ ctx,
38519
+ "publication.status",
38520
+ { ...ids(session), operationId: pending.operationId },
38521
+ publicationStatusShape,
38522
+ true
38523
+ );
38524
+ } catch (error62) {
38525
+ if (!(error62 instanceof PlumeToolError) || error62.code !== "NOT_FOUND" || actionFlags.length)
38526
+ throw error62;
38527
+ const lease = await control(ctx, session);
38528
+ session = await readSession(ctx) ?? session;
38529
+ stop = keepControl(ctx, session, lease);
38530
+ status2 = await call(
38489
38531
  ctx,
38532
+ "publication.start",
38490
38533
  {
38491
38534
  ...ids(session),
38535
+ ...pending,
38492
38536
  sessionId: session.sessionId,
38493
- ...lease ? { token: lease.token } : {},
38494
- ...pending
38537
+ token: lease.token
38495
38538
  },
38496
- onStep
38539
+ publicationStatusShape
38540
+ );
38541
+ }
38542
+ } else {
38543
+ const plan = await call(
38544
+ ctx,
38545
+ "publication.plan",
38546
+ ids(session),
38547
+ publicationPlanShape,
38548
+ true
38549
+ );
38550
+ if (plan.operationId) {
38551
+ status2 = await call(
38552
+ ctx,
38553
+ "publication.status",
38554
+ { ...ids(session), operationId: plan.operationId },
38555
+ publicationStatusShape,
38556
+ true
38557
+ );
38558
+ pending = {
38559
+ operationId: status2.operationId,
38560
+ scope: status2.scope,
38561
+ purpose: status2.purpose,
38562
+ planFingerprint: plan.fingerprint
38563
+ };
38564
+ } else {
38565
+ if (actionFlags.length)
38566
+ throw new UsageError(
38567
+ "There is no saved publication for this Update."
38568
+ );
38569
+ const selected = requestedScope ?? (plan.content.present && plan.website.present ? "both" : plan.content.present ? "content" : "website");
38570
+ const scopes = selected === "both" ? [plan.content, plan.website] : [selected === "content" ? plan.content : plan.website];
38571
+ if (scopes.some(
38572
+ (value) => !value.present || value.permission === "locked" || value.disabledReason
38573
+ ) || selected !== "both" && plan.schemaPartialBlocked)
38574
+ throw new PlumeToolError(
38575
+ "SCOPE_UNAVAILABLE",
38576
+ "The selected publication scope is unavailable. Inspect this Update in Plume."
38577
+ );
38578
+ const lease = await control(ctx, session);
38579
+ session = await readSession(ctx) ?? session;
38580
+ stop = keepControl(ctx, session, lease);
38581
+ pending = {
38582
+ operationId: uuidv72(),
38583
+ scope: selected,
38584
+ purpose: options2.flags.has("--preview") ? "preview" : "publish",
38585
+ planFingerprint: plan.fingerprint
38586
+ };
38587
+ await writeSession(ctx, { ...session, publish: pending });
38588
+ status2 = await call(
38589
+ ctx,
38590
+ "publication.start",
38591
+ {
38592
+ ...ids(session),
38593
+ ...pending,
38594
+ sessionId: session.sessionId,
38595
+ token: lease.token
38596
+ },
38597
+ publicationStatusShape
38497
38598
  );
38498
- } catch (error62) {
38499
- if (uncertain(error62)) continue;
38500
- if (resuming && error62 instanceof PlumeToolError && error62.code === "PUBLISH_CHANGED") {
38501
- resuming = false;
38502
- attempt = -1;
38503
- steps.length = 0;
38504
- pending = fresh();
38505
- await writeSession(ctx, { ...session, publish: pending });
38506
- if (!ctx.json)
38507
- ctx.io.out(
38508
- "The content changed since publishing was last tried. Starting again\u2026\n"
38509
- );
38510
- continue;
38511
- }
38512
- await forget();
38513
- throw error62;
38514
38599
  }
38600
+ await writeSession(ctx, { ...session, publish: pending });
38515
38601
  }
38516
- if (!result)
38602
+ if (status2.operationId !== pending.operationId || status2.sourceUpdateId !== session.updateId)
38517
38603
  throw new PlumeToolError(
38518
- "PUBLISH_UNFINISHED",
38519
- "Publishing didn\u2019t finish: the connection to Plume was lost. Run plume publish again; it continues this press."
38604
+ "INVALID_RESPONSE",
38605
+ "The publication response identifies another operation or Update."
38520
38606
  );
38521
- await forget();
38522
- if (lease) {
38523
- stop();
38524
- await call(
38607
+ const action = actionFlags[0];
38608
+ if (action && action !== "--status") {
38609
+ const allowed = action === "--publish-prepared" ? "publish_prepared" : action.slice(2);
38610
+ if (!status2.allowedActions.includes(
38611
+ allowed
38612
+ ))
38613
+ throw new PlumeToolError(
38614
+ "ACTION_UNAVAILABLE",
38615
+ "This action is unavailable for the saved publication."
38616
+ );
38617
+ const input2 = { ...ids(session), operationId: status2.operationId };
38618
+ status2 = await call(
38525
38619
  ctx,
38526
- "writer.release",
38527
- { ...ids(session), sessionId: session.sessionId, token: lease.token },
38528
- external_exports.unknown()
38529
- ).catch(() => {
38530
- });
38620
+ action === "--publish-prepared" ? "publication.publishPrepared" : action === "--cancel" ? "publication.cancel" : "publication.recover",
38621
+ action === "--publish-prepared" ? {
38622
+ ...input2,
38623
+ preparedFingerprint: status2.candidate?.preparedFingerprint
38624
+ } : input2,
38625
+ publicationStatusShape
38626
+ );
38627
+ }
38628
+ stop();
38629
+ const deadline = Date.now() + PUBLISH_TIMEOUT_MS;
38630
+ let previous = "";
38631
+ while (action !== "--status" && ["preparing", "publishing", "cancelling"].includes(status2.state) && Date.now() < deadline) {
38632
+ const label = status2.progress ?? status2.state;
38633
+ if (!ctx.json && label !== previous) ctx.io.out(`${printable(label)}\u2026
38634
+ `);
38635
+ previous = label;
38636
+ await delay(1e3);
38637
+ status2 = await call(
38638
+ ctx,
38639
+ "publication.status",
38640
+ { ...ids(session), operationId: pending.operationId },
38641
+ publicationStatusShape,
38642
+ true
38643
+ );
38644
+ if (status2.operationId !== pending.operationId || status2.sourceUpdateId !== session.updateId)
38645
+ throw new PlumeToolError(
38646
+ "INVALID_RESPONSE",
38647
+ "The saved publication identity changed."
38648
+ );
38649
+ }
38650
+ if (["accepted", "cancelled"].includes(status2.state))
38531
38651
  await writeSession(ctx, {
38532
38652
  ...session,
38533
38653
  publish: void 0,
38534
38654
  token: void 0
38535
38655
  });
38536
- }
38537
- const outcome = result;
38538
38656
  emit(
38539
38657
  ctx,
38540
- {
38541
- outcome: outcome.outcome,
38542
- reason: outcome.reason ?? null,
38543
- pullRequest: outcome.pullRequest ?? null,
38544
- mergeVerification: outcome.mergeVerification ?? null,
38545
- steps
38546
- },
38547
- () => [
38548
- outcome.outcome === "merged" ? "Published. Your website updates when your host deploys it." : notMerged[outcome.reason ?? ""] ?? "In review.",
38549
- ...outcome.mergeVerification?.verified === false ? [
38550
- "Verification after publishing failed. Ask a developer to check it; your host may already be deploying it."
38551
- ] : [],
38552
- ...outcome.pullRequest ? [`Pull request #${outcome.pullRequest.number}`] : []
38553
- ].join("\n")
38658
+ status2,
38659
+ () => status2.state === "accepted" && status2.result ? `Published ${status2.scope}. Publication ${status2.operationId}, sequence ${status2.result.receipt.sequence}.${status2.result.continuationUpdateId ? ` Retained work: ${status2.result.continuationUpdateId}.` : ""}` : `Publication ${status2.operationId}: ${status2.state}${status2.reason ? ` (${status2.reason})` : ""}.${status2.allowedActions.length ? ` Available actions: ${status2.allowedActions.map((value) => `--${value.replaceAll("_", "-")}`).join(", ")}.` : ""}`
38554
38660
  );
38555
38661
  return exitCodes.done;
38556
38662
  } finally {
@@ -38676,9 +38782,9 @@ Examples:
38676
38782
  summary: "Publish the Update, showing each step",
38677
38783
  help: `plume publish \u2014 publish this checkout's Update, as Publish in Plume does.
38678
38784
 
38679
- Usage: plume publish [--json]
38785
+ Usage: plume publish [--scope content|website|both] [--preview] [--status|--recover|--cancel|--publish-prepared] [--json]
38680
38786
 
38681
- Brings in newer published changes (when nothing conflicts), freezes the content, checks it and publishes it, printing each step. It stops when a person is needed: Items changed both here and in the published version (choose in Plume with Resolve conflicts), code changed in both places, a failed check, or an Admin's approval. If the connection drops, run it again: it continues the same press.
38787
+ Starts one saved scoped publication and observes its status. The default selects the changed scopes. --preview prepares an immutable host preview; publishing it later requires --publish-prepared. --status only reads. --recover wakes an authorized recoverable operation; --cancel requests cancellation. A lost response keeps the same operation identity. Content publication does not cause a Website build.
38682
38788
 
38683
38789
  Example:
38684
38790
  plume publish`,
@@ -39873,7 +39979,8 @@ var MAX_SCHEMA_BYTES2 = 256 * 1024;
39873
39979
  var validationSchema = external_exports.object({
39874
39980
  binding: contentBindingSchema,
39875
39981
  revision: external_exports.number().int().nonnegative(),
39876
- sealed: external_exports.literal(true)
39982
+ sealed: external_exports.literal(true),
39983
+ candidate: previewCandidateSchema.nullable().optional()
39877
39984
  }).strict();
39878
39985
  var PlumeBuildError = class extends Error {
39879
39986
  constructor(code, message) {
@@ -39955,39 +40062,55 @@ function validationUrl(endpoint) {
39955
40062
  );
39956
40063
  }
39957
40064
  }
39958
- async function validateRemote(url2, binding) {
39959
- let response;
40065
+ async function validateRemote(url2, binding, commitSha, operationId) {
40066
+ const abort = new AbortController(), interrupt = () => abort.abort();
40067
+ process.on("SIGINT", interrupt);
40068
+ process.on("SIGTERM", interrupt);
39960
40069
  try {
39961
- response = await fetch(url2, {
39962
- method: "POST",
39963
- headers: { "content-type": "application/json" },
39964
- body: JSON.stringify({ binding }),
39965
- redirect: "error",
39966
- cache: "no-store",
39967
- credentials: "omit",
39968
- signal: AbortSignal.timeout(15e3)
39969
- });
39970
- if (!response.ok) {
40070
+ let response;
40071
+ try {
40072
+ response = await fetch(url2, {
40073
+ method: "POST",
40074
+ headers: { "content-type": "application/json" },
40075
+ body: JSON.stringify({
40076
+ binding,
40077
+ commitSha,
40078
+ ...operationId ? { mode: "selected-preview", operationId } : {}
40079
+ }),
40080
+ redirect: "error",
40081
+ cache: "no-store",
40082
+ credentials: "omit",
40083
+ signal: AbortSignal.any([abort.signal, AbortSignal.timeout(15e3)])
40084
+ });
40085
+ } catch {
40086
+ throw new PlumeBuildError(
40087
+ "VALIDATION_FAILED",
40088
+ "Plume could not confirm this build. No framework build was started."
40089
+ );
40090
+ }
40091
+ if (response.status !== 200) {
39971
40092
  await response.body?.cancel();
39972
- throw new Error();
40093
+ throw new PlumeBuildError(
40094
+ "VALIDATION_FAILED",
40095
+ "Plume could not confirm this build. No framework build was started."
40096
+ );
39973
40097
  }
39974
- } catch {
39975
- throw new PlumeBuildError(
39976
- "VALIDATION_FAILED",
39977
- "Plume could not confirm this build. Build a commit whose plume.lock names prepared or published content (Plume commits it when you prepare or publish an Update), with the plume.schema.ts committed beside it."
39978
- );
39979
- }
39980
- try {
39981
- const result = validationSchema.parse(
39982
- await boundedJson(response, MAX_RESPONSE_BYTES2)
39983
- );
39984
- if (canonicalJson(result.binding) !== canonicalJson(binding))
39985
- throw new Error();
39986
- } catch {
39987
- throw new PlumeBuildError(
39988
- "INVALID_RESPONSE",
39989
- "Plume returned an invalid build validation response. No framework build was started."
39990
- );
40098
+ try {
40099
+ const result = validationSchema.parse(
40100
+ await boundedJson(response, MAX_RESPONSE_BYTES2)
40101
+ );
40102
+ if (canonicalJson(result.binding) !== canonicalJson(binding) || operationId && (!result.candidate || result.candidate.commitSha !== commitSha || result.candidate.operationId !== operationId))
40103
+ throw Error();
40104
+ return result;
40105
+ } catch {
40106
+ throw new PlumeBuildError(
40107
+ "INVALID_RESPONSE",
40108
+ "Plume returned an invalid build validation response. No framework build was started."
40109
+ );
40110
+ }
40111
+ } finally {
40112
+ process.off("SIGINT", interrupt);
40113
+ process.off("SIGTERM", interrupt);
39991
40114
  }
39992
40115
  }
39993
40116
  async function runCommand2(cwd, command) {
@@ -40029,6 +40152,7 @@ async function runBuild(options2) {
40029
40152
  const cwd = resolve8(options2.cwd);
40030
40153
  const directory = resolve8(cwd, ".plume");
40031
40154
  const bindingFile = resolve8(directory, "binding.json");
40155
+ const deliveryFile = resolve8(directory, "delivery.json");
40032
40156
  try {
40033
40157
  await mkdir4(directory, { recursive: true });
40034
40158
  if (!(await lstat5(directory)).isDirectory()) throw new Error();
@@ -40041,6 +40165,7 @@ async function runBuild(options2) {
40041
40165
  const temporary = resolve8(directory, `.binding-${randomUUID3()}.json`);
40042
40166
  try {
40043
40167
  await rm5(bindingFile, { force: true });
40168
+ await rm5(deliveryFile, { force: true });
40044
40169
  if (!options2.command.length || options2.command.some(
40045
40170
  (part) => typeof part !== "string" || part.includes("\0")
40046
40171
  ) || !options2.command[0]?.trim())
@@ -40051,17 +40176,80 @@ async function runBuild(options2) {
40051
40176
  const url2 = validationUrl(options2.endpoint);
40052
40177
  const binding = await readLock(cwd);
40053
40178
  await validateSchema(cwd, options2.schemaPath ?? "plume.schema.ts", binding);
40054
- await validateRemote(url2, binding);
40179
+ const commitSha = await git(cwd, "rev-parse", "HEAD");
40180
+ if (await git(cwd, "status", "--porcelain=v1", "--untracked-files=all"))
40181
+ throw new PlumeBuildError(
40182
+ "INVALID_CONFIGURATION",
40183
+ "Build from a clean Git checkout so the compiled code identity names the code being built."
40184
+ );
40185
+ if (!/^[a-f0-9]{40}$/.test(commitSha))
40186
+ throw new PlumeBuildError(
40187
+ "INVALID_CONFIGURATION",
40188
+ "Build from an exact Git commit."
40189
+ );
40190
+ const requested = options2.delivery ?? "static";
40191
+ let mode = requested === "auto" ? "production-ssr" : requested;
40192
+ let operationId;
40193
+ const trailers = requested === "selected-preview" || requested === "auto" ? /^Prepare Plume publication\n\nPlume-Publication: ([a-f0-9-]{36})\nPlume-Content: ([a-f0-9-]{36})\nPlume-Schema: (sha256:[a-f0-9]{64})$/.exec(
40194
+ await git(cwd, "show", "-s", "--format=%B", "HEAD")
40195
+ ) : null;
40196
+ if (requested === "selected-preview" || trailers) {
40197
+ mode = "selected-preview";
40198
+ const candidate = previewCandidateSchema.safeParse({
40199
+ operationId: trailers?.[1],
40200
+ commitSha
40201
+ });
40202
+ if (!candidate.success || trailers?.[2] !== binding.contentVersionId || trailers?.[3] !== binding.schemaHash)
40203
+ throw new PlumeBuildError(
40204
+ "INVALID_CONFIGURATION",
40205
+ "Build a selected preview from its exact Plume binding commit and matching lock."
40206
+ );
40207
+ operationId = candidate.data.operationId;
40208
+ }
40209
+ const validation = await validateRemote(
40210
+ url2,
40211
+ binding,
40212
+ commitSha,
40213
+ operationId
40214
+ );
40215
+ const descriptor = deliveryDescriptorSchema.safeParse({
40216
+ version: 1,
40217
+ mode,
40218
+ artifact: {
40219
+ commitSha,
40220
+ environment: options2.environment ?? (mode === "selected-preview" ? "preview" : "production")
40221
+ },
40222
+ binding,
40223
+ candidate: mode === "selected-preview" ? validation.candidate ?? null : null
40224
+ });
40225
+ if (!descriptor.success)
40226
+ throw new PlumeBuildError(
40227
+ "VALIDATION_FAILED",
40228
+ "Choose a valid delivery mode; a selected preview requires an exact native reservation."
40229
+ );
40230
+ await writeFile3(
40231
+ deliveryFile,
40232
+ `${JSON.stringify(descriptor.data, null, 2)}
40233
+ `,
40234
+ { flag: "wx", mode: 420 }
40235
+ );
40055
40236
  await writeFile3(temporary, `${JSON.stringify(binding, null, 2)}
40056
40237
  `, {
40057
40238
  flag: "wx",
40058
40239
  mode: 420
40059
40240
  });
40060
40241
  await rename3(temporary, bindingFile);
40242
+ if (await git(cwd, "rev-parse", "HEAD") !== commitSha || await git(cwd, "status", "--porcelain=v1", "--untracked-files=all"))
40243
+ throw new PlumeBuildError(
40244
+ "INVALID_CONFIGURATION",
40245
+ "The checkout changed while validating the build."
40246
+ );
40061
40247
  return { exitCode: await runCommand2(cwd, options2.command), binding };
40062
40248
  } catch (error62) {
40063
40249
  await rm5(bindingFile, { force: true }).catch(() => {
40064
40250
  });
40251
+ await rm5(deliveryFile, { force: true }).catch(() => {
40252
+ });
40065
40253
  if (error62 instanceof PlumeBuildError) throw error62;
40066
40254
  throw new PlumeBuildError(
40067
40255
  "ARTIFACT_FAILED",
@@ -40152,15 +40340,36 @@ ${developerHelp}
40152
40340
  }
40153
40341
  const divider = args.indexOf("--");
40154
40342
  const prefix = args.slice(0, divider);
40155
- if (divider < 1 || prefix.length !== 1 || prefix[0] !== "build" || divider === args.length - 1) {
40343
+ if (divider < 1 || ![1, 3, 5].includes(prefix.length) || prefix[0] !== "build" || divider === args.length - 1) {
40156
40344
  process.stderr.write("Usage: plume build -- <command ...>\n");
40157
40345
  return 1;
40158
40346
  }
40159
40347
  try {
40348
+ const buildFlags = /* @__PURE__ */ new Map();
40349
+ for (let i = 1; i < prefix.length; i += 2) {
40350
+ const flag = prefix[i], value = prefix[i + 1];
40351
+ if (!flag || !value || !["--delivery", "--environment"].includes(flag) || buildFlags.has(flag))
40352
+ throw new PlumeBuildError(
40353
+ "INVALID_CONFIGURATION",
40354
+ "Usage: plume build [--delivery auto|production-ssr|selected-preview|static] [--environment production|preview] -- <command ...>"
40355
+ );
40356
+ buildFlags.set(flag, value);
40357
+ }
40358
+ const mode = buildFlags.get("--delivery") ?? "static";
40359
+ const environment = buildFlags.get("--environment");
40360
+ if (!["auto", "production-ssr", "selected-preview", "static"].includes(
40361
+ mode
40362
+ ) || environment && !["production", "preview"].includes(environment))
40363
+ throw new PlumeBuildError(
40364
+ "INVALID_CONFIGURATION",
40365
+ "Choose a supported delivery mode and environment."
40366
+ );
40160
40367
  const result = await runBuild({
40161
40368
  cwd: process.cwd(),
40162
40369
  command: args.slice(divider + 1),
40163
- endpoint: env2.PLUME_ENDPOINT || DEFAULT_ENDPOINT
40370
+ endpoint: env2.PLUME_ENDPOINT || DEFAULT_ENDPOINT,
40371
+ delivery: mode,
40372
+ ...environment ? { environment } : {}
40164
40373
  });
40165
40374
  return result.exitCode;
40166
40375
  } catch (error62) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plume-press/cli",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "The plume command: set up a website's Plume CMS and check its builds.",
5
5
  "homepage": "https://app.plume.press",
6
6
  "license": "MIT",