@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 +0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AE,GAAG,EAAE,GAAG,IAAI,CAAC;aAChC,QAAQ,CAAC,4CAA4C,CAAC;QACzD,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,8BAA8B,CAAC;KAC5E,CAAC;IACF,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC;YACX,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;YACnB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;YACzB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;SACjB,CAAC;QACF,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;YACb,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;YACnB,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;YACzB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;SACjB,CAAC;QACF,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC;YAClB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;YACjB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;YACtB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;SACnB,CAAC;QACF,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;YACb,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE;YAC7B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;SACtB,CAAC;QACF,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;YAChB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;SACxB,CAAC;KACH,CAAC;CACH,CAAC,CAAC"}
@@ -1,64 +0,0 @@
1
- export declare const DEFAULT_TOPO_SAVE_RETENTION = 50;
2
- export interface DevStatsReport {
3
- readonly db: {
4
- readonly exists: boolean;
5
- readonly fileSizeBytes: number;
6
- readonly path: string;
7
- };
8
- readonly lock: {
9
- readonly exists: boolean;
10
- readonly fileSizeBytes: number;
11
- readonly path: string;
12
- };
13
- readonly retention: {
14
- readonly saves: number;
15
- readonly trackAgeMs: number;
16
- readonly tracks: number;
17
- };
18
- readonly topo: {
19
- readonly pinCount: number;
20
- readonly prunableSaveCount: number;
21
- readonly saveCount: number;
22
- };
23
- readonly tracker: {
24
- readonly recordCount: number;
25
- };
26
- }
27
- export interface DevCleanReport {
28
- readonly dryRun: boolean;
29
- readonly remaining: {
30
- readonly pinCount: number;
31
- readonly saveCount: number;
32
- readonly trackCount: number;
33
- };
34
- readonly removed: {
35
- readonly topoSaves: number;
36
- readonly trackRecords: number;
37
- };
38
- readonly retention: {
39
- readonly saves: number;
40
- readonly trackAgeMs: number;
41
- readonly tracks: number;
42
- };
43
- }
44
- export interface DevResetReport {
45
- readonly dryRun: boolean;
46
- readonly removedCount: number;
47
- readonly removedFiles: readonly string[];
48
- }
49
- interface DevRetentionOptions {
50
- readonly maxAge?: number;
51
- readonly maxRecords?: number;
52
- readonly rootDir?: string;
53
- readonly saveRetention?: number;
54
- }
55
- export declare const buildDevStats: (options?: DevRetentionOptions) => DevStatsReport;
56
- export declare const cleanDevState: (options?: DevRetentionOptions & {
57
- readonly dryRun?: boolean;
58
- }) => DevCleanReport;
59
- export declare const resetDevState: (options?: {
60
- readonly dryRun?: boolean;
61
- readonly rootDir?: string;
62
- }) => DevResetReport;
63
- export {};
64
- //# sourceMappingURL=dev-support.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dev-support.d.ts","sourceRoot":"","sources":["../../../src/trails/dev-support.ts"],"names":[],"mappings":"AAyBA,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAY9C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE;QACX,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;QACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAC/B,QAAQ,CAAC,IAAI,E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,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAED,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AA2KD,eAAO,MAAM,aAAa,GACxB,UAAU,mBAAmB,KAC5B,cAeF,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,UAAU,mBAAmB,GAAG;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,KAC5D,cAeF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,UAAU;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG,cAqBH,CAAC"}
@@ -1,178 +0,0 @@
1
- import { existsSync, rmSync, statSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { countPrunableTopoSaves, countTopoPins, countTopoSaves, pruneUnpinnedTopoSaves, } from '@ontrails/core/internal/topo-saves';
4
- import { openReadTrailsDb, openWriteTrailsDb, resolveTrailsDbPath, resolveTrailsDir, } from '@ontrails/core/internal/trails-db';
5
- import { DEFAULT_MAX_AGE, DEFAULT_MAX_RECORDS, applyTrackCleanup, countTrackRecords, previewTrackCleanup, } from '@ontrails/tracker/internal/dev-state';
6
- import { resolveLockPath } from './topo-support.js';
7
- export const DEFAULT_TOPO_SAVE_RETENTION = 50;
8
- const resolveRootDir = (cwd) => cwd ?? process.cwd();
9
- const removeIfPresent = (filePath) => {
10
- if (!existsSync(filePath)) {
11
- return false;
12
- }
13
- rmSync(filePath, { force: true });
14
- return true;
15
- };
16
- const buildRetention = (options) => ({
17
- saves: options?.saveRetention ?? DEFAULT_TOPO_SAVE_RETENTION,
18
- trackAgeMs: options?.maxAge ?? DEFAULT_MAX_AGE,
19
- tracks: options?.maxRecords ?? DEFAULT_MAX_RECORDS,
20
- });
21
- const emptyDevClean = (retention, dryRun) => ({
22
- dryRun,
23
- remaining: {
24
- pinCount: 0,
25
- saveCount: 0,
26
- trackCount: 0,
27
- },
28
- removed: {
29
- topoSaves: 0,
30
- trackRecords: 0,
31
- },
32
- retention,
33
- });
34
- const buildLockStats = (lockPath) => ({
35
- exists: existsSync(lockPath),
36
- fileSizeBytes: existsSync(lockPath) ? statSync(lockPath).size : 0,
37
- path: lockPath,
38
- });
39
- const buildDbStats = (dbPath, exists) => ({
40
- exists,
41
- fileSizeBytes: exists ? statSync(dbPath).size : 0,
42
- path: '.trails/trails.db',
43
- });
44
- const emptyDevStats = (dbPath, lockPath, retention) => ({
45
- db: buildDbStats(dbPath, false),
46
- lock: buildLockStats(lockPath),
47
- retention,
48
- topo: {
49
- pinCount: 0,
50
- prunableSaveCount: 0,
51
- saveCount: 0,
52
- },
53
- tracker: {
54
- recordCount: 0,
55
- },
56
- });
57
- const liveDevStats = (db, dbPath, lockPath, retention) => ({
58
- db: buildDbStats(dbPath, true),
59
- lock: buildLockStats(lockPath),
60
- retention,
61
- topo: {
62
- pinCount: countTopoPins(db),
63
- prunableSaveCount: countPrunableTopoSaves(db, { keep: retention.saves }),
64
- saveCount: countTopoSaves(db),
65
- },
66
- tracker: {
67
- recordCount: countTrackRecords(db),
68
- },
69
- });
70
- const resolveDevStatsContext = (options) => {
71
- const rootDir = resolveRootDir(options?.rootDir);
72
- const dbPath = resolveTrailsDbPath({ rootDir });
73
- const trailsDir = resolveTrailsDir({ rootDir });
74
- const lockPath = resolveLockPath(trailsDir);
75
- return {
76
- dbExists: existsSync(dbPath),
77
- dbPath,
78
- lockPath,
79
- retention: buildRetention(options),
80
- rootDir,
81
- };
82
- };
83
- const resolveDevCleanupContext = (options) => {
84
- const rootDir = resolveRootDir(options?.rootDir);
85
- return {
86
- dbPath: resolveTrailsDbPath({ rootDir }),
87
- dryRun: options?.dryRun ?? false,
88
- retention: buildRetention(options),
89
- rootDir,
90
- };
91
- };
92
- const cleanupTracks = (db, context) => context.dryRun
93
- ? previewTrackCleanup(db, {
94
- maxAge: context.retention.trackAgeMs,
95
- maxRecords: context.retention.tracks,
96
- })
97
- : applyTrackCleanup(db, {
98
- maxAge: context.retention.trackAgeMs,
99
- maxRecords: context.retention.tracks,
100
- });
101
- const cleanupTopoSaves = (db, context) => context.dryRun
102
- ? countPrunableTopoSaves(db, { keep: context.retention.saves })
103
- : pruneUnpinnedTopoSaves(db, { keep: context.retention.saves });
104
- const buildCleanReport = (db, context) => {
105
- const trackReport = cleanupTracks(db, context);
106
- const topoRemoved = cleanupTopoSaves(db, context);
107
- const saveCount = countTopoSaves(db);
108
- return {
109
- dryRun: context.dryRun,
110
- remaining: {
111
- pinCount: countTopoPins(db),
112
- saveCount: context.dryRun ? saveCount - topoRemoved : saveCount,
113
- trackCount: context.dryRun
114
- ? trackReport.remaining - trackReport.removedTotal
115
- : trackReport.remaining,
116
- },
117
- removed: {
118
- topoSaves: topoRemoved,
119
- trackRecords: trackReport.removedTotal,
120
- },
121
- retention: context.retention,
122
- };
123
- };
124
- const RESET_FILES = [
125
- '.trails/trails.db',
126
- '.trails/trails.db-shm',
127
- '.trails/trails.db-wal',
128
- '.trails/dev/tracker.db',
129
- '.trails/dev/tracker.db-shm',
130
- '.trails/dev/tracker.db-wal',
131
- ];
132
- const presentResetFiles = (rootDir) => RESET_FILES.filter((relativePath) => existsSync(join(rootDir, relativePath)));
133
- export const buildDevStats = (options) => {
134
- const { dbExists, dbPath, lockPath, retention, rootDir } = resolveDevStatsContext(options);
135
- if (!dbExists) {
136
- return emptyDevStats(dbPath, lockPath, retention);
137
- }
138
- const db = openReadTrailsDb({ rootDir });
139
- try {
140
- return liveDevStats(db, dbPath, lockPath, retention);
141
- }
142
- finally {
143
- db.close();
144
- }
145
- };
146
- export const cleanDevState = (options) => {
147
- const context = resolveDevCleanupContext(options);
148
- if (!existsSync(context.dbPath)) {
149
- return emptyDevClean(context.retention, context.dryRun);
150
- }
151
- const db = context.dryRun
152
- ? openReadTrailsDb({ rootDir: context.rootDir })
153
- : openWriteTrailsDb({ rootDir: context.rootDir });
154
- try {
155
- return buildCleanReport(db, context);
156
- }
157
- finally {
158
- db.close();
159
- }
160
- };
161
- export const resetDevState = (options) => {
162
- const rootDir = resolveRootDir(options?.rootDir);
163
- const files = presentResetFiles(rootDir);
164
- if (options?.dryRun === true) {
165
- return {
166
- dryRun: true,
167
- removedCount: files.length,
168
- removedFiles: files,
169
- };
170
- }
171
- const removedFiles = files.filter((relativePath) => removeIfPresent(join(rootDir, relativePath)));
172
- return {
173
- dryRun: false,
174
- removedCount: removedFiles.length,
175
- removedFiles,
176
- };
177
- };
178
- //# sourceMappingURL=dev-support.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dev-support.js","sourceRoot":"","sources":["../../../src/trails/dev-support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,cAAc,EACd,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,CAAC;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OAAO,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC;QAC7B,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,YAAY,EAAE,KAAK,CAAC,MAAM;YAC1B,YAAY,EAAE,KAAK;SACpB,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CACjD,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAC7C,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,KAAK;QACb,YAAY,EAAE,YAAY,CAAC,MAAM;QACjC,YAAY;KACb,CAAC;AACJ,CAAC,CAAC"}
@@ -1,18 +0,0 @@
1
- export declare const draftPromoteTrail: import("@ontrails/core").Trail<{
2
- fromId: string;
3
- renameFiles: boolean;
4
- toId: string;
5
- appModule?: string | undefined;
6
- rootDir?: string | undefined;
7
- }, {
8
- appModule: string | null;
9
- message: string;
10
- promotedEstablished: boolean;
11
- remainingDraftIds: string[];
12
- renamedFiles: {
13
- from: string;
14
- to: string;
15
- }[];
16
- updatedFiles: string[];
17
- }>;
18
- //# sourceMappingURL=draft-promote.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"draft-promote.d.ts","sourceRoot":"","sources":["../../../src/trails/draft-promote.ts"],"names":[],"mappings":"AAkpBA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;EA6C5B,CAAC"}
@@ -1,386 +0,0 @@
1
- import { existsSync, renameSync, statSync } from 'node:fs';
2
- import { basename, dirname, join, relative } from 'node:path';
3
- import { Result, ValidationError, analyzeDraftState, isDraftId, trail, } from '@ontrails/core';
4
- import { DRAFT_FILE_PREFIX, findStringLiterals, isDraftMarkedFile, parse, stripDraftFileMarkers, } from '@ontrails/warden';
5
- import { z } from 'zod';
6
- import { loadApp } from './load-app.js';
7
- import { findTopoPath } from './project.js';
8
- const isManagedSourceFile = (match) => !match.endsWith('.d.ts') &&
9
- !match.startsWith('node_modules/') &&
10
- !match.startsWith('dist/') &&
11
- !match.startsWith('.git/');
12
- const collectTsFiles = (rootDir) => {
13
- const files = [];
14
- for (const match of new Bun.Glob('**/*.ts').scanSync({
15
- cwd: rootDir,
16
- dot: false,
17
- onlyFiles: true,
18
- })) {
19
- if (isManagedSourceFile(match)) {
20
- files.push(join(rootDir, match));
21
- }
22
- }
23
- return files.toSorted();
24
- };
25
- const applyEdits = (sourceCode, edits) => {
26
- let updated = sourceCode;
27
- for (const edit of [...edits].toSorted((a, b) => b.start - a.start)) {
28
- updated =
29
- updated.slice(0, edit.start) + edit.replacement + updated.slice(edit.end);
30
- }
31
- return updated;
32
- };
33
- const literalQuote = (raw) => {
34
- const [first] = raw;
35
- return first === '"' || first === '`' ? first : "'";
36
- };
37
- const replaceQuotedLiteral = (sourceCode, start, end, nextValue) => {
38
- const quote = literalQuote(sourceCode.slice(start, end));
39
- return `${quote}${nextValue}${quote}`;
40
- };
41
- const replaceIdLiterals = (sourceCode, filePath, fromId, toId) => {
42
- const ast = parse(filePath, sourceCode);
43
- if (!ast) {
44
- return { changed: false, nextSource: sourceCode };
45
- }
46
- const edits = findStringLiterals(ast, (value) => value === fromId).map((match) => ({
47
- end: match.end,
48
- replacement: replaceQuotedLiteral(sourceCode, match.start, match.end, toId),
49
- start: match.start,
50
- }));
51
- if (edits.length === 0) {
52
- return { changed: false, nextSource: sourceCode };
53
- }
54
- return {
55
- changed: true,
56
- nextSource: applyEdits(sourceCode, edits),
57
- };
58
- };
59
- const hasDraftIds = (sourceCode, filePath) => {
60
- const ast = parse(filePath, sourceCode);
61
- if (!ast) {
62
- return sourceCode.includes(DRAFT_FILE_PREFIX);
63
- }
64
- return findStringLiterals(ast, (value) => isDraftId(value)).length > 0;
65
- };
66
- const toJsPath = (filePath) => filePath.replace(/\.ts$/, '.js');
67
- const toRelativeModulePath = (fromFile, toFile) => {
68
- const rel = relative(dirname(fromFile), toJsPath(toFile)).replaceAll('\\', '/');
69
- return rel.startsWith('.') ? rel : `./${rel}`;
70
- };
71
- const replaceLiteralValue = (sourceCode, filePath, currentValue, nextValue) => {
72
- const ast = parse(filePath, sourceCode);
73
- if (!ast) {
74
- return { changed: false, nextSource: sourceCode };
75
- }
76
- const edits = findStringLiterals(ast, (value) => value === currentValue).map((match) => ({
77
- end: match.end,
78
- replacement: replaceQuotedLiteral(sourceCode, match.start, match.end, nextValue),
79
- start: match.start,
80
- }));
81
- if (edits.length === 0) {
82
- return { changed: false, nextSource: sourceCode };
83
- }
84
- return {
85
- changed: true,
86
- nextSource: applyEdits(sourceCode, edits),
87
- };
88
- };
89
- const collectOutputId = (app, id) => app.get(id) ?? app.signals.get(id) ?? app.getProvision(id);
90
- const toRelativeOutputPath = (rootDir, filePath) => relative(rootDir, filePath).replaceAll('\\', '/');
91
- const toProjectModulePath = (sourceImport) => sourceImport.startsWith('./')
92
- ? `./src/${sourceImport.slice(2)}`
93
- : sourceImport;
94
- const validatePromotionInput = (input) => {
95
- if (!isDraftId(input.fromId)) {
96
- return Result.err(new ValidationError(`fromId must use the reserved draft prefix: "${input.fromId}"`));
97
- }
98
- if (isDraftId(input.toId)) {
99
- return Result.err(new ValidationError(`toId must be established, not draft: "${input.toId}"`));
100
- }
101
- return Result.ok();
102
- };
103
- const validatePromotionRoot = (rootDir) => {
104
- if (!existsSync(rootDir)) {
105
- return Result.err(new ValidationError(`rootDir does not exist: "${rootDir}"`));
106
- }
107
- if (!statSync(rootDir).isDirectory()) {
108
- return Result.err(new ValidationError(`rootDir must be a directory: "${rootDir}"`));
109
- }
110
- return Result.ok();
111
- };
112
- const resolveValidatedPromotionRoot = (input, ctx) => {
113
- const validation = validatePromotionInput(input);
114
- if (validation.isErr()) {
115
- return validation;
116
- }
117
- const rootDir = input.rootDir ?? ctx.cwd ?? process.cwd();
118
- const rootValidation = validatePromotionRoot(rootDir);
119
- if (rootValidation.isErr()) {
120
- return rootValidation;
121
- }
122
- return Result.ok(rootDir);
123
- };
124
- const rewritePromotedSourceFiles = async (filePaths, fromId, toId, updatedSourceFiles) => {
125
- for (const filePath of filePaths) {
126
- const sourceCode = await Bun.file(filePath).text();
127
- const replaced = replaceIdLiterals(sourceCode, filePath, fromId, toId);
128
- if (!replaced.changed) {
129
- continue;
130
- }
131
- await Bun.write(filePath, replaced.nextSource);
132
- updatedSourceFiles.add(filePath);
133
- }
134
- };
135
- const hasDraftIdsInFile = async (filePath) => {
136
- const sourceCode = await Bun.file(filePath).text();
137
- return hasDraftIds(sourceCode, filePath);
138
- };
139
- const buildPromotableFileRename = (filePath, fileName) => {
140
- const nextFileName = stripDraftFileMarkers(fileName);
141
- if (nextFileName === fileName) {
142
- return Result.ok(null);
143
- }
144
- const nextPath = join(dirname(filePath), nextFileName);
145
- if (nextPath !== filePath && existsSync(nextPath)) {
146
- return Result.err(new ValidationError(`Cannot promote draft file "${filePath}" because "${nextPath}" already exists.`));
147
- }
148
- return Result.ok({ from: filePath, to: nextPath });
149
- };
150
- const collectPromotableFileRename = async (filePath) => {
151
- if (!isDraftMarkedFile(filePath)) {
152
- return Result.ok(null);
153
- }
154
- const fileName = basename(filePath);
155
- if (!fileName) {
156
- return Result.ok(null);
157
- }
158
- if (await hasDraftIdsInFile(filePath)) {
159
- return Result.ok(null);
160
- }
161
- return buildPromotableFileRename(filePath, fileName);
162
- };
163
- /** Validate that no two renames target the same path and no target already exists. */
164
- const validateRenameTargets = (renames) => {
165
- const targets = new Set();
166
- for (const r of renames) {
167
- if (targets.has(r.to)) {
168
- return Result.err(new ValidationError(`Duplicate rename target "${r.to}" — multiple draft files would be renamed to the same path`));
169
- }
170
- if (existsSync(r.to)) {
171
- return Result.err(new ValidationError(`Rename target "${r.to}" already exists — cannot overwrite`));
172
- }
173
- targets.add(r.to);
174
- }
175
- return Result.ok();
176
- };
177
- const collectFileRenames = async (filePaths) => {
178
- const renames = [];
179
- for (const filePath of filePaths) {
180
- const renameResult = await collectPromotableFileRename(filePath);
181
- if (renameResult.isErr()) {
182
- return renameResult;
183
- }
184
- if (renameResult.value !== null) {
185
- renames.push(renameResult.value);
186
- }
187
- }
188
- return Result.ok(renames);
189
- };
190
- const collectAndApplyFileRenames = async (filePaths) => {
191
- const collected = await collectFileRenames(filePaths);
192
- if (collected.isErr()) {
193
- return collected;
194
- }
195
- const renames = collected.value;
196
- const valid = validateRenameTargets(renames);
197
- if (valid.isErr()) {
198
- return valid;
199
- }
200
- for (const r of renames) {
201
- renameSync(r.from, r.to);
202
- }
203
- return Result.ok(renames);
204
- };
205
- const applyRenameEffects = (updatedSourceFiles, renames) => {
206
- for (const rename of renames) {
207
- if (updatedSourceFiles.delete(rename.from)) {
208
- updatedSourceFiles.add(rename.to);
209
- }
210
- }
211
- };
212
- const applyRelativeImportRename = (sourceCode, filePath, rename) => {
213
- const currentValue = toRelativeModulePath(filePath, rename.from);
214
- const nextValue = toRelativeModulePath(filePath, rename.to);
215
- if (currentValue === nextValue) {
216
- return { changed: false, sourceCode };
217
- }
218
- const replaced = replaceLiteralValue(sourceCode, filePath, currentValue, nextValue);
219
- if (!replaced.changed) {
220
- return { changed: false, sourceCode };
221
- }
222
- return { changed: true, sourceCode: replaced.nextSource };
223
- };
224
- const rewriteRelativeImportsForFile = (filePath, renames, sourceCode) => {
225
- let nextSourceCode = sourceCode;
226
- let changed = false;
227
- for (const rename of renames) {
228
- const updated = applyRelativeImportRename(nextSourceCode, filePath, rename);
229
- if (!updated.changed) {
230
- continue;
231
- }
232
- nextSourceCode = updated.sourceCode;
233
- changed = true;
234
- }
235
- return { changed, sourceCode: nextSourceCode };
236
- };
237
- const updateRelativeImportsForFile = async (filePath, renames) => {
238
- const sourceCode = await Bun.file(filePath).text();
239
- const updated = rewriteRelativeImportsForFile(filePath, renames, sourceCode);
240
- if (updated.changed) {
241
- await Bun.write(filePath, updated.sourceCode);
242
- return true;
243
- }
244
- return false;
245
- };
246
- const updateRelativeImports = async (filePaths, renames) => {
247
- const updatedFiles = new Set();
248
- for (const filePath of filePaths) {
249
- const changed = await updateRelativeImportsForFile(filePath, renames);
250
- if (changed) {
251
- updatedFiles.add(filePath);
252
- }
253
- }
254
- return [...updatedFiles].toSorted();
255
- };
256
- const rewritePromotionState = async (rootDir, input) => {
257
- const initialFiles = collectTsFiles(rootDir);
258
- const updatedSourceFiles = new Set();
259
- await rewritePromotedSourceFiles(initialFiles, input.fromId, input.toId, updatedSourceFiles);
260
- const renamesResult = input.renameFiles
261
- ? await collectAndApplyFileRenames(initialFiles)
262
- : Result.ok([]);
263
- if (renamesResult.isErr()) {
264
- return Result.err(renamesResult.error);
265
- }
266
- applyRenameEffects(updatedSourceFiles, renamesResult.value);
267
- for (const f of await updateRelativeImports(collectTsFiles(rootDir), renamesResult.value)) {
268
- updatedSourceFiles.add(f);
269
- }
270
- return Result.ok({ renames: renamesResult.value, updatedSourceFiles });
271
- };
272
- const resolvePromotionAppModule = async (input, rootDir) => {
273
- const discoveredAppModule = await findTopoPath(rootDir);
274
- return (input.appModule ??
275
- (discoveredAppModule === null
276
- ? null
277
- : toProjectModulePath(discoveredAppModule)));
278
- };
279
- const loadVerifiedApp = async (appModule, rootDir) => {
280
- if (appModule === null) {
281
- return { appModule, loadError: null, loadedApp: undefined };
282
- }
283
- let loadError = null;
284
- const loadedApp = await loadApp(appModule, rootDir, { fresh: true }).catch((error) => {
285
- loadError = error instanceof Error ? error.message : String(error);
286
- return undefined;
287
- });
288
- return { appModule, loadError, loadedApp };
289
- };
290
- const toRenamedFiles = (rootDir, renames) => renames.map((rename) => ({
291
- from: toRelativeOutputPath(rootDir, rename.from),
292
- to: toRelativeOutputPath(rootDir, rename.to),
293
- }));
294
- const toUpdatedFiles = (rootDir, updatedSourceFiles) => [...updatedSourceFiles]
295
- .toSorted()
296
- .map((filePath) => toRelativeOutputPath(rootDir, filePath));
297
- const buildUnverifiedPromotionResult = (rootDir, loadError, renames, updatedSourceFiles, appModule) => Result.ok({
298
- appModule,
299
- message: loadError === null
300
- ? 'Promotion rewrote source files, but no topo entrypoint could be loaded for verification.'
301
- : `Promotion rewrote source files, but verification failed: ${loadError}`,
302
- promotedEstablished: false,
303
- remainingDraftIds: [],
304
- renamedFiles: toRenamedFiles(rootDir, renames),
305
- updatedFiles: toUpdatedFiles(rootDir, updatedSourceFiles),
306
- });
307
- const buildVerifiedPromotionResult = (rootDir, analysis, promotedEstablished, renames, updatedSourceFiles, appModule, toId) => {
308
- const blockingFinding = analysis.findings.find((finding) => finding.id === toId);
309
- return Result.ok({
310
- appModule,
311
- message: blockingFinding?.message ??
312
- (promotedEstablished
313
- ? `Promoted "${toId}" is now established.`
314
- : `Promoted "${toId}" could not be verified as established.`),
315
- promotedEstablished,
316
- remainingDraftIds: [...analysis.declaredDraftIds].toSorted(),
317
- renamedFiles: toRenamedFiles(rootDir, renames),
318
- updatedFiles: toUpdatedFiles(rootDir, updatedSourceFiles),
319
- });
320
- };
321
- const buildVerifiedPromotionResultFromApp = (rootDir, loadedApp, renames, updatedSourceFiles, appModule, toId) => {
322
- const analysis = analyzeDraftState(loadedApp);
323
- const promotedNode = collectOutputId(loadedApp, toId);
324
- const promotedEstablished = promotedNode !== undefined && !analysis.contaminatedIds.has(toId);
325
- return buildVerifiedPromotionResult(rootDir, analysis, promotedEstablished, renames, updatedSourceFiles, appModule, toId);
326
- };
327
- const promoteDraftState = async (input, ctx) => {
328
- const rootDirResult = resolveValidatedPromotionRoot(input, ctx);
329
- if (rootDirResult.isErr()) {
330
- return rootDirResult;
331
- }
332
- const rewriteResult = await rewritePromotionState(rootDirResult.value, input);
333
- if (rewriteResult.isErr()) {
334
- return Result.err(rewriteResult.error);
335
- }
336
- const { renames, updatedSourceFiles } = rewriteResult.value;
337
- const appModule = await resolvePromotionAppModule(input, rootDirResult.value);
338
- const { loadError, loadedApp } = await loadVerifiedApp(appModule, rootDirResult.value);
339
- return loadedApp
340
- ? buildVerifiedPromotionResultFromApp(rootDirResult.value, loadedApp, renames, updatedSourceFiles, appModule, input.toId)
341
- : buildUnverifiedPromotionResult(rootDirResult.value, loadError, renames, updatedSourceFiles, appModule);
342
- };
343
- export const draftPromoteTrail = trail('draft.promote', {
344
- blaze: promoteDraftState,
345
- description: 'Promote a draft id to an established id, rewrite inbound references, and verify the result against a fresh topo load.',
346
- examples: [
347
- {
348
- error: 'ValidationError',
349
- input: {
350
- fromId: '_draft.entity.prepare',
351
- renameFiles: true,
352
- rootDir: './__does_not_exist__/draft-promote-example',
353
- toId: 'entity.prepare',
354
- },
355
- name: 'Rejects a missing project root before any rewrite begins',
356
- },
357
- ],
358
- input: z.object({
359
- appModule: z
360
- .string()
361
- .optional()
362
- .describe('Optional app module to verify after promotion'),
363
- fromId: z.string().describe('Draft id to promote'),
364
- renameFiles: z
365
- .boolean()
366
- .default(true)
367
- .describe('Rename draft-marked files that no longer contain draft ids'),
368
- rootDir: z.string().optional().describe('Project root directory'),
369
- toId: z
370
- .string()
371
- .describe('Established id to write in place of the draft id'),
372
- }),
373
- intent: 'write',
374
- output: z.object({
375
- appModule: z.string().nullable(),
376
- message: z.string(),
377
- promotedEstablished: z.boolean(),
378
- remainingDraftIds: z.array(z.string()),
379
- renamedFiles: z.array(z.object({
380
- from: z.string(),
381
- to: z.string(),
382
- })),
383
- updatedFiles: z.array(z.string()),
384
- }),
385
- });
386
- //# sourceMappingURL=draft-promote.js.map