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

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 (691) hide show
  1. package/CHANGELOG.md +1477 -1
  2. package/COMPARISON.md +91 -3
  3. package/CONTRIBUTING.md +37 -0
  4. package/MIGRATING-from-OpenSpec.md +40 -22
  5. package/QUICKSTART.md +181 -9
  6. package/README.md +256 -57
  7. package/ROADMAP.md +108 -11
  8. package/SCHEMA.md +721 -130
  9. package/WORKFLOW.md +272 -62
  10. package/dist/cli.js +26 -8
  11. package/dist/cli.js.map +1 -1
  12. package/dist/commands/adopt/adopt.js +5 -10
  13. package/dist/commands/adopt/adopt.js.map +1 -1
  14. package/dist/commands/archive/archive.js +15 -18
  15. package/dist/commands/archive/archive.js.map +1 -1
  16. package/dist/commands/archive/plan/contracts/asyncapi.js +27 -41
  17. package/dist/commands/archive/plan/contracts/asyncapi.js.map +1 -1
  18. package/dist/commands/archive/plan/contracts/consumers.js +56 -0
  19. package/dist/commands/archive/plan/contracts/consumers.js.map +1 -0
  20. package/dist/commands/archive/plan/contracts/openapi.js +25 -42
  21. package/dist/commands/archive/plan/contracts/openapi.js.map +1 -1
  22. package/dist/commands/archive/plan/contracts/verdict-lines.js +41 -0
  23. package/dist/commands/archive/plan/contracts/verdict-lines.js.map +1 -0
  24. package/dist/commands/archive/plan/gate.js +3 -7
  25. package/dist/commands/archive/plan/gate.js.map +1 -1
  26. package/dist/commands/archive/plan/landscape.js +4 -4
  27. package/dist/commands/archive/plan/landscape.js.map +1 -1
  28. package/dist/commands/archive/plan/refusal.js +8 -18
  29. package/dist/commands/archive/plan/refusal.js.map +1 -1
  30. package/dist/commands/archive/plan/specs.js +134 -25
  31. package/dist/commands/archive/plan/specs.js.map +1 -1
  32. package/dist/commands/archive/plan/state.js +1 -0
  33. package/dist/commands/archive/plan/state.js.map +1 -1
  34. package/dist/commands/archive/run.js +82 -33
  35. package/dist/commands/archive/run.js.map +1 -1
  36. package/dist/commands/archive/shipped.js +49 -0
  37. package/dist/commands/archive/shipped.js.map +1 -0
  38. package/dist/commands/context/context.js +4 -7
  39. package/dist/commands/context/context.js.map +1 -1
  40. package/dist/commands/context/print.js +2 -2
  41. package/dist/commands/context/print.js.map +1 -1
  42. package/dist/commands/delta/delta.js +44 -12
  43. package/dist/commands/delta/delta.js.map +1 -1
  44. package/dist/commands/delta/print.js +1 -1
  45. package/dist/commands/delta/print.js.map +1 -1
  46. package/dist/commands/dependencies.js +3 -7
  47. package/dist/commands/dependencies.js.map +1 -1
  48. package/dist/commands/diff/diff.js +20 -27
  49. package/dist/commands/diff/diff.js.map +1 -1
  50. package/dist/commands/explore.js +4 -8
  51. package/dist/commands/explore.js.map +1 -1
  52. package/dist/commands/gate/gate.js +45 -8
  53. package/dist/commands/gate/gate.js.map +1 -1
  54. package/dist/commands/gate/print.js +15 -3
  55. package/dist/commands/gate/print.js.map +1 -1
  56. package/dist/commands/gherkin/commit.js +13 -54
  57. package/dist/commands/gherkin/commit.js.map +1 -1
  58. package/dist/commands/gherkin/gherkin.js +36 -20
  59. package/dist/commands/gherkin/gherkin.js.map +1 -1
  60. package/dist/commands/gherkin/reconcile.js +10 -13
  61. package/dist/commands/gherkin/reconcile.js.map +1 -1
  62. package/dist/commands/init/first-hour.js +44 -0
  63. package/dist/commands/init/first-hour.js.map +1 -1
  64. package/dist/commands/init/init.js +18 -22
  65. package/dist/commands/init/init.js.map +1 -1
  66. package/dist/commands/list/campaign/campaign.js +4 -6
  67. package/dist/commands/list/campaign/campaign.js.map +1 -1
  68. package/dist/commands/list/json.js +0 -4
  69. package/dist/commands/list/json.js.map +1 -1
  70. package/dist/commands/list/list.js +38 -23
  71. package/dist/commands/list/list.js.map +1 -1
  72. package/dist/commands/list/print.js +38 -6
  73. package/dist/commands/list/print.js.map +1 -1
  74. package/dist/commands/list/suites/suites.js +140 -0
  75. package/dist/commands/list/suites/suites.js.map +1 -0
  76. package/dist/commands/list/views.js +28 -33
  77. package/dist/commands/list/views.js.map +1 -1
  78. package/dist/commands/mcp/dispatch.js +91 -36
  79. package/dist/commands/mcp/dispatch.js.map +1 -1
  80. package/dist/commands/mcp/mcp.js +56 -15
  81. package/dist/commands/mcp/mcp.js.map +1 -1
  82. package/dist/commands/mcp/serve.js.map +1 -1
  83. package/dist/commands/migrate-openspec/materialize/active.js +27 -22
  84. package/dist/commands/migrate-openspec/materialize/active.js.map +1 -1
  85. package/dist/commands/migrate-openspec/materialize/stage.js +4 -3
  86. package/dist/commands/migrate-openspec/materialize/stage.js.map +1 -1
  87. package/dist/commands/migrate-openspec/materialize/target.js +2 -2
  88. package/dist/commands/migrate-openspec/materialize/target.js.map +1 -1
  89. package/dist/commands/migrate-openspec/openspec/decisions.js +9 -14
  90. package/dist/commands/migrate-openspec/openspec/decisions.js.map +1 -1
  91. package/dist/commands/migrate-openspec/openspec/error.js +7 -8
  92. package/dist/commands/migrate-openspec/openspec/error.js.map +1 -1
  93. package/dist/commands/migrate-openspec/openspec/mapping.js +1 -9
  94. package/dist/commands/migrate-openspec/openspec/mapping.js.map +1 -1
  95. package/dist/commands/migrate-openspec/openspec/paths.js +3 -6
  96. package/dist/commands/migrate-openspec/openspec/paths.js.map +1 -1
  97. package/dist/commands/new/capability-template.js +118 -0
  98. package/dist/commands/new/capability-template.js.map +1 -0
  99. package/dist/commands/new/commit.js +8 -22
  100. package/dist/commands/new/commit.js.map +1 -1
  101. package/dist/commands/new/modifies.js +206 -0
  102. package/dist/commands/new/modifies.js.map +1 -0
  103. package/dist/commands/new/new.js +59 -14
  104. package/dist/commands/new/new.js.map +1 -1
  105. package/dist/commands/new/templates.js +48 -124
  106. package/dist/commands/new/templates.js.map +1 -1
  107. package/dist/commands/open.js +3 -7
  108. package/dist/commands/open.js.map +1 -1
  109. package/dist/commands/policy/gate.js +27 -0
  110. package/dist/commands/policy/gate.js.map +1 -1
  111. package/dist/commands/rebase/plan.js +2 -2
  112. package/dist/commands/rebase/plan.js.map +1 -1
  113. package/dist/commands/rebase/rebase.js +60 -35
  114. package/dist/commands/rebase/rebase.js.map +1 -1
  115. package/dist/commands/seed/commit.js +55 -26
  116. package/dist/commands/seed/commit.js.map +1 -1
  117. package/dist/commands/seed/plan.js +64 -13
  118. package/dist/commands/seed/plan.js.map +1 -1
  119. package/dist/commands/seed/seed.js +6 -9
  120. package/dist/commands/seed/seed.js.map +1 -1
  121. package/dist/commands/show/show.js +3 -7
  122. package/dist/commands/show/show.js.map +1 -1
  123. package/dist/commands/status/print.js +13 -4
  124. package/dist/commands/status/print.js.map +1 -1
  125. package/dist/commands/status/status.js +3 -7
  126. package/dist/commands/status/status.js.map +1 -1
  127. package/dist/commands/steps/steps.js +3 -7
  128. package/dist/commands/steps/steps.js.map +1 -1
  129. package/dist/commands/subsystem/edit.js +7 -7
  130. package/dist/commands/subsystem/edit.js.map +1 -1
  131. package/dist/commands/subsystem/move.js +60 -25
  132. package/dist/commands/subsystem/move.js.map +1 -1
  133. package/dist/commands/subsystem/query.js +2 -4
  134. package/dist/commands/subsystem/query.js.map +1 -1
  135. package/dist/commands/subsystem/subsystem.js +4 -7
  136. package/dist/commands/subsystem/subsystem.js.map +1 -1
  137. package/dist/commands/subsystem/sync.js +141 -71
  138. package/dist/commands/subsystem/sync.js.map +1 -1
  139. package/dist/commands/subsystem/txn/report.js +55 -5
  140. package/dist/commands/subsystem/txn/report.js.map +1 -1
  141. package/dist/commands/subsystem/txn/txn.js +121 -45
  142. package/dist/commands/subsystem/txn/txn.js.map +1 -1
  143. package/dist/commands/subsystem/txn/views.js +82 -12
  144. package/dist/commands/subsystem/txn/views.js.map +1 -1
  145. package/dist/commands/tasks/render.js +116 -0
  146. package/dist/commands/tasks/render.js.map +1 -0
  147. package/dist/commands/tasks/tasks.js +113 -0
  148. package/dist/commands/tasks/tasks.js.map +1 -0
  149. package/dist/commands/unarchive/manifest.js +6 -9
  150. package/dist/commands/unarchive/manifest.js.map +1 -1
  151. package/dist/commands/unarchive/restore.js +17 -28
  152. package/dist/commands/unarchive/restore.js.map +1 -1
  153. package/dist/commands/unarchive/unarchive.js +22 -30
  154. package/dist/commands/unarchive/unarchive.js.map +1 -1
  155. package/dist/commands/validate/arch-coverage.js +6 -15
  156. package/dist/commands/validate/arch-coverage.js.map +1 -1
  157. package/dist/commands/validate/checks/fleet-shape.js +4 -49
  158. package/dist/commands/validate/checks/fleet-shape.js.map +1 -1
  159. package/dist/commands/validate/checks/health-deps.js +9 -6
  160. package/dist/commands/validate/checks/health-deps.js.map +1 -1
  161. package/dist/commands/validate/checks/requirements.js +18 -8
  162. package/dist/commands/validate/checks/requirements.js.map +1 -1
  163. package/dist/commands/validate/checks/sources.js +6 -2
  164. package/dist/commands/validate/checks/sources.js.map +1 -1
  165. package/dist/commands/validate/feature.js +23 -19
  166. package/dist/commands/validate/feature.js.map +1 -1
  167. package/dist/commands/validate/fleet/census.js +26 -3
  168. package/dist/commands/validate/fleet/census.js.map +1 -1
  169. package/dist/commands/validate/fleet/landscape.js +35 -32
  170. package/dist/commands/validate/fleet/landscape.js.map +1 -1
  171. package/dist/commands/validate/fleet/map/attest.js +7 -12
  172. package/dist/commands/validate/fleet/map/attest.js.map +1 -1
  173. package/dist/commands/validate/fleet/map/bindings.js +16 -5
  174. package/dist/commands/validate/fleet/map/bindings.js.map +1 -1
  175. package/dist/commands/validate/fleet/map/consumers.js +43 -122
  176. package/dist/commands/validate/fleet/map/consumers.js.map +1 -1
  177. package/dist/commands/validate/fleet/map/usecases.js +5 -11
  178. package/dist/commands/validate/fleet/map/usecases.js.map +1 -1
  179. package/dist/commands/validate/fleet/obligations.js +1 -5
  180. package/dist/commands/validate/fleet/obligations.js.map +1 -1
  181. package/dist/commands/validate/fleet/scorecard/print.js +5 -1
  182. package/dist/commands/validate/fleet/scorecard/print.js.map +1 -1
  183. package/dist/commands/validate/fleet/scorecard/scorecard.js +17 -11
  184. package/dist/commands/validate/fleet/scorecard/scorecard.js.map +1 -1
  185. package/dist/commands/validate/fleet/usecases/usecases.js +6 -4
  186. package/dist/commands/validate/fleet/usecases/usecases.js.map +1 -1
  187. package/dist/commands/validate/fleet/views/fleet-project.js +1 -1
  188. package/dist/commands/validate/fleet/views/fleet-project.js.map +1 -1
  189. package/dist/commands/validate/fleet/views/ids.js +33 -7
  190. package/dist/commands/validate/fleet/views/ids.js.map +1 -1
  191. package/dist/commands/validate/fleet/views/root-documents.js +17 -35
  192. package/dist/commands/validate/fleet/views/root-documents.js.map +1 -1
  193. package/dist/commands/validate/fleet/views/stale.js +31 -14
  194. package/dist/commands/validate/fleet/views/stale.js.map +1 -1
  195. package/dist/commands/validate/links/corpus.js +1 -4
  196. package/dist/commands/validate/links/corpus.js.map +1 -1
  197. package/dist/commands/validate/links/glossary.js.map +1 -1
  198. package/dist/commands/validate/report.js +5 -4
  199. package/dist/commands/validate/report.js.map +1 -1
  200. package/dist/commands/validate/scope.js +113 -0
  201. package/dist/commands/validate/scope.js.map +1 -0
  202. package/dist/commands/validate/service/api.js +16 -104
  203. package/dist/commands/validate/service/api.js.map +1 -1
  204. package/dist/commands/validate/service/contracts/generated.js +134 -0
  205. package/dist/commands/validate/service/contracts/generated.js.map +1 -0
  206. package/dist/commands/validate/service/events/events.js +1 -1
  207. package/dist/commands/validate/service/events/events.js.map +1 -1
  208. package/dist/commands/validate/service/events/message-producers.js +1 -1
  209. package/dist/commands/validate/service/events/message-producers.js.map +1 -1
  210. package/dist/commands/validate/service/evidence-pins.js +56 -10
  211. package/dist/commands/validate/service/evidence-pins.js.map +1 -1
  212. package/dist/commands/validate/service/service.js +16 -26
  213. package/dist/commands/validate/service/service.js.map +1 -1
  214. package/dist/commands/validate/service/specs.js +31 -38
  215. package/dist/commands/validate/service/specs.js.map +1 -1
  216. package/dist/commands/validate/service/spine.js +8 -11
  217. package/dist/commands/validate/service/spine.js.map +1 -1
  218. package/dist/commands/validate/service/usecases/usecases.js +3 -3
  219. package/dist/commands/validate/service/usecases/usecases.js.map +1 -1
  220. package/dist/commands/validate/validate.js +44 -26
  221. package/dist/commands/validate/validate.js.map +1 -1
  222. package/dist/commands/verify/cross/diff.js +2 -6
  223. package/dist/commands/verify/cross/diff.js.map +1 -1
  224. package/dist/commands/verify/evidence/contract.js +1 -1
  225. package/dist/commands/verify/evidence/contract.js.map +1 -1
  226. package/dist/commands/verify/evidence/read.js +12 -3
  227. package/dist/commands/verify/evidence/read.js.map +1 -1
  228. package/dist/commands/verify/frozen.js +45 -23
  229. package/dist/commands/verify/frozen.js.map +1 -1
  230. package/dist/commands/verify/record.js +69 -17
  231. package/dist/commands/verify/record.js.map +1 -1
  232. package/dist/commands/verify/report.js +27 -44
  233. package/dist/commands/verify/report.js.map +1 -1
  234. package/dist/commands/verify/results.js +112 -30
  235. package/dist/commands/verify/results.js.map +1 -1
  236. package/dist/commands/verify/verify.js +54 -51
  237. package/dist/commands/verify/verify.js.map +1 -1
  238. package/dist/commands/vouch/pack/pack.js +2 -2
  239. package/dist/commands/vouch/pack/pack.js.map +1 -1
  240. package/dist/commands/vouch/pack/print.js +1 -6
  241. package/dist/commands/vouch/pack/print.js.map +1 -1
  242. package/dist/commands/vouch/pack/sections.js +1 -2
  243. package/dist/commands/vouch/pack/sections.js.map +1 -1
  244. package/dist/commands/vouch/run.js +26 -81
  245. package/dist/commands/vouch/run.js.map +1 -1
  246. package/dist/commands/vouch/sample/plan.js +20 -34
  247. package/dist/commands/vouch/sample/plan.js.map +1 -1
  248. package/dist/commands/vouch/vet/verify.js +39 -7
  249. package/dist/commands/vouch/vet/verify.js.map +1 -1
  250. package/dist/commands/vouch/vouch.js +10 -17
  251. package/dist/commands/vouch/vouch.js.map +1 -1
  252. package/dist/core/agent/agents-md/command-map.js +57 -102
  253. package/dist/core/agent/agents-md/command-map.js.map +1 -1
  254. package/dist/core/agent/agents-md/map/explain.js +4 -3
  255. package/dist/core/agent/agents-md/map/explain.js.map +1 -1
  256. package/dist/core/agent/agents-md/map/lenses/context.js +4 -3
  257. package/dist/core/agent/agents-md/map/lenses/context.js.map +1 -1
  258. package/dist/core/agent/agents-md/map/lenses/diff.js +33 -20
  259. package/dist/core/agent/agents-md/map/lenses/diff.js.map +1 -1
  260. package/dist/core/agent/agents-md/map/lenses/gate.js +13 -5
  261. package/dist/core/agent/agents-md/map/lenses/gate.js.map +1 -1
  262. package/dist/core/agent/agents-md/map/mcp.js +10 -7
  263. package/dist/core/agent/agents-md/map/mcp.js.map +1 -1
  264. package/dist/core/agent/agents-md/map/status.js +9 -3
  265. package/dist/core/agent/agents-md/map/status.js.map +1 -1
  266. package/dist/core/agent/agents-md/map/subsystem.js +31 -17
  267. package/dist/core/agent/agents-md/map/subsystem.js.map +1 -1
  268. package/dist/core/agent/agents-md/map/usecases.js +24 -6
  269. package/dist/core/agent/agents-md/map/usecases.js.map +1 -1
  270. package/dist/core/agent/agents-md/refusals.js +37 -21
  271. package/dist/core/agent/agents-md/refusals.js.map +1 -1
  272. package/dist/core/agent/agents-md.js +25 -10
  273. package/dist/core/agent/agents-md.js.map +1 -1
  274. package/dist/core/agent/agents-stamp.js +10 -0
  275. package/dist/core/agent/agents-stamp.js.map +1 -1
  276. package/dist/core/agent/scaffold.js +10 -15
  277. package/dist/core/agent/scaffold.js.map +1 -1
  278. package/dist/core/agent/tools/dialects.js +1 -0
  279. package/dist/core/agent/tools/dialects.js.map +1 -1
  280. package/dist/core/agent/tools/registry.js +41 -76
  281. package/dist/core/agent/tools/registry.js.map +1 -1
  282. package/dist/core/agent/workflows/adopt.js +5 -3
  283. package/dist/core/agent/workflows/adopt.js.map +1 -1
  284. package/dist/core/agent/workflows/check.js +25 -22
  285. package/dist/core/agent/workflows/check.js.map +1 -1
  286. package/dist/core/agent/workflows/closing.js +54 -21
  287. package/dist/core/agent/workflows/closing.js.map +1 -1
  288. package/dist/core/agent/workflows/feature.js +79 -11
  289. package/dist/core/agent/workflows/feature.js.map +1 -1
  290. package/dist/core/agent/workflows/implement.js +91 -13
  291. package/dist/core/agent/workflows/implement.js.map +1 -1
  292. package/dist/core/agent/workflows/reference/authoring.js +3 -1
  293. package/dist/core/agent/workflows/reference/authoring.js.map +1 -1
  294. package/dist/core/agent/workflows/reference/codes.js +8 -6
  295. package/dist/core/agent/workflows/reference/codes.js.map +1 -1
  296. package/dist/core/agent/workflows/reference/done-check.js +37 -15
  297. package/dist/core/agent/workflows/reference/done-check.js.map +1 -1
  298. package/dist/core/agent/workflows/reference/reference.js.map +1 -1
  299. package/dist/core/agent/workflows/reference/spine.js +62 -24
  300. package/dist/core/agent/workflows/reference/spine.js.map +1 -1
  301. package/dist/core/asyncapi/baseline/plan.js +14 -81
  302. package/dist/core/asyncapi/baseline/plan.js.map +1 -1
  303. package/dist/core/asyncapi/digest.js +30 -25
  304. package/dist/core/asyncapi/digest.js.map +1 -1
  305. package/dist/core/asyncapi/merge/components.js +5 -4
  306. package/dist/core/asyncapi/merge/components.js.map +1 -1
  307. package/dist/core/asyncapi/merge/error.js +7 -2
  308. package/dist/core/asyncapi/merge/error.js.map +1 -1
  309. package/dist/core/asyncapi/merge/markers.js +30 -50
  310. package/dist/core/asyncapi/merge/markers.js.map +1 -1
  311. package/dist/core/asyncapi/merge/merge.js +31 -53
  312. package/dist/core/asyncapi/merge/merge.js.map +1 -1
  313. package/dist/core/asyncapi/merge/pin.js +10 -36
  314. package/dist/core/asyncapi/merge/pin.js.map +1 -1
  315. package/dist/core/asyncapi/model.js.map +1 -1
  316. package/dist/core/asyncapi/read.js +36 -12
  317. package/dist/core/asyncapi/read.js.map +1 -1
  318. package/dist/core/brief/brief.js +30 -25
  319. package/dist/core/brief/brief.js.map +1 -1
  320. package/dist/core/brief/landscape.js +8 -12
  321. package/dist/core/brief/landscape.js.map +1 -1
  322. package/dist/core/brief/map/extend.js +8 -5
  323. package/dist/core/brief/map/extend.js.map +1 -1
  324. package/dist/core/brief/map/owed.js +8 -26
  325. package/dist/core/brief/map/owed.js.map +1 -1
  326. package/dist/core/brief/targets.js +79 -5
  327. package/dist/core/brief/targets.js.map +1 -1
  328. package/dist/core/brief/unchecked.js +1 -1
  329. package/dist/core/brief/unchecked.js.map +1 -1
  330. package/dist/core/c4/likec4.js +147 -16
  331. package/dist/core/c4/likec4.js.map +1 -1
  332. package/dist/core/c4/locate/unlocated.js +150 -0
  333. package/dist/core/c4/locate/unlocated.js.map +1 -0
  334. package/dist/core/c4/parsed/values.js +54 -1
  335. package/dist/core/c4/parsed/values.js.map +1 -1
  336. package/dist/core/c4/prefetch/fleet.js +1 -9
  337. package/dist/core/c4/prefetch/fleet.js.map +1 -1
  338. package/dist/core/c4/project/architecture.js +31 -9
  339. package/dist/core/c4/project/architecture.js.map +1 -1
  340. package/dist/core/c4/project/documents.js +36 -10
  341. package/dist/core/c4/project/documents.js.map +1 -1
  342. package/dist/core/c4/project/load.js +14 -21
  343. package/dist/core/c4/project/load.js.map +1 -1
  344. package/dist/core/c4/project/staged.js +7 -3
  345. package/dist/core/c4/project/staged.js.map +1 -1
  346. package/dist/core/c4/resolve/external.js +51 -0
  347. package/dist/core/c4/resolve/external.js.map +1 -0
  348. package/dist/core/c4/resolve/service.js +25 -1
  349. package/dist/core/c4/resolve/service.js.map +1 -1
  350. package/dist/core/c4/seed/template.js +15 -1
  351. package/dist/core/c4/seed/template.js.map +1 -1
  352. package/dist/core/c4/service-model/shape.js +2 -22
  353. package/dist/core/c4/service-model/shape.js.map +1 -1
  354. package/dist/core/c4/source-mask.js +288 -4
  355. package/dist/core/c4/source-mask.js.map +1 -1
  356. package/dist/core/c4/source-scan.js +203 -147
  357. package/dist/core/c4/source-scan.js.map +1 -1
  358. package/dist/core/c4/splice/authored-source.js +19 -0
  359. package/dist/core/c4/splice/authored-source.js.map +1 -1
  360. package/dist/core/c4/splice/delta-blocks.js +5 -18
  361. package/dist/core/c4/splice/delta-blocks.js.map +1 -1
  362. package/dist/core/c4/splice/landscape-merge.js +13 -8
  363. package/dist/core/c4/splice/landscape-merge.js.map +1 -1
  364. package/dist/core/c4/splice/model/merge.js +10 -6
  365. package/dist/core/c4/splice/model/merge.js.map +1 -1
  366. package/dist/core/c4/splice/placement.js +108 -18
  367. package/dist/core/c4/splice/placement.js.map +1 -1
  368. package/dist/core/c4/workspace.js +13 -22
  369. package/dist/core/c4/workspace.js.map +1 -1
  370. package/dist/core/capabilities/capabilities.js +6 -6
  371. package/dist/core/capabilities/capabilities.js.map +1 -1
  372. package/dist/core/capabilities/delta/doc.js +7 -10
  373. package/dist/core/capabilities/delta/doc.js.map +1 -1
  374. package/dist/core/capabilities/findings.js +15 -20
  375. package/dist/core/capabilities/findings.js.map +1 -1
  376. package/dist/core/capabilities/realizes/findings.js +12 -19
  377. package/dist/core/capabilities/realizes/findings.js.map +1 -1
  378. package/dist/core/capabilities/realizes/join.js +0 -20
  379. package/dist/core/capabilities/realizes/join.js.map +1 -1
  380. package/dist/core/capabilities/rollup.js +6 -0
  381. package/dist/core/capabilities/rollup.js.map +1 -1
  382. package/dist/core/capabilities/tree.js +6 -28
  383. package/dist/core/capabilities/tree.js.map +1 -1
  384. package/dist/core/capabilities/usecase-join.js +3 -13
  385. package/dist/core/capabilities/usecase-join.js.map +1 -1
  386. package/dist/core/coherence/authoring/scaffold.js +11 -3
  387. package/dist/core/coherence/authoring/scaffold.js.map +1 -1
  388. package/dist/core/coherence/authoring/sentinels.js +2 -1
  389. package/dist/core/coherence/authoring/sentinels.js.map +1 -1
  390. package/dist/core/coherence/coherence.js +30 -16
  391. package/dist/core/coherence/coherence.js.map +1 -1
  392. package/dist/core/coherence/consumed/operations.js +70 -0
  393. package/dist/core/coherence/consumed/operations.js.map +1 -0
  394. package/dist/core/coherence/consumed/refusal.js +38 -0
  395. package/dist/core/coherence/consumed/refusal.js.map +1 -0
  396. package/dist/core/coherence/declared.js +60 -34
  397. package/dist/core/coherence/declared.js.map +1 -1
  398. package/dist/core/coherence/events/declared.js +44 -59
  399. package/dist/core/coherence/events/declared.js.map +1 -1
  400. package/dist/core/coherence/events/events.js +119 -8
  401. package/dist/core/coherence/events/events.js.map +1 -1
  402. package/dist/core/coherence/events/grades.js +31 -8
  403. package/dist/core/coherence/events/grades.js.map +1 -1
  404. package/dist/core/coherence/events/lookups.js +14 -82
  405. package/dist/core/coherence/events/lookups.js.map +1 -1
  406. package/dist/core/coherence/lookups.js +18 -78
  407. package/dist/core/coherence/lookups.js.map +1 -1
  408. package/dist/core/coherence/retired/archived.js +285 -0
  409. package/dist/core/coherence/retired/archived.js.map +1 -0
  410. package/dist/core/coherence/retired/event-pair.js +62 -0
  411. package/dist/core/coherence/retired/event-pair.js.map +1 -0
  412. package/dist/core/coherence/retired/merged.js +79 -0
  413. package/dist/core/coherence/retired/merged.js.map +1 -0
  414. package/dist/core/coherence/retired/retirement.js +49 -0
  415. package/dist/core/coherence/retired/retirement.js.map +1 -0
  416. package/dist/core/coherence/retired/revival/arrivals.js +131 -0
  417. package/dist/core/coherence/retired/revival/arrivals.js.map +1 -0
  418. package/dist/core/coherence/retired/revival/revived.js +297 -0
  419. package/dist/core/coherence/retired/revival/revived.js.map +1 -0
  420. package/dist/core/consumers/after.js +113 -0
  421. package/dist/core/consumers/after.js.map +1 -0
  422. package/dist/core/consumers/consumers.js +296 -0
  423. package/dist/core/consumers/consumers.js.map +1 -0
  424. package/dist/core/consumers/current.js +211 -0
  425. package/dist/core/consumers/current.js.map +1 -0
  426. package/dist/core/consumers/scan.js +46 -0
  427. package/dist/core/consumers/scan.js.map +1 -0
  428. package/dist/core/consumers/state.js +27 -0
  429. package/dist/core/consumers/state.js.map +1 -0
  430. package/dist/core/delta/delta.js +1 -1
  431. package/dist/core/delta/delta.js.map +1 -1
  432. package/dist/core/deployment/delta.js +15 -16
  433. package/dist/core/deployment/delta.js.map +1 -1
  434. package/dist/core/diff/base-git.js +94 -12
  435. package/dist/core/diff/base-git.js.map +1 -1
  436. package/dist/core/diff/base-state.js +28 -16
  437. package/dist/core/diff/base-state.js.map +1 -1
  438. package/dist/core/diff/joins.js +136 -0
  439. package/dist/core/diff/joins.js.map +1 -0
  440. package/dist/core/diff/scope/changed-paths.js +22 -6
  441. package/dist/core/diff/scope/changed-paths.js.map +1 -1
  442. package/dist/core/diff/scope/edges.js +82 -0
  443. package/dist/core/diff/scope/edges.js.map +1 -0
  444. package/dist/core/diff/semantic.js +100 -31
  445. package/dist/core/diff/semantic.js.map +1 -1
  446. package/dist/core/doctor/agents.js +34 -18
  447. package/dist/core/doctor/agents.js.map +1 -1
  448. package/dist/core/doctor/report.js.map +1 -1
  449. package/dist/core/document/apply.js +10 -2
  450. package/dist/core/document/apply.js.map +1 -1
  451. package/dist/core/document/frontmatter.js +55 -0
  452. package/dist/core/document/frontmatter.js.map +1 -1
  453. package/dist/core/document/parse.js +29 -6
  454. package/dist/core/document/parse.js.map +1 -1
  455. package/dist/core/document/scenarios.js +17 -0
  456. package/dist/core/document/scenarios.js.map +1 -1
  457. package/dist/core/document/spec.js +4 -11
  458. package/dist/core/document/spec.js.map +1 -1
  459. package/dist/core/envelope/config.js +10 -0
  460. package/dist/core/envelope/config.js.map +1 -1
  461. package/dist/core/envelope/json.js +34 -0
  462. package/dist/core/envelope/json.js.map +1 -1
  463. package/dist/core/explain/families.js +17 -12
  464. package/dist/core/explain/families.js.map +1 -1
  465. package/dist/core/explain/refusals.js +3 -3
  466. package/dist/core/explain/refusals.js.map +1 -1
  467. package/dist/core/explain/terms.js +18 -9
  468. package/dist/core/explain/terms.js.map +1 -1
  469. package/dist/core/explore/explore.js +2 -7
  470. package/dist/core/explore/explore.js.map +1 -1
  471. package/dist/core/fleet-context.js +34 -95
  472. package/dist/core/fleet-context.js.map +1 -1
  473. package/dist/core/gate/checks.js +10 -3
  474. package/dist/core/gate/checks.js.map +1 -1
  475. package/dist/core/gate/partners.js +64 -19
  476. package/dist/core/gate/partners.js.map +1 -1
  477. package/dist/core/gate/report.js.map +1 -1
  478. package/dist/core/gate/verification.js +75 -12
  479. package/dist/core/gate/verification.js.map +1 -1
  480. package/dist/core/gherkin/stale.js +13 -37
  481. package/dist/core/gherkin/stale.js.map +1 -1
  482. package/dist/core/glossary/tree.js +6 -19
  483. package/dist/core/glossary/tree.js.map +1 -1
  484. package/dist/core/kernel/concurrency.js +19 -0
  485. package/dist/core/kernel/concurrency.js.map +1 -1
  486. package/dist/core/kernel/records.js +11 -0
  487. package/dist/core/kernel/records.js.map +1 -1
  488. package/dist/core/links/backlinks.js +1 -3
  489. package/dist/core/links/backlinks.js.map +1 -1
  490. package/dist/core/links/corpus.js +5 -36
  491. package/dist/core/links/corpus.js.map +1 -1
  492. package/dist/core/mcp/argv.js +101 -0
  493. package/dist/core/mcp/argv.js.map +1 -1
  494. package/dist/core/mcp/author-tools.js +2 -1
  495. package/dist/core/mcp/author-tools.js.map +1 -1
  496. package/dist/core/mcp/protocol.js +2 -2
  497. package/dist/core/mcp/protocol.js.map +1 -1
  498. package/dist/core/mcp/tools.js +43 -33
  499. package/dist/core/mcp/tools.js.map +1 -1
  500. package/dist/core/openapi/baseline/gate.js +53 -12
  501. package/dist/core/openapi/baseline/gate.js.map +1 -1
  502. package/dist/core/openapi/baseline/plan.js +22 -8
  503. package/dist/core/openapi/baseline/plan.js.map +1 -1
  504. package/dist/core/openapi/baseline/record.js +0 -1
  505. package/dist/core/openapi/baseline/record.js.map +1 -1
  506. package/dist/core/openapi/contract-text.js +33 -0
  507. package/dist/core/openapi/contract-text.js.map +1 -0
  508. package/dist/core/openapi/contract-tree.js +56 -0
  509. package/dist/core/openapi/contract-tree.js.map +1 -0
  510. package/dist/core/openapi/depth.js +38 -24
  511. package/dist/core/openapi/depth.js.map +1 -1
  512. package/dist/core/openapi/digest.js +52 -2
  513. package/dist/core/openapi/digest.js.map +1 -1
  514. package/dist/core/openapi/doc.js +12 -4
  515. package/dist/core/openapi/doc.js.map +1 -1
  516. package/dist/core/openapi/merge/components.js +25 -60
  517. package/dist/core/openapi/merge/components.js.map +1 -1
  518. package/dist/core/openapi/merge/error.js +3 -13
  519. package/dist/core/openapi/merge/error.js.map +1 -1
  520. package/dist/core/openapi/merge/markers.js +26 -30
  521. package/dist/core/openapi/merge/markers.js.map +1 -1
  522. package/dist/core/openapi/merge/merge.js +26 -52
  523. package/dist/core/openapi/merge/merge.js.map +1 -1
  524. package/dist/core/openapi/merge/pin.js +15 -35
  525. package/dist/core/openapi/merge/pin.js.map +1 -1
  526. package/dist/core/openspec/decide/verdict.js.map +1 -1
  527. package/dist/core/openspec/inventory.js +4 -5
  528. package/dist/core/openspec/inventory.js.map +1 -1
  529. package/dist/core/openspec/model/mapping.js +30 -28
  530. package/dist/core/openspec/model/mapping.js.map +1 -1
  531. package/dist/core/openspec/model/model.js +12 -7
  532. package/dist/core/openspec/model/model.js.map +1 -1
  533. package/dist/core/openspec/scan/changes.js +10 -4
  534. package/dist/core/openspec/scan/changes.js.map +1 -1
  535. package/dist/core/openspec/scan/config.js +7 -16
  536. package/dist/core/openspec/scan/config.js.map +1 -1
  537. package/dist/core/openspec/scan/shape.js +63 -19
  538. package/dist/core/openspec/scan/shape.js.map +1 -1
  539. package/dist/core/openspec/scan/walk.js +21 -38
  540. package/dist/core/openspec/scan/walk.js.map +1 -1
  541. package/dist/core/pack/living.js +2 -16
  542. package/dist/core/pack/living.js.map +1 -1
  543. package/dist/core/provenance/findings.js +48 -12
  544. package/dist/core/provenance/findings.js.map +1 -1
  545. package/dist/core/provenance/git.js +33 -57
  546. package/dist/core/provenance/git.js.map +1 -1
  547. package/dist/core/provenance/gitq/moves.js +71 -114
  548. package/dist/core/provenance/gitq/moves.js.map +1 -1
  549. package/dist/core/provenance/gitq/vouched-ancestor.js +2 -2
  550. package/dist/core/provenance/gitq/vouched-ancestor.js.map +1 -1
  551. package/dist/core/provenance/sources.js +23 -6
  552. package/dist/core/provenance/sources.js.map +1 -1
  553. package/dist/core/provenance/stamp.js +5 -17
  554. package/dist/core/provenance/stamp.js.map +1 -1
  555. package/dist/core/repo/entries.js.map +1 -1
  556. package/dist/core/repo/paths.js +34 -29
  557. package/dist/core/repo/paths.js.map +1 -1
  558. package/dist/core/repo/repo.js +24 -14
  559. package/dist/core/repo/repo.js.map +1 -1
  560. package/dist/core/repo/tree/find.js +12 -3
  561. package/dist/core/repo/tree/find.js.map +1 -1
  562. package/dist/core/repo/tree/fs.js +27 -1
  563. package/dist/core/repo/tree/fs.js.map +1 -1
  564. package/dist/core/repo/tree/render/body.js +45 -6
  565. package/dist/core/repo/tree/render/body.js.map +1 -1
  566. package/dist/core/repo/tree/render/service/header.js +125 -0
  567. package/dist/core/repo/tree/render/service/header.js.map +1 -0
  568. package/dist/core/repo/tree/render/service/peers.js +28 -0
  569. package/dist/core/repo/tree/render/service/peers.js.map +1 -0
  570. package/dist/core/repo/tree/render/service/view-id.js +67 -0
  571. package/dist/core/repo/tree/render/service/view-id.js.map +1 -0
  572. package/dist/core/repo/tree/render/service/views.js +78 -0
  573. package/dist/core/repo/tree/render/service/views.js.map +1 -0
  574. package/dist/core/repo/tree/render/stale.js +19 -2
  575. package/dist/core/repo/tree/render/stale.js.map +1 -1
  576. package/dist/core/repo/tree/render/views.js +102 -33
  577. package/dist/core/repo/tree/render/views.js.map +1 -1
  578. package/dist/core/repo/tree/walk.js +8 -30
  579. package/dist/core/repo/tree/walk.js.map +1 -1
  580. package/dist/core/results.js +47 -12
  581. package/dist/core/results.js.map +1 -1
  582. package/dist/core/staging/commit.js +10 -12
  583. package/dist/core/staging/commit.js.map +1 -1
  584. package/dist/core/staging/lock.js +74 -12
  585. package/dist/core/staging/lock.js.map +1 -1
  586. package/dist/core/staging/recovery/intent.js +2 -5
  587. package/dist/core/staging/recovery/intent.js.map +1 -1
  588. package/dist/core/staging/recovery/recover.js +60 -1
  589. package/dist/core/staging/recovery/recover.js.map +1 -1
  590. package/dist/core/staging/snapshot/manifest.js +152 -0
  591. package/dist/core/staging/snapshot/manifest.js.map +1 -0
  592. package/dist/core/staging/{snapshot.js → snapshot/snapshot.js} +10 -34
  593. package/dist/core/staging/snapshot/snapshot.js.map +1 -0
  594. package/dist/core/status/actions/execution.js +11 -0
  595. package/dist/core/status/actions/execution.js.map +1 -1
  596. package/dist/core/status/feature/artifacts.js +2 -2
  597. package/dist/core/status/feature/artifacts.js.map +1 -1
  598. package/dist/core/status/feature/feature.js +5 -11
  599. package/dist/core/status/feature/feature.js.map +1 -1
  600. package/dist/core/status/fleet/fleet.js +6 -2
  601. package/dist/core/status/fleet/fleet.js.map +1 -1
  602. package/dist/core/status/fleet/next.js +26 -3
  603. package/dist/core/status/fleet/next.js.map +1 -1
  604. package/dist/core/status/report.js.map +1 -1
  605. package/dist/core/status/verification.js +30 -15
  606. package/dist/core/status/verification.js.map +1 -1
  607. package/dist/core/tasks/packet.js +174 -0
  608. package/dist/core/tasks/packet.js.map +1 -0
  609. package/dist/core/tasks/record.js +43 -0
  610. package/dist/core/tasks/record.js.map +1 -0
  611. package/dist/core/tasks/sources.js +181 -0
  612. package/dist/core/tasks/sources.js.map +1 -0
  613. package/dist/core/tasks/stamps.js +76 -0
  614. package/dist/core/tasks/stamps.js.map +1 -0
  615. package/dist/core/tasks/unit.js +0 -0
  616. package/dist/core/tasks/unit.js.map +1 -0
  617. package/dist/core/usecases/capability.js +11 -14
  618. package/dist/core/usecases/capability.js.map +1 -1
  619. package/dist/core/usecases/delta/flows.js +5 -7
  620. package/dist/core/usecases/delta/flows.js.map +1 -1
  621. package/dist/core/usecases/fleet.js +178 -31
  622. package/dist/core/usecases/fleet.js.map +1 -1
  623. package/dist/core/usecases/operations.js +5 -4
  624. package/dist/core/usecases/operations.js.map +1 -1
  625. package/dist/core/usecases/service/flows.js +9 -6
  626. package/dist/core/usecases/service/flows.js.map +1 -1
  627. package/dist/core/usecases/suites/participants.js +83 -0
  628. package/dist/core/usecases/suites/participants.js.map +1 -0
  629. package/dist/core/usecases/suites/suites.js +45 -0
  630. package/dist/core/usecases/suites/suites.js.map +1 -0
  631. package/dist/core/verify/answers.js +12 -5
  632. package/dist/core/verify/answers.js.map +1 -1
  633. package/dist/core/verify/build.js +102 -82
  634. package/dist/core/verify/build.js.map +1 -1
  635. package/dist/core/verify/checklist.js +45 -10
  636. package/dist/core/verify/checklist.js.map +1 -1
  637. package/dist/core/verify/location.js +67 -0
  638. package/dist/core/verify/location.js.map +1 -0
  639. package/dist/core/verify/pins/lint.js +3 -2
  640. package/dist/core/verify/pins/lint.js.map +1 -1
  641. package/dist/core/verify/pins/pin.js +1 -1
  642. package/dist/core/verify/pins/pin.js.map +1 -1
  643. package/dist/core/verify/read/file.js +224 -0
  644. package/dist/core/verify/read/file.js.map +1 -0
  645. package/dist/core/verify/{file.js → read/shape.js} +16 -104
  646. package/dist/core/verify/read/shape.js.map +1 -0
  647. package/dist/core/verify/read/union.js +105 -0
  648. package/dist/core/verify/read/union.js.map +1 -0
  649. package/dist/core/verify/record.js +35 -12
  650. package/dist/core/verify/record.js.map +1 -1
  651. package/dist/core/verify/store/commit.js +40 -30
  652. package/dist/core/verify/store/commit.js.map +1 -1
  653. package/dist/core/verify/store/render.js +8 -4
  654. package/dist/core/verify/store/render.js.map +1 -1
  655. package/dist/core/vocabulary/issue.js +1 -0
  656. package/dist/core/vocabulary/issue.js.map +1 -1
  657. package/dist/core/vocabulary/maturity.js +53 -3
  658. package/dist/core/vocabulary/maturity.js.map +1 -1
  659. package/examples/README.md +28 -9
  660. package/examples/docs/architecture/landscape.likec4 +21 -7
  661. package/examples/docs/architecture/services.likec4 +70 -0
  662. package/examples/docs/architecture/subsystems.likec4 +3 -0
  663. package/examples/docs/architecture/usecases/order-notification.likec4 +6 -2
  664. package/examples/docs/features/FEAT-101-payment-splitting/specs/payment-service/asyncapi.yaml +11 -8
  665. package/examples/docs/features/FEAT-101-payment-splitting/specs/payment-split-service/openapi.yaml +6 -6
  666. package/examples/docs/features/archive/FEAT-088-refunds/specs/payment-service/openapi.yaml +13 -10
  667. package/examples/docs/services/order-service/asyncapi.yaml +3 -2
  668. package/examples/docs/services/order-service/model.likec4 +10 -8
  669. package/examples/docs/services/payment-service/model.likec4 +6 -4
  670. package/examples/docs/services/platform/identity-service/model.likec4 +9 -7
  671. package/examples/docs/services/platform/notification-service/asyncapi.yaml +2 -1
  672. package/examples/docs/services/platform/notification-service/model.likec4 +4 -5
  673. package/package.json +1 -1
  674. package/dist/commands/validate/checks/vocabulary.js +0 -16
  675. package/dist/commands/validate/checks/vocabulary.js.map +0 -1
  676. package/dist/core/agent/agents-md/artifacts.js +0 -221
  677. package/dist/core/agent/agents-md/artifacts.js.map +0 -1
  678. package/dist/core/agent/agents-md/cycle.js +0 -180
  679. package/dist/core/agent/agents-md/cycle.js.map +0 -1
  680. package/dist/core/agent/agents-md/shipped/archive-gate.js +0 -98
  681. package/dist/core/agent/agents-md/shipped/archive-gate.js.map +0 -1
  682. package/dist/core/agent/agents-md/spine.js +0 -40
  683. package/dist/core/agent/agents-md/spine.js.map +0 -1
  684. package/dist/core/coherence/events/merged.js +0 -40
  685. package/dist/core/coherence/events/merged.js.map +0 -1
  686. package/dist/core/diff/current-state.js +0 -96
  687. package/dist/core/diff/current-state.js.map +0 -1
  688. package/dist/core/diff/victims.js +0 -256
  689. package/dist/core/diff/victims.js.map +0 -1
  690. package/dist/core/staging/snapshot.js.map +0 -1
  691. package/dist/core/verify/file.js.map +0 -1
@@ -1,20 +1,24 @@
1
+ import { existsSync } from "node:fs";
1
2
  import {} from "../../core/staging/writes.js";
2
3
  import { commitScaffold } from "./commit.js";
3
4
  import { join } from "node:path";
4
- import { loadConfig } from "../../core/envelope/config.js";
5
5
  import { parseFeatureId } from "../../core/kernel/ids/feature.js";
6
6
  import { parseServiceIds } from "../../core/kernel/ids/service.js";
7
- import { emitJson, fail, repoPath, reportNoConfig } from "../../core/envelope/json.js";
7
+ import { configOrRefuse, emitJson, fail, repoPath } from "../../core/envelope/json.js";
8
8
  import { UnsafePathError, resolveInside } from "../../core/kernel/path-safety.js";
9
9
  import { featureIdFromDirName, nearestIds } from "../../core/repo/entries.js";
10
- import { featuresDir } from "../../core/repo/paths.js";
10
+ import { featuresDir, landscapePath } from "../../core/repo/paths.js";
11
+ import { loadArchitecture } from "../../core/c4/project/architecture.js";
12
+ import { drawnServiceElements } from "../../core/c4/resolve/service.js";
11
13
  import { DocsRepoUnavailableError } from "../../core/repo/state.js";
12
14
  import { listServices } from "../../core/repo/repo.js";
13
15
  import { docsRepoReady, reportDocsRepoError } from "../policy/gate.js";
14
16
  import { sayRecovered } from "../policy/format.js";
15
17
  import { capabilityIdProblem } from "../../core/kernel/ids/capability.js";
16
18
  import { capabilityNotes } from "../../core/capabilities/authoring/notes.js";
17
- import { archSpecTemplate, capabilityDeltaTemplate, deltaTemplate, intentTemplate, openapiTemplate, specTemplate, } from "./templates.js";
19
+ import { modifiedFiles, planModifies } from "./modifies.js";
20
+ import { archSpecTemplate, deltaTemplate, intentTemplate, openapiTemplate, specTemplate } from "./templates.js";
21
+ import { capabilityDeltaTemplate } from "./capability-template.js";
18
22
  export function registerNew(program) {
19
23
  program
20
24
  .command("new")
@@ -42,6 +46,9 @@ export function registerNew(program) {
42
46
  // promises is as real as a feature touching two services, and the flag that
43
47
  // is not repeatable is the one that sends an author to mkdir by hand.
44
48
  .option("--capability <id>", "a business capability this feature changes (repeatable)", collect, [])
49
+ // The small-change lane (./modifies.ts): the living requirement copied
50
+ // into an uncommented MODIFIED block, pinned at scaffold time.
51
+ .option("--modifies <Req-ID>", "a living requirement of a --touches service this feature rewrites (repeatable): scaffolds its MODIFIED block, already pinned", collect, [])
45
52
  .option("--json", "emit the machine contract instead of the human view")
46
53
  .action(async (featureId, opts) => {
47
54
  const json = opts.json === true;
@@ -92,12 +99,9 @@ export function registerNew(program) {
92
99
  if (problem !== null)
93
100
  return fail(json, "invalid-option", problem);
94
101
  }
95
- const loaded = await loadConfig();
96
- if (loaded.kind !== "loaded") {
97
- reportNoConfig(json, loaded);
102
+ const config = await configOrRefuse(json);
103
+ if (config === null)
98
104
  return;
99
- }
100
- const config = loaded.config;
101
105
  const { docsDir } = config;
102
106
  // Before a single file is scaffolded: a docsDir that is not a docs repo is
103
107
  // refused, never written into. `features/<id>/**` lands happily in any
@@ -122,13 +126,26 @@ export function registerNew(program) {
122
126
  const created = new Set(newServices.ids);
123
127
  const touched = touches.ids.filter((s) => !created.has(s));
124
128
  const dir = join(featuresDir(docsDir), dirName);
125
- const files = {
126
- "intent.md": intentTemplate(featureId, opts.title),
127
- "delta.likec4": deltaTemplate(featureId, touched, [...created]),
128
- };
129
+ // Resolved before anything is written: an id naming no living
130
+ // requirement refuses the whole scaffold, as a bad --touches id does.
131
+ const modifies = await planModifies(docsDir, touched, opts.modifies);
132
+ if (!modifies.ok)
133
+ return fail(json, modifies.code, modifies.message);
134
+ // `--modifies` and nothing else — every touched service has a requirement
135
+ // rewritten, none is introduced, no promise opened — is a feature that
136
+ // changes no architecture, and the scaffold's own advice for that case is
137
+ // "delete delta.likec4". So it is not written; validate and archive read
138
+ // a requirements-only feature as complete without it.
139
+ const requirementsOnly = modifies.targets.length > 0 && created.size === 0 && capabilities.length === 0 &&
140
+ touched.every((svc) => modifies.targets.some((t) => t.service === svc));
141
+ const files = { "intent.md": intentTemplate(featureId, opts.title) };
142
+ if (!requirementsOnly) {
143
+ files["delta.likec4"] = deltaTemplate(featureId, touched, [...created], await drawnIds(docsDir, touched));
144
+ }
129
145
  for (const svc of [...touched, ...created]) {
130
146
  files[join("specs", svc, "spec.md")] = specTemplate(featureId, svc);
131
147
  }
148
+ Object.assign(files, modifiedFiles(featureId, modifies.targets, files));
132
149
  // The business axis, and the ONE file `--capability` adds. No service
133
150
  // spec rides with it, and that is the inversion rather than an omission:
134
151
  // the whole point of opening the document that changes first is that the
@@ -218,8 +235,17 @@ export function registerNew(program) {
218
235
  console.log(`${featureId} scaffolded at ${repoPath(docsDir, dir)}`);
219
236
  for (const w of written)
220
237
  console.log(` + ${w}`);
238
+ for (const t of modifies.targets)
239
+ console.log(` ~ MODIFIED ${t.id}: copied from ${t.living}, Based-On already pinned`);
221
240
  for (const note of notes)
222
241
  console.log(`\n note: ${note}`);
242
+ if (requirementsOnly) {
243
+ console.log(`\nNext: edit each MODIFIED requirement in place, write intent.md's Why, then\n` +
244
+ `\`loam validate --feature ${featureId}\` and \`loam archive ${featureId}\`. No delta.likec4 was written:\n` +
245
+ "rewriting requirements changes no architecture. If this change also moves an element or\n" +
246
+ "an edge, add one — `loam instructions loam-feature` shows its shape.");
247
+ return;
248
+ }
223
249
  console.log(`\nNext: fill in the delta, then \`loam validate --feature ${featureId}\`.`);
224
250
  console.log("If this feature changes no architecture, delete delta.likec4 — a requirements-only\n" +
225
251
  "feature is complete without it, and an empty `model {}` validates clean too.");
@@ -266,6 +292,26 @@ async function unknownServiceNotes(docsDir, touched) {
266
292
  }
267
293
  return notes;
268
294
  }
295
+ /**
296
+ * The element ids the fleet map already draws the touched services as, so the
297
+ * delta's context lines reuse them instead of guessing — the delta's own
298
+ * comment tells the author to reuse the map's identifiers, and it used to
299
+ * hand them a camel-cased guess that never matched a seeded map's `svc_<id>`.
300
+ *
301
+ * Best effort by design: `new` is a scaffolder, not a validator. No map, or
302
+ * one that does not parse, leaves every id to the seed convention, and
303
+ * `loam validate` reports the map on its own. The project loader and the
304
+ * resolver are the ones `loam adopt` reads, so the two commands cannot name
305
+ * one box two ways.
306
+ */
307
+ async function drawnIds(docsDir, touched) {
308
+ if (touched.length === 0 || !existsSync(landscapePath(docsDir)))
309
+ return new Map();
310
+ const land = await loadArchitecture(docsDir);
311
+ if (land.errors.length > 0)
312
+ return new Map();
313
+ return drawnServiceElements(land.elements, new Set((await listServices(docsDir)).map((s) => s.id)));
314
+ }
269
315
  /* ------------------------------------------------------------------ */
270
316
  /* Naming */
271
317
  /* ------------------------------------------------------------------ */
@@ -279,5 +325,4 @@ function slugify(text) {
279
325
  .replace(/[^a-z0-9]+/g, "-")
280
326
  .replace(/^-+|-+$/g, "");
281
327
  }
282
- /** A LikeC4 identifier for a service name: `payment-split-service` -> `paymentSplitService`. */
283
328
  //# sourceMappingURL=new.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"new.js","sourceRoot":"","sources":["../../../src/commands/new/new.ts"],"names":[],"mappings":"AACA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WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC;AAED,gGAAgG","sourcesContent":["import type { Command } from \"commander\";\nimport { type PlannedWrite } from \"../../core/staging/writes.js\";\nimport { commitScaffold } from \"./commit.js\";\nimport { join } from \"node:path\";\nimport { loadConfig } from \"../../core/envelope/config.js\";\nimport { type FeatureId, parseFeatureId } from \"../../core/kernel/ids/feature.js\";\nimport { parseServiceIds } from \"../../core/kernel/ids/service.js\";\nimport { emitJson, fail, repoPath, reportNoConfig } from \"../../core/envelope/json.js\";\nimport { UnsafePathError, resolveInside } from \"../../core/kernel/path-safety.js\";\nimport { featureIdFromDirName, nearestIds } from \"../../core/repo/entries.js\";\nimport { featuresDir } from \"../../core/repo/paths.js\";\nimport { DocsRepoUnavailableError } from \"../../core/repo/state.js\";\nimport { listServices } from \"../../core/repo/repo.js\";\nimport { docsRepoReady, reportDocsRepoError } from \"../policy/gate.js\";\nimport { sayRecovered } from \"../policy/format.js\";\nimport type { DocsDir } from \"../../core/kernel/ids/dirs.js\";\nimport { capabilityIdProblem } from \"../../core/kernel/ids/capability.js\";\nimport { capabilityNotes } from \"../../core/capabilities/authoring/notes.js\";\nimport {\n archSpecTemplate,\n capabilityDeltaTemplate,\n deltaTemplate,\n intentTemplate,\n openapiTemplate,\n specTemplate,\n} from \"./templates.js\";\n\ninterface NewOptions {\n title?: string;\n touches: string[];\n newService: string[];\n capability: string[];\n json?: boolean;\n}\n\nexport function registerNew(program: Command): void {\n program\n .command(\"new\")\n .argument(\"<featureId>\", \"feature id, e.g. FEAT-101\")\n .description(\"Scaffold a feature: intent, C4 delta, a requirement delta per service, a capability delta per promise\")\n .option(\"--title <text>\", \"human title; also becomes the directory slug\")\n // `--touches`, not `--service`: everywhere else `--service` selects the ONE\n // operating target (defaulting to config.service), while this is a repeatable\n // list of services the feature touches — a different arity and a different\n // meaning deserve a different name.\n .option(\"--touches <id>\", \"a service this feature touches (repeatable)\", collect, [])\n .option(\"--new-service <id>\", \"a service this feature introduces (repeatable)\", collect, [])\n // The INVERSION of the two flags above, and it composes with them rather\n // than excluding them. `--touches` asks which services change before the\n // business change has been written; `--capability` opens the document that\n // changes and lets the service work be derived from it. A feature that\n // does both — the analyst writes the promise, and one team already knows it\n // owns part of the mechanism — is an ordinary shape, and refusing the\n // combination would fight this axis's own archive gate: `capability.uncovered`\n // refuses a promise nothing in the same feature keeps, so the fix it names\n // is precisely a `--touches` service's `Realizes:` line living beside the\n // capability delta.\n //\n // Repeatable, like both flags above: a business change that moves two\n // promises is as real as a feature touching two services, and the flag that\n // is not repeatable is the one that sends an author to mkdir by hand.\n .option(\"--capability <id>\", \"a business capability this feature changes (repeatable)\", collect, [])\n .option(\"--json\", \"emit the machine contract instead of the human view\")\n .action(async (featureId: string, opts: NewOptions) => {\n const json = opts.json === true;\n\n // The grammar's verdict arrives as the brand: `featureDirName` demands\n // a FeatureId, so an argv string cannot reach the directory derivation\n // without passing through this parse — the producer the brand was\n // missing while `isFeatureId` narrowed to plain string.\n const parsedId = parseFeatureId(featureId, \"feature id\");\n if (!parsedId.ok) {\n return fail(json, \"invalid-option\", parsedId.problem);\n }\n const dirName = featureDirName(parsedId.id, opts.title);\n // The round-trip is checked beside the grammar, not inside it: the\n // grammar is a fact about the id, while `featureIdFromDirName` depends on\n // the TITLE this command is about to slug into the directory name. Only\n // `new` creates that directory, so only `new` owes that second half.\n if (featureIdFromDirName(dirName) !== featureId) {\n return fail(\n json,\n \"invalid-option\",\n `'${featureId}' does not survive the directory round-trip with this title.`,\n );\n }\n\n // Service ids are validated BEFORE the config is even loaded, and long\n // before anything is written: every one of them is interpolated into\n // `specs/<id>/` under the new feature directory, so `--touches ../../x`\n // was a writer pointed outside the docs repo. One grammar (core/kernel/ids/service.ts),\n // the same one adopt/init/vouch refuse on, so a service that is legal to\n // create is legal to name here and nowhere the two disagree.\n // The LIST, not each item: a loop narrows the element and leaves the\n // array unbranded, so what reached the writer below was `string[]` no\n // matter how thoroughly each id had been checked. --touches first, so the\n // id reported first is the one it was before.\n const touches = parseServiceIds(opts.touches, \"--touches\");\n if (!touches.ok) return fail(json, \"invalid-option\", touches.problem);\n const newServices = parseServiceIds(opts.newService, \"--new-service\");\n if (!newServices.ok) return fail(json, \"invalid-option\", newServices.problem);\n\n // Same reasoning as the two lists above, one tree over. A capability id\n // becomes `features/<dirName>/capabilities/<id>/` — a chain of\n // directories, one per `/`-separated segment — so `--capability\n // ../../evil` resolves to `features/evil/spec.md`, a directory\n // `listFeatures` then enumerates as a feature, and one `..` further\n // reaches the docs-repo root. `resolveInside` below cannot refuse either:\n // both are still inside the repo. Checked here for that reason, and\n // against the same directory-name grammar a service id passes\n // (core/kernel/ids/capability.ts).\n const capabilities = opts.capability;\n for (const id of capabilities) {\n const problem = capabilityIdProblem(id);\n if (problem !== null) return fail(json, \"invalid-option\", problem);\n }\n\n const loaded = await loadConfig();\n if (loaded.kind !== \"loaded\") {\n reportNoConfig(json, loaded);\n return;\n }\n const config = loaded.config;\n const { docsDir } = config;\n // Before a single file is scaffolded: a docsDir that is not a docs repo is\n // refused, never written into. `features/<id>/**` lands happily in any\n // directory, so without this gate `new` reported `ok: true` over a\n // scaffold that no enumeration downstream will ever see — and a docsDir\n // that is simply absent escaped as `internal` (the enumeration below\n // throws) carrying the very sentence `list` and `show` report as\n // `docs-missing`. See docs-repo-gate.ts's docsRepoReady. `services`, not\n // `docs`: every id named by --touches/--new-service is a claim about\n // `services/<id>/`, and the near-miss note below is computed against that\n // directory, so a run without it is guessing.\n if (!docsRepoReady(json, docsDir, \"services\")) return;\n\n // No unlocked existence fast-path, deliberately: staging creates the\n // feature directory at plan time, so a HALF-scaffold from a killed run\n // resolves like a finished feature — and an unlocked refusal here made\n // \\`loam new <id>\\` answer already-exists over its own wreckage without\n // ever reaching the recovery that would complete it, while doctor's fix\n // printed exactly that re-run. Existence is asked once, under the lock,\n // after recovery has run.\n\n // A service named both ways is new — that is the more specific claim.\n const created = new Set(newServices.ids);\n const touched = touches.ids.filter((s) => !created.has(s));\n const dir = join(featuresDir(docsDir), dirName);\n\n const files: Record<string, string> = {\n \"intent.md\": intentTemplate(featureId, opts.title),\n \"delta.likec4\": deltaTemplate(featureId, touched, [...created]),\n };\n for (const svc of [...touched, ...created]) {\n files[join(\"specs\", svc, \"spec.md\")] = specTemplate(featureId, svc);\n }\n // The business axis, and the ONE file `--capability` adds. No service\n // spec rides with it, and that is the inversion rather than an omission:\n // the whole point of opening the document that changes first is that the\n // services realizing it are not known until the promise is written.\n // `--touches` is still how a service the author already knows about gets\n // its delta, which is why the two compose.\n //\n // Spelled relative, mirroring `featureCapabilityDeltasDir` +\n // `capabilityDocPathsAt` in core/repo/authored/paths.ts — the path builders take a\n // FeatureDir, whose provenance is an enumeration that read the directory,\n // and this directory is about to be created rather than read. One\n // directory per segment, exactly as the living tree spells nesting.\n for (const cap of capabilities) {\n files[join(\"capabilities\", ...cap.split(\"/\"), \"spec.md\")] = capabilityDeltaTemplate(featureId, cap);\n }\n for (const svc of created) {\n files[join(\"specs\", svc, \"openapi.yaml\")] = openapiTemplate(svc);\n // The architecture axis is scaffolded only for a service this feature\n // INTRODUCES, because that is the case where `c4.uncovered` will fire\n // the moment the delta is written: a brand-new tagged element nothing\n // covers. Handing an author a blank page for the outbox/retries/alerts\n // requirement is how that axis stays empty across a whole fleet.\n files[join(\"specs\", svc, \"arch.spec.md\")] = archSpecTemplate(featureId, svc);\n }\n\n // The COMPLETE plan in memory before a byte lands on disk: every path\n // resolved (belt and braces over the id grammar — resolveInside proves\n // containment at the moment of the write, symlink cases included), and\n // every write an exclusive create, because the feature must not exist.\n // The sequential writeFile loop this replaces could die mid-scaffold and\n // leave a partial feature the next run refused as already-exists.\n const writes: PlannedWrite[] = [];\n for (const [rel, content] of Object.entries(files)) {\n let path: string;\n try {\n path = resolveInside(docsDir, join(\"features\", dirName, rel), \"feature file\");\n } catch (err) {\n if (!(err instanceof UnsafePathError)) throw err;\n return fail(json, \"invalid-option\", err.message);\n }\n writes.push({ path, content, exclusive: true });\n }\n\n const committed = await commitScaffold(docsDir, featureId, writes);\n if (!committed.ok) {\n if (\"repoGone\" in committed) {\n reportDocsRepoError(json, committed.repoGone);\n return;\n }\n if (committed.code === \"already-exists\") {\n // After a recovery the refusal must SAY the repair happened: doctor\n // told the operator to re-run this exact command, and \"already\n // exists\" alone reads as the fix having failed.\n return fail(\n json,\n \"already-exists\",\n `Feature '${featureId}' already exists at ${repoPath(docsDir, committed.existing?.dir ?? dir)}.` +\n (committed.recovered === null ? \"\" : ` (${sayRecovered(committed.recovered)} The scaffold is complete.)`),\n );\n }\n return fail(json, committed.code, committed.message);\n }\n const recovered = committed.recovered;\n const written = writes.map((w) => repoPath(docsDir, w.path));\n\n // Both note families in ONE list, and the services first so an existing\n // `--touches` consumer reads the same first element it always did. They\n // are the same kind of statement — \"the thing you named is not there yet,\n // and here is what that means\" — so splitting them into two payload keys\n // would ask a consumer to learn a second shape for one idea.\n const notes = [\n ...(await unknownServiceNotes(docsDir, touched)),\n ...(await capabilityNotes(docsDir, { dirName, ids: capabilities })),\n ];\n\n if (json) {\n emitJson({\n command: \"new\",\n feature: featureId,\n path: repoPath(docsDir, dir),\n created: written,\n ...(recovered === null ? {} : { recovered }),\n // Not an error and not a finding: `--touches` on a service that does\n // not exist yet is legal (adopt it later, or say `--new-service`),\n // and `--capability` on a promise nobody has named is the ordinary\n // way a new business area starts. Both are reported because the\n // silent alternative is a delta that will never merge into anything,\n // or a near-miss spelling filed as a second capability.\n notes,\n });\n return;\n }\n console.log(`${featureId} scaffolded at ${repoPath(docsDir, dir)}`);\n for (const w of written) console.log(` + ${w}`);\n for (const note of notes) console.log(`\\n note: ${note}`);\n console.log(`\\nNext: fill in the delta, then \\`loam validate --feature ${featureId}\\`.`);\n console.log(\n \"If this feature changes no architecture, delete delta.likec4 — a requirements-only\\n\" +\n \"feature is complete without it, and an empty `model {}` validates clean too.\",\n );\n });\n}\n\nfunction collect(value: string, previous: string[]): string[] {\n return [...previous, value];\n}\n\n/* ------------------------------------------------------------------ */\n/* Hints */\n/* ------------------------------------------------------------------ */\n\n/**\n * `--touches <id>` naming neither a living `services/<id>/` nor a `--new-service`\n * is almost always a typo, and it is silent by construction: the scaffold writes\n * `specs/<id>/spec.md` happily, `loam validate` grades a delta against a living\n * spec that is not there, and the mistake surfaces at archive time as a service\n * appearing from nowhere. A note, not a refusal — naming a service that will be\n * adopted next week is legitimate — but the near-miss is spelled out, because\n * `order-api` vs `orders-api` is exactly the pair a person cannot see.\n */\nasync function unknownServiceNotes(docsDir: DocsDir, touched: string[]): Promise<string[]> {\n if (touched.length === 0) return [];\n let known: string[];\n try {\n known = (await listServices(docsDir)).map((s) => s.id);\n } catch (err) {\n // No docs repo to compare against is a different diagnosis entirely, and\n // `loam doctor` owns it. Saying nothing here beats inventing a typo hint\n // out of an enumeration that never ran.\n if (!(err instanceof DocsRepoUnavailableError)) throw err;\n return [];\n }\n const notes: string[] = [];\n for (const id of touched) {\n if (known.includes(id)) continue;\n const near = nearestIds(id, known);\n notes.push(\n `--touches '${id}' matches no services/${id}/ in the docs repo` +\n (near.length === 0 ? \"\" : ` — did you mean ${near.map((n) => `'${n}'`).join(\" or \")}?`) +\n ` If ${id} is introduced by this feature, pass --new-service ${id} instead.`,\n );\n }\n return notes;\n}\n\n/* ------------------------------------------------------------------ */\n/* Naming */\n/* ------------------------------------------------------------------ */\n\nfunction featureDirName(featureId: FeatureId, title: string | undefined): string {\n const slug = slugify(title ?? \"\");\n return slug ? `${featureId}-${slug}` : featureId;\n}\n\nfunction slugify(text: string): string {\n return text\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n}\n\n/** A LikeC4 identifier for a service name: `payment-split-service` -> `paymentSplitService`. */\n"]}
1
+ {"version":3,"file":"new.js","sourceRoot":"","sources":["../../../src/commands/new/new.ts"],"names":[],"mappings":"AACA,OA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AAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAAE,OAAO,IAAI,GAAG,EAAE,CAAC;IAClF,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,GAAG,EAAE,CAAC;IAC7C,OAAO,oBAAoB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,GAAG,CAAC,CAAC,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACtG,CAAC;AAED,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE,SAAS,cAAc,CAAC,SAAoB,EAAE,KAAyB;IACrE,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,IAAI;SACR,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import type { Command } from \"commander\";\nimport { existsSync } from \"node:fs\";\nimport { type PlannedWrite } from \"../../core/staging/writes.js\";\nimport { commitScaffold } from \"./commit.js\";\nimport { join } from \"node:path\";\nimport { type FeatureId, parseFeatureId } from \"../../core/kernel/ids/feature.js\";\nimport { parseServiceIds } from \"../../core/kernel/ids/service.js\";\nimport { configOrRefuse, emitJson, fail, repoPath } from \"../../core/envelope/json.js\";\nimport { UnsafePathError, resolveInside } from \"../../core/kernel/path-safety.js\";\nimport { featureIdFromDirName, nearestIds } from \"../../core/repo/entries.js\";\nimport { featuresDir, landscapePath } from \"../../core/repo/paths.js\";\nimport { loadArchitecture } from \"../../core/c4/project/architecture.js\";\nimport { drawnServiceElements } from \"../../core/c4/resolve/service.js\";\nimport { DocsRepoUnavailableError } from \"../../core/repo/state.js\";\nimport { listServices } from \"../../core/repo/repo.js\";\nimport { docsRepoReady, reportDocsRepoError } from \"../policy/gate.js\";\nimport { sayRecovered } from \"../policy/format.js\";\nimport type { DocsDir } from \"../../core/kernel/ids/dirs.js\";\nimport { capabilityIdProblem } from \"../../core/kernel/ids/capability.js\";\nimport { capabilityNotes } from \"../../core/capabilities/authoring/notes.js\";\nimport { modifiedFiles, planModifies } from \"./modifies.js\";\nimport { archSpecTemplate, deltaTemplate, intentTemplate, openapiTemplate, specTemplate } from \"./templates.js\";\nimport { capabilityDeltaTemplate } from \"./capability-template.js\";\n\ninterface NewOptions {\n title?: string;\n touches: string[];\n newService: string[];\n capability: string[];\n modifies: string[];\n json?: boolean;\n}\n\nexport function registerNew(program: Command): void {\n program\n .command(\"new\")\n .argument(\"<featureId>\", \"feature id, e.g. FEAT-101\")\n .description(\"Scaffold a feature: intent, C4 delta, a requirement delta per service, a capability delta per promise\")\n .option(\"--title <text>\", \"human title; also becomes the directory slug\")\n // `--touches`, not `--service`: everywhere else `--service` selects the ONE\n // operating target (defaulting to config.service), while this is a repeatable\n // list of services the feature touches — a different arity and a different\n // meaning deserve a different name.\n .option(\"--touches <id>\", \"a service this feature touches (repeatable)\", collect, [])\n .option(\"--new-service <id>\", \"a service this feature introduces (repeatable)\", collect, [])\n // The INVERSION of the two flags above, and it composes with them rather\n // than excluding them. `--touches` asks which services change before the\n // business change has been written; `--capability` opens the document that\n // changes and lets the service work be derived from it. A feature that\n // does both — the analyst writes the promise, and one team already knows it\n // owns part of the mechanism — is an ordinary shape, and refusing the\n // combination would fight this axis's own archive gate: `capability.uncovered`\n // refuses a promise nothing in the same feature keeps, so the fix it names\n // is precisely a `--touches` service's `Realizes:` line living beside the\n // capability delta.\n //\n // Repeatable, like both flags above: a business change that moves two\n // promises is as real as a feature touching two services, and the flag that\n // is not repeatable is the one that sends an author to mkdir by hand.\n .option(\"--capability <id>\", \"a business capability this feature changes (repeatable)\", collect, [])\n // The small-change lane (./modifies.ts): the living requirement copied\n // into an uncommented MODIFIED block, pinned at scaffold time.\n .option(\n \"--modifies <Req-ID>\",\n \"a living requirement of a --touches service this feature rewrites (repeatable): scaffolds its MODIFIED block, already pinned\",\n collect,\n [],\n )\n .option(\"--json\", \"emit the machine contract instead of the human view\")\n .action(async (featureId: string, opts: NewOptions) => {\n const json = opts.json === true;\n\n // The grammar's verdict arrives as the brand: `featureDirName` demands\n // a FeatureId, so an argv string cannot reach the directory derivation\n // without passing through this parse — the producer the brand was\n // missing while `isFeatureId` narrowed to plain string.\n const parsedId = parseFeatureId(featureId, \"feature id\");\n if (!parsedId.ok) {\n return fail(json, \"invalid-option\", parsedId.problem);\n }\n const dirName = featureDirName(parsedId.id, opts.title);\n // The round-trip is checked beside the grammar, not inside it: the\n // grammar is a fact about the id, while `featureIdFromDirName` depends on\n // the TITLE this command is about to slug into the directory name. Only\n // `new` creates that directory, so only `new` owes that second half.\n if (featureIdFromDirName(dirName) !== featureId) {\n return fail(\n json,\n \"invalid-option\",\n `'${featureId}' does not survive the directory round-trip with this title.`,\n );\n }\n\n // Service ids are validated BEFORE the config is even loaded, and long\n // before anything is written: every one of them is interpolated into\n // `specs/<id>/` under the new feature directory, so `--touches ../../x`\n // was a writer pointed outside the docs repo. One grammar (core/kernel/ids/service.ts),\n // the same one adopt/init/vouch refuse on, so a service that is legal to\n // create is legal to name here and nowhere the two disagree.\n // The LIST, not each item: a loop narrows the element and leaves the\n // array unbranded, so what reached the writer below was `string[]` no\n // matter how thoroughly each id had been checked. --touches first, so the\n // id reported first is the one it was before.\n const touches = parseServiceIds(opts.touches, \"--touches\");\n if (!touches.ok) return fail(json, \"invalid-option\", touches.problem);\n const newServices = parseServiceIds(opts.newService, \"--new-service\");\n if (!newServices.ok) return fail(json, \"invalid-option\", newServices.problem);\n\n // Same reasoning as the two lists above, one tree over. A capability id\n // becomes `features/<dirName>/capabilities/<id>/` — a chain of\n // directories, one per `/`-separated segment — so `--capability\n // ../../evil` resolves to `features/evil/spec.md`, a directory\n // `listFeatures` then enumerates as a feature, and one `..` further\n // reaches the docs-repo root. `resolveInside` below cannot refuse either:\n // both are still inside the repo. Checked here for that reason, and\n // against the same directory-name grammar a service id passes\n // (core/kernel/ids/capability.ts).\n const capabilities = opts.capability;\n for (const id of capabilities) {\n const problem = capabilityIdProblem(id);\n if (problem !== null) return fail(json, \"invalid-option\", problem);\n }\n\n const config = await configOrRefuse(json);\n if (config === null) return;\n const { docsDir } = config;\n // Before a single file is scaffolded: a docsDir that is not a docs repo is\n // refused, never written into. `features/<id>/**` lands happily in any\n // directory, so without this gate `new` reported `ok: true` over a\n // scaffold that no enumeration downstream will ever see — and a docsDir\n // that is simply absent escaped as `internal` (the enumeration below\n // throws) carrying the very sentence `list` and `show` report as\n // `docs-missing`. See docs-repo-gate.ts's docsRepoReady. `services`, not\n // `docs`: every id named by --touches/--new-service is a claim about\n // `services/<id>/`, and the near-miss note below is computed against that\n // directory, so a run without it is guessing.\n if (!docsRepoReady(json, docsDir, \"services\")) return;\n\n // No unlocked existence fast-path, deliberately: staging creates the\n // feature directory at plan time, so a HALF-scaffold from a killed run\n // resolves like a finished feature — and an unlocked refusal here made\n // \\`loam new <id>\\` answer already-exists over its own wreckage without\n // ever reaching the recovery that would complete it, while doctor's fix\n // printed exactly that re-run. Existence is asked once, under the lock,\n // after recovery has run.\n\n // A service named both ways is new — that is the more specific claim.\n const created = new Set(newServices.ids);\n const touched = touches.ids.filter((s) => !created.has(s));\n const dir = join(featuresDir(docsDir), dirName);\n\n // Resolved before anything is written: an id naming no living\n // requirement refuses the whole scaffold, as a bad --touches id does.\n const modifies = await planModifies(docsDir, touched, opts.modifies);\n if (!modifies.ok) return fail(json, modifies.code, modifies.message);\n // `--modifies` and nothing else — every touched service has a requirement\n // rewritten, none is introduced, no promise opened — is a feature that\n // changes no architecture, and the scaffold's own advice for that case is\n // \"delete delta.likec4\". So it is not written; validate and archive read\n // a requirements-only feature as complete without it.\n const requirementsOnly =\n modifies.targets.length > 0 && created.size === 0 && capabilities.length === 0 &&\n touched.every((svc) => modifies.targets.some((t) => t.service === svc));\n\n const files: Record<string, string> = { \"intent.md\": intentTemplate(featureId, opts.title) };\n if (!requirementsOnly) {\n files[\"delta.likec4\"] = deltaTemplate(featureId, touched, [...created], await drawnIds(docsDir, touched));\n }\n for (const svc of [...touched, ...created]) {\n files[join(\"specs\", svc, \"spec.md\")] = specTemplate(featureId, svc);\n }\n Object.assign(files, modifiedFiles(featureId, modifies.targets, files));\n // The business axis, and the ONE file `--capability` adds. No service\n // spec rides with it, and that is the inversion rather than an omission:\n // the whole point of opening the document that changes first is that the\n // services realizing it are not known until the promise is written.\n // `--touches` is still how a service the author already knows about gets\n // its delta, which is why the two compose.\n //\n // Spelled relative, mirroring `featureCapabilityDeltasDir` +\n // `capabilityDocPathsAt` in core/repo/authored/paths.ts — the path builders take a\n // FeatureDir, whose provenance is an enumeration that read the directory,\n // and this directory is about to be created rather than read. One\n // directory per segment, exactly as the living tree spells nesting.\n for (const cap of capabilities) {\n files[join(\"capabilities\", ...cap.split(\"/\"), \"spec.md\")] = capabilityDeltaTemplate(featureId, cap);\n }\n for (const svc of created) {\n files[join(\"specs\", svc, \"openapi.yaml\")] = openapiTemplate(svc);\n // The architecture axis is scaffolded only for a service this feature\n // INTRODUCES, because that is the case where `c4.uncovered` will fire\n // the moment the delta is written: a brand-new tagged element nothing\n // covers. Handing an author a blank page for the outbox/retries/alerts\n // requirement is how that axis stays empty across a whole fleet.\n files[join(\"specs\", svc, \"arch.spec.md\")] = archSpecTemplate(featureId, svc);\n }\n\n // The COMPLETE plan in memory before a byte lands on disk: every path\n // resolved (belt and braces over the id grammar — resolveInside proves\n // containment at the moment of the write, symlink cases included), and\n // every write an exclusive create, because the feature must not exist.\n // The sequential writeFile loop this replaces could die mid-scaffold and\n // leave a partial feature the next run refused as already-exists.\n const writes: PlannedWrite[] = [];\n for (const [rel, content] of Object.entries(files)) {\n let path: string;\n try {\n path = resolveInside(docsDir, join(\"features\", dirName, rel), \"feature file\");\n } catch (err) {\n if (!(err instanceof UnsafePathError)) throw err;\n return fail(json, \"invalid-option\", err.message);\n }\n writes.push({ path, content, exclusive: true });\n }\n\n const committed = await commitScaffold(docsDir, featureId, writes);\n if (!committed.ok) {\n if (\"repoGone\" in committed) {\n reportDocsRepoError(json, committed.repoGone);\n return;\n }\n if (committed.code === \"already-exists\") {\n // After a recovery the refusal must SAY the repair happened: doctor\n // told the operator to re-run this exact command, and \"already\n // exists\" alone reads as the fix having failed.\n return fail(\n json,\n \"already-exists\",\n `Feature '${featureId}' already exists at ${repoPath(docsDir, committed.existing?.dir ?? dir)}.` +\n (committed.recovered === null ? \"\" : ` (${sayRecovered(committed.recovered)} The scaffold is complete.)`),\n );\n }\n return fail(json, committed.code, committed.message);\n }\n const recovered = committed.recovered;\n const written = writes.map((w) => repoPath(docsDir, w.path));\n\n // Both note families in ONE list, and the services first so an existing\n // `--touches` consumer reads the same first element it always did. They\n // are the same kind of statement — \"the thing you named is not there yet,\n // and here is what that means\" — so splitting them into two payload keys\n // would ask a consumer to learn a second shape for one idea.\n const notes = [\n ...(await unknownServiceNotes(docsDir, touched)),\n ...(await capabilityNotes(docsDir, { dirName, ids: capabilities })),\n ];\n\n if (json) {\n emitJson({\n command: \"new\",\n feature: featureId,\n path: repoPath(docsDir, dir),\n created: written,\n ...(recovered === null ? {} : { recovered }),\n // Not an error and not a finding: `--touches` on a service that does\n // not exist yet is legal (adopt it later, or say `--new-service`),\n // and `--capability` on a promise nobody has named is the ordinary\n // way a new business area starts. Both are reported because the\n // silent alternative is a delta that will never merge into anything,\n // or a near-miss spelling filed as a second capability.\n notes,\n });\n return;\n }\n console.log(`${featureId} scaffolded at ${repoPath(docsDir, dir)}`);\n for (const w of written) console.log(` + ${w}`);\n for (const t of modifies.targets) console.log(` ~ MODIFIED ${t.id}: copied from ${t.living}, Based-On already pinned`);\n for (const note of notes) console.log(`\\n note: ${note}`);\n if (requirementsOnly) {\n console.log(\n `\\nNext: edit each MODIFIED requirement in place, write intent.md's Why, then\\n` +\n `\\`loam validate --feature ${featureId}\\` and \\`loam archive ${featureId}\\`. No delta.likec4 was written:\\n` +\n \"rewriting requirements changes no architecture. If this change also moves an element or\\n\" +\n \"an edge, add one — `loam instructions loam-feature` shows its shape.\",\n );\n return;\n }\n console.log(`\\nNext: fill in the delta, then \\`loam validate --feature ${featureId}\\`.`);\n console.log(\n \"If this feature changes no architecture, delete delta.likec4 — a requirements-only\\n\" +\n \"feature is complete without it, and an empty `model {}` validates clean too.\",\n );\n });\n}\n\nfunction collect(value: string, previous: string[]): string[] {\n return [...previous, value];\n}\n\n/* ------------------------------------------------------------------ */\n/* Hints */\n/* ------------------------------------------------------------------ */\n\n/**\n * `--touches <id>` naming neither a living `services/<id>/` nor a `--new-service`\n * is almost always a typo, and it is silent by construction: the scaffold writes\n * `specs/<id>/spec.md` happily, `loam validate` grades a delta against a living\n * spec that is not there, and the mistake surfaces at archive time as a service\n * appearing from nowhere. A note, not a refusal — naming a service that will be\n * adopted next week is legitimate — but the near-miss is spelled out, because\n * `order-api` vs `orders-api` is exactly the pair a person cannot see.\n */\nasync function unknownServiceNotes(docsDir: DocsDir, touched: string[]): Promise<string[]> {\n if (touched.length === 0) return [];\n let known: string[];\n try {\n known = (await listServices(docsDir)).map((s) => s.id);\n } catch (err) {\n // No docs repo to compare against is a different diagnosis entirely, and\n // `loam doctor` owns it. Saying nothing here beats inventing a typo hint\n // out of an enumeration that never ran.\n if (!(err instanceof DocsRepoUnavailableError)) throw err;\n return [];\n }\n const notes: string[] = [];\n for (const id of touched) {\n if (known.includes(id)) continue;\n const near = nearestIds(id, known);\n notes.push(\n `--touches '${id}' matches no services/${id}/ in the docs repo` +\n (near.length === 0 ? \"\" : ` — did you mean ${near.map((n) => `'${n}'`).join(\" or \")}?`) +\n ` If ${id} is introduced by this feature, pass --new-service ${id} instead.`,\n );\n }\n return notes;\n}\n\n/**\n * The element ids the fleet map already draws the touched services as, so the\n * delta's context lines reuse them instead of guessing — the delta's own\n * comment tells the author to reuse the map's identifiers, and it used to\n * hand them a camel-cased guess that never matched a seeded map's `svc_<id>`.\n *\n * Best effort by design: `new` is a scaffolder, not a validator. No map, or\n * one that does not parse, leaves every id to the seed convention, and\n * `loam validate` reports the map on its own. The project loader and the\n * resolver are the ones `loam adopt` reads, so the two commands cannot name\n * one box two ways.\n */\nasync function drawnIds(docsDir: DocsDir, touched: string[]): Promise<ReadonlyMap<string, string>> {\n if (touched.length === 0 || !existsSync(landscapePath(docsDir))) return new Map();\n const land = await loadArchitecture(docsDir);\n if (land.errors.length > 0) return new Map();\n return drawnServiceElements(land.elements, new Set((await listServices(docsDir)).map((s) => s.id)));\n}\n\n/* ------------------------------------------------------------------ */\n/* Naming */\n/* ------------------------------------------------------------------ */\n\nfunction featureDirName(featureId: FeatureId, title: string | undefined): string {\n const slug = slugify(title ?? \"\");\n return slug ? `${featureId}-${slug}` : featureId;\n}\n\nfunction slugify(text: string): string {\n return text\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\");\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  /**
2
- * The six files `loam new` scaffolds, and what each one says.
2
+ * Five of the six files `loam new` scaffolds, and what each one says. The
3
+ * sixth, the `--capability` delta, is in `./capability-template.ts`.
3
4
  *
4
5
  * They are here rather than inline because every one of them is a document a
5
6
  * person edits next, and the wording IS the instruction: the delta's comments
@@ -9,20 +10,32 @@
9
10
  * file stops parsing.
10
11
  */
11
12
  import { stringify as stringifyYaml } from "yaml";
12
- import { REQUIREMENT_ID_RE } from "../../core/document/spec.js";
13
- import { ARCH_REQUIREMENT_SENTINEL, ARCH_SHALL_SENTINEL, CAPABILITY_REQUIREMENT_SENTINEL, CAPABILITY_SHALL_SENTINEL, REQUIREMENT_SENTINEL, SCENARIO_SENTINEL, SERVICE_DESCRIPTION_SENTINEL, GIVEN_SENTINEL, SHALL_SENTINEL, THEN_SENTINEL, WHEN_SENTINEL, } from "../../core/coherence/authoring/sentinels.js";
14
- function identifier(name, taken) {
15
- const parts = name.split(/[^A-Za-z0-9]+/).filter((p) => p.length > 0);
16
- const head = (parts[0] ?? "svc").replace(/^\d+/, "") || "svc";
17
- const base = head[0].toLowerCase() +
18
- head.slice(1) +
19
- parts.slice(1).map((p) => p[0].toUpperCase() + p.slice(1)).join("");
13
+ import { serviceElementId } from "../../core/c4/seed/template.js";
14
+ import { ARCH_REQUIREMENT_SENTINEL, ARCH_SHALL_SENTINEL, REQUIREMENT_SENTINEL, SCENARIO_SENTINEL, SERVICE_DESCRIPTION_SENTINEL, GIVEN_SENTINEL, SHALL_SENTINEL, THEN_SENTINEL, WHEN_SENTINEL, } from "../../core/coherence/authoring/sentinels.js";
15
+ /**
16
+ * The LikeC4 identifier the delta declares a service under: the id the fleet
17
+ * map already draws it as (`drawn`), since a context id the map lacks lines up
18
+ * with nothing at archive, else `serviceElementId` — seed's `svc_<id>`, where
19
+ * this used to camel-case the name into a third spelling beside the seed's and
20
+ * the map's. A collision inside one delta takes the seed's `_<n>` suffix.
21
+ */
22
+ function identifier(name, taken, drawn) {
23
+ if (drawn !== undefined)
24
+ return drawn;
25
+ const base = serviceElementId(name);
20
26
  let id = base;
21
27
  for (let n = 2; taken.has(id); n += 1)
22
- id = `${base}${n}`;
28
+ id = `${base}_${n}`;
23
29
  taken.add(id);
24
30
  return id;
25
31
  }
32
+ /** One context line. A nested id (`a.b`) is no top-level declaration, so it names its parent instead. */
33
+ function contextLine(id, name) {
34
+ const dot = id.lastIndexOf(".");
35
+ if (dot < 0)
36
+ return ` // ${id} = softwareSystem '${name}'`;
37
+ return ` // ${id.slice(dot + 1)} = softwareSystem '${name}' // inside ${id.slice(0, dot)} { }, as the map draws it; edges name it ${id}`;
38
+ }
26
39
  /** `FEAT-101` -> `feat_101`: LikeC4 view names take no dashes. */
27
40
  function viewName(featureId) {
28
41
  return featureId.toLowerCase().replace(/[^a-z0-9]+/g, "_");
@@ -44,6 +57,11 @@ export function intentTemplate(featureId, title) {
44
57
  // explicit null, which is a claim ("this feature has no owner") rather than
45
58
  // the truth ("nobody has said yet") — and every reader then has to tell an
46
59
  // absent key from a null one. The prompt survives as a comment.
60
+ //
61
+ // `## Open questions` is where loam-feature's analyze step writes, so it is
62
+ // scaffolded as a heading over a comment and nothing else. `intent.empty`
63
+ // (coherence/authoring/scaffold.ts) reads past the whole section, so neither
64
+ // the untouched comment nor a page of questions counts as the Why.
47
65
  const frontmatter = stringifyYaml({ feature: featureId, ...(title === undefined ? {} : { title }), status: "proposed" }, { lineWidth: 0 }).trimEnd();
48
66
  return `---
49
67
  ${frontmatter}
@@ -60,11 +78,18 @@ ${frontmatter}
60
78
  ## Scope
61
79
 
62
80
  <!-- Which services this touches — and, more usefully, which it deliberately does not. -->
81
+
82
+ ## Open questions
83
+
84
+ <!-- Optional, never graded. What the documents leave open: an ambiguous SHALL, a value or
85
+ window two services state differently, an edge with no stated timeout, retry or
86
+ compensation. A person answers each by editing this section. -->
63
87
  `;
64
88
  }
65
- export function deltaTemplate(featureId, touched, created) {
66
- const taken = new Set();
67
- const touchedIds = touched.map((s) => [identifier(s, taken), s]);
89
+ export function deltaTemplate(featureId, touched, created, drawn = new Map()) {
90
+ // The map's ids are claimed first: a new service's id never collides with a box quoted as context.
91
+ const taken = new Set(drawn.values());
92
+ const touchedIds = touched.map((s) => [identifier(s, taken, drawn.get(s)), s]);
68
93
  const createdIds = created.map((s) => [identifier(s, taken), s]);
69
94
  const lines = [];
70
95
  if (touchedIds.length > 0) {
@@ -75,11 +100,12 @@ export function deltaTemplate(featureId, touched, created) {
75
100
  // which teaches people that the validator is noise. Uncomment a line when an
76
101
  // edge below actually needs the identifier.
77
102
  lines.push(" // Services this feature touches, as context for the diagram. Uncomment the");
78
- lines.push(" // ones an edge below names, and reuse the identifiers from");
79
- lines.push(" // architecture/landscape.likec4 so the merge lines up. They stay UNTAGGED:");
103
+ lines.push(" // ones an edge below names. A service the fleet map already draws keeps the");
104
+ lines.push(" // identifier architecture/ gives it, so the merge lines up; one it does not");
105
+ lines.push(" // draw yet gets svc_<id>, the convention `loam seed` writes. They stay UNTAGGED:");
80
106
  lines.push(` // only #${featureId} is the change, and everything else here is context.`);
81
107
  for (const [id, name] of touchedIds)
82
- lines.push(` // ${id} = softwareSystem '${name}'`);
108
+ lines.push(contextLine(id, name));
83
109
  lines.push("");
84
110
  }
85
111
  if (createdIds.length > 0) {
@@ -162,10 +188,12 @@ export function specTemplate(featureId, service) {
162
188
  A \`Publishes:\` / \`Consumes:\` body line does the same for event messages:
163
189
  it names what the requirement puts on or takes off the bus, checked
164
190
  against the service's AsyncAPI contract. If ${featureId} changes that
165
- contract, hand-create specs/${service}/asyncapi.yaml — a complete
166
- AsyncAPI 3.0 document, messages declared under \`components.messages\`
167
- (loam scaffolds none: an event contract is genuinely optional) — and run
168
- \`loam rebase ${featureId}\` so every restated slot pins as a quote.
191
+ contract, hand-create specs/${service}/asyncapi.yaml — an AsyncAPI 3.0
192
+ document holding only the slots this feature adds, changes or removes,
193
+ messages under \`components.messages\` (loam scaffolds none: an event
194
+ contract is genuinely optional) — and run \`loam rebase ${featureId}\`
195
+ when it edits a slot the living contract already has, so that slot pins.
196
+ The same holds for an openapi.yaml beside this file: only what changes.
169
197
 
170
198
  Copy the block below out of this comment, unindent it, and replace the
171
199
  TODOs and every <angle-bracket> fill-in — \`loam archive\` refuses the
@@ -230,110 +258,6 @@ export function archSpecTemplate(featureId, service) {
230
258
  -->
231
259
  `;
232
260
  }
233
- /**
234
- * The BUSINESS axis, scaffolded by `--capability`: a delta against the living
235
- * `capabilities/<id>/spec.md`.
236
- *
237
- * Same idiom as the two spec templates above and for the same reason — the
238
- * example lives INSIDE an HTML comment, indented past the line-anchored
239
- * `## ADDED Requirements` / `### Requirement:` patterns core/document/parse.ts
240
- * matches on — so the scaffold declares nothing until a person copies the block
241
- * out. That is what lets a freshly scaffolded feature validate clean while
242
- * still being refused by `loam archive` the moment the block is copied out and
243
- * left unedited (`scaffold.placeholder`, which reads
244
- * `features/<FEAT>/capabilities/` as well as `features/<FEAT>/specs/`).
245
- *
246
- * WHAT THE COMMENT TEACHES IS THE ALTITUDE, because that is the mistake this
247
- * document invites. A capability requirement is a promise a customer could
248
- * check; the four service-scoped lines (`Operations:`, `Covers:`, `Publishes:`,
249
- * `Consumes:`) and the axis's own two (`Capability:`, `Realizes:`) are all
250
- * ERRORS here — `capability.requirement-service-scoped` and
251
- * `capability.requirement-inert-join` — and every one of them parses, so an
252
- * author who is not told writes one and finds out at archive. `Requirement-ID:`
253
- * is spelled as mandatory for the same reason: a capability document outlives
254
- * every service that realizes it, so identity by heading is refused
255
- * (`capability.requirement-unidentified`).
256
- *
257
- * No nested HTML comments, exactly as `specTemplate` states: an inner `-->`
258
- * would end the outer comment early and re-expose the example to the parser.
259
- */
260
- export function capabilityDeltaTemplate(featureId, capability) {
261
- return `# ${capability} — capability delta for ${featureId}
262
-
263
- <!-- The business axis. This is a DELTA against the living
264
- capabilities/${capability}/spec.md, not the document itself: sections are
265
- ADDED / MODIFIED / REMOVED, delete the ones you do not need, and a MODIFIED
266
- requirement carries its full new text rather than a diff. If the fleet has
267
- no capabilities/${capability}/spec.md yet, this feature's archive creates it.
268
-
269
- WHAT BELONGS HERE is a promise somebody outside the fleet could check —
270
- 'a refund reaches the customer's card within five days'. What does NOT is
271
- the mechanism: \`Operations:\`, \`Covers:\`, \`Publishes:\` and \`Consumes:\`
272
- all resolve against ONE service's own contract or model, so a requirement
273
- carrying one is a service requirement filed at the wrong altitude and
274
- \`loam validate\` says so. \`Capability:\` and \`Realizes:\` are refused here
275
- too — they are the joins written on the SERVICE requirement that keeps this
276
- promise, one directory over in specs/<svc>/spec.md, as
277
- \`Realizes: ${capability}#<Requirement-ID>\`.
278
-
279
- \`Requirement-ID:\` is mandatory on every requirement below. A capability
280
- document outlives the services that realize it, so its requirements are
281
- addressed by a stable id rather than by their heading — rewording a heading
282
- would otherwise be a removal and an addition, and every \`Realizes:\` line
283
- pointed at it would break in silence.
284
-
285
- A MODIFIED or REMOVED requirement also needs a \`Based-On:\` pin quoting the
286
- living text it rewrites, so two features touching one capability collide
287
- loudly instead of overwriting each other. Run \`loam rebase ${featureId}\`
288
- and the pins are written for you.
289
-
290
- Copy the block below out of this comment, unindent it, and replace the TODO
291
- and every <angle-bracket> fill-in — \`loam archive\` refuses the scaffold's
292
- own wording (\`scaffold.placeholder\`):
293
-
294
- ## ADDED Requirements
295
-
296
- ### Requirement: ${CAPABILITY_REQUIREMENT_SENTINEL}
297
- Requirement-ID: ${idHint(capability)}
298
-
299
- The fleet SHALL ${CAPABILITY_SHALL_SENTINEL}.
300
-
301
- #### Scenario: ${SCENARIO_SENTINEL}
302
- - **Given** ${GIVEN_SENTINEL}
303
- - **When** ${WHEN_SENTINEL}
304
- - **Then** ${THEN_SENTINEL}
305
- -->
306
- `;
307
- }
308
- /**
309
- * A plausible `Requirement-ID:` for a capability, offered as a shape rather than
310
- * a name: `payments/refunds` -> `PAYMENTS-REFUNDS-1`.
311
- *
312
- * Deliberately NOT the feature id. A service requirement's scaffolded id is
313
- * `<FEAT>.<svc>.requirement` because that requirement is created by, and lives
314
- * and dies with, one feature; a capability requirement outlives every feature
315
- * that touches it, so an id carrying the id of the feature that happened to
316
- * introduce it is exactly the identity-by-accident this axis refuses. The
317
- * suffix is `-1` and not a count of anything: it is a placeholder digit inside
318
- * a placeholder id, and the author is being asked to name the promise.
319
- *
320
- * CHECKED AGAINST THE REAL GRAMMAR, never assumed to satisfy it. A capability id
321
- * may begin with a digit (`3ds`, `2fa`, `1099-filing` — `dirNameHazard` allows an
322
- * alphanumeric head) while `REQUIREMENT_ID_RE` demands a LETTER, so the obvious
323
- * slug hands the author `3DS-1` and `loam validate` then refuses it with
324
- * `delta.requirement-id-invalid` — the author refused for using the shape the
325
- * scaffold offered. Length is the same class of failure at 128 characters. The
326
- * fallback prefixes rather than truncates, because a truncated id is a plausible
327
- * name that means something else.
328
- */
329
- function idHint(capability) {
330
- const slug = capability.toUpperCase().replace(/[^A-Z0-9]+/g, "-").replace(/^-+|-+$/g, "");
331
- const candidate = `${slug}-1`;
332
- if (REQUIREMENT_ID_RE.test(candidate))
333
- return candidate;
334
- const prefixed = `CAP-${candidate}`;
335
- return REQUIREMENT_ID_RE.test(prefixed) ? prefixed : "CAP-1";
336
- }
337
261
  export function openapiTemplate(service) {
338
262
  return `openapi: 3.1.0
339
263
  info:
@@ -1 +1 @@
1
- {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/commands/new/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,+BAA+B,EAC/B,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,4BAA4B,EAC5B,cAAc,EACd,cAAc,EACd,aAAa,EACb,aAAa,GACd,MAAM,6CAA6C,CAAC;AAErD,SAAS,UAAU,CAAC,IAAY,EAAE,KAAkB;IAClD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACtE,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC;IAC9D,MAAM,IAAI,GACR,IAAI,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE;QACtB,IAAI,CAAC,KAAK,CAA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,IAAI,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC1F,MAAM,SAAS,GAAG,GAAG,IAAI,IAAI,CAAC;IAC9B,IAAI,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IACxD,MAAM,QAAQ,GAAG,OAAO,SAAS,EAAE,CAAC;IACpC,OAAO,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO;;WAEE,OAAO;;;;;;;;;;;;;CAajB,CAAC;AACF,CAAC","sourcesContent":["/**\n * The six files `loam new` scaffolds, and what each one says.\n *\n * They are here rather than inline because every one of them is a document a\n * person edits next, and the wording IS the instruction: the delta's comments\n * teach the grammar `core/document/parse.ts` matches on, and the intent's\n * frontmatter is serialized rather than interpolated because a title is free\n * text somebody types — `Checkout: split payments` reopens the mapping and the\n * file stops parsing.\n */\nimport { stringify as stringifyYaml } from \"yaml\";\nimport { REQUIREMENT_ID_RE } from \"../../core/document/spec.js\";\nimport {\n ARCH_REQUIREMENT_SENTINEL,\n ARCH_SHALL_SENTINEL,\n CAPABILITY_REQUIREMENT_SENTINEL,\n CAPABILITY_SHALL_SENTINEL,\n REQUIREMENT_SENTINEL,\n SCENARIO_SENTINEL,\n SERVICE_DESCRIPTION_SENTINEL,\n GIVEN_SENTINEL,\n SHALL_SENTINEL,\n THEN_SENTINEL,\n WHEN_SENTINEL,\n} from \"../../core/coherence/authoring/sentinels.js\";\n\nfunction identifier(name: string, taken: Set<string>): string {\n const parts = name.split(/[^A-Za-z0-9]+/).filter((p) => p.length > 0);\n const head = (parts[0] ?? \"svc\").replace(/^\\d+/, \"\") || \"svc\";\n const base =\n head[0]!.toLowerCase() +\n head.slice(1) +\n parts.slice(1).map((p) => p[0]!.toUpperCase() + p.slice(1)).join(\"\");\n let id = base;\n for (let n = 2; taken.has(id); n += 1) id = `${base}${n}`;\n taken.add(id);\n return id;\n}\n\n/** `FEAT-101` -> `feat_101`: LikeC4 view names take no dashes. */\nfunction viewName(featureId: string): string {\n return featureId.toLowerCase().replace(/[^a-z0-9]+/g, \"_\");\n}\n\n/* ------------------------------------------------------------------ */\n/* Templates */\n/* ------------------------------------------------------------------ */\n\nexport function intentTemplate(featureId: string, title: string | undefined): string {\n const heading = title ?? featureId;\n // The frontmatter is SERIALIZED, never interpolated. A title is free text a\n // person types — `Checkout: split payments` used to be pasted straight after\n // `title: `, where the colon reopens the mapping and the file stops parsing;\n // `Orders #42 rework` lost everything from the `#` as a YAML comment, so the\n // feature quietly answered to a title nobody wrote. The yaml serializer is the\n // only thing that knows every case, and it is already how migrate-openspec\n // writes the same three keys.\n //\n // `owner` is deliberately NOT a key here. Scaffolding `owner:` writes an\n // explicit null, which is a claim (\"this feature has no owner\") rather than\n // the truth (\"nobody has said yet\") — and every reader then has to tell an\n // absent key from a null one. The prompt survives as a comment.\n const frontmatter = stringifyYaml(\n { feature: featureId, ...(title === undefined ? {} : { title }), status: \"proposed\" },\n { lineWidth: 0 },\n ).trimEnd();\n return `---\n${frontmatter}\n# owner: <the team or person who answers for this>\n---\n\n# ${heading}\n\n## Why\n\n<!-- The problem in business terms. This is what a reviewer reads first, and what\n the requirement deltas below have to be justified by. -->\n\n## Scope\n\n<!-- Which services this touches — and, more usefully, which it deliberately does not. -->\n`;\n}\n\nexport function deltaTemplate(featureId: string, touched: string[], created: string[]): string {\n const taken = new Set<string>();\n const touchedIds = touched.map((s) => [identifier(s, taken), s] as const);\n const createdIds = created.map((s) => [identifier(s, taken), s] as const);\n\n const lines: string[] = [];\n if (touchedIds.length > 0) {\n // Context elements ship COMMENTED OUT, exactly like the example edge below.\n // Declared-and-untagged is the one shape `delta.nothing-tagged` exists to\n // refuse (an author who forgot the tags), so writing these live made every\n // `loam new --touches X` fail its own validator on the very first run —\n // which teaches people that the validator is noise. Uncomment a line when an\n // edge below actually needs the identifier.\n lines.push(\" // Services this feature touches, as context for the diagram. Uncomment the\");\n lines.push(\" // ones an edge below names, and reuse the identifiers from\");\n lines.push(\" // architecture/landscape.likec4 so the merge lines up. They stay UNTAGGED:\");\n lines.push(` // only #${featureId} is the change, and everything else here is context.`);\n for (const [id, name] of touchedIds) lines.push(` // ${id} = softwareSystem '${name}'`);\n lines.push(\"\");\n }\n if (createdIds.length > 0) {\n lines.push(\" // Services this feature introduces. The tag is what `loam archive` folds\");\n lines.push(\" // into the living landscape.\");\n for (const [id, name] of createdIds) {\n lines.push(` ${id} = softwareSystem '${name}' {`);\n lines.push(` #${featureId}`);\n // Interpolated from sentinels.ts, never spelled here: the placeholder\n // gate refuses this exact string at archive, and a second spelling is\n // how a template rewording silently retires the check that guards it.\n lines.push(` description '${SERVICE_DESCRIPTION_SENTINEL}'`);\n lines.push(\" }\");\n }\n lines.push(\"\");\n }\n\n // The example edge uses identifiers already declared above when there are two\n // to join; otherwise placeholders, so it never invents a service.\n const from = touchedIds[0]?.[0] ?? createdIds[0]?.[0] ?? \"consumer\";\n const to = createdIds[0]?.[0] ?? touchedIds[1]?.[0] ?? \"provider\";\n lines.push(\" // New calls. `metadata { op }` is the spine: it names the OpenAPI operationId\");\n lines.push(\" // the call uses, and `loam validate` checks it against the target's contract.\");\n lines.push(\" // Uncomment and adjust (both endpoints have to be declared above):\");\n lines.push(\" //\");\n lines.push(` // ${from} -> ${to} 'Calls createSplit' {`);\n lines.push(` // #${featureId}`);\n lines.push(\" // metadata { op 'createSplit' }\");\n lines.push(\" // }\");\n\n return `// ${featureId} — architecture delta.\n//\n// Everything tagged #${featureId} is exactly what \\`loam archive\\` folds into\n// architecture/landscape.likec4. Everything else here is context for the diagram.\n//\n// If ${featureId} changes no architecture, DELETE this file: a requirements-only\n// feature is complete without it, and an empty \\`model {}\\` is just as legal.\n\nspecification {\n element softwareSystem\n tag ${featureId}\n}\n\nmodel {\n${lines.join(\"\\n\")}\n}\n\nviews {\n view ${viewName(featureId)} {\n include *\n }\n}\n`;\n}\n\n/**\n * The business axis, scaffolded with its example INSIDE the comment — the same\n * mechanism as `archSpecTemplate` below, for the same reason: this template\n * used to ship a live `### Requirement: TODO — name the behaviour` that\n * parsed as a real requirement, validated clean, and archived a literal TODO\n * into the living spec at exit 0. The indented headings sit past the\n * line-anchored patterns core/document/parse.ts matches on, so the scaffold\n * declares nothing until a person copies the block out and writes over the\n * fill-ins — and `scaffold.placeholder` gates the archive if the fill-ins\n * survive the copy.\n *\n * No nested HTML comments: the `Operations:` guidance that used to be its own\n * comment lives in this one's prose, because an inner `-->` would end the\n * outer comment early and re-expose the example to the parser.\n */\nexport function specTemplate(featureId: string, service: string): string {\n return `# ${service} — requirement delta for ${featureId}\n\n<!-- Sections: ADDED / MODIFIED / REMOVED. Delete the ones you do not need.\n A MODIFIED requirement carries its full new text, not a diff.\n Every requirement needs at least one scenario — \\`loam validate\\` gates on it.\n\n An \\`Operations:\\` body line names the operationIds the requirement\n governs. \\`loam validate\\` checks each one against the service's OpenAPI,\n and \\`loam archive\\` refuses to merge a requirement that governs an\n operation nobody defines — add the line once the contract exists.\n\n A \\`Publishes:\\` / \\`Consumes:\\` body line does the same for event messages:\n it names what the requirement puts on or takes off the bus, checked\n against the service's AsyncAPI contract. If ${featureId} changes that\n contract, hand-create specs/${service}/asyncapi.yaml — a complete\n AsyncAPI 3.0 document, messages declared under \\`components.messages\\`\n (loam scaffolds none: an event contract is genuinely optional) — and run\n \\`loam rebase ${featureId}\\` so every restated slot pins as a quote.\n\n Copy the block below out of this comment, unindent it, and replace the\n TODOs and every <angle-bracket> fill-in — \\`loam archive\\` refuses the\n scaffold's own wording (\\`scaffold.placeholder\\`):\n\n ## ADDED Requirements\n\n ### Requirement: ${REQUIREMENT_SENTINEL}\n Requirement-ID: ${featureId}.${service}.requirement\n\n The service SHALL ${SHALL_SENTINEL}.\n\n #### Scenario: ${SCENARIO_SENTINEL}\n - **Given** ${GIVEN_SENTINEL}\n - **When** ${WHEN_SENTINEL}\n - **Then** ${THEN_SENTINEL}\n-->\n`;\n}\n\n/**\n * The architecture axis, scaffolded EMPTY on purpose.\n *\n * Same grammar as spec.md, so the template body has to be unparseable as\n * requirements or the scaffold would ship a requirement nobody wrote — the\n * headings are therefore indented inside an HTML comment, which puts them past\n * the line-anchored `## ADDED Requirements` / `### Requirement:` patterns\n * core/document/parse.ts matches on. Copy the block out of the comment and unindent it.\n */\nexport function archSpecTemplate(featureId: string, service: string): string {\n return `# ${service} — architecture requirement delta for ${featureId}\n\n<!-- The architecture axis: the obligations no business scenario was ever going\n to mention — the outbox, the retries, the timeouts, the alerts.\n\n \\`Covers:\\` is to an arch requirement what \\`Operations:\\` is to a business\n one — it names the MODEL OBJECTS the scenarios below exercise, so coverage\n is derived instead of trusted. Three forms, comma-separated:\n\n Covers: ${service} a C4 element — its id, or the service a\n bound/titled element stands for\n Covers: consumer -> ${service} an edge, each side resolved the same way\n Covers: alert:<id>, sli:<id> a signal declared in health.yaml\n\n Every tagged element and edge in delta.likec4 wants one (\\`c4.uncovered\\`).\n Delete this file if ${featureId} adds no architectural obligation.\n\n Copy the block below out of this comment and unindent it:\n\n ## ADDED Requirements\n\n ### Requirement: ${ARCH_REQUIREMENT_SENTINEL}\n Requirement-ID: ${featureId}.${service}.arch\n\n The service SHALL ${ARCH_SHALL_SENTINEL}.\n\n Covers: ${service}\n\n #### Scenario: ${SCENARIO_SENTINEL}\n - **Given** ${GIVEN_SENTINEL}\n - **When** ${WHEN_SENTINEL}\n - **Then** ${THEN_SENTINEL}\n-->\n`;\n}\n\n/**\n * The BUSINESS axis, scaffolded by `--capability`: a delta against the living\n * `capabilities/<id>/spec.md`.\n *\n * Same idiom as the two spec templates above and for the same reason — the\n * example lives INSIDE an HTML comment, indented past the line-anchored\n * `## ADDED Requirements` / `### Requirement:` patterns core/document/parse.ts\n * matches on — so the scaffold declares nothing until a person copies the block\n * out. That is what lets a freshly scaffolded feature validate clean while\n * still being refused by `loam archive` the moment the block is copied out and\n * left unedited (`scaffold.placeholder`, which reads\n * `features/<FEAT>/capabilities/` as well as `features/<FEAT>/specs/`).\n *\n * WHAT THE COMMENT TEACHES IS THE ALTITUDE, because that is the mistake this\n * document invites. A capability requirement is a promise a customer could\n * check; the four service-scoped lines (`Operations:`, `Covers:`, `Publishes:`,\n * `Consumes:`) and the axis's own two (`Capability:`, `Realizes:`) are all\n * ERRORS here — `capability.requirement-service-scoped` and\n * `capability.requirement-inert-join` — and every one of them parses, so an\n * author who is not told writes one and finds out at archive. `Requirement-ID:`\n * is spelled as mandatory for the same reason: a capability document outlives\n * every service that realizes it, so identity by heading is refused\n * (`capability.requirement-unidentified`).\n *\n * No nested HTML comments, exactly as `specTemplate` states: an inner `-->`\n * would end the outer comment early and re-expose the example to the parser.\n */\nexport function capabilityDeltaTemplate(featureId: string, capability: string): string {\n return `# ${capability} — capability delta for ${featureId}\n\n<!-- The business axis. This is a DELTA against the living\n capabilities/${capability}/spec.md, not the document itself: sections are\n ADDED / MODIFIED / REMOVED, delete the ones you do not need, and a MODIFIED\n requirement carries its full new text rather than a diff. If the fleet has\n no capabilities/${capability}/spec.md yet, this feature's archive creates it.\n\n WHAT BELONGS HERE is a promise somebody outside the fleet could check —\n 'a refund reaches the customer's card within five days'. What does NOT is\n the mechanism: \\`Operations:\\`, \\`Covers:\\`, \\`Publishes:\\` and \\`Consumes:\\`\n all resolve against ONE service's own contract or model, so a requirement\n carrying one is a service requirement filed at the wrong altitude and\n \\`loam validate\\` says so. \\`Capability:\\` and \\`Realizes:\\` are refused here\n too — they are the joins written on the SERVICE requirement that keeps this\n promise, one directory over in specs/<svc>/spec.md, as\n \\`Realizes: ${capability}#<Requirement-ID>\\`.\n\n \\`Requirement-ID:\\` is mandatory on every requirement below. A capability\n document outlives the services that realize it, so its requirements are\n addressed by a stable id rather than by their heading — rewording a heading\n would otherwise be a removal and an addition, and every \\`Realizes:\\` line\n pointed at it would break in silence.\n\n A MODIFIED or REMOVED requirement also needs a \\`Based-On:\\` pin quoting the\n living text it rewrites, so two features touching one capability collide\n loudly instead of overwriting each other. Run \\`loam rebase ${featureId}\\`\n and the pins are written for you.\n\n Copy the block below out of this comment, unindent it, and replace the TODO\n and every <angle-bracket> fill-in — \\`loam archive\\` refuses the scaffold's\n own wording (\\`scaffold.placeholder\\`):\n\n ## ADDED Requirements\n\n ### Requirement: ${CAPABILITY_REQUIREMENT_SENTINEL}\n Requirement-ID: ${idHint(capability)}\n\n The fleet SHALL ${CAPABILITY_SHALL_SENTINEL}.\n\n #### Scenario: ${SCENARIO_SENTINEL}\n - **Given** ${GIVEN_SENTINEL}\n - **When** ${WHEN_SENTINEL}\n - **Then** ${THEN_SENTINEL}\n-->\n`;\n}\n\n/**\n * A plausible `Requirement-ID:` for a capability, offered as a shape rather than\n * a name: `payments/refunds` -> `PAYMENTS-REFUNDS-1`.\n *\n * Deliberately NOT the feature id. A service requirement's scaffolded id is\n * `<FEAT>.<svc>.requirement` because that requirement is created by, and lives\n * and dies with, one feature; a capability requirement outlives every feature\n * that touches it, so an id carrying the id of the feature that happened to\n * introduce it is exactly the identity-by-accident this axis refuses. The\n * suffix is `-1` and not a count of anything: it is a placeholder digit inside\n * a placeholder id, and the author is being asked to name the promise.\n *\n * CHECKED AGAINST THE REAL GRAMMAR, never assumed to satisfy it. A capability id\n * may begin with a digit (`3ds`, `2fa`, `1099-filing` — `dirNameHazard` allows an\n * alphanumeric head) while `REQUIREMENT_ID_RE` demands a LETTER, so the obvious\n * slug hands the author `3DS-1` and `loam validate` then refuses it with\n * `delta.requirement-id-invalid` — the author refused for using the shape the\n * scaffold offered. Length is the same class of failure at 128 characters. The\n * fallback prefixes rather than truncates, because a truncated id is a plausible\n * name that means something else.\n */\nfunction idHint(capability: string): string {\n const slug = capability.toUpperCase().replace(/[^A-Z0-9]+/g, \"-\").replace(/^-+|-+$/g, \"\");\n const candidate = `${slug}-1`;\n if (REQUIREMENT_ID_RE.test(candidate)) return candidate;\n const prefixed = `CAP-${candidate}`;\n return REQUIREMENT_ID_RE.test(prefixed) ? prefixed : \"CAP-1\";\n}\n\nexport function openapiTemplate(service: string): string {\n return `openapi: 3.1.0\ninfo:\n title: ${service}\n version: \"0.1\"\n\n# The operations this feature adds. \\`operationId\\` is the token the C4 edge\n# (metadata { op }) and the requirement (Operations:) both point at — keep the\n# three spellings identical or \\`loam validate\\` will say so.\npaths: {}\n# /splits:\n# post:\n# operationId: createSplit\n# responses:\n# \"201\":\n# description: Created\n`;\n}\n"]}
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/commands/new/templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,4BAA4B,EAC5B,cAAc,EACd,cAAc,EACd,aAAa,EACb,aAAa,GACd,MAAM,6CAA6C,CAAC;AAErD;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,IAAY,EAAE,KAAkB,EAAE,KAAc;IAClE,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,EAAE,GAAG,IAAI,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QAAE,EAAE,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;IAC3D,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACd,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,yGAAyG;AACzG,S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AC,IAAI,CAAC,sCAAsC,CAAC,CAAC;IACnD,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAErB,OAAO,MAAM,SAAS;;wBAEA,SAAS;;;QAGzB,SAAS;;;;;QAKT,SAAS;;;;EAIf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;;;;SAIT,QAAQ,CAAC,SAAS,CAAC;;;;CAI3B,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB,EAAE,OAAe;IAC7D,OAAO,KAAK,OAAO,4BAA4B,SAAS;;;;;;;;;;;;;mDAaP,SAAS;mCACzB,OAAO;;;+DAGqB,SAAS;;;;;;;;;;uBAUjD,oBAAoB;sBACrB,SAAS,IAAI,OAAO;;wBAElB,cAAc;;qBAEjB,iBAAiB;kBACpB,cAAc;iBACf,aAAa;iBACb,aAAa;;CAE7B,CAAC;AACF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,OAAe;IACjE,OAAO,KAAK,OAAO,yCAAyC,SAAS;;;;;;;;;iBAStD,OAAO;;6BAEK,OAAO;;;;2BAIT,SAAS;;;;;;uBAMb,yBAAyB;sBAC1B,SAAS,IAAI,OAAO;;wBAElB,mBAAmB;;cAE7B,OAAO;;qBAEA,iBAAiB;kBACpB,cAAc;iBACf,aAAa;iBACb,aAAa;;CAE7B,CAAC;AACF,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,OAAO;;WAEE,OAAO;;;;;;;;;;;;;CAajB,CAAC;AACF,CAAC","sourcesContent":["/**\n * Five of the six files `loam new` scaffolds, and what each one says. The\n * sixth, the `--capability` delta, is in `./capability-template.ts`.\n *\n * They are here rather than inline because every one of them is a document a\n * person edits next, and the wording IS the instruction: the delta's comments\n * teach the grammar `core/document/parse.ts` matches on, and the intent's\n * frontmatter is serialized rather than interpolated because a title is free\n * text somebody types — `Checkout: split payments` reopens the mapping and the\n * file stops parsing.\n */\nimport { stringify as stringifyYaml } from \"yaml\";\nimport { serviceElementId } from \"../../core/c4/seed/template.js\";\nimport {\n ARCH_REQUIREMENT_SENTINEL,\n ARCH_SHALL_SENTINEL,\n REQUIREMENT_SENTINEL,\n SCENARIO_SENTINEL,\n SERVICE_DESCRIPTION_SENTINEL,\n GIVEN_SENTINEL,\n SHALL_SENTINEL,\n THEN_SENTINEL,\n WHEN_SENTINEL,\n} from \"../../core/coherence/authoring/sentinels.js\";\n\n/**\n * The LikeC4 identifier the delta declares a service under: the id the fleet\n * map already draws it as (`drawn`), since a context id the map lacks lines up\n * with nothing at archive, else `serviceElementId` — seed's `svc_<id>`, where\n * this used to camel-case the name into a third spelling beside the seed's and\n * the map's. A collision inside one delta takes the seed's `_<n>` suffix.\n */\nfunction identifier(name: string, taken: Set<string>, drawn?: string): string {\n if (drawn !== undefined) return drawn;\n const base = serviceElementId(name);\n let id = base;\n for (let n = 2; taken.has(id); n += 1) id = `${base}_${n}`;\n taken.add(id);\n return id;\n}\n\n/** One context line. A nested id (`a.b`) is no top-level declaration, so it names its parent instead. */\nfunction contextLine(id: string, name: string): string {\n const dot = id.lastIndexOf(\".\");\n if (dot < 0) return ` // ${id} = softwareSystem '${name}'`;\n return ` // ${id.slice(dot + 1)} = softwareSystem '${name}' // inside ${id.slice(0, dot)} { }, as the map draws it; edges name it ${id}`;\n}\n\n/** `FEAT-101` -> `feat_101`: LikeC4 view names take no dashes. */\nfunction viewName(featureId: string): string {\n return featureId.toLowerCase().replace(/[^a-z0-9]+/g, \"_\");\n}\n\n/* ------------------------------------------------------------------ */\n/* Templates */\n/* ------------------------------------------------------------------ */\n\nexport function intentTemplate(featureId: string, title: string | undefined): string {\n const heading = title ?? featureId;\n // The frontmatter is SERIALIZED, never interpolated. A title is free text a\n // person types — `Checkout: split payments` used to be pasted straight after\n // `title: `, where the colon reopens the mapping and the file stops parsing;\n // `Orders #42 rework` lost everything from the `#` as a YAML comment, so the\n // feature quietly answered to a title nobody wrote. The yaml serializer is the\n // only thing that knows every case, and it is already how migrate-openspec\n // writes the same three keys.\n //\n // `owner` is deliberately NOT a key here. Scaffolding `owner:` writes an\n // explicit null, which is a claim (\"this feature has no owner\") rather than\n // the truth (\"nobody has said yet\") — and every reader then has to tell an\n // absent key from a null one. The prompt survives as a comment.\n //\n // `## Open questions` is where loam-feature's analyze step writes, so it is\n // scaffolded as a heading over a comment and nothing else. `intent.empty`\n // (coherence/authoring/scaffold.ts) reads past the whole section, so neither\n // the untouched comment nor a page of questions counts as the Why.\n const frontmatter = stringifyYaml(\n { feature: featureId, ...(title === undefined ? {} : { title }), status: \"proposed\" },\n { lineWidth: 0 },\n ).trimEnd();\n return `---\n${frontmatter}\n# owner: <the team or person who answers for this>\n---\n\n# ${heading}\n\n## Why\n\n<!-- The problem in business terms. This is what a reviewer reads first, and what\n the requirement deltas below have to be justified by. -->\n\n## Scope\n\n<!-- Which services this touches — and, more usefully, which it deliberately does not. -->\n\n## Open questions\n\n<!-- Optional, never graded. What the documents leave open: an ambiguous SHALL, a value or\n window two services state differently, an edge with no stated timeout, retry or\n compensation. A person answers each by editing this section. -->\n`;\n}\n\nexport function deltaTemplate(featureId: string, touched: string[], created: string[], drawn: ReadonlyMap<string, string> = new Map()): string {\n // The map's ids are claimed first: a new service's id never collides with a box quoted as context.\n const taken = new Set<string>(drawn.values());\n const touchedIds = touched.map((s) => [identifier(s, taken, drawn.get(s)), s] as const);\n const createdIds = created.map((s) => [identifier(s, taken), s] as const);\n\n const lines: string[] = [];\n if (touchedIds.length > 0) {\n // Context elements ship COMMENTED OUT, exactly like the example edge below.\n // Declared-and-untagged is the one shape `delta.nothing-tagged` exists to\n // refuse (an author who forgot the tags), so writing these live made every\n // `loam new --touches X` fail its own validator on the very first run —\n // which teaches people that the validator is noise. Uncomment a line when an\n // edge below actually needs the identifier.\n lines.push(\" // Services this feature touches, as context for the diagram. Uncomment the\");\n lines.push(\" // ones an edge below names. A service the fleet map already draws keeps the\");\n lines.push(\" // identifier architecture/ gives it, so the merge lines up; one it does not\");\n lines.push(\" // draw yet gets svc_<id>, the convention `loam seed` writes. They stay UNTAGGED:\");\n lines.push(` // only #${featureId} is the change, and everything else here is context.`);\n for (const [id, name] of touchedIds) lines.push(contextLine(id, name));\n lines.push(\"\");\n }\n if (createdIds.length > 0) {\n lines.push(\" // Services this feature introduces. The tag is what `loam archive` folds\");\n lines.push(\" // into the living landscape.\");\n for (const [id, name] of createdIds) {\n lines.push(` ${id} = softwareSystem '${name}' {`);\n lines.push(` #${featureId}`);\n // Interpolated from sentinels.ts, never spelled here: the placeholder\n // gate refuses this exact string at archive, and a second spelling is\n // how a template rewording silently retires the check that guards it.\n lines.push(` description '${SERVICE_DESCRIPTION_SENTINEL}'`);\n lines.push(\" }\");\n }\n lines.push(\"\");\n }\n\n // The example edge uses identifiers already declared above when there are two\n // to join; otherwise placeholders, so it never invents a service.\n const from = touchedIds[0]?.[0] ?? createdIds[0]?.[0] ?? \"consumer\";\n const to = createdIds[0]?.[0] ?? touchedIds[1]?.[0] ?? \"provider\";\n lines.push(\" // New calls. `metadata { op }` is the spine: it names the OpenAPI operationId\");\n lines.push(\" // the call uses, and `loam validate` checks it against the target's contract.\");\n lines.push(\" // Uncomment and adjust (both endpoints have to be declared above):\");\n lines.push(\" //\");\n lines.push(` // ${from} -> ${to} 'Calls createSplit' {`);\n lines.push(` // #${featureId}`);\n lines.push(\" // metadata { op 'createSplit' }\");\n lines.push(\" // }\");\n\n return `// ${featureId} — architecture delta.\n//\n// Everything tagged #${featureId} is exactly what \\`loam archive\\` folds into\n// architecture/landscape.likec4. Everything else here is context for the diagram.\n//\n// If ${featureId} changes no architecture, DELETE this file: a requirements-only\n// feature is complete without it, and an empty \\`model {}\\` is just as legal.\n\nspecification {\n element softwareSystem\n tag ${featureId}\n}\n\nmodel {\n${lines.join(\"\\n\")}\n}\n\nviews {\n view ${viewName(featureId)} {\n include *\n }\n}\n`;\n}\n\n/**\n * The business axis, scaffolded with its example INSIDE the comment — the same\n * mechanism as `archSpecTemplate` below, for the same reason: this template\n * used to ship a live `### Requirement: TODO — name the behaviour` that\n * parsed as a real requirement, validated clean, and archived a literal TODO\n * into the living spec at exit 0. The indented headings sit past the\n * line-anchored patterns core/document/parse.ts matches on, so the scaffold\n * declares nothing until a person copies the block out and writes over the\n * fill-ins — and `scaffold.placeholder` gates the archive if the fill-ins\n * survive the copy.\n *\n * No nested HTML comments: the `Operations:` guidance that used to be its own\n * comment lives in this one's prose, because an inner `-->` would end the\n * outer comment early and re-expose the example to the parser.\n */\nexport function specTemplate(featureId: string, service: string): string {\n return `# ${service} — requirement delta for ${featureId}\n\n<!-- Sections: ADDED / MODIFIED / REMOVED. Delete the ones you do not need.\n A MODIFIED requirement carries its full new text, not a diff.\n Every requirement needs at least one scenario — \\`loam validate\\` gates on it.\n\n An \\`Operations:\\` body line names the operationIds the requirement\n governs. \\`loam validate\\` checks each one against the service's OpenAPI,\n and \\`loam archive\\` refuses to merge a requirement that governs an\n operation nobody defines — add the line once the contract exists.\n\n A \\`Publishes:\\` / \\`Consumes:\\` body line does the same for event messages:\n it names what the requirement puts on or takes off the bus, checked\n against the service's AsyncAPI contract. If ${featureId} changes that\n contract, hand-create specs/${service}/asyncapi.yaml — an AsyncAPI 3.0\n document holding only the slots this feature adds, changes or removes,\n messages under \\`components.messages\\` (loam scaffolds none: an event\n contract is genuinely optional) — and run \\`loam rebase ${featureId}\\`\n when it edits a slot the living contract already has, so that slot pins.\n The same holds for an openapi.yaml beside this file: only what changes.\n\n Copy the block below out of this comment, unindent it, and replace the\n TODOs and every <angle-bracket> fill-in — \\`loam archive\\` refuses the\n scaffold's own wording (\\`scaffold.placeholder\\`):\n\n ## ADDED Requirements\n\n ### Requirement: ${REQUIREMENT_SENTINEL}\n Requirement-ID: ${featureId}.${service}.requirement\n\n The service SHALL ${SHALL_SENTINEL}.\n\n #### Scenario: ${SCENARIO_SENTINEL}\n - **Given** ${GIVEN_SENTINEL}\n - **When** ${WHEN_SENTINEL}\n - **Then** ${THEN_SENTINEL}\n-->\n`;\n}\n\n/**\n * The architecture axis, scaffolded EMPTY on purpose.\n *\n * Same grammar as spec.md, so the template body has to be unparseable as\n * requirements or the scaffold would ship a requirement nobody wrote — the\n * headings are therefore indented inside an HTML comment, which puts them past\n * the line-anchored `## ADDED Requirements` / `### Requirement:` patterns\n * core/document/parse.ts matches on. Copy the block out of the comment and unindent it.\n */\nexport function archSpecTemplate(featureId: string, service: string): string {\n return `# ${service} — architecture requirement delta for ${featureId}\n\n<!-- The architecture axis: the obligations no business scenario was ever going\n to mention — the outbox, the retries, the timeouts, the alerts.\n\n \\`Covers:\\` is to an arch requirement what \\`Operations:\\` is to a business\n one — it names the MODEL OBJECTS the scenarios below exercise, so coverage\n is derived instead of trusted. Three forms, comma-separated:\n\n Covers: ${service} a C4 element — its id, or the service a\n bound/titled element stands for\n Covers: consumer -> ${service} an edge, each side resolved the same way\n Covers: alert:<id>, sli:<id> a signal declared in health.yaml\n\n Every tagged element and edge in delta.likec4 wants one (\\`c4.uncovered\\`).\n Delete this file if ${featureId} adds no architectural obligation.\n\n Copy the block below out of this comment and unindent it:\n\n ## ADDED Requirements\n\n ### Requirement: ${ARCH_REQUIREMENT_SENTINEL}\n Requirement-ID: ${featureId}.${service}.arch\n\n The service SHALL ${ARCH_SHALL_SENTINEL}.\n\n Covers: ${service}\n\n #### Scenario: ${SCENARIO_SENTINEL}\n - **Given** ${GIVEN_SENTINEL}\n - **When** ${WHEN_SENTINEL}\n - **Then** ${THEN_SENTINEL}\n-->\n`;\n}\n\nexport function openapiTemplate(service: string): string {\n return `openapi: 3.1.0\ninfo:\n title: ${service}\n version: \"0.1\"\n\n# The operations this feature adds. \\`operationId\\` is the token the C4 edge\n# (metadata { op }) and the requirement (Operations:) both point at — keep the\n# three spellings identical or \\`loam validate\\` will say so.\npaths: {}\n# /splits:\n# post:\n# operationId: createSplit\n# responses:\n# \"201\":\n# description: Created\n`;\n}\n"]}