@firstdraft.com/cli 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/docs/README.md +1 -1
- package/docs/commands.md +659 -132
- package/docs/errors.md +227 -73
- package/package.json +7 -1
- package/src/agent-sentences.js +210 -0
- package/src/api-authentication.js +25 -6
- package/src/api-response.js +110 -6
- package/src/cli.js +3143 -912
- package/src/commands/account.js +97 -0
- package/src/commands/compilation.js +57 -5
- package/src/commands/login.js +246 -42
- package/src/commands/maintain.js +662 -0
- package/src/commands/note.js +204 -0
- package/src/commands/plan-compile.js +44 -77
- package/src/commands/plan-init.js +14 -1
- package/src/commands/plan-push.js +26 -12
- package/src/commands/plan-status.js +1 -1
- package/src/commands/report.js +469 -0
- package/src/commands/sketches.js +388 -0
- package/src/commands/start.js +52 -0
- package/src/compilation-artifact.js +39 -4
- package/src/credentials.js +145 -7
- package/src/oauth.js +33 -25
- package/src/plan-compile-progress.js +8 -81
- package/src/plan-state.js +325 -5
- package/src/root-output.js +13 -1
- package/src/service-client.js +513 -0
- package/src/sketch-capture.js +449 -0
- package/src/commands/plan-publish.js +0 -1146
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { ApiAuthenticationRequiredError } from "../api-authentication.js";
|
|
2
|
+
import { isUtf8 } from "node:buffer";
|
|
3
|
+
import {
|
|
4
|
+
mkdirSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
renameSync,
|
|
9
|
+
unlinkSync,
|
|
10
|
+
mkdtempSync,
|
|
11
|
+
rmSync,
|
|
12
|
+
linkSync,
|
|
13
|
+
} from "node:fs";
|
|
14
|
+
import { isFileSystemError } from "../file-system.js";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
import {
|
|
17
|
+
SERVICE_ROUTES,
|
|
18
|
+
serviceEndpoint,
|
|
19
|
+
sendRequest,
|
|
20
|
+
readResponseBody,
|
|
21
|
+
isProblemBody,
|
|
22
|
+
reviewConflict,
|
|
23
|
+
problemProjection,
|
|
24
|
+
responseMediaType,
|
|
25
|
+
isDiagnostic,
|
|
26
|
+
} from "../api-response.js";
|
|
27
|
+
import { generateUuidV7 } from "../uuid-v7.js";
|
|
28
|
+
import {
|
|
29
|
+
withPlanStateLock,
|
|
30
|
+
PlanStateLocalError,
|
|
31
|
+
readPlanState,
|
|
32
|
+
isUuidV7,
|
|
33
|
+
readLocalFile,
|
|
34
|
+
} from "../plan-state.js";
|
|
35
|
+
import { resolveApiUrl } from "./plan-push.js";
|
|
36
|
+
import {
|
|
37
|
+
digest,
|
|
38
|
+
captureBoard,
|
|
39
|
+
loadSources,
|
|
40
|
+
SketchError,
|
|
41
|
+
} from "../sketch-capture.js";
|
|
42
|
+
export { SketchError };
|
|
43
|
+
const privateWrite = { flag: "wx", mode: 0o600, flush: true };
|
|
44
|
+
/** @param {string} file @param {unknown} data @param {boolean} [exclusive] */
|
|
45
|
+
function save(file, data, exclusive = false) {
|
|
46
|
+
const temp = file + "." + generateUuidV7() + ".tmp";
|
|
47
|
+
writeFileSync(temp, JSON.stringify(data) + "\n", privateWrite);
|
|
48
|
+
try {
|
|
49
|
+
if (exclusive) linkSync(temp, file);
|
|
50
|
+
else renameSync(temp, file);
|
|
51
|
+
} finally {
|
|
52
|
+
if (existsSync(temp)) unlinkSync(temp);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** @typedef {{cwd:string,apiUrl?:string,fetchFunction:typeof globalThis.fetch,hasTokenFor?:(origin:string)=>boolean}} Options */
|
|
56
|
+
/** @param {Options} options */
|
|
57
|
+
export async function startProject({
|
|
58
|
+
cwd,
|
|
59
|
+
apiUrl,
|
|
60
|
+
fetchFunction,
|
|
61
|
+
hasTokenFor,
|
|
62
|
+
}) {
|
|
63
|
+
const dir = path.join(cwd, ".firstdraft");
|
|
64
|
+
const existing = existsSync(dir) ? readPlanState({ cwd }) : null;
|
|
65
|
+
const origin = resolveApiUrl(apiUrl, existing?.api_url);
|
|
66
|
+
if (hasTokenFor && !hasTokenFor(origin))
|
|
67
|
+
throw new ApiAuthenticationRequiredError();
|
|
68
|
+
if (!existing) {
|
|
69
|
+
const temp = mkdtempSync(path.join(cwd, ".firstdraft-start-"));
|
|
70
|
+
try {
|
|
71
|
+
writeFileSync(path.join(temp, ".gitignore"), "*\n", privateWrite);
|
|
72
|
+
save(path.join(temp, "state.json"), {
|
|
73
|
+
format: "firstdraft.cli-state/1",
|
|
74
|
+
project_id: generateUuidV7(),
|
|
75
|
+
reserved: true,
|
|
76
|
+
api_url: origin,
|
|
77
|
+
});
|
|
78
|
+
renameSync(temp, dir);
|
|
79
|
+
} finally {
|
|
80
|
+
rmSync(temp, { force: true, recursive: true });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const state = existing ?? readPlanState({ cwd });
|
|
84
|
+
if (!state.reserved)
|
|
85
|
+
throw new SketchError(
|
|
86
|
+
"This planning directory already has a Plan. Resume its existing workflow.",
|
|
87
|
+
);
|
|
88
|
+
const response = await sendRequest(
|
|
89
|
+
fetchFunction,
|
|
90
|
+
serviceEndpoint(SERVICE_ROUTES.startProject, origin, {
|
|
91
|
+
project_id: state.project_id,
|
|
92
|
+
}),
|
|
93
|
+
{
|
|
94
|
+
headers: { Accept: "application/json" },
|
|
95
|
+
redirect: "error",
|
|
96
|
+
signal: AbortSignal.timeout(30000),
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
const body = await readResponseBody(response);
|
|
100
|
+
if (![200, 201].includes(response.status))
|
|
101
|
+
throw new SketchError(
|
|
102
|
+
"First Draft could not open the Project. Check the hosted Sketches endpoint and retry in this directory.",
|
|
103
|
+
response.status,
|
|
104
|
+
problem(response, body),
|
|
105
|
+
);
|
|
106
|
+
const url = new URL("/projects/" + state.project_id, origin).href;
|
|
107
|
+
if (
|
|
108
|
+
responseMediaType(response) !== "application/json" ||
|
|
109
|
+
body?.project?.id !== state.project_id ||
|
|
110
|
+
![url, "/projects/" + state.project_id].includes(body.project.url)
|
|
111
|
+
)
|
|
112
|
+
throw new SketchError("Unexpected Project identity in the response.");
|
|
113
|
+
return { project: { id: state.project_id, url } };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** @param {string} cwd @param {string} [revision] */
|
|
117
|
+
function readReview(cwd, revision) {
|
|
118
|
+
const file = revision
|
|
119
|
+
? path.join(cwd, ".firstdraft", "sketch-reviews", revision + ".json")
|
|
120
|
+
: path.join(cwd, ".firstdraft", "sketch-review.json");
|
|
121
|
+
if (!existsSync(file)) return null;
|
|
122
|
+
/** @type {{id:string,plan_sha256:string,files:Record<string,string>}} */
|
|
123
|
+
const receipt = JSON.parse(readLocalFile(file, 1024 * 1024).toString());
|
|
124
|
+
if (
|
|
125
|
+
!receipt ||
|
|
126
|
+
!isUuidV7(receipt.id) ||
|
|
127
|
+
!receipt.files ||
|
|
128
|
+
!/^[a-f0-9]{64}$/.test(receipt.plan_sha256)
|
|
129
|
+
)
|
|
130
|
+
throw new SketchError("Invalid local sketch review receipt.");
|
|
131
|
+
return receipt;
|
|
132
|
+
}
|
|
133
|
+
/** @typedef {Options & {capture?:typeof captureBoard, after?:string, head?:string}} PublishOptions */
|
|
134
|
+
/** @param {PublishOptions} options */
|
|
135
|
+
export async function publishSketches(options) {
|
|
136
|
+
return withPlanStateLock(path.join(options.cwd, ".firstdraft"), () =>
|
|
137
|
+
publishCurrentSketches(options),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** @param {PublishOptions} options */
|
|
142
|
+
async function publishCurrentSketches({
|
|
143
|
+
cwd,
|
|
144
|
+
apiUrl,
|
|
145
|
+
fetchFunction,
|
|
146
|
+
hasTokenFor,
|
|
147
|
+
capture = captureBoard,
|
|
148
|
+
after,
|
|
149
|
+
head,
|
|
150
|
+
}) {
|
|
151
|
+
const dir = path.join(cwd, ".firstdraft");
|
|
152
|
+
const state = readPlanState({ cwd });
|
|
153
|
+
if (!state.reserved)
|
|
154
|
+
throw new SketchError(
|
|
155
|
+
"Use firstdraft project start in the hosted interview directory.",
|
|
156
|
+
);
|
|
157
|
+
const origin = resolveApiUrl(apiUrl, state.api_url);
|
|
158
|
+
if (hasTokenFor && !hasTokenFor(origin))
|
|
159
|
+
throw new ApiAuthenticationRequiredError();
|
|
160
|
+
const pendingFile = path.join(dir, "sketch-pending.json");
|
|
161
|
+
const replay = existsSync(pendingFile);
|
|
162
|
+
if (!replay) {
|
|
163
|
+
const previous = after === "none" ? null : (after ?? readReview(cwd)?.id);
|
|
164
|
+
const planBytes = readLocalFile(
|
|
165
|
+
path.join(dir, "foundation-plan.json"),
|
|
166
|
+
1024 * 1024,
|
|
167
|
+
);
|
|
168
|
+
if (!isUtf8(planBytes))
|
|
169
|
+
throw new SketchError("The Foundation Plan must contain valid UTF-8.");
|
|
170
|
+
const plan_source = planBytes.toString("utf8");
|
|
171
|
+
const sources = loadSources(cwd);
|
|
172
|
+
const manifest = await capture(sources, plan_source);
|
|
173
|
+
const body = JSON.stringify({
|
|
174
|
+
previous_revision_id: previous ?? null,
|
|
175
|
+
expected_plan_sha256:
|
|
176
|
+
head === "none"
|
|
177
|
+
? null
|
|
178
|
+
: (head ?? state.foundation_plan_etag?.slice(8, -1) ?? null),
|
|
179
|
+
plan_source,
|
|
180
|
+
manifest,
|
|
181
|
+
});
|
|
182
|
+
if (Buffer.byteLength(body) > 24 * 1024 * 1024)
|
|
183
|
+
throw new SketchError("The review bundle exceeds 24 MiB.");
|
|
184
|
+
save(
|
|
185
|
+
pendingFile,
|
|
186
|
+
{
|
|
187
|
+
id: generateUuidV7(),
|
|
188
|
+
local_etag: state.foundation_plan_etag,
|
|
189
|
+
body,
|
|
190
|
+
files: Object.fromEntries(
|
|
191
|
+
[...sources.files].map(([name, bytes]) => [name, digest(bytes)]),
|
|
192
|
+
),
|
|
193
|
+
},
|
|
194
|
+
true,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
const pending = JSON.parse(
|
|
198
|
+
readLocalFile(pendingFile, 52 * 1024 * 1024).toString(),
|
|
199
|
+
);
|
|
200
|
+
if (!isUuidV7(pending.id))
|
|
201
|
+
throw new SketchError("The pending review ID is invalid.");
|
|
202
|
+
const request = JSON.parse(pending.body);
|
|
203
|
+
if (
|
|
204
|
+
after &&
|
|
205
|
+
(request.previous_revision_id !== (after === "none" ? null : after) ||
|
|
206
|
+
request.expected_plan_sha256 !== (head === "none" ? null : head))
|
|
207
|
+
)
|
|
208
|
+
throw new SketchError(
|
|
209
|
+
"The pending publication has different preconditions. Run sketches publish without options to replay it.",
|
|
210
|
+
);
|
|
211
|
+
const response = await sendRequest(
|
|
212
|
+
fetchFunction,
|
|
213
|
+
serviceEndpoint(SERVICE_ROUTES.publishSketches, origin, {
|
|
214
|
+
project_id: state.project_id,
|
|
215
|
+
revision_id: pending.id,
|
|
216
|
+
}),
|
|
217
|
+
{
|
|
218
|
+
headers: {
|
|
219
|
+
Accept: "application/json",
|
|
220
|
+
"Content-Type": "application/vnd.firstdraft.sketch-review+json",
|
|
221
|
+
},
|
|
222
|
+
body: pending.body,
|
|
223
|
+
redirect: "error",
|
|
224
|
+
signal: AbortSignal.timeout(120000),
|
|
225
|
+
},
|
|
226
|
+
);
|
|
227
|
+
const body = await readResponseBody(response);
|
|
228
|
+
if (![200, 201].includes(response.status)) {
|
|
229
|
+
const rejection = problem(response, body);
|
|
230
|
+
const refusedThisRequest =
|
|
231
|
+
response.status >= 400 &&
|
|
232
|
+
response.status < 500 &&
|
|
233
|
+
response.status !== 408;
|
|
234
|
+
// A refused retry resolves the original ambiguity only after the Service
|
|
235
|
+
// has looked up its revision ID. Authorization and quotas on the endpoint
|
|
236
|
+
// itself run before that lookup.
|
|
237
|
+
const resolvedRevision =
|
|
238
|
+
rejection &&
|
|
239
|
+
(("code" in rejection &&
|
|
240
|
+
((rejection.code === "invalid_sketch_review" &&
|
|
241
|
+
response.status === 422) ||
|
|
242
|
+
(rejection.code === "sketch_review_conflict" &&
|
|
243
|
+
response.status === 409) ||
|
|
244
|
+
(rejection.code === "compilation_active" &&
|
|
245
|
+
response.status === 409) ||
|
|
246
|
+
(rejection.code === "invalid_sketch_review" &&
|
|
247
|
+
response.status === 422) ||
|
|
248
|
+
(rejection.code === "sketch_quota_reached" &&
|
|
249
|
+
response.status === 413))) ||
|
|
250
|
+
("diagnostics" in rejection && response.status === 422));
|
|
251
|
+
if (refusedThisRequest && (!replay || resolvedRevision))
|
|
252
|
+
unlinkSync(pendingFile);
|
|
253
|
+
throw new SketchError(
|
|
254
|
+
"First Draft declined the sketch review. Inspect the current review and repair the draft.",
|
|
255
|
+
response.status,
|
|
256
|
+
rejection,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
const sha = request.manifest.plan_sha256;
|
|
260
|
+
const etag = response.headers.get("etag");
|
|
261
|
+
if (
|
|
262
|
+
responseMediaType(response) !== "application/json" ||
|
|
263
|
+
etag !== '"sha256:' + sha + '"' ||
|
|
264
|
+
body?.project?.id !== state.project_id ||
|
|
265
|
+
body?.review?.id !== pending.id ||
|
|
266
|
+
body?.review?.plan_sha256 !== sha ||
|
|
267
|
+
body?.foundation_plan?.source_sha256 !== sha
|
|
268
|
+
)
|
|
269
|
+
throw new SketchError(
|
|
270
|
+
"Unexpected review identity. Retry the same publication.",
|
|
271
|
+
);
|
|
272
|
+
const latest = readPlanState({ cwd });
|
|
273
|
+
const knownHead = latest.foundation_plan_etag?.slice(8, -1) ?? null;
|
|
274
|
+
if (
|
|
275
|
+
knownHead === request.expected_plan_sha256 ||
|
|
276
|
+
latest.foundation_plan_etag === pending.local_etag
|
|
277
|
+
) {
|
|
278
|
+
save(path.join(dir, "state.json"), {
|
|
279
|
+
...latest,
|
|
280
|
+
foundation_plan_etag: etag,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
const receipt = { id: pending.id, plan_sha256: sha, files: pending.files };
|
|
284
|
+
const archive = path.join(dir, "sketch-reviews");
|
|
285
|
+
mkdirSync(archive, { recursive: true, mode: 0o700 });
|
|
286
|
+
const previous = readReview(cwd);
|
|
287
|
+
if (previous) {
|
|
288
|
+
const oldFile = path.join(archive, previous.id + ".json");
|
|
289
|
+
if (!existsSync(oldFile)) save(oldFile, previous);
|
|
290
|
+
}
|
|
291
|
+
save(path.join(archive, pending.id + ".json"), receipt);
|
|
292
|
+
save(path.join(dir, "sketch-review.json"), receipt);
|
|
293
|
+
unlinkSync(pendingFile);
|
|
294
|
+
let nextStep;
|
|
295
|
+
if (replay) {
|
|
296
|
+
try {
|
|
297
|
+
reviewedSources(cwd, pending.id);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (!(
|
|
300
|
+
error instanceof SketchError || error instanceof PlanStateLocalError
|
|
301
|
+
))
|
|
302
|
+
throw error;
|
|
303
|
+
nextStep =
|
|
304
|
+
"Recovered the saved publication. The current planning files do not match this review. Run firstdraft sketches publish again to capture and publish the current draft.";
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
project: {
|
|
309
|
+
id: state.project_id,
|
|
310
|
+
url: new URL("/projects/" + state.project_id, origin).href,
|
|
311
|
+
},
|
|
312
|
+
review: { id: pending.id, plan_sha256: sha },
|
|
313
|
+
...(nextStep ? { next_step: nextStep } : {}),
|
|
314
|
+
foundation_plan: { source_sha256: sha },
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** @param {string} cwd @param {string|undefined} revision @param {boolean} [retained] */
|
|
319
|
+
export function reviewedSources(cwd, revision, retained = false) {
|
|
320
|
+
try {
|
|
321
|
+
return loadReviewedSources(cwd, revision, retained);
|
|
322
|
+
} catch (error) {
|
|
323
|
+
if (!isFileSystemError(error) && !(error instanceof SyntaxError))
|
|
324
|
+
throw error;
|
|
325
|
+
throw new SketchError(
|
|
326
|
+
"Restore the approved board, source files and local review receipt before Compile.",
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** @param {string} cwd @param {string|undefined} revision @param {boolean} [retained] */
|
|
332
|
+
function loadReviewedSources(cwd, revision, retained) {
|
|
333
|
+
const receipt =
|
|
334
|
+
(retained && isUuidV7(revision) ? readReview(cwd, revision) : null) ??
|
|
335
|
+
readReview(cwd);
|
|
336
|
+
if (!receipt && !revision) {
|
|
337
|
+
if (
|
|
338
|
+
!retained &&
|
|
339
|
+
existsSync(path.join(cwd, ".firstdraft", "state.json")) &&
|
|
340
|
+
readPlanState({ cwd }).reserved
|
|
341
|
+
)
|
|
342
|
+
throw new SketchError(
|
|
343
|
+
"Publish the Sketches and obtain approval for the revision before Compile.",
|
|
344
|
+
);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (!receipt || receipt.id !== revision)
|
|
348
|
+
throw new SketchError(
|
|
349
|
+
retained
|
|
350
|
+
? "Restore the local receipt for this Compilation’s sketch revision in the planning folder before downloading."
|
|
351
|
+
: "Compile with --revision followed by the approved sketch revision ID.",
|
|
352
|
+
);
|
|
353
|
+
const sources = loadSources(cwd);
|
|
354
|
+
if (
|
|
355
|
+
digest(
|
|
356
|
+
readFileSync(path.join(cwd, ".firstdraft", "foundation-plan.json")),
|
|
357
|
+
) !== receipt.plan_sha256 ||
|
|
358
|
+
sources.files.size !== Object.keys(receipt.files).length ||
|
|
359
|
+
[...sources.files].some(
|
|
360
|
+
([name, bytes]) => digest(bytes) !== receipt.files[name],
|
|
361
|
+
)
|
|
362
|
+
)
|
|
363
|
+
throw new SketchError(
|
|
364
|
+
"The Plan or sketch sources changed since review. Publish and review the changes before Compile.",
|
|
365
|
+
);
|
|
366
|
+
return { files: sources.files, planSha256: receipt.plan_sha256 };
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** @param {Response} response @param {Record<string,any>|null} body */
|
|
370
|
+
function problem(response, body) {
|
|
371
|
+
if (!body) return;
|
|
372
|
+
const conflict = reviewConflict(response, body);
|
|
373
|
+
if (conflict) return conflict;
|
|
374
|
+
if (isProblemBody(response, body)) return problemProjection(body);
|
|
375
|
+
if (
|
|
376
|
+
response.status === 422 &&
|
|
377
|
+
Array.isArray(body.diagnostics) &&
|
|
378
|
+
body.diagnostics.every(isDiagnostic)
|
|
379
|
+
)
|
|
380
|
+
return {
|
|
381
|
+
diagnostics: body.diagnostics.map(({ code, message, severity }) => ({
|
|
382
|
+
code,
|
|
383
|
+
message,
|
|
384
|
+
severity,
|
|
385
|
+
})),
|
|
386
|
+
};
|
|
387
|
+
return undefined;
|
|
388
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
environmentTokenFor,
|
|
3
|
+
environmentTokenVariable,
|
|
4
|
+
storedTokenFor,
|
|
5
|
+
} from "../api-authentication.js";
|
|
6
|
+
import { readAccount } from "./account.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Which token a request to `origin` would carry: one set in the environment
|
|
10
|
+
* takes precedence over a saved login.
|
|
11
|
+
*
|
|
12
|
+
* @param {object} options
|
|
13
|
+
* @param {string} options.origin
|
|
14
|
+
* @param {string} [options.apiToken]
|
|
15
|
+
* @param {string} [options.stagingApiToken]
|
|
16
|
+
* @param {() => Readonly<Record<string, string>>} options.readStoredTokens
|
|
17
|
+
* from storedTokenReader, which reads an unreadable or malformed
|
|
18
|
+
* credentials file as no saved login, as every other command does
|
|
19
|
+
* @returns {{origin: string, saved: boolean, environmentVariable: string | null}}
|
|
20
|
+
*/
|
|
21
|
+
export function readLoginState({
|
|
22
|
+
origin,
|
|
23
|
+
apiToken,
|
|
24
|
+
stagingApiToken,
|
|
25
|
+
readStoredTokens,
|
|
26
|
+
}) {
|
|
27
|
+
return {
|
|
28
|
+
origin,
|
|
29
|
+
saved: storedTokenFor(readStoredTokens(), origin) !== undefined,
|
|
30
|
+
environmentVariable:
|
|
31
|
+
environmentTokenFor(origin, { apiToken, stagingApiToken }) === undefined
|
|
32
|
+
? null
|
|
33
|
+
: environmentTokenVariable(origin),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The one request `firstdraft start` makes. A response that told the CLI to
|
|
39
|
+
* stop, such as a minimum version this setup is below, leaves it not ready,
|
|
40
|
+
* so it replaces the result, a failed one included, although no later
|
|
41
|
+
* request was left to send.
|
|
42
|
+
*
|
|
43
|
+
* @param {import("./account.js").ReadAccountOptions & {service: import("../service-client.js").ServiceSession}} options
|
|
44
|
+
*/
|
|
45
|
+
export async function readReadiness({ service, ...request }) {
|
|
46
|
+
const account = await readAccount(request).catch((error) => {
|
|
47
|
+
service.throwIfStopped();
|
|
48
|
+
throw error;
|
|
49
|
+
});
|
|
50
|
+
service.throwIfStopped();
|
|
51
|
+
return account;
|
|
52
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
mkdirSync,
|
|
6
6
|
mkdtempSync,
|
|
7
7
|
readdirSync,
|
|
8
|
+
realpathSync,
|
|
8
9
|
readFileSync,
|
|
9
10
|
renameSync,
|
|
10
11
|
rmSync,
|
|
@@ -27,7 +28,10 @@ export const ARTIFACT_MEDIA_TYPE =
|
|
|
27
28
|
"application/vnd.firstdraft.compilation-artifact+json";
|
|
28
29
|
export const ARTIFACT_FORMAT = "firstdraft.compilation-artifact/1";
|
|
29
30
|
export const FOUNDATION_PLAN_FORMAT = "firstdraft.foundation-plan.sketch/0.23";
|
|
30
|
-
|
|
31
|
+
// The one place the CLI names the Rails target profile: plan init writes it,
|
|
32
|
+
// artifact validation accepts only it, and the documentation test requires
|
|
33
|
+
// the docs to name only it. The value is the profile of this release.
|
|
34
|
+
export const RAILS_TARGET_PROFILE = "rails-sketch/2026-11";
|
|
31
35
|
export const MAX_ARTIFACT_BYTES = 128 * 1024 * 1024;
|
|
32
36
|
|
|
33
37
|
const ARTIFACT_KEYS = ["format", "provenance", "manifest_sha256", "files"];
|
|
@@ -275,8 +279,9 @@ export function releaseCompilationOutputTarget(target) {
|
|
|
275
279
|
/**
|
|
276
280
|
* @param {ValidatedCompilationArtifact} artifact
|
|
277
281
|
* @param {string | import("./root-output.js").RootOutputTarget} target
|
|
282
|
+
* @param {Map<string,Buffer>} [sketchFiles]
|
|
278
283
|
*/
|
|
279
|
-
export function materializeCompilationArtifact(artifact, target) {
|
|
284
|
+
export function materializeCompilationArtifact(artifact, target, sketchFiles) {
|
|
280
285
|
if (typeof target !== "string") {
|
|
281
286
|
try {
|
|
282
287
|
return materializeRootOutput(target, artifact, {
|
|
@@ -284,10 +289,29 @@ export function materializeCompilationArtifact(artifact, target) {
|
|
|
284
289
|
writeArtifactTree(artifact.files, root);
|
|
285
290
|
applyMode(root, DIRECTORY_MODE);
|
|
286
291
|
},
|
|
287
|
-
verifyArtifact: (root, ignoredPaths) =>
|
|
292
|
+
verifyArtifact: (root, ignoredPaths) => {
|
|
288
293
|
verifyArtifactTree(artifact.files, root, ignoredPaths, {
|
|
289
294
|
verifyRootMode: ignoredPaths === undefined,
|
|
290
|
-
})
|
|
295
|
+
});
|
|
296
|
+
},
|
|
297
|
+
verifyDesign: (designDirectory) => {
|
|
298
|
+
if (sketchFiles) {
|
|
299
|
+
const archive = path.join(designDirectory, "sketches");
|
|
300
|
+
for (const [name, bytes] of sketchFiles) {
|
|
301
|
+
const selected = path.join(archive, name);
|
|
302
|
+
if (
|
|
303
|
+
realpathSync(selected) !== selected ||
|
|
304
|
+
!lstatSync(selected).isFile() ||
|
|
305
|
+
!readFileSync(selected).equals(bytes)
|
|
306
|
+
) {
|
|
307
|
+
throw new RootOutputMaterializationError(
|
|
308
|
+
"The archived sketch sources changed after review.",
|
|
309
|
+
"reviewed_sources_changed",
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
},
|
|
291
315
|
});
|
|
292
316
|
} catch (error) {
|
|
293
317
|
if (!(error instanceof RootOutputMaterializationError)) throw error;
|
|
@@ -311,6 +335,17 @@ export function materializeCompilationArtifact(artifact, target) {
|
|
|
311
335
|
writeArtifactTree(artifact.files, temporaryDirectory);
|
|
312
336
|
applyMode(temporaryDirectory, DIRECTORY_MODE);
|
|
313
337
|
verifyArtifactTree(artifact.files, temporaryDirectory);
|
|
338
|
+
if (sketchFiles) {
|
|
339
|
+
const design = path.join(temporaryDirectory, ".firstdraft", "design");
|
|
340
|
+
mkdirSync(design, { recursive: true });
|
|
341
|
+
const root = path.join(design, "sketches");
|
|
342
|
+
mkdirSync(root);
|
|
343
|
+
for (const [name, bytes] of sketchFiles) {
|
|
344
|
+
const file = path.join(root, name);
|
|
345
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
346
|
+
writeFileSync(file, bytes, { flag: "wx" });
|
|
347
|
+
}
|
|
348
|
+
}
|
|
314
349
|
assertTargetStillAvailable(target, parent);
|
|
315
350
|
renameSync(temporaryDirectory, target);
|
|
316
351
|
temporaryDirectory = null;
|