@ybotok/loam 0.2.0-alpha.5 → 0.2.0-alpha.7

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 (303) hide show
  1. package/CHANGELOG.md +1063 -0
  2. package/MIGRATING-from-OpenSpec.md +7 -4
  3. package/QUICKSTART.md +8 -3
  4. package/README.md +13 -7
  5. package/ROADMAP.md +285 -11
  6. package/SCHEMA.md +566 -45
  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 +53 -23
  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/commit.js +34 -1
  25. package/dist/commands/seed/commit.js.map +1 -1
  26. package/dist/commands/seed/plan.js +158 -13
  27. package/dist/commands/seed/plan.js.map +1 -1
  28. package/dist/commands/seed/seed.js +7 -2
  29. package/dist/commands/seed/seed.js.map +1 -1
  30. package/dist/commands/show/feature.js +2 -1
  31. package/dist/commands/show/feature.js.map +1 -1
  32. package/dist/commands/show/marks.js +3 -5
  33. package/dist/commands/show/marks.js.map +1 -1
  34. package/dist/commands/show/service.js +39 -18
  35. package/dist/commands/show/service.js.map +1 -1
  36. package/dist/commands/subsystem/edit.js +4 -2
  37. package/dist/commands/subsystem/edit.js.map +1 -1
  38. package/dist/commands/subsystem/move.js +55 -17
  39. package/dist/commands/subsystem/move.js.map +1 -1
  40. package/dist/commands/subsystem/sync.js +238 -87
  41. package/dist/commands/subsystem/sync.js.map +1 -1
  42. package/dist/commands/subsystem/txn/exclude.js +132 -0
  43. package/dist/commands/subsystem/txn/exclude.js.map +1 -0
  44. package/dist/commands/subsystem/txn/report.js +174 -0
  45. package/dist/commands/subsystem/txn/report.js.map +1 -0
  46. package/dist/commands/subsystem/txn/txn.js +126 -22
  47. package/dist/commands/subsystem/txn/txn.js.map +1 -1
  48. package/dist/commands/subsystem/txn/views.js +159 -19
  49. package/dist/commands/subsystem/txn/views.js.map +1 -1
  50. package/dist/commands/validate/arch-coverage.js +16 -9
  51. package/dist/commands/validate/arch-coverage.js.map +1 -1
  52. package/dist/commands/validate/checks/fleet-shape.js +30 -77
  53. package/dist/commands/validate/checks/fleet-shape.js.map +1 -1
  54. package/dist/commands/validate/checks/health-deps.js +9 -6
  55. package/dist/commands/validate/checks/health-deps.js.map +1 -1
  56. package/dist/commands/validate/checks/vocabulary.js +4 -19
  57. package/dist/commands/validate/checks/vocabulary.js.map +1 -1
  58. package/dist/commands/validate/feature.js +1 -1
  59. package/dist/commands/validate/feature.js.map +1 -1
  60. package/dist/commands/validate/fleet/census.js +37 -13
  61. package/dist/commands/validate/fleet/census.js.map +1 -1
  62. package/dist/commands/validate/fleet/landscape.js +131 -120
  63. package/dist/commands/validate/fleet/landscape.js.map +1 -1
  64. package/dist/commands/validate/fleet/load.js +66 -0
  65. package/dist/commands/validate/fleet/load.js.map +1 -1
  66. package/dist/commands/validate/fleet/map/attest.js +102 -0
  67. package/dist/commands/validate/fleet/map/attest.js.map +1 -0
  68. package/dist/commands/validate/fleet/map/bindings.js +109 -0
  69. package/dist/commands/validate/fleet/map/bindings.js.map +1 -0
  70. package/dist/commands/validate/fleet/map/consumers.js +219 -0
  71. package/dist/commands/validate/fleet/map/consumers.js.map +1 -0
  72. package/dist/commands/validate/fleet/map/isolation.js +116 -0
  73. package/dist/commands/validate/fleet/map/isolation.js.map +1 -0
  74. package/dist/commands/validate/fleet/map/usecases.js +56 -0
  75. package/dist/commands/validate/fleet/map/usecases.js.map +1 -0
  76. package/dist/commands/validate/fleet/scorecard/scorecard.js.map +1 -1
  77. package/dist/commands/validate/fleet/usecases/steps.js +49 -17
  78. package/dist/commands/validate/fleet/usecases/steps.js.map +1 -1
  79. package/dist/commands/validate/fleet/views/fleet-project.js +217 -0
  80. package/dist/commands/validate/fleet/views/fleet-project.js.map +1 -0
  81. package/dist/commands/validate/fleet/views/ids.js +45 -15
  82. package/dist/commands/validate/fleet/views/ids.js.map +1 -1
  83. package/dist/commands/validate/fleet/views/projects.js +258 -70
  84. package/dist/commands/validate/fleet/views/projects.js.map +1 -1
  85. package/dist/commands/validate/fleet/views/root-documents.js +99 -0
  86. package/dist/commands/validate/fleet/views/root-documents.js.map +1 -0
  87. package/dist/commands/validate/fleet/views/stale.js +32 -15
  88. package/dist/commands/validate/fleet/views/stale.js.map +1 -1
  89. package/dist/commands/validate/service/model/diverged.js +226 -0
  90. package/dist/commands/validate/service/model/diverged.js.map +1 -0
  91. package/dist/commands/validate/service/model/grade.js +163 -0
  92. package/dist/commands/validate/service/model/grade.js.map +1 -0
  93. package/dist/commands/validate/service/service.js +110 -34
  94. package/dist/commands/validate/service/service.js.map +1 -1
  95. package/dist/commands/validate/service/specs.js +39 -5
  96. package/dist/commands/validate/service/specs.js.map +1 -1
  97. package/dist/commands/validate/service/spine.js +41 -3
  98. package/dist/commands/validate/service/spine.js.map +1 -1
  99. package/dist/commands/validate/service/usecases/tags.js +113 -0
  100. package/dist/commands/validate/service/usecases/tags.js.map +1 -0
  101. package/dist/commands/validate/service/usecases/usecases.js +209 -0
  102. package/dist/commands/validate/service/usecases/usecases.js.map +1 -0
  103. package/dist/commands/validate/validate.js +10 -24
  104. package/dist/commands/validate/validate.js.map +1 -1
  105. package/dist/core/agent/agents-md/artifacts.js +1 -0
  106. package/dist/core/agent/agents-md/artifacts.js.map +1 -1
  107. package/dist/core/agent/agents-md/command-map.js +19 -5
  108. package/dist/core/agent/agents-md/command-map.js.map +1 -1
  109. package/dist/core/agent/agents-md/cycle.js +24 -9
  110. package/dist/core/agent/agents-md/cycle.js.map +1 -1
  111. package/dist/core/agent/agents-md/map/lenses/context.js +4 -3
  112. package/dist/core/agent/agents-md/map/lenses/context.js.map +1 -1
  113. package/dist/core/agent/agents-md/map/subsystem.js +70 -17
  114. package/dist/core/agent/agents-md/map/subsystem.js.map +1 -1
  115. package/dist/core/agent/agents-md/map/usecases.js +45 -3
  116. package/dist/core/agent/agents-md/map/usecases.js.map +1 -1
  117. package/dist/core/agent/agents-md/refusals.js +5 -3
  118. package/dist/core/agent/agents-md/refusals.js.map +1 -1
  119. package/dist/core/agent/agents-md.js +26 -7
  120. package/dist/core/agent/agents-md.js.map +1 -1
  121. package/dist/core/agent/support/report.js +39 -5
  122. package/dist/core/agent/support/report.js.map +1 -1
  123. package/dist/core/agent/workflows/adopt.js +123 -14
  124. package/dist/core/agent/workflows/adopt.js.map +1 -1
  125. package/dist/core/agent/workflows/check.js +34 -20
  126. package/dist/core/agent/workflows/check.js.map +1 -1
  127. package/dist/core/agent/workflows/closing.js +3 -1
  128. package/dist/core/agent/workflows/closing.js.map +1 -1
  129. package/dist/core/agent/workflows/reference/spine.js +12 -6
  130. package/dist/core/agent/workflows/reference/spine.js.map +1 -1
  131. package/dist/core/brief/brief.js +88 -19
  132. package/dist/core/brief/brief.js.map +1 -1
  133. package/dist/core/brief/checks.js +133 -7
  134. package/dist/core/brief/checks.js.map +1 -1
  135. package/dist/core/brief/landscape.js +212 -129
  136. package/dist/core/brief/landscape.js.map +1 -1
  137. package/dist/core/brief/map/extend.js +81 -0
  138. package/dist/core/brief/map/extend.js.map +1 -0
  139. package/dist/core/brief/map/owed.js +284 -0
  140. package/dist/core/brief/map/owed.js.map +1 -0
  141. package/dist/core/brief/targets.js +94 -29
  142. package/dist/core/brief/targets.js.map +1 -1
  143. package/dist/core/brief/unchecked.js +13 -3
  144. package/dist/core/brief/unchecked.js.map +1 -1
  145. package/dist/core/c4/likec4.js +23 -1
  146. package/dist/core/c4/likec4.js.map +1 -1
  147. package/dist/core/c4/parsed/deployment.js +5 -3
  148. package/dist/core/c4/parsed/deployment.js.map +1 -1
  149. package/dist/core/c4/parsed/view-ids.js +39 -1
  150. package/dist/core/c4/parsed/view-ids.js.map +1 -1
  151. package/dist/core/c4/prefetch/fleet.js +142 -0
  152. package/dist/core/c4/prefetch/fleet.js.map +1 -0
  153. package/dist/core/c4/project/architecture.js +77 -7
  154. package/dist/core/c4/project/architecture.js.map +1 -1
  155. package/dist/core/c4/project/batch.js +140 -0
  156. package/dist/core/c4/project/batch.js.map +1 -0
  157. package/dist/core/c4/project/documents.js +12 -6
  158. package/dist/core/c4/project/documents.js.map +1 -1
  159. package/dist/core/c4/project/load.js +85 -42
  160. package/dist/core/c4/project/load.js.map +1 -1
  161. package/dist/core/c4/project/staged.js +53 -15
  162. package/dist/core/c4/project/staged.js.map +1 -1
  163. package/dist/core/c4/resolve/attested.js +0 -0
  164. package/dist/core/c4/resolve/attested.js.map +1 -0
  165. package/dist/core/c4/resolve/service.js +8 -17
  166. package/dist/core/c4/resolve/service.js.map +1 -1
  167. package/dist/core/c4/resolve/steps.js +18 -0
  168. package/dist/core/c4/resolve/steps.js.map +1 -1
  169. package/dist/core/c4/root-project/exclude.js +352 -0
  170. package/dist/core/c4/root-project/exclude.js.map +1 -0
  171. package/dist/core/c4/service-model/documents.js +47 -0
  172. package/dist/core/c4/service-model/documents.js.map +1 -0
  173. package/dist/core/c4/service-model/fleet/extending.js +82 -0
  174. package/dist/core/c4/service-model/fleet/extending.js.map +1 -0
  175. package/dist/core/c4/service-model/load.js +165 -0
  176. package/dist/core/c4/service-model/load.js.map +1 -0
  177. package/dist/core/c4/service-model/renderer.js +128 -0
  178. package/dist/core/c4/service-model/renderer.js.map +1 -0
  179. package/dist/core/c4/service-model/shape.js +126 -0
  180. package/dist/core/c4/service-model/shape.js.map +1 -0
  181. package/dist/core/c4/service-model/slice.js +188 -0
  182. package/dist/core/c4/service-model/slice.js.map +1 -0
  183. package/dist/core/c4/source-scan.js +26 -0
  184. package/dist/core/c4/source-scan.js.map +1 -1
  185. package/dist/core/c4/splice/authored-source.js +60 -13
  186. package/dist/core/c4/splice/authored-source.js.map +1 -1
  187. package/dist/core/c4/splice/contract.js.map +1 -1
  188. package/dist/core/c4/splice/identity/declared.js +87 -0
  189. package/dist/core/c4/splice/identity/declared.js.map +1 -0
  190. package/dist/core/c4/splice/identity/edges.js +17 -0
  191. package/dist/core/c4/splice/identity/edges.js.map +1 -1
  192. package/dist/core/c4/splice/identity/existing.js +80 -0
  193. package/dist/core/c4/splice/identity/existing.js.map +1 -0
  194. package/dist/core/c4/splice/identity/interior.js +80 -0
  195. package/dist/core/c4/splice/identity/interior.js.map +1 -0
  196. package/dist/core/c4/splice/identity/owner.js +50 -0
  197. package/dist/core/c4/splice/identity/owner.js.map +1 -0
  198. package/dist/core/c4/splice/landscape-merge.js +154 -100
  199. package/dist/core/c4/splice/landscape-merge.js.map +1 -1
  200. package/dist/core/c4/splice/model/merge.js +140 -0
  201. package/dist/core/c4/splice/model/merge.js.map +1 -0
  202. package/dist/core/c4/splice/placement.js +14 -4
  203. package/dist/core/c4/splice/placement.js.map +1 -1
  204. package/dist/core/c4/workspace.js +2 -1
  205. package/dist/core/c4/workspace.js.map +1 -1
  206. package/dist/core/coherence/coherence.js +7 -0
  207. package/dist/core/coherence/coherence.js.map +1 -1
  208. package/dist/core/delta/delta.js +9 -0
  209. package/dist/core/delta/delta.js.map +1 -1
  210. package/dist/core/deployment/delta.js +16 -10
  211. package/dist/core/deployment/delta.js.map +1 -1
  212. package/dist/core/diff/base-state.js +21 -5
  213. package/dist/core/diff/base-state.js.map +1 -1
  214. package/dist/core/diff/victims.js +10 -1
  215. package/dist/core/diff/victims.js.map +1 -1
  216. package/dist/core/docs.js +29 -24
  217. package/dist/core/docs.js.map +1 -1
  218. package/dist/core/doctor/config.js +7 -3
  219. package/dist/core/doctor/config.js.map +1 -1
  220. package/dist/core/doctor/doctor.js +36 -8
  221. package/dist/core/doctor/doctor.js.map +1 -1
  222. package/dist/core/doctor/report.js.map +1 -1
  223. package/dist/core/doctor/reports/scan.js +242 -0
  224. package/dist/core/doctor/reports/scan.js.map +1 -0
  225. package/dist/core/explain/refusals.js +1 -1
  226. package/dist/core/explain/refusals.js.map +1 -1
  227. package/dist/core/explore/explore.js +44 -9
  228. package/dist/core/explore/explore.js.map +1 -1
  229. package/dist/core/fleet-context.js +47 -0
  230. package/dist/core/fleet-context.js.map +1 -1
  231. package/dist/core/gate/checks.js +5 -1
  232. package/dist/core/gate/checks.js.map +1 -1
  233. package/dist/core/gate/partners.js +65 -26
  234. package/dist/core/gate/partners.js.map +1 -1
  235. package/dist/core/kernel/ids/fqn/ancestors.js +65 -0
  236. package/dist/core/kernel/ids/fqn/ancestors.js.map +1 -0
  237. package/dist/core/pack/living.js +47 -13
  238. package/dist/core/pack/living.js.map +1 -1
  239. package/dist/core/pack/pack.js +9 -6
  240. package/dist/core/pack/pack.js.map +1 -1
  241. package/dist/core/projection/arch-slice.js +2 -2
  242. package/dist/core/projection/arch-slice.js.map +1 -1
  243. package/dist/core/repo/paths.js +45 -38
  244. package/dist/core/repo/paths.js.map +1 -1
  245. package/dist/core/repo/tree/render/body.js +45 -6
  246. package/dist/core/repo/tree/render/body.js.map +1 -1
  247. package/dist/core/repo/tree/render/projects.js +93 -35
  248. package/dist/core/repo/tree/render/projects.js.map +1 -1
  249. package/dist/core/repo/tree/render/service/header.js +125 -0
  250. package/dist/core/repo/tree/render/service/header.js.map +1 -0
  251. package/dist/core/repo/tree/render/service/peers.js +28 -0
  252. package/dist/core/repo/tree/render/service/peers.js.map +1 -0
  253. package/dist/core/repo/tree/render/service/view-id.js +67 -0
  254. package/dist/core/repo/tree/render/service/view-id.js.map +1 -0
  255. package/dist/core/repo/tree/render/service/views.js +78 -0
  256. package/dist/core/repo/tree/render/service/views.js.map +1 -0
  257. package/dist/core/repo/tree/render/stale.js +20 -4
  258. package/dist/core/repo/tree/render/stale.js.map +1 -1
  259. package/dist/core/repo/tree/render/views.js +149 -32
  260. package/dist/core/repo/tree/render/views.js.map +1 -1
  261. package/dist/core/repo/tree/walk.js +45 -2
  262. package/dist/core/repo/tree/walk.js.map +1 -1
  263. package/dist/core/scaffold/landscape.js +219 -9
  264. package/dist/core/scaffold/landscape.js.map +1 -1
  265. package/dist/core/staging/writes.js.map +1 -1
  266. package/dist/core/usecases/delta/claims.js +1 -0
  267. package/dist/core/usecases/delta/claims.js.map +1 -1
  268. package/dist/core/usecases/delta/overlay.js +4 -0
  269. package/dist/core/usecases/delta/overlay.js.map +1 -1
  270. package/dist/core/usecases/fleet.js +18 -6
  271. package/dist/core/usecases/fleet.js.map +1 -1
  272. package/dist/core/usecases/operations.js +7 -0
  273. package/dist/core/usecases/operations.js.map +1 -1
  274. package/dist/core/usecases/service/exclude.js +119 -0
  275. package/dist/core/usecases/service/exclude.js.map +1 -0
  276. package/dist/core/usecases/service/flows.js +161 -0
  277. package/dist/core/usecases/service/flows.js.map +1 -0
  278. package/dist/core/verify/checklist.js +42 -10
  279. package/dist/core/verify/checklist.js.map +1 -1
  280. package/dist/core/vocabulary/issue.js.map +1 -1
  281. package/dist/core/vocabulary/maturity.js +51 -1
  282. package/dist/core/vocabulary/maturity.js.map +1 -1
  283. package/examples/README.md +30 -8
  284. package/examples/docs/architecture/landscape.likec4 +47 -0
  285. package/examples/docs/architecture/services.likec4 +70 -0
  286. package/examples/docs/architecture/subsystems.likec4 +3 -0
  287. package/examples/docs/architecture/usecases/order-notification.likec4 +5 -2
  288. package/examples/docs/likec4.config.json +0 -1
  289. package/examples/docs/services/checkout-web/model.likec4 +39 -56
  290. package/examples/docs/services/order-service/arch.spec.md +13 -6
  291. package/examples/docs/services/order-service/model.likec4 +58 -70
  292. package/examples/docs/services/payment-service/arch.spec.md +7 -4
  293. package/examples/docs/services/payment-service/model.likec4 +38 -39
  294. package/examples/docs/services/platform/identity-service/arch.spec.md +7 -4
  295. package/examples/docs/services/platform/identity-service/model.likec4 +35 -37
  296. package/examples/docs/services/platform/notification-service/health.yaml +8 -3
  297. package/examples/docs/services/platform/notification-service/model.likec4 +43 -64
  298. package/package.json +1 -1
  299. package/examples/docs/services/checkout-web/likec4.config.json +0 -4
  300. package/examples/docs/services/order-service/likec4.config.json +0 -4
  301. package/examples/docs/services/payment-service/likec4.config.json +0 -4
  302. package/examples/docs/services/platform/identity-service/likec4.config.json +0 -4
  303. package/examples/docs/services/platform/notification-service/likec4.config.json +0 -4
@@ -13,11 +13,13 @@
13
13
  * PRODUCER owns the contract and it lives in another repository, so the two
14
14
  * could not share a walk even though they share the shape.
15
15
  */
16
+ import { relative } from "node:path";
16
17
  import {} from "../../../core/kernel/ids/service.js";
17
18
  import {} from "../../../core/c4/likec4.js";
19
+ import {} from "../../../core/kernel/ids/dirs.js";
18
20
  import {} from "../../../core/kernel/ids/service.js";
19
21
  import {} from "../../../core/vocabulary/report.js";
20
- import { errorText } from "../checks/vocabulary.js";
22
+ import { errorText } from "../../../core/c4/likec4.js";
21
23
  import {} from "./api.js";
22
24
  export function spineFindings(spine) {
23
25
  const { service, me, land, landSvcOf, contract } = spine;
@@ -35,15 +37,51 @@ export function spineFindings(spine) {
35
37
  // becomes N copies of a dozen cascading diagnostics on a fleet of N
36
38
  // services — the report stops being readable at exactly the moment
37
39
  // somebody needs to read it, and the fix is one file either way.
40
+ // Which DOCUMENT broke, spelled exactly as the fleet arm spells it
41
+ // (`fleet/landscape.ts`): `land` is the whole `architecture/` project, so
42
+ // the broken file is as often a `usecases/*.likec4` as the map itself,
43
+ // and the filename used to be hardcoded here — an agent told to "fix the
44
+ // file the message names" opened a document that parses (verification
45
+ // 2026-09-04, W2).
46
+ const broken = [
47
+ ...new Set(land.errors.map((e) => e.sourceFsPath).filter((p) => p !== undefined)),
48
+ ]
49
+ .map((abs) => relative(spine.docsDir, abs).split(/[\\/]/).join("/"))
50
+ .sort();
51
+ const named = broken.length === 0 ? "architecture/landscape.likec4" : broken.join(", ");
52
+ // The verb agrees with the LIST, not with the count after it: `named` is a
53
+ // comma-joined series once two documents broke, and "a, b, c has 6
54
+ // error(s)" is a sentence a reader trips over — the same care `remedy()`
55
+ // in model/diverged.ts takes over "the kind differ".
56
+ const verb = broken.length > 1 ? "have" : "has";
38
57
  findings.push({
39
58
  severity: "error",
40
59
  code: "spine.landscape-invalid",
41
60
  subject: service,
42
- message: `${service}: landscape.likec4 has ${land.errors.length} error(s) — spine check impossible` +
61
+ message: `${service}: ${named} ${verb} ${land.errors.length} error(s) — spine check impossible` +
62
+ (spine.modelExtends === true
63
+ ? " — and model.likec4 extends it, so the model cannot be read either"
64
+ : "") +
43
65
  (spine.landscapeReported === true
44
66
  ? "; the parser output is reported once, on the landscape target"
45
67
  : ""),
46
- ...(spine.landscapeReported === true ? {} : { details: land.errors.map(errorText) }),
68
+ ...(spine.landscapeReported === true
69
+ ? {}
70
+ : {
71
+ // Every line carries its own file once more than one document is
72
+ // broken, the fleet arm's rule verbatim: a bare `L8:` across two
73
+ // documents is unactionable.
74
+ details: land.errors.map((e) => e.sourceFsPath === undefined || broken.length < 2
75
+ ? errorText(e)
76
+ : `${relative(spine.docsDir, e.sourceFsPath).split(/[\\/]/).join("/")} ${errorText(e)}`),
77
+ }),
78
+ // The broken document first, the service second: the finding is about a
79
+ // file under `architecture/` and is FILED on this service, and without
80
+ // the pair the payload carried only the service directory.
81
+ locations: [
82
+ ...(broken.length === 0 ? [] : [{ path: broken[0], role: "primary" }]),
83
+ { path: spine.treePath, role: "scope" },
84
+ ],
47
85
  });
48
86
  }
49
87
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"spine.js","sourceRoot":"","sources":["../../../../src/commands/validate/service/spine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAwB,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAkB,MAAM,4B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OAAO,WAAW,CAAC,CAAC,EAAE,YAAY,OAAO,kEAAkE;yBACxK,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;qBAAM,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC5D,QAAQ,CAAC,IAAI,CAAC;wBACZ,QAAQ,EAAE,MAAM;wBAChB,IAAI,EAAE,uBAAuB;wBAC7B,OAAO,EAAE,GAAG,OAAO,oBAAoB,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC,KAAK,4CAA4C;qBAC7H,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,IAAI,MAAM,KAAK,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;gBAChC,QAAQ,CAAC,IAAI,CAAC;oBACZ,QAAQ,EAAE,IAAI;oBACd,IAAI,EAAE,gBAAgB;oBACtB,OAAO,EAAE,GAAG,OAAO,sBAAsB,OAAO,sCAAsC;iBACvF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * The inbound half of the C4↔API spine: every cross-system edge the living\n * landscape draws INTO this service must resolve to a real operation in its\n * OpenAPI.\n *\n * Separate from `./api.js` because the two grade different documents and the\n * fix lives in different files — a broken edge is the fleet map's mistake, a\n * missing operation is the contract's — but it may conclude nothing without\n * `api.js`'s answer, which is why `ServiceContract` is a parameter rather than\n * a second read of openapi.yaml.\n *\n * The event-side mirror of this check is inside `./events.js`: there the\n * PRODUCER owns the contract and it lives in another repository, so the two\n * could not share a walk even though they share the shape.\n */\nimport { type DeclaredService } from \"../../../core/kernel/ids/service.js\";\nimport { type LoadedDoc } from \"../../../core/c4/likec4.js\";\nimport { type PathableService } from \"../../../core/kernel/ids/service.js\";\nimport { type Finding } from \"../../../core/vocabulary/report.js\";\nimport { errorText } from \"../checks/vocabulary.js\";\nimport { type ServiceContract } from \"./api.js\";\n\n/** What the service target hands the spine check. */\nexport interface Spine {\n service: PathableService;\n /** `service` widened for `===` against the resolver's DOCUMENT text — see service.ts. */\n me: string;\n /** The living landscape, or null when the repo has none. */\n land: LoadedDoc | null;\n /** Its element→service resolver; null exactly when `land` is. */\n landSvcOf: ((id: string) => DeclaredService) | null;\n contract: ServiceContract;\n /** True when this run also emits a landscape target — see `ServiceCheck`. */\n landscapeReported?: boolean;\n}\n\nexport function spineFindings(spine: Spine): Finding[] {\n const { service, me, land, landSvcOf, contract } = spine;\n const findings: Finding[] = [];\n\n // Landscape spine: cross-system edges calling THIS service must resolve to a real\n // operation in its OpenAPI — the C4↔API contract, checked in the living landscape,\n // not only in feature mode. Catches dangling / de-linked op edges.\n if (land !== null) {\n if (land.errors.length > 0) {\n // A living landscape that does not parse disables the C4↔API spine check —\n // that is a broken source of truth, not a skippable detail.\n //\n // The parser's own output is attached ONCE per run, and not here when the\n // run has a landscape target to carry it. One syntax error in one file\n // becomes N copies of a dozen cascading diagnostics on a fleet of N\n // services — the report stops being readable at exactly the moment\n // somebody needs to read it, and the fix is one file either way.\n findings.push({\n severity: \"error\",\n code: \"spine.landscape-invalid\",\n subject: service,\n message:\n `${service}: landscape.likec4 has ${land.errors.length} error(s) — spine check impossible` +\n (spine.landscapeReported === true\n ? \"; the parser output is reported once, on the landscape target\"\n : \"\"),\n ...(spine.landscapeReported === true ? {} : { details: land.errors.map(errorText) }),\n });\n } else {\n // Which element IS this service is the binding's call, then a title that\n // names a real services/<id>/, and an edge into a modelled container\n // counts as an edge into its service — matching the exact id alone meant a\n // container edge left the spine without a word.\n const svcOf = landSvcOf!;\n const opset = new Set(contract.ops);\n let checked = 0;\n let broken = 0;\n for (const r of land.relationships) {\n if (svcOf(r.target) !== me) continue;\n if (r.op !== undefined) {\n // A contract that cannot be read — broken, or not there at all —\n // proves nothing about this edge, neither broken nor resolved.\n // Grading the edges against an empty operation set turned ONE root\n // cause (the file) into one `spine.op-undefined` per inbound edge, so\n // a service with twelve consumers reported twelve landscape defects\n // and never named the file. `openapi.invalid` / `service.no-openapi`\n // already did, from ./api.js; only op-link-missing (which never reads\n // the contract) stays live, and `checked` stays 0 so no false\n // spine.resolved is claimed either.\n if (contract.unreadable) continue;\n checked += 1;\n if (!opset.has(r.op)) {\n broken += 1;\n findings.push({\n severity: \"error\",\n code: \"spine.op-undefined\",\n message: `${service}: landscape edge ${svcOf(r.source)} → ${service} calls '${r.op}', not defined in ${service}'s OpenAPI`,\n });\n } else if (contract.deprecated.has(r.op)) {\n // The contract holds — the op is defined — but it is marked\n // `deprecated: true`: the consumer is standing on a contract being\n // retired, and should be migrating off it. Warn per inbound edge;\n // a deprecated op nobody calls raises no spine finding at all.\n findings.push({\n severity: \"warn\",\n code: \"spine.op-deprecated\",\n message: `${service}: landscape edge ${svcOf(r.source)} → ${service} calls '${r.op}', which ${service}'s OpenAPI marks deprecated — the consumer should migrate off it`,\n });\n }\n } else if ((r.title ?? \"\").toLowerCase().startsWith(\"call\")) {\n findings.push({\n severity: \"warn\",\n code: \"spine.op-link-missing\",\n message: `${service}: landscape edge ${svcOf(r.source)} → ${service} (\"${r.title}\") has no operation link (metadata { op })`,\n });\n }\n }\n if (broken === 0 && checked > 0) {\n findings.push({\n severity: \"ok\",\n code: \"spine.resolved\",\n message: `${service}: landscape spine (${checked} inbound call(s) resolve to OpenAPI)`,\n });\n }\n }\n }\n\n return findings;\n}\n"]}
1
+ {"version":3,"file":"spine.js","sourceRoot":"","sources":["../../../../src/commands/validate/service/spine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAwB,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAgB,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAwB,MAAM,qCAA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AAY;yBAC3H,CAAC,CAAC;oBACL,CAAC;yBAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;wBACzC,4DAA4D;wBAC5D,mEAAmE;wBACnE,kEAAkE;wBAClE,+DAA+D;wBAC/D,QAAQ,CAAC,IAAI,CAAC;4BACZ,QAAQ,EAAE,MAAM;4BAChB,IAAI,EAAE,qBAAqB;4BAC3B,OAAO,EAAE,GAAG,OAAO,oBAAoB,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC,EAAE,YAAY,OAAO,kEAAkE;yBACxK,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;qBAAM,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC5D,QAAQ,CAAC,IAAI,CAAC;wBACZ,QAAQ,EAAE,MAAM;wBAChB,IAAI,EAAE,uBAAuB;wBAC7B,OAAO,EAAE,GAAG,OAAO,oBAAoB,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,CAAC,KAAK,4CAA4C;qBAC7H,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,IAAI,MAAM,KAAK,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;gBAChC,QAAQ,CAAC,IAAI,CAAC;oBACZ,QAAQ,EAAE,IAAI;oBACd,IAAI,EAAE,gBAAgB;oBACtB,OAAO,EAAE,GAAG,OAAO,sBAAsB,OAAO,sCAAsC;iBACvF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * The inbound half of the C4↔API spine: every cross-system edge the living\n * landscape draws INTO this service must resolve to a real operation in its\n * OpenAPI.\n *\n * Separate from `./api.js` because the two grade different documents and the\n * fix lives in different files — a broken edge is the fleet map's mistake, a\n * missing operation is the contract's — but it may conclude nothing without\n * `api.js`'s answer, which is why `ServiceContract` is a parameter rather than\n * a second read of openapi.yaml.\n *\n * The event-side mirror of this check is inside `./events.js`: there the\n * PRODUCER owns the contract and it lives in another repository, so the two\n * could not share a walk even though they share the shape.\n */\nimport { relative } from \"node:path\";\nimport { type DeclaredService } from \"../../../core/kernel/ids/service.js\";\nimport { type LoadedDoc } from \"../../../core/c4/likec4.js\";\nimport { type DocsDir } from \"../../../core/kernel/ids/dirs.js\";\nimport { type PathableService } from \"../../../core/kernel/ids/service.js\";\nimport { type Finding } from \"../../../core/vocabulary/report.js\";\nimport { errorText } from \"../../../core/c4/likec4.js\";\nimport { type ServiceContract } from \"./api.js\";\n\n/** What the service target hands the spine check. */\nexport interface Spine {\n service: PathableService;\n /** The docs root, so a project error's absolute path can be spelled repo-relative. */\n docsDir: DocsDir;\n /** The service directory, repo-relative and `/`-separated — the scope location beside the broken file. */\n treePath: string;\n /** `service` widened for `===` against the resolver's DOCUMENT text — see service.ts. */\n me: string;\n /** The living landscape, or null when the repo has none. */\n land: LoadedDoc | null;\n /** Its element→service resolver; null exactly when `land` is. */\n landSvcOf: ((id: string) => DeclaredService) | null;\n contract: ServiceContract;\n /** True when this run also emits a landscape target — see `ServiceCheck`. */\n landscapeReported?: boolean;\n /**\n * True when this service's `model.likec4` EXTENDS the map rather than\n * standing alone (`core/c4/service-model/shape.ts`).\n *\n * It changes one sentence and no verdict. An extending model is parsed inside\n * the `architecture/` project, so a map that does not parse takes the model\n * with it: there is no `c4.invalid` and no `c4.valid` on the service target,\n * and without this clause the report shows a service whose model is simply\n * never mentioned. Said here rather than as a finding of its own because it is\n * the same fact — one unreadable document — and a second code would be a\n * second thing to fix for one repair.\n */\n modelExtends?: boolean;\n}\n\nexport function spineFindings(spine: Spine): Finding[] {\n const { service, me, land, landSvcOf, contract } = spine;\n const findings: Finding[] = [];\n\n // Landscape spine: cross-system edges calling THIS service must resolve to a real\n // operation in its OpenAPI — the C4↔API contract, checked in the living landscape,\n // not only in feature mode. Catches dangling / de-linked op edges.\n if (land !== null) {\n if (land.errors.length > 0) {\n // A living landscape that does not parse disables the C4↔API spine check —\n // that is a broken source of truth, not a skippable detail.\n //\n // The parser's own output is attached ONCE per run, and not here when the\n // run has a landscape target to carry it. One syntax error in one file\n // becomes N copies of a dozen cascading diagnostics on a fleet of N\n // services — the report stops being readable at exactly the moment\n // somebody needs to read it, and the fix is one file either way.\n // Which DOCUMENT broke, spelled exactly as the fleet arm spells it\n // (`fleet/landscape.ts`): `land` is the whole `architecture/` project, so\n // the broken file is as often a `usecases/*.likec4` as the map itself,\n // and the filename used to be hardcoded here — an agent told to \"fix the\n // file the message names\" opened a document that parses (verification\n // 2026-09-04, W2).\n const broken = [\n ...new Set(land.errors.map((e) => e.sourceFsPath).filter((p): p is string => p !== undefined)),\n ]\n .map((abs) => relative(spine.docsDir, abs).split(/[\\\\/]/).join(\"/\"))\n .sort();\n const named = broken.length === 0 ? \"architecture/landscape.likec4\" : broken.join(\", \");\n // The verb agrees with the LIST, not with the count after it: `named` is a\n // comma-joined series once two documents broke, and \"a, b, c has 6\n // error(s)\" is a sentence a reader trips over — the same care `remedy()`\n // in model/diverged.ts takes over \"the kind differ\".\n const verb = broken.length > 1 ? \"have\" : \"has\";\n findings.push({\n severity: \"error\",\n code: \"spine.landscape-invalid\",\n subject: service,\n message:\n `${service}: ${named} ${verb} ${land.errors.length} error(s) — spine check impossible` +\n (spine.modelExtends === true\n ? \" — and model.likec4 extends it, so the model cannot be read either\"\n : \"\") +\n (spine.landscapeReported === true\n ? \"; the parser output is reported once, on the landscape target\"\n : \"\"),\n ...(spine.landscapeReported === true\n ? {}\n : {\n // Every line carries its own file once more than one document is\n // broken, the fleet arm's rule verbatim: a bare `L8:` across two\n // documents is unactionable.\n details: land.errors.map((e) =>\n e.sourceFsPath === undefined || broken.length < 2\n ? errorText(e)\n : `${relative(spine.docsDir, e.sourceFsPath).split(/[\\\\/]/).join(\"/\")} ${errorText(e)}`,\n ),\n }),\n // The broken document first, the service second: the finding is about a\n // file under `architecture/` and is FILED on this service, and without\n // the pair the payload carried only the service directory.\n locations: [\n ...(broken.length === 0 ? [] : [{ path: broken[0]!, role: \"primary\" as const }]),\n { path: spine.treePath, role: \"scope\" as const },\n ],\n });\n } else {\n // Which element IS this service is the binding's call, then a title that\n // names a real services/<id>/, and an edge into a modelled container\n // counts as an edge into its service — matching the exact id alone meant a\n // container edge left the spine without a word.\n const svcOf = landSvcOf!;\n const opset = new Set(contract.ops);\n let checked = 0;\n let broken = 0;\n for (const r of land.relationships) {\n if (svcOf(r.target) !== me) continue;\n if (r.op !== undefined) {\n // A contract that cannot be read — broken, or not there at all —\n // proves nothing about this edge, neither broken nor resolved.\n // Grading the edges against an empty operation set turned ONE root\n // cause (the file) into one `spine.op-undefined` per inbound edge, so\n // a service with twelve consumers reported twelve landscape defects\n // and never named the file. `openapi.invalid` / `service.no-openapi`\n // already did, from ./api.js; only op-link-missing (which never reads\n // the contract) stays live, and `checked` stays 0 so no false\n // spine.resolved is claimed either.\n if (contract.unreadable) continue;\n checked += 1;\n if (!opset.has(r.op)) {\n broken += 1;\n findings.push({\n severity: \"error\",\n code: \"spine.op-undefined\",\n message: `${service}: landscape edge ${svcOf(r.source)} → ${service} calls '${r.op}', not defined in ${service}'s OpenAPI`,\n });\n } else if (contract.deprecated.has(r.op)) {\n // The contract holds — the op is defined — but it is marked\n // `deprecated: true`: the consumer is standing on a contract being\n // retired, and should be migrating off it. Warn per inbound edge;\n // a deprecated op nobody calls raises no spine finding at all.\n findings.push({\n severity: \"warn\",\n code: \"spine.op-deprecated\",\n message: `${service}: landscape edge ${svcOf(r.source)} → ${service} calls '${r.op}', which ${service}'s OpenAPI marks deprecated — the consumer should migrate off it`,\n });\n }\n } else if ((r.title ?? \"\").toLowerCase().startsWith(\"call\")) {\n findings.push({\n severity: \"warn\",\n code: \"spine.op-link-missing\",\n message: `${service}: landscape edge ${svcOf(r.source)} → ${service} (\"${r.title}\") has no operation link (metadata { op })`,\n });\n }\n }\n if (broken === 0 && checked > 0) {\n findings.push({\n severity: \"ok\",\n code: \"spine.resolved\",\n message: `${service}: landscape spine (${checked} inbound call(s) resolve to OpenAPI)`,\n });\n }\n }\n }\n\n return findings;\n}\n"]}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The two tag grades of a SERVICE-LOCAL use case: `usecase.requirement-unresolved`
3
+ * with service-worded arms, and `usecase.capability-unresolved`'s placement arm.
4
+ *
5
+ * Both codes are REUSED from the fleet target rather than minted, under
6
+ * add-error-code's "prefer existing" rule: a caller acts the same way (fix the
7
+ * tag, or the `Requirement-ID:` line it names), and only the sentences differ.
8
+ * The fleet's own graders (`../../fleet/usecases/{requirement,capability}-tag.ts`)
9
+ * are not reused for the sentences, because every one of theirs names a
10
+ * capability document, and a service-local flow has none.
11
+ *
12
+ * WHY `#req-` IS SCOPED BY THE SERVICE. Inside `architecture/`, a `#req-` tag
13
+ * means nothing until a `#cap-` tag has said which capability document the
14
+ * `Requirement-ID` is unique inside. Beside a model there is no such question:
15
+ * the directory IS the scope, and the ids are the ones THIS service's `spec.md`
16
+ * and `arch.spec.md` declare — the flow keeps a container-level promise the way
17
+ * a fleet flow keeps a business one. The join is `resolveRequirementTags` with
18
+ * the service as its one-element scope, so the arms fall out mechanically and
19
+ * `unscoped` is unreachable.
20
+ *
21
+ * WHY `#cap-` IS REFUSED, NOT IGNORED AND NOT RESOLVED. A capability is
22
+ * realized by a hop sequence across the fleet map — "the only join that
23
+ * crosses services" — and `keptBy` reads the fleet project only. Ignoring the
24
+ * tag would leave `#cap-checkout` on a service flow green and silently unread;
25
+ * resolving it against the vocabulary would make validate see a claim no other
26
+ * surface sees. So it is refused by PLACEMENT, whether or not
27
+ * `architecture/capabilities.yaml` exists: the reason is where the tag sits,
28
+ * not what the vocabulary says. The view stays opted in and its steps are
29
+ * graded — either prefix is the opt-in, exactly as at fleet altitude.
30
+ */
31
+ import { CAP_TAG_PREFIX, REQ_TAG_PREFIX, resolveRequirementTags, tagSlug, } from "../../../../core/capabilities/usecase-join.js";
32
+ import { compareIds } from "../../../../core/repo/entries.js";
33
+ /** A `Requirement-ID` as an author must write it in a tag: `PAY.AUTH (#req-PAY-AUTH)`. */
34
+ function idAndTag(id) {
35
+ return `${id} (#${REQ_TAG_PREFIX}${tagSlug(id)})`;
36
+ }
37
+ /**
38
+ * The fix for one unresolved claim, in the service's own vocabulary. The same
39
+ * arms the fleet grade has, each sentence pointing at the document that
40
+ * carries the fix here — spec.md and arch.spec.md, never a capability.
41
+ */
42
+ function advice(claim, scope) {
43
+ const where = `${scope.service} (spec.md or arch.spec.md)`;
44
+ switch (claim.kind) {
45
+ case "unscoped":
46
+ // Unreachable: the scope is always exactly one service. A sentence
47
+ // rather than a throw, because this runs inside a validate run over
48
+ // somebody's fleet, and a broken invariant there is one finding, not a
49
+ // crash.
50
+ return "the flow could not be scoped to this service — report this: a service-local flow is always scoped to its own directory.";
51
+ case "undocumented":
52
+ return (`${scope.treePath}/ has no spec.md and no arch.spec.md, so it carries no requirements to satisfy. ` +
53
+ "Write the requirement first — a flow keeps a promise a document makes.");
54
+ case "empty":
55
+ return (`${scope.service}'s spec.md and arch.spec.md declare no \`Requirement-ID:\` at all — a #req- tag joins by ` +
56
+ "stable id, and a requirement without one cannot be named by a flow. Add `Requirement-ID: <id>` to the " +
57
+ "requirement this flow keeps.");
58
+ case "none":
59
+ return claim.close.length > 0
60
+ ? `no requirement of ${where} flattens to '${claim.slug}'. Did you mean: ${claim.close.map(idAndTag).join(", ")}?`
61
+ : `no requirement of ${where} flattens to '${claim.slug}' — check the \`Requirement-ID:\` lines in both documents.`;
62
+ default:
63
+ return (`${claim.ids.length} requirements of ${scope.service} flatten to '${claim.slug}' (${claim.ids.join(", ")}) — ` +
64
+ "a Requirement-ID is unique inside ONE document and this service has two, so nothing in the tag can say " +
65
+ "which promise the flow keeps. Rename one of them.");
66
+ }
67
+ }
68
+ /**
69
+ * One finding per `#req-` tag that does not resolve against the service's own
70
+ * ids — never one per view, for the fleet grade's reason: several `#req-` tags
71
+ * on one view are legal and normal, and a broken tag beside a working one must
72
+ * neither swallow the break nor lose the promise the view genuinely keeps.
73
+ */
74
+ function requirementFindings(view, scope, place) {
75
+ const findings = [];
76
+ for (const claim of resolveRequirementTags(view.tags, [scope.service], () => scope.requirementIds)) {
77
+ if (claim.kind === "resolved")
78
+ continue;
79
+ findings.push({
80
+ severity: "error",
81
+ code: "usecase.requirement-unresolved",
82
+ // The VIEW, not the tag, as at fleet altitude: a subject is what a reader
83
+ // goes and opens, and one broken use case counts once however many of
84
+ // its tags are wrong.
85
+ subject: view.id,
86
+ message: `${place} is tagged #${claim.tag}, and it does not resolve: ${advice(claim, scope)}`,
87
+ });
88
+ }
89
+ return findings;
90
+ }
91
+ /**
92
+ * One finding per `#cap-` tag the view carries — the placement refusal. Sorted
93
+ * and de-duplicated for `resolveCapabilityTags`' reason: nothing in loam has
94
+ * measured that LikeC4 preserves the author's tag order, and one breach earns
95
+ * one finding.
96
+ */
97
+ function capabilityFindings(view, place) {
98
+ const claimed = [...new Set(view.tags.filter((tag) => tag.startsWith(CAP_TAG_PREFIX)))].sort(compareIds);
99
+ return claimed.map((tag) => ({
100
+ severity: "error",
101
+ code: "usecase.capability-unresolved",
102
+ subject: view.id,
103
+ message: `${place} is tagged #${tag} inside this service's own project, where no capability can be claimed: ` +
104
+ "a capability is a fleet promise, and only a flow in architecture/usecases/ can keep one; a flow beside " +
105
+ "model.likec4 keeps THIS service's promises (#req-<Requirement-ID>). Drop the tag: the capability's promise " +
106
+ "is kept by the fleet flow that calls this service, and this flow is the hop sequence inside it.",
107
+ }));
108
+ }
109
+ /** Every tag finding one service-local view earns: the placement refusals first, then the requirement claims. */
110
+ export function serviceTagFindings(view, scope, place) {
111
+ return [...capabilityFindings(view, place), ...requirementFindings(view, scope, place)];
112
+ }
113
+ //# sourceMappingURL=tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../../../../../src/commands/validate/service/usecases/tags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,EACL,cAAc,EACd,cAAc,EACd,sBAAsB,EACtB,OAAO,GAER,MAAM,+CAA+C,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAiB9D,0FAA0F;AAC1F,SAAS,QAAQ,CAAC,EAAU;IAC1B,OAAO,GAAG,EAAE,MAAM,cAAc,GAAG,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,SAAS,MAAM,CAAC,KAAsD,EAAE,KAAsB;IAC5F,MAAM,KAAK,GAAG,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC;IAC3D,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,UAAU;YACb,mEAAmE;YACnE,oEAAoE;YACpE,uEAAuE;YACvE,SAAS;YACT,OAAO,yHAAyH,CAAC;QACnI,KAAK,cAAc;YACjB,OAAO,CACL,GAAG,KAAK,CAAC,QAAQ,kFAAkF;gBACnG,wEAAwE,CACzE,CAAC;QACJ,KAAK,OAAO;YACV,OAAO,CACL,GAAG,KAAK,CAAC,OAAO,2FAA2F;gBAC3G,wGAAwG;gBACxG,8BAA8B,CAC/B,CAAC;QACJ,KAAK,MAAM;YACT,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;gBAC3B,CAAC,CAAC,qBAAqB,KAAK,iBAAiB,KAAK,CAAC,IAAI,oBAAoB,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;gBAClH,CAAC,CAAC,qBAAqB,KAAK,iBAAiB,KAAK,CAAC,IAAI,4DAA4D,CAAC;QACxH;YACE,OAAO,CACL,GAAG,KAAK,CAAC,GAAG,CAAC,M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BAA+B;QACrC,OAAO,EAAE,IAAI,CAAC,EAAE;QAChB,OAAO,EACL,GAAG,KAAK,eAAe,GAAG,0EAA0E;YACpG,yGAAyG;YACzG,6GAA6G;YAC7G,iGAAiG;KACpG,CAAC,CAAC,CAAC;AACN,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,kBAAkB,CAAC,IAAgB,EAAE,KAAsB,EAAE,KAAa;IACxF,OAAO,CAAC,GAAG,kBAAkB,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,GAAG,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAC1F,CAAC","sourcesContent":["/**\n * The two tag grades of a SERVICE-LOCAL use case: `usecase.requirement-unresolved`\n * with service-worded arms, and `usecase.capability-unresolved`'s placement arm.\n *\n * Both codes are REUSED from the fleet target rather than minted, under\n * add-error-code's \"prefer existing\" rule: a caller acts the same way (fix the\n * tag, or the `Requirement-ID:` line it names), and only the sentences differ.\n * The fleet's own graders (`../../fleet/usecases/{requirement,capability}-tag.ts`)\n * are not reused for the sentences, because every one of theirs names a\n * capability document, and a service-local flow has none.\n *\n * WHY `#req-` IS SCOPED BY THE SERVICE. Inside `architecture/`, a `#req-` tag\n * means nothing until a `#cap-` tag has said which capability document the\n * `Requirement-ID` is unique inside. Beside a model there is no such question:\n * the directory IS the scope, and the ids are the ones THIS service's `spec.md`\n * and `arch.spec.md` declare — the flow keeps a container-level promise the way\n * a fleet flow keeps a business one. The join is `resolveRequirementTags` with\n * the service as its one-element scope, so the arms fall out mechanically and\n * `unscoped` is unreachable.\n *\n * WHY `#cap-` IS REFUSED, NOT IGNORED AND NOT RESOLVED. A capability is\n * realized by a hop sequence across the fleet map — \"the only join that\n * crosses services\" — and `keptBy` reads the fleet project only. Ignoring the\n * tag would leave `#cap-checkout` on a service flow green and silently unread;\n * resolving it against the vocabulary would make validate see a claim no other\n * surface sees. So it is refused by PLACEMENT, whether or not\n * `architecture/capabilities.yaml` exists: the reason is where the tag sits,\n * not what the vocabulary says. The view stays opted in and its steps are\n * graded — either prefix is the opt-in, exactly as at fleet altitude.\n */\nimport {\n CAP_TAG_PREFIX,\n REQ_TAG_PREFIX,\n resolveRequirementTags,\n tagSlug,\n type RequirementClaim,\n} from \"../../../../core/capabilities/usecase-join.js\";\nimport type { ParsedView } from \"../../../../core/c4/parsed/dynamic-views.js\";\nimport { compareIds } from \"../../../../core/repo/entries.js\";\nimport type { Finding } from \"../../../../core/vocabulary/report.js\";\n\n/** What the tag grades resolve against: the service, and its own identified requirements. */\nexport interface ServiceTagScope {\n service: string;\n /** Repo-relative tree path of the service directory, for the sentences. */\n treePath: string;\n /**\n * Every `Requirement-ID` this service's spec.md (living, REMOVED skipped) and\n * arch.spec.md declare, or `undefined` when NEITHER document exists — the\n * same two answers `requirementsOf` gives one join over: no document at all,\n * against documents declaring no identified promise yet.\n */\n requirementIds: ReadonlySet<string> | undefined;\n}\n\n/** A `Requirement-ID` as an author must write it in a tag: `PAY.AUTH (#req-PAY-AUTH)`. */\nfunction idAndTag(id: string): string {\n return `${id} (#${REQ_TAG_PREFIX}${tagSlug(id)})`;\n}\n\n/**\n * The fix for one unresolved claim, in the service's own vocabulary. The same\n * arms the fleet grade has, each sentence pointing at the document that\n * carries the fix here — spec.md and arch.spec.md, never a capability.\n */\nfunction advice(claim: Exclude<RequirementClaim, { kind: \"resolved\" }>, scope: ServiceTagScope): string {\n const where = `${scope.service} (spec.md or arch.spec.md)`;\n switch (claim.kind) {\n case \"unscoped\":\n // Unreachable: the scope is always exactly one service. A sentence\n // rather than a throw, because this runs inside a validate run over\n // somebody's fleet, and a broken invariant there is one finding, not a\n // crash.\n return \"the flow could not be scoped to this service — report this: a service-local flow is always scoped to its own directory.\";\n case \"undocumented\":\n return (\n `${scope.treePath}/ has no spec.md and no arch.spec.md, so it carries no requirements to satisfy. ` +\n \"Write the requirement first — a flow keeps a promise a document makes.\"\n );\n case \"empty\":\n return (\n `${scope.service}'s spec.md and arch.spec.md declare no \\`Requirement-ID:\\` at all — a #req- tag joins by ` +\n \"stable id, and a requirement without one cannot be named by a flow. Add `Requirement-ID: <id>` to the \" +\n \"requirement this flow keeps.\"\n );\n case \"none\":\n return claim.close.length > 0\n ? `no requirement of ${where} flattens to '${claim.slug}'. Did you mean: ${claim.close.map(idAndTag).join(\", \")}?`\n : `no requirement of ${where} flattens to '${claim.slug}' — check the \\`Requirement-ID:\\` lines in both documents.`;\n default:\n return (\n `${claim.ids.length} requirements of ${scope.service} flatten to '${claim.slug}' (${claim.ids.join(\", \")}) — ` +\n \"a Requirement-ID is unique inside ONE document and this service has two, so nothing in the tag can say \" +\n \"which promise the flow keeps. Rename one of them.\"\n );\n }\n}\n\n/**\n * One finding per `#req-` tag that does not resolve against the service's own\n * ids — never one per view, for the fleet grade's reason: several `#req-` tags\n * on one view are legal and normal, and a broken tag beside a working one must\n * neither swallow the break nor lose the promise the view genuinely keeps.\n */\nfunction requirementFindings(view: ParsedView, scope: ServiceTagScope, place: string): Finding[] {\n const findings: Finding[] = [];\n for (const claim of resolveRequirementTags(view.tags, [scope.service], () => scope.requirementIds)) {\n if (claim.kind === \"resolved\") continue;\n findings.push({\n severity: \"error\",\n code: \"usecase.requirement-unresolved\",\n // The VIEW, not the tag, as at fleet altitude: a subject is what a reader\n // goes and opens, and one broken use case counts once however many of\n // its tags are wrong.\n subject: view.id,\n message: `${place} is tagged #${claim.tag}, and it does not resolve: ${advice(claim, scope)}`,\n });\n }\n return findings;\n}\n\n/**\n * One finding per `#cap-` tag the view carries — the placement refusal. Sorted\n * and de-duplicated for `resolveCapabilityTags`' reason: nothing in loam has\n * measured that LikeC4 preserves the author's tag order, and one breach earns\n * one finding.\n */\nfunction capabilityFindings(view: ParsedView, place: string): Finding[] {\n const claimed = [...new Set(view.tags.filter((tag) => tag.startsWith(CAP_TAG_PREFIX)))].sort(compareIds);\n return claimed.map((tag) => ({\n severity: \"error\",\n code: \"usecase.capability-unresolved\",\n subject: view.id,\n message:\n `${place} is tagged #${tag} inside this service's own project, where no capability can be claimed: ` +\n \"a capability is a fleet promise, and only a flow in architecture/usecases/ can keep one; a flow beside \" +\n \"model.likec4 keeps THIS service's promises (#req-<Requirement-ID>). Drop the tag: the capability's promise \" +\n \"is kept by the fleet flow that calls this service, and this flow is the hop sequence inside it.\",\n }));\n}\n\n/** Every tag finding one service-local view earns: the placement refusals first, then the requirement claims. */\nexport function serviceTagFindings(view: ParsedView, scope: ServiceTagScope, place: string): Finding[] {\n return [...capabilityFindings(view, place), ...requirementFindings(view, scope, place)];\n}\n"]}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * The use-case axis of the SERVICE target: the `dynamic view`s a service's own
3
+ * LikeC4 project declares, graded as the hop sequences behind its requirements.
4
+ *
5
+ * The fleet target grades flows drawn over the map (`../../fleet/usecases/`);
6
+ * this grades flows drawn over ONE service's containers, which only that
7
+ * service's project can resolve — the whole reason the slot exists
8
+ * (`core/usecases/service/flows.ts` carries the report). The step grades are
9
+ * the fleet's own `stepFindings`, reused with the service's project as the
10
+ * model, the enumerated fleet as `services`, and one injection: where a
11
+ * finding says the view is. A second verdict→code mapping here would be the
12
+ * drift that package's banner forbids.
13
+ *
14
+ * ONLY VIEWS CARRYING A RESERVED TAG ARE GRADED, as at fleet altitude and for
15
+ * the same reason: a service's `views.likec4` full of hand-drawn diagrams must
16
+ * not turn red on upgrade. The reader applies the opt-in; this module never
17
+ * sees an untagged view. Graded is narrower than LOADED, and the difference is
18
+ * the reader's gate (`core/usecases/service/flows.ts`): an untagged sibling is
19
+ * not even loaded while no view in the project opts in and no sibling mentions
20
+ * either reserved prefix anywhere in its bytes — but once a view in
21
+ * model.likec4 itself opts in, or a sibling mentions `req-` or `cap-` in a
22
+ * comment or a title, every sibling is staged, and a project that does not
23
+ * read is one `usecase.flow-invalid` whether or not any view in it opted in.
24
+ *
25
+ * A SIBLING THAT BREAKS THE PROJECT is ONE `usecase.flow-invalid` — reused,
26
+ * because its meaning is exactly this ("loam could not read the flows against
27
+ * the map they are drawn over, so it graded none of them, and the renderer
28
+ * refuses the same project") applied to the service project instead of the
29
+ * merge preview — and NEVER `c4.invalid`: that code means "model.likec4 does
30
+ * not parse, every model check is suspended", and here the model parses and
31
+ * every model check RAN. Reusing it would tell an agent to fix the wrong file
32
+ * and tell the brief's `checks[]` row ("every other check stops here") a lie.
33
+ */
34
+ import { existsSync } from "node:fs";
35
+ import { relative } from "node:path";
36
+ import { serviceResolver } from "../../../../core/c4/resolve/service.js";
37
+ import { compareIds } from "../../../../core/repo/entries.js";
38
+ import { errorText } from "../../../../core/c4/likec4.js";
39
+ import { CAP_TAG_PREFIX, REQ_TAG_PREFIX } from "../../../../core/capabilities/usecase-join.js";
40
+ import { stepFindings } from "../../fleet/usecases/steps.js";
41
+ import { serviceTagFindings } from "./tags.js";
42
+ /** `<svc>: services/<tree>/<file> — dynamic view '<id>'` — the service target's spelling of `viewPlace`. */
43
+ function servicePlace(scope, view) {
44
+ // An absent `sourcePath` names the directory rather than guessing a file,
45
+ // for `viewFile`'s reason; nothing at the 1.59.2 pin reaches that arm.
46
+ return `${scope.service}: ${scope.treePath}/${view.sourcePath ?? ""} — dynamic view '${view.id}'`;
47
+ }
48
+ /** The repo-relative spelling of a project error's document, or the whole project when it carries none. */
49
+ function fileOf(scope, error) {
50
+ return error.sourceFsPath === undefined
51
+ ? `${scope.treePath}/`
52
+ : relative(scope.docsDir, error.sourceFsPath).split(/[\\/]/).join("/");
53
+ }
54
+ /**
55
+ * The one finding a broken project earns. `details` is one `errorText` line
56
+ * per error, each prefixed by its file, because the project may hold several
57
+ * siblings and the fault may sit in any of them — including `model.likec4`
58
+ * itself when a sibling re-declares its `specification` block, an error LikeC4
59
+ * blames on both files. `locations` names the first broken file, in the sorted
60
+ * order the reader produced.
61
+ */
62
+ function flowInvalidFinding(scope, errors) {
63
+ const files = [...new Set(errors.map((error) => fileOf(scope, error)))];
64
+ const [first = `${scope.treePath}/`, ...others] = files;
65
+ const named = others.length === 0 ? first : `${first} and ${others.length} more file(s)`;
66
+ return {
67
+ severity: "error",
68
+ code: "usecase.flow-invalid",
69
+ subject: scope.service,
70
+ message: `${scope.service}: ${named} has ${errors.length} error(s) — every .likec4 beside model.likec4 is one LikeC4 ` +
71
+ "project, read the way the renderer reads it, and the renderer refuses the whole project over one broken " +
72
+ "file; no flow in it was graded. model.likec4 itself parses and is graded alone.",
73
+ // The hint first, for `c4.invalid`'s reason (`../model/grade.ts`):
74
+ // `capDetails` keeps ten lines, one broken document can carry more than ten
75
+ // errors, and a diagnosis appended after them is dropped exactly when the
76
+ // reader needs it.
77
+ details: [...tagHint(errors), ...errors.map((error) => `${fileOf(scope, error)}: ${errorText(error)}`)],
78
+ locations: [{ path: first, role: "primary" }],
79
+ };
80
+ }
81
+ /** `Could not resolve reference to Tag named '#req-PAY-AUTH'.` — measured at the 1.59.2 pin. */
82
+ const UNDECLARED_TAG = /reference to Tag named '#?([\w.-]+)'/;
83
+ /**
84
+ * The one line an undeclared RESERVED tag earns.
85
+ *
86
+ * The opt-in is a tag, LikeC4 refuses a tag no `specification` declares, and the
87
+ * refusal is a bare `Could not resolve reference to Tag named …` — so an author
88
+ * following the protocol's "tag the view `#req-<id>`" got a parse error naming
89
+ * the thing they had just been told to write, with nothing saying a tag must be
90
+ * declared first (verification 2026-09-04, D10). One line, from the first such
91
+ * error only: the second one has the same repair.
92
+ */
93
+ function tagHint(errors) {
94
+ for (const error of errors) {
95
+ const match = UNDECLARED_TAG.exec(error.message);
96
+ const name = match?.[1];
97
+ if (name === undefined)
98
+ continue;
99
+ // `cap-` and `req-` do NOT share a repair here, and covering both with one
100
+ // hint sent an author two steps where one would do: declaring `tag cap-…`
101
+ // makes the file parse and the very next run says `usecase.capability-
102
+ // unresolved` — "no capability can be claimed inside this service's own
103
+ // project. Drop the tag." A capability is claimed at fleet altitude, so the
104
+ // tag can never resolve to anything beside a model, whatever is declared
105
+ // (verification 2026-09-04).
106
+ if (name.startsWith(CAP_TAG_PREFIX)) {
107
+ return [
108
+ `\`#${name}\` claims a capability, and a capability is claimed at FLEET altitude only — a flow beside ` +
109
+ "model.likec4 is read in this service's own project, where no capability can be resolved. Declaring " +
110
+ `\`tag ${name}\` makes the file parse and earns \`usecase.capability-unresolved\` on the next run: ` +
111
+ `drop the tag, and tag the flow \`#${REQ_TAG_PREFIX}<Requirement-ID>\` instead, or draw it in ` +
112
+ "`architecture/usecases/` where a capability tag belongs",
113
+ ];
114
+ }
115
+ if (!name.startsWith(REQ_TAG_PREFIX))
116
+ continue;
117
+ return [
118
+ `declare \`tag ${name}\` in the \`specification { }\` block this project reads — model.likec4's own ` +
119
+ "for a model that stands alone, the fleet map's for one that extends it (or a tags-only " +
120
+ "`specification` in a document beside the model)",
121
+ ];
122
+ }
123
+ return [];
124
+ }
125
+ /**
126
+ * The FILE each finding is about, as `locations[0]`.
127
+ *
128
+ * The step and tag grades carry no `locations` of their own, so `findingJson`
129
+ * fell back to the target's scope — `services/<tree>` and nothing else — and an
130
+ * agent reading `--json`, which is the reason the envelope exists, had to parse
131
+ * the prose to learn which `.likec4` to open. `usecase.flow-invalid` on this
132
+ * same arm already names its file; these say the file the same way, with the
133
+ * service directory kept beside it as `scope` (`../spine.ts`'s shape).
134
+ */
135
+ function atView(scope, view, findings) {
136
+ const file = view.sourcePath === undefined ? `${scope.treePath}/` : `${scope.treePath}/${view.sourcePath}`;
137
+ return findings.map((finding) => finding.locations === undefined
138
+ ? {
139
+ ...finding,
140
+ locations: [
141
+ { path: file, role: "primary" },
142
+ { path: scope.treePath, role: "scope" },
143
+ ],
144
+ }
145
+ : finding);
146
+ }
147
+ /**
148
+ * Every use-case finding a service's own project earns.
149
+ *
150
+ * Views are sorted by (file, view id) for the fleet grader's reason: nothing in
151
+ * loam has measured that the parse preserves declaration order, and a report
152
+ * whose row order depends on it would reorder under a dependency bump.
153
+ */
154
+ export function serviceUseCaseFindings(scope) {
155
+ const { scan } = scope;
156
+ if (scan.kind === "none")
157
+ return [];
158
+ if (scan.kind === "unreadable")
159
+ return [flowInvalidFinding(scope, scan.errors)];
160
+ const place = (view) => servicePlace(scope, view);
161
+ const grading = {
162
+ model: scan.model,
163
+ services: scope.services,
164
+ // Built over the PROJECT's elements with the fleet set, exactly as the
165
+ // attribution's own fallback tier resolves — so "which service is this
166
+ // container" cannot be answered one way by `attributeStep` and another by
167
+ // the provider guard.
168
+ resolve: serviceResolver(scan.model.elements, scan.model.known),
169
+ place,
170
+ };
171
+ const findings = [];
172
+ const views = [...scan.views].sort((a, b) => compareIds(a.sourcePath ?? "", b.sourcePath ?? "") || compareIds(a.id, b.id));
173
+ for (const view of views) {
174
+ const forView = [...serviceTagFindings(view, scope, place(view))];
175
+ for (const step of view.steps)
176
+ forView.push(...stepFindings({ view, step }, grading));
177
+ findings.push(...atView(scope, view, forView));
178
+ }
179
+ return findings;
180
+ }
181
+ /**
182
+ * The `Requirement-ID`s a service-local `#req-` tag may name: every identified
183
+ * requirement of spec.md (living — a REMOVED one is on its way out and keeps no
184
+ * promise) and of arch.spec.md, as ONE set. `undefined` when NEITHER document
185
+ * exists, which the tag grade reads as "no requirement to satisfy" rather than
186
+ * "none flattening to this slug" — the same two answers the fleet's
187
+ * `requirementsOf` gives for a capability with no document at all.
188
+ *
189
+ * An id both documents declare resolves once (a set dedupes it); two ids that
190
+ * merely flatten alike — `PAY.AUTH` in one file, `PAY-AUTH` in the other — are
191
+ * the `many` arm, because a Requirement-ID is unique inside one document and a
192
+ * flow beside the model has two.
193
+ *
194
+ * It lives beside the grade it feeds rather than in `../service.ts`, which is
195
+ * the ORDER and nothing else: the set is this axis's input, its two answers are
196
+ * this axis's vocabulary, and the order module had grown past its line limit
197
+ * carrying it.
198
+ */
199
+ export function requirementIdsOf(paths, livingReqs, archReqs) {
200
+ if (!existsSync(paths.spec) && !existsSync(paths.archSpec))
201
+ return undefined;
202
+ const ids = new Set();
203
+ for (const req of [...livingReqs, ...archReqs.filter((r) => r.kind !== "REMOVED")]) {
204
+ if (req.id !== undefined)
205
+ ids.add(req.id);
206
+ }
207
+ return ids;
208
+ }
209
+ //# sourceMappingURL=usecases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usecases.js","sourceRoot":"","sources":["../../../../../src/commands/validate/service/usecases/usecases.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKrC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAG9D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EAAE,YAAY,EAAoB,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAwB,MAAM,WAAW,CAAC;AAerE,4GAA4G;AAC5G,SAAS,YAAY,CAAC,KAA0B,EAAE,IAAgB;IAChE,0EAA0E;IAC1E,uEAAuE;IACvE,OAAO,GAAG,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,IAAI,EAAE,oBAAoB,IAAI,CAAC,EAAE,GAAG,CAAC;AACpG,CAAC;AAED,2GAA2G;AAC3G,SAAS,MAAM,CAAC,KAA0B,EAAE,KAAkB;IAC5D,OAAO,KAAK,CAAC,YAAY,KAAK,SAAS;QACrC,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,GAAG;QACtB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CAAC,KAA0B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AAK;YAAE,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QACtF,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAmB,EACnB,UAAkC,EAClC,QAAgC;IAEhC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7E,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,UAAU,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC;QACnF,IAAI,GAAG,CAAC,EAAE,KAAK,SAAS;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * The use-case axis of the SERVICE target: the `dynamic view`s a service's own\n * LikeC4 project declares, graded as the hop sequences behind its requirements.\n *\n * The fleet target grades flows drawn over the map (`../../fleet/usecases/`);\n * this grades flows drawn over ONE service's containers, which only that\n * service's project can resolve — the whole reason the slot exists\n * (`core/usecases/service/flows.ts` carries the report). The step grades are\n * the fleet's own `stepFindings`, reused with the service's project as the\n * model, the enumerated fleet as `services`, and one injection: where a\n * finding says the view is. A second verdict→code mapping here would be the\n * drift that package's banner forbids.\n *\n * ONLY VIEWS CARRYING A RESERVED TAG ARE GRADED, as at fleet altitude and for\n * the same reason: a service's `views.likec4` full of hand-drawn diagrams must\n * not turn red on upgrade. The reader applies the opt-in; this module never\n * sees an untagged view. Graded is narrower than LOADED, and the difference is\n * the reader's gate (`core/usecases/service/flows.ts`): an untagged sibling is\n * not even loaded while no view in the project opts in and no sibling mentions\n * either reserved prefix anywhere in its bytes — but once a view in\n * model.likec4 itself opts in, or a sibling mentions `req-` or `cap-` in a\n * comment or a title, every sibling is staged, and a project that does not\n * read is one `usecase.flow-invalid` whether or not any view in it opted in.\n *\n * A SIBLING THAT BREAKS THE PROJECT is ONE `usecase.flow-invalid` — reused,\n * because its meaning is exactly this (\"loam could not read the flows against\n * the map they are drawn over, so it graded none of them, and the renderer\n * refuses the same project\") applied to the service project instead of the\n * merge preview — and NEVER `c4.invalid`: that code means \"model.likec4 does\n * not parse, every model check is suspended\", and here the model parses and\n * every model check RAN. Reusing it would tell an agent to fix the wrong file\n * and tell the brief's `checks[]` row (\"every other check stops here\") a lie.\n */\nimport { existsSync } from \"node:fs\";\nimport { relative } from \"node:path\";\nimport type { LikeC4Error } from \"../../../../core/c4/likec4.js\";\nimport type { Requirement } from \"../../../../core/document/spec.js\";\nimport type { ServicePaths } from \"../../../../core/repo/paths.js\";\nimport type { ParsedView } from \"../../../../core/c4/parsed/dynamic-views.js\";\nimport { serviceResolver } from \"../../../../core/c4/resolve/service.js\";\nimport type { DocsDir } from \"../../../../core/kernel/ids/dirs.js\";\nimport { compareIds } from \"../../../../core/repo/entries.js\";\nimport type { ServiceFlowScan } from \"../../../../core/usecases/service/flows.js\";\nimport type { Finding } from \"../../../../core/vocabulary/report.js\";\nimport { errorText } from \"../../../../core/c4/likec4.js\";\nimport { CAP_TAG_PREFIX, REQ_TAG_PREFIX } from \"../../../../core/capabilities/usecase-join.js\";\nimport { stepFindings, type StepGrading } from \"../../fleet/usecases/steps.js\";\nimport { serviceTagFindings, type ServiceTagScope } from \"./tags.js\";\n\n/** What the service's use-case grades run over. */\nexport interface ServiceUseCaseScope extends ServiceTagScope {\n /** The docs root, so a project error's absolute path can be spelled repo-relative. */\n docsDir: DocsDir;\n scan: ServiceFlowScan;\n /**\n * The `services/<id>/` directories that exist — the SAME enumerated set the\n * fleet target hands `stepFindings`, never an empty one: `StepGrading`\n * documents why the intra-service exemption is a guard and not a scope.\n */\n services: ReadonlySet<string>;\n}\n\n/** `<svc>: services/<tree>/<file> — dynamic view '<id>'` — the service target's spelling of `viewPlace`. */\nfunction servicePlace(scope: ServiceUseCaseScope, view: ParsedView): string {\n // An absent `sourcePath` names the directory rather than guessing a file,\n // for `viewFile`'s reason; nothing at the 1.59.2 pin reaches that arm.\n return `${scope.service}: ${scope.treePath}/${view.sourcePath ?? \"\"} — dynamic view '${view.id}'`;\n}\n\n/** The repo-relative spelling of a project error's document, or the whole project when it carries none. */\nfunction fileOf(scope: ServiceUseCaseScope, error: LikeC4Error): string {\n return error.sourceFsPath === undefined\n ? `${scope.treePath}/`\n : relative(scope.docsDir, error.sourceFsPath).split(/[\\\\/]/).join(\"/\");\n}\n\n/**\n * The one finding a broken project earns. `details` is one `errorText` line\n * per error, each prefixed by its file, because the project may hold several\n * siblings and the fault may sit in any of them — including `model.likec4`\n * itself when a sibling re-declares its `specification` block, an error LikeC4\n * blames on both files. `locations` names the first broken file, in the sorted\n * order the reader produced.\n */\nfunction flowInvalidFinding(scope: ServiceUseCaseScope, errors: readonly LikeC4Error[]): Finding {\n const files = [...new Set(errors.map((error) => fileOf(scope, error)))];\n const [first = `${scope.treePath}/`, ...others] = files;\n const named = others.length === 0 ? first : `${first} and ${others.length} more file(s)`;\n return {\n severity: \"error\",\n code: \"usecase.flow-invalid\",\n subject: scope.service,\n message:\n `${scope.service}: ${named} has ${errors.length} error(s) — every .likec4 beside model.likec4 is one LikeC4 ` +\n \"project, read the way the renderer reads it, and the renderer refuses the whole project over one broken \" +\n \"file; no flow in it was graded. model.likec4 itself parses and is graded alone.\",\n // The hint first, for `c4.invalid`'s reason (`../model/grade.ts`):\n // `capDetails` keeps ten lines, one broken document can carry more than ten\n // errors, and a diagnosis appended after them is dropped exactly when the\n // reader needs it.\n details: [...tagHint(errors), ...errors.map((error) => `${fileOf(scope, error)}: ${errorText(error)}`)],\n locations: [{ path: first, role: \"primary\" }],\n };\n}\n\n/** `Could not resolve reference to Tag named '#req-PAY-AUTH'.` — measured at the 1.59.2 pin. */\nconst UNDECLARED_TAG = /reference to Tag named '#?([\\w.-]+)'/;\n\n/**\n * The one line an undeclared RESERVED tag earns.\n *\n * The opt-in is a tag, LikeC4 refuses a tag no `specification` declares, and the\n * refusal is a bare `Could not resolve reference to Tag named …` — so an author\n * following the protocol's \"tag the view `#req-<id>`\" got a parse error naming\n * the thing they had just been told to write, with nothing saying a tag must be\n * declared first (verification 2026-09-04, D10). One line, from the first such\n * error only: the second one has the same repair.\n */\nfunction tagHint(errors: readonly LikeC4Error[]): string[] {\n for (const error of errors) {\n const match = UNDECLARED_TAG.exec(error.message);\n const name = match?.[1];\n if (name === undefined) continue;\n // `cap-` and `req-` do NOT share a repair here, and covering both with one\n // hint sent an author two steps where one would do: declaring `tag cap-…`\n // makes the file parse and the very next run says `usecase.capability-\n // unresolved` — \"no capability can be claimed inside this service's own\n // project. Drop the tag.\" A capability is claimed at fleet altitude, so the\n // tag can never resolve to anything beside a model, whatever is declared\n // (verification 2026-09-04).\n if (name.startsWith(CAP_TAG_PREFIX)) {\n return [\n `\\`#${name}\\` claims a capability, and a capability is claimed at FLEET altitude only — a flow beside ` +\n \"model.likec4 is read in this service's own project, where no capability can be resolved. Declaring \" +\n `\\`tag ${name}\\` makes the file parse and earns \\`usecase.capability-unresolved\\` on the next run: ` +\n `drop the tag, and tag the flow \\`#${REQ_TAG_PREFIX}<Requirement-ID>\\` instead, or draw it in ` +\n \"`architecture/usecases/` where a capability tag belongs\",\n ];\n }\n if (!name.startsWith(REQ_TAG_PREFIX)) continue;\n return [\n `declare \\`tag ${name}\\` in the \\`specification { }\\` block this project reads — model.likec4's own ` +\n \"for a model that stands alone, the fleet map's for one that extends it (or a tags-only \" +\n \"`specification` in a document beside the model)\",\n ];\n }\n return [];\n}\n\n/**\n * The FILE each finding is about, as `locations[0]`.\n *\n * The step and tag grades carry no `locations` of their own, so `findingJson`\n * fell back to the target's scope — `services/<tree>` and nothing else — and an\n * agent reading `--json`, which is the reason the envelope exists, had to parse\n * the prose to learn which `.likec4` to open. `usecase.flow-invalid` on this\n * same arm already names its file; these say the file the same way, with the\n * service directory kept beside it as `scope` (`../spine.ts`'s shape).\n */\nfunction atView(scope: ServiceUseCaseScope, view: ParsedView, findings: Finding[]): Finding[] {\n const file = view.sourcePath === undefined ? `${scope.treePath}/` : `${scope.treePath}/${view.sourcePath}`;\n return findings.map((finding) =>\n finding.locations === undefined\n ? {\n ...finding,\n locations: [\n { path: file, role: \"primary\" as const },\n { path: scope.treePath, role: \"scope\" as const },\n ],\n }\n : finding,\n );\n}\n\n/**\n * Every use-case finding a service's own project earns.\n *\n * Views are sorted by (file, view id) for the fleet grader's reason: nothing in\n * loam has measured that the parse preserves declaration order, and a report\n * whose row order depends on it would reorder under a dependency bump.\n */\nexport function serviceUseCaseFindings(scope: ServiceUseCaseScope): Finding[] {\n const { scan } = scope;\n if (scan.kind === \"none\") return [];\n if (scan.kind === \"unreadable\") return [flowInvalidFinding(scope, scan.errors)];\n\n const place = (view: ParsedView): string => servicePlace(scope, view);\n const grading: StepGrading = {\n model: scan.model,\n services: scope.services,\n // Built over the PROJECT's elements with the fleet set, exactly as the\n // attribution's own fallback tier resolves — so \"which service is this\n // container\" cannot be answered one way by `attributeStep` and another by\n // the provider guard.\n resolve: serviceResolver(scan.model.elements, scan.model.known),\n place,\n };\n const findings: Finding[] = [];\n const views = [...scan.views].sort(\n (a, b) => compareIds(a.sourcePath ?? \"\", b.sourcePath ?? \"\") || compareIds(a.id, b.id),\n );\n for (const view of views) {\n const forView: Finding[] = [...serviceTagFindings(view, scope, place(view))];\n for (const step of view.steps) forView.push(...stepFindings({ view, step }, grading));\n findings.push(...atView(scope, view, forView));\n }\n return findings;\n}\n\n/**\n * The `Requirement-ID`s a service-local `#req-` tag may name: every identified\n * requirement of spec.md (living — a REMOVED one is on its way out and keeps no\n * promise) and of arch.spec.md, as ONE set. `undefined` when NEITHER document\n * exists, which the tag grade reads as \"no requirement to satisfy\" rather than\n * \"none flattening to this slug\" — the same two answers the fleet's\n * `requirementsOf` gives for a capability with no document at all.\n *\n * An id both documents declare resolves once (a set dedupes it); two ids that\n * merely flatten alike — `PAY.AUTH` in one file, `PAY-AUTH` in the other — are\n * the `many` arm, because a Requirement-ID is unique inside one document and a\n * flow beside the model has two.\n *\n * It lives beside the grade it feeds rather than in `../service.ts`, which is\n * the ORDER and nothing else: the set is this axis's input, its two answers are\n * this axis's vocabulary, and the order module had grown past its line limit\n * carrying it.\n */\nexport function requirementIdsOf(\n paths: ServicePaths,\n livingReqs: readonly Requirement[],\n archReqs: readonly Requirement[],\n): ReadonlySet<string> | undefined {\n if (!existsSync(paths.spec) && !existsSync(paths.archSpec)) return undefined;\n const ids = new Set<string>();\n for (const req of [...livingReqs, ...archReqs.filter((r) => r.kind !== \"REMOVED\")]) {\n if (req.id !== undefined) ids.add(req.id);\n }\n return ids;\n}\n"]}
@@ -6,7 +6,7 @@ import { resolveServiceTarget } from "../../core/repo/service-target.js";
6
6
  import { loadConfig } from "../../core/envelope/config.js";
7
7
  import { emitJson, fail, NO_SERVICE_MESSAGE, reportNoConfig } from "../../core/envelope/json.js";
8
8
  import { DocsRepoUnavailableError } from "../../core/repo/state.js";
9
- import { agentsPath as agentsFile, featurePaths, landscapePath as landscapeFile, servicePathsAt } from "../../core/repo/paths.js";
9
+ import { agentsPath as agentsFile, landscapePath as landscapeFile } from "../../core/repo/paths.js";
10
10
  import { listFeatures, listServices, missingFeatureMessage, resolveFeature } from "../../core/repo/repo.js";
11
11
  import { countSeverity, reportValid, targetJson, targetValid, } from "../../core/vocabulary/report.js";
12
12
  import { LOAM_VERSION } from "../../core/envelope/version.js";
@@ -16,8 +16,7 @@ import { docsRepoReady, reportDocsRepoError, reportRepositoryUnavailable, } from
16
16
  import { interruptedCommitFinding } from "../../core/staging/recovery/finding.js";
17
17
  import { scopeJson, scopeLine, scopeSince } from "../../core/diff/scope/changed-paths.js";
18
18
  import { validateLandscape } from "./fleet/landscape.js";
19
- import { loadArchitecture } from "../../core/c4/project/architecture.js";
20
- import { readLandscape } from "./fleet/load.js";
19
+ import { prefetchFleetDocuments, readLandscape } from "./fleet/load.js";
21
20
  import { buildScorecard } from "./fleet/scorecard/scorecard.js";
22
21
  import { printScorecard } from "./fleet/scorecard/print.js";
23
22
  import { validateFeature } from "./feature.js";
@@ -91,20 +90,9 @@ export function registerValidate(program) {
91
90
  let scope = null;
92
91
  try {
93
92
  if (opts.all) {
94
- // ONE LikeC4 workspace for the whole run. The per-path load pays a
95
- // fresh Langium workspace per document (~100ms each even warm), which
96
- // made the fleet's main CI command O(documents) workspace spins —
97
- // 13.7s median over the 120-service benchmark (docs/BENCHMARKS.md).
98
- // So --all enumerates its documents up front — the landscape, every
99
- // service model, every active feature's delta — and batch-parses
100
- // them into the fleet context's memo; every loadLikeC4 below, the
101
- // landscape read included, is then a seeded hit. The enumerations are
102
- // the same memoized promises the target loops reuse. If the batch
103
- // CANNOT run (a sandbox denying tmpdir writes), prefetch seeds
104
- // nothing and every load falls back to today's per-path parse:
105
- // identical findings, the old speed. Single-service validate and
106
- // list keep their untouched code paths on purpose — the ≤10%
107
- // regression bound in docs/BENCHMARKS.md holds by construction.
93
+ // ONE workspace per document kind for the whole run — the block moved
94
+ // to `fleet/load.ts` (`prefetchFleetDocuments`), which is where the
95
+ // rule about which shape parses in which workspace belongs.
108
96
  const lp = landscapeFile(docsDir);
109
97
  const enumerated = await listServices(docsDir, fleet);
110
98
  const active = await listFeatures(docsDir, {}, fleet);
@@ -123,15 +111,13 @@ export function registerValidate(program) {
123
111
  }
124
112
  const services = scope === null ? enumerated : scope.services;
125
113
  const features = scope === null ? active : scope.features;
126
- await fleet.prefetchLikeC4([
127
- ...(existsSync(lp) ? [lp] : []),
128
- ...services.filter((svc) => svc.has.model).map((svc) => servicePathsAt(svc.dir).model),
129
- ...features.filter((feat) => feat.has.delta).map((feat) => featurePaths(feat.dir).delta),
130
- ]);
114
+ await prefetchFleetDocuments({ docsDir, fleet, services, features });
131
115
  // Read whether or not the landscape is a TARGET: every service check
132
116
  // below joins against it, so a scoped run needs the map in hand even
133
- // when it does not grade the map itself.
134
- const land = existsSync(lp) ? await readLandscape(() => loadArchitecture(docsDir)) : null;
117
+ // when it does not grade the map itself. Through the fleet index, so
118
+ // the single-service path — which now reads the same project — answers
119
+ // out of the same memo rather than parsing it a second time.
120
+ const land = existsSync(lp) ? await readLandscape(() => fleet.architecture(docsDir)) : null;
135
121
  // The fleet-level cross-check first: it frames everything below it, and a
136
122
  // service nobody drew is worth knowing before its own findings scroll past.
137
123
  // Under `--base` it is a target only when `architecture/` changed — the