@ybotok/loam 0.2.0-alpha.4 → 0.2.0-alpha.6

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 (270) hide show
  1. package/CHANGELOG.md +947 -0
  2. package/MIGRATING-from-OpenSpec.md +7 -1
  3. package/QUICKSTART.md +8 -3
  4. package/README.md +20 -13
  5. package/ROADMAP.md +329 -22
  6. package/SCHEMA.md +472 -24
  7. package/WORKFLOW.md +23 -10
  8. package/dist/commands/adopt/render.js +47 -8
  9. package/dist/commands/adopt/render.js.map +1 -1
  10. package/dist/commands/archive/plan/landscape.js +45 -1
  11. package/dist/commands/archive/plan/landscape.js.map +1 -1
  12. package/dist/commands/archive/plan/model/extending.js +85 -0
  13. package/dist/commands/archive/plan/model/extending.js.map +1 -0
  14. package/dist/commands/archive/run.js +5 -2
  15. package/dist/commands/archive/run.js.map +1 -1
  16. package/dist/commands/context/print.js +11 -1
  17. package/dist/commands/context/print.js.map +1 -1
  18. package/dist/commands/doctor.js +46 -0
  19. package/dist/commands/doctor.js.map +1 -1
  20. package/dist/commands/explore.js +12 -2
  21. package/dist/commands/explore.js.map +1 -1
  22. package/dist/commands/list/views.js +5 -1
  23. package/dist/commands/list/views.js.map +1 -1
  24. package/dist/commands/seed/plan.js +97 -3
  25. package/dist/commands/seed/plan.js.map +1 -1
  26. package/dist/commands/seed/seed.js +7 -2
  27. package/dist/commands/seed/seed.js.map +1 -1
  28. package/dist/commands/show/feature.js +2 -1
  29. package/dist/commands/show/feature.js.map +1 -1
  30. package/dist/commands/show/marks.js +3 -5
  31. package/dist/commands/show/marks.js.map +1 -1
  32. package/dist/commands/show/service.js +39 -18
  33. package/dist/commands/show/service.js.map +1 -1
  34. package/dist/commands/subsystem/sync.js +184 -39
  35. package/dist/commands/subsystem/sync.js.map +1 -1
  36. package/dist/commands/subsystem/txn/exclude.js +132 -0
  37. package/dist/commands/subsystem/txn/exclude.js.map +1 -0
  38. package/dist/commands/subsystem/txn/report.js +124 -0
  39. package/dist/commands/subsystem/txn/report.js.map +1 -0
  40. package/dist/commands/subsystem/txn/txn.js +29 -3
  41. package/dist/commands/subsystem/txn/txn.js.map +1 -1
  42. package/dist/commands/subsystem/txn/views.js +113 -16
  43. package/dist/commands/subsystem/txn/views.js.map +1 -1
  44. package/dist/commands/validate/arch-coverage.js +16 -9
  45. package/dist/commands/validate/arch-coverage.js.map +1 -1
  46. package/dist/commands/validate/checks/fleet-shape.js +30 -77
  47. package/dist/commands/validate/checks/fleet-shape.js.map +1 -1
  48. package/dist/commands/validate/checks/vocabulary.js +4 -19
  49. package/dist/commands/validate/checks/vocabulary.js.map +1 -1
  50. package/dist/commands/validate/feature.js +1 -1
  51. package/dist/commands/validate/feature.js.map +1 -1
  52. package/dist/commands/validate/fleet/census.js +11 -10
  53. package/dist/commands/validate/fleet/census.js.map +1 -1
  54. package/dist/commands/validate/fleet/landscape.js +128 -114
  55. package/dist/commands/validate/fleet/landscape.js.map +1 -1
  56. package/dist/commands/validate/fleet/load.js +66 -0
  57. package/dist/commands/validate/fleet/load.js.map +1 -1
  58. package/dist/commands/validate/fleet/map/attest.js +103 -0
  59. package/dist/commands/validate/fleet/map/attest.js.map +1 -0
  60. package/dist/commands/validate/fleet/map/bindings.js +96 -0
  61. package/dist/commands/validate/fleet/map/bindings.js.map +1 -0
  62. package/dist/commands/validate/fleet/map/consumers.js +298 -0
  63. package/dist/commands/validate/fleet/map/consumers.js.map +1 -0
  64. package/dist/commands/validate/fleet/map/isolation.js +116 -0
  65. package/dist/commands/validate/fleet/map/isolation.js.map +1 -0
  66. package/dist/commands/validate/fleet/map/usecases.js +56 -0
  67. package/dist/commands/validate/fleet/map/usecases.js.map +1 -0
  68. package/dist/commands/validate/fleet/usecases/steps.js +49 -17
  69. package/dist/commands/validate/fleet/usecases/steps.js.map +1 -1
  70. package/dist/commands/validate/fleet/views/fleet-project.js +217 -0
  71. package/dist/commands/validate/fleet/views/fleet-project.js.map +1 -0
  72. package/dist/commands/validate/fleet/views/ids.js +13 -9
  73. package/dist/commands/validate/fleet/views/ids.js.map +1 -1
  74. package/dist/commands/validate/fleet/views/projects.js +278 -0
  75. package/dist/commands/validate/fleet/views/projects.js.map +1 -0
  76. package/dist/commands/validate/fleet/views/root-documents.js +97 -0
  77. package/dist/commands/validate/fleet/views/root-documents.js.map +1 -0
  78. package/dist/commands/validate/fleet/views/stale.js +2 -2
  79. package/dist/commands/validate/fleet/views/stale.js.map +1 -1
  80. package/dist/commands/validate/service/model/diverged.js +226 -0
  81. package/dist/commands/validate/service/model/diverged.js.map +1 -0
  82. package/dist/commands/validate/service/model/grade.js +163 -0
  83. package/dist/commands/validate/service/model/grade.js.map +1 -0
  84. package/dist/commands/validate/service/service.js +110 -34
  85. package/dist/commands/validate/service/service.js.map +1 -1
  86. package/dist/commands/validate/service/specs.js +39 -5
  87. package/dist/commands/validate/service/specs.js.map +1 -1
  88. package/dist/commands/validate/service/spine.js +41 -3
  89. package/dist/commands/validate/service/spine.js.map +1 -1
  90. package/dist/commands/validate/service/usecases/tags.js +113 -0
  91. package/dist/commands/validate/service/usecases/tags.js.map +1 -0
  92. package/dist/commands/validate/service/usecases/usecases.js +209 -0
  93. package/dist/commands/validate/service/usecases/usecases.js.map +1 -0
  94. package/dist/commands/validate/validate.js +10 -24
  95. package/dist/commands/validate/validate.js.map +1 -1
  96. package/dist/core/agent/agents-md/artifacts.js +1 -0
  97. package/dist/core/agent/agents-md/artifacts.js.map +1 -1
  98. package/dist/core/agent/agents-md/command-map.js +18 -2
  99. package/dist/core/agent/agents-md/command-map.js.map +1 -1
  100. package/dist/core/agent/agents-md/cycle.js +24 -9
  101. package/dist/core/agent/agents-md/cycle.js.map +1 -1
  102. package/dist/core/agent/agents-md/map/lenses/context.js +4 -3
  103. package/dist/core/agent/agents-md/map/lenses/context.js.map +1 -1
  104. package/dist/core/agent/agents-md/map/subsystem.js +51 -2
  105. package/dist/core/agent/agents-md/map/subsystem.js.map +1 -1
  106. package/dist/core/agent/agents-md/map/usecases.js +45 -3
  107. package/dist/core/agent/agents-md/map/usecases.js.map +1 -1
  108. package/dist/core/agent/agents-md.js +14 -4
  109. package/dist/core/agent/agents-md.js.map +1 -1
  110. package/dist/core/agent/support/report.js +39 -5
  111. package/dist/core/agent/support/report.js.map +1 -1
  112. package/dist/core/agent/workflows/adopt.js +125 -6
  113. package/dist/core/agent/workflows/adopt.js.map +1 -1
  114. package/dist/core/agent/workflows/check.js +35 -19
  115. package/dist/core/agent/workflows/check.js.map +1 -1
  116. package/dist/core/agent/workflows/closing.js +3 -1
  117. package/dist/core/agent/workflows/closing.js.map +1 -1
  118. package/dist/core/brief/brief.js +63 -11
  119. package/dist/core/brief/brief.js.map +1 -1
  120. package/dist/core/brief/checks.js +138 -3
  121. package/dist/core/brief/checks.js.map +1 -1
  122. package/dist/core/brief/landscape.js +212 -129
  123. package/dist/core/brief/landscape.js.map +1 -1
  124. package/dist/core/brief/map/extend.js +81 -0
  125. package/dist/core/brief/map/extend.js.map +1 -0
  126. package/dist/core/brief/map/owed.js +284 -0
  127. package/dist/core/brief/map/owed.js.map +1 -0
  128. package/dist/core/brief/targets.js +30 -26
  129. package/dist/core/brief/targets.js.map +1 -1
  130. package/dist/core/brief/unchecked.js +12 -2
  131. package/dist/core/brief/unchecked.js.map +1 -1
  132. package/dist/core/c4/likec4.js +23 -1
  133. package/dist/core/c4/likec4.js.map +1 -1
  134. package/dist/core/c4/parsed/deployment.js +5 -3
  135. package/dist/core/c4/parsed/deployment.js.map +1 -1
  136. package/dist/core/c4/parsed/view-ids.js +39 -1
  137. package/dist/core/c4/parsed/view-ids.js.map +1 -1
  138. package/dist/core/c4/prefetch/fleet.js +142 -0
  139. package/dist/core/c4/prefetch/fleet.js.map +1 -0
  140. package/dist/core/c4/project/architecture.js +52 -4
  141. package/dist/core/c4/project/architecture.js.map +1 -1
  142. package/dist/core/c4/project/batch.js +140 -0
  143. package/dist/core/c4/project/batch.js.map +1 -0
  144. package/dist/core/c4/project/documents.js +9 -4
  145. package/dist/core/c4/project/documents.js.map +1 -1
  146. package/dist/core/c4/project/load.js +77 -38
  147. package/dist/core/c4/project/load.js.map +1 -1
  148. package/dist/core/c4/project/staged.js +46 -12
  149. package/dist/core/c4/project/staged.js.map +1 -1
  150. package/dist/core/c4/resolve/attested.js +0 -0
  151. package/dist/core/c4/resolve/attested.js.map +1 -0
  152. package/dist/core/c4/resolve/service.js +8 -17
  153. package/dist/core/c4/resolve/service.js.map +1 -1
  154. package/dist/core/c4/resolve/steps.js +18 -0
  155. package/dist/core/c4/resolve/steps.js.map +1 -1
  156. package/dist/core/c4/root-project/exclude.js +352 -0
  157. package/dist/core/c4/root-project/exclude.js.map +1 -0
  158. package/dist/core/c4/service-model/documents.js +47 -0
  159. package/dist/core/c4/service-model/documents.js.map +1 -0
  160. package/dist/core/c4/service-model/fleet/extending.js +82 -0
  161. package/dist/core/c4/service-model/fleet/extending.js.map +1 -0
  162. package/dist/core/c4/service-model/load.js +165 -0
  163. package/dist/core/c4/service-model/load.js.map +1 -0
  164. package/dist/core/c4/service-model/renderer.js +128 -0
  165. package/dist/core/c4/service-model/renderer.js.map +1 -0
  166. package/dist/core/c4/service-model/shape.js +126 -0
  167. package/dist/core/c4/service-model/shape.js.map +1 -0
  168. package/dist/core/c4/service-model/slice.js +188 -0
  169. package/dist/core/c4/service-model/slice.js.map +1 -0
  170. package/dist/core/c4/source-scan.js +26 -0
  171. package/dist/core/c4/source-scan.js.map +1 -1
  172. package/dist/core/c4/splice/authored-source.js +60 -13
  173. package/dist/core/c4/splice/authored-source.js.map +1 -1
  174. package/dist/core/c4/splice/contract.js.map +1 -1
  175. package/dist/core/c4/splice/identity/declared.js +87 -0
  176. package/dist/core/c4/splice/identity/declared.js.map +1 -0
  177. package/dist/core/c4/splice/identity/edges.js +17 -0
  178. package/dist/core/c4/splice/identity/edges.js.map +1 -1
  179. package/dist/core/c4/splice/identity/existing.js +80 -0
  180. package/dist/core/c4/splice/identity/existing.js.map +1 -0
  181. package/dist/core/c4/splice/identity/interior.js +80 -0
  182. package/dist/core/c4/splice/identity/interior.js.map +1 -0
  183. package/dist/core/c4/splice/identity/owner.js +50 -0
  184. package/dist/core/c4/splice/identity/owner.js.map +1 -0
  185. package/dist/core/c4/splice/landscape-merge.js +154 -100
  186. package/dist/core/c4/splice/landscape-merge.js.map +1 -1
  187. package/dist/core/c4/splice/model/merge.js +140 -0
  188. package/dist/core/c4/splice/model/merge.js.map +1 -0
  189. package/dist/core/c4/splice/placement.js +14 -4
  190. package/dist/core/c4/splice/placement.js.map +1 -1
  191. package/dist/core/c4/workspace.js +2 -1
  192. package/dist/core/c4/workspace.js.map +1 -1
  193. package/dist/core/coherence/coherence.js +7 -0
  194. package/dist/core/coherence/coherence.js.map +1 -1
  195. package/dist/core/delta/delta.js +9 -0
  196. package/dist/core/delta/delta.js.map +1 -1
  197. package/dist/core/deployment/delta.js +4 -0
  198. package/dist/core/deployment/delta.js.map +1 -1
  199. package/dist/core/diff/base-state.js +21 -5
  200. package/dist/core/diff/base-state.js.map +1 -1
  201. package/dist/core/diff/victims.js +10 -1
  202. package/dist/core/diff/victims.js.map +1 -1
  203. package/dist/core/docs.js +31 -22
  204. package/dist/core/docs.js.map +1 -1
  205. package/dist/core/doctor/config.js +7 -3
  206. package/dist/core/doctor/config.js.map +1 -1
  207. package/dist/core/doctor/doctor.js +48 -9
  208. package/dist/core/doctor/doctor.js.map +1 -1
  209. package/dist/core/doctor/report.js.map +1 -1
  210. package/dist/core/doctor/reports/scan.js +242 -0
  211. package/dist/core/doctor/reports/scan.js.map +1 -0
  212. package/dist/core/explain/families.js +1 -1
  213. package/dist/core/explain/families.js.map +1 -1
  214. package/dist/core/explain/refusals.js +1 -1
  215. package/dist/core/explain/refusals.js.map +1 -1
  216. package/dist/core/explore/explore.js +44 -9
  217. package/dist/core/explore/explore.js.map +1 -1
  218. package/dist/core/fleet-context.js +47 -0
  219. package/dist/core/fleet-context.js.map +1 -1
  220. package/dist/core/gate/partners.js +5 -9
  221. package/dist/core/gate/partners.js.map +1 -1
  222. package/dist/core/kernel/ids/fqn/ancestors.js +65 -0
  223. package/dist/core/kernel/ids/fqn/ancestors.js.map +1 -0
  224. package/dist/core/pack/living.js +47 -13
  225. package/dist/core/pack/living.js.map +1 -1
  226. package/dist/core/pack/pack.js +9 -6
  227. package/dist/core/pack/pack.js.map +1 -1
  228. package/dist/core/projection/arch-slice.js +2 -2
  229. package/dist/core/projection/arch-slice.js.map +1 -1
  230. package/dist/core/repo/paths.js +40 -0
  231. package/dist/core/repo/paths.js.map +1 -1
  232. package/dist/core/repo/tree/render/projects.js +182 -0
  233. package/dist/core/repo/tree/render/projects.js.map +1 -0
  234. package/dist/core/repo/tree/render/stale.js +2 -3
  235. package/dist/core/repo/tree/render/stale.js.map +1 -1
  236. package/dist/core/repo/tree/render/views.js +51 -3
  237. package/dist/core/repo/tree/render/views.js.map +1 -1
  238. package/dist/core/repo/tree/walk.js +45 -2
  239. package/dist/core/repo/tree/walk.js.map +1 -1
  240. package/dist/core/scaffold/landscape.js +219 -9
  241. package/dist/core/scaffold/landscape.js.map +1 -1
  242. package/dist/core/staging/writes.js.map +1 -1
  243. package/dist/core/usecases/delta/claims.js +1 -0
  244. package/dist/core/usecases/delta/claims.js.map +1 -1
  245. package/dist/core/usecases/delta/overlay.js +4 -0
  246. package/dist/core/usecases/delta/overlay.js.map +1 -1
  247. package/dist/core/usecases/fleet.js +18 -6
  248. package/dist/core/usecases/fleet.js.map +1 -1
  249. package/dist/core/usecases/operations.js +7 -0
  250. package/dist/core/usecases/operations.js.map +1 -1
  251. package/dist/core/usecases/service/exclude.js +119 -0
  252. package/dist/core/usecases/service/exclude.js.map +1 -0
  253. package/dist/core/usecases/service/flows.js +161 -0
  254. package/dist/core/usecases/service/flows.js.map +1 -0
  255. package/dist/core/vocabulary/maturity.js +10 -0
  256. package/dist/core/vocabulary/maturity.js.map +1 -1
  257. package/examples/README.md +23 -0
  258. package/examples/docs/architecture/landscape.likec4 +41 -0
  259. package/examples/docs/architecture/usecases/order-notification.likec4 +5 -2
  260. package/examples/docs/likec4.config.json +0 -1
  261. package/examples/docs/services/checkout-web/model.likec4 +39 -56
  262. package/examples/docs/services/order-service/arch.spec.md +13 -6
  263. package/examples/docs/services/order-service/model.likec4 +53 -67
  264. package/examples/docs/services/payment-service/arch.spec.md +7 -4
  265. package/examples/docs/services/payment-service/model.likec4 +32 -33
  266. package/examples/docs/services/platform/identity-service/arch.spec.md +7 -4
  267. package/examples/docs/services/platform/identity-service/model.likec4 +29 -33
  268. package/examples/docs/services/platform/notification-service/health.yaml +8 -3
  269. package/examples/docs/services/platform/notification-service/model.likec4 +39 -59
  270. package/package.json +1 -1
@@ -0,0 +1,217 @@
1
+ /**
2
+ * `c4.fleet-project-invalid` — the one thing no per-document grade can see:
3
+ * every document loam reads is clean, and the project the RENDERER builds out of
4
+ * them is not.
5
+ *
6
+ * loam grades a fleet document by document, and that is deliberate: a service's
7
+ * model is graded on its own merits, and one broken model must not blank the
8
+ * fleet. The renderer has no such rule. Point `npx likec4 start` at the docs
9
+ * root and it merges every `.likec4` the root project reads into ONE model — the
10
+ * map, every extending model, and every `.likec4` sitting beside one — so a
11
+ * declaration made in two of those documents is a duplicate there and nowhere
12
+ * else. Measured at the 1.59.2 pin: a tags-only `specification { tag req-X }` in
13
+ * an extending model is legal, and the SAME tag declared in a second extending
14
+ * model is a duplicate blamed on both files. Two services, two clean grades, and
15
+ * a renderer that draws nothing.
16
+ *
17
+ * So this is one extra load, and it is the renderer's reading rather than
18
+ * loam's. What it reports is the SET DIFFERENCE: an error already reported where
19
+ * loam grades that document — the map's own parse, a per-service project's
20
+ * `c4.invalid`, a service flow project's use-case failure — is not repeated
21
+ * here, because the fix is one file either way and N copies of one cascade is
22
+ * the report. What is left over is exactly the class above: errors that exist
23
+ * only because these documents were merged.
24
+ *
25
+ * WHICH DOCUMENTS ARE IN IT is `./root-documents.ts`'s question, and it is a
26
+ * walk of the docs root rather than a list of the shapes loam knows about: a
27
+ * `.likec4` in a SUBSYSTEM directory — the parent of service directories — was
28
+ * in none of the three roots this used to merge, and went unreported while the
29
+ * renderer refused the whole project over it (verification 2026-09-04, R2). That
30
+ * module also carries why the generated `architecture/subsystems.likec4`,
31
+ * every standalone service directory and `features/` stay out.
32
+ *
33
+ * `--all` ONLY, and only when at least one model extends the map, the map itself
34
+ * parses, and the root `exclude` does not hide it. A single-target run has not
35
+ * enumerated the fleet, so it cannot build the project at all; a fleet whose
36
+ * models all stand alone has no such project (every one of them is excluded from
37
+ * the root); and a map that does not parse would report its own cascade here
38
+ * under a second code while `landscape.invalid` already names the file.
39
+ *
40
+ * THE LAST OF THOSE GATES IS THE CASCADE RULE, the one `permissions.invalid` and
41
+ * `capability.invalid` already state: a grade that resolves against a
42
+ * document nobody loaded is not a diagnosis. `architectureProjectDocuments`
43
+ * keeps the map whatever the root `exclude` says — that floor is what stopped
44
+ * loam asserting a fleet's map declares nothing — but this load has no such
45
+ * floor ON PURPOSE, because its whole claim is to read what the renderer reads.
46
+ * So an entry covering `architecture/landscape.likec4` leaves every extending
47
+ * model in the project with its `extend <fqn>` resolving against nothing:
48
+ * measured on `examples/docs` with `architecture/*.likec4` in the list, one
49
+ * authored line came back as 161 warnings under this code. `landscape.excluded`
50
+ * (`./projects.ts`) is the one finding that names the cause, and it says the
51
+ * fleet project is not graded until the entry goes. The fact arrives as
52
+ * `mapExcluded` rather than being re-read here, so the two can never disagree
53
+ * about which state they are in.
54
+ *
55
+ * WHY A WARNING. Nothing loam concludes changes: every model still parses where
56
+ * loam reads it, every binding still resolves, the spine is unaffected. What is
57
+ * broken is the picture, which is what `service.likec4-config-missing` and its
58
+ * three siblings in `./projects.ts` also grade, at the same severity.
59
+ */
60
+ import { existsSync } from "node:fs";
61
+ import { relative, resolve, sep } from "node:path";
62
+ import { errorText } from "../../../../core/c4/likec4.js";
63
+ import { asLoadedDoc, loadProject } from "../../../../core/c4/project/load.js";
64
+ import { FleetContext } from "../../../../core/fleet-context.js";
65
+ import { inOrder } from "../../../../core/kernel/concurrency.js";
66
+ import { servicePathsAt } from "../../../../core/repo/paths.js";
67
+ import { readServiceFlows } from "../../../../core/usecases/service/flows.js";
68
+ import { rootProjectDocuments } from "./root-documents.js";
69
+ export async function fleetProjectFindings(check) {
70
+ // A map that did not parse is `landscape.invalid`'s, and this load would only
71
+ // repeat its cascade under a second code.
72
+ if (check.architecture.errors.length > 0)
73
+ return { kind: "skipped" };
74
+ // A map the root `exclude` hides is `landscape.excluded`'s, for the same
75
+ // reason one line up — see the banner's cascade-rule paragraph. The view-id
76
+ // census goes with it: `clean` is a claim about a project that parsed, and
77
+ // there is none.
78
+ if (check.mapExcluded)
79
+ return { kind: "skipped" };
80
+ const shapeOf = (entry) => {
81
+ const model = servicePathsAt(entry.dir).model;
82
+ return existsSync(model) ? (check.shapes.get(resolve(model)) ?? null) : null;
83
+ };
84
+ const extending = check.entries.filter((entry) => shapeOf(entry) === "extending");
85
+ if (extending.length === 0)
86
+ return { kind: "skipped" };
87
+ const paths = extending.map((entry) => servicePathsAt(entry.dir));
88
+ // The TREE, not three roots. `./root-documents.ts` carries what comes out of
89
+ // it and why; the standalone directories are handed in because their shape is
90
+ // this run's memo and re-reading every model here would be a second scanner.
91
+ const documents = await rootProjectDocuments(check.docsDir, check.entries.filter((entry) => shapeOf(entry) === "standalone").map((entry) => entry.dir));
92
+ const project = await loadProject(check.docsDir, documents);
93
+ if (project.clean) {
94
+ // The census `subsystem.view-id-collision` needs and could not have until
95
+ // now: an extending model's authored view ids live in the SAME flat
96
+ // namespace as the map's, because both documents are in this project. The
97
+ // claims arrive docs-relative, which is the spelling `viewIdFindings` takes.
98
+ return { kind: "clean", viewIds: project.viewIds };
99
+ }
100
+ const reported = await alreadyReported(check, paths);
101
+ const findings = [];
102
+ for (const err of asLoadedDoc(project).errors) {
103
+ if (reported.has(errorKey(err)))
104
+ continue;
105
+ const owner = extending.find((entry) => err.sourceFsPath !== undefined && err.sourceFsPath.startsWith(`${entry.dir}${sep}`));
106
+ const file = err.sourceFsPath === undefined ? null : relative(check.docsDir, err.sourceFsPath).split(/[\\/]/).join("/");
107
+ findings.push({
108
+ severity: "warn",
109
+ code: "c4.fleet-project-invalid",
110
+ ...(owner === undefined ? {} : { subject: owner.id }),
111
+ // The file the error is IN, never the map by default: `locations[0].path`
112
+ // was `architecture/landscape.likec4` on every one of these, so a reader
113
+ // acting on the payload opened a document that was not the one at fault
114
+ // (verification 2026-09-04, D10). Absent when LikeC4 declined to attribute
115
+ // the error to a document at all — a location loam cannot spell is left
116
+ // unspelled rather than guessed.
117
+ ...(file === null ? {} : { locations: [{ path: file, role: "primary" }] }),
118
+ details: [file === null ? errorText(err) : `${file}: ${errorText(err)}`],
119
+ message: `fleet project: ${file ?? "the merged project"}: ${errorText(err)} — each document reads clean where ` +
120
+ "loam grades it, but the renderer merges every `.likec4` the root project reads except the generated " +
121
+ "subsystems.likec4 — the map, every extending model and every `.likec4` beside one — into ONE project, " +
122
+ `and that project does not parse. ${remedy(err.message)}`,
123
+ });
124
+ }
125
+ return { kind: "invalid", findings };
126
+ }
127
+ /**
128
+ * The tail that names WHICH failure this is.
129
+ *
130
+ * It used to say "a tag or an element declared in two of those documents is
131
+ * declared twice there" for every error, including the ones that are not a
132
+ * double declaration at all (verification 2026-09-04, D10) — an unresolved
133
+ * reference sent its reader hunting for a second declaration that does not
134
+ * exist. LikeC4's own wording is the evidence, matched loosely on purpose: an
135
+ * unrecognised message falls to the third arm, which asserts nothing beyond
136
+ * where to look.
137
+ */
138
+ function remedy(message) {
139
+ if (/duplicat|already (declared|defined)|declared (more than once|twice)/i.test(message)) {
140
+ return ("A tag or an element declared in two of those documents is declared twice there; declare it once " +
141
+ "(the map, or the one service that owns it)");
142
+ }
143
+ if (/could not resolve|unresolved|unknown/i.test(message)) {
144
+ return ("A name resolves against ALL of those documents here, so a reference the renderer cannot place is one " +
145
+ "no document in the project declares; declare it where the reader can see it, or drop the reference");
146
+ }
147
+ return "Open the file and line named above — every reader who points a renderer at the docs root sees this";
148
+ }
149
+ /**
150
+ * Every parse error this run has ALREADY reported against one of these
151
+ * documents, keyed so the merged project's copy can be recognised.
152
+ *
153
+ * Two sources, and both are loads the run made anyway or would make: each
154
+ * extending model's own per-service project (`c4.invalid` on the service
155
+ * target) and, where nothing was wrong there, each service's FLOW project
156
+ * (`readServiceFlows` — the use-case grade names the file). The flow read goes
157
+ * through that function rather than a second `loadProject` here so the OPT-IN
158
+ * gate is the same one: a broken sibling that nothing tagged is loaded by
159
+ * neither, which is exactly why the merged project has to report it.
160
+ *
161
+ * Computed only when the merged project actually failed, which is why it is a
162
+ * function rather than an input: on a healthy fleet this whole file costs one
163
+ * load and nothing else.
164
+ *
165
+ * THE FLOW PROJECTS ARE PARSED AGAIN by `validateService` later in the same run,
166
+ * and that is accepted rather than unnoticed: it happens only on the path where
167
+ * the merged project already failed, so a healthy fleet pays nothing, and the
168
+ * `ServiceModel` half above IS the run's memo. If that path ever becomes hot,
169
+ * the follow-up is to memoise the flow scan on `FleetContext` beside the
170
+ * per-service projects — not to hand the scan in here, which would make this
171
+ * grade depend on an argument the caller has no reason to have loaded.
172
+ */
173
+ async function alreadyReported(check, paths) {
174
+ // Both sets reach the same documents through `architectureProjectDocuments`,
175
+ // which now drops what the root `exclude` covers exactly as the merged load's
176
+ // own walk does — so a document out of one is out of both, and the generated
177
+ // `subsystems.likec4` is out of all of them without being remembered twice.
178
+ //
179
+ // Pooled rather than awaited one at a time: each entry is an independent
180
+ // LikeC4 workspace over one service's own documents, which is exactly the
181
+ // work `inOrder` rations — and a serial loop here made the ONE path that
182
+ // already costs a fleet its whole set of flow projects pay for them in
183
+ // sequence.
184
+ const perService = await inOrder(paths, async (service) => {
185
+ const model = await check.fleet.serviceModel(check.docsDir, service);
186
+ const errors = [...model.doc.errors];
187
+ if (errors.length > 0 || model.mapUnreadable)
188
+ return errors;
189
+ // `model.project` is non-null here by construction — these are extending
190
+ // models whose own load came back clean, which is the arm that carries it —
191
+ // and the guard is the compiler's rather than an assertion: a null would
192
+ // mean grading a flow against a document that did not load.
193
+ if (model.project === null)
194
+ return [];
195
+ const flows = await readServiceFlows({
196
+ paths: service,
197
+ model: model.doc,
198
+ known: check.known,
199
+ extending: { docsDir: check.docsDir, project: model.project },
200
+ });
201
+ return flows.kind === "unreadable" ? flows.errors : [];
202
+ });
203
+ return new Set(perService.flat().map(errorKey));
204
+ }
205
+ /**
206
+ * One error's identity across two loads of overlapping document sets: the real
207
+ * file, the line, and the message.
208
+ *
209
+ * There is no id to join on — LikeC4 mints diagnostics per parse — and the
210
+ * message has to be part of the key: two DIFFERENT problems on one line of one
211
+ * file are two errors, and collapsing them would let a merged-project-only
212
+ * failure hide behind a per-service one that happens to share a line.
213
+ */
214
+ function errorKey(err) {
215
+ return JSON.stringify([err.sourceFsPath ?? "", err.line ?? -1, err.message]);
216
+ }
217
+ //# sourceMappingURL=fleet-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fleet-project.js","sourceRoot":"","sources":["../../../../../src/commands/validate/fleet/views/fleet-project.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAoC,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAG/E,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAGjE,OAAO,EAAE,cAAc,EAAqB,MAAM,gCAAgC,CAAC;AAEnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,OAAO,EAAE,oBAAoB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,EAAE,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["/**\n * `c4.fleet-project-invalid` — the one thing no per-document grade can see:\n * every document loam reads is clean, and the project the RENDERER builds out of\n * them is not.\n *\n * loam grades a fleet document by document, and that is deliberate: a service's\n * model is graded on its own merits, and one broken model must not blank the\n * fleet. The renderer has no such rule. Point `npx likec4 start` at the docs\n * root and it merges every `.likec4` the root project reads into ONE model — the\n * map, every extending model, and every `.likec4` sitting beside one — so a\n * declaration made in two of those documents is a duplicate there and nowhere\n * else. Measured at the 1.59.2 pin: a tags-only `specification { tag req-X }` in\n * an extending model is legal, and the SAME tag declared in a second extending\n * model is a duplicate blamed on both files. Two services, two clean grades, and\n * a renderer that draws nothing.\n *\n * So this is one extra load, and it is the renderer's reading rather than\n * loam's. What it reports is the SET DIFFERENCE: an error already reported where\n * loam grades that document — the map's own parse, a per-service project's\n * `c4.invalid`, a service flow project's use-case failure — is not repeated\n * here, because the fix is one file either way and N copies of one cascade is\n * the report. What is left over is exactly the class above: errors that exist\n * only because these documents were merged.\n *\n * WHICH DOCUMENTS ARE IN IT is `./root-documents.ts`'s question, and it is a\n * walk of the docs root rather than a list of the shapes loam knows about: a\n * `.likec4` in a SUBSYSTEM directory — the parent of service directories — was\n * in none of the three roots this used to merge, and went unreported while the\n * renderer refused the whole project over it (verification 2026-09-04, R2). That\n * module also carries why the generated `architecture/subsystems.likec4`,\n * every standalone service directory and `features/` stay out.\n *\n * `--all` ONLY, and only when at least one model extends the map, the map itself\n * parses, and the root `exclude` does not hide it. A single-target run has not\n * enumerated the fleet, so it cannot build the project at all; a fleet whose\n * models all stand alone has no such project (every one of them is excluded from\n * the root); and a map that does not parse would report its own cascade here\n * under a second code while `landscape.invalid` already names the file.\n *\n * THE LAST OF THOSE GATES IS THE CASCADE RULE, the one `permissions.invalid` and\n * `capability.invalid` already state: a grade that resolves against a\n * document nobody loaded is not a diagnosis. `architectureProjectDocuments`\n * keeps the map whatever the root `exclude` says — that floor is what stopped\n * loam asserting a fleet's map declares nothing — but this load has no such\n * floor ON PURPOSE, because its whole claim is to read what the renderer reads.\n * So an entry covering `architecture/landscape.likec4` leaves every extending\n * model in the project with its `extend <fqn>` resolving against nothing:\n * measured on `examples/docs` with `architecture/*.likec4` in the list, one\n * authored line came back as 161 warnings under this code. `landscape.excluded`\n * (`./projects.ts`) is the one finding that names the cause, and it says the\n * fleet project is not graded until the entry goes. The fact arrives as\n * `mapExcluded` rather than being re-read here, so the two can never disagree\n * about which state they are in.\n *\n * WHY A WARNING. Nothing loam concludes changes: every model still parses where\n * loam reads it, every binding still resolves, the spine is unaffected. What is\n * broken is the picture, which is what `service.likec4-config-missing` and its\n * three siblings in `./projects.ts` also grade, at the same severity.\n */\nimport { existsSync } from \"node:fs\";\nimport { relative, resolve, sep } from \"node:path\";\nimport { errorText, type LikeC4Error, type LoadedDoc } from \"../../../../core/c4/likec4.js\";\nimport { asLoadedDoc, loadProject } from \"../../../../core/c4/project/load.js\";\nimport type { ViewIdClaim } from \"../../../../core/c4/parsed/view-ids.js\";\nimport type { ModelShape } from \"../../../../core/c4/service-model/shape.js\";\nimport { FleetContext } from \"../../../../core/fleet-context.js\";\nimport { inOrder } from \"../../../../core/kernel/concurrency.js\";\nimport type { DocsDir } from \"../../../../core/kernel/ids/dirs.js\";\nimport type { ServiceEntry } from \"../../../../core/repo/entries.js\";\nimport { servicePathsAt, type ServicePaths } from \"../../../../core/repo/paths.js\";\nimport type { FleetTree } from \"../../../../core/repo/tree/walk.js\";\nimport { readServiceFlows } from \"../../../../core/usecases/service/flows.js\";\nimport type { Finding } from \"../../../../core/vocabulary/report.js\";\nimport { rootProjectDocuments } from \"./root-documents.js\";\n\nexport interface FleetProjectCheck {\n docsDir: DocsDir;\n /** The FULL enumeration — the project the renderer builds holds every model, not a narrowed run's subset. */\n entries: readonly ServiceEntry[];\n /** Each model's shape, keyed by resolved path (`FleetContext.modelShapes`). */\n shapes: ReadonlyMap<string, ModelShape>;\n /** The run's read index: the per-service projects it already parsed are half of the set difference. */\n fleet: FleetContext;\n /** The map parsed ALONE — the gate, and the other half of the difference. */\n architecture: LoadedDoc;\n /**\n * Whether the root `exclude` hides the map itself — `landscape.excluded`'s own\n * condition, computed once in `./projects.ts` and carried here rather than\n * re-derived. It is a GATE, for the reason the banner's cascade-rule paragraph\n * gives: this load has no floor under the map, so the entry that hides it\n * turns one authored line into an unresolved reference in every extending\n * model.\n */\n mapExcluded: boolean;\n /** The walked tree, for the view-id census this load makes answerable. */\n tree: FleetTree;\n /** Every service directory that exists — the flow scan's resolver evidence. */\n known: ReadonlySet<string>;\n}\n\n/**\n * What the merged load found, as three answers rather than one list — because\n * the caller has a second question to ask of it and the answers are mutually\n * exclusive.\n *\n * `skipped` is \"there is no such project, or loam declines to read one\": no model\n * extends the map, the map does not parse, the root `exclude` hides the map\n * (`landscape.excluded` names that entry and this grade stands down behind it),\n * or the run has no fleet index. `clean` carries the view-id\n * CENSUS, which is the only thing a caller may take from a project that parsed —\n * and the reason this is not just an empty finding list: an empty list and a\n * clean census are the same thing to `.length`, and one of them licenses\n * `subsystem.view-id-collision` to be graded over every extending model's\n * authored ids while the other does not.\n */\nexport type FleetProjectGrade =\n | { kind: \"skipped\" }\n | { kind: \"invalid\"; findings: Finding[] }\n | { kind: \"clean\"; viewIds: ViewIdClaim[] };\n\nexport async function fleetProjectFindings(check: FleetProjectCheck): Promise<FleetProjectGrade> {\n // A map that did not parse is `landscape.invalid`'s, and this load would only\n // repeat its cascade under a second code.\n if (check.architecture.errors.length > 0) return { kind: \"skipped\" };\n // A map the root `exclude` hides is `landscape.excluded`'s, for the same\n // reason one line up — see the banner's cascade-rule paragraph. The view-id\n // census goes with it: `clean` is a claim about a project that parsed, and\n // there is none.\n if (check.mapExcluded) return { kind: \"skipped\" };\n const shapeOf = (entry: ServiceEntry): ModelShape | null => {\n const model = servicePathsAt(entry.dir).model;\n return existsSync(model) ? (check.shapes.get(resolve(model)) ?? null) : null;\n };\n const extending = check.entries.filter((entry) => shapeOf(entry) === \"extending\");\n if (extending.length === 0) return { kind: \"skipped\" };\n\n const paths = extending.map((entry) => servicePathsAt(entry.dir));\n // The TREE, not three roots. `./root-documents.ts` carries what comes out of\n // it and why; the standalone directories are handed in because their shape is\n // this run's memo and re-reading every model here would be a second scanner.\n const documents = await rootProjectDocuments(\n check.docsDir,\n check.entries.filter((entry) => shapeOf(entry) === \"standalone\").map((entry) => entry.dir),\n );\n const project = await loadProject(check.docsDir, documents);\n\n if (project.clean) {\n // The census `subsystem.view-id-collision` needs and could not have until\n // now: an extending model's authored view ids live in the SAME flat\n // namespace as the map's, because both documents are in this project. The\n // claims arrive docs-relative, which is the spelling `viewIdFindings` takes.\n return { kind: \"clean\", viewIds: project.viewIds };\n }\n\n const reported = await alreadyReported(check, paths);\n const findings: Finding[] = [];\n for (const err of asLoadedDoc(project).errors) {\n if (reported.has(errorKey(err))) continue;\n const owner = extending.find(\n (entry) => err.sourceFsPath !== undefined && err.sourceFsPath.startsWith(`${entry.dir}${sep}`),\n );\n const file =\n err.sourceFsPath === undefined ? null : relative(check.docsDir, err.sourceFsPath).split(/[\\\\/]/).join(\"/\");\n findings.push({\n severity: \"warn\",\n code: \"c4.fleet-project-invalid\",\n ...(owner === undefined ? {} : { subject: owner.id }),\n // The file the error is IN, never the map by default: `locations[0].path`\n // was `architecture/landscape.likec4` on every one of these, so a reader\n // acting on the payload opened a document that was not the one at fault\n // (verification 2026-09-04, D10). Absent when LikeC4 declined to attribute\n // the error to a document at all — a location loam cannot spell is left\n // unspelled rather than guessed.\n ...(file === null ? {} : { locations: [{ path: file, role: \"primary\" as const }] }),\n details: [file === null ? errorText(err) : `${file}: ${errorText(err)}`],\n message:\n `fleet project: ${file ?? \"the merged project\"}: ${errorText(err)} — each document reads clean where ` +\n \"loam grades it, but the renderer merges every `.likec4` the root project reads except the generated \" +\n \"subsystems.likec4 — the map, every extending model and every `.likec4` beside one — into ONE project, \" +\n `and that project does not parse. ${remedy(err.message)}`,\n });\n }\n return { kind: \"invalid\", findings };\n}\n\n/**\n * The tail that names WHICH failure this is.\n *\n * It used to say \"a tag or an element declared in two of those documents is\n * declared twice there\" for every error, including the ones that are not a\n * double declaration at all (verification 2026-09-04, D10) — an unresolved\n * reference sent its reader hunting for a second declaration that does not\n * exist. LikeC4's own wording is the evidence, matched loosely on purpose: an\n * unrecognised message falls to the third arm, which asserts nothing beyond\n * where to look.\n */\nfunction remedy(message: string): string {\n if (/duplicat|already (declared|defined)|declared (more than once|twice)/i.test(message)) {\n return (\n \"A tag or an element declared in two of those documents is declared twice there; declare it once \" +\n \"(the map, or the one service that owns it)\"\n );\n }\n if (/could not resolve|unresolved|unknown/i.test(message)) {\n return (\n \"A name resolves against ALL of those documents here, so a reference the renderer cannot place is one \" +\n \"no document in the project declares; declare it where the reader can see it, or drop the reference\"\n );\n }\n return \"Open the file and line named above — every reader who points a renderer at the docs root sees this\";\n}\n\n/**\n * Every parse error this run has ALREADY reported against one of these\n * documents, keyed so the merged project's copy can be recognised.\n *\n * Two sources, and both are loads the run made anyway or would make: each\n * extending model's own per-service project (`c4.invalid` on the service\n * target) and, where nothing was wrong there, each service's FLOW project\n * (`readServiceFlows` — the use-case grade names the file). The flow read goes\n * through that function rather than a second `loadProject` here so the OPT-IN\n * gate is the same one: a broken sibling that nothing tagged is loaded by\n * neither, which is exactly why the merged project has to report it.\n *\n * Computed only when the merged project actually failed, which is why it is a\n * function rather than an input: on a healthy fleet this whole file costs one\n * load and nothing else.\n *\n * THE FLOW PROJECTS ARE PARSED AGAIN by `validateService` later in the same run,\n * and that is accepted rather than unnoticed: it happens only on the path where\n * the merged project already failed, so a healthy fleet pays nothing, and the\n * `ServiceModel` half above IS the run's memo. If that path ever becomes hot,\n * the follow-up is to memoise the flow scan on `FleetContext` beside the\n * per-service projects — not to hand the scan in here, which would make this\n * grade depend on an argument the caller has no reason to have loaded.\n */\nasync function alreadyReported(\n check: FleetProjectCheck,\n paths: readonly ServicePaths[],\n): Promise<ReadonlySet<string>> {\n // Both sets reach the same documents through `architectureProjectDocuments`,\n // which now drops what the root `exclude` covers exactly as the merged load's\n // own walk does — so a document out of one is out of both, and the generated\n // `subsystems.likec4` is out of all of them without being remembered twice.\n //\n // Pooled rather than awaited one at a time: each entry is an independent\n // LikeC4 workspace over one service's own documents, which is exactly the\n // work `inOrder` rations — and a serial loop here made the ONE path that\n // already costs a fleet its whole set of flow projects pay for them in\n // sequence.\n const perService = await inOrder(paths, async (service) => {\n const model = await check.fleet.serviceModel(check.docsDir, service);\n const errors = [...model.doc.errors];\n if (errors.length > 0 || model.mapUnreadable) return errors;\n // `model.project` is non-null here by construction — these are extending\n // models whose own load came back clean, which is the arm that carries it —\n // and the guard is the compiler's rather than an assertion: a null would\n // mean grading a flow against a document that did not load.\n if (model.project === null) return [];\n const flows = await readServiceFlows({\n paths: service,\n model: model.doc,\n known: check.known,\n extending: { docsDir: check.docsDir, project: model.project },\n });\n return flows.kind === \"unreadable\" ? flows.errors : [];\n });\n return new Set(perService.flat().map(errorKey));\n}\n\n/**\n * One error's identity across two loads of overlapping document sets: the real\n * file, the line, and the message.\n *\n * There is no id to join on — LikeC4 mints diagnostics per parse — and the\n * message has to be part of the key: two DIFFERENT problems on one line of one\n * file are two errors, and collapsing them would let a merged-project-only\n * failure hide behind a per-service one that happens to share a line.\n */\nfunction errorKey(err: LikeC4Error): string {\n return JSON.stringify([err.sourceFsPath ?? \"\", err.line ?? -1, err.message]);\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  import { SUBSYSTEM_VIEW_PREFIX, subsystemViewId } from "../../../../core/repo/tree/render/views.js";
2
2
  /**
3
- * `authored` is every view id the `architecture/` project claims, each with the
4
- * file that claims it — static views included, because a static view claims an
5
- * id exactly as firmly as a dynamic one. Absent (the document did not parse, or
6
- * an older loader did not read them) is treated as "nothing to compare", never
7
- * as "nothing collides".
3
+ * `authored` is every view id the project claims, each with the DOCS-RELATIVE
4
+ * path of the file that claims it — static views included, because a static view
5
+ * claims an id exactly as firmly as a dynamic one. Absent (the document did not
6
+ * parse, or an older loader did not read them) is treated as "nothing to
7
+ * compare", never as "nothing collides".
8
8
  */
9
9
  export function viewIdFindings(authored, tree) {
10
10
  if (authored === undefined || authored.length === 0)
@@ -32,11 +32,15 @@ export function viewIdFindings(authored, tree) {
32
32
  // the one the report's target fallback gets wrong: it files this under
33
33
  // the landscape, which is exactly the file a reader must NOT rename the
34
34
  // view in when the claim came from a document of their own.
35
- locations: [{ path: `architecture/${file}`, role: "primary" }],
36
- message: `subsystems: architecture/${file} declares \`view ${id}\`, which is the id loam generates ` +
35
+ locations: [{ path: file, role: "primary" }],
36
+ message: `subsystems: ${file} declares \`view ${id}\`, which is the id loam generates ` +
37
37
  `into architecture/subsystems.likec4 for services/${owner}/ — LikeC4 merges both files into one project, ` +
38
- `so it refuses the whole architecture/ project and renders nothing. ` +
39
- `Rename the view in architecture/${file}; ids beginning \`${SUBSYSTEM_VIEW_PREFIX}\` are loam's ` +
38
+ // The ROOT project, not `architecture/`: the claimant may be a model's
39
+ // own view now (an extending model is a document of the root project),
40
+ // and telling that author the `architecture/` project is refused sends
41
+ // them to look for the breakage in a directory they never touched.
42
+ `so it refuses the whole root project and renders nothing. ` +
43
+ `Rename the view in ${file}; ids beginning \`${SUBSYSTEM_VIEW_PREFIX}\` are loam's ` +
40
44
  "to mint, and architecture/subsystems.likec4 is generated (`loam subsystem sync`) and must never be hand-edited.",
41
45
  });
42
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ids.js","sourceRoot":"","sources":["../../../../../src/commands/validate/fleet/views/ids.ts"],"names":[],"mappings":"AAsCA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAIpG;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,QAAmC,EAAE,IAAe;IACjF,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,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,SAAkB,EAAE,CAAC;YACvE,OAAO,EACL,4BAA4B,IAAI,oBAAoB,EAAE,qCAAqC;gBAC3F,oDAAoD,KAAK,iDAAiD;gBAC1G,qEAAqE;gBACrE,mCAAmC,IAAI,qBAAqB,qBAAqB,gBAAgB;gBACjG,iHAAiH;SACpH,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * An authored view id that collides with one loam GENERATES into\n * `architecture/subsystems.likec4`.\n *\n * This closes a green-while-broken hole, and the shape of it is measured rather\n * than argued. The LikeC4 renderer merges every `.likec4` file in a project into\n * one model, and `likec4.config.json` scopes the root project to\n * `architecture/` — so `landscape.likec4` and the generated `subsystems.likec4`\n * share ONE flat view-id namespace. Author `view subsystem_commerce { }` in the\n * landscape while the tree has a `commerce` subsystem and the renderer refuses\n * the ENTIRE `architecture/` project with two `Duplicate view` diagnostics, one\n * per file — while `loam validate --all` printed `landscape: N service(s)\n * modelled — architecture/landscape.likec4 and services/ agree`. Reproduced at\n * the 1.59.2 pin.\n *\n * Nothing else in a loam repo can produce this. A duplicate INSIDE one document\n * is already 2 LikeC4 errors, so `landscape.invalid` has it (measured). A\n * service's `model.likec4` and a feature's `delta.likec4` are each their own\n * LikeC4 project — `likec4.config.json` excludes `services/**` and\n * `features/**` from the root — so their view ids cannot collide with the\n * landscape's, and a delta's views never travel through `archive` anyway. That\n * leaves exactly one pair, which is why this check compares exactly one pair\n * rather than taking a census across every document loam parses.\n *\n * ONLY the real collision is refused, never the merely reserved-looking name.\n * A landscape view called `subsystem_overview` with no `overview` subsystem\n * breaks nothing today, and refusing it would be loam inventing a rule about a\n * name that harms no one. The latent case is not lost: the moment somebody\n * creates that subsystem, the generator mints the id, and this same check fires\n * on the same run. The message names the reservation anyway, so an author fixing\n * one collision learns not to make the next.\n *\n * Graded on `validate --all` only, and the caller holds that gate together with\n * the landscape-parsed one: under a single-target run the fleet tree is not\n * walked and the generated ids are unknown, so the question is unanswerable and\n * the check stays silent rather than half-answering.\n */\nimport type { ViewIdClaim } from \"../../../../core/c4/parsed/view-ids.js\";\nimport { SUBSYSTEM_VIEW_PREFIX, subsystemViewId } from \"../../../../core/repo/tree/render/views.js\";\nimport type { FleetTree } from \"../../../../core/repo/tree/walk.js\";\nimport type { Finding } from \"../../../../core/vocabulary/report.js\";\n\n/**\n * `authored` is every view id the `architecture/` project claims, each with the\n * file that claims it — static views included, because a static view claims an\n * id exactly as firmly as a dynamic one. Absent (the document did not parse, or\n * an older loader did not read them) is treated as \"nothing to compare\", never\n * as \"nothing collides\".\n */\nexport function viewIdFindings(authored: ViewIdClaim[] | undefined, tree: FleetTree): Finding[] {\n if (authored === undefined || authored.length === 0) return [];\n const generated = new Map(tree.subsystems.map((sub) => [subsystemViewId(sub), sub.path.join(\"/\")]));\n const findings: Finding[] = [];\n // Sorted and de-duplicated by id so a project claiming the same id twice —\n // itself already a parse error, but reachable through a partial read — yields\n // one finding per id rather than one per occurrence. The first claimant's file\n // is the one named: with a duplicate the project does not parse at all, so\n // there is never a second one to choose between.\n const claimants = new Map<string, string>();\n for (const claim of authored) if (!claimants.has(claim.id)) claimants.set(claim.id, claim.sourcePath);\n for (const [id, file] of [...claimants].sort(([a], [b]) => (a < b ? -1 : 1))) {\n const owner = generated.get(id);\n if (owner === undefined) continue;\n findings.push({\n severity: \"error\",\n code: \"subsystem.view-id-collision\",\n subject: id,\n // The CLAIMANT file — the one the message tells the reader to edit, and\n // the one the report's target fallback gets wrong: it files this under\n // the landscape, which is exactly the file a reader must NOT rename the\n // view in when the claim came from a document of their own.\n locations: [{ path: `architecture/${file}`, role: \"primary\" as const }],\n message:\n `subsystems: architecture/${file} declares \\`view ${id}\\`, which is the id loam generates ` +\n `into architecture/subsystems.likec4 for services/${owner}/ — LikeC4 merges both files into one project, ` +\n `so it refuses the whole architecture/ project and renders nothing. ` +\n `Rename the view in architecture/${file}; ids beginning \\`${SUBSYSTEM_VIEW_PREFIX}\\` are loam's ` +\n \"to mint, and architecture/subsystems.likec4 is generated (`loam subsystem sync`) and must never be hand-edited.\",\n });\n }\n return findings;\n}\n"]}
1
+ {"version":3,"file":"ids.js","sourceRoot":"","sources":["../../../../../src/commands/validate/fleet/views/ids.ts"],"names":[],"mappings":"AAqDA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAIpG;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,QAAmC,EAAE,IAAe;IACjF,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC/D,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpG,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,2EAA2E;IAC3E,8EAA8E;IAC9E,+EAA+E;IAC/E,2EAA2E;IAC3E,iDAAiD;IACjD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC5C,KAAK,MAAM,KAAK,IAAI,QAAQ;QAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACtG,KAAK,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7E,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,QAAQ,CAAC,IAAI,CAAC;YACZ,QAAQ,EAAE,OAAO;YACjB,IAAI,EAAE,6BAA6B;YACnC,OAAO,EAAE,EAAE;YACX,wEAAwE;YACxE,uEAAuE;YACvE,wEAAwE;YACxE,4DAA4D;YAC5D,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAkB,EAAE,CAAC;YACrD,OAAO,EACL,eAAe,IAAI,oBAAoB,EAAE,qCAAqC;gBAC9E,oDAAoD,KAAK,iDAAiD;gBAC1G,uEAAuE;gBACvE,uEAAuE;gBACvE,uEAAuE;gBACvE,mEAAmE;gBACnE,4DAA4D;gBAC5D,sBAAsB,IAAI,qBAAqB,qBAAqB,gBAAgB;gBACpF,iHAAiH;SACpH,CAAC,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * An authored view id that collides with one loam GENERATES into\n * `architecture/subsystems.likec4`.\n *\n * This closes a green-while-broken hole, and the shape of it is measured rather\n * than argued. The LikeC4 renderer merges every `.likec4` file in a project into\n * one model, and `architecture/landscape.likec4` and the generated\n * `architecture/subsystems.likec4` are two documents of the ROOT project — so\n * they share ONE flat view-id namespace. (This file used to say the reason was\n * that `likec4.config.json` scopes the root project to `architecture/`; it does\n * not, and never had to for the collision to exist. The scaffold's `exclude`\n * names `features/**` and node_modules, and a fleet whose models extend the map\n * has `services/` in the root project too — see `./fleet-project.ts`.) Author\n * `view subsystem_commerce { }` in the landscape while the tree has a `commerce`\n * subsystem and the renderer refuses the ENTIRE root project with two\n * `Duplicate view` diagnostics, one per file — while `loam validate --all`\n * printed `landscape: N service(s) modelled — architecture/landscape.likec4 and\n * services/ agree`. Reproduced at the 1.59.2 pin.\n *\n * WHICH DOCUMENTS CLAIM IDS IN THAT NAMESPACE, corrected. A duplicate INSIDE one\n * document is already 2 LikeC4 errors, so `landscape.invalid` has it (measured).\n * A feature's `delta.likec4` is its own LikeC4 project — the root excludes\n * `features/**` — and a delta's views never travel through `archive` anyway. A\n * service's `model.likec4` used to be in the same position and no longer is:\n * this file's original premise, that `likec4.config.json` excludes `services/**`\n * so a model's view ids cannot collide with the landscape's, holds only for a\n * model that STANDS ALONE. A model that EXTENDS the map lives in the root\n * project beside it, so its authored view ids — and those of every `.likec4`\n * beside it — share exactly this namespace. That census is made by the merged\n * load in `./fleet-project.ts` and handed here; the landscape's own claims are\n * still graded from the `architecture/` project, which is the only census a run\n * with no extending model can make.\n *\n * The claims therefore arrive spelled DOCS-RELATIVE, and the caller does the\n * spelling: the `architecture/` project reports a view's `sourcePath` relative\n * to `architecture/`, the merged project reports it relative to the docs root,\n * and a prefix pasted on here would name `architecture/services/…` for every\n * model. The message and the location both print the path verbatim.\n *\n * ONLY the real collision is refused, never the merely reserved-looking name.\n * A landscape view called `subsystem_overview` with no `overview` subsystem\n * breaks nothing today, and refusing it would be loam inventing a rule about a\n * name that harms no one. The latent case is not lost: the moment somebody\n * creates that subsystem, the generator mints the id, and this same check fires\n * on the same run. The message names the reservation anyway, so an author fixing\n * one collision learns not to make the next.\n *\n * Graded on `validate --all` only, and the caller holds that gate together with\n * the landscape-parsed one: under a single-target run the fleet tree is not\n * walked and the generated ids are unknown, so the question is unanswerable and\n * the check stays silent rather than half-answering.\n */\nimport type { ViewIdClaim } from \"../../../../core/c4/parsed/view-ids.js\";\nimport { SUBSYSTEM_VIEW_PREFIX, subsystemViewId } from \"../../../../core/repo/tree/render/views.js\";\nimport type { FleetTree } from \"../../../../core/repo/tree/walk.js\";\nimport type { Finding } from \"../../../../core/vocabulary/report.js\";\n\n/**\n * `authored` is every view id the project claims, each with the DOCS-RELATIVE\n * path of the file that claims it — static views included, because a static view\n * claims an id exactly as firmly as a dynamic one. Absent (the document did not\n * parse, or an older loader did not read them) is treated as \"nothing to\n * compare\", never as \"nothing collides\".\n */\nexport function viewIdFindings(authored: ViewIdClaim[] | undefined, tree: FleetTree): Finding[] {\n if (authored === undefined || authored.length === 0) return [];\n const generated = new Map(tree.subsystems.map((sub) => [subsystemViewId(sub), sub.path.join(\"/\")]));\n const findings: Finding[] = [];\n // Sorted and de-duplicated by id so a project claiming the same id twice —\n // itself already a parse error, but reachable through a partial read — yields\n // one finding per id rather than one per occurrence. The first claimant's file\n // is the one named: with a duplicate the project does not parse at all, so\n // there is never a second one to choose between.\n const claimants = new Map<string, string>();\n for (const claim of authored) if (!claimants.has(claim.id)) claimants.set(claim.id, claim.sourcePath);\n for (const [id, file] of [...claimants].sort(([a], [b]) => (a < b ? -1 : 1))) {\n const owner = generated.get(id);\n if (owner === undefined) continue;\n findings.push({\n severity: \"error\",\n code: \"subsystem.view-id-collision\",\n subject: id,\n // The CLAIMANT file — the one the message tells the reader to edit, and\n // the one the report's target fallback gets wrong: it files this under\n // the landscape, which is exactly the file a reader must NOT rename the\n // view in when the claim came from a document of their own.\n locations: [{ path: file, role: \"primary\" as const }],\n message:\n `subsystems: ${file} declares \\`view ${id}\\`, which is the id loam generates ` +\n `into architecture/subsystems.likec4 for services/${owner}/ — LikeC4 merges both files into one project, ` +\n // The ROOT project, not `architecture/`: the claimant may be a model's\n // own view now (an extending model is a document of the root project),\n // and telling that author the `architecture/` project is refused sends\n // them to look for the breakage in a directory they never touched.\n `so it refuses the whole root project and renders nothing. ` +\n `Rename the view in ${file}; ids beginning \\`${SUBSYSTEM_VIEW_PREFIX}\\` are loam's ` +\n \"to mint, and architecture/subsystems.likec4 is generated (`loam subsystem sync`) and must never be hand-edited.\",\n });\n }\n return findings;\n}\n"]}
@@ -0,0 +1,278 @@
1
+ /**
2
+ * The four ways a service's `model.likec4` and the renderer's project files can
3
+ * disagree, graded as one warning per service on the fleet target — plus the
4
+ * one way the same root config can hide the fleet MAP, graded once for the
5
+ * fleet (`landscape.excluded`, at the foot of this module).
6
+ *
7
+ * They are one walk because they are one question — "can the renderer actually
8
+ * show what this model says?" — asked of the two shapes a model has. A model
9
+ * that STANDS ALONE (declares its own element kinds) is parsed alone: it needs a
10
+ * project file of its own, and the root project must exclude its directory. A
11
+ * model that EXTENDS the fleet map declares no kinds and lives IN the root
12
+ * project: it must NOT be excluded, and a project file beside it TAKES it out of
13
+ * there — measured at the 1.59.2 pin, the nested project claims the model, which
14
+ * then does not resolve (the map's kinds are not in there with it) and the fleet
15
+ * project loses the service's interior. Each shape therefore owes the opposite of
16
+ * the other, and each of the four codes below is one half of one of those pairs:
17
+ *
18
+ * - `service.likec4-config-missing` — standalone, no project file.
19
+ * - `service.likec4-config-stray` — extending, project file present.
20
+ * - `service.model-excluded` — extending, root `exclude` covers it. Two
21
+ * questions, not one: the DIRECTORY (`excludingEntry`, which `subsystem sync`
22
+ * can repair) and, where that says no, the model FILE (`excludingPath`, which
23
+ * it cannot — the message says so).
24
+ * - `service.model-unexcluded` — standalone, root `exclude` does not.
25
+ *
26
+ * `landscape.excluded` is the fifth, and it is the same question asked one
27
+ * level up: the root `exclude` covering `architecture/landscape.likec4` itself.
28
+ *
29
+ * WHY WARNINGS. Every fact loam grades about a model — its parse, its bindings,
30
+ * its edges into the spine — holds exactly as it did in all five states, so
31
+ * nothing here may gate. The fifth is only true because the architecture loader
32
+ * keeps the map whatever the root `exclude` says (`core/c4/project/architecture.ts`);
33
+ * before it did, an excluded map blanked every cross-service grade in the run. ROADMAP's clause that rendering "must stay outside
34
+ * validation so view computation cannot slow or change the gate" is about
35
+ * computing views; this check computes nothing: one `existsSync` per service and
36
+ * one read of the root config. And the sibling that grades the ROOT file's
37
+ * absence (`doctor.likec4-config-missing`, `core/doctor/doctor.ts`) calls a repo
38
+ * without it "only unrenderable" and warns; these are the same condition one
39
+ * directory down and earn the same severity.
40
+ *
41
+ * WHY `validate --all` AND NOT `doctor`. `doctor` is the step-0 preflight of the
42
+ * adopt protocol — wiring, the config, the fleet map's readability — and the
43
+ * protocol's step 5 is the `validate --all` run whose findings the agent
44
+ * branches on. The report that motivated the first of these codes had its own
45
+ * `doctor --json` answer `healthy: true` with 0 findings on a tree where every
46
+ * adopted model was unrenderable from the root: the model is written in step 3,
47
+ * so its renderability is a fact that first exists at step 5, and a preflight
48
+ * that ran before the model did could not have said otherwise. Never in
49
+ * `validate --service`, `status` or `doctor`: the writer is a fleet verb
50
+ * (`subsystem sync`) and the findings belong beside the files that verb owns.
51
+ *
52
+ * WHY PER SERVICE. `subject` is the service id so a `--json` worklist filters by
53
+ * team the way `landscape.service-unmodelled` already lets it — one fleet
54
+ * finding listing every gap would have to be re-parsed to find out whose it is.
55
+ * The `scope` location is the service's tree path, through `serviceTreePath` on
56
+ * the ENTRY the survey hands back — never a join by id: these grades are emitted
57
+ * before the map's early returns precisely so they hold on a broken tree, and a
58
+ * tree with two services sharing a leaf name under different subsystems
59
+ * (`subsystem.name-collision`) is exactly such a tree, still enumerated in full.
60
+ * Joined by id, both findings named the first directory while `subsystem sync`
61
+ * wrote both files at the right paths.
62
+ *
63
+ * WHY THE ROOT GATE, and it does double duty. Semantically: `subsystem sync`
64
+ * writes nothing — no per-service file, no rewritten `exclude` — until the root
65
+ * `likec4.config.json` exists (the docs root is then a LikeC4 workspace and a
66
+ * nested project is registered inside it — measured at the 1.59.2 pin), so a
67
+ * repo without the root file has `doctor` telling it to write that first and
68
+ * nothing to sync into; grading a gap the writer would not fill is a loop no
69
+ * command can clear. The same rule silences a directory whose name is not a
70
+ * legal service id: the survey skips it (`render/projects.ts` says why),
71
+ * `service.id-invalid` already names it, and a warning here would advertise a
72
+ * repair `sync` refuses to perform. Fixture-wise: `makeProject` writes NO root
73
+ * file, so every existing fixture stays silent under this gate, and the suites
74
+ * that pin a fleet's warning set exactly (`test/examples.test.ts`,
75
+ * `test/self-model.test.ts`) ship the files their shapes call for and keep their
76
+ * counts.
77
+ *
78
+ * The exclude half has a SECOND gate, inside `readRootExclude`: a root config
79
+ * loam cannot read an `exclude` list out of answers `null`, and both grades that
80
+ * read it stay silent. loam does not know what the renderer will do with a file
81
+ * it could not parse, and asserting an exclusion on evidence it does not have is
82
+ * worse than saying nothing.
83
+ */
84
+ import { existsSync } from "node:fs";
85
+ import { relative, resolve } from "node:path";
86
+ import { excludingEntry, excludingPath, readRootExclude } from "../../../../core/c4/root-project/exclude.js";
87
+ import { serviceTreePath } from "../../../../core/kernel/ids/dirs.js";
88
+ import { ARTIFACT_FILES, landscapePath, LIKEC4_PROJECT_FILENAME, rootProjectPath, serviceRenderPaths } from "../../../../core/repo/paths.js";
89
+ import { surveyProjects } from "../../../../core/repo/tree/render/projects.js";
90
+ /**
91
+ * `entries` is the fleet enumeration at whatever depth each service lives, and
92
+ * `shapes` is the shape of every model in it, keyed by resolved path
93
+ * (`FleetContext.modelShapes`). The shape map is built over the FULL enumeration
94
+ * rather than a `--base` narrowing: a model missing from it would read as
95
+ * standalone, which is the wrong half of every pair above.
96
+ *
97
+ * The predicate handed into the survey is the ONE spelling of "has a model,
98
+ * lacks a project file" that `subsystem sync` also fills, so the grader can
99
+ * never name a gap the writer would leave.
100
+ */
101
+ export async function projectFindings(docsDir, entries, shapes) {
102
+ // No root project file, no root project — and no `exclude` list either, so the
103
+ // map is not excluded by anything loam can see. `false` here is a fact, not a
104
+ // default: `readRootExclude` would answer `null` one line down and every grade
105
+ // below it stays silent for the same reason.
106
+ if (!existsSync(rootProjectPath(docsDir)))
107
+ return { findings: [], mapExcluded: false };
108
+ const survey = surveyProjects(entries, serviceRenderPaths, (model) => shapes.get(resolve(model)) !== "extending");
109
+ const exclude = await readRootExclude(docsDir);
110
+ const findings = [];
111
+ // The ONE derivation. The boolean is read off the finding rather than computed
112
+ // beside it, so a fleet where `c4.fleet-project-invalid` is suspended is by
113
+ // construction a fleet where `landscape.excluded` says why.
114
+ const excluded = mapExcluded(docsDir, exclude);
115
+ findings.push(...excluded);
116
+ for (const model of survey.models) {
117
+ const tree = serviceTreePath(model.service);
118
+ // Everything the four share, so each push below is its code and its
119
+ // sentence and nothing else. `scope`, not `primary`: two of the four are
120
+ // about a file that does not exist yet, and the actionable place is the
121
+ // directory either way.
122
+ const at = {
123
+ severity: "warn",
124
+ subject: model.service.id,
125
+ locations: [{ path: tree, role: "scope" }],
126
+ };
127
+ if (model.standalone && !model.configured) {
128
+ findings.push({
129
+ ...at,
130
+ code: "service.likec4-config-missing",
131
+ message: `${model.service.id}: ${tree}/${ARTIFACT_FILES.model} exists and ${tree}/${LIKEC4_PROJECT_FILENAME} does not — ` +
132
+ "a model that stands alone (declares its own `specification`) renders only as a project of its own, " +
133
+ "and nothing renders it from the docs root now. Run `loam subsystem sync`; it writes the file (create-only) — never write it by hand.",
134
+ });
135
+ }
136
+ if (!model.standalone && model.configured) {
137
+ findings.push({
138
+ ...at,
139
+ code: "service.likec4-config-stray",
140
+ message: `${model.service.id}: ${tree}/${ARTIFACT_FILES.model} extends the fleet map and ${tree}/${LIKEC4_PROJECT_FILENAME} ` +
141
+ "sits beside it — the renderer registers that file as a project of its own rooted at that directory, so " +
142
+ "the docs root stops being a one-project workspace (`likec4 validate .` then refuses without `--project`), " +
143
+ "and wherever that nested project claims the model it parses alone, out of the root project where the " +
144
+ "map's kinds are: the model does not resolve and `export json --project fleet` loses this service's " +
145
+ "containers (measured, likec4 1.59.2 — which of the two happens depends on the workspace, and neither is " +
146
+ "a state this file buys anything in). Run `loam subsystem sync`; it deletes the file (or delete it " +
147
+ "yourself). loam never writes one beside an extending model",
148
+ });
149
+ }
150
+ // `excludingEntry` reports the entry VERBATIM because the repair is to
151
+ // delete or narrow THAT line, and a fleet that files its services under
152
+ // subsystems is excluded by `services/platform/**` rather than by anything
153
+ // naming the service — a message that did not quote the entry would send
154
+ // its reader looking for a line that is not there.
155
+ const entry = exclude === null ? null : excludingEntry(exclude, tree);
156
+ // THE SECOND QUESTION, and the state that was silent until it was asked:
157
+ // an entry shaped like a FILE hides the model without covering the
158
+ // directory. `services/**/model.likec4` and the bare `**/model.likec4` each
159
+ // took every extending model out of the renderer on `examples/docs` — 3
160
+ // source files of 8, five drill-down views gone from the export — with the
161
+ // whole run reporting 0 errors and not one line containing the word
162
+ // "exclude" (re-verification 2026-09-04, area C item 5). It is asked ONLY
163
+ // where the directory question said no, because that arm names an entry
164
+ // `subsystem sync` can take back and this one names an entry it cannot.
165
+ const fileEntry = exclude === null || entry !== null ? null : excludingPath(exclude, `${tree}/${ARTIFACT_FILES.model}`);
166
+ const hiding = entry ?? fileEntry;
167
+ if (exclude !== null && !model.standalone && hiding !== null) {
168
+ findings.push({
169
+ ...at,
170
+ code: "service.model-excluded",
171
+ message: `${model.service.id}: ${tree}/${ARTIFACT_FILES.model} extends the fleet map and the root ` +
172
+ `${LIKEC4_PROJECT_FILENAME} excludes it ('${hiding}') — the renderer never loads it, so the service is ` +
173
+ "a box with nothing inside it from the docs root. " +
174
+ (entry === null
175
+ ? // The repair is an EDIT, not a command, and saying otherwise is the
176
+ // loop `landscape.excluded` already refuses to open: sync recomputes
177
+ // only the `services/<tree>/**` entries and would report success
178
+ // having changed nothing.
179
+ "That entry hides the model file without covering " +
180
+ `${tree}/, so \`loam subsystem sync\` cannot repair it: sync maintains only the ` +
181
+ "`services/` directory entries and leaves every other line exactly as the team wrote it. Narrow that " +
182
+ "entry to the paths it was written for, or delete it"
183
+ : "Run `loam subsystem sync`: it rewrites the root project's `exclude` to cover exactly the models " +
184
+ "that stand alone"),
185
+ });
186
+ }
187
+ if (exclude !== null && model.standalone && entry === null) {
188
+ findings.push({
189
+ ...at,
190
+ code: "service.model-unexcluded",
191
+ message: `${model.service.id}: ${tree}/${ARTIFACT_FILES.model} stands alone (declares its own specification) and ` +
192
+ `the root ${LIKEC4_PROJECT_FILENAME} does not exclude ${tree}/ — the renderer merges it into the map ` +
193
+ "and reports every kind and element it declares as a duplicate, blanking the whole root project. " +
194
+ `Run \`loam subsystem sync\`: it adds ${tree}/** to the root project's \`exclude\``,
195
+ });
196
+ }
197
+ }
198
+ return { findings, mapExcluded: excluded.length > 0 };
199
+ }
200
+ /**
201
+ * `landscape.excluded` — the root `exclude` covers the fleet MAP itself.
202
+ *
203
+ * WHY IT EXISTS AT ALL, and why only now. The architecture loader used to apply
204
+ * the root `exclude` with no floor under it, so an entry covering
205
+ * `architecture/landscape.likec4` — an `architecture/*.likec4` written for a
206
+ * palette, say — left that project EMPTY, and an empty project parses with zero
207
+ * errors. Every reader downstream took that for "the map declares nothing":
208
+ * `landscape.service-unmodelled` on every service, `c4.invalid` on every
209
+ * extending model, `subsystem sync` cutting a good generated file back to a
210
+ * title (verification 2026-09-04, review C). The loader now keeps the map
211
+ * whatever the list says, so loam has stopped asserting those falsehoods — but
212
+ * the RENDERER still applies the entry, and it has no floor. Nothing told the
213
+ * author that the fleet map they are grading is a map nobody can open. This is
214
+ * that sentence, and it is the only finding in the run that names it.
215
+ *
216
+ * WARN, NEVER GATING, for the reason the module banner gives: with the loader's
217
+ * floor in place, every fact loam grades holds identically either way. The gap
218
+ * is a renderer gap, exactly like the four per-service grades above.
219
+ *
220
+ * THE SAME ROOT GATE covers it — the caller returns early with no root
221
+ * `likec4.config.json`, and a config loam cannot read an `exclude` list out of
222
+ * answers `null`, which says nothing rather than guessing. It is gated on the
223
+ * map EXISTING as well: with no file there, `landscape.missing` is the finding
224
+ * and an entry covering a path nobody wrote is not a repair anyone owes.
225
+ *
226
+ * `excludingPath`, not `excludingEntry`: the map is a FILE, and this must fire
227
+ * exactly when `architectureProjectDocuments` would have dropped it — same
228
+ * list, same matcher, same argument. Asking the directory question instead
229
+ * would answer for `architecture/` as a whole and miss `architecture/*.likec4`,
230
+ * which is the spelling that caused the defect.
231
+ *
232
+ * The repair is NOT `loam subsystem sync`, and the message says so where the
233
+ * four grades above name it: sync recomputes only the `services/<tree>/**`
234
+ * entries and leaves every other line in the order the team wrote it, so it
235
+ * would report success and change nothing. The four had a writer; this one has
236
+ * an author.
237
+ *
238
+ * AND IT SUSPENDS `c4.fleet-project-invalid`, which is the cascade discipline
239
+ * `permissions.invalid` and `capability.invalid` already state: a grade that
240
+ * RESOLVES against a document nobody loaded is not a diagnosis. That check
241
+ * builds the fleet project the way the renderer does — no floor under the map —
242
+ * so the very entry named here takes the map out of it and every `extend` in
243
+ * every extending model then resolves against nothing. Measured on
244
+ * `examples/docs` with `architecture/*.likec4` in the list: one
245
+ * `landscape.excluded` and **161** `c4.fleet-project-invalid`, all of them one
246
+ * line's fault. The message carries that clause so the reader knows the fleet
247
+ * project is unread rather than clean, and the caller reads the same fact off
248
+ * `ProjectGrade.mapExcluded` — see `./fleet-project.ts`'s `mapExcluded` gate.
249
+ */
250
+ function mapExcluded(docsDir, exclude) {
251
+ const map = landscapePath(docsDir);
252
+ if (exclude === null || !existsSync(map))
253
+ return [];
254
+ const rel = relative(docsDir, map).split(/[\\/]/).join("/");
255
+ const entry = excludingPath(exclude, rel);
256
+ if (entry === null)
257
+ return [];
258
+ return [
259
+ {
260
+ severity: "warn",
261
+ code: "landscape.excluded",
262
+ // Quoted VERBATIM, for `service.model-excluded`'s reason one level down:
263
+ // the repair is to edit THAT line, and an entry loam re-spelled is a line
264
+ // its author would go looking for and not find.
265
+ message: `landscape: the root ${LIKEC4_PROJECT_FILENAME}'s \`exclude\` covers ${rel} ('${entry}') — the renderer never ` +
266
+ "loads the fleet map, so it draws no map at all and every model that EXTENDS the map resolves against " +
267
+ "nothing in the root project, while loam goes on grading the map it reads from disk. `c4.fleet-project-invalid` " +
268
+ "is NOT graded while this entry stands: that check loads the fleet project the way the renderer does, so it " +
269
+ "would report the same one line as an unresolved reference in every extending model rather than as this. " +
270
+ "Remove that entry, or " +
271
+ `narrow it to the paths it was written for, and the fleet project is graded again. \`loam subsystem sync\` ` +
272
+ "will not do it: that command maintains " +
273
+ "only the `services/` entries in the list and leaves every other line exactly as the team wrote it",
274
+ locations: [{ path: rel, role: "primary" }],
275
+ },
276
+ ];
277
+ }
278
+ //# sourceMappingURL=projects.js.map