@ontrails/trails 0.2.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.
Files changed (121) hide show
  1. package/CHANGELOG.md +1906 -0
  2. package/README.md +48 -0
  3. package/bin/trails.ts +3 -0
  4. package/package.json +57 -0
  5. package/src/app.ts +167 -0
  6. package/src/clack.ts +111 -0
  7. package/src/cli.ts +308 -0
  8. package/src/completions.ts +431 -0
  9. package/src/lifecycle-source-io.ts +33 -0
  10. package/src/load-app-mirror.ts +202 -0
  11. package/src/local-state-io.ts +129 -0
  12. package/src/mcp-app.ts +42 -0
  13. package/src/mcp-options.ts +92 -0
  14. package/src/mcp.ts +8 -0
  15. package/src/project-writes.ts +377 -0
  16. package/src/regrade/audit.ts +571 -0
  17. package/src/regrade/config.ts +152 -0
  18. package/src/regrade/history.ts +636 -0
  19. package/src/regrade/lifecycle.ts +76 -0
  20. package/src/regrade/live-api-preserve.ts +123 -0
  21. package/src/regrade/plan-artifact.ts +515 -0
  22. package/src/regrade/plan-derivation.ts +301 -0
  23. package/src/regrade/prepared-run.ts +259 -0
  24. package/src/regrade/receipt-history.ts +446 -0
  25. package/src/regrade/source-transaction.ts +185 -0
  26. package/src/release/bindings.ts +58 -0
  27. package/src/release/changeset-packages.ts +99 -0
  28. package/src/release/check.ts +1191 -0
  29. package/src/release/cli-bundle.ts +575 -0
  30. package/src/release/config.ts +73 -0
  31. package/src/release/contract-facts.ts +425 -0
  32. package/src/release/homebrew.ts +221 -0
  33. package/src/release/index.ts +180 -0
  34. package/src/release/lock-roundtrip-smoke.ts +255 -0
  35. package/src/release/lock-roundtrip-workspace.ts +107 -0
  36. package/src/release/native-bun-publish.ts +964 -0
  37. package/src/release/native-bun-registry.ts +848 -0
  38. package/src/release/notes-cli.ts +171 -0
  39. package/src/release/notes.ts +390 -0
  40. package/src/release/pack-coherence.ts +455 -0
  41. package/src/release/package-route-facts.ts +146 -0
  42. package/src/release/packed-artifacts-smoke.ts +236 -0
  43. package/src/release/policy.ts +1780 -0
  44. package/src/release/semver.ts +104 -0
  45. package/src/release/smoke.ts +56 -0
  46. package/src/release/stable-version-release.ts +80 -0
  47. package/src/release/wayfinder-dogfood-smoke.ts +762 -0
  48. package/src/release/zero-line-transition.ts +68 -0
  49. package/src/retired-topo-command.ts +36 -0
  50. package/src/run-adapter-check.ts +76 -0
  51. package/src/run-argv.ts +133 -0
  52. package/src/run-collision.ts +126 -0
  53. package/src/run-completions-install.ts +179 -0
  54. package/src/run-example.ts +149 -0
  55. package/src/run-examples.ts +148 -0
  56. package/src/run-quiet.ts +75 -0
  57. package/src/run-regrade-progress.ts +47 -0
  58. package/src/run-release-check.ts +74 -0
  59. package/src/run-schema.ts +74 -0
  60. package/src/run-trace.ts +273 -0
  61. package/src/run-warden.ts +39 -0
  62. package/src/run-watch-project.ts +52 -0
  63. package/src/run-watch.ts +381 -0
  64. package/src/run-wayfind-outline.ts +170 -0
  65. package/src/scaffold-version-sync.ts +183 -0
  66. package/src/scaffold-versions.generated.ts +12 -0
  67. package/src/trails/adapter-check.ts +244 -0
  68. package/src/trails/add-surface.ts +816 -0
  69. package/src/trails/add-trail.ts +141 -0
  70. package/src/trails/add-verify.ts +252 -0
  71. package/src/trails/compile.ts +118 -0
  72. package/src/trails/completions-complete.ts +236 -0
  73. package/src/trails/completions.ts +47 -0
  74. package/src/trails/config-explain.ts +43 -0
  75. package/src/trails/create-adapter.ts +785 -0
  76. package/src/trails/create-scaffold.ts +1215 -0
  77. package/src/trails/create-versions.ts +62 -0
  78. package/src/trails/create.ts +652 -0
  79. package/src/trails/deprecate.ts +59 -0
  80. package/src/trails/dev-clean.ts +80 -0
  81. package/src/trails/dev-reset.ts +48 -0
  82. package/src/trails/dev-stats.ts +71 -0
  83. package/src/trails/dev-support.ts +360 -0
  84. package/src/trails/doctor.ts +77 -0
  85. package/src/trails/draft-promote.ts +949 -0
  86. package/src/trails/guide.ts +106 -0
  87. package/src/trails/load-app.ts +1145 -0
  88. package/src/trails/operator-context.ts +66 -0
  89. package/src/trails/project-context-output.ts +304 -0
  90. package/src/trails/project-context.ts +613 -0
  91. package/src/trails/project.ts +65 -0
  92. package/src/trails/regrade.ts +4951 -0
  93. package/src/trails/release-check.ts +113 -0
  94. package/src/trails/release-smoke.ts +49 -0
  95. package/src/trails/revise.ts +53 -0
  96. package/src/trails/root-dir.ts +21 -0
  97. package/src/trails/run-example.ts +592 -0
  98. package/src/trails/run-examples.ts +149 -0
  99. package/src/trails/run.ts +496 -0
  100. package/src/trails/scaffold-json.ts +60 -0
  101. package/src/trails/scaffold-topo-identity.ts +479 -0
  102. package/src/trails/survey.ts +990 -0
  103. package/src/trails/topo-activation.ts +14 -0
  104. package/src/trails/topo-constants.ts +2 -0
  105. package/src/trails/topo-history.ts +47 -0
  106. package/src/trails/topo-output-schemas.ts +259 -0
  107. package/src/trails/topo-pin.ts +38 -0
  108. package/src/trails/topo-read-support.ts +368 -0
  109. package/src/trails/topo-reports.ts +809 -0
  110. package/src/trails/topo-store-support.ts +323 -0
  111. package/src/trails/topo-support.ts +247 -0
  112. package/src/trails/topo-unpin.ts +61 -0
  113. package/src/trails/topo.ts +92 -0
  114. package/src/trails/validate.ts +348 -0
  115. package/src/trails/version-lifecycle-support.ts +936 -0
  116. package/src/trails/warden-guide.ts +134 -0
  117. package/src/trails/warden.ts +598 -0
  118. package/src/trails/wayfind-diff.ts +716 -0
  119. package/src/trails/wayfind-outline.ts +876 -0
  120. package/src/trails/wayfind.ts +1319 -0
  121. package/src/versions.ts +31 -0
@@ -0,0 +1,236 @@
1
+ /**
2
+ * `completions __complete` internal trail -- dynamic completion suggestions.
3
+ *
4
+ * The static shell scripts emitted by {@link completionsTrail} delegate to this
5
+ * trail at tab-press time. The trail receives the partial argv that the user
6
+ * has typed (after the binary name) and returns newline-delimited suggestions
7
+ * the shell should offer.
8
+ *
9
+ * Today the trail knows about two `run` positions:
10
+ *
11
+ * - `trails run <prefix>` — return matching trail IDs.
12
+ * - `trails run example <trail-id> <prefix>` — return matching example names
13
+ * defined on the resolved trail.
14
+ *
15
+ * The `run example` branch loads the trail's owning app at tab-press time so the
16
+ * suggestions reflect the live trail definition. Unknown trails and no
17
+ * examples naturally collapse to an empty list; recoverable load failures are
18
+ * suppressed here because completion must never surface errors back to the
19
+ * shell mid-keystroke.
20
+ */
21
+
22
+ import { Result, trail } from '@ontrails/core';
23
+ import { z } from 'zod';
24
+
25
+ import {
26
+ renderAppIdCompletions,
27
+ renderTrailExampleCompletions,
28
+ renderTrailIdCompletions,
29
+ } from '../completions.js';
30
+ import { parseRunArgv, parseSelectionControls } from '../run-argv.js';
31
+ import { resolveOperatorProjectContext } from './project-context.js';
32
+
33
+ const EMPTY_SUGGESTIONS = '';
34
+
35
+ interface CompleteContext {
36
+ readonly args: readonly string[];
37
+ readonly rootDir: string;
38
+ readonly selectedAppId?: string | undefined;
39
+ readonly selectedModulePath?: string | undefined;
40
+ }
41
+
42
+ type CompletionHandler = (ctx: CompleteContext) => Promise<readonly string[]>;
43
+
44
+ /**
45
+ * Detect whether the user is completing the example-name positional on a
46
+ * `trails run example` invocation.
47
+ *
48
+ * The shell hands us the partial argv with the **last element** as the token
49
+ * being completed. We recognize the `run example <trail-id> <TAB>` shape when:
50
+ *
51
+ * - the command family is `run example`, and
52
+ * - a non-flag positional (the trail ID) follows `example`.
53
+ *
54
+ * Returns the trail ID + prefix to complete, or `null` if the cursor is not
55
+ * in an example-name value position.
56
+ */
57
+ const detectExampleValueCompletion = (
58
+ args: readonly string[]
59
+ ): { readonly trailId: string; readonly prefix: string } | null => {
60
+ if (args.length < 3) {
61
+ return null;
62
+ }
63
+ const [subcommand, trailId] = args;
64
+ if (subcommand !== 'example') {
65
+ return null;
66
+ }
67
+ if (trailId === undefined || trailId.startsWith('-')) {
68
+ return null;
69
+ }
70
+ const prefix = args[2] ?? '';
71
+ return { prefix, trailId };
72
+ };
73
+
74
+ /**
75
+ * Handler for the `trails run` subcommand.
76
+ *
77
+ * Two completion positions are recognized:
78
+ *
79
+ * - `trails run example <trail-id> <prefix>` — return example names defined
80
+ * on the resolved trail (matching `prefix`, sorted).
81
+ * - `trails run <prefix>` — return matching trail IDs.
82
+ *
83
+ * Anything else (unknown flag context, a cursor beyond the trail ID, etc.)
84
+ * returns no suggestions so completed positional values are not suggested
85
+ * again.
86
+ */
87
+ const completeRunPosition: CompletionHandler = async ({
88
+ args,
89
+ rootDir,
90
+ selectedAppId,
91
+ selectedModulePath,
92
+ }) => {
93
+ const exampleContext = detectExampleValueCompletion(args);
94
+ if (exampleContext !== null) {
95
+ const suggestionsResult = await renderTrailExampleCompletions(
96
+ rootDir,
97
+ exampleContext.trailId,
98
+ exampleContext.prefix,
99
+ selectedAppId,
100
+ selectedModulePath
101
+ );
102
+ return suggestionsResult.unwrapOr([]);
103
+ }
104
+ if (args.length !== 1) {
105
+ return [];
106
+ }
107
+ const prefix = args[0] ?? '';
108
+ return await renderTrailIdCompletions(
109
+ rootDir,
110
+ prefix,
111
+ selectedAppId,
112
+ selectedModulePath
113
+ );
114
+ };
115
+
116
+ const renderSuggestions = (suggestions: readonly string[]): string =>
117
+ suggestions.join('\n');
118
+
119
+ const detectAppValueCompletion = (
120
+ args: readonly string[]
121
+ ): { readonly inline: boolean; readonly prefix: string } | null => {
122
+ const token = args.at(-1) ?? '';
123
+ const previous = args.at(-2);
124
+ if (previous === '--app') {
125
+ return { inline: false, prefix: token };
126
+ }
127
+ if (token.startsWith('--app=')) {
128
+ return { inline: true, prefix: token.slice('--app='.length) };
129
+ }
130
+ return null;
131
+ };
132
+
133
+ /**
134
+ * Subcommand → handler dispatch table.
135
+ *
136
+ * Keep this a pure lookup so adding a new completion target (`run example`,
137
+ * `--app`, etc.) is a new entry rather than a new branch.
138
+ *
139
+ * @remarks As more handlers grow per-token-shape logic (e.g. distinguishing
140
+ * `--app <TAB>` vs `<trail-id> <TAB>` for the same subcommand), expect this
141
+ * table to evolve into a sub-table of (token-pattern → completion-fn) per
142
+ * subcommand or a small parser yielding a discriminated `CompletionContext`
143
+ * union. Today the single `'run'` entry is small enough that explicit
144
+ * branching inside `completeRunPosition` is cleaner.
145
+ */
146
+ const SUBCOMMAND_HANDLERS: Readonly<Record<string, CompletionHandler>> = {
147
+ run: completeRunPosition,
148
+ };
149
+
150
+ export const completionsCompleteTrail = trail('completions.__complete', {
151
+ description:
152
+ 'Internal: emit dynamic completion suggestions for the current partial argv. Invoked by the static shell completion script at tab-press time.',
153
+ examples: [
154
+ {
155
+ description: 'Empty argv yields no suggestions',
156
+ input: { args: [] },
157
+ name: 'Empty args',
158
+ },
159
+ ],
160
+ implementation: async (input, ctx) => {
161
+ const appContext = detectAppValueCompletion(input.args);
162
+ const typedSelection = parseSelectionControls(input.args);
163
+ const parsedRun = parseRunArgv(input.args);
164
+ const selectionRootDir = typedSelection.rootDir ?? input.rootDir;
165
+ const selectedContextInput = appContext === null ? typedSelection : {};
166
+ const context = await resolveOperatorProjectContext(
167
+ {
168
+ ...selectedContextInput,
169
+ ...(selectionRootDir === undefined
170
+ ? {}
171
+ : { rootDir: selectionRootDir }),
172
+ },
173
+ { cwd: ctx.cwd }
174
+ );
175
+ if (context.isErr()) {
176
+ return context;
177
+ }
178
+ const rootDir = context.value.projectRoot;
179
+ const selectedAppId =
180
+ context.value.selectedExtent === 'configured-app'
181
+ ? context.value.app.id
182
+ : undefined;
183
+ const selectedModulePath =
184
+ context.value.selectedExtent !== 'workspace' &&
185
+ context.value.app.moduleSource === 'module'
186
+ ? context.value.app.modulePath
187
+ : undefined;
188
+
189
+ if (appContext !== null) {
190
+ const suggestions = await renderAppIdCompletions(
191
+ rootDir,
192
+ appContext.prefix
193
+ );
194
+ return Result.ok(
195
+ renderSuggestions(
196
+ appContext.inline
197
+ ? suggestions.map((suggestion) => `--app=${suggestion}`)
198
+ : suggestions
199
+ )
200
+ );
201
+ }
202
+
203
+ const [subcommand] = input.args;
204
+ if (subcommand === undefined) {
205
+ return Result.ok(EMPTY_SUGGESTIONS);
206
+ }
207
+
208
+ const handler = SUBCOMMAND_HANDLERS[subcommand];
209
+ if (handler === undefined) {
210
+ return Result.ok(EMPTY_SUGGESTIONS);
211
+ }
212
+
213
+ const suggestions = await handler({
214
+ args: parsedRun.positionals,
215
+ rootDir,
216
+ selectedAppId,
217
+ selectedModulePath,
218
+ });
219
+ return Result.ok(renderSuggestions(suggestions));
220
+ },
221
+ input: z.object({
222
+ args: z
223
+ .array(z.string())
224
+ .readonly()
225
+ .describe(
226
+ 'Partial argv after the binary name; the last element is the token being completed'
227
+ ),
228
+ rootDir: z.string().optional().describe('Workspace root directory'),
229
+ }),
230
+ intent: 'read',
231
+ output: z
232
+ .string()
233
+ .describe(
234
+ 'Newline-delimited suggestions the shell should offer for the current token'
235
+ ),
236
+ });
@@ -0,0 +1,47 @@
1
+ /**
2
+ * `completions` trail -- Print a shell completion script for the `trails` CLI.
3
+ *
4
+ * The trail's responsibility is small: render a static shell script that, when
5
+ * sourced by the user's shell, registers a tab-completion handler that
6
+ * delegates to `trails completions __complete <args...>` for the live
7
+ * suggestions. See {@link renderCompletionScript} for the per-shell shape.
8
+ */
9
+
10
+ import { trail } from '@ontrails/core';
11
+ import { z } from 'zod';
12
+
13
+ import { renderCompletionScript } from '../completions.js';
14
+
15
+ const COMPLETIONS_BIN_NAME = 'trails';
16
+
17
+ export const completionsTrail = trail('completions', {
18
+ args: ['shell'],
19
+ description:
20
+ 'Print a shell completion script for the trails CLI; pipe into your shell rc to register tab-completion',
21
+ examples: [
22
+ {
23
+ description: 'Render a bash completion script',
24
+ input: { shell: 'bash' },
25
+ name: 'Render bash completion',
26
+ },
27
+ {
28
+ description: 'Render a zsh completion script',
29
+ input: { shell: 'zsh' },
30
+ name: 'Render zsh completion',
31
+ },
32
+ {
33
+ description: 'Render a fish completion script',
34
+ input: { shell: 'fish' },
35
+ name: 'Render fish completion',
36
+ },
37
+ ],
38
+ implementation: async (input) =>
39
+ renderCompletionScript(input.shell, COMPLETIONS_BIN_NAME),
40
+ input: z.object({
41
+ shell: z
42
+ .enum(['bash', 'zsh', 'fish'])
43
+ .describe('Target shell flavor for the completion script'),
44
+ }),
45
+ intent: 'read',
46
+ output: z.string(),
47
+ });
@@ -0,0 +1,43 @@
1
+ import { Result, trail } from '@ontrails/core';
2
+ import { z } from 'zod';
3
+
4
+ import { resolveOperatorProjectContext } from './project-context.js';
5
+ import {
6
+ operatorProjectContextOutput,
7
+ operatorProjectContextOutputSchema,
8
+ } from './project-context-output.js';
9
+
10
+ const configExplainInputSchema = z.object({
11
+ app: z.string().optional().describe('Configured workspace app ID'),
12
+ rootDir: z.string().optional().describe('Workspace root directory'),
13
+ });
14
+
15
+ const configExplainOutputSchema = z.object({
16
+ configPath: z.string().nullable(),
17
+ project: operatorProjectContextOutputSchema,
18
+ });
19
+
20
+ export const configExplainTrail = trail('config.explain', {
21
+ description: 'Explain static Trails project and app identity',
22
+ examples: [
23
+ {
24
+ input: {},
25
+ name: 'Explain project identity from the current app context',
26
+ },
27
+ ],
28
+ implementation: async (input, ctx) => {
29
+ const context = await resolveOperatorProjectContext(input, {
30
+ cwd: ctx.cwd,
31
+ });
32
+ if (context.isErr()) {
33
+ return context;
34
+ }
35
+ return Result.ok({
36
+ configPath: context.value.identity.configPath ?? null,
37
+ project: operatorProjectContextOutput(context.value),
38
+ });
39
+ },
40
+ input: configExplainInputSchema,
41
+ intent: 'read',
42
+ output: configExplainOutputSchema,
43
+ });