@ontrails/warden 1.0.0-beta.0

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 (118) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/.turbo/turbo-lint.log +3 -0
  3. package/.turbo/turbo-typecheck.log +1 -0
  4. package/CHANGELOG.md +21 -0
  5. package/README.md +132 -0
  6. package/dist/cli.d.ts +46 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +221 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/drift.d.ts +26 -0
  11. package/dist/drift.d.ts.map +1 -0
  12. package/dist/drift.js +27 -0
  13. package/dist/drift.js.map +1 -0
  14. package/dist/formatters.d.ts +29 -0
  15. package/dist/formatters.d.ts.map +1 -0
  16. package/dist/formatters.js +87 -0
  17. package/dist/formatters.js.map +1 -0
  18. package/dist/index.d.ts +26 -0
  19. package/dist/index.d.ts.map +1 -0
  20. package/dist/index.js +26 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/rules/ast.d.ts +41 -0
  23. package/dist/rules/ast.d.ts.map +1 -0
  24. package/dist/rules/ast.js +163 -0
  25. package/dist/rules/ast.js.map +1 -0
  26. package/dist/rules/context-no-surface-types.d.ts +12 -0
  27. package/dist/rules/context-no-surface-types.d.ts.map +1 -0
  28. package/dist/rules/context-no-surface-types.js +96 -0
  29. package/dist/rules/context-no-surface-types.js.map +1 -0
  30. package/dist/rules/implementation-returns-result.d.ts +13 -0
  31. package/dist/rules/implementation-returns-result.d.ts.map +1 -0
  32. package/dist/rules/implementation-returns-result.js +231 -0
  33. package/dist/rules/implementation-returns-result.js.map +1 -0
  34. package/dist/rules/index.d.ts +22 -0
  35. package/dist/rules/index.d.ts.map +1 -0
  36. package/dist/rules/index.js +41 -0
  37. package/dist/rules/index.js.map +1 -0
  38. package/dist/rules/no-direct-impl-in-route.d.ts +12 -0
  39. package/dist/rules/no-direct-impl-in-route.d.ts.map +1 -0
  40. package/dist/rules/no-direct-impl-in-route.js +46 -0
  41. package/dist/rules/no-direct-impl-in-route.js.map +1 -0
  42. package/dist/rules/no-direct-implementation-call.d.ts +12 -0
  43. package/dist/rules/no-direct-implementation-call.d.ts.map +1 -0
  44. package/dist/rules/no-direct-implementation-call.js +39 -0
  45. package/dist/rules/no-direct-implementation-call.js.map +1 -0
  46. package/dist/rules/no-sync-result-assumption.d.ts +6 -0
  47. package/dist/rules/no-sync-result-assumption.d.ts.map +1 -0
  48. package/dist/rules/no-sync-result-assumption.js +98 -0
  49. package/dist/rules/no-sync-result-assumption.js.map +1 -0
  50. package/dist/rules/no-throw-in-detour-target.d.ts +12 -0
  51. package/dist/rules/no-throw-in-detour-target.d.ts.map +1 -0
  52. package/dist/rules/no-throw-in-detour-target.js +87 -0
  53. package/dist/rules/no-throw-in-detour-target.js.map +1 -0
  54. package/dist/rules/no-throw-in-implementation.d.ts +9 -0
  55. package/dist/rules/no-throw-in-implementation.d.ts.map +1 -0
  56. package/dist/rules/no-throw-in-implementation.js +34 -0
  57. package/dist/rules/no-throw-in-implementation.js.map +1 -0
  58. package/dist/rules/prefer-schema-inference.d.ts +7 -0
  59. package/dist/rules/prefer-schema-inference.d.ts.map +1 -0
  60. package/dist/rules/prefer-schema-inference.js +86 -0
  61. package/dist/rules/prefer-schema-inference.js.map +1 -0
  62. package/dist/rules/scan.d.ts +8 -0
  63. package/dist/rules/scan.d.ts.map +1 -0
  64. package/dist/rules/scan.js +32 -0
  65. package/dist/rules/scan.js.map +1 -0
  66. package/dist/rules/specs.d.ts +29 -0
  67. package/dist/rules/specs.d.ts.map +1 -0
  68. package/dist/rules/specs.js +192 -0
  69. package/dist/rules/specs.js.map +1 -0
  70. package/dist/rules/structure.d.ts +13 -0
  71. package/dist/rules/structure.d.ts.map +1 -0
  72. package/dist/rules/structure.js +142 -0
  73. package/dist/rules/structure.js.map +1 -0
  74. package/dist/rules/types.d.ts +52 -0
  75. package/dist/rules/types.d.ts.map +1 -0
  76. package/dist/rules/types.js +2 -0
  77. package/dist/rules/types.js.map +1 -0
  78. package/dist/rules/valid-describe-refs.d.ts +7 -0
  79. package/dist/rules/valid-describe-refs.d.ts.map +1 -0
  80. package/dist/rules/valid-describe-refs.js +51 -0
  81. package/dist/rules/valid-describe-refs.js.map +1 -0
  82. package/dist/rules/valid-detour-refs.d.ts +6 -0
  83. package/dist/rules/valid-detour-refs.d.ts.map +1 -0
  84. package/dist/rules/valid-detour-refs.js +116 -0
  85. package/dist/rules/valid-detour-refs.js.map +1 -0
  86. package/package.json +25 -0
  87. package/src/__tests__/cli.test.ts +198 -0
  88. package/src/__tests__/drift.test.ts +74 -0
  89. package/src/__tests__/formatters.test.ts +157 -0
  90. package/src/__tests__/implementation-returns-result.test.ts +75 -0
  91. package/src/__tests__/no-direct-implementation-call.test.ts +83 -0
  92. package/src/__tests__/no-sync-result-assumption.test.ts +85 -0
  93. package/src/__tests__/no-throw-in-detour-target.test.ts +78 -0
  94. package/src/__tests__/prefer-schema-inference.test.ts +84 -0
  95. package/src/__tests__/rules.test.ts +188 -0
  96. package/src/__tests__/valid-describe-refs.test.ts +60 -0
  97. package/src/cli.ts +343 -0
  98. package/src/drift.ts +50 -0
  99. package/src/formatters.ts +113 -0
  100. package/src/index.ts +47 -0
  101. package/src/rules/ast.ts +217 -0
  102. package/src/rules/context-no-surface-types.ts +150 -0
  103. package/src/rules/implementation-returns-result.ts +343 -0
  104. package/src/rules/index.ts +54 -0
  105. package/src/rules/no-direct-impl-in-route.ts +77 -0
  106. package/src/rules/no-direct-implementation-call.ts +47 -0
  107. package/src/rules/no-sync-result-assumption.ts +156 -0
  108. package/src/rules/no-throw-in-detour-target.ts +150 -0
  109. package/src/rules/no-throw-in-implementation.ts +41 -0
  110. package/src/rules/prefer-schema-inference.ts +141 -0
  111. package/src/rules/scan.ts +46 -0
  112. package/src/rules/specs.ts +384 -0
  113. package/src/rules/structure.ts +234 -0
  114. package/src/rules/types.ts +62 -0
  115. package/src/rules/valid-describe-refs.ts +94 -0
  116. package/src/rules/valid-detour-refs.ts +187 -0
  117. package/tsconfig.json +9 -0
  118. package/tsconfig.tsbuildinfo +1 -0
package/src/cli.ts ADDED
@@ -0,0 +1,343 @@
1
+ /**
2
+ * Warden CLI command runner.
3
+ *
4
+ * Scans TypeScript files, runs all warden rules, optionally checks drift,
5
+ * and returns a structured report.
6
+ */
7
+
8
+ import { resolve } from 'node:path';
9
+
10
+ import type { Topo } from '@ontrails/core';
11
+
12
+ import type { DriftResult } from './drift.js';
13
+ import { checkDrift } from './drift.js';
14
+ import {
15
+ findConfigProperty,
16
+ findTrailDefinitions,
17
+ parse,
18
+ walk,
19
+ } from './rules/ast.js';
20
+ import { wardenRules } from './rules/index.js';
21
+ import type {
22
+ ProjectAwareWardenRule,
23
+ ProjectContext,
24
+ WardenDiagnostic,
25
+ WardenRule,
26
+ } from './rules/types.js';
27
+
28
+ /**
29
+ * Options for the warden CLI runner.
30
+ */
31
+ export interface WardenOptions {
32
+ /** Root directory to scan for TypeScript files. Defaults to cwd. */
33
+ readonly rootDir?: string | undefined;
34
+ /** Only run lint rules, skip drift detection */
35
+ readonly lintOnly?: boolean | undefined;
36
+ /** Only run drift detection, skip lint rules */
37
+ readonly driftOnly?: boolean | undefined;
38
+ /** App topology for drift detection. When provided, enables real surface lock comparison. */
39
+ readonly topo?: Topo | undefined;
40
+ }
41
+
42
+ /**
43
+ * Result of a warden run.
44
+ */
45
+ export interface WardenReport {
46
+ /** All diagnostics from lint rules */
47
+ readonly diagnostics: readonly WardenDiagnostic[];
48
+ /** Count of error-severity diagnostics */
49
+ readonly errorCount: number;
50
+ /** Count of warn-severity diagnostics */
51
+ readonly warnCount: number;
52
+ /** Drift detection result, or null if skipped */
53
+ readonly drift: DriftResult | null;
54
+ /** Whether the warden run passed (no errors, no drift) */
55
+ readonly passed: boolean;
56
+ }
57
+
58
+ /**
59
+ * Collect all .ts files under a directory, excluding node_modules, dist, and .git.
60
+ */
61
+ const isSourceFile = (match: string): boolean =>
62
+ !match.endsWith('.d.ts') &&
63
+ !match.startsWith('node_modules/') &&
64
+ !match.startsWith('dist/') &&
65
+ !match.startsWith('.git/') &&
66
+ !match.includes('__tests__/') &&
67
+ !match.includes('__test__/') &&
68
+ !match.endsWith('.test.ts') &&
69
+ !match.endsWith('.spec.ts');
70
+
71
+ const collectTsFiles = (dir: string): readonly string[] => {
72
+ const glob = new Bun.Glob('**/*.ts');
73
+ let matches: IterableIterator<string>;
74
+ try {
75
+ matches = glob.scanSync({ cwd: dir, dot: false, onlyFiles: true });
76
+ } catch {
77
+ return [];
78
+ }
79
+
80
+ const files: string[] = [];
81
+ for (const match of matches) {
82
+ if (isSourceFile(match)) {
83
+ files.push(`${dir}/${match}`);
84
+ }
85
+ }
86
+ return files;
87
+ };
88
+
89
+ interface SourceFile {
90
+ readonly filePath: string;
91
+ readonly sourceCode: string;
92
+ }
93
+
94
+ const collectKnownTrailIds = (
95
+ sourceCode: string,
96
+ filePath: string,
97
+ knownTrailIds: Set<string>
98
+ ): void => {
99
+ const ast = parse(filePath, sourceCode);
100
+ if (!ast) {
101
+ return;
102
+ }
103
+ for (const def of findTrailDefinitions(ast)) {
104
+ knownTrailIds.add(def.id);
105
+ }
106
+ };
107
+
108
+ const collectDetourTargetTrailIds = (
109
+ sourceCode: string,
110
+ filePath: string,
111
+ detourTargetTrailIds: Set<string>
112
+ ): void => {
113
+ const ast = parse(filePath, sourceCode);
114
+ if (!ast) {
115
+ return;
116
+ }
117
+ for (const def of findTrailDefinitions(ast)) {
118
+ const detoursProp = findConfigProperty(def.config, 'detours');
119
+ if (!detoursProp) {
120
+ continue;
121
+ }
122
+ // Walk the detours value for string literals that look like trail IDs
123
+ walk(detoursProp, (node) => {
124
+ if (node.type !== 'Literal') {
125
+ return;
126
+ }
127
+ const val = (node as unknown as { value?: string }).value;
128
+ if (val && val.includes('.')) {
129
+ detourTargetTrailIds.add(val);
130
+ }
131
+ });
132
+ }
133
+ };
134
+
135
+ const loadSourceFiles = async (
136
+ rootDir: string
137
+ ): Promise<readonly SourceFile[]> => {
138
+ const sourceFiles: SourceFile[] = [];
139
+
140
+ for (const filePath of collectTsFiles(rootDir)) {
141
+ try {
142
+ sourceFiles.push({
143
+ filePath,
144
+ sourceCode: await Bun.file(filePath).text(),
145
+ });
146
+ } catch {
147
+ continue;
148
+ }
149
+ }
150
+
151
+ return sourceFiles;
152
+ };
153
+
154
+ const buildProjectContextFromTopo = (appTopo: Topo): ProjectContext => {
155
+ const knownTrailIds = new Set<string>([
156
+ ...appTopo.trails.keys(),
157
+ ...appTopo.hikes.keys(),
158
+ ]);
159
+
160
+ const detourTargetTrailIds = new Set<string>();
161
+ for (const t of appTopo.trails.values()) {
162
+ const detours = (t as unknown as Record<string, unknown>)['detours'] as
163
+ | Readonly<Record<string, readonly string[]>>
164
+ | undefined;
165
+ if (!detours) {
166
+ continue;
167
+ }
168
+ for (const targets of Object.values(detours)) {
169
+ for (const id of targets) {
170
+ detourTargetTrailIds.add(id);
171
+ }
172
+ }
173
+ }
174
+
175
+ return { detourTargetTrailIds, knownTrailIds };
176
+ };
177
+
178
+ const buildProjectContextFromFiles = (
179
+ sourceFiles: readonly SourceFile[]
180
+ ): ProjectContext => {
181
+ const knownTrailIds = new Set<string>();
182
+ const detourTargetTrailIds = new Set<string>();
183
+
184
+ for (const sourceFile of sourceFiles) {
185
+ collectKnownTrailIds(
186
+ sourceFile.sourceCode,
187
+ sourceFile.filePath,
188
+ knownTrailIds
189
+ );
190
+ collectDetourTargetTrailIds(
191
+ sourceFile.sourceCode,
192
+ sourceFile.filePath,
193
+ detourTargetTrailIds
194
+ );
195
+ }
196
+
197
+ return {
198
+ detourTargetTrailIds,
199
+ knownTrailIds,
200
+ };
201
+ };
202
+
203
+ const isProjectAwareRule = (rule: WardenRule): rule is ProjectAwareWardenRule =>
204
+ 'checkWithContext' in rule;
205
+
206
+ /**
207
+ * Lint all files against all warden rules.
208
+ */
209
+ const lintFiles = async (
210
+ rootDir: string,
211
+ appTopo?: Topo | undefined
212
+ ): Promise<WardenDiagnostic[]> => {
213
+ const allDiagnostics: WardenDiagnostic[] = [];
214
+ const sourceFiles = await loadSourceFiles(rootDir);
215
+ const context = appTopo
216
+ ? buildProjectContextFromTopo(appTopo)
217
+ : buildProjectContextFromFiles(sourceFiles);
218
+
219
+ for (const sourceFile of sourceFiles) {
220
+ for (const rule of wardenRules.values()) {
221
+ if (isProjectAwareRule(rule)) {
222
+ allDiagnostics.push(
223
+ ...rule.checkWithContext(
224
+ sourceFile.sourceCode,
225
+ sourceFile.filePath,
226
+ context
227
+ )
228
+ );
229
+ continue;
230
+ }
231
+
232
+ allDiagnostics.push(
233
+ ...rule.check(sourceFile.sourceCode, sourceFile.filePath)
234
+ );
235
+ }
236
+ }
237
+
238
+ return allDiagnostics;
239
+ };
240
+
241
+ /**
242
+ * Run all warden checks and return a structured report.
243
+ */
244
+ export const runWarden = async (
245
+ options: WardenOptions = {}
246
+ ): Promise<WardenReport> => {
247
+ const rootDir = resolve(options.rootDir ?? process.cwd());
248
+ const allDiagnostics = options.driftOnly
249
+ ? []
250
+ : await lintFiles(rootDir, options.topo);
251
+ const drift = options.lintOnly
252
+ ? null
253
+ : await checkDrift(rootDir, options.topo);
254
+
255
+ const errorCount = allDiagnostics.filter(
256
+ (d) => d.severity === 'error'
257
+ ).length;
258
+ const warnCount = allDiagnostics.filter((d) => d.severity === 'warn').length;
259
+
260
+ return {
261
+ diagnostics: allDiagnostics,
262
+ drift,
263
+ errorCount,
264
+ passed: errorCount === 0 && !(drift?.stale ?? false),
265
+ warnCount,
266
+ };
267
+ };
268
+
269
+ /**
270
+ * Format the lint section of the report.
271
+ */
272
+ const formatLintSection = (report: WardenReport): string[] => {
273
+ if (report.diagnostics.length === 0) {
274
+ return ['Lint: clean'];
275
+ }
276
+
277
+ const lines = [
278
+ `Lint: ${report.errorCount} errors, ${report.warnCount} warnings`,
279
+ ];
280
+
281
+ for (const d of report.diagnostics) {
282
+ const prefix = d.severity === 'error' ? 'ERROR' : 'WARN';
283
+ lines.push(
284
+ ` ${d.filePath}:${String(d.line)} [${prefix}] ${d.rule} ${d.message}`
285
+ );
286
+ }
287
+
288
+ return lines;
289
+ };
290
+
291
+ /**
292
+ * Format the drift section of the report.
293
+ */
294
+ const formatDriftSection = (drift: DriftResult | null): string[] => {
295
+ if (drift === null) {
296
+ return [];
297
+ }
298
+ const label = drift.stale
299
+ ? 'Drift: surface.lock is stale (regenerate with `trails survey generate`)'
300
+ : 'Drift: clean';
301
+ return [label, ''];
302
+ };
303
+
304
+ /**
305
+ * Format the result line.
306
+ */
307
+ const formatResultLine = (report: WardenReport): string => {
308
+ if (report.passed) {
309
+ return 'Result: PASS';
310
+ }
311
+ const parts: string[] = [];
312
+ if (report.errorCount > 0) {
313
+ parts.push(`${report.errorCount} errors`);
314
+ }
315
+ if (report.drift?.stale) {
316
+ parts.push('drift detected');
317
+ }
318
+ return `Result: FAIL (${parts.join(', ')})`;
319
+ };
320
+
321
+ /**
322
+ * Format a warden report as a human-readable string.
323
+ */
324
+ export const formatWardenReport = (report: WardenReport): string => {
325
+ const lintLines = formatLintSection(report);
326
+ const driftLines = formatDriftSection(report.drift);
327
+
328
+ if (lintLines.length === 0 && driftLines.length === 0) {
329
+ return ['Warden Report', '=============', '', 'No checks were run.'].join(
330
+ '\n'
331
+ );
332
+ }
333
+
334
+ return [
335
+ 'Warden Report',
336
+ '=============',
337
+ '',
338
+ ...lintLines,
339
+ '',
340
+ ...driftLines,
341
+ formatResultLine(report),
342
+ ].join('\n');
343
+ };
package/src/drift.ts ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Surface lock drift detection.
3
+ *
4
+ * Compares the committed `surface.lock` hash against a freshly generated
5
+ * surface map hash to detect when the trail topology has changed without
6
+ * updating the lock file.
7
+ */
8
+
9
+ import type { Topo } from '@ontrails/core';
10
+ import {
11
+ generateSurfaceMap,
12
+ hashSurfaceMap,
13
+ readSurfaceLock,
14
+ } from '@ontrails/schema';
15
+
16
+ /**
17
+ * Result of a drift check comparing committed surface.lock against the current state.
18
+ */
19
+ export interface DriftResult {
20
+ /** Whether the committed lock is out of date */
21
+ readonly stale: boolean;
22
+ /** Hash from the committed surface.lock file, or null if not found */
23
+ readonly committedHash: string | null;
24
+ /** Hash computed from the current trail topology */
25
+ readonly currentHash: string;
26
+ }
27
+
28
+ /**
29
+ * Check whether the committed surface.lock is stale compared to the current topology.
30
+ *
31
+ * When no topo is provided, returns a clean result (no drift detectable without runtime info).
32
+ */
33
+ export const checkDrift = async (
34
+ rootDir: string,
35
+ topo?: Topo | undefined
36
+ ): Promise<DriftResult> => {
37
+ if (!topo) {
38
+ return { committedHash: null, currentHash: 'unknown', stale: false };
39
+ }
40
+
41
+ const surfaceMap = generateSurfaceMap(topo);
42
+ const currentHash = hashSurfaceMap(surfaceMap);
43
+ const committedHash = await readSurfaceLock({ dir: rootDir });
44
+
45
+ return {
46
+ committedHash,
47
+ currentHash,
48
+ stale: committedHash !== null && committedHash !== currentHash,
49
+ };
50
+ };
@@ -0,0 +1,113 @@
1
+ /**
2
+ * CI-oriented formatters for warden reports.
3
+ *
4
+ * Each formatter takes a `WardenReport` and produces output suited to a
5
+ * specific CI environment: GitHub Actions annotations, structured JSON,
6
+ * or a concise markdown summary.
7
+ */
8
+
9
+ import type { WardenReport } from './cli.js';
10
+ import type { WardenSeverity } from './rules/types.js';
11
+
12
+ /** Map warden severity to GitHub Actions annotation level. */
13
+ const ghLevel: Record<WardenSeverity, string> = {
14
+ error: 'error',
15
+ warn: 'warning',
16
+ };
17
+
18
+ /**
19
+ * Produce GitHub Actions workflow command annotations, one per diagnostic.
20
+ *
21
+ * Severity mapping: `error` to `::error`, `warn` to `::warning`.
22
+ * Drift staleness is emitted as a single `::error` annotation when detected.
23
+ */
24
+ export const formatGitHubAnnotations = (report: WardenReport): string => {
25
+ const lines: string[] = [];
26
+
27
+ for (const d of report.diagnostics) {
28
+ const level = ghLevel[d.severity];
29
+ lines.push(
30
+ `::${level} file=${d.filePath},line=${String(d.line)}::${d.rule}: ${d.message}`
31
+ );
32
+ }
33
+
34
+ if (report.drift?.stale) {
35
+ lines.push(
36
+ '::error::drift: surface.lock is stale (regenerate with `trails survey generate`)'
37
+ );
38
+ }
39
+
40
+ return lines.join('\n');
41
+ };
42
+
43
+ /**
44
+ * Produce a structured JSON string from the report.
45
+ *
46
+ * Includes a `summary` object with error, warning, and suggestion counts
47
+ * for easy consumption by downstream tooling.
48
+ */
49
+ export const formatJson = (report: WardenReport): string => {
50
+ const summary = {
51
+ errors: report.errorCount,
52
+ suggestions: 0,
53
+ warnings: report.warnCount,
54
+ };
55
+
56
+ return JSON.stringify(
57
+ {
58
+ diagnostics: report.diagnostics,
59
+ drift: report.drift,
60
+ passed: report.passed,
61
+ summary,
62
+ },
63
+ null,
64
+ 2
65
+ );
66
+ };
67
+
68
+ /** Format a diagnostic as a markdown list item. */
69
+ const diagnosticLine = (d: WardenReport['diagnostics'][number]): string =>
70
+ `- \`${d.filePath}:${String(d.line)}\` — ${d.rule}: ${d.message}`;
71
+
72
+ /** Render a severity group as a headed markdown section, or empty array. */
73
+ const severitySection = (
74
+ heading: string,
75
+ diagnostics: WardenReport['diagnostics']
76
+ ): readonly string[] => {
77
+ if (diagnostics.length === 0) {
78
+ return [];
79
+ }
80
+ return ['', `### ${heading}`, ...diagnostics.map(diagnosticLine)];
81
+ };
82
+
83
+ /** Render a drift section if stale, otherwise empty array. */
84
+ const driftSection = (drift: WardenReport['drift']): readonly string[] => {
85
+ if (!drift?.stale) {
86
+ return [];
87
+ }
88
+ return [
89
+ '',
90
+ '### Drift',
91
+ '- surface.lock is stale (regenerate with `trails survey generate`)',
92
+ ];
93
+ };
94
+
95
+ /**
96
+ * Produce a concise markdown summary suitable for a GitHub job summary or PR comment.
97
+ *
98
+ * Groups diagnostics by severity and includes drift status when relevant.
99
+ */
100
+ export const formatSummary = (report: WardenReport): string => {
101
+ const result = report.passed ? 'PASS' : 'FAIL';
102
+ const errors = report.diagnostics.filter((d) => d.severity === 'error');
103
+ const warnings = report.diagnostics.filter((d) => d.severity === 'warn');
104
+
105
+ return [
106
+ '## Warden Report',
107
+ '',
108
+ `**Result: ${result}** | ${String(report.errorCount)} errors, ${String(report.warnCount)} warnings`,
109
+ ...severitySection('Errors', errors),
110
+ ...severitySection('Warnings', warnings),
111
+ ...driftSection(report.drift),
112
+ ].join('\n');
113
+ };
package/src/index.ts ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Warden - Governance package for Trails.
3
+ *
4
+ * Provides lint rules, drift detection, and a CLI runner to enforce
5
+ * contract-first discipline at development time.
6
+ *
7
+ * Package: `@ontrails/warden`
8
+ */
9
+
10
+ // Rule types
11
+ export type {
12
+ ProjectAwareWardenRule,
13
+ ProjectContext,
14
+ WardenDiagnostic,
15
+ WardenRule,
16
+ WardenSeverity,
17
+ } from './rules/index.js';
18
+
19
+ // Individual rules
20
+ export { noThrowInImplementation } from './rules/no-throw-in-implementation.js';
21
+ export { contextNoSurfaceTypes } from './rules/context-no-surface-types.js';
22
+ export { validDetourRefs } from './rules/valid-detour-refs.js';
23
+ export { noDirectImplInRoute } from './rules/no-direct-impl-in-route.js';
24
+ export { noDirectImplementationCall } from './rules/no-direct-implementation-call.js';
25
+ export { noSyncResultAssumption } from './rules/no-sync-result-assumption.js';
26
+ export { implementationReturnsResult } from './rules/implementation-returns-result.js';
27
+ export { noThrowInDetourTarget } from './rules/no-throw-in-detour-target.js';
28
+ export { preferSchemaInference } from './rules/prefer-schema-inference.js';
29
+ export { validDescribeRefs } from './rules/valid-describe-refs.js';
30
+
31
+ // Rule registry
32
+ export { wardenRules } from './rules/index.js';
33
+
34
+ // CLI runner
35
+ export type { WardenOptions, WardenReport } from './cli.js';
36
+ export { formatWardenReport, runWarden } from './cli.js';
37
+
38
+ // CI formatters
39
+ export {
40
+ formatGitHubAnnotations,
41
+ formatJson,
42
+ formatSummary,
43
+ } from './formatters.js';
44
+
45
+ // Drift detection
46
+ export type { DriftResult } from './drift.js';
47
+ export { checkDrift } from './drift.js';