@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,194 +1,277 @@
1
1
  /**
2
- * The fleet-map half of the adoption brief: what `architecture/landscape.likec4`
2
+ * The fleet-map half of the adoption brief, READ side: what the fleet map
3
3
  * already says about one service — its elements, its inbound and outbound
4
- * edges, the operations the fleet already calls on it — and the block the
5
- * service still owes the file when nothing in it resolves to the service yet.
6
- * Both halves exist to stop an agent inventing a parallel model: the fleet has
7
- * already drawn some of these boxes and edges, and a baseline has to attach to
8
- * them.
4
+ * edges, the operations the fleet already calls on it — and which of the four
5
+ * states the map is in for it. The write the service still owes the file — the
6
+ * block, when nothing in it resolves to the service yet, or the EDGES, when an
7
+ * element does and no edge touches it — is spelled in `./map/owed.ts`
8
+ * (`landscapeArtifact`, `instructionFor`), which this module hands its findings
9
+ * to. Both halves exist to stop an agent inventing a parallel model: the fleet
10
+ * has already drawn some of these boxes and edges, and a baseline has to attach.
11
+ *
12
+ * "The fleet map" is the `architecture/` PROJECT — the landscape plus every
13
+ * other `.likec4` under it, minus the generated views file — and not the
14
+ * landscape FILE. The two are the same document set `validate --all` grades
15
+ * `landscape.service-isolated` over, and reading one file here let the two
16
+ * surfaces disagree about the same tree.
9
17
  */
10
18
  import { existsSync } from "node:fs";
11
19
  import { loadFile } from "../c4/likec4.js";
12
- import { elementService, serviceResolver } from "../c4/resolve/service.js";
20
+ import { loadArchitecture } from "../c4/project/architecture.js";
21
+ import { attestedCalls } from "../c4/resolve/attested.js";
22
+ import { serviceResolver } from "../c4/resolve/service.js";
23
+ import { ServiceModels } from "../c4/prefetch/fleet.js";
24
+ import { OBLIGATION_TAG_PREFIX } from "../obligations/obligations.js";
13
25
  import { landscapePath } from "../repo/paths.js";
14
26
  import { enumeratedServiceIds, serviceTreePathOf } from "../repo/service-target.js";
27
+ import { EXTERNAL_TAG, GRADED_TAGS } from "../vocabulary/maturity.js";
28
+ import { brokenDocuments, instructionFor } from "./map/owed.js";
29
+ import { properAncestorIds } from "../kernel/ids/fqn/ancestors.js";
15
30
  /**
16
- * The LikeC4 identifier the fleet map's element for a service conventionally
17
- * carries: the directory name, camel-cased. It is a suggestion and nothing
18
- * more — `metadata { service '<id>' }` is what actually joins the element to
19
- * the directory — but a brief that hands over a concrete block gets followed,
20
- * and one that describes a block in prose gets improvised on.
31
+ * The service ids the resolver may fall back on when an element carries no
32
+ * `metadata { service }` binding — the same positive evidence `validate` and
33
+ * `list` hand it. A docs repo with no `services/` yet (`adopt` runs there)
34
+ * leaves the resolver with bindings alone, which is what it had before.
21
35
  */
22
- function elementIdFor(service) {
23
- const parts = service.split(/[^A-Za-z0-9]+/).filter((p) => p !== "");
24
- if (parts.length === 0)
25
- return "service";
26
- const head = parts[0].toLowerCase();
27
- const tail = parts.slice(1).map((p) => p[0].toUpperCase() + p.slice(1).toLowerCase());
28
- const id = head + tail.join("");
29
- // LikeC4 identifiers cannot open with a digit; a service id can.
30
- return /^[0-9]/.test(id) ? `svc${id[0].toUpperCase()}${id.slice(1)}` : id;
36
+ async function knownServices(docsDir) {
37
+ return new Set(await enumeratedServiceIds(docsDir));
31
38
  }
32
39
  /**
33
- * The block this service still owes `architecture/landscape.likec4`.
34
- *
35
- * `expects` is what the fleet ALREADY calls on the service — those edges exist
36
- * in the map today, so the example draws the outbound side as a comment rather
37
- * than telling an agent to duplicate an edge that is already there.
40
+ * The tags loam reads on an ELEMENT. `GRADED_TAGS` is the vocabulary's own
41
+ * list of the tags that change what loam concludes — spelled once there, so
42
+ * the day a third tag is graded this set follows and the instruction below
43
+ * does not tell an agent to clear it as unread. The obligation prefix is the
44
+ * one tag PREFIX loam reads on an element; `#cap-`/`#req-` are view tags and
45
+ * never sit on one, so they are not in this list.
38
46
  */
39
- function landscapeBlock(service, expects, present) {
40
- const id = elementIdFor(service);
41
- const calls = expects.length > 0
42
- ? expects.map((op) => `// <caller> -> ${id} 'Calls ${op}' { metadata { op '${op}' } }`)
43
- : [`// <caller> -> ${id} 'Calls <operationId>' { metadata { op '<operationId>' } }`];
44
- const model = [
45
- "model {",
46
- ...(present ? [" // ... the fleet's other services stay exactly as they are ...", ""] : []),
47
- ` ${id} = softwareSystem '${service}' {`,
48
- " description '<one line: what this service is responsible for>'",
49
- ` metadata { service '${service}' }`,
50
- " }",
51
- "",
52
- " // every call in or out of it, one edge each:",
53
- ...calls.map((line) => ` ${line}`),
54
- "}",
55
- ];
56
- // When the file does not exist the example is the WHOLE file, so it carries
57
- // the `specification` block a bare `model` would be rejected without: the
58
- // brief must never hand over a document `loam validate` refuses. When the file
59
- // does exist the example is a fragment to splice, and repeating a
60
- // `specification` block there would invite a second one.
61
- return present
62
- ? model.join("\n")
63
- : ["specification {", " element softwareSystem", "}", "", ...model].join("\n");
64
- }
65
- /** The fleet map's own brief — assembled per service, because the block it owes names the service. */
66
- export function landscapeArtifact(service, expects, present, servicePath) {
67
- return {
68
- artifact: "landscape.likec4",
69
- required: true,
70
- purpose: "the fleet map — until an element here resolves to this directory, the service is documented and invisible to every cross-service check",
71
- shape: [
72
- "This file is the WHOLE FLEET's, not this service's. Add to it; never rewrite it. Everything already in `model { ... }` belongs to the other services, and replacing the file destroys their map along with their edges.",
73
- `Add one top-level element for the service, bound to its directory: \`metadata { service '${service}' }\`. Until an element resolves to \`${servicePath}/\`, \`loam validate --all\` reports \`landscape.service-unmodelled\` (error).`,
74
- "Bind rather than rename: a binding whose id names no directory is `landscape.binding-unknown` (error), and two elements binding the SAME directory is `landscape.binding-duplicate` (warn) — every element→service join then picks one of them arbitrarily.",
75
- "Draw every cross-service call as an edge carrying the operation it uses: `a -> b 'Calls createSplit' { metadata { op 'createSplit' } }`. The `op` must be an operationId the TARGET's openapi.yaml defines, or `spine.op-undefined` (error) — a broken contract between services.",
76
- "If the file does not exist yet, create it with a `specification { ... }` block declaring the kinds you use, then the `model { ... }` block. A landscape that does not parse is `landscape.invalid` (error) and blinds every cross-service check at once.",
77
- ],
78
- example: landscapeBlock(service, expects, present),
79
- };
80
- }
47
+ const LOAM_TAGS = new Set(GRADED_TAGS);
48
+ const LOAM_TAG_PREFIXES = [OBLIGATION_TAG_PREFIX];
81
49
  /**
82
- * The service ids the resolver may fall back on when an element carries no
83
- * `metadata { service }` binding — the same positive evidence `validate` and
84
- * `list` hand it. A docs repo that cannot be enumerated (no `services/` yet:
85
- * `adopt` runs there) leaves the resolver with bindings alone, which is what it
86
- * had before.
50
+ * The element's tags loam does NOT read — named in the instruction and never
51
+ * interpreted. A placeholder convention ("drawn ahead of adoption") is the
52
+ * fleet's own, `loam seed` writes none, and a view written `exclude
53
+ * element.tag = #<that>` keeps an adopted service hidden until it is cleared.
87
54
  */
88
- async function knownServices(docsDir) {
89
- return new Set(await enumeratedServiceIds(docsDir));
55
+ function foreignTagsOf(elements) {
56
+ const unread = (t) => !LOAM_TAGS.has(t) && !LOAM_TAG_PREFIXES.some((p) => t.startsWith(p));
57
+ return [...new Set(elements.flatMap((e) => e.tags))].filter(unread);
90
58
  }
91
59
  /**
92
- * What the living landscape already says about this service.
60
+ * The attested calls, or nothing off a model that could not be read: `c4.invalid`
61
+ * is validate's finding, and an edge list read off half a document is invention.
93
62
  *
94
- * This is the half of the brief that stops an agent inventing a parallel model:
95
- * the fleet has already drawn some of these boxes and edges, and the baseline has
96
- * to attach to them. A landscape that does not parse yields `modelled: null` —
97
- * "nothing models it" would be a claim about a document nobody could read.
63
+ * Through the ONE reader of `model.likec4` (`core/c4/service-model/load.ts`),
64
+ * because the two shapes are read differently and this brief is handed to an
65
+ * agent that will act on it: a model that EXTENDS the fleet map, opened as a
66
+ * lone file, comes back as a pile of parse errors — so the brief would tell
67
+ * every migrated service that its model attests nothing and quietly drop the
68
+ * edges the map most likely owes. `mapUnreadable` is the same empty answer for
69
+ * the same reason: an extending model whose map does not parse was never read.
70
+ */
71
+ async function attestedFrom(docsDir, paths, service, known) {
72
+ // The memo directly rather than through `core/fleet-context.ts`, and the
73
+ // reason is the package graph: this module already depends on `core/c4/`, and
74
+ // reaching for the read index would add a `brief -> core-root` edge for one
75
+ // read in a command that grades a single service. The three things the memo
76
+ // cannot know for itself are supplied here — the enumeration this function
77
+ // was already handed, the per-file loader, and a counter nobody is keeping.
78
+ const models = new ServiceModels({
79
+ onProjectLoad: () => {
80
+ // `adopt` reports no read counters, so there is nothing to increment. The
81
+ // hook is the memo's way of letting a caller own its own statistics, and
82
+ // an empty one is that answer, not a forgotten line.
83
+ },
84
+ known: async () => known,
85
+ standalone: (path) => loadFile(path),
86
+ });
87
+ const model = await models.model(docsDir, paths);
88
+ if (model.mapUnreadable || model.doc.errors.length > 0)
89
+ return [];
90
+ return attestedCalls(model.doc, service, known);
91
+ }
92
+ /**
93
+ * What the living fleet map already says about this service — the half of the
94
+ * brief that stops an agent inventing a parallel model: the fleet has already
95
+ * drawn some of these boxes and edges, and the baseline has to attach to them.
96
+ * An `architecture/` project that does not parse yields `modelled: null` —
97
+ * "nothing models it" would be a claim about documents nobody could read; the
98
+ * landscape FILE parsing on its own does not rescue it, because the map the
99
+ * renderer and `validate --all` see is the whole project. `paths` is the
100
+ * service's own artifact set, located by the caller through the enumeration
101
+ * (never joined at `services/<id>/`): the model is opened in exactly one state —
102
+ * an element with no edge — to name the calls the map most likely owes. The
103
+ * WHOLE record travels rather than the model path alone, because the model is
104
+ * now read through its own shape and an extending one is read as a project of
105
+ * the service's directory plus the map. It is required rather than optional
106
+ * because the edgeless instruction states what that file attests, and a caller
107
+ * that omitted it would get a brief asserting a fact about a document loam never
108
+ * opened.
98
109
  */
99
- export async function landscapeContext(docsDir, service) {
110
+ export async function landscapeContext(docsDir, service, paths) {
100
111
  const path = landscapePath(docsDir);
101
112
  // The service's own directory, spelled from the enumeration rather than joined
102
113
  // at the root: this text is handed to an AGENT that will go and edit files, and
103
114
  // a filed service named at `services/<id>/` sends it to create a second
104
115
  // directory beside the one that already exists.
105
116
  const servicePath = await serviceTreePathOf(docsDir, service);
117
+ const bare = { service, expects: [], servicePath, attested: [], foreignTags: [] };
106
118
  const empty = {
107
119
  present: existsSync(path),
108
120
  parses: false,
121
+ callersKnown: false,
109
122
  modelled: null,
110
123
  elements: [],
111
124
  inbound: [],
112
125
  outbound: [],
113
126
  expects: [],
127
+ touched: null,
128
+ attested: [],
114
129
  instruction: null,
115
130
  };
116
131
  if (!empty.present)
117
- return { ...empty, modelled: false, instruction: instructionFor(service, "absent", [], servicePath) };
118
- const land = await loadFile(path);
119
- if (land.errors.length > 0)
120
- return { ...empty, instruction: instructionFor(service, "unparseable", [], servicePath) };
121
- const mine = (e) => elementService(e) === service;
122
- const elements = land.elements.filter(mine).map((e) => ({
132
+ return { ...empty, modelled: false, instruction: instructionFor({ ...bare, state: "absent" }) };
133
+ // The `architecture/` PROJECT, through the one loader every other reader
134
+ // shares — never `loadFile(path)`. A fleet spreads its model over more than
135
+ // the landscape (a second `model { }` block in a sibling, a use case, a
136
+ // palette), and `landscape.service-isolated` grades `touched` over exactly
137
+ // this set: reading the landscape alone made `adopt` report `touched: false`,
138
+ // the attested calls and an edit target for a service the fleet run on the
139
+ // same tree called matched, with nothing to tell an agent which was right.
140
+ const known = await knownServices(docsDir);
141
+ const land = await loadArchitecture(docsDir);
142
+ if (land.errors.length > 0) {
143
+ // Since W4 this arm answers for the whole `architecture/` PROJECT, so the
144
+ // document that broke is very often a SIBLING beside a landscape that parses
145
+ // perfectly — and two things followed from not saying so:
146
+ // - the instruction told an agent to go and fix parse errors in
147
+ // `architecture/landscape.likec4`, which has none, contradicting
148
+ // `validate --all` run one second later on the same tree;
149
+ // - the API question — who CALLS this service — was answered "unknown"
150
+ // off a landscape file loam can read, so a broken palette flipped
151
+ // `openapi.yaml` to required for a browser UI the map proves nobody
152
+ // calls, while `list` and `context` (which read the FILE, see
153
+ // core/pack/living.ts) answered the opposite about the same tree.
154
+ // Nothing else is rescued: `modelled`, `elements` and `touched` stay
155
+ // unknown, because those are claims about the project the renderer loads.
156
+ const expects = await expectsFromFile(path, service, known);
157
+ return {
158
+ ...empty,
159
+ callersKnown: expects !== null,
160
+ expects: expects ?? [],
161
+ instruction: instructionFor({
162
+ ...bare,
163
+ expects: expects ?? [],
164
+ state: "unparseable",
165
+ broken: brokenDocuments(docsDir, land),
166
+ }),
167
+ };
168
+ }
169
+ // One resolver for the whole scan, built with the real service ids, and
170
+ // built BEFORE the element filter: "an element resolves to this service" is
171
+ // the resolver's answer — a nearest-ancestor binding wins over a descendant's
172
+ // title — and it is the answer `validate --all` grades `service-unmodelled`
173
+ // on and `loam context` prints `modelled` from. This used to ask each
174
+ // element for its OWN binding-or-title instead, so a container titled
175
+ // 'payment-service' inside an element bound to order-service read as
176
+ // payment-service's box, and the edgeless arm told an agent "do not add a
177
+ // second element" for a service the fleet run reported unmodelled (error).
178
+ // The same resolver serves the edges: one drawn into a modelled container
179
+ // (`paymentService.api`) is an edge into the service, and `expects` — which
180
+ // decides whether this service owes an OpenAPI contract at all — has to see
181
+ // it. Building it once also stops the per-edge rebuild the old
182
+ // `serviceOf(land.elements, id)` call did.
183
+ const svcOf = serviceResolver(land.elements, known);
184
+ const mine = (id) => svcOf(id) === service;
185
+ // The service-LEVEL elements only: one that resolves to the service while
186
+ // an ancestor does too is a container of it, and listing it would show a
187
+ // second box the map does not have.
188
+ const elements = land.elements
189
+ .filter((e) => mine(e.id) && !properAncestorIds(e.id).some(mine))
190
+ .map((e) => ({
123
191
  id: e.id,
124
192
  title: e.title,
125
193
  kind: e.kind,
126
194
  tags: e.tags,
127
195
  bound: e.service !== undefined,
128
196
  }));
129
- // One resolver for the whole scan, built with the real service ids: an edge
130
- // drawn into a modelled container (`paymentService.api`) is an edge into the
131
- // service, and `expects` — which now decides whether this service owes an
132
- // OpenAPI contract at all — has to see it. Building it once also stops the
133
- // per-edge rebuild the old `serviceOf(land.elements, id)` call did.
134
- const svcOf = serviceResolver(land.elements, await knownServices(docsDir));
135
197
  const inbound = [];
136
198
  const outbound = [];
199
+ // An edge whose BOTH endpoints resolve here is the service's own internal
200
+ // wiring: filed as inbound it made the service its own caller (verification
201
+ // 2026-09-04). It still TOUCHES the service, so `touched` below reads the
202
+ // relationships rather than these lists — the isolation check counts either
203
+ // endpoint, and the two predicates must not disagree.
204
+ const self = (r) => mine(r.source) && mine(r.target);
137
205
  for (const r of land.relationships) {
206
+ if (self(r))
207
+ continue;
138
208
  const edge = { op: r.op ?? null, title: r.title ?? null };
139
- if (svcOf(r.target) === service)
209
+ if (mine(r.target))
140
210
  inbound.push({ from: svcOf(r.source), ...edge });
141
- else if (svcOf(r.source) === service)
211
+ else if (mine(r.source))
142
212
  outbound.push({ to: svcOf(r.target), ...edge });
143
213
  }
144
214
  const expects = [...new Set(inbound.map((e) => e.op).filter((op) => op !== null))];
215
+ const modelled = land.elements.some((e) => mine(e.id));
216
+ const touched = modelled ? land.relationships.some((r) => mine(r.source) || mine(r.target)) : null;
217
+ const attested = touched === false && existsSync(paths.model) ? await attestedFrom(docsDir, paths, service, known) : [];
218
+ const req = {
219
+ service,
220
+ expects,
221
+ servicePath,
222
+ attested,
223
+ foreignTags: foreignTagsOf(elements),
224
+ elementId: elements[0]?.id,
225
+ // The one graded tag that changes what the brief may PROMISE: an `#external`
226
+ // element is never `landscape.service-isolated`'s subject. Off the same
227
+ // element `elementId` names, never the union.
228
+ external: elements[0]?.tags.includes(EXTERNAL_TAG) ?? false,
229
+ };
230
+ const instruction = !modelled
231
+ ? instructionFor({ ...req, state: "unmodelled" })
232
+ : touched === false
233
+ ? instructionFor({ ...req, state: "edgeless" })
234
+ : null;
145
235
  return {
146
236
  present: true,
147
237
  parses: true,
148
- modelled: elements.length > 0,
238
+ callersKnown: true,
239
+ modelled,
149
240
  elements,
150
241
  inbound,
151
242
  outbound,
152
243
  expects,
153
- instruction: elements.length > 0 ? null : instructionFor(service, "unmodelled", expects, servicePath),
244
+ touched,
245
+ attested,
246
+ instruction,
154
247
  };
155
248
  }
156
249
  /**
157
- * The fleet-map instruction, in the three states a landscape can be in.
250
+ * The operations the fleet already calls on this service, read off the landscape
251
+ * FILE alone — `null` when that file cannot be read either.
158
252
  *
159
- * It says the file, the block, and the consequence, in that order. The
160
- * consequence is the part agents acted on: "add an element" reads as tidiness,
161
- * "until you do, `loam validate --all` fails and no cross-service check can see
162
- * this service" reads as work.
253
+ * The fallback for an `architecture/` project that does not parse, and the
254
+ * narrowest one that can be justified: it answers ONE question, the one `loam
255
+ * list` and `loam context` answer off the same bytes (`landscapeEvidence`,
256
+ * core/vocabulary/maturity.ts). "Nothing calls this service" and "loam could not
257
+ * tell" are different answers, and only the first may switch an API contract
258
+ * off, which is why the empty list and the unreadable file are told apart here
259
+ * rather than collapsed to `[]`.
163
260
  */
164
- function instructionFor(service, state, expects, servicePath) {
165
- const id = elementIdFor(service);
166
- const bind = `an element bound with \`metadata { service '${service}' }\``;
167
- const consequence = `Until one resolves, \`loam validate --all\` reports \`landscape.service-unmodelled\` (error) for ` +
168
- `${servicePath}/: the service is documented and invisible — no edge into it can be checked ` +
169
- `against its openapi.yaml, and no feature can draw a call to it.`;
170
- // `expects` is reachable only through elements that already resolve to this
171
- // service, so it is empty in every state that produces an instruction. It is
172
- // threaded through anyway rather than dropped: the caller computes it once,
173
- // and the day an unmodelled service can inherit an edge (a container-level
174
- // binding, say) the sentence is already here instead of being noticed missing.
175
- const owed = expects.length > 0
176
- ? ` The fleet already calls ${expects.map((o) => `'${o}'`).join(", ")} on this service, so those edges exist; your element is what they will resolve to.`
177
- : "";
178
- if (state === "absent") {
179
- return (`architecture/landscape.likec4 does not exist yet. Create it with a \`specification { ... }\` block ` +
180
- `declaring the kinds you use and a \`model { ... }\` block containing ${bind} ` +
181
- `(conventionally \`${id} = softwareSystem '${service}'\`), plus one edge per cross-service call, each ` +
182
- `carrying \`metadata { op '<operationId>' }\`. ${consequence}${owed}`);
261
+ async function expectsFromFile(path, service, known) {
262
+ try {
263
+ const doc = await loadFile(path);
264
+ if (doc.errors.length > 0)
265
+ return null;
266
+ const svcOf = serviceResolver(doc.elements, known);
267
+ const ops = doc.relationships
268
+ .filter((r) => svcOf(r.target) === service)
269
+ .map((r) => r.op)
270
+ .filter((op) => op !== undefined);
271
+ return [...new Set(ops)];
183
272
  }
184
- if (state === "unparseable") {
185
- return (`architecture/landscape.likec4 exists but does not parse (\`landscape.invalid\`), so nothing can be said ` +
186
- `about what it already models. Fix the parse errors first — they blind every cross-service check at once — ` +
187
- `then make sure it holds ${bind}. ${consequence}`);
273
+ catch {
274
+ return null;
188
275
  }
189
- return (`Nothing in architecture/landscape.likec4 resolves to ${servicePath}/. ADD to that file — do not rewrite ` +
190
- `it, every other service's map is in there — ${bind}, conventionally ` +
191
- `\`${id} = softwareSystem '${service}'\`, inside the existing \`model { ... }\` block, and draw each ` +
192
- `cross-service call as an edge carrying \`metadata { op '<operationId>' }\`. ${consequence}${owed}`);
193
276
  }
194
277
  //# sourceMappingURL=landscape.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"landscape.js","sourceRoot":"","sources":["../../../src/core/brief/landscape.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAIpF;;;;;;GAMG;AACH,SAAS,YA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sB,OAAO,kEAAkE;QACtG,+EAA+E,WAAW,GAAG,IAAI,EAAE,CACpG,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The fleet-map half of the adoption brief: what `architecture/landscape.likec4`\n * already says about one service — its elements, its inbound and outbound\n * edges, the operations the fleet already calls on it — and the block the\n * service still owes the file when nothing in it resolves to the service yet.\n * Both halves exist to stop an agent inventing a parallel model: the fleet has\n * already drawn some of these boxes and edges, and a baseline has to attach to\n * them.\n */\nimport { existsSync } from \"node:fs\";\nimport { loadFile, type Elem } from \"../c4/likec4.js\";\nimport { elementService, serviceResolver } from \"../c4/resolve/service.js\";\nimport { landscapePath } from \"../repo/paths.js\";\nimport { enumeratedServiceIds, serviceTreePathOf } from \"../repo/service-target.js\";\nimport type { BriefTarget } from \"./targets.js\";\nimport type { DocsDir } from \"../kernel/ids/dirs.js\";\n\n/**\n * The LikeC4 identifier the fleet map's element for a service conventionally\n * carries: the directory name, camel-cased. It is a suggestion and nothing\n * more — `metadata { service '<id>' }` is what actually joins the element to\n * the directory — but a brief that hands over a concrete block gets followed,\n * and one that describes a block in prose gets improvised on.\n */\nfunction elementIdFor(service: string): string {\n const parts = service.split(/[^A-Za-z0-9]+/).filter((p) => p !== \"\");\n if (parts.length === 0) return \"service\";\n const head = parts[0]!.toLowerCase();\n const tail = parts.slice(1).map((p) => p[0]!.toUpperCase() + p.slice(1).toLowerCase());\n const id = head + tail.join(\"\");\n // LikeC4 identifiers cannot open with a digit; a service id can.\n return /^[0-9]/.test(id) ? `svc${id[0]!.toUpperCase()}${id.slice(1)}` : id;\n}\n\n/**\n * The block this service still owes `architecture/landscape.likec4`.\n *\n * `expects` is what the fleet ALREADY calls on the service — those edges exist\n * in the map today, so the example draws the outbound side as a comment rather\n * than telling an agent to duplicate an edge that is already there.\n */\nfunction landscapeBlock(service: string, expects: string[], present: boolean): string {\n const id = elementIdFor(service);\n const calls =\n expects.length > 0\n ? expects.map((op) => `// <caller> -> ${id} 'Calls ${op}' { metadata { op '${op}' } }`)\n : [`// <caller> -> ${id} 'Calls <operationId>' { metadata { op '<operationId>' } }`];\n const model = [\n \"model {\",\n ...(present ? [\" // ... the fleet's other services stay exactly as they are ...\", \"\"] : []),\n ` ${id} = softwareSystem '${service}' {`,\n \" description '<one line: what this service is responsible for>'\",\n ` metadata { service '${service}' }`,\n \" }\",\n \"\",\n \" // every call in or out of it, one edge each:\",\n ...calls.map((line) => ` ${line}`),\n \"}\",\n ];\n // When the file does not exist the example is the WHOLE file, so it carries\n // the `specification` block a bare `model` would be rejected without: the\n // brief must never hand over a document `loam validate` refuses. When the file\n // does exist the example is a fragment to splice, and repeating a\n // `specification` block there would invite a second one.\n return present\n ? model.join(\"\\n\")\n : [\"specification {\", \" element softwareSystem\", \"}\", \"\", ...model].join(\"\\n\");\n}\n\n/** The fleet map's own brief — assembled per service, because the block it owes names the service. */\nexport function landscapeArtifact(\n service: string,\n expects: string[],\n present: boolean,\n servicePath: string,\n): Omit<BriefTarget, \"path\" | \"exists\" | \"action\"> {\n return {\n artifact: \"landscape.likec4\",\n required: true,\n purpose:\n \"the fleet map — until an element here resolves to this directory, the service is documented and invisible to every cross-service check\",\n shape: [\n \"This file is the WHOLE FLEET's, not this service's. Add to it; never rewrite it. Everything already in `model { ... }` belongs to the other services, and replacing the file destroys their map along with their edges.\",\n `Add one top-level element for the service, bound to its directory: \\`metadata { service '${service}' }\\`. Until an element resolves to \\`${servicePath}/\\`, \\`loam validate --all\\` reports \\`landscape.service-unmodelled\\` (error).`,\n \"Bind rather than rename: a binding whose id names no directory is `landscape.binding-unknown` (error), and two elements binding the SAME directory is `landscape.binding-duplicate` (warn) — every element→service join then picks one of them arbitrarily.\",\n \"Draw every cross-service call as an edge carrying the operation it uses: `a -> b 'Calls createSplit' { metadata { op 'createSplit' } }`. The `op` must be an operationId the TARGET's openapi.yaml defines, or `spine.op-undefined` (error) — a broken contract between services.\",\n \"If the file does not exist yet, create it with a `specification { ... }` block declaring the kinds you use, then the `model { ... }` block. A landscape that does not parse is `landscape.invalid` (error) and blinds every cross-service check at once.\",\n ],\n example: landscapeBlock(service, expects, present),\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* What the fleet already says about this service */\n/* ------------------------------------------------------------------ */\n\nexport interface LandscapeElement {\n id: string;\n title: string;\n kind: string;\n tags: string[];\n /** True when the element binds explicitly with `metadata { service }`. */\n bound: boolean;\n}\n\nexport interface LandscapeEdge {\n from?: string;\n to?: string;\n op: string | null;\n title: string | null;\n}\n\nexport interface LandscapeContext {\n present: boolean;\n /** False when the landscape exists but does not parse. */\n parses: boolean;\n /** Whether any element resolves to this service — null when nothing could be read. */\n modelled: boolean | null;\n elements: LandscapeElement[];\n inbound: LandscapeEdge[];\n outbound: LandscapeEdge[];\n /** Operations other services already call on this one: the contract owes them. */\n expects: string[];\n /**\n * The write this service still owes the fleet map, in prose — null once an\n * element resolves to it.\n *\n * It duplicates the `landscape.likec4` target's shape rules on purpose: an\n * agent driving off `--json` reads `landscape` to learn what the fleet\n * already says, and every `targets[]` consumer walks the artifact list. Only\n * one of those two readers used to exist, so `adopt` briefed eight files and\n * never once said the ninth thing — that a documented service nobody drew is\n * invisible to the whole cross-service layer.\n */\n instruction: string | null;\n}\n\n/**\n * The service ids the resolver may fall back on when an element carries no\n * `metadata { service }` binding — the same positive evidence `validate` and\n * `list` hand it. A docs repo that cannot be enumerated (no `services/` yet:\n * `adopt` runs there) leaves the resolver with bindings alone, which is what it\n * had before.\n */\nasync function knownServices(docsDir: DocsDir): Promise<ReadonlySet<string>> {\n return new Set(await enumeratedServiceIds(docsDir));\n}\n\n/**\n * What the living landscape already says about this service.\n *\n * This is the half of the brief that stops an agent inventing a parallel model:\n * the fleet has already drawn some of these boxes and edges, and the baseline has\n * to attach to them. A landscape that does not parse yields `modelled: null` —\n * \"nothing models it\" would be a claim about a document nobody could read.\n */\nexport async function landscapeContext(docsDir: DocsDir, service: string): Promise<LandscapeContext> {\n const path = landscapePath(docsDir);\n // The service's own directory, spelled from the enumeration rather than joined\n // at the root: this text is handed to an AGENT that will go and edit files, and\n // a filed service named at `services/<id>/` sends it to create a second\n // directory beside the one that already exists.\n const servicePath = await serviceTreePathOf(docsDir, service);\n const empty: LandscapeContext = {\n present: existsSync(path),\n parses: false,\n modelled: null,\n elements: [],\n inbound: [],\n outbound: [],\n expects: [],\n instruction: null,\n };\n if (!empty.present)\n return { ...empty, modelled: false, instruction: instructionFor(service, \"absent\", [], servicePath) };\n\n const land = await loadFile(path);\n if (land.errors.length > 0)\n return { ...empty, instruction: instructionFor(service, \"unparseable\", [], servicePath) };\n\n const mine = (e: Elem): boolean => elementService(e) === service;\n const elements: LandscapeElement[] = land.elements.filter(mine).map((e) => ({\n id: e.id,\n title: e.title,\n kind: e.kind,\n tags: e.tags,\n bound: e.service !== undefined,\n }));\n\n // One resolver for the whole scan, built with the real service ids: an edge\n // drawn into a modelled container (`paymentService.api`) is an edge into the\n // service, and `expects` — which now decides whether this service owes an\n // OpenAPI contract at all — has to see it. Building it once also stops the\n // per-edge rebuild the old `serviceOf(land.elements, id)` call did.\n const svcOf = serviceResolver(land.elements, await knownServices(docsDir));\n const inbound: LandscapeEdge[] = [];\n const outbound: LandscapeEdge[] = [];\n for (const r of land.relationships) {\n const edge = { op: r.op ?? null, title: r.title ?? null };\n if (svcOf(r.target) === service) inbound.push({ from: svcOf(r.source), ...edge });\n else if (svcOf(r.source) === service) outbound.push({ to: svcOf(r.target), ...edge });\n }\n\n const expects = [...new Set(inbound.map((e) => e.op).filter((op): op is string => op !== null))];\n return {\n present: true,\n parses: true,\n modelled: elements.length > 0,\n elements,\n inbound,\n outbound,\n expects,\n instruction:\n elements.length > 0 ? null : instructionFor(service, \"unmodelled\", expects, servicePath),\n };\n}\n\n/**\n * The fleet-map instruction, in the three states a landscape can be in.\n *\n * It says the file, the block, and the consequence, in that order. The\n * consequence is the part agents acted on: \"add an element\" reads as tidiness,\n * \"until you do, `loam validate --all` fails and no cross-service check can see\n * this service\" reads as work.\n */\nfunction instructionFor(\n service: string,\n state: \"absent\" | \"unparseable\" | \"unmodelled\",\n expects: string[],\n servicePath: string,\n): string {\n const id = elementIdFor(service);\n const bind = `an element bound with \\`metadata { service '${service}' }\\``;\n const consequence =\n `Until one resolves, \\`loam validate --all\\` reports \\`landscape.service-unmodelled\\` (error) for ` +\n `${servicePath}/: the service is documented and invisible — no edge into it can be checked ` +\n `against its openapi.yaml, and no feature can draw a call to it.`;\n // `expects` is reachable only through elements that already resolve to this\n // service, so it is empty in every state that produces an instruction. It is\n // threaded through anyway rather than dropped: the caller computes it once,\n // and the day an unmodelled service can inherit an edge (a container-level\n // binding, say) the sentence is already here instead of being noticed missing.\n const owed =\n expects.length > 0\n ? ` The fleet already calls ${expects.map((o) => `'${o}'`).join(\", \")} on this service, so those edges exist; your element is what they will resolve to.`\n : \"\";\n\n if (state === \"absent\") {\n return (\n `architecture/landscape.likec4 does not exist yet. Create it with a \\`specification { ... }\\` block ` +\n `declaring the kinds you use and a \\`model { ... }\\` block containing ${bind} ` +\n `(conventionally \\`${id} = softwareSystem '${service}'\\`), plus one edge per cross-service call, each ` +\n `carrying \\`metadata { op '<operationId>' }\\`. ${consequence}${owed}`\n );\n }\n if (state === \"unparseable\") {\n return (\n `architecture/landscape.likec4 exists but does not parse (\\`landscape.invalid\\`), so nothing can be said ` +\n `about what it already models. Fix the parse errors first — they blind every cross-service check at once — ` +\n `then make sure it holds ${bind}. ${consequence}`\n );\n }\n return (\n `Nothing in architecture/landscape.likec4 resolves to ${servicePath}/. ADD to that file — do not rewrite ` +\n `it, every other service's map is in there — ${bind}, conventionally ` +\n `\\`${id} = softwareSystem '${service}'\\`, inside the existing \\`model { ... }\\` block, and draw each ` +\n `cross-service call as an edge carrying \\`metadata { op '<operationId>' }\\`. ${consequence}${owed}`\n );\n}\n"]}
1
+ {"version":3,"file":"landscape.js","sourceRoot":"","sources":["../../../src/core/brief/landscape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,U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E,KAA0B;IACtF,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QACvC,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACnD,MAAM,GAAG,GAAG,GAAG,CAAC,aAAa;aAC1B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC;aAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChB,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/**\n * The fleet-map half of the adoption brief, READ side: what the fleet map\n * already says about one service — its elements, its inbound and outbound\n * edges, the operations the fleet already calls on it — and which of the four\n * states the map is in for it. The write the service still owes the file — the\n * block, when nothing in it resolves to the service yet, or the EDGES, when an\n * element does and no edge touches it — is spelled in `./map/owed.ts`\n * (`landscapeArtifact`, `instructionFor`), which this module hands its findings\n * to. Both halves exist to stop an agent inventing a parallel model: the fleet\n * has already drawn some of these boxes and edges, and a baseline has to attach.\n *\n * \"The fleet map\" is the `architecture/` PROJECT — the landscape plus every\n * other `.likec4` under it, minus the generated views file — and not the\n * landscape FILE. The two are the same document set `validate --all` grades\n * `landscape.service-isolated` over, and reading one file here let the two\n * surfaces disagree about the same tree.\n */\nimport { existsSync } from \"node:fs\";\nimport { loadFile } from \"../c4/likec4.js\";\nimport { loadArchitecture } from \"../c4/project/architecture.js\";\nimport { attestedCalls, type AttestedCall } from \"../c4/resolve/attested.js\";\nimport { serviceResolver } from \"../c4/resolve/service.js\";\nimport { ServiceModels } from \"../c4/prefetch/fleet.js\";\nimport { OBLIGATION_TAG_PREFIX } from \"../obligations/obligations.js\";\nimport { landscapePath, type ServicePaths } from \"../repo/paths.js\";\nimport { enumeratedServiceIds, serviceTreePathOf } from \"../repo/service-target.js\";\nimport { EXTERNAL_TAG, GRADED_TAGS } from \"../vocabulary/maturity.js\";\nimport { brokenDocuments, instructionFor } from \"./map/owed.js\";\nimport { properAncestorIds } from \"../kernel/ids/fqn/ancestors.js\";\nimport type { DocsDir } from \"../kernel/ids/dirs.js\";\n\n/* ------------------------------------------------------------------ */\n/* What the fleet already says about this service */\n/* ------------------------------------------------------------------ */\n\nexport interface LandscapeElement {\n id: string;\n title: string;\n kind: string;\n tags: string[];\n /** True when the element binds explicitly with `metadata { service }`. */\n bound: boolean;\n}\n\nexport interface LandscapeEdge {\n from?: string;\n to?: string;\n op: string | null;\n title: string | null;\n}\n\nexport interface LandscapeContext {\n /** Whether `architecture/landscape.likec4` — the file the brief asks for edits to — is on disk. */\n present: boolean;\n /**\n * False when the landscape exists but the `architecture/` project does not\n * parse. A sibling under `architecture/` counts: a broken use case leaves the\n * map unusable for `validate --all` too, and a brief that read the landscape\n * alone would report a fleet nobody can render.\n */\n parses: boolean;\n /**\n * Whether loam could read WHO CALLS this service — the only evidence an EMPTY\n * `expects` may be read as \"nothing calls it\".\n *\n * A separate fact from `parses` because they answer about different documents.\n * `parses` is about the whole `architecture/` PROJECT (W4), and the callers\n * live in the landscape FILE: a broken palette or use case beside a landscape\n * that reads perfectly left `parses` false, and `apiExpected` then demanded an\n * OpenAPI contract of a browser UI the map proves nobody calls — while `loam\n * list` and `loam context`, which read the file (core/pack/living.ts), said the\n * opposite about the same tree.\n */\n callersKnown: boolean;\n /** Whether any element resolves to this service — null when nothing could be read. */\n modelled: boolean | null;\n /**\n * The service-LEVEL elements that resolve to this service: an element whose\n * ancestor also resolves to it is one of its containers, not a second box.\n */\n elements: LandscapeElement[];\n /**\n * The map's edges into and out of this service, INTERNAL edges excluded: an\n * edge whose two endpoints both resolve here (`svc.web -> svc.db`) is this\n * service's own wiring, and filed as inbound it named the service as its own\n * caller.\n */\n inbound: LandscapeEdge[];\n outbound: LandscapeEdge[];\n /** Operations other services already call on this one: the contract owes them. */\n expects: string[];\n /**\n * Whether at least one relationship in the map has an endpoint resolving to\n * this service — read off the relationships, NOT off `inbound`/`outbound`,\n * because an intra-service edge counts here (it is `landscape.service-\n * isolated`'s predicate) while those two lists drop it. `null` exactly when\n * `modelled` is `null` or `false`. It exists\n * because `instruction` used to go null on element existence alone, and\n * `loam seed` writes a bound, edgeless element for every service nobody\n * listed under `calls:` — so the brief declared the map finished for exactly\n * the services the map had not reached.\n *\n * Binary by design, and the fifth silent case of `landscape.service-isolated`\n * with it: ONE edge closes the state, so a map drawing one of five attested\n * calls reports `touched: true`, `attested: []` and no instruction. The check\n * is touched/untouched, not a set difference — loam cannot tell a call the map\n * omits from a call it deliberately does not draw at fleet level, and a\n * difference reported as an omission would be an invented edge with a code\n * beside it.\n */\n touched: boolean | null;\n /**\n * The calls `services/<…>/<svc>/model.likec4` declares ACROSS its boundary\n * (`attestedCalls`, core/c4/resolve/attested.ts). `[]` when the model is\n * absent, unparseable, or declares none — deliberately not told apart, since\n * the only thing the brief may do with the list is name edges ALREADY\n * ATTESTED, never invent one. Read only when `touched` is `false`: every\n * other state either has edges (nothing owed) or no element (the block, not\n * the edges, is owed), and a first adoption has no model to read anyway.\n */\n attested: AttestedCall[];\n /**\n * The write this service still owes the fleet map, in prose — null once an\n * element resolves to it AND an edge touches that element. It duplicates the\n * `landscape.likec4` target's shape rules on purpose: an agent driving off\n * `--json` reads `landscape` to learn what the fleet already says, and every\n * `targets[]` consumer walks the artifact list. Only one of those two readers\n * used to exist, so `adopt` briefed eight files and never once said the ninth\n * thing — that a documented service nobody drew is invisible to the whole\n * cross-service layer.\n */\n instruction: string | null;\n}\n\n/**\n * The service ids the resolver may fall back on when an element carries no\n * `metadata { service }` binding — the same positive evidence `validate` and\n * `list` hand it. A docs repo with no `services/` yet (`adopt` runs there)\n * leaves the resolver with bindings alone, which is what it had before.\n */\nasync function knownServices(docsDir: DocsDir): Promise<ReadonlySet<string>> {\n return new Set(await enumeratedServiceIds(docsDir));\n}\n\n/**\n * The tags loam reads on an ELEMENT. `GRADED_TAGS` is the vocabulary's own\n * list of the tags that change what loam concludes — spelled once there, so\n * the day a third tag is graded this set follows and the instruction below\n * does not tell an agent to clear it as unread. The obligation prefix is the\n * one tag PREFIX loam reads on an element; `#cap-`/`#req-` are view tags and\n * never sit on one, so they are not in this list.\n */\nconst LOAM_TAGS: ReadonlySet<string> = new Set(GRADED_TAGS);\nconst LOAM_TAG_PREFIXES: readonly string[] = [OBLIGATION_TAG_PREFIX];\n\n/**\n * The element's tags loam does NOT read — named in the instruction and never\n * interpreted. A placeholder convention (\"drawn ahead of adoption\") is the\n * fleet's own, `loam seed` writes none, and a view written `exclude\n * element.tag = #<that>` keeps an adopted service hidden until it is cleared.\n */\nfunction foreignTagsOf(elements: LandscapeElement[]): string[] {\n const unread = (t: string): boolean => !LOAM_TAGS.has(t) && !LOAM_TAG_PREFIXES.some((p) => t.startsWith(p));\n return [...new Set(elements.flatMap((e) => e.tags))].filter(unread);\n}\n\n/**\n * The attested calls, or nothing off a model that could not be read: `c4.invalid`\n * is validate's finding, and an edge list read off half a document is invention.\n *\n * Through the ONE reader of `model.likec4` (`core/c4/service-model/load.ts`),\n * because the two shapes are read differently and this brief is handed to an\n * agent that will act on it: a model that EXTENDS the fleet map, opened as a\n * lone file, comes back as a pile of parse errors — so the brief would tell\n * every migrated service that its model attests nothing and quietly drop the\n * edges the map most likely owes. `mapUnreadable` is the same empty answer for\n * the same reason: an extending model whose map does not parse was never read.\n */\nasync function attestedFrom(\n docsDir: DocsDir,\n paths: ServicePaths,\n service: string,\n known: ReadonlySet<string>,\n): Promise<AttestedCall[]> {\n // The memo directly rather than through `core/fleet-context.ts`, and the\n // reason is the package graph: this module already depends on `core/c4/`, and\n // reaching for the read index would add a `brief -> core-root` edge for one\n // read in a command that grades a single service. The three things the memo\n // cannot know for itself are supplied here — the enumeration this function\n // was already handed, the per-file loader, and a counter nobody is keeping.\n const models = new ServiceModels({\n onProjectLoad: () => {\n // `adopt` reports no read counters, so there is nothing to increment. The\n // hook is the memo's way of letting a caller own its own statistics, and\n // an empty one is that answer, not a forgotten line.\n },\n known: async () => known,\n standalone: (path) => loadFile(path),\n });\n const model = await models.model(docsDir, paths);\n if (model.mapUnreadable || model.doc.errors.length > 0) return [];\n return attestedCalls(model.doc, service, known);\n}\n\n/**\n * What the living fleet map already says about this service — the half of the\n * brief that stops an agent inventing a parallel model: the fleet has already\n * drawn some of these boxes and edges, and the baseline has to attach to them.\n * An `architecture/` project that does not parse yields `modelled: null` —\n * \"nothing models it\" would be a claim about documents nobody could read; the\n * landscape FILE parsing on its own does not rescue it, because the map the\n * renderer and `validate --all` see is the whole project. `paths` is the\n * service's own artifact set, located by the caller through the enumeration\n * (never joined at `services/<id>/`): the model is opened in exactly one state —\n * an element with no edge — to name the calls the map most likely owes. The\n * WHOLE record travels rather than the model path alone, because the model is\n * now read through its own shape and an extending one is read as a project of\n * the service's directory plus the map. It is required rather than optional\n * because the edgeless instruction states what that file attests, and a caller\n * that omitted it would get a brief asserting a fact about a document loam never\n * opened.\n */\nexport async function landscapeContext(\n docsDir: DocsDir,\n service: string,\n paths: ServicePaths,\n): Promise<LandscapeContext> {\n const path = landscapePath(docsDir);\n // The service's own directory, spelled from the enumeration rather than joined\n // at the root: this text is handed to an AGENT that will go and edit files, and\n // a filed service named at `services/<id>/` sends it to create a second\n // directory beside the one that already exists.\n const servicePath = await serviceTreePathOf(docsDir, service);\n const bare = { service, expects: [], servicePath, attested: [], foreignTags: [] };\n const empty: LandscapeContext = {\n present: existsSync(path),\n parses: false,\n callersKnown: false,\n modelled: null,\n elements: [],\n inbound: [],\n outbound: [],\n expects: [],\n touched: null,\n attested: [],\n instruction: null,\n };\n if (!empty.present) return { ...empty, modelled: false, instruction: instructionFor({ ...bare, state: \"absent\" }) };\n\n // The `architecture/` PROJECT, through the one loader every other reader\n // shares — never `loadFile(path)`. A fleet spreads its model over more than\n // the landscape (a second `model { }` block in a sibling, a use case, a\n // palette), and `landscape.service-isolated` grades `touched` over exactly\n // this set: reading the landscape alone made `adopt` report `touched: false`,\n // the attested calls and an edit target for a service the fleet run on the\n // same tree called matched, with nothing to tell an agent which was right.\n const known = await knownServices(docsDir);\n const land = await loadArchitecture(docsDir);\n if (land.errors.length > 0) {\n // Since W4 this arm answers for the whole `architecture/` PROJECT, so the\n // document that broke is very often a SIBLING beside a landscape that parses\n // perfectly — and two things followed from not saying so:\n // - the instruction told an agent to go and fix parse errors in\n // `architecture/landscape.likec4`, which has none, contradicting\n // `validate --all` run one second later on the same tree;\n // - the API question — who CALLS this service — was answered \"unknown\"\n // off a landscape file loam can read, so a broken palette flipped\n // `openapi.yaml` to required for a browser UI the map proves nobody\n // calls, while `list` and `context` (which read the FILE, see\n // core/pack/living.ts) answered the opposite about the same tree.\n // Nothing else is rescued: `modelled`, `elements` and `touched` stay\n // unknown, because those are claims about the project the renderer loads.\n const expects = await expectsFromFile(path, service, known);\n return {\n ...empty,\n callersKnown: expects !== null,\n expects: expects ?? [],\n instruction: instructionFor({\n ...bare,\n expects: expects ?? [],\n state: \"unparseable\",\n broken: brokenDocuments(docsDir, land),\n }),\n };\n }\n\n // One resolver for the whole scan, built with the real service ids, and\n // built BEFORE the element filter: \"an element resolves to this service\" is\n // the resolver's answer — a nearest-ancestor binding wins over a descendant's\n // title — and it is the answer `validate --all` grades `service-unmodelled`\n // on and `loam context` prints `modelled` from. This used to ask each\n // element for its OWN binding-or-title instead, so a container titled\n // 'payment-service' inside an element bound to order-service read as\n // payment-service's box, and the edgeless arm told an agent \"do not add a\n // second element\" for a service the fleet run reported unmodelled (error).\n // The same resolver serves the edges: one drawn into a modelled container\n // (`paymentService.api`) is an edge into the service, and `expects` — which\n // decides whether this service owes an OpenAPI contract at all — has to see\n // it. Building it once also stops the per-edge rebuild the old\n // `serviceOf(land.elements, id)` call did.\n const svcOf = serviceResolver(land.elements, known);\n const mine = (id: string): boolean => svcOf(id) === service;\n // The service-LEVEL elements only: one that resolves to the service while\n // an ancestor does too is a container of it, and listing it would show a\n // second box the map does not have.\n const elements: LandscapeElement[] = land.elements\n .filter((e) => mine(e.id) && !properAncestorIds(e.id).some(mine))\n .map((e) => ({\n id: e.id,\n title: e.title,\n kind: e.kind,\n tags: e.tags,\n bound: e.service !== undefined,\n }));\n\n const inbound: LandscapeEdge[] = [];\n const outbound: LandscapeEdge[] = [];\n // An edge whose BOTH endpoints resolve here is the service's own internal\n // wiring: filed as inbound it made the service its own caller (verification\n // 2026-09-04). It still TOUCHES the service, so `touched` below reads the\n // relationships rather than these lists — the isolation check counts either\n // endpoint, and the two predicates must not disagree.\n const self = (r: { source: string; target: string }): boolean => mine(r.source) && mine(r.target);\n for (const r of land.relationships) {\n if (self(r)) continue;\n const edge = { op: r.op ?? null, title: r.title ?? null };\n if (mine(r.target)) inbound.push({ from: svcOf(r.source), ...edge });\n else if (mine(r.source)) outbound.push({ to: svcOf(r.target), ...edge });\n }\n\n const expects = [...new Set(inbound.map((e) => e.op).filter((op): op is string => op !== null))];\n const modelled = land.elements.some((e) => mine(e.id));\n const touched = modelled ? land.relationships.some((r) => mine(r.source) || mine(r.target)) : null;\n const attested =\n touched === false && existsSync(paths.model) ? await attestedFrom(docsDir, paths, service, known) : [];\n const req = {\n service,\n expects,\n servicePath,\n attested,\n foreignTags: foreignTagsOf(elements),\n elementId: elements[0]?.id,\n // The one graded tag that changes what the brief may PROMISE: an `#external`\n // element is never `landscape.service-isolated`'s subject. Off the same\n // element `elementId` names, never the union.\n external: elements[0]?.tags.includes(EXTERNAL_TAG) ?? false,\n };\n const instruction = !modelled\n ? instructionFor({ ...req, state: \"unmodelled\" })\n : touched === false\n ? instructionFor({ ...req, state: \"edgeless\" })\n : null;\n return {\n present: true,\n parses: true,\n callersKnown: true,\n modelled,\n elements,\n inbound,\n outbound,\n expects,\n touched,\n attested,\n instruction,\n };\n}\n\n/**\n * The operations the fleet already calls on this service, read off the landscape\n * FILE alone — `null` when that file cannot be read either.\n *\n * The fallback for an `architecture/` project that does not parse, and the\n * narrowest one that can be justified: it answers ONE question, the one `loam\n * list` and `loam context` answer off the same bytes (`landscapeEvidence`,\n * core/vocabulary/maturity.ts). \"Nothing calls this service\" and \"loam could not\n * tell\" are different answers, and only the first may switch an API contract\n * off, which is why the empty list and the unreadable file are told apart here\n * rather than collapsed to `[]`.\n */\nasync function expectsFromFile(path: string, service: string, known: ReadonlySet<string>): Promise<string[] | null> {\n try {\n const doc = await loadFile(path);\n if (doc.errors.length > 0) return null;\n const svcOf = serviceResolver(doc.elements, known);\n const ops = doc.relationships\n .filter((r) => svcOf(r.target) === service)\n .map((r) => r.op)\n .filter((op): op is string => op !== undefined);\n return [...new Set(ops)];\n } catch {\n return null;\n }\n}\n"]}
@@ -0,0 +1,81 @@
1
+ /** The literals `targets.ts` leaves in the model target for this module to fill in. */
2
+ export const FQN = "<fqn>";
3
+ /**
4
+ * The service being adopted, in the model example's header. It is a placeholder
5
+ * for the same reason `<fqn>` is: the example is handed to an agent that copies
6
+ * it, and a header naming payment-service travelled verbatim into every other
7
+ * service's model — the more convincingly for sitting one line above an
8
+ * `extend` the brief HAD substituted.
9
+ */
10
+ export const SVC = "<svc>";
11
+ /** The token an example carries where loam has no id to substitute. Short on purpose — see `ExtendPoint`. */
12
+ const PLACEHOLDER = "<your-element-id>";
13
+ /**
14
+ * Which element an extending `model.likec4` says it is inside — the id, when
15
+ * the map leaves no doubt, and a placeholder plus the doubt when it does.
16
+ *
17
+ * Four answers because the map is in four states and only one of them has an
18
+ * answer to give. With exactly ONE service-level element resolving to this
19
+ * service, `extend <that id> {` is the file's first line and printing anything
20
+ * else makes an agent go and look it up. With NONE, there is nothing to extend
21
+ * yet — the landscape target below this one is what the agent must do first, and
22
+ * saying so is what stops it inventing an id and writing a model that cannot
23
+ * parse. With SEVERAL — `landscape.binding-duplicate`, a real and reported
24
+ * state — loam must not choose: every element→service join in the fleet picks
25
+ * one of them arbitrarily, so a brief that named one would be teaching an agent
26
+ * the arbitrary answer as the right one. And when the map could not be READ
27
+ * (`modelled === null`) the empty element list is evidence of nothing: "write
28
+ * the element into the map first" is exactly the instruction that draws a second
29
+ * box for a service the map already holds, so that arm says the map is
30
+ * unreadable and asks for no map write at all.
31
+ */
32
+ export function extendPoint(landscape) {
33
+ if (landscape.modelled === null) {
34
+ return {
35
+ id: PLACEHOLDER,
36
+ note: "the fleet map (architecture/) does not parse, so loam cannot say which element binds this directory. " +
37
+ "Fix the map first — the landscape section of this brief names the documents that failed — then write " +
38
+ "the id of the element that resolves to this service here.",
39
+ };
40
+ }
41
+ const ids = landscape.elements.map((e) => e.id);
42
+ const [only, ...rest] = ids;
43
+ if (only === undefined) {
44
+ return {
45
+ id: PLACEHOLDER,
46
+ note: "nothing in the fleet map resolves to this directory yet. Add the element to " +
47
+ "architecture/landscape.likec4 first — the landscape target below — then write its id here.",
48
+ };
49
+ }
50
+ return { id: rest.length === 0 ? only : `<one of: ${ids.join(", ")}>` };
51
+ }
52
+ /**
53
+ * An example with its placeholders resolved, and the placeholder's explanation
54
+ * prepended as a comment when there is one.
55
+ *
56
+ * Guarded on the example actually containing `<fqn>`: the note is about that
57
+ * substitution, and heading an example that never had one with it would answer a
58
+ * question its reader did not ask.
59
+ */
60
+ export function exampleFor(example, extend, service) {
61
+ const body = example.replaceAll(FQN, extend.id).replaceAll(SVC, service);
62
+ if (extend.note === undefined || !example.includes(FQN))
63
+ return body;
64
+ return `${commentLines(`${extend.id} is a placeholder: ${extend.note}`)}\n\n${body}`;
65
+ }
66
+ /** One sentence as `//` lines, wrapped to the width the examples around it are written at. */
67
+ function commentLines(text, width = 76) {
68
+ const out = [];
69
+ let line = "//";
70
+ for (const word of text.trim().split(/\s+/)) {
71
+ if (line !== "//" && line.length + 1 + word.length > width) {
72
+ out.push(line);
73
+ line = `// ${word}`;
74
+ }
75
+ else
76
+ line = `${line} ${word}`;
77
+ }
78
+ out.push(line);
79
+ return out.join("\n");
80
+ }
81
+ //# sourceMappingURL=extend.js.map