@starci/eslint-canon-be 3.18.3 → 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 +8 -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 -716
  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,68 +0,0 @@
1
- // fe-no-tests.mjs - FE_NO_TESTS (R97): a front-end repository has no tests by standard (owner 2026-09-30). There is no exception: a spec
2
- // anywhere in a front-end repository is a finding, `scripts/` included.
3
- // - a tracked test file: `*.spec.*`, `*.test.*`, `*-spec.*` (also `*.e2e-spec.*`);
4
- // - a tracked test directory: `e2e/`, `__tests__/`, `__mocks__/` or `test-support/`;
5
- // - a tracked test-tool file: `vitest.*`, `jest.*`, `playwright.*` (config, setup, workspace), `cypress.config.*`, `tsconfig.e2e.json`, `e2e.yml`;
6
- // - a test script in a package.json: a script named `test`, `test:*` (or with a pre/post prefix), or one that runs a test runner;
7
- // - a test dependency in a package.json: a test runner, a test environment, testing-library or an axe package.
8
- // The check reads the tracked tree and the manifests only. One finding per path (a manifest: one per script or dependency), and it is
9
- // the only finding of a test file: the slot check leaves these paths to it (isFeTestPath).
10
- import { found, readJson } from './read.mjs';
11
- export const FE_NO_TESTS = 'FE_NO_TESTS';
12
- const SPEC_FILE = /(?:\.(?:spec|test)|-spec)\.[cm]?[jt]sx?$/;
13
- const TEST_DIRECTORY = /(?:^|\/)(?:e2e|__tests__|__mocks__|test-support)\//;
14
- const TEST_TOOL_FILE = /(?:^|\/)(?:(?:vitest|jest|playwright)\.[^/]+|cypress\.config\.[^/]+|tsconfig\.e2e\.json|e2e\.ya?ml)$/;
15
- const TEST_SCRIPT_NAME = /^(?:pre|post)?test(?::|$)/;
16
- const TEST_RUNNER_COMMAND_SOURCE = String.raw `(?:^|[\s&|;(])(?:npx\s+)?(?:vitest|jest|playwright|cypress|mocha)(?=$|[\s&|;)])|\bnode\s+(?:--\S+\s+)*--test\b`;
17
- const TEST_RUNNER_COMMAND = new RegExp(TEST_RUNNER_COMMAND_SOURCE);
18
- const TEST_DEPENDENCY_SOURCE = String.raw `^(?:vitest|@vitest\/.+|playwright|playwright-core|@playwright\/.+|jest|@jest\/.+|ts-jest|babel-jest|@types\/jest|jest-[\w-]+|mocha|@types\/mocha|cypress|@testing-library\/.+|jsdom|@types\/jsdom|happy-dom|axe-core|@axe-core\/.+|vitest-axe|@starci\/(?:vitest|jest|playwright)-preset)$`;
19
- const TEST_DEPENDENCY = new RegExp(TEST_DEPENDENCY_SOURCE);
20
- export const DEPENDENCY_SECTIONS = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
21
- /** True for a path FE_NO_TESTS owns: a spec file, a test directory or a test-tool file. */
22
- export const isFeTestPath = (file) => SPEC_FILE.test(file) || TEST_DIRECTORY.test(file) || TEST_TOOL_FILE.test(file);
23
- function testPathFinding(file) {
24
- let what = 'test tooling';
25
- if (SPEC_FILE.test(file))
26
- what = 'a test file';
27
- else if (TEST_DIRECTORY.test(file))
28
- what = 'inside a test directory';
29
- return found(FE_NO_TESTS, file, `${file} is ${what}; a front-end repository has no tests, no test tooling and no exception: delete it`);
30
- }
31
- function testDependencyFindings(file, pkg) {
32
- const findings = [];
33
- for (const section of DEPENDENCY_SECTIONS) {
34
- for (const name of Object.keys(pkg[section] ?? {})) {
35
- if (TEST_DEPENDENCY.test(name))
36
- findings.push(found(FE_NO_TESTS, file, `${file} ${section} names ${name}, a test dependency; a front-end repository has no tests: delete the dependency`));
37
- }
38
- }
39
- return findings;
40
- }
41
- function packageTestFindings(repoRoot, file) {
42
- if (file !== 'package.json' && !file.endsWith('/package.json'))
43
- return [];
44
- if (file.includes('node_modules/'))
45
- return [];
46
- const pkg = readJson(repoRoot, file);
47
- if (!pkg || typeof pkg !== 'object')
48
- return [];
49
- const findings = [];
50
- for (const [name, command] of Object.entries(pkg.scripts ?? {})) {
51
- if (TEST_SCRIPT_NAME.test(name) || TEST_RUNNER_COMMAND.test(String(command)))
52
- findings.push(found(FE_NO_TESTS, file, `${file} script ${name} is a test script (${String(command).slice(0, 80)}); a front-end repository has no tests: delete the script`));
53
- }
54
- findings.push(...testDependencyFindings(file, pkg));
55
- return findings;
56
- }
57
- /** The findings of R97 over the tracked paths `files` of a front-end repository at `repoRoot`. */
58
- export function feNoTestsFindings({ repoRoot, files }) {
59
- const findings = [];
60
- for (const file of files) {
61
- if (isFeTestPath(file)) {
62
- findings.push(testPathFinding(file));
63
- continue;
64
- }
65
- findings.push(...packageTestFindings(repoRoot, file));
66
- }
67
- return findings;
68
- }
@@ -1,45 +0,0 @@
1
- // read.mjs - what the tree checks of hfs-check.mjs share: one bounded text read and the shape of a finding.
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- /** Files above this size are not read by a tree check (a tracked binary or a generated dump is no source of these laws). */
5
- const MAX_READ_BYTES = 1024 * 1024;
6
- let sink = null;
7
- /** Runs `run` with every `readText` / `readJson` it makes reported to `onRead` (before the read), and returns its value. */
8
- export function recordReads(onRead, run) {
9
- const before = sink;
10
- sink = onRead;
11
- try {
12
- return run();
13
- }
14
- finally {
15
- sink = before;
16
- }
17
- }
18
- /** The text of `rel` under `repoRoot`, or null when it is absent, unreadable, over MAX_READ_BYTES or binary. */
19
- export function readText(repoRoot, rel) {
20
- sink?.(repoRoot, rel);
21
- try {
22
- const target = path.join(repoRoot, rel);
23
- if (fs.statSync(target).size > MAX_READ_BYTES)
24
- return null;
25
- const text = fs.readFileSync(target, 'utf8');
26
- return text.includes('\0') ? null : text;
27
- }
28
- catch {
29
- return null;
30
- }
31
- }
32
- /** The JSON of `rel`, or null when it is absent or not JSON. */
33
- export function readJson(repoRoot, rel) {
34
- const text = readText(repoRoot, rel);
35
- if (text === null)
36
- return null;
37
- try {
38
- return JSON.parse(text);
39
- }
40
- catch {
41
- return null;
42
- }
43
- }
44
- /** One error finding of `code` on `file`; `extra` carries the finding's own fields. */
45
- export const found = (code, file, message, extra = {}) => ({ code, level: 'error', path: file, ...extra, message });
@@ -1,79 +0,0 @@
1
- // secrets.mjs - HFS_PLAINTEXT_SECRET (R06): secrets exist only as `.starcistacks/<env>/secrets/<slug>.enc` sops envelopes.
2
- // It judges the tracked tree with the one list of secret shapes the push scan refuses (scripts/lib/secret-patterns.mjs):
3
- // - a tracked file that is a secret by being (an env file, a key file, a credentials file, a plaintext member of a
4
- // secrets directory), and every path a forbidden `external` slot names HFS_PLAINTEXT_SECRET for (the slot manifest);
5
- // - a tracked `.enc` that is not a sops envelope (an encrypted-looking file that holds plaintext);
6
- // - a line of any other tracked text file that matches a secret pattern.
7
- // A finding names the file, the line and the pattern, never the value.
8
- import fs from 'node:fs';
9
- import path from 'node:path';
10
- import { FORBIDDEN_FILES, secretHitsInFile } from '../../lib/secret-patterns.mjs';
11
- import { isSopsEnvelope } from '../../lib/sops-envelope.mjs';
12
- import { found, readText } from './read.mjs';
13
-
14
- const PLAINTEXT_SECRET = 'HFS_PLAINTEXT_SECRET';
15
- /** Files whose lines are not secrets: a lockfile carries integrity hashes, never a credential. */
16
- const NOT_SCANNED = /(^|\/)package-lock\.json$/;
17
-
18
- /** True when the slot `id` of the manifest reports HFS_PLAINTEXT_SECRET for the paths it forbids. */
19
- export const slotOwnsSecrets = (slot) => slot?.rules?.includes(PLAINTEXT_SECRET) === true;
20
-
21
- /** A legacy lite root secrets.env is reported even when ignored; its presence is enough, so no value is read. */
22
- export function untrackedSecretFindings({ repoRoot, files, repo }) {
23
- if (repo.profile !== 'app' || repo.edition !== 'lite' || files.includes('secrets.env')) return [];
24
- try {
25
- if (!fs.statSync(path.join(repoRoot, 'secrets.env')).isFile()) return [];
26
- } catch {
27
- return [];
28
- }
29
- return [found(PLAINTEXT_SECRET, 'secrets.env', 'secrets.env is an untracked plaintext secret at the lite app root; seal it with starci app secret set into .starcistacks/<env>/secrets/<slug>.enc and remove the plaintext file; read materialized values by *_FILE', { level: 'warning', pattern: 'untracked-secrets-env' })];
30
- }
31
-
32
- /**
33
- * The findings of R06 for one tracked file that no forbidden slot claims: a secret by being (an env file, a key file), an `.enc` that is
34
- * no sops envelope, or a line that matches a secret pattern. `text` is the file's text, or null when it cannot be read (binary, too
35
- * large, absent). The whole-tree check reads the work tree and the commit hook (`starci app check --staged`) reads the staged blob: one judgement.
36
- */
37
- export function secretFileFindings({ file, text, manifestText }) {
38
- const being = FORBIDDEN_FILES.find((rule) => rule.test(file));
39
- if (being) return [found(PLAINTEXT_SECRET, file, `${file} is a plaintext secret by being (${being.name}); a secret is committed only as a sops envelope at .starcistacks/<env>/secrets/<slug>.enc`, { pattern: being.name })];
40
- if (text === null || text === undefined || NOT_SCANNED.test(file)) return [];
41
- if (file.endsWith('.enc')) return isSopsEnvelope(text) ? [] : [found(PLAINTEXT_SECRET, file, `${file} is named like a sealed secret but is not a sops envelope; encrypt the value with sops and commit only the envelope`, { pattern: 'sops-not-envelope' })];
42
- const findings = [];
43
- const seen = new Set();
44
- for (const { line, pattern } of secretHitsInFile(file, text, { manifestText })) {
45
- if (seen.has(pattern)) continue;
46
- seen.add(pattern);
47
- findings.push(found(PLAINTEXT_SECRET, file, `${file}:${line} holds a plaintext secret (${pattern}); seal it with sops at .starcistacks/<env>/secrets/<slug>.enc and read it by *_FILE`, { line, pattern }));
48
- }
49
- return findings;
50
- }
51
-
52
- /** The findings of R06 over `files` (tracked paths) of `repoRoot`; `resolver` names the slots. */
53
- export function secretFindings({ repoRoot, files, resolver }) {
54
- const findings = [];
55
- for (const file of files) {
56
- const slot = resolver.classifyPath(file);
57
- if (slot.status === 'forbidden' && slotOwnsSecrets(resolver.slot(slot.slot))) {
58
- const destination = slot.goesTo ? `; it belongs at ${slot.goesTo}` : '';
59
- findings.push(found(PLAINTEXT_SECRET, file, `${file} is a plaintext secret file tracked in ${slot.slot}${destination}`, { slot: slot.slot, goesTo: slot.goesTo }));
60
- continue;
61
- }
62
- const manifestText = /(?:^|\/)README\.md$/.test(file) ? readText(repoRoot, path.posix.join(path.posix.dirname(file), '.starcistacks/application-stacks.yaml')) : undefined;
63
- findings.push(...secretFileFindings({ file, text: readText(repoRoot, file), manifestText }));
64
- }
65
- return findings;
66
- }
67
-
68
- // The age identity stays on the host: `.claude/secret.env` (SOPS_AGE_KEY) or the sops config dir's `keys.txt`,
69
- // both host-local files. A tracked `secret.env`, `keys.txt` or `*.agekey` is the identity committed.
70
- const AGE_KEY_FILE = /^\.claude\/secret\.env$|(?:^|\/)keys\.txt$|\.agekey$/i;
71
- export function ageKeyCustodyFindings({ files, inScope }) {
72
- const findings = [];
73
- for (const file of files.filter((f) => !inScope || inScope(f))) {
74
- if (!AGE_KEY_FILE.test(file)) continue;
75
- findings.push(found('HFS_AGE_KEY_CUSTODY', file,
76
- `${file} is a tracked sops/age identity file; the age key lives only in the host-local .claude/secret.env or the sops keys.txt - never commit the identity`));
77
- }
78
- return findings;
79
- }
@@ -1,28 +0,0 @@
1
- // spec-placement.mjs - BE_SPEC_PLACEMENT (R102): a back-end spec or test file lives in one of the four test layers and nowhere else.
2
- // - a unit spec is `<name>.service.spec.ts` beside its service, in a slot whose `tests` is `unit-beside` (the slot and the lint rule
3
- // `unit-test-colocated` judge the name);
4
- // - integration, e2e and contract specs are `src/tests/{integration,e2e,contract}/...`, the slots whose `tests` is `e2e`;
5
- // Every other tracked `*.spec.*`, `*.test.*` or `*-spec.*` file is a finding, `scripts/` and `tools/` included: an operational script
6
- // carries no spec, and a spec that guards one moves into a layer or goes. A file no slot owns (`tools/x.spec.ts`) is judged too, so the
7
- // finding names the rule rather than only the missing slot. Which folder is a layer is read from the slot manifest, never spelled here.
8
- import { found } from './read.mjs';
9
- const SPEC_PLACEMENT = 'BE_SPEC_PLACEMENT';
10
- const SPEC_FILE = /(?:\.(?:spec|test)|-spec)\.[cm]?[jt]sx?$/;
11
- const TEST_SLOT_TESTS = new Set(['unit-beside', 'e2e']);
12
- /** True for a file name that is a spec or a test. */
13
- export const isSpecFile = (file) => SPEC_FILE.test(file);
14
- /** The findings of R102 over the tracked paths `files` of a back-end repository; `resolver` names the slots. */
15
- export function specPlacementFindings({ files, resolver }) {
16
- const findings = [];
17
- for (const file of files) {
18
- if (!isSpecFile(file) || file.includes('node_modules/'))
19
- continue;
20
- const classified = resolver.classifyPath(file);
21
- const slot = classified.status === 'owned' ? resolver.slot(classified.slot) : null;
22
- if (slot && TEST_SLOT_TESTS.has(slot.tests))
23
- continue;
24
- const where = slot ? `slot ${slot.id}` : 'no slot';
25
- findings.push(found(SPEC_PLACEMENT, file, `${file} is a spec outside the test layers (${where}); a unit spec is <name>.service.spec.ts beside its service and an integration, e2e or contract spec sits under src/tests/{integration,e2e,contract}; an operational script or a tool carries no spec`));
26
- }
27
- return findings;
28
- }
@@ -1,97 +0,0 @@
1
- // slot-app-view.mjs - the resolver of a whole app: a root path is answered by the scope of the app root, a path below a side folder
2
- // (be/, fe/) by that side's scope with the side prefixed back onto every path and root it returns. Only the declared `reads` cross sides.
3
- // slots.mjs builds the scopes (`root` and `sides`, each a resolver of one scope) and hands them to appResolver.
4
- import { APP_SCOPE, isSide, PROFILES } from './slot-manifest-shape.mjs';
5
- import { cleanSlotPath } from './slot-path.mjs';
6
- /** True for the view of a whole app (profile app), the one resolveRepoDeclaration builds with both sides. */
7
- export const isAppRepo = (repo) => repo.sides !== undefined;
8
- /** { side, rest } when `p` lies below a side folder, else null. */
9
- function splitSide(input) {
10
- const p = cleanSlotPath(input);
11
- const slash = p.indexOf('/');
12
- const head = slash < 0 ? p : p.slice(0, slash);
13
- return isSide(head) && slash > 0 ? { side: head, rest: p.slice(slash + 1) } : null;
14
- }
15
- const under = (side, rel) => (rel ? `${side}/${rel}` : side);
16
- function prefixed(side, c) {
17
- return {
18
- ...c,
19
- path: under(side, c.path),
20
- side,
21
- ...(c.root !== undefined ? { root: under(side, c.root) } : {}),
22
- ...(c.nearest ? { nearest: { ...c.nearest, matchedPrefix: under(side, c.nearest.matchedPrefix), matchedDepth: c.nearest.matchedDepth + 1 } } : {}),
23
- };
24
- }
25
- function classifyApp({ root, sides }, input) {
26
- const at = splitSide(input);
27
- return at ? prefixed(at.side, sides[at.side].classifyPath(at.rest)) : root.classifyPath(input);
28
- }
29
- function ownerApp({ root, sides }, input) {
30
- const at = splitSide(input);
31
- if (!at)
32
- return root.ownerOf(input);
33
- const owner = sides[at.side].ownerOf(at.rest);
34
- return owner ? { ...owner, root: under(at.side, owner.root), side: at.side } : null;
35
- }
36
- /** Whether `toPath`, of the other side, lies below a path `fromSide` declares it reads. */
37
- const readsPath = (repo, fromSide, toPath) => repo.sides[fromSide].reads.some((read) => `${cleanSlotPath(toPath)}/`.startsWith(read));
38
- /** The verdict of an import from a side file to a path of the other side (or of the app root, `toSide` null): allowed only through a declared read. */
39
- function sideCrossing(repo, fromSide, toSide, toPath) {
40
- return readsPath(repo, fromSide, toPath)
41
- ? { allowed: true, reason: 'sideRead', fromSide, toSide }
42
- : { allowed: false, reason: 'crossSide', fromSide, toSide, reads: repo.sides[fromSide].reads };
43
- }
44
- function importAllowedApp({ repo, root, sides }, fromPath, toPath) {
45
- const from = splitSide(fromPath);
46
- const to = splitSide(toPath);
47
- // A side file may read an app-root path (db/types/) only through a declared read, exactly as it reads the other side.
48
- if (from && from.side !== to?.side)
49
- return sideCrossing(repo, from.side, to?.side ?? null, toPath);
50
- if (from && to)
51
- return sides[from.side].importAllowed(from.rest, to.rest);
52
- return root.importAllowed(fromPath, toPath);
53
- }
54
- function requiredPathsApp({ root, sides }) {
55
- const own = root.requiredPaths();
56
- const paths = [...own.paths];
57
- const minimums = [...own.minimums];
58
- for (const side of PROFILES) {
59
- const required = sides[side].requiredPaths();
60
- paths.push(...required.paths.map((entry) => ({ ...entry, path: under(side, entry.path), side })));
61
- minimums.push(...required.minimums.map((entry) => ({ ...entry, side })));
62
- }
63
- return { paths, minimums };
64
- }
65
- function slotEnabledApp({ root, sides }, slot) {
66
- if (slot.profiles.includes(APP_SCOPE))
67
- return root.slotEnabled(slot);
68
- return PROFILES.some((side) => slot.profiles.includes(side) && sides[side].slotEnabled(slot));
69
- }
70
- /** The resolver of the app `repo`: `root` answers its root paths and `sides[side]` the paths below that side's folder. */
71
- export function appResolver(repo, root, sides) {
72
- const view = { repo, root, sides };
73
- const allSlots = [...new Map([...root.slots(), ...PROFILES.flatMap((side) => sides[side].slots())].map((s) => [s.id, s])).values()];
74
- const byId = new Map(allSlots.map((s) => [s.id, s]));
75
- const classifyPath = (input) => classifyApp(view, input);
76
- return Object.freeze({
77
- repo,
78
- sides: Object.freeze(sides),
79
- /** The side of a path (be, fe) or null for a root path. */
80
- sideOf: (input) => splitSide(input)?.side ?? null,
81
- slot: (id) => byId.get(id) ?? null,
82
- slots: () => allSlots,
83
- slotEnabled: (slot) => slotEnabledApp(view, slot),
84
- classifyPath,
85
- slotOf: (p) => { const c = classifyPath(p); return c.slot ? byId.get(c.slot) : null; },
86
- ownerOf: (input) => ownerApp(view, input),
87
- tierOf: (input) => { const at = splitSide(input); return at ? sides[at.side].tierOf(at.rest) : root.tierOf(input); },
88
- importAllowed: (fromPath, toPath) => importAllowedApp(view, fromPath, toPath),
89
- requiredFiles: (input) => { const at = splitSide(input); return at ? sides[at.side].requiredFiles(at.rest).map((p) => under(at.side, p)) : root.requiredFiles(input); },
90
- requiredPaths: () => requiredPathsApp(view),
91
- trackingOf: (p) => classifyPath(p).tracking ?? null,
92
- isTracked: (p) => classifyPath(p).tracking === 'tracked',
93
- // The root has no tier and no rule parameters of its own; each side has them (sides.<side>.ruleParams()).
94
- ruleParams: () => null,
95
- allowedImports: () => null,
96
- });
97
- }
@@ -1,69 +0,0 @@
1
- // slot-classify.mjs - what slot of one scope (the app root or one side) owns a path: its status, owner unit, tier, folder kind and role.
2
- // A scope is {manifest, repo, profile, edition, slots, byId, variants, appKind} built once by slots.mjs; every function here reads it.
3
- import { globExpression } from '../lib/glob.mjs';
4
- import { declaredSlotEnabled } from './declaration-slots.mjs';
5
- import { bestMatch, fillVars, matchVariants, nearestSlot } from './slot-match.mjs';
6
- import { cleanSlotPath } from './slot-path.mjs';
7
- /** Whether the repository of the scope holds the slot. */
8
- export function slotEnabled(scope, slot) {
9
- // A provider slot is gated by its provider in every edition: litePresence may lift it to required, but it still
10
- // exists for this repository only while a connection declares the provider.
11
- if (slot.provider !== undefined)
12
- return declaredSlotEnabled(slot, scope.repo);
13
- if (slot.presence !== 'opt-in')
14
- return true;
15
- return declaredSlotEnabled(slot, scope.repo);
16
- }
17
- /** The folder kind of a file in its slot, from a named layer or kind folder. */
18
- function kindOf({ variant, slot, root }, p) {
19
- const names = [...(slot.layers ?? []), ...(slot.kinds ?? [])];
20
- if (!names.length)
21
- return null;
22
- const literal = variant.segments.find((segment) => names.includes(segment));
23
- if (literal)
24
- return literal;
25
- const below = root ? p.slice(root.length + 1) : p;
26
- return below.split('/').slice(0, -1).find((segment) => names.includes(segment)) ?? null;
27
- }
28
- /** The role of a file in its slot: the entry of `roles` whose file name (variables filled from the path, `*` a wildcard inside the name) matches the file's name. */
29
- function roleOf(slot, bindings, p) {
30
- const name = p.split('/').pop();
31
- for (const [role, file] of Object.entries(slot.roles ?? {}))
32
- if (globExpression(fillVars(file, bindings)).test(name))
33
- return role;
34
- return null;
35
- }
36
- /**
37
- * status: owned | forbidden (external slot) | not-enabled (opt-in slot the repository did not declare) | ambiguous
38
- * (two slots of equal specificity; a manifest gap) | no-slot (code HFS_SLOT_UNDECLARED, with the nearest slot).
39
- */
40
- export function classifyIn(scope, input) {
41
- const p = cleanSlotPath(input);
42
- const { hit, ambiguous } = bestMatch(matchVariants(scope, p));
43
- if (ambiguous.length)
44
- return { path: p, status: 'ambiguous', candidates: ambiguous };
45
- if (!hit)
46
- return { path: p, status: 'no-slot', code: 'HFS_SLOT_UNDECLARED', nearest: nearestSlot(scope.variants, p) };
47
- const { slot, root, bindings } = hit;
48
- const status = (slot.presence === 'forbidden' && 'forbidden') || (slotEnabled(scope, slot) ? 'owned' : 'not-enabled');
49
- const kind = kindOf(hit, p);
50
- const role = roleOf(slot, bindings, p);
51
- return { path: p, status, slot: slot.id, root, bindings, ...(kind ? { kind } : {}), ...(role ? { role } : {}), presence: slot.presence, tracking: slot.tracked, ...(status === 'forbidden' ? { goesTo: slot.goesTo } : {}) };
52
- }
53
- /** The owner unit of `p`: the most specific owner slot instance containing it (a slot's own root when it owns nothing). */
54
- export function ownerIn(scope, input) {
55
- const p = cleanSlotPath(input);
56
- const { hit } = bestMatch(matchVariants(scope, p, (s) => s.owner === true));
57
- return hit ? { slot: hit.slot.id, root: hit.root, bindings: hit.bindings } : null;
58
- }
59
- /** The tier of `p` in the direction matrix: its slot's tier, the owner's for an inheriting slot, none for an untiered one; null when no slot owns it. */
60
- export function tierIn(scope, input) {
61
- const c = classifyIn(scope, input);
62
- if (!c.slot)
63
- return null;
64
- const tier = scope.byId.get(c.slot).tier;
65
- if (tier !== 'inherit')
66
- return tier;
67
- const owner = ownerIn(scope, input);
68
- return owner ? scope.byId.get(owner.slot).tier : 'none';
69
- }
@@ -1,12 +0,0 @@
1
- // slot-errors.mjs - the shared refusal type for HFS manifest and declaration loaders.
2
- export class HfsSlotsError extends Error {
3
- code;
4
- details;
5
- constructor(code, message, details = {}) {
6
- super(`${code}: ${message}`);
7
- this.name = 'HfsSlotsError';
8
- this.code = code;
9
- this.details = details;
10
- }
11
- }
12
- export const fail = (code, message, details) => { throw new HfsSlotsError(code, message, details); };
@@ -1,98 +0,0 @@
1
- // slot-imports.mjs - whether one file of a scope (the app root or one side) may import another: the tier direction matrix, the
2
- // owner units, the layer order and the public entry of an owner. Cycles are a graph property of the architecture check, not of one edge.
3
- import { RUNTIME_KIND } from './manifest-shape.mjs';
4
- import { classifyIn, ownerIn, tierIn } from './slot-classify.mjs';
5
- import { braceVariants, globExpression } from '../lib/glob.mjs';
6
- const isEntryFile = (name) => name === 'index.ts' || name === 'index.tsx';
7
- function declaredEntry(slot, relative) {
8
- return (slot.entries ?? []).some((entry) => braceVariants(entry).some((pattern) => globExpression(pattern).test(relative)));
9
- }
10
- function unownedPathProblem(from, to) {
11
- for (const side of [from, to]) {
12
- if (side.status === 'no-slot')
13
- return { allowed: false, reason: 'unowned', code: side.code, path: side.path, nearest: side.nearest };
14
- }
15
- return null;
16
- }
17
- function unavailableSlotProblem(from, to) {
18
- for (const side of [from, to]) {
19
- if (side.status !== 'owned')
20
- return { allowed: false, reason: `slot${side.status[0].toUpperCase()}${side.status.slice(1).replace(/-(.)/g, (_, c) => c.toUpperCase())}`, path: side.path, slot: side.slot };
21
- }
22
- return null;
23
- }
24
- function sameOwnerUnit(side, owner) {
25
- return owner ? `${owner.slot}:${owner.root}` : `${side.slot}:${side.root}`;
26
- }
27
- const layerIndex = (slot, root) => (slot.layers ? slot.layers.findIndex((layer) => root.split('/').includes(layer)) : -1);
28
- function lowerLayerProblem({ manifest, profile, byId }, from, to, fromTier, toTier, fromOwner, toOwner) {
29
- if (manifest.tiers[profile][fromTier].lowerLayerOnly && fromTier === toTier) {
30
- const fromSlot = byId.get((fromOwner ?? from).slot);
31
- const a = layerIndex(fromSlot, fromOwner?.root ?? from.root);
32
- const b = layerIndex(byId.get((toOwner ?? to).slot), toOwner?.root ?? to.root);
33
- if (a >= 0 && b >= 0 && b <= a)
34
- return { allowed: false, reason: 'layerOrder', fromLayer: fromSlot.layers[a], toLayer: fromSlot.layers[b] };
35
- }
36
- return null;
37
- }
38
- function privateEntryProblem({ repo, byId }, to, toOwner) {
39
- if (toOwner && repo.kind !== RUNTIME_KIND) {
40
- const relative = to.path === toOwner.root ? '' : to.path.slice(toOwner.root.length + 1);
41
- const ownerSlot = byId.get(toOwner.slot);
42
- const entry = isEntryFile(relative) || declaredEntry(byId.get(to.slot), to.path.slice(to.root.length + 1)) || (ownerSlot.tier === 'package' && relative === 'src/index.ts') || (ownerSlot.tier === 'app' && relative === 'app.module.ts');
43
- if (!entry)
44
- return { allowed: false, reason: 'notPublicEntry', owner: toOwner.root, path: to.path };
45
- }
46
- return null;
47
- }
48
- function tierImportProblem(scope, from, to, fromTier, toTier) {
49
- const { mayImport, mayImportKinds, mayImportSlots } = scope.manifest.tiers[scope.profile][fromTier] ?? {};
50
- if (!mayImport?.includes(toTier))
51
- return { allowed: false, reason: 'tierDirection', fromTier, toTier, mayImport: mayImport ?? [] };
52
- const kindRestriction = mayImportKinds?.[toTier];
53
- if (kindRestriction && (!kindRestriction.from.includes(from.kind) || !kindRestriction.to.includes(to.kind)))
54
- return { allowed: false, reason: 'tierDirection', fromTier, toTier, mayImport, kindRestriction, fromKind: from.kind ?? null, toKind: to.kind ?? null };
55
- const slotRestriction = mayImportSlots?.[toTier];
56
- if (slotRestriction && !slotRestriction.from.includes(from.slot))
57
- return { allowed: false, reason: 'tierDirection', fromTier, toTier, mayImport, slotRestriction, fromSlot: from.slot };
58
- return null;
59
- }
60
- /**
61
- * Whether `fromPath` may import `toPath`: {allowed, reason, ...}. Reasons: sameOwner, untiered, crossApp,
62
- * tierDirection, layerOrder, notPublicEntry, allowed, slotForbidden, slotNotEnabled, slotAmbiguous, and unowned (HFS_SLOT_UNDECLARED for the path no slot owns).
63
- * Cycles are a graph property and belong to the architecture check, not to one edge.
64
- */
65
- export function importAllowedIn(scope, fromPath, toPath) {
66
- const fromClassified = classifyIn(scope, fromPath);
67
- const toClassified = classifyIn(scope, toPath);
68
- const unowned = unownedPathProblem(fromClassified, toClassified);
69
- if (unowned)
70
- return unowned;
71
- const unavailable = unavailableSlotProblem(fromClassified, toClassified);
72
- if (unavailable)
73
- return unavailable;
74
- // reason: unavailableSlotProblem answers for every status but owned, so both paths are placed from here on
75
- const from = fromClassified;
76
- const to = toClassified;
77
- const fromTier = tierIn(scope, from.path);
78
- const toTier = tierIn(scope, to.path);
79
- if (fromTier === 'none' || toTier === 'none')
80
- return { allowed: true, reason: 'untiered' };
81
- if (from.bindings.app !== undefined && to.bindings.app !== undefined && from.bindings.app !== to.bindings.app)
82
- return { allowed: false, reason: 'crossApp', from: from.bindings.app, to: to.bindings.app };
83
- const fromOwner = ownerIn(scope, from.path);
84
- const toOwner = ownerIn(scope, to.path);
85
- if (sameOwnerUnit(from, fromOwner) === sameOwnerUnit(to, toOwner))
86
- return { allowed: true, reason: 'sameOwner' };
87
- const tierProblem = tierImportProblem(scope, from, to, fromTier, toTier);
88
- if (tierProblem)
89
- return tierProblem;
90
- const layerProblem = lowerLayerProblem(scope, from, to, fromTier, toTier, fromOwner, toOwner);
91
- if (layerProblem)
92
- return layerProblem;
93
- // A runtime owner is imported file by file (crossOwner of knowledge/hfs/runtime-slots.yaml): no public entry.
94
- const privateEntry = privateEntryProblem(scope, to, toOwner);
95
- if (privateEntry)
96
- return privateEntry;
97
- return { allowed: true, reason: 'allowed', fromTier, toTier };
98
- }
@@ -1,111 +0,0 @@
1
- import { isPlainObject } from '../../engine/plain-object.mjs';
2
- import { byCodeUnit } from '../lib/list.mjs';
3
- import { ruleParamsProblems } from './rule-params-shape.mjs';
4
- import { APP_KIND, EDITIONS, MANIFEST_KINDS, NAME, PRESENCE, RUNTIME_KIND, SEMVER, TESTS, TRACKED, manifestKind, runtimeShapeProblems, slotProblems, tierMapProblems } from './manifest-shape.mjs';
5
- export const PROFILES = ['be', 'fe'];
6
- /** Whether `value` names a side of an app. */
7
- export const isSide = (value) => PROFILES.includes(value);
8
- export const APP_SCOPE = 'app';
9
- export const SCOPES = [APP_SCOPE, ...PROFILES];
10
- /** Shape problems of a parsed manifest, in the words of modules/schemas/hfs-slots.schema.yaml. */
11
- function checkCoreManifestFields(m, bad) {
12
- const allowed = new Set(['schema', 'kind', 'version', 'versioning', 'presenceValues', 'trackedValues', 'testValues', 'editions', 'sides', 'appKinds', 'triggerKinds', 'tiers', 'ruleParams', 'crossOwner', 'crossApp', 'slots', 'consumers', 'naming']);
13
- for (const key of Object.keys(m))
14
- if (!allowed.has(key))
15
- bad.push(`unknown top-level key ${key}`);
16
- if (!/^starci\/hfs-slots@\d+$/.test(String(m.schema)))
17
- bad.push('schema must be starci/hfs-slots@<major>');
18
- if (!SEMVER.test(String(m.version)))
19
- bad.push('version must be MAJOR.MINOR.PATCH');
20
- if (!isPlainObject(m.versioning) || !['patch', 'minor', 'major', 'pins'].every((k) => typeof m.versioning[k] === 'string'))
21
- bad.push('versioning needs patch, minor, major and pins text');
22
- if (JSON.stringify(m.presenceValues) !== JSON.stringify(PRESENCE))
23
- bad.push(`presenceValues must be ${PRESENCE.join(', ')}`);
24
- if (JSON.stringify(m.trackedValues) !== JSON.stringify(TRACKED))
25
- bad.push(`trackedValues must be ${TRACKED.join(', ')}`);
26
- if (JSON.stringify(m.testValues) !== JSON.stringify(TESTS))
27
- bad.push(`testValues must be ${TESTS.join(', ')}`);
28
- if (JSON.stringify(m.editions) !== JSON.stringify(EDITIONS))
29
- bad.push(`editions must be ${EDITIONS.join(', ')}`);
30
- }
31
- function checkSideShapes(m, bad) {
32
- if (!isPlainObject(m.sides) || Object.keys(m.sides).sort(byCodeUnit).join() !== PROFILES.join())
33
- bad.push('sides must be a map with exactly be and fe');
34
- else
35
- for (const side of PROFILES) {
36
- const def = m.sides[side];
37
- if (!isPlainObject(def) || Object.keys(def).join() !== 'reads' || !Array.isArray(def.reads) || !def.reads.every((r) => typeof r === 'string' && /^[a-z][a-z0-9-]*\/([^/]+\/)+$/.test(r)) || new Set(def.reads).size !== def.reads.length)
38
- bad.push(`sides.${side} must be {reads: [unique <owner>/<dir>/ paths]}`);
39
- }
40
- }
41
- function checkTriggerKinds(m, bad) {
42
- if (m.triggerKinds !== undefined && (!Array.isArray(m.triggerKinds) || !m.triggerKinds.length || !m.triggerKinds.every((k) => NAME.test(String(k))) || new Set(m.triggerKinds).size !== m.triggerKinds.length))
43
- bad.push('triggerKinds must be a non-empty list of unique names');
44
- }
45
- function checkProfileMaps(m, bad) {
46
- for (const key of ['appKinds', 'tiers']) {
47
- if (!isPlainObject(m[key])) {
48
- bad.push(`${key} must be a map with be and fe`);
49
- continue;
50
- }
51
- for (const extra of Object.keys(m[key]))
52
- if (!isSide(extra) && !(key === 'tiers' && extra === COMPONENT_LIBRARY))
53
- bad.push(`${key}.${extra} is not a profile`);
54
- for (const profile of PROFILES)
55
- if (!(profile in m[key]))
56
- bad.push(`${key}.${profile} is missing`);
57
- }
58
- }
59
- /** The tier matrix of a component library (packages/grammar), beside the be and fe profiles: tiers.grammar. */
60
- const COMPONENT_LIBRARY = 'grammar';
61
- function checkComponentLibraryTiers(m, bad) {
62
- const tiers = m.tiers?.[COMPONENT_LIBRARY];
63
- if (tiers === undefined)
64
- return;
65
- bad.push(...tierMapProblems(COMPONENT_LIBRARY, tiers));
66
- if (!isPlainObject(tiers))
67
- return;
68
- for (const [tier, def] of Object.entries(tiers))
69
- for (const target of def?.mayImport ?? [])
70
- if (!(target in tiers))
71
- bad.push(`tiers.${COMPONENT_LIBRARY}.${tier}.mayImport names ${target}, which is not a ${COMPONENT_LIBRARY} tier`);
72
- }
73
- function checkAppKindAndTierShapes(m, bad) {
74
- for (const profile of PROFILES) {
75
- const kinds = m.appKinds?.[profile];
76
- if (kinds !== undefined && (!Array.isArray(kinds) || !kinds.length || !kinds.every((k) => NAME.test(String(k))) || new Set(kinds).size !== kinds.length))
77
- bad.push(`appKinds.${profile} must be a non-empty list of unique names`);
78
- const tiers = m.tiers?.[profile];
79
- if (tiers === undefined)
80
- continue;
81
- bad.push(...tierMapProblems(profile, tiers));
82
- }
83
- checkComponentLibraryTiers(m, bad);
84
- }
85
- function checkSlotShapes(m, bad) {
86
- if (!Array.isArray(m.slots) || !m.slots.length) {
87
- bad.push('slots must be a non-empty list');
88
- return false;
89
- }
90
- const logicRoles = Array.isArray(m.ruleParams?.be?.logicRoles) ? m.ruleParams.be.logicRoles : [];
91
- m.slots.forEach((slot, index) => bad.push(...slotProblems(slot, index, APP_KIND, { appScope: APP_SCOPE, scopes: SCOPES, logicRoles })));
92
- return true;
93
- }
94
- export function manifestShapeProblems(m) {
95
- const bad = [];
96
- if (!isPlainObject(m))
97
- return ['the manifest is not a map'];
98
- if (!MANIFEST_KINDS.includes(manifestKind(m)))
99
- return [`kind must be one of ${MANIFEST_KINDS.join(', ')}`];
100
- if (manifestKind(m) === RUNTIME_KIND)
101
- return runtimeShapeProblems(m);
102
- checkCoreManifestFields(m, bad);
103
- checkSideShapes(m, bad);
104
- checkTriggerKinds(m, bad);
105
- checkProfileMaps(m, bad);
106
- checkAppKindAndTierShapes(m, bad);
107
- bad.push(...ruleParamsProblems(m));
108
- if (!checkSlotShapes(m, bad))
109
- return bad;
110
- return bad;
111
- }