@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
@@ -1 +1 @@
1
- {"version":3,"file":"refusals.js","sourceRoot":"","sources":["../../../src/core/explain/refusals.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,WAAW,EACT,gMAAgM;IAClM,gBAAgB,EACd,4MAA4M;IAC9M,gBAAgB,EACd,oJAAoJ;IACtJ,gBAAgB,EACd,qQAAqQ;IACvQ,gBAAgB,EACd,iNAAiN;IACnN,gBAAgB,EACd,4KAA4K;IAC9K,sBAAsB,EACpB,8LAA8L;IAChM,cAAc,EACZ,oOAAoO;IACtO,6BAA6B,EAC3B,yQAAyQ;IAC3Q,gBAAgB,EACd,gLAAgL;IAClL,cAAc,EACZ,yJAAyJ;IAC3J,qBAAqB,EACnB,qLAAqL;IACvL,gBAAgB,EACd,yLAAyL;IAC3L,kBAAkB,EAChB,oMAAoM;IACtM,gBAAgB,EACd,gMAAgM;IAClM,kBAAkB,EAChB,2NAA2N;IAC7N,oBAAoB,EAClB,sRAAsR;IACxR,gBAAgB,EACd,wIAAwI;IAC1I,oBAAoB,EAClB,wMAAwM;IAC1M,kBAAkB,EAChB,gNAAgN;IAClN,qBAAqB,EACnB,uLAAuL;IACzL,kBAAkB,EAChB,6XAA6X;IAC/X,iBAAiB,EACf,gLAAgL;IAClL,wBAAwB,EACtB,+VAA+V;IACjW,kBAAkB,EAChB,uNAAuN;IACzN,mBAAmB,EACjB,4KAA4K;IAC9K,cAAc,EACZ,uNAAuN;IACzN,kBAAkB,EAChB,mMAAmM;IACrM,aAAa,EACX,uJAAuJ;IACzJ,kBAAkB,EAChB,oJAAoJ;IACtJ,sBAAsB,EACpB,6LAA6L;IAC/L,gBAAgB,EACd,uGAAuG;IACzG,cAAc,EACZ,0MAA0M;IAC5M,kBAAkB,EAChB,wNAAwN;IAC1N,WAAW,EACT,wMAAwM;IAC1M,qBAAqB,EACnB,sOAAsO;IACxO,kBAAkB,EAChB,kOAAkO;IACpO,aAAa,EACX,+JAA+J;IACjK,YAAY,EACV,sNAAsN;IACxN,mBAAmB,EACjB,4NAA4N;IAC9N,mBAAmB,EACjB,oQAAoQ;IACtQ,mBAAmB,EACjB,oSAAoS;IACtS,wBAAwB,EACtB,yOAAyO;IAC3O,wBAAwB,EACtB,+MAA+M;IACjN,uBAAuB,EACrB,mSAAmS;IACrS,QAAQ,EACN,mNAAmN;CACzK,CAAC","sourcesContent":["/**\n * One sentence per envelope refusal code, for `loam explain`.\n *\n * This is the one deliberate restatement in the explain lookup, and the\n * compiler is its drift test: unlike the finding codes — whose prose ships in\n * the /loam-check fix tables and is PARSED at runtime (fix-tables.ts) — the\n * `ErrorCode` union's meanings live only in doc comments, which are erased,\n * so there is no runtime constant to read. `satisfies Record<ErrorCode,\n * string>` makes the pairing exhaustive both ways: a new union member cannot\n * ship without a row here (missing key fails typecheck), and a row for a\n * retired code fails the same way. What tsc cannot pin is accuracy — a\n * reworded doc comment can drift from its sentence — which is why each row\n * stays ONE sentence in the union's own voice (what happened, what it means,\n * whether re-running can work) rather than growing a paragraph of its own.\n */\nimport type { ErrorCode } from \"../envelope/json.js\";\n\nexport const REFUSAL_MEANINGS = {\n \"no-config\":\n \"No loam.json at or above the working directory — the repo is not wired to a fleet; run `loam init --docs <dir>` once per repository rather than letting a command guess where the fleet lives.\",\n \"config-invalid\":\n \"loam.json exists but cannot be loaded — repair the file (or delete it and re-run `loam init`); the code is distinct from `no-config` because running init over a corrupt config would silently rewrite it.\",\n \"unknown-target\":\n \"The name resolves to nothing this command can address — no such service, feature, workflow or subject; the message offers the closest known names.\",\n \"invalid-option\":\n \"The invocation itself is wrong — flags that contradict each other, a value that cannot be right, or a mistyped flag or command; nothing was read or written, and with `--json` anywhere in the arguments even commander's own usage errors arrive as this envelope.\",\n \"already-exists\":\n \"Refusing to create over something that already exists — a feature directory, a workspace file, a name already claimed in the subsystem namespace — because overwriting would destroy work nobody asked to lose.\",\n \"sources-absent\":\n \"`loam vouch` refuses to stamp a document that names no `sources` — with nothing tying the document to code, the staleness signal a vouch exists to power could never fire.\",\n \"sources-path-missing\":\n \"`loam vouch` refuses to stamp: a listed source does not exist in the service repo, or is a glob pattern (not supported) — the digest would cover a different file set than the author meant.\",\n \"not-coherent\":\n \"`loam archive` refuses: the feature has coherence issues, carried in `issues[]` with a per-issue `overridable` — fix the gating ones, or `--approve` the judgment calls; a refusal `--approve` cannot move says so in the message.\",\n \"living-outside-requirements\":\n \"`loam archive` refuses: the LIVING spec holds a requirement outside its `## Requirements` section, and the merge rewrites only that section, so the requirement would land in the file twice — the fix is in the living document, and `--approve` does not override it.\",\n \"archive-exists\":\n \"`loam archive` refuses: `features/archive/` already holds a directory for this feature — a destination collision, not a merge problem; move the old archive entry aside first.\",\n \"merge-failed\":\n \"The merge — or a journaled writer's one-file commit — could not be computed or was rolled back; the living docs are unchanged, and re-running can work.\",\n \"rollback-incomplete\":\n \"A failed write could not be fully undone: some files were not put back, and the message lists them — the one refusal that needs a human before anything else runs against the repo.\",\n \"feature-active\":\n \"`loam unarchive` refuses: a `features/` directory for this feature already exists outside the archive, so restoring would write over work in flight — remove or rename it, then re-run.\",\n \"snapshot-missing\":\n \"`loam unarchive` refuses: the archive carries no snapshot of what it overwrote (it predates snapshots, or was written by a different loam) — restore the living docs from version control instead.\",\n \"snapshot-stale\":\n \"`loam unarchive` refuses: the living docs changed after the archive, so restoring is no longer an undo — re-run with `--force` to restore anyway, deliberately discarding those later changes.\",\n \"snapshot-corrupt\":\n \"`loam unarchive` refuses: a snapshot pre-image no longer matches the digest the archive recorded for it, so restoring would write text nobody wrote — `--force` does not override this one; restore from version control.\",\n \"commit-interrupted\":\n \"A journaled writer (archive, unarchive, rebase, vouch, new, gherkin, a recording verify) was killed mid-commit and this run cannot repair the leftovers on its own — the docs may be half-written; run the command the message names, or `loam doctor` for the file-by-file account.\",\n \"restore-failed\":\n \"`loam unarchive` failed and everything was rolled back — nothing was restored, the living docs are unchanged, and re-running can work.\",\n \"answers-unreadable\":\n \"A recording `loam verify` could not read a user-named file — the answers JSON, or a cucumber/contract report — as what it claims to be; fail-closed: nothing was recorded, so fix the file and re-run.\",\n \"answers-mismatch\":\n \"The answer set does not answer the current checklist — an id not on it, a claim with no answer, or an entry for a claim a passed report already owns; re-derive the checklist and answer exactly what it asks.\",\n \"answers-unevidenced\":\n \"A `confirmed` answer carries no evidence — evidence is `file:line`, and a claim you cannot show is `unconfirmed` with a note saying why, which is a successful record, not a failure.\",\n \"service-mismatch\":\n \"A command that must run inside one service's own repository was told `--service` for a service this repository's loam.json does not declare: a recording `loam verify`, whose attestation must be bound to the code it is about; `loam gherkin`, whose .feature files land in that service's checkout; or `loam vouch`, whose `sources` resolve there. Run it from that service's own repo.\",\n \"unknown-service\":\n \"Federated verify recording: the selected service is not one this feature's checklist (or the docs repo) knows, so there is nothing its attestation could bind to — fix the id.\",\n \"repository-unavailable\":\n \"The repository this operation must be bound to (or read from) cannot be answered for — most commonly a writing `loam verify`, a `loam gherkin` or a `loam vouch` run where loam.json declares no `service` at all (the docs repo, usually), or a docs repo that cannot be enumerated — so the command refuses rather than guessing which service it is about.\",\n \"record-federated\":\n \"`loam verify --record` without `--service` over a federated (schema 2) record — the all-at-once form would erase other repositories' attestations, so it is refused naming the attestors; record per service instead.\",\n \"record-unreadable\":\n \"A verification.yaml exists but cannot be read as a record — it is never overwritten and never reported as absent; repair it by hand, or re-record from the service's repo.\",\n \"record-raced\":\n \"`loam verify --record` found the record changed between its locked read and the swap — an editor or a lock-ignoring writer landed first; nothing was written, and re-running merges over the record as it now stands.\",\n \"gherkin-conflict\":\n \"`loam gherkin <FEAT>` would overwrite a `.feature` file owned by another feature still in flight — the whole emission refuses and names the owner; archive or coordinate with that feature first.\",\n \"vouch-raced\":\n \"`loam vouch` found the spec changed between reading and stamping — another vouch or an edit landed first; nothing was written, so re-read and re-run.\",\n \"vouch-unattended\":\n \"`loam vouch` with nobody on the other end of stdin and no `--yes` — the stamp is a person's claim to have read the document, and nobody was asked.\",\n \"vouch-unattributable\":\n \"`loam vouch` could not learn who is vouching — git names no `user.email` here — and a stamp with nobody behind it records only that the word was written; set your git identity and re-run.\",\n \"vouch-declined\":\n \"`loam vouch` asked and the person said no — nothing was stamped; a successful refusal, not a failure.\",\n \"docs-missing\":\n \"`docsDir` in loam.json points at nothing — the docs repo was never cloned, or the path is wrong; a read command refuses rather than reporting an empty fleet, and `loam doctor` names the wiring to fix.\",\n \"services-missing\":\n \"`docsDir` is a directory but holds no `services/` — it is some other directory, most often the service repo itself after a typo; fix the pointer rather than scaffolding a second source of truth beside the real one.\",\n \"docs-busy\":\n \"Another loam writer holds the docs repo's advisory lock — nothing was read or written, and re-running once it finishes works; a lock nothing will ever release shows up in `loam doctor` as a blocker.\",\n \"subsystem-not-empty\":\n \"`loam subsystem` rm refuses a subsystem that still holds members — services or child subsystems, named in the message — because a destructive command never picks targets the caller did not name; move them out first, then re-run.\",\n \"move-uncommitted\":\n \"A subsystem move/rename refuses because git reports uncommitted or untracked paths under a directory being moved — the rename would sweep them into a move nobody reviewed; commit, `git stash -u`, or remove them, then re-run.\",\n \"move-failed\":\n \"A subsystem move/rename failed and was rolled back cleanly — every rename undone, the generated views file restored, the docs unchanged; re-running can work.\",\n \"no-members\":\n \"`loam open` found no service checkout bound to this docs repo under any scanned root — the workspace would hold only the docs repo; clone a bound checkout beside it, or point `--root` at where the checkouts live.\",\n \"binding-duplicate\":\n \"Two discovered repositories' committed loam.json files declare the same `service` for this docs repo — loam will not guess which checkout speaks for the service; narrow the scan with `--root`, or fix the stray binding.\",\n \"owners-unreadable\":\n \"`loam list --owners` could not use the named CODEOWNERS file — the path cannot be read, or a line does not parse as `pattern owner…` (the message names the line); fail-closed, because a half-read ownership file must never file a service under the wrong team.\",\n \"seed-file-invalid\":\n \"`loam seed`'s fleet file is missing, unreadable, not YAML, the wrong shape, carries an illegal id — or no longer names every existing `services/<id>/` (that refusal lists the exact ids as `missingServices`); the message names the file and line, and editing the file and re-running succeeds.\",\n \"seed-duplicate-service\":\n \"fleet.yaml declares one name twice — as two services, or as both a service and an external/subsystem; service ids, subsystem names and externals share one flat namespace, both declaration lines are named, and renaming one fixes it.\",\n \"seed-unknown-subsystem\":\n \"A service's `subsystem:` in fleet.yaml names nothing `subsystems:` declares — the message carries a did-you-mean over the names the file really declares; add the subsystem or fix the spelling, then re-run.\",\n \"seed-landscape-edited\":\n \"architecture/landscape.likec4 carries hand edits (the line-1 stamp's digest no longer matches) or was authored some other way — `loam seed` never overwrites human work and wrote nothing; fold the edits into fleet.yaml and delete the file, or keep the hand-authored map and stop using seed.\",\n internal:\n \"An unexpected throw — the one refusal with no stable meaning; it exists so a `--json` consumer still receives an envelope instead of a stack trace, and a repeatable `internal` is a loam defect worth reporting.\",\n} as const satisfies Record<ErrorCode, string>;\n"]}
1
+ {"version":3,"file":"refusals.js","sourceRoot":"","sources":["../../../src/core/explain/refusals.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,WAAW,EACT,gMAAgM;IAClM,gBAAgB,EACd,4MAA4M;IAC9M,gBAAgB,EACd,oJAAoJ;IACtJ,gBAAgB,EACd,qQAAqQ;IACvQ,gBAAgB,EACd,iNAAiN;IACnN,gBAAgB,EACd,4KAA4K;IAC9K,sBAAsB,EACpB,8LAA8L;IAChM,cAAc,EACZ,oOAAoO;IACtO,6BAA6B,EAC3B,yQAAyQ;IAC3Q,gBAAgB,EACd,gLAAgL;IAClL,cAAc,EACZ,yJAAyJ;IAC3J,qBAAqB,EACnB,qLAAqL;IACvL,gBAAgB,EACd,yLAAyL;IAC3L,kBAAkB,EAChB,oMAAoM;IACtM,gBAAgB,EACd,gMAAgM;IAClM,kBAAkB,EAChB,2NAA2N;IAC7N,oBAAoB,EAClB,sRAAsR;IACxR,gBAAgB,EACd,wIAAwI;IAC1I,oBAAoB,EAClB,wMAAwM;IAC1M,kBAAkB,EAChB,gNAAgN;IAClN,qBAAqB,EACnB,uLAAuL;IACzL,kBAAkB,EAChB,6XAA6X;IAC/X,iBAAiB,EACf,gLAAgL;IAClL,wBAAwB,EACtB,+VAA+V;IACjW,kBAAkB,EAChB,uNAAuN;IACzN,mBAAmB,EACjB,4KAA4K;IAC9K,cAAc,EACZ,uNAAuN;IACzN,kBAAkB,EAChB,mMAAmM;IACrM,aAAa,EACX,uJAAuJ;IACzJ,kBAAkB,EAChB,oJAAoJ;IACtJ,sBAAsB,EACpB,6LAA6L;IAC/L,gBAAgB,EACd,uGAAuG;IACzG,cAAc,EACZ,0MAA0M;IAC5M,kBAAkB,EAChB,wNAAwN;IAC1N,WAAW,EACT,wMAAwM;IAC1M,qBAAqB,EACnB,sOAAsO;IACxO,kBAAkB,EAChB,kOAAkO;IACpO,aAAa,EACX,+JAA+J;IACjK,YAAY,EACV,sNAAsN;IACxN,mBAAmB,EACjB,4NAA4N;IAC9N,mBAAmB,EACjB,oQAAoQ;IACtQ,mBAAmB,EACjB,oSAAoS;IACtS,wBAAwB,EACtB,yOAAyO;IAC3O,wBAAwB,EACtB,+MAA+M;IACjN,uBAAuB,EACrB,8VAA8V;IAChW,QAAQ,EACN,mNAAmN;CACzK,CAAC","sourcesContent":["/**\n * One sentence per envelope refusal code, for `loam explain`.\n *\n * This is the one deliberate restatement in the explain lookup, and the\n * compiler is its drift test: unlike the finding codes — whose prose ships in\n * the /loam-check fix tables and is PARSED at runtime (fix-tables.ts) — the\n * `ErrorCode` union's meanings live only in doc comments, which are erased,\n * so there is no runtime constant to read. `satisfies Record<ErrorCode,\n * string>` makes the pairing exhaustive both ways: a new union member cannot\n * ship without a row here (missing key fails typecheck), and a row for a\n * retired code fails the same way. What tsc cannot pin is accuracy — a\n * reworded doc comment can drift from its sentence — which is why each row\n * stays ONE sentence in the union's own voice (what happened, what it means,\n * whether re-running can work) rather than growing a paragraph of its own.\n */\nimport type { ErrorCode } from \"../envelope/json.js\";\n\nexport const REFUSAL_MEANINGS = {\n \"no-config\":\n \"No loam.json at or above the working directory — the repo is not wired to a fleet; run `loam init --docs <dir>` once per repository rather than letting a command guess where the fleet lives.\",\n \"config-invalid\":\n \"loam.json exists but cannot be loaded — repair the file (or delete it and re-run `loam init`); the code is distinct from `no-config` because running init over a corrupt config would silently rewrite it.\",\n \"unknown-target\":\n \"The name resolves to nothing this command can address — no such service, feature, workflow or subject; the message offers the closest known names.\",\n \"invalid-option\":\n \"The invocation itself is wrong — flags that contradict each other, a value that cannot be right, or a mistyped flag or command; nothing was read or written, and with `--json` anywhere in the arguments even commander's own usage errors arrive as this envelope.\",\n \"already-exists\":\n \"Refusing to create over something that already exists — a feature directory, a workspace file, a name already claimed in the subsystem namespace — because overwriting would destroy work nobody asked to lose.\",\n \"sources-absent\":\n \"`loam vouch` refuses to stamp a document that names no `sources` — with nothing tying the document to code, the staleness signal a vouch exists to power could never fire.\",\n \"sources-path-missing\":\n \"`loam vouch` refuses to stamp: a listed source does not exist in the service repo, or is a glob pattern (not supported) — the digest would cover a different file set than the author meant.\",\n \"not-coherent\":\n \"`loam archive` refuses: the feature has coherence issues, carried in `issues[]` with a per-issue `overridable` — fix the gating ones, or `--approve` the judgment calls; a refusal `--approve` cannot move says so in the message.\",\n \"living-outside-requirements\":\n \"`loam archive` refuses: the LIVING spec holds a requirement outside its `## Requirements` section, and the merge rewrites only that section, so the requirement would land in the file twice — the fix is in the living document, and `--approve` does not override it.\",\n \"archive-exists\":\n \"`loam archive` refuses: `features/archive/` already holds a directory for this feature — a destination collision, not a merge problem; move the old archive entry aside first.\",\n \"merge-failed\":\n \"The merge — or a journaled writer's one-file commit — could not be computed or was rolled back; the living docs are unchanged, and re-running can work.\",\n \"rollback-incomplete\":\n \"A failed write could not be fully undone: some files were not put back, and the message lists them — the one refusal that needs a human before anything else runs against the repo.\",\n \"feature-active\":\n \"`loam unarchive` refuses: a `features/` directory for this feature already exists outside the archive, so restoring would write over work in flight — remove or rename it, then re-run.\",\n \"snapshot-missing\":\n \"`loam unarchive` refuses: the archive carries no snapshot of what it overwrote (it predates snapshots, or was written by a different loam) — restore the living docs from version control instead.\",\n \"snapshot-stale\":\n \"`loam unarchive` refuses: the living docs changed after the archive, so restoring is no longer an undo — re-run with `--force` to restore anyway, deliberately discarding those later changes.\",\n \"snapshot-corrupt\":\n \"`loam unarchive` refuses: a snapshot pre-image no longer matches the digest the archive recorded for it, so restoring would write text nobody wrote — `--force` does not override this one; restore from version control.\",\n \"commit-interrupted\":\n \"A journaled writer (archive, unarchive, rebase, vouch, new, gherkin, a recording verify) was killed mid-commit and this run cannot repair the leftovers on its own — the docs may be half-written; run the command the message names, or `loam doctor` for the file-by-file account.\",\n \"restore-failed\":\n \"`loam unarchive` failed and everything was rolled back — nothing was restored, the living docs are unchanged, and re-running can work.\",\n \"answers-unreadable\":\n \"A recording `loam verify` could not read a user-named file — the answers JSON, or a cucumber/contract report — as what it claims to be; fail-closed: nothing was recorded, so fix the file and re-run.\",\n \"answers-mismatch\":\n \"The answer set does not answer the current checklist — an id not on it, a claim with no answer, or an entry for a claim a passed report already owns; re-derive the checklist and answer exactly what it asks.\",\n \"answers-unevidenced\":\n \"A `confirmed` answer carries no evidence — evidence is `file:line`, and a claim you cannot show is `unconfirmed` with a note saying why, which is a successful record, not a failure.\",\n \"service-mismatch\":\n \"A command that must run inside one service's own repository was told `--service` for a service this repository's loam.json does not declare: a recording `loam verify`, whose attestation must be bound to the code it is about; `loam gherkin`, whose .feature files land in that service's checkout; or `loam vouch`, whose `sources` resolve there. Run it from that service's own repo.\",\n \"unknown-service\":\n \"Federated verify recording: the selected service is not one this feature's checklist (or the docs repo) knows, so there is nothing its attestation could bind to — fix the id.\",\n \"repository-unavailable\":\n \"The repository this operation must be bound to (or read from) cannot be answered for — most commonly a writing `loam verify`, a `loam gherkin` or a `loam vouch` run where loam.json declares no `service` at all (the docs repo, usually), or a docs repo that cannot be enumerated — so the command refuses rather than guessing which service it is about.\",\n \"record-federated\":\n \"`loam verify --record` without `--service` over a federated (schema 2) record — the all-at-once form would erase other repositories' attestations, so it is refused naming the attestors; record per service instead.\",\n \"record-unreadable\":\n \"A verification.yaml exists but cannot be read as a record — it is never overwritten and never reported as absent; repair it by hand, or re-record from the service's repo.\",\n \"record-raced\":\n \"`loam verify --record` found the record changed between its locked read and the swap — an editor or a lock-ignoring writer landed first; nothing was written, and re-running merges over the record as it now stands.\",\n \"gherkin-conflict\":\n \"`loam gherkin <FEAT>` would overwrite a `.feature` file owned by another feature still in flight — the whole emission refuses and names the owner; archive or coordinate with that feature first.\",\n \"vouch-raced\":\n \"`loam vouch` found the spec changed between reading and stamping — another vouch or an edit landed first; nothing was written, so re-read and re-run.\",\n \"vouch-unattended\":\n \"`loam vouch` with nobody on the other end of stdin and no `--yes` — the stamp is a person's claim to have read the document, and nobody was asked.\",\n \"vouch-unattributable\":\n \"`loam vouch` could not learn who is vouching — git names no `user.email` here — and a stamp with nobody behind it records only that the word was written; set your git identity and re-run.\",\n \"vouch-declined\":\n \"`loam vouch` asked and the person said no — nothing was stamped; a successful refusal, not a failure.\",\n \"docs-missing\":\n \"`docsDir` in loam.json points at nothing — the docs repo was never cloned, or the path is wrong; a read command refuses rather than reporting an empty fleet, and `loam doctor` names the wiring to fix.\",\n \"services-missing\":\n \"`docsDir` is a directory but holds no `services/` — it is some other directory, most often the service repo itself after a typo; fix the pointer rather than scaffolding a second source of truth beside the real one.\",\n \"docs-busy\":\n \"Another loam writer holds the docs repo's advisory lock — nothing was read or written, and re-running once it finishes works; a lock nothing will ever release shows up in `loam doctor` as a blocker.\",\n \"subsystem-not-empty\":\n \"`loam subsystem` rm refuses a subsystem that still holds members — services or child subsystems, named in the message — because a destructive command never picks targets the caller did not name; move them out first, then re-run.\",\n \"move-uncommitted\":\n \"A subsystem move/rename refuses because git reports uncommitted or untracked paths under a directory being moved — the rename would sweep them into a move nobody reviewed; commit, `git stash -u`, or remove them, then re-run.\",\n \"move-failed\":\n \"A subsystem move/rename failed and was rolled back cleanly — every rename undone, the generated views file restored, the docs unchanged; re-running can work.\",\n \"no-members\":\n \"`loam open` found no service checkout bound to this docs repo under any scanned root — the workspace would hold only the docs repo; clone a bound checkout beside it, or point `--root` at where the checkouts live.\",\n \"binding-duplicate\":\n \"Two discovered repositories' committed loam.json files declare the same `service` for this docs repo — loam will not guess which checkout speaks for the service; narrow the scan with `--root`, or fix the stray binding.\",\n \"owners-unreadable\":\n \"`loam list --owners` could not use the named CODEOWNERS file — the path cannot be read, or a line does not parse as `pattern owner…` (the message names the line); fail-closed, because a half-read ownership file must never file a service under the wrong team.\",\n \"seed-file-invalid\":\n \"`loam seed`'s fleet file is missing, unreadable, not YAML, the wrong shape, carries an illegal id — or no longer names every existing `services/<id>/` (that refusal lists the exact ids as `missingServices`); the message names the file and line, and editing the file and re-running succeeds.\",\n \"seed-duplicate-service\":\n \"fleet.yaml declares one name twice — as two services, or as both a service and an external/subsystem; service ids, subsystem names and externals share one flat namespace, both declaration lines are named, and renaming one fixes it.\",\n \"seed-unknown-subsystem\":\n \"A service's `subsystem:` in fleet.yaml names nothing `subsystems:` declares — the message carries a did-you-mean over the names the file really declares; add the subsystem or fix the spelling, then re-run.\",\n \"seed-landscape-edited\":\n \"architecture/landscape.likec4 carries hand edits (the line-1 stamp's digest no longer matches) or was authored some other way, which includes anything written ABOVE the scaffold's stub — `loam seed` never overwrites human work and wrote nothing; fold the edits into fleet.yaml and delete the file, or keep the hand-authored map and stop using seed.\",\n internal:\n \"An unexpected throw — the one refusal with no stable meaning; it exists so a `--json` consumer still receives an envelope instead of a stack trace, and a repeatable `internal` is a loam defect worth reporting.\",\n} as const satisfies Record<ErrorCode, string>;\n"]}
@@ -16,13 +16,19 @@
16
16
  * documentation has got — and stops. Which of those neighbours the feature
17
17
  * really touches is a judgement about intent, and loam does not make those.
18
18
  *
19
- * The landscape is parsed ONCE for the whole exploration. Per-service reads of
20
- * it exist (`brief/landscape.ts`'s `landscapeContext`) and are correct for one service;
19
+ * "The fleet map" here is the `architecture/` PROJECT — the landscape plus every
20
+ * other `.likec4` under it, minus the generated views file — and not the
21
+ * landscape FILE. See the read below for the disagreement that reading one file
22
+ * caused.
23
+ *
24
+ * It is parsed ONCE for the whole exploration. Per-service reads of it exist
25
+ * (`brief/landscape.ts`'s `landscapeContext`) and are correct for one service;
21
26
  * calling one of those per seed is how `validate --all` came to cost 13 seconds
22
27
  * on 120 services, and this command sits in front of authoring, where that is
23
28
  * the difference between a habit and a thing people skip.
24
29
  */
25
30
  import { existsSync } from "node:fs";
31
+ import { relative } from "node:path";
26
32
  import { FleetContext } from "../fleet-context.js";
27
33
  import {} from "../c4/likec4.js";
28
34
  import { serviceResolver } from "../c4/resolve/service.js";
@@ -43,9 +49,24 @@ export async function explore(req) {
43
49
  const entries = await context.listServices(docsDir);
44
50
  const byId = new Map(entries.map((e) => [e.id, e]));
45
51
  const known = new Set(byId.keys());
46
- const landPath = landscapePath(docsDir);
47
- const present = existsSync(landPath);
48
- const land = present ? await context.loadLikeC4(landPath) : null;
52
+ // The `architecture/` PROJECT, never `architecture/landscape.likec4` alone.
53
+ // The map is a project — the landscape merged with every use case, palette and
54
+ // second `model { }` block beside it — and reading one file of it made this
55
+ // command answer differently from `loam adopt` and `loam context` about the
56
+ // same tree (reproduced: with a broken `architecture/palette.likec4` beside a
57
+ // landscape that parses, `context checkout-web --json` reported
58
+ // `landscape.parses: false` while `explore checkout-web --json` reported
59
+ // `parses: true` and went on to describe every edge). `core/pack/living.ts`
60
+ // named this module as the last reader that disagreed. Whichever answer is
61
+ // right, an agent handed both has no way to tell — and the renderer's answer
62
+ // is the project's.
63
+ //
64
+ // `present` stays a fact about the FILE, because that file is the WRITE target:
65
+ // `loam new`'s scaffold and every brief ask for edits to
66
+ // `architecture/landscape.likec4` by name, and "the project is empty" is not
67
+ // the same instruction as "there is no map to edit".
68
+ const present = existsSync(landscapePath(docsDir));
69
+ const land = present ? await context.architecture(docsDir) : null;
49
70
  const parses = land !== null && land.errors.length === 0;
50
71
  const elements = parses ? land.elements : [];
51
72
  const relationships = parses ? land.relationships : [];
@@ -79,9 +100,15 @@ export async function explore(req) {
79
100
  // other: a service can realize a capability without appearing in its drawn
80
101
  // flow, and a flow can pass through a service that has written nothing down.
81
102
  //
82
- // The scan gates its own load, and this whole block is already behind
83
- // `--capability` being passed at all, so an exploration by service or by
84
- // operation never touches `architecture/` as a project.
103
+ // The scan gates its own load — a fleet whose documents mention no reserved
104
+ // tag never starts LikeC4 for it — and this whole block is behind
105
+ // `--capability` being passed at all. What it is no longer behind is the
106
+ // project itself: the read above loads `architecture/` for every exploration,
107
+ // so a `--capability` run pays for a SECOND parse of the same documents
108
+ // (`readUseCases` takes a `DocsDir`, not this invocation's memo). Accepted
109
+ // rather than unnoticed: the alternative is a seam that hands the scan a
110
+ // pre-loaded project, which is a change to a module five callers share, and
111
+ // the cost lands only on the flag that already opts into the fleet rollup.
85
112
  const capSeeds = [];
86
113
  let unresolvedCaps = [];
87
114
  if (req.capabilities.length > 0) {
@@ -167,7 +194,15 @@ export async function explore(req) {
167
194
  services,
168
195
  neighbours: [...ring.keys()].sort(compareIds),
169
196
  overlaps,
170
- landscape: { present, parses },
197
+ landscape: {
198
+ present,
199
+ parses,
200
+ broken: land === null
201
+ ? []
202
+ : [...new Set(land.errors.map((e) => e.sourceFsPath).filter((p) => p !== undefined))]
203
+ .map((abs) => relative(docsDir, abs).split(/[\\/]/).join("/"))
204
+ .sort(),
205
+ },
171
206
  scaffold: newCommand(featureId, seeds, known),
172
207
  };
173
208
  }
@@ -1 +1 @@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AE,CAAC;YACnB,aAAa;YACb,KAAK;YACL,QAAQ;YACR,MAAM;YACN,OAAO;SACR,CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAqB,QAAQ;SACxC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACnF,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;SACpC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAEpD,OAAO;QACL,KAAK;QACL,OAAO;QACP,oBAAoB;QACpB,sBAAsB,EAAE,cAAc;QACtC,QAAQ;QACR,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;QAC7C,QAAQ;QACR,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;QAC9B,QAAQ,EAAE,UAAU,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC;KAC9C,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The blast radius of a change nobody has written down yet.\n *\n * Everything else in loam answers a question about documents that exist. This\n * module answers the one that comes BEFORE the first document: which services\n * does this feature actually touch? On a fleet of a hundred that call is the\n * hardest one in the cycle and the only one made with no tool in hand —\n * `loam new FEAT-101 --touches a --touches b` takes the answer as an argument\n * and scaffolds whatever it was told. A `--touches` list short by one service\n * is not caught by anything: the feature validates, archives, and ships with a\n * consumer nobody updated.\n *\n * So this states the work the same way `brief/brief.ts` does. It reads the fleet map\n * and the living contracts, reports the ring of services around the seeds, the\n * features already in flight over the same ground, and how far each service's\n * documentation has got — and stops. Which of those neighbours the feature\n * really touches is a judgement about intent, and loam does not make those.\n *\n * The landscape is parsed ONCE for the whole exploration. Per-service reads of\n * it exist (`brief/landscape.ts`'s `landscapeContext`) and are correct for one service;\n * calling one of those per seed is how `validate --all` came to cost 13 seconds\n * on 120 services, and this command sits in front of authoring, where that is\n * the difference between a habit and a thing people skip.\n */\nimport { existsSync } from \"node:fs\";\nimport { FleetContext } from \"../fleet-context.js\";\nimport { type Rel } from \"../c4/likec4.js\";\nimport { serviceResolver } from \"../c4/resolve/service.js\";\nimport { type Maturity } from \"../vocabulary/maturity.js\";\nimport { capabilityRollup, unresolvedCapabilities } from \"../capabilities/rollup.js\";\nimport { compareIds, nearestIds, type ServiceEntry } from \"../repo/entries.js\";\nimport { landscapePath } from \"../repo/paths.js\";\nimport { readUseCases } from \"../usecases/fleet.js\";\nimport { servicesInFlowsClaiming } from \"../usecases/capability.js\";\nimport { describe, newCommand, operationOwner } from \"./describe.js\";\nimport type { DocsDir } from \"../kernel/ids/dirs.js\";\n\n/** One end of a call the fleet map already draws. */\nexport interface ExploreEdge {\n /** The service at the other end. */\n service: string;\n /** The operationId the call uses, or null for an edge nobody tied to one. */\n op: string | null;\n title: string | null;\n}\n\n/**\n * Why a service is in the answer. Seeds were asked for; the rest were derived.\n *\n * A neighbour on both sides of a seed reports `calls-seed` — see the overlap\n * rule in `explore`. The field is a hint about where to look, not a complete\n * description of the edges; `inbound`/`outbound` are that.\n */\nexport type ExploreReason = \"seed\" | \"calls-seed\" | \"called-by-seed\";\n\nexport interface ExploreService {\n id: string;\n reason: ExploreReason;\n /** Whether `services/<id>/` exists at all. */\n known: boolean;\n /**\n * How far this service's documentation has got, or null when it does not\n * exist yet. A `--touches` naming a service at `empty` or `partial` is a\n * different job from one naming a vouched service, and the difference decides\n * whether the feature starts with `loam adopt`.\n */\n maturity: Maturity | null;\n /** What stands between it and `vouched` — `maturityGaps`, so it matches `list --needs-work`. */\n missing: string[];\n /** Whether anything in the fleet map resolves to it. */\n modelled: boolean;\n /** operationIds its living contract exposes today, `x-loam-remove` markers excluded. */\n operations: string[];\n /**\n * Whether that contract could be read at all, beside the `error` the parser\n * gave when it could not.\n *\n * It rides next to `operations` rather than inside it for the reason `delta`\n * carries the same pair: an unreadable contract yields an EMPTY operation\n * list, indistinguishable from a service with no endpoints — and this is the\n * field the workflow tells an agent to read before deciding whether an\n * operation it is about to add already exists. Answering `[]` over a YAML\n * error is how a MODIFIED requirement gets authored as ADDED.\n */\n openapi: { unreadable: boolean; error?: string };\n inbound: ExploreEdge[];\n outbound: ExploreEdge[];\n}\n\n/** An active feature already working over ground the exploration covers. */\nexport interface ExploreOverlap {\n feature: string;\n /** The explored services it already carries a delta for. */\n services: string[];\n}\n\nexport interface Exploration {\n /** The seed ids, as asked for. */\n seeds: string[];\n /**\n * Seeds that name no `services/<id>/`, each with the closest real ids. A seed\n * may legitimately be a service the feature INTRODUCES, so this is reported\n * rather than refused — but a typo produces exactly the same shape, and the\n * near-miss list is what tells the two apart.\n */\n unknown: Array<{ id: string; nearest: string[] }>;\n /** Operation seeds that resolved to no service's living contract. */\n unresolvedOperations: string[];\n /**\n * Capability seeds that seeded nothing: not declared in\n * architecture/capabilities.yaml (the file may not exist at all — explore\n * refuses nothing, every miss is a field), or declared and realized by no\n * living requirement. One list on purpose; splitting the two miss kinds\n * waits for a consumer to ask.\n */\n unresolvedCapabilities: string[];\n /** Seeds first, then the ring, each in id order. */\n services: ExploreService[];\n /** Ids the ring added that were not asked for — the candidates to weigh. */\n neighbours: string[];\n overlaps: ExploreOverlap[];\n landscape: { present: boolean; parses: boolean };\n /**\n * The literal `loam new` line the seeds imply — seeds only. The ring is\n * deliberately NOT folded in: this module's whole claim is that it does not\n * know which neighbours the feature touches, and a command line that quietly\n * included them would make the guess on the reader's behalf and look derived\n * while doing it.\n *\n * Named for what it does rather than `command`, which is the envelope's key\n * for the command that RAN. The rename is not cosmetic: `emitJson` spreads\n * the payload LAST, so a payload field called `command` would silently\n * OVERRIDE the envelope's — `command` would come back as\n * `\"loam new FEAT-000 …\"`, and every consumer branching on\n * `command === \"explore\"` (the same key `status`, `doctor`, `dependencies`,\n * `archive` and `unarchive` emit) would quietly stop matching, with tsc and\n * the linter green throughout.\n */\n scaffold: string;\n}\n\nexport interface ExploreRequest {\n docsDir: DocsDir;\n /** Service ids to explore around. Checked at the command boundary. */\n services: ServiceEntry[\"id\"][];\n /** operationIds to explore around; each resolves to the service that defines it. */\n operations: string[];\n /** Declared capability ids to explore around; each seeds its realizing services. */\n capabilities: string[];\n /** Placeholder feature id for the suggested command line. */\n featureId: string;\n context?: FleetContext;\n}\n\n/**\n * Read the fleet around a proposed change. Reads only; writes nothing, and\n * refuses nothing — every miss is reported as a field.\n */\nexport async function explore(req: ExploreRequest): Promise<Exploration> {\n const { docsDir, featureId } = req;\n const context = req.context ?? new FleetContext();\n const entries = await context.listServices(docsDir);\n const byId = new Map<string, ServiceEntry>(entries.map((e) => [e.id, e]));\n const known: ReadonlySet<string> = new Set(byId.keys());\n\n const landPath = landscapePath(docsDir);\n const present = existsSync(landPath);\n const land = present ? await context.loadLikeC4(landPath) : null;\n const parses = land !== null && land.errors.length === 0;\n const elements = parses ? land.elements : [];\n const relationships: Rel[] = parses ? land.relationships : [];\n // One resolver for the whole scan, built with the real service ids so an edge\n // drawn into a modelled container (`paymentService.api`) counts for the\n // service that owns it — the same resolution `list`, `show` and `validate`\n // use, so no two commands can disagree about who calls whom.\n const svcOf = serviceResolver(elements, known);\n\n // Operation seeds resolve through the living contracts, not the map: the map\n // says who CALLS an operation, and the question here is who DEFINES it.\n const opSeeds: ServiceEntry[\"id\"][] = [];\n const unresolvedOperations: string[] = [];\n for (const op of req.operations) {\n const owner = await operationOwner(entries, op, context);\n if (owner === null) unresolvedOperations.push(op);\n else opSeeds.push(owner);\n }\n\n // Capability seeds resolve through the vocabulary and the fleet rollup —\n // one rollup pass for ALL requested ids, through this exploration's shared\n // context cache, never a fresh walk per capability. A realizing service is\n // by construction an enumerated one, so every seed it adds is `known`.\n //\n // And through the fleet's USE CASES, which answer the same question off a\n // different document. The rollup finds services whose living requirements\n // carry a `Capability:` line; a `dynamic view` tagged `#cap-<slug>` finds the\n // services the flow actually runs through — including ones whose spec.md has\n // never named the capability, which on a brownfield fleet is most of them.\n // The two are unioned rather than ranked because neither is a subset of the\n // other: a service can realize a capability without appearing in its drawn\n // flow, and a flow can pass through a service that has written nothing down.\n //\n // The scan gates its own load, and this whole block is already behind\n // `--capability` being passed at all, so an exploration by service or by\n // operation never touches `architecture/` as a project.\n const capSeeds: ServiceEntry[\"id\"][] = [];\n let unresolvedCaps: string[] = [];\n if (req.capabilities.length > 0) {\n const vocab = await context.capabilities(docsDir);\n const rows = await capabilityRollup({ services: entries, vocab, read: (p) => context.readRequirements(p) });\n const wanted = new Set(req.capabilities);\n const realizing = new Set(rows.filter((r) => wanted.has(r.id)).flatMap((r) => r.services));\n const scan = await readUseCases({ docsDir, known });\n for (const id of servicesInFlowsClaiming(scan, req.capabilities)) realizing.add(id);\n capSeeds.push(...entries.filter((e) => realizing.has(e.id)).map((e) => e.id));\n // `unresolvedCapabilities` is unchanged on purpose: it grades the\n // VOCABULARY — declared or not, realized by a living requirement or not —\n // and a capability drawn in a flow but realized by nobody is still a\n // capability nothing implements. Letting a tag silence that would hide the\n // gap the field exists to name.\n unresolvedCaps = unresolvedCapabilities(rows, req.capabilities);\n }\n\n const seeds = [...new Set([...req.services, ...opSeeds, ...capSeeds])];\n const unknown = seeds\n .filter((id) => !known.has(id))\n .map((id) => ({ id, nearest: nearestIds(id, [...known]) }));\n\n // The ring: one hop, both directions. A seed that is not modelled contributes\n // nothing here and that is the honest answer — an invisible service has no\n // neighbours anyone can derive, which is what `landscape.service-unmodelled`\n // is about.\n //\n // The two directions are collected separately rather than written into one\n // map as the loop goes, because a neighbour can be BOTH — it calls a seed and\n // the seed calls it — and a single-map version answers whichever edge the\n // parser happened to yield last. That is a field whose value depends on the\n // order lines appear in a `.likec4` file, which is the kind of answer that\n // reads as derived and is not.\n const seedSet = new Set<string>(seeds);\n const callsSeed = new Set<string>();\n const calledBySeed = new Set<string>();\n for (const r of relationships) {\n const from = svcOf(r.source);\n const to = svcOf(r.target);\n if (seedSet.has(from) && !seedSet.has(to)) calledBySeed.add(to);\n if (seedSet.has(to) && !seedSet.has(from)) callsSeed.add(from);\n }\n\n // `calls-seed` wins the overlap, deterministically. Of the two directions it\n // is the one that more often has to be touched: a consumer depends on the\n // seed's contract, so a change to that contract is what breaks it, while a\n // provider the seed merely calls is usually unaffected by the seed changing.\n const ring = new Map<string, ExploreReason>([\n ...[...calledBySeed].map((id) => [id, \"called-by-seed\" as const] as const),\n ...[...callsSeed].map((id) => [id, \"calls-seed\" as const] as const),\n ]);\n\n const ordered: Array<{ id: string; reason: ExploreReason }> = [\n ...[...seeds].sort(compareIds).map((id) => ({ id, reason: \"seed\" as const })),\n ...[...ring]\n .sort(([a], [b]) => compareIds(a, b))\n .map(([id, reason]) => ({ id, reason })),\n ];\n\n const services: ExploreService[] = [];\n for (const { id, reason } of ordered) {\n services.push(\n await describe({\n id,\n reason,\n entry: byId.get(id),\n relationships,\n svcOf,\n elements,\n parses,\n context,\n }),\n );\n }\n\n const covered = new Set(services.map((s) => s.id));\n const features = await context.listFeatures(docsDir);\n const overlaps: ExploreOverlap[] = features\n .map((f) => ({ feature: f.id, services: f.services.filter((s) => covered.has(s)) }))\n .filter((o) => o.services.length > 0)\n .sort((a, b) => compareIds(a.feature, b.feature));\n\n return {\n seeds,\n unknown,\n unresolvedOperations,\n unresolvedCapabilities: unresolvedCaps,\n services,\n neighbours: [...ring.keys()].sort(compareIds),\n overlaps,\n landscape: { present, parses },\n scaffold: newCommand(featureId, seeds, known),\n };\n}\n"]}
1
+ {"version":3,"file":"explore.js","sourceRoot":"","sources":["../../../src/core/explore/explore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgIrE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAAmB;IAC/C,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC;IACnC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,IAAI,YAAY,EAAE,CAAC;IAClD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAuB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE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AAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAEpD,OAAO;QACL,KAAK;QACL,OAAO;QACP,oBAAoB;QACpB,sBAAsB,EAAE,cAAc;QACtC,QAAQ;QACR,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;QAC7C,QAAQ;QACR,SAAS,EAAE;YACT,OAAO;YACP,MAAM;YACN,MAAM,EACJ,IAAI,KAAK,IAAI;gBACX,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;qBAC7F,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;qBAC7D,IAAI,EAAE;SAChB;QACD,QAAQ,EAAE,UAAU,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC;KAC9C,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The blast radius of a change nobody has written down yet.\n *\n * Everything else in loam answers a question about documents that exist. This\n * module answers the one that comes BEFORE the first document: which services\n * does this feature actually touch? On a fleet of a hundred that call is the\n * hardest one in the cycle and the only one made with no tool in hand —\n * `loam new FEAT-101 --touches a --touches b` takes the answer as an argument\n * and scaffolds whatever it was told. A `--touches` list short by one service\n * is not caught by anything: the feature validates, archives, and ships with a\n * consumer nobody updated.\n *\n * So this states the work the same way `brief/brief.ts` does. It reads the fleet map\n * and the living contracts, reports the ring of services around the seeds, the\n * features already in flight over the same ground, and how far each service's\n * documentation has got — and stops. Which of those neighbours the feature\n * really touches is a judgement about intent, and loam does not make those.\n *\n * \"The fleet map\" here is the `architecture/` PROJECT — the landscape plus every\n * other `.likec4` under it, minus the generated views file — and not the\n * landscape FILE. See the read below for the disagreement that reading one file\n * caused.\n *\n * It is parsed ONCE for the whole exploration. Per-service reads of it exist\n * (`brief/landscape.ts`'s `landscapeContext`) and are correct for one service;\n * calling one of those per seed is how `validate --all` came to cost 13 seconds\n * on 120 services, and this command sits in front of authoring, where that is\n * the difference between a habit and a thing people skip.\n */\nimport { existsSync } from \"node:fs\";\nimport { relative } from \"node:path\";\nimport { FleetContext } from \"../fleet-context.js\";\nimport { type Rel } from \"../c4/likec4.js\";\nimport { serviceResolver } from \"../c4/resolve/service.js\";\nimport { type Maturity } from \"../vocabulary/maturity.js\";\nimport { capabilityRollup, unresolvedCapabilities } from \"../capabilities/rollup.js\";\nimport { compareIds, nearestIds, type ServiceEntry } from \"../repo/entries.js\";\nimport { landscapePath } from \"../repo/paths.js\";\nimport { readUseCases } from \"../usecases/fleet.js\";\nimport { servicesInFlowsClaiming } from \"../usecases/capability.js\";\nimport { describe, newCommand, operationOwner } from \"./describe.js\";\nimport type { DocsDir } from \"../kernel/ids/dirs.js\";\n\n/** One end of a call the fleet map already draws. */\nexport interface ExploreEdge {\n /** The service at the other end. */\n service: string;\n /** The operationId the call uses, or null for an edge nobody tied to one. */\n op: string | null;\n title: string | null;\n}\n\n/**\n * Why a service is in the answer. Seeds were asked for; the rest were derived.\n *\n * A neighbour on both sides of a seed reports `calls-seed` — see the overlap\n * rule in `explore`. The field is a hint about where to look, not a complete\n * description of the edges; `inbound`/`outbound` are that.\n */\nexport type ExploreReason = \"seed\" | \"calls-seed\" | \"called-by-seed\";\n\nexport interface ExploreService {\n id: string;\n reason: ExploreReason;\n /** Whether `services/<id>/` exists at all. */\n known: boolean;\n /**\n * How far this service's documentation has got, or null when it does not\n * exist yet. A `--touches` naming a service at `empty` or `partial` is a\n * different job from one naming a vouched service, and the difference decides\n * whether the feature starts with `loam adopt`.\n */\n maturity: Maturity | null;\n /** What stands between it and `vouched` — `maturityGaps`, so it matches `list --needs-work`. */\n missing: string[];\n /** Whether anything in the fleet map resolves to it. */\n modelled: boolean;\n /** operationIds its living contract exposes today, `x-loam-remove` markers excluded. */\n operations: string[];\n /**\n * Whether that contract could be read at all, beside the `error` the parser\n * gave when it could not.\n *\n * It rides next to `operations` rather than inside it for the reason `delta`\n * carries the same pair: an unreadable contract yields an EMPTY operation\n * list, indistinguishable from a service with no endpoints — and this is the\n * field the workflow tells an agent to read before deciding whether an\n * operation it is about to add already exists. Answering `[]` over a YAML\n * error is how a MODIFIED requirement gets authored as ADDED.\n */\n openapi: { unreadable: boolean; error?: string };\n inbound: ExploreEdge[];\n outbound: ExploreEdge[];\n}\n\n/** An active feature already working over ground the exploration covers. */\nexport interface ExploreOverlap {\n feature: string;\n /** The explored services it already carries a delta for. */\n services: string[];\n}\n\nexport interface Exploration {\n /** The seed ids, as asked for. */\n seeds: string[];\n /**\n * Seeds that name no `services/<id>/`, each with the closest real ids. A seed\n * may legitimately be a service the feature INTRODUCES, so this is reported\n * rather than refused — but a typo produces exactly the same shape, and the\n * near-miss list is what tells the two apart.\n */\n unknown: Array<{ id: string; nearest: string[] }>;\n /** Operation seeds that resolved to no service's living contract. */\n unresolvedOperations: string[];\n /**\n * Capability seeds that seeded nothing: not declared in\n * architecture/capabilities.yaml (the file may not exist at all — explore\n * refuses nothing, every miss is a field), or declared and realized by no\n * living requirement. One list on purpose; splitting the two miss kinds\n * waits for a consumer to ask.\n */\n unresolvedCapabilities: string[];\n /** Seeds first, then the ring, each in id order. */\n services: ExploreService[];\n /** Ids the ring added that were not asked for — the candidates to weigh. */\n neighbours: string[];\n overlaps: ExploreOverlap[];\n /**\n * `broken` is the `architecture/` documents that failed, docs-relative POSIX,\n * deduped and sorted — `[]` while `parses` is true. `parses` answers for the\n * PROJECT, so the broken document is very often a SIBLING beside a landscape\n * that reads perfectly, and naming the landscape file was a claim about bytes\n * loam read fine (verification 2026-09-04). Spelled as `landscape.invalid`\n * spells it, so the two surfaces name one file one way.\n */\n landscape: { present: boolean; parses: boolean; broken: string[] };\n /**\n * The literal `loam new` line the seeds imply — seeds only. The ring is\n * deliberately NOT folded in: this module's whole claim is that it does not\n * know which neighbours the feature touches, and a command line that quietly\n * included them would make the guess on the reader's behalf and look derived\n * while doing it.\n *\n * Named for what it does rather than `command`, which is the envelope's key\n * for the command that RAN. The rename is not cosmetic: `emitJson` spreads\n * the payload LAST, so a payload field called `command` would silently\n * OVERRIDE the envelope's — `command` would come back as\n * `\"loam new FEAT-000 …\"`, and every consumer branching on\n * `command === \"explore\"` (the same key `status`, `doctor`, `dependencies`,\n * `archive` and `unarchive` emit) would quietly stop matching, with tsc and\n * the linter green throughout.\n */\n scaffold: string;\n}\n\nexport interface ExploreRequest {\n docsDir: DocsDir;\n /** Service ids to explore around. Checked at the command boundary. */\n services: ServiceEntry[\"id\"][];\n /** operationIds to explore around; each resolves to the service that defines it. */\n operations: string[];\n /** Declared capability ids to explore around; each seeds its realizing services. */\n capabilities: string[];\n /** Placeholder feature id for the suggested command line. */\n featureId: string;\n context?: FleetContext;\n}\n\n/**\n * Read the fleet around a proposed change. Reads only; writes nothing, and\n * refuses nothing — every miss is reported as a field.\n */\nexport async function explore(req: ExploreRequest): Promise<Exploration> {\n const { docsDir, featureId } = req;\n const context = req.context ?? new FleetContext();\n const entries = await context.listServices(docsDir);\n const byId = new Map<string, ServiceEntry>(entries.map((e) => [e.id, e]));\n const known: ReadonlySet<string> = new Set(byId.keys());\n\n // The `architecture/` PROJECT, never `architecture/landscape.likec4` alone.\n // The map is a project — the landscape merged with every use case, palette and\n // second `model { }` block beside it — and reading one file of it made this\n // command answer differently from `loam adopt` and `loam context` about the\n // same tree (reproduced: with a broken `architecture/palette.likec4` beside a\n // landscape that parses, `context checkout-web --json` reported\n // `landscape.parses: false` while `explore checkout-web --json` reported\n // `parses: true` and went on to describe every edge). `core/pack/living.ts`\n // named this module as the last reader that disagreed. Whichever answer is\n // right, an agent handed both has no way to tell — and the renderer's answer\n // is the project's.\n //\n // `present` stays a fact about the FILE, because that file is the WRITE target:\n // `loam new`'s scaffold and every brief ask for edits to\n // `architecture/landscape.likec4` by name, and \"the project is empty\" is not\n // the same instruction as \"there is no map to edit\".\n const present = existsSync(landscapePath(docsDir));\n const land = present ? await context.architecture(docsDir) : null;\n const parses = land !== null && land.errors.length === 0;\n const elements = parses ? land.elements : [];\n const relationships: Rel[] = parses ? land.relationships : [];\n // One resolver for the whole scan, built with the real service ids so an edge\n // drawn into a modelled container (`paymentService.api`) counts for the\n // service that owns it — the same resolution `list`, `show` and `validate`\n // use, so no two commands can disagree about who calls whom.\n const svcOf = serviceResolver(elements, known);\n\n // Operation seeds resolve through the living contracts, not the map: the map\n // says who CALLS an operation, and the question here is who DEFINES it.\n const opSeeds: ServiceEntry[\"id\"][] = [];\n const unresolvedOperations: string[] = [];\n for (const op of req.operations) {\n const owner = await operationOwner(entries, op, context);\n if (owner === null) unresolvedOperations.push(op);\n else opSeeds.push(owner);\n }\n\n // Capability seeds resolve through the vocabulary and the fleet rollup —\n // one rollup pass for ALL requested ids, through this exploration's shared\n // context cache, never a fresh walk per capability. A realizing service is\n // by construction an enumerated one, so every seed it adds is `known`.\n //\n // And through the fleet's USE CASES, which answer the same question off a\n // different document. The rollup finds services whose living requirements\n // carry a `Capability:` line; a `dynamic view` tagged `#cap-<slug>` finds the\n // services the flow actually runs through — including ones whose spec.md has\n // never named the capability, which on a brownfield fleet is most of them.\n // The two are unioned rather than ranked because neither is a subset of the\n // other: a service can realize a capability without appearing in its drawn\n // flow, and a flow can pass through a service that has written nothing down.\n //\n // The scan gates its own load — a fleet whose documents mention no reserved\n // tag never starts LikeC4 for it — and this whole block is behind\n // `--capability` being passed at all. What it is no longer behind is the\n // project itself: the read above loads `architecture/` for every exploration,\n // so a `--capability` run pays for a SECOND parse of the same documents\n // (`readUseCases` takes a `DocsDir`, not this invocation's memo). Accepted\n // rather than unnoticed: the alternative is a seam that hands the scan a\n // pre-loaded project, which is a change to a module five callers share, and\n // the cost lands only on the flag that already opts into the fleet rollup.\n const capSeeds: ServiceEntry[\"id\"][] = [];\n let unresolvedCaps: string[] = [];\n if (req.capabilities.length > 0) {\n const vocab = await context.capabilities(docsDir);\n const rows = await capabilityRollup({ services: entries, vocab, read: (p) => context.readRequirements(p) });\n const wanted = new Set(req.capabilities);\n const realizing = new Set(rows.filter((r) => wanted.has(r.id)).flatMap((r) => r.services));\n const scan = await readUseCases({ docsDir, known });\n for (const id of servicesInFlowsClaiming(scan, req.capabilities)) realizing.add(id);\n capSeeds.push(...entries.filter((e) => realizing.has(e.id)).map((e) => e.id));\n // `unresolvedCapabilities` is unchanged on purpose: it grades the\n // VOCABULARY — declared or not, realized by a living requirement or not —\n // and a capability drawn in a flow but realized by nobody is still a\n // capability nothing implements. Letting a tag silence that would hide the\n // gap the field exists to name.\n unresolvedCaps = unresolvedCapabilities(rows, req.capabilities);\n }\n\n const seeds = [...new Set([...req.services, ...opSeeds, ...capSeeds])];\n const unknown = seeds\n .filter((id) => !known.has(id))\n .map((id) => ({ id, nearest: nearestIds(id, [...known]) }));\n\n // The ring: one hop, both directions. A seed that is not modelled contributes\n // nothing here and that is the honest answer — an invisible service has no\n // neighbours anyone can derive, which is what `landscape.service-unmodelled`\n // is about.\n //\n // The two directions are collected separately rather than written into one\n // map as the loop goes, because a neighbour can be BOTH — it calls a seed and\n // the seed calls it — and a single-map version answers whichever edge the\n // parser happened to yield last. That is a field whose value depends on the\n // order lines appear in a `.likec4` file, which is the kind of answer that\n // reads as derived and is not.\n const seedSet = new Set<string>(seeds);\n const callsSeed = new Set<string>();\n const calledBySeed = new Set<string>();\n for (const r of relationships) {\n const from = svcOf(r.source);\n const to = svcOf(r.target);\n if (seedSet.has(from) && !seedSet.has(to)) calledBySeed.add(to);\n if (seedSet.has(to) && !seedSet.has(from)) callsSeed.add(from);\n }\n\n // `calls-seed` wins the overlap, deterministically. Of the two directions it\n // is the one that more often has to be touched: a consumer depends on the\n // seed's contract, so a change to that contract is what breaks it, while a\n // provider the seed merely calls is usually unaffected by the seed changing.\n const ring = new Map<string, ExploreReason>([\n ...[...calledBySeed].map((id) => [id, \"called-by-seed\" as const] as const),\n ...[...callsSeed].map((id) => [id, \"calls-seed\" as const] as const),\n ]);\n\n const ordered: Array<{ id: string; reason: ExploreReason }> = [\n ...[...seeds].sort(compareIds).map((id) => ({ id, reason: \"seed\" as const })),\n ...[...ring]\n .sort(([a], [b]) => compareIds(a, b))\n .map(([id, reason]) => ({ id, reason })),\n ];\n\n const services: ExploreService[] = [];\n for (const { id, reason } of ordered) {\n services.push(\n await describe({\n id,\n reason,\n entry: byId.get(id),\n relationships,\n svcOf,\n elements,\n parses,\n context,\n }),\n );\n }\n\n const covered = new Set(services.map((s) => s.id));\n const features = await context.listFeatures(docsDir);\n const overlaps: ExploreOverlap[] = features\n .map((f) => ({ feature: f.id, services: f.services.filter((s) => covered.has(s)) }))\n .filter((o) => o.services.length > 0)\n .sort((a, b) => compareIds(a.feature, b.feature));\n\n return {\n seeds,\n unknown,\n unresolvedOperations,\n unresolvedCapabilities: unresolvedCaps,\n services,\n neighbours: [...ring.keys()].sort(compareIds),\n overlaps,\n landscape: {\n present,\n parses,\n broken:\n land === null\n ? []\n : [...new Set(land.errors.map((e) => e.sourceFsPath).filter((p): p is string => p !== undefined))]\n .map((abs) => relative(docsDir, abs).split(/[\\\\/]/).join(\"/\"))\n .sort(),\n },\n scaffold: newCommand(featureId, seeds, known),\n };\n}\n"]}
@@ -28,6 +28,7 @@ import { conflictMarkerLines } from "./conflict-markers.js";
28
28
  import { decodeDocument } from "./kernel/document-bytes.js";
29
29
  import { loadFile } from "./c4/likec4.js";
30
30
  import { loadBatch } from "./c4/workspace.js";
31
+ import { ServiceModels } from "./c4/prefetch/fleet.js";
31
32
  import { readOpenapi } from "./openapi/doc.js";
32
33
  import {} from "./repo/entries.js";
33
34
  import { featureSpecServices, listFeatures, listFleetTree, serviceEntries } from "./repo/repo.js";
@@ -47,6 +48,19 @@ export class FleetContext {
47
48
  capabilityVocabularies = new Map();
48
49
  featureCapabilities = new Map();
49
50
  likec4 = new Map();
51
+ /**
52
+ * The service-model axis's own memos, one object because the rules they
53
+ * encode are `c4/prefetch/fleet.ts`'s rather than this class's. It counts
54
+ * through this instance's counter, so `stats()` stays the one place a caller
55
+ * reads what an invocation cost.
56
+ */
57
+ models = new ServiceModels({
58
+ onProjectLoad: () => {
59
+ this.counts.projectLoads += 1;
60
+ },
61
+ known: async (docsDir) => new Set((await this.listServices(docsDir)).map((s) => s.id)),
62
+ standalone: (path) => this.loadLikeC4(path),
63
+ });
50
64
  counts = {
51
65
  serviceEnumerations: 0,
52
66
  featureEnumerations: 0,
@@ -58,6 +72,7 @@ export class FleetContext {
58
72
  capabilityParses: 0,
59
73
  featureCapabilityWalks: 0,
60
74
  likec4Loads: 0,
75
+ projectLoads: 0,
61
76
  };
62
77
  /** A copy suitable for diagnostics/tests; callers cannot mutate the counters. */
63
78
  stats() {
@@ -276,5 +291,37 @@ export class FleetContext {
276
291
  this.likec4.set(k, Promise.resolve(doc));
277
292
  }
278
293
  }
294
+ /** The fleet map as the PROJECT it is — landscape plus use cases, minus the generated views file. */
295
+ architecture(docsDir) {
296
+ return this.models.architecture(docsDir);
297
+ }
298
+ /**
299
+ * Which shape each of these models has, keyed by resolved path — one read of
300
+ * each file's bytes per invocation. Ask over the FULL enumeration, never a
301
+ * narrowed run's subset: shapes decide which directories are owed a
302
+ * per-service `likec4.config.json`, and a partial map answers "not
303
+ * standalone" for every service outside it.
304
+ */
305
+ modelShapes(paths) {
306
+ return this.models.shapes(paths);
307
+ }
308
+ /**
309
+ * A service's C4 model, read the way its own SHAPE demands — the one entry
310
+ * point for every reader of `model.likec4`, standalone or extending
311
+ * (`c4/service-model/load.ts` states the four arms and why each exists).
312
+ */
313
+ serviceModel(docsDir, paths) {
314
+ return this.models.model(docsDir, paths);
315
+ }
316
+ /**
317
+ * Every service's model prepared in two workspaces whatever the fleet's mix:
318
+ * the extending ones as one project each in one of them, the standalone ones
319
+ * through the document batch above. An accelerator with `prefetchLikeC4`'s
320
+ * failure story exactly — a batch that could not be created seeds nothing, so
321
+ * findings never change because of a tmpdir, only the speed does.
322
+ */
323
+ async prefetchServiceModels(docsDir, paths) {
324
+ await this.prefetchLikeC4(await this.models.prefetch(docsDir, paths));
325
+ }
279
326
  }
280
327
  //# sourceMappingURL=fleet-context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fleet-context.js","sourceRoot":"","sources":["../../src/core/fleet-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,wBAAwB,EAA6B,MAAM,gCAAgC,CAAC;AACrG,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAkB,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAmC,MAAM,kBAAkB,CAAC;AAEhF,OAAO,EAAwC,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAElG,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAoB,MAAM,oBAAoB,CAAC;AAsCtD,MAAM,GAAG,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;A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,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;YAC5B,yEAAyE;YACzE,sEAAsE;YACtE,kEAAkE;YAClE,uDAAuD;YACvD,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,SAAS;YACjC,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * Request-scoped read index for commands that walk a whole loam repository.\n *\n * The filesystem remains the source of truth. This class deliberately has no\n * singleton/global instance: a command creates one after loading loam.json and\n * drops it when that invocation finishes. Within that lifetime identical\n * reads share their in-flight Promise, which removes both duplicate I/O and\n * duplicate parsing without making a later CLI invocation observe stale data.\n *\n * Because every markdown artifact is read HERE, this is also where the two\n * failures a read must never swallow are answered: bytes that are not UTF-8\n * (which `readFile(path, \"utf8\")` silently turns into U+FFFD, so a UTF-16\n * spec.md parses as zero requirements and grades green), and git conflict\n * markers left in a living document (which parse as prose, and which the next\n * `loam archive` rewrites away). One place, so no reader can forget. Both\n * RULES live in leaves — the decode in `document-bytes.ts`, the marker scan\n * and its findings in `conflict-markers.ts` — because the parsers and graders\n * that touch a single file without an index owe the same rules, and must not\n * have to import this module — and the fleet it pulls in behind it — to obey\n * them.\n */\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { readAsyncapi } from \"./asyncapi/read.js\";\nimport type { AsyncapiDoc } from \"./asyncapi/model.js\";\nimport { readCapabilityVocabulary, type CapabilityVocabulary } from \"./capabilities/capabilities.js\";\nimport { featureCapabilityDeltas } from \"./capabilities/delta/tree.js\";\nimport type { CapabilityTree } from \"./capabilities/tree.js\";\nimport { conflictMarkerLines } from \"./conflict-markers.js\";\nimport { decodeDocument } from \"./kernel/document-bytes.js\";\nimport { loadFile, type LoadedDoc } from \"./c4/likec4.js\";\nimport { loadBatch } from \"./c4/workspace.js\";\nimport { readOpenapi, type OpenapiDoc, type Operation } from \"./openapi/doc.js\";\nimport type { RawServiceId } from \"./kernel/ids/service.js\";\nimport { type FeatureEntry, type ServiceEntry } from \"./repo/entries.js\";\nimport { featureSpecServices, listFeatures, listFleetTree, serviceEntries } from \"./repo/repo.js\";\nimport type { FleetTree } from \"./repo/tree/walk.js\";\nimport { parseRequirements } from \"./document/parse.js\";\nimport { type Requirement } from \"./document/spec.js\";\nimport type { DocsDir, FeatureDir } from \"./kernel/ids/dirs.js\";\n\nexport interface FleetContextStats {\n serviceEnumerations: number;\n featureEnumerations: number;\n featureServiceEnumerations: number;\n textReads: number;\n requirementParses: number;\n openapiParses: number;\n /**\n * Reads of a service's `asyncapi.yaml`. Counted separately because this axis\n * is the one that makes a per-service run read the whole fleet: \"does anybody\n * publish this message\" has no local answer, so `spine.message-unproduced`\n * walks every service's contract. The memo is what keeps that one walk per\n * command instead of one per consuming edge.\n */\n asyncapiParses: number;\n /**\n * Reads of the capability vocabulary — `architecture/capabilities.yaml` AND\n * the `capabilities/` walk, which are one vocabulary and so one read. One per\n * invocation is the capability axis's exit criterion, and this counter is how\n * a test pins it. (Permissions predates the memo and re-parses per service —\n * do not copy that.)\n */\n capabilityParses: number;\n /**\n * Walks of ONE feature's `capabilities/` delta tree. Counted apart from\n * `capabilityParses` because it answers a different question about a\n * different directory, and because a fleet that has not adopted the business\n * axis must be able to prove it pays nothing: every feature's walk is a\n * single `existsSync` that finds no directory, so this counter rises while\n * `textReads` and `requirementParses` do not.\n */\n featureCapabilityWalks: number;\n likec4Loads: number;\n}\n\nconst key = (path: string): string => resolve(path);\n\n/** One coherent filesystem snapshot for one command invocation. */\nexport class FleetContext {\n private readonly trees = new Map<string, Promise<FleetTree>>();\n private readonly services = new Map<string, Promise<ServiceEntry[]>>();\n private readonly features = new Map<string, Promise<FeatureEntry[]>>();\n private readonly featureServices = new Map<string, Promise<RawServiceId[]>>();\n private readonly texts = new Map<string, Promise<string>>();\n private readonly requirements = new Map<string, Promise<Requirement[]>>();\n private readonly openapis = new Map<string, Promise<OpenapiDoc>>();\n private readonly asyncapis = new Map<string, Promise<AsyncapiDoc>>();\n private readonly capabilityVocabularies = new Map<string, Promise<CapabilityVocabulary>>();\n private readonly featureCapabilities = new Map<string, Promise<CapabilityTree>>();\n private readonly likec4 = new Map<string, Promise<LoadedDoc>>();\n\n private readonly counts: FleetContextStats = {\n serviceEnumerations: 0,\n featureEnumerations: 0,\n featureServiceEnumerations: 0,\n textReads: 0,\n requirementParses: 0,\n openapiParses: 0,\n asyncapiParses: 0,\n capabilityParses: 0,\n featureCapabilityWalks: 0,\n likec4Loads: 0,\n };\n\n /** A copy suitable for diagnostics/tests; callers cannot mutate the counters. */\n stats(): Readonly<FleetContextStats> {\n return { ...this.counts };\n }\n\n /**\n * The classified `services/` tree — the ONE enumeration this invocation\n * performs. `listServices` below derives its entries from this memo, so a\n * command that asks for both the fleet and the tree's findings (`validate\n * --all` does) still walks the directories exactly once. The counter keeps\n * its historical meaning — walks of `services/` — it just counts the walk\n * where the walk now happens.\n */\n fleetTree(docsDir: DocsDir): Promise<FleetTree> {\n const k = key(docsDir);\n let pending = this.trees.get(k);\n if (pending === undefined) {\n this.counts.serviceEnumerations += 1;\n pending = listFleetTree(docsDir);\n this.trees.set(k, pending);\n }\n return pending;\n }\n\n listServices(docsDir: DocsDir): Promise<ServiceEntry[]> {\n const k = key(docsDir);\n let pending = this.services.get(k);\n if (pending === undefined) {\n pending = this.fleetTree(docsDir).then(serviceEntries);\n this.services.set(k, pending);\n }\n return pending;\n }\n\n listFeatures(docsDir: DocsDir, opts: { includeArchived?: boolean } = {}): Promise<FeatureEntry[]> {\n const k = `${key(docsDir)}\\0${opts.includeArchived === true ? \"all\" : \"active\"}`;\n let pending = this.features.get(k);\n if (pending === undefined) {\n this.counts.featureEnumerations += 1;\n pending = listFeatures(docsDir, opts).then((entries) => {\n // listFeatures has already enumerated every feature's specs/ directory;\n // seed the narrower lookup so validation/coherence do not read it again.\n for (const entry of entries) {\n const featureKey = key(entry.dir);\n if (!this.featureServices.has(featureKey)) {\n this.featureServices.set(featureKey, Promise.resolve(entry.services));\n }\n }\n return entries;\n });\n this.features.set(k, pending);\n }\n return pending;\n }\n\n featureSpecServices(featureDir: FeatureDir): Promise<RawServiceId[]> {\n const k = key(featureDir);\n let pending = this.featureServices.get(k);\n if (pending === undefined) {\n this.counts.featureServiceEnumerations += 1;\n pending = featureSpecServices(featureDir);\n this.featureServices.set(k, pending);\n }\n return pending;\n }\n\n /**\n * A markdown artifact as text. Bytes in, decoded once, and refused rather\n * than degraded when they are not UTF-8 — see NotUtf8DocumentError.\n */\n readText(path: string): Promise<string> {\n const k = key(path);\n let pending = this.texts.get(k);\n if (pending === undefined) {\n this.counts.textReads += 1;\n pending = readFile(path).then((bytes) => decodeDocument(bytes, path));\n this.texts.set(k, pending);\n }\n return pending;\n }\n\n /**\n * Git conflict markers in an already-read document, by line. Free for any\n * caller that was going to read the file anyway — which is every caller,\n * which is the point: the marker check used to cost a whole extra read of one\n * hand-picked file, so it was done for one hand-picked file.\n */\n async conflictMarkers(path: string): Promise<number[]> {\n return conflictMarkerLines(await this.readText(path));\n }\n\n readRequirements(path: string): Promise<Requirement[]> {\n const k = key(path);\n let pending = this.requirements.get(k);\n if (pending === undefined) {\n this.counts.requirementParses += 1;\n pending = this.readText(path).then(parseRequirements);\n this.requirements.set(k, pending);\n }\n return pending;\n }\n\n readOpenapi(path: string): Promise<OpenapiDoc> {\n const k = key(path);\n let pending = this.openapis.get(k);\n if (pending === undefined) {\n this.counts.openapiParses += 1;\n pending = readOpenapi(path);\n this.openapis.set(k, pending);\n }\n return pending;\n }\n\n readAsyncapi(path: string): Promise<AsyncapiDoc> {\n const k = key(path);\n let pending = this.asyncapis.get(k);\n if (pending === undefined) {\n this.counts.asyncapiParses += 1;\n pending = readAsyncapi(path);\n this.asyncapis.set(k, pending);\n }\n return pending;\n }\n\n /**\n * The capability vocabulary, read once per invocation. Direction rule,\n * load-bearing: this file imports `capabilities/capabilities.js`, so nothing\n * under src/core/capabilities/ may import this module back — that edge is a\n * core-root↔capabilities package cycle `import/no-cycle` cannot see, which is\n * why the functions there take plain data or a `read` function, never a FleetContext.\n */\n capabilities(docsDir: DocsDir): Promise<CapabilityVocabulary> {\n const k = key(docsDir);\n let pending = this.capabilityVocabularies.get(k);\n if (pending === undefined) {\n this.counts.capabilityParses += 1;\n pending = readCapabilityVocabulary(docsDir);\n this.capabilityVocabularies.set(k, pending);\n }\n return pending;\n }\n\n /**\n * One feature's `capabilities/` delta tree, walked once per invocation. Two\n * readers ask for it in the same run — the delta-shape walk\n * (`core/delta/delta.ts`) and the capability overlay\n * (`core/coherence/declared.ts`) — and without the memo a feature carrying\n * three capability deltas paid the readdirs twice.\n *\n * The direction rule stated on `capabilities()` above applies verbatim: the\n * function this stands in front of takes a plain `FeatureDir`, never a\n * FleetContext, so `src/core/capabilities/` never imports this module back.\n */\n featureCapabilityDeltas(featureDir: FeatureDir): Promise<CapabilityTree> {\n const k = key(featureDir);\n let pending = this.featureCapabilities.get(k);\n if (pending === undefined) {\n this.counts.featureCapabilityWalks += 1;\n pending = featureCapabilityDeltas(featureDir);\n this.featureCapabilities.set(k, pending);\n }\n return pending;\n }\n\n async operations(path: string): Promise<Operation[]> {\n return (await this.readOpenapi(path)).ops;\n }\n\n async operationIds(path: string): Promise<string[]> {\n return (await this.readOpenapi(path)).ops.map((op) => op.id);\n }\n\n /*\n * Deliberately no `serviceOperationIds` here. The living-plus-feature union is\n * a RULE — every removal applied before any upsert — not a read, and a second\n * copy of a rule is a second chance to spell it differently. This one did: it\n * interleaved removals with upserts, so a relocated operation answered\n * \"defined\" through `archive` (no context) and \"gone\" through `validate` and\n * `status` (context), or the reverse, depending on the order the feature's\n * YAML happened to spell the two slots in. `core/openapi/doc.ts` owns the rule and\n * threads a context through the reads underneath it, which is the only part\n * this class was ever needed for.\n */\n\n loadLikeC4(path: string): Promise<LoadedDoc> {\n const k = key(path);\n let pending = this.likec4.get(k);\n if (pending === undefined) {\n this.counts.likec4Loads += 1;\n pending = loadFile(path);\n this.likec4.set(k, pending);\n }\n return pending;\n }\n\n /**\n * Parse many `.likec4` documents through ONE shared workspace (`loadBatch`)\n * and seed the memo above, so every later `loadLikeC4` in this invocation is\n * a hit. Purely an accelerator: the cache is still this instance's — one\n * invocation, one snapshot, no module state — and the counter still means\n * \"documents parsed via LikeC4\", incremented once per batch-parsed document.\n *\n * The failure story is the contract here. A batch-INFRASTRUCTURE failure —\n * a sandboxed runner denying tmpdir writes is the environment class ROADMAP\n * documents — degrades to today's per-path loads by seeding nothing: never\n * an error, and never fewer findings, only the old speed. A path the batch\n * could not stage (missing, unreadable) is simply absent from the result, so\n * the later `loadLikeC4` reproduces today's per-path error exactly. And\n * fewer than two misses returns without a workspace at all: one document\n * gains nothing from batch isolation it already has.\n */\n async prefetchLikeC4(paths: string[]): Promise<void> {\n const missing = [...new Set(paths.map(key))].filter((k) => !this.likec4.has(k));\n if (missing.length < 2) return;\n let docs: Map<string, LoadedDoc>;\n try {\n docs = await loadBatch(missing);\n } catch {\n return;\n }\n for (const [k, doc] of docs) {\n // Keyed by the same `key()` as loadLikeC4 — loadBatch resolves paths the\n // identical way, and `missing` was already resolved, so this holds by\n // construction; the has() guard keeps a concurrent load's promise\n // authoritative rather than double-counting the parse.\n if (this.likec4.has(k)) continue;\n this.counts.likec4Loads += 1;\n this.likec4.set(k, Promise.resolve(doc));\n }\n }\n}\n"]}
1
+ {"version":3,"file":"fleet-context.js","sourceRoot":"","sources":["../../src/core/fleet-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oB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CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;YAC5B,yEAAyE;YACzE,sEAAsE;YACtE,kEAAkE;YAClE,uDAAuD;YACvD,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,SAAS;YACjC,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,qGAAqG;IACrG,YAAY,CAAC,OAAgB;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,KAAwB;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,OAAgB,EAAE,KAAmB;QAChD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,qBAAqB,CAAC,OAAgB,EAAE,KAA8B;QAC1E,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;CACF","sourcesContent":["/**\n * Request-scoped read index for commands that walk a whole loam repository.\n *\n * The filesystem remains the source of truth. This class deliberately has no\n * singleton/global instance: a command creates one after loading loam.json and\n * drops it when that invocation finishes. Within that lifetime identical\n * reads share their in-flight Promise, which removes both duplicate I/O and\n * duplicate parsing without making a later CLI invocation observe stale data.\n *\n * Because every markdown artifact is read HERE, this is also where the two\n * failures a read must never swallow are answered: bytes that are not UTF-8\n * (which `readFile(path, \"utf8\")` silently turns into U+FFFD, so a UTF-16\n * spec.md parses as zero requirements and grades green), and git conflict\n * markers left in a living document (which parse as prose, and which the next\n * `loam archive` rewrites away). One place, so no reader can forget. Both\n * RULES live in leaves — the decode in `document-bytes.ts`, the marker scan\n * and its findings in `conflict-markers.ts` — because the parsers and graders\n * that touch a single file without an index owe the same rules, and must not\n * have to import this module — and the fleet it pulls in behind it — to obey\n * them.\n */\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { readAsyncapi } from \"./asyncapi/read.js\";\nimport type { AsyncapiDoc } from \"./asyncapi/model.js\";\nimport { readCapabilityVocabulary, type CapabilityVocabulary } from \"./capabilities/capabilities.js\";\nimport { featureCapabilityDeltas } from \"./capabilities/delta/tree.js\";\nimport type { CapabilityTree } from \"./capabilities/tree.js\";\nimport { conflictMarkerLines } from \"./conflict-markers.js\";\nimport { decodeDocument } from \"./kernel/document-bytes.js\";\nimport { loadFile, type LoadedDoc } from \"./c4/likec4.js\";\nimport { loadBatch } from \"./c4/workspace.js\";\nimport { ServiceModels } from \"./c4/prefetch/fleet.js\";\nimport type { ServiceModel } from \"./c4/service-model/load.js\";\nimport type { ModelShape } from \"./c4/service-model/shape.js\";\nimport type { ServicePaths } from \"./repo/paths.js\";\nimport { readOpenapi, type OpenapiDoc, type Operation } from \"./openapi/doc.js\";\nimport type { RawServiceId } from \"./kernel/ids/service.js\";\nimport { type FeatureEntry, type ServiceEntry } from \"./repo/entries.js\";\nimport { featureSpecServices, listFeatures, listFleetTree, serviceEntries } from \"./repo/repo.js\";\nimport type { FleetTree } from \"./repo/tree/walk.js\";\nimport { parseRequirements } from \"./document/parse.js\";\nimport { type Requirement } from \"./document/spec.js\";\nimport type { DocsDir, FeatureDir } from \"./kernel/ids/dirs.js\";\n\nexport interface FleetContextStats {\n serviceEnumerations: number;\n featureEnumerations: number;\n featureServiceEnumerations: number;\n textReads: number;\n requirementParses: number;\n openapiParses: number;\n /**\n * Reads of a service's `asyncapi.yaml`. Counted separately because this axis\n * is the one that makes a per-service run read the whole fleet: \"does anybody\n * publish this message\" has no local answer, so `spine.message-unproduced`\n * walks every service's contract. The memo is what keeps that one walk per\n * command instead of one per consuming edge.\n */\n asyncapiParses: number;\n /**\n * Reads of the capability vocabulary — `architecture/capabilities.yaml` AND\n * the `capabilities/` walk, which are one vocabulary and so one read. One per\n * invocation is the capability axis's exit criterion, and this counter is how\n * a test pins it. (Permissions predates the memo and re-parses per service —\n * do not copy that.)\n */\n capabilityParses: number;\n /**\n * Walks of ONE feature's `capabilities/` delta tree. Counted apart from\n * `capabilityParses` because it answers a different question about a\n * different directory, and because a fleet that has not adopted the business\n * axis must be able to prove it pays nothing: every feature's walk is a\n * single `existsSync` that finds no directory, so this counter rises while\n * `textReads` and `requirementParses` do not.\n */\n featureCapabilityWalks: number;\n likec4Loads: number;\n /**\n * PER-SERVICE PROJECTS parsed — the map plus one extending model, staged\n * together (`c4/service-model/`). Apart from `likec4Loads` because they are\n * different units: that counter means documents parsed alone, and a fleet\n * whose models all extend the map moves every unit to this one. One project\n * per service is the axis's exit criterion, and this is how a test pins it.\n */\n projectLoads: number;\n}\n\nconst key = (path: string): string => resolve(path);\n\n/** One coherent filesystem snapshot for one command invocation. */\nexport class FleetContext {\n private readonly trees = new Map<string, Promise<FleetTree>>();\n private readonly services = new Map<string, Promise<ServiceEntry[]>>();\n private readonly features = new Map<string, Promise<FeatureEntry[]>>();\n private readonly featureServices = new Map<string, Promise<RawServiceId[]>>();\n private readonly texts = new Map<string, Promise<string>>();\n private readonly requirements = new Map<string, Promise<Requirement[]>>();\n private readonly openapis = new Map<string, Promise<OpenapiDoc>>();\n private readonly asyncapis = new Map<string, Promise<AsyncapiDoc>>();\n private readonly capabilityVocabularies = new Map<string, Promise<CapabilityVocabulary>>();\n private readonly featureCapabilities = new Map<string, Promise<CapabilityTree>>();\n private readonly likec4 = new Map<string, Promise<LoadedDoc>>();\n /**\n * The service-model axis's own memos, one object because the rules they\n * encode are `c4/prefetch/fleet.ts`'s rather than this class's. It counts\n * through this instance's counter, so `stats()` stays the one place a caller\n * reads what an invocation cost.\n */\n private readonly models = new ServiceModels({\n onProjectLoad: () => {\n this.counts.projectLoads += 1;\n },\n known: async (docsDir) => new Set((await this.listServices(docsDir)).map((s) => s.id)),\n standalone: (path) => this.loadLikeC4(path),\n });\n\n private readonly counts: FleetContextStats = {\n serviceEnumerations: 0,\n featureEnumerations: 0,\n featureServiceEnumerations: 0,\n textReads: 0,\n requirementParses: 0,\n openapiParses: 0,\n asyncapiParses: 0,\n capabilityParses: 0,\n featureCapabilityWalks: 0,\n likec4Loads: 0,\n projectLoads: 0,\n };\n\n /** A copy suitable for diagnostics/tests; callers cannot mutate the counters. */\n stats(): Readonly<FleetContextStats> {\n return { ...this.counts };\n }\n\n /**\n * The classified `services/` tree — the ONE enumeration this invocation\n * performs. `listServices` below derives its entries from this memo, so a\n * command that asks for both the fleet and the tree's findings (`validate\n * --all` does) still walks the directories exactly once. The counter keeps\n * its historical meaning — walks of `services/` — it just counts the walk\n * where the walk now happens.\n */\n fleetTree(docsDir: DocsDir): Promise<FleetTree> {\n const k = key(docsDir);\n let pending = this.trees.get(k);\n if (pending === undefined) {\n this.counts.serviceEnumerations += 1;\n pending = listFleetTree(docsDir);\n this.trees.set(k, pending);\n }\n return pending;\n }\n\n listServices(docsDir: DocsDir): Promise<ServiceEntry[]> {\n const k = key(docsDir);\n let pending = this.services.get(k);\n if (pending === undefined) {\n pending = this.fleetTree(docsDir).then(serviceEntries);\n this.services.set(k, pending);\n }\n return pending;\n }\n\n listFeatures(docsDir: DocsDir, opts: { includeArchived?: boolean } = {}): Promise<FeatureEntry[]> {\n const k = `${key(docsDir)}\\0${opts.includeArchived === true ? \"all\" : \"active\"}`;\n let pending = this.features.get(k);\n if (pending === undefined) {\n this.counts.featureEnumerations += 1;\n pending = listFeatures(docsDir, opts).then((entries) => {\n // listFeatures has already enumerated every feature's specs/ directory;\n // seed the narrower lookup so validation/coherence do not read it again.\n for (const entry of entries) {\n const featureKey = key(entry.dir);\n if (!this.featureServices.has(featureKey)) {\n this.featureServices.set(featureKey, Promise.resolve(entry.services));\n }\n }\n return entries;\n });\n this.features.set(k, pending);\n }\n return pending;\n }\n\n featureSpecServices(featureDir: FeatureDir): Promise<RawServiceId[]> {\n const k = key(featureDir);\n let pending = this.featureServices.get(k);\n if (pending === undefined) {\n this.counts.featureServiceEnumerations += 1;\n pending = featureSpecServices(featureDir);\n this.featureServices.set(k, pending);\n }\n return pending;\n }\n\n /**\n * A markdown artifact as text. Bytes in, decoded once, and refused rather\n * than degraded when they are not UTF-8 — see NotUtf8DocumentError.\n */\n readText(path: string): Promise<string> {\n const k = key(path);\n let pending = this.texts.get(k);\n if (pending === undefined) {\n this.counts.textReads += 1;\n pending = readFile(path).then((bytes) => decodeDocument(bytes, path));\n this.texts.set(k, pending);\n }\n return pending;\n }\n\n /**\n * Git conflict markers in an already-read document, by line. Free for any\n * caller that was going to read the file anyway — which is every caller,\n * which is the point: the marker check used to cost a whole extra read of one\n * hand-picked file, so it was done for one hand-picked file.\n */\n async conflictMarkers(path: string): Promise<number[]> {\n return conflictMarkerLines(await this.readText(path));\n }\n\n readRequirements(path: string): Promise<Requirement[]> {\n const k = key(path);\n let pending = this.requirements.get(k);\n if (pending === undefined) {\n this.counts.requirementParses += 1;\n pending = this.readText(path).then(parseRequirements);\n this.requirements.set(k, pending);\n }\n return pending;\n }\n\n readOpenapi(path: string): Promise<OpenapiDoc> {\n const k = key(path);\n let pending = this.openapis.get(k);\n if (pending === undefined) {\n this.counts.openapiParses += 1;\n pending = readOpenapi(path);\n this.openapis.set(k, pending);\n }\n return pending;\n }\n\n readAsyncapi(path: string): Promise<AsyncapiDoc> {\n const k = key(path);\n let pending = this.asyncapis.get(k);\n if (pending === undefined) {\n this.counts.asyncapiParses += 1;\n pending = readAsyncapi(path);\n this.asyncapis.set(k, pending);\n }\n return pending;\n }\n\n /**\n * The capability vocabulary, read once per invocation. Direction rule,\n * load-bearing: this file imports `capabilities/capabilities.js`, so nothing\n * under src/core/capabilities/ may import this module back — that edge is a\n * core-root↔capabilities package cycle `import/no-cycle` cannot see, which is\n * why the functions there take plain data or a `read` function, never a FleetContext.\n */\n capabilities(docsDir: DocsDir): Promise<CapabilityVocabulary> {\n const k = key(docsDir);\n let pending = this.capabilityVocabularies.get(k);\n if (pending === undefined) {\n this.counts.capabilityParses += 1;\n pending = readCapabilityVocabulary(docsDir);\n this.capabilityVocabularies.set(k, pending);\n }\n return pending;\n }\n\n /**\n * One feature's `capabilities/` delta tree, walked once per invocation. Two\n * readers ask for it in the same run — the delta-shape walk\n * (`core/delta/delta.ts`) and the capability overlay\n * (`core/coherence/declared.ts`) — and without the memo a feature carrying\n * three capability deltas paid the readdirs twice.\n *\n * The direction rule stated on `capabilities()` above applies verbatim: the\n * function this stands in front of takes a plain `FeatureDir`, never a\n * FleetContext, so `src/core/capabilities/` never imports this module back.\n */\n featureCapabilityDeltas(featureDir: FeatureDir): Promise<CapabilityTree> {\n const k = key(featureDir);\n let pending = this.featureCapabilities.get(k);\n if (pending === undefined) {\n this.counts.featureCapabilityWalks += 1;\n pending = featureCapabilityDeltas(featureDir);\n this.featureCapabilities.set(k, pending);\n }\n return pending;\n }\n\n async operations(path: string): Promise<Operation[]> {\n return (await this.readOpenapi(path)).ops;\n }\n\n async operationIds(path: string): Promise<string[]> {\n return (await this.readOpenapi(path)).ops.map((op) => op.id);\n }\n\n /*\n * Deliberately no `serviceOperationIds` here. The living-plus-feature union is\n * a RULE — every removal applied before any upsert — not a read, and a second\n * copy of a rule is a second chance to spell it differently. This one did: it\n * interleaved removals with upserts, so a relocated operation answered\n * \"defined\" through `archive` (no context) and \"gone\" through `validate` and\n * `status` (context), or the reverse, depending on the order the feature's\n * YAML happened to spell the two slots in. `core/openapi/doc.ts` owns the rule and\n * threads a context through the reads underneath it, which is the only part\n * this class was ever needed for.\n */\n\n loadLikeC4(path: string): Promise<LoadedDoc> {\n const k = key(path);\n let pending = this.likec4.get(k);\n if (pending === undefined) {\n this.counts.likec4Loads += 1;\n pending = loadFile(path);\n this.likec4.set(k, pending);\n }\n return pending;\n }\n\n /**\n * Parse many `.likec4` documents through ONE shared workspace (`loadBatch`)\n * and seed the memo above, so every later `loadLikeC4` in this invocation is\n * a hit. Purely an accelerator: the cache is still this instance's — one\n * invocation, one snapshot, no module state — and the counter still means\n * \"documents parsed via LikeC4\", incremented once per batch-parsed document.\n *\n * The failure story is the contract here. A batch-INFRASTRUCTURE failure —\n * a sandboxed runner denying tmpdir writes is the environment class ROADMAP\n * documents — degrades to today's per-path loads by seeding nothing: never\n * an error, and never fewer findings, only the old speed. A path the batch\n * could not stage (missing, unreadable) is simply absent from the result, so\n * the later `loadLikeC4` reproduces today's per-path error exactly. And\n * fewer than two misses returns without a workspace at all: one document\n * gains nothing from batch isolation it already has.\n */\n async prefetchLikeC4(paths: string[]): Promise<void> {\n const missing = [...new Set(paths.map(key))].filter((k) => !this.likec4.has(k));\n if (missing.length < 2) return;\n let docs: Map<string, LoadedDoc>;\n try {\n docs = await loadBatch(missing);\n } catch {\n return;\n }\n for (const [k, doc] of docs) {\n // Keyed by the same `key()` as loadLikeC4 — loadBatch resolves paths the\n // identical way, and `missing` was already resolved, so this holds by\n // construction; the has() guard keeps a concurrent load's promise\n // authoritative rather than double-counting the parse.\n if (this.likec4.has(k)) continue;\n this.counts.likec4Loads += 1;\n this.likec4.set(k, Promise.resolve(doc));\n }\n }\n\n /** The fleet map as the PROJECT it is — landscape plus use cases, minus the generated views file. */\n architecture(docsDir: DocsDir): Promise<LoadedDoc> {\n return this.models.architecture(docsDir);\n }\n\n /**\n * Which shape each of these models has, keyed by resolved path — one read of\n * each file's bytes per invocation. Ask over the FULL enumeration, never a\n * narrowed run's subset: shapes decide which directories are owed a\n * per-service `likec4.config.json`, and a partial map answers \"not\n * standalone\" for every service outside it.\n */\n modelShapes(paths: readonly string[]): Promise<Map<string, ModelShape>> {\n return this.models.shapes(paths);\n }\n\n /**\n * A service's C4 model, read the way its own SHAPE demands — the one entry\n * point for every reader of `model.likec4`, standalone or extending\n * (`c4/service-model/load.ts` states the four arms and why each exists).\n */\n serviceModel(docsDir: DocsDir, paths: ServicePaths): Promise<ServiceModel> {\n return this.models.model(docsDir, paths);\n }\n\n /**\n * Every service's model prepared in two workspaces whatever the fleet's mix:\n * the extending ones as one project each in one of them, the standalone ones\n * through the document batch above. An accelerator with `prefetchLikeC4`'s\n * failure story exactly — a batch that could not be created seeds nothing, so\n * findings never change because of a tmpdir, only the speed does.\n */\n async prefetchServiceModels(docsDir: DocsDir, paths: readonly ServicePaths[]): Promise<void> {\n await this.prefetchLikeC4(await this.models.prefetch(docsDir, paths));\n }\n}\n"]}
@@ -111,7 +111,11 @@ function partnersFindings(scan, service) {
111
111
  for (const p of scan.partners) {
112
112
  // An `#external` partner is somebody else's system: its side of the join
113
113
  // is unrecorded ON PURPOSE, the same exemption the landscape census grants
114
- // (`landscape.service-undocumented` skips #external too).
114
+ // (`landscape.service-undocumented` skips #external too). The fleet's own
115
+ // infrastructure — a `database`, `queue`, `topic`, `cache` or `bucket` — is
116
+ // not a partner at all and never reaches this loop: `./partners.ts` drops it
117
+ // from the SET, beside the actors, because the three remedies below are all
118
+ // false of a store the fleet runs.
115
119
  if (p.external)
116
120
  continue;
117
121
  if (p.maturity === null) {
@@ -1 +1 @@
1
- {"version":3,"file":"checks.js","sourceRoot":"","sources":["../../../src/core/gate/checks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAqB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EA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**\n * The four checks behind `loam gate` — a can-i-deploy-shaped PURE QUERY over\n * evidence other commands already recorded. Nothing here executes anything,\n * writes anything, takes the docs lock, or re-derives a coherence plan: every\n * answer is either already on disk (verification.yaml, vouch stamps, the\n * commit journal) or a presence/landscape fact the enumeration carries.\n *\n * partners the landscape's direct joins, both ends graded on the ladder\n * freshness content.stale / sources.stale over the target and partners,\n * plus the one integrity error that makes freshness\n * unjudgeable (frontmatter.malformed) and a refusing decode\n * of the spec bytes themselves\n * verification verificationState per active feature touching the service\n * (its own module, `./verification.ts`)\n * interrupted the `.loam-commit` journal — the one repo state that poisons\n * every other answer above\n *\n * Every `gate.*` code is spelled as a literal `code:` property at its emit\n * site, never through a code-taking factory parameter — verifyStep\n * (core/status/verification.ts) records that test/codes-drift.test.ts's\n * collector is blind to the parameter form, and a refactor toward a factory\n * would silently undocument the family.\n */\nimport { existsSync } from \"node:fs\";\nimport { inOrder } from \"../kernel/concurrency.js\";\nimport { serviceProvenance } from \"../provenance/findings.js\";\nimport { interruptedCommitFinding } from \"../staging/recovery/finding.js\";\nimport { servicePathsAt, SPEC_AXES, type ServicePaths } from \"../repo/paths.js\";\nimport { serviceTreePath } from \"../kernel/ids/dirs.js\";\nimport { locateServicePaths } from \"../repo/service-target.js\";\nimport type { Finding } from \"../vocabulary/report.js\";\nimport type { FleetContext } from \"../fleet-context.js\";\nimport type { DocsDir } from \"../kernel/ids/dirs.js\";\nimport type { RawServiceId } from \"../kernel/ids/service.js\";\nimport { atLeastDocumented, partnerScan, type PartnerScan } from \"./partners.js\";\nimport { verificationCheck } from \"./verification.js\";\nimport { unreadableSubject, type GateCheck, type GateReport } from \"./report.js\";\n\nexport interface GateRequest {\n docsDir: DocsDir;\n /** The service being deployed — a name the enumeration approved. */\n service: RawServiceId;\n /**\n * The repository loam is standing in, passed ONLY when the gated service is\n * this repo's own binding — validate's `repoOf` rule: `sources` are paths\n * into a service's own repository, so `sources.stale` is honestly checkable\n * only there, while `content.stale` needs nothing but the document.\n */\n repoDir?: string;\n fleet: FleetContext;\n}\n\nexport async function gateReport(req: GateRequest): Promise<GateReport> {\n // The scan first, alone: freshness walks the partner set it derives. The\n // three remaining checks are independent of each other — different files,\n // memoized reads — so they run concurrently; only the scan must be ordered.\n const scan = await partnerScan({ docsDir: req.docsDir, service: req.service, fleet: req.fleet });\n const [freshness, verification, interrupted] = await Promise.all([\n freshnessFindings(req, scan),\n verificationCheck({ docsDir: req.docsDir, service: req.service, fleet: req.fleet }),\n interruptedCommitFinding(req.docsDir),\n ]);\n const checks: GateCheck[] = [\n { check: \"partners\", findings: partnersFindings(scan, req.service) },\n { check: \"freshness\", findings: freshness },\n { check: \"verification\", findings: verification.findings },\n { check: \"interrupted\", findings: interrupted === null ? [] : [interrupted] },\n ];\n return {\n service: req.service,\n landscape: scan.landscape,\n partners: scan.partners,\n features: verification.features,\n checks,\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* Check 1: partners */\n/* ------------------------------------------------------------------ */\n\nfunction partnersFindings(scan: PartnerScan, service: string): Finding[] {\n const findings: Finding[] = [];\n // \"Could not look\" must never read as \"no partners\" — the docsRepoReady\n // doctrine one level down. `validate --all` owns the diagnosis of the\n // landscape itself; this code only refuses the false silence. The two ways\n // of not looking are graded apart, the way `landscape.missing` and\n // `landscape.invalid` are: ABSENT is a warning — a repo before its first\n // adopt legitimately has no map yet — but a map that EXISTS and cannot be\n // parsed or read is an ERROR, because `validate --all` fails that repo\n // (`landscape.invalid`) and a deploy gate that passed where the fleet gate\n // fails would be the quieter of two contradictory verdicts.\n if (scan.landscape === \"absent\") {\n findings.push({\n severity: \"warn\",\n code: \"gate.partners-unknown\",\n message: `architecture/landscape.likec4 does not exist, so the partner set for '${service}' could not be derived — an absent map means nobody could look, not that nothing joins this service. \\`loam validate --all\\` diagnoses the landscape itself.`,\n });\n } else if (scan.landscape === \"invalid\") {\n findings.push({\n severity: \"error\",\n code: \"gate.partners-unknown\",\n message:\n `architecture/landscape.likec4 exists but cannot be used — ${scan.landscapeProblem ?? \"it did not parse\"} — so the partner set for '${service}' could not be derived. ` +\n `A broken map means nobody could look, not that nothing joins this service, and \\`loam validate --all\\` fails this repo for the same file. Fix the landscape, then re-run.`,\n });\n }\n // The rung depends on the landscape only through the api question (does\n // anything call this service?). With no readable map that question is\n // unanswerable, and the fail-closed grading — `landscapeEvidence`: no proof\n // means an API is expected — would convict a worker or UI for a contract\n // nobody may be owed. One unanswerable fact yields ONE finding (the\n // landscape's own, above), so under an unreadable map this error fires only\n // when the service is below `documented` REGARDLESS of the api question.\n const target = scan.landscape === \"read\" ? scan.target : scan.targetWithoutApi;\n if (!atLeastDocumented(target.maturity)) {\n findings.push({\n severity: \"error\",\n code: \"gate.service-undocumented\",\n subject: service,\n message:\n `${serviceTreePath(scan.targetEntry)}/ sits at '${target.maturity}' on the adoption ladder — below 'documented', the docs cannot say what its joins even are, so no recorded evidence can answer the deploy question. ` +\n `Author the baseline (\\`loam adopt --service ${service}\\` briefs it); this check passes once the required artifact set exists.`,\n details: target.gaps,\n text: { detailPrefix: \"- \" },\n });\n }\n // The partners that HAVE a directory, by id: their findings name it, and it\n // is `services/<subsystem>/<id>/` for a filed one. The no-directory branch\n // below keeps the bare `services/<id>/` spelling deliberately — there is no\n // directory to name, and the unfiled form is what the fix would create.\n const partnerPath = new Map(scan.partnerEntries.map((e) => [e.id as string, serviceTreePath(e)]));\n for (const p of scan.partners) {\n // An `#external` partner is somebody else's system: its side of the join\n // is unrecorded ON PURPOSE, the same exemption the landscape census grants\n // (`landscape.service-undocumented` skips #external too).\n if (p.external) continue;\n if (p.maturity === null) {\n findings.push({\n severity: \"warn\",\n code: \"gate.partner-undocumented\",\n subject: p.service,\n message:\n `'${p.service}' joins '${service}' (${p.via.join(\", \")}) but has no services/${p.service}/ directory — its side of the join is unrecorded. ` +\n `Adopt it, bind its landscape element to the right service with metadata { service '<id>' }, or tag it #external if it is not ours.`,\n details: p.via,\n });\n } else if (!atLeastDocumented(p.maturity)) {\n findings.push({\n severity: \"warn\",\n code: \"gate.partner-undocumented\",\n subject: p.service,\n message:\n `${partnerPath.get(p.service) ?? `services/${p.service}`}/ sits at '${p.maturity}' — below 'documented' — while it joins '${service}' (${p.via.join(\", \")}): its side of the join is not fully recorded. \\`loam adopt --service ${p.service}\\` briefs what is missing.`,\n details: p.via,\n });\n }\n }\n return findings;\n}\n\n/* ------------------------------------------------------------------ */\n/* Check 2: freshness */\n/* ------------------------------------------------------------------ */\n\n/**\n * `serviceProvenance` filtered to the two staleness codes plus the ONE\n * integrity error that makes freshness unjudgeable: `frontmatter.malformed`.\n * A header YAML refuses to parse cannot certify a `content_digest`, and\n * dropping that error read \"cannot judge\" as \"nothing stale\" — the exact\n * fail-open a deploy gate must not have. Everything else provenance grades\n * (missing owners, unstamped sources, absent frontmatter) is `validate`'s\n * report to make — a deploy gate that repeated it would drown the findings a\n * pipeline can actually act on at deploy time.\n */\nasync function freshnessFindings(req: GateRequest, scan: PartnerScan): Promise<Finding[]> {\n const subjects: { id: RawServiceId; repoDir: string | undefined; paths: ServicePaths }[] = [\n {\n id: req.service,\n repoDir: req.repoDir,\n paths: await locateServicePaths(req.docsDir, req.service, req.fleet),\n },\n // Only the DOCUMENTED partners: a partner with no directory has nothing to\n // grade, and already carries gate.partner-undocumented from check 1.\n ...scan.partnerEntries.map((e) => ({\n id: e.id,\n repoDir: undefined,\n paths: servicePathsAt(e.dir),\n })),\n ];\n // Independent per-subject reads through the shared memo; inOrder keeps the\n // findings in subject order (target first, partners sorted) so identical\n // state yields identical bytes.\n const graded = await inOrder(subjects, async (s) => {\n try {\n // The integrity gate serviceProvenance cannot give: its own reads decode\n // with 'utf8', which silently turns UTF-16 bytes into replacement\n // characters — the file then grades as having no frontmatter at all (a\n // warning this check does not retain), and mangled bytes read as\n // \"nothing stale\". So both spec axes are decoded FIRST through the\n // invocation's read index, whose decoder refuses non-UTF-8 naming the\n // file (NotUtf8DocumentError spells `path` the way Node does, so the\n // containment below names it without knowing the type).\n for (const axis of SPEC_AXES) {\n const path = s.paths[axis.key];\n if (existsSync(path)) await req.fleet.readText(path);\n }\n const all = await serviceProvenance(req.docsDir, s.id, { repoDir: s.repoDir, fleet: req.fleet });\n return all\n .filter(\n (f) =>\n f.code === \"content.stale\" ||\n f.code === \"sources.stale\" ||\n f.code === \"frontmatter.malformed\",\n )\n // The staleness emitters name the file in the message but set no\n // subject; the payload's per-service attribution should not make a\n // caller parse it back out of prose.\n .map((f) => (f.subject === undefined ? { ...f, subject: s.id } : f));\n } catch (err) {\n return [unreadableSubject(\"service\", s.id, err)];\n }\n });\n return graded.flat();\n}\n"]}
1
+ {"version":3,"file":"checks.js","sourceRoot":"","sources":["../../../src/core/gate/checks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,SAAS,EAAqB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAK/D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAoB,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAmC,MAAM,aAAa,CAAC;AAgBjF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAgB;IAC/C,yEAAyE;IACzE,0EAA0E;IAC1E,4EAA4E;IAC5E,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC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GAAG,MAAM,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;YACjG,OAAO,GAAG;iBACP,MAAM,CACL,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI,KAAK,eAAe;gBAC1B,CAAC,CAAC,IAAI,KAAK,eAAe;gBAC1B,CAAC,CAAC,IAAI,KAAK,uBAAuB,CACrC;gBACD,iEAAiE;gBACjE,mEAAmE;gBACnE,qCAAqC;iBACpC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACzE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,iBAAiB,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC","sourcesContent":["/**\n * The four checks behind `loam gate` — a can-i-deploy-shaped PURE QUERY over\n * evidence other commands already recorded. Nothing here executes anything,\n * writes anything, takes the docs lock, or re-derives a coherence plan: every\n * answer is either already on disk (verification.yaml, vouch stamps, the\n * commit journal) or a presence/landscape fact the enumeration carries.\n *\n * partners the landscape's direct joins, both ends graded on the ladder\n * freshness content.stale / sources.stale over the target and partners,\n * plus the one integrity error that makes freshness\n * unjudgeable (frontmatter.malformed) and a refusing decode\n * of the spec bytes themselves\n * verification verificationState per active feature touching the service\n * (its own module, `./verification.ts`)\n * interrupted the `.loam-commit` journal — the one repo state that poisons\n * every other answer above\n *\n * Every `gate.*` code is spelled as a literal `code:` property at its emit\n * site, never through a code-taking factory parameter — verifyStep\n * (core/status/verification.ts) records that test/codes-drift.test.ts's\n * collector is blind to the parameter form, and a refactor toward a factory\n * would silently undocument the family.\n */\nimport { existsSync } from \"node:fs\";\nimport { inOrder } from \"../kernel/concurrency.js\";\nimport { serviceProvenance } from \"../provenance/findings.js\";\nimport { interruptedCommitFinding } from \"../staging/recovery/finding.js\";\nimport { servicePathsAt, SPEC_AXES, type ServicePaths } from \"../repo/paths.js\";\nimport { serviceTreePath } from \"../kernel/ids/dirs.js\";\nimport { locateServicePaths } from \"../repo/service-target.js\";\nimport type { Finding } from \"../vocabulary/report.js\";\nimport type { FleetContext } from \"../fleet-context.js\";\nimport type { DocsDir } from \"../kernel/ids/dirs.js\";\nimport type { RawServiceId } from \"../kernel/ids/service.js\";\nimport { atLeastDocumented, partnerScan, type PartnerScan } from \"./partners.js\";\nimport { verificationCheck } from \"./verification.js\";\nimport { unreadableSubject, type GateCheck, type GateReport } from \"./report.js\";\n\nexport interface GateRequest {\n docsDir: DocsDir;\n /** The service being deployed — a name the enumeration approved. */\n service: RawServiceId;\n /**\n * The repository loam is standing in, passed ONLY when the gated service is\n * this repo's own binding — validate's `repoOf` rule: `sources` are paths\n * into a service's own repository, so `sources.stale` is honestly checkable\n * only there, while `content.stale` needs nothing but the document.\n */\n repoDir?: string;\n fleet: FleetContext;\n}\n\nexport async function gateReport(req: GateRequest): Promise<GateReport> {\n // The scan first, alone: freshness walks the partner set it derives. The\n // three remaining checks are independent of each other — different files,\n // memoized reads — so they run concurrently; only the scan must be ordered.\n const scan = await partnerScan({ docsDir: req.docsDir, service: req.service, fleet: req.fleet });\n const [freshness, verification, interrupted] = await Promise.all([\n freshnessFindings(req, scan),\n verificationCheck({ docsDir: req.docsDir, service: req.service, fleet: req.fleet }),\n interruptedCommitFinding(req.docsDir),\n ]);\n const checks: GateCheck[] = [\n { check: \"partners\", findings: partnersFindings(scan, req.service) },\n { check: \"freshness\", findings: freshness },\n { check: \"verification\", findings: verification.findings },\n { check: \"interrupted\", findings: interrupted === null ? [] : [interrupted] },\n ];\n return {\n service: req.service,\n landscape: scan.landscape,\n partners: scan.partners,\n features: verification.features,\n checks,\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* Check 1: partners */\n/* ------------------------------------------------------------------ */\n\nfunction partnersFindings(scan: PartnerScan, service: string): Finding[] {\n const findings: Finding[] = [];\n // \"Could not look\" must never read as \"no partners\" — the docsRepoReady\n // doctrine one level down. `validate --all` owns the diagnosis of the\n // landscape itself; this code only refuses the false silence. The two ways\n // of not looking are graded apart, the way `landscape.missing` and\n // `landscape.invalid` are: ABSENT is a warning — a repo before its first\n // adopt legitimately has no map yet — but a map that EXISTS and cannot be\n // parsed or read is an ERROR, because `validate --all` fails that repo\n // (`landscape.invalid`) and a deploy gate that passed where the fleet gate\n // fails would be the quieter of two contradictory verdicts.\n if (scan.landscape === \"absent\") {\n findings.push({\n severity: \"warn\",\n code: \"gate.partners-unknown\",\n message: `architecture/landscape.likec4 does not exist, so the partner set for '${service}' could not be derived — an absent map means nobody could look, not that nothing joins this service. \\`loam validate --all\\` diagnoses the landscape itself.`,\n });\n } else if (scan.landscape === \"invalid\") {\n findings.push({\n severity: \"error\",\n code: \"gate.partners-unknown\",\n message:\n `architecture/landscape.likec4 exists but cannot be used — ${scan.landscapeProblem ?? \"it did not parse\"} — so the partner set for '${service}' could not be derived. ` +\n `A broken map means nobody could look, not that nothing joins this service, and \\`loam validate --all\\` fails this repo for the same file. Fix the landscape, then re-run.`,\n });\n }\n // The rung depends on the landscape only through the api question (does\n // anything call this service?). With no readable map that question is\n // unanswerable, and the fail-closed grading — `landscapeEvidence`: no proof\n // means an API is expected — would convict a worker or UI for a contract\n // nobody may be owed. One unanswerable fact yields ONE finding (the\n // landscape's own, above), so under an unreadable map this error fires only\n // when the service is below `documented` REGARDLESS of the api question.\n const target = scan.landscape === \"read\" ? scan.target : scan.targetWithoutApi;\n if (!atLeastDocumented(target.maturity)) {\n findings.push({\n severity: \"error\",\n code: \"gate.service-undocumented\",\n subject: service,\n message:\n `${serviceTreePath(scan.targetEntry)}/ sits at '${target.maturity}' on the adoption ladder — below 'documented', the docs cannot say what its joins even are, so no recorded evidence can answer the deploy question. ` +\n `Author the baseline (\\`loam adopt --service ${service}\\` briefs it); this check passes once the required artifact set exists.`,\n details: target.gaps,\n text: { detailPrefix: \"- \" },\n });\n }\n // The partners that HAVE a directory, by id: their findings name it, and it\n // is `services/<subsystem>/<id>/` for a filed one. The no-directory branch\n // below keeps the bare `services/<id>/` spelling deliberately — there is no\n // directory to name, and the unfiled form is what the fix would create.\n const partnerPath = new Map(scan.partnerEntries.map((e) => [e.id as string, serviceTreePath(e)]));\n for (const p of scan.partners) {\n // An `#external` partner is somebody else's system: its side of the join\n // is unrecorded ON PURPOSE, the same exemption the landscape census grants\n // (`landscape.service-undocumented` skips #external too). The fleet's own\n // infrastructure — a `database`, `queue`, `topic`, `cache` or `bucket` — is\n // not a partner at all and never reaches this loop: `./partners.ts` drops it\n // from the SET, beside the actors, because the three remedies below are all\n // false of a store the fleet runs.\n if (p.external) continue;\n if (p.maturity === null) {\n findings.push({\n severity: \"warn\",\n code: \"gate.partner-undocumented\",\n subject: p.service,\n message:\n `'${p.service}' joins '${service}' (${p.via.join(\", \")}) but has no services/${p.service}/ directory — its side of the join is unrecorded. ` +\n `Adopt it, bind its landscape element to the right service with metadata { service '<id>' }, or tag it #external if it is not ours.`,\n details: p.via,\n });\n } else if (!atLeastDocumented(p.maturity)) {\n findings.push({\n severity: \"warn\",\n code: \"gate.partner-undocumented\",\n subject: p.service,\n message:\n `${partnerPath.get(p.service) ?? `services/${p.service}`}/ sits at '${p.maturity}' — below 'documented' — while it joins '${service}' (${p.via.join(\", \")}): its side of the join is not fully recorded. \\`loam adopt --service ${p.service}\\` briefs what is missing.`,\n details: p.via,\n });\n }\n }\n return findings;\n}\n\n/* ------------------------------------------------------------------ */\n/* Check 2: freshness */\n/* ------------------------------------------------------------------ */\n\n/**\n * `serviceProvenance` filtered to the two staleness codes plus the ONE\n * integrity error that makes freshness unjudgeable: `frontmatter.malformed`.\n * A header YAML refuses to parse cannot certify a `content_digest`, and\n * dropping that error read \"cannot judge\" as \"nothing stale\" — the exact\n * fail-open a deploy gate must not have. Everything else provenance grades\n * (missing owners, unstamped sources, absent frontmatter) is `validate`'s\n * report to make — a deploy gate that repeated it would drown the findings a\n * pipeline can actually act on at deploy time.\n */\nasync function freshnessFindings(req: GateRequest, scan: PartnerScan): Promise<Finding[]> {\n const subjects: { id: RawServiceId; repoDir: string | undefined; paths: ServicePaths }[] = [\n {\n id: req.service,\n repoDir: req.repoDir,\n paths: await locateServicePaths(req.docsDir, req.service, req.fleet),\n },\n // Only the DOCUMENTED partners: a partner with no directory has nothing to\n // grade, and already carries gate.partner-undocumented from check 1.\n ...scan.partnerEntries.map((e) => ({\n id: e.id,\n repoDir: undefined,\n paths: servicePathsAt(e.dir),\n })),\n ];\n // Independent per-subject reads through the shared memo; inOrder keeps the\n // findings in subject order (target first, partners sorted) so identical\n // state yields identical bytes.\n const graded = await inOrder(subjects, async (s) => {\n try {\n // The integrity gate serviceProvenance cannot give: its own reads decode\n // with 'utf8', which silently turns UTF-16 bytes into replacement\n // characters — the file then grades as having no frontmatter at all (a\n // warning this check does not retain), and mangled bytes read as\n // \"nothing stale\". So both spec axes are decoded FIRST through the\n // invocation's read index, whose decoder refuses non-UTF-8 naming the\n // file (NotUtf8DocumentError spells `path` the way Node does, so the\n // containment below names it without knowing the type).\n for (const axis of SPEC_AXES) {\n const path = s.paths[axis.key];\n if (existsSync(path)) await req.fleet.readText(path);\n }\n const all = await serviceProvenance(req.docsDir, s.id, { repoDir: s.repoDir, fleet: req.fleet });\n return all\n .filter(\n (f) =>\n f.code === \"content.stale\" ||\n f.code === \"sources.stale\" ||\n f.code === \"frontmatter.malformed\",\n )\n // The staleness emitters name the file in the message but set no\n // subject; the payload's per-service attribution should not make a\n // caller parse it back out of prose.\n .map((f) => (f.subject === undefined ? { ...f, subject: s.id } : f));\n } catch (err) {\n return [unreadableSubject(\"service\", s.id, err)];\n }\n });\n return graded.flat();\n}\n"]}