@ontrails/warden 1.0.0-beta.4 → 1.0.0-beta.42
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 +837 -13
- package/README.md +133 -26
- package/bin/warden.ts +51 -0
- package/package.json +27 -6
- package/src/adapter-check.ts +136 -0
- package/src/cli.ts +1570 -105
- package/src/command.ts +986 -0
- package/src/config.ts +193 -0
- package/src/draft.ts +22 -0
- package/src/drift.ts +233 -23
- package/src/fix.ts +126 -0
- package/src/formatters.ts +78 -13
- package/src/guide.ts +245 -0
- package/src/index.ts +247 -15
- package/src/project-context.ts +446 -0
- package/src/project-rules.ts +290 -0
- package/src/resolve.ts +531 -0
- package/src/rules/activation-orphan.ts +97 -0
- package/src/rules/captured-kernel.ts +375 -0
- package/src/rules/circular-refs.ts +150 -0
- package/src/rules/cli-command-route-coherence.ts +177 -0
- package/src/rules/composes-declarations.ts +839 -0
- package/src/rules/context-no-surface-types.ts +79 -15
- package/src/rules/dead-internal-trail.ts +161 -0
- package/src/rules/dead-public-trail.ts +258 -0
- package/src/rules/draft-file-marking.ts +155 -0
- package/src/rules/draft-visible-debt.ts +82 -0
- package/src/rules/duplicate-exported-symbol.ts +211 -0
- package/src/rules/duplicate-public-contract.ts +137 -0
- package/src/rules/entity-exists.ts +254 -0
- package/src/rules/entity-ids.ts +15 -0
- package/src/rules/error-mapping-completeness.ts +290 -0
- package/src/rules/example-valid.ts +395 -0
- package/src/rules/fires-declarations.ts +740 -0
- package/src/rules/governed-symbol-residue.ts +438 -0
- package/src/rules/implementation-returns-result.ts +1409 -166
- package/src/rules/incomplete-accessor-for-standard-op.ts +272 -0
- package/src/rules/incomplete-crud.ts +583 -0
- package/src/rules/index.ts +277 -10
- package/src/rules/intent-propagation.ts +125 -0
- package/src/rules/layer-field-name-drift.ts +102 -0
- package/src/rules/library-projection-coherence.ts +100 -0
- package/src/rules/metadata.ts +871 -0
- package/src/rules/missing-reconcile.ts +97 -0
- package/src/rules/missing-visibility.ts +111 -0
- package/src/rules/no-destructured-compose.ts +196 -0
- package/src/rules/no-dev-permit-in-source.ts +99 -0
- package/src/rules/no-direct-implementation-call.ts +12 -7
- package/src/rules/no-legacy-cli-alias-export.ts +247 -0
- package/src/rules/no-legacy-layer-imports.ts +211 -0
- package/src/rules/no-native-error-result.ts +118 -0
- package/src/rules/no-redundant-result-error-wrap.ts +384 -0
- package/src/rules/no-retired-cross-vocabulary.ts +204 -0
- package/src/rules/no-sync-result-assumption.ts +1141 -98
- package/src/rules/no-throw-in-detour-recover.ts +225 -0
- package/src/rules/no-throw-in-implementation.ts +15 -8
- package/src/rules/no-top-level-surface.ts +371 -0
- package/src/rules/on-references-exist.ts +194 -0
- package/src/rules/orphaned-signal.ts +149 -0
- package/src/rules/owner-projection-parity.ts +143 -0
- package/src/rules/permit-governance.ts +25 -0
- package/src/rules/public-export-example-coverage.ts +573 -0
- package/src/rules/public-internal-deep-imports.ts +456 -0
- package/src/rules/public-output-schema.ts +29 -0
- package/src/rules/public-union-output-discriminants.ts +150 -0
- package/src/rules/read-intent-fires.ts +188 -0
- package/src/rules/reference-exists.ts +97 -0
- package/src/rules/registry-names.ts +167 -0
- package/src/rules/resolved-import-boundary.ts +146 -0
- package/src/rules/resource-declarations.ts +697 -0
- package/src/rules/resource-exists.ts +181 -0
- package/src/rules/resource-id-grammar.ts +65 -0
- package/src/rules/resource-mock-coverage.ts +115 -0
- package/src/rules/retired-vocabulary.ts +633 -0
- package/src/rules/scan.ts +38 -25
- package/src/rules/scheduled-destroy-intent.ts +44 -0
- package/src/rules/signal-graph-coaching.ts +220 -0
- package/src/rules/source/composition.ts +165 -0
- package/src/rules/source/drafts.ts +164 -0
- package/src/rules/source/entities.ts +618 -0
- package/src/rules/source/pragmas.ts +45 -0
- package/src/rules/source/resources.ts +64 -0
- package/src/rules/source/signals.ts +397 -0
- package/src/rules/source/stores.ts +310 -0
- package/src/rules/specs.ts +9 -5
- package/src/rules/static-resource-accessor-preference.ts +653 -0
- package/src/rules/surface-overlay-coherence.ts +262 -0
- package/src/rules/surface-trailhead-coherence.ts +366 -0
- package/src/rules/trail-fork-coaching.ts +625 -0
- package/src/rules/trail-versioning-source.ts +1076 -0
- package/src/rules/trail-versioning-topo.ts +172 -0
- package/src/rules/trailhead-override-divergence.ts +356 -0
- package/src/rules/types.ts +354 -8
- package/src/rules/unmaterialized-activation-source.ts +85 -0
- package/src/rules/unreachable-detour-shadowing.ts +339 -0
- package/src/rules/valid-describe-refs.ts +162 -32
- package/src/rules/valid-detour-contract.ts +78 -0
- package/src/rules/warden-export-symmetry.ts +540 -0
- package/src/rules/warden-rules-use-ast.ts +1109 -0
- package/src/rules/webhook-route-collision.ts +306 -0
- package/src/trails/activation-orphan.trail.ts +84 -0
- package/src/trails/captured-kernel.trail.ts +108 -0
- package/src/trails/circular-refs.trail.ts +29 -0
- package/src/trails/cli-command-route-coherence.trail.ts +47 -0
- package/src/trails/composes-declarations.trail.ts +22 -0
- package/src/trails/context-no-surface-types.trail.ts +21 -0
- package/src/trails/dead-internal-trail.trail.ts +26 -0
- package/src/trails/dead-public-trail.trail.ts +31 -0
- package/src/trails/deprecation-without-guidance.trail.ts +21 -0
- package/src/trails/draft-file-marking.trail.ts +16 -0
- package/src/trails/draft-visible-debt.trail.ts +16 -0
- package/src/trails/duplicate-exported-symbol.trail.ts +48 -0
- package/src/trails/duplicate-public-contract.trail.ts +47 -0
- package/src/trails/entity-exists.trail.ts +21 -0
- package/src/trails/error-mapping-completeness.trail.ts +30 -0
- package/src/trails/example-valid.trail.ts +25 -0
- package/src/trails/fires-declarations.trail.ts +23 -0
- package/src/trails/fork-without-preserved-implementation.trail.ts +31 -0
- package/src/trails/governed-symbol-residue.trail.ts +24 -0
- package/src/trails/implementation-returns-result.trail.ts +20 -0
- package/src/trails/incomplete-accessor-for-standard-op.trail.ts +76 -0
- package/src/trails/incomplete-crud.trail.ts +39 -0
- package/src/trails/index.ts +89 -0
- package/src/trails/intent-propagation.trail.ts +30 -0
- package/src/trails/layer-field-name-drift.trail.ts +39 -0
- package/src/trails/library-projection-coherence.trail.ts +43 -0
- package/src/trails/marker-schema-unsupported.trail.ts +23 -0
- package/src/trails/missing-reconcile.trail.ts +33 -0
- package/src/trails/missing-visibility.trail.ts +22 -0
- package/src/trails/no-destructured-compose.trail.ts +44 -0
- package/src/trails/no-dev-permit-in-source.trail.ts +16 -0
- package/src/trails/no-direct-implementation-call.trail.ts +16 -0
- package/src/trails/no-legacy-cli-alias-export.trail.ts +41 -0
- package/src/trails/no-legacy-layer-imports.trail.ts +41 -0
- package/src/trails/no-native-error-result.trail.ts +18 -0
- package/src/trails/no-redundant-result-error-wrap.trail.ts +55 -0
- package/src/trails/no-retired-cross-vocabulary.trail.ts +42 -0
- package/src/trails/no-sync-result-assumption.trail.ts +19 -0
- package/src/trails/no-throw-in-detour-recover.trail.ts +24 -0
- package/src/trails/no-throw-in-implementation.trail.ts +20 -0
- package/src/trails/no-top-level-surface.trail.ts +43 -0
- package/src/trails/on-references-exist.trail.ts +21 -0
- package/src/trails/orphaned-signal.trail.ts +36 -0
- package/src/trails/owner-projection-parity.trail.ts +26 -0
- package/src/trails/pending-force.trail.ts +21 -0
- package/src/trails/permit-governance.trail.ts +51 -0
- package/src/trails/prefer-schema-inference.trail.ts +21 -0
- package/src/trails/public-export-example-coverage.trail.ts +16 -0
- package/src/trails/public-internal-deep-imports.trail.ts +94 -0
- package/src/trails/public-output-schema.trail.ts +55 -0
- package/src/trails/public-union-output-discriminants.trail.ts +33 -0
- package/src/trails/read-intent-fires.trail.ts +20 -0
- package/src/trails/reference-exists.trail.ts +25 -0
- package/src/trails/resolved-import-boundary.trail.ts +109 -0
- package/src/trails/resource-declarations.trail.ts +25 -0
- package/src/trails/resource-exists.trail.ts +27 -0
- package/src/trails/resource-id-grammar.trail.ts +39 -0
- package/src/trails/resource-mock-coverage.trail.ts +40 -0
- package/src/trails/run.ts +160 -0
- package/src/trails/scheduled-destroy-intent.trail.ts +56 -0
- package/src/trails/schema.ts +237 -0
- package/src/trails/signal-graph-coaching.trail.ts +77 -0
- package/src/trails/static-resource-accessor-preference.trail.ts +25 -0
- package/src/trails/surface-overlay-coherence.trail.ts +24 -0
- package/src/trails/surface-trailhead-coherence.trail.ts +25 -0
- package/src/trails/topo.ts +6 -0
- package/src/trails/trail-fork-coaching.trail.ts +42 -0
- package/src/trails/trailhead-override-divergence.trail.ts +47 -0
- package/src/trails/unmaterialized-activation-source.trail.ts +72 -0
- package/src/trails/unreachable-detour-shadowing.trail.ts +45 -0
- package/src/trails/valid-describe-refs.trail.ts +18 -0
- package/src/trails/valid-detour-contract.trail.ts +71 -0
- package/src/trails/version-gap.trail.ts +35 -0
- package/src/trails/version-pinned-compose.trail.ts +23 -0
- package/src/trails/version-without-examples.trail.ts +38 -0
- package/src/trails/warden-export-symmetry.trail.ts +16 -0
- package/src/trails/warden-rules-use-ast.trail.ts +64 -0
- package/src/trails/webhook-route-collision.trail.ts +50 -0
- package/src/trails/wrap-rule.ts +224 -0
- package/src/workspaces.ts +199 -0
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/cli.d.ts +0 -46
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -218
- package/dist/cli.js.map +0 -1
- package/dist/drift.d.ts +0 -26
- package/dist/drift.d.ts.map +0 -1
- package/dist/drift.js +0 -27
- package/dist/drift.js.map +0 -1
- package/dist/formatters.d.ts +0 -29
- package/dist/formatters.d.ts.map +0 -1
- package/dist/formatters.js +0 -87
- package/dist/formatters.js.map +0 -1
- package/dist/index.d.ts +0 -26
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -26
- package/dist/index.js.map +0 -1
- package/dist/rules/ast.d.ts +0 -41
- package/dist/rules/ast.d.ts.map +0 -1
- package/dist/rules/ast.js +0 -161
- package/dist/rules/ast.js.map +0 -1
- package/dist/rules/context-no-surface-types.d.ts +0 -12
- package/dist/rules/context-no-surface-types.d.ts.map +0 -1
- package/dist/rules/context-no-surface-types.js +0 -96
- package/dist/rules/context-no-surface-types.js.map +0 -1
- package/dist/rules/implementation-returns-result.d.ts +0 -13
- package/dist/rules/implementation-returns-result.d.ts.map +0 -1
- package/dist/rules/implementation-returns-result.js +0 -277
- package/dist/rules/implementation-returns-result.js.map +0 -1
- package/dist/rules/index.d.ts +0 -15
- package/dist/rules/index.d.ts.map +0 -1
- package/dist/rules/index.js +0 -34
- package/dist/rules/index.js.map +0 -1
- package/dist/rules/no-direct-impl-in-route.d.ts +0 -12
- package/dist/rules/no-direct-impl-in-route.d.ts.map +0 -1
- package/dist/rules/no-direct-impl-in-route.js +0 -47
- package/dist/rules/no-direct-impl-in-route.js.map +0 -1
- package/dist/rules/no-direct-implementation-call.d.ts +0 -12
- package/dist/rules/no-direct-implementation-call.d.ts.map +0 -1
- package/dist/rules/no-direct-implementation-call.js +0 -39
- package/dist/rules/no-direct-implementation-call.js.map +0 -1
- package/dist/rules/no-sync-result-assumption.d.ts +0 -6
- package/dist/rules/no-sync-result-assumption.d.ts.map +0 -1
- package/dist/rules/no-sync-result-assumption.js +0 -98
- package/dist/rules/no-sync-result-assumption.js.map +0 -1
- package/dist/rules/no-throw-in-detour-target.d.ts +0 -12
- package/dist/rules/no-throw-in-detour-target.d.ts.map +0 -1
- package/dist/rules/no-throw-in-detour-target.js +0 -87
- package/dist/rules/no-throw-in-detour-target.js.map +0 -1
- package/dist/rules/no-throw-in-implementation.d.ts +0 -9
- package/dist/rules/no-throw-in-implementation.d.ts.map +0 -1
- package/dist/rules/no-throw-in-implementation.js +0 -34
- package/dist/rules/no-throw-in-implementation.js.map +0 -1
- package/dist/rules/prefer-schema-inference.d.ts +0 -7
- package/dist/rules/prefer-schema-inference.d.ts.map +0 -1
- package/dist/rules/prefer-schema-inference.js +0 -86
- package/dist/rules/prefer-schema-inference.js.map +0 -1
- package/dist/rules/scan.d.ts +0 -8
- package/dist/rules/scan.d.ts.map +0 -1
- package/dist/rules/scan.js +0 -32
- package/dist/rules/scan.js.map +0 -1
- package/dist/rules/specs.d.ts +0 -29
- package/dist/rules/specs.d.ts.map +0 -1
- package/dist/rules/specs.js +0 -192
- package/dist/rules/specs.js.map +0 -1
- package/dist/rules/structure.d.ts +0 -13
- package/dist/rules/structure.d.ts.map +0 -1
- package/dist/rules/structure.js +0 -142
- package/dist/rules/structure.js.map +0 -1
- package/dist/rules/types.d.ts +0 -52
- package/dist/rules/types.d.ts.map +0 -1
- package/dist/rules/types.js +0 -2
- package/dist/rules/types.js.map +0 -1
- package/dist/rules/valid-describe-refs.d.ts +0 -7
- package/dist/rules/valid-describe-refs.d.ts.map +0 -1
- package/dist/rules/valid-describe-refs.js +0 -51
- package/dist/rules/valid-describe-refs.js.map +0 -1
- package/dist/rules/valid-detour-refs.d.ts +0 -6
- package/dist/rules/valid-detour-refs.d.ts.map +0 -1
- package/dist/rules/valid-detour-refs.js +0 -116
- package/dist/rules/valid-detour-refs.js.map +0 -1
- package/src/__tests__/cli.test.ts +0 -198
- package/src/__tests__/drift.test.ts +0 -74
- package/src/__tests__/formatters.test.ts +0 -157
- package/src/__tests__/implementation-returns-result.test.ts +0 -129
- package/src/__tests__/no-direct-implementation-call.test.ts +0 -83
- package/src/__tests__/no-sync-result-assumption.test.ts +0 -85
- package/src/__tests__/no-throw-in-detour-target.test.ts +0 -78
- package/src/__tests__/prefer-schema-inference.test.ts +0 -84
- package/src/__tests__/rules.test.ts +0 -227
- package/src/__tests__/valid-describe-refs.test.ts +0 -60
- package/src/rules/ast.ts +0 -213
- package/src/rules/no-direct-impl-in-route.ts +0 -81
- package/src/rules/no-throw-in-detour-target.ts +0 -150
- package/src/rules/valid-detour-refs.ts +0 -187
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
# @ontrails/warden
|
|
2
2
|
|
|
3
|
-
AST-based code convention rules for Trails.
|
|
3
|
+
AST-based code convention rules for Trails. Built-in lint rules catch contract violations at development time, alongside lock drift detection and CI formatters.
|
|
4
4
|
|
|
5
|
-
Structural checks (
|
|
5
|
+
Structural checks (compose target existence, declared resource existence, recursive composition, example schema validation) live in `validateTopo()` from `@ontrails/core`. Warden handles the code-level rules that need AST analysis.
|
|
6
|
+
|
|
7
|
+
For rule-home boundaries and authoring doctrine, see the [Warden guide](../../docs/warden.md) and [Warden Rules](../../docs/contributing/warden-rules.md).
|
|
6
8
|
|
|
7
9
|
## Usage
|
|
8
10
|
|
|
9
11
|
From the Trails CLI:
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
|
-
trails warden
|
|
13
|
-
trails warden --exit-code # Non-zero exit on errors or drift
|
|
14
|
-
trails warden --lint-only # Skip drift detection
|
|
15
|
-
trails warden --drift-only # Skip lint rules
|
|
14
|
+
bunx trails warden # Run all checks
|
|
16
15
|
```
|
|
17
16
|
|
|
18
17
|
Or programmatically:
|
|
@@ -20,35 +19,89 @@ Or programmatically:
|
|
|
20
19
|
```typescript
|
|
21
20
|
import { runWarden, formatWardenReport } from '@ontrails/warden';
|
|
22
21
|
|
|
23
|
-
const report = await runWarden(
|
|
22
|
+
const report = await runWarden({ topo: graph });
|
|
24
23
|
console.log(formatWardenReport(report));
|
|
25
24
|
```
|
|
26
25
|
|
|
27
26
|
## Rules
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
Built-in rules are registered in `wardenRules` and `wardenTopoRules`; use those registries or `wardenTopo.ids()` for the current rule list instead of copying a static table into docs.
|
|
29
|
+
|
|
30
|
+
Rules cover several families:
|
|
31
|
+
|
|
32
|
+
- implementation and `Result` contract checks
|
|
33
|
+
- compose, fire, resource, and detour declaration drift
|
|
34
|
+
- draft-state containment
|
|
35
|
+
- source-static guardrails such as surface-type leakage
|
|
36
|
+
- topo-aware checks that need the resolved graph or resource mock shape
|
|
37
|
+
|
|
38
|
+
When adding or auditing rules, follow [Warden Rules](../../docs/contributing/warden-rules.md): name the invariant, import owner-held framework data, choose the narrowest Warden tier, and collapse families only when the data model, traversal, and diagnostic shape are shared.
|
|
39
|
+
|
|
40
|
+
## Project-local rules
|
|
41
|
+
|
|
42
|
+
Projects can carry local Warden rules in `.trails/rules.ts` or direct `.trails/rules/*.ts` files. `runWarden()` and `trails warden` load those files by default for lint runs, then run those rules alongside the built-in registries. Drift-only runs do not import project-local rule modules. Embedders that need only built-in or explicitly provided rules can pass `projectRules: false`.
|
|
43
|
+
|
|
44
|
+
Warden does not recursively discover nested `.trails/rules` files. Use nested files as private helpers and re-export from a direct entrypoint when a local rule grows. Rule ids must be unique across every project-local module. The retired `trails/warden/rules` location reports a migration diagnostic instead of loading.
|
|
45
|
+
|
|
46
|
+
Warden uses the shared Trails project-root resolver when a caller does not pass `rootDir` or `--root-dir`, so commands launched from nested directories still load the nearest root `trails.config.*` and its `.trails/rules*` files. An explicit root always wins over discovery.
|
|
47
|
+
|
|
48
|
+
This is the right home for repo-specific migration checks or governance that has not earned a place in `@ontrails/warden` itself.
|
|
49
|
+
|
|
50
|
+
## Scope
|
|
51
|
+
|
|
52
|
+
Use `warden.scope.exclude` in `trails.config.*` to keep generated, scratch, or local planning paths outside Warden governance while leaving durable project paths in scope.
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"warden": {
|
|
57
|
+
"scope": {
|
|
58
|
+
"exclude": [".scratch/**", ".agents/notes/**"]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For a single run, pass one or more root-relative globs:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
warden --scope-exclude '.scratch/**' --scope-exclude '.agents/notes/**'
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Scope is a governance boundary, not a migration scan boundary. Regrade uses its own `scope.exclude` / `--exclude` controls for migration plans.
|
|
71
|
+
|
|
72
|
+
A rule module may export `rule`, `rules`, `sourceRule`, `sourceRules`, `topoRule`, or `topoRules`. Rules without explicit metadata receive default repo-local source-static or topo-aware metadata so short migration rules can run without extra ceremony. Project-aware source rules that provide `checkWithContext()` default to repo-local project-static metadata.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
export const rule = {
|
|
76
|
+
name: 'local-contract-check',
|
|
77
|
+
severity: 'error',
|
|
78
|
+
description: 'Local contract examples keep their migration marker.',
|
|
79
|
+
check(sourceCode, filePath) {
|
|
80
|
+
return sourceCode.includes('deprecatedMarker')
|
|
81
|
+
? [
|
|
82
|
+
{
|
|
83
|
+
filePath,
|
|
84
|
+
line: 1,
|
|
85
|
+
message: 'Replace deprecatedMarker before release.',
|
|
86
|
+
rule: 'local-contract-check',
|
|
87
|
+
severity: 'error',
|
|
88
|
+
},
|
|
89
|
+
]
|
|
90
|
+
: [];
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
```
|
|
41
94
|
|
|
42
95
|
## Drift detection
|
|
43
96
|
|
|
44
|
-
Warden integrates with `@ontrails/
|
|
97
|
+
Warden integrates with `@ontrails/topography` to detect when the topo has changed without updating the lock file:
|
|
45
98
|
|
|
46
99
|
```typescript
|
|
47
100
|
import { checkDrift } from '@ontrails/warden';
|
|
48
101
|
|
|
49
|
-
const drift = await checkDrift(
|
|
102
|
+
const drift = await checkDrift(process.cwd(), graph);
|
|
50
103
|
if (drift.stale) {
|
|
51
|
-
console.log('
|
|
104
|
+
console.log('lock file is stale -- regenerate with `trails compile`');
|
|
52
105
|
}
|
|
53
106
|
```
|
|
54
107
|
|
|
@@ -60,27 +113,81 @@ Add to lefthook for pre-push enforcement:
|
|
|
60
113
|
pre-push:
|
|
61
114
|
commands:
|
|
62
115
|
warden:
|
|
63
|
-
run: trails warden
|
|
116
|
+
run: bunx trails warden
|
|
64
117
|
tags: governance
|
|
65
118
|
```
|
|
66
119
|
|
|
67
120
|
CI formatters for structured output:
|
|
68
121
|
|
|
69
122
|
```typescript
|
|
70
|
-
import {
|
|
123
|
+
import {
|
|
124
|
+
formatGitHubAnnotations,
|
|
125
|
+
formatJson,
|
|
126
|
+
formatSummary,
|
|
127
|
+
} from '@ontrails/warden';
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Reusable source-code parser helpers now live in `@ontrails/source`:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { findStringLiterals, parse, walk } from '@ontrails/source';
|
|
71
134
|
```
|
|
72
135
|
|
|
136
|
+
## Trail-based API
|
|
137
|
+
|
|
138
|
+
Every built-in warden rule is also available as a composable trail. This makes rules queryable, testable, and invocable through any Trails surface.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import {
|
|
142
|
+
runTopoAwareWardenTrails,
|
|
143
|
+
runWardenTrails,
|
|
144
|
+
wardenTopo,
|
|
145
|
+
} from '@ontrails/warden';
|
|
146
|
+
|
|
147
|
+
// Inspect the warden rule trails
|
|
148
|
+
console.log(wardenTopo.ids()); // ['warden.rule.no-throw-in-implementation', ...]
|
|
149
|
+
|
|
150
|
+
// Run all rule trails against a source file
|
|
151
|
+
const diagnostics = await runWardenTrails(filePath, sourceCode, {
|
|
152
|
+
knownTrailIds: myApp.ids(),
|
|
153
|
+
knownResourceIds: myApp.resourceIds(),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Run built-in topo-aware rule trails once against the resolved graph
|
|
157
|
+
const topoDiagnostics = await runTopoAwareWardenTrails(myApp);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
To wrap a custom rule as a trail, import `wrapRule` from the root package entrypoint:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { wrapRule } from '@ontrails/warden';
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
This is the same factory used internally to build all built-in rule trails.
|
|
167
|
+
|
|
73
168
|
## API
|
|
74
169
|
|
|
75
170
|
| Export | What it does |
|
|
76
171
|
| --- | --- |
|
|
77
|
-
| `runWarden(
|
|
172
|
+
| `runWarden(options?)` | Run all rules and drift checks, return a report |
|
|
78
173
|
| `formatWardenReport(report)` | Human-readable report |
|
|
79
|
-
| `checkDrift(
|
|
174
|
+
| `checkDrift(rootDir, topo?, options?)` | Check if the lock file matches the current topo; pass `{ overlays }` from the app module so the comparison graph carries the overlay content compile embeds. Stale results name `driftedOverlayNamespaces` when overlays diverge |
|
|
80
175
|
| `wardenRules` | Registry of all built-in rules |
|
|
176
|
+
| `builtinWardenRuleMetadata` | Tier, scope, lifecycle, and invariant metadata for built-in rules |
|
|
177
|
+
| `getWardenRuleMetadata(ruleOrName)` | Resolve inline or built-in metadata for a Warden rule |
|
|
178
|
+
| `listWardenRuleMetadata()` | List built-in rule metadata entries |
|
|
179
|
+
| `wardenTopo` | `Topo` of all built-in rule trails (one per rule) |
|
|
180
|
+
| `runWardenTrails(filePath, sourceCode, options?)` | Dispatch file-scoped rule trails for a file, collect diagnostics |
|
|
181
|
+
| `runTopoAwareWardenTrails(topo)` | Dispatch built-in topo-aware rule trails once for a resolved topo |
|
|
182
|
+
| `loadProjectWardenRules(rootDir)` | Load rule modules from `.trails/rules.ts` or direct `.trails/rules/*.ts` children |
|
|
81
183
|
| `formatGitHubAnnotations(report)` | GitHub Actions annotation format |
|
|
82
184
|
| `formatJson(report)` | Machine-readable JSON |
|
|
83
185
|
| `formatSummary(report)` | Compact summary line |
|
|
186
|
+
| `wrapRule(rule)` | Wrap a custom rule as a trail (same factory used for all built-in rule trails) |
|
|
187
|
+
|
|
188
|
+
Source-code parser helpers are owned by `@ontrails/source`, not the Warden root runtime barrel.
|
|
189
|
+
|
|
190
|
+
`runWarden({ tier })` can narrow a run to `source-static`, `project-static`, `topo-aware`, `drift`, or `advisory`. Omit `tier` for the default full run.
|
|
84
191
|
|
|
85
192
|
See the [API Reference](../../docs/api-reference.md) for the full list.
|
|
86
193
|
|
package/bin/warden.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/* oxlint-disable eslint-plugin-jest/require-hook -- CLI bin entrypoints execute at module scope */
|
|
3
|
+
|
|
4
|
+
import { runWardenCommand } from '../src/command.js';
|
|
5
|
+
|
|
6
|
+
const HELP = `Usage: warden [options]
|
|
7
|
+
|
|
8
|
+
Run Trails Warden governance checks.
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
--ci Apply CI defaults
|
|
12
|
+
--pre-push Apply pre-push defaults
|
|
13
|
+
--apps, -a <names> Comma-delimited Trails app names
|
|
14
|
+
--config-path <path> Path to trails.config.* file
|
|
15
|
+
--root-dir <path> Project root to inspect
|
|
16
|
+
--fix Apply safe source fixes
|
|
17
|
+
--adapter-check Include shared adapter authoring diagnostics
|
|
18
|
+
--depth <value> source, project, topo, or all
|
|
19
|
+
--fail-on <value> error or warning
|
|
20
|
+
--format <value> summary, github, or json
|
|
21
|
+
--drafts <value> include, exclude, or only
|
|
22
|
+
--scope-exclude <glob> Root-relative path glob Warden should not govern
|
|
23
|
+
--lock <value> auto, cached, refresh, or skip
|
|
24
|
+
--no-lock-mutation Do not write lock artifacts
|
|
25
|
+
--strict Fail on warnings
|
|
26
|
+
-h, --help Display help for command
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
const args = Bun.argv.slice(2);
|
|
30
|
+
if (args.includes('--help') || args.includes('-h') || args[0] === 'help') {
|
|
31
|
+
console.log(HELP);
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const env = { ...process.env } as Record<string, string | undefined>;
|
|
36
|
+
const result = await runWardenCommand({
|
|
37
|
+
args,
|
|
38
|
+
cwd: process.cwd(),
|
|
39
|
+
env,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (result.output.length > 0) {
|
|
43
|
+
console.log(result.output);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const summaryPath = env['GITHUB_STEP_SUMMARY'];
|
|
47
|
+
if (result.writeStepSummary && summaryPath !== undefined) {
|
|
48
|
+
await Bun.write(summaryPath, result.summary);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
process.exit(result.exitCode);
|
package/package.json
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontrails/warden",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.42",
|
|
4
|
+
"bin": {
|
|
5
|
+
"warden": "./bin/warden.ts"
|
|
6
|
+
},
|
|
7
|
+
"files": [
|
|
8
|
+
"bin/**/*.ts",
|
|
9
|
+
"src/**/*.ts",
|
|
10
|
+
"!src/**/__tests__/**",
|
|
11
|
+
"!src/**/*.test.ts",
|
|
12
|
+
"!src/**/*.test-d.ts",
|
|
13
|
+
"README.md",
|
|
14
|
+
"CHANGELOG.md"
|
|
15
|
+
],
|
|
4
16
|
"type": "module",
|
|
5
17
|
"exports": {
|
|
6
18
|
".": "./src/index.ts",
|
|
19
|
+
"./resolve": "./src/resolve.ts",
|
|
7
20
|
"./package.json": "./package.json"
|
|
8
21
|
},
|
|
9
22
|
"scripts": {
|
|
@@ -13,13 +26,21 @@
|
|
|
13
26
|
"lint": "oxlint ./src",
|
|
14
27
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
15
28
|
},
|
|
16
|
-
"
|
|
17
|
-
"@
|
|
18
|
-
"
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@ontrails/adapter-kit": "^1.0.0-beta.42",
|
|
31
|
+
"@ontrails/cli": "^1.0.0-beta.42",
|
|
32
|
+
"@ontrails/config": "^1.0.0-beta.42",
|
|
33
|
+
"@ontrails/permits": "^1.0.0-beta.42",
|
|
34
|
+
"@ontrails/source": "^1.0.0-beta.42",
|
|
35
|
+
"@ontrails/store": "^1.0.0-beta.42",
|
|
36
|
+
"oxc-resolver": "11.19.1",
|
|
19
37
|
"zod": "^4.3.5"
|
|
20
38
|
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@ontrails/testing": "^1.0.0-beta.42"
|
|
41
|
+
},
|
|
21
42
|
"peerDependencies": {
|
|
22
|
-
"@ontrails/core": "^1.0.0-beta.
|
|
23
|
-
"@ontrails/
|
|
43
|
+
"@ontrails/core": "^1.0.0-beta.42",
|
|
44
|
+
"@ontrails/topography": "^1.0.0-beta.42"
|
|
24
45
|
}
|
|
25
46
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Warden projection for shared adapter readiness checks.
|
|
3
|
+
*
|
|
4
|
+
* Adapter facts stay in @ontrails/adapter-kit. Warden only maps those facts
|
|
5
|
+
* into governance diagnostics and severity.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { checkAdapters } from '@ontrails/adapter-kit';
|
|
9
|
+
import type { AdapterCheckDiagnostic } from '@ontrails/adapter-kit';
|
|
10
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
|
|
13
|
+
import type { WardenDiagnostic } from './rules/types.js';
|
|
14
|
+
|
|
15
|
+
export const adapterCheckRuleName = 'adapter-check';
|
|
16
|
+
const adapterCheckRootCode = 'adapter-check-root';
|
|
17
|
+
|
|
18
|
+
const isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>
|
|
19
|
+
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
20
|
+
|
|
21
|
+
const toWardenDiagnostic = (
|
|
22
|
+
diagnostic: AdapterCheckDiagnostic
|
|
23
|
+
): WardenDiagnostic => ({
|
|
24
|
+
code: diagnostic.code,
|
|
25
|
+
filePath: diagnostic.packageJsonPath,
|
|
26
|
+
line: 1,
|
|
27
|
+
message: diagnostic.message,
|
|
28
|
+
rule: adapterCheckRuleName,
|
|
29
|
+
severity: 'warn',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const toRootDiagnostic = (
|
|
33
|
+
message: string,
|
|
34
|
+
filePath: string
|
|
35
|
+
): WardenDiagnostic => ({
|
|
36
|
+
code: adapterCheckRootCode,
|
|
37
|
+
filePath,
|
|
38
|
+
line: 1,
|
|
39
|
+
message,
|
|
40
|
+
rule: adapterCheckRuleName,
|
|
41
|
+
severity: 'error',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const workspacePatternsFromManifest = (
|
|
45
|
+
manifest: Readonly<Record<string, unknown>>
|
|
46
|
+
): readonly string[] => {
|
|
47
|
+
const { workspaces } = manifest;
|
|
48
|
+
if (Array.isArray(workspaces)) {
|
|
49
|
+
return workspaces.filter(
|
|
50
|
+
(pattern): pattern is string => typeof pattern === 'string'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const packages = isRecord(workspaces) ? workspaces['packages'] : undefined;
|
|
55
|
+
return Array.isArray(packages)
|
|
56
|
+
? packages.filter(
|
|
57
|
+
(pattern): pattern is string => typeof pattern === 'string'
|
|
58
|
+
)
|
|
59
|
+
: [];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const validateAdapterCheckRoot = (
|
|
63
|
+
rootDir: string
|
|
64
|
+
): readonly WardenDiagnostic[] => {
|
|
65
|
+
if (!existsSync(rootDir)) {
|
|
66
|
+
return [
|
|
67
|
+
toRootDiagnostic(
|
|
68
|
+
`adapter.check rootDir does not exist: "${rootDir}"`,
|
|
69
|
+
rootDir
|
|
70
|
+
),
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!statSync(rootDir).isDirectory()) {
|
|
75
|
+
return [
|
|
76
|
+
toRootDiagnostic(
|
|
77
|
+
`adapter.check rootDir must be a directory: "${rootDir}"`,
|
|
78
|
+
rootDir
|
|
79
|
+
),
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const packageJsonPath = join(rootDir, 'package.json');
|
|
84
|
+
if (!existsSync(packageJsonPath)) {
|
|
85
|
+
return [
|
|
86
|
+
toRootDiagnostic(
|
|
87
|
+
`adapter.check rootDir must contain a package.json workspace manifest: "${packageJsonPath}"`,
|
|
88
|
+
packageJsonPath
|
|
89
|
+
),
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let manifest: unknown;
|
|
94
|
+
try {
|
|
95
|
+
manifest = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const reason = error instanceof Error ? `: ${error.message}` : '';
|
|
98
|
+
return [
|
|
99
|
+
toRootDiagnostic(
|
|
100
|
+
`adapter.check could not read root package.json: "${packageJsonPath}"${reason}`,
|
|
101
|
+
packageJsonPath
|
|
102
|
+
),
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!isRecord(manifest)) {
|
|
107
|
+
return [
|
|
108
|
+
toRootDiagnostic(
|
|
109
|
+
`adapter.check root package.json must contain a JSON object: "${packageJsonPath}"`,
|
|
110
|
+
packageJsonPath
|
|
111
|
+
),
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (workspacePatternsFromManifest(manifest).length === 0) {
|
|
116
|
+
return [
|
|
117
|
+
toRootDiagnostic(
|
|
118
|
+
`adapter.check root package.json must declare workspace packages: "${packageJsonPath}"`,
|
|
119
|
+
packageJsonPath
|
|
120
|
+
),
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return [];
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const runWardenAdapterChecks = (
|
|
128
|
+
rootDir: string
|
|
129
|
+
): readonly WardenDiagnostic[] => {
|
|
130
|
+
const rootDiagnostics = validateAdapterCheckRoot(rootDir);
|
|
131
|
+
if (rootDiagnostics.length > 0) {
|
|
132
|
+
return rootDiagnostics;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return checkAdapters(rootDir).diagnostics.map(toWardenDiagnostic);
|
|
136
|
+
};
|