@ontrails/trails 1.0.0-beta.2 → 1.0.0-beta.22

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 (150) hide show
  1. package/CHANGELOG.md +647 -0
  2. package/README.md +26 -0
  3. package/package.json +28 -7
  4. package/src/app.ts +86 -2
  5. package/src/clack.ts +22 -0
  6. package/src/cli.ts +330 -11
  7. package/src/completions.ts +240 -0
  8. package/src/lifecycle-source-io.ts +33 -0
  9. package/src/load-app-mirror.ts +202 -0
  10. package/src/local-state-io.ts +153 -0
  11. package/src/mcp-app.ts +30 -0
  12. package/src/mcp-options.ts +77 -0
  13. package/src/mcp.ts +8 -0
  14. package/src/project-writes.ts +377 -0
  15. package/src/release/bindings.ts +39 -0
  16. package/src/release/check.ts +818 -0
  17. package/src/release/config.ts +63 -0
  18. package/src/release/contract-facts.ts +425 -0
  19. package/src/release/index.ts +85 -0
  20. package/src/release/native-bun-publish.ts +651 -0
  21. package/src/release/native-bun-registry.ts +350 -0
  22. package/src/release/packed-artifacts-smoke.ts +236 -0
  23. package/src/release/smoke.ts +46 -0
  24. package/src/release/wayfinder-dogfood-smoke.ts +226 -0
  25. package/src/retired-topo-command.ts +36 -0
  26. package/src/run-adapter-check.ts +76 -0
  27. package/src/run-collision.ts +126 -0
  28. package/src/run-completions-install.ts +179 -0
  29. package/src/run-example.ts +149 -0
  30. package/src/run-examples.ts +148 -0
  31. package/src/run-quiet.ts +75 -0
  32. package/src/run-release-check.ts +74 -0
  33. package/src/run-trace.ts +273 -0
  34. package/src/run-warden.ts +39 -0
  35. package/src/run-watch.ts +432 -0
  36. package/src/scaffold-version-sync.ts +183 -0
  37. package/src/scaffold-versions.generated.ts +12 -0
  38. package/src/trails/adapter-check.ts +244 -0
  39. package/src/trails/add-surface.ts +94 -40
  40. package/src/trails/add-trail.ts +79 -41
  41. package/src/trails/add-verify.ts +95 -25
  42. package/src/trails/compile.ts +67 -0
  43. package/src/trails/completions-complete.ts +165 -0
  44. package/src/trails/completions.ts +47 -0
  45. package/src/trails/create-adapter.ts +1084 -0
  46. package/src/trails/create-scaffold.ts +399 -104
  47. package/src/trails/create-versions.ts +62 -0
  48. package/src/trails/create.ts +185 -71
  49. package/src/trails/deprecate.ts +59 -0
  50. package/src/trails/dev-clean.ts +82 -0
  51. package/src/trails/dev-reset.ts +50 -0
  52. package/src/trails/dev-stats.ts +72 -0
  53. package/src/trails/dev-support.ts +340 -0
  54. package/src/trails/doctor.ts +56 -0
  55. package/src/trails/draft-promote.ts +949 -0
  56. package/src/trails/guide.ts +74 -68
  57. package/src/trails/load-app.ts +1143 -15
  58. package/src/trails/project.ts +17 -3
  59. package/src/trails/release-check.ts +104 -0
  60. package/src/trails/release-smoke.ts +48 -0
  61. package/src/trails/revise.ts +53 -0
  62. package/src/trails/root-dir.ts +21 -0
  63. package/src/trails/run-example.ts +491 -0
  64. package/src/trails/run-examples.ts +145 -0
  65. package/src/trails/run.ts +410 -0
  66. package/src/trails/scaffold-json.ts +58 -0
  67. package/src/trails/survey.ts +881 -226
  68. package/src/trails/topo-activation.ts +385 -0
  69. package/src/trails/topo-constants.ts +2 -0
  70. package/src/trails/topo-history.ts +47 -0
  71. package/src/trails/topo-output-schemas.ts +248 -0
  72. package/src/trails/topo-pin.ts +52 -0
  73. package/src/trails/topo-read-support.ts +313 -0
  74. package/src/trails/topo-reports.ts +807 -0
  75. package/src/trails/topo-store-support.ts +174 -0
  76. package/src/trails/topo-support.ts +220 -0
  77. package/src/trails/topo-unpin.ts +61 -0
  78. package/src/trails/topo.ts +106 -0
  79. package/src/trails/validate.ts +38 -0
  80. package/src/trails/version-lifecycle-support.ts +945 -0
  81. package/src/trails/warden-guide.ts +129 -0
  82. package/src/trails/warden.ts +165 -58
  83. package/src/versions.ts +31 -0
  84. package/.turbo/turbo-build.log +0 -1
  85. package/.turbo/turbo-lint.log +0 -3
  86. package/.turbo/turbo-typecheck.log +0 -1
  87. package/__tests__/examples.test.ts +0 -6
  88. package/dist/bin/trails.d.ts +0 -3
  89. package/dist/bin/trails.d.ts.map +0 -1
  90. package/dist/bin/trails.js +0 -4
  91. package/dist/bin/trails.js.map +0 -1
  92. package/dist/src/app.d.ts +0 -2
  93. package/dist/src/app.d.ts.map +0 -1
  94. package/dist/src/app.js +0 -11
  95. package/dist/src/app.js.map +0 -1
  96. package/dist/src/clack.d.ts +0 -9
  97. package/dist/src/clack.d.ts.map +0 -1
  98. package/dist/src/clack.js +0 -62
  99. package/dist/src/clack.js.map +0 -1
  100. package/dist/src/cli.d.ts +0 -2
  101. package/dist/src/cli.d.ts.map +0 -1
  102. package/dist/src/cli.js +0 -13
  103. package/dist/src/cli.js.map +0 -1
  104. package/dist/src/trails/add-surface.d.ts +0 -13
  105. package/dist/src/trails/add-surface.d.ts.map +0 -1
  106. package/dist/src/trails/add-surface.js +0 -88
  107. package/dist/src/trails/add-surface.js.map +0 -1
  108. package/dist/src/trails/add-trail.d.ts +0 -11
  109. package/dist/src/trails/add-trail.d.ts.map +0 -1
  110. package/dist/src/trails/add-trail.js +0 -85
  111. package/dist/src/trails/add-trail.js.map +0 -1
  112. package/dist/src/trails/add-verify.d.ts +0 -10
  113. package/dist/src/trails/add-verify.d.ts.map +0 -1
  114. package/dist/src/trails/add-verify.js +0 -67
  115. package/dist/src/trails/add-verify.js.map +0 -1
  116. package/dist/src/trails/create-scaffold.d.ts +0 -15
  117. package/dist/src/trails/create-scaffold.d.ts.map +0 -1
  118. package/dist/src/trails/create-scaffold.js +0 -288
  119. package/dist/src/trails/create-scaffold.js.map +0 -1
  120. package/dist/src/trails/create.d.ts +0 -22
  121. package/dist/src/trails/create.d.ts.map +0 -1
  122. package/dist/src/trails/create.js +0 -121
  123. package/dist/src/trails/create.js.map +0 -1
  124. package/dist/src/trails/guide.d.ts +0 -11
  125. package/dist/src/trails/guide.d.ts.map +0 -1
  126. package/dist/src/trails/guide.js +0 -80
  127. package/dist/src/trails/guide.js.map +0 -1
  128. package/dist/src/trails/load-app.d.ts +0 -4
  129. package/dist/src/trails/load-app.d.ts.map +0 -1
  130. package/dist/src/trails/load-app.js +0 -24
  131. package/dist/src/trails/load-app.js.map +0 -1
  132. package/dist/src/trails/project.d.ts +0 -8
  133. package/dist/src/trails/project.d.ts.map +0 -1
  134. package/dist/src/trails/project.js +0 -43
  135. package/dist/src/trails/project.js.map +0 -1
  136. package/dist/src/trails/survey.d.ts +0 -33
  137. package/dist/src/trails/survey.d.ts.map +0 -1
  138. package/dist/src/trails/survey.js +0 -225
  139. package/dist/src/trails/survey.js.map +0 -1
  140. package/dist/src/trails/warden.d.ts +0 -19
  141. package/dist/src/trails/warden.d.ts.map +0 -1
  142. package/dist/src/trails/warden.js +0 -88
  143. package/dist/src/trails/warden.js.map +0 -1
  144. package/dist/tsconfig.tsbuildinfo +0 -1
  145. package/src/__tests__/create.test.ts +0 -349
  146. package/src/__tests__/guide.test.ts +0 -91
  147. package/src/__tests__/load-app.test.ts +0 -15
  148. package/src/__tests__/survey.test.ts +0 -161
  149. package/src/__tests__/warden.test.ts +0 -74
  150. package/tsconfig.json +0 -9
@@ -0,0 +1,149 @@
1
+ /**
2
+ * CLI-surface bridge for the `run.example` trail.
3
+ *
4
+ * `run.example` resolves the named example on the target trail, executes it
5
+ * through the full pipeline, and packages an actual-vs-expected comparison
6
+ * into a structured envelope on the trail's outer `Result.ok(...)`. This module
7
+ * owns the surface decision of how to render that envelope:
8
+ *
9
+ * - Text mode (default): a compact summary on match, an `input / expected /
10
+ * actual / diff` block on mismatch.
11
+ * - JSON / JSONL: emits the full {@link RunExampleComparison} envelope so
12
+ * downstream consumers can parse the comparison shape directly.
13
+ *
14
+ * Match/mismatch is a comparison outcome, not an execution error: the trail
15
+ * always returns `Result.ok(envelope)`. This helper maps mismatch onto a
16
+ * non-zero exit code by throwing a `ValidationError` (category `validation`,
17
+ * exit 1) so Commander's error path runs.
18
+ *
19
+ * Outer Err on the run trail (NotFound, Ambiguous, Validation) is unaffected
20
+ * by `run.example`: this helper defers to the default handler so existing
21
+ * exit-code mapping and recovery hooks stay intact.
22
+ */
23
+
24
+ import type { ActionResultContext } from '@ontrails/cli';
25
+ import { deriveOutputMode, output } from '@ontrails/cli';
26
+ import { ValidationError } from '@ontrails/core';
27
+
28
+ import { runExampleComparisonSchema } from './trails/run-example.js';
29
+ import type { RunExampleComparison } from './trails/run-example.js';
30
+
31
+ // ---------------------------------------------------------------------------
32
+ // Detection
33
+ // ---------------------------------------------------------------------------
34
+
35
+ const isExampleRunCtx = (ctx: ActionResultContext): boolean =>
36
+ ctx.trail.id === 'run.example';
37
+
38
+ // ---------------------------------------------------------------------------
39
+ // Text formatting
40
+ // ---------------------------------------------------------------------------
41
+
42
+ const formatJson = (value: unknown): string => {
43
+ try {
44
+ const encoded = JSON.stringify(value, null, 2);
45
+ return encoded === undefined ? String(value) : encoded;
46
+ } catch {
47
+ return String(value);
48
+ }
49
+ };
50
+
51
+ const formatMatchText = (envelope: RunExampleComparison): string =>
52
+ [
53
+ `OK ${envelope.trailId} :: ${envelope.exampleName}`,
54
+ `mode: ${envelope.mode}`,
55
+ 'actual matches expected.',
56
+ ].join('\n');
57
+
58
+ const formatMismatchText = (envelope: RunExampleComparison): string => {
59
+ const diffBlock =
60
+ envelope.diff !== undefined && envelope.diff.length > 0
61
+ ? envelope.diff.map((line) => ` - ${line}`).join('\n')
62
+ : ' - <no diff lines>';
63
+
64
+ return [
65
+ `MISMATCH ${envelope.trailId} :: ${envelope.exampleName}`,
66
+ `mode: ${envelope.mode}`,
67
+ 'input:',
68
+ formatJson(envelope.input),
69
+ 'expected:',
70
+ formatJson(envelope.expected),
71
+ 'actual:',
72
+ formatJson(envelope.actual),
73
+ 'diff:',
74
+ diffBlock,
75
+ ].join('\n');
76
+ };
77
+
78
+ // ---------------------------------------------------------------------------
79
+ // Entry point
80
+ // ---------------------------------------------------------------------------
81
+
82
+ /**
83
+ * Return value:
84
+ * - `false` — `run.example` did not apply; caller should fall through to its
85
+ * default handler.
86
+ * - `true` — `run.example` handled the result and wrote output. Caller should
87
+ * not invoke the default handler.
88
+ *
89
+ * Throws a {@link ValidationError} on mismatch so Commander's error path runs
90
+ * and the run trail surface exits with the validation category exit code.
91
+ */
92
+ export const tryExampleRunOutput = (ctx: ActionResultContext): boolean => {
93
+ if (!isExampleRunCtx(ctx)) {
94
+ return false;
95
+ }
96
+
97
+ // Outer Err on the run.example trail (NotFound, Ambiguous, Validation) is not
98
+ // in scope here: defer to the default handler so existing
99
+ // exit-code mapping and recovery hooks stay intact.
100
+ if (ctx.result.isErr()) {
101
+ return false;
102
+ }
103
+
104
+ const envelope = runExampleComparisonSchema.safeParse(ctx.result.value);
105
+ if (!envelope.success) {
106
+ // Defensive fallback: the trail owns the output schema, so this branch is
107
+ // unreachable in practice. Defer to the default handler if anything else
108
+ // slips through.
109
+ return false;
110
+ }
111
+ const comparison = envelope.data;
112
+
113
+ const { mode } = deriveOutputMode(ctx.flags, ctx.topoName);
114
+
115
+ if (mode === 'text') {
116
+ if (comparison.match) {
117
+ output(formatMatchText(comparison), mode);
118
+ return true;
119
+ }
120
+ process.stderr.write(`${formatMismatchText(comparison)}\n`);
121
+ throw new ValidationError(
122
+ `Example '${comparison.exampleName}' on trail '${comparison.trailId}' did not match expected outcome.`,
123
+ {
124
+ context: {
125
+ exampleName: comparison.exampleName,
126
+ mode: comparison.mode,
127
+ trailId: comparison.trailId,
128
+ },
129
+ }
130
+ );
131
+ }
132
+
133
+ // JSON / JSONL: emit the full envelope so downstream consumers can parse
134
+ // the comparison shape directly.
135
+ output(comparison, mode);
136
+ if (!comparison.match) {
137
+ throw new ValidationError(
138
+ `Example '${comparison.exampleName}' on trail '${comparison.trailId}' did not match expected outcome.`,
139
+ {
140
+ context: {
141
+ exampleName: comparison.exampleName,
142
+ mode: comparison.mode,
143
+ trailId: comparison.trailId,
144
+ },
145
+ }
146
+ );
147
+ }
148
+ return true;
149
+ };
@@ -0,0 +1,148 @@
1
+ /**
2
+ * CLI-surface bridge for the `run.examples` trail.
3
+ *
4
+ * `run.examples` is a pure metadata read: the trail returns a
5
+ * {@link RunExamplesListing} on its outer Ok value.
6
+ * This module owns the surface decision of how to render that listing:
7
+ *
8
+ * - Text mode (default): a table-like list with `name`, truncated `input`,
9
+ * and outcome (`ok` / `error: <code>`). Empty listings print
10
+ * `No examples defined`.
11
+ * - JSON / JSONL: the structured `examples` array is emitted directly via
12
+ * the resolved output mode, so agents and downstream consumers can parse
13
+ * the full structured shape (`name`, `input`, `expected`, `expectedMatch`,
14
+ * `error`, `signals`, `kind`, `provenance`).
15
+ *
16
+ * Errors at the outer layer (NotFoundError, AmbiguousError, ValidationError)
17
+ * are unaffected by `run.examples`: we always defer to the supplied default
18
+ * handler so the existing exit-code mapping and recovery hooks stay intact.
19
+ */
20
+
21
+ import type { ActionResultContext } from '@ontrails/cli';
22
+ import { deriveOutputMode, output } from '@ontrails/cli';
23
+ import type { StructuredTrailExample } from '@ontrails/core';
24
+
25
+ import { runExamplesListingSchema } from './trails/run-examples.js';
26
+ import type { RunExamplesListing } from './trails/run-examples.js';
27
+
28
+ // ---------------------------------------------------------------------------
29
+ // Detection
30
+ // ---------------------------------------------------------------------------
31
+
32
+ const isExamplesRunCtx = (ctx: ActionResultContext): boolean =>
33
+ ctx.trail.id === 'run.examples';
34
+
35
+ // ---------------------------------------------------------------------------
36
+ // Text formatting
37
+ // ---------------------------------------------------------------------------
38
+
39
+ const INPUT_PREVIEW_LIMIT = 60;
40
+
41
+ const truncate = (value: string, limit: number): string =>
42
+ value.length <= limit ? value : `${value.slice(0, limit - 1)}…`;
43
+
44
+ const formatInputPreview = (input: unknown): string => {
45
+ if (input === undefined) {
46
+ return '';
47
+ }
48
+ let encoded: string;
49
+ try {
50
+ encoded = JSON.stringify(input) ?? '';
51
+ } catch {
52
+ encoded = String(input);
53
+ }
54
+ return truncate(encoded, INPUT_PREVIEW_LIMIT);
55
+ };
56
+
57
+ const formatOutcome = (example: StructuredTrailExample): string => {
58
+ if (example.kind === 'error') {
59
+ const code = example.error;
60
+ return code === undefined || code.length === 0 ? 'error' : `error: ${code}`;
61
+ }
62
+ return 'ok';
63
+ };
64
+
65
+ interface ExampleRow {
66
+ readonly name: string;
67
+ readonly input: string;
68
+ readonly outcome: string;
69
+ }
70
+
71
+ const buildRows = (
72
+ examples: readonly StructuredTrailExample[]
73
+ ): readonly ExampleRow[] =>
74
+ examples.map((example) => ({
75
+ input: formatInputPreview(example.input),
76
+ name: example.name,
77
+ outcome: formatOutcome(example),
78
+ }));
79
+
80
+ const padRight = (value: string, width: number): string =>
81
+ value.length >= width ? value : value + ' '.repeat(width - value.length);
82
+
83
+ const formatTable = (rows: readonly ExampleRow[]): string => {
84
+ const headers = { input: 'INPUT', name: 'NAME', outcome: 'OUTCOME' };
85
+ const allRows: readonly ExampleRow[] = [headers, ...rows];
86
+
87
+ const widths = {
88
+ input: Math.max(...allRows.map((row) => row.input.length)),
89
+ name: Math.max(...allRows.map((row) => row.name.length)),
90
+ outcome: Math.max(...allRows.map((row) => row.outcome.length)),
91
+ };
92
+
93
+ const formatRow = (row: ExampleRow): string =>
94
+ `${padRight(row.name, widths.name)} ${padRight(row.input, widths.input)} ${row.outcome}`;
95
+
96
+ return allRows.map(formatRow).join('\n');
97
+ };
98
+
99
+ const formatTextListing = (listing: RunExamplesListing): string => {
100
+ if (listing.examples.length === 0) {
101
+ return 'No examples defined';
102
+ }
103
+ return formatTable(buildRows(listing.examples));
104
+ };
105
+
106
+ // ---------------------------------------------------------------------------
107
+ // Entry point
108
+ // ---------------------------------------------------------------------------
109
+
110
+ /**
111
+ * Return value:
112
+ * - `false` — `run.examples` did not apply; caller should fall through to its
113
+ * default handler.
114
+ * - `true` — `run.examples` handled the result and wrote output. Caller should
115
+ * not invoke the default handler.
116
+ */
117
+ export const tryExamplesRunOutput = (ctx: ActionResultContext): boolean => {
118
+ if (!isExamplesRunCtx(ctx)) {
119
+ return false;
120
+ }
121
+
122
+ // Outer Err on `run.examples` (NotFound, Ambiguous, Validation) is not in
123
+ // scope for this renderer: defer to the default handler so existing
124
+ // exit-code mapping and recovery hooks stay intact.
125
+ if (ctx.result.isErr()) {
126
+ return false;
127
+ }
128
+
129
+ const listing = runExamplesListingSchema.safeParse(ctx.result.value);
130
+ if (!listing.success) {
131
+ // Defensive fallback: the trail owns the output schema, so this branch is
132
+ // unreachable in practice. Defer to the default handler if anything else
133
+ // slips through.
134
+ return false;
135
+ }
136
+
137
+ const { mode } = deriveOutputMode(ctx.flags, ctx.topoName);
138
+
139
+ if (mode === 'text') {
140
+ output(formatTextListing(listing.data), mode);
141
+ return true;
142
+ }
143
+
144
+ // JSON / JSONL: emit the structured examples array directly so downstream
145
+ // consumers can parse the full structured shape per example.
146
+ output(listing.data.examples, mode);
147
+ return true;
148
+ };
@@ -0,0 +1,75 @@
1
+ /**
2
+ * CLI-surface bridge for the `run` trail's `--quiet` flag.
3
+ *
4
+ * The `run` trail returns an `inner-trail-result` envelope as the `value` of
5
+ * its own outer `Result.ok(...)`. The default CLI on-result handler unwraps
6
+ * once, leaving stdout as `{ "kind": "inner-trail-result", "trailId": "...",
7
+ * "value": ... }` — useful when a caller wants provenance, but noisy when the
8
+ * caller only wants the inner value to feed downstream pipes.
9
+ *
10
+ * `--quiet` strips that envelope:
11
+ *
12
+ * - Inner result envelope → write the inner value to stdout via the resolved
13
+ * output mode.
14
+ *
15
+ * Errors at the outer layer (the run trail itself failing — `NotFoundError`,
16
+ * `AmbiguousError`, `ValidationError` from input) are unaffected by `--quiet`:
17
+ * we always defer to the supplied default handler so collision-recovery and
18
+ * the existing error surface stay intact.
19
+ */
20
+
21
+ import type { ActionResultContext } from '@ontrails/cli';
22
+ import { deriveOutputMode, output } from '@ontrails/cli';
23
+
24
+ import { INNER_TRAIL_RESULT_KIND } from './trails/run.js';
25
+
26
+ interface InnerTrailResultEnvelope {
27
+ readonly kind: typeof INNER_TRAIL_RESULT_KIND;
28
+ readonly trailId: string;
29
+ readonly value: unknown;
30
+ }
31
+
32
+ const isInnerTrailResultEnvelope = (
33
+ value: unknown
34
+ ): value is InnerTrailResultEnvelope =>
35
+ typeof value === 'object' &&
36
+ value !== null &&
37
+ (value as { readonly kind?: unknown }).kind === INNER_TRAIL_RESULT_KIND &&
38
+ typeof (value as { readonly trailId?: unknown }).trailId === 'string' &&
39
+ 'value' in value;
40
+
41
+ const isQuietRunCtx = (ctx: ActionResultContext): boolean =>
42
+ ctx.trail.id === 'run' && ctx.flags['quiet'] === true;
43
+
44
+ /**
45
+ * Return value:
46
+ * - `false` — `--quiet` did not apply; caller should fall through to its
47
+ * default handler.
48
+ * - `true` — `--quiet` handled the result and wrote output. Caller should not
49
+ * invoke the default handler.
50
+ *
51
+ */
52
+ export const tryQuietRunOutput = async (
53
+ ctx: ActionResultContext
54
+ ): Promise<boolean> => {
55
+ if (!isQuietRunCtx(ctx)) {
56
+ return false;
57
+ }
58
+
59
+ // Outer Err on the run trail (collision, not-found, validation) is not in
60
+ // scope for --quiet: defer to the default handler so existing exit-code
61
+ // mapping and recovery hooks stay intact.
62
+ if (ctx.result.isErr()) {
63
+ return false;
64
+ }
65
+
66
+ const inner: unknown = ctx.result.value;
67
+ if (!isInnerTrailResultEnvelope(inner)) {
68
+ return false;
69
+ }
70
+
71
+ const { mode } = deriveOutputMode(ctx.flags, ctx.topoName);
72
+ const value = inner.value === undefined ? null : inner.value;
73
+ output(value, mode);
74
+ return true;
75
+ };
@@ -0,0 +1,74 @@
1
+ import type { ActionResultContext } from '@ontrails/cli';
2
+ import { deriveOutputMode } from '@ontrails/cli';
3
+
4
+ interface ReleaseCheckResultValue {
5
+ readonly formatted: string;
6
+ readonly passed: boolean;
7
+ }
8
+
9
+ const isReleaseCheckResultValue = (
10
+ value: unknown
11
+ ): value is ReleaseCheckResultValue => {
12
+ if (typeof value !== 'object' || value === null) {
13
+ return false;
14
+ }
15
+
16
+ const candidate = value as Record<string, unknown>;
17
+ return (
18
+ typeof candidate['formatted'] === 'string' &&
19
+ typeof candidate['passed'] === 'boolean'
20
+ );
21
+ };
22
+
23
+ const wantsStructuredOutput = (ctx: ActionResultContext): boolean =>
24
+ deriveOutputMode(ctx.flags, ctx.topoName).mode !== 'text';
25
+
26
+ const readReleaseCheckResultValue = (
27
+ ctx: ActionResultContext
28
+ ): ReleaseCheckResultValue | undefined => {
29
+ if (ctx.trail.id !== 'release.check' || ctx.result.isErr()) {
30
+ return undefined;
31
+ }
32
+
33
+ return isReleaseCheckResultValue(ctx.result.value)
34
+ ? ctx.result.value
35
+ : undefined;
36
+ };
37
+
38
+ export const applyReleaseCheckExitCode = (
39
+ ctx: ActionResultContext
40
+ ): boolean => {
41
+ if (ctx.trail.id !== 'release.check') {
42
+ return false;
43
+ }
44
+
45
+ if (ctx.result.isErr()) {
46
+ process.exitCode = 1;
47
+ return true;
48
+ }
49
+
50
+ const value = readReleaseCheckResultValue(ctx);
51
+ if (!value) {
52
+ return false;
53
+ }
54
+
55
+ process.exitCode = value.passed ? 0 : 1;
56
+ return true;
57
+ };
58
+
59
+ export const tryReleaseCheckOutput = (ctx: ActionResultContext): boolean => {
60
+ const value = readReleaseCheckResultValue(ctx);
61
+ if (!value) {
62
+ return false;
63
+ }
64
+
65
+ applyReleaseCheckExitCode(ctx);
66
+ if (wantsStructuredOutput(ctx)) {
67
+ return false;
68
+ }
69
+
70
+ if (value.formatted.length > 0) {
71
+ process.stdout.write(`${value.formatted}\n`);
72
+ }
73
+ return true;
74
+ };