@starci/eslint-canon-be 3.18.4 → 3.19.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 (208) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/comments.js +1 -1
  3. package/dist/explicit-surface.js +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/jwt-alg.js +1 -1
  6. package/dist/lib/edition.d.ts +1 -1
  7. package/dist/lib/edition.js +1 -1
  8. package/dist/lib/hfs.d.ts +0 -6
  9. package/dist/lib/hfs.js +7 -5
  10. package/dist/lib/runtime-root.d.ts +6 -1
  11. package/dist/lib/runtime-root.js +8 -2
  12. package/dist/lib/subject-values.js +1 -1
  13. package/dist/module-layering.js +2 -2
  14. package/dist/project-graph.js +1 -1
  15. package/dist/third-party-owner.js +1 -1
  16. package/package.json +3 -1
  17. package/runtime/bundle.json +1 -190
  18. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  19. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  20. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  21. package/runtime/config.example.yaml +0 -194
  22. package/runtime/engine/by-code-unit.mjs +0 -12
  23. package/runtime/engine/config.mjs +0 -461
  24. package/runtime/engine/invalid-config.mjs +0 -15
  25. package/runtime/engine/model-config.mjs +0 -112
  26. package/runtime/engine/orca-config.mjs +0 -34
  27. package/runtime/engine/plain-object.mjs +0 -5
  28. package/runtime/engine/release-config.mjs +0 -32
  29. package/runtime/engine/removed-vocabulary.mjs +0 -27
  30. package/runtime/engine/resources-config.mjs +0 -59
  31. package/runtime/engine/runtime-root.mjs +0 -138
  32. package/runtime/engine/secrets.mjs +0 -202
  33. package/runtime/engine/sonar-config.mjs +0 -24
  34. package/runtime/engine/temp-root.mjs +0 -26
  35. package/runtime/engine/yaml.mjs +0 -161
  36. package/runtime/knowledge/grammars/index.yaml +0 -114
  37. package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
  38. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  39. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  40. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  41. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  42. package/runtime/knowledge/sonar-gate.yaml +0 -151
  43. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  44. package/runtime/modules/models/registry.yaml +0 -221
  45. package/runtime/modules/models/runtimes.yaml +0 -556
  46. package/runtime/modules/models/tiers.yaml +0 -66
  47. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  48. package/runtime/scripts/api/git/config-get.mjs +0 -9
  49. package/runtime/scripts/api/git/diff.mjs +0 -4
  50. package/runtime/scripts/api/git/lib.mjs +0 -80
  51. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  52. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  53. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  54. package/runtime/scripts/api/git/remote.mjs +0 -4
  55. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  56. package/runtime/scripts/api/git/show.mjs +0 -5
  57. package/runtime/scripts/api/git/tag.mjs +0 -4
  58. package/runtime/scripts/hfs/allows.mjs +0 -77
  59. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  60. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  61. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  62. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  63. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  64. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  65. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  66. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  67. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  68. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  69. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  70. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  71. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  72. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  73. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  74. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  75. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  76. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  77. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  78. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  79. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  80. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  81. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  82. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  83. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  84. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  85. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  86. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  87. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  88. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  89. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  90. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  91. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  92. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  93. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  94. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  95. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  96. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  97. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  98. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  99. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  100. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  101. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  102. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  103. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  104. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  105. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  106. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  107. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  108. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  109. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  110. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  111. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  112. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  113. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  114. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  115. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  116. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  117. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  118. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  119. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  120. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  121. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  122. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  123. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  124. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  125. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  126. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  127. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  128. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  129. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  130. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  132. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  133. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  134. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  135. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  136. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  137. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  138. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  139. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  140. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  141. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  142. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  143. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  144. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  145. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  146. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  147. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  148. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  149. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  150. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  151. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  152. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  153. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  154. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  155. package/runtime/scripts/hfs/param-names.mjs +0 -13
  156. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  157. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  158. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  159. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  160. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  161. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  162. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  163. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  164. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  165. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  166. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  167. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  168. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  169. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  170. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  171. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  172. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  173. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  174. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  175. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  176. package/runtime/scripts/hfs/slots.mjs +0 -306
  177. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  178. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  179. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  180. package/runtime/scripts/hfs/view.mjs +0 -180
  181. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  182. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  183. package/runtime/scripts/lib/env.mjs +0 -18
  184. package/runtime/scripts/lib/event-contract.mjs +0 -102
  185. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  186. package/runtime/scripts/lib/git.mjs +0 -35
  187. package/runtime/scripts/lib/glob.mjs +0 -32
  188. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  189. package/runtime/scripts/lib/i18n.mjs +0 -82
  190. package/runtime/scripts/lib/in-order.mjs +0 -90
  191. package/runtime/scripts/lib/json-clone.mjs +0 -70
  192. package/runtime/scripts/lib/json.mjs +0 -44
  193. package/runtime/scripts/lib/language.mjs +0 -233
  194. package/runtime/scripts/lib/list.mjs +0 -26
  195. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  196. package/runtime/scripts/lib/package-at.mjs +0 -62
  197. package/runtime/scripts/lib/path-key.mjs +0 -124
  198. package/runtime/scripts/lib/read-text.mjs +0 -47
  199. package/runtime/scripts/lib/regex.mjs +0 -3
  200. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  201. package/runtime/scripts/lib/same-text.mjs +0 -4
  202. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  203. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  204. package/runtime/scripts/lib/stack-services.mjs +0 -191
  205. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  206. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  207. package/runtime/scripts/lib/walk.mjs +0 -45
  208. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,237 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { lsFiles } from '../../api/git/ls-files.mjs';
4
- import { revParseQuery } from '../../api/git/rev-parse-query.mjs';
5
- import { gitOutputOf } from '../../lib/git.mjs';
6
- import { trimTrailingSlashes } from '../trailing-slashes.mjs';
7
- import { requiredFileApplies } from '../slot-required.mjs';
8
- /**
9
- * HFS check 5: the files and directories the slot manifest requires (knowledge/hfs/slots.yaml `requires`,
10
- * `requiredInstances`, `minInstances`, required app kinds) must exist in the repository tree. Everything is read through the
11
- * resolver of scripts/hfs/slots.mjs; nothing here names a path.
12
- *
13
- * FE_ERROR_BOUNDARY_MISSING a fe.app.next app lacks global-error, error, not-found or loading under src/app
14
- * HFS_REQUIRED_FILE_MISSING any other required file or directory of any slot (backend app, feature, domain, integrations and
15
- * platform instances, a required platform instance such as config or logging, packages, fe modules,
16
- * i18n, api ...), and a minimum (no api app, no feature, no next app) which is reported once at hfs.json
17
- *
18
- * Slots of tier none (README, root config, .starciwork, .starcistacks) belong to the slot check; fe.app.next is the one
19
- * tier-none slot judged here. The tree is the tracked one (`git ls-files` from the repository root, minus files deleted
20
- * on disk), else the filesystem without node_modules, .git, dist and .next.
21
- */
22
- export const REQUIRED_FILE_RULE_IDS = ['FE_ERROR_BOUNDARY_MISSING', 'HFS_REQUIRED_FILE_MISSING'];
23
- const SKIPPED_DIRECTORIES = new Set(['node_modules', '.git', 'dist', '.next']);
24
- const ERROR_BOUNDARY_FILE = /^(?:global-error|error|not-found|loading)\.tsx$/u;
25
- const ALSO_JUDGED_TIER_NONE = new Set(['fe.app.next']);
26
- function gitFiles(root) {
27
- try {
28
- // gitOutputOf threw unless git exited 0, whose stdout is text
29
- const run = (call, args) => gitOutputOf(call(args, { cwd: root, maxBuffer: 256 * 1024 * 1024 }));
30
- run(revParseQuery, ['--is-inside-work-tree']);
31
- const deleted = new Set(run(lsFiles, ['--deleted', '-z', '--', '.']).split('\0').filter(Boolean));
32
- return run(lsFiles, ['--cached', '-z', '--', '.']).split('\0').filter(file => file && !deleted.has(file));
33
- }
34
- catch {
35
- return null;
36
- }
37
- }
38
- function diskFiles(root, relative = '') {
39
- const out = [];
40
- let entries;
41
- try {
42
- entries = fs.readdirSync(path.join(root, ...relative.split('/').filter(Boolean)), { withFileTypes: true });
43
- }
44
- catch {
45
- return out;
46
- }
47
- for (const entry of entries) {
48
- if (SKIPPED_DIRECTORIES.has(entry.name))
49
- continue;
50
- const child = relative ? `${relative}/${entry.name}` : entry.name;
51
- if (entry.isDirectory())
52
- out.push(...diskFiles(root, child));
53
- else
54
- out.push(child);
55
- }
56
- return out;
57
- }
58
- let runTrees = null;
59
- /** Runs `run` with one tree read per root: every checker of one machine run shares the repository listing instead of spawning git again. */
60
- export function withTreeCache(run) {
61
- const outer = runTrees;
62
- runTrees = outer ?? new Map();
63
- try {
64
- return run();
65
- }
66
- finally {
67
- runTrees = outer;
68
- }
69
- }
70
- function readTree(root) {
71
- const list = gitFiles(root) ?? diskFiles(root);
72
- const files = new Set(list);
73
- const directories = new Set();
74
- for (const file of list) {
75
- const parts = file.split('/');
76
- for (let i = 1; i < parts.length; i += 1)
77
- directories.add(parts.slice(0, i).join('/'));
78
- }
79
- return { files, directories };
80
- }
81
- /** The repository tree as file and directory sets over posix relatives. */
82
- export function treeOf(root) {
83
- if (!runTrees)
84
- return readTree(root);
85
- let tree = runTrees.get(root);
86
- if (!tree) {
87
- tree = readTree(root);
88
- runTrees.set(root, tree);
89
- }
90
- return tree;
91
- }
92
- /**
93
- * The prelude every tree-walking architecture checker shares: the input's config/graph/context, the compiler,
94
- * the slot resolver and the tracked repository tree.
95
- */
96
- export function checkerScope({ config, graph, context }) {
97
- return { config, graph, context, ts: context.ts, resolver: graph.resolver, tree: treeOf(config.root) };
98
- }
99
- const rootOfTarget = (target) => {
100
- if (target.endsWith('/'))
101
- return trimTrailingSlashes(target);
102
- const parent = path.posix.dirname(target);
103
- return parent === '.' ? '' : parent;
104
- };
105
- function ruleFor(slotId, target, rootExists) {
106
- if (slotId === 'fe.app.next' && rootExists && ERROR_BOUNDARY_FILE.test(path.posix.basename(trimTrailingSlashes(target))))
107
- return 'FE_ERROR_BOUNDARY_MISSING';
108
- return 'HFS_REQUIRED_FILE_MISSING';
109
- }
110
- function slotIsJudged(resolver, slotId) {
111
- const slot = resolver.slot(slotId);
112
- return slot != null && (slot.tier !== 'none' || ALSO_JUDGED_TIER_NONE.has(slotId));
113
- }
114
- function addRequirement(requirements, slot, target, root) {
115
- if (!requirements.has(target))
116
- requirements.set(target, { slot, target, root });
117
- }
118
- function collectDeclaredRequirements(declared, requirements, instances, judged) {
119
- const currentRoot = new Map();
120
- for (const item of declared.paths) {
121
- if (!judged(item.slot))
122
- continue;
123
- if (item.via !== 'requires') {
124
- const root = rootOfTarget(item.path);
125
- currentRoot.set(item.slot, root);
126
- instances.add(`${item.slot}|${root}`);
127
- addRequirement(requirements, item.slot, item.path, root);
128
- }
129
- else {
130
- addRequirement(requirements, item.slot, item.path, currentRoot.get(item.slot) ?? '');
131
- }
132
- }
133
- }
134
- function addInstanceRequirements(resolver, classified, representative, requirements, instances, seenInstances, judged) {
135
- const { slot: slotId, root } = classified;
136
- const key = `${slotId}|${root}`;
137
- if (seenInstances.has(key) || !judged(slotId))
138
- return;
139
- seenInstances.add(key);
140
- instances.add(key);
141
- for (const target of resolver.requiredFiles(representative))
142
- addRequirement(requirements, slotId, target, root);
143
- }
144
- function addOwnerRequirements(resolver, owner, requirements, instances, seenInstances, judged) {
145
- const key = `${owner.slot}|${owner.root}`;
146
- const ownerSlot = resolver.slot(owner.slot);
147
- // judged() already answered false for a slot the resolver does not know
148
- if (seenInstances.has(key) || !judged(owner.slot) || !ownerSlot || !resolver.slotEnabled(ownerSlot))
149
- return;
150
- seenInstances.add(key);
151
- instances.add(key);
152
- for (const entry of ownerSlot.requires ?? []) {
153
- const rooted = entry.startsWith('/');
154
- const filled = (rooted ? entry.slice(1) : entry).replace(/<([A-Za-z][A-Za-z0-9-]*)>/g, (whole, name) => owner.bindings[name] ?? whole);
155
- addRequirement(requirements, owner.slot, rooted || !owner.root ? filled : `${owner.root}/${filled}`, owner.root);
156
- }
157
- }
158
- function noteInstance(found, slotId, root) {
159
- let roots = found.get(slotId);
160
- if (!roots) {
161
- roots = new Set();
162
- found.set(slotId, roots);
163
- }
164
- roots.add(root);
165
- }
166
- function collectTreeRequirements(tree, resolver, requirements, instances, judged) {
167
- const seenInstances = new Set();
168
- const found = new Map(); // slot -> Set(root) of instances seen while walking
169
- for (const file of tree.files) {
170
- const classified = resolver.classifyPath(file);
171
- if (classified.status === 'owned' && classified.slot) {
172
- noteInstance(found, classified.slot, classified.root);
173
- addInstanceRequirements(resolver, { slot: classified.slot, root: classified.root }, file, requirements, instances, seenInstances, judged);
174
- }
175
- const owner = resolver.ownerOf(file);
176
- if (owner) {
177
- noteInstance(found, owner.slot, owner.root);
178
- // an owner root may classify to a more specific slot (modules/i18n) or a nested one, so expand the owner slot's own requires
179
- addOwnerRequirements(resolver, owner, requirements, instances, seenInstances, judged);
180
- }
181
- }
182
- return found;
183
- }
184
- function requirementExists(tree, target) {
185
- return target.endsWith('/') ? tree.directories.has(trimTrailingSlashes(target)) : tree.files.has(target);
186
- }
187
- function reportMissingRequirement(requirement, tree, report) {
188
- if (requirementExists(tree, requirement.target) || !requiredFileApplies(requirement.slot, requirement.target, tree.files))
189
- return;
190
- const rootExists = !requirement.root || tree.directories.has(requirement.root);
191
- if (!rootExists) {
192
- report(ruleFor(requirement.slot, requirement.target, false), requirement.root, requirement.slot, requirement.root, { kind: 'directory' }, `Required directory ${requirement.root} (slot ${requirement.slot}) does not exist; the slot manifest requires it, along with what it holds.`);
193
- return;
194
- }
195
- const kind = requirement.target.endsWith('/') ? 'directory' : 'file';
196
- const rootNote = requirement.root ? ` (${requirement.root})` : '';
197
- report(ruleFor(requirement.slot, requirement.target, true), trimTrailingSlashes(requirement.target), requirement.slot, requirement.root, { kind }, `Required ${kind} ${trimTrailingSlashes(requirement.target)} is missing; slot ${requirement.slot} requires it in every instance${rootNote}.`);
198
- }
199
- function reportMissingRequirements(requirements, tree, report) {
200
- for (const requirement of requirements.values())
201
- reportMissingRequirement(requirement, tree, report);
202
- }
203
- function reportMinimumRequirements(minimums, resolver, judged, found, report) {
204
- for (const minimum of minimums) {
205
- if (!judged(minimum.slot))
206
- continue;
207
- const count = minimum.appKind !== undefined
208
- ? resolver.repo.apps.filter(app => app.kind === minimum.appKind).length
209
- : (found.get(minimum.slot)?.size ?? 0);
210
- if (count >= minimum.min)
211
- continue;
212
- const appKindNote = minimum.appKind ? ' (an app of kind ' + minimum.appKind + ' declared in hfs.json)' : '';
213
- report('HFS_REQUIRED_FILE_MISSING', 'hfs.json', minimum.slot, '', { minimum: minimum.min, found: count }, `Slot ${minimum.slot} needs at least ${minimum.min} instance${minimum.min === 1 ? '' : 's'}${appKindNote}; the repository has ${count}.`);
214
- }
215
- }
216
- export function checkRequiredFiles({ config, graph }) {
217
- const resolver = graph?.resolver ?? config.hfs;
218
- const tree = treeOf(config.root);
219
- const judged = slotId => slotIsJudged(resolver, slotId);
220
- const requirements = new Map(); // repository-relative target (as written, dirs end with /) -> {slot, target, root}
221
- const instances = new Set();
222
- const declared = resolver.requiredPaths();
223
- collectDeclaredRequirements(declared, requirements, instances, judged);
224
- const found = collectTreeRequirements(tree, resolver, requirements, instances, judged);
225
- const violations = [];
226
- const reported = new Set();
227
- const report = (ruleId, target, slotId, root, extra, message) => {
228
- const key = `${ruleId}|${target}`;
229
- if (reported.has(key))
230
- return;
231
- reported.add(key);
232
- violations.push({ ruleId, path: target, slot: slotId, ...(root ? { root } : {}), ...extra, message });
233
- };
234
- reportMissingRequirements(requirements, tree, report);
235
- reportMinimumRequirements(declared.minimums, resolver, judged, found, report);
236
- return { violations, coverage: { status: 'checked', instances: instances.size, requirements: requirements.size, missing: violations.length } };
237
- }
@@ -1,78 +0,0 @@
1
- // root-packages.mjs - the workspace packages of an app ROOT (packages/<name>: the agent SDK, a block library, a module package, the managed packages/modules).
2
- // They lie outside both side folders and belong to no side; both sides import them by package name, through their package entry points
3
- // (the `exports` of the manifest), so the import graph reads them as first-party packages and the back-end canon never reads them as
4
- // a third-party library. The app root's one package.json lists them in `workspaces`; the patterns that start with a side folder
5
- // (`fe/apps/*`) are that side's own workspaces and are not read here.
6
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- import { readJsonFile as readJson } from '../../lib/json.mjs';
9
- import { byCodeUnit } from '../../lib/list.mjs';
10
- import { isInside } from '../../lib/walk.mjs';
11
- import { slash } from '../../lib/path-key.mjs';
12
- /** The slots whose directories at the app root are first-party packages of the app (agent SDK, module packages, the managed registry). */
13
- export const ROOT_PACKAGE_SLOTS = new Set(['app.packages', 'app.module-registry']);
14
- const SIDE_PREFIX = /^(?:be|fe)\//;
15
- /** A workspace pattern this reader expands (a literal path, or `*` as a whole segment); the others are judged by the workspace rules. */
16
- const expandablePattern = (written) => !path.isAbsolute(written) && written.split('/').every(segment => segment !== '..' && (!segment.includes('*') || segment === '*'));
17
- function expandSegment(base, segment) {
18
- if (segment !== '*')
19
- return [path.join(base, segment)];
20
- if (!fs.existsSync(base) || !fs.lstatSync(base).isDirectory())
21
- return [];
22
- return fs.readdirSync(base, { withFileTypes: true }).filter(item => item.isDirectory()).sort((a, b) => byCodeUnit(a.name, b.name)).map(item => path.join(base, item.name));
23
- }
24
- /** A package folder with a regular package.json (a link is not one). */
25
- export function packageDirectory(absolute) {
26
- try {
27
- if (!fs.lstatSync(absolute).isDirectory())
28
- return false;
29
- const manifest = fs.lstatSync(path.join(absolute, 'package.json'));
30
- return manifest.isFile() && !manifest.isSymbolicLink();
31
- }
32
- catch {
33
- return false;
34
- }
35
- }
36
- /** The folders the `workspaces` of the app root's package.json name that no side owns, as absolute paths in code-unit order. */
37
- export function rootWorkspaceDirectories(packageRoot) {
38
- const manifest = readJson(path.join(packageRoot, 'package.json'));
39
- const declared = manifest?.workspaces;
40
- const patterns = Array.isArray(declared) ? declared : declared?.packages;
41
- const found = new Set();
42
- for (const pattern of Array.isArray(patterns) ? patterns : []) {
43
- if (typeof pattern !== 'string' || !pattern.trim())
44
- continue;
45
- const written = slash(pattern.trim()).replace(/^\.\//, '');
46
- if (SIDE_PREFIX.test(written) || !expandablePattern(written))
47
- continue;
48
- let bases = [packageRoot];
49
- for (const segment of written.split('/'))
50
- bases = bases.flatMap(base => expandSegment(base, segment));
51
- for (const base of bases)
52
- found.add(path.resolve(base));
53
- }
54
- return [...found].sort(byCodeUnit);
55
- }
56
- /**
57
- * The record of one package folder of the app root, or null when it is no named package inside the app root.
58
- * `canonical` is the file-identity function of the caller (the real path), so a record agrees with the files the graph reads.
59
- */
60
- export function rootPackageRecord(packageRoot, directory, canonical) {
61
- if (!packageDirectory(directory) || !isInside(packageRoot, directory))
62
- return null;
63
- const manifest = readJson(path.join(directory, 'package.json'));
64
- const name = manifest?.['name'];
65
- if (manifest === null || typeof name !== 'string' || !name)
66
- return null;
67
- return { root: canonical(directory), relative: slash(path.relative(packageRoot, directory)), name, exports: manifest['exports'], manifest, workspace: true, app: false };
68
- }
69
- /** The names of the workspace packages of the app root: what the back-end canon must not read as third-party libraries. */
70
- export function rootPackageNames(packageRoot) {
71
- const names = new Set();
72
- for (const directory of rootWorkspaceDirectories(packageRoot)) {
73
- const record = rootPackageRecord(packageRoot, directory, (file) => file);
74
- if (record !== null)
75
- names.add(record.name);
76
- }
77
- return names;
78
- }
@@ -1,133 +0,0 @@
1
- import path from 'node:path';
2
- import { machineKit } from './machine-ast.mjs';
3
- /**
4
- * R54 `route-files-thin` (FE_ROUTE_FILES_THIN, knowledge/hfs/README.md 6.2). A route file only mounts an owner: it holds no
5
- * inline component, no drawing and no hook. For every file of the route slot (fe.route, apps/<app>/src/app) named
6
- * `layout`, `template`, `loading` or `not-found`:
7
- *
8
- * - no host element (`<div>`, `<main>`): drawing belongs to the feature the file mounts;
9
- * - no function other than the default export that returns JSX: an inline component is a feature in the wrong folder;
10
- * - JSX, when present, mounts exactly one feature owner (a component resolved to a file of tier `feature`); a file with no
11
- * JSX re-exports or delegates and needs none. Package components (a locale shell) may wrap the owner.
12
- *
13
- * and, for every such file and every `page`: no hook call. A hook is an imported `use<Name>` function or any function of
14
- * hooks/. The page's own mount, redirect and decision rules are the existing FE_ROUTE_ONE_PAGE, FE_ROUTE_DRAWING_DECISION,
15
- * FE_ROUTE_CLIENT_BOUNDARY and FE_ROUTE_CLIENT_HOOK checks of frontend.mjs and are not judged a second time here.
16
- */
17
- export const ROUTE_FILES_THIN_RULE_IDS = ['FE_ROUTE_FILES_THIN'];
18
- const RULE = 'FE_ROUTE_FILES_THIN';
19
- const ROUTE_SLOT = 'fe.route';
20
- const MOUNTING_ROUTES = new Set(['layout', 'template', 'loading', 'not-found']);
21
- const HOOK_ROUTES = new Set([...MOUNTING_ROUTES, 'page']);
22
- const HOOK_NAME = /^use[A-Z0-9]/u;
23
- const HOOKS_SLOT = 'fe.hooks';
24
- /** The client providers (fe.components.providers) wrap the mounted owner like a package shell; they are not a second owner. */
25
- const PROVIDERS_SLOT = 'fe.components.providers';
26
- const isFeatureOwner = (target) => target?.tier === 'feature' && target.slot !== PROVIDERS_SLOT;
27
- const isFunction = (ts, node) => ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node);
28
- const jsxOf = (ts, node) => ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node);
29
- function tagOf(ts, node) {
30
- if (ts.isJsxElement(node))
31
- return node.openingElement.tagName;
32
- if (ts.isJsxSelfClosingElement(node))
33
- return node.tagName;
34
- return null;
35
- }
36
- function addExportAssignmentDefaults(ts, statement, kit, checker, defaults) {
37
- const target = statement.expression;
38
- if (!ts.isIdentifier(target)) {
39
- defaults.add(target);
40
- return;
41
- }
42
- for (const declaration of kit.declarationsOf(checker, target))
43
- defaults.add(ts.isVariableDeclaration(declaration) ? declaration.initializer ?? declaration : declaration);
44
- }
45
- function routeDefaults(ts, file, kit, checker) {
46
- const defaults = new Set();
47
- for (const statement of file.sourceFile.statements) {
48
- if (ts.isFunctionDeclaration(statement) && statement.modifiers?.some((item) => item.kind === ts.SyntaxKind.DefaultKeyword))
49
- defaults.add(statement);
50
- if (ts.isExportAssignment(statement) && !statement.isExportEquals)
51
- addExportAssignmentDefaults(ts, statement, kit, checker, defaults);
52
- }
53
- return defaults;
54
- }
55
- /** True when the function contains JSX that is not inside a nested function. */
56
- function drawsDirectly(ts, fn) {
57
- let found = false;
58
- const visit = (node) => {
59
- if (found)
60
- return;
61
- if (node !== fn && isFunction(ts, node))
62
- return;
63
- if (jsxOf(ts, node)) {
64
- found = true;
65
- return;
66
- }
67
- ts.forEachChild(node, visit);
68
- };
69
- visit(fn);
70
- return found;
71
- }
72
- function reportRoute(violations, kit, file, stem, node, message, extra = {}) {
73
- violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node), message, route: stem, ...extra });
74
- }
75
- function inspectMountingTag(tag, { graph, kit, ts, file, stem, checker, violations, state }) {
76
- if (ts.isIdentifier(tag) && /^[a-z]/u.test(tag.text)) {
77
- reportRoute(violations, kit, file, stem, tag, `<${tag.text}> is drawing in a ${stem} route file; a route file mounts one feature and draws nothing. Move the markup into the feature.`);
78
- }
79
- else if (kit.declarationsOf(checker, ts.isPropertyAccessExpression(tag) ? tag.name : tag).some(declaration => isFeatureOwner(graph.files.get(kit.graphPath(declaration) ?? '')))) {
80
- state.owners += 1;
81
- }
82
- }
83
- function inspectHookCall(node, { graph, kit, ts, file, stem, checker, violations }) {
84
- const callee = ts.isIdentifier(node.expression) ? node.expression : null;
85
- if (!callee || !HOOK_NAME.test(callee.text))
86
- return;
87
- const binding = kit.importBinding(checker, callee);
88
- const inHooks = kit.declarationsOf(checker, callee).some(declaration => graph.files.get(kit.graphPath(declaration) ?? '')?.slot === HOOKS_SLOT);
89
- if (binding || inHooks)
90
- reportRoute(violations, kit, file, stem, callee, `${callee.text} is a hook called in a ${stem} route file; a route file is a server adapter and holds no hook. Read the data in the feature it mounts.`);
91
- }
92
- function inspectRouteNode(node, context) {
93
- const { kit, ts, file, stem, mounting, defaults, violations, state } = context;
94
- if (jsxOf(ts, node))
95
- state.hasJsx = true;
96
- const tag = tagOf(ts, node);
97
- if (mounting && tag)
98
- inspectMountingTag(tag, context);
99
- if (mounting && isFunction(ts, node) && !defaults.has(node) && drawsDirectly(ts, node)) {
100
- reportRoute(violations, kit, file, stem, node, `A function other than the default export draws JSX in a ${stem} route file; that is an inline component. Move it into the feature the route mounts.`);
101
- }
102
- if (ts.isCallExpression(node))
103
- inspectHookCall(node, context);
104
- return true;
105
- }
106
- function inspectRouteFile(graph, kit, file, stem, violations) {
107
- const { ts } = kit;
108
- const mounting = MOUNTING_ROUTES.has(stem);
109
- const checker = kit.checkerOf(file.sourceFile);
110
- const defaults = routeDefaults(ts, file, kit, checker);
111
- const state = { hasJsx: false, owners: 0 };
112
- kit.walk(file.sourceFile, (node) => inspectRouteNode(node, { graph, kit, ts, file, stem, mounting, checker, defaults, violations, state }));
113
- if (mounting && state.hasJsx && state.owners !== 1) {
114
- violations.push({ ruleId: RULE, path: file.rel, line: 1, column: 1, route: stem, owners: state.owners,
115
- message: `${file.rel} mounts ${state.owners} feature owners; a ${stem} route file mounts exactly one feature (a layouts- or pages-tier component of the app), optionally inside a package shell.` });
116
- }
117
- }
118
- export function checkRouteFilesThin(input) {
119
- const { graph } = input;
120
- const kit = machineKit(input);
121
- const violations = [];
122
- let routes = 0;
123
- for (const file of graph.files.values()) {
124
- if (file.slot !== ROUTE_SLOT)
125
- continue;
126
- const stem = path.posix.basename(file.rel).replace(/\.[cm]?[jt]sx?$/u, '');
127
- if (!HOOK_ROUTES.has(stem))
128
- continue;
129
- routes += 1;
130
- inspectRouteFile(graph, kit, file, stem, violations);
131
- }
132
- return { violations, coverage: { status: 'checked', routes } };
133
- }