@starci/eslint-canon-be 3.8.20 → 3.9.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 (164) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -1,6 +1,5 @@
1
1
  import { byCodeUnit } from '../../lib/list.mjs';
2
2
  import { registryListImport, registrySlot } from './entity-registry.mjs';
3
-
4
3
  /**
5
4
  * HFS checks 1 and 2 (knowledge/hfs/slots.yaml `tiers`):
6
5
  * 1. the tier direction matrix: every import, re-export and type-only import between two owners must go from a tier to
@@ -16,193 +15,201 @@ import { registryListImport, registrySlot } from './entity-registry.mjs';
16
15
  * Importing inside one owner is always allowed; the public-entry rule stays with owners.mjs (ARCH_OWNER_EXPORT_BYPASS).
17
16
  */
18
17
  export const TIER_RULE_IDS = ['BE_TIER_DIRECTION', 'BE_FEATURE_IMPORTS_FEATURE', 'BE_KIND_ISOLATION', 'BE_SERVICE_ISOLATION', 'FE_TIER_DIRECTION', 'FE_APP_ISOLATION', 'ARCH_OWNER_CYCLE'];
19
-
20
18
  function tierDirectionText({ fromTier, toTier, mayImport, kindRestriction, fromKind, toKind }) {
21
- if (!kindRestriction) return `a ${fromTier} may import only ${mayImport.join(', ') || 'nothing'}; it imports a ${toTier}`;
22
- const source = fromKind ?? 'no folder kind';
23
- const target = toKind ?? 'no folder kind';
24
- return `a ${fromTier} may import ${toTier} owners only from kinds ${kindRestriction.from.join(', ')} to kinds ${kindRestriction.to.join(', ')}; it imports ${source} -> ${target}`;
19
+ if (!kindRestriction)
20
+ return `a ${fromTier} may import only ${mayImport.join(', ') || 'nothing'}; it imports a ${toTier}`;
21
+ const source = fromKind ?? 'no folder kind';
22
+ const target = toKind ?? 'no folder kind';
23
+ return `a ${fromTier} may import ${toTier} owners only from kinds ${kindRestriction.from.join(', ')} to kinds ${kindRestriction.to.join(', ')}; it imports ${source} -> ${target}`;
25
24
  }
26
-
27
25
  const REASON_TEXT = {
28
- tierDirection: tierDirectionText,
29
- layerOrder: ({ fromLayer, toLayer }) => `a ${fromLayer} component may import only the layers after it; it imports a ${toLayer}`,
30
- crossApp: ({ from, to }) => `app ${from} imports app ${to}; apps never import each other, shared code is a packages/<pkg> slot`,
26
+ tierDirection: tierDirectionText,
27
+ layerOrder: ({ fromLayer, toLayer }) => `a ${fromLayer} component may import only the layers after it; it imports a ${toLayer}`,
28
+ crossApp: ({ from, to }) => `app ${from} imports app ${to}; apps never import each other, shared code is a packages/<pkg> slot`,
31
29
  };
32
-
33
30
  /** Strongly connected components (Tarjan, iterative) of `adjacency` (Map<node, Set<node>>); components of one node are dropped. */
34
31
  function startTraversal(state, adjacency, node) {
35
- const at = state.counter;
36
- state.counter += 1;
37
- state.index.set(node, at);
38
- state.low.set(node, at);
39
- state.stack.push(node);
40
- state.onStack.add(node);
41
- state.work.push({ node, iterator: adjacency.get(node)[Symbol.iterator]() });
32
+ const at = state.counter;
33
+ state.counter += 1;
34
+ state.index.set(node, at);
35
+ state.low.set(node, at);
36
+ state.stack.push(node);
37
+ state.onStack.add(node);
38
+ state.work.push({ node, iterator: adjacency.get(node)[Symbol.iterator]() });
42
39
  }
43
-
44
40
  function visitTarget(state, adjacency, frame, target) {
45
- if (!adjacency.has(target)) return;
46
- if (!state.index.has(target)) {
47
- startTraversal(state, adjacency, target);
48
- return;
49
- }
50
- if (state.onStack.has(target)) state.low.set(frame.node, Math.min(state.low.get(frame.node), state.index.get(target)));
41
+ if (!adjacency.has(target))
42
+ return;
43
+ if (!state.index.has(target)) {
44
+ startTraversal(state, adjacency, target);
45
+ return;
46
+ }
47
+ if (state.onStack.has(target))
48
+ state.low.set(frame.node, Math.min(state.low.get(frame.node), state.index.get(target)));
51
49
  }
52
-
53
50
  function closeComponent(state, frame) {
54
- const component = [];
55
- let member;
56
- do {
57
- member = state.stack.pop();
58
- state.onStack.delete(member);
59
- component.push(member);
60
- } while (member !== frame.node);
61
- if (component.length > 1) state.result.push(component);
51
+ const component = [];
52
+ let member;
53
+ do {
54
+ member = state.stack.pop();
55
+ state.onStack.delete(member);
56
+ component.push(member);
57
+ } while (member !== frame.node);
58
+ if (component.length > 1)
59
+ state.result.push(component);
62
60
  }
63
-
64
61
  function finishFrame(state, frame) {
65
- state.work.pop();
66
- if (state.work.length) {
67
- const parent = state.work.at(-1).node;
68
- state.low.set(parent, Math.min(state.low.get(parent), state.low.get(frame.node)));
69
- }
70
- if (state.low.get(frame.node) === state.index.get(frame.node)) closeComponent(state, frame);
62
+ state.work.pop();
63
+ if (state.work.length) {
64
+ const parent = state.work.at(-1).node;
65
+ state.low.set(parent, Math.min(state.low.get(parent), state.low.get(frame.node)));
66
+ }
67
+ if (state.low.get(frame.node) === state.index.get(frame.node))
68
+ closeComponent(state, frame);
71
69
  }
72
-
73
70
  function stronglyConnected(adjacency) {
74
- const state = { counter: 0, index: new Map(), low: new Map(), onStack: new Set(), stack: [], result: [], work: [] };
75
- for (const start of adjacency.keys()) {
76
- if (state.index.has(start)) continue;
77
- startTraversal(state, adjacency, start);
78
- for (let frame = state.work.at(-1); frame; frame = state.work.at(-1)) {
79
- const next = frame.iterator.next();
80
- if (next.done) {
81
- finishFrame(state, frame);
82
- continue;
83
- }
84
- visitTarget(state, adjacency, frame, next.value);
71
+ const state = { counter: 0, index: new Map(), low: new Map(), onStack: new Set(), stack: [], result: [], work: [] };
72
+ for (const start of adjacency.keys()) {
73
+ if (state.index.has(start))
74
+ continue;
75
+ startTraversal(state, adjacency, start);
76
+ for (let frame = state.work.at(-1); frame; frame = state.work.at(-1)) {
77
+ const next = frame.iterator.next();
78
+ if (next.done) {
79
+ finishFrame(state, frame);
80
+ continue;
81
+ }
82
+ visitTarget(state, adjacency, frame, next.value);
83
+ }
85
84
  }
86
- }
87
- return state.result;
85
+ return state.result;
88
86
  }
89
-
90
87
  /** A shortest cycle through `origin` inside `members`, as a node path that starts and ends at origin. */
91
88
  function cycleThrough(adjacency, members, origin) {
92
- const queue = [[origin]];
93
- const seen = new Set();
94
- while (queue.length) {
95
- const trail = queue.shift();
96
- for (const next of adjacency.get(trail.at(-1)) ?? []) {
97
- if (!members.has(next)) continue;
98
- if (next === origin) return [...trail, origin];
99
- if (seen.has(next)) continue;
100
- seen.add(next);
101
- queue.push([...trail, next]);
89
+ const queue = [[origin]];
90
+ const seen = new Set();
91
+ while (queue.length) {
92
+ const trail = queue.shift();
93
+ for (const next of adjacency.get(trail.at(-1)) ?? []) {
94
+ if (!members.has(next))
95
+ continue;
96
+ if (next === origin)
97
+ return [...trail, origin];
98
+ if (seen.has(next))
99
+ continue;
100
+ seen.add(next);
101
+ queue.push([...trail, next]);
102
+ }
102
103
  }
103
- }
104
- return [origin, origin];
104
+ return [origin, origin];
105
105
  }
106
-
107
106
  /** The trigger kind (slot field `trigger`) of the owner that holds `file`, or null when its owner's slot names none. */
108
107
  const triggerOf = (resolver, file) => {
109
- const owner = resolver.ownerOf(file);
110
- return owner ? (resolver.slot(owner.slot)?.trigger ?? null) : null;
108
+ const owner = resolver.ownerOf(file);
109
+ return owner ? (resolver.slot(owner.slot)?.trigger ?? null) : null;
111
110
  };
112
-
113
- function reportReasonedTierViolation(graph, edge, verdict, tierRule, counts, violations) {
114
- if (verdict.allowed || !REASON_TEXT[verdict.reason]) return;
115
- counts[verdict.reason] += 1;
116
- const featureToFeature = graph.profile === 'be' && verdict.reason === 'tierDirection' && verdict.fromTier === 'feature' && verdict.toTier === 'feature';
117
- const fromKind = featureToFeature ? triggerOf(graph.resolver, edge.from) : null;
118
- const toKind = featureToFeature ? triggerOf(graph.resolver, edge.to) : null;
119
- const crossKind = fromKind !== null && toKind !== null && fromKind !== toKind;
120
- let ruleId = tierRule;
121
- if (featureToFeature) ruleId = 'BE_FEATURE_IMPORTS_FEATURE';
122
- if (crossKind) ruleId = 'BE_KIND_ISOLATION';
123
- if (verdict.reason === 'crossApp') ruleId = graph.profile === 'be' ? 'BE_SERVICE_ISOLATION' : 'FE_APP_ISOLATION';
124
- const typeOnly = edge.runtime ? '' : ' (type-only imports count)';
125
- const message = crossKind
126
- ? `${edge.from} -> ${edge.to}: a ${fromKind} feature imports a ${toKind} feature; no kind imports another, every cross-kind call is an event published with eventBus.publish(event, tx) from a domain service${typeOnly}.`
127
- : `${edge.from} -> ${edge.to}: ${REASON_TEXT[verdict.reason](verdict)}${typeOnly}.`;
128
- violations.push({
129
- ruleId,
130
- path: edge.from, line: edge.line, column: edge.column,
131
- specifier: edge.specifier, resolvedPath: edge.to, typeOnly: !edge.runtime,
132
- fromTier: verdict.fromTier ?? null, toTier: verdict.toTier ?? null,
133
- message,
134
- });
111
+ function reportReasonedTierViolation(graph, edge, answer, tierRule, counts, violations) {
112
+ // reason: importAllowed carries the details of REASON_TEXT's reasons (tierDirection, layerOrder, crossApp) as the TierVerdict fields; any other reason returns below
113
+ const verdict = answer;
114
+ const reason = verdict.reason ?? '';
115
+ const describe = REASON_TEXT[reason];
116
+ if (verdict.allowed || !describe)
117
+ return;
118
+ counts[reason] = (counts[reason] ?? 0) + 1;
119
+ const featureToFeature = graph.profile === 'be' && verdict.reason === 'tierDirection' && verdict.fromTier === 'feature' && verdict.toTier === 'feature';
120
+ const fromKind = featureToFeature ? triggerOf(graph.resolver, edge.from) : null;
121
+ const toKind = featureToFeature ? triggerOf(graph.resolver, edge.to) : null;
122
+ const crossKind = fromKind !== null && toKind !== null && fromKind !== toKind;
123
+ let ruleId = tierRule;
124
+ if (featureToFeature)
125
+ ruleId = 'BE_FEATURE_IMPORTS_FEATURE';
126
+ if (crossKind)
127
+ ruleId = 'BE_KIND_ISOLATION';
128
+ if (verdict.reason === 'crossApp')
129
+ ruleId = graph.profile === 'be' ? 'BE_SERVICE_ISOLATION' : 'FE_APP_ISOLATION';
130
+ const typeOnly = edge.runtime ? '' : ' (type-only imports count)';
131
+ const message = crossKind
132
+ ? `${edge.from} -> ${edge.to}: a ${fromKind} feature imports a ${toKind} feature; no kind imports another, every cross-kind call is an event published with eventBus.publish(event, tx) from a domain service${typeOnly}.`
133
+ : `${edge.from} -> ${edge.to}: ${describe(verdict)}${typeOnly}.`;
134
+ violations.push({
135
+ ruleId,
136
+ path: edge.from, line: edge.line, column: edge.column,
137
+ specifier: edge.specifier, resolvedPath: edge.to, typeOnly: !edge.runtime,
138
+ fromTier: verdict.fromTier ?? null, toTier: verdict.toTier ?? null,
139
+ message,
140
+ });
135
141
  }
136
-
137
142
  function inspectTierEdge(graph, edge, tierRule, counts, violations, coverage) {
138
- const verdict = graph.resolver.importAllowed(edge.from, edge.to);
139
- if (verdict.reason === 'unowned' || verdict.reason?.startsWith('slot')) {
140
- coverage.unclassifiedEdges += 1;
141
- return;
142
- }
143
- coverage.edgesChecked += 1;
144
- if (verdict.reason === 'tierDirection' && registryListImport(graph.resolver, edge)) return;
145
- reportReasonedTierViolation(graph, edge, verdict, tierRule, counts, violations);
143
+ const verdict = graph.resolver.importAllowed(edge.from, edge.to);
144
+ if (verdict.reason === 'unowned' || verdict.reason?.startsWith('slot')) {
145
+ coverage.unclassifiedEdges += 1;
146
+ return;
147
+ }
148
+ coverage.edgesChecked += 1;
149
+ if (verdict.reason === 'tierDirection' && registryListImport(graph.resolver, edge))
150
+ return;
151
+ reportReasonedTierViolation(graph, edge, verdict, tierRule, counts, violations);
146
152
  }
147
-
148
153
  /**
149
154
  * The cycle unit of a file: its owner unit, except the entity registry (entity-registry.mjs), which is a unit of its own. It sits in
150
155
  * platform/database but is composition-level by role (it imports every capability's `<c>Entities`), so it never closes a cycle
151
156
  * among capabilities through the owner it lives in.
152
157
  */
153
158
  const cycleUnit = (graph, resolver, rel) => (registrySlot(resolver, rel) ? `entity-registry:${rel}` : graph.unit(rel));
154
-
155
159
  function ownerAdjacency(graph, resolver) {
156
- const adjacency = new Map();
157
- const witness = new Map();
158
- for (const edge of graph.edges) {
159
- const a = cycleUnit(graph, resolver, edge.from);
160
- const b = cycleUnit(graph, resolver, edge.to);
161
- if (!a || !b || a === b) continue;
162
- if (resolver.tierOf(edge.from) === 'none' || resolver.tierOf(edge.to) === 'none') continue;
163
- if (!adjacency.has(a)) adjacency.set(a, new Set());
164
- if (!adjacency.has(b)) adjacency.set(b, new Set());
165
- adjacency.get(a).add(b);
166
- if (!witness.has(`${a}\0${b}`)) witness.set(`${a}\0${b}`, edge);
167
- }
168
- return { adjacency, witness };
160
+ const adjacency = new Map();
161
+ const witness = new Map();
162
+ for (const edge of graph.edges) {
163
+ const a = cycleUnit(graph, resolver, edge.from);
164
+ const b = cycleUnit(graph, resolver, edge.to);
165
+ if (!a || !b || a === b)
166
+ continue;
167
+ if (resolver.tierOf(edge.from) === 'none' || resolver.tierOf(edge.to) === 'none')
168
+ continue;
169
+ if (!adjacency.has(a))
170
+ adjacency.set(a, new Set());
171
+ if (!adjacency.has(b))
172
+ adjacency.set(b, new Set());
173
+ adjacency.get(a).add(b);
174
+ if (!witness.has(`${a}\0${b}`))
175
+ witness.set(`${a}\0${b}`, edge);
176
+ }
177
+ return { adjacency, witness };
169
178
  }
170
-
171
- function addOwnerCycleViolations(graph, adjacency, witness, violations) {
172
- const components = stronglyConnected(adjacency);
173
- for (const component of components) {
174
- const members = new Set(component);
175
- const origin = [...component].sort(byCodeUnit)[0];
176
- const cycle = cycleThrough(adjacency, members, origin);
177
- const hops = cycle.slice(0, -1).map((unit, i) => witness.get(`${unit}\0${cycle[i + 1]}`));
178
- const label = unit => unit.slice(unit.indexOf(':') + 1) || unit;
179
- const first = hops[0];
180
- const connectedOwners = component.length > cycle.length - 1 ? ` (strongly connected with ${component.length} owners)` : '';
181
- violations.push({
182
- ruleId: 'ARCH_OWNER_CYCLE',
183
- path: first.from, line: first.line, column: first.column,
184
- cycle: cycle.map(label),
185
- cycleImports: hops.map(hop => ({ path: hop.from, line: hop.line, specifier: hop.specifier, typeOnly: !hop.runtime })),
186
- componentSize: component.length,
187
- message: `Owner cycle: ${cycle.map(label).join(' -> ')}${connectedOwners}; type-only imports count.`,
188
- });
189
- }
190
- return components.length;
179
+ function addOwnerCycleViolations(adjacency, witness, violations) {
180
+ const components = stronglyConnected(adjacency);
181
+ for (const component of components) {
182
+ const members = new Set(component);
183
+ const origin = [...component].sort(byCodeUnit)[0];
184
+ const cycle = cycleThrough(adjacency, members, origin);
185
+ const hops = cycle.slice(0, -1).map((unit, i) => witness.get(`${unit}\0${cycle[i + 1]}`));
186
+ const label = (unit) => unit.slice(unit.indexOf(':') + 1) || unit;
187
+ const first = hops[0];
188
+ const connectedOwners = component.length > cycle.length - 1 ? ` (strongly connected with ${component.length} owners)` : '';
189
+ violations.push({
190
+ ruleId: 'ARCH_OWNER_CYCLE',
191
+ path: first.from, line: first.line, column: first.column,
192
+ cycle: cycle.map(label),
193
+ cycleImports: hops.map((hop) => ({ path: hop.from, line: hop.line, specifier: hop.specifier, typeOnly: !hop.runtime })),
194
+ componentSize: component.length,
195
+ message: `Owner cycle: ${cycle.map(label).join(' -> ')}${connectedOwners}; type-only imports count.`,
196
+ });
197
+ }
198
+ return components.length;
191
199
  }
192
-
193
200
  export function checkTiers(graph) {
194
- const { resolver, profile } = graph;
195
- const violations = [];
196
- const tierRule = profile === 'be' ? 'BE_TIER_DIRECTION' : 'FE_TIER_DIRECTION';
197
- const coverage = { edgesChecked: 0, unclassifiedEdges: 0 };
198
- const counts = { tierDirection: 0, layerOrder: 0, crossApp: 0 };
199
- for (const edge of graph.edges) inspectTierEdge(graph, edge, tierRule, counts, violations, coverage);
200
-
201
- // Owner cycles: nodes are owner units, edges the imports between two distinct units.
202
- const { adjacency, witness } = ownerAdjacency(graph, resolver);
203
- const cycles = addOwnerCycleViolations(graph, adjacency, witness, violations);
204
- return {
205
- violations,
206
- coverage: { status: 'checked', ...coverage, ownerUnits: adjacency.size, cycles, ...counts },
207
- };
201
+ const { resolver, profile } = graph;
202
+ const violations = [];
203
+ const tierRule = profile === 'be' ? 'BE_TIER_DIRECTION' : 'FE_TIER_DIRECTION';
204
+ const coverage = { edgesChecked: 0, unclassifiedEdges: 0 };
205
+ const counts = { tierDirection: 0, layerOrder: 0, crossApp: 0 };
206
+ for (const edge of graph.edges)
207
+ inspectTierEdge(graph, edge, tierRule, counts, violations, coverage);
208
+ // Owner cycles: nodes are owner units, edges the imports between two distinct units.
209
+ const { adjacency, witness } = ownerAdjacency(graph, resolver);
210
+ const cycles = addOwnerCycleViolations(adjacency, witness, violations);
211
+ return {
212
+ violations,
213
+ coverage: { status: 'checked', ...coverage, ownerUnits: adjacency.size, cycles, ...counts },
214
+ };
208
215
  }