@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.
- package/CHANGELOG.md +208 -0
- package/README.md +27 -0
- package/package.json +19 -8
- package/src/app.ts +17 -7
- package/src/clack.ts +1 -1
- package/src/cli.ts +304 -10
- package/src/completions.ts +240 -0
- package/src/load-app-mirror.ts +160 -0
- package/src/local-state-io.ts +153 -0
- package/src/project-writes.ts +320 -0
- package/src/run-collision.ts +125 -0
- package/src/run-completions-install.ts +179 -0
- package/src/run-example.ts +149 -0
- package/src/run-examples.ts +148 -0
- package/src/run-quiet.ts +75 -0
- package/src/run-trace.ts +273 -0
- package/src/run-warden.ts +39 -0
- package/src/run-watch.ts +432 -0
- package/src/scaffold-versions.generated.ts +12 -0
- package/src/trails/add-surface.ts +172 -0
- package/src/trails/add-trail.ts +73 -27
- package/src/trails/add-verify.ts +68 -23
- package/src/trails/completions-complete.ts +165 -0
- package/src/trails/completions.ts +47 -0
- package/src/trails/create-scaffold.ts +101 -35
- package/src/trails/create.ts +87 -74
- package/src/trails/dev-clean.ts +31 -22
- package/src/trails/dev-reset.ts +9 -3
- package/src/trails/dev-stats.ts +28 -20
- package/src/trails/dev-support.ts +109 -95
- package/src/trails/draft-promote.ts +351 -107
- package/src/trails/guide.ts +55 -38
- package/src/trails/load-app.ts +712 -38
- package/src/trails/root-dir.ts +21 -0
- package/src/trails/run-example.ts +482 -0
- package/src/trails/run-examples.ts +141 -0
- package/src/trails/run.ts +403 -0
- package/src/trails/survey.ts +517 -186
- package/src/trails/topo-activation.ts +385 -0
- package/src/trails/topo-compile.ts +55 -0
- package/src/trails/topo-history.ts +14 -11
- package/src/trails/topo-output-schemas.ts +175 -0
- package/src/trails/topo-pin.ts +25 -16
- package/src/trails/topo-read-support.ts +178 -238
- package/src/trails/topo-reports.ts +445 -63
- package/src/trails/topo-store-support.ts +67 -35
- package/src/trails/topo-support.ts +93 -147
- package/src/trails/topo-unpin.ts +17 -7
- package/src/trails/topo-verify.ts +19 -10
- package/src/trails/topo.ts +64 -31
- package/src/trails/warden-guide.ts +121 -0
- package/src/trails/warden.ts +137 -47
- package/src/versions.ts +28 -0
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/__tests__/examples.test.ts +0 -20
- package/dist/bin/trails.d.ts +0 -3
- package/dist/bin/trails.d.ts.map +0 -1
- package/dist/bin/trails.js +0 -4
- package/dist/bin/trails.js.map +0 -1
- package/dist/src/app.d.ts +0 -2
- package/dist/src/app.d.ts.map +0 -1
- package/dist/src/app.js +0 -22
- package/dist/src/app.js.map +0 -1
- package/dist/src/clack.d.ts +0 -9
- package/dist/src/clack.d.ts.map +0 -1
- package/dist/src/clack.js +0 -84
- package/dist/src/clack.js.map +0 -1
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -13
- package/dist/src/cli.js.map +0 -1
- package/dist/src/trails/add-surface.d.ts +0 -13
- package/dist/src/trails/add-surface.d.ts.map +0 -1
- package/dist/src/trails/add-surface.js +0 -88
- package/dist/src/trails/add-surface.js.map +0 -1
- package/dist/src/trails/add-trail.d.ts +0 -10
- package/dist/src/trails/add-trail.d.ts.map +0 -1
- package/dist/src/trails/add-trail.js +0 -77
- package/dist/src/trails/add-trail.js.map +0 -1
- package/dist/src/trails/add-trailhead.d.ts +0 -13
- package/dist/src/trails/add-trailhead.d.ts.map +0 -1
- package/dist/src/trails/add-trailhead.js +0 -88
- package/dist/src/trails/add-trailhead.js.map +0 -1
- package/dist/src/trails/add-verify.d.ts +0 -10
- package/dist/src/trails/add-verify.d.ts.map +0 -1
- package/dist/src/trails/add-verify.js +0 -67
- package/dist/src/trails/add-verify.js.map +0 -1
- package/dist/src/trails/create-scaffold.d.ts +0 -15
- package/dist/src/trails/create-scaffold.d.ts.map +0 -1
- package/dist/src/trails/create-scaffold.js +0 -288
- package/dist/src/trails/create-scaffold.js.map +0 -1
- package/dist/src/trails/create.d.ts +0 -22
- package/dist/src/trails/create.d.ts.map +0 -1
- package/dist/src/trails/create.js +0 -121
- package/dist/src/trails/create.js.map +0 -1
- package/dist/src/trails/dev-clean.d.ts +0 -9
- package/dist/src/trails/dev-clean.d.ts.map +0 -1
- package/dist/src/trails/dev-clean.js +0 -65
- package/dist/src/trails/dev-clean.js.map +0 -1
- package/dist/src/trails/dev-reset.d.ts +0 -6
- package/dist/src/trails/dev-reset.d.ts.map +0 -1
- package/dist/src/trails/dev-reset.js +0 -38
- package/dist/src/trails/dev-reset.js.map +0 -1
- package/dist/src/trails/dev-stats.d.ts +0 -7
- package/dist/src/trails/dev-stats.d.ts.map +0 -1
- package/dist/src/trails/dev-stats.js +0 -61
- package/dist/src/trails/dev-stats.js.map +0 -1
- package/dist/src/trails/dev-support.d.ts +0 -64
- package/dist/src/trails/dev-support.d.ts.map +0 -1
- package/dist/src/trails/dev-support.js +0 -178
- package/dist/src/trails/dev-support.js.map +0 -1
- package/dist/src/trails/draft-promote.d.ts +0 -18
- package/dist/src/trails/draft-promote.d.ts.map +0 -1
- package/dist/src/trails/draft-promote.js +0 -386
- package/dist/src/trails/draft-promote.js.map +0 -1
- package/dist/src/trails/guide.d.ts +0 -21
- package/dist/src/trails/guide.d.ts.map +0 -1
- package/dist/src/trails/guide.js +0 -64
- package/dist/src/trails/guide.js.map +0 -1
- package/dist/src/trails/load-app.d.ts +0 -6
- package/dist/src/trails/load-app.d.ts.map +0 -1
- package/dist/src/trails/load-app.js +0 -67
- package/dist/src/trails/load-app.js.map +0 -1
- package/dist/src/trails/project.d.ts +0 -8
- package/dist/src/trails/project.d.ts.map +0 -1
- package/dist/src/trails/project.js +0 -54
- package/dist/src/trails/project.js.map +0 -1
- package/dist/src/trails/survey.d.ts +0 -18
- package/dist/src/trails/survey.d.ts.map +0 -1
- package/dist/src/trails/survey.js +0 -212
- package/dist/src/trails/survey.js.map +0 -1
- package/dist/src/trails/topo-constants.d.ts +0 -3
- package/dist/src/trails/topo-constants.d.ts.map +0 -1
- package/dist/src/trails/topo-constants.js +0 -3
- package/dist/src/trails/topo-constants.js.map +0 -1
- package/dist/src/trails/topo-export.d.ts +0 -18
- package/dist/src/trails/topo-export.d.ts.map +0 -1
- package/dist/src/trails/topo-export.js +0 -34
- package/dist/src/trails/topo-export.js.map +0 -1
- package/dist/src/trails/topo-history.d.ts +0 -24
- package/dist/src/trails/topo-history.d.ts.map +0 -1
- package/dist/src/trails/topo-history.js +0 -33
- package/dist/src/trails/topo-history.js.map +0 -1
- package/dist/src/trails/topo-pin.d.ts +0 -21
- package/dist/src/trails/topo-pin.d.ts.map +0 -1
- package/dist/src/trails/topo-pin.js +0 -35
- package/dist/src/trails/topo-pin.js.map +0 -1
- package/dist/src/trails/topo-read-support.d.ts +0 -54
- package/dist/src/trails/topo-read-support.d.ts.map +0 -1
- package/dist/src/trails/topo-read-support.js +0 -178
- package/dist/src/trails/topo-read-support.js.map +0 -1
- package/dist/src/trails/topo-reports.d.ts +0 -50
- package/dist/src/trails/topo-reports.d.ts.map +0 -1
- package/dist/src/trails/topo-reports.js +0 -122
- package/dist/src/trails/topo-reports.js.map +0 -1
- package/dist/src/trails/topo-show.d.ts +0 -23
- package/dist/src/trails/topo-show.d.ts.map +0 -1
- package/dist/src/trails/topo-show.js +0 -53
- package/dist/src/trails/topo-show.js.map +0 -1
- package/dist/src/trails/topo-store-support.d.ts +0 -13
- package/dist/src/trails/topo-store-support.d.ts.map +0 -1
- package/dist/src/trails/topo-store-support.js +0 -55
- package/dist/src/trails/topo-store-support.js.map +0 -1
- package/dist/src/trails/topo-support.d.ts +0 -87
- package/dist/src/trails/topo-support.d.ts.map +0 -1
- package/dist/src/trails/topo-support.js +0 -165
- package/dist/src/trails/topo-support.js.map +0 -1
- package/dist/src/trails/topo-unpin.d.ts +0 -15
- package/dist/src/trails/topo-unpin.d.ts.map +0 -1
- package/dist/src/trails/topo-unpin.js +0 -39
- package/dist/src/trails/topo-unpin.js.map +0 -1
- package/dist/src/trails/topo-verify.d.ts +0 -5
- package/dist/src/trails/topo-verify.d.ts.map +0 -1
- package/dist/src/trails/topo-verify.js +0 -28
- package/dist/src/trails/topo-verify.js.map +0 -1
- package/dist/src/trails/topo.d.ts +0 -5
- package/dist/src/trails/topo.d.ts.map +0 -1
- package/dist/src/trails/topo.js +0 -67
- package/dist/src/trails/topo.js.map +0 -1
- package/dist/src/trails/warden.d.ts +0 -19
- package/dist/src/trails/warden.d.ts.map +0 -1
- package/dist/src/trails/warden.js +0 -89
- package/dist/src/trails/warden.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/__tests__/create.test.ts +0 -351
- package/src/__tests__/draft-promote.test.ts +0 -144
- package/src/__tests__/guide.test.ts +0 -91
- package/src/__tests__/load-app.test.ts +0 -58
- package/src/__tests__/survey.test.ts +0 -301
- package/src/__tests__/topo-dev.test.ts +0 -424
- package/src/__tests__/warden.test.ts +0 -74
- package/src/trails/add-trailhead.ts +0 -121
- package/src/trails/topo-export.ts +0 -39
- package/src/trails/topo-show.ts +0 -58
- package/tsconfig.json +0 -9
package/src/trails/dev-stats.ts
CHANGED
|
@@ -1,39 +1,47 @@
|
|
|
1
1
|
import { Result, trail } from '@ontrails/core';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
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
|
|
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.
|
|
13
|
-
maxRecords: input.
|
|
20
|
+
maxAge: input.traceAgeMs,
|
|
21
|
+
maxRecords: input.traces,
|
|
14
22
|
rootDir,
|
|
15
|
-
|
|
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:
|
|
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
|
-
|
|
36
|
+
snapshots: z
|
|
29
37
|
.number()
|
|
30
|
-
.default(
|
|
31
|
-
.describe('Unpinned topo
|
|
32
|
-
|
|
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
|
|
36
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
snapshots: z.number(),
|
|
60
|
+
traceAgeMs: z.number(),
|
|
61
|
+
traces: z.number(),
|
|
54
62
|
}),
|
|
55
63
|
topo: z.object({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
pinnedCount: z.number(),
|
|
65
|
+
prunableSnapshotCount: z.number(),
|
|
66
|
+
snapshotCount: z.number(),
|
|
59
67
|
}),
|
|
60
|
-
|
|
68
|
+
tracing: z.object({
|
|
61
69
|
recordCount: z.number(),
|
|
62
70
|
}),
|
|
63
71
|
}),
|
|
@@ -1,38 +1,43 @@
|
|
|
1
|
-
import { existsSync,
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
} from '@ontrails/core
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from '@ontrails/
|
|
19
|
+
applyTraceCleanup,
|
|
20
|
+
countTraceRecords,
|
|
21
|
+
previewTraceCleanup,
|
|
22
|
+
} from '@ontrails/tracing';
|
|
23
|
+
|
|
24
|
+
import { removeRootRelativeFileIfPresent } from '../local-state-io.js';
|
|
23
25
|
|
|
24
|
-
import {
|
|
26
|
+
import { requireTrailRootDir } from './root-dir.js';
|
|
25
27
|
|
|
26
|
-
export const
|
|
28
|
+
export const DEFAULT_TOPO_SNAPSHOT_RETENTION = 50;
|
|
27
29
|
|
|
28
|
-
const
|
|
30
|
+
const deriveRootDir = (cwd?: string): string => requireTrailRootDir(cwd);
|
|
29
31
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
|
51
|
-
readonly
|
|
52
|
-
readonly
|
|
55
|
+
readonly snapshots: number;
|
|
56
|
+
readonly traceAgeMs: number;
|
|
57
|
+
readonly traces: number;
|
|
53
58
|
};
|
|
54
59
|
readonly topo: {
|
|
55
|
-
readonly
|
|
56
|
-
readonly
|
|
57
|
-
readonly
|
|
60
|
+
readonly pinnedCount: number;
|
|
61
|
+
readonly prunableSnapshotCount: number;
|
|
62
|
+
readonly snapshotCount: number;
|
|
58
63
|
};
|
|
59
|
-
readonly
|
|
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
|
|
68
|
-
readonly
|
|
69
|
-
readonly
|
|
72
|
+
readonly pinnedCount: number;
|
|
73
|
+
readonly snapshotCount: number;
|
|
74
|
+
readonly traceCount: number;
|
|
70
75
|
};
|
|
71
76
|
readonly removed: {
|
|
72
|
-
readonly
|
|
73
|
-
readonly
|
|
77
|
+
readonly topoSnapshots: number;
|
|
78
|
+
readonly traceRecords: number;
|
|
74
79
|
};
|
|
75
80
|
readonly retention: {
|
|
76
|
-
readonly
|
|
77
|
-
readonly
|
|
78
|
-
readonly
|
|
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
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
pinnedCount: 0,
|
|
120
|
+
snapshotCount: 0,
|
|
121
|
+
traceCount: 0,
|
|
117
122
|
},
|
|
118
123
|
removed: {
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
pinnedCount: 0,
|
|
155
|
+
prunableSnapshotCount: 0,
|
|
156
|
+
snapshotCount: 0,
|
|
152
157
|
},
|
|
153
|
-
|
|
158
|
+
tracing: {
|
|
154
159
|
recordCount: 0,
|
|
155
160
|
},
|
|
156
161
|
});
|
|
157
162
|
|
|
158
163
|
const liveDevStats = (
|
|
159
|
-
db: Parameters<typeof
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
173
|
+
pinnedCount: countPinnedSnapshots(db),
|
|
174
|
+
prunableSnapshotCount: countPrunableSnapshots(db, {
|
|
175
|
+
keep: retention.snapshots,
|
|
176
|
+
}),
|
|
177
|
+
snapshotCount: countTopoSnapshots(db),
|
|
171
178
|
},
|
|
172
|
-
|
|
173
|
-
recordCount:
|
|
179
|
+
tracing: {
|
|
180
|
+
recordCount: countTraceRecords(db),
|
|
174
181
|
},
|
|
175
182
|
});
|
|
176
183
|
|
|
177
|
-
const
|
|
178
|
-
const rootDir =
|
|
179
|
-
const dbPath =
|
|
180
|
-
const trailsDir =
|
|
181
|
-
const lockPath =
|
|
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
|
|
198
|
+
const deriveDevCleanupContext = (
|
|
192
199
|
options?: DevRetentionOptions & { readonly dryRun?: boolean }
|
|
193
200
|
): DevCleanupContext => {
|
|
194
|
-
const rootDir =
|
|
201
|
+
const rootDir = deriveRootDir(options?.rootDir);
|
|
195
202
|
return {
|
|
196
|
-
dbPath:
|
|
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
|
|
204
|
-
db: Parameters<typeof
|
|
210
|
+
const cleanupTraces = (
|
|
211
|
+
db: Parameters<typeof countPinnedSnapshots>[0],
|
|
205
212
|
context: DevCleanupContext
|
|
206
213
|
) =>
|
|
207
214
|
context.dryRun
|
|
208
|
-
?
|
|
209
|
-
maxAge: context.retention.
|
|
210
|
-
maxRecords: context.retention.
|
|
215
|
+
? previewTraceCleanup(db, {
|
|
216
|
+
maxAge: context.retention.traceAgeMs,
|
|
217
|
+
maxRecords: context.retention.traces,
|
|
211
218
|
})
|
|
212
|
-
:
|
|
213
|
-
maxAge: context.retention.
|
|
214
|
-
maxRecords: context.retention.
|
|
219
|
+
: applyTraceCleanup(db, {
|
|
220
|
+
maxAge: context.retention.traceAgeMs,
|
|
221
|
+
maxRecords: context.retention.traces,
|
|
215
222
|
});
|
|
216
223
|
|
|
217
|
-
const
|
|
218
|
-
db: Parameters<typeof
|
|
224
|
+
const cleanupTopoSnapshots = (
|
|
225
|
+
db: Parameters<typeof countPinnedSnapshots>[0],
|
|
219
226
|
context: DevCleanupContext
|
|
220
227
|
): number =>
|
|
221
228
|
context.dryRun
|
|
222
|
-
?
|
|
223
|
-
:
|
|
229
|
+
? countPrunableSnapshots(db, { keep: context.retention.snapshots })
|
|
230
|
+
: pruneUnpinnedSnapshots(db, { keep: context.retention.snapshots });
|
|
224
231
|
|
|
225
232
|
const buildCleanReport = (
|
|
226
|
-
db: Parameters<typeof
|
|
233
|
+
db: Parameters<typeof countPinnedSnapshots>[0],
|
|
227
234
|
context: DevCleanupContext
|
|
228
235
|
): DevCleanReport => {
|
|
229
|
-
const
|
|
230
|
-
const topoRemoved =
|
|
231
|
-
const
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
244
|
-
|
|
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/
|
|
255
|
-
'.trails/dev/
|
|
256
|
-
'.trails/dev/
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
332
|
+
removeResetFileIfPresent(rootDir, relativePath)
|
|
319
333
|
);
|
|
320
334
|
|
|
321
335
|
return {
|