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

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 (197) hide show
  1. package/CHANGELOG.md +208 -0
  2. package/README.md +27 -0
  3. package/package.json +19 -8
  4. package/src/app.ts +17 -7
  5. package/src/clack.ts +1 -1
  6. package/src/cli.ts +304 -10
  7. package/src/completions.ts +240 -0
  8. package/src/load-app-mirror.ts +160 -0
  9. package/src/local-state-io.ts +153 -0
  10. package/src/project-writes.ts +320 -0
  11. package/src/run-collision.ts +125 -0
  12. package/src/run-completions-install.ts +179 -0
  13. package/src/run-example.ts +149 -0
  14. package/src/run-examples.ts +148 -0
  15. package/src/run-quiet.ts +75 -0
  16. package/src/run-trace.ts +273 -0
  17. package/src/run-warden.ts +39 -0
  18. package/src/run-watch.ts +432 -0
  19. package/src/scaffold-versions.generated.ts +12 -0
  20. package/src/trails/add-surface.ts +172 -0
  21. package/src/trails/add-trail.ts +73 -27
  22. package/src/trails/add-verify.ts +68 -23
  23. package/src/trails/completions-complete.ts +165 -0
  24. package/src/trails/completions.ts +47 -0
  25. package/src/trails/create-scaffold.ts +101 -35
  26. package/src/trails/create.ts +87 -74
  27. package/src/trails/dev-clean.ts +31 -22
  28. package/src/trails/dev-reset.ts +9 -3
  29. package/src/trails/dev-stats.ts +28 -20
  30. package/src/trails/dev-support.ts +109 -95
  31. package/src/trails/draft-promote.ts +351 -107
  32. package/src/trails/guide.ts +55 -38
  33. package/src/trails/load-app.ts +712 -38
  34. package/src/trails/root-dir.ts +21 -0
  35. package/src/trails/run-example.ts +482 -0
  36. package/src/trails/run-examples.ts +141 -0
  37. package/src/trails/run.ts +403 -0
  38. package/src/trails/survey.ts +517 -186
  39. package/src/trails/topo-activation.ts +385 -0
  40. package/src/trails/topo-compile.ts +55 -0
  41. package/src/trails/topo-history.ts +14 -11
  42. package/src/trails/topo-output-schemas.ts +175 -0
  43. package/src/trails/topo-pin.ts +25 -16
  44. package/src/trails/topo-read-support.ts +178 -238
  45. package/src/trails/topo-reports.ts +445 -63
  46. package/src/trails/topo-store-support.ts +67 -35
  47. package/src/trails/topo-support.ts +93 -147
  48. package/src/trails/topo-unpin.ts +17 -7
  49. package/src/trails/topo-verify.ts +19 -10
  50. package/src/trails/topo.ts +64 -31
  51. package/src/trails/warden-guide.ts +121 -0
  52. package/src/trails/warden.ts +137 -47
  53. package/src/versions.ts +28 -0
  54. package/.turbo/turbo-build.log +0 -1
  55. package/.turbo/turbo-lint.log +0 -3
  56. package/.turbo/turbo-typecheck.log +0 -1
  57. package/__tests__/examples.test.ts +0 -20
  58. package/dist/bin/trails.d.ts +0 -3
  59. package/dist/bin/trails.d.ts.map +0 -1
  60. package/dist/bin/trails.js +0 -4
  61. package/dist/bin/trails.js.map +0 -1
  62. package/dist/src/app.d.ts +0 -2
  63. package/dist/src/app.d.ts.map +0 -1
  64. package/dist/src/app.js +0 -22
  65. package/dist/src/app.js.map +0 -1
  66. package/dist/src/clack.d.ts +0 -9
  67. package/dist/src/clack.d.ts.map +0 -1
  68. package/dist/src/clack.js +0 -84
  69. package/dist/src/clack.js.map +0 -1
  70. package/dist/src/cli.d.ts +0 -2
  71. package/dist/src/cli.d.ts.map +0 -1
  72. package/dist/src/cli.js +0 -13
  73. package/dist/src/cli.js.map +0 -1
  74. package/dist/src/trails/add-surface.d.ts +0 -13
  75. package/dist/src/trails/add-surface.d.ts.map +0 -1
  76. package/dist/src/trails/add-surface.js +0 -88
  77. package/dist/src/trails/add-surface.js.map +0 -1
  78. package/dist/src/trails/add-trail.d.ts +0 -10
  79. package/dist/src/trails/add-trail.d.ts.map +0 -1
  80. package/dist/src/trails/add-trail.js +0 -77
  81. package/dist/src/trails/add-trail.js.map +0 -1
  82. package/dist/src/trails/add-trailhead.d.ts +0 -13
  83. package/dist/src/trails/add-trailhead.d.ts.map +0 -1
  84. package/dist/src/trails/add-trailhead.js +0 -88
  85. package/dist/src/trails/add-trailhead.js.map +0 -1
  86. package/dist/src/trails/add-verify.d.ts +0 -10
  87. package/dist/src/trails/add-verify.d.ts.map +0 -1
  88. package/dist/src/trails/add-verify.js +0 -67
  89. package/dist/src/trails/add-verify.js.map +0 -1
  90. package/dist/src/trails/create-scaffold.d.ts +0 -15
  91. package/dist/src/trails/create-scaffold.d.ts.map +0 -1
  92. package/dist/src/trails/create-scaffold.js +0 -288
  93. package/dist/src/trails/create-scaffold.js.map +0 -1
  94. package/dist/src/trails/create.d.ts +0 -22
  95. package/dist/src/trails/create.d.ts.map +0 -1
  96. package/dist/src/trails/create.js +0 -121
  97. package/dist/src/trails/create.js.map +0 -1
  98. package/dist/src/trails/dev-clean.d.ts +0 -9
  99. package/dist/src/trails/dev-clean.d.ts.map +0 -1
  100. package/dist/src/trails/dev-clean.js +0 -65
  101. package/dist/src/trails/dev-clean.js.map +0 -1
  102. package/dist/src/trails/dev-reset.d.ts +0 -6
  103. package/dist/src/trails/dev-reset.d.ts.map +0 -1
  104. package/dist/src/trails/dev-reset.js +0 -38
  105. package/dist/src/trails/dev-reset.js.map +0 -1
  106. package/dist/src/trails/dev-stats.d.ts +0 -7
  107. package/dist/src/trails/dev-stats.d.ts.map +0 -1
  108. package/dist/src/trails/dev-stats.js +0 -61
  109. package/dist/src/trails/dev-stats.js.map +0 -1
  110. package/dist/src/trails/dev-support.d.ts +0 -64
  111. package/dist/src/trails/dev-support.d.ts.map +0 -1
  112. package/dist/src/trails/dev-support.js +0 -178
  113. package/dist/src/trails/dev-support.js.map +0 -1
  114. package/dist/src/trails/draft-promote.d.ts +0 -18
  115. package/dist/src/trails/draft-promote.d.ts.map +0 -1
  116. package/dist/src/trails/draft-promote.js +0 -386
  117. package/dist/src/trails/draft-promote.js.map +0 -1
  118. package/dist/src/trails/guide.d.ts +0 -21
  119. package/dist/src/trails/guide.d.ts.map +0 -1
  120. package/dist/src/trails/guide.js +0 -64
  121. package/dist/src/trails/guide.js.map +0 -1
  122. package/dist/src/trails/load-app.d.ts +0 -6
  123. package/dist/src/trails/load-app.d.ts.map +0 -1
  124. package/dist/src/trails/load-app.js +0 -67
  125. package/dist/src/trails/load-app.js.map +0 -1
  126. package/dist/src/trails/project.d.ts +0 -8
  127. package/dist/src/trails/project.d.ts.map +0 -1
  128. package/dist/src/trails/project.js +0 -54
  129. package/dist/src/trails/project.js.map +0 -1
  130. package/dist/src/trails/survey.d.ts +0 -18
  131. package/dist/src/trails/survey.d.ts.map +0 -1
  132. package/dist/src/trails/survey.js +0 -212
  133. package/dist/src/trails/survey.js.map +0 -1
  134. package/dist/src/trails/topo-constants.d.ts +0 -3
  135. package/dist/src/trails/topo-constants.d.ts.map +0 -1
  136. package/dist/src/trails/topo-constants.js +0 -3
  137. package/dist/src/trails/topo-constants.js.map +0 -1
  138. package/dist/src/trails/topo-export.d.ts +0 -18
  139. package/dist/src/trails/topo-export.d.ts.map +0 -1
  140. package/dist/src/trails/topo-export.js +0 -34
  141. package/dist/src/trails/topo-export.js.map +0 -1
  142. package/dist/src/trails/topo-history.d.ts +0 -24
  143. package/dist/src/trails/topo-history.d.ts.map +0 -1
  144. package/dist/src/trails/topo-history.js +0 -33
  145. package/dist/src/trails/topo-history.js.map +0 -1
  146. package/dist/src/trails/topo-pin.d.ts +0 -21
  147. package/dist/src/trails/topo-pin.d.ts.map +0 -1
  148. package/dist/src/trails/topo-pin.js +0 -35
  149. package/dist/src/trails/topo-pin.js.map +0 -1
  150. package/dist/src/trails/topo-read-support.d.ts +0 -54
  151. package/dist/src/trails/topo-read-support.d.ts.map +0 -1
  152. package/dist/src/trails/topo-read-support.js +0 -178
  153. package/dist/src/trails/topo-read-support.js.map +0 -1
  154. package/dist/src/trails/topo-reports.d.ts +0 -50
  155. package/dist/src/trails/topo-reports.d.ts.map +0 -1
  156. package/dist/src/trails/topo-reports.js +0 -122
  157. package/dist/src/trails/topo-reports.js.map +0 -1
  158. package/dist/src/trails/topo-show.d.ts +0 -23
  159. package/dist/src/trails/topo-show.d.ts.map +0 -1
  160. package/dist/src/trails/topo-show.js +0 -53
  161. package/dist/src/trails/topo-show.js.map +0 -1
  162. package/dist/src/trails/topo-store-support.d.ts +0 -13
  163. package/dist/src/trails/topo-store-support.d.ts.map +0 -1
  164. package/dist/src/trails/topo-store-support.js +0 -55
  165. package/dist/src/trails/topo-store-support.js.map +0 -1
  166. package/dist/src/trails/topo-support.d.ts +0 -87
  167. package/dist/src/trails/topo-support.d.ts.map +0 -1
  168. package/dist/src/trails/topo-support.js +0 -165
  169. package/dist/src/trails/topo-support.js.map +0 -1
  170. package/dist/src/trails/topo-unpin.d.ts +0 -15
  171. package/dist/src/trails/topo-unpin.d.ts.map +0 -1
  172. package/dist/src/trails/topo-unpin.js +0 -39
  173. package/dist/src/trails/topo-unpin.js.map +0 -1
  174. package/dist/src/trails/topo-verify.d.ts +0 -5
  175. package/dist/src/trails/topo-verify.d.ts.map +0 -1
  176. package/dist/src/trails/topo-verify.js +0 -28
  177. package/dist/src/trails/topo-verify.js.map +0 -1
  178. package/dist/src/trails/topo.d.ts +0 -5
  179. package/dist/src/trails/topo.d.ts.map +0 -1
  180. package/dist/src/trails/topo.js +0 -67
  181. package/dist/src/trails/topo.js.map +0 -1
  182. package/dist/src/trails/warden.d.ts +0 -19
  183. package/dist/src/trails/warden.d.ts.map +0 -1
  184. package/dist/src/trails/warden.js +0 -89
  185. package/dist/src/trails/warden.js.map +0 -1
  186. package/dist/tsconfig.tsbuildinfo +0 -1
  187. package/src/__tests__/create.test.ts +0 -351
  188. package/src/__tests__/draft-promote.test.ts +0 -144
  189. package/src/__tests__/guide.test.ts +0 -91
  190. package/src/__tests__/load-app.test.ts +0 -58
  191. package/src/__tests__/survey.test.ts +0 -301
  192. package/src/__tests__/topo-dev.test.ts +0 -424
  193. package/src/__tests__/warden.test.ts +0 -74
  194. package/src/trails/add-trailhead.ts +0 -121
  195. package/src/trails/topo-export.ts +0 -39
  196. package/src/trails/topo-show.ts +0 -58
  197. package/tsconfig.json +0 -9
@@ -1,39 +1,47 @@
1
1
  import { Result, trail } from '@ontrails/core';
2
2
  import { z } from 'zod';
3
3
 
4
- import { buildDevStats, DEFAULT_TOPO_SAVE_RETENTION } from './dev-support.js';
5
- import { isolatedExampleInput } from './topo-support.js';
4
+ import {
5
+ buildDevStats,
6
+ DEFAULT_TOPO_SNAPSHOT_RETENTION,
7
+ } from './dev-support.js';
8
+ import { resolveTrailRootDir } from './root-dir.js';
9
+ import { createIsolatedExampleInput } from './topo-support.js';
6
10
 
7
11
  export const devStatsTrail = trail('dev.stats', {
8
12
  blaze: (input, ctx) => {
9
- const rootDir = input.rootDir ?? ctx.cwd ?? process.cwd();
13
+ const rootDirResult = resolveTrailRootDir(input.rootDir, ctx.cwd);
14
+ if (rootDirResult.isErr()) {
15
+ return Result.err(rootDirResult.error);
16
+ }
17
+ const rootDir = rootDirResult.value;
10
18
  return Result.ok(
11
19
  buildDevStats({
12
- maxAge: input.trackAgeMs,
13
- maxRecords: input.tracks,
20
+ maxAge: input.traceAgeMs,
21
+ maxRecords: input.traces,
14
22
  rootDir,
15
- saveRetention: input.saves,
23
+ snapshotRetention: input.snapshots,
16
24
  })
17
25
  );
18
26
  },
19
27
  description: 'Show local Trails workspace state and retention',
20
28
  examples: [
21
29
  {
22
- input: { rootDir: isolatedExampleInput('dev-stats').rootDir },
30
+ input: { rootDir: createIsolatedExampleInput('dev-stats').rootDir },
23
31
  name: 'Show local dev state',
24
32
  },
25
33
  ],
26
34
  input: z.object({
27
35
  rootDir: z.string().optional().describe('Workspace root directory'),
28
- saves: z
36
+ snapshots: z
29
37
  .number()
30
- .default(DEFAULT_TOPO_SAVE_RETENTION)
31
- .describe('Unpinned topo saves to retain'),
32
- trackAgeMs: z
38
+ .default(DEFAULT_TOPO_SNAPSHOT_RETENTION)
39
+ .describe('Unpinned topo snapshots to retain'),
40
+ traceAgeMs: z
33
41
  .number()
34
42
  .default(7 * 24 * 60 * 60 * 1000)
35
- .describe('Maximum retained track age in milliseconds'),
36
- tracks: z.number().default(10_000).describe('Maximum retained track count'),
43
+ .describe('Maximum retained trace age in milliseconds'),
44
+ traces: z.number().default(10_000).describe('Maximum retained trace count'),
37
45
  }),
38
46
  intent: 'read',
39
47
  output: z.object({
@@ -48,16 +56,16 @@ export const devStatsTrail = trail('dev.stats', {
48
56
  path: z.string(),
49
57
  }),
50
58
  retention: z.object({
51
- saves: z.number(),
52
- trackAgeMs: z.number(),
53
- tracks: z.number(),
59
+ snapshots: z.number(),
60
+ traceAgeMs: z.number(),
61
+ traces: z.number(),
54
62
  }),
55
63
  topo: z.object({
56
- pinCount: z.number(),
57
- prunableSaveCount: z.number(),
58
- saveCount: z.number(),
64
+ pinnedCount: z.number(),
65
+ prunableSnapshotCount: z.number(),
66
+ snapshotCount: z.number(),
59
67
  }),
60
- tracker: z.object({
68
+ tracing: z.object({
61
69
  recordCount: z.number(),
62
70
  }),
63
71
  }),
@@ -1,38 +1,43 @@
1
- import { existsSync, rmSync, statSync } from 'node:fs';
1
+ import { existsSync, statSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
 
4
- import {
5
- countPrunableTopoSaves,
6
- countTopoPins,
7
- countTopoSaves,
8
- pruneUnpinnedTopoSaves,
9
- } from '@ontrails/core/internal/topo-saves';
10
4
  import {
11
5
  openReadTrailsDb,
12
6
  openWriteTrailsDb,
13
- resolveTrailsDbPath,
14
- resolveTrailsDir,
15
- } from '@ontrails/core/internal/trails-db';
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
16
  import {
17
17
  DEFAULT_MAX_AGE,
18
18
  DEFAULT_MAX_RECORDS,
19
- applyTrackCleanup,
20
- countTrackRecords,
21
- previewTrackCleanup,
22
- } from '@ontrails/tracker/internal/dev-state';
19
+ applyTraceCleanup,
20
+ countTraceRecords,
21
+ previewTraceCleanup,
22
+ } from '@ontrails/tracing';
23
+
24
+ import { removeRootRelativeFileIfPresent } from '../local-state-io.js';
23
25
 
24
- import { resolveLockPath } from './topo-support.js';
26
+ import { requireTrailRootDir } from './root-dir.js';
25
27
 
26
- export const DEFAULT_TOPO_SAVE_RETENTION = 50;
28
+ export const DEFAULT_TOPO_SNAPSHOT_RETENTION = 50;
27
29
 
28
- const resolveRootDir = (cwd?: string): string => cwd ?? process.cwd();
30
+ const deriveRootDir = (cwd?: string): string => requireTrailRootDir(cwd);
29
31
 
30
- const removeIfPresent = (filePath: string): boolean => {
31
- if (!existsSync(filePath)) {
32
- return false;
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;
33
39
  }
34
- rmSync(filePath, { force: true });
35
- return true;
40
+ return removed.value;
36
41
  };
37
42
 
38
43
  export interface DevStatsReport {
@@ -47,16 +52,16 @@ export interface DevStatsReport {
47
52
  readonly path: string;
48
53
  };
49
54
  readonly retention: {
50
- readonly saves: number;
51
- readonly trackAgeMs: number;
52
- readonly tracks: number;
55
+ readonly snapshots: number;
56
+ readonly traceAgeMs: number;
57
+ readonly traces: number;
53
58
  };
54
59
  readonly topo: {
55
- readonly pinCount: number;
56
- readonly prunableSaveCount: number;
57
- readonly saveCount: number;
60
+ readonly pinnedCount: number;
61
+ readonly prunableSnapshotCount: number;
62
+ readonly snapshotCount: number;
58
63
  };
59
- readonly tracker: {
64
+ readonly tracing: {
60
65
  readonly recordCount: number;
61
66
  };
62
67
  }
@@ -64,18 +69,18 @@ export interface DevStatsReport {
64
69
  export interface DevCleanReport {
65
70
  readonly dryRun: boolean;
66
71
  readonly remaining: {
67
- readonly pinCount: number;
68
- readonly saveCount: number;
69
- readonly trackCount: number;
72
+ readonly pinnedCount: number;
73
+ readonly snapshotCount: number;
74
+ readonly traceCount: number;
70
75
  };
71
76
  readonly removed: {
72
- readonly topoSaves: number;
73
- readonly trackRecords: number;
77
+ readonly topoSnapshots: number;
78
+ readonly traceRecords: number;
74
79
  };
75
80
  readonly retention: {
76
- readonly saves: number;
77
- readonly trackAgeMs: number;
78
- readonly tracks: number;
81
+ readonly snapshots: number;
82
+ readonly traceAgeMs: number;
83
+ readonly traces: number;
79
84
  };
80
85
  }
81
86
 
@@ -89,7 +94,7 @@ interface DevRetentionOptions {
89
94
  readonly maxAge?: number;
90
95
  readonly maxRecords?: number;
91
96
  readonly rootDir?: string;
92
- readonly saveRetention?: number;
97
+ readonly snapshotRetention?: number;
93
98
  }
94
99
 
95
100
  interface DevCleanupContext {
@@ -100,9 +105,9 @@ interface DevCleanupContext {
100
105
  }
101
106
 
102
107
  const buildRetention = (options?: DevRetentionOptions) => ({
103
- saves: options?.saveRetention ?? DEFAULT_TOPO_SAVE_RETENTION,
104
- trackAgeMs: options?.maxAge ?? DEFAULT_MAX_AGE,
105
- tracks: options?.maxRecords ?? DEFAULT_MAX_RECORDS,
108
+ snapshots: options?.snapshotRetention ?? DEFAULT_TOPO_SNAPSHOT_RETENTION,
109
+ traceAgeMs: options?.maxAge ?? DEFAULT_MAX_AGE,
110
+ traces: options?.maxRecords ?? DEFAULT_MAX_RECORDS,
106
111
  });
107
112
 
108
113
  const emptyDevClean = (
@@ -111,13 +116,13 @@ const emptyDevClean = (
111
116
  ): DevCleanReport => ({
112
117
  dryRun,
113
118
  remaining: {
114
- pinCount: 0,
115
- saveCount: 0,
116
- trackCount: 0,
119
+ pinnedCount: 0,
120
+ snapshotCount: 0,
121
+ traceCount: 0,
117
122
  },
118
123
  removed: {
119
- topoSaves: 0,
120
- trackRecords: 0,
124
+ topoSnapshots: 0,
125
+ traceRecords: 0,
121
126
  },
122
127
  retention,
123
128
  });
@@ -134,7 +139,7 @@ const buildDbStats = (
134
139
  ): DevStatsReport['db'] => ({
135
140
  exists,
136
141
  fileSizeBytes: exists ? statSync(dbPath).size : 0,
137
- path: '.trails/trails.db',
142
+ path: '.trails/state/trails.db',
138
143
  });
139
144
 
140
145
  const emptyDevStats = (
@@ -146,17 +151,17 @@ const emptyDevStats = (
146
151
  lock: buildLockStats(lockPath),
147
152
  retention,
148
153
  topo: {
149
- pinCount: 0,
150
- prunableSaveCount: 0,
151
- saveCount: 0,
154
+ pinnedCount: 0,
155
+ prunableSnapshotCount: 0,
156
+ snapshotCount: 0,
152
157
  },
153
- tracker: {
158
+ tracing: {
154
159
  recordCount: 0,
155
160
  },
156
161
  });
157
162
 
158
163
  const liveDevStats = (
159
- db: Parameters<typeof countTopoPins>[0],
164
+ db: Parameters<typeof countPinnedSnapshots>[0],
160
165
  dbPath: string,
161
166
  lockPath: string,
162
167
  retention: DevStatsReport['retention']
@@ -165,20 +170,22 @@ const liveDevStats = (
165
170
  lock: buildLockStats(lockPath),
166
171
  retention,
167
172
  topo: {
168
- pinCount: countTopoPins(db),
169
- prunableSaveCount: countPrunableTopoSaves(db, { keep: retention.saves }),
170
- saveCount: countTopoSaves(db),
173
+ pinnedCount: countPinnedSnapshots(db),
174
+ prunableSnapshotCount: countPrunableSnapshots(db, {
175
+ keep: retention.snapshots,
176
+ }),
177
+ snapshotCount: countTopoSnapshots(db),
171
178
  },
172
- tracker: {
173
- recordCount: countTrackRecords(db),
179
+ tracing: {
180
+ recordCount: countTraceRecords(db),
174
181
  },
175
182
  });
176
183
 
177
- const resolveDevStatsContext = (options?: DevRetentionOptions) => {
178
- const rootDir = resolveRootDir(options?.rootDir);
179
- const dbPath = resolveTrailsDbPath({ rootDir });
180
- const trailsDir = resolveTrailsDir({ rootDir });
181
- const lockPath = resolveLockPath(trailsDir);
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');
182
189
  return {
183
190
  dbExists: existsSync(dbPath),
184
191
  dbPath,
@@ -188,72 +195,79 @@ const resolveDevStatsContext = (options?: DevRetentionOptions) => {
188
195
  };
189
196
  };
190
197
 
191
- const resolveDevCleanupContext = (
198
+ const deriveDevCleanupContext = (
192
199
  options?: DevRetentionOptions & { readonly dryRun?: boolean }
193
200
  ): DevCleanupContext => {
194
- const rootDir = resolveRootDir(options?.rootDir);
201
+ const rootDir = deriveRootDir(options?.rootDir);
195
202
  return {
196
- dbPath: resolveTrailsDbPath({ rootDir }),
203
+ dbPath: deriveTrailsDbPath({ rootDir }),
197
204
  dryRun: options?.dryRun ?? false,
198
205
  retention: buildRetention(options),
199
206
  rootDir,
200
207
  };
201
208
  };
202
209
 
203
- const cleanupTracks = (
204
- db: Parameters<typeof countTopoPins>[0],
210
+ const cleanupTraces = (
211
+ db: Parameters<typeof countPinnedSnapshots>[0],
205
212
  context: DevCleanupContext
206
213
  ) =>
207
214
  context.dryRun
208
- ? previewTrackCleanup(db, {
209
- maxAge: context.retention.trackAgeMs,
210
- maxRecords: context.retention.tracks,
215
+ ? previewTraceCleanup(db, {
216
+ maxAge: context.retention.traceAgeMs,
217
+ maxRecords: context.retention.traces,
211
218
  })
212
- : applyTrackCleanup(db, {
213
- maxAge: context.retention.trackAgeMs,
214
- maxRecords: context.retention.tracks,
219
+ : applyTraceCleanup(db, {
220
+ maxAge: context.retention.traceAgeMs,
221
+ maxRecords: context.retention.traces,
215
222
  });
216
223
 
217
- const cleanupTopoSaves = (
218
- db: Parameters<typeof countTopoPins>[0],
224
+ const cleanupTopoSnapshots = (
225
+ db: Parameters<typeof countPinnedSnapshots>[0],
219
226
  context: DevCleanupContext
220
227
  ): number =>
221
228
  context.dryRun
222
- ? countPrunableTopoSaves(db, { keep: context.retention.saves })
223
- : pruneUnpinnedTopoSaves(db, { keep: context.retention.saves });
229
+ ? countPrunableSnapshots(db, { keep: context.retention.snapshots })
230
+ : pruneUnpinnedSnapshots(db, { keep: context.retention.snapshots });
224
231
 
225
232
  const buildCleanReport = (
226
- db: Parameters<typeof countTopoPins>[0],
233
+ db: Parameters<typeof countPinnedSnapshots>[0],
227
234
  context: DevCleanupContext
228
235
  ): DevCleanReport => {
229
- const trackReport = cleanupTracks(db, context);
230
- const topoRemoved = cleanupTopoSaves(db, context);
231
- const saveCount = countTopoSaves(db);
236
+ const traceReport = cleanupTraces(db, context);
237
+ const topoRemoved = cleanupTopoSnapshots(db, context);
238
+ const snapshotCount = countTopoSnapshots(db);
232
239
 
233
240
  return {
234
241
  dryRun: context.dryRun,
235
242
  remaining: {
236
- pinCount: countTopoPins(db),
237
- saveCount: context.dryRun ? saveCount - topoRemoved : saveCount,
238
- trackCount: context.dryRun
239
- ? trackReport.remaining - trackReport.removedTotal
240
- : trackReport.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,
241
250
  },
242
251
  removed: {
243
- topoSaves: topoRemoved,
244
- trackRecords: trackReport.removedTotal,
252
+ topoSnapshots: topoRemoved,
253
+ traceRecords: traceReport.removedTotal,
245
254
  },
246
255
  retention: context.retention,
247
256
  };
248
257
  };
249
258
 
250
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.
251
265
  '.trails/trails.db',
252
266
  '.trails/trails.db-shm',
253
267
  '.trails/trails.db-wal',
254
- '.trails/dev/tracker.db',
255
- '.trails/dev/tracker.db-shm',
256
- '.trails/dev/tracker.db-wal',
268
+ '.trails/dev/tracing.db',
269
+ '.trails/dev/tracing.db-shm',
270
+ '.trails/dev/tracing.db-wal',
257
271
  ] as const;
258
272
 
259
273
  const presentResetFiles = (
@@ -265,7 +279,7 @@ export const buildDevStats = (
265
279
  options?: DevRetentionOptions
266
280
  ): DevStatsReport => {
267
281
  const { dbExists, dbPath, lockPath, retention, rootDir } =
268
- resolveDevStatsContext(options);
282
+ deriveDevStatsContext(options);
269
283
 
270
284
  if (!dbExists) {
271
285
  return emptyDevStats(dbPath, lockPath, retention);
@@ -283,7 +297,7 @@ export const buildDevStats = (
283
297
  export const cleanDevState = (
284
298
  options?: DevRetentionOptions & { readonly dryRun?: boolean }
285
299
  ): DevCleanReport => {
286
- const context = resolveDevCleanupContext(options);
300
+ const context = deriveDevCleanupContext(options);
287
301
  if (!existsSync(context.dbPath)) {
288
302
  return emptyDevClean(context.retention, context.dryRun);
289
303
  }
@@ -303,7 +317,7 @@ export const resetDevState = (options?: {
303
317
  readonly dryRun?: boolean;
304
318
  readonly rootDir?: string;
305
319
  }): DevResetReport => {
306
- const rootDir = resolveRootDir(options?.rootDir);
320
+ const rootDir = deriveRootDir(options?.rootDir);
307
321
  const files = presentResetFiles(rootDir);
308
322
 
309
323
  if (options?.dryRun === true) {
@@ -315,7 +329,7 @@ export const resetDevState = (options?: {
315
329
  }
316
330
 
317
331
  const removedFiles = files.filter((relativePath) =>
318
- removeIfPresent(join(rootDir, relativePath))
332
+ removeResetFileIfPresent(rootDir, relativePath)
319
333
  );
320
334
 
321
335
  return {