@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
@@ -2,36 +2,63 @@
2
2
  * `add.verify` trail -- Add testing + warden setup to a project.
3
3
  */
4
4
 
5
- import { existsSync, mkdirSync } from 'node:fs';
6
- import { dirname, join, resolve } from 'node:path';
5
+ import { existsSync } from 'node:fs';
7
6
 
8
7
  import { Result, trail } from '@ontrails/core';
9
8
  import { z } from 'zod';
10
9
 
10
+ import {
11
+ PROJECT_NAME_MESSAGE,
12
+ PROJECT_NAME_PATTERN,
13
+ projectPathExists,
14
+ resolveProjectDir,
15
+ resolveProjectPath,
16
+ writeProjectFile,
17
+ } from '../project-writes.js';
18
+ import {
19
+ ontrailsPackageRange,
20
+ scaffoldDependencyVersions,
21
+ } from '../versions.js';
22
+ import { stringifyScaffoldPackageJson } from './scaffold-json.js';
23
+
11
24
  // ---------------------------------------------------------------------------
12
25
  // Content generators
13
26
  // ---------------------------------------------------------------------------
14
27
 
15
28
  const generateTestFile = (): string =>
16
- `import { testAll } from '@ontrails/testing';
29
+ `import { testAllEstablished } from '@ontrails/testing/established';
17
30
  import { app } from '../src/app.js';
18
31
 
19
- testAll(app);
32
+ const permitScopes = [
33
+ ...new Set(
34
+ app
35
+ .list()
36
+ .flatMap((trail) =>
37
+ trail.permit && trail.permit !== 'public' ? trail.permit.scopes : []
38
+ )
39
+ ),
40
+ ];
41
+
42
+ testAllEstablished(app, {
43
+ ctx: {
44
+ permit: { id: 'test-permit', scopes: permitScopes },
45
+ },
46
+ });
20
47
  `;
21
48
 
22
49
  const generateLefthookYml = (): string =>
23
50
  `pre-push:
24
51
  commands:
25
52
  warden:
26
- run: bunx trails warden --exit-code
53
+ run: bunx trails warden
27
54
  `;
28
55
 
29
56
  /** Add testing and warden devDependencies to package.json when present. */
30
57
  const patchVerifyDeps = (pkg: Record<string, unknown>): void => {
31
58
  const devDeps = (pkg['devDependencies'] ?? {}) as Record<string, string>;
32
- devDeps['@ontrails/testing'] = 'workspace:*';
33
- devDeps['@ontrails/warden'] = 'workspace:*';
34
- devDeps['lefthook'] = '^2.1.1';
59
+ devDeps['@ontrails/testing'] = ontrailsPackageRange;
60
+ devDeps['@ontrails/warden'] = ontrailsPackageRange;
61
+ devDeps['lefthook'] = scaffoldDependencyVersions.lefthook;
35
62
  pkg['devDependencies'] = Object.fromEntries(
36
63
  Object.entries(devDeps).toSorted(([a], [b]) => a.localeCompare(b))
37
64
  );
@@ -40,14 +67,24 @@ const patchVerifyDeps = (pkg: Record<string, unknown>): void => {
40
67
  /** Update package.json in the target project with verify dependencies. */
41
68
  const updatePackageJsonForVerify = async (
42
69
  projectDir: string
43
- ): Promise<void> => {
44
- const pkgPath = join(projectDir, 'package.json');
70
+ ): Promise<Result<void, Error>> => {
71
+ const pkgPathResult = resolveProjectPath(projectDir, 'package.json');
72
+ if (pkgPathResult.isErr()) {
73
+ return Result.err(pkgPathResult.error);
74
+ }
75
+
76
+ const pkgPath = pkgPathResult.value;
45
77
  if (!existsSync(pkgPath)) {
46
- return;
78
+ return Result.ok();
47
79
  }
48
80
  const pkg = (await Bun.file(pkgPath).json()) as Record<string, unknown>;
49
81
  patchVerifyDeps(pkg);
50
- await Bun.write(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
82
+ const written = await writeProjectFile(
83
+ projectDir,
84
+ 'package.json',
85
+ stringifyScaffoldPackageJson(pkg)
86
+ );
87
+ return written.isErr() ? Result.err(written.error) : Result.ok();
51
88
  };
52
89
 
53
90
  // ---------------------------------------------------------------------------
@@ -55,33 +92,66 @@ const updatePackageJsonForVerify = async (
55
92
  // ---------------------------------------------------------------------------
56
93
 
57
94
  export const addVerify = trail('add.verify', {
58
- description: 'Add testing and warden verification',
59
- implementation: async (input) => {
60
- const projectDir = resolve(input.dir ?? '.', input.name);
95
+ blaze: async (input) => {
96
+ const projectDirResult = resolveProjectDir(input.dir ?? '.', input.name);
97
+ if (projectDirResult.isErr()) {
98
+ return projectDirResult;
99
+ }
100
+
101
+ const projectDir = projectDirResult.value;
61
102
  const files: string[] = [];
62
103
 
63
104
  const writeFile = async (
64
105
  relativePath: string,
65
106
  content: string
66
- ): Promise<void> => {
67
- const fullPath = join(projectDir, relativePath);
68
- mkdirSync(dirname(fullPath), { recursive: true });
69
- await Bun.write(fullPath, content);
70
- files.push(relativePath);
107
+ ): Promise<Result<void, Error>> => {
108
+ const exists = projectPathExists(projectDir, relativePath);
109
+ if (exists.isErr()) {
110
+ return Result.err(exists.error);
111
+ }
112
+ if (exists.value) {
113
+ return Result.ok();
114
+ }
115
+
116
+ const written = await writeProjectFile(projectDir, relativePath, content);
117
+ if (written.isErr()) {
118
+ return Result.err(written.error);
119
+ }
120
+ files.push(written.value);
121
+ return Result.ok();
71
122
  };
72
123
 
73
- await writeFile('__tests__/examples.test.ts', generateTestFile());
74
- await writeFile('lefthook.yml', generateLefthookYml());
75
- await updatePackageJsonForVerify(projectDir);
124
+ const testFile = await writeFile(
125
+ '__tests__/examples.test.ts',
126
+ generateTestFile()
127
+ );
128
+ if (testFile.isErr()) {
129
+ return testFile;
130
+ }
131
+
132
+ const lefthookFile = await writeFile('lefthook.yml', generateLefthookYml());
133
+ if (lefthookFile.isErr()) {
134
+ return lefthookFile;
135
+ }
136
+
137
+ const packageResult = await updatePackageJsonForVerify(projectDir);
138
+ if (packageResult.isErr()) {
139
+ return packageResult;
140
+ }
76
141
 
77
142
  return Result.ok({ created: files });
78
143
  },
144
+ description: 'Add testing and warden verification',
79
145
  input: z.object({
80
146
  dir: z.string().optional().describe('Parent directory'),
81
- name: z.string().describe('Project name'),
147
+ name: z
148
+ .string()
149
+ .regex(PROJECT_NAME_PATTERN, PROJECT_NAME_MESSAGE)
150
+ .describe('Project name'),
82
151
  }),
83
- markers: { internal: true },
84
152
  output: z.object({
85
153
  created: z.array(z.string()),
86
154
  }),
155
+ permit: { scopes: ['project:write'] },
156
+ visibility: 'internal',
87
157
  });
@@ -0,0 +1,67 @@
1
+ import { trail } from '@ontrails/core';
2
+ import type { Result, Topo } from '@ontrails/core';
3
+ import { z } from 'zod';
4
+
5
+ import { tryLoadFreshAppLease } from './load-app.js';
6
+ import { resolveTrailRootDir } from './root-dir.js';
7
+ import { exportCurrentTopo } from './topo-store-support.js';
8
+ import type { TopoExportReport } from './topo-support.js';
9
+ import {
10
+ createIsolatedExampleInput,
11
+ topoSnapshotOutput,
12
+ } from './topo-support.js';
13
+
14
+ export const compileCurrentTopo = async (
15
+ app: Topo,
16
+ options?: { readonly force?: boolean | undefined; readonly rootDir?: string }
17
+ ): Promise<Result<TopoExportReport, Error>> => exportCurrentTopo(app, options);
18
+
19
+ const compileTrailInputSchema = z.object({
20
+ force: z
21
+ .boolean()
22
+ .optional()
23
+ .describe('Record graph-only force events for breaking changes'),
24
+ module: z.string().optional().describe('Path to the app module'),
25
+ rootDir: z.string().optional().describe('Workspace root directory'),
26
+ });
27
+
28
+ type CompileTrailInput = z.output<typeof compileTrailInputSchema>;
29
+
30
+ export const compileTrail = trail('compile', {
31
+ blaze: async (input: CompileTrailInput, ctx) => {
32
+ const rootDirResult = resolveTrailRootDir(input.rootDir, ctx.cwd);
33
+ if (rootDirResult.isErr()) {
34
+ return rootDirResult;
35
+ }
36
+ const rootDir = rootDirResult.value;
37
+ const leaseResult = await tryLoadFreshAppLease(input.module, rootDir);
38
+ if (leaseResult.isErr()) {
39
+ return leaseResult;
40
+ }
41
+ const lease = leaseResult.value;
42
+ try {
43
+ return await compileCurrentTopo(lease.app, {
44
+ force: input.force,
45
+ rootDir,
46
+ });
47
+ } finally {
48
+ lease.release();
49
+ }
50
+ },
51
+ description: 'Compile the current topo to .trails artifacts',
52
+ examples: [
53
+ {
54
+ input: createIsolatedExampleInput('compile'),
55
+ name: 'Compile the current topo artifacts',
56
+ },
57
+ ],
58
+ input: compileTrailInputSchema,
59
+ intent: 'write',
60
+ output: z.object({
61
+ hash: z.string(),
62
+ lockPath: z.string(),
63
+ snapshot: topoSnapshotOutput,
64
+ topoPath: z.string(),
65
+ }),
66
+ permit: { scopes: ['topo:write'] },
67
+ });
@@ -0,0 +1,165 @@
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
+ renderTrailExampleCompletions,
27
+ renderTrailIdCompletions,
28
+ } from '../completions.js';
29
+ import { resolveTrailRootDir } from './root-dir.js';
30
+
31
+ const EMPTY_SUGGESTIONS = '';
32
+
33
+ interface CompleteContext {
34
+ readonly args: readonly string[];
35
+ readonly rootDir: string;
36
+ }
37
+
38
+ type CompletionHandler = (ctx: CompleteContext) => Promise<readonly string[]>;
39
+
40
+ /**
41
+ * Detect whether the user is completing the example-name positional on a
42
+ * `trails run example` invocation.
43
+ *
44
+ * The shell hands us the partial argv with the **last element** as the token
45
+ * being completed. We recognize the `run example <trail-id> <TAB>` shape when:
46
+ *
47
+ * - the command family is `run example`, and
48
+ * - a non-flag positional (the trail ID) sits at `args[2]`.
49
+ *
50
+ * Returns the trail ID + prefix to complete, or `null` if the cursor is not
51
+ * in an example-name value position.
52
+ */
53
+ const detectExampleValueCompletion = (
54
+ args: readonly string[]
55
+ ): { readonly trailId: string; readonly prefix: string } | null => {
56
+ if (args.length < 4) {
57
+ return null;
58
+ }
59
+ const [, subcommand, trailId] = args;
60
+ if (subcommand !== 'example') {
61
+ return null;
62
+ }
63
+ if (trailId === undefined || trailId.startsWith('-')) {
64
+ return null;
65
+ }
66
+ const prefix = args[3] ?? '';
67
+ return { prefix, trailId };
68
+ };
69
+
70
+ /**
71
+ * Handler for the `trails run` subcommand.
72
+ *
73
+ * Two completion positions are recognized:
74
+ *
75
+ * - `trails run example <trail-id> <prefix>` — return example names defined
76
+ * on the resolved trail (matching `prefix`, sorted).
77
+ * - `trails run <prefix>` — return matching trail IDs.
78
+ *
79
+ * Anything else (unknown flag context, a cursor beyond the trail ID, etc.)
80
+ * returns no suggestions so completed positional values are not suggested
81
+ * again.
82
+ */
83
+ const completeRunPosition: CompletionHandler = async ({ args, rootDir }) => {
84
+ const exampleContext = detectExampleValueCompletion(args);
85
+ if (exampleContext !== null) {
86
+ const suggestionsResult = await renderTrailExampleCompletions(
87
+ rootDir,
88
+ exampleContext.trailId,
89
+ exampleContext.prefix
90
+ );
91
+ return suggestionsResult.unwrapOr([]);
92
+ }
93
+ if (args.length !== 2) {
94
+ return [];
95
+ }
96
+ const prefix = args[1] ?? '';
97
+ return await renderTrailIdCompletions(rootDir, prefix);
98
+ };
99
+
100
+ const renderSuggestions = (suggestions: readonly string[]): string =>
101
+ suggestions.join('\n');
102
+
103
+ /**
104
+ * Subcommand → handler dispatch table.
105
+ *
106
+ * Keep this a pure lookup so adding a new completion target (`run example`,
107
+ * `--app`, etc.) is a new entry rather than a new branch.
108
+ *
109
+ * @remarks As more handlers grow per-token-shape logic (e.g. distinguishing
110
+ * `--app <TAB>` vs `<trail-id> <TAB>` for the same subcommand), expect this
111
+ * table to evolve into a sub-table of (token-pattern → completion-fn) per
112
+ * subcommand or a small parser yielding a discriminated `CompletionContext`
113
+ * union. Today the single `'run'` entry is small enough that explicit
114
+ * branching inside `completeRunPosition` is cleaner.
115
+ */
116
+ const SUBCOMMAND_HANDLERS: Readonly<Record<string, CompletionHandler>> = {
117
+ run: completeRunPosition,
118
+ };
119
+
120
+ export const completionsCompleteTrail = trail('completions.__complete', {
121
+ blaze: async (input, ctx) => {
122
+ const rootDirResult = resolveTrailRootDir(input.rootDir, ctx.cwd);
123
+ if (rootDirResult.isErr()) {
124
+ return rootDirResult;
125
+ }
126
+ const rootDir = rootDirResult.value;
127
+
128
+ const [subcommand] = input.args;
129
+ if (subcommand === undefined) {
130
+ return Result.ok(EMPTY_SUGGESTIONS);
131
+ }
132
+
133
+ const handler = SUBCOMMAND_HANDLERS[subcommand];
134
+ if (handler === undefined) {
135
+ return Result.ok(EMPTY_SUGGESTIONS);
136
+ }
137
+
138
+ const suggestions = await handler({ args: input.args, rootDir });
139
+ return Result.ok(renderSuggestions(suggestions));
140
+ },
141
+ description:
142
+ 'Internal: emit dynamic completion suggestions for the current partial argv. Invoked by the static shell completion script at tab-press time.',
143
+ examples: [
144
+ {
145
+ description: 'Empty argv yields no suggestions',
146
+ input: { args: [] },
147
+ name: 'Empty args',
148
+ },
149
+ ],
150
+ input: z.object({
151
+ args: z
152
+ .array(z.string())
153
+ .readonly()
154
+ .describe(
155
+ 'Partial argv after the binary name; the last element is the token being completed'
156
+ ),
157
+ rootDir: z.string().optional().describe('Workspace root directory'),
158
+ }),
159
+ intent: 'read',
160
+ output: z
161
+ .string()
162
+ .describe(
163
+ 'Newline-delimited suggestions the shell should offer for the current token'
164
+ ),
165
+ });
@@ -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
+ blaze: async (input) =>
20
+ renderCompletionScript(input.shell, COMPLETIONS_BIN_NAME),
21
+ description:
22
+ 'Print a shell completion script for the trails CLI; pipe into your shell rc to register tab-completion',
23
+ examples: [
24
+ {
25
+ description: 'Render a bash completion script',
26
+ input: { shell: 'bash' },
27
+ name: 'Render bash completion',
28
+ },
29
+ {
30
+ description: 'Render a zsh completion script',
31
+ input: { shell: 'zsh' },
32
+ name: 'Render zsh completion',
33
+ },
34
+ {
35
+ description: 'Render a fish completion script',
36
+ input: { shell: 'fish' },
37
+ name: 'Render fish completion',
38
+ },
39
+ ],
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
+ });