@firstdraft.com/cli 0.2.0 → 0.2.2
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 +85 -63
- package/docs/README.md +11 -12
- package/docs/commands.md +150 -25
- package/docs/errors.md +78 -29
- package/docs/release-history.md +16 -0
- package/package.json +1 -1
- package/src/cli.js +317 -35
- package/src/commands/compilation.js +413 -32
- package/src/commands/plan-compile.js +124 -10
- package/src/compilation-artifact.js +116 -14
- package/src/plan-compile-progress.js +6 -2
- package/src/root-output.js +1485 -0
package/docs/release-history.md
CHANGED
|
@@ -30,3 +30,19 @@ the living [release policy and runbook](../RELEASING.md).
|
|
|
30
30
|
The alpha versions remain immutable registry history but, as of the August 12 observation, neither distribution
|
|
31
31
|
channel selected them. Protected tag `v0.1.0` and package version `0.1.0` were consumed and immutable. Preparing
|
|
32
32
|
source or documentation does not mutate either dist-tag.
|
|
33
|
+
|
|
34
|
+
## 0.2.0 candidate publication
|
|
35
|
+
|
|
36
|
+
- On August 27, 2026, protected tag `v0.2.0` published ordinary version `0.2.0` under `next`; `latest` remained
|
|
37
|
+
`0.1.0`. The candidate established compatibility with API contract `0.3.x` but did not displace the separately
|
|
38
|
+
promoted stable release.
|
|
39
|
+
- Package version `0.2.0` and protected tag `v0.2.0` are consumed and immutable. A backward-compatible addition to
|
|
40
|
+
the `0.2.x` line therefore requires a higher patch version rather than reusing those identities.
|
|
41
|
+
|
|
42
|
+
## 0.2.1 candidate publication
|
|
43
|
+
|
|
44
|
+
- On August 28, 2026, protected tag `v0.2.1` published ordinary version `0.2.1` under `next`; `latest` remained
|
|
45
|
+
`0.1.0`. The patch hardened direct Compilation recovery while preserving the `0.2.x` compatibility line.
|
|
46
|
+
- Package version `0.2.1` and protected tag `v0.2.1` are consumed and immutable. As observed on August 29, 2026,
|
|
47
|
+
current-directory root-output had integrated to `main` at `4352f64baf673ad93457e8bc84273e9d1d9a9501` (tree
|
|
48
|
+
`b43ba6de98e27328e548cc3410ba9f39dfa9fcee`) but was not part of those registry bytes.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -14,11 +14,18 @@ import {
|
|
|
14
14
|
CompilationArtifactInvalidError,
|
|
15
15
|
CompilationArtifactResponseInvalidError,
|
|
16
16
|
CompilationArtifactUnavailableError,
|
|
17
|
+
CompilationCancelledError,
|
|
17
18
|
CompilationChangedError,
|
|
19
|
+
CompilationFailedError,
|
|
20
|
+
CompilationLocalPlanChangedError,
|
|
21
|
+
CompilationLocalStateError,
|
|
18
22
|
CompilationMaterializationError,
|
|
19
23
|
CompilationNotSucceededError,
|
|
20
24
|
CompilationNotPushedError,
|
|
21
25
|
CompilationOutputPathError,
|
|
26
|
+
CompilationRetainedError,
|
|
27
|
+
CompilationRequestOutcomeUnknownError,
|
|
28
|
+
CompilationStartRejectedError,
|
|
22
29
|
CompilationStatusInvalidError,
|
|
23
30
|
CompilationStatusUnavailableError,
|
|
24
31
|
CompilationTimeoutError,
|
|
@@ -32,6 +39,7 @@ import {
|
|
|
32
39
|
PlanCompileAnalysisUnavailableError,
|
|
33
40
|
PlanCompilePushRejectedError,
|
|
34
41
|
compilePlan,
|
|
42
|
+
compilePlanToDirectory,
|
|
35
43
|
} from "./commands/plan-compile.js";
|
|
36
44
|
import { initializePlan } from "./commands/plan-init.js";
|
|
37
45
|
import {
|
|
@@ -92,7 +100,7 @@ Commands:
|
|
|
92
100
|
init Create a local empty Foundation Plan
|
|
93
101
|
push Send the local Foundation Plan to First Draft
|
|
94
102
|
status Read the current whole-graph analysis status
|
|
95
|
-
compile Compile
|
|
103
|
+
compile Compile the current Foundation Plan
|
|
96
104
|
|
|
97
105
|
Options:
|
|
98
106
|
-h, --help Show help
|
|
@@ -173,18 +181,23 @@ const PLAN_COMPILE_HELP = `First Draft CLI
|
|
|
173
181
|
|
|
174
182
|
Usage:
|
|
175
183
|
firstdraft plan compile
|
|
184
|
+
firstdraft plan compile --output <absent-directory|.>
|
|
176
185
|
|
|
177
186
|
Options:
|
|
178
|
-
|
|
187
|
+
--output <absent-directory|.> Materialize the generated application here
|
|
188
|
+
-h, --help Show help
|
|
179
189
|
|
|
180
190
|
Environment:
|
|
181
191
|
FIRSTDRAFT_API_TOKEN Authenticate API requests
|
|
182
192
|
FIRSTDRAFT_API_URL Override the initial API origin
|
|
183
193
|
|
|
184
194
|
The command submits the exact current whole-file Plan, waits for its analysis,
|
|
185
|
-
and proceeds only when that analysis is valid.
|
|
186
|
-
replays the internal GitHub Publication lifecycle
|
|
187
|
-
|
|
195
|
+
and proceeds only when that analysis is valid. Without --output, it conditionally
|
|
196
|
+
creates or replays the internal GitHub Publication lifecycle and prints the
|
|
197
|
+
private repository URL. With --output, it starts one direct Compilation and
|
|
198
|
+
atomically materializes the verified artifact into an absent directory, or
|
|
199
|
+
preserves existing root material under ./design when the output is ., without
|
|
200
|
+
starting GitHub Publication. Progress is written to stderr.
|
|
188
201
|
`;
|
|
189
202
|
|
|
190
203
|
const COMPILATION_HELP = `First Draft CLI
|
|
@@ -220,18 +233,19 @@ cancelled terminal states are successful status reads.
|
|
|
220
233
|
const COMPILATION_DOWNLOAD_HELP = `First Draft CLI
|
|
221
234
|
|
|
222
235
|
Usage:
|
|
223
|
-
firstdraft compilation download <compilation-id> --output <absent-path
|
|
236
|
+
firstdraft compilation download <compilation-id> --output <absent-path|.>
|
|
224
237
|
|
|
225
238
|
Options:
|
|
226
|
-
--output <absent-path
|
|
227
|
-
-h, --help
|
|
239
|
+
--output <absent-path|.> Materialize the generated application here
|
|
240
|
+
-h, --help Show help
|
|
228
241
|
|
|
229
242
|
Environment:
|
|
230
243
|
FIRSTDRAFT_API_TOKEN Authenticate API requests
|
|
231
244
|
|
|
232
245
|
The command reads the retained Compilation once, requires it to have
|
|
233
246
|
succeeded, downloads and verifies its exact artifact once, and atomically
|
|
234
|
-
|
|
247
|
+
materializes it into an absent output path or adopts the current directory
|
|
248
|
+
while preserving existing material under ./design. It never starts work.
|
|
235
249
|
`;
|
|
236
250
|
|
|
237
251
|
const PLAN_INIT_HELP = `First Draft CLI
|
|
@@ -312,6 +326,24 @@ const PLAN_COMPILE_ANALYSIS_REJECTED_DETAIL =
|
|
|
312
326
|
"First Draft rejected the current analysis status request.";
|
|
313
327
|
const PLAN_COMPILE_ANALYSIS_NOT_VALID_DETAIL =
|
|
314
328
|
"The current Foundation Plan analysis is not valid. Inspect its status and diagnostics before compiling again.";
|
|
329
|
+
const PLAN_COMPILE_LOCAL_PLAN_CHANGED_DETAIL =
|
|
330
|
+
"The local Foundation Plan changed after validation. Run 'firstdraft plan compile' again to submit the current bytes.";
|
|
331
|
+
const PLAN_COMPILE_DIRECT_REQUEST_OUTCOME_UNKNOWN_DETAIL =
|
|
332
|
+
"A Compilation may have started, but its response could not be verified. Do not rerun 'firstdraft plan compile --output' or start another Compilation until the current Project is reconciled.";
|
|
333
|
+
const PLAN_COMPILE_DIRECT_START_REJECTED_DETAIL =
|
|
334
|
+
"First Draft rejected the direct Compilation request.";
|
|
335
|
+
const PLAN_COMPILE_DIRECT_STATUS_UNAVAILABLE_DETAIL =
|
|
336
|
+
"Could not read the retained Compilation status. Use current.compilation.id with 'firstdraft compilation status'; do not start another Compilation.";
|
|
337
|
+
const PLAN_COMPILE_DIRECT_STATUS_INVALID_DETAIL =
|
|
338
|
+
"First Draft returned an invalid status for the retained Compilation. Preserve current.compilation.id for contract reconciliation; do not start another Compilation.";
|
|
339
|
+
const PLAN_COMPILE_DIRECT_CHANGED_DETAIL =
|
|
340
|
+
"The pinned Compilation changed while being polled. The command stopped without downloading an artifact.";
|
|
341
|
+
const PLAN_COMPILE_DIRECT_TIMEOUT_DETAIL =
|
|
342
|
+
"The retained Compilation is still processing after the bounded ten-minute wait. Use current.compilation.id with 'firstdraft compilation status'; do not rerun 'firstdraft plan compile --output' or start another Compilation.";
|
|
343
|
+
const PLAN_COMPILE_DIRECT_FAILED_DETAIL =
|
|
344
|
+
"The pinned Compilation failed. No artifact was downloaded or materialized.";
|
|
345
|
+
const PLAN_COMPILE_DIRECT_CANCELLED_DETAIL =
|
|
346
|
+
"The pinned Compilation was cancelled. No artifact was downloaded or materialized.";
|
|
315
347
|
const PLAN_PUBLISH_INCOMPATIBLE_STATE_DETAIL =
|
|
316
348
|
"The saved Foundation Plan ETag is incompatible with publication. No network request was made; reconcile the CLI and server contract.";
|
|
317
349
|
const PLAN_PUBLISH_NOT_PUSHED_DETAIL =
|
|
@@ -356,9 +388,15 @@ const COMPILATION_ARTIFACT_UNAVAILABLE_DETAIL =
|
|
|
356
388
|
const COMPILATION_ARTIFACT_INVALID_DETAIL =
|
|
357
389
|
"The downloaded Compilation artifact did not satisfy the integrity contract. No files were materialized.";
|
|
358
390
|
const COMPILATION_MATERIALIZATION_FAILED_DETAIL =
|
|
359
|
-
"The validated Compilation artifact could not be materialized at the requested
|
|
391
|
+
"The validated Compilation artifact could not be materialized at the requested output path.";
|
|
392
|
+
const PLAN_COMPILE_DIRECT_ARTIFACT_UNAVAILABLE_DETAIL =
|
|
393
|
+
"Could not download the retained Compilation artifact. Use current.compilation.id with 'firstdraft compilation download'; do not start another Compilation.";
|
|
394
|
+
const PLAN_COMPILE_DIRECT_ARTIFACT_INVALID_DETAIL =
|
|
395
|
+
"The retained Compilation artifact did not satisfy the integrity contract. Preserve current.compilation.id for reconciliation; do not start another Compilation.";
|
|
396
|
+
const PLAN_COMPILE_DIRECT_MATERIALIZATION_FAILED_DETAIL =
|
|
397
|
+
"The retained Compilation artifact was validated but could not be materialized. Use current.compilation.id with 'firstdraft compilation download' after repairing the output path; do not start another Compilation.";
|
|
360
398
|
const COMPILATION_INVALID_OUTPUT_PATH_DETAIL =
|
|
361
|
-
"The compilation output
|
|
399
|
+
"The compilation output must be an absent path beneath an existing real directory or the eligible current directory.";
|
|
362
400
|
const GENERATE_UUID_INVALID_ARGUMENTS_DETAIL =
|
|
363
401
|
"Invalid arguments. Run 'firstdraft generate uuid --help' for usage.";
|
|
364
402
|
const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
|
|
@@ -394,6 +432,7 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
|
|
|
394
432
|
* @property {typeof pushPlan} [planCompilePush]
|
|
395
433
|
* @property {typeof readPlanStatus} [planCompileReadStatus]
|
|
396
434
|
* @property {typeof import("./commands/plan-publish.js").publishPlan} [planCompilePublish]
|
|
435
|
+
* @property {typeof import("./commands/compilation.js").compileAndDownload} [planCompileDownload]
|
|
397
436
|
* @property {string} [apiUrl]
|
|
398
437
|
* @property {string} [apiToken]
|
|
399
438
|
*/
|
|
@@ -422,6 +461,7 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
|
|
|
422
461
|
* @property {typeof pushPlan} [planCompilePush]
|
|
423
462
|
* @property {typeof readPlanStatus} [planCompileReadStatus]
|
|
424
463
|
* @property {typeof import("./commands/plan-publish.js").publishPlan} [planCompilePublish]
|
|
464
|
+
* @property {typeof import("./commands/compilation.js").compileAndDownload} [planCompileDownload]
|
|
425
465
|
* @property {string} [apiUrl]
|
|
426
466
|
* @property {string} [apiToken]
|
|
427
467
|
*/
|
|
@@ -435,7 +475,7 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
|
|
|
435
475
|
*/
|
|
436
476
|
|
|
437
477
|
/**
|
|
438
|
-
* @typedef {Omit<CommandOptions, "cwd" | "createProjectId" | "createUuid" | "fileSystem" | "createTemporaryId" | "planStatusSleep" | "planStatusNow" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "apiUrl" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish"> & {cwd?: string, getCwd: () => string}} CompilationCommandOptions
|
|
478
|
+
* @typedef {Omit<CommandOptions, "cwd" | "createProjectId" | "createUuid" | "fileSystem" | "createTemporaryId" | "planStatusSleep" | "planStatusNow" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "apiUrl" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "planCompileDownload"> & {cwd?: string, getCwd: () => string}} CompilationCommandOptions
|
|
439
479
|
*/
|
|
440
480
|
|
|
441
481
|
/** @param {RunOptions} options */
|
|
@@ -463,6 +503,7 @@ export async function run({
|
|
|
463
503
|
planCompilePush,
|
|
464
504
|
planCompileReadStatus,
|
|
465
505
|
planCompilePublish,
|
|
506
|
+
planCompileDownload,
|
|
466
507
|
apiUrl = process.env.FIRSTDRAFT_API_URL,
|
|
467
508
|
apiToken = process.env.FIRSTDRAFT_API_TOKEN,
|
|
468
509
|
}) {
|
|
@@ -494,9 +535,12 @@ export async function run({
|
|
|
494
535
|
planCompileNow,
|
|
495
536
|
planPublishSleep,
|
|
496
537
|
planPublishNow,
|
|
538
|
+
compilationSleep,
|
|
539
|
+
compilationNow,
|
|
497
540
|
planCompilePush,
|
|
498
541
|
planCompileReadStatus,
|
|
499
542
|
planCompilePublish,
|
|
543
|
+
planCompileDownload,
|
|
500
544
|
apiUrl,
|
|
501
545
|
apiToken,
|
|
502
546
|
});
|
|
@@ -583,9 +627,12 @@ async function runPlan({
|
|
|
583
627
|
planCompileNow,
|
|
584
628
|
planPublishSleep,
|
|
585
629
|
planPublishNow,
|
|
630
|
+
compilationSleep,
|
|
631
|
+
compilationNow,
|
|
586
632
|
planCompilePush,
|
|
587
633
|
planCompileReadStatus,
|
|
588
634
|
planCompilePublish,
|
|
635
|
+
planCompileDownload,
|
|
589
636
|
apiUrl,
|
|
590
637
|
apiToken,
|
|
591
638
|
}) {
|
|
@@ -644,9 +691,12 @@ async function runPlan({
|
|
|
644
691
|
planCompileNow,
|
|
645
692
|
planPublishSleep,
|
|
646
693
|
planPublishNow,
|
|
694
|
+
compilationSleep,
|
|
695
|
+
compilationNow,
|
|
647
696
|
planCompilePush,
|
|
648
697
|
planCompileReadStatus,
|
|
649
698
|
planCompilePublish,
|
|
699
|
+
planCompileDownload,
|
|
650
700
|
apiUrl,
|
|
651
701
|
apiToken,
|
|
652
702
|
});
|
|
@@ -946,6 +996,7 @@ async function runCompilationDownload({
|
|
|
946
996
|
writeJson(stderr, {
|
|
947
997
|
error: "invalid_output_path",
|
|
948
998
|
detail: COMPILATION_INVALID_OUTPUT_PATH_DETAIL,
|
|
999
|
+
...(error.reason ? { reason: error.reason } : {}),
|
|
949
1000
|
});
|
|
950
1001
|
return 2;
|
|
951
1002
|
}
|
|
@@ -954,6 +1005,8 @@ async function runCompilationDownload({
|
|
|
954
1005
|
writeJson(stderr, {
|
|
955
1006
|
error: "materialization_failed",
|
|
956
1007
|
detail: COMPILATION_MATERIALIZATION_FAILED_DETAIL,
|
|
1008
|
+
...(error.reason ? { reason: error.reason } : {}),
|
|
1009
|
+
...(error.recoveryPath ? { recovery_path: error.recoveryPath } : {}),
|
|
957
1010
|
});
|
|
958
1011
|
return 1;
|
|
959
1012
|
}
|
|
@@ -1445,7 +1498,7 @@ async function runPlanStatus({
|
|
|
1445
1498
|
}
|
|
1446
1499
|
|
|
1447
1500
|
/**
|
|
1448
|
-
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "apiUrl" | "apiToken">} options
|
|
1501
|
+
* @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "compilationSleep" | "compilationNow" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "planCompileDownload" | "apiUrl" | "apiToken">} options
|
|
1449
1502
|
*/
|
|
1450
1503
|
async function runPlanCompile({
|
|
1451
1504
|
argv,
|
|
@@ -1460,16 +1513,22 @@ async function runPlanCompile({
|
|
|
1460
1513
|
planCompileNow,
|
|
1461
1514
|
planPublishSleep,
|
|
1462
1515
|
planPublishNow,
|
|
1516
|
+
compilationSleep,
|
|
1517
|
+
compilationNow,
|
|
1463
1518
|
planCompilePush,
|
|
1464
1519
|
planCompileReadStatus,
|
|
1465
1520
|
planCompilePublish,
|
|
1521
|
+
planCompileDownload,
|
|
1466
1522
|
apiUrl,
|
|
1467
1523
|
apiToken,
|
|
1468
1524
|
}) {
|
|
1469
1525
|
const parsed = parseArguments(() =>
|
|
1470
1526
|
parseArgs({
|
|
1471
1527
|
args: [...argv],
|
|
1472
|
-
options: {
|
|
1528
|
+
options: {
|
|
1529
|
+
output: { type: "string" },
|
|
1530
|
+
help: { type: "boolean", short: "h" },
|
|
1531
|
+
},
|
|
1473
1532
|
allowPositionals: false,
|
|
1474
1533
|
strict: true,
|
|
1475
1534
|
tokens: true,
|
|
@@ -1489,41 +1548,67 @@ async function runPlanCompile({
|
|
|
1489
1548
|
return 0;
|
|
1490
1549
|
}
|
|
1491
1550
|
|
|
1551
|
+
const output = parsed.values.output;
|
|
1552
|
+
if (output !== undefined && output.length === 0) {
|
|
1553
|
+
writeJson(stderr, {
|
|
1554
|
+
error: "invalid_arguments",
|
|
1555
|
+
detail: PLAN_COMPILE_INVALID_ARGUMENTS_DETAIL,
|
|
1556
|
+
});
|
|
1557
|
+
return 2;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1492
1560
|
const authorizedFetch = authenticatedFetch(fetchFunction, apiToken);
|
|
1493
1561
|
if (authorizedFetch === null) {
|
|
1494
1562
|
writeAuthenticationRequired(stderr);
|
|
1495
1563
|
return 1;
|
|
1496
1564
|
}
|
|
1497
1565
|
|
|
1498
|
-
let result;
|
|
1499
1566
|
const reportProgress = createPlanCompileProgressReporter(stderr);
|
|
1567
|
+
const shared = {
|
|
1568
|
+
cwd,
|
|
1569
|
+
apiUrl,
|
|
1570
|
+
fetchFunction: authorizedFetch,
|
|
1571
|
+
fileSystem: planPushFileSystem,
|
|
1572
|
+
createTemporaryId,
|
|
1573
|
+
createRequestSignal,
|
|
1574
|
+
analysisSleep: planCompileSleep,
|
|
1575
|
+
analysisNow: planCompileNow,
|
|
1576
|
+
push: planCompilePush,
|
|
1577
|
+
readStatus: planCompileReadStatus,
|
|
1578
|
+
onProgress: reportProgress,
|
|
1579
|
+
};
|
|
1580
|
+
if (output !== undefined) {
|
|
1581
|
+
try {
|
|
1582
|
+
const result = await compilePlanToDirectory({
|
|
1583
|
+
...shared,
|
|
1584
|
+
output,
|
|
1585
|
+
compilationSleep,
|
|
1586
|
+
compilationNow,
|
|
1587
|
+
compile: planCompileDownload,
|
|
1588
|
+
});
|
|
1589
|
+
writeJson(stdout, result);
|
|
1590
|
+
return 0;
|
|
1591
|
+
} catch (error) {
|
|
1592
|
+
return writePlanCompileError(stderr, error);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1500
1596
|
try {
|
|
1501
|
-
result = await compilePlan({
|
|
1502
|
-
|
|
1503
|
-
apiUrl,
|
|
1504
|
-
fetchFunction: authorizedFetch,
|
|
1505
|
-
fileSystem: planPushFileSystem,
|
|
1506
|
-
createTemporaryId,
|
|
1507
|
-
createRequestSignal,
|
|
1508
|
-
analysisSleep: planCompileSleep,
|
|
1509
|
-
analysisNow: planCompileNow,
|
|
1597
|
+
const result = await compilePlan({
|
|
1598
|
+
...shared,
|
|
1510
1599
|
publicationSleep: planPublishSleep,
|
|
1511
1600
|
publicationNow: planPublishNow,
|
|
1512
|
-
push: planCompilePush,
|
|
1513
|
-
readStatus: planCompileReadStatus,
|
|
1514
1601
|
publish: planCompilePublish,
|
|
1515
|
-
onProgress: reportProgress,
|
|
1516
1602
|
});
|
|
1603
|
+
const repository =
|
|
1604
|
+
/** @type {NonNullable<typeof result.publication.repository>} */ (
|
|
1605
|
+
result.publication.repository
|
|
1606
|
+
);
|
|
1607
|
+
stdout.write(`${repository.html_url}\n`);
|
|
1608
|
+
return 0;
|
|
1517
1609
|
} catch (error) {
|
|
1518
1610
|
return writePlanCompileError(stderr, error);
|
|
1519
1611
|
}
|
|
1520
|
-
|
|
1521
|
-
const repository =
|
|
1522
|
-
/** @type {NonNullable<typeof result.publication.repository>} */ (
|
|
1523
|
-
result.publication.repository
|
|
1524
|
-
);
|
|
1525
|
-
stdout.write(`${repository.html_url}\n`);
|
|
1526
|
-
return 0;
|
|
1527
1612
|
}
|
|
1528
1613
|
|
|
1529
1614
|
/** @param {Writer} writer @param {unknown} error */
|
|
@@ -1671,6 +1756,201 @@ function writePlanCompileError(writer, error) {
|
|
|
1671
1756
|
return 1;
|
|
1672
1757
|
}
|
|
1673
1758
|
|
|
1759
|
+
const retainedError =
|
|
1760
|
+
error instanceof CompilationRetainedError ? error : null;
|
|
1761
|
+
const compilationError = retainedError?.error ?? error;
|
|
1762
|
+
const retainedCompilation = retainedError?.current;
|
|
1763
|
+
|
|
1764
|
+
if (compilationError instanceof CompilationLocalStateError) {
|
|
1765
|
+
writeJson(writer, {
|
|
1766
|
+
error: "invalid_configuration",
|
|
1767
|
+
detail: PLAN_COMPILE_INCOMPATIBLE_STATE_DETAIL,
|
|
1768
|
+
});
|
|
1769
|
+
return 2;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
if (compilationError instanceof CompilationNotPushedError) {
|
|
1773
|
+
writeJson(writer, {
|
|
1774
|
+
error: "project_not_pushed",
|
|
1775
|
+
detail: PLAN_COMPILE_NOT_PUSHED_DETAIL,
|
|
1776
|
+
});
|
|
1777
|
+
return 1;
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
if (compilationError instanceof CompilationLocalPlanChangedError) {
|
|
1781
|
+
writeJson(writer, {
|
|
1782
|
+
error: "local_plan_changed",
|
|
1783
|
+
detail: PLAN_COMPILE_LOCAL_PLAN_CHANGED_DETAIL,
|
|
1784
|
+
});
|
|
1785
|
+
return 1;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
if (compilationError instanceof CompilationRequestOutcomeUnknownError) {
|
|
1789
|
+
writeJson(writer, {
|
|
1790
|
+
error: "request_outcome_unknown",
|
|
1791
|
+
phase: "compilation",
|
|
1792
|
+
detail: PLAN_COMPILE_DIRECT_REQUEST_OUTCOME_UNKNOWN_DETAIL,
|
|
1793
|
+
...(typeof compilationError.status === "number"
|
|
1794
|
+
? { status: compilationError.status }
|
|
1795
|
+
: {}),
|
|
1796
|
+
...(compilationError.response
|
|
1797
|
+
? { response: compilationError.response }
|
|
1798
|
+
: {}),
|
|
1799
|
+
});
|
|
1800
|
+
return 1;
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
if (
|
|
1804
|
+
(compilationError instanceof CompilationStartRejectedError ||
|
|
1805
|
+
compilationError instanceof CompilationStatusUnavailableError) &&
|
|
1806
|
+
isAuthenticationProblem(compilationError.status, compilationError.response)
|
|
1807
|
+
) {
|
|
1808
|
+
writeAuthenticationRequired(
|
|
1809
|
+
writer,
|
|
1810
|
+
compilationError.status,
|
|
1811
|
+
/** @type {Record<string, unknown>} */ (compilationError.response),
|
|
1812
|
+
retainedCompilation,
|
|
1813
|
+
);
|
|
1814
|
+
return 1;
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
if (compilationError instanceof CompilationStartRejectedError) {
|
|
1818
|
+
writeJson(writer, {
|
|
1819
|
+
error: "compilation_start_rejected",
|
|
1820
|
+
detail: PLAN_COMPILE_DIRECT_START_REJECTED_DETAIL,
|
|
1821
|
+
status: compilationError.status,
|
|
1822
|
+
response: compilationError.response,
|
|
1823
|
+
});
|
|
1824
|
+
return 1;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
if (compilationError instanceof CompilationStatusUnavailableError) {
|
|
1828
|
+
writeJson(writer, {
|
|
1829
|
+
error: "compilation_status_unavailable",
|
|
1830
|
+
detail: PLAN_COMPILE_DIRECT_STATUS_UNAVAILABLE_DETAIL,
|
|
1831
|
+
...(typeof compilationError.status === "number"
|
|
1832
|
+
? { status: compilationError.status }
|
|
1833
|
+
: {}),
|
|
1834
|
+
...(compilationError.response
|
|
1835
|
+
? { response: compilationError.response }
|
|
1836
|
+
: {}),
|
|
1837
|
+
...(retainedCompilation ? { current: retainedCompilation } : {}),
|
|
1838
|
+
});
|
|
1839
|
+
return 1;
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
if (compilationError instanceof CompilationStatusInvalidError) {
|
|
1843
|
+
writeJson(writer, {
|
|
1844
|
+
error: "invalid_compilation_status",
|
|
1845
|
+
detail: PLAN_COMPILE_DIRECT_STATUS_INVALID_DETAIL,
|
|
1846
|
+
status: compilationError.status,
|
|
1847
|
+
...(retainedCompilation ? { current: retainedCompilation } : {}),
|
|
1848
|
+
});
|
|
1849
|
+
return 1;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
if (compilationError instanceof CompilationChangedError) {
|
|
1853
|
+
writeJson(writer, {
|
|
1854
|
+
error: "compilation_changed",
|
|
1855
|
+
detail: PLAN_COMPILE_DIRECT_CHANGED_DETAIL,
|
|
1856
|
+
current: compilationError.current,
|
|
1857
|
+
});
|
|
1858
|
+
return 1;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
if (compilationError instanceof CompilationTimeoutError) {
|
|
1862
|
+
writeJson(writer, {
|
|
1863
|
+
error: "compilation_wait_timed_out",
|
|
1864
|
+
detail: PLAN_COMPILE_DIRECT_TIMEOUT_DETAIL,
|
|
1865
|
+
current: compilationError.current,
|
|
1866
|
+
});
|
|
1867
|
+
return 1;
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
if (compilationError instanceof CompilationFailedError) {
|
|
1871
|
+
writeJson(writer, {
|
|
1872
|
+
error: "compilation_failed",
|
|
1873
|
+
detail: PLAN_COMPILE_DIRECT_FAILED_DETAIL,
|
|
1874
|
+
current: compilationError.current,
|
|
1875
|
+
});
|
|
1876
|
+
return 1;
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
if (compilationError instanceof CompilationCancelledError) {
|
|
1880
|
+
writeJson(writer, {
|
|
1881
|
+
error: "compilation_cancelled",
|
|
1882
|
+
detail: PLAN_COMPILE_DIRECT_CANCELLED_DETAIL,
|
|
1883
|
+
current: compilationError.current,
|
|
1884
|
+
});
|
|
1885
|
+
return 1;
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
if (compilationError instanceof CompilationArtifactUnavailableError) {
|
|
1889
|
+
if (
|
|
1890
|
+
isAuthenticationProblem(
|
|
1891
|
+
compilationError.status,
|
|
1892
|
+
compilationError.response,
|
|
1893
|
+
)
|
|
1894
|
+
) {
|
|
1895
|
+
writeAuthenticationRequired(
|
|
1896
|
+
writer,
|
|
1897
|
+
compilationError.status,
|
|
1898
|
+
/** @type {Record<string, unknown>} */ (compilationError.response),
|
|
1899
|
+
retainedCompilation,
|
|
1900
|
+
);
|
|
1901
|
+
return 1;
|
|
1902
|
+
}
|
|
1903
|
+
writeJson(writer, {
|
|
1904
|
+
error: "artifact_unavailable",
|
|
1905
|
+
detail: PLAN_COMPILE_DIRECT_ARTIFACT_UNAVAILABLE_DETAIL,
|
|
1906
|
+
...(typeof compilationError.status === "number"
|
|
1907
|
+
? { status: compilationError.status }
|
|
1908
|
+
: {}),
|
|
1909
|
+
...(compilationError.response
|
|
1910
|
+
? { response: compilationError.response }
|
|
1911
|
+
: {}),
|
|
1912
|
+
...(retainedCompilation ? { current: retainedCompilation } : {}),
|
|
1913
|
+
});
|
|
1914
|
+
return 1;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
if (
|
|
1918
|
+
compilationError instanceof CompilationArtifactResponseInvalidError ||
|
|
1919
|
+
compilationError instanceof CompilationArtifactInvalidError
|
|
1920
|
+
) {
|
|
1921
|
+
writeJson(writer, {
|
|
1922
|
+
error: "invalid_artifact",
|
|
1923
|
+
detail: PLAN_COMPILE_DIRECT_ARTIFACT_INVALID_DETAIL,
|
|
1924
|
+
...(compilationError instanceof CompilationArtifactResponseInvalidError
|
|
1925
|
+
? { status: compilationError.status }
|
|
1926
|
+
: {}),
|
|
1927
|
+
...(retainedCompilation ? { current: retainedCompilation } : {}),
|
|
1928
|
+
});
|
|
1929
|
+
return 1;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
if (compilationError instanceof CompilationOutputPathError) {
|
|
1933
|
+
writeJson(writer, {
|
|
1934
|
+
error: "invalid_output_path",
|
|
1935
|
+
detail: COMPILATION_INVALID_OUTPUT_PATH_DETAIL,
|
|
1936
|
+
...(compilationError.reason ? { reason: compilationError.reason } : {}),
|
|
1937
|
+
});
|
|
1938
|
+
return 2;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
if (compilationError instanceof CompilationMaterializationError) {
|
|
1942
|
+
writeJson(writer, {
|
|
1943
|
+
error: "materialization_failed",
|
|
1944
|
+
detail: PLAN_COMPILE_DIRECT_MATERIALIZATION_FAILED_DETAIL,
|
|
1945
|
+
...(compilationError.reason ? { reason: compilationError.reason } : {}),
|
|
1946
|
+
...(compilationError.recoveryPath
|
|
1947
|
+
? { recovery_path: compilationError.recoveryPath }
|
|
1948
|
+
: {}),
|
|
1949
|
+
...(retainedCompilation ? { current: retainedCompilation } : {}),
|
|
1950
|
+
});
|
|
1951
|
+
return 1;
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1674
1954
|
if (error instanceof PublicationLocalStateError) {
|
|
1675
1955
|
writeJson(writer, {
|
|
1676
1956
|
error: "invalid_configuration",
|
|
@@ -1935,13 +2215,15 @@ function writeJson(writer, value) {
|
|
|
1935
2215
|
* @param {Writer} writer
|
|
1936
2216
|
* @param {number} [status]
|
|
1937
2217
|
* @param {Record<string, unknown>} [response]
|
|
2218
|
+
* @param {import("./commands/compilation.js").CompilationResponse} [current]
|
|
1938
2219
|
*/
|
|
1939
|
-
function writeAuthenticationRequired(writer, status, response) {
|
|
2220
|
+
function writeAuthenticationRequired(writer, status, response, current) {
|
|
1940
2221
|
writeJson(writer, {
|
|
1941
2222
|
error: "authentication_required",
|
|
1942
2223
|
detail: AUTHENTICATION_REQUIRED_DETAIL,
|
|
1943
2224
|
...(status === undefined ? {} : { status }),
|
|
1944
2225
|
...(response === undefined ? {} : { response }),
|
|
2226
|
+
...(current === undefined ? {} : { current }),
|
|
1945
2227
|
});
|
|
1946
2228
|
}
|
|
1947
2229
|
|