@ontrails/trails 1.0.0-beta.12 → 1.0.0-beta.14

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/.turbo/turbo-lint.log +1 -1
  2. package/CHANGELOG.md +40 -12
  3. package/__tests__/examples.test.ts +14 -0
  4. package/dist/src/app.d.ts.map +1 -1
  5. package/dist/src/app.js +13 -2
  6. package/dist/src/app.js.map +1 -1
  7. package/dist/src/clack.d.ts +1 -1
  8. package/dist/src/clack.js +1 -1
  9. package/dist/src/cli.js +2 -2
  10. package/dist/src/cli.js.map +1 -1
  11. package/dist/src/trails/add-trail.js +13 -13
  12. package/dist/src/trails/add-trail.js.map +1 -1
  13. package/dist/src/trails/add-trailhead.d.ts +13 -0
  14. package/dist/src/trails/add-trailhead.d.ts.map +1 -0
  15. package/dist/src/trails/add-trailhead.js +88 -0
  16. package/dist/src/trails/add-trailhead.js.map +1 -0
  17. package/dist/src/trails/add-verify.js +10 -10
  18. package/dist/src/trails/add-verify.js.map +1 -1
  19. package/dist/src/trails/create-scaffold.js +26 -26
  20. package/dist/src/trails/create-scaffold.js.map +1 -1
  21. package/dist/src/trails/create.d.ts +6 -6
  22. package/dist/src/trails/create.d.ts.map +1 -1
  23. package/dist/src/trails/create.js +29 -29
  24. package/dist/src/trails/create.js.map +1 -1
  25. package/dist/src/trails/dev-clean.d.ts +9 -0
  26. package/dist/src/trails/dev-clean.d.ts.map +1 -0
  27. package/dist/src/trails/dev-clean.js +65 -0
  28. package/dist/src/trails/dev-clean.js.map +1 -0
  29. package/dist/src/trails/dev-reset.d.ts +6 -0
  30. package/dist/src/trails/dev-reset.d.ts.map +1 -0
  31. package/dist/src/trails/dev-reset.js +38 -0
  32. package/dist/src/trails/dev-reset.js.map +1 -0
  33. package/dist/src/trails/dev-stats.d.ts +7 -0
  34. package/dist/src/trails/dev-stats.d.ts.map +1 -0
  35. package/dist/src/trails/dev-stats.js +61 -0
  36. package/dist/src/trails/dev-stats.js.map +1 -0
  37. package/dist/src/trails/dev-support.d.ts +64 -0
  38. package/dist/src/trails/dev-support.d.ts.map +1 -0
  39. package/dist/src/trails/dev-support.js +178 -0
  40. package/dist/src/trails/dev-support.js.map +1 -0
  41. package/dist/src/trails/draft-promote.d.ts +18 -0
  42. package/dist/src/trails/draft-promote.d.ts.map +1 -0
  43. package/dist/src/trails/draft-promote.js +386 -0
  44. package/dist/src/trails/draft-promote.js.map +1 -0
  45. package/dist/src/trails/guide.d.ts +13 -3
  46. package/dist/src/trails/guide.d.ts.map +1 -1
  47. package/dist/src/trails/guide.js +21 -37
  48. package/dist/src/trails/guide.js.map +1 -1
  49. package/dist/src/trails/load-app.d.ts +3 -1
  50. package/dist/src/trails/load-app.d.ts.map +1 -1
  51. package/dist/src/trails/load-app.js +53 -10
  52. package/dist/src/trails/load-app.js.map +1 -1
  53. package/dist/src/trails/project.d.ts.map +1 -1
  54. package/dist/src/trails/project.js +14 -3
  55. package/dist/src/trails/project.js.map +1 -1
  56. package/dist/src/trails/survey.d.ts +4 -58
  57. package/dist/src/trails/survey.d.ts.map +1 -1
  58. package/dist/src/trails/survey.js +52 -173
  59. package/dist/src/trails/survey.js.map +1 -1
  60. package/dist/src/trails/topo-constants.d.ts +3 -0
  61. package/dist/src/trails/topo-constants.d.ts.map +1 -0
  62. package/dist/src/trails/topo-constants.js +3 -0
  63. package/dist/src/trails/topo-constants.js.map +1 -0
  64. package/dist/src/trails/topo-export.d.ts +18 -0
  65. package/dist/src/trails/topo-export.d.ts.map +1 -0
  66. package/dist/src/trails/topo-export.js +34 -0
  67. package/dist/src/trails/topo-export.js.map +1 -0
  68. package/dist/src/trails/topo-history.d.ts +24 -0
  69. package/dist/src/trails/topo-history.d.ts.map +1 -0
  70. package/dist/src/trails/topo-history.js +33 -0
  71. package/dist/src/trails/topo-history.js.map +1 -0
  72. package/dist/src/trails/topo-pin.d.ts +21 -0
  73. package/dist/src/trails/topo-pin.d.ts.map +1 -0
  74. package/dist/src/trails/topo-pin.js +35 -0
  75. package/dist/src/trails/topo-pin.js.map +1 -0
  76. package/dist/src/trails/topo-read-support.d.ts +54 -0
  77. package/dist/src/trails/topo-read-support.d.ts.map +1 -0
  78. package/dist/src/trails/topo-read-support.js +178 -0
  79. package/dist/src/trails/topo-read-support.js.map +1 -0
  80. package/dist/src/trails/topo-reports.d.ts +50 -0
  81. package/dist/src/trails/topo-reports.d.ts.map +1 -0
  82. package/dist/src/trails/topo-reports.js +122 -0
  83. package/dist/src/trails/topo-reports.js.map +1 -0
  84. package/dist/src/trails/topo-show.d.ts +23 -0
  85. package/dist/src/trails/topo-show.d.ts.map +1 -0
  86. package/dist/src/trails/topo-show.js +53 -0
  87. package/dist/src/trails/topo-show.js.map +1 -0
  88. package/dist/src/trails/topo-store-support.d.ts +13 -0
  89. package/dist/src/trails/topo-store-support.d.ts.map +1 -0
  90. package/dist/src/trails/topo-store-support.js +55 -0
  91. package/dist/src/trails/topo-store-support.js.map +1 -0
  92. package/dist/src/trails/topo-support.d.ts +87 -0
  93. package/dist/src/trails/topo-support.d.ts.map +1 -0
  94. package/dist/src/trails/topo-support.js +165 -0
  95. package/dist/src/trails/topo-support.js.map +1 -0
  96. package/dist/src/trails/topo-unpin.d.ts +15 -0
  97. package/dist/src/trails/topo-unpin.d.ts.map +1 -0
  98. package/dist/src/trails/topo-unpin.js +39 -0
  99. package/dist/src/trails/topo-unpin.js.map +1 -0
  100. package/dist/src/trails/topo-verify.d.ts +5 -0
  101. package/dist/src/trails/topo-verify.d.ts.map +1 -0
  102. package/dist/src/trails/topo-verify.js +28 -0
  103. package/dist/src/trails/topo-verify.js.map +1 -0
  104. package/dist/src/trails/topo.d.ts +5 -0
  105. package/dist/src/trails/topo.d.ts.map +1 -0
  106. package/dist/src/trails/topo.js +67 -0
  107. package/dist/src/trails/topo.js.map +1 -0
  108. package/dist/src/trails/warden.d.ts +1 -1
  109. package/dist/src/trails/warden.d.ts.map +1 -1
  110. package/dist/src/trails/warden.js +28 -27
  111. package/dist/src/trails/warden.js.map +1 -1
  112. package/dist/tsconfig.tsbuildinfo +1 -1
  113. package/package.json +8 -7
  114. package/src/__tests__/create.test.ts +35 -33
  115. package/src/__tests__/draft-promote.test.ts +144 -0
  116. package/src/__tests__/guide.test.ts +4 -4
  117. package/src/__tests__/load-app.test.ts +43 -0
  118. package/src/__tests__/survey.test.ts +140 -55
  119. package/src/__tests__/topo-dev.test.ts +424 -0
  120. package/src/__tests__/warden.test.ts +2 -2
  121. package/src/app.ts +24 -2
  122. package/src/clack.ts +1 -1
  123. package/src/cli.ts +2 -2
  124. package/src/trails/add-trail.ts +13 -13
  125. package/src/trails/{add-surface.ts → add-trailhead.ts} +39 -37
  126. package/src/trails/add-verify.ts +10 -10
  127. package/src/trails/create-scaffold.ts +28 -28
  128. package/src/trails/create.ts +42 -42
  129. package/src/trails/dev-clean.ts +73 -0
  130. package/src/trails/dev-reset.ts +44 -0
  131. package/src/trails/dev-stats.ts +64 -0
  132. package/src/trails/dev-support.ts +326 -0
  133. package/src/trails/draft-promote.ts +704 -0
  134. package/src/trails/guide.ts +29 -44
  135. package/src/trails/load-app.ts +76 -13
  136. package/src/trails/project.ts +17 -3
  137. package/src/trails/survey.ts +80 -279
  138. package/src/trails/topo-constants.ts +2 -0
  139. package/src/trails/topo-export.ts +39 -0
  140. package/src/trails/topo-history.ts +40 -0
  141. package/src/trails/topo-pin.ts +42 -0
  142. package/src/trails/topo-read-support.ts +332 -0
  143. package/src/trails/topo-reports.ts +221 -0
  144. package/src/trails/topo-show.ts +58 -0
  145. package/src/trails/topo-store-support.ts +96 -0
  146. package/src/trails/topo-support.ts +274 -0
  147. package/src/trails/topo-unpin.ts +51 -0
  148. package/src/trails/topo-verify.ts +29 -0
  149. package/src/trails/topo.ts +73 -0
  150. package/src/trails/warden.ts +33 -32
@@ -0,0 +1,424 @@
1
+ /* oxlint-disable max-statements */
2
+
3
+ import { describe, expect, test } from 'bun:test';
4
+ import {
5
+ existsSync,
6
+ mkdirSync,
7
+ readFileSync,
8
+ rmSync,
9
+ writeFileSync,
10
+ } from 'node:fs';
11
+ import { join, resolve } from 'node:path';
12
+
13
+ import type { Result } from '@ontrails/core';
14
+ import { openReadTrailsDb } from '@ontrails/core/internal/trails-db';
15
+ import { createDevStore } from '@ontrails/tracker';
16
+
17
+ import { devCleanTrail } from '../trails/dev-clean.js';
18
+ import { devResetTrail } from '../trails/dev-reset.js';
19
+ import { devStatsTrail } from '../trails/dev-stats.js';
20
+ import { guideTrail } from '../trails/guide.js';
21
+ import { surveyTrail } from '../trails/survey.js';
22
+ import { topoExportTrail } from '../trails/topo-export.js';
23
+ import { topoHistoryTrail } from '../trails/topo-history.js';
24
+ import { topoPinTrail } from '../trails/topo-pin.js';
25
+ import { topoShowTrail } from '../trails/topo-show.js';
26
+ import { topoTrail } from '../trails/topo.js';
27
+ import { topoUnpinTrail } from '../trails/topo-unpin.js';
28
+ import { topoVerifyTrail } from '../trails/topo-verify.js';
29
+
30
+ const repoTempDir = (): string =>
31
+ join(
32
+ resolve(import.meta.dir, '../..'),
33
+ '.tmp-tests',
34
+ `topo-dev-${Date.now()}-${Math.random().toString(36).slice(2)}`
35
+ );
36
+
37
+ const expectOk = <T>(result: Result<T, Error>): T => {
38
+ if (result.isErr()) {
39
+ throw result.error;
40
+ }
41
+ return result.value;
42
+ };
43
+
44
+ const expectErr = <E extends Error>(result: Result<unknown, E>): E => {
45
+ if (result.isOk()) {
46
+ throw new Error('expected result to be an error');
47
+ }
48
+ return result.error;
49
+ };
50
+
51
+ const moduleInput = { module: './src/app.ts' } as const;
52
+
53
+ const writeAppFixture = (dir: string): void => {
54
+ mkdirSync(join(dir, 'src'), { recursive: true });
55
+ writeFileSync(
56
+ join(dir, 'src', 'app.ts'),
57
+ `import { Result, provision, topo, trail } from '@ontrails/core';
58
+ import { z } from 'zod';
59
+
60
+ const hello = trail('hello', {
61
+ blaze: async (input) => Result.ok({ message: \`Hello, \${input.name ?? 'world'}!\` }),
62
+ crosses: ['goodbye'],
63
+ examples: [{ input: {}, name: 'Default greeting' }],
64
+ input: z.object({ name: z.string().optional() }),
65
+ intent: 'read',
66
+ output: z.object({ message: z.string() }),
67
+ provisions: [
68
+ provision('db.main', {
69
+ create: () => Result.ok({ source: 'factory' }),
70
+ }),
71
+ ],
72
+ });
73
+
74
+ const goodbye = trail('goodbye', {
75
+ blaze: async () => Result.ok({ ok: true }),
76
+ input: z.object({}),
77
+ intent: 'write',
78
+ output: z.object({ ok: z.boolean() }),
79
+ });
80
+
81
+ const [dbMain] = hello.provisions;
82
+ if (!dbMain) {
83
+ throw new Error('expected hello to declare db.main');
84
+ }
85
+
86
+ export const app = topo('fixture-app', { dbMain, goodbye, hello });
87
+ `
88
+ );
89
+ };
90
+
91
+ describe('topo and dev trails', () => {
92
+ test('topo surfaces current summary, detail, and export/verify flow', async () => {
93
+ const dir = repoTempDir();
94
+
95
+ try {
96
+ writeAppFixture(dir);
97
+
98
+ const summary = expectOk(
99
+ await topoTrail.blaze(moduleInput, { cwd: dir } as never)
100
+ );
101
+ expect(summary.app.name).toBe('fixture-app');
102
+ expect(summary.list.count).toBe(2);
103
+ expect(summary.list.provisionCount).toBe(1);
104
+ expect(summary.lockExists).toBe(false);
105
+
106
+ const detail = expectOk(
107
+ await topoShowTrail.blaze({ ...moduleInput, id: 'hello' }, {
108
+ cwd: dir,
109
+ } as never)
110
+ );
111
+ expect(detail.id).toBe('hello');
112
+ expect(detail.provisions).toEqual(['db.main']);
113
+
114
+ const exportResult = expectOk(
115
+ await topoExportTrail.blaze(moduleInput, { cwd: dir } as never)
116
+ );
117
+ expect(exportResult.hash).toHaveLength(64);
118
+ expect(existsSync(join(dir, '.trails', '_trailhead.json'))).toBe(true);
119
+ expect(existsSync(join(dir, '.trails', 'trails.lock'))).toBe(true);
120
+ expect(
121
+ JSON.parse(readFileSync(join(dir, '.trails', 'trails.lock'), 'utf8'))
122
+ ).toMatchObject({
123
+ hash: exportResult.hash,
124
+ version: 1,
125
+ });
126
+
127
+ writeFileSync(
128
+ join(dir, '.trails', 'trailhead.lock'),
129
+ readFileSync(join(dir, '.trails', 'trails.lock'), 'utf8')
130
+ );
131
+ rmSync(join(dir, '.trails', 'trails.lock'));
132
+
133
+ const legacySummary = expectOk(
134
+ await topoTrail.blaze(moduleInput, { cwd: dir } as never)
135
+ );
136
+ expect(legacySummary.lockExists).toBe(true);
137
+
138
+ const verifyResult = expectOk(
139
+ await topoVerifyTrail.blaze(moduleInput, { cwd: dir } as never)
140
+ );
141
+ expect(verifyResult.stale).toBe(false);
142
+
143
+ writeFileSync(join(dir, '.trails', 'trailhead.lock'), 'stale\n');
144
+ const verifyError = expectErr(
145
+ await topoVerifyTrail.blaze(moduleInput, { cwd: dir } as never)
146
+ );
147
+ expect(verifyError.message).toContain('trails.lock is stale');
148
+ } finally {
149
+ rmSync(dir, { force: true, recursive: true });
150
+ }
151
+ });
152
+
153
+ test('survey and guide read current topo state through the shared topo store', async () => {
154
+ const dir = repoTempDir();
155
+
156
+ try {
157
+ writeAppFixture(dir);
158
+
159
+ const surveyList = expectOk(
160
+ await surveyTrail.blaze({ module: './src/app.ts' }, {
161
+ cwd: dir,
162
+ } as never)
163
+ );
164
+ expect(surveyList).toMatchObject({
165
+ count: 2,
166
+ provisionCount: 1,
167
+ });
168
+
169
+ const surveyBrief = expectOk(
170
+ await surveyTrail.blaze({ brief: true, module: './src/app.ts' }, {
171
+ cwd: dir,
172
+ } as never)
173
+ );
174
+ expect(surveyBrief).toMatchObject({
175
+ features: {
176
+ examples: true,
177
+ outputSchemas: true,
178
+ provisions: true,
179
+ },
180
+ name: 'fixture-app',
181
+ trails: 2,
182
+ });
183
+
184
+ const surveyDetail = expectOk(
185
+ await surveyTrail.blaze({ module: './src/app.ts', trailId: 'hello' }, {
186
+ cwd: dir,
187
+ } as never)
188
+ );
189
+ expect(surveyDetail).toMatchObject({
190
+ id: 'hello',
191
+ provisions: ['db.main'],
192
+ });
193
+
194
+ const guideList = expectOk(
195
+ await guideTrail.blaze({ module: './src/app.ts' }, {
196
+ cwd: dir,
197
+ } as never)
198
+ );
199
+ expect(guideList).toEqual([
200
+ {
201
+ description: '(no description)',
202
+ exampleCount: 0,
203
+ id: 'goodbye',
204
+ kind: 'trail',
205
+ },
206
+ {
207
+ description: '(no description)',
208
+ exampleCount: 1,
209
+ id: 'hello',
210
+ kind: 'trail',
211
+ },
212
+ ]);
213
+
214
+ const guideDetail = expectOk(
215
+ await guideTrail.blaze({ module: './src/app.ts', trailId: 'hello' }, {
216
+ cwd: dir,
217
+ } as never)
218
+ );
219
+ expect(guideDetail).toMatchObject({
220
+ description: null,
221
+ examples: [
222
+ {
223
+ input: {},
224
+ name: 'Default greeting',
225
+ },
226
+ ],
227
+ id: 'hello',
228
+ kind: 'trail',
229
+ });
230
+ } finally {
231
+ rmSync(dir, { force: true, recursive: true });
232
+ }
233
+ });
234
+
235
+ test('pinning, history, unpinning, and dev maintenance work against shared trails.db', async () => {
236
+ const dir = repoTempDir();
237
+
238
+ try {
239
+ writeAppFixture(dir);
240
+
241
+ const firstPin = expectOk(
242
+ await topoPinTrail.blaze({ ...moduleInput, name: 'before-auth' }, {
243
+ cwd: dir,
244
+ } as never)
245
+ );
246
+ expect(firstPin.pin.name).toBe('before-auth');
247
+ expect(firstPin.pin.saveId).toBe(firstPin.save.id);
248
+
249
+ const firstExport = expectOk(
250
+ await topoExportTrail.blaze(moduleInput, { cwd: dir } as never)
251
+ );
252
+ const secondExport = expectOk(
253
+ await topoExportTrail.blaze(moduleInput, { cwd: dir } as never)
254
+ );
255
+ expect(firstExport.hash).toBe(secondExport.hash);
256
+ expect(
257
+ JSON.parse(readFileSync(join(dir, '.trails', 'trails.lock'), 'utf8'))
258
+ ).toMatchObject({
259
+ hash: secondExport.hash,
260
+ version: 1,
261
+ });
262
+
263
+ const projectionDb = openReadTrailsDb({ rootDir: dir });
264
+ try {
265
+ const pinnedRows = projectionDb
266
+ .query<{ count: number }, [string]>(
267
+ 'SELECT COUNT(*) as count FROM topo_trails WHERE save_id = ?'
268
+ )
269
+ .get(firstPin.save.id);
270
+ const exportedRows = projectionDb
271
+ .query<{ count: number }, [string]>(
272
+ 'SELECT COUNT(*) as count FROM topo_trails WHERE save_id = ?'
273
+ )
274
+ .get(firstExport.save.id);
275
+ const projectedSaves = projectionDb
276
+ .query<{ count: number }, []>(
277
+ 'SELECT COUNT(DISTINCT save_id) as count FROM topo_trails'
278
+ )
279
+ .get();
280
+ const cachedSchemas = projectionDb
281
+ .query<{ count: number }, []>(
282
+ 'SELECT COUNT(*) as count FROM topo_schemas'
283
+ )
284
+ .get();
285
+
286
+ expect(pinnedRows?.count).toBe(2);
287
+ expect(exportedRows?.count).toBe(2);
288
+ expect(projectedSaves?.count).toBe(3);
289
+ expect(cachedSchemas?.count).toBeGreaterThanOrEqual(9);
290
+ } finally {
291
+ projectionDb.close();
292
+ }
293
+
294
+ const store = createDevStore({ rootDir: dir });
295
+ try {
296
+ store.write({
297
+ attrs: {},
298
+ endedAt: Date.now() - 1000,
299
+ id: 'track-1',
300
+ kind: 'trail',
301
+ name: 'hello',
302
+ rootId: 'track-1',
303
+ startedAt: Date.now() - 10_000,
304
+ status: 'ok',
305
+ traceId: 'trace-1',
306
+ trailId: 'hello',
307
+ trailhead: 'cli',
308
+ });
309
+ store.write({
310
+ attrs: {},
311
+ endedAt: Date.now() - 500,
312
+ id: 'track-2',
313
+ kind: 'trail',
314
+ name: 'goodbye',
315
+ rootId: 'track-2',
316
+ startedAt: Date.now() - 20_000,
317
+ status: 'err',
318
+ traceId: 'trace-2',
319
+ trailId: 'goodbye',
320
+ trailhead: 'cli',
321
+ });
322
+ } finally {
323
+ store.close();
324
+ }
325
+
326
+ const history = expectOk(
327
+ await topoHistoryTrail.blaze({}, { cwd: dir } as never)
328
+ );
329
+ expect(history.pinCount).toBe(1);
330
+ expect(history.saveCount).toBeGreaterThanOrEqual(3);
331
+ expect(history.pins[0]?.saveId).toBe(firstPin.save.id);
332
+ expect(
333
+ history.saves.some((save) => save.id === secondExport.save.id)
334
+ ).toBe(true);
335
+
336
+ const stats = expectOk(
337
+ await devStatsTrail.blaze({}, { cwd: dir } as never)
338
+ );
339
+ expect(stats.topo.pinCount).toBe(1);
340
+ expect(stats.tracker.recordCount).toBe(2);
341
+
342
+ const cleanPreview = expectOk(
343
+ await devCleanTrail.blaze({ dryRun: true, saves: 0, trackAgeMs: 0 }, {
344
+ cwd: dir,
345
+ } as never)
346
+ );
347
+ expect(cleanPreview.dryRun).toBe(true);
348
+ expect(cleanPreview.removed.topoSaves).toBeGreaterThanOrEqual(2);
349
+ expect(cleanPreview.removed.trackRecords).toBe(2);
350
+
351
+ const cleanResult = expectOk(
352
+ await devCleanTrail.blaze(
353
+ { dryRun: false, saves: 0, trackAgeMs: 0, yes: true },
354
+ { cwd: dir } as never
355
+ )
356
+ );
357
+ expect(cleanResult.removed.trackRecords).toBe(2);
358
+ expect(cleanResult.remaining.pinCount).toBe(1);
359
+
360
+ const unpinPreview = expectOk(
361
+ await topoUnpinTrail.blaze({ dryRun: true, name: 'before-auth' }, {
362
+ cwd: dir,
363
+ } as never)
364
+ );
365
+ expect(unpinPreview.dryRun).toBe(true);
366
+ expect(unpinPreview.pin?.name).toBe('before-auth');
367
+
368
+ const unpinResult = expectOk(
369
+ await topoUnpinTrail.blaze(
370
+ { dryRun: false, name: 'before-auth', yes: true },
371
+ { cwd: dir } as never
372
+ )
373
+ );
374
+ expect(unpinResult.removed).toBe(true);
375
+
376
+ const resetPreview = expectOk(
377
+ await devResetTrail.blaze({ dryRun: true }, { cwd: dir } as never)
378
+ );
379
+ expect(resetPreview.dryRun).toBe(true);
380
+ expect(resetPreview.removedFiles).toContain('.trails/trails.db');
381
+
382
+ const resetResult = expectOk(
383
+ await devResetTrail.blaze({ dryRun: false, yes: true }, {
384
+ cwd: dir,
385
+ } as never)
386
+ );
387
+ expect(resetResult.removedFiles).toContain('.trails/trails.db');
388
+ expect(existsSync(join(dir, '.trails', 'trails.db'))).toBe(false);
389
+ expect(
390
+ readFileSync(join(dir, '.trails', 'trails.lock'), 'utf8').length
391
+ ).toBeGreaterThan(0);
392
+ } finally {
393
+ rmSync(dir, { force: true, recursive: true });
394
+ }
395
+ });
396
+
397
+ test('dev clean stays side-effect free when no local state exists', async () => {
398
+ const dir = repoTempDir();
399
+
400
+ try {
401
+ mkdirSync(dir, { recursive: true });
402
+
403
+ const preview = expectOk(
404
+ await devCleanTrail.blaze({ dryRun: true }, { cwd: dir } as never)
405
+ );
406
+ expect(preview.dryRun).toBe(true);
407
+ expect(preview.removed.topoSaves).toBe(0);
408
+ expect(preview.removed.trackRecords).toBe(0);
409
+ expect(existsSync(join(dir, '.trails', 'trails.db'))).toBe(false);
410
+
411
+ const applied = expectOk(
412
+ await devCleanTrail.blaze({ dryRun: false, yes: true }, {
413
+ cwd: dir,
414
+ } as never)
415
+ );
416
+ expect(applied.dryRun).toBe(false);
417
+ expect(applied.removed.topoSaves).toBe(0);
418
+ expect(applied.removed.trackRecords).toBe(0);
419
+ expect(existsSync(join(dir, '.trails', 'trails.db'))).toBe(false);
420
+ } finally {
421
+ rmSync(dir, { force: true, recursive: true });
422
+ }
423
+ });
424
+ });
@@ -21,7 +21,7 @@ describe('trails warden', () => {
21
21
  writeFileSync(
22
22
  join(dir, 'good.ts'),
23
23
  `trail("hello", {
24
- run: async (input, ctx) => {
24
+ blaze: async (input, ctx) => {
25
25
  return Result.ok({ message: "hi" });
26
26
  }
27
27
  })`
@@ -54,7 +54,7 @@ describe('trails warden', () => {
54
54
  writeFileSync(
55
55
  join(dir, 'bad.ts'),
56
56
  `trail("x", {
57
- run: async () => { throw new Error("boom"); }
57
+ blaze: async () => { throw new Error("boom"); }
58
58
  })`
59
59
  );
60
60
  const report = await runWarden({ driftOnly: true, rootDir: dir });
package/src/app.ts CHANGED
@@ -1,22 +1,44 @@
1
1
  import { topo } from '@ontrails/core';
2
2
 
3
- import * as addSurface from './trails/add-surface.js';
3
+ import * as addTrailhead from './trails/add-trailhead.js';
4
4
  import * as addTrail from './trails/add-trail.js';
5
5
  import * as addVerify from './trails/add-verify.js';
6
6
  import * as create from './trails/create.js';
7
7
  import * as createScaffold from './trails/create-scaffold.js';
8
+ import * as devClean from './trails/dev-clean.js';
9
+ import * as devReset from './trails/dev-reset.js';
10
+ import * as devStats from './trails/dev-stats.js';
11
+ import * as draftPromote from './trails/draft-promote.js';
8
12
  import * as guide from './trails/guide.js';
9
13
  import * as survey from './trails/survey.js';
14
+ import * as topoExport from './trails/topo-export.js';
15
+ import * as topoHistory from './trails/topo-history.js';
16
+ import * as topoPin from './trails/topo-pin.js';
17
+ import * as topoShow from './trails/topo-show.js';
18
+ import * as topoCommand from './trails/topo.js';
19
+ import * as topoUnpin from './trails/topo-unpin.js';
20
+ import * as topoVerify from './trails/topo-verify.js';
10
21
  import * as warden from './trails/warden.js';
11
22
 
12
23
  export const app = topo(
13
24
  'trails',
14
25
  survey,
26
+ topoCommand,
27
+ topoShow,
28
+ topoHistory,
29
+ topoPin,
30
+ topoUnpin,
31
+ topoExport,
32
+ topoVerify,
33
+ devStats,
34
+ devClean,
35
+ devReset,
15
36
  guide,
37
+ draftPromote,
16
38
  warden,
17
39
  create,
18
40
  createScaffold,
19
- addSurface,
41
+ addTrailhead,
20
42
  addVerify,
21
43
  addTrail
22
44
  );
package/src/clack.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Clack-backed input resolver for the Trails CLI.
3
3
  *
4
- * This stays at the app layer so @ontrails/cli remains prompt-library agnostic.
4
+ * This stays at the app gate so @ontrails/cli remains prompt-library agnostic.
5
5
  */
6
6
 
7
7
  import type { Field, InputResolver, ResolveInputOptions } from '@ontrails/cli';
package/src/cli.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { outputModePreset } from '@ontrails/cli';
2
- import { blaze } from '@ontrails/cli/commander';
2
+ import { trailhead } from '@ontrails/cli/commander';
3
3
 
4
4
  import { app } from './app.js';
5
5
  import { resolveInputWithClack } from './clack.js';
6
6
 
7
7
  // oxlint-disable-next-line require-hook -- CLI entry point
8
- blaze(app, {
8
+ trailhead(app, {
9
9
  description: 'Agent-native, contract-first TypeScript framework',
10
10
  name: 'trails',
11
11
  presets: [outputModePreset()],
@@ -29,7 +29,7 @@ export const ${id.replaceAll('.', '_')} = trail('${id}', {
29
29
  name: 'TODO: add example',
30
30
  },
31
31
  ],
32
- run: async (input) => {
32
+ blaze: async (input) => {
33
33
  return Result.ok({ message: 'TODO' });
34
34
  },
35
35
  input: z.object({}),${intentLine}
@@ -64,18 +64,7 @@ const writeWithDirs = async (
64
64
  };
65
65
 
66
66
  export const addTrail = trail('add.trail', {
67
- description: 'Scaffold a new trail with tests and examples',
68
- input: z.object({
69
- id: z.string().describe('Trail ID (e.g., entity.update)'),
70
- intent: z
71
- .enum(['read', 'write', 'destroy'])
72
- .default('write')
73
- .describe('Trail intent'),
74
- }),
75
- output: z.object({
76
- created: z.array(z.string()),
77
- }),
78
- run: async (input, ctx) => {
67
+ blaze: async (input, ctx) => {
79
68
  const { id } = input;
80
69
  const moduleName = id.replaceAll('.', '-');
81
70
  const cwd = resolve(ctx.cwd ?? '.');
@@ -91,4 +80,15 @@ export const addTrail = trail('add.trail', {
91
80
 
92
81
  return Result.ok({ created: [...files.keys()] });
93
82
  },
83
+ description: 'Scaffold a new trail with tests and examples',
84
+ input: z.object({
85
+ id: z.string().describe('Trail ID (e.g., entity.update)'),
86
+ intent: z
87
+ .enum(['read', 'write', 'destroy'])
88
+ .default('write')
89
+ .describe('Trail intent'),
90
+ }),
91
+ output: z.object({
92
+ created: z.array(z.string()),
93
+ }),
94
94
  });