@starci/eslint-canon-be 3.0.8 → 3.0.10

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 (151) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/LICENSE +21 -0
  3. package/README.md +12 -6
  4. package/ambient-id.mjs +90 -0
  5. package/cli.mjs +181 -0
  6. package/comments.mjs +24 -36
  7. package/config-owner.mjs +20 -4
  8. package/connections.mjs +12 -12
  9. package/cookies.mjs +106 -0
  10. package/cqrs.mjs +22 -26
  11. package/data-access.mjs +9 -28
  12. package/default-deny.mjs +2 -1
  13. package/e2e-flow.mjs +4 -4
  14. package/event-bus.mjs +237 -0
  15. package/feature-thin.mjs +237 -0
  16. package/idempotency.mjs +57 -6
  17. package/index.mjs +22 -1
  18. package/infra-owner.mjs +1 -1
  19. package/injection.mjs +67 -22
  20. package/input-bounds.mjs +2 -1
  21. package/jobs.mjs +214 -0
  22. package/lib/ast.mjs +7 -0
  23. package/lib/config.mjs +1 -1
  24. package/lib/db-writes.mjs +1 -1
  25. package/lib/doors.mjs +81 -0
  26. package/lib/edition.mjs +45 -0
  27. package/lib/entity-writes.mjs +35 -0
  28. package/lib/path.mjs +0 -6
  29. package/lib/persistence.mjs +11 -18
  30. package/lib/ports.mjs +5 -2
  31. package/lib/specifier.mjs +27 -0
  32. package/lib/transactions.mjs +37 -0
  33. package/lib/transport-slots.mjs +8 -3
  34. package/lib/unit-spec.mjs +63 -2
  35. package/module-layering.mjs +3 -24
  36. package/module-shape.mjs +2 -2
  37. package/naming.mjs +2 -2
  38. package/package.json +5 -2
  39. package/project-graph.mjs +5 -2
  40. package/projections.mjs +117 -0
  41. package/query-safety.mjs +1 -1
  42. package/realtime.mjs +181 -0
  43. package/runtime/engine/config.mjs +486 -0
  44. package/runtime/engine/invalid-config.mjs +15 -0
  45. package/runtime/engine/orca-config.mjs +27 -0
  46. package/runtime/engine/secrets.mjs +130 -0
  47. package/runtime/knowledge/hfs/canon-pins.yaml +162 -31
  48. package/runtime/knowledge/hfs/rules.yaml +2059 -0
  49. package/runtime/knowledge/hfs/slots.yaml +912 -120
  50. package/runtime/knowledge/patterns/fe/folder.yaml +131 -25
  51. package/runtime/knowledge/sonar-gate.yaml +52 -18
  52. package/runtime/modules/models/registry.yaml +553 -0
  53. package/runtime/modules/models/runtimes.yaml +695 -0
  54. package/runtime/packages/hfs/templates/app/package-scripts/package.json +3 -10
  55. package/runtime/scripts/api/git/config-get.mjs +10 -0
  56. package/runtime/scripts/api/git/lib.mjs +18 -26
  57. package/runtime/scripts/api/git/ls-files.mjs +6 -0
  58. package/runtime/scripts/api/git/remote.mjs +5 -0
  59. package/runtime/scripts/api/git/rev-parse-query.mjs +5 -0
  60. package/runtime/scripts/hfs/architecture/ast-walks.mjs +220 -0
  61. package/runtime/scripts/hfs/architecture/backend.mjs +16 -23
  62. package/runtime/scripts/hfs/architecture/background-unowned.mjs +16 -34
  63. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +3 -1
  64. package/runtime/scripts/hfs/architecture/clones.mjs +4 -4
  65. package/runtime/scripts/hfs/architecture/config.mjs +9 -6
  66. package/runtime/scripts/hfs/architecture/connection-map.mjs +20 -8
  67. package/runtime/scripts/hfs/architecture/context-coupling.mjs +88 -0
  68. package/runtime/scripts/hfs/architecture/context-map.mjs +237 -0
  69. package/runtime/scripts/hfs/architecture/context-owner.mjs +82 -0
  70. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -0
  71. package/runtime/scripts/hfs/architecture/context-transaction.mjs +60 -0
  72. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +4 -10
  73. package/runtime/scripts/hfs/architecture/contracts.mjs +33 -162
  74. package/runtime/scripts/hfs/architecture/dead-exports.mjs +58 -29
  75. package/runtime/scripts/hfs/architecture/doc-language.mjs +1 -1
  76. package/runtime/scripts/hfs/architecture/entrypoint.mjs +2 -1
  77. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +2 -2
  78. package/runtime/scripts/hfs/architecture/feature-shape.mjs +5 -2
  79. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +1 -1
  80. package/runtime/scripts/hfs/architecture/frontend.mjs +17 -43
  81. package/runtime/scripts/hfs/architecture/hfs.mjs +24 -39
  82. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +1 -1
  83. package/runtime/scripts/hfs/architecture/index.mjs +17 -4
  84. package/runtime/scripts/hfs/architecture/machine-ast.mjs +44 -11
  85. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +27 -0
  86. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +30 -6
  87. package/runtime/scripts/hfs/architecture/next-data.mjs +22 -63
  88. package/runtime/scripts/hfs/architecture/owners.mjs +35 -15
  89. package/runtime/scripts/hfs/architecture/register-once.mjs +2 -1
  90. package/runtime/scripts/hfs/architecture/registration.mjs +23 -81
  91. package/runtime/scripts/hfs/architecture/required-files.mjs +20 -12
  92. package/runtime/scripts/hfs/architecture/schema-owner.mjs +17 -114
  93. package/runtime/scripts/hfs/architecture/server-action.mjs +24 -0
  94. package/runtime/scripts/hfs/architecture/side-boundary.mjs +16 -0
  95. package/runtime/scripts/hfs/architecture/source-names.mjs +27 -147
  96. package/runtime/scripts/hfs/architecture/sql-owner.mjs +59 -18
  97. package/runtime/scripts/hfs/architecture/sql-returning.mjs +64 -0
  98. package/runtime/scripts/hfs/architecture/supabase-ast.mjs +111 -0
  99. package/runtime/scripts/hfs/architecture/supabase-be.mjs +131 -0
  100. package/runtime/scripts/hfs/architecture/supabase-tables.mjs +42 -0
  101. package/runtime/scripts/hfs/architecture/supabase.mjs +434 -0
  102. package/runtime/scripts/hfs/architecture/surface.mjs +9 -3
  103. package/runtime/scripts/hfs/architecture/test-world-files.mjs +9 -19
  104. package/runtime/scripts/hfs/architecture/tiers.mjs +47 -5
  105. package/runtime/scripts/hfs/architecture/transport-owner.mjs +3 -3
  106. package/runtime/scripts/hfs/architecture/typescript.mjs +12 -26
  107. package/runtime/scripts/hfs/declaration-shape.mjs +62 -0
  108. package/runtime/scripts/hfs/declaration-slots.mjs +75 -0
  109. package/runtime/scripts/hfs/edition-slots.mjs +66 -0
  110. package/runtime/scripts/hfs/manifest-shape.mjs +109 -32
  111. package/runtime/scripts/hfs/param-names.mjs +18 -0
  112. package/runtime/scripts/hfs/path-findings.mjs +1 -1
  113. package/runtime/scripts/hfs/project-graph.mjs +3 -3
  114. package/runtime/scripts/hfs/repo-identity.mjs +9 -6
  115. package/runtime/scripts/hfs/rule-params-shape.mjs +50 -0
  116. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +6 -5
  117. package/runtime/scripts/hfs/rules/read.mjs +1 -1
  118. package/runtime/scripts/hfs/rules/secrets.mjs +3 -3
  119. package/runtime/scripts/hfs/rules/spec-placement.mjs +1 -1
  120. package/runtime/scripts/hfs/slots.mjs +78 -108
  121. package/runtime/scripts/hfs/test-world-slot.mjs +6 -0
  122. package/runtime/scripts/hfs/typescript-programs.mjs +0 -5
  123. package/runtime/scripts/hfs/view.mjs +3 -2
  124. package/runtime/scripts/lib/dockerfile.mjs +124 -0
  125. package/runtime/scripts/lib/git.mjs +36 -0
  126. package/runtime/scripts/lib/i18n.mjs +86 -0
  127. package/runtime/scripts/lib/jsdoc.mjs +35 -0
  128. package/runtime/scripts/lib/json.mjs +13 -3
  129. package/runtime/scripts/lib/language.mjs +24 -5
  130. package/runtime/scripts/lib/list.mjs +20 -0
  131. package/runtime/scripts/lib/mutation-fence.mjs +15 -0
  132. package/runtime/scripts/lib/path-key.mjs +57 -2
  133. package/runtime/scripts/lib/read-text.mjs +34 -0
  134. package/runtime/scripts/lib/regex.mjs +4 -0
  135. package/runtime/scripts/lib/secret-patterns.mjs +4 -3
  136. package/runtime/scripts/lib/sops-envelope.mjs +112 -0
  137. package/runtime/scripts/lib/stack-services.mjs +7 -31
  138. package/runtime/scripts/lib/ts-ast.mjs +35 -0
  139. package/runtime/scripts/lib/walk.mjs +4 -3
  140. package/schema-authority.mjs +14 -12
  141. package/service-deps.mjs +7 -13
  142. package/service-isolation.mjs +72 -0
  143. package/size-budget.mjs +1 -1
  144. package/test-world.mjs +5 -4
  145. package/testing.mjs +27 -24
  146. package/transport.mjs +12 -9
  147. package/unit-spec.mjs +1 -1
  148. package/user-copy.mjs +5 -4
  149. package/webhooks.mjs +173 -0
  150. package/runtime/scripts/api/sops/decrypt.mjs +0 -16
  151. package/runtime/scripts/lib/test-secrets.mjs +0 -116
@@ -6,7 +6,8 @@ import { machineKit } from './machine-ast.mjs';
6
6
  * `client-fetch-has-signal`. ESLint judges one file at a time by the spelling of a call; the machine judges the repository by
7
7
  * what the checker resolves. A repository has exactly ONE transport client and ONE Outcome union, both named by slot (never
8
8
  * by a path spelled here): the api package's (`fe.package.api.client`, `fe.package.api.outcome`) when the repository shares
9
- * it, or the only app's (`fe.transport.client`, `fe.transport.outcome`) when the repository declares exactly one app.
9
+ * it, or the only app's (`fe.transport.client`, `fe.transport.outcome`) when the repository declares exactly one app. The
10
+ * Outcome homes are the slots the manifest marks `outcomeHome` (the lite edition adds `fe.modules.db.outcome`), not a list kept here.
10
11
  *
11
12
  * - two or more clients, or two or more Outcome unions, in the repository (two apps each keeping one, or a package one plus
12
13
  * an app one) are findings on every copy;
@@ -30,7 +31,6 @@ const APP_CLIENT_SLOT = 'fe.transport.client';
30
31
  const APP_OUTCOME_SLOT = 'fe.transport.outcome';
31
32
  const PACKAGE_API_SLOT = 'fe.package.api';
32
33
  const CLIENT_SLOTS = new Set([APP_CLIENT_SLOT, 'fe.package.api.client']);
33
- const OUTCOME_SLOTS = new Set([APP_OUTCOME_SLOT, 'fe.package.api.outcome']);
34
34
  const NO_CLIENT = "the repository has no transport client. Create the one client (packages/<family>-api/src/client.ts, or the only app's modules/api/client.ts) and call it.";
35
35
 
36
36
  export function checkTransportOwner(input) {
@@ -60,7 +60,7 @@ export function checkTransportOwner(input) {
60
60
 
61
61
  const files = [...graph.files.values()].filter(file => file.slot && file.tier !== 'e2e');
62
62
  const clients = files.filter(file => CLIENT_SLOTS.has(file.slot));
63
- const outcomes = files.filter(file => OUTCOME_SLOTS.has(file.slot));
63
+ const outcomes = files.filter(file => resolver.slot(file.slot)?.outcomeHome === true);
64
64
  const clientRels = new Set(clients.map(file => file.rel));
65
65
  const list = items => items.map(item => item.rel).join(', ');
66
66
  const owned = clients.length ? `the repository has one transport (${list(clients)}). Call the client and take its Outcome.` : NO_CLIENT;
@@ -2,9 +2,11 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { createRequire } from 'node:module';
4
4
  import { canonical, isInside, slash } from './config.mjs';
5
+ import { crossesSide } from './side-boundary.mjs';
5
6
  import { sameOrUnder } from '../../lib/path-key.mjs';
6
7
  import { createTypeScriptProgram, readTypeScriptProject, resolveTypeScriptModule, sharedInProgramRun, typeScriptProjectReferencePath } from '../typescript-programs.mjs';
7
8
  import { readJsonFile } from '../../lib/json.mjs';
9
+ import { sourceLocation } from '../../lib/ts-ast.mjs';
8
10
  import { locateDeclaration } from '../slots.mjs';
9
11
 
10
12
  const CODE_EXTENSIONS = /\.(?:[cm]?[jt]sx?)$/i;
@@ -12,21 +14,11 @@ const TEST_FILE = /(?:^|[.-])(?:spec|test)\.[cm]?[jt]sx?$/i;
12
14
  const ASSET_EXTENSION = /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|avif|ico|woff2?|ttf|eot|ya?ml|json)$/i;
13
15
  // Framework build output a tsconfig may include (Next writes `.next/types/**/*.ts` back into tsconfig.json on
14
16
  // every build) is compiled for type resolution but is never source: it is gitignored, regenerated, and no
15
- // canon or architecture rule applies to it (starci-next inc-2260b3754afa, nivo inc-ffe60c49f502).
16
- export const GENERATED_SEGMENTS = new Set(['.next', '.turbo', '.vercel', '.output', '.nuxt', '.svelte-kit', '.expo', '.docusaurus', '.swc', '.cache']);
17
- export function isGeneratedPath(root, fileName) {
17
+ // canon or architecture rule applies to it (inc-ffe60c49f502).
18
+ const GENERATED_SEGMENTS = new Set(['.next', '.turbo', '.vercel', '.output', '.nuxt', '.svelte-kit', '.expo', '.docusaurus', '.swc', '.cache']);
19
+ function isGeneratedPath(root, fileName) {
18
20
  return slash(path.relative(root, fileName)).split('/').slice(0, -1).some(segment => GENERATED_SEGMENTS.has(segment));
19
21
  }
20
- // A `<tool>.config.*` or `<tool>.setup.*` module at the root of a project (beside a package manifest or a tsconfig.json:
21
- // next.config.ts and postcss.config.mjs of an app, which has no package.json of its own) is build tooling a broad `**/*.ts`
22
- // include pulls in; a `*.config.ts` inside a source tree (src/config/database.config.ts) has neither beside it and stays source.
23
- // The architecture program still reads tooling modules (a profile may declare one as source); the lint (hfs lint) judges one only
24
- // through the repository's own eslint.config.
25
- const TOOLING_MODULE = /^[^/]+\.(?:config|setup)\.[cm]?[jt]sx?$/i;
26
- export function isToolingModule(fileName) {
27
- return TOOLING_MODULE.test(path.basename(fileName)) && ['package.json', 'tsconfig.json'].some((manifest) => fs.existsSync(path.join(path.dirname(fileName), manifest)));
28
- }
29
-
30
22
  function diagnosticMessage(ts, diagnostic) {
31
23
  return ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
32
24
  }
@@ -53,7 +45,7 @@ function compilerError(ts, root, diagnostic, project, ruleId = 'ARCH_TSCONFIG_IN
53
45
  * Load TypeScript through the target package boundary, never through StarCi's own dependency graph. A side folder of an app has no
54
46
  * package.json of its own: the app root's one manifest is the boundary its TypeScript is installed under.
55
47
  */
56
- export function loadTargetTypeScript(repositoryRoot) {
48
+ function loadTargetTypeScript(repositoryRoot) {
57
49
  const packageFile = path.join(locateDeclaration(repositoryRoot).appRoot, 'package.json');
58
50
  if (!fs.existsSync(packageFile)) throw Error('ARCH_TYPESCRIPT_MISSING: target package.json is required to resolve target-installed TypeScript.');
59
51
  const targetRequire = createRequire(packageFile);
@@ -98,7 +90,7 @@ function runtimeImport(ts, node) {
98
90
  return true;
99
91
  }
100
92
 
101
- function isUnshadowedCommonJsRequire(ts, checker, expression) {
93
+ export function isUnshadowedCommonJsRequire(ts, checker, expression) {
102
94
  if (!ts.isIdentifier(expression) || expression.text !== 'require') return false;
103
95
  const symbol = checker?.getSymbolAtLocation(expression);
104
96
  if (!symbol) return true;
@@ -113,7 +105,7 @@ function isUnshadowedCommonJsRequire(ts, checker, expression) {
113
105
  * existing directory and a data-asset extension tail qualify; code never does, since a context of code would
114
106
  * be an import graph nobody wrote down. Returns the specifiers, or null when the import stays unproven.
115
107
  */
116
- export function assetContextSpecifiers(ts, sourceFile, argument) {
108
+ function assetContextSpecifiers(ts, sourceFile, argument) {
117
109
  if (!argument || !ts.isTemplateExpression(argument)) return null;
118
110
  const head = argument.head.text;
119
111
  const spans = argument.templateSpans;
@@ -168,11 +160,6 @@ function moduleReferences(ts, sourceFile, checker) {
168
160
  return { found, unproven };
169
161
  }
170
162
 
171
- function sourceLocation(sourceFile, node) {
172
- const point = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
173
- return { line: point.line + 1, column: point.character + 1 };
174
- }
175
-
176
163
  function isProductionSource(root, sourceFile) {
177
164
  return isInside(root, sourceFile.fileName)
178
165
  && CODE_EXTENSIONS.test(sourceFile.fileName)
@@ -210,7 +197,7 @@ function exportPatternCapture(pattern, request) {
210
197
  return request.startsWith(before) && request.endsWith(after) ? request.slice(before.length, request.length - after.length) : null;
211
198
  }
212
199
 
213
- function exportTargetStrings(value) {
200
+ export function exportTargetStrings(value) {
214
201
  if (typeof value === 'string') return [value];
215
202
  if (Array.isArray(value)) return value.flatMap(exportTargetStrings);
216
203
  if (value && typeof value === 'object' && !Object.keys(value).some(key => key.startsWith('.'))) return Object.values(value).flatMap(exportTargetStrings);
@@ -497,9 +484,7 @@ function typeScriptContext(config, loaded, paths) {
497
484
  || (config.repository && isInside(config.repository, actualTarget) && !slash(actualTarget).includes('/node_modules/'));
498
485
  // A side of an app (config.root is be/ or fe/) imports nothing of the app outside itself: the root holds no source, the other
499
486
  // side is another program, and a declared read (sides.fe.reads, be/contracts/) is codegen input, never an import.
500
- const crossesSide = config.packageRoot !== undefined && config.packageRoot !== config.root
501
- && isInside(config.packageRoot, actualTarget) && !isInside(config.root, actualTarget) && !slash(actualTarget).includes('/node_modules/');
502
- if (internal && crossesSide) {
487
+ if (internal && crossesSide(config, actualTarget)) {
503
488
  errors.push({
504
489
  ruleId: 'ARCH_INTERNAL_IMPORT_OUTSIDE',
505
490
  project: project.relative,
@@ -581,6 +566,8 @@ export function unwrapExpression(ts, expression) {
581
566
  return expression;
582
567
  }
583
568
 
569
+ /* ---- the AST walks every architecture checker shares ---- */
570
+
584
571
  /** The names of `expected` an import or re-export statement binds (all of them for a namespace or star form). */
585
572
  export function referencedExports(ts, statement, expected) {
586
573
  if (ts.isImportDeclaration(statement)) {
@@ -595,4 +582,3 @@ export function referencedExports(ts, statement, expected) {
595
582
  return [...expected];
596
583
  }
597
584
 
598
- export { isUnshadowedCommonJsRequire, sourceLocation };
@@ -0,0 +1,62 @@
1
+ // declaration-shape.mjs - the dependency-free hfs.json shape validation used by the HFS slot loader. Semantic checks
2
+ // against a loaded manifest remain in slots.mjs; this module mirrors modules/schemas/hfs-repo.schema.yaml only.
3
+ import { isPlainObject } from '../../engine/plain-object.mjs';
4
+ import { APP_KIND, connectionShapeProblems, NAME, RUNTIME_KIND, SLOT_ID } from './manifest-shape.mjs';
5
+ import { kindShapeProblems, patternShapeProblems } from './declaration-slots.mjs';
6
+
7
+ /** Shape problems of the optional hfs.json `supabase` block whose auth posture DB_CONFIG_POLICY checks. */
8
+ function supabaseBlockProblems(block) {
9
+ if (block === undefined) return [];
10
+ if (!isPlainObject(block)) return ['supabase must be an object'];
11
+ const bad = [];
12
+ for (const key of Object.keys(block)) if (!['enableSignup', 'jwtExpiry', 'siteUrl', 'redirectUrls', 'forceRls'].includes(key)) bad.push(`supabase has unknown key ${key}`);
13
+ if (block.enableSignup !== undefined && typeof block.enableSignup !== 'boolean') bad.push('supabase.enableSignup must be true or false');
14
+ if (block.jwtExpiry !== undefined && !(Number.isInteger(block.jwtExpiry) && block.jwtExpiry > 0 && block.jwtExpiry <= 3600)) bad.push('supabase.jwtExpiry must be an integer of seconds, 3600 at most');
15
+ if (block.siteUrl !== undefined && (typeof block.siteUrl !== 'string' || !block.siteUrl.trim())) bad.push('supabase.siteUrl must be a URL string');
16
+ for (const key of ['redirectUrls', 'forceRls']) if (block[key] !== undefined && !(Array.isArray(block[key]) && block[key].every((value) => typeof value === 'string' && value.trim()))) bad.push(`supabase.${key} must be a list of strings`);
17
+ return bad;
18
+ }
19
+
20
+ /** Shape problems of a parsed hfs.json, in the words of modules/schemas/hfs-repo.schema.yaml. */
21
+ export function declarationShapeProblems(declaration, profiles) {
22
+ const bad = [];
23
+ if (!isPlainObject(declaration)) return ['hfs.json is not an object'];
24
+ if (!(Number.isInteger(declaration.hfs) && declaration.hfs >= 1)) bad.push('hfs must be the pinned manifest major (an integer, 1 or more)');
25
+ if (!NAME.test(String(declaration.project))) bad.push('project must be a project name');
26
+ if (declaration.kind === RUNTIME_KIND) {
27
+ for (const key of Object.keys(declaration)) if (!['hfs', 'kind', 'project'].includes(key)) bad.push(`unknown key ${key} (a runtime declaration is {hfs, kind, project})`);
28
+ return bad;
29
+ }
30
+ for (const key of Object.keys(declaration)) if (!['hfs', 'kind', 'project', 'edition', 'supabase', 'sides', 'browser'].includes(key)) bad.push(`unknown key ${key}`);
31
+ bad.push(...supabaseBlockProblems(declaration.supabase));
32
+ if (declaration.browser !== undefined && declaration.browser !== true) bad.push('browser is `true` when the app has a browser journey (slot app.browser), and is left out otherwise');
33
+ if (declaration.kind !== APP_KIND) bad.push(`kind must be ${APP_KIND} (a product is one app repository with a be and an fe side) or ${RUNTIME_KIND} (the StarCi runtime repository)`);
34
+ if (!isPlainObject(declaration.sides) || Object.keys(declaration.sides).sort().join() !== profiles.join()) { bad.push('sides must declare exactly be and fe'); return bad; }
35
+ const names = new Map();
36
+ for (const side of profiles) {
37
+ const value = declaration.sides[side];
38
+ const at = `sides.${side}`;
39
+ if (!isPlainObject(value)) { bad.push(`${at} must be an object`); continue; }
40
+ for (const key of Object.keys(value)) if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads'].includes(key)) bad.push(`${at} has unknown key ${key}`);
41
+ if (!Array.isArray(value.apps) || !value.apps.length) bad.push(`${at}.apps must list every ${side}/apps/<name> with its kind`);
42
+ else value.apps.forEach((app, index) => {
43
+ if (!isPlainObject(app) || !NAME.test(String(app.name)) || !NAME.test(String(app.kind)) || Object.keys(app).some((key) => key !== 'name' && key !== 'kind')) bad.push(`${at}.apps[${index}] must be {name, kind}`);
44
+ else if (names.has(app.name)) bad.push(`app ${app.name} is declared twice (${names.get(app.name)} and ${side})`);
45
+ else names.set(app.name, side);
46
+ });
47
+ if (value.optionalSlots !== undefined && (!Array.isArray(value.optionalSlots) || !value.optionalSlots.every((slot) => SLOT_ID.test(String(slot))) || new Set(value.optionalSlots).size !== value.optionalSlots.length)) bad.push(`${at}.optionalSlots must be a unique list of slot ids`);
48
+ bad.push(...patternShapeProblems(value, at, NAME), ...kindShapeProblems(value, at, NAME));
49
+ if (value.reads !== undefined && (!Array.isArray(value.reads) || !value.reads.every((read) => typeof read === 'string' && read.length > 0) || new Set(value.reads).size !== value.reads.length)) bad.push(`${at}.reads must be a unique list of paths`);
50
+ if (value.connections !== undefined) {
51
+ if (side !== 'be') { bad.push('connections belong to the be side'); continue; }
52
+ const list = Array.isArray(value.connections) ? value.connections : null;
53
+ const shape = connectionShapeProblems(list, value.apps);
54
+ if (shape.length) bad.push(...shape);
55
+ else {
56
+ if (new Set(list.map((connection) => connection.name)).size !== list.length) bad.push('connections names must be unique');
57
+ for (const a of list) for (const b of list) if (a !== b && `${b.envPrefix}_`.startsWith(`${a.envPrefix}_`)) bad.push(`connections ${a.name} and ${b.name} share env keys (${a.envPrefix}_ covers ${b.envPrefix}_)`);
58
+ }
59
+ }
60
+ }
61
+ return bad;
62
+ }
@@ -0,0 +1,75 @@
1
+ // declaration-slots.mjs - how an app declaration (hfs.json) switches on the opt-in slots of a side: by name (`optionalSlots`), by app kind
2
+ // (a slot with `appKind`) and by declared pattern (a slot with `pattern: <name>` is enabled by `sides.<side>.patterns: [<name>]`, one
3
+ // mechanism for every pattern: saga, event-bus, fenced-job, ...). slots.mjs asks this file to judge a side's lists and to say whether a
4
+ // slot is enabled for a repository.
5
+
6
+ /** The problems of a side's `optionalSlots` and `patterns` against the manifest. */
7
+ export function optionalSlotProblems(manifest, side, s) {
8
+ const bad = [];
9
+ for (const id of s.optionalSlots ?? []) {
10
+ const slot = manifest.slots.find((candidate) => candidate.id === id);
11
+ if (!slot || !slot.profiles.includes(side)) bad.push(`sides.${side}.optionalSlots names ${id}, which is not a ${side} slot`);
12
+ else if (slot.presence !== 'opt-in') bad.push(`sides.${side}.optionalSlots names ${id}, which is ${slot.presence}, not opt-in`);
13
+ else if (slot.appKind !== undefined) bad.push(`sides.${side}.optionalSlots names ${id}; an app of kind ${slot.appKind} enables it`);
14
+ }
15
+ for (const name of s.patterns ?? []) {
16
+ if (!manifest.slots.some((slot) => slot.profiles.includes(side) && slot.pattern === name)) bad.push(`sides.${side}.patterns names ${name}, which no ${side} slot declares as its pattern`);
17
+ }
18
+ if (s.kinds !== undefined && side !== 'be') bad.push(`sides.${side}.kinds belongs to the be side`);
19
+ for (const kind of s.kinds ?? []) {
20
+ if (!(manifest.triggerKinds ?? []).includes(kind)) bad.push(`sides.${side}.kinds names ${kind}, which is not one of triggerKinds (${(manifest.triggerKinds ?? []).join(', ')})`);
21
+ }
22
+ return bad;
23
+ }
24
+
25
+ /** The problems of the shape of a side's `patterns` list (a unique list of pattern names). */
26
+ export function patternShapeProblems(s, at, namePattern) {
27
+ const list = s.patterns;
28
+ if (list === undefined) return [];
29
+ return Array.isArray(list) && list.every((value) => namePattern.test(String(value))) && new Set(list).size === list.length ? [] : [`${at}.patterns must be a unique list of pattern names`];
30
+ }
31
+
32
+ /** The problems of the shape of a side's `kinds` list (a unique list of trigger kind names). */
33
+ export function kindShapeProblems(s, at, namePattern) {
34
+ const list = s.kinds;
35
+ if (list === undefined) return [];
36
+ return Array.isArray(list) && list.every((value) => namePattern.test(String(value))) && new Set(list).size === list.length ? [] : [`${at}.kinds must be a unique list of trigger kind names`];
37
+ }
38
+
39
+ /** The problems of `ruleParams.be.kindPatterns` (trigger kind -> patterns) and `ruleParams.be.addKinds` (starci app add noun -> {topic, variable, patterns, trigger?, needs?, also?, defaults?, wire?}). */
40
+ export function kindParamProblems(be, triggerKinds) {
41
+ const kebab = /^[a-z][a-z0-9-]*$/;
42
+ const names = (list) => Array.isArray(list) && list.every((value) => kebab.test(String(value))) && new Set(list).size === list.length;
43
+ const bad = [];
44
+ const patterns = be.kindPatterns;
45
+ if (patterns === null || typeof patterns !== 'object' || Array.isArray(patterns) || !Object.entries(patterns).every(([kind, list]) => (triggerKinds ?? []).includes(kind) && names(list))) bad.push('ruleParams.be.kindPatterns must map a trigger kind to a unique list of pattern names');
46
+ const nouns = be.addKinds;
47
+ const nounOk = (spec) => spec !== null && typeof spec === 'object' && kebab.test(String(spec.topic)) && kebab.test(String(spec.variable)) && names(spec.patterns) && (spec.trigger === undefined || kebab.test(String(spec.trigger))) && (spec.needs === undefined || names(spec.needs)) && (spec.also === undefined || names(spec.also)) && (spec.defaults === undefined || (typeof spec.defaults === 'object' && !Array.isArray(spec.defaults))) && (spec.wire === undefined || (spec.wire !== null && typeof spec.wire === 'object' && ['file', 'import', 'symbol'].every((key) => typeof spec.wire[key] === 'string' && spec.wire[key] !== '')));
48
+ if (nouns === null || typeof nouns !== 'object' || Array.isArray(nouns) || !Object.entries(nouns).every(([noun, spec]) => kebab.test(noun) && nounOk(spec))) bad.push('ruleParams.be.addKinds must map a noun to {topic, variable, patterns, trigger?, needs?, also?, defaults?}');
49
+ return bad;
50
+ }
51
+
52
+ /** The problems of `ruleParams.be.patternScenarios`: a pattern name to a non-empty list of unique kebab-case scenario ids. */
53
+ export function scenarioProblem(scenarios) {
54
+ const kebab = /^[a-z][a-z0-9-]*$/;
55
+ const ok = scenarios !== null && typeof scenarios === 'object' && !Array.isArray(scenarios) && Object.entries(scenarios).every(([name, list]) => kebab.test(name) && Array.isArray(list) && list.length > 0 && list.every((id) => kebab.test(String(id))) && new Set(list).size === list.length);
56
+ return ok ? [] : ['ruleParams.be.patternScenarios must map a pattern name to a non-empty list of unique kebab-case scenario ids'];
57
+ }
58
+
59
+ /** The problems of the `trigger` of a slot against the manifest's `triggerKinds`: a known kind, on a feature-tier slot only. */
60
+ export function triggerProblems(slot, triggerKinds) {
61
+ if (slot.trigger === undefined) return [];
62
+ const bad = [];
63
+ if (!(triggerKinds ?? []).includes(slot.trigger)) bad.push(`slot ${slot.id}: trigger ${slot.trigger} is not one of triggerKinds`);
64
+ if (slot.tier !== 'feature') bad.push(`slot ${slot.id}: a trigger belongs to a feature-tier slot`);
65
+ return bad;
66
+ }
67
+
68
+ /** Whether an opt-in slot is enabled for the repository: by its app kind, by a connection's provider, by name in optionalSlots, or by its declared pattern. */
69
+ export function declaredSlotEnabled(slot, repo) {
70
+ if (slot.appKind !== undefined) return repo.apps.some((app) => app.kind === slot.appKind);
71
+ // A provider declared on any connection (be owns them all today) enables the provider slots of every profile: repo.providers
72
+ // is the app-wide union the declaration resolver computed; a hand-built repo falls back to its own connections.
73
+ if (slot.provider !== undefined) return (repo.providers ?? (repo.connections ?? []).map((connection) => connection.provider)).includes(slot.provider);
74
+ return repo.optionalSlots.includes(slot.id) || (slot.pattern !== undefined && (repo.patterns ?? []).includes(slot.pattern));
75
+ }
@@ -0,0 +1,66 @@
1
+ // edition.mjs - the one edition filter shared by the HFS slot resolver, declaration validation, rule catalog and
2
+ // edition-specific rule parameters. Full is the default; lite changes data views, never the checks that consume them.
3
+ import { isPlainObject } from '../../engine/plain-object.mjs';
4
+ import { EDITIONS } from './manifest-shape.mjs';
5
+
6
+ /** The presence of `slot` under edition lite for `profile`: `litePresence`, else the slot's own presence. */
7
+ export function litePresenceOf(slot, profile) {
8
+ const lp = slot.litePresence;
9
+ if (lp === undefined) return slot.presence;
10
+ return isPlainObject(lp) ? (lp[profile] ?? slot.presence) : lp;
11
+ }
12
+
13
+ /** Whether `slot` exists under `edition` of `manifest` (default: the manifest's own editions). */
14
+ export function slotInEdition(manifest, slot, edition) {
15
+ return (slot.editions ?? manifest.editions ?? EDITIONS).includes(edition);
16
+ }
17
+
18
+ /** The slot as `edition` sees it: lite overlays its data, presence and tracking while forbidding every test world. */
19
+ export function effectiveSlot(slot, profile, edition) {
20
+ if (edition !== 'lite') return slot;
21
+ const { lite, litePresence, ...base } = slot;
22
+ const presence = litePresenceOf(slot, profile);
23
+ const tracked = presence === 'forbidden' ? 'external' : (slot.tracked === 'external' ? 'tracked' : slot.tracked);
24
+ return { ...base, ...(lite ?? {}), presence, tracked, tests: 'none' };
25
+ }
26
+
27
+ /** The template group starci app sync renders `slot` from under `edition`: `liteManagedBy` (else `managedBy`) in lite, `managedBy` otherwise; undefined when unmanaged. */
28
+ export function managedGroupOf(slot, edition) {
29
+ return edition === 'lite' ? (slot.liteManagedBy ?? slot.managedBy) : slot.managedBy;
30
+ }
31
+
32
+ /** The declared edition and the vocabulary against which it is validated. */
33
+ export function declarationEdition(manifest, declaration) {
34
+ const edition = declaration.edition === undefined ? 'full' : declaration.edition;
35
+ const known = manifest.editions ?? EDITIONS;
36
+ return { edition, known, valid: known.includes(edition) };
37
+ }
38
+
39
+ /** Problems of an optional rule-catalog `editions` list, in the catalog schema's words. */
40
+ export function ruleEditionProblems(rule, label) {
41
+ if (rule.editions === undefined) return [];
42
+ const bad = [];
43
+ if (!Array.isArray(rule.editions) || !rule.editions.length) return [`${label}.editions must be a non-empty list`];
44
+ for (const value of rule.editions) if (!EDITIONS.includes(value)) bad.push(`${label}.editions has ${JSON.stringify(value)}, not one of ${EDITIONS.join(', ')}`);
45
+ if (new Set(rule.editions).size !== rule.editions.length) bad.push(`${label}.editions repeats a value`);
46
+ return bad;
47
+ }
48
+
49
+ /** Whether a catalogued rule owner judges its finding under `edition`; uncatalogued codes always remain judged. */
50
+ export function judgedInEdition(owner, edition = 'full') {
51
+ return !owner?.editions || owner.editions.includes(edition);
52
+ }
53
+
54
+ /** Whether the enforcer `kind:id` of the catalog `rules` runs under `edition`: every rule listing it is judged there, and the enforcer row's own `editions` (a rule with several enforcers where only one is full-only) agrees. A lint rule no rule lists runs everywhere. */
55
+ export function enforcerJudgedInEdition(rules, kind, id, edition = 'full') {
56
+ const owners = rules.filter((rule) => rule.enforcers.some((enforcer) => enforcer.kind === kind && enforcer.id === id));
57
+ return owners.every((rule) => judgedInEdition(rule, edition) && rule.enforcers.filter((enforcer) => enforcer.kind === kind && enforcer.id === id).every((enforcer) => judgedInEdition(enforcer, edition)));
58
+ }
59
+
60
+ /** A frozen copy of one profile's parameters, with its lite overrides applied only in the lite edition. */
61
+ export function editionRuleParams(params, edition) {
62
+ const { lite, ...base } = params;
63
+ const merged = edition === 'lite' && lite ? { ...base, ...lite } : base;
64
+ const deepFreeze = (value) => { if (value && typeof value === 'object') Object.values(value).forEach(deepFreeze); return Object.freeze(value); };
65
+ return deepFreeze(structuredClone(merged));
66
+ }
@@ -1,31 +1,96 @@
1
1
  // manifest-shape.mjs - the shape rules of an HFS slot manifest that both manifest kinds share, and the whole shape of a
2
- // manifest of kind runtime (knowledge/hfs/runtime-slots.yaml): the slot fields, the tier map, ruleParams.runtime and the
3
- // `pending` allowlist. scripts/hfs/slots.mjs (loadSlotManifest) is the only reader; it adds the app kind's own rules
2
+ // manifest of kind runtime (knowledge/hfs/runtime-slots.yaml): the slot fields, the tier map and ruleParams.runtime.
3
+ // scripts/hfs/slots.mjs (loadSlotManifest) is the only reader; it adds the app kind's own rules
4
4
  // (sides, app kinds) and refuses a manifest whole on any problem (HFS_MANIFEST_INVALID). Pure: every function takes a
5
5
  // parsed manifest or slot and returns a list of problems in the words of modules/schemas/hfs-slots.schema.yaml.
6
6
  import { isPlainObject } from '../../engine/plain-object.mjs';
7
+ import { stringList } from '../lib/list.mjs';
7
8
 
8
9
  export const SEMVER = /^(\d+)\.(\d+)\.(\d+)$/;
9
10
  export const NAME = /^[a-z][a-z0-9-]*$/;
10
11
  export const ENV_PREFIX = /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/;
12
+ /** How a bounded context (a connection) is isolated: its own logical database, or its own schema of a shared one. */
13
+ const CONTEXT_ISOLATIONS = Object.freeze(["database", "schema"]);
14
+ /** The app kinds that may own a context: the services, never the migrate or cli apps that only run migrations. */
15
+ const CONTEXT_OWNER_KINDS = Object.freeze(["api", "worker"]);
16
+ /** The database engines a connection may run on: a self-described Postgres, or the Postgres of a Supabase project. */
17
+ const CONNECTION_PROVIDERS = Object.freeze(["postgres", "supabase"]);
18
+ /** The editions an app repository may declare in hfs.json (`full` when absent): the filter slots.mjs applies. */
19
+ export const EDITIONS = Object.freeze(["full", "lite"]);
20
+ /** What decides where schema changes live (ruleParams.<side>.schemaAuthority): TypeORM migrations under persistence/, or the Supabase migration tree. */
21
+ export const SCHEMA_AUTHORITIES = Object.freeze(["typeorm", "supabase"]);
22
+ /**
23
+ * The shape problems of the `connections` of one side: a list of {name, envPrefix, owner, isolation}, the owner an api or worker app
24
+ * of the same side (a connection is a bounded context and one service owns it), isolation `database` or `schema`.
25
+ *
26
+ * @param {unknown} list - The declared connections (null when it is not an array).
27
+ * @param {unknown} apps - The declared apps of the same side.
28
+ * @returns {string[]} The problems, none when the shape is right.
29
+ */
30
+ export function connectionShapeProblems(list, apps) {
31
+ const keys = (c) => isPlainObject(c) && NAME.test(String(c.name)) && ENV_PREFIX.test(String(c.envPrefix)) && NAME.test(String(c.owner)) && CONTEXT_ISOLATIONS.includes(c.isolation)
32
+ && (c.provider === undefined || CONNECTION_PROVIDERS.includes(c.provider))
33
+ && Object.keys(c).every((k) => ['name', 'envPrefix', 'owner', 'isolation', 'provider'].includes(k)) && ['name', 'envPrefix', 'owner', 'isolation'].every((k) => k in c);
34
+ if (!list || !list.every(keys)) return [`connections must be a list of {name: kebab-case context name, envPrefix: UPPER_SNAKE prefix of its env keys, owner: the service app that owns the context, isolation: ${CONTEXT_ISOLATIONS.join(' | ')}, provider?: ${CONNECTION_PROVIDERS.join(' | ')}}`];
35
+ const owns = (c) => Array.isArray(apps) && apps.some((app) => isPlainObject(app) && app.name === c.owner && CONTEXT_OWNER_KINDS.includes(app.kind));
36
+ return list.filter((c) => !owns(c)).map((c) => `connections ${c.name} is owned by ${c.owner}, which is not a ${CONTEXT_OWNER_KINDS.join(' or ')} app declared in the same side`);
37
+ }
11
38
  export const SLOT_ID = /^(app|repo|be|fe)\.[a-z0-9-]+(\.[a-z0-9-]+)*$/;
12
- export const RUNTIME_SLOT_ID = /^runtime\.[a-z0-9-]+(\.[a-z0-9-]+)*$/;
39
+ const RUNTIME_SLOT_ID = /^runtime\.[a-z0-9-]+(\.[a-z0-9-]+)*$/;
13
40
  export const PRESENCE = ['required', 'optional', 'opt-in', 'forbidden'];
14
41
  export const TRACKED = ['tracked', 'ignored', 'external'];
15
42
  /** A runtime manifest adds `generated`: tracked, written only by the slot's generatedBy, judged by drift (RT_GENERATED_DRIFT). */
16
- export const RUNTIME_TRACKED = [...TRACKED, 'generated'];
43
+ const RUNTIME_TRACKED = [...TRACKED, 'generated'];
17
44
  export const TESTS = ['unit-beside', 'e2e', 'none'];
45
+ /** The coverage mode of a tracked slot of the be profile (scripts/hfs/coverage-scope.mjs derives the three coverage consumers from it). */
46
+ export const COVERAGE = ['required', 'none'];
18
47
  export const APP_KIND = 'app';
48
+
49
+ /**
50
+ * The unit-tested roles of a back end whose spec is required (ruleParams.be.unitRoles of the slot manifest): [{ role, spec, slot?, exempt? }].
51
+ * THE one list: every check that asks "is this file unit-tested, and where is its spec" asks it here. What the unit run MEASURES is
52
+ * logicRoles over the coverage-required slots (coverage-scope.mjs), not this list.
53
+ */
54
+ export const unitRolesOf = (manifest) => manifest.ruleParams.be.unitRoles;
55
+
56
+ /** The roles that carry logic (ruleParams.be.logicRoles): measured at 100 per file inside a coverage-required slot. */
57
+ export const logicRolesOf = (manifest) => manifest.ruleParams.be.logicRoles;
58
+
59
+ /** The roles a feature-tier file is judged thin by (ruleParams.be.thinRoles, R203 BE_FEATURE_THIN). */
60
+ export const thinRolesOf = (manifest) => manifest.ruleParams.be.thinRoles;
61
+
62
+ /** Shape problems of ruleParams.be.unitRoles: unique roles of the suffix vocabulary, each spec `<role>.spec`. */
63
+ export function unitRolesProblems(be) {
64
+ const roles = be.unitRoles;
65
+ const roleOk = (r) => r !== null && typeof r === 'object' && !Array.isArray(r) && Object.keys(r).every((k) => ['role', 'spec', 'slot', 'exempt'].includes(k)) && NAME.test(String(r.role)) && String(r.spec) === `${r.role}.spec` && (r.slot === undefined || /^be.[a-z0-9.-]+$/.test(String(r.slot))) && (r.exempt === undefined || (Array.isArray(r.exempt) && r.exempt.every((c) => /^[A-Z][A-Z0-9_]+$/.test(String(c)))));
66
+ if (!Array.isArray(roles) || !roles.length || !roles.every(roleOk) || new Set(roles.map((r) => r.role)).size !== roles.length) return ['ruleParams.be.unitRoles must be a non-empty list of unique {role, spec: <role>.spec, slot?, exempt?: [rule codes]}'];
67
+ if (Array.isArray(be.suffixes) && roles.some((r) => !be.suffixes.includes(r.role))) return ['ruleParams.be.unitRoles names a role that is not in ruleParams.be.suffixes'];
68
+ return [];
69
+ }
70
+
71
+ /** Shape problems of ruleParams.be.logicRoles and thinRoles: each a non-empty list of unique roles of the suffix vocabulary; every unit role is a logic role. */
72
+ export function roleListProblems(be) {
73
+ const bad = [];
74
+ for (const key of ['logicRoles', 'thinRoles']) {
75
+ const list = be[key];
76
+ if (!strList(list) || !list.length || new Set(list).size !== list.length || !list.every((role) => NAME.test(role))) bad.push(`ruleParams.be.${key} must be a non-empty list of unique kebab-case roles`);
77
+ else if (Array.isArray(be.suffixes) && list.some((role) => !be.suffixes.includes(role))) bad.push(`ruleParams.be.${key} names a role that is not in ruleParams.be.suffixes`);
78
+ }
79
+ if (strList(be.logicRoles) && Array.isArray(be.unitRoles) && be.unitRoles.some((r) => r?.slot === undefined && !be.logicRoles.includes(r?.role))) bad.push('every ruleParams.be.unitRoles role that is not tied to a slot is a logic role (ruleParams.be.logicRoles)');
80
+ return bad;
81
+ }
19
82
  /** The kind of a manifest and of a declaration that describes the StarCi runtime repository; also its one profile. */
20
83
  export const RUNTIME_KIND = 'runtime';
21
84
  export const MANIFEST_KINDS = [APP_KIND, RUNTIME_KIND];
22
85
  /** The kind of a parsed manifest: `kind`, or app when absent (knowledge/hfs/slots.yaml carries none). */
23
86
  export const manifestKind = (m) => (isPlainObject(m) && m.kind !== undefined ? m.kind : APP_KIND);
24
- export const strList = (v) => Array.isArray(v) && v.every((s) => typeof s === 'string' && s.length > 0);
87
+ const strList = (v) => stringList(v);
25
88
 
26
- const APP_SLOT_KEYS = ['id', 'profiles', 'path', 'presence', 'tracked', 'tier', 'tests', 'owner', 'appKind', 'minInstances', 'requiredWhen', 'requiredInstances', 'requires', 'allows', 'forbids', 'layers', 'kinds', 'roles', 'composedBy', 'budget', 'managedBy', 'rules', 'goesTo', 'why', 'since', 'retiredIn', 'successor'];
89
+ const APP_SLOT_KEYS = ['id', 'profiles', 'path', 'presence', 'tracked', 'tier', 'tests', 'owner', 'appKind', 'minInstances', 'requiredWhen', 'requiredInstances', 'requires', 'pattern', 'trigger', 'allows', 'forbids', 'layers', 'kinds', 'roles', 'composedBy', 'budget', 'managedBy', 'liteManagedBy', 'rules', 'goesTo', 'why', 'since', 'retiredIn', 'successor', 'perConnection', 'parent', 'editions', 'litePresence', 'lite', 'provider', 'coverage', 'entries', 'outcomeHome', 'anonymousActions'];
90
+ /** The fields a slot's `lite` overlay may hold: the same keys it would carry in the slot body, resolved under edition lite. */
91
+ const LITE_OVERLAY_KEYS = ['path', 'requires', 'allows', 'forbids', 'minInstances', 'requiredInstances'];
27
92
  /** A runtime slot has no app kind, side composition, layer or managed template; it may name the generator of a generated copy. */
28
- const RUNTIME_SLOT_KEYS = ['id', 'profiles', 'path', 'presence', 'tracked', 'tier', 'tests', 'owner', 'minInstances', 'requires', 'allows', 'forbids', 'budget', 'rules', 'goesTo', 'why', 'since', 'retiredIn', 'successor', 'generatedBy'];
93
+ const RUNTIME_SLOT_KEYS = ['id', 'profiles', 'path', 'presence', 'tracked', 'tier', 'tests', 'owner', 'minInstances', 'requires', 'allows', 'forbids', 'budget', 'rules', 'goesTo', 'why', 'since', 'retiredIn', 'successor', 'generatedBy', 'parent'];
29
94
 
30
95
  /** Shape problems of one slot of a manifest of `kind` (app or runtime). */
31
96
  export function slotProblems(slot, index, kind, { appScope = 'app', scopes = [] } = {}) {
@@ -47,14 +112,23 @@ export function slotProblems(slot, index, kind, { appScope = 'app', scopes = []
47
112
  else if ((slot.profiles[0] === appScope) !== String(slot.id).startsWith(`${appScope}.`)) bad.push(`${at}: an app-root slot has profiles [app] and an id app.<name>, and only it`);
48
113
  }
49
114
  if (typeof slot.path !== 'string' || !slot.path) bad.push(`${at}: path is required`);
115
+ if (slot.parent !== undefined && !/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/.test(String(slot.parent))) bad.push(`${at}: parent must be a slot id`);
50
116
  if (!PRESENCE.includes(slot.presence)) bad.push(`${at}: presence must be one of ${PRESENCE.join(', ')}`);
51
117
  if (!tracked.includes(slot.tracked)) bad.push(`${at}: tracked must be one of ${tracked.join(', ')}`);
52
118
  if (!NAME.test(String(slot.tier))) bad.push(`${at}: tier must be a tier name, none or inherit`);
53
119
  if (!TESTS.includes(slot.tests)) bad.push(`${at}: tests must be one of ${TESTS.join(', ')}`);
54
120
  if (slot.owner !== undefined && typeof slot.owner !== 'boolean') bad.push(`${at}: owner must be a boolean`);
121
+ if (!runtime) {
122
+ const measured = Array.isArray(slot.profiles) && slot.profiles.includes('be') && slot.tracked === 'tracked';
123
+ if (measured && !COVERAGE.includes(slot.coverage)) bad.push(`${at}: coverage must be one of ${COVERAGE.join(', ')} (every tracked slot of the be profile declares it)`);
124
+ if (!measured && slot.coverage !== undefined) bad.push(`${at}: coverage belongs to a tracked slot of the be profile only`);
125
+ }
55
126
  if (slot.appKind !== undefined && !NAME.test(String(slot.appKind))) bad.push(`${at}: appKind must be a name`);
127
+ if (slot.trigger !== undefined && !NAME.test(String(slot.trigger))) bad.push(`${at}: trigger must be a trigger kind name`);
128
+ if (slot.pattern !== undefined && !NAME.test(String(slot.pattern))) bad.push(`${at}: pattern must be a pattern name`);
56
129
  if (slot.minInstances !== undefined && !(Number.isInteger(slot.minInstances) && slot.minInstances >= 1)) bad.push(`${at}: minInstances must be a positive integer`);
57
130
  if (slot.requiredWhen !== undefined && slot.requiredWhen !== 'connections') bad.push(`${at}: requiredWhen may only be connections`);
131
+ if (slot.pattern !== undefined && !/^[a-z][a-z0-9-]*$/.test(String(slot.pattern))) bad.push(`${at}: pattern must be a kebab-case pattern name`);
58
132
  if (slot.requiredInstances !== undefined && !(isPlainObject(slot.requiredInstances) && Object.values(slot.requiredInstances).every((v) => strList(v) && v.length))) bad.push(`${at}: requiredInstances must map a variable to a non-empty list of names`);
59
133
  for (const key of ['requires', 'allows', 'forbids', 'layers', 'kinds']) if (slot[key] !== undefined && !strList(slot[key])) bad.push(`${at}: ${key} must be a list of strings`);
60
134
  if (slot.kinds !== undefined && strList(slot.kinds) && (!slot.kinds.length || new Set(slot.kinds).size !== slot.kinds.length || slot.kinds.some((k) => !NAME.test(k) || (slot.layers ?? []).includes(k)))) bad.push(`${at}: kinds must be a non-empty list of unique folder names that are not layers`);
@@ -62,7 +136,33 @@ export function slotProblems(slot, index, kind, { appScope = 'app', scopes = []
62
136
  if (slot.composedBy !== undefined && !(strList(slot.composedBy) && slot.composedBy.length && new Set(slot.composedBy).size === slot.composedBy.length)) bad.push(`${at}: composedBy must be a non-empty list of unique app kinds`);
63
137
  if (slot.budget !== undefined && !(isPlainObject(slot.budget) && Object.keys(slot.budget).length && Object.values(slot.budget).every((v) => Number.isInteger(v) && v >= 1))) bad.push(`${at}: budget must map names to positive integers`);
64
138
  if (slot.managedBy !== undefined && !NAME.test(String(slot.managedBy))) bad.push(`${at}: managedBy must be a template id`);
139
+ if (slot.liteManagedBy !== undefined && !NAME.test(String(slot.liteManagedBy))) bad.push(`${at}: liteManagedBy must be a template id`);
140
+ if (!runtime) {
141
+ if (slot.editions !== undefined && !(Array.isArray(slot.editions) && slot.editions.length && slot.editions.every((e) => EDITIONS.includes(e)) && new Set(slot.editions).size === slot.editions.length)) bad.push(`${at}: editions must be a non-empty subset of ${EDITIONS.join(', ')}`);
142
+ if (slot.litePresence !== undefined && !(PRESENCE.includes(slot.litePresence) || (isPlainObject(slot.litePresence) && Object.keys(slot.litePresence).length && Object.entries(slot.litePresence).every(([side, value]) => ['be', 'fe'].includes(side) && PRESENCE.includes(value))))) bad.push(`${at}: litePresence must be a presence value or map sides to presence values`);
143
+ if (slot.provider !== undefined) {
144
+ if (!CONNECTION_PROVIDERS.includes(slot.provider)) bad.push(`${at}: provider must be one of ${CONNECTION_PROVIDERS.join(' | ')}`);
145
+ else if (slot.presence !== 'opt-in' || slot.appKind !== undefined) bad.push(`${at}: provider belongs to an opt-in slot that is not an app kind (a connection with that provider enables it)`);
146
+ }
147
+ if (slot.lite !== undefined) {
148
+ const ok = isPlainObject(slot.lite) && Object.keys(slot.lite).length && Object.keys(slot.lite).every((key) => LITE_OVERLAY_KEYS.includes(key))
149
+ && (slot.lite.path === undefined || (typeof slot.lite.path === 'string' && slot.lite.path))
150
+ && ['requires', 'allows', 'forbids'].every((key) => slot.lite[key] === undefined || strList(slot.lite[key]))
151
+ && (slot.lite.minInstances === undefined || (Number.isInteger(slot.lite.minInstances) && slot.lite.minInstances >= 1))
152
+ && (slot.lite.requiredInstances === undefined || (isPlainObject(slot.lite.requiredInstances) && Object.values(slot.lite.requiredInstances).every((v) => strList(v) && v.length)));
153
+ if (!ok) bad.push(`${at}: lite may hold only ${LITE_OVERLAY_KEYS.join(', ')}, each shaped as in the slot body`);
154
+ }
155
+ }
156
+ if (slot.entries !== undefined) {
157
+ const listed = strList(slot.entries) && slot.entries.length > 0 && new Set(slot.entries).size === slot.entries.length && slot.entries.every(relPath);
158
+ if (!listed) bad.push(`${at}: entries must be a non-empty list of unique relative file paths`);
159
+ else if (typeof slot.path !== 'string' || !slot.path.endsWith('/') || slot.owner === true) bad.push(`${at}: entries belong to a directory slot that is not an owner (they name extra public entries of the owner that holds it)`);
160
+ else if (Array.isArray(slot.allows) && slot.entries.some((entry) => !slot.allows.includes(entry))) bad.push(`${at}: every entry must be one of the names the slot allows`);
161
+ }
162
+ if (slot.anonymousActions !== undefined && !(strList(slot.anonymousActions) && slot.anonymousActions.length > 0 && new Set(slot.anonymousActions).size === slot.anonymousActions.length && slot.anonymousActions.every(relPath) && typeof slot.path === 'string' && slot.path.endsWith('/'))) bad.push(`${at}: anonymousActions must be a non-empty list of unique relative file paths of a directory slot`);
163
+ if (slot.outcomeHome !== undefined && !(slot.outcomeHome === true && typeof slot.path === 'string' && slot.path && !slot.path.endsWith('/'))) bad.push(`${at}: outcomeHome is true and belongs to a file slot (the one file that declares the repository's Outcome union)`);
65
164
  if (slot.rules !== undefined && !(Array.isArray(slot.rules) && slot.rules.every((r) => /^[A-Z][A-Z0-9_]*\*?$/.test(String(r))) && new Set(slot.rules).size === slot.rules.length)) bad.push(`${at}: rules must be unique rule ids`);
165
+ if (slot.perConnection !== undefined && !(slot.id === 'be.persistence' && strList(slot.perConnection) && slot.perConnection.length && new Set(slot.perConnection).size === slot.perConnection.length && slot.perConnection.every((name) => NAME.test(name)))) bad.push(`${at}: perConnection is a unique list of capability names, only on be.persistence (the platform capabilities whose tables exist on every connection that uses them)`);
66
166
  if (slot.since !== undefined && !SEMVER.test(String(slot.since))) bad.push(`${at}: since must be a version`);
67
167
  if (slot.retiredIn !== undefined && !(Number.isInteger(slot.retiredIn) && slot.retiredIn >= 2)) bad.push(`${at}: retiredIn must be a major`);
68
168
  if (slot.retiredIn !== undefined && typeof slot.successor !== 'string') bad.push(`${at}: a retired slot names its successor`);
@@ -74,16 +174,12 @@ export function slotProblems(slot, index, kind, { appScope = 'app', scopes = []
74
174
  /** The owners of an external call in a runtime manifest: an api system folder (`api/<system>`, `api/*` any system) or the DB tier. */
75
175
  const INFRA_OWNER = /^(?:api\/(?:\*|[a-z][a-z0-9-]*)|engine\/db)$/;
76
176
  const RUNTIME_PARAM_KEYS = ['fileLines', 'sourceRoots', 'infraOwners', 'baseWriteMembers', 'baseEnvSeams', 'apiContracts', 'sourceName', 'oneOffNames', 'sharedBasenames', 'generated', 'pinned', 'selfChecks'];
77
- const PENDING_KEYS = ['path', 'rule', 'lane', 'since', 'reason'];
78
- /** The chunk of the runtime migration that deletes a pending entry (C1..C8, a split chunk C2a/C2b). */
79
- const PENDING_LANE = /^C[1-8][ab]?$/;
80
- const DATE = /^\d{4}-\d{2}-\d{2}$/;
81
177
  const relPath = (v) => typeof v === 'string' && v.length > 0 && !v.startsWith('/') && !v.includes('..') && !v.includes('\\');
82
178
 
83
179
  /** Shape problems of a parsed manifest of kind runtime (knowledge/hfs/runtime-slots.yaml), in the words of modules/schemas/hfs-slots.schema.yaml. */
84
180
  export function runtimeShapeProblems(m) {
85
181
  const bad = [];
86
- const allowed = new Set(['schema', 'kind', 'version', 'versioning', 'presenceValues', 'trackedValues', 'testValues', 'profiles', 'tiers', 'ruleParams', 'crossOwner', 'crossSystem', 'slots', 'pending', 'consumers']);
182
+ const allowed = new Set(['schema', 'kind', 'version', 'versioning', 'presenceValues', 'trackedValues', 'testValues', 'profiles', 'tiers', 'ruleParams', 'crossOwner', 'crossSystem', 'slots', 'consumers']);
87
183
  for (const key of Object.keys(m)) if (!allowed.has(key)) bad.push(`unknown top-level key ${key}`);
88
184
  if (!/^starci\/runtime-slots@\d+$/.test(String(m.schema))) bad.push('schema must be starci/runtime-slots@<major>');
89
185
  if (!SEMVER.test(String(m.version))) bad.push('version must be MAJOR.MINOR.PATCH');
@@ -100,19 +196,6 @@ export function runtimeShapeProblems(m) {
100
196
  else bad.push(...runtimeParamProblems(rp.runtime));
101
197
  if (!Array.isArray(m.slots) || !m.slots.length) bad.push('slots must be a non-empty list');
102
198
  else m.slots.forEach((slot, index) => bad.push(...slotProblems(slot, index, RUNTIME_KIND)));
103
- if (m.pending !== undefined) {
104
- if (!Array.isArray(m.pending)) bad.push('pending must be a list');
105
- else m.pending.forEach((entry, index) => {
106
- const at = `pending[${index}]`;
107
- if (!isPlainObject(entry)) { bad.push(`${at} is not a map`); return; }
108
- for (const key of Object.keys(entry)) if (!PENDING_KEYS.includes(key)) bad.push(`${at}: unknown field ${key}`);
109
- if (!relPath(entry.path)) bad.push(`${at}: path must be a repository-relative glob`);
110
- if (!/^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$/.test(String(entry.rule))) bad.push(`${at}: rule must be a finding code`);
111
- if (!PENDING_LANE.test(String(entry.lane))) bad.push(`${at}: lane must be the chunk that removes it (C1..C8, C2a, C2b)`);
112
- if (!DATE.test(String(entry.since))) bad.push(`${at}: since must be a date YYYY-MM-DD`);
113
- if (typeof entry.reason !== 'string' || !entry.reason.trim()) bad.push(`${at}: reason is required`);
114
- });
115
- }
116
199
  if (m.consumers !== undefined && !strList(m.consumers)) bad.push('consumers must be a list of paths');
117
200
  return bad;
118
201
  }
@@ -151,19 +234,13 @@ export function tierMapProblems(profile, tiers) {
151
234
  return bad;
152
235
  }
153
236
 
154
- /** The semantic rules of a runtime manifest beyond the slot rules both kinds share: tier names, the schema major, unique pending entries. */
237
+ /** The semantic rules of a runtime manifest beyond the slot rules both kinds share: tier names and the schema major. */
155
238
  export function runtimeSemanticProblems(m) {
156
239
  const bad = [];
157
240
  const tiers = m.tiers.runtime;
158
241
  for (const [tier, def] of Object.entries(tiers)) {
159
242
  for (const target of def.mayImport) if (!(target in tiers)) bad.push(`tiers.runtime.${tier}.mayImport names ${target}, which is not a runtime tier`);
160
243
  }
161
- const seen = new Set();
162
- for (const entry of m.pending ?? []) {
163
- const key = `${entry.path}\0${entry.rule}`;
164
- if (seen.has(key)) bad.push(`pending names ${entry.path} for ${entry.rule} twice`);
165
- seen.add(key);
166
- }
167
244
  const major = Number(m.version.split('.')[0]);
168
245
  if (String(m.schema) !== `starci/runtime-slots@${major}`) bad.push(`schema ${m.schema} does not carry the major of version ${m.version}`);
169
246
  return bad;
@@ -0,0 +1,18 @@
1
+ // param-names.mjs - the one shape of `ruleParams.be.paramNames` of knowledge/hfs/slots.yaml (R85 injected-param-name): a non-empty list of unique
2
+ // entries `{type | typeSuffix, names, nameSuffix?}`. The loader of scripts/hfs/slots.mjs calls it; the schema (modules/schemas/hfs-slots.schema.yaml)
3
+ // states the same shape and tests/hfs/hfs-slots.spec.mjs proves the two agree.
4
+ import { isPlainObject } from '../../engine/plain-object.mjs';
5
+
6
+ const UPPER = /^[A-Z][A-Za-z0-9]*$/u;
7
+ const LOWER = /^[a-z][A-Za-z0-9]*$/u;
8
+
9
+ const entryOk = (e) => isPlainObject(e) && ((e.type === undefined) !== (e.typeSuffix === undefined)) && UPPER.test(String(e.type ?? e.typeSuffix))
10
+ && Array.isArray(e.names) && e.names.length > 0 && new Set(e.names).size === e.names.length && e.names.every((n) => LOWER.test(String(n)))
11
+ && (e.nameSuffix === undefined || UPPER.test(String(e.nameSuffix))) && Object.keys(e).every((k) => ['type', 'typeSuffix', 'names', 'nameSuffix'].includes(k));
12
+
13
+ /** True when `list` is a well-formed paramNames table. */
14
+ export function paramNamesOk(list) {
15
+ if (!Array.isArray(list) || list.length === 0 || !list.every(entryOk)) return false;
16
+ const keys = list.map((e) => (e.type !== undefined ? `type:${e.type}` : `typeSuffix:${e.typeSuffix}`));
17
+ return new Set(keys).size === keys.length;
18
+ }
@@ -1,4 +1,4 @@
1
- // hfs-path-findings.mjs - the per-path judgements of the slot manifest: what a tracked path is. One function, two surfaces: `hfs check`
1
+ // hfs-path-findings.mjs - the per-path judgements of the slot manifest: what a tracked path is. One function, two surfaces: `starci app check`
2
2
  // (checkRepo) runs it over the tracked tree and keeps the findings that have no TypeScript file to sit on; the lint canon's project graph
3
3
  // (scripts/hfs/project-graph.mjs) runs it over the same tree and serves the findings on a TypeScript file as ESLint reports.
4
4
  // HFS_SLOT_UNDECLARED / HFS_SLOT_AMBIGUOUS / HFS_SLOT_NOT_ENABLED / HFS_FORBIDDEN_PRESENT / HFS_TOOL_CONFIG_LOCAL / HFS_TRACKED_MUST_BE_IGNORED (R01, R16)