@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,340 @@
1
+ import { existsSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+
4
+ import {
5
+ openReadTrailsDb,
6
+ openWriteTrailsDb,
7
+ deriveTrailsDbPath,
8
+ deriveTrailsDir,
9
+ } from '@ontrails/core';
10
+ import {
11
+ countPinnedSnapshots,
12
+ countPrunableSnapshots,
13
+ countTopoSnapshots,
14
+ pruneUnpinnedSnapshots,
15
+ } from '@ontrails/topographer/backend-support';
16
+ import {
17
+ DEFAULT_MAX_AGE,
18
+ DEFAULT_MAX_RECORDS,
19
+ applyTraceCleanup,
20
+ countTraceRecords,
21
+ previewTraceCleanup,
22
+ } from '@ontrails/tracing';
23
+
24
+ import { removeRootRelativeFileIfPresent } from '../local-state-io.js';
25
+
26
+ import { requireTrailRootDir } from './root-dir.js';
27
+
28
+ export const DEFAULT_TOPO_SNAPSHOT_RETENTION = 50;
29
+
30
+ const deriveRootDir = (cwd?: string): string => requireTrailRootDir(cwd);
31
+
32
+ const removeResetFileIfPresent = (
33
+ rootDir: string,
34
+ relativePath: string
35
+ ): boolean => {
36
+ const removed = removeRootRelativeFileIfPresent(rootDir, relativePath);
37
+ if (removed.isErr()) {
38
+ throw removed.error;
39
+ }
40
+ return removed.value;
41
+ };
42
+
43
+ export interface DevStatsReport {
44
+ readonly db: {
45
+ readonly exists: boolean;
46
+ readonly fileSizeBytes: number;
47
+ readonly path: string;
48
+ };
49
+ readonly lock: {
50
+ readonly exists: boolean;
51
+ readonly fileSizeBytes: number;
52
+ readonly path: string;
53
+ };
54
+ readonly retention: {
55
+ readonly snapshots: number;
56
+ readonly traceAgeMs: number;
57
+ readonly traces: number;
58
+ };
59
+ readonly topo: {
60
+ readonly pinnedCount: number;
61
+ readonly prunableSnapshotCount: number;
62
+ readonly snapshotCount: number;
63
+ };
64
+ readonly tracing: {
65
+ readonly recordCount: number;
66
+ };
67
+ }
68
+
69
+ export interface DevCleanReport {
70
+ readonly dryRun: boolean;
71
+ readonly remaining: {
72
+ readonly pinnedCount: number;
73
+ readonly snapshotCount: number;
74
+ readonly traceCount: number;
75
+ };
76
+ readonly removed: {
77
+ readonly topoSnapshots: number;
78
+ readonly traceRecords: number;
79
+ };
80
+ readonly retention: {
81
+ readonly snapshots: number;
82
+ readonly traceAgeMs: number;
83
+ readonly traces: number;
84
+ };
85
+ }
86
+
87
+ export interface DevResetReport {
88
+ readonly dryRun: boolean;
89
+ readonly removedCount: number;
90
+ readonly removedFiles: readonly string[];
91
+ }
92
+
93
+ interface DevRetentionOptions {
94
+ readonly maxAge?: number;
95
+ readonly maxRecords?: number;
96
+ readonly rootDir?: string;
97
+ readonly snapshotRetention?: number;
98
+ }
99
+
100
+ interface DevCleanupContext {
101
+ readonly dbPath: string;
102
+ readonly dryRun: boolean;
103
+ readonly retention: DevCleanReport['retention'];
104
+ readonly rootDir: string;
105
+ }
106
+
107
+ const buildRetention = (options?: DevRetentionOptions) => ({
108
+ snapshots: options?.snapshotRetention ?? DEFAULT_TOPO_SNAPSHOT_RETENTION,
109
+ traceAgeMs: options?.maxAge ?? DEFAULT_MAX_AGE,
110
+ traces: options?.maxRecords ?? DEFAULT_MAX_RECORDS,
111
+ });
112
+
113
+ const emptyDevClean = (
114
+ retention: DevCleanReport['retention'],
115
+ dryRun: boolean
116
+ ): DevCleanReport => ({
117
+ dryRun,
118
+ remaining: {
119
+ pinnedCount: 0,
120
+ snapshotCount: 0,
121
+ traceCount: 0,
122
+ },
123
+ removed: {
124
+ topoSnapshots: 0,
125
+ traceRecords: 0,
126
+ },
127
+ retention,
128
+ });
129
+
130
+ const buildLockStats = (lockPath: string): DevStatsReport['lock'] => ({
131
+ exists: existsSync(lockPath),
132
+ fileSizeBytes: existsSync(lockPath) ? statSync(lockPath).size : 0,
133
+ path: lockPath,
134
+ });
135
+
136
+ const buildDbStats = (
137
+ dbPath: string,
138
+ exists: boolean
139
+ ): DevStatsReport['db'] => ({
140
+ exists,
141
+ fileSizeBytes: exists ? statSync(dbPath).size : 0,
142
+ path: '.trails/state/trails.db',
143
+ });
144
+
145
+ const emptyDevStats = (
146
+ dbPath: string,
147
+ lockPath: string,
148
+ retention: DevStatsReport['retention']
149
+ ): DevStatsReport => ({
150
+ db: buildDbStats(dbPath, false),
151
+ lock: buildLockStats(lockPath),
152
+ retention,
153
+ topo: {
154
+ pinnedCount: 0,
155
+ prunableSnapshotCount: 0,
156
+ snapshotCount: 0,
157
+ },
158
+ tracing: {
159
+ recordCount: 0,
160
+ },
161
+ });
162
+
163
+ const liveDevStats = (
164
+ db: Parameters<typeof countPinnedSnapshots>[0],
165
+ dbPath: string,
166
+ lockPath: string,
167
+ retention: DevStatsReport['retention']
168
+ ): DevStatsReport => ({
169
+ db: buildDbStats(dbPath, true),
170
+ lock: buildLockStats(lockPath),
171
+ retention,
172
+ topo: {
173
+ pinnedCount: countPinnedSnapshots(db),
174
+ prunableSnapshotCount: countPrunableSnapshots(db, {
175
+ keep: retention.snapshots,
176
+ }),
177
+ snapshotCount: countTopoSnapshots(db),
178
+ },
179
+ tracing: {
180
+ recordCount: countTraceRecords(db),
181
+ },
182
+ });
183
+
184
+ const deriveDevStatsContext = (options?: DevRetentionOptions) => {
185
+ const rootDir = deriveRootDir(options?.rootDir);
186
+ const dbPath = deriveTrailsDbPath({ rootDir });
187
+ const trailsDir = deriveTrailsDir({ rootDir });
188
+ const lockPath = join(trailsDir, 'trails.lock');
189
+ return {
190
+ dbExists: existsSync(dbPath),
191
+ dbPath,
192
+ lockPath,
193
+ retention: buildRetention(options),
194
+ rootDir,
195
+ };
196
+ };
197
+
198
+ const deriveDevCleanupContext = (
199
+ options?: DevRetentionOptions & { readonly dryRun?: boolean }
200
+ ): DevCleanupContext => {
201
+ const rootDir = deriveRootDir(options?.rootDir);
202
+ return {
203
+ dbPath: deriveTrailsDbPath({ rootDir }),
204
+ dryRun: options?.dryRun ?? false,
205
+ retention: buildRetention(options),
206
+ rootDir,
207
+ };
208
+ };
209
+
210
+ const cleanupTraces = (
211
+ db: Parameters<typeof countPinnedSnapshots>[0],
212
+ context: DevCleanupContext
213
+ ) =>
214
+ context.dryRun
215
+ ? previewTraceCleanup(db, {
216
+ maxAge: context.retention.traceAgeMs,
217
+ maxRecords: context.retention.traces,
218
+ })
219
+ : applyTraceCleanup(db, {
220
+ maxAge: context.retention.traceAgeMs,
221
+ maxRecords: context.retention.traces,
222
+ });
223
+
224
+ const cleanupTopoSnapshots = (
225
+ db: Parameters<typeof countPinnedSnapshots>[0],
226
+ context: DevCleanupContext
227
+ ): number =>
228
+ context.dryRun
229
+ ? countPrunableSnapshots(db, { keep: context.retention.snapshots })
230
+ : pruneUnpinnedSnapshots(db, { keep: context.retention.snapshots });
231
+
232
+ const buildCleanReport = (
233
+ db: Parameters<typeof countPinnedSnapshots>[0],
234
+ context: DevCleanupContext
235
+ ): DevCleanReport => {
236
+ const traceReport = cleanupTraces(db, context);
237
+ const topoRemoved = cleanupTopoSnapshots(db, context);
238
+ const snapshotCount = countTopoSnapshots(db);
239
+
240
+ return {
241
+ dryRun: context.dryRun,
242
+ remaining: {
243
+ pinnedCount: countPinnedSnapshots(db),
244
+ snapshotCount: context.dryRun
245
+ ? snapshotCount - topoRemoved
246
+ : snapshotCount,
247
+ traceCount: context.dryRun
248
+ ? traceReport.remaining - traceReport.removedTotal
249
+ : traceReport.remaining,
250
+ },
251
+ removed: {
252
+ topoSnapshots: topoRemoved,
253
+ traceRecords: traceReport.removedTotal,
254
+ },
255
+ retention: context.retention,
256
+ };
257
+ };
258
+
259
+ const RESET_FILES = [
260
+ '.trails/state/trails.db',
261
+ '.trails/state/trails.db-shm',
262
+ '.trails/state/trails.db-wal',
263
+ // Legacy paths (pre-state migration) — cleaned for one cycle so upgrading
264
+ // workspaces do not leave stale DB sidecars at old locations.
265
+ '.trails/trails.db',
266
+ '.trails/trails.db-shm',
267
+ '.trails/trails.db-wal',
268
+ '.trails/dev/tracing.db',
269
+ '.trails/dev/tracing.db-shm',
270
+ '.trails/dev/tracing.db-wal',
271
+ ] as const;
272
+
273
+ const presentResetFiles = (
274
+ rootDir: string
275
+ ): readonly (typeof RESET_FILES)[number][] =>
276
+ RESET_FILES.filter((relativePath) => existsSync(join(rootDir, relativePath)));
277
+
278
+ export const buildDevStats = (
279
+ options?: DevRetentionOptions
280
+ ): DevStatsReport => {
281
+ const { dbExists, dbPath, lockPath, retention, rootDir } =
282
+ deriveDevStatsContext(options);
283
+
284
+ if (!dbExists) {
285
+ return emptyDevStats(dbPath, lockPath, retention);
286
+ }
287
+
288
+ const db = openReadTrailsDb({ rootDir });
289
+
290
+ try {
291
+ return liveDevStats(db, dbPath, lockPath, retention);
292
+ } finally {
293
+ db.close();
294
+ }
295
+ };
296
+
297
+ export const cleanDevState = (
298
+ options?: DevRetentionOptions & { readonly dryRun?: boolean }
299
+ ): DevCleanReport => {
300
+ const context = deriveDevCleanupContext(options);
301
+ if (!existsSync(context.dbPath)) {
302
+ return emptyDevClean(context.retention, context.dryRun);
303
+ }
304
+
305
+ const db = context.dryRun
306
+ ? openReadTrailsDb({ rootDir: context.rootDir })
307
+ : openWriteTrailsDb({ rootDir: context.rootDir });
308
+
309
+ try {
310
+ return buildCleanReport(db, context);
311
+ } finally {
312
+ db.close();
313
+ }
314
+ };
315
+
316
+ export const resetDevState = (options?: {
317
+ readonly dryRun?: boolean;
318
+ readonly rootDir?: string;
319
+ }): DevResetReport => {
320
+ const rootDir = deriveRootDir(options?.rootDir);
321
+ const files = presentResetFiles(rootDir);
322
+
323
+ if (options?.dryRun === true) {
324
+ return {
325
+ dryRun: true,
326
+ removedCount: files.length,
327
+ removedFiles: files,
328
+ };
329
+ }
330
+
331
+ const removedFiles = files.filter((relativePath) =>
332
+ removeResetFileIfPresent(rootDir, relativePath)
333
+ );
334
+
335
+ return {
336
+ dryRun: false,
337
+ removedCount: removedFiles.length,
338
+ removedFiles,
339
+ };
340
+ };
@@ -0,0 +1,56 @@
1
+ import { deriveTrailsDir, Result, trail } from '@ontrails/core';
2
+ import { readTopoGraph } from '@ontrails/topographer';
3
+ import { z } from 'zod';
4
+
5
+ import {
6
+ deriveDoctorSummary,
7
+ withLifecycleApp,
8
+ } from './version-lifecycle-support.js';
9
+
10
+ const readDoctorForceGraph = async (
11
+ rootDir: string
12
+ ): Promise<Awaited<ReturnType<typeof readTopoGraph>> | undefined> => {
13
+ try {
14
+ return await readTopoGraph({ dir: deriveTrailsDir({ rootDir }) });
15
+ } catch {
16
+ // Force audit details are supplemental; stale topo locks should not block doctor counts.
17
+ return undefined;
18
+ }
19
+ };
20
+
21
+ export const doctorTrail = trail('doctor', {
22
+ blaze: async (input, ctx) =>
23
+ withLifecycleApp(input, ctx.cwd, async (app, rootDir) => {
24
+ const forceGraph = await readDoctorForceGraph(rootDir);
25
+ return Result.ok(deriveDoctorSummary(app, { forceGraph }));
26
+ }),
27
+ description: 'Diagnose trail versioning lifecycle state',
28
+ input: z.object({
29
+ module: z.string().optional().describe('Path to the app module'),
30
+ rootDir: z.string().optional().describe('Workspace root directory'),
31
+ }),
32
+ intent: 'read',
33
+ output: z.object({
34
+ archived: z.number(),
35
+ deprecated: z.number(),
36
+ forceDetails: z.array(
37
+ z
38
+ .object({
39
+ acceptedAt: z.string(),
40
+ change: z.enum(['modified', 'removed']),
41
+ detail: z.string(),
42
+ id: z.string(),
43
+ kind: z.enum(['contour', 'trail', 'signal', 'resource']),
44
+ reason: z.string().optional(),
45
+ scope: z.enum(['entry', 'graph']),
46
+ severity: z.literal('breaking'),
47
+ source: z.literal('trails compile --force'),
48
+ })
49
+ .strict()
50
+ ),
51
+ forceEvents: z.number(),
52
+ mode: z.literal('doctor'),
53
+ trails: z.number(),
54
+ versioned: z.number(),
55
+ }),
56
+ });